MySQL: Start, Stop, Uninstall & Reset Password

As a developer, when working with MySQL, you typically focus on database commands and queries like INSERT INTO, SELECT etc.

You can learn all about MySQL, Postgresql and SQL in general in our SQL - The Practical Guide course!

No prior SQL knowledge is required and you will learn all about the basics, core concepts and also explore lots of advanced concepts!

But some basic database administration knowledge also comes in handy from time to time.

This article explains how to perform some of the most important, common tasks:

#Stopping a running server (Windows)

If you started the MySQL server as a service, you can start and stop it via the Windows services tool. You find more details here.

A running MySQL server can be stopped via the mysqladmin command which was installed on your system automatically. You can find this executable in your installation directory inside the bin folder - for example C:\Program Files\MySQL\MySQL Server 8.0\bin.

You can optionally add the path to this bin directory to your Windows path environment variable (see this tutorial), so that you can access the tools inside this bin folder from anywhere on your system.

If you haven't added the bin path to your environment variable, you have to navigate into that bin folder via your system command prompt.

For example, this is how you could navigate into the installation path mentioned above:

cd "\Program Files\MySQL\MySQL Server 8.0\bin"

Once you navigated into that path, you can run the mysqladmin command which is located there. Stop the running server by executing:

mysqladmin -u root -p shutdown

It will prompt you for your password and shut down the running server once you entered it.

You can then also restart the server if you want to.

#Stopping a running server (macOS)

If you installed MySQL via the official installer, you should have a new entry in your "System Preferences" (at the very bottom of the overview page). If you dive into the "MySQL" option there, you can start and stop the MySQL server via this GUI.

Besides that, you can also stop the MySQL server via the macOS terminal:

sudo /usr/local/mysql/support-files/mysql.server stop

#Stopping a running server (Linux)

To stop a running MySQL server on Linux, you can run the following command:

/etc/init.d/mysqld stop 

Alternatively, you can also stop the running background server service by running:

service mysqld stop 

That's all! You can thereafter restart the server if you want to.

#Starting a server (Windows)

If you want to run the MySQL server as a service, you can start and stop it via the Windows services tool. You find more details here.

A MySQL server can be started via the mysqld command which was installed on your system automatically. You can find this executable in your installation directory inside the bin folder - for example C:\Program Files\MySQL\MySQL Server 8.0\bin.

You can optionally add the path to this bin directory to your Windows path environment variable (see this tutorial), so that you can access the tools inside this bin folder from anywhere on your system.

If you haven't added the bin path to your environment variable, you have to navigate into that bin folder via your system command prompt.

For example, this is how you could navigate into the installation path mentioned above:

cd "\Program Files\MySQL\MySQL Server 8.0\bin"

Once you navigated into that path, you can run the mysqld command which is located there. Start the running server by executing:

mysqld

It will prompt you for your password and start the server once you entered it.

#Starting a server (macOS)

If you installed MySQL via the official installer, you should have a new entry in your "System Preferences" (at the very bottom of the overview page). If you dive into the "MySQL" option there, you can start and stop the MySQL server via this GUI.

Besides that, you can also start the MySQL server via the macOS terminal:

sudo /usr/local/mysql/support-files/mysql.server start

#Starting a server (Linux)

To start a MySQL server on Linux, you can run the following command:

/etc/init.d/mysqld start 

Alternatively, you can also start a running background server service by running:

service mysqld start 

#Uninstalling MySQL (Windows)

To uninstall MySQL on Windows, make sure that your first stop the running server.

Once the server is stopped, you can uninstall MySQL via the Windows "Control Panel". Go to "Programs and Features" and select "MySQL" => "Uninstall".

Thereafter, to clean up any remaining data, make sure you can see hidden folders and then delete the following folders:

  • C:\Program Files\MySQL
  • C:\Program Files (x86)\MySQL
  • C:\ProgramData\MySQL
  • C:\Users\<your-username>\AppData\Roaming\MySQL

#Uninstalling MySQL (macOS)

If you installed MySQL via the official installer, you can uninstall it via the macOS "System Preferences". Go to the "MySQL" option and choose "Uinstall".

You also might want to get rid of all the related data - this article describes how that can be achieved.

#Uninstalling MySQL (Linux)

You find detailed instructions on how to completely remove MySQL on Linux in this Stackoverflow thread.

#Resetting the root user password

Forgot the password of your root database server user? No worries, you can reset it!

This article from the official documentation describes in detail, how you may reset your password on different systems.

#Switching to the legacy password flow

For some clients (e.g. the VS Code SQLTools extension), you need to switch to the "legacy" authentication flow for MySQL.

To do this, you just need to connect to your database server (e.g. via MySQL Workbench) and then run the following command there:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<password>';