linux mysql关闭启动不了了,在Linux平台下启动和关闭MySQL服务

本文详细介绍了如何在Linux环境下手动启动和停止MySQL服务的方法。包括使用命令行方式启动和关闭MySQL服务的过程,以及通过服务方式启动和关闭MySQL服务的具体步骤。

首先需要查看下载MySQL服务的状态

[root@localhost bin]# netstat -nlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemdtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2482/dnsmasqtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1071/sshdtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1084/cupsdtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2289/mastertcp6       0      0 :::3306                 :::*                    LISTEN      52044/mysqld

命令行方式启动和关闭

现在MySQL服务处于启动中,执行下列命令进行关闭操作。

[root@localhost bin]# ./mysqladmin -uroot -p shutdownEnter password:171215 09:11:29 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended[1]+  完成                  ./mysqld_safe[root@localhost bin]# netstat -nlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemdtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2482/dnsmasqtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1071/sshdtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1084/cupsdtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2289/mastertcp6       0      0 :::111                  :::*                    LISTEN      1/systemdtcp6       0      0 :::22                   :::*                    LISTEN      1071/sshdtcp6       0      0 ::1:631                 :::*                    LISTEN      1084/cupsdtcp6       0      0 ::1:25                  :::*                    LISTEN      2289/masterudp        0      0 192.168.122.1:53        0.0.0.0:*                           2482/dnsmasqudp        0      0 0.0.0.0:67              0.0.0.0:*                           2482/dnsmasqudp        0      0 127.0.0.1:323           0.0.0.0:*                           708/chronydudp        0      0 0.0.0.0:37653           0.0.0.0:*                           705/avahi-daemon: rudp        0      0 0.0.0.0:5353            0.0.0.0:*                           705/avahi-daemon: rudp6       0      0 ::1:323                 :::*                                708/chronydraw6       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 -nlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemdtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2482/dnsmasqtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1071/sshdtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1084/cupsdtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2289/mastertcp6       0      0 :::3306                 :::*                    LISTEN      52044/mysqld

[root@localhost bin]# service mysql startRedirecting to /bin/systemctl start  mysql.service[root@localhost bin]# netstat -nlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemdtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2482/dnsmasqtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1071/sshdtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1084/cupsdtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2289/mastertcp6       0      0 :::3306                 :::*                    LISTEN      52044/mysqld

最后再执行命令将MySQL服务关闭,我使用中发现一个问题,就是服务方式打开貌似必须用服务方式关闭。

服务方式启动和关闭

通过服务先打开MySQL服务

[root@localhost bin]# service mysql startRedirecting to /bin/systemctl start  mysql.service[root@localhost bin]# netstat -nlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemdtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2482/dnsmasqtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1071/sshdtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1084/cupsdtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2289/mastertcp6       0      0 :::3306                 :::*                    LISTEN      56017/mysqld

看见MySQL的服务了,再通过服务的方式来关闭服务。

[root@localhost bin]# service mysql stopRedirecting to /bin/systemctl stop  mysql.service[root@localhost bin]# netstat -nlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemdtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2482/dnsmasqtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1071/sshdtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1084/cupsdtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2289/mastertcp6       0      0 :::111                  :::*                    LISTEN      1/systemdtcp6       0      0 :::22                   :::*                    LISTEN      1071/sshdtcp6       0      0 ::1:631                 :::*                    LISTEN      1084/cupsdtcp6       0      0 ::1:25                  :::*                    LISTEN      2289/masterudp        0      0 192.168.122.1:53        0.0.0.0:*                           2482/dnsmasqudp        0      0 0.0.0.0:67              0.0.0.0:*                           2482/dnsmasqudp        0      0 127.0.0.1:323           0.0.0.0:*                           708/chronydudp        0      0 0.0.0.0:37653           0.0.0.0:*                           705/avahi-daemon: rudp        0      0 0.0.0.0:5353            0.0.0.0:*                           705/avahi-daemon: rudp6       0      0 ::1:323                 :::*                                708/chronydraw6       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下。

699ba7046c51816a17b33a7caa85f179.png

0

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值