centos7.2 将mysql添加到服务中

手动安装的mysql是不会自动添加到系统服务中的。如果需要配置开机启动,最好是将mysql配置成系统服务,也便于管理。

确定mysql运行时的pid文件位置

1、先去mysql安装目录启动mysql

[root@host01 mysql]# cd /usr/local/mysql/support-files/
[root@host01 support-files]# pwd
/usr/local/mysql/support-files
[root@host01 support-files]# ./mysql.server start
Starting MySQL. SUCCESS! 
[root@host01 support-files]# 

2、查看mysql进程,找到【–pid-file】对应的值,然后可以停掉mysql

[root@host01 support-files]# ps -ef | grep mysql
root       5877      1  0 10:32 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/host01.pid
mysql      6029   5877  1 10:32 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/host01.pid --socket=/var/lib/mysql/mysql.sock
root       6059   3035  0 10:33 pts/0    00:00:00 grep --color=auto mysql
[root@host01 support-files]# 
[root@host01 support-files]# ./mysql.server stop
Shutting down MySQL.. SUCCESS! 
[root@host01 support-files]#

添加mysql服务

1、在/usr/lib/systemd/system目录下创建【mysql.service】内容如下,注意路径可能有变化,根据实际情况写,PIDFile就是上面拿到的路径文件名

[Unit]
Description=Mysql
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/mysql/data/host01.pid
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=false

[Install]
WantedBy=multi-user.target

2、重启systemctl,让mysql.service生效

[root@host01 support-files]# systemctl daemon-reload

3、测试通过service方式启动mysql

[root@host01 support-files]# ps -ef |grep mysql
root       6105   3662  0 10:42 pts/2    00:00:00 grep --color=auto mysql
[root@host01 support-files]# systemctl start mysql
[root@host01 support-files]# ps -ef |grep mysql
root       6119      1  1 10:42 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/host01.pid
mysql      6272   6119 10 10:42 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/host01.pid --socket=/var/lib/mysql/mysql.sock
root       6302   3662  0 10:42 pts/2    00:00:00 grep --color=auto mysql
[root@host01 support-files]# 

4、mysql服务相关命令

将mysql设置为开机启动
systemctl enable mysql
将mysql设置为开机不启动
systemctl disable mysql
启动mysql
systemctl start mysql
关闭mysql
systemctl stop mysql
重启mysql
systemctl restart mysql
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值