Preamble
MySQL is the most popular open-source relational database management system. It is fast, easy to use, scalable, and an integral part of the popular LAMP and LEMP stacks.
This article explains how to install and protect MySQL in Ubuntu 20.04.
Make sure that you are logged on as a user with sudo privileges.
Install MySQL in Ubuntu
At the time of writing this article, the latest version of MySQL available in Ubuntu repositories was MySQL version 8.0. To install it, run the following commands:
sudo apt update
sudo apt install mysql-server
After installation is complete, the MySQL service will start automatically. To make sure that the MySQL server is running, type:
sudo systemctl status mysql
The output should show that the service is on and running:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-04-28 20:59:52 UTC; 10min ago
Main PID: 8617 (mysqld)
Status: "Server is operational"
...
Securing MySQL
The MySQL installation comes with a script named mysql_secure_installation, which makes it easy to improve the security of the database server.
Call the script without arguments:
sudo mysql_secure_installation
You will be asked to configure the VALIDATE PASSWORD PLUGIN, which is used to check the reliability of MySQL users’ passwords and improve 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 the password
and allows the users to set only those passwords which are
secure enough. Would you like to setup the VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: y
There are three levels of password checking policy: low, medium, and strong. Click, Wesley you want to configure a password verification plugin or any other key to proceed to the next step:
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
The next invitation will ask you to set a password for the user root MySQL:
Please set the password for root here.
New password:
Re-enter new password:
If you installed the password verification plugin, the script will show you the strength of your new password. Enter the password validation plugin:
Estimated strength of the password: 50
Do you wish to continue with the password provided? (Press y|Y for Yes, any other key for No) : y
Next, you will be prompted to delete an anonymous user, restrict root access to the local computer, delete the test database, and reboot the privilege tables. You shall be asked to answer all questions.
Log in as root
To interact with the MySQL server from the command line, use the MySQL client utility, which is installed as a dependency on the MySQL server package.
On MySQL 8.0 the user root auth_socket is checked by default by the plugin.
The auth_socket plugin authenticates users who connect from localhost via Unix socket file. This means that you cannot authenticate as root by providing a password.
To login to the MySQL server as root, type:
sudo mysql
You will be presented with the MySQL shell as shown below:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.19-0ubuntu5 (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.
affiliates. Other may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
If you want to log into your MySQL server as root using an external program such as phpMyAdmin, you have two options.
The first is to change the authentication method from auth_socket to mysql_native_password. You can do this by running the following command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';FLUSH PRIVILEGES;
The second recommended option is to create a new dedicated administrative user with access to all databases:
GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password‘;
Conclusion
We showed you how to install MySQL on Ubuntu 20.04. Now that the database server is up and running, the next step is to learn how to manage MySQL user accounts and databases.
MYSQL on Ubuntu
About Enteros
IT organizations routinely spend days and weeks troubleshooting production database performance issues across multitudes of critical business systems. Fast and reliable resolution of database performance problems by Enteros enables businesses to generate and save millions of direct revenue, minimize waste of employees’ productivity, reduce the number of licenses, servers, and cloud resources and maximize the productivity of the application, database, and IT operations teams.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Enhancing Database Performance and Scalability in Digital Banking Platforms with Advanced Analytics
- 14 May 2026
- Database Performance Management
Introduction Digital banking has transformed the financial services landscape. Customers now expect seamless mobile banking experiences, instant payments, real-time transaction confirmations, and 24/7 service availability. These modern banking services rely heavily on high-performance database infrastructures that support massive transaction volumes and complex analytics workloads. At the core of every digital banking interaction—whether it is a … Continue reading “Enhancing Database Performance and Scalability in Digital Banking Platforms with Advanced Analytics”
How Intelligent Database Analytics Improves Performance and Reliability in Modern E-Learning Platforms
Introduction The global shift toward digital education has transformed how institutions deliver learning experiences. Universities, online learning platforms, corporate training systems, and educational technology companies now rely heavily on digital platforms to deliver courses, manage learning data, and support millions of simultaneous users. Behind every online lecture, virtual classroom, exam submission, and learning analytics dashboard … Continue reading “How Intelligent Database Analytics Improves Performance and Reliability in Modern E-Learning Platforms”
How Intelligent Database Analytics Improves Performance and Scalability in Modern Retail Platforms
- 13 May 2026
- Database Performance Management
Introduction Retail has undergone a dramatic transformation over the past decade. Today’s retailers operate in a digital-first economy where customers expect fast, personalized, and seamless shopping experiences across multiple channels. From e-commerce platforms and mobile apps to in-store point-of-sale systems and inventory management tools, every component of modern retail relies on efficient data infrastructure. At … Continue reading “How Intelligent Database Analytics Improves Performance and Scalability in Modern Retail Platforms”
How to Accelerate Insurance Sector Growth with Enteros Cost Attribution and RevOps Strategy
Introduction The insurance industry is rapidly evolving as organizations embrace digital transformation, data-driven decision-making, and customer-centric business models. Modern insurers must deliver seamless digital experiences, process claims efficiently, personalize policy offerings, and maintain operational agility in an increasingly competitive market. At the same time, insurance companies face rising operational costs, growing regulatory complexity, and increasing … Continue reading “How to Accelerate Insurance Sector Growth with Enteros Cost Attribution and RevOps Strategy”