next up previous contents
Next: 實機操作練習題 Up: Database 資料庫 Previous: 選取工作資料庫   Contents   DYWANG_HOME


  1. 文字命令列直接刪除資料庫 dyw。
    [root@kvm3 ~]# 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 ~]# vim /var/www/html/dropdb.php
    [root@kvm3 ~]# cat /var/www/html/dropdb.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";
  3. 以 curl 連線 dropdb.php,回應連線成功且刪除資料庫 dywphp。
    [root@kvm3 ~]# curl -s
    Connected successfully
    Database dywphp deleted successfully
  4. 再以 curl 連線 dropdb.php,回應連線成功但資料庫 dywphp 不存在。
    [root@kvm3 ~]# curl -s
    Connected successfully
    Error: Can't drop database 'dywphp'; database doesn't exist
  5. 直接在命令列查詢 mysql 中的資料庫,dyw 及 dywphp 兩個資料庫及不見。
    [root@kvm3 html]# mysql -uroot -p123qwe -e "show databases"
    | Database           |
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |

De-Yu Wang 2020-09-18