Red Hat

How to Install MySQL Version 8 on Red Hat Enterprise Linux 8

Install MySQL Version 8 on Red Hat Enterprise Linux 8

MySQL is the most widely used open-source database management system, particularly in the area of application development. This guide describes how to install MySQL version 8 (the latest at the time of writing) via the MySQL yum repository on Red Hat Enterprise Linux (RHEL) 8.

Prerequisite

You need to have sudo or root privileges in order to install MySQL on your system.

Add the MySQL Yum Repository

First of all, run the command below to download the MySQL Yum repository package for RHEL 8.

$ wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

Next, install the downloaded MySQL Yum repository package as follows.

$ sudo yum install https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

Run the next command to verify that the MySQL Yum repository was successfully added.

$ yum repolist enabled | grep -i mysql

Install MySQL Version 8

Once the MySQL Yum repository has been successfully added, you may now install MySQL with the command below.

$ sudo yum install mysql-community-server

Note: If you get an error message indicating that a match could not be found for the mysql-community-server, then you may need to first run the next command to disable the MySQL module.

Apparently, this module hides packages provided by MySQL repositories. Once the MySQL module has been successfully disabled, you may run the previous command again to install MySQL.

$ sudo yum module disable mysql

After the installation completes successfully, run the command below to verify the version of MySQL.

$ mysql --version

Start the MySQL Server

Run the following command to start the MySQL server.

$ sudo systemctl start mysqld

Next, verify that the MySQL server started successfully with the command below

$ sudo systemctl status mysqld

Secure the MySQL Server

Run the command below to retrieve the temporary password that was automatically created during installation for the MySQL root user.

$ sudo grep 'temporary password' /var/log/mysqld.log

Next, run the mysql_secure_installation script with the command below.

$ sudo mysql_secure_installation

When prompted, enter the temporary password you retrieved in the previous step. You should be prompted to:

  1. Set a new password
  2. Remove anonymous users
  3. Disallow root login remotely
  4. Remove test database
  5. Reload the privilege tables

Login to MySQL

After the mysql_secure_installation script completes, you may now login to MySQL with the command below.

$ mysql -u root -p

Once logged in, let us create a sample database.

mysql> CREATE DATABASE company;
mysql> USE company;

Also, let us create a table as well as some records as follows.

mysql> CREATE TABLE departments ( dept_name varchar(25), dept_head varchar(25), dept_code char(7), PRIMARY KEY (dept_code) );
mysql> INSERT INTO departments VALUES (‘Information Technology’, ‘Olushola Akinye’, ‘IT’), (‘Human Resources’, ‘Jane Doe’, ‘HR’), (‘Digital Marketing’, ‘Peter Lagbaja’, ‘DMKT’);

Now, we can display all records in the department’s table with the following query.

mysql> SELECT * FROM departments;

Remove or Uninstall MySQL

If you would like to remove MySQL at any time, run the following command on the terminal.

sudo yum remove mysql-community*

Conclusion

If you followed all the steps above, you should now have a fully functioning MySQL server version 8 running on Red Hat Enterprise Linux 8. Feel free to reach out to us if anything is unclear or if you have any comments regarding this article.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *