MySQL is one of the most popular open-source relational database management systems used worldwide. It is known for its reliability, performance, and ease of use. In this guide, we will walk you through the step-by-step process of installing MySQL 8 on Ubuntu 24.04 LTS. Each command will be explained in detail, making it easy to follow for beginners.
Prerequisites
Before proceeding with the installation, ensure that:
- You have a server or system running Ubuntu 24.04 LTS.
- You have
sudo
privileges to perform administrative tasks. - Your system is updated.
Step 1: Update Your System 🔄
Start by updating your package lists to ensure you’re installing the latest software versions.
sudo apt update && sudo apt upgrade -y
sudo apt update
: Updates the package index.sudo apt upgrade -y
: Upgrades installed packages to their latest versions automatically.
Step 2: Install Required Dependencies
Before installing MySQL, ensure that essential packages are installed to avoid any dependency issues.
sudo apt install wget gnupg -y
wget
: A utility for downloading files from the web.gnupg
: Ensures secure communication and verifies the authenticity of packages.
Step 3: Add MySQL APT Repository 📥
To install MySQL 8, you need to add its official APT repository to your system.
- Download the MySQL APT configuration package:
sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.25-1_all.deb
- This fetches the MySQL APT repository configuration package.
- Install the downloaded package:
sudo dpkg -i mysql-apt-config_0.8.25-1_all.deb
dpkg -i
: Installs the MySQL APT configuration package. During installation, a configuration prompt will appear. SelectMySQL 8.0
and confirm your selection.
In the prompt, choose Ubuntu Bionic and click Ok
The next prompt selects MySQL 8.0 by default. Choose the last option Ok and click OK
Step 4: Update the Package List Again
After adding the repository, update your package list to include the new repository.
sudo apt update
- This ensures that Ubuntu recognizes MySQL packages from the newly added repository.
If you encounter the error:
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C
Resolve it by adding the missing public key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B7B3B788A8D3785C
apt-key adv
: Adds the specified public key.--keyserver
: Specifies the keyserver to retrieve the key from.--recv-keys
: Imports the public key.
After running the above command, repeat the update:
sudo apt update
Step 5: Install MySQL 8 🚀
Now, install MySQL 8 using the following command:
sudo apt install mysql-server -y
- This command installs the MySQL server and client.
Step 6: Secure MySQL Installation 🔐
MySQL provides a script to secure your installation by removing insecure default settings.
sudo mysql_secure_installation
- Follow the prompts:
- Set a strong root password.
- Remove anonymous users.
- Disallow root login remotely.
- Remove the test database.
- Reload privilege tables.
Step 7: Verify MySQL Service Status ⚡
Ensure that the MySQL service is running.
sudo systemctl status mysql
- If the service is active, you will see a status of
active (running)
.
To enable MySQL to start automatically on system boot:
sudo systemctl enable mysql
Step 8: Log in to MySQL ✅
Access the MySQL command line to verify the installation.
sudo mysql -u root -p
-u root
: Specifies the root user.-p
: Prompts you to enter the root password.
If the login is successful, you will see the MySQL shell prompt (mysql>
).
Conclusion 🎉
Congratulations! You have successfully installed MySQL 8 on Ubuntu 24.04 LTS. MySQL is now ready to manage your databases efficiently. You can start creating databases, managing users, and building robust applications.
If you have any questions or need further assistance, feel free to reach out to us at:
Email: devopsbyrushi@gmail.com