Youtube, Facebook, twitter and most web hosting providers are using MySQL. As an open source freely available (RDBMS) Relational Database Management System, MySQL is an essential component of almost every open PHP application. Joomla, Magento, WordPress and Drupal are are all relying on the reliability and robustness of MySQL to handle and process large numbers of complex SQL statements. Your website is most likely managed in the background by MySQL.
In this article, we will describe the installation steps of MySQL in Ubuntu 18.04 using both the apt command and the Ubuntu official repos.
In the following sections, you will learn how to install MySQL using the Ubuntu terminal and how to configure its related security settings.
To install the most recent version of a software from the available repositories, you you would need to update your local repository index. To do so , run the following command:
sudo apt-get update
To install MySQL from the APT repositories, run the following command:
sudo apt-get install mysql-server [install mysql ubuntu 18.04]
Install mysql on Ubuntu
Once the installation is finished, MySQL service will launch automatically. In order to check that MySQL server is running, type in the command:
sudo systemctl status mysql
To verify the version of MySQL installation, execute the following command :
Some default settings would have to be changed each time a fresh copy of MySQL is installed so that the security of your MySQL installation is enhanced. This includes the suppression of test users, test databases and permissions.
To run the security script, run the following command :
After you run this command, you will be asked first to setup the Validate Password plugin. This is to set a strong password for root user. Once you hit Y to run the Validate Password Plugin, you will obtain the following prompt:
Go ahead and provide your selection for password strength and press Enter. You will then be asked for the new root password.
The system will then show the password strength that you entered. Hit Y for the next prompt and then press Enter.
You will now be presented with a series of questions, one at a time.
if you want to remove anonymous test users, press Y.
To ensure that someone cannot guess the root password from a remote system, you would have to press Y to the next question.
In the next question go ahead and remove the default MySQL database with the name “test” from your current system and remove the access to it.
For the changes made so far to take effect, the system has to reload the privilege tables. To commit all your security changes, hit Y.
1 – Visit the download page of the official MySQL website.
2 – Right click on the last statement shown above, “No thanks, just start my download’ and choose Copy link location.
3 – Once you have the download link to the deb package, run the command below :
The link show above might be different for you depending on the current version of MySQL. You simply have to replace the name of the download in the link above with the one you obtained in the previous step.
3- Let’s now use dpkg to start the installation of MySQL:
sudo dpkg -i mysql-apt-config*
4 – Now to update the repositories, run the command :
sudo apt update
5 – In order to install MySQL, run the command that we used previously:
sudo apt install mysql-server -y
This will launch a prompt in your terminal related to package configuration.
6 – Use the down key to choose the Ok option.
Hit Enter key. You will be asked to provide a password. This is to set the root password for MySQL which is not to be confused with your Ubuntu root password.
Enter a password and hit Tab to select <Ok>. Hit Enter. You’ll need to enter the password again.
As shown above, you will be presented with some detailed information on MySQL Server configuration. Now hit Tab to select <Ok> and press Enter again:
In this step, you would need to select a default authentication plugin. Go ahead and choose ‘Use Strong Password Encryption’. Click on Tab and then hit Enter.
You have now successfully installed MySQL using Ubuntu official repositories.
Once MySQL is installed on your system, the mysql.service should be up and running automatically. To check this , run the command below :
sudo systemctl status mysql.service
If this is not your case,, .i.e. the service is not active or running, execute the following command in order to start it:
sudo systemctl start mysql.service
To stop the mysql service, type in the command :
sudo systemctl stop mysql
To uninstall MySQL, you would first need to disable the service by running the command:
sudo systemctl stop mysql.service && sudo systemctl disable mysql.service
Uninstall mysql on Ubuntu : Disabling service
In case you set out to re-use your databases, make sure to back them up beforehand.
To uninstall MySQL issue the command:
sudo apt purge mysql*
To clean up potential hanging dependencies:
sudo apt autoremove
In this article, you have seen how to install MySQL in Ubuntu using two methods: the apt command and Ubuntu official repos.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.