How to install MySQL on CentOS 7

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 – mysql-server.example.com
  • IP Address – 192.168.116.180/24

Install MySQL Yum Repository:

Connect with mysql-server.example.com using ssh as root user.

Download and install MySQL yum repository from MySQL official website.

# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Retrieving https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
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: ftp3.isra.edu.pk
 * extras: ftp3.isra.edu.pk
 * updates: ftp3.isra.edu.pk
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
environment.

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


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

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


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

 - Removing privileges on test database...
Success.

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

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

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)

mysql>

We have successfully install MySQL on CentOS 7.

Conclusion:

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