MySQL is an RDMS that runs as a service on operating systems like Linux, Ubuntu, Debian, Windows, etc. As a service, it can be started, stopped, or restarted. If there is a problem or major change in the MySQL database generally a restart is required. Also if there is an unresolved problem or performance problem generally restarting the MySQL database server is the best first step. In this tutorial, we examine how to restart the MySQL database server or service in different operating systems (Linux, Ubuntu, Debian, CentOS, Windows) using different methods.
Check Status of MySQL Database Server In Linux (Ubuntu, Debian, CentOS)
Before restarting the MySQL database server checking its status is beneficial. In Linux, there are a lot of ways to check the status of the MySQL database server whether it is running or stopped. But the most popular and compatible command is
systemctl which can be used to check the status of the MySQL database server or service. The MySQL database service is named as
mysqld for service name.
$ systemctl status mysqld
init.d scripts can be used to check MySQL database service status like below.
$ /etc/init.d/mysql status
Restart MySQL Database Server In Linux (Ubuntu, Debian, CentOS)
systemctl command can be used to restart the MySQL database service. The restart first stops the service and then starts it with a single command. The
systemctl restart command can be used to restart the MySQL database service. The MySQL database service is named as
mysqld which is the short form of “MySQL Daemon”. As restarting a service is an administrative task it requires administrative privileges which can be provided as root or running with sudo command like below.
$ sudo systemctl restart mysqld
sudo command may requires the password for the current user with the following prompt.
[sudo] password for ismail:
After the restart, the status of the MySQL database service status can be checked if it is started properly.
Check Status of MySQL Database Server In Windows
The status of the MySQL database service can be check-in Windows by using the Services. The Services configuration can be opened via the Windows Run. First, we open the Windows Run with the
WIN+R keyboard shortcuts. Then put
services.msc command into Windows Run and execute it.
In the Services navigate to the
MySQL service which is like below. The status of the service is listed as
Restart MySQL Database Server In Windows
The MySQL database service can be restarted in different ways from command line interface or Services configuration. First the MS-DOS command line interface can be used to restart MySQL database service in Windows.
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqladmin" -u root shutdown "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld"
Alternative way is using the Services which is the official service mangement method for Windows operating systems. First we open the services screen via Windows Run by executing the
services.msc like below.
In the Services configuration screen navigate to the
MySQL service and select it. The
Restart button or text can be used to restart MySQL service like below.
Check Status of MySQL Database Server In MacOSX
The MySQL database service or server status can be checked in MacOSX operating systems similar to the Linux operating system. If the installed version of the MySQL database server is older than 5.7 the following instructions can be used to check MySQL service status via the command-line interface.
$ sudo /usr/local/mysql/support-files/mysql.server status
If the installed MySQL database service version is higher then 5.7 the following commands can be used to check status.
sudo launchctl status -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Restart MySQL Database Server In MacOSX
The MySQL database service can be restarted using the following commands in MacOSX operating system.
sudo /usr/local/mysql/support-files/mysql.server restart