How to install MySQL into your VPS (Ubuntu 18.04)
Welcome to Something!
In this guide, you will learn how to install MySQL to your powerful VPS
This guide was created for Ubuntu 18.04 but should work on another Ubuntu flavors.
Need help connecting to your VPS? Check out this tutorial!
- Summary
This tutorial aims to download MySQL and secure it. To do that we need to execute 3 commands. If you need detailed instructions, follow the next part of this guide.
Note! Each line is a command that needs to run separately
$ sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation
- Detailed instructions
1. Installing the MySQL server
The first step we need to do is to make sure our operating system and it's libraries is up-to-date. To do that we need to run the following command
$ sudo apt-get update
Next up we need to install MySQL, to do that we need to run the following command:
$ sudo apt install mysql-server
If you get any prompts asking to restart services, do not be afraid, read the instructions (different per VPS) and select the option you wish to use.
Beware! Your database is not secured yet and will have no password requirements so we need to secure it.
2. Securing the MySQL server
To secure our MySQL database and finish the setup sequence we need to run the following command
$ sudo mysql_secure_installation
The command / script mysql_secure_installation will go through a series of questions that you can answer as you wish.
3. Setting up the password library for MySQL (Optional)
By default MySQL will use a Linux library to allow you to connect to it. This is useful if you do not have any external connections but if you wish to have multiple accounts or connect from third party applications or computers, you will need to use the mysql_native_password password authentication method.
To do that, you will need to firstly login to your MySQL database. To connect to our MySQL database, we need to run
$ sudo mysql
You can now execute SQL commands, which is what we will do now:
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
This command will output all the users of our database and the authentication method they are using. You should see auth_socket on the root account.

To change it to mysql_native_password, we will need to run this SQL query:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'securePassword';
Replace securePassword with a secure password of your choice! This is what you will use in the future to connect to your database!
Let's confirm that the password and authentication method has switched by running the same query as before:
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
You should now see that the root account will show `mysql_native_password`!

Now run the command EXIT; to exit the MySQL console!
From now and on you will need to use the command mysql -u root -p which lets you connect to the root user using password authentication!
- Result
Congratulations! You have installed MySQL to your VPS, secured it and switched to the password authentication!
Updated on: 10/02/2021
Thank you!