systemctl中添加mysql服务

时间:2024-10-17 21:03:56

由于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 -- :: CST; 44s ago
Main PID: (mysqld)
CGroup: /system.slice/mysqld.service
└─ /mysqldb/base/bin/mysqld --defaults-file=/mysqldb/config/my.cnf --basedir=/mysqldb/base --datadir=/mysqldb/data --plugi... Nov :: n4 systemd[]: Started MySQL Community Server.
Nov :: n4 systemd[]: Starting MySQL Community Server...