Contact

Blogs

Take a look at the things that interest us.

Install MySQL 8 on Centos 7

Wesley Wesley 2 years

In today's post, we are going to install MySQL 8 on our Centos 7 system.

Step 1. Mysql 8 repository

Let's begin with setting up the MySQL repository.

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

Step 2. Install MySQL 8

Since the MySQL repository has multiple MySQL versions, we'll need to disable all MySQL repositories and only enable the MySQL 8 repository.

sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo

Now let's enable and install MySQL 8.

yum --enablerepo=mysql80-community install mysql-community-server
# output
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                                       | 9.7 kB  00:00:00     
 * base: d36uatko69830t.cloudfront.net
 * epel: nrt.edge.kernel.org
 * extras: d36uatko69830t.cloudfront.net
 * remi-php72: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: d36uatko69830t.cloudfront.net
base                                                                                                                                                                                       | 3.6 kB  00:00:00     
epel                                                                                                                                                                                       | 4.7 kB  00:00:00     
extras                                                                                                                                                                                     | 2.9 kB  00:00:00     
mysql80-community                                                                                                                                                                          | 2.6 kB  00:00:00     
remi-php72                                                                                                                                                                                 | 3.0 kB  00:00:00     
remi-safe                                                                                                                                                                                  | 3.0 kB  00:00:00     
updates                                                                                                                                                                                    | 2.9 kB  00:00:00     
(1/6): epel/x86_64/group_gz                                                                                                                                                                |  95 kB  00:00:00     
(2/6): epel/x86_64/updateinfo                                                                                                                                                              | 1.0 MB  00:00:00     
(3/6): epel/x86_64/primary_db                                                                                                                                                              | 6.9 MB  00:00:00     
(4/6): mysql80-community/x86_64/primary_db                                                                                                                                                 | 128 kB  00:00:00     
(5/6): remi-php72/primary_db                                                                                                                                                               | 243 kB  00:00:00     
(6/6): remi-safe/primary_db                                                                                                                                                                | 1.8 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.22-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.22-1.el7 for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:8.0.22-1.el7 will be installed
--> Processing Dependency: mysql-community-client-plugins = 8.0.22-1.el7 for package: mysql-community-client-8.0.22-1.el7.x86_64
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.22-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.22-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: mysql-connector-odbc-5.2.5-8.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: mysql-connector-odbc-5.2.5-8.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
---> Package mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.22-1.el7 will be obsoleting
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.68-1.el7 will be obsoleted
---> Package mysql-community-devel.x86_64 0:8.0.22-1.el7 will be obsoleting
---> Package mysql-community-libs-compat.x86_64 0:8.0.22-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                         Arch                                    Version                                         Repository                                          Size
==================================================================================================================================================================================================================
Installing:
 mysql-community-devel                                           x86_64                                  8.0.22-1.el7                                    mysql80-community                                  8.1 M
     replacing  mariadb-devel.x86_64 1:5.5.68-1.el7
 mysql-community-libs                                            x86_64                                  8.0.22-1.el7                                    mysql80-community                                  4.6 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.el7
 mysql-community-libs-compat                                     x86_64                                  8.0.22-1.el7                                    mysql80-community                                  1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.el7
 mysql-community-server                                          x86_64                                  8.0.22-1.el7                                    mysql80-community                                  510 M
Installing for dependencies:
 libaio                                                          x86_64                                  0.3.109-13.el7                                  base                                                24 k
 mysql-community-client                                          x86_64                                  8.0.22-1.el7                                    mysql80-community                                   48 M
 mysql-community-client-plugins                                  x86_64                                  8.0.22-1.el7                                    mysql80-community                                  235 k
 mysql-community-common                                          x86_64                                  8.0.22-1.el7                                    mysql80-community                                  616 k

Transaction Summary
==================================================================================================================================================================================================================
Install  4 Packages (+4 Dependent packages)

Total download size: 572 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): libaio-0.3.109-13.el7.x86_64.rpm                                                                                                                                                    |  24 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm is not installed
(2/8): mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm                                                                                                                              | 235 kB  00:00:00     
(3/8): mysql-community-common-8.0.22-1.el7.x86_64.rpm                                                                                                                                      | 616 kB  00:00:00     
(4/8): mysql-community-devel-8.0.22-1.el7.x86_64.rpm                                                                                                                                       | 8.1 MB  00:00:00     
(5/8): mysql-community-libs-8.0.22-1.el7.x86_64.rpm                                                                                                                                        | 4.6 MB  00:00:00     
(6/8): mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm                                                                                                                                 | 1.2 MB  00:00:00     
(7/8): mysql-community-client-8.0.22-1.el7.x86_64.rpm                                                                                                                                      |  48 MB  00:00:01     
(8/8): mysql-community-server-8.0.22-1.el7.x86_64.rpm                                                                                                                                      | 510 MB  00:00:06     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                              79 MB/s | 572 MB  00:00:07     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql80-community-release-el7-3.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-8.0.22-1.el7.x86_64                                                                                                                                                    1/10 
  Installing : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                                                                                                                            2/10 
  Installing : mysql-community-libs-8.0.22-1.el7.x86_64                                                                                                                                                      3/10 
  Installing : mysql-community-client-8.0.22-1.el7.x86_64                                                                                                                                                    4/10 
  Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                                                                  5/10 
  Installing : mysql-community-server-8.0.22-1.el7.x86_64                                                                                                                                                    6/10 
  Installing : mysql-community-devel-8.0.22-1.el7.x86_64                                                                                                                                                     7/10 
  Installing : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                                                                                                                               8/10 
  Erasing    : 1:mariadb-devel-5.5.68-1.el7.x86_64                                                                                                                                                           9/10 
  Erasing    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                                           10/10 
  Verifying  : mysql-community-libs-8.0.22-1.el7.x86_64                                                                                                                                                      1/10 
  Verifying  : mysql-community-server-8.0.22-1.el7.x86_64                                                                                                                                                    2/10 
  Verifying  : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                                                                                                                            3/10 
  Verifying  : mysql-community-common-8.0.22-1.el7.x86_64                                                                                                                                                    4/10 
  Verifying  : mysql-community-devel-8.0.22-1.el7.x86_64                                                                                                                                                     5/10 
  Verifying  : mysql-community-client-8.0.22-1.el7.x86_64                                                                                                                                                    6/10 
  Verifying  : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                                                                                                                               7/10 
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                                                                  8/10 
  Verifying  : 1:mariadb-devel-5.5.68-1.el7.x86_64                                                                                                                                                           9/10 
  Verifying  : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                                           10/10 

Installed:
  mysql-community-devel.x86_64 0:8.0.22-1.el7       mysql-community-libs.x86_64 0:8.0.22-1.el7       mysql-community-libs-compat.x86_64 0:8.0.22-1.el7       mysql-community-server.x86_64 0:8.0.22-1.el7      

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7         mysql-community-client.x86_64 0:8.0.22-1.el7         mysql-community-client-plugins.x86_64 0:8.0.22-1.el7         mysql-community-common.x86_64 0:8.0.22-1.el7        

Replaced:
  mariadb-devel.x86_64 1:5.5.68-1.el7                                                                      mariadb-libs.x86_64 1:5.5.68-1.el7                                                                     

Step 3. Start MySQL Service

After the installation has been done, let's start and enable MySQL.

systemctl enable mysqld
systemctl start mysqld

Step 4. Get the default root user password for MySQL.

After installing MySQL 8, the root user account is created with a temporary password. Let's get the temporary password for the root user.

grep "A temporary password" /var/log/mysqld.log
# output
[Note] A temporary password is generated for root@localhost: thisismypassword

Note that your temporary password will be different. You'll need this password for setting up your root user account.

Step 5. MySQL Secure Installation

Let's set up the mysql_secure_installation to secure our MySQL server.

mysql_secure_installation

This will prompt you for the current password of the root account.

# ouput
Enter password for user root:

Enter the temporary password that you have got earlier [thisismypassword] and press Enter.

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

New password:
Re-enter new password:

You will need to enter the new password for the root‘s account twice. After this you'll see some questions, here it's recommended to type: y.

#output
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Step 6. Set mysql_native_password

In this step we'll need to update the mysql native password. Let's start mysql

mysql -u root -p

Write here the password that you have set for your root user.

# output
Enter password: 

After logging in into Mysql you'll have to run the following SQL query with your current MySQL password.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypasswordformysql';

After this you can close your MySQL connection.

Step 7. Restart MySQL

After setting up the mysql_secure_installation, we'll need to restart MySQL.

systemctl restart mysqld

MySQL 8 is now installed on Centos 7 and ready for use.

Install MySQL 8 on Centos 7 2021-08-24 08:03:40

There are no comments.

4985

Have questions about our services?

Contact our Sales team to get answers.

Contact Us
gomibako@aska-ltd.jp