This is the MySQL reference manual; it documents MySQL version 3.22.15-gamma.
MySQL is a very fast, multi-threaded, multi-user and robust SQL database server.
For Unix and OS/2 platforms, MySQL is basically free; for Microsoft platforms you must get a MySQL license after a trial time of 30 days. See section 3 Licensing or When do I have/want to pay for MySQL?.
The MySQL home page provides the latest information about MySQL.
For a discussion of MySQL's capabilities, see section 1.4 The main features of MySQL.
For installation instructions, see section 4 Installing MySQL. For tips on porting MySQL to new machines or operating systems, see section G Comments on porting to other systems.
See section 4.16.1 Upgrading from a 3.21 version to 3.22, for information about upgrading from a 3.21 release.
For examples of SQL and benchmarking information, see the `bench' directory.
For a history of new features and bug fixes, see section D MySQL change history.
For a list of currently known bugs and misfeatures, see section E Known errors and design deficiencies in MySQL.
For future plans, see section F List of things we want to add to MySQL in the future (The TODO).
For a list of all the contributors to this product, see section C Contributors to MySQL.
IMPORTANT:
Send bug (error) reports, questions and comments to the mailing list at
For source distributions, the mysqlbug script can be found in the
`scripts' directory. For binary distributions, mysqlbug can be
found in the `bin' directory.
If you have any suggestions concerning additions or corrections to this
manual, please send them to the MySQL mailing list
(mysql@tcx.se) with the following subject line: documentation
suggestion: [Insert Topic Here].
See section 2.1 The MySQL mailing lists.
MySQL is a true multi-user, multi-threaded SQL (Structured
Query Language) database server. SQL is the most popular database
language in the world. MySQL is a client/server implementation
that consists of a server daemon mysqld and many different client
programs and libraries.
The main goals of MySQL are speed, robustness and ease of use. MySQL was originally developed because we at TcX needed a SQL server that could handle very large databases an order of magnitude faster than what any database vendor could offer to us. We have now been using MySQL since 1996 in an environment with more than 40 databases containing 10,000 tables, of which more than 500 have more than 7 million rows. This is about 100 gigabytes of mission-critical data.
The base upon which MySQL is built is a set of routines that have been used in a highly demanding production environment for many years. While MySQL is still in development, it already offers a rich and highly useful function set.
The official way to pronounce MySQL is "My Ess Que Ell" (Not MY-SEQUEL).
This manual is currently available in TeXInfo, plain text, Info and HTML versions. Because of their size, PostScript and PDF versions are available for separate download.
The primary document is the TeXInfo file. The HTML version is produced
automatically with a modified version of texi2html. The plain text and
Info versions are produced with makeinfo. The Postscript version is
produced using texi2dvi and dvips. The PDF version is produced
with the Ghostscript utility ps2pdf.
This manual is written and maintained by David Axmark, Michael (Monty) Widenius, Paul DuBois and Kim Aldale. For other contributors, see section C Contributors to MySQL.
This manual uses certain typographical conventions:
constant
mysqladmin works, invoke it with the
--help option."
When commands are shown that are meant to be executed by a particular
program, the prompt for the command indicates the program. For example,
shell> indicates a command that you execute from your login shell,
and mysql> indicates a command that you execute from the mysql
client:
shell> type a shell command here mysql> type a mysql command here
Shell commands are given using Bourne shell syntax. If you are using a
csh-style shell, you may need to issue commands slightly differently.
For example, the sequence to set an environment variable and run a command
looks like this in Bourne shell syntax:
shell> VARNAME=value some_command
For csh, you would execute the sequence like this:
shell> setenv VARNAME value shell> some_command
Database, table and column names often must be substituted into commands. To
indicate that such substitution is necessary, this manual uses
db_name, tbl_name and col_name. For example, if you see
this:
mysql> SELECT col_name FROM db_name.tbl_name;
It means that were you to enter a similar statement, you would supply your own database, table and column names, perhaps like this:
mysql> SELECT author_name FROM biblio_db.author_list;
SQL statements may be entered in uppercase or lowercase. When this manual
shows a SQL statement, uppercase is used for particular keywords if those
keywords are under discussion (to emphasize them) and lowercase for the
rest of the statement. So you might see the following in a discussion
of the SELECT statement:
mysql> SELECT count(*) FROM tbl_name;
On the other hand, in a discussion of the COUNT() function, the
statement would be written like this:
mysql> select COUNT(*) from tbl_name;
If no particular emphasis is intended, all keywords are written in uppercase.
In syntax descriptions, square brackets (`[' and `]') are used to indicate optional words or clauses:
DROP TABLE [IF EXISTS] tbl_name
When a syntax element consists of a number of alternatives, the alternatives are separated by vertical bars (`|'). When one member from a set of choices may be chosen, the alternatives are listed within square brackets. When one member from a set of choices must be chosen, the alternatives are listed within braces (`{' and `}'):
TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
{DESCRIBE | DESC} tbl_name {col_name | wild}
We once started off with the intention to use mSQL to connect to
our own fast low-level (ISAM) tables. However, after some testing we
came to the conclusion that mSQL was not fast enough or flexible
enough for our needs. This resulted in a new SQL interface to our database
but with almost the same API interface as mSQL. This API was chosen to
ease porting of third-party code.
The derivation of the name MySQL is not perfectly clear. Our base directory and a large number of our libraries and tools have had the prefix "my" for well over 10 years. However, Monty's daughter (some years younger) is also named My. So which of the two gave its name to MySQL is still a mystery, even for us.
FLOAT, DOUBLE, CHAR, VARCHAR,
TEXT, BLOB, DATE, DATETIME, TIMESTAMP,
YEAR, SET and ENUM types. See section 7.2 Column types.
SELECT and WHERE
parts of queries. Example:
mysql> SELECT CONCAT (first_name, " ", last_name) from tbl_name
WHERE income/dependents > 10000 AND age > 30;
GROUP BY and ORDER BY clauses. Support for
group functions (COUNT(), AVG(), STD(), SUM(),
MAX() and MIN()).
LEFT OUTER JOIN with ANSI SQL and ODBC syntax.
CHAR or VARCHAR field.
INSERT to insert a
subset of a table's columns and columns that were not explicitly given
values will be set to their default values.
libtool for portability.
purify).
isamchk, a very fast table check, optimize and repair utility.
See section 13 Using isamchk for table maintenance and crash recovery.
DELETE, INSERT, REPLACE, and UPDATE return
how many rows were affected.
ABS
is a valid column name. The only restriction is that for a function call, no
spaces are allowed between the function name and the `(' that follows it.
See section 7.30 Is MySQL picky about reserved words?.
--help or -?
options to obtain online assistance.
SHOW command can be used to retrieve
information about databases, tables and indexes. The EXPLAIN command
can be used to check how the optimizer resolves a query.
This section addresses the questions, "how stable is MySQL?" and, "can I depend on MySQL in this project?"
At TcX, MySQL has worked without any problems in our projects since mid-1996. When MySQL was released to a wider public, we noticed that there were some pieces of "untested code" that were quickly found by the new users who made queries in a different manner. Each new release has had fewer portability problems than the previous one, even though each has had many new features, and we hope that it will be possible to label one of the next releases "stable".
Each release of MySQL has been usable and there have been problems only when users start to use code from "the gray zones". Naturally, outside users can't know what the gray zones are; this section attempts to indicate those that are currently known.
Here we will try to clarify some issues and to answer some of the more important questions that seem to concern many people. This section has been put together from information gathered from the mailing list (which is very active in reporting bugs).
The descriptions deal with the 3.21.x version of MySQL. All known and reported bugs are fixed in the latest version, with the exception of the bugs listed in the BUGS file which are things that are "design"-related.
MySQL is written in multiple layers and different independent modules. Here is a list of the different modules and how well-tested each of them is:
mysql, mysqladmin and mysqlshow, mysqldump,
mysqlimport -- Stable
fcntl()). In these cases, you should run the
MySQL daemon with the --skip-locking flag. Problems are known
to occur on some Linux systems and on SunOS when using NFS-mounted file
systems.
fcntl() call, which is fixed
by using the --skip-locking option to mysqld. Some people
have reported lockup problems with the 0.5 release.
SELECT
statements are usually done in one time frame so there shouldn't be a mutex
locking/thread juggling.
LOAD DATA ..., INSERT ... SELECT -- Stable
ALTER TABLE -- Gamma
mysqlaccess -- Gamma
GRANT -- Alpha
TcX provides email support for paying customers, but the MySQL mailing list usually provides answers to common questions. Bugs are usually fixed right away with a patch; for serious bugs, there is almost always a new release.
MySQL itself has no problems with Year 2000 compliance:
2069; all 2-digit years are regarded to be in the range
1970 to 2069, which means that if you store 01 in a
year column, MySQL treats it as 2001.
YEAR column type
can store years 0 and 1901 to 2155 in 1 byte and display
them using 2 or 4 digits.
You may run into problems with applications that use MySQL in a
way that is not Year 2000-safe. For example, many old applications store
or manipulate years using 2-digit values (which are ambiguous) rather than
4-digit values. This problem may be compounded by applications that use
values such as 00 or 99 as "missing" value indicators.
Unfortunately, these problems may be difficult to fix, since different applications may be written by different programmers, each of whom may use a different set of conventions and date-handling functions.
Here is a simple test that shows that MySQL doesn't have any problems with dates until 2030 !
mysql> DROP TABLE IF EXISTS y2k;
mysql> CREATE TABLE y2k (date date, date_time datetime, time_stamp timestamp);
mysql> INSERT INTO y2k VALUES ("1998-12-31","1998-12-31 23:59:59",19981231235959);
mysql> INSERT INTO y2k VALUES ("1999-01-01","1999-01-01 00:00:00",19990101000000);
mysql> INSERT INTO y2k VALUES ("1999-09-09","1999-09-09 23:59:59",19990909235959);
mysql> INSERT INTO y2k VALUES ("2000-01-01","2000-01-01 00:00:00",20000101000000);
mysql> INSERT INTO y2k VALUES ("2000-02-28","2000-02-28 00:00:00",20000228000000);
mysql> INSERT INTO y2k VALUES ("2000-02-29","2000-02-29 00:00:00",20000229000000);
mysql> INSERT INTO y2k VALUES ("2000-03-01","2000-03-01 00:00:00",20000301000000);
mysql> INSERT INTO y2k VALUES ("2000-12-31","2000-12-31 23:59:59",20001231235959);
mysql> INSERT INTO y2k VALUES ("2001-01-01","2001-01-01 00:00:00",20010101000000);
mysql> INSERT INTO y2k VALUES ("2004-12-31","2004-12-31 23:59:59",20041231235959);
mysql> INSERT INTO y2k VALUES ("2005-01-01","2005-01-01 00:00:00",20050101000000);
mysql> INSERT INTO y2k VALUES ("2030-01-01","2030-01-01 00:00:00",20300101000000);
mysql> INSERT INTO y2k VALUES ("2050-01-01","2050-01-01 00:00:00",20500101000000);
mysql> SELECT * FROM y2k;
+------------+---------------------+----------------+
| date | date_time | time_stamp |
+------------+---------------------+----------------+
| 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
| 1999-01-01 | 1999-01-01 00:00:00 | 19981231000000 |
| 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
| 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
| 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
| 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
| 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
| 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
| 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
| 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
| 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
| 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
| 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
+------------+---------------------+----------------+
13 rows in set (0.00 sec)
mysql> DROP TABLE y2k;
This shows that the DATE and DATETIME types are Date
Data compliant, while the TIMESTAMP type, that is used to store the
current time, only has a range up to 2030-01-01. TIMESTAMP has
a range of 1970 to 2030 on 32-bit machines.
This book has been recommended by a several people on the MySQL mailing list:
Judith S. Bowman, Sandra L. Emerson and Marcy Darnovsky The Practical SQL Handbook: Using Structured Query Language Second Edition Addison-Wesley ISBN 0-201-62623-3 http://www.awl.com
This book has also received some recommendations on the mailing list:
Martin Gruber Understanding SQL ISBN 0-89588-644-8 Publisher Sybex 510 523 8233 Alameda, CA USA
A SQL tutorial is available on the net at http://w3.one.net/~jhoffman/sqltut.htm.
DBI/DBD.
mSQL
mSQL TCL
DBI/DBD modules homepage
There are also many web pages that use MySQL. See section A Some MySQL users. Send any additions to this list to
Go to the first, previous, next, last section, table of contents.