Skip to main content

Install MySQL in Ubuntu 20.04 Focal Pit

In this guide we will see how to install MySQL in Ubuntu 20.04 Focal Fossa with apt, the default package manager, version present is 8.0
It is very common in our Linux Support, being the basis for LAMP stacks (Linux, Apache, MySQL, PHP), LEMP (NginX) and several others needed for many webapps, CMS and e-commerce

Installing MySQL in Ubuntu

As a first step we update the list of available packages with

sudo apt update

We proceed to install MySQL with this command

sudo apt install mysql-server

The server should already be active, let's check if the process is active

sudo systemctl status mysql

If it is not active, we can restart MySQL and repeat the check

sudo systemctl restart mysql

We check the default port of MySQL, the 3306 TCP, which should be listening at this point

sudo apt install net-tools
sudo netstat -tnplu |grep 3306

The command should return the following output

tcp 0 0 127.0.0.1:3306 0.0.0:* LISTEN -
tcp6 0 0 :::33060 :::* LISTEN -

Configure MySQL

The server is up, for a new installation the configurations used are the default ones, security is poor, at this point it is recommended to run the DBMS configuration script to set the root password and anonymous logins

sudo mysql_secure_installation

The script will guide us in configuring the server security options

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of passwords
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

You need to set the MySQL root password, we recommend a "strong" password, with numbers, uppercase and lowercase and special characters
You will not need to re-enter it in applications, in case they need to access the database, such as for a WordPress blog or a Magento e commerce, we will need to create a dedicated user, with permissions on the specific database

Please set the password for root here.
New password:

At this point is we can log in with the root user and the newly created password

mysql -u root -p

show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

The output shows us the databases present, we managed to install MySQL in Ubuntu 20.04, we can use with the usual syntax our MySQL, connect ne our web apps and CMS

Add new comment

Comment

  • Allowed HTML tags: <br> <p> <code class="language-*"> <pre>
  • Lines and paragraphs break automatically.
  • Only images hosted on this site may be used in <img> tags.