Paridhi SolutionsBlog

How to Install MySQL 8 on Ubuntu 24.04 LTS (Complete Step-by-Step Guide)

Learn how to install MySQL 8 on Ubuntu 24.04 LTS, secure your database server, create a Magento database and user, optimize MySQL settings, and troubleshoot common issues.

2026-07-02
4 min read read
How to Install MySQL 8 on Ubuntu 24.04 LTS (Complete Step-by-Step Guide)
How to Install MySQL 8 on Ubuntu 24.04 LTS (Complete Step-by-Step Guide)

How to Install MySQL 8 on Ubuntu 24.04 LTS

MySQL is one of the most widely used relational database management systems and is commonly used with PHP applications such as Magento, WordPress, Laravel, and many others.

In this guide, you'll install MySQL 8, secure the server, create a database and user for Magento, verify the installation, and learn basic administration commands.


Why MySQL?

MySQL offers:

  • Excellent performance
  • High reliability
  • Strong community support
  • ACID-compliant transactions
  • Compatibility with Magento

Prerequisites

Before starting, ensure you have:

  • Ubuntu 24.04 LTS
  • A sudo user
  • Terminal access
  • PHP installed (recommended if you're preparing a Magento server)

Step 1 — Update Your System

bash
sudo apt update
sudo apt upgrade -y

Keeping packages updated helps ensure you're installing the latest security fixes.


Step 2 — Install MySQL Server

Install MySQL:

bash
sudo apt install mysql-server -y

Verify the installation:

bash
mysql --version

Example output:

text
mysql  Ver 8.x.x

Step 3 — Start and Enable MySQL

Check the service status:

bash
sudo systemctl status mysql

Enable MySQL to start automatically at boot:

bash
sudo systemctl enable mysql

If needed, start the service:

bash
sudo systemctl start mysql

Step 4 — Secure Your Installation

Run the security script:

bash
sudo mysql_secure_installation

The wizard will help you:

  • Set a root password (depending on authentication method)
  • Remove anonymous users
  • Disallow remote root login
  • Remove the test database
  • Reload privilege tables

These steps improve the security of your MySQL server.


Step 5 — Log In to MySQL

bash
sudo mysql

If your installation uses password authentication:

bash
mysql -u root -p

Exit the MySQL shell:

sql
EXIT;

Step 6 — Create a Database for Magento

sql
CREATE DATABASE magento;

Use a descriptive database name that matches your project.


Step 7 — Create a Database User

Replace the password below with a strong, unique password.

sql
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'StrongPasswordHere';

Step 8 — Grant Permissions

sql
GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost';

FLUSH PRIVILEGES;

This gives the Magento user full access to the Magento database.


Step 9 — Verify the Database

List all databases:

sql
SHOW DATABASES;

Verify the new user:

sql
SELECT user, host FROM mysql.user;

Common MySQL Commands

Show databases:

sql
SHOW DATABASES;

Select a database:

sql
USE magento;

Show tables:

sql
SHOW TABLES;

Exit MySQL:

sql
EXIT;

Troubleshooting

MySQL Service Not Running

Check the service:

bash
sudo systemctl status mysql

Restart it:

bash
sudo systemctl restart mysql

Can't Connect to MySQL

Verify the service is running and confirm the username, password, and authentication method you're using.


Access Denied

Double-check:

  • Username
  • Password
  • Granted privileges
  • Host (localhost vs. another host)

Best Practices

  • Use strong passwords.
  • Create separate users for each application.
  • Grant only the required permissions.
  • Back up your databases regularly.
  • Keep MySQL updated.

Frequently Asked Questions

How do I check the MySQL version?

bash
mysql --version

How do I start MySQL?

bash
sudo systemctl start mysql

How do I stop MySQL?

bash
sudo systemctl stop mysql

How do I restart MySQL?

bash
sudo systemctl restart mysql

How do I list databases?

sql
SHOW DATABASES;

Conclusion

Congratulations! 🎉

You've successfully installed MySQL 8 on Ubuntu 24.04 LTS, secured the server, and created a dedicated database and user for Magento.

Your database server is now ready for the next stage of the Magento installation process.


Continue the Magento Installation Series

Next tutorial:

➡️ How to Install OpenSearch on Ubuntu 24.04 for Magento 2.4.8

Upcoming guides:

  • Install Redis
  • Install Nginx
  • Install Magento 2.4.8
  • Configure Production Mode
  • Configure Cron Jobs
  • File Permissions

Share this article

Tags

MySQLUbuntuUbuntu 24.04MagentoDatabase

Written by

Paridhi Solutions

We help businesses build scalable Magento, React, Next.js, Laravel and custom web applications. Our blog shares practical development guides, performance tips, and real-world solutions from client projects.

Adobe CommerceMagentoReactNext.jsLaravel

Related Articles

🚀 We're Just Getting Started

Join the Paridhi Solutions Developer Community

We're actively publishing practical tutorials covering Magento, Adobe Commerce, React, Next.js, PHP and WordPress. Join our newsletter and be the first to know whenever a new guide is published.

📚 Practical Tutorials⚡ Performance Tips💼 Real Project Experience
✓ New tutorials every week✓ No spam✓ Unsubscribe anytime