LoginSignup
1
0

More than 5 years have passed since last update.

MySQLで英数字_以外を含むDBをDROPする時はバッククォートで囲む

Posted at

Railsのアプリケーション名をtest-projectとかにして、rails db:createとかしてると、test-project_development みたいなDBが大量にできている。

毎プロジェクト、用済みになった時にrails db:dropしていれば問題ないのだが、忘れたままrenameしたりして、どんどん溜まっていき、可視性が悪くなったので、localのMySQLの整備をしようとした。

mysql
DROP DATABASE test-project_development;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-project_development' at line 1

失敗した👻
ハイフンが使えないのを忘れていた。
英数字_以外を含むDB名の時はバッククォートで囲む。

mysql
DROP DATABASE `test-project_development`;

Query OK, 3 rows affected (0.06 sec)

めでたし🎉

1
0
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
1
0