在centos 7 环境下对服务的管理已经不再用service 命令了,而是改为systemctl 命令来管理服务.
一、创建systemctl 的对mysql服务的配置文件:
touch /usr/lib/systemd/system/mysql.service
# 注意systemctl 中规定、服务的配置文件要以.service 为后缀
[Unit]
Description=MySQL Server
Documentation=man:mysqld()
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 PIDFile=/usr/local/mysql/data/mysqld.pid # Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec= # Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd # Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid
#注意这里要加上 --daemonize
# Use this to switch malloc implementation
#EnvironmentFile=-/etc/sysconfig/mysql # Sets open_files_limit
LimitNOFILE = Restart=on-failure RestartPreventExitStatus= PrivateTmp=false
二、配置开机启动:
[root@workstudio system]# systemctl enable mysql
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.
[root@workstudio system]#
三、启动mysql服务:
[root@workstudio system]# systemctl start mysql
[root@workstudio system]#
[root@workstudio system]# ps -ef | grep mysql
mysql : ? :: /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid
root : pts/ :: grep --color=auto mysql
---