This guide is to help you with the installation of MySQL 8 Server on CentOS 7 Linux system. MySQL 8 is the latest release of powerful MySQL database management system. It powers many enterprise applications, websites and transactional real-time systems.

To start installing MySQL 8.0 server on CentOS 7, you need to add the official MySQL community repository to your system. Run below commands to add it,

sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

Press y key to proceed with the installation:

....
Dependencies Resolved

======================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing:
mysql80-community-release noarch el7-1 /mysql80-community-release-el7-1.noarch 31 k

Transaction Summary
======================================================================================================================================================================================================
Install 1 Package

Total size: 31 k
Installed size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql80-community-release-el7-1.noarch 1/1
Verifying : mysql80-community-release-el7-1.noarch 1/1

Installed:
mysql80-community-release.noarch 0:el7-1

Complete!

Installing MySQL 8 on CentOS 7 Linux System

Now that repo is added, you can install MysQL 8 without editing repository content since repo for 8 is enabled by default.

sudo yum --enablerepo=mysql80-community install mysql-community-server

A number of dependencies are installed automatically for you:

....
Dependencies Resolved

======================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing:
mysql-community-libs x86_64 8.0.26-1.el7 mysql80-community 4.0 M
replacing mariadb-libs.x86_64 1:5.5.65-1.el7
mysql-community-libs-compat x86_64 8.0.26-1.el7 mysql80-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.65-1.el7
mysql-community-server x86_64 8.0.26-1.el7 mysql80-community 434 M
Installing for dependencies:
libaio x86_64 0.3.109-13.el7 base 24 k
mysql-community-client x86_64 8.0.26-1.el7 mysql80-community 46 M
mysql-community-client-plugins x86_64 8.0.26-1.el7 mysql80-community 4.5 M
mysql-community-common x86_64 8.0.26-1.el7 mysql80-community 620 k
perl x86_64 4:5.16.3-299.el7_9 updates 8.0 M
perl-Carp noarch 1.26-244.el7 base 19 k
perl-Encode x86_64 2.51-7.el7 base 1.5 M
perl-Exporter noarch 5.68-3.el7 base 28 k
perl-File-Path noarch 2.09-2.el7 base 26 k
perl-File-Temp noarch 0.23.01-3.el7 base 56 k
perl-Filter x86_64 1.49-3.el7 base 76 k
perl-Getopt-Long noarch 2.40-3.el7 base 56 k
perl-HTTP-Tiny noarch 0.033-3.el7 base 38 k
perl-PathTools x86_64 3.40-5.el7 base 82 k
perl-Pod-Escapes noarch 1:1.04-299.el7_9 updates 52 k
perl-Pod-Perldoc noarch 3.20-4.el7 base 87 k
perl-Pod-Simple noarch 1:3.28-4.el7 base 216 k
perl-Pod-Usage noarch 1.63-3.el7 base 27 k
perl-Scalar-List-Utils x86_64 1.27-248.el7 base 36 k
perl-Socket x86_64 2.010-5.el7 base 49 k
perl-Storable x86_64 2.45-3.el7 base 77 k
perl-Text-ParseWords noarch 3.29-4.el7 base 14 k
perl-Time-HiRes x86_64 4:1.9725-3.el7 base 45 k
perl-Time-Local noarch 1.2300-2.el7 base 24 k
perl-constant noarch 1.27-2.el7 base 19 k
perl-libs x86_64 4:5.16.3-299.el7_9 updates 690 k
perl-macros x86_64 4:5.16.3-299.el7_9 updates 44 k
perl-parent noarch 1:0.225-244.el7 base 12 k
perl-podlators noarch 2.5.1-3.el7 base 112 k
perl-threads x86_64 1.87-4.el7 base 49 k
perl-threads-shared x86_64 1.43-6.el7 base 39 k

Transaction Summary
======================================================================================================================================================================================================
Install 3 Packages (+31 Dependent packages)

Total download size: 501 M
Is this ok [y/d/N]: y

Installing MySQL 5.7 on CentOS 7 Linux System

To install MySQL 5.7, you need to disable pository then download it.

sudo yum --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server

Starting MySQL 8 Service on CentOS 7

For CentOS 7, use systemd to start mysql service:

sudo systemctl enable  --now mysqld.service

Confirm that service status return as running:

$ systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-09-29 19:46:31 UTC; 13s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 9114 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 9192 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─9192 /usr/sbin/mysqld

Sep 29 19:46:24 centos systemd[1]: Starting MySQL Server...
Sep 29 19:46:31 centos systemd[1]: Started MySQL Server.

To restart the service use the command:

sudo systemctl restart mysqld.service

Set MySQL root password

Installation of MySQL 8.0 on CentOS 7 generates a temporary password for you. You can get it by running:

grep 'A temporary password is generated for root@localhost' /var/log/mysqld.log |tail -1

It will look like below:

2021-09-29T19:46:27.745095Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3F24r/ik%pTd

Change mysql root user password and secure database server installation:

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 3F24r/ik%pTd

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!

Configure Firewall if Database Server is accessed remotely

With iptables:

sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
sudo service iptables restartt

Firewalld:

sudo firewall-cmd --add-service mysql --permanent
sudo firewall-cmd --reload

Test your settings:

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.26 |
+-----------+
1 row in set (0.00 sec)

mysql> quit
Bye

We have successfully installed MySQL 8.0 on CentOS 7 Linux System. We also secured the database server by setting root password, removing test database and disabling remote root user logins to the database server.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ComputingPost

ComputingPost — Linux Howtos, Tutorials, Guides, News, Tips and Tricks.