Answered by the Webhosting Experts

How to Start, Stop, and Restart MySQL Server

Starting, stopping, and restarting the MySQL server are fundamental administrative tasks that administrators must perform regularly. These actions are necessary when conducting maintenance, troubleshooting issues, or implementing configuration changes. Understanding these operations is critical for maintaining the overall health and performance of the database. In this guide, we will walk you through the essential commands for managing the MySQL service safely across both Linux and Windows operating systems. By following these guidelines, you can ensure that your database remains consistently available and reliable.

Managing the MySQL Service in Linux

Managing the MySQL service in Linux is a routine responsibility for both developers and system administrators. Whether you’re implementing configuration updates or resolving service issues, understanding how to control the service is essential. Proper management helps ensure the database remains stable and responsive during various operational conditions. This section introduces the primary methods used on Linux systems to maintain a reliable MySQL environment.

  • systemctl is used on modern systemd-based Linux distributions for advanced service management.
  • service is a legacy command for older, pre-systemd systems and sometimes a compatibility wrapper.

Important Tips

  • Keep in mind that if mysql fails as a service name you will need try mysqld depending on the distribution.
  • Ensure to check the service status after restarting to confirm it started cleanly.
  • Restarting MySQL will briefly disconnect active connections so keep that in mind.
  • On older systems, service may still call systemctl behind the scenes.

Check Service Status

Use this to verify if MySQL is currently running or if it has encountered an error.

  • Newer Systems: sudo systemctl status mysql
  • Older Systems: sudo service mysql status
sudo systemctl status mysqld
sudo systemctl status mysqld

Restart MySQL

This is the “go-to” fix for applying configuration changes or clearing minor glitches.

  • Newer Systems: sudo systemctl restart mysql
  • Older Systems: sudo service mysql restart
sudo systemctl restart mysqld
sudo systemctl restart mysqld

Stop MySQL

Use this when you need to take the database offline for maintenance or backups.

  • Newer Systems: sudo systemctl stop mysql
  • Older Systems: sudo service mysql stop
sudo systemctl stop mysqld
sudo systemctl stop mysqld

Start MySQL

Use this to bring the service back online after it has been stopped.

  • Newer Systems: sudo systemctl start mysql
  • Older Systems: sudo service mysql start

sudo systemctl start mysqld
sudo systemctl start mysqld

Note: On some Linux distributions, the MySQL service is named mysqld rather than mysql. Because this name often reflects the underlying daemon (Service Agent), you should therefore verify which one your system uses if the initial command fails. In addition, the images provided above demonstrate the specific commands and the expected output within the command line. Consequently, following these visual guides will help you confirm that the service has responded correctly.

Managing the MySQL Service in Windows

Similarly to Linux, managing the MySQL service in Windows is a critical administrative task. In many scenarios, such as routine maintenance or troubleshooting, it is essential to have a thorough understanding of service controls. As a result, by mastering how to manage the service efficiently, you not only simplify administration but also enhance overall system reliability.

Do not confuse MySQL with Microsoft SQL Server (MSSQL). These platforms are distinct despite their shared nomenclature. Consequently, you must utilize specialized tools tailored specifically to each environment. Since the underlying architectures differ, commands used in one system will not work in the other.

Important Tips

  • Always run CMD (Command Prompt) as Administrator to avoid “Access Denied” errors.
  • Confirm the name in services.msc first, otherwise your commands will likely fail.
  • Locate my.ini in the hidden C:\ProgramData folder and ensure “Hidden Items” is enabled.
  • Use the stop command instead of Task Manager to prevent data corruption (Avoid Task Manager to kill this service if you can).
  • Set the service to Automatic, as a result the database remains active after every reboot.

Managing with Command Prompt

In many situations, Windows service names are versioned (for example, MySQL80). Because of this, it is recommended that you first confirm the exact service name. By doing so, you ensure that your commands execute as intended. This reduces the likelihood of errors and prevents unnecessary troubleshooting.

Command Prompt
Command Prompt

List All MySQL Services

Use this to find the exact name of your MySQL service (e.g., MySQL80 or mysql).

Command: sc query | findstr /i mysql

sc query | findstr /i mysql
sc query | findstr /i mysql

Check Specific Service Status

Verify if the MySQL service is “RUNNING” or “STOPPED”. Replace MySQL with your specific service name if it differs.

Command: sc query MySQL

sc query MySQL80
sc query MySQL80

Restart MySQL

Windows doesn’t have a single “restart” command in CMD, so you chain the stop and start commands together.

Command: net stop MySQL && net start MySQL

net stop MySQL80 && net start MySQL80
net stop MySQL80 && net start MySQL80

Stop MySQL Service

Command: net stop MySQLor sc stop MySQL 

Start MySQL Service

Command: net start MySQL or sc start MySQL

Managing with Services.msc (Graphical Interface)

To open the Services utility, start by pressing Windows Key + R, typing services.msc, and hitting Enter. Once the window appears, you can locate the MySQL entry to apply a stop, pause, or restart as necessary.

Services Utility
Services Utility
Managing the MySQL80 Service via the Services Utility
Managing the MySQL80 Service via the Services Utility

— Written by Pascal Suissa

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: support@hivelocity.net. We are also available to you through our phone and live chat system 24/7/365.