7.4.3. MySQL编译安装
- Date:
2018-11
7.4.3.1. 环境说明
7.4.3.2. MySQL安装
7.4.3.2.1. MySQL安装准备
防火墙、selinux、时间同步配置系统准备命令集合
1ntpdate pool.ntp.org
2sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
3setenforce 0
4/etc/init.d/iptables stop
5chkconfig iptables off
注意
- 时间同步最好加入到定时任务。这样保证以后时间如果有错误的时候会自动更正。
echo "#time sysc by myhome at 2018-03-30" >>/var/spool/cron/rootecho "*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2&1" >>/var/spool/cron/root
安装MySQL需要预安装的依赖包
1[root@mysql_001 ~]# yum install ncurses-devel libaio-devel cmake -y
7.4.3.2.2. MySQL下载
1[root@mysql_001 ~]# cd /data/tools/
2[root@mysql_001 tools]# wget http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.5/mysql-5.5.60.tar.gz
3[root@mysql_001 tools]# ls
4mysql-5.5.60.tar.gz
7.4.3.2.3. MySQL编译安装
1[root@mysql_001 tools]# mkdir /app
2[root@mysql_001 tools]# ll -d /app/
3drwxr-xr-x 2 root root 4096 Nov 26 23:48 /app/
4
5[root@mysql_001 mysql-5.5.60]# cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql-5.5.60 \
6> -DMYSQL_DATADIR=/app/mysql-5.5.60/data \
7> -DMYSQL_UNIX_ADDR=/app/mysql-5.5.60/tmp/mysql.sock \
8> -DDEFAULT_CHARSET=utf8 \
9> -DDEFAULT_COLLATION=utf8_general_ci \
10> -DWITH_EXTRA_CHARSETS=all \
11> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
12> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
13> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
14> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
15> -DWITH_ZLIB=bundled \
16> -DWITH_SSL=bundled \
17> -DENABLED_LOCAL_INFILE=1 \
18> -DWITH_EMBEDDED_SERVER=1 \
19> -DENABLE_DOWNLOADS=1 \
20> -DWITH_DEBUG=0
1cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql-5.5.60 \
2-DMYSQL_DATADIR=/app/mysql-5.5.60/data \
3-DMYSQL_UNIX_ADDR=/app/mysql-5.5.60/tmp/mysql.sock \
4-DDEFAULT_CHARSET=utf8 \
5-DDEFAULT_COLLATION=utf8_general_ci \
6-DWITH_EXTRA_CHARSETS=all \
7-DWITH_INNOBASE_STORAGE_ENGINE=1 \
8-DWITH_FEDERATED_STORAGE_ENGINE=1 \
9-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
10-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
11-DWITH_ZLIB=bundled \
12-DWITH_SSL=bundled \
13-DENABLED_LOCAL_INFILE=ON \
14-DWITH_EMBEDDED_SERVER=1 \
15-DENABLE_DOWNLOADS=1 \
16-DWITH_DEBUG=0
1[root@mysql_001 mysql-5.5.60]# make && make install
创建软连接
1[root@mysql_001 mysql-5.5.60]# ln -s /app/mysql-5.5.60 /app/mysql
2
3[root@mysql_001 mysql-5.5.60]# ll /app/mysql
4lrwxrwxrwx 1 root root 17 Nov 27 00:30 /app/mysql -> /app/mysql-5.5.60
配置系统环境变量,使mysql命令可以直接使用不用输入全路径
1echo "export PATH=/app/mysql/bin:$PATH" >>/etc/profile
2source /etc/profile
3echo $PATH
设置socket目录权限:
1[root@mysql_001 mysql]# chmod 1777 /app/mysql-5.5.60/tmp/
启动脚本
1[root@mysql_001 mysql-5.5.60]# pwd
2/data/tools/mysql-5.5.60
3[root@mysql_001 mysql-5.5.60]# cd support-files/
4
5[root@mysql_001 support-files]# cp mysql.server /etc/init.d/mysqld
6[root@mysql_001 support-files]# chmod 700 /etc/init.d/mysqld
7.4.3.2.4. MySQL数据库初始化
更改数据目录所属用户和组:
1id mysql
2useradd -s /sbin/nologin -M mysql
3id mysql
4
5chown -R mysql.mysql /app/mysql/data/
6ll /app/mysql/data/
1[root@mysql_001 mysql-5.5.60]# pwd
2/data/tools/mysql-5.5.60
3[root@mysql_001 mysql-5.5.60]# cp support-files/my-small.cnf /etc/my.cnf
4cp: overwrite `/etc/my.cnf'? y`
1[root@mysql_001 mysql-5.5.60]# chown -R mysql.mysql /app/mysql/data/
2[root@mysql_001 mysql-5.5.60]# ll -d /app/mysql/data/
3drwxr-xr-x 3 mysql mysql 4096 Nov 27 00:25 /app/mysql/data/
1[root@mysql_001 mysql-5.5.60]# cd /app/mysql/scripts/
2[root@mysql_001 scripts]# ./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/app/mysql/ --datadir=/app/mysql/data --user=mysql
7.4.3.2.5. MySQL启动
1[root@mysql_001 ~]# /etc/init.d/mysqld start
7.4.3.2.6. MySQL登陆测试并加登陆密码
没有设置密码时用默认MySQL客户端登陆MySQL数据库:
1[root@mysql_001 ~]# mysql
2Welcome to the MySQL monitor. Commands end with ; or \g.
3Your MySQL connection id is 1
4Server version: 5.5.60 Source distribution
5
6Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
7
8Oracle is a registered trademark of Oracle Corporation and/or its
9affiliates. Other names may be trademarks of their respective
10owners.
11
12Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
13
14mysql> show databases;
15+--------------------+
16| Database |
17+--------------------+
18| information_schema |
19| mysql |
20| performance_schema |
21| test |
22+--------------------+
234 rows in set (0.00 sec)
初始设置MySQL的root密码,设置密码为 test :
1[root@mysql_001 ~]# mysqladmin -u root password 'test'
2[root@mysql_001 ~]# mysql -uroot -ptest
3Welcome to the MySQL monitor. Commands end with ; or \g.
4Your MySQL connection id is 3
5Server version: 5.5.60 Source distribution
6
7Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
8
9Oracle is a registered trademark of Oracle Corporation and/or its
10affiliates. Other names may be trademarks of their respective
11owners.
12
13Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14
15mysql>