0
0
MysqlHow-ToBeginner · 3 min read

How to Stop MySQL Server Safely and Quickly

To stop the MySQL server, use the mysqladmin shutdown command or the system service commands like systemctl stop mysql on Linux. On Windows, you can stop the MySQL service via the Services app or by running net stop mysql in the command prompt.
📐

Syntax

There are several ways to stop the MySQL server depending on your operating system and setup:

  • Using mysqladmin: mysqladmin -u root -p shutdown stops the server by authenticating as root.
  • Using systemctl (Linux): sudo systemctl stop mysql stops the MySQL service managed by systemd.
  • Using service command (Linux): sudo service mysql stop stops the MySQL service on older Linux systems.
  • Using Windows command prompt: net stop mysql stops the MySQL service.
bash
mysqladmin -u root -p shutdown
sudo systemctl stop mysql
sudo service mysql stop
net stop mysql
💻

Example

This example shows how to stop the MySQL server using mysqladmin on a Linux or macOS terminal. You will be prompted for the root password.

bash
mysqladmin -u root -p shutdown
Output
Enter password: ******** Server shutdown completed
⚠️

Common Pitfalls

Common mistakes when stopping MySQL server include:

  • Not running the command with sufficient privileges (use sudo if needed).
  • Using incorrect service names (some systems use mysqld instead of mysql).
  • Forgetting to provide the root password when using mysqladmin.
  • Trying to stop MySQL without proper permissions, causing the command to fail silently.
bash
Wrong: sudo systemctl stop mysql
Right: sudo systemctl stop mysqld
📊

Quick Reference

CommandDescriptionPlatform
mysqladmin -u root -p shutdownStops MySQL server with root authenticationLinux/macOS/Windows (with mysqladmin)
sudo systemctl stop mysqlStops MySQL service using systemdLinux (systemd-based)
sudo service mysql stopStops MySQL service using service commandLinux (older systems)
net stop mysqlStops MySQL serviceWindows

Key Takeaways

Use mysqladmin shutdown with root credentials to stop MySQL safely.
On Linux, prefer sudo systemctl stop mysql for systemd-managed services.
Windows users can stop MySQL via net stop mysql or Services app.
Always ensure you have proper permissions to stop the MySQL server.
Check your system's service name if the stop command fails.