Restart MySQL Ubuntu

MySQL is a database management system that’s installed as part of LAMP/LEMP stacks. On Ubuntu, the MySQL server is managed by systemd. We’ll cover the necessary steps to stop and start it with systemctl in this article. We’ll also explain what you should do if the MySQL server doesn’t start.

Check MySQL Server Status 

Assuming the MySQL server is already installed, you should first check its current status.

sudo systemctl status mysql

Start/Restart MySQL Server

By default, the server status should be active (running). You can restart the server from this state with

sudo systemctl restart mysql

If the server is inactive (dead), you can start the server instead, although restarting will have the same end result as well.

sudo systemctl start mysql

Stop/Disable MySQL Server

If you need to shut down the MySQL server, you can do so with 

sudo systemctl stop mysql

The MySQL service is configured to start automatically at boot. This means the server will start again when you reboot your machine. If you want, you can change this behavior with

sudo systemctl disable mysql

And in case you want to revert it back to the default behavior in the future, you can set the server to startup at boot with

sudo systemctl enable mysql

Fixing MySQL Server Startup Issues

Older Ubuntu versions used the mysqld unit to manage the MySQL server, but present versions use mysql

If you try to use mysqld out of habit, you’ll get the “failed to start mysqld.service: unit mysqld.service not found” error. Resolving this is super easy; simply use mysql instead as we’ve shown in the earlier sections.

Another common scenario is that the startup fails stating that “the start request repeated too quickly”. This can be resolved by setting the correct permissions for the /var/lib/mysql/ and /var/log/mysql/ directories. 

sudo chown -R mysql:mysql /var/lib/mysql/ /var/log/mysql/ 

Aside from these two cases, you can take a couple of other steps to troubleshoot startup problems. 

First, review the configurations from the /etc/mysql directory. If you made any config changes before the startup issues started, try reverting them.

Next, check the error log at /var/log/mysql/error.log. This should give you some insight into what’s causing the problem.

Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.