使用MySQL样本数据库Sakila

来源:互联网 发布:端口聚合的模式 编辑:程序博客网 时间:2024/04/28 08:30

正在阅读学习《高性能MySQL》第三版,里面提到了MySQL提供的样本数据库Sakila,也使用Sakila作为演示。自己的的数据中也没有真实的数据用于测试,决定带Sakila数据库。这让想起了Microsoft为MS SqlServer默认提供北风数据库NorthWind,^.^。

大体步骤:

1、下载Sakila样本数据库,下载地址http://downloads.mysql.com/docs/sakila-db.tar.gz(下载页面http://dev.mysql.com/doc/index-other.html)。

2、导入sakila-schema.sql和sakila-data.sql文件。

3、测试

MySQL中导入Sakila的过程如下(MySQL网站原文,没有难以理解的地方就没有翻译,另外一方面我的英语翻译水平较差):

4. Installation

The Sakila sampledatabase is available from http://dev.mysql.com/doc/index-other.html. Adownloadable archive is available in compressed tar fileor Zip format. The archive contains three files: sakila-schema.sqlsakila-data.sql, and sakila.mwb.

The sakila-schema.sql filecontains all the CREATE statements required to create the structure of theSakila database including tables, views, stored procedures, and triggers.

The sakila-data.sql filecontains the INSERT statements required to populate the structurecreated by thesakila-schema.sql file, along with definitions for triggers that mustbe created after the initial data load.

The sakila.mwb file is aMySQL Workbench data model that you can open within MySQL Workbench to examinethe database structure. For more information, see MySQL Workbench.

To install theSakila sample database, follow these steps:

1.   Extract the installation archive to a temporary locationsuch as C:\temp\ or /tmp/. When you unpackthe archive, it creates a directory named sakila-db thatcontains the sakila-schema.sql and sakila-data.sql files.

2.   Connect to the MySQL server using the mysql command-line client with the followingcommand:

3.  shell> mysql -u root -p

Enter yourpassword when prompted. A non-root account can be used as long as the account hasprivileges to create new databases.

4.   Execute the sakila-schema.sql script tocreate the database structure by using the following command:

5.  mysql> SOURCE C:/temp/sakila-db/sakila-schema.sql;

Replace C:/temp/sakila-db with thepath to the sakila-schema.sql file on your system.

Note

On Windows youshould use slashes, rather than backslashes, when executing the SOURCE command.

6.   Execute the sakila-data.sql script topopulate the database structure with the following command:

7.  mysql> SOURCE C:/temp/sakila-db/sakila-data.sql;

Replace C:/temp/sakila-db with thepath to the sakila-data.sql file on your system.

8.   Confirm that the sample database is installed correctly.Execute the following statements. You should see output similar to that shownhere.

9.  mysql> USE sakila;

10.Database changed

11. 

12.mysql> SHOW TABLES;

13.+----------------------------+

14.| Tables_in_sakila           |

15.+----------------------------+

16.| actor                      |

17.| address                    |

18.| category                   |

19.| city                       |

20.| country                    |

21.| customer                   |

22.| customer_list              |

23.| film                       |

24.| film_actor                 |

25.| film_category              |

26.| film_list                  |

27.| film_text                  |

28.| inventory                  |

29.| language                   |

30.| nicer_but_slower_film_list |

31.| payment                    |

32.| rental                     |

33.| sales_by_film_category     |

34.| sales_by_store             |

35.| staff                      |

36.| staff_list                 |

37.| store                      |

38.+----------------------------+

39.22 rows in set (0.00 sec)

40. 

41.mysql> SELECT COUNT(*) FROM film;

42.+----------+

43.| COUNT(*) |

44.+----------+

45.| 1000    |

46.+----------+

47.1 row in set (0.02 sec)

48. 

49.mysql> SELECT COUNT(*) FROM film_text;

50.+----------+

51.| COUNT(*) |

52.+----------+

53.| 1000    |

54.+----------+

55.1 row in set (0.00 sec)

 

其余部分可以查看http://dev.mysql.com/doc/sakila/en/index.html#网页上的其它部分,

·        Sakila Sample Database

o    1 Preface and Legal Notices

o    2 Introduction

o    3 History

o    4 Installation

o    5 Structure

o    6 Usage Examples

o    7 Acknowledgments

o    8 License for the Sakila Sample Database

o    9 Note for Authors

o    10 Sakila Change History





原创粉丝点击