官网安装地址:https://downloads.mysql.com/archives/community/
或者你也可以这样安装:wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
此处安装的是 mysql-5.7.26.tar.gz
解压mysql安装包
[root@chenwanting ~]# tar -zxvf mysql-5.7.26.tar.gz
[root@chenwanting ~]# mv mysql-5.7.26 /usr/local/src
下载boost
[root@chenwanting ~]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
解压boots压缩包
[root@chenwanting ~]# tar -zxvf boost_1_59_0.tar.gz
将boots移动到/usr/local/boost
[root@chenwanting ~]# mkdir /usr/local/boost
[root@chenwanting ~]# mv boost_1_59_0 /usr/local/boost
安装依赖库
[root@chenwanting ~]# yum -y install cmake gcc gcc-c++ bison ncurses ncurses-devel
创建用户和组
[root@chenwanting ~]# groupadd mysql
[root@chenwanting ~]# useradd -g mysql -s /sbin/nologin -M mysql
源码编码编译:
[root@chenwanting ~]# cd /usr/local/src
[root@chenwanting src]# cd mysql-5.7.26
[root@chenwanting mysql-5.7.26]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=1 -DWITH_BOOST=/usr/local/boost
编译
[root@chenwanting mysql-5.7.26]# make && make install
[root@chenwanting mysql-5.7.26]# make clean
设置权限
[root@chenwanting ~]# chown -R mysql:mysql /usr/local/mysql
创建数据存放目录
[root@chenwanting ~]# mkdir /data/mysql_3306
初始化
[root@chenwanting ~]# cd /usr/local/mysql/
[root@chenwanting mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_3306
2019-08-17T06:18:15.076735Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T06:18:15.899899Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T06:18:15.974369Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T06:18:16.034169Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: cc93f9a3-c0b6-11e9-a41d-000c2964923c.
2019-08-17T06:18:16.035554Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T06:18:16.036871Z 1 [Note] A temporary password is generated for root@localhost: 3!Yghq=hXGwM
注意:
这里的初始密码为随机,记录下初始密码下面会用到。
修改配置文件
#复制启动文件
[root@chenwanting ~]# cd /usr/local/mysql/support-files/
[root@chenwanting support-files]# cp mysql.server /etc/init.d/mysqld
[root@chenwanting support-files]# chmod 755 /etc/init.d/mysqld
#修改文件存放路径
[root@chenwanting ~]# vim /etc/init.d/mysqld
basedir= /usr/local/mysql/
datadir= /data/mysql_3306
#修改mysql配置项
[root@chenwanting ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir=/data/mysql_3306
socket=/tmp/mysql.sock
user = mysql
tmpdir = /data/mysql_3306
symbolic-links=0
[mysqld_safe]
log-error=/data/mysql_3306/error.log
pid-file=/data/mysql_3306/mysql.pid
#启动mysql
[root@chenwanting ~]# service mysqld start
Starting MySQL SUCCESS!
[root@chenwanting ~]# ps -ef |grep mysql
root 75157 1 0 15:02 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql_3306 --pid-file=/data/mysql_3306/chenwanting.pid
mysql 75355 75157 0 15:02 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql_3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql_3306/error.log --pid-file=/data/mysql_3306/chenwanting.pid --socket=/data/mysql_3306/mysql.sock
root 76060 57640 0 15:07 pts/2 00:00:00 grep --color=auto mysql
修改密码
[root@chenwanting ~]# mysql -uroot -p
Enter password:
#这里使用的是之前的初始密码
#修改密码
mysql> set password = password('chen123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#使用新密码登入
[root@chenwanting ~]# mysql -uroot -pchen123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>