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

でかいサイズのDBを一瞬で削除する

0
Posted at

2GBごえのDBを削除する必要があり、drop database {DB名};でやったら、すごく時間がかかってしまっていろいろ問題があり、大変だった。

そこでググってみて、一瞬で削除できる方法が見つかったので、メモメモ。

直接データファイルを削除する

以下の手順で直接データファイルを削除する

今回削除したいDBはtestdbとする

# MySQLにログイン
$ mysql -u {ユーザー名} -p
Enter password:

MariaDB [(none)]> show databases;
+------------------------+
| Database               |
+------------------------+
| information_schema     |
| testdb                 | ←存在する

MariaDB [(none)]> show variables like 'datadir';データファイルの場所を探す
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.00 sec)

# 一度MySQLからログアウト or 別のタブで実行
$ sudo rm -rf /var/lib/mysql/testdb

-- もう一度DB一覧を表示
MariaDB [(none)]> show databases;
+------------------------+
| Database               |
+------------------------+
| information_schema     |
|                        | ←削除されている

最後に

DBの削除はdrop databaseしか知らなかったけど、こんなやり方もあるんだなと勉強になりました。

参考

MYSQLでDROP DATABASEがエラーになる( ERROR 1010 (HY000): Error dropping database )

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