这篇文章主要为大家展示了“centos7上如何配置MySQL5.7的开机自启动”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“centos7上如何配置MysqL5.7的开机自启动”这篇文章吧。
centos7开始使得以往老版本系统服务的/etc/init.d的启动脚本的方式就此改变,在centos7中所有对服务的管理都集中到了systemctl当中。
systemctl是一个系统管理守护进程、工具和库的集合,用于取代以往的System V、service和chkconfig命令。
创建用于启动MysqL的配置文件
[root@localhost ~]# touch /usr/lib/systemd/system/MysqLd.service
[root@localhost ~]# cd /usr/lib/systemd/system
编辑MysqLd.service文件,加入如下内容:
[root@localhost system]# vi MysqLd.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
ExecStart=/opt/MysqL-5.7.18/bin/MysqLd --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
保存退出
备注:ExecStart=/opt/MysqL-5.7.18/bin/MysqLd (此处请对应修改为MysqL程序所在的路径)
查找MysqLd路径,例如:
[root@localhost system]# which MysqLd
/opt/MysqL-5.7.18/bin/MysqLd
通过systemctl方式启动MysqL5.7:
[root@localhost system]# systemctl start MysqLd
检查MysqL运行状态:
[root@localhost system]# MysqL -p
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 6
Server version: 5.7.18-log MysqL Community Server (GPL)
copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MysqL>
MysqL>
MysqL> \s
--------------
MysqL Ver 14.14 distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 6
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.18-log MysqL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/MysqL.sock
Uptime: 45 sec
Threads: 3 Questions: 6 Slow queries: 0 Opens: 108 Flush tables: 1 Open tables: 101 Queries per second avg: 0.133
--------------
MysqL>
关闭防火墙:
[root@localhost system]# systemctl stop firewalld.service
[root@localhost system]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
设置MysqL的开机启动:
[root@localhost system]# systemctl enable MysqLd
Created symlink from /etc/systemd/system/multi-user.target.wants/MysqLd.service to /usr/lib/systemd/system/MysqLd.service.
[root@localhost system]# systemctl list-unit-files | grep MysqLd
MysqLd.service enabled
取消MysqL的开机自启动:
[root@localhost system]# systemctl disable MysqLd
Removed symlink /etc/systemd/system/multi-user.target.wants/MysqLd.service.
[root@localhost system]# systemctl list-unit-files | grep MysqLd
MysqLd.service disabled
以上是“centos7上如何配置MysqL5.7的开机自启动”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程之家行业资讯频道!