设为首页 加入收藏

TOP

CentOS 7上配置MySQL5.7开机自启动方法
2017-10-30 06:07:17 】 浏览:1020
Tags:CentOS 配置 MySQL5.7 开机 启动 方法

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)



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>


设置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


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用Percona XtraBackup进行MySQL.. 下一篇Linux下MongoDB单节点安装方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目