先送上官方爸爸配置文档
相信很多小伙伴懒得看,那么往下看吧
1.使用下面命令配置mysql.service文件(文件不存在会自动创建)
vim /etc/systemd/system/mysqld.service #会自动生成新文件
2.复制粘贴
[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
# Have mysqld write its state to the systemd notify socket
Type=forking
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Start main service
ExecStart=/opt/mysql5.7/bin/mysqld --daemonize --pid-file=/opt/data/mysql/mysql.pid $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
# Set environment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
完了记得wq保存,然后source /etc/systemd/system/mysqld.service刷新一下
source /etc/systemd/system/mysqld.service #刷新配置文件
3.使用systemctl启动mysql
systemctl start mysqld #启动mysql
systemctl status mysqld.service #查看mysql状态
QAQ:有问题留言,看到必回