在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
- 啟動與關閉服務
- linux 下啟動服務Linux
- Linux下chkconfig命令詳解即新增服務以及兩種方式啟動關閉系統服務Linux
- systemctl 命令在 Linux 中啟動、停止和重新啟動服務Linux
- Linux平臺下snmp服務的安裝和配置Linux
- MySQL啟動和關閉命令總結MySql
- Linux下的MongoDB安裝&啟動&關閉LinuxMongoDB
- 在linux中無法啟動mysqld 服務LinuxMySql
- 在Linux中,如何啟動、停止或重啟服務?Linux
- Linux MySQL 服務設定開機自啟動LinuxMySql
- linux後臺執行和關閉、檢視後臺任務Linux
- 3 啟動和關閉
- linux關閉防火牆命令 linux防火牆關閉和開啟命令Linux防火牆
- 在Linux中,如何管理服務的自啟動?Linux
- centos下nginx啟動、重啟、關閉CentOSNginx
- 在win10上管理JavaWeb後臺專案的啟動和關閉Win10JavaWeb
- 在資料庫繁忙時如何快速有效的關閉MySQL服務資料庫MySql
- oracle資料庫的啟動關閉與各種服務Oracle資料庫
- LInux下檢視和關閉程式Linux
- Ubuntu關閉(重啟)網路服務命令Ubuntu
- springboot在lunix後臺啟動,退出賬號也不關閉Spring Boot
- linux停止和檢視啟動服務的命令Linux
- 控制linux啟動的服務Linux
- Linux使用Ambari啟動服務啟動失敗Linux
- mysql 開啟和關閉日誌記錄MySql
- windows下啟動nacos服務Windows
- MySQL服務名無效或者MySQL正在啟動 MySQL無法啟動MySql
- 大家信夫:閉環商務信用體系服務平臺
- linux 下redis關閉LinuxRedis
- 在Linux中,如何讓某個服務(假如服務名為 nginx)只在3,5兩個運⾏級別開啟,其他級別關閉?LinuxNginx
- Kali Linux常用服務配置教程啟動DHCP服務Linux
- 在linux下啟動tomcat命令LinuxTomcat
- Linux下命令列開啟關閉觸控板Linux命令列
- java -jar 在後臺執行和關閉JavaJAR
- 如何在cmd視窗關閉情況下保持後臺啟動docsify?
- linux系統下Apache服務啟動時80埠報錯LinuxApache
- Window下啟動/停止Zookeeper服務
- Oracle 11gR2 RAC 叢集服務啟動與關閉總結Oracle