实现数据库服务多实例被systemd管理
01 编写服务启动配置文件
首先,参考正常MySQL数据库服务启动的systemd配置文件信息:
# 查看默认数据库服务启动文件信息
vim /etc/systemd/system/mysqld.service
[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
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=5000
其次,可以根据默认的MySQL数据库服务启动文件,编写多实例启动文件
# 编写数据库3307端口实例服务启动文件
vim /etc/systemd/system/mysqld3307.service
[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
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
LimitNOFILE=5000
# 编写数据库3308端口实例服务启动文件
vim /etc/systemd/system/mysqld3308.service
[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
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
LimitNOFILE=5000
# 编写数据库3309端口实例服务启动文件
vim /etc/systemd/system/mysqld3308.service
[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
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
LimitNOFILE=5000
02 加载服务启动配置文件
systemctl daemon-reload
# 启动数据库多实例服务
systemctl start mysqld3307
systemctl start mysqld3308
systemctl start mysqld3308
检查多实例运行状态
ss -lntp|grep mysql
停止数据库多实例服务
systemctl stop mysqld3307
systemctl stop mysqld3308
systemctl stop mysqld3308
检查多实例运行状态
ss -lntp|grep mysql
登录:
mysql -uroot -S /tmp/mysql3356.sock