How To

How to Install and Secure MySQL on Ubuntu 26.04

If you want to Install MySQL Ubuntu systems for web applications, development environments, or database hosting, Ubuntu 26.04 offers a fast and reliable setup process. MySQL remains one of the most trusted open-source relational database systems used in modern Linux infrastructures.

This guide explains how to install MySQL 8.4 on Ubuntu 26.04, secure the server, create databases, and enable remote access safely.

Why Choose MySQL on Ubuntu 26.04?

MySQL is widely used in LAMP and LEMP stacks because it delivers excellent performance, scalability, and stability. Developers often pair it with PHP, Apache, or Nginx for hosting websites and enterprise applications.

Ubuntu 26.04 ships with MySQL 8.4 directly from its official repositories, making installation simple and secure.

Install MySQL Ubuntu Server

Before starting, ensure your account has sudo privileges.

First, refresh the package index:

sudo apt update

Next, install the MySQL server package:

sudo apt install mysql-server

Once installation finishes, the MySQL service starts automatically. Verify the service status with:

sudo systemctl status mysql

You should see the service marked as active and running.

To confirm the installed version, run:

mysql --version

This command displays the MySQL release currently installed on your Ubuntu system.

Secure Install MySQL Ubuntu Environment

After installation, securing the database server is extremely important. MySQL includes a built-in security script that helps remove unsafe defaults.

Run the following command:

sudo mysql_secure_installation

During the setup process, you can:

  • Enable password validation
  • Remove anonymous users
  • Disable remote root logins
  • Delete test databases
  • Reload privilege tables

For production servers, selecting at least the MEDIUM password policy is recommended.

Create MySQL Database and User

After securing the server, you can create databases and dedicated user accounts.

Open the MySQL shell:

sudo mysql

Create a new database:

CREATE DATABASE myapp;

Now create a new user and assign permissions:

CREATE USER 'myappuser'@'localhost' IDENTIFIED BY 'strong_password';GRANT ALL PRIVILEGES ON myapp.* TO 'myappuser'@'localhost';FLUSH PRIVILEGES;

Using separate accounts instead of the root user improves overall security.

Enable Remote Access Securely

By default, MySQL only accepts local connections. If remote access is required, edit the MySQL configuration file:

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

Locate the bind-address setting and update it:

bind-address = 0.0.0.0

Restart MySQL afterward:

sudo systemctl restart mysql

You should also allow port 3306 through the firewall for trusted IP addresses only:

sudo ufw allow from 192.168.1.100 to any port 3306

Avoid exposing MySQL publicly unless absolutely necessary.

Conclusion

Learning how to Install MySQL Ubuntu servers correctly is essential for building secure and scalable Linux hosting environments. Ubuntu 26.04 simplifies the deployment process while MySQL 8.4 provides modern authentication, strong performance, and enterprise-ready features.

After completing the setup, you can continue by integrating MySQL with PHP, WordPress, Laravel, or containerized applications for production workloads.

Cyber Defence

Recent Posts

Configure a Static IP Address on Ubuntu 18.04: Netplan Guide

Setting a static IP address on your server is a smart move. It ensures your…

2 hours ago

Install Xrdp on Ubuntu 18.04: Remote Desktop Setup Guide

Xrdp is an open-source implementation of the Microsoft Remote Desktop Protocol (RDP). It lets you access…

3 hours ago

Add and Delete Users on Ubuntu 18.04: A Practical Guide

Managing user accounts is one of the most basic system administration tasks on any Linux…

3 hours ago

Install Wine on Ubuntu 18.04: Run Windows Apps on Linux

Wine (short for "Wine Is Not an Emulator") is a compatibility layer that lets you run…

3 hours ago

Install KVM on Ubuntu 18.04: Setup, Network, and Create VMs

KVM (Kernel-based Virtual Machine) is an open-source virtualization technology built into the Linux kernel. It lets…

3 hours ago

Upgrade to Ubuntu 20.04 LTS: Prepare, Update, and Confirm

Ubuntu 20.04 LTS (code name Focal Fossa) was released on April 23, 2020. It is a…

1 day ago