LoginSignup
114
148

More than 3 years have passed since last update.

MySQL データベースの削除

Last updated at Posted at 2017-01-08

mysqlへ接続

SQLを実行するために、まずはデータベースへ接続をする必要があります。

mysql -u root

データベースの削除

下記のコマンドを打てば、データベースを削除できます。

mysql> drop database 削除したいデータベース名;

[注意]ハイフンのついたデータベースを削除する場合

例えば、hello-app_developmentというデータベースを削除したい場合、上記のコマンドを参考に削除しようとすると、エラーがでます。

mysql> drop database hello-app_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 '-app_development' at line 1

なので、ハイフンのついたデータベースを削除する場合は、バッククォート(`)でデータベース名を囲んであげる必要があります。

mysql> drop database`hello-app_development`;
Query OK, 0 rows affected (0.02 sec)

削除できたか確認方法

mysql> show databases;

上記のコマンドでデータベースを一覧で表示させると確認できます。

114
148
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
114
148