centos7 mysql5.7.17源码安装
**安装前准备
操作系统环境:Centos 7.2
1、解决依赖包并下载源码包至/home/soft/目录下
1
2
3
4
5
6
7
|
[root@node03 ~] # yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison [root@node03 ~] # cd /home/soft/ [root@node03 soft] # wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz [root@node03 soft] #tar -zxvf boost_1_59_0.tar.gz #解压 [root@node03 soft] #mv boost_1_59_0 /usr/local/boost #移动至/usr/local/boost/目录下 [root@node03 soft] # wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz [root@node03 soft] # tar -zxvf mysql-5.7.17.tar.gz |
2、新建MySQL用户和用户组,创建/data/mysql 目录存放mysql数据
1
2
|
[root@node03 soft] # groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql [root@node03 soft] # mkdir -pv /data/mysql |
3、预编译及编译安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node03 soft] # cd mysql-5.7.17 [root@node03 mysql-5.7.17]
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock\
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BOOST=/usr/local/boost \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
|
注:
DCMAKE_INSTALL_PREFIX=/usr/local/mysql:安装路径
DMYSQL_DATADIR=/data/mysql:数据文件存放位置
DSYSCONFDIR=/etc:my.cnf路径
DWITH_MYISAM_STORAGE_ENGINE=1:支持MyIASM引擎
DWITH_INNOBASE_STORAGE_ENGINE=1:支持InnoDB引擎
DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock:连接数据库socket路径
DMYSQL_TCP_PORT=3306:端口
DENABLED_LOCAL_INFILE=1:允许从本地导入数据
DWITH_PARTITION_STORAGE_ENGINE=1:安装支持数据库分区
DEXTRA_CHARSETS=all:安装所有的字符集
DDEFAULT_CHARSET=utf8:默认字符
DWITH_EMBEDDED_SERVER=1:嵌入式服务器
1
|
[root@node03 mysql-5.7.17] # make -j4
make install #编译安装 |
4、设置启动脚本,开机自启动
1
2
3
4
5
6
|
[root@node03 ~] # chown -R mysql:mysql /usr/local/mysql [root@node03 ~] # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@node03 ~] # chmod +x /etc/init.d/mysqld ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@node03 ~] # chkconfig --add mysqld chkconfig mysqld on
|
5、拷贝my.cnf至/etc/目录下,并初始化数据库
1
2
|
[root@node03 ~] # cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf [root@node03 ~] # /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql |
注:初始化最后一行是root用户密码(root@localhost: ,5j1Qj_LLAek)
6、启动服务
service mysqld start
7、root管理员修改密码
1
2
3
4
5
6
7
|
[root@node03 mysql] #mysql -uroot -p,5j1Qj_LLAek mysql> SET PASSWORD = PASSWORD( '111111' ); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> ALTER USER 'root' @ 'localhost' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) |