🌜

MySQL 示例数据库

微软 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)

相关资源

posted @ 2019-05-07 23:54  bloger11  阅读(6142)  评论(0编辑  收藏  举报

Bingo!!

少年,我看你骨骼清奇,怕是一名前端吧‽

腾讯内推长期有效,简历这边来 liuwayong@gmail.com