在centos 7 环境下对服务的管理已经不再用service 命令了,而是改为systemctl 命令来管理服务.
一、创建systemctl 的对mysql服务的配置文件:
touch /usr/lib/systemd/system/mysql.service# 注意systemctl 中规定、服务的配置文件要以.service 为后缀
[Unit]Description=MySQL ServerDocumentation=man:mysqld(8)Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlPIDFile=/usr/local/mysql/data/mysqld.pid# Disable service start and stop timeout logic of systemd for mysqld service.TimeoutSec=0# Execute pre and post scripts as rootPermissionsStartOnly=true# Needed to create system tables#ExecStartPre=/usr/bin/mysqld_pre_systemd# Start main serviceExecStart=/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_limitLimitNOFILE = 5000Restart=on-failureRestartPreventExitStatus=1PrivateTmp=false
二、配置开机启动:
[root@workstudio system]# systemctl enable mysqlCreated 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 mysqlmysql 8910 1 10 10:33 ? 00:00:00 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/data/mysqld.pidroot 8950 8625 0 10:33 pts/3 00:00:00 grep --color=auto mysql
---