刪除資料庫

  1. 文字命令列直接刪除資料庫 dyw。
    [root@kvm3 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 刪除資料庫 dywphp。
    [root@kvm3 html]# vi dropdb.php
    <?php
    $dbhost = 'localhost:3306';
    $dbuser = 'root';
    $dbpass = '123qwe';
    $conn = mysqli_connect($dbhost, $dbuser, $dbpass)
            or die(mysqli_connect_error().PHP_EOL);
    echo 'Connected successfully'.PHP_EOL;
    $sql = 'DROP DATABASE dywphp';
    mysqli_query( $conn, $sql )
            or die('Error: '.mysqli_error($conn).PHP_EOL);
    echo "Database dywphp deleted successfully\n";
    mysqli_close($conn);
    ?>
    
  3. 以 curl 連線 dropdb.php,回應連線成功且刪除資料庫 dywphp。
    [root@kvm3 html]# curl http://kvm3/dropdb.php
    Connected successfully
    Database dywphp deleted successfully
    
  4. 再以 curl 連線 dropdb.php,回應連線成功但資料庫 dywphp 不存在。
    [root@kvm3 html]# curl http://kvm3/dropdb.php
    Connected successfully
    Error: Can't drop database 'dywphp'; database doesn't exist
    
  5. 直接在命令列查詢 mysql 中的資料庫,dyw 及 dywphp 兩個資料庫及不見。
    [root@kvm3 html]# mariadb -uroot -p123qwe -e "show databases"
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+