How to Install MySQL on Ubuntu 22.04: A Complete Guide for Beginners
If you're planning to run a dynamic website, develop database-driven applications, or manage data in a secure environment, MySQL is a top choice for a relational database system. Coupled with the power and stability of Ubuntu 22.04 (Jammy Jellyfish), MySQL becomes a reliable and scalable solution. This blog will walk you through how to Install MySQL on Ubuntu 22.04, using simple steps inspired by Vultr’s comprehensive guide.
Why Use MySQL on Ubuntu 22.04?
Ubuntu 22.04 LTS is one of the most stable and widely used Linux distributions, especially among developers and system administrators. It offers long-term support, security updates, and compatibility with the latest open-source tools. MySQL, on the other hand, is a widely trusted relational database system known for:
High performance and scalability
Robust security features
ACID compliance
Strong community support
Compatibility with numerous applications and frameworks
Using MySQL with Ubuntu 22.04 ensures a powerful foundation for managing and storing structured data efficiently.
Prerequisites Before Installation
To get started with installing MySQL on Ubuntu 22.04, ensure the following:
You are running a system with Ubuntu 22.04 installed
You have sudo/root privileges
You have access to a terminal or remote SSH connection
Step-by-Step Guide to Install MySQL on Ubuntu 22.04
Step 1: Update System Packages
First, update your system’s package index to ensure you're installing the latest versions:
sudo apt update
Step 2: Install MySQL Server
Next, run the following command to install MySQL:
sudo apt install mysql-server
This command will install the MySQL server along with necessary dependencies.
Step 3: Verify MySQL Service
Once the installation is complete, confirm that MySQL is up and running:
sudo systemctl status mysql
You should see a green active (running) status. If not, you can start it using:
sudo systemctl start mysql
Step 4: Secure Your MySQL Installation
MySQL comes with a security script to remove insecure defaults and strengthen your server’s security:
sudo mysql_secure_installation
You will be prompted to:
Set a root password
Remove anonymous users
Disallow remote root logins
Remove the test database
Reload privilege tables
We recommend answering “Yes” to all prompts unless you have specific requirements.
Step 5: Access the MySQL Console
Once MySQL is installed and secured, log in to the MySQL shell:
sudo mysql
You will enter the MySQL console, where you can begin creating databases, users, and tables.
Basic MySQL Commands to Get Started
Show all databases: SHOW DATABASES;
Create a new database:
CREATE DATABASE example_db;
Create a new user: CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'your_password';
Grant user privileges:
GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
Exit MySQL:
EXIT;
Step 6: Optional – Enable Remote Access
If you need remote access to your MySQL server, configure the bind-address in the MySQL config file (/etc/mysql/mysql.conf.d/mysqld.cnf) and allow traffic on port 3306 in your firewall.
Step 7: Uninstalling MySQL (If Needed)
To remove MySQL completely:
sudo apt remove --purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo apt autoclean
Final Thoughts
That’s it! You’ve now learned how to Install MySQL on Ubuntu 22.04. Whether you’re a developer building a new app, or a system admin managing server data, this setup provides a solid base for running robust and secure databases.
For a visual step-by-step guide and more advanced options, be sure to visit Vultr’s official MySQL installation documentation. If you run into issues or want to share your experience, feel free to join the discussion and ask questions in the forum!