• slider image 168
:::
條列式新聞
新聞載入中,請稍後...

3-2-2-7 mysql 資料庫的移轉

舊主機:

  1. 將 sfs3 資料表的資料 dump 出來
    /usr/bin/mysqldump -uroot -p密碼 --default-character-set=latin1 sfs3 > sfs3.sql
  2. 將 sfs3.sql 傳送到新主機
    # ssh root@172.20.2.213 mkdir /var/www/tmp/
    # scp sfs3.sql root@172.20.2.213:/var/www/tmp/
    # rm sfs3.sql

​新主機:

  1. 建立 sfs3 資料庫
    進入系統之後,輸入以下的指令:
    # mysql -p
    在 Enter Password: 提示,輸入你的 mysql 密碼。
  2. 建立資料庫:
    在 mysql 提示,輸入:
    mysql> create database sfs3;
    這樣,就會在 MySQL建立一個名為 sfs3 的資料庫。
    說明: create database 資料庫名稱 是 MySQL 建立資料庫的命令,後面接資料庫的名稱。
    切記:所有的 mysql 命令後面必須加分號 ; 分號在 mysql 中代表 命令的結束點。
    必須要有分號才算完整的一個 mysql 命令。
    
  3. 在 mysql 提示,輸入:
    mysql> show databases; 
    這樣就會秀出這台 MySQL 主機中,所有的資料庫名稱。


    完成後,再輸入 quit 離開 mysql.

     
  4. 開始將 sfs3.sql 匯入 mysql 裡的 sfs3 資料庫
    # mysql -uroot -p密碼 sfs3 < /var/www/tmp/sfs3.sql
    或是
    # mysql -uroot -p        sfs3 < /var/www/tmp/sfs3.sql

    Enter password:輸入密碼
    這樣就完成sfs3的資料庫匯入

     
  5. 查看 sfs3 資料庫的所有資料表
    # mysql -p

    在 Enter Password: 提示,輸入你的 mysql 密碼。
    mysql> 
     use sfs3;

    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> show tables;
    +-------------------------------------+
    | Tables_in_sfs3                      |
    +-------------------------------------+
    | BMI                                 |
    中間省略
    | week_setup                          |
    | yuanzhumin                          |
    +-------------------------------------+
    295 rows in set (0.00 sec)

    mysql> quit
    Bye


    刪除舊資料庫--請事先備份好才刪除
    mysqladmin -uroot -p密碼  drop  sfs3


    # 建立空白資料庫
    mysqladmin -uroot -p密碼 create sfs3

     

:::
展開 | 闔起

文章類別

書籍目錄

展開 | 闔起

線上使用者

6人線上 (6人在瀏覽線上書籍)

會員: 0

訪客: 6

更多…