How to Install MySQL on Ubuntu 22.04 – A Complete Beginner’s Guide

MySQL is a leading open-source relational database management system (RDBMS) trusted by millions of developers and organizations worldwide. Whether you're setting up a blog, e-commerce platform, or enterprise application, MySQL provides the speed, scalability, and reliability you need to manage data effectively.

In this guide, we’ll walk you through how to Install MySQL on Ubuntu 22.04, following the step-by-step instructions provided in the official documentation by Vultr. You can access the full tutorial at Vultr Docs.

Ubuntu 22.04 LTS (Jammy Jellyfish) is the latest long-term support version of Ubuntu, making it a great foundation for your MySQL server due to its stability and extended support.

Why Use MySQL on Ubuntu 22.04?

Choosing MySQL on Ubuntu 22.04 offers several advantages:

  1. Open-source and free: No licensing fees for most use cases.

  2. Performance: Fast and reliable performance even under high workloads.

  3. Security: Tools for encryption, access control, and password protection.

  4. Community support: Widely used and well-documented.

  5. LTS benefits: Ubuntu 22.04 receives updates and support through 2027.

Prerequisites

Before you start the installation process, make sure:

  1. You are using a system running Ubuntu 22.04.

  2. You have access to a user account with sudo privileges.

  3. Your system is connected to the internet.

  4. Basic knowledge of terminal commands is helpful.

Step-by-Step Guide to Install MySQL on Ubuntu 22.04

The following steps are adapted from the official Vultr documentation to help you install and configure MySQL securely and efficiently.

Step 1: Update Your System

Open your terminal and ensure your package list is up-to-date by running:

sudo apt update && sudo apt upgrade -y


This helps avoid package conflicts and ensures system stability.

Step 2: Install MySQL Server

Install MySQL using the default APT package manager:

sudo apt install mysql-server -y


This will install the MySQL server and its dependencies.

Step 3: Start and Enable MySQL

After installation, check if the MySQL service is running:

sudo systemctl status mysql


If it’s not running, you can start it with:

sudo systemctl start mysql


To enable MySQL to start automatically on boot:

sudo systemctl enable mysql


Step 4: Secure Your MySQL Installation

It’s strongly recommended to run the mysql_secure_installation script:

sudo mysql_secure_installation


This script allows you to:

  1. Set a root password.

  2. Remove anonymous users.

  3. Disallow remote root login.

  4. Remove test databases.

  5. Reload the privilege table.

Follow the on-screen prompts and choose "Y" (yes) for recommended settings.

Step 5: Log In to MySQL

To verify the installation and access MySQL, run:

sudo mysql -u root -p


Enter the root password you set during the secure installation. You’ll enter the MySQL shell, where you can start managing databases and users.

Optional: Enable Remote Access (If Required)

If your application or project requires remote access to MySQL:

  1. Open the configuration file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf


  1. Locate the line:

bind-address = 127.0.0.1


  1. Change it to:

bind-address = 0.0.0.0


  1. Save and exit, then restart the service:

sudo systemctl restart mysql


Ensure your firewall is configured to allow traffic on port 3306.

Conclusion

Learning how to Install MySQL on Ubuntu 22.04 is a valuable skill for developers, system administrators, and anyone working with databases. MySQL offers a secure, flexible, and high-performing solution for managing structured data in web and enterprise environments.

By following this guide and referring to the trusted Vultr tutorial, you can set up a robust MySQL environment on your Ubuntu server in just a few steps.

With your MySQL server up and running, you're now ready to create databases, manage users, and power the backend of your next big project.


Write a comment ...

Write a comment ...