MySQL Tutorial

Table of Contents

31. Connecting to and Disconnecting from the Server
32. Entering Queries
33. Creating and Using a Database
Creating and Selecting a Database
Creating a Table
Loading Data into a Table
Retrieving Information from a Table
Selecting All Data
Selecting Particular Rows
Selecting Particular Columns
Sorting Rows
Date Calculations
Working with NULL Values
Pattern Matching
Counting Rows
Using More Than one Table
34. Getting Information About Databases and Tables
35. Using mysql in Batch Mode
36. Examples of Common Queries
The Maximum Value for a Column
The Row Holding the Maximum of a Certain Column
Maximum of Column per Group
The Rows Holding the Group-wise Maximum of a Certain Field
Using User Variables
Using Foreign Keys
Searching on Two Keys
Calculating Visits Per Day
Using AUTO_INCREMENT
37. Queries from the Twin Project
Find All Non-distributed Twins
Show a Table of Twin Pair Status
38. Using MySQL with 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 (sometimes referred to as the ``terminal monitor'' or just ``monitor'') is an interactive program that allows you to connect to a MySQL server, run queries, and view the results. 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. Both ways of using mysql are covered here.

To see a list of options provided by mysql, invoke it with the --help option:

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. If this is not true, contact your MySQL administrator. (If you are the administrator, you will need to consult other sections of this manual.)

This chapter describes the entire process of setting up and using a database. If you are interested only in accessing an already-existing database, you may want to skip over 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.