實機操作練習題

  1. 登入
    1. 遠端登入 kvm6 虛擬機。
    2. 以 root 身份登入 mysql。
  2. 資料庫、資料表建立:
    1. 產生資料庫 dba。
    2. 在資料庫中建立資料表 tbla,包含下列欄位:
      1. id int not null auto_increment,
      2. student varchar(40) not null,
      3. subject varchar(50) not null,
      4. score int,
      5. date date,
      6. primary key (id)
  3. 使用以下 shell 命令,查詢資料庫 dba 的資料表 tbla 的欄位特徵,並導向到 /tmp/alter1.txt。
    [root@kvm6 ~]# mysql -s -uroot -p123qwe -e 'use dba; .......;'
    
  4. 使用以下 php 範例程式,其中 ........ 依要求填入 mysql 語法,其中資料庫名稱依題目要求修改。
    <?php
    $dbhost = 'localhost:3306';
    $dbuser = 'root';
    $dbpass = '123qwe';
    $str = $_GET['str'];
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error().PHP_EOL);
    $sql = ".............";
    $retval = mysql_db_query( 'dbd',$sql ) or die(mysql_error().PHP_EOL);
    mysql_close($conn); 
    ?>
    
  5. php 程式
    1. alter2.php:資料表 tbla 最前面增加一個欄位 $str 格式為 tinyint,變數 $str 由 php get 取得。
    2. alter3.php:資料表 tbla 欄位 id 後新加一個欄位 $str 格式為 char(4),變數 $str 由 php get 取得。
    3. alter4.php:資料表 tbla 欄位 student 的名稱及格式,改成 $str 格式 char(10),變數 $str 由 php get 取得。
    4. alter5.php:刪除資料表 tbla 欄位 $str,變數 $str 由 php get 取得。
    5. alter6.php:設定資料表 tbla 欄位 $str 型態 bigint、不可是空的且指定預設值是 137,變數 $str 由 php get 取得。
    6. alter7.php:變更資料表 tbla 名稱為 $str,變數 $str 由 php get 取得。