Home » MySQL: Install MySQL 8.0 on Linux – CentOS 7

MySQL: Install MySQL 8.0 on Linux – CentOS 7

by Pring
MySQL: Install MySQL 8.0 on Linux - CentOS 7

I. Introduction.

This tutorial will teaches you how to install MySQL 8.0 on Linux – CentOS 7 server. MySQL 8 is the latest version available for the installation. MySQL is a most popular database server for Linux systems, it also supports a large number of platforms.

II. Prerequisites.

1.  Login to your system via SSH.  You can use PuTTy tool or Poderosa tool,…
2.  Login with root user.  If you are logged in as another user, you will need to add sudo before each command.

III. Install PHP on CentOS 7 by step by step.

To install MySQL 8.0 on Linux – CentOS 7. Follow these steps:
Step 1. Add MySQL Repository.
Step 2. Install MySQL 8.0 Community Server.
Step 3. Start MySQL Server.
Step 4. Find default root password.
Step 5. Secure MySQL server.
Step 6. Testing the Installation.
Step 7. Login to MySQL.

You can see details of Video on How to Install MySQL 8.0 on Linux – CentOS 7 as below.
[Sorry, the video we will update later]

Or you also can see details as below.

Step 1. Add MySQL Repository.

Enter command below:

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

Sample Output:

[root@devopsio ~]# yum install https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
mysql80-community-release-el7-2.noarch.rpm                              |  25 kB  00:00:00     
Examining /var/tmp/yum-root-TGq5Ho/mysql80-community-release-el7-2.noarch.rpm: mysql80-community-release-el7-2.noarch
Marking /var/tmp/yum-root-TGq5Ho/mysql80-community-release-el7-2.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================
 Package                     Arch     Version  Repository                                 Size
===============================================================================================
Installing:
 mysql80-community-release   noarch   el7-2    /mysql80-community-release-el7-2.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-2.noarch                                      1/1 
  Verifying  : mysql80-community-release-el7-2.noarch                                      1/1 

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

Complete!

To ensure sure the MySQL repository has been added and enabled. 

Enter command below:

sudo yum repolist all | grep mysql | grep enabled

Sample Output:

[root@devopsio ~]# yum repolist all | grep mysql | grep enabled
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:    118
mysql-tools-community/x86_64       MySQL Tools Community         enabled:     95
mysql80-community/x86_64           MySQL 8.0 Community Server    enabled:    129

Step 2. Install MySQL 8.0 Community Server.

Oracle offers version 8.0 and version 5.7. We use MySQL 8.0. Use yum command in CentOS to install the latest stable version.
Enter command below:

sudo yum -y install mysql-community-server

Sample Output:

[root@devopsio ~]# sudo yum -y install mysql-community-server
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.17-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================
 Package                      Arch         Version               Repository               Size
===============================================================================================
Installing:
 mysql-community-server       x86_64       8.0.17-1.el7          mysql80-community       415 M

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

Total download size: 415 M
Installed size: 1.8 G
Downloading packages:
mysql-community-server-8.0.17-1.el7.x86_64.rpm                          | 415 MB  00:00:25     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-server-8.0.17-1.el7.x86_64                                  1/1 
  Verifying  : mysql-community-server-8.0.17-1.el7.x86_64                                  1/1 

Installed:
  mysql-community-server.x86_64 0:8.0.17-1.el7                                                 

Complete!

Step 3. Start MySQL Server.

Enter command below:

sudo systemctl start mysqld

Enable MySQL server when start your server.
Enter command below:

sudo systemctl enable mysqld

Step 4. Find default root password.

With the installation of MySQL 8.0, a temporary password is created for the MySQL root user. You can find the temporary password generated in log files.
Note: temporary root password use in Step 5.
Enter command below:

sudo cat /var/log/mysqld.log | grep “A temporary password”

Sample Output:

[root@devopsio ~]# sudo cat /var/log/mysqld.log | grep "A temporary password"
2019-08-04T15:51:30.702596Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: L;y?!tr4qKPQ

Step 5. Secure MySQL server.

※ Note: In CentOS, initial MySQL root password can be found in /var/log/mysqld.log.
Setting the root password, removing anonymous users, disallow root login remotely,…
Enter command below.

sudo mysql_secure_installation

Sample Output:

[root@devopsio ~]# sudo 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 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

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! 

Step 6. Testing the Installation.

Enter command below:

sudo systemctl status mysqld

Sample Output:

[root@devopsio ~]# sudo systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-08-04 15:52:00 UTC; 11min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 6531 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─6531 /usr/sbin/mysqld

Aug 04 15:50:34 devopsio systemd[1]: Starting MySQL Server...
Aug 04 15:52:00 devopsio systemd[1]: Started MySQL Server.

Step 7. Login to MySQL.

Login to MySQL server with the root user and password.
Enter command below:

mysql -u root -p

Sample Output:

[root@devopsio ~]# 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.17 MySQL Community Server - 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.00 sec)

mysql> exit;
Bye
[root@devopsio ~]#

IV. Conclusion.

In this tutorial, we was install MySQL on CentOS 7 server. To learn more about using MySQL, this guide to learning more about MySQL.
You might want to check the following guides:

  • MySQL Share Blog
  • How to manage MySQL user accounts and databases
  • How to reset a MySQL root password
  • How to Create a MySQL Database
  • How to Create MySQL Users Accounts and Grant Privileges
  • How to Show MySQL Users
  • How to Back Up and Restore MySQL Databases with Mysqldump

Install MySQL on Linux – CentOS 7 is complete. Wish you success and luck.
Thanks and best regards!
— Pring —

Related Articles

Leave a Comment