Linux平台下启动和关闭mysql服务_在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下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值