安装 Sakila 数据库
本文展示了下载 Sakila 数据库脚本、并导入到 MySQL 服务器中的方法。
安装 Sakila 数据库之前,请先安装 MySQL 服务器。
下载 Sakila 数据库
您可以从 https://downloads.mysql.com/docs/sakila-db.zip 下载 Sakila 示例数据库。
点击下载链接,将会下载一个 Zip 格式的压缩文件。压缩文件中包含三个文件: sakila-schema.sql, sakila-data.sql,和 sakila.mwb。
sakila-schema.sql文件包含创建 Sakila 数据库结构所需的所有CREATE语句,包括表、视图、存储过程和触发器。sakila-data.sql文件包含插入所有数据的INSERT语句,这些语句一定要在sakila-schema.sql中的语句执行完后再运行。sakila.mwb文件是一个 MySQL Workbench 数据模型,您可以在 MySQL Workbench 中打开它以检查数据库结构。
Sakila 包含 MySQL 版本特定的注释,因为 sakila 模式和数据取决于您的 MySQL 服务器的版本。例如,MySQL 服务器 5.7.5 添加了对空间数据索引的支持 InnoDB,因此 地址表将包含 MySQL 5.7.5 及更高版本的空间感知位置列
安装 Sakila 数据库
请按照以下步骤安装 Sakila 示例数据库:
-
将下载的 zip 文件解压缩到一个临时位置,例如
C:\temp\或/tmp/。当您解压缩存档时,它会创建一个名为sakila-db的目录,其中包含sakila-schema.sql和sakila-data.sql文件。 -
使用 mysql 命令行客户端和以下命令连接到 MySQL 服务器:
mysql -u root -p出现提示时输入您的密码。可以使用非
root帐户,前提是该帐户具有创建新数据库的权限。 -
执行
sakila-schema.sql脚本创建数据库结构,并执行sakila-data.sql脚本填充数据库结构,使用以下命令:mysql> SOURCE C:/temp/sakila-db/sakila-schema.sql; mysql> SOURCE C:/temp/sakila-db/sakila-data.sql;用系统上的实际路径替换
sakila-schema.sql和sakila-data.sql文件的路径。在 Windows 上,执行
SOURCE命令时使用斜杠而不是反斜杠。 -
确认示例数据库安装正确。执行以下语句。您应该会看到类似于此处显示的输出。
mysql> USE sakila; Database changed mysql> SHOW FULL TABLES; +----------------------------+------------+ | Tables_in_sakila | Table_type | +----------------------------+------------+ | actor | BASE TABLE | | actor_info | VIEW | | address | BASE TABLE | | category | BASE TABLE | | city | BASE TABLE | | country | BASE TABLE | | customer | BASE TABLE | | customer_list | VIEW | | film | BASE TABLE | | film_actor | BASE TABLE | | film_category | BASE TABLE | | film_list | VIEW | | film_text | BASE TABLE | | inventory | BASE TABLE | | language | BASE TABLE | | nicer_but_slower_film_list | VIEW | | payment | BASE TABLE | | rental | BASE TABLE | | sales_by_film_category | VIEW | | sales_by_store | VIEW | | staff | BASE TABLE | | staff_list | VIEW | | store | BASE TABLE | +----------------------------+------------+ 23 rows in set (0.01 sec) mysql> SELECT COUNT(*) FROM film; +----------+ | COUNT(*) | +----------+ | 1000 | +----------+ 1 row in set (0.00 sec) mysql> SELECT COUNT(*) FROM film_text; +----------+ | COUNT(*) | +----------+ | 1000 | +----------+ 1 row in set (0.00 sec)