How to install MySQL on Ubuntu 26.04

How to install MySQL on Ubuntu 26.04

In this blog post, we will show you how to install MySQL server on Ubuntu 26.04. MySQL is a very popular open-source Relational Database Management System (RDBMS) for storing, managing, controlling access, and retrieving structured data. The key characteristics of MySQL are that it is open source, relational, SQL-based (Structured Query Language), scalable, reliable, and versatile, enabling it to run on various systems, including desktops, servers, and clusters. Many popular applications like Facebook, WordPress, YouTube, or Netflix store their data in a MySQL database. In this tutorial, besides the installation process, you will learn how to manage the MySQL service, how to secure it, and some basic MySQL commands.

Installing MySQL is a straightforward process that may take up to 5 minutes. Let’s get started!

Prerequisites

Update the System

Before we start installing MySQL, we assume you have a freshly installed Ubuntu 26.04 OS, so we will update the system packages to their latest versions. To do that, execute the following command:

apt update -y && apt upgrade -y

Install MySQL database server

By default, the MySQL packages are included in the latest Ubuntu 26.04 repository. Installing the MySQL server can be done with the following command:

apt install mysql-server

Once installed, start and enable the MySQL service for automatic start after system boot:

systemctl start mysql && systemctl enable mysql

Once started to check the status of the MySQL service, you can use the following command:

systemctl status mysql

You should get the following output:

root@test.vps:~# sudo systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Fri 2026-01-16 16:23:19 UTC; 3min 50s ago
 Invocation: a51f00e85d6243bfa247c26002089f4e
   Main PID: 22204 (mysqld)
     Status: "Server is operational"
      Tasks: 34 (limit: 1857)
     Memory: 480.2M (peak: 480.6M)
        CPU: 3.540s
     CGroup: /system.slice/mysql.service
             └─22204 /usr/sbin/mysqld

Jan 16 16:23:17 test.vps systemd[1]: Starting mysql.service - MySQL Community Server...
Jan 16 16:23:19 test.vps systemd[1]: Started mysql.service - MySQL Community Server.

To restart the MySQL service, you can use the command below:

systemctl restart mysql

Stopping the MySQL service:

systemctl stop mysql

To check the installed MySQL version, you can use the following command:

mysql -V

You should use output similar to this:

root@host:~# mysql -V
mysql Ver 8.4.8-0ubuntu1 for Linux on x86_64 ((Ubuntu))

Secure the MySQL database service

For a fresh installation, it is highly recommended to run the included security script. This script helps improve the security of your MySQL server by setting the root password, removing anonymous users, and disabling remote root logins. To execute the script, use the following command:

mysql_secure_installation

There will be a couple of questions and steps that you need to complete to fully secure the MySQL service. It should look like this:

Press y|Y for Yes, any other key for No: Y

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

The final output should look like this:

 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

Basic MySQL commands

Here is a list of the most used basic MySQL commands:

1. Connect to the MySQL server from your terminal (shell).

mysql -u [username] -p

2. Export/backup databases from the terminal.

mysqldump -u root -p mydatabase > backup.sql

3. Import the database from the terminal.

mysql -u root -p mydatabase < backup.sql

4. MySQL check database for table corruption

mysqlcheck -u root -p --check dbname

5. MySQL repair corrupted tables

mysqlcheck -u root -p --repair dbname dbtable

6. Check all databases and repair errors

mysqlcheck -u root -p --auto-repair --all-databases

7. Create a MySQL database in the MySQL command line

CREATE DATABASE dbtest;

8. Create database user

CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'Str0ngP@sswordHere!!';

9. Granting permissions to the user for the database

GRANT ALL ON dbtest.* TO 'dbuser'@'localhost' WITH GRANT OPTION;

10. Reload the in-memory copy of privileges from the privilege tables. 

FLUSH PRIVILEGES;

Wrap Up

That’s it. You successfully installed MySQL on Ubuntu 26.04.

Of course, you don’t have to install MySQL on Ubuntu 26.04 if you have difficulty or are not familiar with Linux. You can always contact our technical support. You only need to sign up for one of our Linux VPS hosting plans and submit a support ticket. We are available 24/7 and will address your request immediately.

If you liked this post about installing MySQL on Ubuntu 26.04, please share it with your friends or leave a comment down below.

Leave a Comment