linux:centos:centos7_mysql_install

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
linux:centos:centos7_mysql_install [2024/02/04 13:42] – 削除 - 外部編集 (Unknown date) 非ログインユーザーlinux:centos:centos7_mysql_install [2024/02/04 13:42] (現在) – ↷ linux:centos7_mysql_install から linux:centos:centos7_mysql_install へページを移動しました。 ともやん
行 1: 行 1:
 +====== CentOS 7 に MySQL 5.7 をインストールする ======
 +===== リポジトリの追加 =====
 +<code>
 +$ sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
 +</code>
 +
 +===== MySQL のインストール =====
 +<code>
 +$ sudo yum install -y mysql-community-server
 +</code>
 +
 +===== MySQL の初期パスワード =====
 +<code>
 +$ 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
 +</code>
 +
 +===== MySQLサービスの自動起動設定 =====
 +自動起動設定はされているのでしなくて良い。
 +
 +===== MySQL Secure Installation の実行 =====
 +以下のコマンドを実行して MySQL の root パスワードを変更する。
 +<code>
 +$ 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.
 +</code>
 +
 +===== ログイン確認 =====
 +root にてログインできることを確認する。
 +<code>
 +$ 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>
 +</code>
 +
 +===== MySQL の設定 =====
 +UTF-8を標準とするように設定する。
 +<code>
 +$ sudo vi /etc/my.cnf
 +</code>
 +
 +<code ini>
 +[mysqld]
 +character-set-server=utf8
 +</code>
 +
 +設定を反映するために MySQL を再起動する。
 +<code>
 +$ sudo systemctl restart mysqld
 +</code>
 +
 +UTF-8 設定確認
 +<code>
 +$ mysql -u root -p
 +</code>
 +<code>
 +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)
 +</code>
 +
 +===== root のパスワード設定 =====
 +MySQL 5.6まで
 +<code>
 +mysql> UPDATE mysql.user SET Password=PASSWORD('パスワード') WHERE User='root';
 +mysql> FLUSH PRIVILEGES;
 +</code>
 +MySQL 5.7以降
 +<code>
 +mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'パスワード';
 +</code>
 +
 +===== ユーザー追加 =====
 +<code>
 +mysql> GRANT ALL ON *.* TO username IDENTIFIED BY 'password';
 +</code>
 +
 +===== WordPress 向けの設定 =====
 +
 +<code>
 +$ sudo vi /etc/my.cnf
 +</code>
 +
 +<code ini>
 +[mysqld]
 +sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
 +</code>
 +===== 参考文献 =====
 +[[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をインストール]]\\