Chapter 3 Tutorial第3章 教程

Table of Contents目录

3.1 Connecting to and Disconnecting from the Server连接到服务器和断开与服务器的连接
3.2 Entering Queries输入查询
3.3 Creating and Using a Database创建和使用数据库
3.3.1 Creating and Selecting a Database创建和选择数据库
3.3.2 Creating a Table创建表
3.3.3 Loading Data into a Table将数据加载到表中
3.3.4 Retrieving Information from a Table从表中检索信息
3.4 Getting Information About Databases and Tables获取有关数据库和表的信息
3.5 Using mysql in Batch Mode在批处理模式下使用mysql
3.6 Examples of Common Queries常见查询示例
3.6.1 The Maximum Value for a Column列的最大值
3.6.2 The Row Holding the Maximum of a Certain Column包含某一列的最大值的行
3.6.3 Maximum of Column per Group每个组的最大列数
3.6.4 The Rows Holding the Group-wise Maximum of a Certain Column包含某一列按组最大值的行
3.6.5 Using User-Defined Variables使用用户定义的变量
3.6.6 Using Foreign Keys使用外键
3.6.7 Searching on Two Keys搜索两个键
3.6.8 Calculating Visits Per Day计算每天的访问量
3.6.9 Using 使用AUTO_INCREMENT
3.7 Using MySQL with Apache将MySQL与Apache结合使用

This chapter provides a tutorial introduction to MySQL by showing how to use the mysql client program to create and use a simple database. 本章通过演示如何使用mysql客户端程序创建和使用简单数据库,提供了MySQL的教程介绍。mysql (sometimes referred to as the terminal monitor or just monitor) is an interactive program that enables you to connect to a MySQL server, run queries, and view the results. mysql(有时称为“终端监视器”或“监视器”)是一个交互式程序,可用于连接mysql服务器、运行查询和查看结果。mysql may also be used in batch mode: you place your queries in a file beforehand, then tell mysql to execute the contents of the file. mysql也可以在批处理模式下使用:您预先将查询放入一个文件中,然后告诉mysql执行该文件的内容。Both ways of using mysql are covered here.这里介绍了使用mysql的两种方法。

To see a list of options provided by mysql, invoke it with the --help option:要查看mysql提供的选项列表,请使用--help选项调用它:

shell> mysql --help

This chapter assumes that mysql is installed on your machine and that a MySQL server is available to which you can connect. 本章假设您的计算机上安装了mysql,并且您可以连接到mysql服务器。If this is not true, contact your MySQL administrator. 如果不是这样,请与MySQL管理员联系。(If you are the administrator, you need to consult the relevant portions of this manual, such as Chapter 5, MySQL Server Administration.)(如果您是管理员,则需要参考本手册的相关部分,如第5章,“MySQL服务器管理”。)

This chapter describes the entire process of setting up and using a database. 本章介绍设置和使用数据库的整个过程。If you are interested only in accessing an existing database, you may want to skip the sections that describe how to create the database and the tables it contains.如果您只对访问现有数据库感兴趣,则可能希望跳过描述如何创建数据库及其包含的表的部分。

Because this chapter is tutorial in nature, many details are necessarily omitted. 由于本章本质上是教程,许多细节都必须省略。Consult the relevant sections of the manual for more information on the topics covered here.有关此处所涵盖主题的更多信息,请参阅手册的相关章节。

3.1 Connecting to and Disconnecting from the Server
3.2 Entering Queries
3.3 Creating and Using a Database
3.4 Getting Information About Databases and Tables
3.5 Using mysql in Batch Mode
3.6 Examples of Common Queries
3.7 Using MySQL with Apache