はじめに
Docker imageを再度buildしなおした時に発生した事象の記録です。
対応
今回、遭遇したエラー
rootユーザーでも入れないところからスタートしました。
その際に遭遇したエラーは以下です。
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- ERROR 1044 (42000): Access denied for user ‘my_user’@’localhost’ to database ‘my_db’
- ERROR 1410 (42000): You are not allowed to create a user with GRANT
対応の記録
まずそもそも、rootユーザーでも入れない。
パスワードが正しくても入れない
bash-4.4# mysql -u root -p root
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
こちらを参考にrootだけで入ろうとしたけど駄目だった
bash-4.4# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
パスワードを聞かれたときに何も入力せずenter押したら入れた。。。
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 8.0.35 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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>
ちなみに以下を参考は以下

ERROR 1045 (28000) [Warning] Using a password on the command line interface can be insecure
When I write in the prompt
mysql -u root -p;
the prompt throw back this:
mysql: Using a password on the command line interface can be insecure.
ERROR 1045 (
docker composeファイルで以下を設定していたのに。
environment:
- MYSQL_ROOT_PASSWORD=xxxxx
そして、
mysql> set password for root@localhost = 'パスワード';
でパスワード設定ができた
ユーザーの作成をします。
mysql> CREATE USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.32 sec)
ユーザーへのパスワード設定をします。
mysql> ALTER USER 'test_user'@'localhost' IDENTIFIED BY 'test_passwd';
Query OK, 0 rows affected (0.04 sec)
DB作成をします。
mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.33 sec)
ERROR 1044 (42000): Access denied for user ‘my_user’@’localhost’ to database ‘my_db’
DBアクセス→失敗
$ mysql --user=test_user --password=test_passwd test_db
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1044 (42000): Access denied for user 'test_user'@'localhost' to database 'test_db'
ERROR 1410 (42000): You are not allowed to create a user with GRANT
DBにrootで入り直して、
ユーザーへの権限付与 → エラー
mysql> GRANT ALL PRIVILEGES ON django_db.* TO 'test_user'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
localhostに設定して解消
mysql> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
Query OK, 0 rows affected, 1 warning (0.98 sec)
これでDBへのアクセスができました。