UbuntuUbuntu Based

How To Install MySQL on Ubuntu 24.04 LTS

Install MySQL on Ubuntu 24.04

In this tutorial, we will show you how to install MySQL on Ubuntu 24.04 LTS. MySQL, an open-source relational database management system (RDBMS), plays a crucial role in modern web development. Its reliability, scalability, and performance make it a popular choice for developers and businesses alike. As Ubuntu 24.04 continues to be a stable and secure platform for server environments, installing MySQL on this operating system becomes an essential skill for any Linux administrator or developer.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MySQL database on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install MySQL on Ubuntu 24.04 LTS Noble Numbat

Step 1. Updating the Package Repository.

To begin the installation process, we first need to update the package repository to ensure we have access to the latest version of MySQL. Run the following command in your terminal:

sudo apt update

This command will fetch the latest package information from the Ubuntu repositories, allowing you to install the most recent version of MySQL and its dependencies. Updating the package repository is crucial to maintaining the security and stability of your system.

Step 2. Installing MySQL on Ubuntu 24.04.

With the package repository updated, we can now proceed with installing MySQL. To do this, execute the following command:

sudo apt install mysql-server

This command will download and install the MySQL server package along with its dependencies. During the installation process, you may be prompted to confirm the installation by pressing ‘Y‘ and then ‘Enter’.

Step 3. Securing MySQL Installation.

Once the installation is complete, it’s essential to secure your MySQL server by running the mysql_secure_installation script. This script will guide you through setting a root password, removing anonymous users, disabling remote root login, and removing the test database. To run the script, execute the following command:

sudo mysql_secure_installation

Follow the prompts and answer the questions according to your security preferences. It’s highly recommended to set a strong root password and remove anonymous users to enhance the security of your MySQL installation.

Step 4. Configuring MySQL.

After securing your MySQL installation, you may want to configure it for optimal performance based on your specific requirements. The main configuration file for MySQL is located at /etc/mysql/my.cnf. To modify this file, use a text editor with sudo privileges:

sudo nano /etc/mysql/my.cnf

Some common configuration options include:

  • max_connections: Sets the maximum number of allowed client connections.
  • innodb_buffer_pool_size: Determines the size of the buffer pool used by InnoDB tables and indexes.
  • query_cache_size: Sets the size of the query cache, which can improve performance by caching query results.

Make sure to save the changes and exit the text editor when you’re done.

If you need to access your MySQL server remotely, you’ll need to configure MySQL to listen on the appropriate network interface and adjust the firewall rules accordingly. This can be done by modifying the bind-address directive in the MySQL configuration file and allowing incoming connections on the MySQL port (default: 3306) in your firewall settings.

Step 5. Managing MySQL Service.

To manage the MySQL service on Ubuntu 24.04, you can use the systemctl command. Here are some common service management commands:

    • Start the MySQL service:
sudo systemctl start mysql
    • Stop the MySQL service:
sudo systemctl stop mysql
    • Restart the MySQL service:
sudo systemctl restart mysql
    • Enable MySQL to start automatically on system boot:
sudo systemctl enable mysql
    • Check the status of the MySQL service:
sudo systemctl status mysql

These commands allow you to control the MySQL service and ensure it is running properly.

Step 6. Testing the Installation.

To verify that your MySQL installation is functioning correctly, you can log into the MySQL command-line client and execute some basic queries. To log in, run the following command:

sudo mysql

This will open the MySQL command-line client. From here, you can create a new database and run queries to ensure everything is working as expected. For example:

CREATE DATABASE testdb;
USE testdb;
CREATE TABLE users (id INT, name VARCHAR(255));
INSERT INTO users (id, name) VALUES (1, 'Meilana Maria');
SELECT * FROM users;

If these commands execute without any errors, your MySQL installation is set up correctly.

Step 7. Troubleshooting Common Issues

Despite following the installation steps carefully, you may encounter issues. Here are some common problems and their solutions:

  1. MySQL server fails to start: Check the MySQL error log located at /var/log/mysql/error.log for any clues. Common causes include incorrect configuration settings or insufficient permissions.
  2. “Access denied” error when trying to connect: Double-check that you’re using the correct username and password. If you’ve forgotten your root password, you can reset it by following the official MySQL documentation.
  3. Slow query performance: Analyze your slow queries using tools like mysqldumpslow or the MySQL slow query log. Optimize your queries, add appropriate indexes, and adjust configuration settings like query_cache_size and innodb_buffer_pool_size.

If you encounter any other issues, consult the official MySQL documentation or seek help from the vibrant MySQL community forums.

Congratulations! You have successfully installed MySQL. Thanks for using this tutorial for installing the MySQL database on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the MySQL website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button