下载 SQL 脚本
MySQL 官方提供了示例数据库,下载地址:MySQL 官方示例数据库下载地址
找到如下图所示 Example Databases:
点击下载对应类型的压缩包即可。
导入数据
解压文件:
下载完成之后解压完显示如上图三个文件,这里拿 sakila 作为示例:
- sakila.mwb:workbench 数据模型;
- sakila-data.sql:表记录信息;
- sakila-schema.sql:表结构信息。
从控制台进入 MySQL,根据 sakila-schema.sql 文件所在的位置进行导入:
SOURCE E:/sakila-db/sakila-db/sakila-schema.sql;Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected, 1 warning (0.05 sec)Query OK, 1 row affected (0.01 sec)Database changed
Query OK, 0 rows affected (0.18 sec)Query OK, 0 rows affected (0.26 sec)Query OK, 0 rows affected (0.06 sec)Query OK, 0 rows affected (0.07 sec)Query OK, 0 rows affected (0.06 sec)Query OK, 0 rows affected (0.12 sec)Query OK, 0 rows affected (0.12 sec)Query OK, 0 rows affected (0.07 sec)Query OK, 0 rows affected (0.07 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.48 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.12 sec)Query OK, 0 rows affected (0.06 sec)Query OK, 0 rows affected (0.11 sec)Query OK, 0 rows affected (0.13 sec)Query OK, 0 rows affected (0.16 sec)Query OK, 0 rows affected (0.10 sec)Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.07 sec)Query OK, 0 rows affected (0.03 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.02 sec)
查看数据库:
show databases;+--------------------+
| Database |
+--------------------+
| information_schema |
| learn_sql_grp |
| mysql |
| performance_schema |
| sakila |
| sys |
+--------------------+
6 rows in set (0.00 sec)
导入数据:
SOURCE E:/sakila-db/sakila-db/sakila-data.sql;Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Database changed
Query OK, 0 rows affected (0.00 sec)Query OK, 200 rows affected (0.01 sec)
Records: 200 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 603 rows affected (0.18 sec)
Records: 603 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 16 rows affected (0.00 sec)
Records: 16 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.06 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 600 rows affected (0.04 sec)
Records: 600 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.03 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 109 rows affected (0.00 sec)
Records: 109 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.02 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 599 rows affected (0.14 sec)
Records: 599 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 1000 rows affected (0.45 sec)
Records: 1000 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.05 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 5462 rows affected (0.27 sec)
Records: 5462 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 1000 rows affected (0.04 sec)
Records: 1000 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 4581 rows affected (0.40 sec)
Records: 4581 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.03 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 14881 rows affected (1.53 sec)
Records: 14881 Duplicates: 0 Warnings: 0Query OK, 1163 rows affected (0.02 sec)
Records: 1163 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.03 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 12377 rows affected (1.49 sec)
Records: 12377 Duplicates: 0 Warnings: 0Query OK, 3667 rows affected (0.07 sec)
Records: 3667 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.04 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)
此时,数据导入操作已经完成,可以查看库中的数据:
USE sakila;SELECT *
FROM actor
LIMIT 10;+----------+------------+--------------+---------------------+
| actor_id | first_name | last_name | last_update |
+----------+------------+--------------+---------------------+
| 1 | PENELOPE | GUINESS | 2006-02-15 04:34:33 |
| 2 | NICK | WAHLBERG | 2006-02-15 04:34:33 |
| 3 | ED | CHASE | 2006-02-15 04:34:33 |
| 4 | JENNIFER | DAVIS | 2006-02-15 04:34:33 |
| 5 | JOHNNY | LOLLOBRIGIDA | 2006-02-15 04:34:33 |
| 6 | BETTE | NICHOLSON | 2006-02-15 04:34:33 |
| 7 | GRACE | MOSTEL | 2006-02-15 04:34:33 |
| 8 | MATTHEW | JOHANSSON | 2006-02-15 04:34:33 |
| 9 | JOE | SWANK | 2006-02-15 04:34:33 |
| 10 | CHRISTIAN | GABLE | 2006-02-15 04:34:33 |
+----------+------------+--------------+---------------------+
10 rows in set (0.00 sec)