📜  mysql restart ubuntu - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:33:01.845000             🧑  作者: Mango

介绍:如何在Ubuntu上重启MySQL服务

在日常的开发中,我们难免会因为各种原因需要重启MySQL服务。本文将介绍Ubuntu系统下如何重启MySQL服务。

步骤
1. 查看MySQL服务状态

在重启之前,我们需要查看MySQL的状态是否正常,可以使用以下命令:

sudo service mysql status

如果MySQL正在运行,那么将会看到如下信息:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-02-06 18:15:19 EST; 3 months 10 days ago
 Main PID: 933 (mysqld)
   CGroup: /system.slice/mysql.service
           └─933 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

如果MySQL没有运行,那么将会看到如下信息:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2020-02-06 18:15:36 EST; 3 months 10 days ago
  Process: 31032 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 0 (code=exited, status=0/SUCCESS)
   Status: "Server startup in progress"

Feb 06 18:15:36 ubuntu systemd[1]: Starting MySQL Community Server...
Feb 06 18:15:36 ubuntu mysql-systemd-start[31032]: MySQL pre-start process (31032) started...
Feb 06 18:15:36 ubuntu mysql-systemd-start[31032]: MySQL is downloading required data
Feb 06 18:15:36 ubuntu mysql-systemd-start[31032]: MySQL failed to start. Please check mysqld.log for further information.
Feb 06 18:15:36 ubuntu systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Feb 06 18:15:36 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 06 18:15:36 ubuntu systemd[1]: Failed to start MySQL Community Server.
2. 关闭MySQL服务

在重启之前,我们需要先关闭MySQL服务。可以使用以下命令:

sudo service mysql stop
3. 重启MySQL服务

使用以下命令重启MySQL服务:

sudo service mysql start
4. 重新查看MySQL服务状态

使用以下命令重新查看MySQL服务状态:

sudo service mysql status

如果看到如下信息,说明MySQL服务已经成功重启:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-05-14 12:31:11 EDT; 5s ago
  Process: 31322 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
 Main PID: 31323 (mysqld)
   CGroup: /system.slice/mysql.service
           └─31323 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
结论

使用以上步骤,我们可以在Ubuntu系统下轻松重启MySQL服务。