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

Bash Scripting Best Practices Every Beginner Should Know

Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…

15 hours ago

How To Create A Self-Signed SSL Certificate Using Bash And OpenSSL

Introduction A self-signed SSL certificate is a certificate that is created and signed by the…

16 hours ago

How To Debug Bash Scripts Using bash -x And set Commands

Introduction Debugging is an important part of Bash scripting. When a script does not work…

20 hours ago

How To Use Cron Jobs With Bash Scripts For Automation

Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…

21 hours ago

How To Use Pipes In Bash Scripts For Command Chaining

Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…

22 hours ago

How To Use grep, awk, And sed In Bash Scripts

Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…

23 hours ago