MySQL Installation on RHEL Linux Using RPM Packages


In this article, we’ll guide you through the process of installing MySQL on a Linux RHEL system using RPM packages. Follow along as we provide step-by-step instructions to help you set up a MySQL database quickly and efficiently. Whether you’re new to database management or a seasoned administrator, this comprehensive tutorial will simplify the installation process and have you up and running with MySQL in no time. Let’s dive in!

1. Create folders for the data directory and RPM packages.

[root@localhost /]# mkdir data
[root@localhost /]#
[root@localhost /]# cd data/
[root@localhost data]#
[root@localhost data]# mkdir rpm_pack
[root@localhost data]#
[root@localhost data]# mkdir mysql
[root@localhost data]#
[root@localhost data]# cd mysql/
[root@localhost mysql]#
[root@localhost mysql]# mkdir data
[root@localhost mysql]#
[root@localhost mysql]#

2. Download & Extract the MySQL RPM packages

                        Link:- https://dev.mysql.com/downloads/mysql/

                  Note: You can download older versions from the archival package
[root@localhost rpm_pack]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
--2024-05-23 01:19:46--  https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
Resolving dev.mysql.com (dev.mysql.com)... 104.122.98.3, 2600:140f:1e00:486::2e31, 2600:140f:1e00:4b2::2e31
Connecting to dev.mysql.com (dev.mysql.com)|104.122.98.3|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar [following]
--2024-05-23 01:19:47--  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
Resolving cdn.mysql.com (cdn.mysql.com)... 104.122.108.203, 2600:140f:1e00:4b2::1d68, 2600:140f:1e00:4aa::1d68
Connecting to cdn.mysql.com (cdn.mysql.com)|104.122.108.203|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1043773440 (995M) [application/x-tar]
Saving to: ‘mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar’

100%[=================================================================================================================>] 1,043,773,440 10.5MB/s   in 2m 8s

2024-05-23 01:21:55 (7.79 MB/s) - ‘mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar’ saved [1043773440/1043773440]

[root@localhost rpm_pack]# ll
total 1019312
-rw-r--r--. 1 root root 1043773440 Mar 31 08:08 mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
[root@localhost rpm_pack]#
[root@localhost rpm_pack]# ll
total 1019312
-rw-r--r--. 1 root root 1043773440 Mar 31 08:08 mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
[root@localhost rpm_pack]#
[root@localhost rpm_pack]# tar -xvf mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.37-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.37-1.el7.x86_64.rpm
mysql-community-common-8.0.37-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.37-1.el7.x86_64.rpm
mysql-community-devel-8.0.37-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.37-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.37-1.el7.x86_64.rpm
mysql-community-libs-8.0.37-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.37-1.el7.x86_64.rpm
mysql-community-server-8.0.37-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.37-1.el7.x86_64.rpm
mysql-community-test-8.0.37-1.el7.x86_64.rpm
[root@localhost rpm_pack]#
[root@localhost rpm_pack]# ll
total 2038628
-rw-r--r--. 1 root root  1043773440 Mar 31 08:08 mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415   16768148 Mar 31 07:51 mysql-community-client-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    3621444 Mar 31 07:52 mysql-community-client-plugins-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415     681816 Mar 31 07:52 mysql-community-common-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  538409072 Mar 31 07:53 mysql-community-debuginfo-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    1948516 Mar 31 07:53 mysql-community-devel-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    4218268 Mar 31 07:53 mysql-community-embedded-compat-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    2344724 Mar 31 07:53 mysql-community-icu-data-files-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    1564000 Mar 31 07:53 mysql-community-libs-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415     685676 Mar 31 07:53 mysql-community-libs-compat-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   67951180 Mar 31 07:54 mysql-community-server-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   25689952 Mar 31 07:54 mysql-community-server-debug-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  379877568 Mar 31 07:56 mysql-community-test-8.0.37-1.el7.x86_64.rpm
[root@localhost rpm_pack]#

3. Install the RPM packages one by one.

                      [root@localhost rpm_pack]# yum remove mariadb-libs
[root@localhost rpm_pack]# rpm -ivh mysql-community-common-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.37-1.e################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-client-plugins-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-client-plugins-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-plugins-8.################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-libs-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.0.37-1.el7################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-libs-compat-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-compat-8.0.3################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-client-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.0.37-1.e################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-icu-data-files-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-icu-data-files-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-icu-data-files-8.################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-server-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.37-1.e################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-server-debug-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-server-debug-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-debug-8.0.################################# [100%]

[root@localhost rpm_pack]# rpm -ivh mysql-community-embedded-compat-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-embedded-compat-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-embedded-compat-8################################# [100%]

         Note: The following packages are optional and not necessary to install.

[root@localhost rpm_pack]# rpm -ivh mysql-community-debuginfo-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-debuginfo-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-debuginfo-8.0.37-################################# [100%]

4. Set up the configuration file.

                           configuration file path:- /etc/my.cnf
configuration file setting:- 

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/data/mysql/data
socket=/data/mysql/data/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

innodb_buffer_pool_size=1G

bind-address = 0.0.0.0

port = 3306

lower_case_table_names=1

[client]

socket=/data/mysql/data/mysql.sock
port = 3306

5. Change the ownership of the data directory and log file to mysql if it is not already set to mysql.

[root@localhost /]# chown mysql:mysql -R /data/
[root@localhost /]#
[root@localhost /]# ll
total 28
lrwxrwxrwx.   1 root    root           7 May 19 08:27 bin -> usr/bin
dr-xr-xr-x.   5 root    root        4096 May 19 09:26 boot
drwxr-xr-x.   4 mysql   mysql         35 May 23 00:58 data
drwxr-xr-x.  19 root    root        3260 May 23 00:33 dev
drwxr-xr-x. 144 root    root        8192 May 23 02:15 etc
drwxr-xr-x.   4 root    root          34 May 19 10:17 home
lrwxrwxrwx.   1 root    root           7 May 19 08:27 lib -> usr/lib
lrwxrwxrwx.   1 root    root           9 May 19 08:27 lib64 -> usr/lib64
drwxr-xr-x.   2 root    root           6 Apr 10  2018 media
drwxr-xr-x.   2 root    root           6 Apr 10  2018 mnt
drwxr-xr-x.   5 mongodb mongodb_grp   42 May 19 10:29 mongodb
drwxr-xr-x.   3 root    root          16 May 19 08:36 opt
dr-xr-xr-x. 211 root    root           0 May 23 00:33 proc
dr-xr-x---.   5 root    root         203 May 19 03:46 root
drwxr-xr-x.  44 root    root        1300 May 23 01:38 run
lrwxrwxrwx.   1 root    root           8 May 19 08:27 sbin -> usr/sbin
drwxr-xr-x.   2 root    root           6 Apr 10  2018 srv
dr-xr-xr-x.  13 root    root           0 May 23 00:33 sys
drwxrwxrwt.  43 root    root        4096 May 23 02:19 tmp
drwxr-xr-x.  13 root    root         155 May 19 08:27 usr
drwxr-xr-x.  21 root    root        4096 May 19 08:48 var
[root@localhost /]#
[root@localhost /]# cd /data/
[root@localhost data]# ll
total 4
drwxr-xr-x. 3 mysql mysql   18 May 23 00:58 mysql
drwxr-xr-x. 2 mysql mysql 4096 May 23 01:22 rpm_pack
[root@localhost data]# cd mysql/
[root@localhost mysql]#
[root@localhost mysql]# ll
total 0
drwxr-xr-x. 2 mysql mysql 6 May 23 00:58 data

6. Now start the mysqld service.

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-05-23 02:38:00 PDT; 27s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5343 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5429 (mysqld)
   Status: "Server is operational"
    Tasks: 41
   CGroup: /system.slice/mysqld.service
           └─5429 /usr/sbin/mysqld

May 23 02:37:35 localhost.localdomain systemd[1]: Starting MySQL Server...
May 23 02:38:00 localhost.localdomain systemd[1]: Started MySQL Server.
Note: If you encounter an error when starting the MySQL service, such as "permission denied" in the log file, you can disable the SELinux status.

[root@localhost ~]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled                                            <============= disabled the selinux
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

6. Set the password for the root user to login into the database, by default password.

                        first get default password from log file

[root@localhost ~]# cat /var/log/mysqld.log | grep password
2024-05-23T09:37:45.252425Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: R!a+dfo0aPx2
 command for set password:- ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.37

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@123';
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.37    |
+-----------+
1 row in set (0.00 sec)

mysql> select @@port;
+--------+
| @@port |
+--------+
|   3306 |
+--------+
1 row in set (0.01 sec)

mysql> SHOW VARIABLES LIKE 'datadir';
+---------------+-------------------+
| Variable_name | Value             |
+---------------+-------------------+
| datadir       | /data/mysql/data/ |
+---------------+-------------------+
1 row in set (0.32 sec)

In summary, you’ve achieved a production-ready MySQL installation on RHEL Linux using RPM packages. Now, you’re ready to leverage MySQL’s capabilities for your projects.

Similar Posts

One Comment

Leave a Reply

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