更新時間:2022-03-21 10:13:26 來源:動力節(jié)點 瀏覽1520次
需要特殊權(quán)限來創(chuàng)建或刪除一個MySQL數(shù)據(jù)庫。因此,假如你有機會獲得root用戶來登錄,可以用mysql中mysqladmin二進制來創(chuàng)建任何數(shù)據(jù)庫。
在刪除任何數(shù)據(jù)庫時要注意,因為刪除數(shù)據(jù)庫時所有的數(shù)據(jù)在數(shù)據(jù)庫中。
下面是一個例子,用來刪除前面的章節(jié)中所創(chuàng)建的數(shù)據(jù)庫:
[ root@host ]# mysqladmin - u root - p drop yiibai
Enter password :******
這會給出一個警告,它會確認(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 ' yiibai ' database [ y / N ] y
Database " yiibai " dropped
或使用:
mysql> drop database yiibai ;
Query OK, 0 rows affected (0.01 sec)
使用下面命令看刪除后,數(shù)據(jù)庫的列表情況:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| yiibai |
+--------------------+
6 rows in set (0.00 sec)
PHP使用mysql_query()函數(shù)來創(chuàng)建或刪除MySQL數(shù)據(jù)庫。該函數(shù)有兩個參數(shù),成功返回TRUE或失敗返回FALSE。語法:
bool mysql_query ( sql , connection );
示例:
試試下面的例子用于刪除MySQL數(shù)據(jù)庫:
<html>
<head>
<title>刪除MySQL數(shù)據(jù)庫</title>
</head>
<body>
<? php
$dbhost = 'localhost:3036' ;
$dbuser = 'root' ;
$dbpass = '' ;
$conn = mysql_connect ( $dbhost , $dbuser , $dbpass );
if (! $conn )
{
die ( 'Could not connect: ' . mysql_error ());
}
echo 'Connected successfully<br />' ;
$sql = 'DROP DATABASE yiibai' ;
$retval = mysql_query ( $sql, $conn );
if (! $retval )
{
die ( 'Could not delete database: ' . mysql_error ());
}
echo "Database YIIBAI deleted successfully\n" ;
mysql_close ( $conn );
?>
</body>
</html>
注意: 在使用上面PHP腳本刪除數(shù)據(jù)庫,它不會提示輸入任何確認(rèn)。所以,在刪除MySQL數(shù)據(jù)庫時要小心,它執(zhí)行后將直接刪除數(shù)庫,數(shù)據(jù)庫的一切信息將被刪除無法恢復(fù)。如果大家想了解更相關(guān)知識,不妨來關(guān)注一下動力節(jié)點的Java在線學(xué)習(xí),里面的課程內(nèi)容從入門到精通,細致全面,通俗易懂,比較適合沒有基礎(chǔ)的小伙伴學(xué)習(xí),希望對大家能夠有所幫助。