Mysql 5.7インストール

5394 ワード

1.インストールファイルを/usr/local/src/にダウンロード

[root@honeybee ~]# cd /usr/local/src/
[root@honeybee src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz


2.インストールディレクトリ、データ格納ディレクトリ、ログディレクトリの作成

[root@honeybee src]# mkdir -p /usr/local/mysql
[root@honeybee src]# mkdir -p /data/mysql
[root@honeybee src]# mkdir -p /var/log/mysql


3.圧縮パッケージをインストールディレクトリに解凍する

[root@honeybee src]# tar -xzf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@honeybee src]# mv mysql-5.7.20-linux-glibc2.12-x86_64/* /usr/local/mysql/


4.mysqlユーザー、グループの作成

[root@honeybee src]# cd /usr/local/mysql/
[root@honeybee mysql]# groupadd mysql
[root@honeybee mysql]# useradd -r -g mysql mysql



5.ディレクトリ権限の設定

[root@honeybee mysql]# chown -R mysql /usr/local/mysql/
[root@honeybee mysql]# chown -R mysql:mysql /data/mysql
[root@honeybee mysql]# chgrp -R mysql /data/mysql
[root@honeybee mysql]# chown -R mysql:mysql /var/log/mysql


6.データベースの初期化

[root@honeybee mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql


次のエラーが発生しました.

[root@honeybee mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory


libaioのインストール
[root@honeybee mysql]# yum install libaio


初期化の再実行

[root@honeybee mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2017-11-12T14:06:27.150049Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-12T14:06:29.285338Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-12T14:06:29.516354Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-12T14:06:29.623677Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ae0c4a8c-c7b2-11e7-a1cd-00163e102209.
2017-11-12T14:06:29.627181Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-12T14:06:29.627612Z 1 [Note] A temporary password is generated for root@localhost: rdCixlilG2*D


上の初期パスワードを覚えてください:rdCixlilG 2*D
7.システムサービスの追加

[root@honeybee mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld



8.作成または変更/etc/my.cnfファイル
my.cnfの重要な構成:

[client]
port = 3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
socket=/tmp/mysql.sock
pid-file = /data/mysql/mysql.pid
character_set_server=utf8
[mysqld_safe]
log-error = /var/log/mysql/error.log
pid-file = /data/mysql/mysql.pid


9.mysqlを起動する

[root@honeybee mysql]# service mysqld start
Starting MySQL.                                            [  OK  ]


10.ログイン、パスワード変更

[root@honeybee mysql]# bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-log

Copyright (c) 2000, 2017, 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> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)


11.rootユーザーにリモート接続を追加する能力

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> select host,user,authentication_string from mysql.user;
+-----------+---------------+-------------------------------------------+
| host      | user          | authentication_string                     |
+-----------+---------------+-------------------------------------------+
| localhost | root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| %         | root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+---------------+-------------------------------------------+
4 rows in set (0.00 sec)


12.環境変数の追加
変更/etc/profileファイル

PATH=$PATH:/usr/local/mysql/bin


変更を即時に有効にする

[root@honeybee mysql]# source /etc/profile


13.パスワードを忘れた場合、次の方法でリセットできます.


[root@honeybee mysql]# /usr/local/mysql/bin/mysqld_safe --user=root --skip-grant-tables --skip-networking &

[root@honeybee mysql]# mysql -uroot

mysql> use mysql;

mysql> update user set authentication_string=password('123456') where user='root';

mysql> flush privileges;