差分
このページの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 をインストールする ====== | ||
+ | ===== リポジトリの追加 ===== | ||
+ | < | ||
+ | $ sudo rpm -ivh http:// | ||
+ | </ | ||
+ | |||
+ | ===== MySQL のインストール ===== | ||
+ | < | ||
+ | $ sudo yum install -y mysql-community-server | ||
+ | </ | ||
+ | |||
+ | ===== MySQL の初期パスワード ===== | ||
+ | < | ||
+ | $ sudo cat / | ||
+ | 2018-03-01T15: | ||
+ | </ | ||
+ | |||
+ | ===== 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. | ||
+ | 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 ' | ||
+ | |||
+ | mysql> | ||
+ | </ | ||
+ | |||
+ | ===== MySQL の設定 ===== | ||
+ | UTF-8を標準とするように設定する。 | ||
+ | < | ||
+ | $ sudo vi /etc/my.cnf | ||
+ | </ | ||
+ | |||
+ | <code ini> | ||
+ | [mysqld] | ||
+ | character-set-server=utf8 | ||
+ | </ | ||
+ | |||
+ | 設定を反映するために MySQL を再起動する。 | ||
+ | < | ||
+ | $ sudo systemctl restart mysqld | ||
+ | </ | ||
+ | |||
+ | UTF-8 設定確認 | ||
+ | < | ||
+ | $ mysql -u root -p | ||
+ | </ | ||
+ | < | ||
+ | mysql> show variables like " | ||
+ | +--------------------------+----------------------------+ | ||
+ | | Variable_name | ||
+ | +--------------------------+----------------------------+ | ||
+ | | character_set_client | ||
+ | | character_set_connection | utf8 | | ||
+ | | character_set_database | ||
+ | | character_set_filesystem | binary | ||
+ | | character_set_results | ||
+ | | character_set_server | ||
+ | | character_set_system | ||
+ | | character_sets_dir | ||
+ | +--------------------------+----------------------------+ | ||
+ | 8 rows in set (0.01 sec) | ||
+ | </ | ||
+ | |||
+ | ===== root のパスワード設定 ===== | ||
+ | MySQL 5.6まで | ||
+ | < | ||
+ | mysql> UPDATE mysql.user SET Password=PASSWORD(' | ||
+ | mysql> FLUSH PRIVILEGES; | ||
+ | </ | ||
+ | MySQL 5.7以降 | ||
+ | < | ||
+ | mysql> ALTER USER ' | ||
+ | </ | ||
+ | |||
+ | ===== ユーザー追加 ===== | ||
+ | < | ||
+ | mysql> GRANT ALL ON *.* TO username IDENTIFIED BY ' | ||
+ | </ | ||
+ | |||
+ | ===== WordPress 向けの設定 ===== | ||
+ | |||
+ | < | ||
+ | $ sudo vi /etc/my.cnf | ||
+ | </ | ||
+ | |||
+ | <code ini> | ||
+ | [mysqld] | ||
+ | sql_mode=' | ||
+ | </ | ||
+ | ===== 参考文献 ===== | ||
+ | [[https:// | ||
+ | [[https:// | ||