How To Install Mysql In Linux Step By Step

In this tutorial, we will guide you through the step-by-step process of installing MySQL on a Linux-based operating system.

MySQL is an open-source relational database management system (RDBMS) that is widely used for web applications and embedded systems. Whether you are a web developer or a system administrator, having MySQL installed on your Linux machine might be essential for your projects.

Step 1: Update your System Repository

Before starting the installation process, it is always a good idea to update your system repository. This ensures that you have access to the latest available packages.

For Debian-based systems such as Ubuntu, run the following commands:

For Red Hat-based systems such as Fedora and CentOS, run the following commands:

Step 2: Install MySQL Community Server

To install the MySQL community server, follow the instructions below based on your Linux distribution.

Debian-based Systems (Ubuntu, Debian)

Run the following commands in your terminal:

During the installation, you will be prompted to create a root password for the MySQL server. Make sure you choose a strong password and remember it, as this will be required to access the MySQL server.

Once the installation is complete, run the following command to start the MySQL server:

To enable the MySQL server to start at boot, run:

Red Hat-based Systems (Fedora, CentOS)

For Red Hat-based systems, you need to enable the MySQL repository first. Follow the instructions on the official MySQL website to download the .repo file and place it in the /etc/yum.repos.d/ directory.

After enabling the repository, run the following command:

Once the installation is complete, start the MySQL server using:

And to enable MySQL server to start at boot, run:

Step 3: Run the MySQL Secure Installation Script

After the installation is complete, it is recommended to run the MySQL secure installation script. This script will help you to secure your MySQL installation by allowing you to set a password for the root account, remove anonymous user accounts, disable remote logins for root, and remove the test database.

To run the MySQL secure installation script, use the following command:

Follow the on-screen prompts to complete the secure installation process.

Step 4: Test the MySQL Installation

To test if the MySQL server is successfully installed and running, you can try to log in as the root user. Run the following command in your terminal:

You will be prompted to enter the root password you created during the installation process. After entering the password, you should see the MySQL command prompt (mysql>).

Congratulations! You have successfully installed MySQL on your Linux system.

Conclusion

In this tutorial, we have provided a step-by-step guide on how to install MySQL in a Linux environment. After completing these steps, you should have a fully functional MySQL server up and running on your machine. Now you can start building and managing your database projects using this powerful and widely-used RDBMS.