mozyのかきおき

mozyの読書感想文や思考置き場

【解決】MySQLのpasswordをなしにする

起きた事

local環境で色々遊んでいたところ、databaseを流し込もうとした時に以下のような、password があっていない時に出るエラーが起きた。

Access denied for user 'root'@'localhost' (using password: NO)
Couldn't drop database 'test_dev'

解決策

ちょっと手間だったので、mysqlにログインして、passwordの設定をなしにした。

$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.39 Homebrew

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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password='' where User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
$ mysql -uroot   
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.6.39 Homebrew

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> quit
Bye

passwordなしでログインできるようになった。やったね。

その他

MYSQL_ROOT_PASSWORD とか色々設定方法はあるけど、今回は一瞬だったので、簡単な方法で解決した。