読者です 読者をやめる 読者になる 読者になる

centos7にmysql5.7をインストールする

centos7にmysql5.7をいれる

DBが必要になったのでmysqlをインストールまでのメモです

mysqlがインストールできない

[vagrant@localhost ~]$ sudo yum -y install mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.jaist.ac.jp
 * extras: www.ftp.ne.jp
 * remi-safe: repo1.sea.innoscale.net
 * updates: www.ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1:mariadb-5.5.52-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                          Arch                       Version                               Repository                Size
==================================================================================================================================
Installing:
 mariadb                          x86_64                     1:5.5.52-1.el7                        base                     8.7 M
Installing for dependencies:
 mariadb-libs                     x86_64                     1:5.5.52-1.el7                        base                     761 k

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

Total download size: 9.5 M
Installed size: 53 M
Downloading packages:
(1/2): mariadb-libs-5.5.52-1.el7.x86_64.rpm                                                                | 761 kB  00:00:00
(2/2): mariadb-5.5.52-1.el7.x86_64.rpm                                                                     | 8.7 MB  00:00:11
----------------------------------------------------------------------------------------------------------------------------------
Total                                                                                             871 kB/s | 9.5 MB  00:00:11
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                             1/2
  Installing : 1:mariadb-5.5.52-1.el7.x86_64                                                                                  2/2
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                                                                  1/2
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                             2/2

Installed:
  mariadb.x86_64 1:5.5.52-1.el7

Dependency Installed:
  mariadb-libs.x86_64 1:5.5.52-1.el7

Complete!

なぜかmariaDBがインストールされる

CentOS7にはデフォルトでmariaDBというのがはいっているとのこと
なのでそちらが優先でインストールされちゃうのかな
mariaDBmysqlは競合を起こすようなのでmysqlを入れる場合はmariaDBを削除する

一応確認
[vagrant@localhost ~]$ rpm -qa | grep -i "mariadb"
mariadb-libs-5.5.52-1.el7.x86_64
mariaDBを削除する
[vagrant@localhost ~]sudo yum -y remove mariadb-libs
古いmysqlがあったら削除する
[vagrant@localhost ~]rm -rf /var/lib/mysql/
リポジトリをインストールする
[vagrant@localhost ~]$wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
-bash: wget: command not found
wgetがないのでインストールする
[vagrant@localhost ~]$sudo yum -y install wget
再度実行
[vagrant@localhost ~]$ wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2017-03-27 10:04:49--  https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm [following]
--2017-03-27 10:04:50--  https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 114.179.154.109
Connecting to repo.mysql.com (repo.mysql.com)|114.179.154.109|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[========================================================================================>] 9,224       --.-K/s   in 0s

2017-03-27 10:04:50 (375 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]
[vagrant@localhost ~]$ sudo rpm -Uvh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-9  ################################# [100%]


[vagrant@localhost ~]$ sudo yum -y install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community                                                                                 | 2.5 kB  00:00:00
mysql-tools-community                                                                                      | 2.5 kB  00:00:00
mysql57-community                                                                                          | 2.5 kB  00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db                                                        |  13 kB  00:00:00
(2/3): mysql-tools-community/x86_64/primary_db                                                             |  32 kB  00:00:00
(3/3): mysql57-community/x86_64/primary_db                                                                 |  96 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.jaist.ac.jp
 * extras: www.ftp.ne.jp
 * remi-safe: repo1.sea.innoscale.net
 * updates: www.ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.17-1.el7 for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Processing Dependency: net-tools for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.17-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.17-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.17-1.el7 will be installed
---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                            Arch               Version                                Repository                     Size
==================================================================================================================================
Installing:
 mysql-community-server             x86_64             5.7.17-1.el7                           mysql57-community             162 M
Installing for dependencies:
 mysql-community-client             x86_64             5.7.17-1.el7                           mysql57-community              24 M
 mysql-community-common             x86_64             5.7.17-1.el7                           mysql57-community             271 k
 mysql-community-libs               x86_64             5.7.17-1.el7                           mysql57-community             2.1 M
 net-tools                          x86_64             2.0-0.17.20131004git.el7               base                          304 k

Transaction Summary
==================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 188 M
Installed size: 848 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.17-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.17-1.el7.x86_64.rpm                                                      | 271 kB  00:00:00
(2/5): mysql-community-libs-5.7.17-1.el7.x86_64.rpm                                                        | 2.1 MB  00:00:01
(3/5): net-tools-2.0-0.17.20131004git.el7.x86_64.rpm                                                       | 304 kB  00:00:00
(4/5): mysql-community-client-5.7.17-1.el7.x86_64.rpm                                                      |  24 MB  00:00:03
(5/5): mysql-community-server-5.7.17-1.el7.x86_64.rpm                                                      | 162 MB  00:00:28
----------------------------------------------------------------------------------------------------------------------------------
Total                                                                                             6.1 MB/s | 188 MB  00:00:30
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    : mysql57-community-release-el7-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-5.7.17-1.el7.x86_64                                                                     1/5
  Installing : mysql-community-libs-5.7.17-1.el7.x86_64                                                                       2/5
  Installing : mysql-community-client-5.7.17-1.el7.x86_64                                                                     3/5
  Installing : net-tools-2.0-0.17.20131004git.el7.x86_64                                                                      4/5
  Installing : mysql-community-server-5.7.17-1.el7.x86_64                                                                     5/5
  Verifying  : mysql-community-server-5.7.17-1.el7.x86_64                                                                     1/5
  Verifying  : net-tools-2.0-0.17.20131004git.el7.x86_64                                                                      2/5
  Verifying  : mysql-community-client-5.7.17-1.el7.x86_64                                                                     3/5
  Verifying  : mysql-community-libs-5.7.17-1.el7.x86_64                                                                       4/5
  Verifying  : mysql-community-common-5.7.17-1.el7.x86_64                                                                     5/5

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

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.17-1.el7                    mysql-community-common.x86_64 0:5.7.17-1.el7
  mysql-community-libs.x86_64 0:5.7.17-1.el7                      net-tools.x86_64 0:2.0-0.17.20131004git.el7

Complete!

インストールできた

バージョンの確認
[vagrant@localhost ~]$ mysqld --version
mysqld  Ver 5.7.17 for Linux on x86_64 (MySQL Community Server (GPL))
mysqlログインする
[vagrant@localhost ~]$mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

なんか失敗する
調べてみるとパスワードは初回起動時にログファイルに作られるのでそれでログインするみたい
有名どころだけど古いバージョンのサイトをみてたからつまずいた

パスワードの確認
[vagrant@localhost ~]$ sudo cat /var/log/mysqld.log | grep 'temporary password'
2017-03-27T10:32:26.278899Z 1 [Note] A temporary password is generated for root@localhost: rLw3>lfut?1q
再度ログインする
[vagrant@localhost ~]$ mysql -uroot -prLw3>lfut?1q
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

コマンドラインでパスワードつきはだめみたい 履歴のこってセキュリティー上あぶないからかな

[vagrant@localhost ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.17

Copyright (c) 2000, 2016, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

パスワードをリセットしなさいとのこと
このパスワードは一時的にアクセスするためのものみたい

次のコマンドでパスワードを再設定する
[vagrant@localhost ~]$mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:  ;<-ここで先程確認したパスワードをいれる

そのあとパスワードを入力、確認をして再設定をおこなう

[vagrant@localhost ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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がインストールできました。
結構まえにためしたときは簡単にいれられたのですが
5.7?からなのか設定方法がけっこう変わったのですね