在Linux平臺下啟動和關閉MySQL服務
首先需要檢視下載MySQL服務的狀態
[root@localhost bin]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2482/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1071/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2289/master
tcp6 0 0 :::3306 :::* LISTEN 52044/mysqld
命令列方式啟動和關閉
現在MySQL服務處於啟動中,執行下列命令進行關閉操作。
[root@localhost bin]# ./mysqladmin -uroot -p shutdown
Enter password:
171215 09:11:29 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+ 完成 ./mysqld_safe
[root@localhost bin]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2482/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1071/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2289/master
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1071/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1084/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 2289/master
udp 0 0 192.168.122.1:53 0.0.0.0:* 2482/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 2482/dnsmasq
udp 0 0 127.0.0.1:323 0.0.0.0:* 708/chronyd
udp 0 0 0.0.0.0:37653 0.0.0.0:* 705/avahi-daemon: r
udp 0 0 0.0.0.0:5353 0.0.0.0:* 705/avahi-daemon: r
udp6 0 0 ::1:323 :::* 708/chronyd
raw6 0 0 :::58 :::* 7 800/NetworkManager
可以發現MySQL服務已經被關閉。然後執行下列命令來啟動服務。
[root@localhost bin]# ./mysqld_safe &
[1] 51836
[root@localhost bin]# 171215 09:19:05 mysqld_safe Logging to '/var/log/mysqld.log'.
171215 09:19:05 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost bin]# clear
[root@localhost bin]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2482/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1071/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2289/master
tcp6 0 0 :::3306 :::* LISTEN 52044/mysqld
[root@localhost bin]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@localhost bin]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2482/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1071/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2289/master
tcp6 0 0 :::3306 :::* LISTEN 52044/mysqld
最後再執行命令將MySQL服務關閉,我使用中發現一個問題,就是服務方式開啟貌似必須用服務方式關閉。
服務方式啟動和關閉
通過服務先開啟MySQL服務
[root@localhost bin]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@localhost bin]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2482/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1071/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2289/master
tcp6 0 0 :::3306 :::* LISTEN 56017/mysqld
看見MySQL的服務了,再通過服務的方式來關閉服務。
[root@localhost bin]# service mysql stop
Redirecting to /bin/systemctl stop mysql.service
[root@localhost bin]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2482/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1071/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2289/master
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1071/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1084/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 2289/master
udp 0 0 192.168.122.1:53 0.0.0.0:* 2482/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 2482/dnsmasq
udp 0 0 127.0.0.1:323 0.0.0.0:* 708/chronyd
udp 0 0 0.0.0.0:37653 0.0.0.0:* 705/avahi-daemon: r
udp 0 0 0.0.0.0:5353 0.0.0.0:* 705/avahi-daemon: r
udp6 0 0 ::1:323 :::* 708/chronyd
raw6 0 0 :::58 :::* 7 800/NetworkManager
命令和服務方式的區別
啟動一些程式服務的時候,有時候直接去程式的bin目錄下去執行命令,有時候利用service啟動。比如啟動mysql服務時,大部分喜歡執行service mysql start。當然也可以去mysql下執行bin命令帶上幾個引數什麼的。linux可以man一下,看出來就是去/etc/init.d下執行了可執行的shell指令碼。service執行的服務指令碼都是在/etc/init.d目錄下,各個程式下指令碼里執行的命令仍然是在各個bin下。
相關文章
- 在 Windows 平臺下安裝與配置 MySQL 5.7.36之啟動與關閉MySQL服務WindowsMySql
- MySQL Windows下關閉和啟動MySqlWindows
- 在linux下使用dbstart和dbshut啟動和關閉db!Linux
- 在Windows平臺下修改Oracle例項不隨服務啟動WindowsOracle
- 在linux上關閉不必要的服務加快啟動時間Linux
- mysql的啟動和關閉MySql
- linux 下啟動服務Linux
- MySQL服務開啟關閉及登陸- 2MySql
- linux svn啟動和關閉Linux
- Ubuntu 下啟動/停止/重啟mysql服務UbuntuMySql
- Linux平臺下snmp服務的安裝和配置Linux
- Linux 下 Oracle隨系統自動啟動和關閉LinuxOracle
- MySQL啟動和關閉命令總結MySql
- Linux下chkconfig命令詳解即新增服務以及兩種方式啟動關閉系統服務Linux
- linux下開機使用dbstart和dbshut自動啟動和關閉db!Linux
- LINUX下開機使用dbstart和dbshut自動啟動和關閉dbLinux
- MySQL 多例項啟動和關閉指令碼MySql指令碼
- Linux下關閉和開啟防火牆Linux防火牆
- Linux系統下Oracle服務關閉問題LinuxOracle
- oracle啟動和關閉指令碼for LinuxOracle指令碼Linux
- Linux下的MongoDB安裝&啟動&關閉LinuxMongoDB
- mysql啟動和關閉外來鍵約束MySql
- windows下mysql的安裝於使用(啟動、關閉)WindowsMySql
- 在linux中無法啟動mysqld 服務LinuxMySql
- 【MySql】開機自動啟動mysql服務MySql
- centos下nginx啟動、重啟、關閉CentOSNginx
- oracle資料庫的啟動關閉與各種服務Oracle資料庫
- windows平臺下配置cron服務Windows
- 在win10上管理JavaWeb後臺專案的啟動和關閉Win10JavaWeb
- Ubuntu關閉(重啟)網路服務命令Ubuntu
- Linux平臺Oracle 11g DataGuard Physical Standby 非正常關閉後的啟動LinuxOracle
- 在資料庫繁忙時如何快速有效的關閉MySQL服務資料庫MySql
- linux平臺下監聽器和Oracle的自動啟動與停止LinuxOracle
- linux後臺執行和關閉、檢視後臺任務Linux
- windows下啟動nacos服務Windows
- mysql啟動與關閉(手動與自動)MySql
- Linux平臺下oracle設定開機啟動LinuxOracle
- 大家信夫:閉環商務信用體系服務平臺