Introduction:

In today’s digital landscape, setting up and managing databases is a crucial aspect of many software projects. Among the most popular database management systems is MySQL, renowned for its reliability and scalability. This guide will walk you through the process of installing MySQL on Ubuntu 24.04, along with creating a new user to facilitate secure access to the database.

Prerequisites:

Before proceeding with the installation, ensure that you have administrative access to an Ubuntu 24.04 server or workstation. Additionally, make sure your system is up to date by running the following commands:

sudo apt update

sudo apt upgrade

Installation:

To install MySQL on Ubuntu 24.04, execute the following command:

sudo apt install mysql-server

Once the installation is complete, MySQL will be automatically started. However, we need to make a slight adjustment to the user authentication method to enhance security.

Modify User Authentication Method:

By default, MySQL uses a caching_sha2_password authentication plugin, which may not be compatible with certain applications. To ensure compatibility and simplicity, we will switch the authentication method for the root user to mysql_native_password. Execute the following command:

sudo mysql -e “ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘your_password’;”

Replace ‘your_password’ with the desired password for the root user.

Create a New Database and User:

Now, let’s create a new MySQL user with limited privileges and a database for them. For demonstration purposes, let’s create a user named ‘sam’ with the password ‘2114’ and a database named ‘example_db’. Execute the following commands:

sudo mysql -u root -p

Enter the password of root user and run the following commands in mysql:

CREATE DATABASE example_db;

CREATE USER ‘sam’@’localhost’ IDENTIFIED BY ‘2114’;

GRANT ALL PRIVILEGES ON example_db.* TO ‘sam’@’localhost’;

FLUSH PRIVILEGES;

exit

Conclusion:

You have successfully installed MySQL on your Ubuntu 24.04 system and created a new user for database access. Remember to replace ‘your_password’ and ‘2114’ with strong, secure passwords of your choice. With MySQL up and running, you’re well-equipped to leverage the power of databases in your projects.

Leave a Reply