在centos 7 環境下對服務的管理已經再也不用service 命令了,而是改成systemctl 命令來管理服務.html
1、建立systemctl 的對mysql服務的配置文件:mysql
touch /usr/lib/systemd/system/mysql.service # 注意systemctl 中規定、服務的配置文件要以.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 PIDFile=/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 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 = 5000 Restart=on-failure RestartPreventExitStatus=1 PrivateTmp=false
2、配置開機啓動:sql
[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]#
3、啓動mysql服務:centos
[root@workstudio system]# systemctl start mysql [root@workstudio system]# [root@workstudio system]# ps -ef | grep mysql mysql 8910 1 10 10:33 ? 00:00:00 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid root 8950 8625 0 10:33 pts/3 00:00:00 grep --color=auto mysql
---post