How to Install MySQL on a CentOS 8 Server
MySQL is one of the most popular open-source relational database management systems (RDBMS). It is widely used for web applications and various database-driven projects. If you’re working with a CentOS 8 server and need to install MySQL, follow the steps below. This guide will walk you through the installation and basic configuration of MySQL on a CentOS 8 system.
Step 1: Update the System
Before installing any new software, it’s a good practice to update your system to ensure all packages are up-to-date. Open your terminal and run the following command:
sudo dnf update
This will update all the installed packages on your CentOS 8 server.
Step 2: Enable the MySQL Repository
CentOS 8 does not include MySQL by default in its package manager. You’ll need to enable the official MySQL repository. To do this, use the following command to download the MySQL repository package:
sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Once the repository is installed, you can verify that it has been added by running:
dnf repolist enabled | grep "mysql.*"
Step 3: Install MySQL
Now that the MySQL repository is enabled, you can install MySQL by running the following command:
sudo dnf install mysql-server
When prompted, press “y” to confirm the installation.
Step 4: Start and Enable MySQL
After MySQL is installed, you need to start the MySQL service. Run the following command to start MySQL:
sudo systemctl start mysqld
To ensure that MySQL starts automatically every time your server boots, enable it with this command:
sudo systemctl enable mysqld
Step 5: Secure the MySQL Installation
MySQL comes with a security script that helps you configure the root password and remove insecure default settings. Run the following command to begin the security setup:
sudo mysql_secure_installation
You will be prompted to configure the root password, remove anonymous users, disable remote root login, and remove test databases. It is recommended to answer “yes” to all security questions for a more secure installation.
Step 6: Verify MySQL Installation
To verify that MySQL is installed and running correctly, check the MySQL service status:
sudo systemctl status mysqld
You should see output indicating that the service is “active” and running. If MySQL is active, everything is set up correctly.
Step 7: Log into MySQL
You can now log in to the MySQL shell using the root account with the following command:
mysql -u root -p
You will be prompted to enter the root password that you set during the mysql_secure_installation
process. Once authenticated, you will have access to the MySQL command-line interface.
Conclusion
You have successfully installed MySQL on your CentOS 8 server. From here, you can begin creating databases, adding users, and configuring MySQL according to your project requirements. Make sure to maintain regular backups and keep your MySQL installation updated for security purposes.
By following the above steps, you have a reliable MySQL installation that is ready to support your applications and databases on CentOS 8.