How to restart MySQL server?

Restart the MySQL Server with the help of restart command.

The syntax is as follows


Let us first check the MySQL version.

The query is as follows

SELECT version();

Now, implement the above command in order to restart the MySQL Server.

The query is as follows

mysql> restart;
Query OK, 0 rows affected (0.00 sec)

Case 1

Now, MySQL Server is being restarted. If you try to perform any query during the restart command, you will get an error.

The query is as follows

mysql> show databases;
ERROR 2013 (HY000): Lost connection to MySQL server during query

Case 2

If the MySQL restart process is complete, then a new connection id will be assigned to MySQL.

The query is as follows

mysql> select version();

The following is the output

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 8
Current database: sample
| version() |
| 8.0.12    |
1 row in set (0.05 sec)

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started