首页 > 代码库 > centos7 mysql5.7.17源码安装
centos7 mysql5.7.17源码安装
centos7 mysql5.7.17源码安装
**安装前准备
操作系统环境:Centos 7.2
1、解决依赖包并下载源码包至/home/soft/目录下
[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用户和用户组,创建/mydata/data目录存放mysql数据
[root@node03 soft]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql [root@node03 soft]# mkdir -pv /mydata/data
3、预编译及编译安装
[root@node03 soft]# cd mysql-5.7.17 [root@node03 mysql-5.7.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DDEFAULT_CHARSET=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/boost -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_EMBEDDED_SERVER=1 \
注:
DCMAKE_INSTALL_PREFIX=/usr/local/mysql:安装路径
DMYSQL_DATADIR=/mysql/data:数据文件存放位置
DSYSCONFDIR=/etc:my.cnf路径
DWITH_MYISAM_STORAGE_ENGINE=1:支持MyIASM引擎
DWITH_INNOBASE_STORAGE_ENGINE=1:支持InnoDB引擎
DMYSQL_UNIX_ADDR=/tmp/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:嵌入式服务器
[root@node03 mysql-5.7.17]# make install #编译安装
4、设置启动脚本,开机自启动
[root@node03 ~]# cp /home/soft/mysql-5.7.17/support-files/mysql.server /etc/init.d/mysqld [root@node03 ~]# chmod +x /etc/init.d/mysqld [root@node03 ~]# systemctl enable mysqld mysqld.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig mysqld on [root@node03 ~]# chown -R mysql:mysql /usr/local/mysql
5、拷贝my.cnf至/etc/目录下,并初始化数据库
[root@node03 ~]# cp /home/soft/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf [root@node03 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
注:初始化最后一行是root用户密码(root@localhost: ,5j1Qj_LLAek)
6、配置mysql环境变量,并启动服务
[root@node03 data]# vim /etc/profile
#编辑/etc/profile文件在最后添加如下两行
PATH=/usr/local/mysql/bin:$PATH export PATH
[root@node03 data]# source /etc/profile #刷新生效 [root@node03 mysql]# systemctl start mysqld.service [root@node03 mysql]# ss -tlpn |grep ‘3306‘ LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=25268,fd=20))
7、root管理员修改密码
[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)
本文出自 “一万小时定律” 博客,请务必保留此出处http://daisywei.blog.51cto.com/7837970/1896614
centos7 mysql5.7.17源码安装