3 min read

How to Install MySQL on Ubuntu (Xorg) – Step-by-Step Guide

If you're setting up a development or production server on Ubuntu, installing MySQL with a web interface like phpMyAdmin is one of the first steps for managing databases efficiently.

Whether you're using Ubuntu with Xorg (desktop environment) or a server edition, the installation process remains almost the same. In this complete guide, you'll learn:

  • Required packages

  • Step-by-step MySQL installation

  • Securing MySQL

  • Installing and configuring phpMyAdmin

  • Common mistakes to avoid

  • Frequently asked questions

We’ll be installing:

  • MySQL

  • phpMyAdmin

  • Apache HTTP Server

  • PHP

Let’s get started.

Requirements:

Before installing MySQL and phpMyAdmin on Ubuntu, make sure you have:

  • Ubuntu 20.04 / 22.04 / 24.04 installed

  • Sudo privileges

  • Internet connection

  • Terminal access

Update your system first:

sudo apt update

Then:

sudo apt upgrade -y

Required Packages

To run MySQL with phpMyAdmin, you need:

Package

Purpose

mysql-server

Database engine

apache2

Web server

php

Server-side scripting

php-mysql

PHP-MySQL connector

phpmyadmin

Web UI for MySQL

libapache2-mod-php

Apache PHP module

How to Install MySQL on Ubuntu

Step 1: Install MySQL Server

sudo apt install mysql-server -y

After installation, check status:

sudo systemctl status mysql

If running, you’ll see active (running).

Enable auto-start:

sudo systemctl enable mysql

Step 2: Secure MySQL Installation

Run:

sudo mysql_secure_installation

You’ll be asked:

  • Set root password

  • Remove anonymous users

  • Disable remote root login

  • Remove test database

  • Reload privilege tables

Choose Yes for all recommended options.

Step 3: Login to MySQL

sudo mysql -u root -p

Inside MySQL:

SHOW DATABASES;

Exit:

EXIT;

Install Apache and PHP

Step 4: Install Apache

sudo apt install apache2 -y

Check in browser:

http://localhost

You should see Apache default page.

Step 5: Install PHP and Required Extensions

sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip -y

Check PHP version:

php -v

Restart Apache:

sudo systemctl restart apache2

Install phpMyAdmin

Step 6: Install phpMyAdmin

sudo apt install phpmyadmin -y

During installation:

  • Choose apache2

  • Select Yes for dbconfig-common

  • Enter MySQL root password

  • Set phpMyAdmin password

Step 7: Enable phpMyAdmin in Apache

If not automatically enabled:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Restart Apache:

sudo systemctl restart apache2

Step 8: Access phpMyAdmin Web Interface

Open browser:

http://localhost/phpmyadmin

Login using:

  • Username: root

  • Password: (your MySQL password)

Create a Test Database (Practical Example)

Let’s create a database for a sample project.

Create Database via MySQL CLI

sudo mysql -u root -p

Then:

CREATE DATABASE company_db;

Verify:

SHOW DATABASES;

Create Database via phpMyAdmin

  1. Login

  2. Click New

  3. Enter 'company_db'

  4. Click Create

Create a User and Grant Privileges (Best Practice)

Avoid using root in production.

Step 1:

CREATE USER 'company_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';

Step 2:

GRANT ALL PRIVILEGES ON company_db.* TO 'company_user'@'localhost';

Step 3:

FLUSH PRIVILEGES;

Now login using:

mysql -u company_user -p

Common Mistakes to Avoid

1. Not Running mysql_secure_installation

This leaves:

  • Anonymous users

  • Weak root access

  • Test databases

Always secure installation.

2. Using Root for Applications

Root has full privileges - risky for production.

3. Forgetting Apache Restart

After installing PHP or phpMyAdmin:

sudo systemctl restart apache2

4. Port Conflict (3306)

Check if MySQL is using port:

sudo netstat -tlnp | grep 3306

5. phpMyAdmin Not Found

If "/phpmyadmin" gives 404:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Benefits of Installing MySQL with phpMyAdmin

1. Easy Database Management

phpMyAdmin provides GUI access.

2. Faster Development

Quickly create tables and run queries.

3. Ideal for Local Development

Perfect for testing Laravel, WordPress, or custom PHP apps.

4. Secure and Stable

MySQL is production-ready and widely used.

How to Uninstall (Optional)

Remove phpMyAdmin:

sudo apt remove phpmyadmin -y

Remove MySQL:

sudo apt remove mysql-server -y
sudo apt purge mysql-server -y

Conclusion

Installing MySQL on Ubuntu Xorg with phpMyAdmin is straightforward when done step by step:

  1. Update system

  2. Install MySQL

  3. Secure installation

  4. Install Apache and PHP

  5. Install phpMyAdmin

  6. Create database and user

This setup is perfect for:

  • Local development

  • Learning SQL

  • Hosting PHP applications

  • Running small production apps

If you’re building web applications or backend systems, this stack provides a solid foundation.

Frequently Asked Questions

How do I open phpMyAdmin in Ubuntu?
http://localhost/phpmyadmin
Which is better: MySQL or MariaDB?
MariaDB is a fork of MySQL and fully compatible. For most use cases, both perform similarly. Ubuntu sometimes ships MariaDB by default.
How do I check if MySQL is running?
sudo systemctl status mysql
What is SQL?
SQL (Structured Query Language) is a programming language used to communicate with databases. It allows you to create tables, insert data, update records, delete information, and retrieve data from a database. SQL is not software; it is a language that database systems use to manage and organize data efficiently.
What is the difference between SQL and MySQL?
SQL is a language used to write database queries, while MySQL is a database management system that uses SQL to store and manage data. In simple terms, SQL is the language, and MySQL is the software that understands and executes that language. Many other database systems also use SQL, not just MySQL.
Is MySQL free to use?
Yes, MySQL Community Edition is free and open source, which makes it very popular among developers and startups. There is also a paid Enterprise version that provides advanced features, security tools, and official support for businesses.
What is a database?
A database is an organized collection of data stored electronically in a structured format. It helps store information such as user details, product information, orders, or messages in tables made up of rows and columns. Databases make it easy to search, manage, and update data efficiently.
What is phpMyAdmin used for?
phpMyAdmin is a web based tool used to manage MySQL databases through a graphical interface. Instead of using command line instructions, users can create databases, manage tables, run SQL queries, and import or export data using a browser. It is especially helpful for beginners.
What is the default MySQL port number?
The default port number used by MySQL is 3306.

Related Articles