微軟 SQL Server 自帶了一些示例數據庫,可用於練習和測試。也可作為自己數據庫設計時的參考。這些示例數據庫開源在了 GitHub,可在 Microsoft/sql-server-samples 查看和下載。
但因為 SQL 語法略有出入,這些數據庫並不能直接通過其中的 SQL 文件來安裝導入。
社區能找到一些轉換好的版本,比如這個 AdventureWorks的 MySQL 版本,這個 NorthWind 的 MySQL 版本。MySQL 其實有自己的示例數據庫,
示例數據庫資源
在官網 Other MySQL Documentation 中 Example Databases 部分有提供一些示例數據庫資源和相應的獲取地址。
導入
導入是通過執行相應的 .sql
文件完成的。拿上面資源中提供的第一個示例數據庫 test_db 為例。下載倉庫到本地后,執行以下命令進行導入:
$ mysql -u <user_name> -p < ./employees.sql
然后等待其執行完成。
執行結果:
$ mysql -u wayou -p < ./employees.sql
Enter password: ******
INFO
CREATING DATABASE STRUCTURE
INFO
storage engine: InnoDB
INFO
LOADING departments
INFO
LOADING employees
INFO
LOADING dept_emp
INFO
LOADING dept_manager
INFO
LOADING titles
INFO
LOADING salaries
data_load_time_diff
00:01:24
測試
成功導入后,可查詢到相關數據庫和里面的表以及數據。
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| employees |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> USE employees;
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_employees |
+----------------------+
| current_dept_emp |
| departments |
| dept_emp |
| dept_emp_latest_date |
| dept_manager |
| employees |
| salaries |
| titles |
+----------------------+
8 rows in set (0.01 sec)
mysql> SELECT * FROM employees LIMIT 10;
+--------+------------+------------+-----------+--------+------------+
| emp_no | birth_date | first_name | last_name | gender | hire_date |
+--------+------------+------------+-----------+--------+------------+
| 10001 | 1953-09-02 | Georgi | Facello | M | 1986-06-26 |
| 10002 | 1964-06-02 | Bezalel | Simmel | F | 1985-11-21 |
| 10003 | 1959-12-03 | Parto | Bamford | M | 1986-08-28 |
| 10004 | 1954-05-01 | Chirstian | Koblick | M | 1986-12-01 |
| 10005 | 1955-01-21 | Kyoichi | Maliniak | M | 1989-09-12 |
| 10006 | 1953-04-20 | Anneke | Preusig | F | 1989-06-02 |
| 10007 | 1957-05-23 | Tzvetan | Zielinski | F | 1989-02-10 |
| 10008 | 1958-02-19 | Saniya | Kalloufi | M | 1994-09-15 |
| 10009 | 1952-04-19 | Sumant | Peac | F | 1985-02-18 |
| 10010 | 1963-06-01 | Duangkaew | Piveteau | F | 1989-08-24 |
+--------+------------+------------+-----------+--------+------------+
10 rows in set (0.00 sec)