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
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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2145999/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle配置開機自啟動Oracle
- Linux開機自啟動配置Linux
- OracleLinux上的Oracle開關機自啟動OracleLinux
- Linux系統上配置redis開機自啟LinuxRedis
- [ubuntu]設定開機自啟動程式的方法Ubuntu
- Linux配置開機自啟動執行指令碼方法有哪些?Linux指令碼
- [Windows][VC]開機自動啟動程式的幾種方法Windows
- 配置 Oracle 11gR2 在 CentOS6 上開機自啟動OracleCentOS
- win10如何禁止autodesk開機自啟_win10禁止autodesk開機自動啟動的方法Win10
- 如何設定win10軟體開機自動啟動 win10軟體開機自動啟動的方法Win10
- Linux中配置開機自啟動執行指令碼的方法是什麼?Linux指令碼
- Linux開機自啟配置Linux
- 配置Nginx/Redis開機自啟NginxRedis
- oracle開機自啟動Oracle
- CentOS 7 - 配置服務實現開機自啟動CentOS
- KVM虛機開機自啟和取消自啟動
- Nginx設定成服務並開機自動啟動的配置詳解Nginx
- win10怎麼設定bat開機自啟動_win10系統新增bat開機自啟動的方法Win10BAT
- windows開機自動啟動oracleWindowsOracle
- WinForm程式開機自動啟動ORM
- Centos7下安裝配置MySQL5.7CentOSMySql
- Linux配置開機自啟動執行指令碼方法有哪些?常見介紹!Linux指令碼
- 在centos7上安裝mysql5.7CentOSMySql
- centos7開機無法自動載入bonding核心模組的解決方法CentOS
- 開機自動啟動ORACLE ON LinuxOracleLinux
- android APP開機自動啟動AndroidAPP
- win10電腦開機自動重啟迴圈怎麼辦_win10開機後自動重啟的解決方法Win10
- Android開機自啟動程式Android
- 開機自啟動Powershell指令碼指令碼
- Linux 新增開機自啟動Linux
- win10開機自啟動程式關閉方法_win10怎麼關閉開機啟動項Win10
- Apache DolphinScheduler如何開啟開機自啟動功能?Apache
- C#程式實現軟體開機自動啟動的兩種常用方法C#
- Windows10 開機自動啟動 VagrantWindows
- nginx 加入到開機自動啟動Nginx
- oracle資料庫開機自動啟動Oracle資料庫
- Linux下開機自動啟動OracleLinuxOracle
- linux開機自動啟動指令碼Linux指令碼