systemctl 配置mysql 开机启动

 

在centos 7 环境下对服务的管理已经不再用service 命令了,而是改为systemctl 命令来管理服务.

一、创建systemctl 的对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

 

二、配置开机启动

[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      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

 

---

posted on 2017-06-02 10:35  蒋乐兴的技术随笔  阅读(12558)  评论(0编辑  收藏  举报

导航