====== CentOS 7 に MySQL 5.7 をインストールする ====== ===== リポジトリの追加 ===== $ sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm ===== MySQL のインストール ===== $ sudo yum install -y mysql-community-server ===== MySQL の初期パスワード ===== $ sudo cat /var/log/mysqld.log | grep 'temporary password' 2018-03-01T15:45:33.932304Z 1 [Note] A temporary password is generated for root@localhost: 2rGWtisl*JYC ===== MySQLサービスの自動起動設定 ===== 自動起動設定はされているのでしなくて良い。 ===== MySQL Secure Installation の実行 ===== 以下のコマンドを実行して MySQL の root パスワードを変更する。 $ mysql_secure_installation ~省略~ Enter password for user root: ******** <- 初期パスワードを入力 ~省略~ Change the password for root ? ((Press y|Y for Yes, any other key for No) : y を入力 New password: ******** <- root のパスワードを入力 Re-enter new password: ******** <- root の確認パスワードを入力 ~省略~ Remove anonymous users? (Press y|Y for Yes, any other key for No) : y を入力 Success. ~省略~ Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y を入力 Success. ~省略~ Remove test database and access to it? (Press y|Y for Yes, any other key for No) : <- Enter を入力 ... skipping. ~省略~ Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y を入力 Success. ===== ログイン確認 ===== root にてログインできることを確認する。 $ mysql -u root -p Enter password: ******** <- root ユーザーのパスワードを入力 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.21 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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 の設定 ===== UTF-8を標準とするように設定する。 $ sudo vi /etc/my.cnf [mysqld] character-set-server=utf8 設定を反映するために MySQL を再起動する。 $ sudo systemctl restart mysqld UTF-8 設定確認 $ mysql -u root -p mysql> show variables like "char%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec) ===== root のパスワード設定 ===== MySQL 5.6まで mysql> UPDATE mysql.user SET Password=PASSWORD('パスワード') WHERE User='root'; mysql> FLUSH PRIVILEGES; MySQL 5.7以降 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'パスワード'; ===== ユーザー追加 ===== mysql> GRANT ALL ON *.* TO username IDENTIFIED BY 'password'; ===== WordPress 向けの設定 ===== $ sudo vi /etc/my.cnf [mysqld] sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' ===== 参考文献 ===== [[https://qiita.com/park-jh/items/1e118580ae1deab70f99#%E5%8F%82%E8%80%83|CentOS 7.3でMySQL 5.7を設置、かなり勉強になりました。]]\\ [[https://qiita.com/ksugawara61/items/336ffab798e05cae4afc|CentOS7.1にMySQL 5.7をインストール]]\\