MySQL刪除數(shù)據(jù)庫的兩種方法
本文為大家分享了兩種MySQL刪除數(shù)據(jù)庫的方法,供大家參考,具體內(nèi)容如下
第一種方法:使用 mysqladmin 刪除數(shù)據(jù)庫
使用普通用戶登陸mysql服務器,你可能需要特定的權限來創(chuàng)建或者刪除 MySQL 數(shù)據(jù)庫。
所以我們這邊使用root用戶登錄,root用戶擁有最高權限,可以使用 mysql mysqladmin 命令來創(chuàng)建數(shù)據(jù)庫。
在刪除數(shù)據(jù)庫過程中,務必要十分謹慎,因為在執(zhí)行刪除命令后,所有數(shù)據(jù)將會消失。
以下實例刪除數(shù)據(jù)庫TUTORIALS(該數(shù)據(jù)庫在前一章節(jié)已創(chuàng)建):
[root@host]# mysqladmin -u root -p drop TUTORIALS
Enter password:******
執(zhí)行以上刪除數(shù)據(jù)庫命令后,會出現(xià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 'TUTORIALS' database [y/N] y Database "TUTORIALS" dropped
第二種方法:使用PHP腳本刪除數(shù)據(jù)庫
PHP使用 mysql_query 函數(shù)來創(chuàng)建或者刪除 MySQL 數(shù)據(jù)庫。
該函數(shù)有兩個參數(shù),在執(zhí)行成功時返回 TRUE,否則返回 FALSE。
語法
bool mysql_query( sql, connection );

實例
以下實例演示了使用PHP mysql_query函數(shù)來刪除數(shù)據(jù)庫:
<html>
<head>
<title>Deleting MySQL Database</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('連接失敗: ' . mysql_error());
}
echo '連接成功<br />';
$sql = 'DROP DATABASE TUTORIALS';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('刪除數(shù)據(jù)庫失敗: ' . mysql_error());
}
echo "數(shù)據(jù)庫 TUTORIALS 刪除成功\n";
mysql_close($conn);
?>
</body>
</html>
注意:在使用PHP腳本刪除數(shù)據(jù)庫時,不會出現(xiàn)確認是否刪除信息,會直接刪除指定數(shù)據(jù)庫,所以你在刪除數(shù)據(jù)庫時要特別小心。
以上就是MySQL刪除數(shù)據(jù)庫的兩種方法,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- MySQL刪除數(shù)據(jù)庫的方法舉例
- MySql中刪除數(shù)據(jù)表的方法詳解
- mysql如何刪除數(shù)據(jù)表和關聯(lián)的數(shù)據(jù)表刪除詳情
- Mysql如何刪除數(shù)據(jù)庫表中的某一列
- 淺談為什么MySQL不建議delete刪除數(shù)據(jù)
- Mysql刪除數(shù)據(jù)以及數(shù)據(jù)表的方法實例
- MySQL刪除數(shù)據(jù),表文件大小依然沒變的原因
- MySQL實現(xiàn)快速刪除所有表而不刪除數(shù)據(jù)庫的方法
- Mysql單文件存儲刪除數(shù)據(jù)文件容量不會減少的bug與解決方法
- mysql中刪除數(shù)據(jù)的四種方法小結
相關文章
使用存儲過程實現(xiàn)循環(huán)插入100條記錄
本節(jié)主要介紹了使用存儲過程實現(xiàn)循環(huán)插入100條記錄的具體實現(xiàn),需要的朋友可以參考下2014-07-07

