LoginSignup
7
7

More than 5 years have passed since last update.

ある日突然rails dbが起動しない。

Last updated at Posted at 2016-02-26

背景

rails dbを起動しようとしたら。。。
こんなエラーが

$ rails db
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'database_name'

解決策

権限がないって言われているので権限を追加。

ルート権限で入ります。

$ mysql -u root

現状の権限を確認


mysql> show grants for ''@'localhost';
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+

USAGE 「権限が無い」 の同義語です。
http://www.dbonline.jp/mysql/user/index5.html

! 権限がなくなっている!

権限を変更します

mysql> GRANT ALL PRIVILEGES ON *.* TO ''@'localhost';

すべての権限に変更しました。

GRANT ALL PRIVILEGES ON DB名.テーブル TO 'ユーザ名'@'ホスト名';
http://qiita.com/pinohara/items/481c95dc4c8c2568bf8d

もう1回確認

mysql> show grants for ''@'localhost';
+-----------------------------------------------+
| Grants for @localhost                         |
+-----------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO ''@'localhost' |
+-----------------------------------------------+
1 row in set (0.01 sec)

そして・・・

$ rails db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.27 Homebrew

Copyright (c) 2000, 2015, 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>

とりあえずこれで動きました!

なぜ権限が変わっていたのかの
直接的な原因はわかっていません。。(´・ω・`)

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7