Share on Social Media

In this guide, you will learn, how to install MySQL on CentOS 7 or other Redhat based Linux OS. #centlinux #linux #mysql

What is MySQL? :

MySQL Server Community Edition (CE) is the free version of world’s most popular open source database server. It is distributed under GPL License and supported by a large and active community of open source developers. There is also a commercial version of MySQL server, which is developed and maintained by Oracle Corporation.

This article does not address the usage of MySQL commands and SQL statements. Therefore, if you wish to learn MySQL architecture, commands and SQL statements, then we recommend you to read Murach’s MySQL (3rd Edition) (PAID LINK) by Mike Murach & Associates.

Read Also: How to install MariaDB on Rocky Linux 9

MySQL Server 8 Community Edition Features:

Main features of MySQL Server CE are.

  • Supports SQL and NoSQL
  • Pluggable Storage Engine Architecture
  • MySQL Replication
  • MySQL InnoDB Cluster
  • MySQL Router
  • MySQL Partitioning
  • MySQL Workbench

Checkout complete list of MySQL Server 8 features at MySQL official website.

Environment Specification:

We have configured a CentOS 7 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 7.6
  • Hostname –
  • IP Address –

Install MySQL Yum Repository:

Connect with using ssh as root user.

Download and install MySQL yum repository from MySQL official website.

# rpm -ivh
warning: /var/tmp/rpm-tmp.fJdAIJ: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el7-3  ################################# [100%]

Build cache for MySQL yum repository.

# yum makecache fast
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base:
 * extras:
 * updates:
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
mysql-connectors-community                               | 2.5 kB     00:00
mysql-tools-community                                    | 2.5 kB     00:00
mysql80-community                                        | 2.5 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/5): mysql-connectors-community/x86_64/primary_db        |  41 kB   00:00
(2/5): mysql-tools-community/x86_64/primary_db             |  58 kB   00:00
(3/5): mysql80-community/x86_64/primary_db                 |  70 kB   00:01
(4/5): extras/7/x86_64/primary_db                          | 205 kB   00:01
(5/5): updates/7/x86_64/primary_db                         | 6.4 MB   00:15
Metadata Cache Created

Install MySQL on CentOS 7:

We have added the MySQL yum repository, now we can install MySQL on CentOS 7 and relevant packages using yum command.

# yum install -y mysql-community-server

MySQL service is automatically enabled by the installer. Therefore, we are only required to start mysqld.service once.

# systemctl start mysqld.service

During first start-up, MySQL service generates a temporary password in /var/log/mysqld.log file.

Retrieve this password using following command.

# grep 'temporary password' /var/log/mysqld.log
2019-06-24T14:23:17.605740Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: B4gqaLFg6p_Y

Note down this password, we will use it later.

Secure MySQL Server:

To configure and secure our MySQL database instance, we can use mysql_secure_installation command. We are also required to use temporary password to set a new password for root user.

# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...

 - Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

All done!

Connect with MySQL database server using mysql command as root user.

# 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.16 MySQL Community Edition - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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

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

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


We have successfully install MySQL on CentOS 7.


In this guide, you have learned, how to install MySQL on CentOS 7 or other Redhat based Linux OS.

Leave a Reply

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