国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

MySQL刪除數(shù)據(jù)庫命令用法詳解

2024-07-24 12:37:25
字體:
來源:轉載
供稿:網(wǎng)友

在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ù)庫,代碼如下:

  1. mysql> drop database drop_database; 
  2. ERROR 1008 (HY000): Can't drop database 'drop_database'; database doesn't exist 
  3.    //發(fā)生錯誤,不能刪除'drop_database'數(shù)據(jù)庫,該數(shù)據(jù)庫不存在。 
  4. mysql> drop database if exists drop_database; 
  5. Query OK, 0 rows affected, 1 warning (0.00 sec)//產(chǎn)生一個警告說明此數(shù)據(jù)庫不存在 
  6. mysql> create database drop_database; 
  7. Query OK, 1 row affected (0.00 sec) 
  8. mysql> drop database if exists drop_database;//if exists 判斷數(shù)據(jù)庫是否存在,不存在也不產(chǎn)生錯誤 
  9. 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ù)庫,代碼如下:

  1. <html> 
  2. <head> 
  3. <title>Deleting MySQL Database - by m.survivalescaperooms.com</title> 
  4. </head> 
  5. <body> 
  6. <?php 
  7. $dbhost = 'localhost:3036'
  8. $dbuser = 'root'
  9. $dbpass = 'rootpassword'
  10. $conn = mysql_connect($dbhost$dbuser$dbpass); 
  11. if(! $conn ) 
  12.   die('Could not connect: ' . mysql_error()); 
  13. echo 'Connected successfully<br />'
  14. $sql = 'DROP DATABASE TUTORIALS'
  15. $retval = mysql_query( $sql$conn ); 
  16. if(! $retval ) 
  17.   die('Could not delete database: ' . mysql_error()); 
  18. echo "Database TUTORIALS deleted successfullyn"
  19. mysql_close($conn); 
  20. ?> 
  21. </body> 
  22. </html> 

警告:在刪除一個數(shù)據(jù)庫,使用PHP腳本,它不會提示任何確認,所以刪除一個MySQL數(shù)據(jù)庫一定要小心.

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东兰县| 宣恩县| 江城| 顺昌县| 新疆| 海阳市| 大埔区| 河间市| 宁陵县| 万源市| 泾源县| 汝南县| 闵行区| 綦江县| 新平| 琼海市| 清原| 浏阳市| 漾濞| 定南县| 宣武区| 绍兴县| 龙州县| 长泰县| 奉化市| 蕉岭县| 保靖县| 南澳县| 瑞金市| 梁山县| 岳阳市| 南召县| 沧源| 阿坝县| 长汀县| 株洲市| 社旗县| 拉萨市| 富锦市| 东阿县| 阿克苏市|