MySQL 教程
使用普通用戶登陸 MySQL 服務(wù)器,你可能需要特定的權(quán)限來創(chuàng)建或者刪除 MySQL 數(shù)據(jù)庫,所以我們這邊使用 root 用戶登錄,root 用戶擁有最高權(quán)限。
在刪除數(shù)據(jù)庫過程中,務(wù)必要十分謹(jǐn)慎,因?yàn)樵趫?zhí)行刪除命令后,所有數(shù)據(jù)將會(huì)消失。
drop 命令格式:
drop database <數(shù)據(jù)庫名>;
例如刪除名為 JSON 的數(shù)據(jù)庫:
mysql> drop database JSON;
你也可以使用 mysql mysqladmin 命令在終端來執(zhí)行刪除命令。
以下實(shí)例刪除數(shù)據(jù)庫 JSON(該數(shù)據(jù)庫在前一章節(jié)已創(chuàng)建):[root@host]# mysqladmin -u root -p drop JSON Enter password:******
執(zhí)行以上刪除數(shù)據(jù)庫命令后,會(huì)出現(xiàn)一個(gè)提示框,來確認(rèn)是否真的刪除數(shù)據(jù)庫:
Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'JSON' database [y/N] y Database "JSON" dropped
PHP使用 mysqli_query 函數(shù)來創(chuàng)建或者刪除 MySQL 數(shù)據(jù)庫。
該函數(shù)有兩個(gè)參數(shù),在執(zhí)行成功時(shí)返回 TRUE,否則返回 FALSE。
mysqli_query(connection,query,resultmode);
參數(shù) | 描述 |
---|---|
connection | 必需。規(guī)定要使用的 MySQL 連接。 |
query | 必需,規(guī)定查詢字符串。 |
resultmode |
可選。一個(gè)常量??梢允窍铝兄抵械娜我庖粋€(gè):
|
以下實(shí)例演示了使用PHP mysqli_query函數(shù)來刪除數(shù)據(jù)庫:
注意: 在使用PHP腳本刪除數(shù)據(jù)庫時(shí),不會(huì)出現(xiàn)確認(rèn)是否刪除信息,會(huì)直接刪除指定數(shù)據(jù)庫,所以你在刪除數(shù)據(jù)庫時(shí)要特別小心。