新聞中心
當(dāng)數(shù)據(jù)庫不再使用時(shí)應(yīng)該將其刪除,以確保數(shù)據(jù)庫存儲(chǔ)空間中存放的是有效數(shù)據(jù)。刪除數(shù)據(jù)庫是將已經(jīng)存在的數(shù)據(jù)庫從磁盤空間上清除,清除之后,數(shù)據(jù)庫中的所有數(shù)據(jù)也將一同被刪除。

在鐵門關(guān)等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營銷網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需策劃設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,全網(wǎng)整合營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),鐵門關(guān)網(wǎng)站建設(shè)費(fèi)用合理。
在 MySQL 中,當(dāng)需要?jiǎng)h除已創(chuàng)建的數(shù)據(jù)庫時(shí),可以使用
DROP DATABASE語句。其語法格式為:
DROP DATABASE [ IF EXISTS ] <數(shù)據(jù)庫名>
語法說明如下:
- <數(shù)據(jù)庫名>:指定要?jiǎng)h除的數(shù)據(jù)庫名。
- IF EXISTS:用于防止當(dāng)數(shù)據(jù)庫不存在時(shí)發(fā)生錯(cuò)誤。
- DROP DATABASE:刪除數(shù)據(jù)庫中的所有表格并同時(shí)刪除數(shù)據(jù)庫。使用此語句時(shí)要非常小心,以免錯(cuò)誤刪除。如果要使用 DROP DATABASE,需要獲得數(shù)據(jù)庫 DROP 權(quán)限。
注意:MySQL 安裝后,系統(tǒng)會(huì)自動(dòng)創(chuàng)建名為 information_schema 和 mysql 的兩個(gè)系統(tǒng)數(shù)據(jù)庫,系統(tǒng)數(shù)據(jù)庫存放一些和數(shù)據(jù)庫相關(guān)的信息,如果刪除了這兩個(gè)數(shù)據(jù)庫,MySQL 將不能正常工作。
例 1
下面在 MySQL 中創(chuàng)建一個(gè)測試數(shù)據(jù)庫 test_db_del。
mysql> CREATE DATABASE test_db_del; Query OK, 1 row affected (0.08 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | test_db | | test_db_char | | test_db_del | | world | +--------------------+ 9 rows in set (0.00 sec)
使用命令行工具將數(shù)據(jù)庫 test_db_del 從數(shù)據(jù)庫列表中刪除,輸入的 SQL 語句與執(zhí)行結(jié)果如下所示:
mysql> DROP DATABASE test_db_del; Query OK, 0 rows affected (0.57 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | test_db | | test_db_char | | world | +--------------------+ 8 rows in set (0.00 sec)
此時(shí)數(shù)據(jù)庫 test_db_del 不存在。再次執(zhí)行相同的命令,直接使用 DROP DATABASE test_db_del,系統(tǒng)會(huì)報(bào)錯(cuò),如下所示:
mysql> DROP DATABASE test_db_del; ERROR 1008 (HY000): Can't drop database 'test_db_del'; database doesn't exist
如果使用IF EXISTS從句,可以防止系統(tǒng)報(bào)此類錯(cuò)誤,如下所示:
mysql> DROP DATABASE IF EXISTS test_db_del; Query OK, 0 rows affected, 1 warning (0.00 sec)
使用 DROP DATABASE 命令時(shí)要非常謹(jǐn)慎,在執(zhí)行該命令后,MySQL 不會(huì)給出任何提示確認(rèn)信息。DROP DATABASE 刪除數(shù)據(jù)庫后,數(shù)據(jù)庫中存儲(chǔ)的所有數(shù)據(jù)表和數(shù)據(jù)也將一同被刪除,而且不能恢復(fù)。因此最好在刪除數(shù)據(jù)庫之前先將數(shù)據(jù)庫進(jìn)行備份。備份數(shù)據(jù)庫的方法會(huì)在教程后面進(jìn)行講解。
網(wǎng)頁標(biāo)題:創(chuàng)新互聯(lián)數(shù)據(jù)庫教程:MySQL刪除數(shù)據(jù)庫(DROPDATABASE語句)
本文網(wǎng)址:http://fisionsoft.com.cn/article/dhojjsh.html


咨詢
建站咨詢
