Ubuntu 20.04 LTS (Focal Fossa) is a popular choice for servers, offering long-term support and a stable environment for applications like MySQL. This tutorial will guide you through the process of installing MySQL Community Server on an Ubuntu 20.04 LTS system. We will cover updating your package index, installing the MySQL packages, running the security script, and managing the MySQL service. For comprehensive server management and optimization, consider exploring Linux Server Support options.
MySQL is a widely-used open-source relational database management system (RDBMS), crucial for many web applications and data storage needs. Following this guide will result in a functional and secured MySQL installation.
sudo privileges.Ensure your system is up-to-date and you have a sudo user configured before proceeding. Standard Ubuntu initial server setup guides can help with this.
Before installing any new software, it’s good practice to update your server’s package list to ensure you get the latest versions of packages and their dependencies.
sudo apt update
Ubuntu 20.04 includes MySQL in its default APT repositories. You can install the mysql-server package, which will pull in mysql-community-server and related dependencies.
sudo apt install mysql-server
During the installation, you will likely not be prompted to set a root password or make other configuration choices. MySQL 8.0 on Ubuntu initializes with the auth_socket plugin for the root user by default, which allows authentication by validating the operating system user connecting via a Unix socket.
Once the installation is complete, the MySQL service should start automatically. You can verify its status:
sudo systemctl status mysql
The output should show the service as active (running).
MySQL comes with a security script that should be run after installation to improve the security of your MySQL server. This script, mysql_secure_installation, will help you configure options like the VALIDATE PASSWORD component, set or change the root password (if not using auth_socket or if you wish to change authentication method), remove anonymous users, disallow remote root login, and remove the test database.
Run the script with sudo:
sudo mysql_secure_installation
This script will guide you through the following prompts:
auth_socket: If you plan to continue using auth_socket for the root user (allowing sudo mysql access without a password), you might not need to set a password here for that specific purpose. However, mysql_secure_installation might still prompt for it. If you wish to enable password authentication for root, you would later need to alter the root user: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password'; FLUSH PRIVILEGES;Completing these steps is crucial for a secure MySQL deployment. For advanced security hardening or ongoing database management, consider seeking professional MySQL support.
After running the security script, you can test your MySQL installation. If you are using auth_socket for the root user (the default on Ubuntu 20.04), you can access MySQL as root using sudo:
sudo mysql
If you configured root to use password authentication (e.g., mysql_native_password), you would log in with:
mysql -u root -p
And then enter the root password you set.
Once logged in, you will be at the MySQL monitor prompt (mysql>). You can run a simple query, like checking the server version:
SELECT VERSION();
Or show databases:
SHOW DATABASES;
To exit the MySQL monitor, type:
EXIT;
The MySQL service is managed using systemctl on Ubuntu 20.04.
bash
sudo systemctl start mysqlbash
sudo systemctl stop mysqlbash
sudo systemctl restart mysqlbash
sudo systemctl status mysqlbash
sudo systemctl enable mysqlbash
sudo systemctl disable mysqlYou have successfully installed and secured MySQL on your Ubuntu 20.04 LTS server. Your database is now ready to be used by your applications. Remember to perform regular backups and keep your system updated.
For further reading and related guides, you might find these useful:
Effective database administration is key for performance and security. If your organization requires expert assistance with database management or is looking for comprehensive Managed IT Services, Medha Cloud offers a range of solutions. For Managed Service Providers (MSPs), Medha Cloud also provides white-label managed IT services, allowing you to expand your service offerings under your own brand.

