1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MySQL データベース削除

Posted at

##MySQLへ接続

SQLを実行するためにはデータベースに接続しなければいけません。

Tarminal
mysql -u root

##データベースの一覧を確認
次に作成したデータベースの一覧を確認します。

Tarminal
show databases;

するとこういった一覧が表示されます(データベースの内容は個々人によって異なります)
データベース.png

##データベースの削除
このコマンドでデータベースを削除できます。

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

##ハイフン付きのデータベース名を削除するにはデータベース名を`(バッククオート)で囲む

例えば exam-pictweet_development のようなデータベース名のものを削除しようとすると下記のようなエラーが出てしまいます。

Tarminal
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 'exam-pictweet_development' at line 1

なのでデータベース名にハイフンが入っているものには `(バッククオート) で囲んで上げる必要があります。

Tarminal
mysql> drop database `exam-pictweet_development`;

そうすれば下記のように表示されデータベースを削除できます。

Tarminal
Query OK, 7 rows affected (0.17 sec)

念の為削除できているかデータベースの一覧を確認します。

Tarminal
show databases;
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?