×

MySQL is the most widely used open-source database management system, particularly in the area of application development. The main function of MySQL is to store and retrieve records and information.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related MySQL queries.

In this context, we shall look into 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.


Steps to install MySQL on your Red Hat Enterprise Linux system:

To begin, ensure that you have  sudo or root privileges for the Server.

The follow the steps given below.


1. 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


2. 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


3. How to 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


4. 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:

i. Set a new password

ii. Remove anonymous users

iii. Disallow root login remotely

iv. Remove test database

v. Reload the privilege tables


5. 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’, ‘Linux APT’, ‘IT’), (‘Human Resources’, ‘Jane Doe’, ‘HR’), (‘Digital Marketing’, ‘Ibmi Media’, ‘DMKT’);

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

mysql> SELECT * FROM departments;


How to 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*


[Need urgent help in setting up MYSQL configuration on your Linux Server ? We are available to help you today. ]


Conclusion

More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com