My SQL Reference Manual
User Manual:
Open the PDF directly: View PDF .
Page Count: 1406
MySQL Reference Manual
c 1997-2004 MySQL AB
Copyright °
i
Table of Contents
1
General Information . . . . . . . . . . . . . . . . . . . . . . . 1
1.1
1.2
1.3
1.4
1.5
About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Conventions Used in This Manual . . . . . . . . . . . . . . . . 2
Overview of the MySQL Database Management System . . . . 4
1.2.1 History of MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 The Main Features of MySQL . . . . . . . . . . . . . . . . . . . 6
1.2.3 MySQL Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.4 How Big MySQL Tables Can Be . . . . . . . . . . . . . . . . . 9
1.2.5 Year 2000 Compliance . . . . . . . . . . . . . . . . . . . . . . . . . 10
Overview of MySQL AB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3.1 The Business Model and Services of MySQL AB . . 13
1.3.1.1 Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.1.2 Training and Certification . . . . . . . . . . . . . 13
1.3.1.3 Consulting . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.3.1.4 Commercial Licenses . . . . . . . . . . . . . . . . . . 14
1.3.1.5 Partnering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.2 Contact Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
MySQL Support and Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4.1 Support Offered by MySQL AB. . . . . . . . . . . . . . . . . 16
1.4.2 Copyrights and Licenses Used by MySQL. . . . . . . . 17
1.4.3 MySQL Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.3.1 Using the MySQL Software Under a
Commercial License . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.3.2 Using the MySQL Software for Free Under
GPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4.4 MySQL AB Logos and Trademarks . . . . . . . . . . . . . 19
1.4.4.1 The Original MySQL Logo. . . . . . . . . . . . . 20
1.4.4.2 MySQL Logos That May Be Used Without
Written Permission . . . . . . . . . . . . . . . . . . . . . . . 20
1.4.4.3 When You Need Written Permission to Use
MySQL Logos . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.4.4.4 MySQL AB Partnership Logos . . . . . . . . . 21
1.4.4.5 Using the Word MySQL in Printed Text or
Presentations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.4.4.6 Using the Word MySQL in Company and
Product Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
MySQL Development Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.5.1 MySQL 4.0 in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . 22
1.5.1.1 Features Available in MySQL 4.0 . . . . . . . 22
1.5.1.2 The Embedded MySQL Server . . . . . . . . . 23
1.5.2 MySQL 4.1 in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . 24
1.5.2.1 Features Available in MySQL 4.1 . . . . . . . 24
1.5.2.2 Stepwise Rollout . . . . . . . . . . . . . . . . . . . . . . 25
ii
1.5.2.3 Ready for Immediate Development Use
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.5.3 MySQL 5.0: The Next Development Release . . . . . 26
1.6 MySQL and the Future (the TODO) . . . . . . . . . . . . . . . . . . . . 26
1.6.1 New Features Planned for 5.0 . . . . . . . . . . . . . . . . . . . 26
1.6.2 New Features Planned for 5.1 . . . . . . . . . . . . . . . . . . . 27
1.6.3 New Features Planned for the Near Future . . . . . . 28
1.6.4 New Features Planned for the Mid-Term Future . . 30
1.6.5 New Features We Don’t Plan to Implement . . . . . . 31
1.7 MySQL Information Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.7.1 MySQL Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.7.1.1 The MySQL Mailing Lists . . . . . . . . . . . . . 32
1.7.1.2 Asking Questions or Reporting Bugs. . . . 33
1.7.1.3 How to Report Bugs or Problems . . . . . . 34
1.7.1.4 Guidelines for Answering Questions on the
Mailing List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
1.7.2 MySQL Community Support on IRC (Internet Relay
Chat) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.8 MySQL Standards Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.8.1 What Standards MySQL Follows . . . . . . . . . . . . . . . 40
1.8.2 Selecting SQL Modes . . . . . . . . . . . . . . . . . . . . . . . . . . 40
1.8.3 Running MySQL in ANSI Mode . . . . . . . . . . . . . . . . 40
1.8.4 MySQL Extensions to Standard SQL . . . . . . . . . . . . 41
1.8.5 MySQL Differences from Standard SQL . . . . . . . . . 44
1.8.5.1 Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.8.5.2 SELECT INTO TABLE . . . . . . . . . . . . . . . . . . . 44
1.8.5.3 Transactions and Atomic Operations . . . 45
1.8.5.4 Stored Procedures and Triggers . . . . . . . . 47
1.8.5.5 Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . 47
1.8.5.6 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
1.8.5.7 ‘--’ as the Start of a Comment. . . . . . . . . 49
1.8.6 How MySQL Deals with Constraints . . . . . . . . . . . . 50
1.8.6.1 Constraint PRIMARY KEY / UNIQUE . . . . . . 50
1.8.6.2 Constraint NOT NULL and DEFAULT Values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1.8.6.3 Constraint ENUM and SET . . . . . . . . . . . . . . 52
1.8.7 Known Errors and Design Deficiencies in MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
1.8.7.1 Errors in 3.23 Fixed in a Later MySQL
Version. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
1.8.7.2 Errors in 4.0 Fixed in a Later MySQL
Version. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.8.7.3 Open Bugs and Design Deficiencies in
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
iii
2
Installing MySQL . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.1
General Installation Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.1.1 Operating Systems Supported by MySQL . . . . . . . 60
2.1.2 Choosing Which MySQL Distribution to Install . . 61
2.1.2.1 Choosing Which Version of MySQL to
Install. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.1.2.2 Choosing a Distribution Format . . . . . . . . 64
2.1.2.3 How and When Updates Are Released . . 65
2.1.2.4 Release Philosophy—No Known Bugs in
Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.1.2.5 MySQL Binaries Compiled by MySQL AB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.1.3 How to Get MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.1.4 Verifying Package Integrity Using MD5 Checksums
or GnuPG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2.1.4.1 Verifying the MD5 Checksum . . . . . . . . . . 73
2.1.4.2 Signature Checking Using GnuPG . . . . . . . 74
2.1.4.3 Signature Checking Using RPM. . . . . . . . . . 75
2.1.5 Installation Layouts. . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
2.2 Standard MySQL Installation Using a Binary Distribution
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.2.1 Installing MySQL on Windows . . . . . . . . . . . . . . . . . 77
2.2.1.1 Windows System Requirements . . . . . . . . 78
2.2.1.2 Installing a Windows Binary Distribution
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
2.2.1.3 Preparing the Windows MySQL
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.2.1.4 Selecting a Windows Server . . . . . . . . . . . . 81
2.2.1.5 Starting the Server for the First Time . . 82
2.2.1.6 Starting MySQL from the Windows
Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
2.2.1.7 Starting MySQL as a Windows Service . . 84
2.2.1.8 Troubleshooting a MySQL Installation
Under Windows . . . . . . . . . . . . . . . . . . . . . . . . . . 86
2.2.1.9 Running MySQL Client Programs on
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.2.1.10 MySQL on Windows Compared to
MySQL on Unix . . . . . . . . . . . . . . . . . . . . . . . . . . 88
2.2.2 Installing MySQL on Linux. . . . . . . . . . . . . . . . . . . . . 90
2.2.3 Installing MySQL on Mac OS X . . . . . . . . . . . . . . . . 93
2.2.4 Installing MySQL on NetWare . . . . . . . . . . . . . . . . . . 95
2.2.5 Installing MySQL on Other Unix-Like Systems. . . 97
2.3 MySQL Installation Using a Source Distribution . . . . . . . . . 100
2.3.1 Source Installation Overview . . . . . . . . . . . . . . . . . . 101
2.3.2 Typical configure Options . . . . . . . . . . . . . . . . . . . 103
2.3.3 Installing from the Development Source Tree . . . 106
2.3.4 Dealing with Problems Compiling MySQL . . . . . . 109
2.3.5 MIT-pthreads Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 112
iv
2.3.6 Installing MySQL from Source on Windows. . . . . 113
2.3.6.1 Building MySQL Using VC++ . . . . . . . . . 114
2.3.6.2 Creating a Windows Source Package from
the Latest Development Source . . . . . . . . . . . 116
2.3.7 Compiling MySQL Clients on Windows . . . . . . . . 117
2.4 Post-Installation Setup and Testing . . . . . . . . . . . . . . . . . . . . . 117
2.4.1 Windows Post-Installation Procedures . . . . . . . . . . 118
2.4.2 Unix Post-Installation Procedures . . . . . . . . . . . . . . 118
2.4.2.1 Problems Running mysql_install_db
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
2.4.2.2 Starting and Stopping MySQL
Automatically . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
2.4.2.3 Starting and Troubleshooting the MySQL
Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
2.4.3 Securing the Initial MySQL Accounts . . . . . . . . . . 130
2.5 Upgrading/Downgrading MySQL . . . . . . . . . . . . . . . . . . . . . . . 133
2.5.1 Upgrading from Version 4.1 to 5.0 . . . . . . . . . . . . . 134
2.5.2 Upgrading from Version 4.0 to 4.1 . . . . . . . . . . . . . 134
2.5.3 Upgrading from Version 3.23 to 4.0 . . . . . . . . . . . . 139
2.5.4 Upgrading from Version 3.22 to 3.23 . . . . . . . . . . . 143
2.5.5 Upgrading from Version 3.21 to 3.22 . . . . . . . . . . . 145
2.5.6 Upgrading from Version 3.20 to 3.21 . . . . . . . . . . . 145
2.5.7 Upgrading MySQL Under Windows . . . . . . . . . . . . 146
2.5.8 Upgrading the Grant Tables . . . . . . . . . . . . . . . . . . . 147
2.5.9 Copying MySQL Databases to Another Machine
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
2.6 Operating System-Specific Notes . . . . . . . . . . . . . . . . . . . . . . . 149
2.6.1 Linux Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
2.6.1.1 Linux Operating System Notes . . . . . . . . 149
2.6.1.2 Linux Binary Distribution Notes . . . . . . 150
2.6.1.3 Linux Source Distribution Notes . . . . . . 151
2.6.1.4 Linux Post-Installation Notes . . . . . . . . . 152
2.6.1.5 Linux x86 Notes . . . . . . . . . . . . . . . . . . . . . 154
2.6.1.6 Linux SPARC Notes . . . . . . . . . . . . . . . . . 155
2.6.1.7 Linux Alpha Notes . . . . . . . . . . . . . . . . . . . 156
2.6.1.8 Linux PowerPC Notes . . . . . . . . . . . . . . . . 156
2.6.1.9 Linux MIPS Notes . . . . . . . . . . . . . . . . . . . 156
2.6.1.10 Linux IA-64 Notes . . . . . . . . . . . . . . . . . . 157
2.6.2 Mac OS X Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
2.6.2.1 Mac OS X 10.x (Darwin) . . . . . . . . . . . . . 157
2.6.2.2 Mac OS X Server 1.2 (Rhapsody) . . . . . 157
2.6.3 Solaris Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
2.6.3.1 Solaris 2.7/2.8 Notes . . . . . . . . . . . . . . . . . 160
2.6.3.2 Solaris x86 Notes . . . . . . . . . . . . . . . . . . . . 161
2.6.4 BSD Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
2.6.4.1 FreeBSD Notes . . . . . . . . . . . . . . . . . . . . . . 161
2.6.4.2 NetBSD Notes . . . . . . . . . . . . . . . . . . . . . . . 163
2.6.4.3 OpenBSD 2.5 Notes . . . . . . . . . . . . . . . . . . 163
v
2.7
3
2.6.4.4 OpenBSD 2.8 Notes . . . . . . . . . . . . . . . . . .
2.6.4.5 BSD/OS Version 2.x Notes . . . . . . . . . . .
2.6.4.6 BSD/OS Version 3.x Notes . . . . . . . . . . .
2.6.4.7 BSD/OS Version 4.x Notes . . . . . . . . . . .
2.6.5 Other Unix Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6.5.1 HP-UX Version 10.20 Notes. . . . . . . . . . .
2.6.5.2 HP-UX Version 11.x Notes. . . . . . . . . . . .
2.6.5.3 IBM-AIX notes . . . . . . . . . . . . . . . . . . . . . .
2.6.5.4 SunOS 4 Notes . . . . . . . . . . . . . . . . . . . . . .
2.6.5.5 Alpha-DEC-UNIX Notes (Tru64). . . . . .
2.6.5.6 Alpha-DEC-OSF/1 Notes . . . . . . . . . . . . .
2.6.5.7 SGI Irix Notes . . . . . . . . . . . . . . . . . . . . . . .
2.6.5.8 SCO Notes . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6.5.9 SCO UnixWare Version 7.1.x Notes. . . .
2.6.6 OS/2 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6.7 BeOS Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Perl Installation Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.7.1 Installing Perl on Unix . . . . . . . . . . . . . . . . . . . . . . . .
2.7.2 Installing ActiveState Perl on Windows . . . . . . . .
2.7.3 Problems Using the Perl DBI/DBD Interface . . . . .
163
163
164
164
165
165
165
167
168
169
170
171
172
176
178
178
179
179
180
180
MySQL Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . 184
3.1
3.2
3.3
Connecting to and Disconnecting from the Server . . . . . . . . 184
Entering Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Creating and Using a Database. . . . . . . . . . . . . . . . . . . . . . . . . 188
3.3.1 Creating and Selecting a Database . . . . . . . . . . . . . 189
3.3.2 Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
3.3.3 Loading Data into a Table . . . . . . . . . . . . . . . . . . . . 191
3.3.4 Retrieving Information from a Table . . . . . . . . . . . 192
3.3.4.1 Selecting All Data . . . . . . . . . . . . . . . . . . . 193
3.3.4.2 Selecting Particular Rows . . . . . . . . . . . . . 193
3.3.4.3 Selecting Particular Columns . . . . . . . . . 195
3.3.4.4 Sorting Rows . . . . . . . . . . . . . . . . . . . . . . . . 196
3.3.4.5 Date Calculations . . . . . . . . . . . . . . . . . . . . 197
3.3.4.6 Working with NULL Values . . . . . . . . . . . . 200
3.3.4.7 Pattern Matching . . . . . . . . . . . . . . . . . . . . 201
3.3.4.8 Counting Rows . . . . . . . . . . . . . . . . . . . . . . 204
3.3.4.9 Using More Than one Table . . . . . . . . . . 206
3.4 Getting Information About Databases and Tables . . . . . . . 207
3.5 Using mysql in Batch Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
3.6 Examples of Common Queries . . . . . . . . . . . . . . . . . . . . . . . . . . 210
3.6.1 The Maximum Value for a Column . . . . . . . . . . . . 211
3.6.2 The Row Holding the Maximum of a Certain
Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
3.6.3 Maximum of Column per Group . . . . . . . . . . . . . . . 212
3.6.4 The Rows Holding the Group-wise Maximum of a
Certain Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
3.6.5 Using User Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 213
vi
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 Queries from the Twin Project . . . . . . . . . . . . . . . . . . . . . . . . .
3.7.1 Find All Non-distributed Twins. . . . . . . . . . . . . . . .
3.7.2 Show a Table of Twin Pair Status . . . . . . . . . . . . .
3.8 Using MySQL with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
Using MySQL Programs . . . . . . . . . . . . . . . . . 222
4.1 Overview of MySQL Programs . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Invoking MySQL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 Specifying Program Options . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3.1 Using Options on the Command Line . . . . . . . . . .
4.3.2 Using Option Files. . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3.3 Using Environment Variables to Specify Options
...............................................
4.3.4 Using Options to Set Program Variables . . . . . . . .
5
213
215
216
216
218
218
221
221
222
222
223
224
225
229
229
Database Administration . . . . . . . . . . . . . . . . . 231
5.1
5.2
5.3
5.4
5.5
The MySQL Server and Server Startup Scripts . . . . . . . . . . 231
5.1.1 Overview of the Server-Side Scripts and Utilities
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
5.1.2 The mysqld-max Extended MySQL Server . . . . . . 232
5.1.3 The mysqld_safe Server Startup Script . . . . . . . . 234
5.1.4 The mysql.server Server Startup Script . . . . . . . 237
5.1.5 The mysqld_multi Program for Managing Multiple
MySQL Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Configuring the MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . 241
5.2.1 mysqld Command-Line Options . . . . . . . . . . . . . . . 241
5.2.2 The Server SQL Mode . . . . . . . . . . . . . . . . . . . . . . . . 251
5.2.3 Server System Variables . . . . . . . . . . . . . . . . . . . . . . . 255
5.2.3.1 Dynamic System Variables . . . . . . . . . . . . 278
5.2.4 Server Status Variables . . . . . . . . . . . . . . . . . . . . . . . 281
The MySQL Server Shutdown Process . . . . . . . . . . . . . . . . . . 288
General Security Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
5.4.1 General Security Guidelines . . . . . . . . . . . . . . . . . . . 290
5.4.2 Making MySQL Secure Against Attackers . . . . . . 292
5.4.3 Startup Options for mysqld Concerning Security
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
5.4.4 Security Issues with LOAD DATA LOCAL . . . . . . . . . . 295
The MySQL Access Privilege System . . . . . . . . . . . . . . . . . . . 296
5.5.1 What the Privilege System Does . . . . . . . . . . . . . . . 296
5.5.2 How the Privilege System Works. . . . . . . . . . . . . . . 296
5.5.3 Privileges Provided by MySQL . . . . . . . . . . . . . . . . 300
5.5.4 Connecting to the MySQL Server . . . . . . . . . . . . . . 303
5.5.5 Access Control, Stage 1: Connection Verification
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
vii
5.5.6
5.5.7
5.5.8
5.5.9
Access Control, Stage 2: Request Verification . . . 308
When Privilege Changes Take Effect . . . . . . . . . . . 311
Causes of Access denied Errors . . . . . . . . . . . . . . . 311
Password Hashing in MySQL 4.1 . . . . . . . . . . . . . . 316
5.5.9.1 Implications of Password Hashing Changes
for Application Programs . . . . . . . . . . . . . . . . . 320
5.5.9.2 Password Hashing in MySQL 4.1.0 . . . . 320
5.6 MySQL User Account Management . . . . . . . . . . . . . . . . . . . . . 321
5.6.1 MySQL Usernames and Passwords . . . . . . . . . . . . . 321
5.6.2 Adding New User Accounts to MySQL . . . . . . . . . 322
5.6.3 Removing User Accounts from MySQL . . . . . . . . . 326
5.6.4 Limiting Account Resources . . . . . . . . . . . . . . . . . . . 326
5.6.5 Assigning Account Passwords . . . . . . . . . . . . . . . . . . 327
5.6.6 Keeping Your Password Secure . . . . . . . . . . . . . . . . 328
5.6.7 Using Secure Connections . . . . . . . . . . . . . . . . . . . . . 330
5.6.7.1 Basic SSL Concepts . . . . . . . . . . . . . . . . . . 330
5.6.7.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . 331
5.6.7.3 Setting Up SSL Certificates for MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
5.6.7.4 SSL GRANT Options . . . . . . . . . . . . . . . . . . 335
5.6.7.5 SSL Command-Line Options . . . . . . . . . . 337
5.6.7.6 Connecting to MySQL Remotely from
Windows with SSH . . . . . . . . . . . . . . . . . . . . . . 338
5.7 Disaster Prevention and Recovery . . . . . . . . . . . . . . . . . . . . . . 338
5.7.1 Database Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
5.7.2 Table Maintenance and Crash Recovery . . . . . . . . 340
5.7.2.1 myisamchk Invocation Syntax . . . . . . . . . 340
5.7.2.2 General Options for myisamchk . . . . . . . 342
5.7.2.3 Check Options for myisamchk . . . . . . . . . 344
5.7.2.4 Repair Options for myisamchk . . . . . . . . 344
5.7.2.5 Other Options for myisamchk . . . . . . . . . 346
5.7.2.6 myisamchk Memory Usage . . . . . . . . . . . . 347
5.7.2.7 Using myisamchk for Crash Recovery . . 347
5.7.2.8 How to Check MyISAM Tables for Errors
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
5.7.2.9 How to Repair Tables . . . . . . . . . . . . . . . . 349
5.7.2.10 Table Optimization . . . . . . . . . . . . . . . . . 351
5.7.3 Setting Up a Table Maintenance Schedule . . . . . . 352
5.7.4 Getting Information About a Table . . . . . . . . . . . . 353
5.8 MySQL Localization and International Usage . . . . . . . . . . . 359
5.8.1 The Character Set Used for Data and Sorting . . . 359
5.8.1.1 Using the German Character Set . . . . . . 360
5.8.2 Setting the Error Message Language . . . . . . . . . . . 360
5.8.3 Adding a New Character Set . . . . . . . . . . . . . . . . . . 361
5.8.4 The Character Definition Arrays . . . . . . . . . . . . . . . 362
5.8.5 String Collating Support . . . . . . . . . . . . . . . . . . . . . . 363
5.8.6 Multi-Byte Character Support . . . . . . . . . . . . . . . . . 363
5.8.7 Problems With Character Sets. . . . . . . . . . . . . . . . . 363
viii
5.8.8 MySQL Server Time Zone Support . . . . . . . . . . . . 364
The MySQL Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
5.9.1 The Error Log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
5.9.2 The General Query Log . . . . . . . . . . . . . . . . . . . . . . . 366
5.9.3 The Update Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
5.9.4 The Binary Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
5.9.5 The Slow Query Log . . . . . . . . . . . . . . . . . . . . . . . . . . 371
5.9.6 Log File Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . 371
5.10 Running Multiple MySQL Servers on the Same Machine
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
5.10.1 Running Multiple Servers on Windows . . . . . . . . 373
5.10.1.1 Starting Multiple Windows Servers at the
Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . 374
5.10.1.2 Starting Multiple Windows Servers as
Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
5.10.2 Running Multiple Servers on Unix . . . . . . . . . . . . 377
5.10.3 Using Client Programs in a Multiple-Server
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
5.11 The MySQL Query Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
5.11.1 How the Query Cache Operates. . . . . . . . . . . . . . . 379
5.11.2 Query Cache SELECT Options . . . . . . . . . . . . . . . . . 381
5.11.3 Query Cache Configuration. . . . . . . . . . . . . . . . . . . 381
5.11.4 Query Cache Status and Maintenance . . . . . . . . . 382
5.9
6
Replication in MySQL . . . . . . . . . . . . . . . . . . . 384
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
Introduction to Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replication Implementation Overview. . . . . . . . . . . . . . . . . . .
Replication Implementation Details . . . . . . . . . . . . . . . . . . . . .
6.3.1 Replication Master Thread States . . . . . . . . . . . . . .
6.3.2 Replication Slave I/O Thread States . . . . . . . . . . .
6.3.3 Replication Slave SQL Thread States . . . . . . . . . .
6.3.4 Replication Relay and Status Files . . . . . . . . . . . . .
How to Set Up Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replication Compatibility Between MySQL Versions . . . . .
Upgrading a Replication Setup . . . . . . . . . . . . . . . . . . . . . . . . .
6.6.1 Upgrading Replication to 4.0 or 4.1 . . . . . . . . . . . .
6.6.2 Upgrading Replication to 5.0 . . . . . . . . . . . . . . . . . .
Replication Features and Known Problems . . . . . . . . . . . . . .
Replication Startup Options . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replication FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Troubleshooting Replication . . . . . . . . . . . . . . . . . . . . . . . . . .
Reporting Replication Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . .
384
384
385
387
387
388
389
391
395
395
395
396
397
400
409
415
416
ix
7
MySQL Optimization . . . . . . . . . . . . . . . . . . . . 418
7.1
Optimization Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
7.1.1 MySQL Design Limitations and Tradeoffs . . . . . . 418
7.1.2 Designing Applications for Portability . . . . . . . . . . 419
7.1.3 What We Have Used MySQL For . . . . . . . . . . . . . . 420
7.1.4 The MySQL Benchmark Suite . . . . . . . . . . . . . . . . . 421
7.1.5 Using Your Own Benchmarks. . . . . . . . . . . . . . . . . . 422
7.2 Optimizing SELECT Statements and Other Queries . . . . . . . 422
7.2.1 EXPLAIN Syntax (Get Information About a SELECT)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
7.2.2 Estimating Query Performance . . . . . . . . . . . . . . . . 431
7.2.3 Speed of SELECT Queries . . . . . . . . . . . . . . . . . . . . . . 431
7.2.4 How MySQL Optimizes WHERE Clauses . . . . . . . . . 432
7.2.5 Range Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . 434
7.2.5.1 Range Access Method for Single-Part
Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
7.2.5.2 Range Access Method for Multiple-Part
Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
7.2.6 Index Merge Optimization . . . . . . . . . . . . . . . . . . . . 437
7.2.6.1 Index Merge Intersection Access Algorithm
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
7.2.6.2 Index Merge Union Access Algorithm . . 439
7.2.6.3 Index Merge Sort-Union Access Algorithm
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
7.2.7 How MySQL Optimizes IS NULL . . . . . . . . . . . . . . . 439
7.2.8 How MySQL Optimizes DISTINCT . . . . . . . . . . . . . 440
7.2.9 How MySQL Optimizes LEFT JOIN and RIGHT JOIN
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
7.2.10 How MySQL Optimizes ORDER BY . . . . . . . . . . . . . 441
7.2.11 How MySQL Optimizes LIMIT . . . . . . . . . . . . . . . . 444
7.2.12 How to Avoid Table Scans . . . . . . . . . . . . . . . . . . . 444
7.2.13 Speed of INSERT Statements . . . . . . . . . . . . . . . . . . 445
7.2.14 Speed of UPDATE Statements . . . . . . . . . . . . . . . . . . 447
7.2.15 Speed of DELETE Statements . . . . . . . . . . . . . . . . . . 447
7.2.16 Other Optimization Tips . . . . . . . . . . . . . . . . . . . . . 447
7.3 Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
7.3.1 Locking Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
7.3.2 Table Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . 452
7.4 Optimizing Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . 454
7.4.1 Design Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
7.4.2 Make Your Data as Small as Possible . . . . . . . . . . 454
7.4.3 Column Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
7.4.4 Multiple-Column Indexes. . . . . . . . . . . . . . . . . . . . . . 456
7.4.5 How MySQL Uses Indexes . . . . . . . . . . . . . . . . . . . . 457
7.4.6 The MyISAM Key Cache . . . . . . . . . . . . . . . . . . . . . . . 459
7.4.6.1 Shared Key Cache Access . . . . . . . . . . . . . 460
7.4.6.2 Multiple Key Caches . . . . . . . . . . . . . . . . . 461
7.4.6.3 Midpoint Insertion Strategy. . . . . . . . . . . 462
x
7.4.6.4 Index Preloading . . . . . . . . . . . . . . . . . . . . . 463
7.4.6.5 Key Cache Block Size . . . . . . . . . . . . . . . . 463
7.4.6.6 Restructuring a Key Cache . . . . . . . . . . . 464
7.4.7 How MySQL Counts Open Tables . . . . . . . . . . . . . 464
7.4.8 How MySQL Opens and Closes Tables . . . . . . . . . 465
7.4.9 Drawbacks to Creating Many Tables in the Same
Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
7.5 Optimizing the MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . 466
7.5.1 System Factors and Startup Parameter Tuning . . 466
7.5.2 Tuning Server Parameters . . . . . . . . . . . . . . . . . . . . . 467
7.5.3 Controlling Query Optimizer Performance . . . . . . 469
7.5.4 How Compiling and Linking Affects the Speed of
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
7.5.5 How MySQL Uses Memory . . . . . . . . . . . . . . . . . . . . 471
7.5.6 How MySQL Uses DNS . . . . . . . . . . . . . . . . . . . . . . . 473
7.6 Disk Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
7.6.1 Using Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . 475
7.6.1.1 Using Symbolic Links for Databases on
Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
7.6.1.2 Using Symbolic Links for Tables on Unix
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
7.6.1.3 Using Symbolic Links for Databases on
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
8
MySQL Client and Utility Programs . . . . . . 479
8.1 Overview of the Client-Side Scripts and Utilities . . . . . . . . .
8.2 myisampack, the MySQL Compressed Read-only Table
Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.3 mysql, the Command-Line Tool . . . . . . . . . . . . . . . . . . . . . . . .
8.3.1 mysql Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.3.2 Executing SQL Statements from a Text File . . . .
8.3.3 mysql Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.3.3.1 Displaying Query Results Vertically . . .
8.3.3.2 Using the --safe-updates Option . . . .
8.3.3.3 Disabling mysql Auto-Reconnect . . . . . .
8.4 mysqladmin, Administering a MySQL Server . . . . . . . . . . . .
8.5 The mysqlbinlog Binary Log Utility . . . . . . . . . . . . . . . . . . .
8.6 mysqlcc, the MySQL Control Center . . . . . . . . . . . . . . . . . . .
8.7 The mysqlcheck Table Maintenance and Repair Program
......................................................
8.8 The mysqldump Database Backup Program . . . . . . . . . . . . . .
8.9 The mysqlhotcopy Database Backup Program . . . . . . . . . .
8.10 The mysqlimport Data Import Program . . . . . . . . . . . . . . .
8.11 mysqlshow, Showing Databases, Tables, and Columns . . .
8.12 perror, Explaining Error Codes . . . . . . . . . . . . . . . . . . . . . . .
8.13 The replace String-Replacement Utility . . . . . . . . . . . . . . .
479
480
487
491
495
495
495
496
496
497
501
504
506
508
514
516
518
520
520
xi
9
MySQL Language Reference . . . . . . . . . . . . . 522
10
Language Structure . . . . . . . . . . . . . . . . . . . . . 523
10.1 Literal Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.1.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.1.2 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.1.3 Hexadecimal Values. . . . . . . . . . . . . . . . . . . . . . . . . .
10.1.4 Boolean Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.1.5 NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2 Database, Table, Index, Column, and Alias Names . . . . . .
10.2.1 Identifier Qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2.2 Identifier Case Sensitivity . . . . . . . . . . . . . . . . . . . .
10.3 User Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.4 System Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.4.1 Structured System Variables. . . . . . . . . . . . . . . . . .
10.5 Comment Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.6 Treatment of Reserved Words in MySQL. . . . . . . . . . . . . . .
11
523
523
525
525
526
526
526
528
528
530
531
533
534
535
Character Set Support . . . . . . . . . . . . . . . . . . 539
11.1 Character Sets and Collations in General . . . . . . . . . . . . . . 539
11.2 Character Sets and Collations in MySQL . . . . . . . . . . . . . . 540
11.3 Determining the Default Character Set and Collation . . . 541
11.3.1 Server Character Set and Collation . . . . . . . . . . . 541
11.3.2 Database Character Set and Collation . . . . . . . . . 542
11.3.3 Table Character Set and Collation . . . . . . . . . . . . 542
11.3.4 Column Character Set and Collation . . . . . . . . . . 543
11.3.5 Examples of Character Set and Collation
Assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
11.3.6 Connection Character Sets and Collations . . . . . 545
11.3.7 Character String Literal Character Set and
Collation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
11.3.8 Using COLLATE in SQL Statements . . . . . . . . . . . . 547
11.3.9 COLLATE Clause Precedence . . . . . . . . . . . . . . . . . . 548
11.3.10 BINARY Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
11.3.11 Some Special Cases Where the Collation
Determination Is Tricky . . . . . . . . . . . . . . . . . . . . . . . . . 548
11.3.12 Collations Must Be for the Right Character Set
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
11.3.13 An Example of the Effect of Collation . . . . . . . . 550
11.4 Operations Affected by Character Set Support . . . . . . . . . 551
11.4.1 Result Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
11.4.2 CONVERT() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
11.4.3 CAST() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
11.4.4 SHOW Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
11.5 Unicode Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
11.6 UTF8 for Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
11.7 Compatibility with Other DBMSs . . . . . . . . . . . . . . . . . . . . . 556
xii
11.8 New Character Set Configuration File Format . . . . . . . . . . 556
11.9 National Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
11.10 Upgrading Character Sets from MySQL 4.0 . . . . . . . . . . . 556
11.10.1 4.0 Character Sets and Corresponding 4.1
Character Set/Collation Pairs. . . . . . . . . . . . . . . . . . . . 557
11.10.2 Converting 4.0 Character Columns to 4.1 Format
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
11.11 Character Sets and Collations That MySQL Supports . . 559
11.11.1 Unicode Character Sets . . . . . . . . . . . . . . . . . . . . . 560
11.11.2 West European Character Sets . . . . . . . . . . . . . . 561
11.11.3 Central European Character Sets . . . . . . . . . . . . 562
11.11.4 South European and Middle East Character Sets
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
11.11.5 Baltic Character Sets . . . . . . . . . . . . . . . . . . . . . . . 563
11.11.6 Cyrillic Character Sets . . . . . . . . . . . . . . . . . . . . . . 564
11.11.7 Asian Character Sets . . . . . . . . . . . . . . . . . . . . . . . 564
12
Column Types . . . . . . . . . . . . . . . . . . . . . . . . . 566
12.1 Column Type Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
12.1.1 Overview of Numeric Types . . . . . . . . . . . . . . . . . . 566
12.1.2 Overview of Date and Time Types . . . . . . . . . . . . 568
12.1.3 Overview of String Types . . . . . . . . . . . . . . . . . . . . 569
12.2 Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
12.3 Date and Time Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
12.3.1 The DATETIME, DATE, and TIMESTAMP Types . . . 576
12.3.1.1 TIMESTAMP Properties Prior to MySQL 4.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
12.3.1.2 TIMESTAMP Properties as of MySQL 4.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
12.3.2 The TIME Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
12.3.3 The YEAR Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
12.3.4 Y2K Issues and Date Types . . . . . . . . . . . . . . . . . . 583
12.4 String Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
12.4.1 The CHAR and VARCHAR Types . . . . . . . . . . . . . . . . 584
12.4.2 The BLOB and TEXT Types . . . . . . . . . . . . . . . . . . . . 585
12.4.3 The ENUM Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
12.4.4 The SET Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
12.5 Column Type Storage Requirements . . . . . . . . . . . . . . . . . . . 589
12.6 Choosing the Right Type for a Column . . . . . . . . . . . . . . . . 590
12.7 Using Column Types from Other Database Engines . . . . . 591
xiii
13
Functions and Operators . . . . . . . . . . . . . . . . 592
13.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.1.1 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . .
13.1.2 Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.1.3 Comparison Functions and Operators . . . . . . . . .
13.1.4 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.2 Control Flow Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.3 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.3.1 String Comparison Functions . . . . . . . . . . . . . . . . .
13.4 Numeric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.4.1 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . .
13.4.2 Mathematical Functions. . . . . . . . . . . . . . . . . . . . . .
13.5 Date and Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.6 Full-Text Search Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.6.1 Boolean Full-Text Searches . . . . . . . . . . . . . . . . . . .
13.6.2 Full-Text Searches with Query Expansion . . . . .
13.6.3 Full-Text Restrictions . . . . . . . . . . . . . . . . . . . . . . . .
13.6.4 Fine-Tuning MySQL Full-Text Search . . . . . . . . .
13.6.5 Full-Text Search TODO. . . . . . . . . . . . . . . . . . . . . .
13.7 Cast Functions and Operators. . . . . . . . . . . . . . . . . . . . . . . . .
13.8 Other Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.8.1 Bit Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.8.2 Encryption Functions . . . . . . . . . . . . . . . . . . . . . . . .
13.8.3 Information Functions . . . . . . . . . . . . . . . . . . . . . . .
13.8.4 Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . .
13.9 Functions and Modifiers for Use with GROUP BY Clauses . .
13.9.1 GROUP BY (Aggregate) Functions . . . . . . . . . . . . . .
13.9.2 GROUP BY Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . .
13.9.3 GROUP BY with Hidden Fields . . . . . . . . . . . . . . . . .
14
592
592
593
593
597
599
601
610
612
612
613
619
635
638
639
640
641
643
643
646
646
647
650
655
658
658
660
663
SQL Statement Syntax . . . . . . . . . . . . . . . . . . 665
14.1 Data Manipulation Statements . . . . . . . . . . . . . . . . . . . . . . . .
14.1.1 DELETE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.2 DO Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.3 HANDLER Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.4 INSERT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.4.1 INSERT ... SELECT Syntax . . . . . . . . . .
14.1.4.2 INSERT DELAYED Syntax . . . . . . . . . . . . .
14.1.5 LOAD DATA INFILE Syntax . . . . . . . . . . . . . . . . . . . .
14.1.6 REPLACE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.7 SELECT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.7.1 JOIN Syntax . . . . . . . . . . . . . . . . . . . . . . . .
14.1.7.2 UNION Syntax . . . . . . . . . . . . . . . . . . . . . . .
14.1.8 Subquery Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.1.8.1 The Subquery as Scalar Operand. . . . .
14.1.8.2 Comparisons Using Subqueries . . . . . . .
14.1.8.3 Subqueries with ANY, IN, and SOME . . .
14.1.8.4 Subqueries with ALL. . . . . . . . . . . . . . . . .
665
665
667
667
669
672
673
675
682
683
688
690
691
692
693
694
694
xiv
14.2
14.3
14.4
14.5
14.1.8.5 Correlated Subqueries . . . . . . . . . . . . . . . 695
14.1.8.6 EXISTS and NOT EXISTS . . . . . . . . . . . . . 695
14.1.8.7 Row Subqueries. . . . . . . . . . . . . . . . . . . . . 696
14.1.8.8 Subqueries in the FROM clause . . . . . . . . 697
14.1.8.9 Subquery Errors . . . . . . . . . . . . . . . . . . . . 697
14.1.8.10 Optimizing Subqueries . . . . . . . . . . . . . 699
14.1.8.11 Rewriting Subqueries as Joins for Earlier
MySQL Versions . . . . . . . . . . . . . . . . . . . . . . . . . 700
14.1.9 TRUNCATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
14.1.10 UPDATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702
Data Definition Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
14.2.1 ALTER DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . 703
14.2.2 ALTER TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 704
14.2.3 ALTER VIEW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 708
14.2.4 CREATE DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . 709
14.2.5 CREATE INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . 709
14.2.6 CREATE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 710
14.2.6.1 Silent Column Specification Changes . . 721
14.2.7 CREATE VIEW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 722
14.2.8 DROP DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . . 723
14.2.9 DROP INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 723
14.2.10 DROP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 723
14.2.11 DROP VIEW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 724
14.2.12 RENAME TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . 724
MySQL Utility Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
14.3.1 DESCRIBE Syntax (Get Information About
Columns) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
14.3.2 USE Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
MySQL Transactional and Locking Statements . . . . . . . . . 726
14.4.1 START TRANSACTION, COMMIT, and ROLLBACK Syntax
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
14.4.2 Statements That Cannot Be Rolled Back . . . . . . 727
14.4.3 Statements That Cause an Implicit Commit . . . 727
14.4.4 SAVEPOINT and ROLLBACK TO SAVEPOINT Syntax
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
14.4.5 LOCK TABLES and UNLOCK TABLES Syntax . . . . . . 728
14.4.6 SET TRANSACTION Syntax . . . . . . . . . . . . . . . . . . . . . 731
Database Administration Statements . . . . . . . . . . . . . . . . . . 731
14.5.1 Account Management Statements . . . . . . . . . . . . . 731
14.5.1.1 DROP USER Syntax . . . . . . . . . . . . . . . . . . . 731
14.5.1.2 GRANT and REVOKE Syntax . . . . . . . . . . . 732
14.5.1.3 SET PASSWORD Syntax . . . . . . . . . . . . . . . 738
14.5.2 Table Maintenance Statements . . . . . . . . . . . . . . . 739
14.5.2.1 ANALYZE TABLE Syntax . . . . . . . . . . . . . . 739
14.5.2.2 BACKUP TABLE Syntax . . . . . . . . . . . . . . . 739
14.5.2.3 CHECK TABLE Syntax . . . . . . . . . . . . . . . . 740
14.5.2.4 CHECKSUM TABLE Syntax . . . . . . . . . . . . . 742
14.5.2.5 OPTIMIZE TABLE Syntax . . . . . . . . . . . . . 742
xv
14.5.2.6 REPAIR TABLE Syntax . . . . . . . . . . . . . . .
14.5.2.7 RESTORE TABLE Syntax . . . . . . . . . . . . . .
14.5.3 SET and SHOW Syntax . . . . . . . . . . . . . . . . . . . . . . . .
14.5.3.1 SET Syntax . . . . . . . . . . . . . . . . . . . . . . . . .
14.5.3.2 SHOW CHARACTER SET Syntax . . . . . . . . .
14.5.3.3 SHOW COLLATION Syntax . . . . . . . . . . . . .
14.5.3.4 SHOW COLUMNS Syntax . . . . . . . . . . . . . . .
14.5.3.5 SHOW CREATE DATABASE Syntax . . . . . . .
14.5.3.6 SHOW CREATE TABLE Syntax . . . . . . . . . .
14.5.3.7 SHOW CREATE VIEW Syntax . . . . . . . . . . .
14.5.3.8 SHOW DATABASES Syntax . . . . . . . . . . . . .
14.5.3.9 SHOW ENGINES Syntax . . . . . . . . . . . . . . .
14.5.3.10 SHOW ERRORS Syntax . . . . . . . . . . . . . . .
14.5.3.11 SHOW GRANTS Syntax . . . . . . . . . . . . . . .
14.5.3.12 SHOW INDEX Syntax. . . . . . . . . . . . . . . . .
14.5.3.13 SHOW INNODB STATUS Syntax . . . . . . . .
14.5.3.14 SHOW LOGS Syntax . . . . . . . . . . . . . . . . . .
14.5.3.15 SHOW PRIVILEGES Syntax . . . . . . . . . . .
14.5.3.16 SHOW PROCESSLIST Syntax . . . . . . . . . .
14.5.3.17 SHOW STATUS Syntax . . . . . . . . . . . . . . .
14.5.3.18 SHOW TABLE STATUS Syntax . . . . . . . . .
14.5.3.19 SHOW TABLES Syntax . . . . . . . . . . . . . . .
14.5.3.20 SHOW VARIABLES Syntax . . . . . . . . . . . .
14.5.3.21 SHOW WARNINGS Syntax . . . . . . . . . . . . .
14.5.4 Other Administrative Statements . . . . . . . . . . . . .
14.5.4.1 CACHE INDEX Syntax . . . . . . . . . . . . . . . .
14.5.4.2 FLUSH Syntax . . . . . . . . . . . . . . . . . . . . . . .
14.5.4.3 KILL Syntax . . . . . . . . . . . . . . . . . . . . . . . .
14.5.4.4 LOAD INDEX INTO CACHE Syntax . . . . . .
14.5.4.5 RESET Syntax . . . . . . . . . . . . . . . . . . . . . . .
14.6 Replication Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.6.1 SQL Statements for Controlling Master Servers
...............................................
14.6.1.1 PURGE MASTER LOGS Syntax . . . . . . . . . .
14.6.1.2 RESET MASTER Syntax . . . . . . . . . . . . . . .
14.6.1.3 SET SQL_LOG_BIN Syntax . . . . . . . . . . . .
14.6.1.4 SHOW BINLOG EVENTS Syntax . . . . . . . . .
14.6.1.5 SHOW MASTER LOGS Syntax . . . . . . . . . . .
14.6.1.6 SHOW MASTER STATUS Syntax . . . . . . . . .
14.6.1.7 SHOW SLAVE HOSTS Syntax . . . . . . . . . . .
14.6.2 SQL Statements for Controlling Slave Servers . .
14.6.2.1 CHANGE MASTER TO Syntax . . . . . . . . . . .
14.6.2.2 LOAD DATA FROM MASTER Syntax . . . . . .
14.6.2.3 LOAD TABLE tbl_name FROM MASTER
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.6.2.4 MASTER_POS_WAIT() Syntax . . . . . . . . .
14.6.2.5 RESET SLAVE Syntax . . . . . . . . . . . . . . . .
743
744
744
745
749
749
750
750
751
751
751
751
753
753
754
755
755
755
757
759
760
761
762
763
765
765
766
767
768
769
769
770
770
770
770
771
771
771
771
771
771
774
775
775
775
xvi
14.6.2.6 SET GLOBAL SQL_SLAVE_SKIP_COUNTER
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.6.2.7 SHOW SLAVE STATUS Syntax . . . . . . . . . .
14.6.2.8 START SLAVE Syntax . . . . . . . . . . . . . . . .
14.6.2.9 STOP SLAVE Syntax. . . . . . . . . . . . . . . . . .
14.7 SQL Syntax for Prepared Statements . . . . . . . . . . . . . . . . . .
15
775
776
779
780
780
MySQL Storage Engines and Table Types
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
15.1 The MyISAM Storage Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
15.1.1 MyISAM Startup Options. . . . . . . . . . . . . . . . . . . . . . 786
15.1.2 Space Needed for Keys . . . . . . . . . . . . . . . . . . . . . . . 787
15.1.3 MyISAM Table Storage Formats. . . . . . . . . . . . . . . . 788
15.1.3.1 Static (Fixed-Length) Table
Characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . 788
15.1.3.2 Dynamic Table Characteristics . . . . . . . 789
15.1.3.3 Compressed Table Characteristics . . . . 790
15.1.4 MyISAM Table Problems . . . . . . . . . . . . . . . . . . . . . . 790
15.1.4.1 Corrupted MyISAM Tables . . . . . . . . . . . . 790
15.1.4.2 Problems from Tables Not Being Closed
Properly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
15.2 The MERGE Storage Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 792
15.2.1 MERGE Table Problems . . . . . . . . . . . . . . . . . . . . . . . 794
15.3 The MEMORY (HEAP) Storage Engine . . . . . . . . . . . . . . . . . . . . 795
15.4 The BDB (BerkeleyDB) Storage Engine . . . . . . . . . . . . . . . . . 797
15.4.1 Operating Systems Supported by BDB . . . . . . . . . 798
15.4.2 Installing BDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
15.4.3 BDB Startup Options . . . . . . . . . . . . . . . . . . . . . . . . . 799
15.4.4 Characteristics of BDB Tables . . . . . . . . . . . . . . . . . 800
15.4.5 Things We Need to Fix for BDB . . . . . . . . . . . . . . . 801
15.4.6 Restrictions on BDB Tables . . . . . . . . . . . . . . . . . . . 802
15.4.7 Errors That May Occur When Using BDB Tables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
15.5 The ISAM Storage Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
16
The InnoDB Storage Engine . . . . . . . . . . . . . . 804
16.1
16.2
16.3
16.4
16.5
16.6
InnoDB Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804
InnoDB Contact Information . . . . . . . . . . . . . . . . . . . . . . . . . . 804
InnoDB in MySQL 3.23 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
InnoDB Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
InnoDB Startup Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810
Creating the InnoDB Tablespace . . . . . . . . . . . . . . . . . . . . . . . 814
16.6.1 Dealing with InnoDB Initialization Problems . . . 815
16.7 Creating InnoDB Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
16.7.1 How to Use Transactions in InnoDB with Different
APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
16.7.2 Converting MyISAM Tables to InnoDB . . . . . . . . . . 817
xvii
16.8
16.9
16.10
16.11
16.12
16.13
16.14
16.15
16.16
16.17
16.18
16.7.3 How an AUTO_INCREMENT Column Works in InnoDB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
16.7.4 FOREIGN KEY Constraints . . . . . . . . . . . . . . . . . . . . . 819
16.7.5 InnoDB and MySQL Replication . . . . . . . . . . . . . . 822
16.7.6 Using Per-Table Tablespaces . . . . . . . . . . . . . . . . . 823
Adding and Removing InnoDB Data and Log Files . . . . . . 825
Backing Up and Recovering an InnoDB Database . . . . . . . 826
16.9.1 Forcing Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828
16.9.2 Checkpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
Moving an InnoDB Database to Another Machine . . . . . . 829
InnoDB Transaction Model and Locking . . . . . . . . . . . . . . . 830
16.11.1 InnoDB and AUTOCOMMIT . . . . . . . . . . . . . . . . . . . . 830
16.11.2 InnoDB and TRANSACTION ISOLATION LEVEL . . 830
16.11.3 Consistent Non-Locking Read . . . . . . . . . . . . . . . 832
16.11.4 Locking Reads SELECT ... FOR UPDATE and
SELECT ... LOCK IN SHARE MODE . . . . . . . . . . . . . . . . . 832
16.11.5 Next-Key Locking: Avoiding the Phantom
Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833
16.11.6 An Example of How the Consistent Read Works in
InnoDB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 834
16.11.7 Locks Set by Different SQL Statements in InnoDB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835
16.11.8 When Does MySQL Implicitly Commit or Roll
Back a Transaction? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836
16.11.9 Deadlock Detection and Rollback . . . . . . . . . . . . 837
16.11.10 How to Cope with Deadlocks . . . . . . . . . . . . . . . 837
InnoDB Performance Tuning Tips. . . . . . . . . . . . . . . . . . . . . 838
16.12.1 SHOW INNODB STATUS and the InnoDB Monitors
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840
Implementation of Multi-Versioning . . . . . . . . . . . . . . . . . . 845
Table and Index Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 846
16.14.1 Physical Structure of an Index . . . . . . . . . . . . . . . 847
16.14.2 Insert Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
16.14.3 Adaptive Hash Indexes. . . . . . . . . . . . . . . . . . . . . . 847
16.14.4 Physical Record Structure . . . . . . . . . . . . . . . . . . . 848
File Space Management and Disk I/O . . . . . . . . . . . . . . . . 848
16.15.1 Disk I/O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
16.15.2 Using Raw Devices for the Tablespace. . . . . . . . 849
16.15.3 File Space Management . . . . . . . . . . . . . . . . . . . . . 850
16.15.4 Defragmenting a Table . . . . . . . . . . . . . . . . . . . . . . 850
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851
16.16.1 InnoDB Error Codes . . . . . . . . . . . . . . . . . . . . . . . . 851
16.16.2 Operating System Error Codes . . . . . . . . . . . . . . 852
Restrictions on InnoDB Tables. . . . . . . . . . . . . . . . . . . . . . . . 856
InnoDB Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
16.18.1 Troubleshooting InnoDB Data Dictionary
Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
xviii
17
MySQL Cluster . . . . . . . . . . . . . . . . . . . . . . . . 860
17.1 MySQL Cluster Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 860
17.2 Basic MySQL Cluster Concepts . . . . . . . . . . . . . . . . . . . . . . . 860
17.3 MySQL Cluster Configuration. . . . . . . . . . . . . . . . . . . . . . . . . 862
17.3.1 Building from Source Code . . . . . . . . . . . . . . . . . . . 862
17.3.2 Installing the Software . . . . . . . . . . . . . . . . . . . . . . . 862
17.3.3 Quick Test Setup of MySQL Cluster . . . . . . . . . . 862
17.3.4 Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . 865
17.3.4.1 An Example Configuration in a MySQL
Cluster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865
17.3.4.2 Defining the Computers in a MySQL
Cluster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866
17.3.4.3 Defining the Management Server in a
MySQL Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . 866
17.3.4.4 Defining the Storage Nodes in a MySQL
Cluster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
17.3.4.5 Defining the MySQL Servers in a MySQL
Cluster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
17.3.4.6 Defining TCP/IP Connections in a
MySQL Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . 884
17.3.4.7 Defining Shared-Memory Connections in a
MySQL Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . 885
17.4 Process Management in MySQL Cluster . . . . . . . . . . . . . . . 886
17.4.1 MySQL Server Process Usage for MySQL Cluster
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
17.4.2 ndbd, the Storage Engine Node Process . . . . . . . 887
17.4.3 ndb_mgmd, the Management Server Process . . . . 888
17.4.4 ndb_mgm, the Management Client Process . . . . . 889
17.4.5 Command Options for MySQL Cluster Processes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 889
17.4.5.1 MySQL Cluster-Related Command
Options for mysqld . . . . . . . . . . . . . . . . . . . . . . 889
17.4.5.2 Command Options for ndbd . . . . . . . . . 890
17.4.5.3 Command Options for ndb_mgmd . . . . . 891
17.4.5.4 Command Options for ndb_mgm . . . . . . 891
17.5 Management of MySQL Cluster . . . . . . . . . . . . . . . . . . . . . . . 892
17.5.1 Commands in the Management Client . . . . . . . . . 892
17.5.2 Event Reports Generated in MySQL Cluster. . . 893
17.5.2.1 Logging Management Commands . . . . 893
17.5.2.2 Log Events . . . . . . . . . . . . . . . . . . . . . . . . . 894
17.5.3 Single User Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
17.5.4 On-line Backup of MySQL Cluster . . . . . . . . . . . . 898
17.5.4.1 Cluster Backup Concepts . . . . . . . . . . . . 898
17.5.4.2 Using The Management Server to Create a
Backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
17.5.4.3 How to Restore a Cluster Backup . . . . 899
17.5.4.4 Configuration for Cluster Backup . . . . 900
17.5.4.5 Backup Troubleshooting . . . . . . . . . . . . . 900
xix
18
Introduction to MaxDB . . . . . . . . . . . . . . . . . 901
18.1
18.2
18.3
18.4
18.5
18.6
18.7
19
History of MaxDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Licensing and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MaxDB-Related Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Basic Concepts of MaxDB . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Feature Differences Between MaxDB and MySQL . . . . . .
Interoperability Features Between MaxDB and MySQL . .
Reserved Words in MaxDB . . . . . . . . . . . . . . . . . . . . . . . . . . .
901
901
901
901
902
902
903
Spatial Extensions in MySQL . . . . . . . . . . . 907
19.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907
19.2 The OpenGIS Geometry Model . . . . . . . . . . . . . . . . . . . . . . . 907
19.2.1 The Geometry Class Hierarchy . . . . . . . . . . . . . . . 908
19.2.2 Class Geometry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
19.2.3 Class Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
19.2.4 Class Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
19.2.5 Class LineString . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
19.2.6 Class Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
19.2.7 Class Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
19.2.8 Class GeometryCollection . . . . . . . . . . . . . . . . . . 912
19.2.9 Class MultiPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
19.2.10 Class MultiCurve . . . . . . . . . . . . . . . . . . . . . . . . . . 912
19.2.11 Class MultiLineString . . . . . . . . . . . . . . . . . . . . . 913
19.2.12 Class MultiSurface . . . . . . . . . . . . . . . . . . . . . . . . 913
19.2.13 Class MultiPolygon . . . . . . . . . . . . . . . . . . . . . . . . 913
19.3 Supported Spatial Data Formats . . . . . . . . . . . . . . . . . . . . . . 914
19.3.1 Well-Known Text (WKT) Format. . . . . . . . . . . . . 914
19.3.2 Well-Known Binary (WKB) Format. . . . . . . . . . . 915
19.4 Creating a Spatially Enabled MySQL Database. . . . . . . . . 915
19.4.1 MySQL Spatial Data Types . . . . . . . . . . . . . . . . . . 916
19.4.2 Creating Spatial Values . . . . . . . . . . . . . . . . . . . . . . 916
19.4.2.1 Creating Geometry Values Using WKT
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916
19.4.2.2 Creating Geometry Values Using WKB
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917
19.4.2.3 Creating Geometry Values Using
MySQL-Specific Functions . . . . . . . . . . . . . . . . 918
19.4.3 Creating Spatial Columns . . . . . . . . . . . . . . . . . . . . 919
19.4.4 Populating Spatial Columns . . . . . . . . . . . . . . . . . . 919
19.4.5 Fetching Spatial Data . . . . . . . . . . . . . . . . . . . . . . . . 921
19.4.5.1 Fetching Spatial Data in Internal Format
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
19.4.5.2 Fetching Spatial Data in WKT Format
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
19.4.5.3 Fetching Spatial Data in WKB Format
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
19.5 Analyzing Spatial Information . . . . . . . . . . . . . . . . . . . . . . . . 921
19.5.1 Geometry Format Conversion Functions . . . . . . . 922
xx
19.5.2 Geometry Functions . . . . . . . . . . . . . . . . . . . . . . . . . 922
19.5.2.1 General Geometry Functions . . . . . . . . . 922
19.5.2.2 Point Functions . . . . . . . . . . . . . . . . . . . . 924
19.5.2.3 LineString Functions . . . . . . . . . . . . . . . 924
19.5.2.4 MultiLineString Functions . . . . . . . . . 926
19.5.2.5 Polygon Functions . . . . . . . . . . . . . . . . . . 926
19.5.2.6 MultiPolygon Functions . . . . . . . . . . . . 927
19.5.2.7 GeometryCollection Functions . . . . . . 928
19.5.3 Functions That Create New Geometries from
Existing Ones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928
19.5.3.1 Geometry Functions That Produce New
Geometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929
19.5.3.2 Spatial Operators . . . . . . . . . . . . . . . . . . . 929
19.5.4 Functions for Testing Spatial Relations Between
Geometric Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929
19.5.5 Relations on Geometry Minimal Bounding
Rectangles (MBRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929
19.5.6 Functions That Test Spatial Relationships Between
Geometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930
19.6 Optimizing Spatial Analysis. . . . . . . . . . . . . . . . . . . . . . . . . . . 932
19.6.1 Creating Spatial Indexes . . . . . . . . . . . . . . . . . . . . . 932
19.6.2 Using a Spatial Index . . . . . . . . . . . . . . . . . . . . . . . . 933
19.7 MySQL Conformance and Compatibility . . . . . . . . . . . . . . . 935
19.7.1 GIS Features That Are Not Yet Implemented . . 935
20
Stored Procedures and Functions . . . . . . . . 936
20.1 Stored Procedure Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936
20.1.1 Maintaining Stored Procedures . . . . . . . . . . . . . . . 937
20.1.1.1 CREATE PROCEDURE and CREATE FUNCTION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937
20.1.1.2 ALTER PROCEDURE and ALTER FUNCTION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 939
20.1.1.3 DROP PROCEDURE and DROP FUNCTION . . 940
20.1.1.4 SHOW CREATE PROCEDURE and SHOW CREATE
FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
20.1.2 SHOW PROCEDURE STATUS and SHOW FUNCTION
STATUS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
20.1.3 CALL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
20.1.4 BEGIN ... END Compound Statement . . . . . . . . . 941
20.1.5 DECLARE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 941
20.1.6 Variables in Stored Procedures . . . . . . . . . . . . . . . 941
20.1.6.1 DECLARE Local Variables . . . . . . . . . . . . . 941
20.1.6.2 Variable SET Statement. . . . . . . . . . . . . . 941
20.1.6.3 SELECT ... INTO Statement . . . . . . . . . 942
20.1.7 Conditions and Handlers . . . . . . . . . . . . . . . . . . . . . 942
20.1.7.1 DECLARE Conditions . . . . . . . . . . . . . . . . . 942
20.1.7.2 DECLARE Handlers . . . . . . . . . . . . . . . . . . . 942
20.1.8 Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
xxi
20.1.8.1 Declaring Cursors . . . . . . . . . . . . . . . . . . .
20.1.8.2 Cursor OPEN Statement . . . . . . . . . . . . . .
20.1.8.3 Cursor FETCH Statement . . . . . . . . . . . . .
20.1.8.4 Cursor CLOSE Statement . . . . . . . . . . . . .
20.1.9 Flow Control Constructs . . . . . . . . . . . . . . . . . . . . .
20.1.9.1 IF Statement . . . . . . . . . . . . . . . . . . . . . . .
20.1.9.2 CASE Statement . . . . . . . . . . . . . . . . . . . . .
20.1.9.3 LOOP Statement . . . . . . . . . . . . . . . . . . . . .
20.1.9.4 LEAVE Statement . . . . . . . . . . . . . . . . . . . .
20.1.9.5 ITERATE Statement . . . . . . . . . . . . . . . . .
20.1.9.6 REPEAT Statement. . . . . . . . . . . . . . . . . . .
20.1.9.7 WHILE Statement . . . . . . . . . . . . . . . . . . . .
21
944
944
944
945
945
945
945
946
946
946
946
947
MySQL APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . 948
21.1 MySQL Program Development Utilities . . . . . . . . . . . . . . . . 948
21.1.1 msql2mysql, Convert mSQL Programs for Use with
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948
21.1.2 mysql_config, Get compile options for compiling
clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948
21.2 MySQL C API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
21.2.1 C API Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . 950
21.2.2 C API Function Overview . . . . . . . . . . . . . . . . . . . . 953
21.2.3 C API Function Descriptions . . . . . . . . . . . . . . . . . 957
21.2.3.1 mysql_affected_rows() . . . . . . . . . . . . 957
21.2.3.2 mysql_change_user() . . . . . . . . . . . . . . 958
21.2.3.3 mysql_character_set_name(). . . . . . . 959
21.2.3.4 mysql_close() . . . . . . . . . . . . . . . . . . . . . 960
21.2.3.5 mysql_connect() . . . . . . . . . . . . . . . . . . . 960
21.2.3.6 mysql_create_db() . . . . . . . . . . . . . . . . 961
21.2.3.7 mysql_data_seek() . . . . . . . . . . . . . . . . 961
21.2.3.8 mysql_debug() . . . . . . . . . . . . . . . . . . . . . 962
21.2.3.9 mysql_drop_db() . . . . . . . . . . . . . . . . . . . 962
21.2.3.10 mysql_dump_debug_info() . . . . . . . . . 963
21.2.3.11 mysql_eof() . . . . . . . . . . . . . . . . . . . . . . 964
21.2.3.12 mysql_errno() . . . . . . . . . . . . . . . . . . . . 965
21.2.3.13 mysql_error() . . . . . . . . . . . . . . . . . . . . 966
21.2.3.14 mysql_escape_string() . . . . . . . . . . . 966
21.2.3.15 mysql_fetch_field() . . . . . . . . . . . . . 966
21.2.3.16 mysql_fetch_fields() . . . . . . . . . . . . 967
21.2.3.17 mysql_fetch_field_direct() . . . . . 968
21.2.3.18 mysql_fetch_lengths() . . . . . . . . . . . 969
21.2.3.19 mysql_fetch_row() . . . . . . . . . . . . . . . 970
21.2.3.20 mysql_field_count() . . . . . . . . . . . . . 971
21.2.3.21 mysql_field_seek() . . . . . . . . . . . . . . 972
21.2.3.22 mysql_field_tell() . . . . . . . . . . . . . . 972
21.2.3.23 mysql_free_result() . . . . . . . . . . . . . 973
21.2.3.24 mysql_get_client_info() . . . . . . . . . 973
21.2.3.25 mysql_get_client_version() . . . . . 974
xxii
21.2.3.26 mysql_get_host_info() . . . . . . . . . . . 974
21.2.3.27 mysql_get_proto_info() . . . . . . . . . . 974
21.2.3.28 mysql_get_server_info() . . . . . . . . . 975
21.2.3.29 mysql_get_server_version() . . . . . 975
21.2.3.30 mysql_info() . . . . . . . . . . . . . . . . . . . . . 976
21.2.3.31 mysql_init() . . . . . . . . . . . . . . . . . . . . . 976
21.2.3.32 mysql_insert_id() . . . . . . . . . . . . . . . 977
21.2.3.33 mysql_kill() . . . . . . . . . . . . . . . . . . . . . 978
21.2.3.34 mysql_list_dbs(). . . . . . . . . . . . . . . . . 978
21.2.3.35 mysql_list_fields() . . . . . . . . . . . . . 979
21.2.3.36 mysql_list_processes() . . . . . . . . . . 980
21.2.3.37 mysql_list_tables() . . . . . . . . . . . . . 980
21.2.3.38 mysql_num_fields() . . . . . . . . . . . . . . 981
21.2.3.39 mysql_num_rows(). . . . . . . . . . . . . . . . . 982
21.2.3.40 mysql_options() . . . . . . . . . . . . . . . . . . 983
21.2.3.41 mysql_ping() . . . . . . . . . . . . . . . . . . . . . 985
21.2.3.42 mysql_query() . . . . . . . . . . . . . . . . . . . . 986
21.2.3.43 mysql_real_connect() . . . . . . . . . . . . 987
21.2.3.44 mysql_real_escape_string() . . . . . 989
21.2.3.45 mysql_real_query() . . . . . . . . . . . . . . 990
21.2.3.46 mysql_reload() . . . . . . . . . . . . . . . . . . . 991
21.2.3.47 mysql_row_seek(). . . . . . . . . . . . . . . . . 992
21.2.3.48 mysql_row_tell(). . . . . . . . . . . . . . . . . 992
21.2.3.49 mysql_select_db() . . . . . . . . . . . . . . . 993
21.2.3.50 mysql_set_server_option(). . . . . . . 993
21.2.3.51 mysql_shutdown(). . . . . . . . . . . . . . . . . 994
21.2.3.52 mysql_sqlstate(). . . . . . . . . . . . . . . . . 995
21.2.3.53 mysql_ssl_set() . . . . . . . . . . . . . . . . . . 995
21.2.3.54 mysql_stat() . . . . . . . . . . . . . . . . . . . . . 996
21.2.3.55 mysql_store_result() . . . . . . . . . . . . 996
21.2.3.56 mysql_thread_id() . . . . . . . . . . . . . . . 998
21.2.3.57 mysql_use_result() . . . . . . . . . . . . . . 998
21.2.3.58 mysql_warning_count() . . . . . . . . . . . 999
21.2.3.59 mysql_commit() . . . . . . . . . . . . . . . . . . . 999
21.2.3.60 mysql_rollback() . . . . . . . . . . . . . . . 1000
21.2.3.61 mysql_autocommit() . . . . . . . . . . . . . 1000
21.2.3.62 mysql_more_results() . . . . . . . . . . . 1001
21.2.3.63 mysql_next_result() . . . . . . . . . . . . 1001
21.2.4 C API Prepared Statements . . . . . . . . . . . . . . . . . 1002
21.2.5 C API Prepared Statement Data types . . . . . . . 1003
21.2.6 C API Prepared Statement Function Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005
21.2.7 C API Prepared Statement Function Descriptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008
21.2.7.1 mysql_stmt_affected_rows() . . . . . 1009
21.2.7.2 mysql_stmt_attr_get() . . . . . . . . . . . 1009
21.2.7.3 mysql_stmt_attr_set() . . . . . . . . . . . 1010
21.2.7.4 mysql_stmt_bind_param() . . . . . . . . . 1010
xxiii
21.2.7.5 mysql_stmt_bind_result() . . . . . . . . 1011
21.2.7.6 mysql_stmt_close() . . . . . . . . . . . . . . 1012
21.2.7.7 mysql_stmt_data_seek() . . . . . . . . . . 1013
21.2.7.8 mysql_stmt_errno() . . . . . . . . . . . . . . 1014
21.2.7.9 mysql_stmt_error() . . . . . . . . . . . . . . 1014
21.2.7.10 mysql_stmt_execute() . . . . . . . . . . . 1015
21.2.7.11 mysql_stmt_free_result() . . . . . . . 1019
21.2.7.12 mysql_stmt_insert_id() . . . . . . . . . 1019
21.2.7.13 mysql_stmt_fetch() . . . . . . . . . . . . . 1020
21.2.7.14 mysql_stmt_fetch_column(). . . . . . 1025
21.2.7.15 mysql_stmt_field_count() . . . . . . . 1025
21.2.7.16 mysql_stmt_init() . . . . . . . . . . . . . . 1026
21.2.7.17 mysql_stmt_num_rows() . . . . . . . . . . 1026
21.2.7.18 mysql_stmt_param_count() . . . . . . . 1027
21.2.7.19 mysql_stmt_param_metadata() . . . 1027
21.2.7.20 mysql_stmt_prepare() . . . . . . . . . . . 1028
21.2.7.21 mysql_stmt_reset() . . . . . . . . . . . . . 1029
21.2.7.22 mysql_stmt_result_metadata() . . 1029
21.2.7.23 mysql_stmt_row_seek() . . . . . . . . . . 1030
21.2.7.24 mysql_stmt_row_tell() . . . . . . . . . . 1031
21.2.7.25 mysql_stmt_send_long_data() . . . 1031
21.2.7.26 mysql_stmt_sqlstate() . . . . . . . . . . 1033
21.2.7.27 mysql_stmt_store_result(). . . . . . 1034
21.2.8 C API Handling of Multiple Query Execution
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035
21.2.9 C API Handling of Date and Time Values . . . . 1036
21.2.10 C API Threaded Function Descriptions . . . . . 1037
21.2.10.1 my_init() . . . . . . . . . . . . . . . . . . . . . . . 1037
21.2.10.2 mysql_thread_init() . . . . . . . . . . . . 1038
21.2.10.3 mysql_thread_end() . . . . . . . . . . . . . 1038
21.2.10.4 mysql_thread_safe() . . . . . . . . . . . . 1038
21.2.11 C API Embedded Server Function Descriptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038
21.2.11.1 mysql_server_init() . . . . . . . . . . . . 1039
21.2.11.2 mysql_server_end() . . . . . . . . . . . . . 1040
21.2.12 Common questions and problems when using the
C API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1040
21.2.12.1 Why mysql_store_result() Sometimes
Returns NULL After mysql_query() Returns
Success . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1040
21.2.12.2 What Results You Can Get from a Query
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041
21.2.12.3 How to Get the Unique ID for the Last
Inserted Row . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041
21.2.12.4 Problems Linking with the C API . . 1042
21.2.13 Building Client Programs . . . . . . . . . . . . . . . . . . 1042
21.2.14 How to Make a Threaded Client . . . . . . . . . . . . 1043
xxiv
21.3
21.4
21.5
21.6
21.7
21.8
21.9
21.10
22
21.2.15 libmysqld, the Embedded MySQL Server Library
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1044
21.2.15.1 Overview of the Embedded MySQL
Server Library . . . . . . . . . . . . . . . . . . . . . . . . . . 1044
21.2.15.2 Compiling Programs with libmysqld
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045
21.2.15.3 Restrictions when using the Embedded
MySQL Server. . . . . . . . . . . . . . . . . . . . . . . . . . 1045
21.2.15.4 Using Option Files with the Embedded
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045
21.2.15.5 Things left to do in Embedded Server
(TODO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046
21.2.15.6 A Simple Embedded Server Example
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046
21.2.15.7 Licensing the Embedded Server . . . . 1050
MySQL ODBC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1050
21.3.1 What is Connector/ODBC? . . . . . . . . . . . . . . . . . 1050
21.3.2 What is MyODBC 2.50? . . . . . . . . . . . . . . . . . . . . 1050
21.3.3 What is MyODBC 3.51? . . . . . . . . . . . . . . . . . . . . 1050
21.3.4 How to Install MyODBC . . . . . . . . . . . . . . . . . . . . 1050
21.3.5 How to Fill in the Various Fields in the ODBC
Administrator Program . . . . . . . . . . . . . . . . . . . . . . . . 1051
21.3.6 Connect parameters for MyODBC . . . . . . . . . . . 1052
21.3.7 How to Report Problems with MyODBC . . . . . 1054
21.3.8 Applications Tested with MyODBC . . . . . . . . . . 1055
21.3.9 Programs Known to Work with MyODBC . . . . 1056
21.3.10 How to Get the Value of an AUTO_INCREMENT
Column in ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061
MySQL Java Connectivity (JDBC) . . . . . . . . . . . . . . . . . . . 1061
MySQL PHP API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061
21.5.1 Common Problems with MySQL and PHP . . . 1061
MySQL Perl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1062
MySQL C++ API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1062
21.7.1 Borland C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
MySQL Python API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
MySQL Tcl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
MySQL Eiffel Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
Error Handling in MySQL . . . . . . . . . . . . . 1064
xxv
23
Extending MySQL . . . . . . . . . . . . . . . . . . . . . 1088
23.1 MySQL Internals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1088
23.1.1 MySQL Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 1088
23.1.2 MySQL Test Suite . . . . . . . . . . . . . . . . . . . . . . . . . . 1088
23.1.2.1 Running the MySQL Test Suite . . . . . 1089
23.1.2.2 Extending the MySQL Test Suite . . . 1089
23.1.2.3 Reporting Bugs in the MySQL Test Suite
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1090
23.2 Adding New Functions to MySQL . . . . . . . . . . . . . . . . . . . . 1091
23.2.1 CREATE FUNCTION/DROP FUNCTION Syntax . . . . 1092
23.2.2 Adding a New User-defined Function . . . . . . . . . 1092
23.2.2.1 UDF Calling Sequences for simple
functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1094
23.2.2.2 UDF Calling Sequences for aggregate
functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095
23.2.2.3 Argument Processing. . . . . . . . . . . . . . . 1096
23.2.2.4 Return Values and Error Handling . . 1097
23.2.2.5 Compiling and Installing User-defined
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098
23.2.3 Adding a New Native Function . . . . . . . . . . . . . . 1100
23.3 Adding New Procedures to MySQL. . . . . . . . . . . . . . . . . . . 1101
23.3.1 Procedure Analyse. . . . . . . . . . . . . . . . . . . . . . . . . . 1101
23.3.2 Writing a Procedure . . . . . . . . . . . . . . . . . . . . . . . . 1102
Appendix A Problems and Common Errors
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103
A.1
A.2
A.3
How to Determine What Is Causing a Problem . . . . . . . . 1103
Common Errors When Using MySQL Programs. . . . . . . . 1104
A.2.1 Access denied . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104
A.2.2 Can’t connect to [local] MySQL server . . . . 1104
A.2.3 Client does not support authentication
protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106
A.2.4 Password Fails When Entered Interactively . . . 1107
A.2.5 Host ’host_name ’ is blocked . . . . . . . . . . . . . . 1107
A.2.6 Too many connections . . . . . . . . . . . . . . . . . . . . . . 1108
A.2.7 Out of memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1108
A.2.8 MySQL server has gone away . . . . . . . . . . . . . . . . 1108
A.2.9 Packet too large . . . . . . . . . . . . . . . . . . . . . . . . . . 1109
A.2.10 Communication Errors and Aborted Connections
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1110
A.2.11 The table is full . . . . . . . . . . . . . . . . . . . . . . . . . 1111
A.2.12 Can’t create/write to file . . . . . . . . . . . . . . . 1112
A.2.13 Commands out of sync . . . . . . . . . . . . . . . . . . . . . 1112
A.2.14 Ignoring user . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1113
A.2.15 Table ’tbl_name ’ doesn’t exist . . . . . . . . . . 1113
A.2.16 Can’t initialize character set . . . . . . . . . . 1113
A.2.17 File Not Found . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1114
Installation-Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115
xxvi
A.3.1 Problems Linking to the MySQL Client Library
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115
A.3.2 How to Run MySQL as a Normal User . . . . . . . 1116
A.3.3 Problems with File Permissions . . . . . . . . . . . . . . 1117
A.4 Administration-Related Issues . . . . . . . . . . . . . . . . . . . . . . . . 1117
A.4.1 How to Reset the Root Password . . . . . . . . . . . . . 1117
A.4.2 What to Do If MySQL Keeps Crashing . . . . . . . 1119
A.4.3 How MySQL Handles a Full Disk . . . . . . . . . . . . 1121
A.4.4 Where MySQL Stores Temporary Files . . . . . . . 1122
A.4.5 How to Protect or Change the MySQL Socket File
‘/tmp/mysql.sock’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123
A.4.6 Time Zone Problems . . . . . . . . . . . . . . . . . . . . . . . . 1123
A.5 Query-Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1124
A.5.1 Case Sensitivity in Searches . . . . . . . . . . . . . . . . . . 1124
A.5.2 Problems Using DATE Columns . . . . . . . . . . . . . . . 1124
A.5.3 Problems with NULL Values . . . . . . . . . . . . . . . . . . 1125
A.5.4 Problems with Column Aliases . . . . . . . . . . . . . . . 1127
A.5.5 Rollback Failure for Non-Transactional Tables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1127
A.5.6 Deleting Rows from Related Tables . . . . . . . . . . . 1128
A.5.7 Solving Problems with No Matching Rows . . . . 1128
A.5.8 Problems with Floating-Point Comparisons . . . 1129
A.6 Optimizer-Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1131
A.7 Table Definition-Related Issues . . . . . . . . . . . . . . . . . . . . . . . 1132
A.7.1 Problems with ALTER TABLE . . . . . . . . . . . . . . . . . 1132
A.7.2 How to Change the Order of Columns in a Table
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1132
A.7.3 TEMPORARY TABLE Problems . . . . . . . . . . . . . . . . . . 1133
Appendix B Credits . . . . . . . . . . . . . . . . . . . . . . 1134
B.1
B.2
B.3
B.4
B.5
B.6
B.7
Developers at MySQL AB . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contributors to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Documenters and translators . . . . . . . . . . . . . . . . . . . . . . . . .
Libraries used by and included with MySQL . . . . . . . . . . .
Packages that support MySQL . . . . . . . . . . . . . . . . . . . . . . . .
Tools that were used to create MySQL . . . . . . . . . . . . . . . .
Supporters of MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1134
1137
1141
1142
1143
1143
1144
xxvii
Appendix C MySQL Change History. . . . . . . 1145
C.1
Changes in release 5.0.x (Development). . . . . . . . . . . . . . . . 1145
C.1.1 Changes in release 5.0.2 (not released yet) . . . . 1145
C.1.2 Changes in release 5.0.1 (27 Jul 2004) . . . . . . . . 1147
C.1.3 Changes in release 5.0.0 (22 Dec 2003: Alpha)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151
C.2 Changes in release 4.1.x (Gamma) . . . . . . . . . . . . . . . . . . . . 1152
C.2.1 Changes in release 4.1.6 (not released yet) . . . . 1153
C.2.2 Changes in release 4.1.5 (16 Sep 2004) . . . . . . . . 1154
C.2.3 Changes in release 4.1.4 (26 Aug 2004: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155
C.2.4 Changes in release 4.1.3 (28 Jun 2004: Beta) . . 1157
C.2.5 Changes in release 4.1.2 (28 May 2004) . . . . . . . 1160
C.2.6 Changes in release 4.1.1 (01 Dec 2003) . . . . . . . . 1169
C.2.7 Changes in release 4.1.0 (03 Apr 2003: Alpha)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1174
C.3 Changes in release 4.0.x (Production) . . . . . . . . . . . . . . . . . 1176
C.3.1 Changes in release 4.0.22 (not released yet) . . . 1177
C.3.2 Changes in release 4.0.21 (06 Sep 2004) . . . . . . . 1178
C.3.3 Changes in release 4.0.20 (17 May 2004) . . . . . . 1180
C.3.4 Changes in release 4.0.19 (04 May 2004) . . . . . . 1180
C.3.5 Changes in release 4.0.18 (12 Feb 2004) . . . . . . . 1184
C.3.6 Changes in release 4.0.17 (14 Dec 2003) . . . . . . . 1187
C.3.7 Changes in release 4.0.16 (17 Oct 2003) . . . . . . . 1189
C.3.8 Changes in release 4.0.15 (03 Sep 2003) . . . . . . . 1192
C.3.9 Changes in release 4.0.14 (18 Jul 2003) . . . . . . . 1196
C.3.10 Changes in release 4.0.13 (16 May 2003) . . . . . 1199
C.3.11 Changes in release 4.0.12 (15 Mar 2003:
Production) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1203
C.3.12 Changes in release 4.0.11 (20 Feb 2003) . . . . . . 1205
C.3.13 Changes in release 4.0.10 (29 Jan 2003) . . . . . . 1206
C.3.14 Changes in release 4.0.9 (09 Jan 2003) . . . . . . . 1207
C.3.15 Changes in release 4.0.8 (07 Jan 2003) . . . . . . . 1207
C.3.16 Changes in release 4.0.7 (20 Dec 2002) . . . . . . . 1208
C.3.17 Changes in release 4.0.6 (14 Dec 2002: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1208
C.3.18 Changes in release 4.0.5 (13 Nov 2002). . . . . . . 1210
C.3.19 Changes in release 4.0.4 (29 Sep 2002) . . . . . . . 1212
C.3.20 Changes in release 4.0.3 (26 Aug 2002: Beta)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1214
C.3.21 Changes in release 4.0.2 (01 Jul 2002) . . . . . . . 1215
C.3.22 Changes in release 4.0.1 (23 Dec 2001) . . . . . . . 1219
C.3.23 Changes in release 4.0.0 (Oct 2001: Alpha). . . 1220
C.4 Changes in release 3.23.x (Recent; still supported). . . . . . 1221
C.4.1 Changes in release 3.23.59 (not released yet) . . 1222
C.4.2 Changes in release 3.23.58 (11 Sep 2003) . . . . . . 1223
C.4.3 Changes in release 3.23.57 (06 Jun 2003) . . . . . . 1223
C.4.4 Changes in release 3.23.56 (13 Mar 2003) . . . . . 1225
xxviii
C.4.5 Changes in release 3.23.55 (23 Jan 2003) . . . . . . 1226
C.4.6 Changes in release 3.23.54 (05 Dec 2002) . . . . . . 1226
C.4.7 Changes in release 3.23.53 (09 Oct 2002) . . . . . . 1227
C.4.8 Changes in release 3.23.52 (14 Aug 2002) . . . . . 1228
C.4.9 Changes in release 3.23.51 (31 May 2002) . . . . . 1228
C.4.10 Changes in release 3.23.50 (21 Apr 2002). . . . . 1229
C.4.11 Changes in release 3.23.49 (14 Feb 2002) . . . . . 1230
C.4.12 Changes in release 3.23.48 (07 Feb 2002) . . . . . 1230
C.4.13 Changes in release 3.23.47 (27 Dec 2001) . . . . . 1231
C.4.14 Changes in release 3.23.46 (29 Nov 2001) . . . . 1232
C.4.15 Changes in release 3.23.45 (22 Nov 2001) . . . . 1232
C.4.16 Changes in release 3.23.44 (31 Oct 2001) . . . . . 1232
C.4.17 Changes in release 3.23.43 (04 Oct 2001) . . . . . 1234
C.4.18 Changes in release 3.23.42 (08 Sep 2001) . . . . . 1234
C.4.19 Changes in release 3.23.41 (11 Aug 2001) . . . . 1235
C.4.20 Changes in release 3.23.40 (18 Jul 2001) . . . . . 1235
C.4.21 Changes in release 3.23.39 (12 Jun 2001) . . . . . 1236
C.4.22 Changes in release 3.23.38 (09 May 2001) . . . . 1236
C.4.23 Changes in release 3.23.37 (17 Apr 2001). . . . . 1237
C.4.24 Changes in release 3.23.36 (27 Mar 2001) . . . . 1238
C.4.25 Changes in release 3.23.35 (15 Mar 2001) . . . . 1239
C.4.26 Changes in release 3.23.34a (11 Mar 2001) . . . 1239
C.4.27 Changes in release 3.23.34 (10 Mar 2001) . . . . 1239
C.4.28 Changes in release 3.23.33 (09 Feb 2001) . . . . . 1240
C.4.29 Changes in release 3.23.32 (22 Jan 2001) . . . . . 1241
C.4.30 Changes in release 3.23.31 (17 Jan 2001:
Production) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1242
C.4.31 Changes in release 3.23.30 (04 Jan 2001) . . . . . 1242
C.4.32 Changes in release 3.23.29 (16 Dec 2000) . . . . . 1243
C.4.33 Changes in release 3.23.28 (22 Nov 2000: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1245
C.4.34 Changes in release 3.23.27 (24 Oct 2000) . . . . . 1246
C.4.35 Changes in release 3.23.26 (18 Oct 2000) . . . . . 1246
C.4.36 Changes in release 3.23.25 (29 Sep 2000) . . . . . 1247
C.4.37 Changes in release 3.23.24 (08 Sep 2000) . . . . . 1249
C.4.38 Changes in release 3.23.23 (01 Sep 2000) . . . . . 1249
C.4.39 Changes in release 3.23.22 (31 Jul 2000) . . . . . 1250
C.4.40 Changes in release 3.23.21 (04 Jul 2000) . . . . . 1251
C.4.41 Changes in release 3.23.20 (28 Jun 2000: Beta)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1251
C.4.42 Changes in release 3.23.19 . . . . . . . . . . . . . . . . . . 1251
C.4.43 Changes in release 3.23.18 (11 Jun 2000) . . . . . 1252
C.4.44 Changes in release 3.23.17 (07 Jun 2000) . . . . . 1252
C.4.45 Changes in release 3.23.16 (16 May 2000) . . . . 1253
C.4.46 Changes in release 3.23.15 (08 May 2000) . . . . 1253
C.4.47 Changes in release 3.23.14 (09 Apr 2000). . . . . 1254
C.4.48 Changes in release 3.23.13 (14 Mar 2000) . . . . 1255
C.4.49 Changes in release 3.23.12 (07 Mar 2000) . . . . 1255
xxix
C.5
C.4.50 Changes in release 3.23.11 (16 Feb 2000) . . . . . 1256
C.4.51 Changes in release 3.23.10 (30 Jan 2000) . . . . . 1257
C.4.52 Changes in release 3.23.9 (29 Jan 2000) . . . . . . 1257
C.4.53 Changes in release 3.23.8 (02 Jan 2000) . . . . . . 1258
C.4.54 Changes in release 3.23.7 (10 Dec 1999) . . . . . . 1258
C.4.55 Changes in release 3.23.6 (15 Nov 1999) . . . . . 1259
C.4.56 Changes in release 3.23.5 (20 Oct 1999) . . . . . . 1260
C.4.57 Changes in release 3.23.4 (28 Sep 1999) . . . . . . 1260
C.4.58 Changes in release 3.23.3 (13 Sep 1999) . . . . . . 1261
C.4.59 Changes in release 3.23.2 (09 Aug 1999) . . . . . 1261
C.4.60 Changes in release 3.23.1 (08 Jul 1999) . . . . . . 1262
C.4.61 Changes in release 3.23.0 (05 Jul 1999: Alpha)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1262
Changes in release 3.22.x (Old; discontinued) . . . . . . . . . . 1264
C.5.1 Changes in release 3.22.35 . . . . . . . . . . . . . . . . . . . 1264
C.5.2 Changes in release 3.22.34 . . . . . . . . . . . . . . . . . . . 1265
C.5.3 Changes in release 3.22.33 . . . . . . . . . . . . . . . . . . . 1265
C.5.4 Changes in release 3.22.32 (14 Feb 2000) . . . . . . 1265
C.5.5 Changes in release 3.22.31 . . . . . . . . . . . . . . . . . . . 1265
C.5.6 Changes in release 3.22.30 (11 Jan 2000) . . . . . . 1265
C.5.7 Changes in release 3.22.29 (02 Jan 2000) . . . . . . 1265
C.5.8 Changes in release 3.22.28 (20 Oct 1999) . . . . . . 1266
C.5.9 Changes in release 3.22.27 (05 Oct 1999) . . . . . . 1266
C.5.10 Changes in release 3.22.26 (16 Sep 1999) . . . . . 1266
C.5.11 Changes in release 3.22.25 (07 Jun 1999) . . . . . 1266
C.5.12 Changes in release 3.22.24 (05 Jul 1999) . . . . . 1266
C.5.13 Changes in release 3.22.23 (08 Jun 1999) . . . . . 1267
C.5.14 Changes in release 3.22.22 (30 Apr 1999). . . . . 1267
C.5.15 Changes in release 3.22.21 (04 Apr 1999). . . . . 1267
C.5.16 Changes in release 3.22.20 (18 Mar 1999) . . . . 1268
C.5.17 Changes in release 3.22.19 (01 Mar 1999) . . . . 1268
C.5.18 Changes in release 3.22.18 (26 Feb 1999) . . . . . 1268
C.5.19 Changes in release 3.22.17 (22 Feb 1999:
Production) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1268
C.5.20 Changes in release 3.22.16 (05 Feb 1999) . . . . . 1268
C.5.21 Changes in release 3.22.15 (27 Jan 1999) . . . . . 1269
C.5.22 Changes in release 3.22.14 (01 Jan 1999: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1269
C.5.23 Changes in release 3.22.13 (16 Dec 1998) . . . . . 1269
C.5.24 Changes in release 3.22.12 (09 Dec 1998) . . . . . 1270
C.5.25 Changes in release 3.22.11 (24 Nov 1998) . . . . 1270
C.5.26 Changes in release 3.22.10 (04 Nov 1998) . . . . 1271
C.5.27 Changes in release 3.22.9 (19 Oct 1998) . . . . . . 1271
C.5.28 Changes in release 3.22.8 (06 Oct 1998) . . . . . . 1272
C.5.29 Changes in release 3.22.7 (21 Sep 1998: Beta)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1272
C.5.30 Changes in release 3.22.6 (31 Aug 1998) . . . . . 1273
xxx
C.5.31 Changes in release 3.22.5 (20 Aug 1998: Alpha)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1273
C.5.32 Changes in release 3.22.4 (06 Jul 1998: Beta)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1275
C.5.33 Changes in release 3.22.3 (30 Jun 1998) . . . . . . 1275
C.5.34 Changes in release 3.22.2 . . . . . . . . . . . . . . . . . . . 1275
C.5.35 Changes in release 3.22.1 (Jun 1998). . . . . . . . . 1276
C.5.36 Changes in release 3.22.0 (18 May 1998: Alpha)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1277
C.6 Changes in release 3.21.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1278
C.6.1 Changes in release 3.21.33 (08 Jul 1998) . . . . . . 1278
C.6.2 Changes in release 3.21.32 (30 Jun 1998) . . . . . . 1278
C.6.3 Changes in release 3.21.31 (10 Jun 1998) . . . . . . 1279
C.6.4 Changes in release 3.21.30 . . . . . . . . . . . . . . . . . . . 1279
C.6.5 Changes in release 3.21.29 . . . . . . . . . . . . . . . . . . . 1279
C.6.6 Changes in release 3.21.28 . . . . . . . . . . . . . . . . . . . 1280
C.6.7 Changes in release 3.21.27 . . . . . . . . . . . . . . . . . . . 1280
C.6.8 Changes in release 3.21.26 . . . . . . . . . . . . . . . . . . . 1280
C.6.9 Changes in release 3.21.25 . . . . . . . . . . . . . . . . . . . 1281
C.6.10 Changes in release 3.21.24 . . . . . . . . . . . . . . . . . . 1281
C.6.11 Changes in release 3.21.23 . . . . . . . . . . . . . . . . . . 1281
C.6.12 Changes in release 3.21.22 . . . . . . . . . . . . . . . . . . 1282
C.6.13 Changes in release 3.21.21a . . . . . . . . . . . . . . . . . 1282
C.6.14 Changes in release 3.21.21 . . . . . . . . . . . . . . . . . . 1282
C.6.15 Changes in release 3.21.20 . . . . . . . . . . . . . . . . . . 1283
C.6.16 Changes in release 3.21.19 . . . . . . . . . . . . . . . . . . 1283
C.6.17 Changes in release 3.21.18 . . . . . . . . . . . . . . . . . . 1283
C.6.18 Changes in release 3.21.17 . . . . . . . . . . . . . . . . . . 1283
C.6.19 Changes in release 3.21.16 . . . . . . . . . . . . . . . . . . 1284
C.6.20 Changes in release 3.21.15 . . . . . . . . . . . . . . . . . . 1284
C.6.21 Changes in release 3.21.14b . . . . . . . . . . . . . . . . . 1285
C.6.22 Changes in release 3.21.14a . . . . . . . . . . . . . . . . . 1285
C.6.23 Changes in release 3.21.13 . . . . . . . . . . . . . . . . . . 1286
C.6.24 Changes in release 3.21.12 . . . . . . . . . . . . . . . . . . 1286
C.6.25 Changes in release 3.21.11 . . . . . . . . . . . . . . . . . . 1287
C.6.26 Changes in release 3.21.10 . . . . . . . . . . . . . . . . . . 1287
C.6.27 Changes in release 3.21.9 . . . . . . . . . . . . . . . . . . . 1288
C.6.28 Changes in release 3.21.8 . . . . . . . . . . . . . . . . . . . 1288
C.6.29 Changes in release 3.21.7 . . . . . . . . . . . . . . . . . . . 1288
C.6.30 Changes in release 3.21.6 . . . . . . . . . . . . . . . . . . . 1289
C.6.31 Changes in release 3.21.5 . . . . . . . . . . . . . . . . . . . 1289
C.6.32 Changes in release 3.21.4 . . . . . . . . . . . . . . . . . . . 1289
C.6.33 Changes in release 3.21.3 . . . . . . . . . . . . . . . . . . . 1289
C.6.34 Changes in release 3.21.2 . . . . . . . . . . . . . . . . . . . 1290
C.6.35 Changes in release 3.21.0 . . . . . . . . . . . . . . . . . . . 1291
C.7 Changes in release 3.20.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1292
C.7.1 Changes in release 3.20.18 . . . . . . . . . . . . . . . . . . . 1292
C.7.2 Changes in release 3.20.17 . . . . . . . . . . . . . . . . . . . 1292
xxxi
C.7.3 Changes in release 3.20.16 . . . . . . . . . . . . . . . . . . .
C.7.4 Changes in release 3.20.15 . . . . . . . . . . . . . . . . . . .
C.7.5 Changes in release 3.20.14 . . . . . . . . . . . . . . . . . . .
C.7.6 Changes in release 3.20.13 . . . . . . . . . . . . . . . . . . .
C.7.7 Changes in release 3.20.11 . . . . . . . . . . . . . . . . . . .
C.7.8 Changes in release 3.20.10 . . . . . . . . . . . . . . . . . . .
C.7.9 Changes in release 3.20.9 . . . . . . . . . . . . . . . . . . . .
C.7.10 Changes in release 3.20.8 . . . . . . . . . . . . . . . . . . .
C.7.11 Changes in release 3.20.7 . . . . . . . . . . . . . . . . . . .
C.7.12 Changes in release 3.20.6 . . . . . . . . . . . . . . . . . . .
C.7.13 Changes in release 3.20.3 . . . . . . . . . . . . . . . . . . .
C.7.14 Changes in release 3.20.0 . . . . . . . . . . . . . . . . . . .
C.8 Changes in release 3.19.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
C.8.1 Changes in release 3.19.5 . . . . . . . . . . . . . . . . . . . .
C.8.2 Changes in release 3.19.4 . . . . . . . . . . . . . . . . . . . .
C.8.3 Changes in release 3.19.3 . . . . . . . . . . . . . . . . . . . .
C.9 InnoDB Change History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
C.9.1 MySQL/InnoDB-4.0.21, September 10, 2004 . .
C.9.2 MySQL/InnoDB-4.1.4, August 31, 2004 . . . . . . .
C.9.3 MySQL/InnoDB-4.1.3, June 28, 2004 . . . . . . . . .
C.9.4 MySQL/InnoDB-4.1.2, May 30, 2004 . . . . . . . . .
C.9.5 MySQL/InnoDB-4.0.20, May 18, 2004 . . . . . . . .
C.9.6 MySQL/InnoDB-4.0.19, May 4, 2004 . . . . . . . . .
C.9.7 MySQL/InnoDB-4.0.18, February 13, 2004 . . . .
C.9.8 MySQL/InnoDB-5.0.0, December 24, 2003 . . . .
C.9.9 MySQL/InnoDB-4.0.17, December 17, 2003 . . .
C.9.10 MySQL/InnoDB-4.1.1, December 4, 2003 . . . .
C.9.11 MySQL/InnoDB-4.0.16, October 22, 2003 . . . .
C.9.12 MySQL/InnoDB-3.23.58, September 15, 2003
..............................................
C.9.13 MySQL/InnoDB-4.0.15, September 10, 2003 . .
C.9.14 MySQL/InnoDB-4.0.14, July 22, 2003 . . . . . . .
C.9.15 MySQL/InnoDB-3.23.57, June 20, 2003 . . . . . .
C.9.16 MySQL/InnoDB-4.0.13, May 20, 2003 . . . . . . .
C.9.17 MySQL/InnoDB-4.1.0, April 3, 2003. . . . . . . . .
C.9.18 MySQL/InnoDB-3.23.56, March 17, 2003 . . . .
C.9.19 MySQL/InnoDB-4.0.12, March 18, 2003 . . . . .
C.9.20 MySQL/InnoDB-4.0.11, February 25, 2003 . . .
C.9.21 MySQL/InnoDB-4.0.10, February 4, 2003 . . . .
C.9.22 MySQL/InnoDB-3.23.55, January 24, 2003 . . .
C.9.23 MySQL/InnoDB-4.0.9, January 14, 2003 . . . . .
C.9.24 MySQL/InnoDB-4.0.8, January 7, 2003 . . . . . .
C.9.25 MySQL/InnoDB-4.0.7, December 26, 2002 . . .
C.9.26 MySQL/InnoDB-4.0.6, December 19, 2002 . . .
C.9.27 MySQL/InnoDB-3.23.54, December 12, 2002
..............................................
C.9.28 MySQL/InnoDB-4.0.5, November 18, 2002 . . .
C.9.29 MySQL/InnoDB-3.23.53, October 9, 2002 . . . .
1293
1293
1294
1294
1295
1295
1295
1296
1296
1296
1297
1298
1298
1298
1299
1299
1299
1299
1301
1302
1303
1304
1304
1305
1306
1306
1306
1307
1307
1307
1308
1309
1309
1311
1311
1311
1311
1311
1312
1313
1313
1313
1313
1314
1314
1315
xxxii
C.9.30 MySQL/InnoDB-4.0.4, October 2, 2002 . . . . . .
C.9.31 MySQL/InnoDB-4.0.3, August 28, 2002. . . . . .
C.9.32 MySQL/InnoDB-3.23.52, August 16, 2002 . . .
C.9.33 MySQL/InnoDB-4.0.2, July 10, 2002 . . . . . . . .
C.9.34 MySQL/InnoDB-3.23.51, June 12, 2002 . . . . . .
C.9.35 MySQL/InnoDB-3.23.50, April 23, 2002 . . . . .
C.9.36 MySQL/InnoDB-3.23.49, February 17, 2002 . .
C.9.37 MySQL/InnoDB-3.23.48, February 9, 2002 . . .
C.9.38 MySQL/InnoDB-3.23.47, December 28, 2001
..............................................
C.9.39 MySQL/InnoDB-4.0.1, December 23, 2001 . . .
C.9.40 MySQL/InnoDB-3.23.46, November 30, 2001
..............................................
C.9.41 MySQL/InnoDB-3.23.45, November 23, 2001
..............................................
C.9.42 MySQL/InnoDB-3.23.44, November 2, 2001 . .
C.9.43 MySQL/InnoDB-3.23.43, October 4, 2001 . . . .
C.9.44 MySQL/InnoDB-3.23.42, September 9, 2001 . .
C.9.45 MySQL/InnoDB-3.23.41, August 13, 2001 . . .
C.9.46 MySQL/InnoDB-3.23.40, July 16, 2001 . . . . . .
C.9.47 MySQL/InnoDB-3.23.39, June 13, 2001 . . . . . .
C.9.48 MySQL/InnoDB-3.23.38, May 12, 2001 . . . . . .
C.10 MySQL Cluster Change History . . . . . . . . . . . . . . . . . . . . . .
C.10.1 MySQL Cluster-4.1.6, Q4 2004 . . . . . . . . . . . . . .
C.10.2 MySQL Cluster-4.1.5, sep/oct 2004 . . . . . . . . . .
C.10.3 MySQL Cluster-4.1.4, 31 Aug 2004 . . . . . . . . . .
C.10.4 MySQL Cluster-5.0.1, 27 Jul 2004 . . . . . . . . . . .
C.10.5 MySQL Cluster-4.1.3, 28 Jun 2004 . . . . . . . . . .
1316
1316
1317
1318
1319
1319
1320
1320
1321
1321
1321
1321
1322
1323
1323
1323
1323
1323
1323
1324
1324
1324
1326
1326
1326
Appendix D Porting to Other Systems . . . . . 1327
D.1
D.2
D.3
D.4
D.5
Debugging a MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . 1328
D.1.1 Compiling MySQL for Debugging . . . . . . . . . . . . 1328
D.1.2 Creating Trace Files. . . . . . . . . . . . . . . . . . . . . . . . . 1329
D.1.3 Debugging mysqld under gdb . . . . . . . . . . . . . . . . 1330
D.1.4 Using a Stack Trace . . . . . . . . . . . . . . . . . . . . . . . . . 1331
D.1.5 Using Log Files to Find Cause of Errors in mysqld
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1332
D.1.6 Making a Test Case If You Experience Table
Corruption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1332
Debugging a MySQL Client . . . . . . . . . . . . . . . . . . . . . . . . . . 1333
The DBUG Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1334
Comments about RTS Threads . . . . . . . . . . . . . . . . . . . . . . . 1335
Differences Between Thread Packages . . . . . . . . . . . . . . . . . 1337
Appendix E Environment Variables . . . . . . . . 1338
Appendix F MySQL Regular Expressions . . 1339
xxxiii
Appendix G GNU General Public License . . 1343
Appendix H MySQL FLOSS License Exception
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1349
SQL Command, Type, and Function Index . . 1351
Concept Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1360
Chapter 1: General Information
1
1 General Information
R
The MySQL °
software delivers a very fast, multi-threaded, multi-user, and robust SQL
(Structured Query Language) database server. MySQL Server is intended for missioncritical, heavy-load production systems as well as for embedding into mass-deployed software. MySQL is a registered trademark of MySQL AB.
The MySQL software is Dual Licensed. Users can choose to use the MySQL software as an
Open Source/Free Software product under the terms of the GNU General Public License
(http://www.fsf.org/licenses/) or can purchase a standard commercial license from
MySQL AB. See Section 1.4 [Licensing and Support], page 16.
The MySQL Web site (http://www.mysql.com/) provides the latest information about the
MySQL software.
The following list describes some sections of particular interest in this manual:
• For information about the company behind the MySQL Database Server, see Section 1.3
[What is MySQL AB], page 12.
• For a discussion about the capabilities of the MySQL Database Server, see Section 1.2.2
[Features], page 6.
• For installation instructions, see Chapter 2 [Installing], page 59.
• For tips on porting the MySQL Database Software to new architectures or operating
systems, see Appendix D [Porting], page 1327.
• For information about upgrading from a Version 4.0 release, see Section 2.5.2
[Upgrading-from-4.0], page 134.
• For information about upgrading from a Version 3.23 release, see Section 2.5.3
[Upgrading-from-3.23], page 139.
• For information about upgrading from a Version 3.22 release, see Section 2.5.4
[Upgrading-from-3.22], page 143.
• For a tutorial introduction to the MySQL Database Server, see Chapter 3 [Tutorial],
page 184.
• For examples of SQL and benchmarking information, see the benchmarking directory
(‘sql-bench’ in the distribution).
• For a history of new features and bugfixes, see Appendix C [News], page 1145.
• For a list of currently known bugs and misfeatures, see Section 1.8.7 [Bugs], page 52.
• For future plans, see Section 1.6 [TODO], page 26.
• For a list of all the contributors to this project, see Appendix B [Credits], page 1134.
Important:
Reports of errors (often called “bugs”), as well as questions and comments, should be
sent to the general MySQL mailing list. See Section 1.7.1.1 [Mailing-list], page 32. See
Section 1.7.1.3 [Bug reports], page 34.
The mysqlbug script should be used to generate bug reports on Unix. (Windows distributions contain a file named ‘mysqlbug.txt’ in the base directory that can be used as a
template for a bug report.)
2
MySQL Technical Reference for Version 5.0.1-alpha
For source distributions, the mysqlbug script can be found in the ‘scripts’ directory. For
binary distributions, mysqlbug can be found in the ‘bin’ directory (‘/usr/bin’ for the
MySQL-server RPM package).
If you have found a sensitive security bug in MySQL Server, please let us know immediately
by sending an email message to security@mysql.com.
1.1 About This Manual
This is the Reference Manual for the MySQL Database System. It documents MySQL up to
Version 5.0.1-alpha, but is also applicable for older versions of the MySQL software (such as
3.23 or 4.0-production) because functional changes are indicated with reference to a version
number.
Because this manual serves as a reference, it does not provide general instruction on SQL
or relational database concepts. It also will not teach you how to use your operating system
or command-line interpreter.
The MySQL Database Software is under constant development, and the Reference Manual
is updated frequently as well. The most recent version of the manual is available online in
searchable form at http://dev.mysql.com/doc/. Other formats also are available, including HTML, PDF, and Windows CHM versions.
The primary document is the Texinfo file. The HTML version is produced automatically
using 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 pdftex.
If you have any suggestions concerning additions or corrections to this manual, please send
them to the documentation team at docs@mysql.com.
This manual was initially written by David Axmark and Michael “Monty” Widenius. It
is now maintained by the MySQL Documentation Team, consisting of Arjen Lentz, Paul
DuBois, and Stefan Hinz. For the many other contributors, see Appendix B [Credits],
page 1134.
The copyright (2004) to this manual is owned by the Swedish company MySQL AB. See
Section 1.4.2 [Copyright], page 17. MySQL and the MySQL logo are (registered) trademarks
of MySQL AB. Other trademarks and registered trademarks referred to in this manual are
the property of their respective owners, and are used for identification purposes only.
1.1.1 Conventions Used in This Manual
This manual uses certain typographical conventions:
constant
Constant-width font is used for command names and options; SQL statements;
database, table, and column names; C and Perl code; and environment variables. Example: “To see how mysqladmin works, invoke it with the --help
option.”
constant italic
Italic constant-width font is used to indicate variable input for which you should
substitute a value of your own choosing.
Chapter 1: General Information
3
‘filename’
Constant-width font with surrounding quotes is used for filenames and pathnames. Example: “The distribution is installed under the ‘/usr/local/’ directory.”
‘c’
Constant-width font with surrounding quotes is also used to indicate character
sequences. Example: “To specify a wildcard, use the ‘%’ character.”
italic
Italic font is used for emphasis, like this.
boldface
Boldface font is used in table headings and to convey especially strong emphasis.
When commands are shown that are meant to be executed from within a particular program, the program is indicated by a prompt shown before the command. For example,
shell> indicates a command that you execute from your login shell, and mysql> indicates
a statement that you execute from the mysql client program:
shell> type a shell command here
mysql> type a mysql statement here
The “shell” is your command interpreter. On Unix, this is typically a program such as sh
or csh. On Windows, the equivalent program is command.com or cmd.exe, typically run in
a console window.
When you enter a command or statement shown in an example, do not type the prompt
shown in the example.
Database, table, and column names must often be substituted into statements. To indicate
that such substitution is necessary, this manual uses db name, tbl name, and col name.
For example, you might see a statement like this:
mysql> SELECT col_name FROM db_name.tbl_name ;
This means that if you were 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 keywords are not case sensitive and may be written in uppercase or lowercase. This
manual uses uppercase.
In syntax descriptions, square brackets (‘[’ and ‘]’) are used to indicate optional words or
clauses. For example, in the following statement, IF EXISTS is optional:
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 (‘[’ and ‘]’):
TRIM([[BOTH | LEADING | TRAILING] [remstr ] FROM] str )
When one member from a set of choices must be chosen, the alternatives are listed within
braces (‘{’ and ‘}’):
{DESCRIBE | DESC} tbl_name [col_name | wild ]
An ellipsis (...) indicates the omission of a section of a statement, typically to provide a
shorter version of more complex syntax. For example, INSERT ... SELECT is shorthand for
the form of INSERT statement that is followed by a SELECT statement.
4
MySQL Technical Reference for Version 5.0.1-alpha
An ellipsis can also indicate that the preceding syntax element of a statement may be
repeated. In the following example, multiple reset option values may be given, with each
of those after the first preceded by commas:
RESET reset_option [,reset_option ] ...
Commands for setting shell variables are shown using Bourne shell syntax. 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
If you are using csh or tcsh, you must issue commands somewhat differently. You would
execute the sequence just shown like this:
shell> setenv VARNAME value
shell> some_command
1.2 Overview of the MySQL Database Management System
MySQL, the most popular Open Source SQL database management system, is developed,
distributed, and supported by MySQL AB. MySQL AB is a commercial company, founded
by the MySQL developers. It is a second generation open source company that unites open
source values and methodology with a successful business model. See Section 1.3 [What is
MySQL AB], page 12.
The MySQL Web site (http://www.mysql.com/) provides the latest information about
MySQL software and MySQL AB.
MySQL is a database management system.
A database is a structured collection of data. It may be anything from a
simple shopping list to a picture gallery or the vast amounts of information in
a corporate network. To add, access, and process data stored in a computer
database, you need a database management system such as MySQL Server.
Since computers are very good at handling large amounts of data, database
management systems play a central role in computing, as standalone utilities
or as parts of other applications.
MySQL is a relational database management system.
A relational database stores data in separate tables rather than putting all the
data in one big storeroom. This adds speed and flexibility. The SQL part of
“MySQL” stands for “Structured Query Language.” SQL is the most common
standardized language used to access databases and is defined by the ANSI/ISO
SQL Standard. The SQL standard has been evolving since 1986 and several
versions exist. In this manual, “SQL-92” refers to the standard released in 1992,
“SQL:1999” refers to the standard released in 1999, and “SQL:2003” refers to
the current version of the standard. We use the phrase “the SQL standard” to
mean the current version of the SQL Standard at any time.
MySQL software is Open Source.
Open Source means that it is possible for anyone to use and modify the software. Anybody can download the MySQL software from the Internet and use
it without paying anything. If you wish, you may study the source code and
Chapter 1: General Information
5
change it to suit your needs. The MySQL software uses the GPL (GNU General
Public License), http://www.fsf.org/licenses/, to define what you may and
may not do with the software in different situations. If you feel uncomfortable
with the GPL or need to embed MySQL code into a commercial application,
you can buy a commercially licensed version from us. See Section 1.4.3 [MySQL
licenses], page 17.
The MySQL Database Server is very fast, reliable, and easy to use.
If that is what you are looking for, you should give it a try. MySQL Server also
has a practical set of features developed in close cooperation with our users.
You can find a performance comparison of MySQL Server with other database
managers on our benchmark page. See Section 7.1.4 [MySQL Benchmarks],
page 421.
MySQL Server was originally developed to handle large databases much faster
than existing solutions and has been successfully used in highly demanding production environments for several years. Although under constant development,
MySQL Server today offers a rich and useful set of functions. Its connectivity,
speed, and security make MySQL Server highly suited for accessing databases
on the Internet.
MySQL Server works in client/server or embedded systems.
The MySQL Database Software is a client/server system that consists of a multithreaded SQL server that supports different backends, several different client
programs and libraries, administrative tools, and a wide range of application
programming interfaces (APIs).
We also provide MySQL Server as an embedded multi-threaded library that
you can link into your application to get a smaller, faster, easier-to-manage
product.
A large amount of contributed MySQL software is available.
It is very likely that you will find that your favorite application or language
already supports the MySQL Database Server.
The official way to pronounce “MySQL” is “My Ess Que Ell” (not “my sequel”), but we
don’t mind if you pronounce it as “my sequel” or in some other localized way.
1.2.1 History of MySQL
We started out with the intention of using mSQL to connect to our tables using our own fast
low-level (ISAM) routines. 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
designed to allow third-party code that was written for use with mSQL to be ported easily
for use with MySQL.
The derivation of the name MySQL is not clear. Our base directory and a large number of
our libraries and tools have had the prefix “my” for well over 10 years. However, co-founder
Monty Widenius’s daughter is also named My. Which of the two gave its name to MySQL
is still a mystery, even for us.
6
MySQL Technical Reference for Version 5.0.1-alpha
The name of the MySQL Dolphin (our logo) is “Sakila,” which was chosen by the founders
of MySQL AB from a huge list of names suggested by users in our “Name the Dolphin”
contest. The winning name was submitted by Ambrose Twebaze, an Open Source software
developer from Swaziland, Africa. According to Ambrose, the name Sakila has its roots
in SiSwati, the local language of Swaziland. Sakila is also the name of a town in Arusha,
Tanzania, near Ambrose’s country of origin, Uganda.
1.2.2 The Main Features of MySQL
The following list describes some of the important characteristics of the MySQL Database
Software. See also Section 1.5 [Roadmap], page 21 for more information about current and
upcoming features.
Internals and Portability
• Written in C and C++.
• Tested with a broad range of different compilers.
• Works on many different platforms. See Section 2.1.1 [Which OS], page 60.
• Uses GNU Automake, Autoconf, and Libtool for portability.
• APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and Tcl are available. See Chapter 21 [Clients], page 948.
• Fully multi-threaded using kernel threads. It can easily use multiple CPUs
if they are available.
• Provides transactional and non-transactional storage engines.
• Uses very fast B-tree disk tables (MyISAM) with index compression.
• Relatively easy to add another storage engine. This is useful if you want
to add an SQL interface to an in-house database.
• A very fast thread-based memory allocation system.
• Very fast joins using an optimized one-sweep multi-join.
• In-memory hash tables, which are used as temporary tables.
• SQL functions are implemented using a highly optimized class library and
should be as fast as possible. Usually there is no memory allocation at all
after query initialization.
• The MySQL code is tested with Purify (a commercial memory leakage detector) as well as with Valgrind, a GPL tool
(http://developer.kde.org/~sewardj/).
• The server is available as a separate program for use in a client/server networked environment. It is also available as a library that can be embedded
(linked) into standalone applications. Such applications can be used in
isolation or in environments where no network is available.
Column Types
• Many column types: signed/unsigned integers 1, 2, 3, 4, and 8 bytes
long, FLOAT, DOUBLE, CHAR, VARCHAR, TEXT, BLOB, DATE, TIME, DATETIME,
TIMESTAMP, YEAR, SET, ENUM, and OpenGIS spatial types. See Chapter 12
[Column types], page 566.
Chapter 1: General Information
7
• Fixed-length and variable-length records.
Statements and Functions
• Full operator and function support in the SELECT and WHERE clauses of
queries. For example:
mysql> SELECT CONCAT(first_name, ’ ’, last_name)
-> FROM citizen
-> WHERE income/dependents > 10000 AND age > 30;
• Full support for SQL GROUP BY and ORDER BY clauses. Support for group
functions (COUNT(), COUNT(DISTINCT ...), AVG(), STD(), SUM(), MAX(),
MIN(), and GROUP_CONCAT()).
• Support for LEFT OUTER JOIN and RIGHT OUTER JOIN with both standard
SQL and ODBC syntax.
• Support for aliases on tables and columns as required by standard SQL.
• DELETE, INSERT, REPLACE, and UPDATE return the number of rows that were
changed (affected). It is possible to return the number of rows matched
instead by setting a flag when connecting to the server.
• The MySQL-specific SHOW command can be used to retrieve information
about databases, tables, and indexes. The EXPLAIN command can be used
to determine how the optimizer resolves a query.
• Function names do not clash with table or column names. For example,
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 10.6 [Reserved words], page 535.
• You can mix tables from different databases in the same query (as of
MySQL 3.22).
Security
• A privilege and password system that is very flexible and secure, and that
allows host-based verification. Passwords are secure because all password
traffic is encrypted when you connect to a server.
Scalability and Limits
• Handles large databases. We use MySQL Server with databases that contain 50 million records. We also know of users who use MySQL Server with
60,000 tables and about 5,000,000,000 rows.
• Up to 64 indexes per table are allowed (32 before MySQL 4.1.2). Each
index may consist of 1 to 16 columns or parts of columns. The maximum
index width is 1000 bytes (500 before MySQL 4.1.2). An index may use a
prefix of a column for CHAR, VARCHAR, BLOB, or TEXT column types.
Connectivity
• Clients can connect to the MySQL server using TCP/IP sockets on any
platform. On Windows systems in the NT family (NT, 2000, or XP), clients
can connect using named pipes. On Unix systems, clients can connect using
Unix domain socket files.
8
MySQL Technical Reference for Version 5.0.1-alpha
• The Connector/ODBC (MyODBC) interface provides MySQL support for
client programs that use ODBC (Open Database Connectivity) connections. For example, you can use MS Access to connect to your MySQL
server. Clients can be run on Windows or Unix. MyODBC source is available. All ODBC 2.5 functions are supported, as are many others. See
Section 21.3 [ODBC], page 1050.
• The Connector/J interface provides MySQL support for Java client programs that use JDBC connections. Clients can be run on Windows or
Unix. Connector/J source is available. See Section 21.4 [Java], page 1061.
Localization
• The server can provide error messages to clients in many languages. See
Section 5.8.2 [Languages], page 360.
• Full support for several different character sets, including latin1 (ISO8859-1), german, big5, ujis, and more. For example, the Scandinavian
characters ‘^
a’, ‘ä’ and ‘ö’ are allowed in table and column names. Unicode
support is available as of MySQL 4.1.
• All data is saved in the chosen character set. All comparisons for normal
string columns are case-insensitive.
• Sorting is done according to the chosen character set (using Swedish collation by default). It is possible to change this when the MySQL server
is started. To see an example of very advanced sorting, look at the Czech
sorting code. MySQL Server supports many different character sets that
can be specified at compile time and runtime.
Clients and Tools
• The MySQL server has built-in support for SQL statements to check, optimize, and repair tables. These statements are available from the command
line through the mysqlcheck client. MySQL also includes myisamchk, a
very fast command-line utility for performing these operations on MyISAM
tables. See Chapter 5 [MySQL Database Administration], page 231.
• All MySQL programs can be invoked with the --help or -? options to
obtain online assistance.
1.2.3 MySQL Stability
This section addresses the questions, “How stable is MySQL Server? ” and, “Can I depend
on MySQL Server in this project? ” We will try to clarify these issues and answer some
important questions that concern many potential users. The information in this section is
based on data gathered from the mailing lists, which are very active in identifying problems
as well as reporting types of use.
The original code stems back to the early 1980s. It provides a stable code base, and the
ISAM table format used by the original storage engine remains backward-compatible. At
TcX, the predecessor of MySQL AB, MySQL code has worked in projects since mid-1996,
without any problems. When the MySQL Database Software initially was released to a
wider public, our new users quickly found some pieces of untested code. Each new release
Chapter 1: General Information
9
since then has had fewer portability problems, even though each new release has also had
many new features.
Each release of the MySQL Server has been usable. Problems have occurred only when
users try code from the “gray zones.” Naturally, new users don’t know what the gray zones
are; this section therefore attempts to document those areas that are currently known. The
descriptions mostly deal with Version 3.23, 4.0 and 4.1 of MySQL Server. All known and
reported bugs are fixed in the latest version, with the exception of those listed in the bugs
section, which are design-related. See Section 1.8.7 [Bugs], page 52.
The MySQL Server design is multi-layered with independent modules. Some of the newer
modules are listed here with an indication of how well-tested each of them is:
Replication (Stable)
Large groups of servers using replication are in production use, with good results. Work on enhanced replication features is continuing in MySQL 5.x.
InnoDB tables (Stable)
The InnoDB transactional storage engine has been declared stable in the MySQL
3.23 tree, starting from version 3.23.49. InnoDB is being used in large, heavyload production systems.
BDB tables (Stable)
The Berkeley DB code is very stable, but we are still improving the BDB transactional storage engine interface in MySQL Server, so it will take some time
before this is as well tested as the other table types.
Full-text searches (Stable)
Full-text searching works but is not yet widely used. Important enhancements
have been implemented in MySQL 4.0.
MyODBC 3.51 (Stable)
MyODBC 3.51 uses ODBC SDK 3.51 and is in wide production use. Some issues
brought up appear to be application-related and independent of the ODBC
driver or underlying database server.
Automatic recovery of MyISAM tables (Stable)
This status applies only to the new code in the MyISAM storage engine that
checks when opening a table whether it was closed properly and executes an
automatic check or repair of the table if it wasn’t.
1.2.4 How Big MySQL Tables Can Be
MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in
MySQL 3.23, the maximum table size was increased to 8 million terabytes (2 ^ 63 bytes).
With this larger allowed table size, the maximum effective table size for MySQL databases
now usually is determined by operating system constraints on file sizes, not by MySQL
internal limits.
The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size.
The tablespace can include raw disk partitions, which allows extremely large tables. The
maximum tablespace size is 64TB.
10
MySQL Technical Reference for Version 5.0.1-alpha
The following table lists some examples of operating system file-size limits:
Operating System
Linux-Intel 32-bit
Linux-Alpha
Solaris 2.5.1
Solaris 2.6
Solaris 2.7 Intel
Solaris 2.7 UltraSPARC
NetWare w/NSS filesystem
File-size Limit
2GB, much more when using LFS
8TB (?)
2GB (4GB possible with patch)
4GB (can be changed with flag)
4GB
512GB
8TB
On Linux 2.2, you can get MyISAM tables larger than 2GB in size by using the Large File
Support (LFS) patch for the ext2 filesystem. On Linux 2.4, patches also exist for ReiserFS
to get support for big files. Most current Linux distributions are based on kernel 2.4 and
already include all the required LFS patches. However, the maximum available file size still
depends on several factors, one of them being the filesystem used to store MySQL tables.
For a detailed overview about LFS in Linux, have a look at Andreas Jaeger’s Large File
Support in Linux page at http://www.suse.de/~aj/linux_lfs.html.
By default, MySQL creates MyISAM tables with an internal structure that allows a maximum
size of about 4GB. You can check the maximum table size for a table with the SHOW TABLE
STATUS statement or with myisamchk -dv tbl_name . See Section 14.5.3 [SHOW], page 744.
If you need a MyISAM table that will be larger than 4GB in size (and your operating system
supports large files), the CREATE TABLE statement allows AVG_ROW_LENGTH and MAX_ROWS
options. See Section 14.2.6 [CREATE TABLE], page 710. You can also change these options
with ALTER TABLE after the table has been created, to increase the table’s maximum allowable size. See Section 14.2.2 [ALTER TABLE], page 704.
Other ways to work around file-size limits for MyISAM tables are as follows:
• If your large table is read-only, you can use myisampack to compress it. myisampack
usually compresses a table by at least 50%, so you can have, in effect, much bigger
tables. myisampack also can merge multiple tables into a single table. See Section 8.2
[myisampack], page 480.
• Another way to get around the operating system file limit for MyISAM data files is by
using the RAID options. See Section 14.2.6 [CREATE TABLE], page 710.
• MySQL includes a MERGE library that allows you to handle a collection of MyISAM tables
that have identical structure as a single MERGE table. See Section 15.2 [MERGE tables],
page 792.
1.2.5 Year 2000 Compliance
The MySQL Server itself has no problems with Year 2000 (Y2K) compliance:
• MySQL Server uses Unix time functions that handle dates into the year 2037 for
TIMESTAMP values. For DATE and DATETIME values, dates through the year 9999 are
accepted.
• All MySQL date functions are implemented in one source file, ‘sql/time.cc’, and are
coded very carefully to be year 2000-safe.
Chapter 1: General Information
11
• In MySQL 3.22 and later, the YEAR column type can store years 0 and 1901 to 2155 in
one byte and display them using two or four digits. All two-digit years are considered
to be in the range 1970 to 2069, which means that if you store 01 in a YEAR column,
MySQL Server treats it as 2001.
The following simple demonstration illustrates that MySQL Server has no problems with
DATE or DATETIME values through the year 9999, and no problems with TIMESTAMP values
until after the year 2030:
mysql> DROP TABLE IF EXISTS y2k;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE y2k (date DATE,
->
date_time DATETIME,
->
time_stamp TIMESTAMP);
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO y2k VALUES
-> (’1998-12-31’,’1998-12-31 23:59:59’,19981231235959),
-> (’1999-01-01’,’1999-01-01 00:00:00’,19990101000000),
-> (’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),
-> (’2040-01-01’,’2040-01-01 00:00:00’,20400101000000),
-> (’9999-12-31’,’9999-12-31 23:59:59’,99991231235959);
Query OK, 14 rows affected (0.01 sec)
Records: 14 Duplicates: 0 Warnings: 2
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 | 19990101000000 |
| 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 |
12
MySQL Technical Reference for Version 5.0.1-alpha
| 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 |
| 2040-01-01 | 2040-01-01 00:00:00 | 00000000000000 |
| 9999-12-31 | 9999-12-31 23:59:59 | 00000000000000 |
+------------+---------------------+----------------+
14 rows in set (0.00 sec)
The final two TIMESTAMP column values are zero because the year values (2040, 9999)
exceed the TIMESTAMP maximum. The TIMESTAMP data type, which is used to store the
current time, supports values that range from 19700101000000 to 20300101000000 on 32bit machines (signed value). On 64-bit machines, TIMESTAMP handles values up to 2106
(unsigned value).
Although MySQL Server itself is Y2K-safe, you may run into problems if you use it with
applications that are not Y2K-safe. For example, many old applications store or manipulate
years using two-digit values (which are ambiguous) rather than four-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 because different
applications may be written by different programmers, each of whom may use a different
set of conventions and date-handling functions.
Thus, even though MySQL Server has no Y2K problems, it is the application’s responsibility
to provide unambiguous input. See Section 12.3.4 [Y2K issues], page 583 for MySQL Server’s
rules for dealing with ambiguous date input data that contains two-digit year values.
1.3 Overview of MySQL AB
MySQL AB is the company of the MySQL founders and main developers. MySQL AB was
originally established in Sweden by David Axmark, Allan Larsson, and Michael “Monty”
Widenius.
The developers of the MySQL server are all employed by the company. We are a virtual organization with people in a dozen countries around the world. We communicate extensively
over the Internet every day with one another and with our users, supporters, and partners.
We are dedicated to developing the MySQL database software and promoting it to new
users. MySQL AB owns the copyright to the MySQL source code, the MySQL logo and
(registered) trademark, and this manual. See Section 1.2 [What-is], page 4.
The MySQL core values show our dedication to MySQL and Open Source.
These core values direct how MySQL AB works with the MySQL server software:
• To be the best and the most widely used database in the world
• To be available and affordable by all
• To be easy to use
• To be continuously improved while remaining fast and safe
• To be fun to use and improve
• To be free from bugs
These are the core values of the company MySQL AB and its employees:
Chapter 1: General Information
•
•
•
•
•
•
13
We subscribe to the Open Source philosophy and support the Open Source community
We aim to be good citizens
We prefer partners that share our values and mindset
We answer email and provide support
We are a virtual company, networking with others
We work against software patents
The MySQL Web site (http://www.mysql.com/) provides the latest information about
MySQL and MySQL AB.
By the way, the “AB” part of the company name is the acronym for the Swedish “aktiebolag,” or “stock company.” It translates to “MySQL, Inc.” In fact, MySQL, Inc. and
MySQL GmbH are examples of MySQL AB subsidiaries. They are located in the US and
Germany, respectively.
1.3.1 The Business Model and Services of MySQL AB
One of the most common questions we encounter is, “How can you make a living from
something you give away for free? ” This is how:
• MySQL AB makes money on support, services, commercial licenses, and royalties.
• We use these revenues to fund product development and to expand the MySQL business.
The company has been profitable since its inception. In October 2001, we accepted venture financing from leading Scandinavian investors and a handful of business angels. This
investment is used to solidify our business model and build a basis for sustainable growth.
1.3.1.1 Support
MySQL AB is run and owned by the founders and main developers of the MySQL database.
The developers are committed to providing support to customers and other users in order
to stay in touch with their needs and problems. All our support is provided by qualified
developers. Really tricky questions are answered by Michael “Monty” Widenius, principal
author of the MySQL Server.
Paying customers receive high-quality support directly from MySQL AB. MySQL AB also
provides the MySQL mailing lists as a community resource where anyone may ask questions.
For more information and ordering support at various levels, see Section 1.4 [Licensing and
Support], page 16.
1.3.1.2 Training and Certification
MySQL AB delivers MySQL and related training worldwide. We offer both open courses
and in-house courses tailored to the specific needs of your company. MySQL Training is
also available through our partners, the Authorized MySQL Training Centers.
Our training material uses the same sample databases used in our documentation and
our sample applications, and is always updated to reflect the latest MySQL version. Our
14
MySQL Technical Reference for Version 5.0.1-alpha
trainers are backed by the development team to guarantee the quality of the training and
the continuous development of the course material. This also ensures that no questions
raised during the courses remain unanswered.
Attending our training courses will enable you to achieve your MySQL application goals.
You will also:
• Save time
• Improve the performance of your applications
• Reduce or eliminate the need for additional hardware, decreasing cost
• Enhance security.
• Increase customer and co-worker satisfaction
• Prepare yourself for MySQL Certification
If you are interested in our training as a potential participant or as a training partner,
please visit the training section at http://www.mysql.com/training/, or send email to
training@mysql.com.
For details about the MySQL Certification Program, please see http://www.mysql.com/certification/.
1.3.1.3 Consulting
MySQL AB and its Authorized Partners offer consulting services to users of MySQL Server
and to those who embed MySQL Server in their own software, all over the world.
Our consultants can help you design and tune your databases, construct efficient queries,
tune your platform for optimal performance, resolve migration issues, set up replication,
build robust transactional applications, and more. We also help customers embed MySQL
Server in their products and applications for large-scale deployment.
Our consultants work in close collaboration with our development team, which ensures the
technical quality of our professional services. Consulting assignments range from two-day
power-start sessions to projects that span weeks and months. Our expertise covers not only
MySQL Server, it also extends into programming and scripting languages such as PHP,
Perl, and more.
If you are interested in our consulting services or want to become a consulting partner,
please visit the consulting section of our Web site at http://www.mysql.com/consulting/
or contact our consulting staff at consulting@mysql.com.
1.3.1.4 Commercial Licenses
The MySQL database is released under the GNU General Public License (GPL). This means
that the MySQL software can be used free of charge under the GPL. If you do not want
to be bound by the GPL terms (such as the requirement that your application must also
be GPL), you may purchase a commercial license for the same product from MySQL AB;
see https://order.mysql.com/. Since MySQL AB owns the copyright to the MySQL
source code, we are able to employ Dual Licensing, which means that the same product is
available under GPL and under a commercial license. This does not in any way affect the
Open Source commitment of MySQL AB. For details about when a commercial license is
required, please see Section 1.4.3 [MySQL licenses], page 17.
Chapter 1: General Information
15
We also sell commercial licenses of third-party Open Source GPL software that adds value
to MySQL Server. A good example is the InnoDB transactional storage engine that offers
ACID support, row-level locking, crash recovery, multi-versioning, foreign key support, and
more. See Chapter 16 [InnoDB], page 804.
1.3.1.5 Partnering
MySQL AB has a worldwide partner program that covers training courses, consulting and
support, publications, plus reselling and distributing MySQL and related products. MySQL
AB Partners get visibility on the http://www.mysql.com/ Web site and the right to use
special versions of the MySQL (registered) trademarks to identify their products and promote their business.
If you are interested in becoming a MySQL AB Partner, please email partner@mysql.com.
The word MySQL and the MySQL dolphin logo are (registered) trademarks of MySQL
AB. See Section 1.4.4 [MySQL AB Logos and Trademarks], page 20. These trademarks
represent a significant value that the MySQL founders have built over the years.
The MySQL Web site (http://www.mysql.com/) is popular among developers and users. In
December 2003, we served 16 million page views. Our visitors represent a group that makes
purchase decisions and recommendations for both software and hardware. Twelve percent
of our visitors authorize purchase decisions, and only nine percent have no involvement at
all in purchase decisions. More than 65% have made one or more online business purchases
within the last half-year, and 70% plan to make one in the next few months.
1.3.2 Contact Information
The MySQL Web site (http://www.mysql.com/) provides the latest information about
MySQL and MySQL AB.
For press services and inquiries not covered in our news releases (http://www.mysql.com/news-and-events
please send email to press@mysql.com.
If you have a support contract with MySQL AB, you will get timely, precise answers to
your technical questions about the MySQL software. For more information, see Section 1.4.1
[Support], page 16. On our Web site, see http://www.mysql.com/support/, or send email
to sales@mysql.com.
For information about MySQL training, please visit the training section at
http://www.mysql.com/training/, or send email to training@mysql.com.
See
Section 1.3.1.2 [Business Services Training], page 13.
For information on the MySQL Certification Program, please see http://www.mysql.com/certification/.
See Section 1.3.1.2 [Business Services Training], page 13.
If you’re interested in consulting, please visit the consulting section of our Web site at
http://www.mysql.com/consulting/, or send email to consulting@mysql.com. See Section 1.3.1.3 [Business Services Consulting], page 14.
Commercial licenses may be purchased online at https://order.mysql.com/. There you
will also find information on how to fax your purchase order to MySQL AB. More information about licensing can be found at http://www.mysql.com/products/licensing/.
16
MySQL Technical Reference for Version 5.0.1-alpha
If you have questions regarding licensing or you want a quote for high-volume licensing,
please fill in the contact form on our Web site (http://www.mysql.com/), or send email to
licensing@mysql.com (for licensing questions) or to sales@mysql.com (for sales inquiries).
See Section 1.4.3 [MySQL licenses], page 17.
If you represent a business that is interested in partnering with MySQL AB, please send
email to partner@mysql.com. See Section 1.3.1.5 [Business Services Partnering], page 15.
For more information on the MySQL trademark policy, refer to http://www.mysql.com/company/trademar
or send email to trademark@mysql.com. See Section 1.4.4 [MySQL AB Logos and
Trademarks], page 20.
If you are interested in any of the MySQL AB jobs listed in our jobs section
(http://www.mysql.com/company/jobs/), please send email to jobs@mysql.com. Please
do not send your CV as an attachment, but rather as plain text at the end of your email
message.
For general discussion among our many users, please direct your attention to the appropriate
mailing list. See Section 1.7.1 [Questions], page 32.
Reports of errors (often called “bugs”), as well as questions and comments, should be sent
to the general MySQL mailing list. See Section 1.7.1.1 [Mailing-list], page 32. If you have
found a sensitive security bug in MySQL Server, please let us know immediately by sending
email to security@mysql.com. See Section 1.7.1.3 [Bug reports], page 34.
If you have benchmark results that we can publish, please contact us via email at
benchmarks@mysql.com.
If you have suggestions concerning additions or corrections to this manual, please send them
to the documentation team via email at docs@mysql.com.
For questions or comments about the workings or content of the MySQL Web site
(http://www.mysql.com/), please send email to webmaster@mysql.com.
MySQL AB has a privacy policy, which can be read at http://www.mysql.com/company/privacy.html.
For any queries regarding this policy, please send email to privacy@mysql.com.
For all other inquiries, please send email to info@mysql.com.
1.4 MySQL Support and Licensing
This section describes MySQL support and licensing arrangements.
1.4.1 Support Offered by MySQL AB
Technical support from MySQL AB means individualized answers to your unique problems
direct from the software engineers who code the MySQL database engine.
We try to take a broad and inclusive view of technical support. Almost any problem involving MySQL software is important to us if it’s important to you. Typically customers seek
help on how to get different commands and utilities to work, remove performance bottlenecks, restore crashed systems, understand the impact of operating system or networking
issues on MySQL, set up best practices for backup and recovery, utilize APIs, and so on.
Our support covers only the MySQL server and our own utilities, not third-party products
that access the MySQL server, although we try to help with these where we can.
Chapter 1: General Information
17
Detailed information about our various support options is given at http://www.mysql.com/support/,
where support contracts can also be ordered online. To contact our sales staff, send email
to sales@mysql.com.
Technical support is like life insurance. You can live happily without it for years. However,
when your hour arrives, it becomes critically important, but it’s too late to buy it. If you
use MySQL Server for important applications and encounter sudden difficulties, it may be
too time-consuming to figure out all the answers yourself. You may need immediate access
to the most experienced MySQL troubleshooters available, those employed by MySQL AB.
1.4.2 Copyrights and Licenses Used by MySQL
MySQL AB owns the copyright to the MySQL source code, the MySQL logos and (registered) trademarks, and this manual. See Section 1.3 [What is MySQL AB], page 12. Several
different licenses are relevant to the MySQL distribution:
1. All the MySQL-specific source in the server, the mysqlclient library and the client,
as well as the GNU readline library, are covered by the GNU General Public License.
See Appendix G [GPL license], page 1343. The text of this license can be found as the
file ‘COPYING’ in MySQL distributions.
2. The GNU getopt library is covered by the GNU Lesser General Public License. See
http://www.fsf.org/licenses/.
3. Some parts of the source (the regexp library) are covered by a Berkeley-style copyright.
4. Older versions of MySQL (3.22 and earlier) are subject to a stricter license
(http://www.mysql.com/products/licensing/mypl.html). See the documentation
of the specific version for information.
5. The MySQL Reference Manual is not distributed under a GPL-style license. Use of
the manual is subject to the following terms:
• Conversion to other formats is allowed, but the actual content may not be altered
or edited in any way.
• You may create a printed copy for your own personal use.
• For all other uses, such as selling printed copies or using (parts of) the manual in
another publication, prior written agreement from MySQL AB is required.
Please send an email message to docs@mysql.com for more information or if you are
interested in doing a translation.
For information about how the MySQL licenses work in practice, please refer to Section 1.4.3
[MySQL licenses], page 17 and Section 1.4.4 [MySQL AB Logos and Trademarks], page 20.
1.4.3 MySQL Licenses
The MySQL software is released under the GNU General Public License (GPL),
which is probably the best known Open Source license.
The formal terms of
the GPL license can be found at http://www.fsf.org/licenses/.
See also
http://www.fsf.org/licenses/gpl-faq.html and http://www.gnu.org/philosophy/enforcing-gpl.h
18
MySQL Technical Reference for Version 5.0.1-alpha
Our GPL licensing is supported by an optional license exception that enables many Free/Libre and Open Source Software (“FLOSS”) applications to include the GPL-licensed MySQL client libraries despite the fact
that not all FLOSS licenses are compatible with the GPL. For details, see
http://www.mysql.com/products/licensing/foss-exception.html.
Because the MySQL software is released under the GPL, it may often be used for free,
but for certain uses you may want or need to buy commercial licenses from MySQL AB
at https://order.mysql.com/. See http://www.mysql.com/products/licensing/ for
more information.
Older versions of MySQL (3.22 and earlier) are subject to a stricter license
(http://www.mysql.com/products/licensing/mypl.html). See the documentation of
the specific version for information.
Please note that the use of the MySQL software under commercial license, GPL, or the old
MySQL license does not automatically give you the right to use MySQL AB (registered)
trademarks. See Section 1.4.4 [MySQL AB Logos and Trademarks], page 20.
1.4.3.1 Using the MySQL Software Under a Commercial License
The GPL license is contagious in the sense that when a program is linked to a GPL program,
all the source code for all the parts of the resulting product must also be released under the
GPL. If you do not follow this GPL requirement, you break the license terms and forfeit
your right to use the GPL program altogether. You also risk damages.
You need a commercial license under these conditions:
• When you link a program with any GPL code from the MySQL software and don’t
want the resulting product to be licensed under GPL, perhaps because you want to
build a commercial product or keep the added non-GPL code closed source for other
reasons. When purchasing commercial licenses, you are not using the MySQL software
under GPL even though it’s the same code.
• When you distribute a non-GPL application that works only with the MySQL software
and ship it with the MySQL software. This type of solution is considered to be linking
even if it’s done over a network.
• When you distribute copies of the MySQL software without providing the source code
as required under the GPL license.
• When you want to support the further development of the MySQL database even if you
don’t formally need a commercial license. Purchasing support directly from MySQL
AB is another good way of contributing to the development of the MySQL software,
with immediate advantages for you. See Section 1.4.1 [Support], page 16.
Our GPL licensing is supported by an optional license exception that enables many Free/Libre and Open Source Software (“FLOSS”) applications to include the GPL-licensed MySQL client libraries despite the fact
that not all FLOSS licenses are compatible with the GPL. For details, see
http://www.mysql.com/products/licensing/foss-exception.html.
If you require a commercial license, you will need one for each installation of the MySQL
software. This covers any number of CPUs on a machine, and there is no artificial limit on
the number of clients that connect to the server in any way.
Chapter 1: General Information
19
For commercial licenses, please visit our Web site at http://www.mysql.com/products/licensing/.
For support contracts, see http://www.mysql.com/support/. If you have special needs,
please contact our sales staff via email at sales@mysql.com.
1.4.3.2 Using the MySQL Software for Free Under GPL
You can use the MySQL software for free under the GPL if you adhere to the
conditions of the GPL. For additional details about the GPL, including answers
to common questions, see the generic FAQ from the Free Software Foundation at
http://www.fsf.org/licenses/gpl-faq.html.
Our GPL licensing is supported by an optional license exception that enables many Free/Libre and Open Source Software (“FLOSS”) applications to include the GPL-licensed MySQL client libraries despite the fact
that not all FLOSS licenses are compatible with the GPL. For details, see
http://www.mysql.com/products/licensing/foss-exception.html.
Common uses of the GPL include:
• When you distribute both your own application and the MySQL source code under the
GPL with your product.
• When you distribute the MySQL source code bundled with other programs that are
not linked to or dependent on the MySQL system for their functionality even if you sell
the distribution commercially. This is called “mere aggregation” in the GPL license.
• When you are not distributing any part of the MySQL system, you can use it for free.
• When you are an Internet Service Provider (ISP), offering Web hosting with MySQL
servers for your customers. We encourage people to use ISPs that have MySQL support,
because doing so will give them the confidence that their ISP will, in fact, have the
resources to solve any problems they may experience with the MySQL installation.
Even if an ISP does not have a commercial license for MySQL Server, their customers
should at least be given read access to the source of the MySQL installation so that
the customers can verify that it is correctly patched.
• When you use the MySQL database software in conjunction with a Web server, you
do not need a commercial license (so long as it is not a product you distribute). This
is true even if you run a commercial Web server that uses MySQL Server, because
you are not distributing any part of the MySQL system. However, in this case we
would like you to purchase MySQL support because the MySQL software is helping
your enterprise.
If your use of MySQL database software does not require a commercial license, we encourage
you to purchase support from MySQL AB anyway. This way you contribute toward MySQL
development and also gain immediate advantages for yourself. See Section 1.4.1 [Support],
page 16.
If you use the MySQL database software in a commercial context such that you profit by its
use, we ask that you further the development of the MySQL software by purchasing some
level of support. We feel that if the MySQL database helps your business, it is reasonable
to ask that you help MySQL AB. (Otherwise, if you ask us support questions, you are not
only using for free something into which we’ve put a lot a work, you’re asking us to provide
free support, too.)
20
MySQL Technical Reference for Version 5.0.1-alpha
1.4.4 MySQL AB Logos and Trademarks
Many users of the MySQL database want to display the MySQL AB dolphin logo on
their Web sites, books, or boxed products. We welcome and encourage this, although
it should be noted that the word MySQL and the MySQL dolphin logo are (registered)
trademarks of MySQL AB and may only be used as stated in our trademark policy at
http://www.mysql.com/company/trademark.html.
1.4.4.1 The Original MySQL Logo
The MySQL dolphin logo was designed by the Finnish advertising agency Priority in 2001.
The dolphin was chosen as a suitable symbol for the MySQL database management system,
which is like a smart, fast, and lean animal, effortlessly navigating oceans of data. We also
happen to like dolphins.
The original MySQL logo may only be used by representatives of MySQL AB and by those
having a written agreement allowing them to do so.
1.4.4.2 MySQL Logos That May Be Used Without Written
Permission
We have designed a set of special Conditional Use logos that may be downloaded from
our Web site at http://www.mysql.com/press/logos.html and used on third-party Web
sites without written permission from MySQL AB. The use of these logos is not entirely
unrestricted but, as the name implies, subject to our trademark policy that is also available
on our Web site. You should read through the trademark policy if you plan to use them.
The requirements are basically as follows:
• Use the logo you need as displayed on the http://www.mysql.com/ site. You may
scale it to fit your needs, but may not change colors or design, or alter the graphics in
any way.
• Make it evident that you, and not MySQL AB, are the creator and owner of the site
that displays the MySQL (registered) trademark.
• Don’t use the trademark in a way that is detrimental to MySQL AB or to the value of
MySQL AB trademarks. We reserve the right to revoke the right to use the MySQL
AB trademark.
• If you use the trademark on a Web site, make it clickable, leading directly to
http://www.mysql.com/.
• If you use the MySQL database under GPL in an application, your application must
be Open Source and must be able to connect to a MySQL server.
Contact us via email at trademark@mysql.com to inquire about special arrangements to fit
your needs.
1.4.4.3 When You Need Written Permission to Use MySQL Logos
You need written permission from MySQL AB before using MySQL logos in the following
cases:
Chapter 1: General Information
21
• When displaying any MySQL AB logo anywhere except on your Web site.
• When displaying any MySQL AB logo except the Conditional Use logos (mentioned
previously) on Web sites or elsewhere.
Due to legal and commercial reasons, we monitor the use of MySQL (registered) trademarks
on products, books, and other items. We usually require a fee for displaying MySQL AB
logos on commercial products, since we think it is reasonable that some of the revenue is
returned to fund further development of the MySQL database.
1.4.4.4 MySQL AB Partnership Logos
MySQL partnership logos may be used only by companies and persons having a written
partnership agreement with MySQL AB. Partnerships include certification as a MySQL
trainer or consultant. For more information, please see Section 1.3.1.5 [Partnering], page 15.
1.4.4.5 Using the Word MySQL in Printed Text or Presentations
MySQL AB welcomes references to the MySQL database, but it should be noted that
the word MySQL is a registered trademark of MySQL AB. Because of this, you must
append the “registered trademark” notice symbol (R) to the first or most prominent use
of the word MySQL in a text and, where appropriate, state that MySQL is a registered
trademark of MySQL AB. For more information, please refer to our trademark policy at
http://www.mysql.com/company/trademark.html.
1.4.4.6 Using the Word MySQL in Company and Product Names
Use of the word MySQL in company or product names or in Internet domain names is not allowed without written permission from MySQL AB.
http://www.mysql.com/company/contact/.
1.5 MySQL Development Roadmap
This section provides a snapshot of the MySQL development roadmap, including major
features implemented or planned for MySQL 4.0, 4.1, 5.0, and 5.1. The following sections
provide information for each release series.
The production release series is MySQL 4.0, which was declared stable for production use
as of Version 4.0.12, released in March 2003. This means that future 4.0 development is
limited only to bugfixes. For the older MySQL 3.23 series, only critical bugfixes are made.
4.1 is available in gamma status and will soon move to production stage.
Active MySQL development currently is taking place in the MySQL 5.0 release series, this
means that new features are being added there. MySQL 5.0 is available in alpha status.
Before upgrading from one release series to the next, please see the notes at Section 2.5
[Upgrade], page 133.
Plans for some of the most requested features are summarized in the following table.
Feature
MySQL Series
22
MySQL Technical Reference for Version 5.0.1-alpha
Unions
Subqueries
R-trees
Stored procedures
Views
Cursors
Foreign keys
Triggers
Full outer join
Constraints
4.0
4.1
4.1 (for MyISAM tables)
5.0
5.0
5.0
5.1 (already implemented in 3.23 for InnoDB)
5.0 and 5.1
5.1
5.1
1.5.1 MySQL 4.0 in a Nutshell
MySQL Server 4.0 is available in production status.
MySQL 4.0 is available for download at http://dev.mysql.com/ and from our mirrors.
MySQL 4.0 has been tested by a large number of users and is in production use at many
large sites.
The major new features of MySQL Server 4.0 are geared toward our existing business and
community users, enhancing the MySQL database software as the solution for missioncritical, heavy-load database systems. Other new features target the users of embedded
databases.
1.5.1.1 Features Available in MySQL 4.0
Speed enhancements
• MySQL 4.0 has a query cache that can give a huge speed boost to applications with repetitive queries. See Section 5.11 [Query Cache], page 379.
• Version 4.0 further increases the speed of MySQL Server in a number of
areas, such as bulk INSERT statements, searching on packed indexes, fulltext searching (using FULLTEXT indexes), and COUNT(DISTINCT).
Embedded MySQL Server introduced
• The new Embedded Server library can easily be used to create standalone
and embedded applications. The embedded server provides an alternative to using MySQL in a client/server environment. See Section 1.5.1.2
[Nutshell Embedded MySQL], page 23.
InnoDB storage engine as standard
• The InnoDB storage engine is offered as a standard feature of the MySQL
server. This means full support for ACID transactions, foreign keys with
cascading UPDATE and DELETE, and row-level locking are now standard
features. See Chapter 16 [InnoDB], page 804.
New functionality
• The enhanced FULLTEXT search properties of MySQL Server 4.0 enables
FULLTEXT indexing of large text masses with both binary and naturallanguage searching logic. You can customize minimal word length and
Chapter 1: General Information
23
define your own stop word lists in any human language, enabling a new set
of applications to be built with MySQL Server. See Section 13.6 [Fulltext
Search], page 635.
Standards compliance, portability, and migration
• Many users will also be happy to learn that MySQL Server now supports
the UNION statement, a long-awaited standard SQL feature.
• MySQL runs natively on the Novell NetWare platform beginning with NetWare 6.0. See Section 2.2.4 [NetWare installation], page 95.
• Features to simplify migration from other database systems to MySQL
Server include TRUNCATE TABLE (as in Oracle).
Internationalization
• Our German, Austrian, and Swiss users will note that MySQL 4.0 now
supports a new character set, latin1_de, which ensures that the German
sorting order sorts words with umlauts in the same order as do German
telephone books.
Usability enhancements
In the process of implementing features for new users, we have not forgotten
requests from our loyal community of existing users.
• Most mysqld parameters (startup options) can be set without taking
down the server. This is a convenient feature for database administrators
(DBAs). See Section 14.5.3.1 [SET OPTION], page 745.
• Multiple-table DELETE and UPDATE statements have been added.
• On Windows, symbolic link handling at the database level is enabled by
default. On Unix, the MyISAM storage engine supports symbolic linking at
the table level (and not just the database level as before).
• SQL_CALC_FOUND_ROWS and FOUND_ROWS() are new functions that make it
possible to find out the number of rows a SELECT query that includes a
LIMIT clause would have returned without that clause.
The news section of this manual includes a more in-depth list of features. See Section C.3
[News-4.0.x], page 1176.
1.5.1.2 The Embedded MySQL Server
The libmysqld embedded server library makes MySQL Server suitable for a vastly expanded
realm of applications. By using this library, developers can embed MySQL Server into
various applications and electronics devices, where the end user has no knowledge of there
actually being an underlying database. Embedded MySQL Server is ideal for use behind
the scenes in Internet appliances, public kiosks, turnkey hardware/software combination
units, high performance Internet servers, self-contained databases distributed on CD-ROM,
and so on.
Many users of libmysqld will benefit from the MySQL Dual Licensing. For those not
wishing to be bound by the GPL, the software is also made available under a commercial
license. The embedded MySQL library uses the same interface as the normal client library,
so it is convenient and easy to use. See Section 21.2.15 [libmysqld], page 1044.
24
MySQL Technical Reference for Version 5.0.1-alpha
On windows there are two different libraries:
libmysqld.lib
mysqldemb.lib
Dynamic library for threaded applications.
Static library for not threaded applications.
1.5.2 MySQL 4.1 in a Nutshell
MySQL Server 4.0 laid the foundation for new features implemented in MySQL 4.1, such
as subqueries and Unicode support, and for the work on stored procedures being done in
version 5.0. These features come at the top of the wish list of many of our customers.
Already well-known for its stability, speed, and ease of use, MySQL Server is now able to
fulfill the requirement checklists of very demanding buyers.
MySQL 4.1 is now available in gamma status, and will be production soon.
1.5.2.1 Features Available in MySQL 4.1
This section lists features implemented in MySQL 4.1.
New features currently being coded are or will be available in MySQL 5.0. See Section 1.6.1
[TODO MySQL 5.0], page 26.
Support for subqueries and derived tables
• A “subquery” is a SELECT statement nested within another statement. A
“derived table” (an unnamed view) is a subquery in the FROM clause of
another statement. See Section 14.1.8 [Subqueries], page 692.
Speed enhancements
• Faster binary client/server protocol with support for prepared statements
and parameter binding. See Section 21.2.4 [C API Prepared statements],
page 1002.
• BTREE indexing is supported for HEAP tables, significantly improving response time for non-exact searches.
New functionality
• CREATE TABLE tbl_name2 LIKE tbl_name1 allows you to create, with a
single statement, a new table with a structure exactly like that of an existing table.
• The MyISAM storage engine supports OpenGIS spatial types for storing geographical data. See Chapter 19 [Spatial extensions in MySQL], page 907.
• Replication can be done over SSL connections.
Standards compliance, portability, and migration
• The new client/server protocol adds the ability to pass multiple warnings
to the client, rather than only a single result. This makes it much easier
to track problems that occur in operations such as bulk data loading.
• SHOW WARNINGS shows warnings for the last command. See Section 14.5.3.21
[SHOW WARNINGS], page 763.
Chapter 1: General Information
25
Internationalization and Localization
• To support applications that require the use of local languages, the MySQL
software offers extensive Unicode support through the utf8 and ucs2 character sets.
• Character sets can be defined per column, table, and database. This allows
for a high degree of flexibility in application design, particularly for multilanguage Web sites.
• For documentation for this improved character set support, see Chapter 11
[Charset], page 539.
• Per-connection time zones are supported, allowing individual clients to
select their own time zone when necessary.
Usability enhancements
• In response to popular demand, we have added a server-based HELP command that can be used to get help information for SQL statements. The
advantage of having this information on the server side is that the information is always applicable to the particular server version that you
actually are using. Because this information is available by issuing an SQL
statement, any client can be written to access it. For example, the help
command of the mysql command-line client has been modified to have this
capability.
• In the new client/server protocol, multiple statements can be issued with
a single call. See Section 21.2.8 [C API multiple queries], page 1035.
• The new client/server protocol also supports returning multiple result sets.
This might occur as a result of sending multiple statements, for example.
• A new INSERT ... ON DUPLICATE KEY UPDATE ... syntax has been implemented. This allows you to UPDATE an existing row if the INSERT would
have caused a duplicate in a PRIMARY or UNIQUE index. See Section 14.1.4
[INSERT], page 669.
• A new aggregate function, GROUP_CONCAT() adds the extremely useful capability of concatenating column values from grouped rows into a single
result string. See Section 13.9 [Group by functions and modifiers], page 658.
The news section of this manual includes a more in-depth list of features. See Section C.2
[News-4.1.x], page 1152.
1.5.2.2 Stepwise Rollout
The gamma version of MySQL 4.1 is available for download. See Section 1.5.2.3 [Nutshell
Ready for Immediate Use], page 26.
MySQL 4.1 is currently in the Gamma stage (indicating that a production release is just
weeks ahead). At the end of this process, MySQL 4.1 will become the new production
release.
Development is already ongoing for version 5.0.
26
MySQL Technical Reference for Version 5.0.1-alpha
1.5.2.3 Ready for Immediate Development Use
MySQL 4.1 is currently in the gamma stage, and binaries are available for download at
http://dev.mysql.com/downloads/mysql/4.1.html. All binary releases pass our extensive test suite without any errors on the platforms on which we test. See Section C.2
[News-4.1.x], page 1152.
For those wishing to use the most recent development source for MySQL 4.1, we also make
our BitKeeper repositories publicly available. See Section 2.3.3 [Installing source tree],
page 106.
1.5.3 MySQL 5.0: The Next Development Release
New development for MySQL is focused on the 5.0 release, featuring stored procedures,
updatable views, rudimentary triggers, and other new features. See Section 1.6.1 [TODO
MySQL 5.0], page 26.
For those wishing to take a look at the bleeding edge of MySQL development, we make our
BitKeeper repository for MySQL version 5.0 publicly available. See Section 2.3.3 [Installing
source tree], page 106. As of December 2003, binary builds of version 5.0 have also been
available.
1.6 MySQL and the Future (the TODO)
This section summarizes the features that we plan to implement in MySQL Server. The
items are ordered by release series. Within a list, items are shown in approximately the
order they will be done.
Note: If you are an enterprise-level user with an urgent need for a particular feature, please
contact sales@mysql.com to discuss sponsoring options. Targeted financing by sponsor
companies allows us to allocate additional resources for specific purposes. One example of
a feature sponsored in the past is replication.
1.6.1 New Features Planned for 5.0
The following features are planned for inclusion into MySQL 5.0. Some of the features such
as stored procedures are complete and are included in MySQL 5.0 alpha, which is available
now. Others such as cursors are only partially available. Expect these and other features
to mature and be fully supported in upcoming releases.
Note that because we have many developers that are working on different projects, there
will also be many additional features. There is also a small chance that some of these
features will be added to MySQL 4.1. For a list what is already done in MySQL 4.1, see
Section 1.5.2.1 [Nutshell 4.1 features], page 24.
For those wishing to take a look at the bleeding edge of MySQL development, we make our
BitKeeper repository for MySQL version 5.0 publicly available. See Section 2.3.3 [Installing
source tree], page 106. As of December 2003, binary builds of version 5.0 are also available.
Views
Chapter 1: General Information
27
• Views, implemented in stepwise fashion up to full functionality. See Section 1.8.5.6 [ANSI diff Views], page 49. See Section 14.2.7 [CREATE
VIEW], page 722.
Stored Procedures
• Stored procedures currently are implemented, based on the SQL:2003 standard. See Chapter 20 [Stored Procedures], page 936.
New functionality
• Elementary cursor support. See Section 20.1.8 [Cursors], page 944.
• The ability to specify explicitly for MyISAM tables that an index should
be created as an RTREE index. (In MySQL 4.1, RTREE indexes are used
internally for geometrical data that use GIS data types, but cannot be
created on request.)
• Dynamic length rows for MEMORY tables.
Standards compliance, portability and migration
• Support for Data Dictionary / INFORMATION_SCHEMA.
• Add true VARCHAR support (column lengths longer than 255, and no stripping of trailing whitespace). There is already support for this in the MyISAM
storage engine, but it is not yet available at the user level.
Speed enhancements
• SHOW COLUMNS FROM tbl_name (used by the mysql client to allow expansions of column names) should not open the table, only the definition file.
This will require less memory and be much faster.
• Allow DELETE on MyISAM tables to use the record cache. To do this, we
need to update the threads record cache when we update the ‘.MYD’ file.
• Better support for MEMORY tables:
• Dynamic length rows.
• Faster row handling (less copying).
Usability enhancements
• Resolving the issue of RENAME TABLE on a table used in an active MERGE
table possibly corrupting the table.
The news section of this manual includes a more in-depth list of features. See Section C.1
[News-5.0.x], page 1145.
1.6.2 New Features Planned for 5.1
New functionality
• FOREIGN KEY support for all table types, not just InnoDB.
• Column-level constraints. See Section 1.8.6 [Constraints], page 50.
• Online backup with very low performance penalty. The online backup will
make it easy to add a new replication slave without taking down the master.
28
MySQL Technical Reference for Version 5.0.1-alpha
Speed enhancements
• New text based table definition file format (‘.frm’ files) and a table cache
for table definitions. This will enable us to do faster queries of table structures and do more efficient foreign key support.
• Optimize the BIT type to take one bit. (BIT now takes one byte; it is
treated as a synonym for TINYINT.)
Usability enhancements
• Add options to the client/server protocol to get progress notes for long
running commands.
• Implement RENAME DATABASE. To make this safe for all storage engines, it
should work as follows:
1. Create the new database.
2. For every table, do a rename of the table to another database, as we
do with the RENAME command.
3. Drop the old database.
• New internal file interface change. This will make all file handling much
more general and make it easier to add extensions like RAID.
1.6.3 New Features Planned for the Near Future
New functionality
• Oracle-like CONNECT BY PRIOR to search tree-like (hierarchical) structures.
• Add all missing standard SQL and ODBC 3.0 types.
• Add SUM(DISTINCT).
• INSERT SQL_CONCURRENT and mysqld --concurrent-insert to do a concurrent insert at the end of a table if the table is read-locked.
• Allow variables to be updated in UPDATE statements. For example: UPDATE
foo SET @a:=a+b,a=@a, b=@a+c.
• Change when user variables are updated so that you can use them with
GROUP BY, as in the following statement: SELECT id, @a:=COUNT(*),
SUM(sum_col )/@a FROM tbl_name GROUP BY id.
• Add an IMAGE option to LOAD DATA INFILE to not update TIMESTAMP and
AUTO_INCREMENT columns.
• Add LOAD DATA INFILE ... UPDATE syntax that works like this:
• For tables with primary keys, if an input record contains a primary key
value, existing rows matching that primary key value are updated from
the remainder of the input columns. However, columns corresponding
to columns that are missing from the input record are not touched.
• For tables with primary keys, if an input record does not contain the
primary key value or is missing some part of the key, the record is
treated as LOAD DATA INFILE ... REPLACE INTO.
• Make LOAD DATA INFILE understand syntax like this:
Chapter 1: General Information
•
•
•
•
•
•
•
29
LOAD DATA INFILE ’file_name.txt’ INTO TABLE tbl_name
TEXT_FIELDS (text_col1, text_col2, text_col3)
SET table_col1=CONCAT(text_col1, text_col2),
table_col3=23
IGNORE text_col3
This can be used to skip over extra columns in the text file, or update
columns based on expressions of the read data.
New functions for working with SET type columns:
• ADD_TO_SET(value,set )
• REMOVE_FROM_SET(value,set )
If you abort mysql in the middle of a query, you should open another
connection and kill the old running query. Alternatively, an attempt should
be made to detect this in the server.
Add a storage engine interface for table information so that you can use it
as a system table. This would be a bit slow if you requested information
about all tables, but very flexible. SHOW INFO FROM tbl_name for basic
table information should be implemented.
Allow SELECT a FROM tbl_name1 LEFT JOIN tbl_name2 USING (a); in
this case a is assumed to come from tbl name1.
DELETE and REPLACE options to the UPDATE statement (this will delete rows
when a duplicate-key error occurs while updating).
Change the format of DATETIME to store fractions of seconds.
Make it possible to use the new GNU regexp library instead of the current
one (the new library should be much faster than the current one).
Standards compliance, portability and migration
• Add ANY(), EVERY(), and SOME() group functions. In standard SQL, these
work only on boolean columns, but we can extend these to work on any
columns or expressions by treating a value of zero as FALSE and non-zero
values as TRUE.
• Fix the type of MAX(column) to be the same as the column type:
mysql> CREATE TABLE t1 (a DATE);
mysql> INSERT INTO t1 VALUES (NOW());
mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
mysql> SHOW COLUMNS FROM t2;
Speed enhancements
• Don’t allow more than a defined number of threads to run MyISAM recovery
at the same time.
• Change INSERT INTO ... SELECT to optionally use concurrent inserts.
• Add an option to periodically flush key pages for tables with delayed keys
if they haven’t been used in a while.
• Allow join on key parts (optimization issue).
• Add a log file analyzer that can extract information about which tables are
hit most often, how often multiple-table joins are executed, and so on. This
30
MySQL Technical Reference for Version 5.0.1-alpha
should help users identify areas of table design that could be optimized to
execute much more efficient queries.
Usability enhancements
• Return the original column types when doing SELECT MIN(column) ...
GROUP BY.
• Make it possible to specify long_query_time with a granularity in microseconds.
• Link the myisampack code into the server so that it can perform PACK or
COMPRESS operations.
• Add a temporary key buffer cache during INSERT/DELETE/UPDATE so that
we can gracefully recover if the index file gets full.
• If you perform an ALTER TABLE on a table that is symlinked to another
disk, create temporary tables on that disk.
• Implement a DATE/DATETIME type that handles time zone information properly, to make dealing with dates in different time zones easier.
• Fix configure so that all libraries (like MyISAM) can be compiled without
threads.
• Allow user variables as LIMIT arguments; for example, LIMIT @a,@b.
• Automatic output from mysql to a Web browser.
• LOCK DATABASES (with various options).
• Many more variables for SHOW STATUS. Record reads and updates. Selects
on a single table and selects with joins. Mean number of tables in selects.
Number of ORDER BY and GROUP BY queries.
• mysqladmin copy database new-database; this requires a COPY operation
to be added to mysqld.
• Processlist output should indicate the number of queries/threads.
• SHOW HOSTS for printing information about the hostname cache.
• Change table names from empty strings to NULL for calculated columns.
• Don’t use Item_copy_string on numerical values to avoid number-tostring-to-number conversion in case of SELECT COUNT(*)*(id+0) FROM
tbl_name GROUP BY id.
• Change so that ALTER TABLE doesn’t abort clients that execute INSERT
DELAYED.
• Fix so that when columns are referenced in an UPDATE clause, they contain
the old values from before the update started.
New operating systems
• Port the MySQL clients to LynxOS.
1.6.4 New Features Planned for the Mid-Term Future
• Implement function: get_changed_tables(timeout,table1,table2,...).
• Change reading through tables to use mmap() when possible. Now only compressed
tables use mmap().
Chapter 1: General Information
31
• Make the automatic timestamp code nicer. Add timestamps to the update log with
SET TIMESTAMP=val;.
• Use read/write mutex in some places to get more speed.
• Automatically close some tables if a table, temporary table, or temporary file gets error
23 (too many open files).
• Better constant propagation. When an occurrence of col name=n is found in an expression, for some constant n, replace other occurrences of col name within the expression
with n. Currently, this is done only for some simple cases.
• Change all const expressions with calculated expressions if possible.
• Optimize key = expr comparisons. At the moment, only key = column or key =
constant comparisons are optimized.
• Join some of the copy functions for nicer code.
• Change ‘sql_yacc.yy’ to an inline parser to reduce its size and get better error messages.
• Change the parser to use only one rule per different number of arguments in function.
• Use of full calculation names in the order part (for Access97).
• MINUS, INTERSECT, and FULL OUTER JOIN. (Currently UNION and LEFT|RIGHT OUTER
JOIN are supported.)
• Allow SQL_OPTION MAX_SELECT_TIME=val, for placing a time limit on a query.
• Allow updates to be logged to a database.
• Enhance LIMIT to allow retrieval of data from the end of a result set.
• Alarm around client connect/read/write functions.
• Please note the changes to mysqld_safe: According to FSSTND (which Debian tries
to follow), PID files should go into ‘/var/run/.pid’ and log files into
‘/var/log’. It would be nice if you could put the "DATADIR" in the first declaration of "pidfile" and "log" so that the placement of these files can be changed with
a single statement.
• Allow a client to request logging.
• Allow the LOAD DATA INFILE statement to read files that have been compressed with
gzip.
• Fix sorting and grouping of BLOB columns (partly solved now).
• Change to use semaphores when counting threads. One should first implement a
semaphore library for MIT-pthreads.
• Add full support for JOIN with parentheses.
• As an alternative to the one-thread-per-connection model, manage a pool of threads
to handle queries.
• Allow GET_LOCK() to obtain more than one lock. When doing this, it is also necessary
to handle the possible deadlocks this change will introduce.
1.6.5 New Features We Don’t Plan to Implement
We aim toward full compliance with ANSI/ISO SQL. There are no features we plan not to
implement.
32
MySQL Technical Reference for Version 5.0.1-alpha
1.7 MySQL Information Sources
1.7.1 MySQL Mailing Lists
This section introduces the MySQL mailing lists and provides guidelines as to how the lists
should be used. When you subscribe to a mailing list, you will receive all postings to the
list as email messages. You can also send your own questions and answers to the list.
1.7.1.1 The MySQL Mailing Lists
To subscribe to or unsubscribe from any of the mailing lists described in this section, visit
http://lists.mysql.com/. For most of them, you can select the regular version of the list
where you get individual messages, or a digest version where you get one large message per
day.
Please do not send messages about subscribing or unsubscribing to any of the mailing lists,
because such messages are distributed automatically to thousands of other users.
Your local site may have many subscribers to a MySQL mailing list. If so, the site may
have a local mailing list, so that messages sent from lists.mysql.com to your site are
propagated to the local list. In such cases, please contact your system administrator to be
added to or dropped from the local MySQL list.
If you wish to have traffic for a mailing list go to a separate mailbox in your mail program, set
up a filter based on the message headers. You can use either the List-ID: or DeliveredTo: headers to identify list messages.
The MySQL mailing lists are as follows:
announce
This list is for announcements of new versions of MySQL and related programs.
This is a low-volume list to which all MySQL users should subscribe.
mysql
This is the main list for general MySQL discussion. Please note that some
topics are better discussed on the more-specialized lists. If you post to the
wrong list, you may not get an answer.
bugs
This list will be of interest to you if you want to stay informed about issues
reported since the last release of MySQL or if you want to be actively involved
in the process of bug hunting and fixing. See Section 1.7.1.3 [Bug reports],
page 34.
internals
This list is for people who work on the MySQL code. This is also the forum for
discussions on MySQL development and for posting patches.
mysqldoc
This list is for people who work on the MySQL documentation: people from
MySQL AB, translators, and other community members.
benchmarks
This list is for anyone interested in performance issues. Discussions concentrate
on database performance (not limited to MySQL), but also include broader
categories such as performance of the kernel, filesystem, disk system, and so
on.
Chapter 1: General Information
33
packagers
This list is for discussions on packaging and distributing MySQL. This is the
forum used by distribution maintainers to exchange ideas on packaging MySQL
and on ensuring that MySQL looks and feels as similar as possible on all supported platforms and operating systems.
java
This list is for discussions about the MySQL server and Java. It is mostly used
to discuss JDBC drivers, including MySQL Connector/J.
win32
This list is for all topics concerning the MySQL software on Microsoft operating
systems, such as Windows 9x, Me, NT, 2000, and XP.
myodbc
This list is for all topics concerning connecting to the MySQL server with
ODBC.
gui-tools
This list is for all topics concerning MySQL GUI tools, including MySQL
Administrator and the MySQL Control Center graphical client.
cluster
This list is for discussion of MySQL Cluster.
dotnet
This list is for discussion of the MySQL server and the .NET platform. Mostly
related to the MySQL Connector/Net provider.
plusplus
This list is for all topics concerning programming with the C++ API for MySQL.
perl
This list is for all topics concerning the Perl support for MySQL with
DBD::mysql.
If you’re unable to get an answer to your questions from a MySQL mailing list, one option
is to purchase support from MySQL AB. This will put you in direct contact with MySQL
developers. See Section 1.4.1 [Support], page 16.
The following table shows some MySQL mailing lists in languages other than English. These
lists are not operated by MySQL AB.
mysql-france-subscribe@yahoogroups.com
A French mailing list.
list@tinc.net
A Korean mailing list. Email subscribe mysql your@email.address to this
list.
mysql-de-request@lists.4t2.com
A German mailing list. Email subscribe mysql-de your@email.address
to this list.
You can find information about this mailing list at
http://www.4t2.com/mysql/.
mysql-br-request@listas.linkway.com.br
A Portuguese mailing list. Email subscribe mysql-br your@email.address
to this list.
mysql-alta@elistas.net
A Spanish mailing list. Email subscribe mysql your@email.address to this
list.
34
MySQL Technical Reference for Version 5.0.1-alpha
1.7.1.2 Asking Questions or Reporting Bugs
Before posting a bug report or question, please do the following:
• Start by searching the MySQL online manual at http://dev.mysql.com/doc/. We try
to keep the manual up to date by updating it frequently with solutions to newly found
problems. The change history (http://dev.mysql.com/doc/mysql/en/News.html)
can be particularly useful since it is quite possible that a newer version already contains
a solution to your problem.
• Search in the bugs database at http://bugs.mysql.com/ to see whether the bug has
already been reported and fixed.
• Search the MySQL mailing list archives at http://lists.mysql.com/.
• You can also use http://www.mysql.com/search/ to search all the Web pages (including the manual) that are located at the MySQL AB Web site.
If you can’t find an answer in the manual or the archives, check with your local MySQL
expert. If you still can’t find an answer to your question, please follow the guidelines on
sending mail to a MySQL mailing list, outlined in the next section, before contacting us.
1.7.1.3 How to Report Bugs or Problems
The normal place to report bugs is http://bugs.mysql.com/, which is the address for our
bugs database. This database is public, and can be browsed and searched by anyone. If
you log in to the system, you will also be able to enter new reports.
Writing a good bug report takes patience, but doing it right the first time saves time both
for us and for yourself. A good bug report, containing a full test case for the bug, makes
it very likely that we will fix the bug in the next release. This section will help you write
your report correctly so that you don’t waste your time doing things that may not help us
much or at all.
We encourage everyone to use the mysqlbug script to generate a bug report (or a report
about any problem). mysqlbug can be found in the ‘scripts’ directory (source distribution)
and in the ‘bin’ directory under your MySQL installation directory (binary distribution).
If you are unable to use mysqlbug (for example, if you are running on Windows), it is still
vital that you include all the necessary information noted in this section (most importantly,
a description of the operating system and the MySQL version).
The mysqlbug script helps you generate a report by determining much of the following
information automatically, but if something important is missing, please include it with
your message. Please read this section carefully and make sure that all the information
described here is included in your report.
Preferably, you should test the problem using the latest production or development version
of MySQL Server before posting. Anyone should be able to repeat the bug by just using
mysql test < script_file on the included test case or by running the shell or Perl script
that is included in the bug report.
All bugs posted in the bugs database at http://bugs.mysql.com/ will be corrected or
documented in the next MySQL release. If only minor code changes are needed to correct
a problem, we may also post a patch that fixes the problem.
Chapter 1: General Information
35
If you have found a sensitive security bug in MySQL, you can send email to
security@mysql.com.
If you have a repeatable bug report, please report it to the bugs database at
http://bugs.mysql.com/. Note that even in this case it’s good to run the mysqlbug
script first to find information about your system. Any bug that we are able to repeat has
a high chance of being fixed in the next MySQL release.
To report other problems, you can use one of the MySQL mailing lists.
Remember that it is possible for us to respond to a message containing too much information, but not to one containing too little. People often omit facts because they think they
know the cause of a problem and assume that some details don’t matter. A good principle is
this: If you are in doubt about stating something, state it. It is faster and less troublesome
to write a couple more lines in your report than to wait longer for the answer if we must
ask you to provide information that was missing from the initial report.
The most common errors made in bug reports are (a) not including the version number of the
MySQL distribution used, and (b) not fully describing the platform on which the MySQL
server is installed (including the platform type and version number). This is highly relevant
information, and in 99 cases out of 100, the bug report is useless without it. Very often we
get questions like, “Why doesn’t this work for me?” Then we find that the feature requested
wasn’t implemented in that MySQL version, or that a bug described in a report has already
been fixed in newer MySQL versions. Sometimes the error is platform-dependent; in such
cases, it is next to impossible for us to fix anything without knowing the operating system
and the version number of the platform.
If you compiled MySQL from source, remember also to provide information about your
compiler, if it is related to the problem. Often people find bugs in compilers and think the
problem is MySQL-related. Most compilers are under development all the time and become
better version by version. To determine whether your problem depends on your compiler,
we need to know what compiler you use. Note that every compiling problem should be
regarded as a bug and reported accordingly.
It is most helpful when a good description of the problem is included in the bug report.
That is, give a good example of everything you did that led to the problem and describe,
in exact detail, the problem itself. The best reports are those that include a full example
showing how to reproduce the bug or problem. See Section D.1.6 [Reproduceable test case],
page 1333.
If a program produces an error message, it is very important to include the message in your
report. If we try to search for something from the archives using programs, it is better that
the error message reported exactly matches the one that the program produces. (Even the
lettercase should be observed.) You should never try to reproduce from memory what the
error message was; instead, copy and paste the entire message into your report.
If you have a problem with Connector/ODBC (MyODBC), please try to generate a trace
file and send it with your report. See Section 21.3.7 [MyODBC bug report], page 1054.
Please remember that many of the people who will read your report will do so using an
80-column display. When generating reports or examples using the mysql command-line
tool, you should therefore use the --vertical option (or the \G statement terminator) for
output that would exceed the available width for such a display (for example, with the
EXPLAIN SELECT statement; see the example later in this section).
36
MySQL Technical Reference for Version 5.0.1-alpha
Please include the following information in your report:
• The version number of the MySQL distribution you are using (for example, MySQL
4.0.12). You can find out which version you are running by executing mysqladmin
version. The mysqladmin program can be found in the ‘bin’ directory under your
MySQL installation directory.
• The manufacturer and model of the machine on which you experience the problem.
• The operating system name and version. If you work with Windows, you can usually get
the name and version number by double-clicking your My Computer icon and pulling
down the “Help/About Windows” menu. For most Unix-like operating systems, you
can get this information by executing the command uname -a.
• Sometimes the amount of memory (real and virtual) is relevant. If in doubt, include
these values.
• If you are using a source distribution of the MySQL software, the name and version
number of the compiler used are needed. If you have a binary distribution, the distribution name is needed.
• If the problem occurs during compilation, include the exact error messages and also a
few lines of context around the offending code in the file where the error occurs.
• If mysqld died, you should also report the query that crashed mysqld. You can usually
find this out by running mysqld with query logging enabled, and then looking in the
log after mysqld crashes See Section D.1.5 [Using log files], page 1332.
• If a database table is related to the problem, include the output from mysqldump -no-data db_name tbl_name . This is very easy to do and is a powerful way to get
information about any table in a database. The information will help us create a
situation matching the one you have.
• For speed-related bugs or problems with SELECT statements, you should always include
the output of EXPLAIN SELECT ..., and at least the number of rows that the SELECT
statement produces. You should also include the output from SHOW CREATE TABLE tbl_
name for each involved table. The more information you give about your situation, the
more likely it is that someone can help you.
The following is an example of a very good bug report. It should be posted with the
mysqlbug script. The example uses the mysql command-line tool. Note the use of the
\G statement terminator for statements whose output width would otherwise exceed
that of an 80-column display device.
mysql> SHOW VARIABLES;
mysql> SHOW COLUMNS FROM ...\G
Source Exif Data:
File Type : PDF
File Type Extension : pdf
MIME Type : application/pdf
PDF Version : 1.5
Linearized : Yes
Encryption : Standard V2.3 (128-bit)
User Access : Extract
Page Count : 1406
XMP Toolkit : XMP toolkit 2.9.1-13, framework 1.6
About : uuid:b4fe7ece-398e-4f6b-aa7c-d624e28c7cea
Producer : dvipdfm 0.13.2c, Copyright © 1998, by Mark A. Wicks
Create Date : 2004:10:10 18:06:26+01:00
Creator Tool : TeX output 2004.10.10:1806
Modify Date : 2005:02:18 17:34:47+01:00
Metadata Date : 2005:02:18 17:34:47+01:00
Document ID : uuid:fd78f383-afa8-4002-8ddc-71d7e0ce54c7
Format : application/pdf
Creator : TeX output 2004.10.10:1806
EXIF Metadata provided by EXIF.tools