MySQL is the most popular open-source relational database management system which is supported by a huge and active community of open source developers. It is available on over 20 platforms and operating systems including Linux, Unix, Mac and Windows. In this guide you are going to learn how to install and secure MySQL on Ubuntu 20.04 LTS.
1./ Installing MySQL on Ubuntu
01- Start by updating the packages to the latest version available.
$ sudo apt update $ sudo apt upgrade
02- In Ubuntu 20.04 MySQL 8 is included by default in the Focal Fossa repositories, so you can install it easily using the apt install
command:
$ sudo apt install mysql-server
03- Once the installation is completed, the MySQL service will start automatically. To verify that the MySQL server is running, type:
$ sudo service mysql status ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-05-29 20:13:18 UTC; 1min 4s ago Main PID: 3333 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 2010) Memory: 322.9M CGroup: /system.slice/mysql.service └─3333 /usr/sbin/mysqld
2./ Securing MySQL on Ubuntu
01- MySQL installation comes with a script named mysql_secure_installation
that allows you to easily improve the MySQL server security, so run the below command:
$ sudo mysql_secure_installation
02- You will be asked to configure the VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL users passwords and improve the security.
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 password 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:
Press y
if you want to set up the validate password plugin or any other key to move to the next step.
03- There are three levels of password validation policy, low, medium, and strong.
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:
Enter 2
for strong password validation.
04- Next, you will be asked to set a password for the MySQL root user.
Please set the password for root here.
If you set up the validate password plugin, the script will show you the strength of your new password. Type y
to confirm the password.
Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
05- Next, you’ll be asked to remove the anonymous user, restrict root user access to the local machine, remove the test database, and reload privilege tables. You should answer y
to all questions.
3./ Connecting to MySQL Server on Ubuntu
In MySQL 8.0, the root user is authenticated by the auth_socket
plugin by default. So, use the below command to connect to MySQL server as the root:
$ sudo mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.20-0ubuntu0.20.04.1 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Conclusion
That’s it! you have learned how to install and secure MySQL Server in Ubuntu 20.04 LTS server by using the mysql_secure_installation
tool and by enabling the VALIDATE PASSWORD COMPONENT
plugin.
Here are some more guides that may interest you: