MySQL Server is the most popular tool used for relational databases. It hosts multiple databases using a single server where allows multi-user can access these databases individually. At the time, when we are writing this article MySQL Server 8.0 is available for installation. This version introduced some new features that are not compatible with some applications. So, first, read the application documentation before deploy on CentOS 8 server.

In this article, we will explain how to install MySQL on CentOS 8 using the terminal. We will also show you how to get started with using MySQL 8.

Installation of MySQL on CentOS 8

To install MySQL server on your system, you need to do the following steps:

Step 1. Login as root user on your system. So, you can install some necessarily required packages on CentOS 8.

Step 2. Open the terminal by pressing ‘Ctrl + Alt + t’. Or you can also launch the terminal application from the application launcher as follows:

CentOS Terminal (Command line)

Step 3. Now, you will install MySQL server 8 on your system using the Yum package manager. Type the following command on the terminal:

$ sudo dnf install @mysql

Install mysql with dns

You will press ‘y’ to download and install the MySQL dependencies. Using the @mysql module, all dependencies and MySQL will automatically install on the system.

Confirm installation

After a while, a ‘complete’ message will be displayed on the terminal. It’s mean that MySQL has been successfully installed on your system.

MySQL installation completed successfully.

Step 4. Once the installation of MySQL server 8 is completed, it’s time to start and enable the service of MySQL by using the following command:

$ sudo systemctl enable --now mysqld

Enable mysql service

Step 5. It is recommended that you must check the MySQL service running status before to start as follows:

$ sudo systemctl status mysqld

You can see in the following screenshot services of MySQL are running on my system.

Check MySQL status

Step 6. To set the secure root password for MySQL server, you will run the following script:

$ sudo mysql_secure_installation

Secure MySQL installation

After executing the above script, it will ask you to configure a component for password validation named as ‘validate_password’. You will press ‘y’ and hit ‘Enter’ key. It will automatically configure the validate password component. In the next prompt, it will ask you about password length, three options will available on your terminal: 0: low, 1: medium, 2: strong. You will select the option ‘2’ for a strong password. Now, you will set the root password. Enter the new root password and then again you need to re-type the root password. After that, more user prompts will appear on the terminal to confirm the following questions:

  1. Either you want to remove the anonymous user?
  2. Do you want to restrict a root user to access the local machine?
  3. Do you want to remove the test database?
  4. Want to reload privileges of the table?

You must answer ‘yes’ or type ‘y’ to all needed questions and further proceed.

Step 7. Now, you will interact with MySQL server using the command line. Type the following command to start the MySQL environment:

$ mysql -u root -p

You need to enter the root password which you have defined above. Now, your MySQL server 8 with secure configuration has been installed on your system. Now, you can explore more MySQL command by working on it.

Create a database using MySQL server

To create a database named ‘vitux’, you will run the following command:

mysql> create database vitux;

More, you can grant prvillages to users using the following command:

mysql> GRANT ALL ON vitux.* TO [email protected] IDENTIFIED BY 'kbuzdar123';

If you want to close the MySQL command line environment then simple you will write the following command that will switch to a normal shell.

mysql> exit

Conclusion

In this article, you have learned how to install MySQL server 8 on CentOS 8 system. I hope you liked this article and would be useful for you in the future. Please give us your feedback via comments in the comment box.

How to Install MySQL 8 on CentOS 8
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.