由于mysql的版本更新,许多术语有了新含义,所以需要特别指出,mysqld.service 等价于mysqld
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
[Service]
# 启动服务
User=mysql
Group=mysql
ExecStart=/mysqldb/base/bin/mysqld --defaults-file=/mysqldb/config/my.cnf --basedir=/mysqldb/base --datadir=/mysqldb/data --plugin-dir=/mysqldb/base/lib/plugin --user=mysql --log-error=/mysqldb/log/mysql.err --open-files-limit=65000 --pid-file=/mysqldb/home/mysql.pid --socket=/mysqldb/home/mysql.sock --port=3306
#根据自己配置,编写启动命令
ExecStop=mysqldb/base/bin/mysqladmin shutdown -p123456
#根据自己配置,编写关闭命令
LimitNOFILE = 5000
保存退出后,重载systemctl;
systemctl daemon-reload
然后就可以使用熟悉的启动命令了
# systemctl start mysqld
再查看下结果
[root@n4 ~]# systemctl status mysqld
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-11-27 17:42:33 CST; 44s ago
Main PID: 28742 (mysqld)
CGroup: /system.slice/mysqld.service
└─28742 /mysqldb/base/bin/mysqld --defaults-file=/mysqldb/config/my.cnf --basedir=/mysqldb/base --datadir=/mysqldb/data --plugi...
Nov 27 17:42:33 n4 systemd[1]: Started MySQL Community Server.
Nov 27 17:42:33 n4 systemd[1]: Starting MySQL Community Server...