CentOS7.3 MySQL5.7系のインストール

シェアする

最近、個人で使うには、MariaDBを使うほうが良いのでは?と何となく思ったりしますが、お試しでMySQL5.7系をインストールしてみましたので、そのメモです。

基本的には5.6系のときと同様な流れでした。

インストール前の準備

MariaDB関連のパッケージを削除し、MySQLリポジトリー設定ファイルのパッケージをダウンロードして、インストールします。

# yum -y remove mariadb-libs <LF>
    :
Removed:
  mariadb-libs.x86_64 1:5.5.52-1.el7
 
Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7
 
Complete!
# cd /tmp <LF>
# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm <LF>
    :
2017-04-08 22:53:47 (37.6 MB/s) - 'mysql57-community-release-el7-9.noarch.rpm' saved [9224/9224]
# yum -y install mysql57-community-release-el7-9.noarch.rpm <LF>
    :
Installed:
  mysql57-community-release.noarch 0:el7-9
 
Complete!

MySQLのインストール

yumコマンドでパッケージをインストールします。

# yum list | grep mysql-community <LF>
mysql-community-client.i686                5.7.17-1.el7                mysql57-community
mysql-community-client.x86_64              5.7.17-1.el7                mysql57-community
mysql-community-common.i686                5.7.17-1.el7                mysql57-community
mysql-community-common.x86_64              5.7.17-1.el7                mysql57-community
mysql-community-devel.i686                 5.7.17-1.el7                mysql57-community
mysql-community-devel.x86_64               5.7.17-1.el7                mysql57-community
mysql-community-embedded.i686              5.7.17-1.el7                mysql57-community
mysql-community-embedded.x86_64            5.7.17-1.el7                mysql57-community
mysql-community-embedded-compat.i686       5.7.17-1.el7                mysql57-community
mysql-community-embedded-compat.x86_64     5.7.17-1.el7                mysql57-community
mysql-community-embedded-devel.i686        5.7.17-1.el7                mysql57-community
mysql-community-embedded-devel.x86_64      5.7.17-1.el7                mysql57-community
mysql-community-libs.i686                  5.7.17-1.el7                mysql57-community
mysql-community-libs.x86_64                5.7.17-1.el7                mysql57-community
mysql-community-libs-compat.i686           5.7.17-1.el7                mysql57-community
mysql-community-libs-compat.x86_64         5.7.17-1.el7                mysql57-community
mysql-community-release.noarch             el7-7                       mysql57-community
mysql-community-server.x86_64              5.7.17-1.el7                mysql57-community
mysql-community-test.x86_64                5.7.17-1.el7                mysql57-community
# yum install mysql-community-server <LF>
    :
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!

オプションファイルの設定(my.cnf)

オプションファイルの設定で、文字コードをUTF8にします。

# /etc <LF>
# cp -p my.cnf my.cnf.original.20170409 <LF>
# cat my.cnf.original.20170409 | sed '/^#/d' | sed '/^$/d' > /etc/my.cnf <LF>
# sed -i '/^\[mysqld\]$/a character-set-server=utf8' /etc/my.cnf <LF>
# cat /etc/my.cnf <LF>
[mysqld]
character-set-server=utf8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

初期設定

MySQLの初期設定を行ないます。

# systemctl start mysqld <LF>
# cat /var/log/mysqld.log  | grep password <LF>
... 1 [Note] A temporary password is generated for root@localhost: rlBwkC_o:55*
# mysql_secure_installation <LF>
 
Securing the MySQL server deployment.
 
Enter password for user root:rlBwkC_o:55*
 
The existing password for the user account root has expired. Please set a new password.
 
New password:Root*Pass01
 
Re-enter new password:Root*Pass01
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
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:Root*Pass01
 
Re-enter new password:Root*Pass01
 
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!

確認

MySQLにログインできるかを確認します。

# mysql -u root -p <LF>
Enter password:Root*Pass01
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
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.01 sec)

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

mysql> exit;
Bye

データベースを作成して、ユーザーを作成してみます。

# mysql -u root -p <LF>
Enter password:Root*Pass01
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
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> create database testdb;
Query OK, 1 row affected (0.00 sec)
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
testdb             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)
 
mysql> create user 'testuser'@'%' identified by 'Testuser*Pass01';
Query OK, 0 rows affected (0.00 sec)
 
mysql> select user,host from mysql.user;
+------------+-----------+
| user       | host      |
+------------+-----------+
testuser   | %         |
| mysql.sys  | localhost |
| root       | localhost |
+------------+-----------+
3 rows in set (0.00 sec)
 
mysql> grant all privileges on testdb.* to 'testuser'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)
 
mysql> show grants for testuser;
+------------------------------------------------------------------------+
| Grants for testuser@%                                                  |
+------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'testuser'@'%'                                   |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'testuser'@'%' WITH GRANT OPTION |
+------------------------------------------------------------------------+
2 rows in set (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit;
Bye