Install MySQL Server on Ubuntu

Install MySQL Server on Ubuntu 24.04 LTS

MySQL is a widely used open-source relational database management system. Its versatility and robust features make it a preferred choice for developers and administrators. This guide provides detailed steps to install MySQL Server on Ubuntu 24.04 LTS, ensuring a fully operational database environment.


TL;DR

To install MySQL Server on Ubuntu 24.04 LTS:

  1. Update your package index using apt update.
  2. Install the MySQL server package with apt install mysql-server.
  3. Start and enable the MySQL service.
  4. Secure the installation using mysql_secure_installation.


Prerequisites

Before you begin, ensure your system meets the following requirements:

  1. Operating System: Ubuntu 24.04 LTS.
  2. User Privileges: Administrative privileges or sudo access.
  3. Internet Access: To download packages and dependencies.

Step 1: Update the Package Index

First, update the package index to ensure you install the latest version of MySQL from the Ubuntu repository.

Command:

This command synchronizes your local package index with the repository, ensuring access to the latest software versions.


Step 2: Install MySQL Server

Use the apt package manager to install MySQL Server.

Command:

When prompted, confirm the installation by typing Y and pressing Enter. This command installs MySQL Server along with its dependencies.


Step 3: Start and Enable MySQL Service

After installation, start the MySQL service and enable it to start on system boot.

Commands:

You can verify the status of the MySQL service using:

Expected Output:

Output of sudo systemctl status mysql

Step 4: Secure the MySQL Installation

Use the mysql_secure_installation script to configure the security settings for your MySQL installation.

Command:

Prompts You’ll Encounter:

  1. Validate Password Component: Decide whether to enable the password validation plugin.
  2. Set Root Password: Enter and confirm a strong root password.
  3. Remove Anonymous Users: Restrict access to authenticated users.
  4. Disallow Root Login Remotely: Limit root user access to localhost.
  5. Remove Test Database: Delete the default test database.
  6. Reload Privilege Tables: Apply the new changes immediately.

This script enhances the security of your MySQL server by enforcing best practices.


Step 5: Verify the MySQL Installation

Log in to the MySQL server to ensure it is installed and running correctly.

Command:

Enter the root password set during the secure installation process. Once logged in, verify the server status:

Command:

Expected Output:


Optional: Configure MySQL for Remote Access

If your use case requires remote access to MySQL, modify the server configuration and allow traffic through the firewall.

Steps:

1. Edit the MySQL Configuration File: Open the MySQL configuration file:

Find the line bind-address and set it to 0.0.0.0 to allow connections from any IP address:

Save and exit the file.

2. Restart MySQL Service:

3. Open Firewall Port: Allow MySQL traffic through the firewall:

4. Grant Remote Access Privileges: Log in to MySQL and grant remote access to the desired user:


Common Issues and Solutions

1: MySQL Service Fails to Start

  • Cause: Misconfigured settings or insufficient resources.
  • Solution: Check the logs for errors:

2: Password Authentication Fails

  • Cause: Incorrect root password.
  • Solution: Reset the root password:

3: Remote Access Not Working

  • Cause: Firewall or incorrect bind address.
  • Solution: Ensure the firewall allows traffic on port 3306 and the bind address is set to 0.0.0.0.

  1. MySQL Official Documentation
  2. Ubuntu Official Documentation
  3. MySQL Secure Installation Guide

Leave a Reply

Your email address will not be published. Required fields are marked *