はじめに
1 2 3 4 |
# MySQLをインストール yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm yum info mysql-community-server sudo yum install -y mysql-community-server |
とやったあとの初期設定でハマったので備忘録。
初期パスワードの確認
rootでMySQLに入ろうとすると、パスワードが必要というエラーが出てしまうので、初期設定されているパスワードを確認する必要があります。
1 2 3 |
[vagrant@localhost ~]$ mysql -u root mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) |
/var/log/mysqld.logに残っている、初期設定時のログからパスワードを確認します。
1 2 3 4 5 6 7 8 9 |
[vagrant@localhost ~]$ sudo cat /var/log/mysqld.log 2020-02-27T16:00:23.460496Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-02-27T16:00:23.741340Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-02-27T16:00:23.796645Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-02-27T16:00:23.855279Z 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: 4352063e-597a-11ea-acf0-5254008afee6. 2020-02-27T16:00:23.856630Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-02-27T16:00:25.340051Z 0 [Warning] CA certificate ca.pem is self signed. 2020-02-27T16:00:25.804182Z 1 [Note] A temporary password is generated for root@localhost: kJbD+Z6UfPYD ⬆️⬆️⬆️パスワード |
確認できたら、MySQLサーバーへログインし、初期設定のパスワードを変更しましょう。
1 2 |
mysql> set password for root@localhost=password('P@ssw0rd!'); Query OK, 0 rows affected, 1 warning (0.00 sec) |
変更したパスワードでMySQLに入れることを確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
mysql> quit Bye [vagrant@localhost ~]$ mysql -u root -pP@ssw0rd! mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.29 Copyright (c) 2000, 2020, 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> quit Bye |
パスワードの変更(追記)
MySQLのパスワードポリシーにあったパスワードを設定していないと
1 2 |
mysql> \s ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. |
というエラーが出るので追記。
パスワードポリシーの初期設定は以下の通り
1 |
mysql> SHOW VARIABLES LIKE 'validate_password%'; |
Variable_name | Value |
---|---|
validate_password_check_user_name | OFF |
validate_password_dictionary_file | |
validate_password_length | 8 |
validate_password_mixed_case_count | 1 |
validate_password_number_count | 1 |
validate_password_policy | MEDIUM |
validate_password_special_char_count | 1 |
Leave a Reply