MySQL MariaDB

How to Restart MySQL in Ubuntu

MySQL is an RDMS (Relational Database Management System), which is used in the back-end development of any website, to store its data and the data is stored in the form of rows and columns, which are combined to form tables. With the help of MySQL, one can not only store data, but also can insert it, delete it, or modify it in tables, and to improve the performance of the system MySQL needs to be restarted. In this article, we will learn how to restart MySQL in Ubuntu by running simple commands.

How to validate the installation of MySQL in Ubuntu

Before restarting, MySQL first confirmed that MySQL is installed in Ubuntu or not. To verify this, we will run the command to check the version of MySQL:

$ sudo mysql --version

The output is displaying the version details of MySQL which mean MySQL has been installed in Ubuntu.

How to restart MySQL using the systemctl command in Ubuntu

The systemctl command is used to start, restart, and stop the applications in Ubuntu and it is also used to check the status of applications. To restart MySQL, using the systemctl command:

$ sudo systemctl restart mysql

Though successful execution of the above command without generating any error is the indication that MySQL has been restarted, we can confirm it by checking its status again using the systemctl command:

$ sudo systemctl STATUS mysql

How to restart MySQL using the service command in Ubuntu

Likewise the systemctl command, the service command can also be used to manage the different applications to start, stop and restart. To restart MySQL in Ubuntu using the service command:

$ service mysqld restart

Once the command is executed, it will ask for the password for authentication purposes:

Type password, and click on Authenticate to proceed with the command. To confirm the successful execution of the above command, check the status of MySQL using the service command:

$ service mysql STATUS

How to restart MySQL through init.d process in Ubuntu

Similar to the service and systemctl command, we can start, stop, and restart the applications by using the init.d command with the path of MySQL in Ubuntu. Before restarting the MySQL let us understand what is init.d?

There are many other services like ssh, MongoDB, etc whose scripts are located in this directory. When Linux is started, it’s the first process that initialized in Ubuntu is init.d, later on, other services start using init.d Now using the extension of “.d” with the path of a directory, which is stands for daemon, we can run these services and also supervise the processes. To restart MySQL in Ubuntu using the init.d:

$ sudo /etc/init.d/mysql restart


Though from the output, it is being obvious the MySQL has been restarted but to confirm this by checking its status, run the command:

$ sudo /etc/init.d/mysql STATUS

Conclusion

In MySQL after making changes in any configuration file, it is recommended to restart the MySQL, so modified changes can be implemented. To restart the MySQL in Ubuntu is not very tough, one has to simply run some simple commands in the terminal.

This article is related to the methods of the restart of MySQL in Ubuntu, three methods are discussed by using the systemctl command, by using the service command, or by using the init.d command. It is not recommended to restart the MySQL regularly because it removes the cache memory while restarting, and also engines have to wait until it starts again, as a result, it decreases the performance.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.