This post is a tutorial that shows step by step how to install MySQL 8 on Ubuntu 20.04.
In the tests we conducted, we used Ubuntu running as a subsystem of Windows 10. But nothing prevents you from following these steps on a server running only the Ubuntu 20.04 Operating System.
Before any installation, it is important to update the package index of your Ubuntu server by running the command:
sudo apt update
The result will be something close to the screenshot below:
The next step is to install the MySQL Server package.
To do this, use the command:
sudo apt install mysql-server
As soon as some downloads are made, you will need to confirm the total download.
As you can see in the screenshot below, this will be a download of 246 MB.
To continue, you need to confirm by typing Y or deny by typing N. After typing Y, press ENTER and be patient until the download is finished ?.
The final result after many downloads was this:
Note that at the end of the MySQL installation there were errors in the process both for mysql-server-8.0 and mysql-server.
However, we can ensure that the MySQL service was installed with the following command:
service mysql status
See in the screenshot below:
The return message indicated that the MySQL service is stopped. The good news is that it already exists!
You can also check the installed version of MySQL with the command:
mysql --version
To start the configuration, we need it to be running, and we can only start it by executing as a super user.
To do this, use the command:
sudo su -
You will be prompted for the root user password. Just type it and press ENTER.
Now we can start the MySQL service with the command:
service mysql start
Attention, only if you are running Ubuntu as a Windows subsystem, ensure that if you have MySQL installed on Windows, you need to stop the service to start it on Ubuntu. Because by default both will run on the same port (3306).
Now we can start the configuration of MySQL 8, using the command:
mysql_secure_installation
The first configuration that will be asked is whether you want to use MySQL's secure password validation component. Basically, it checks the strength of the password and may even require stronger passwords when creating any user in MySQL.
Whether to use it or not is your decision and it will not affect the installation of MySQL, which is the purpose of this post.
As before, if you want to use it, press Y, if not, N.
In this tutorial, we chose not to use it.
Now you will need to set the password for the MySQL root user, which has nothing to do with the Ubuntu root user. ?
Once the password is created and confirmed, indicate whether you want to remove the access of anonymous users. (We chose to remove by responding Y)
Then it asks if you want to disable the remote login of the MySQL root user. (We chose to keep this permission by responding N)
Now it asks if you want to remove the test database that comes by default. (We chose to remove by responding Y)
Finally, the configuration wizard asks if we want to update the permissions now. (We chose to update by responding Y)
? phew! It's over.
The final screenshot of the responses looks like this:
Very well, now we can try to connect our root user to MySQL 8!
For that, use the command:
mysql -u root -p
When you press ENTER, you will be prompted for the password. Type the password and press ENTER again.
Great! We are connected to MySQL.
Just as a test, I will create a database called hcode with the command:
CREATE DATABASE hcode;
And then request to show all the databases that exist with the command:
SHOW DATABASES;
The result is this:
Now the most amazing part: since I am running Ubuntu as a subsystem of Windows 10, access to my database from MySQL Workbench installed on Windows 10 should work.
Just configure the connection to localhost using the user and password created. (As long as you have allowed remote access for the root user. If not, you will have to create a new user in MySQL for this access. Of course, in production this is a good security practice.)
There it is! ? We can see our hcode database in Windows running on MySQL 8 on Ubuntu 20.04!!
Did you like what you are learning on the Hcode blog?
Then check out our YouTube channel and also the Online Course Mastering MySQL Databases.
See you later.