安装

1.初始化
tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql
useradd -s /sbin/nologin mysql
mkdir -p /opt/mysql/data
chown -R mysql:mysql /opt/mysql
cd /opt/mysql
bin/mysqld --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --initialize

#此处记住root密码

2.准备启动脚本
cp support-files/mysql.server ./
vim mysql.server
...
 basedir=/opt/mysql
 datadir=/opt/mysql/data
...

3.配置文件
cat <<EOF>> /opt/mysql/my.cnf
[mysqld]
user = mysql
basedir = /opt/mysql
datadir = /mysq/data
socket= /tmp/mysql.sock
log-error = /opt/mysql/error.log
pid-file = /opt/mysql/mysql.pid
EOF

3.清理干扰配置文件
mv /etc/my.cnf /tmp 
chown -R mysql:mysql /opt/mysql

4.启动
/opt/mysql/mysql.server start

MySQL systemd 配置文件

[Unit]
Description=MySQL Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
[Service]
User=root
Group=root
ExecStart=/data/mysql-server/mysql.server start
ExecStop=/data/mysql-server/mysql.server stop
PIDFile=/data/mysql-server/mysql.pid
Restart=always
PermissionsStartOnly=false
LimitNOFILE=5000

results matching ""

    No results matching ""