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:
1 2 |
sudo apt-get update sudo apt-get upgrade |
For Red Hat-based systems such as Fedora and CentOS, run the following commands:
1 2 |
sudo yum update sudo yum upgrade |
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:
1 |
sudo apt-get install mysql-server |
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:
1 |
sudo systemctl start mysql |
To enable the MySQL server to start at boot, run:
1 |
sudo systemctl enable mysql |
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:
1 |
sudo yum install mysql-community-server |
Once the installation is complete, start the MySQL server using:
1 |
sudo systemctl start mysqld |
And to enable MySQL server to start at boot, run:
1 |
sudo systemctl enable mysqld |
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:
1 |
sudo mysql_secure_installation |
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:
1 |
mysql -u root -p |
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.