MySQL is an open-source, simple, and relational database that uses SQL (Structured Query Language) to manage and manipulate the data. MySQL is an essential part of the LAMP (https://linuxhint.com/install-lamp-stack-ubuntu/) stack. As of the writing, the newest version of MySQL is 8.0.23.

This post explains the MySQL installation on Linux Mint 20 and Ubuntu 20.04.

Installing MySQL on Linux Mint 20 and Ubuntu 20.04

Fire up the terminal and update the apt repository cache before installing MySQL:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_1.jpg" data-lazy- height="301" src="data:image/svg xml,” width=”810″>

Next, install the MySQL server with the command:

$ sudo apt install mysql-server

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_2.jpg" data-lazy- height="320" src="data:image/svg xml,” width=”811″>

Press ‘y’ to continue installing the MySQL server.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_3.jpg" data-lazy- height="116" src="data:image/svg xml,” width=”813″>

Once the MySQL server is successfully installed, check the installed version and verify the installation using the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_4.jpg" data-lazy- height="93" src="data:image/svg xml,” width=”812″>

Upon successful installation, the MySQL service will start automatically. To check the status of the MySQL server, run the command:

$ sudo systemctl status mysql

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_5.jpg" data-lazy- height="325" src="data:image/svg xml,” width=”821″>

The output shows that the MySQL service is active and running.

Configuring the MySQL on Linux Mint 20 and Ubuntu 20.04

The mysql_secure_installation script, which comes by default with the MySQL installation, allows us to secure the MySQL security.

Run the mysql_secure_installation script with the command:

$ sudo mysql_secure_installation

During the execution of the mysql_secure_installation script, you will be displayed various prompts. First, you will see three levels of a password validation policy. You are supposed to press ‘y’ to set up a password. Further, select the password level by entering the respective numeric digit.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_6.jpg" data-lazy- height="464" src="data:image/svg xml,” width=”808″>

Moreover, enter the password and re-enter the password for confirmation. The command line will display the estimated strength of the password.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_7.jpg" data-lazy- height="191" src="data:image/svg xml,” width=”814″>

Additionally, you will be prompted to remove the anonymous users, test databases, and reload the privileges table. Press’ y or n’ according to your choice, and the configuration will be performed successfully.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_8.jpg" data-lazy- height="384" src="data:image/svg xml,” width=”809″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_9.jpg" data-lazy- height="137" src="data:image/svg xml,” width=”810″>

Creating new user

To start with MySQL server from the command line, use the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_10.jpg" data-lazy- height="347" src="data:image/svg xml,” width=”814″>

The MySQL interactive shell will start. Once the MySQL server is set up, the MySQL creates a root user that can manage the databases and perform various administrative actions.

Moreover, you can also create a new user in the MySQL server. While creating a new user, enter a username and password. Follow the below-given syntax to create a new user:

CREATE USER user_name@‘localhost’ IDENTIFIED BY ‘password’;

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_11.jpg" data-lazy- height="347" src="data:image/svg xml,” width=”814″>

After successfully creating the new user, you can grant the privileges to the user as follows:

GRANT ALL PRIVILEGES ON *. * TO user_name@‘localhost’;

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_12.jpg" data-lazy- height="75" src="data:image/svg xml,” width=”820″>

The *.* will grant all types of privileges to the newly created user.

It is advisable to flush the privileges. It will free up the extra memory that the server cached while creating a new user.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/13-7.jpg" data-lazy- height="133" src="data:image/svg xml,” width=”810″>

Logging into MySQL server and create a database

Now let’s login to the MySQL server and create a new database. To perform a login, use the command:

Enter the password that you have set before for this user, and MySQL interactive shell will start.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_14.jpg" data-lazy- height="344" src="data:image/svg xml,” width=”804″>

For creating a new database, execute the command:

CREATE DATABASE database_name;

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_15.jpg" data-lazy- height="58" src="data:image/svg xml,” width=”624″>

To see the list of all available databases, type the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Install-MySQL-on-Linux-Mint-20-and-Ubuntu-20.04_16.jpg" data-lazy- height="279" src="data:image/svg xml,” width=”975″>

Conclusion

MySQL is a very popular and open-source relational database. The MySQL server is included in Linux Mint 20 and Ubuntu 20.04 standard repositories. This article explains the MySQL installation on two popular Linux distros, i.e., Linux Mint 20 and Ubuntu 20.04.

About the author

<img alt="Kamran Sattar Awaisi" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/52E439DD556343299E3D211D5E577D28-150×150.jpg603d9a9068d1e.jpg" height="112" src="data:image/svg xml,” width=”112″>

Kamran Sattar Awaisi

I am a software engineer and a research scholar. I like to write article and make tutorial on various IT topics including Python, Cloud Computing, Fog Computing and Deep Learning. I love to use Linux based operating systems.