MySQL is one of the most widely used relational database management systems for websites and applications. It is used by platforms like WordPress, Laravel, Magento, and many custom applications to store and manage data.
Ubuntu 26.04 includes MySQL 8.4 in its official repositories, so you can install it with a single command without adding any extra repositories. This guide walks you through the complete installation, security configuration, and basic database setup.
Prerequisites
- An Ubuntu 26.04 dedicated server
- A user with sudo privileges
- An active internet connection
Step 1: Update Your System
Before installing MySQL, update your package list and install any available updates.
sudo apt update
sudo apt upgrade -y
Step 2: Check the Available MySQL Version
If you'd like to see which version Ubuntu will install, run the following command.
apt-cache policy mysql-server
On Ubuntu 26.04, the default repository provides MySQL 8.4 LTS, so there is no need to add Oracle's MySQL repository for a standard installation.
Step 3: Install MySQL Server
Install the MySQL server package using APT.
sudo apt install mysql-server -y
The installation usually finishes within a minute or two depending on your server and internet connection.
Step 4: Verify the Installation
After the installation completes, check the installed version.
mysql --version
You should see output similar to this.
mysql Ver 8.4.x for Linux on x86_64
Step 5: Check the MySQL Service
MySQL normally starts automatically after installation. Verify that the service is running.
sudo systemctl status mysql
If everything is working correctly, you'll see Active: active (running).
Press Q to exit the status screen.
Step 6: Enable MySQL to Start on Boot
Ubuntu usually enables the service automatically, but you can confirm it with the following command.
sudo systemctl enable mysql
If the service isn't running, start it manually.
sudo systemctl start mysql
Step 7: Secure Your MySQL Installation
MySQL includes a built in security script that removes insecure default settings.
sudo mysql_secure_installation
During the setup, you'll be asked several questions. The following answers are recommended for most servers.
Would you like to setup VALIDATE PASSWORD component?
Y
Select password policy:
2 (Strong)
Remove anonymous users?
Y
Disallow root login remotely?
Y
Remove test database and access to it?
Y
Reload privilege tables now?
Y
This step removes anonymous accounts, disables remote root access, deletes the test database, and reloads the privilege tables to apply the changes.
Step 8: Log in to MySQL
Ubuntu configures the MySQL root account to authenticate using your system account.
Log in with the following command.
sudo mysql
If the login is successful, you'll see the MySQL prompt.
mysql>
Exit MySQL by running.
exit;
Step 9: Create Your First Database
Log back into MySQL.
sudo mysql
Create a new database.
CREATE DATABASE myapp;
Verify that it was created.
SHOW DATABASES;
You should see output similar to this.
+--------------------+
| Database |
+--------------------+
| information_schema |
| myapp |
| mysql |
| performance_schema |
| sys |
+--------------------+
Step 10: Create a New Database User
Using the root account for applications is not recommended. Create a dedicated user instead.
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
Grant the user full access to the database.
GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';
Reload the privilege tables.
FLUSH PRIVILEGES;
Exit MySQL.
exit;
Step 11: Test the New User
Connect using the new account.
mysql -u myuser -p
After entering the password, verify the available databases.
SHOW DATABASES;
If you can see the myapp database, your user has been configured successfully.
Useful MySQL Service Commands
| Task | Command |
|---|---|
| Start MySQL | sudo systemctl start mysql |
| Stop MySQL | sudo systemctl stop mysql |
| Restart MySQL | sudo systemctl restart mysql |
| Check Status | sudo systemctl status mysql |
| Enable on Boot | sudo systemctl enable mysql |
Common MySQL Commands
| Task | Command |
|---|---|
| Check Version | mysql --version |
| Login as Root | sudo mysql |
| Show Databases | SHOW DATABASES; |
| Create Database | CREATE DATABASE database_name; |
| Delete Database | DROP DATABASE database_name; |
| Exit MySQL | exit; |
Troubleshooting
MySQL Service Is Not Running
Start the service manually.
sudo systemctl start mysql
If it still doesn't start, check the service logs.
sudo journalctl -u mysql
mysql: command not found
If the MySQL client isn't available, the installation may not have completed successfully.
sudo apt install mysql-server
Cannot Connect to MySQL
Verify that the service is running.
sudo systemctl status mysql
If it's stopped, start it.
sudo systemctl start mysql
Conclusion
You have successfully installed MySQL on Ubuntu 26.04, secured the installation, created a database, added a new user, and verified that everything is working correctly.
Your server is now ready to host applications such as WordPress, Laravel, Magento, phpMyAdmin, or any other software that requires a MySQL database. Databases spend their lives quietly storing everyone else's mistakes. MySQL has become exceptionally good at it.

