MySQL 5.7 单节点
服务器IP | 主机角色 |
---|---|
192.168.10.2 | MySQL Server |
MySQL Server
-
下载 mysql 安装包
- 服务器支持访问互联网
- 服务器不支持访问互联网
wget http://pdpublic.mingdao.com/private-deployment/offline/common/mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
# mysql 安装包文件下载链接,下载完成后上传到部署服务器
http://pdpublic.mingdao.com/private-deployment/offline/common/mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz -
解压至安装目录
tar -zxvf mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.42-linux-glibc2.12-x86_64 /usr/local/mysql -
创建 mysql 用户
useradd -U -M -s /sbin/nologin mysql
-
创建数据、日志目录并授予权限
mkdir -p /data/mysql/ /data/logs/mysql
chown -R mysql:mysql /usr/local/mysql/ /data/mysql/ /data/logs -
配置 systemd 管理文件
cat > /etc/systemd/system/mysql.service <<EOF
[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
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/usr/local/mysql/mysqld.pid
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --log-error=/data/logs/mysql/mysqld.log --datadir=/data/mysql --socket=/usr/local/mysql/mysql.sock --character-set-server=utf8 --pid-file=/usr/local/mysql/mysqld.pid --server-id=1 --log-bin=mysql-bin --max_connections=2000 --slow_query_log=1 --slow_query_log_file=/data/logs/mysql/mysql-slow.log
LimitNOFILE=102400
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
[Install]
WantedBy=multi-user.target
EOF -
初始化
/usr/local/mysql/bin/mysqld --initialize --datadir=/data/mysql/ --user=mysql --log-error=/data/logs/mysql/mysqld.log
-
启动 mysql 并加入开机自启动
systemctl daemon-reload
systemctl enable mysql
systemctl start mysql -
修改 mysql 密码
/usr/local/mysql/bin/mysql -h127.0.0.1 -uroot -p$(grep 'temporary password' /data/logs/mysql/mysqld.log | awk '{print $NF}')
set PASSWORD = PASSWORD('123456');
GRANT ALL ON *.* to root@'%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
quit;- 命令中修改的 root 用户密码为
123456
,实际部署时注意替换
- 命令中修改的 root 用户密码为