Linux CentOS7にMySQL 8.0をインストールする手順

スポンサーリンク
Linux

手頃なRDBMSといえばみんな大好きMySQLです。今回はLinux(CentOS7)に、MySQL8.0をインストールする手順を紹介します。

※MySQL5.7のインストール方法については以下の記事を参照してください。

対象OS

今回はCentOS7.6にインストールします。

[root@cent76 ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

対象MySQLバージョン

Ver 8.0.19 for Linux on x86_64

MySQL8.0のRPMファイルをダウンロード

まずは、MySQLのRPMファイルをダウンロードするために以下のサイトへ行きます。

https://dev.mysql.com/downloads/mysql/

 

  1. 今回インストールするOSはCentOSなので、[Red Hat Enterprise Linux / Oracle Linux ]を選択。
  2. バージョンはCentOS7なので、[Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)]を選択。
  3. RPM Bundle(MySQLのRPM達をtarで固めたファイル)をDownloadします。

ログインはせずに、[No thanks, just start my download.]をクリックしてMySQL RPM Bundleファイルをダウンロードします。

MySQL8.0のRPM Bundleの配置と解凍

ダウンロードしたRPM Bundleファイルをサーバにコピーし、tarで解凍します。

今回はサーバの /usr/local/ ディレクトリ配下にファイルをコピーしました。

[root@cent76 local]# cd /usr/local/
[root@cent76 local]# ls -l mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 root root 765306880 Jan 17 23:28 mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
[root@cent76 local]# tar xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.19-1.el7.x86_64.rpm
mysql-community-server-8.0.19-1.el7.x86_64.rpm
mysql-community-test-8.0.19-1.el7.x86_64.rpm
mysql-community-common-8.0.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.19-1.el7.x86_64.rpm
mysql-community-devel-8.0.19-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm
mysql-community-libs-8.0.19-1.el7.x86_64.rpm

RPMファイルがあることを確認します。

[root@cent76 local]# ls -l mysql*.rpm
-rw-r--r-- 1 7155 31415  43126424 Dec 10 21:59 mysql-community-client-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    619248 Dec 10 21:59 mysql-community-common-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   7421828 Dec 10 21:59 mysql-community-devel-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  23691824 Dec 10 21:59 mysql-community-embedded-compat-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   4212908 Dec 10 21:59 mysql-community-libs-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   1365572 Dec 10 21:59 mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 457272180 Dec 10 22:00 mysql-community-server-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 227581052 Dec 10 22:01 mysql-community-test-8.0.19-1.el7.x86_64.rpm

MySQLインストール前に不要なRPMの削除

CentOS7からMariaDBが標準のDBになっているので、MariaDBのライブラリを削除しないとMySQLはインストールできません。

[root@cent76 local]# rpm -qa |grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64

yum removeコマンドで関連パッケージと共に削除します。

[root@cent76 local]# yum remove mariadb-libs
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-7.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                      Arch                   Version                            Repository                 Size
========================================================================================================================
Removing:
 mariadb-libs                 x86_64                 1:5.5.60-1.el7_5                   @anaconda                 4.4 M
Removing for dependencies:
 postfix                      x86_64                 2:2.10.1-7.el7                     @anaconda                  12 M

Transaction Summary
========================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-7.el7.x86_64                                                                        1/2
  Erasing    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                 2/2
  Verifying  : 2:postfix-2.10.1-7.el7.x86_64                                                                        1/2
  Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                 2/2

Removed:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5

Dependency Removed:
  postfix.x86_64 2:2.10.1-7.el7

Complete!

MySQL8.0のインストール

yum localinstallコマンドでアップロードしたMySQL8.0のRPMをインストールします。

[root@cent76 local]# yum localinstall mysql-community-*
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-client-8.0.19-1.el7.x86_64.rpm: mysql-community-client-8.0.19-1.el7.x86_64
Marking mysql-community-client-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-common-8.0.19-1.el7.x86_64.rpm: mysql-community-common-8.0.19-1.el7.x86_64
Marking mysql-community-common-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-devel-8.0.19-1.el7.x86_64.rpm: mysql-community-devel-8.0.19-1.el7.x86_64
Marking mysql-community-devel-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-embedded-compat-8.0.19-1.el7.x86_64.rpm: mysql-community-embedded-compat-8.0.19-1.el7.x86_64
Marking mysql-community-embedded-compat-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-libs-8.0.19-1.el7.x86_64.rpm: mysql-community-libs-8.0.19-1.el7.x86_64
Marking mysql-community-libs-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm: mysql-community-libs-compat-8.0.19-1.el7.x86_64
Marking mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-server-8.0.19-1.el7.x86_64.rpm: mysql-community-server-8.0.19-1.el7.x86_64
Marking mysql-community-server-8.0.19-1.el7.x86_64.rpm to be installed
Examining mysql-community-test-8.0.19-1.el7.x86_64.rpm: mysql-community-test-8.0.19-1.el7.x86_64
Marking mysql-community-test-8.0.19-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.19-1.el7 will be installed
---> Package mysql-community-common.x86_64 0:8.0.19-1.el7 will be installed
---> Package mysql-community-devel.x86_64 0:8.0.19-1.el7 will be installed
--> Processing Dependency: pkgconfig(openssl) for package: mysql-community-devel-8.0.19-1.el7.x86_64
Loading mirror speeds from cached hostfile
 * c7-media:
---> Package mysql-community-embedded-compat.x86_64 0:8.0.19-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.19-1.el7 will be installed
---> Package mysql-community-libs-compat.x86_64 0:8.0.19-1.el7 will be installed
---> Package mysql-community-server.x86_64 0:8.0.19-1.el7 will be installed
---> Package mysql-community-test.x86_64 0:8.0.19-1.el7 will be installed
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-test-8.0.19-1.el7.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-test-8.0.19-1.el7.x86_64
--> Processing Dependency: perl(JSON) for package: mysql-community-test-8.0.19-1.el7.x86_64
--> Processing Dependency: perl(JSON) for package: mysql-community-test-8.0.19-1.el7.x86_64
--> Running transaction check
---> Package openssl-devel.x86_64 1:1.0.2k-16.el7 will be installed
--> Processing Dependency: zlib-devel(x86-64) for package: 1:openssl-devel-1.0.2k-16.el7.x86_64
--> Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.2k-16.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
---> Package perl-JSON.noarch 0:2.59-2.el7 will be installed
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.15.1-34.el7 will be installed
--> Processing Dependency: libkadm5(x86-64) = 1.15.1-34.el7 for package: krb5-devel-1.15.1-34.el7.x86_64
--> Processing Dependency: libverto-devel for package: krb5-devel-1.15.1-34.el7.x86_64
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.15.1-34.el7.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.15.1-34.el7.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.15.1-34.el7.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-18.el7 will be installed
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.5.8-3.el7 will be installed
---> Package libcom_err-devel.x86_64 0:1.42.9-13.el7 will be installed
---> Package libkadm5.x86_64 0:1.15.1-34.el7 will be installed
---> Package libselinux-devel.x86_64 0:2.5-14.1.el7 will be installed
--> Processing Dependency: libsepol-devel(x86-64) >= 2.5-10 for package: libselinux-devel-2.5-14.1.el7.x86_64
--> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.5-14.1.el7.x86_64
--> Processing Dependency: pkgconfig(libpcre) for package: libselinux-devel-2.5-14.1.el7.x86_64
---> Package libverto-devel.x86_64 0:0.2.5-4.el7 will be installed
--> Running transaction check
---> Package libsepol-devel.x86_64 0:2.5-10.el7 will be installed
---> Package pcre-devel.x86_64 0:8.32-17.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                          Arch    Version           Repository                                             Size
========================================================================================================================
Installing:
 mysql-community-client           x86_64  8.0.19-1.el7      /mysql-community-client-8.0.19-1.el7.x86_64           191 M
 mysql-community-common           x86_64  8.0.19-1.el7      /mysql-community-common-8.0.19-1.el7.x86_64           8.6 M
 mysql-community-devel            x86_64  8.0.19-1.el7      /mysql-community-devel-8.0.19-1.el7.x86_64             48 M
 mysql-community-embedded-compat  x86_64  8.0.19-1.el7      /mysql-community-embedded-compat-8.0.19-1.el7.x86_64   90 M
 mysql-community-libs             x86_64  8.0.19-1.el7      /mysql-community-libs-8.0.19-1.el7.x86_64              19 M
 mysql-community-libs-compat      x86_64  8.0.19-1.el7      /mysql-community-libs-compat-8.0.19-1.el7.x86_64      6.4 M
 mysql-community-server           x86_64  8.0.19-1.el7      /mysql-community-server-8.0.19-1.el7.x86_64           1.9 G
 mysql-community-test             x86_64  8.0.19-1.el7      /mysql-community-test-8.0.19-1.el7.x86_64             579 M
Installing for dependencies:
 keyutils-libs-devel              x86_64  1.5.8-3.el7       c7-media                                               37 k
 krb5-devel                       x86_64  1.15.1-34.el7     c7-media                                              271 k
 libcom_err-devel                 x86_64  1.42.9-13.el7     c7-media                                               31 k
 libkadm5                         x86_64  1.15.1-34.el7     c7-media                                              177 k
 libselinux-devel                 x86_64  2.5-14.1.el7      c7-media                                              187 k
 libsepol-devel                   x86_64  2.5-10.el7        c7-media                                               77 k
 libverto-devel                   x86_64  0.2.5-4.el7       c7-media                                               12 k
 openssl-devel                    x86_64  1:1.0.2k-16.el7   c7-media                                              1.5 M
 pcre-devel                       x86_64  8.32-17.el7       c7-media                                              480 k
 perl-Data-Dumper                 x86_64  2.145-3.el7       c7-media                                               47 k
 perl-JSON                        noarch  2.59-2.el7        c7-media                                               96 k
 zlib-devel                       x86_64  1.2.7-18.el7      c7-media                                               50 k

Transaction Summary
========================================================================================================================
Install  8 Packages (+12 Dependent packages)

Total size: 2.8 G
Total download size: 2.9 M
Installed size: 2.9 G
Is this ok [y/d/N]: y
Downloading packages:
warning: /media/cdrom/Packages/keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm is not installed
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   1.5 MB/s | 2.9 MB  00:00:01
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-8.0.19-1.el7.x86_64                                                          1/20
  Installing : mysql-community-libs-8.0.19-1.el7.x86_64                                                            2/20
  Installing : mysql-community-client-8.0.19-1.el7.x86_64                                                          3/20
  Installing : mysql-community-server-8.0.19-1.el7.x86_64                                                          4/20
  Installing : libkadm5-1.15.1-34.el7.x86_64                                                                       5/20
  Installing : libcom_err-devel-1.42.9-13.el7.x86_64                                                               6/20
  Installing : libsepol-devel-2.5-10.el7.x86_64                                                                    7/20
  Installing : pcre-devel-8.32-17.el7.x86_64                                                                       8/20
  Installing : libselinux-devel-2.5-14.1.el7.x86_64                                                                9/20
  Installing : keyutils-libs-devel-1.5.8-3.el7.x86_64                                                             10/20
  Installing : libverto-devel-0.2.5-4.el7.x86_64                                                                  11/20
  Installing : krb5-devel-1.15.1-34.el7.x86_64                                                                    12/20
  Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                                                13/20
  Installing : perl-JSON-2.59-2.el7.noarch                                                                        14/20
  Installing : zlib-devel-1.2.7-18.el7.x86_64                                                                     15/20
  Installing : 1:openssl-devel-1.0.2k-16.el7.x86_64                                                               16/20
  Installing : mysql-community-devel-8.0.19-1.el7.x86_64                                                          17/20
  Installing : mysql-community-test-8.0.19-1.el7.x86_64                                                           18/20
  Installing : mysql-community-libs-compat-8.0.19-1.el7.x86_64                                                    19/20
  Installing : mysql-community-embedded-compat-8.0.19-1.el7.x86_64                                                20/20
  Verifying  : krb5-devel-1.15.1-34.el7.x86_64                                                                     1/20
  Verifying  : zlib-devel-1.2.7-18.el7.x86_64                                                                      2/20
  Verifying  : perl-JSON-2.59-2.el7.noarch                                                                         3/20
  Verifying  : mysql-community-libs-8.0.19-1.el7.x86_64                                                            4/20
  Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                 5/20
  Verifying  : 1:openssl-devel-1.0.2k-16.el7.x86_64                                                                6/20
  Verifying  : libverto-devel-0.2.5-4.el7.x86_64                                                                   7/20
  Verifying  : mysql-community-libs-compat-8.0.19-1.el7.x86_64                                                     8/20
  Verifying  : mysql-community-client-8.0.19-1.el7.x86_64                                                          9/20
  Verifying  : mysql-community-test-8.0.19-1.el7.x86_64                                                           10/20
  Verifying  : mysql-community-devel-8.0.19-1.el7.x86_64                                                          11/20
  Verifying  : keyutils-libs-devel-1.5.8-3.el7.x86_64                                                             12/20
  Verifying  : pcre-devel-8.32-17.el7.x86_64                                                                      13/20
  Verifying  : libselinux-devel-2.5-14.1.el7.x86_64                                                               14/20
  Verifying  : mysql-community-common-8.0.19-1.el7.x86_64                                                         15/20
  Verifying  : mysql-community-server-8.0.19-1.el7.x86_64                                                         16/20
  Verifying  : mysql-community-embedded-compat-8.0.19-1.el7.x86_64                                                17/20
  Verifying  : libsepol-devel-2.5-10.el7.x86_64                                                                   18/20
  Verifying  : libcom_err-devel-1.42.9-13.el7.x86_64                                                              19/20
  Verifying  : libkadm5-1.15.1-34.el7.x86_64                                                                      20/20

Installed:
  mysql-community-client.x86_64 0:8.0.19-1.el7           mysql-community-common.x86_64 0:8.0.19-1.el7
  mysql-community-devel.x86_64 0:8.0.19-1.el7            mysql-community-embedded-compat.x86_64 0:8.0.19-1.el7
  mysql-community-libs.x86_64 0:8.0.19-1.el7             mysql-community-libs-compat.x86_64 0:8.0.19-1.el7
  mysql-community-server.x86_64 0:8.0.19-1.el7           mysql-community-test.x86_64 0:8.0.19-1.el7

Dependency Installed:
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7                     krb5-devel.x86_64 0:1.15.1-34.el7
  libcom_err-devel.x86_64 0:1.42.9-13.el7                      libkadm5.x86_64 0:1.15.1-34.el7
  libselinux-devel.x86_64 0:2.5-14.1.el7                       libsepol-devel.x86_64 0:2.5-10.el7
  libverto-devel.x86_64 0:0.2.5-4.el7                          openssl-devel.x86_64 1:1.0.2k-16.el7
  pcre-devel.x86_64 0:8.32-17.el7                              perl-Data-Dumper.x86_64 0:2.145-3.el7
  perl-JSON.noarch 0:2.59-2.el7                                zlib-devel.x86_64 0:1.2.7-18.el7

Complete!

MySQL8.0の起動

systemctlコマンドでMySQLを起動します。

[root@cent76 local]# systemctl start mysqld.service

MySQLのrootユーザの初期パスワード変更

mysqld.logからMySQLのrootユーザ初期パスワードを確認します。

[root@cent76 local]# grep 'temporary password' /var/log/mysqld.log
2020-01-17T01:52:41.170146Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vKrpCEjjo4;5

MySQLのrootユーザで接続します。パスワードは初期パスワードを入力してください。

[root@cent76 local]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

Copyright (c) 2000, 2020, 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>

※初期パスワードを変更しないとデータベースの操作が何も出来ず、以下のメッセージでパスワード変更を促されます。

mysql> select user,host from mysql.user;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

rootユーザの初期パスワードを変更します。

mysql> ALTER USER 'root'@'localhost' identified BY 'dekiruMySQL8#';
Query OK, 0 rows affected (0.56 sec)

パスワードを変更するとデータベースの操作ができるようになります。

mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

動作確認

試しにCreate Databaseしてみます。

mysql> create database dekirudb;
Query OK, 1 row affected (0.30 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| dekirudb           |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)