# 安装依赖
yum install -y ncurses-devel libaio-devel cmake glibc autoconf
# 下载安装包
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
# 解压
tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
# 做软连接
ln -s mysql-5.7.20 mysql
# 创建MySQL用户
useradd -s /sbin/nologin mysql -M
# 初始化系统数据
mkdir /usr/local/mysql-5.7.20/data/
# 加上--initialize参数是开启临时密码、安全策略(密码过期时间)------------(当前使用为无密码、无安全策略)
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql-5.7.20 --datadir=/usr/local/mysql-5.7.20/data
# 授权
chown -R mysql.mysql /usr/local/mysql-5.7.20/
# 修改配置文件
vim /etc/my.cnf
[mysqld]
user=mysql
bind-address=0.0.0.0
basedir=/usr/local/mysql-5.7.20
datadir=/usr/local/mysql-5.7.20/data
socket=/tmp/mysql.sock
server_id=1
[mysql]
socket=/tmp/mysql.sock
# 添加systemd管理启动
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql-5.7.20/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000