Dragon Arrow written by Tatsuya Nakaji, all rights reserved animated-dragon-image-0164

EC2に入れたMySQL5.6を8.0にする

updated on 2019-05-21

EC2仮想サーバーに入れたMySQL5.6を8.0にする


現在, 仮想サーバーに入れたMySQLは以下の通り5.7です。

[tatsuya@ip-10-0-0-238 ~]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.26 MySQL Community Server (GPL)


初めに...MySQL8.0を入れてみる

[tatsuya@ip-10-0-0-238 rails] $sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm

https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm を取得中
エラー: 依存性の欠如:
mysql57-community-release は mysql80-community-release-el7-2.noarch と競合します。

MySQL5.7がすでに入っていて、新たに入れようとしているMySQL8.0と競合を起こすとエラーが出ています。

$ yum list installed | grep mysql でインストール済みのmysqlを確認できる

MySQL5.6を一旦アンインストールする

[tatsuya@ip-10-0-0-238 /]$ sudo yum remove mysql
[sudo] tatsuya のパスワード:
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ mysql-community-client.x86_64 0:5.7.26-1.el7 を 削除
--> 依存性の処理をしています: mysql-community-client(x86-64) >= 5.7.9 のパッケージ: mysql-community-server-5.7.26-1.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ mysql-community-server.x86_64 0:5.7.26-1.el7 を 削除
--> 依存性解決を終了しました。
amzn2-core/2/x86_64                                      | 2.4 kB     00:00     
...
依存性を解決しました
[tatsuya@ip-10-0-0-238 /]$ sudo rm -rf /var/lib/mysql
[tatsuya@ip-10-0-0-238 /]$ sudo yum remove mysql*
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ mysql-community-common.x86_64 0:5.7.26-1.el7 を 削除
---> パッケージ mysql-community-devel.x86_64 0:5.7.26-1.el7 を 削除
---> パッケージ mysql-community-libs.x86_64 0:5.7.26-1.el7 を 削除
---> パッケージ mysql57-community-release.noarch 0:el7-10 を 削除
--> 依存性解決を終了しました。

...
依存性を解決しました


MySQL8.0を入れる

[tatsuya@ip-10-0-0-238 /]$ sudo  rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm を取得中
準備しています...              ################################# [100%]
更新中 / インストール中...
   1:mysql80-community-release-el7-1  ################################# [100%]
[tatsuya@ip-10-0-0-238 /]$ sudo  yum -y install mysql-community-server mysql-devel
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
mysql80-community                                        | 2.5 kB     00:00     
mysql80-community/x86_64/primary_db                        |  70 kB   00:00     
200 packages excluded due to repository priority protections
依存性の解決をしています
...
--> 依存性解決を終了しました。
依存性を解決しました

ロックファイル /var/run/yum.pid が存在します: PID 5633 として別に実行されています。みたいなエラーが出たら...

[tatsuya@ip-10-0-0-238 /]$ sudo rm -rf /var/run/yum.pid


MySQL初期設定

[tatsuya@ip-10-0-0-238 /]$ sudo  systemctl start mysqld.service
[tatsuya@ip-10-0-0-238 /]$ sudo  systemctl enable mysqld.service
[tatsuya@ip-10-0-0-238 /]$ grep password /var/log/mysqld.log
2019-05-21T03:09:44.809223Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ##########(臨時パスワード)
[tatsuya@ip-10-0-0-238 /]$ 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
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) : 
 ... skipping.
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) : 
 ... skipping.
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) : 
 ... skipping.
All done!


発行したパスワードでログインしてみる

[tatsuya@ip-10-0-0-238 /]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.16 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> select version();
+-----------+
| version() |
+-----------+
| 8.0.16    |
+-----------+
1 row in set (0.00 sec)