How to Restart MySQL: Simple Commands and Tips
To restart
MySQL, use the command sudo systemctl restart mysql on Linux systems with systemd. On Windows, restart the MySQL service via the Services app or use net stop mysql followed by net start mysql in Command Prompt.Syntax
Restarting MySQL depends on your operating system and how MySQL was installed. Here are common commands:
- Linux (systemd):
sudo systemctl restart mysqlrestarts the MySQL service. - Linux (SysVinit):
sudo service mysql restartrestarts the service. - Windows: Use the Services app or run
net stop mysqlthennet start mysqlin Command Prompt.
bash
sudo systemctl restart mysql
Example
This example shows how to restart MySQL on a Linux system using systemd. It stops and then starts the MySQL service to apply any configuration changes or recover from issues.
bash
sudo systemctl restart mysql sudo systemctl status mysql
Output
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-06-20 10:00:00 UTC; 2s ago
Main PID: 1234 (mysqld)
Tasks: 29 (limit: 4915)
Memory: 150.0M
CGroup: /system.slice/mysql.service
└─1234 /usr/sbin/mysqld
Common Pitfalls
Common mistakes when restarting MySQL include:
- Not using
sudoor administrator rights, causing permission errors. - Using the wrong service name (e.g.,
mysqlvsmysqld). - Restarting without checking if MySQL is running, which can cause errors.
- On Windows, forgetting to run Command Prompt as Administrator.
bash
sudo systemctl restart mysqld # Wrong service name on some systems # Correct way: sudo systemctl restart mysql
Quick Reference
| Platform | Command to Restart MySQL |
|---|---|
| Linux (systemd) | sudo systemctl restart mysql |
| Linux (SysVinit) | sudo service mysql restart |
| Windows (Command Prompt) | net stop mysql && net start mysql |
| Windows (Services app) | Restart MySQL service via Services.msc |
Key Takeaways
Use
sudo systemctl restart mysql on modern Linux systems to restart MySQL.On Windows, restart MySQL via Services app or use
net stop mysql and net start mysql in an Administrator Command Prompt.Always check the service name and your permissions before restarting MySQL.
Restarting MySQL applies configuration changes and can fix some service issues.
Avoid common mistakes like wrong service names or missing admin rights.