Managing MySQL services—starting, stopping, and restarting—is a common task in daily database administration. This guide explains the standard commands for different Linux distributions and system management methods.
Starting MySQL Service
Depending on your system's initialization method (SysV init or systemd), use the following commands to start MySQL.
For systemd Systems (e.g., CentOS 7+, Ubuntu 16.04+)
sudo systemctl start mysqld
# or
sudo systemctl start mysql
Note: The service name may be mysqld or mysql, depending on your installation package and distribution.
For SysV init Systems (Legacy Systems)
sudo service mysqld start
# or
sudo /etc/init.d/mysqld start
Stopping MySQL Service
For systemd Systems
sudo systemctl stop mysqld
# or
sudo systemctl stop mysql
For SysV init Systems
sudo service mysqld stop
# or
sudo /etc/init.d/mysqld stop
Using mysqladmin (Universal Method)
mysqladmin -u root -p shutdown
This command prompts for the root user's password and then gracefully shuts down the MySQL service.
Restarting MySQL Service
For systemd Systems
sudo systemctl restart mysqld
# or
sudo systemctl restart mysql
For SysV init Systems
sudo service mysqld restart
# or
sudo /etc/init.d/mysqld restart
Checking MySQL Service Status
After performing an operation, it's recommended to check the service status to confirm success.
For systemd Systems
sudo systemctl status mysqld
For SysV init Systems
sudo service mysqld status
Enabling Automatic Startup on Boot
To have MySQL start automatically when the system boots, enable the service.
For systemd Systems
sudo systemctl enable mysqld
For SysV init Systems
sudo chkconfig mysqld on
# or on Debian/Ubuntu
sudo update-rc.d mysql defaults
Note: The script safe_mysqld mentioned in some older documentation is from very old MySQL versions (pre-5.0). Modern versions use mysqld_safe, which is typically managed by the system service; direct use is not recommended. Also, the path /etc/inint.d/ is a typo; the correct path is /etc/init.d/.