How to install MySQL on CentOS 8?


MySQL is a free and open-source relational database management system. A relational database organizes data into one or more tables in which data types may be related to each other. SQL (Structured Query Language) is used to create, modify and extract data from a relational database, also control the user access to the database.

CentOS 8 AppStream repository provides the default installation of MySQL 8.0 it comes enabled by default on CentOS 8 and RHEL 8 systems. In this article, we will discuss how to install MySQL 8.0 on CentOS 8. You can also follow these instructions to install it on RHEL 8.

If you are using a Debian-based system then you could follow how to install MySQL on Ubuntu.

Prerequisites

To complete this installation guide you will need to have the following.

  • A server running CentOS 8
  • Access to a user account with superuser privileges

Installing MySQL on CentOS 8

On CentOS 8 if you are not logged in as root then always use sudo before executing the command.

First, run the given command to update the package index and upgrade all the packages on your system –

dnf update && dnf upgrade

Now use the given command to install the MySQL server on your system –

dnf install @mysql

If it asks for confirmation press y and then enter. This will install MySQL with all its dependencies. Once installation gets completed you can verify it by using.

mysql --version

This will display the installed version –

By default, MySQL services are not running you can use the following command to start it –

systemclt start mysqld

Enable it to automatically start on boot by running the given command –

systemctl enable mysqld

Check the status of MySQL service on CentOS 8

After starting and enabling MySQL services in your system. You can check if MySQL services are running or not by using the given command.

systemctl status mysqld

If MySQL services are running on your system you will see –

Securing MySQL database

Run the mysql_secure_installation to secure MySQL on your system. This is a security script that makes some less secure default options more secure for example the Validate Password Component is used to test the strength of the MySql password, you can disallow remote root login if you want.

Use the given command to run this script on CentOS 8 terminal –

sudo mysql_secure_installation

This will prompt you to choose the options if you want to allow the option press y and enter for yes otherwise type n and then press enter for no. Meanwhile, you will be asked to set the MySql root user password. Choose the strength 0 for low 1 for medium 3 for strong password and then enter the password for root. If everything gets completed you will see the All done! message.

Start MySql to enter commands

To start MySQL on your system use the following command in your terminal –

sudo mysql -u root -p

This will ask you to enter MySQL root user password, enter to proceed.

Once authentication gets completed. Your prompt will change to MySQL shell. You can start executing MySQL commands here.

Conclusion

You have successfully installed MySQL on your system. Now if you have any query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.