刪除資料庫

  1. 文字命令列直接刪除資料庫 dyw。
    [root@kvm8 html]# mysqladmin -uroot -p123qwe drop dyw
    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 'dyw' database [y/N] y
    Database "dyw" dropped
    
  2. 使用 php 函數 mysql_query 刪除資料庫 dywphp。
    [root@kvm8 html]# vim dropdb.php
    [root@kvm8 html]# cat dropdb.php
    <html>
    <head>
    <title>Deleting MySQL Database</title>
    </head>
    <body>
    <?php
    $dbhost = 'localhost:3306';
    $dbuser = 'root';
    $dbpass = '123qwe';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully<br />';
    $sql = 'DROP DATABASE dywphp';
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    {
      die('Could not delete database: ' . mysql_error());
    }
    echo "Database dywphp deleted successfully\n";
    mysql_close($conn);
    ?>
    </body>
    </html>
    
  3. 以 php 命令執行 dropdb.php 刪除 dywphp 資料庫,使用瀏覽器開啟 dropdb.php 也可以。
    [root@kvm8 html]# php dropdb.php
    <html>
    <head>
    <title>Deleting MySQL Database</title>
    </head>
    <body>
    Connected successfully<br />Database dywphp deleted successfully
    </body>
    </html>
    
  4. 直接在命令列查詢 mysql 中的資料庫,dyw 及 dywphp 兩個資料庫及不見。
    [root@kvm8 html]# mysql -uroot -p123qwe -e "show databases"
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+