1.清理环境
①关闭防火墙和selinux
$ sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config
$ setenforce 0
$ systemctl stop firewalld
$ systemctl disable firewalld.service
②清理已安装的数据库
$ rpm -qa |grep mysql
$ yum remove mysql*
$ rpm -qa |grep mariadb
$ yum remove mariadb*
2.下载二进制包
3.安装MySQL5.7
①解压并安装依赖
$ mkdir -p /opt/src && cd /opt/src
$ rz mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
$ tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
$ mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql-5.7.26
# 创建软连接便于数据库升级
$ ln -s /opt/src/mysql-5.7.26 /usr/local/mysql
# 安装依赖
$ yum install -y libaio*
②初始化并设置环境变量
$ cd /usr/local/mysql
$ useradd -s /sbin/nologin mysql
$ mkdir -p /data/mysql
$ chown mysql.mysql /data/mysql -R
# 初始化并生成默认密码
$ ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql
[Note] A temporary password is generated for root@localhost: =aCHc<qQz9wu
# 检查初始化是否成功
$ echo $?
# 设置环境变量
$ echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
$ source /etc/profile
③配置MySQL
$ vim /etc/my.cnf
basedir = /usr/local/mysql
port=3306
datadir = /data/mysql
socket = /tmp/mysql.sock
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535
default_storage_engine = InnoDB
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
innodb_buffer_pool_size = 512M
innodb_log_file_size = 1024M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 64M
log-bin = /data/mysql/mysql-bin
binlog_format = mixed
expire_logs_days = 10
slow_query_log = 1
slow_query_log_file = /data/mysql/slow_query.log
long_query_time = 1
server-id=1
[mysqld_safe]
log-error=/data/mysql/mysql_error.log
pid-file=/data/mysql/mysql.pid
④将MySQL添加到系统服务
$ cp support-files/mysql.server /etc/init.d/mysqld
$ vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
⑤启动服务
$ /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/mysql_error.log'.
SUCCESS!
⑥修改root密码
使用初始化密码登录
$ mysql -uroot -p
>set password=password("oldboy123");
>exit # 退出使用新密码登录