在mysql中要刪除數(shù)據(jù)庫很簡單我們只要使用DROP DATABASE 就可以快速刪除數(shù)據(jù)庫了,并且數(shù)據(jù)庫中所有表也給刪除了,下面給大家介紹介紹.
使用cmd模式下載刪除
命令:drop database <數(shù)據(jù)庫名>
例如:刪除名為 xhkdb的數(shù)據(jù)庫,代碼如下:mysql> drop database xhkdb;
例子1,刪除一個已經(jīng)確定存在的數(shù)據(jù)庫,代碼如下:
mysql> drop database drop_database;
Query OK, 0 rows affected (0.00 sec)
例子2,刪除一個不確定存在的數(shù)據(jù)庫,代碼如下:
- mysql> drop database drop_database;
- ERROR 1008 (HY000): Can't drop database 'drop_database'; database doesn't exist
- //發(fā)生錯誤,不能刪除'drop_database'數(shù)據(jù)庫,該數(shù)據(jù)庫不存在。
- mysql> drop database if exists drop_database;
- Query OK, 0 rows affected, 1 warning (0.00 sec)//產(chǎn)生一個警告說明此數(shù)據(jù)庫不存在
- mysql> create database drop_database;
- Query OK, 1 row affected (0.00 sec)
- mysql> drop database if exists drop_database;//if exists 判斷數(shù)據(jù)庫是否存在,不存在也不產(chǎn)生錯誤
- Query OK, 0 rows affected (0.00 sec)
使用mysqladmin刪除數(shù)據(jù)庫:
需要特殊的權限才能創(chuàng)建或刪除一個MySQL數(shù)據(jù)庫,因此,假設以root用戶的訪問,可以使用mysql mysqladmin二進制創(chuàng)建任何數(shù)據(jù)庫.
小心刪除任何數(shù)據(jù)庫,因為它會失去數(shù)據(jù)庫中可用的所有數(shù)據(jù).
Here is an example to delete a database created in previous chapter:[root@host]# mysqladmin -u root -p drop TUTORIALS
Enter password:******
下面是一個例子刪除在前面的章節(jié)中創(chuàng)建一個數(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ù),成功返回TRUE或失敗則返回FALSE.
例子:bool mysql_query( sql, connection );
參數(shù) 描述
sql Required - SQL query to create or delete a MySQL database
connection Optional - if not specified then last opened connection by mysql_connect will be used.
例子,試試下面的例子中,刪除一個數(shù)據(jù)庫,代碼如下:
- <html>
- <head>
- <title>Deleting MySQL Database - by m.survivalescaperooms.com</title>
- </head>
- <body>
- <?php
- $dbhost = 'localhost:3036';
- $dbuser = 'root';
- $dbpass = 'rootpassword';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass);
- if(! $conn )
- {
- die('Could not connect: ' . mysql_error());
- }
- echo 'Connected successfully<br />';
- $sql = 'DROP DATABASE TUTORIALS';
- $retval = mysql_query( $sql, $conn );
- if(! $retval )
- {
- die('Could not delete database: ' . mysql_error());
- }
- echo "Database TUTORIALS deleted successfullyn";
- mysql_close($conn);
- ?>
- </body>
- </html>
警告:在刪除一個數(shù)據(jù)庫,使用PHP腳本,它不會提示任何確認,所以刪除一個MySQL數(shù)據(jù)庫一定要小心.
新聞熱點
疑難解答
圖片精選