1070
MySQL Reference Manual Copyright c 1997-2003 MySQL AB

MySQL Reference Manualwin.dl4u.org/docs/mysql.pdf · 2004-08-26 · 1.5.1 MySQL 4.0 in a Nutshell..... 20 1.5.1.1 Features Available in MySQL 4.0..... 21 1.5.1.2 Embedded MySQL Server

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

  • MySQL Reference Manual

    Copyright c© 1997-2003 MySQL AB

  • i

    Table of Contents

    1 General Information . . . . . . . . . . . . . . . . . . . . . . . 11.1 About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    1.1.1 Conventions Used in This Manual . . . . . . . . . . . . . . . . 21.2 What Is MySQL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    1.2.1 History of MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2.2 The Main Features of MySQL . . . . . . . . . . . . . . . . . . . 51.2.3 How Stable Is MySQL? . . . . . . . . . . . . . . . . . . . . . . . . . 81.2.4 How Big Can MySQL Tables Be? . . . . . . . . . . . . . . . . 91.2.5 Year 2000 Compliance . . . . . . . . . . . . . . . . . . . . . . . . . 10

    1.3 What Is MySQL AB? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.3.1 The Business Model and Services of MySQL AB . . 12

    1.3.1.1 Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.3.1.2 Training and Certification . . . . . . . . . . . . . 131.3.1.3 Consulting . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.3.1.4 Commercial Licenses . . . . . . . . . . . . . . . . . . 131.3.1.5 Partnering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    1.3.2 Contact Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.4 MySQL Support and Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    1.4.1 Support Offered by MySQL AB. . . . . . . . . . . . . . . . . 151.4.2 Copyrights and Licenses Used by MySQL. . . . . . . . 161.4.3 MySQL Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    1.4.3.1 Using the MySQL Software Under aCommercial License . . . . . . . . . . . . . . . . . . . . . . . 17

    1.4.3.2 Using the MySQL Software for Free UnderGPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    1.4.4 MySQL AB Logos and Trademarks . . . . . . . . . . . . . 181.4.4.1 The Original MySQL Logo. . . . . . . . . . . . . 191.4.4.2 MySQL Logos that may be Used Without

    Written Permission . . . . . . . . . . . . . . . . . . . . . . . 191.4.4.3 When do you need a Written Permission to

    use MySQL Logos? . . . . . . . . . . . . . . . . . . . . . . . 191.4.4.4 MySQL AB Partnership Logos . . . . . . . . . 201.4.4.5 Using the word MySQL in Printed Text or

    Presentations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.4.4.6 Using the word MySQL in Company and

    Product Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.5 MySQL Development Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . 20

    1.5.1 MySQL 4.0 in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . 201.5.1.1 Features Available in MySQL 4.0 . . . . . . . 211.5.1.2 Embedded MySQL Server . . . . . . . . . . . . . 22

    1.5.2 MySQL 4.1 in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . 221.5.2.1 Features Available in MySQL 4.1 . . . . . . . 221.5.2.2 Stepwise Rollout . . . . . . . . . . . . . . . . . . . . . . 24

  • ii

    1.5.2.3 Ready for Immediate Development Use. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    1.5.3 MySQL 5.0, The Next Development Release . . . . . 241.6 MySQL Information Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    1.6.1 MySQL Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 251.6.1.1 The MySQL Mailing Lists . . . . . . . . . . . . . 251.6.1.2 Asking Questions or Reporting Bugs. . . . 271.6.1.3 How to Report Bugs or Problems . . . . . . 271.6.1.4 Guidelines for Answering Questions on the

    Mailing List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321.6.2 MySQL Community Support on IRC (Internet Relay

    Chat) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321.7 MySQL Standards Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    1.7.1 What Standards Does MySQL Follow? . . . . . . . . . . 331.7.2 Running MySQL in ANSI Mode . . . . . . . . . . . . . . . . 331.7.3 MySQL Extensions to the SQL-92 Standard . . . . . 341.7.4 MySQL Differences Compared to SQL-92 . . . . . . . . 37

    1.7.4.1 Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . 371.7.4.2 SELECT INTO TABLE . . . . . . . . . . . . . . . . . . . 381.7.4.3 Transactions and Atomic Operations . . . 381.7.4.4 Stored Procedures and Triggers . . . . . . . . 411.7.4.5 Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . 411.7.4.6 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421.7.4.7 ‘--’ as the Start of a Comment . . . . . . . . . 43

    1.7.5 How MySQL deals with constraints . . . . . . . . . . . . . 441.7.5.1 Constraint PRIMARY KEY / UNIQUE

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441.7.5.2 Constraint NOT NULL and DEFAULT values

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441.7.5.3 Constraint ENUM and SET . . . . . . . . . . . . . . 45

    1.7.6 Known Errors and Design Deficiencies in MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    1.7.6.1 Errors in 3.23 Fixed in a Later MySQLVersion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    1.7.6.2 Open Bugs / Design Deficiencies in MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    1.8 MySQL and the Future (The TODO) . . . . . . . . . . . . . . . . . . . . 501.8.1 New Features Planned For 4.1 . . . . . . . . . . . . . . . . . . 501.8.2 New Features Planned For 5.0 . . . . . . . . . . . . . . . . . . 511.8.3 New Features Planned For 5.1 . . . . . . . . . . . . . . . . . . 521.8.4 New Features Planned for the Near Future . . . . . . 521.8.5 New Features Planned for the Mid-Term Future . . 551.8.6 New Features We Don’t Plan to Do . . . . . . . . . . . . . 56

  • iii

    2 Installing MySQL . . . . . . . . . . . . . . . . . . . . . . . . . 572.1 Quick Standard Installation of MySQL. . . . . . . . . . . . . . . . . . . 57

    2.1.1 Installing MySQL on Windows . . . . . . . . . . . . . . . . . 572.1.1.1 Installing the Binaries . . . . . . . . . . . . . . . . . 582.1.1.2 Preparing the Windows MySQL

    Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582.1.1.3 Starting the Server for the First Time . . 60

    2.1.2 Installing MySQL on Linux . . . . . . . . . . . . . . . . . . . . . 602.1.3 Installing MySQL on Mac OS X . . . . . . . . . . . . . . . . 622.1.4 Installing MySQL on NetWare . . . . . . . . . . . . . . . . . . 65

    2.1.4.1 Installing the MySQL for NetWare Binaries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    2.2 General Installation Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662.2.1 How to Get MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 662.2.2 Verifying Package Integrity Using MD5 Checksums or

    GnuPG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662.2.3 Operating Systems Supported by MySQL . . . . . . . 692.2.4 Which MySQL Version to Use . . . . . . . . . . . . . . . . . . 712.2.5 Installation Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732.2.6 How and When Updates Are Released. . . . . . . . . . . 742.2.7 Release Philosophy - No Known Bugs in Releases

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752.2.8 MySQL Binaries Compiled by MySQL AB. . . . . . . 762.2.9 Installing a MySQL Binary Distribution . . . . . . . . . 81

    2.3 Installing a MySQL Source Distribution . . . . . . . . . . . . . . . . . . 842.3.1 Quick Installation Overview . . . . . . . . . . . . . . . . . . . . 842.3.2 Applying Patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872.3.3 Typical configure Options . . . . . . . . . . . . . . . . . . . . 872.3.4 Installing from the Development Source Tree. . . . . 902.3.5 Problems Compiling MySQL? . . . . . . . . . . . . . . . . . . 922.3.6 MIT-pthreads Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . 952.3.7 Windows Source Distribution . . . . . . . . . . . . . . . . . . . 97

    2.4 Post-installation Setup and Testing . . . . . . . . . . . . . . . . . . . . . . 972.4.1 Problems Running mysql_install_db . . . . . . . . . 1012.4.2 Problems Starting the MySQL Server . . . . . . . . . . 1032.4.3 Starting and Stopping MySQL Automatically . . . 104

    2.5 Upgrading/Downgrading MySQL . . . . . . . . . . . . . . . . . . . . . . . 1062.5.1 Upgrading From Version 4.0 to 4.1 . . . . . . . . . . . . . 1062.5.2 Upgrading From Version 3.23 to 4.0 . . . . . . . . . . . . 1092.5.3 Upgrading From Version 3.22 to 3.23 . . . . . . . . . . . 1122.5.4 Upgrading from Version 3.21 to 3.22 . . . . . . . . . . . 1142.5.5 Upgrading from Version 3.20 to 3.21 . . . . . . . . . . . 1142.5.6 Upgrading the Grant Tables . . . . . . . . . . . . . . . . . . . 1152.5.7 Upgrading to Another Architecture . . . . . . . . . . . . 1162.5.8 Upgrading MySQL under Windows . . . . . . . . . . . . 117

    2.6 Operating System Specific Notes . . . . . . . . . . . . . . . . . . . . . . . 1182.6.1 Windows Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

  • iv

    2.6.1.1 Starting MySQL on Windows 95, 98, or Me. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

    2.6.1.2 Starting MySQL on Windows NT, 2000, orXP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

    2.6.1.3 Running MySQL on Windows. . . . . . . . . 1202.6.1.4 Connecting to MySQL Remotely from

    Windows with SSH . . . . . . . . . . . . . . . . . . . . . . 1212.6.1.5 Distributing Data Across Different Disks on

    Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222.6.1.6 Compiling MySQL Clients on Windows

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222.6.1.7 MySQL for Windows Compared to Unix

    MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1232.6.2 Linux Notes (All Linux Versions) . . . . . . . . . . . . . . 125

    2.6.2.1 Linux Notes for Binary Distributions . . 1292.6.2.2 Linux x86 Notes . . . . . . . . . . . . . . . . . . . . . 1302.6.2.3 Linux SPARC Notes . . . . . . . . . . . . . . . . . 1312.6.2.4 Linux Alpha Notes . . . . . . . . . . . . . . . . . . . 1312.6.2.5 Linux PowerPC Notes . . . . . . . . . . . . . . . . 1322.6.2.6 Linux MIPS Notes . . . . . . . . . . . . . . . . . . . 1322.6.2.7 Linux IA-64 Notes . . . . . . . . . . . . . . . . . . . 132

    2.6.3 Solaris Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1322.6.3.1 Solaris 2.7/2.8 Notes . . . . . . . . . . . . . . . . . 1352.6.3.2 Solaris x86 Notes . . . . . . . . . . . . . . . . . . . . 136

    2.6.4 BSD Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1362.6.4.1 FreeBSD Notes . . . . . . . . . . . . . . . . . . . . . . 1362.6.4.2 NetBSD Notes . . . . . . . . . . . . . . . . . . . . . . . 1382.6.4.3 OpenBSD 2.5 Notes . . . . . . . . . . . . . . . . . . 1382.6.4.4 OpenBSD 2.8 Notes . . . . . . . . . . . . . . . . . . 1382.6.4.5 BSD/OS Version 2.x Notes . . . . . . . . . . . 1382.6.4.6 BSD/OS Version 3.x Notes . . . . . . . . . . . 1392.6.4.7 BSD/OS Version 4.x Notes . . . . . . . . . . . 139

    2.6.5 Mac OS X Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1402.6.5.1 Mac OS X 10.x . . . . . . . . . . . . . . . . . . . . . . 1402.6.5.2 Mac OS X Server 1.2 (Rhapsody) . . . . . 140

    2.6.6 Other Unix Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1402.6.6.1 HP-UX Notes for Binary Distributions

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1402.6.6.2 HP-UX Version 10.20 Notes. . . . . . . . . . . 1412.6.6.3 HP-UX Version 11.x Notes. . . . . . . . . . . . 1412.6.6.4 IBM-AIX notes . . . . . . . . . . . . . . . . . . . . . . 1432.6.6.5 SunOS 4 Notes . . . . . . . . . . . . . . . . . . . . . . 1442.6.6.6 Alpha-DEC-UNIX Notes (Tru64) . . . . . . 1452.6.6.7 Alpha-DEC-OSF/1 Notes . . . . . . . . . . . . . 1462.6.6.8 SGI Irix Notes . . . . . . . . . . . . . . . . . . . . . . . 1472.6.6.9 SCO Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 1482.6.6.10 SCO UnixWare Version 7.1.x Notes . . 150

    2.6.7 OS/2 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

  • v

    2.6.8 Novell NetWare Notes . . . . . . . . . . . . . . . . . . . . . . . . 1512.6.9 BeOS Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

    2.7 Perl Installation Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1512.7.1 Installing Perl on Unix . . . . . . . . . . . . . . . . . . . . . . . . 1522.7.2 Installing ActiveState Perl on Windows . . . . . . . . 1522.7.3 Problems Using the Perl DBI/DBD Interface . . . . . 153

    3 MySQL Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . 1563.1 Connecting to and Disconnecting from the Server . . . . . . . . 1563.2 Entering Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1573.3 Creating and Using a Database. . . . . . . . . . . . . . . . . . . . . . . . . 160

    3.3.1 Creating and Selecting a Database . . . . . . . . . . . . . 1613.3.2 Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623.3.3 Loading Data into a Table . . . . . . . . . . . . . . . . . . . . 1633.3.4 Retrieving Information from a Table . . . . . . . . . . . 164

    3.3.4.1 Selecting All Data . . . . . . . . . . . . . . . . . . . 1653.3.4.2 Selecting Particular Rows . . . . . . . . . . . . . 1653.3.4.3 Selecting Particular Columns . . . . . . . . . 1673.3.4.4 Sorting Rows . . . . . . . . . . . . . . . . . . . . . . . . 1683.3.4.5 Date Calculations . . . . . . . . . . . . . . . . . . . . 1693.3.4.6 Working with NULL Values . . . . . . . . . . . . 1723.3.4.7 Pattern Matching . . . . . . . . . . . . . . . . . . . . 1733.3.4.8 Counting Rows . . . . . . . . . . . . . . . . . . . . . . 1753.3.4.9 Using More Than one Table . . . . . . . . . . 178

    3.4 Getting Information About Databases and Tables . . . . . . . 1793.5 Using mysql in Batch Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1803.6 Examples of Common Queries . . . . . . . . . . . . . . . . . . . . . . . . . . 182

    3.6.1 The Maximum Value for a Column . . . . . . . . . . . . 1823.6.2 The Row Holding the Maximum of a Certain

    Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1833.6.3 Maximum of Column per Group . . . . . . . . . . . . . . . 1833.6.4 The Rows Holding the Group-wise Maximum of a

    Certain Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1843.6.5 Using User Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 1853.6.6 Using Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 1853.6.7 Searching on Two Keys . . . . . . . . . . . . . . . . . . . . . . . 1873.6.8 Calculating Visits Per Day . . . . . . . . . . . . . . . . . . . . 1873.6.9 Using AUTO_INCREMENT. . . . . . . . . . . . . . . . . . . . . . . . 188

    3.7 Queries from the Twin Project . . . . . . . . . . . . . . . . . . . . . . . . . 1893.7.1 Find All Non-distributed Twins. . . . . . . . . . . . . . . . 1903.7.2 Show a Table of Twin Pair Status . . . . . . . . . . . . . 192

    3.8 Using MySQL with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

  • vi

    4 Database Administration . . . . . . . . . . . . . . . . . 1944.1 Configuring MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

    4.1.1 mysqld Command-line Options . . . . . . . . . . . . . . . . 1944.1.2 ‘my.cnf’ Option Files . . . . . . . . . . . . . . . . . . . . . . . . . 2024.1.3 Running Multiple MySQL Servers on the Same

    Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2054.1.3.1 Running Multiple Servers on Windows

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2064.1.3.2 Running Multiple Servers on Unix . . . . . 2094.1.3.3 Using Client Programs in a Multiple-Server

    Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2104.2 General Security Issues and the MySQL Access Privilege

    System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2114.2.1 General Security Guidelines . . . . . . . . . . . . . . . . . . . 2114.2.2 How to Make MySQL Secure Against Crackers . . 2144.2.3 Startup Options for mysqld Concerning Security

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2154.2.4 Security issues with LOAD DATA LOCAL . . . . . . . . . . 2164.2.5 What the Privilege System Does . . . . . . . . . . . . . . . 2174.2.6 How the Privilege System Works . . . . . . . . . . . . . . . 2174.2.7 Privileges Provided by MySQL . . . . . . . . . . . . . . . . 2204.2.8 Connecting to the MySQL Server . . . . . . . . . . . . . . 2234.2.9 Access Control, Stage 1: Connection Verification

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2244.2.10 Access Control, Stage 2: Request Verification . . 2274.2.11 Password Hashing in MySQL 4.1 . . . . . . . . . . . . . 2294.2.12 Causes of Access denied Errors . . . . . . . . . . . . . . 233

    4.3 MySQL User Account Management . . . . . . . . . . . . . . . . . . . . . 2374.3.1 GRANT and REVOKE Syntax . . . . . . . . . . . . . . . . . . . . . 2384.3.2 MySQL User Names and Passwords . . . . . . . . . . . . 2424.3.3 When Privilege Changes Take Effect . . . . . . . . . . . 2434.3.4 Setting Up the Initial MySQL Privileges. . . . . . . . 2434.3.5 Adding New Users to MySQL . . . . . . . . . . . . . . . . . 2454.3.6 Deleting Users from MySQL . . . . . . . . . . . . . . . . . . . 2474.3.7 Limiting user resources . . . . . . . . . . . . . . . . . . . . . . . . 2484.3.8 Setting Up Passwords . . . . . . . . . . . . . . . . . . . . . . . . . 2494.3.9 Keeping Your Password Secure . . . . . . . . . . . . . . . . 2494.3.10 Using Secure Connections . . . . . . . . . . . . . . . . . . . . 250

    4.3.10.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2504.3.10.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . 2514.3.10.3 Setting Up SSL Certificates for MySQL

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2514.3.10.4 SSL GRANT Options . . . . . . . . . . . . . . . . . 2564.3.10.5 SSL Command-line Options . . . . . . . . . 257

    4.4 Disaster Prevention and Recovery . . . . . . . . . . . . . . . . . . . . . . 2584.4.1 Database Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2584.4.2 BACKUP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 2594.4.3 RESTORE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 260

  • vii

    4.4.4 CHECK TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 2604.4.5 REPAIR TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 2624.4.6 Using myisamchk for Table Maintenance and Crash

    Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2634.4.6.1 myisamchk Invocation Syntax . . . . . . . . . 2634.4.6.2 General Options for myisamchk . . . . . . . 2644.4.6.3 Check Options for myisamchk . . . . . . . . . 2654.4.6.4 Repair Options for myisamchk . . . . . . . . 2664.4.6.5 Other Options for myisamchk . . . . . . . . . 2684.4.6.6 myisamchk Memory Usage . . . . . . . . . . . . 2684.4.6.7 Using myisamchk for Crash Recovery . . 2694.4.6.8 How to Check Tables for Errors . . . . . . . 2704.4.6.9 How to Repair Tables . . . . . . . . . . . . . . . . 2704.4.6.10 Table Optimisation . . . . . . . . . . . . . . . . . 273

    4.4.7 Setting Up a Table Maintenance Regimen . . . . . . 2734.4.8 Getting Information About a Table . . . . . . . . . . . . 274

    4.5 Database Administration Language Reference . . . . . . . . . . . 2794.5.1 OPTIMIZE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . 2794.5.2 ANALYZE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 2804.5.3 FLUSH Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2804.5.4 RESET Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2814.5.5 PURGE MASTER LOGS Syntax . . . . . . . . . . . . . . . . . . . . 2824.5.6 KILL Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2824.5.7 SHOW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

    4.5.7.1 Retrieving information about Database,Tables, Columns, and Indexes . . . . . . . . . . . . . 283

    4.5.7.2 SHOW TABLE STATUS . . . . . . . . . . . . . . . . . . 2844.5.7.3 SHOW STATUS . . . . . . . . . . . . . . . . . . . . . . . . . 2854.5.7.4 SHOW VARIABLES . . . . . . . . . . . . . . . . . . . . . 2894.5.7.5 SHOW [BDB] LOGS . . . . . . . . . . . . . . . . . . . . . 2994.5.7.6 SHOW PROCESSLIST . . . . . . . . . . . . . . . . . . . 2994.5.7.7 SHOW GRANTS . . . . . . . . . . . . . . . . . . . . . . . . . 3014.5.7.8 SHOW CREATE TABLE . . . . . . . . . . . . . . . . . . 3014.5.7.9 SHOW WARNINGS | ERRORS . . . . . . . . . . . . . 3014.5.7.10 SHOW TABLE TYPES . . . . . . . . . . . . . . . . . . 3034.5.7.11 SHOW PRIVILEGES . . . . . . . . . . . . . . . . . . . 304

    4.6 MySQL Localisation and International Usage . . . . . . . . . . . . 3044.6.1 The Character Set Used for Data and Sorting . . . 304

    4.6.1.1 German character set . . . . . . . . . . . . . . . . 3054.6.2 Non-English Error Messages . . . . . . . . . . . . . . . . . . . 3054.6.3 Adding a New Character Set . . . . . . . . . . . . . . . . . . 3064.6.4 The Character Definition Arrays . . . . . . . . . . . . . . . 3074.6.5 String Collating Support . . . . . . . . . . . . . . . . . . . . . . 3084.6.6 Multi-byte Character Support . . . . . . . . . . . . . . . . . 3084.6.7 Problems With Character Sets . . . . . . . . . . . . . . . . . 308

    4.7 MySQL Server-Side Scripts and Utilities . . . . . . . . . . . . . . . . 3094.7.1 Overview of the Server-Side Scripts and Utilities

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

  • viii

    4.7.2 mysqld_safe, The Wrapper Around mysqld . . . . 3104.7.3 mysqld_multi, A Program for Managing Multiple

    MySQL Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3114.7.4 myisampack, The MySQL Compressed Read-only

    Table Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3154.7.5 mysqld-max, An Extended mysqld Server . . . . . . . 321

    4.8 MySQL Client-Side Scripts and Utilities . . . . . . . . . . . . . . . . 3234.8.1 Overview of the Client-Side Scripts and Utilities

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3234.8.2 mysql, The Command-line Tool. . . . . . . . . . . . . . . . 3244.8.3 mysqladmin, Administrating a MySQL Server . . 3324.8.4 mysqlbinlog, Executing the queries from a binary

    log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3344.8.5 Using mysqlcheck for Table Maintenance and Crash

    Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3354.8.6 mysqldump, Dumping Table Structure and Data

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3374.8.7 mysqlhotcopy, Copying MySQL Databases and

    Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3424.8.8 mysqlimport, Importing Data from Text Files . . 3434.8.9 mysqlshow, Showing Databases, Tables, and

    Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3454.8.10 mysql_config, Get compile options for compiling

    clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3464.8.11 perror, Explaining Error Codes . . . . . . . . . . . . . . 3474.8.12 How to Run SQL Commands from a Text File . . 347

    4.9 The MySQL Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3474.9.1 The Error Log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3484.9.2 The General Query Log . . . . . . . . . . . . . . . . . . . . . . . 3484.9.3 The Update Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3494.9.4 The Binary Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3494.9.5 The Slow Query Log . . . . . . . . . . . . . . . . . . . . . . . . . . 3524.9.6 Log File Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . 352

    4.10 Replication in MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3534.10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3534.10.2 Replication Implementation Overview . . . . . . . . . 3544.10.3 Replication Implementation Details . . . . . . . . . . . 3554.10.4 How to Set Up Replication . . . . . . . . . . . . . . . . . . . 3604.10.5 Replication Features and Known Problems . . . . 3644.10.6 Replication Startup Options . . . . . . . . . . . . . . . . . . 3664.10.7 SQL Statements for Controlling Master Servers

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3744.10.7.1 PURGE MASTER LOGS . . . . . . . . . . . . . . . . . 3744.10.7.2 RESET MASTER . . . . . . . . . . . . . . . . . . . . . . 3754.10.7.3 SET SQL_LOG_BIN . . . . . . . . . . . . . . . . . . . 3754.10.7.4 SHOW BINLOG EVENTS . . . . . . . . . . . . . . . . 3754.10.7.5 SHOW MASTER STATUS . . . . . . . . . . . . . . . . 3754.10.7.6 SHOW MASTER LOGS . . . . . . . . . . . . . . . . . . 375

  • ix

    4.10.7.7 SHOW SLAVE HOSTS . . . . . . . . . . . . . . . . . . 3754.10.8 SQL Statements for Controlling Slave Servers . . 375

    4.10.8.1 CHANGE MASTER TO . . . . . . . . . . . . . . . . . . 3764.10.8.2 LOAD DATA FROM MASTER . . . . . . . . . . . . . 3784.10.8.3 LOAD TABLE tbl_name FROM MASTER . . . 3794.10.8.4 MASTER_POS_WAIT() . . . . . . . . . . . . . . . . 3794.10.8.5 RESET SLAVE . . . . . . . . . . . . . . . . . . . . . . . . 3794.10.8.6 SET GLOBAL SQL_SLAVE_SKIP_COUNTER

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3794.10.8.7 SHOW SLAVE STATUS . . . . . . . . . . . . . . . . . 3804.10.8.8 START SLAVE . . . . . . . . . . . . . . . . . . . . . . . . 3834.10.8.9 STOP SLAVE . . . . . . . . . . . . . . . . . . . . . . . . . 384

    4.10.9 Replication FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3844.10.10 Troubleshooting Replication . . . . . . . . . . . . . . . . . 3894.10.11 Reporting Replication Bugs . . . . . . . . . . . . . . . . . 390

    5 MySQL Optimisation . . . . . . . . . . . . . . . . . . . . 3925.1 Optimisation Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392

    5.1.1 MySQL Design Limitations/Tradeoffs . . . . . . . . . . 3925.1.2 Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3935.1.3 What Have We Used MySQL For? . . . . . . . . . . . . . 3945.1.4 The MySQL Benchmark Suite . . . . . . . . . . . . . . . . . 3955.1.5 Using Your Own Benchmarks . . . . . . . . . . . . . . . . . . 396

    5.2 Optimising SELECTs and Other Queries . . . . . . . . . . . . . . . . . 3965.2.1 EXPLAIN Syntax (Get Information About a SELECT)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3975.2.2 Estimating Query Performance . . . . . . . . . . . . . . . . 4045.2.3 Speed of SELECT Queries . . . . . . . . . . . . . . . . . . . . . . 4045.2.4 How MySQL Optimises WHERE Clauses . . . . . . . . . 4055.2.5 How MySQL Optimises IS NULL . . . . . . . . . . . . . . . 4065.2.6 How MySQL Optimises DISTINCT. . . . . . . . . . . . . . 4075.2.7 How MySQL Optimises LEFT JOIN and RIGHT JOIN

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4075.2.8 How MySQL Optimises ORDER BY . . . . . . . . . . . . . . 4085.2.9 How MySQL Optimises LIMIT . . . . . . . . . . . . . . . . . 4105.2.10 Speed of INSERT Queries . . . . . . . . . . . . . . . . . . . . . 4105.2.11 Speed of UPDATE Queries . . . . . . . . . . . . . . . . . . . . . 4125.2.12 Speed of DELETE Queries . . . . . . . . . . . . . . . . . . . . . 4135.2.13 Other Optimisation Tips . . . . . . . . . . . . . . . . . . . . . 413

    5.3 Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4155.3.1 How MySQL Locks Tables . . . . . . . . . . . . . . . . . . . . 4165.3.2 Table Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . 416

    5.4 Optimising Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . 4185.4.1 Design Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4185.4.2 Get Your Data as Small as Possible . . . . . . . . . . . . 4185.4.3 How MySQL Uses Indexes . . . . . . . . . . . . . . . . . . . . 4195.4.4 Column Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4215.4.5 Multiple-Column Indexes . . . . . . . . . . . . . . . . . . . . . . 422

  • x

    5.4.6 Why So Many Open tables? . . . . . . . . . . . . . . . . . . . 4235.4.7 How MySQL Opens and Closes Tables . . . . . . . . . 4235.4.8 Drawbacks to Creating Large Numbers of Tables in

    the Same Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4245.5 Optimising the MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . 424

    5.5.1 System/Compile Time and Startup ParameterTuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424

    5.5.2 Tuning Server Parameters . . . . . . . . . . . . . . . . . . . . . 4255.5.3 How Compiling and Linking Affects the Speed of

    MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4275.5.4 How MySQL Uses Memory . . . . . . . . . . . . . . . . . . . . 4295.5.5 How MySQL uses DNS . . . . . . . . . . . . . . . . . . . . . . . 4305.5.6 SET Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430

    5.6 Disk Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4345.6.1 Using Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . 436

    5.6.1.1 Using Symbolic Links for Databases . . . 4365.6.1.2 Using Symbolic Links for Tables . . . . . . 436

    6 MySQL Language Reference . . . . . . . . . . . . . 4386.1 Language Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438

    6.1.1 Literals: How to Write Strings and Numbers . . . . 4386.1.1.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4386.1.1.2 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4406.1.1.3 Hexadecimal Values . . . . . . . . . . . . . . . . . . 4406.1.1.4 NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . 440

    6.1.2 Database, Table, Index, Column, and Alias Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441

    6.1.3 Case Sensitivity in Names . . . . . . . . . . . . . . . . . . . . . 4426.1.4 User Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4436.1.5 System Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4446.1.6 Comment Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4476.1.7 Is MySQL Picky About Reserved Words?. . . . . . . 448

    6.2 Column Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4506.2.1 Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4556.2.2 Date and Time Types . . . . . . . . . . . . . . . . . . . . . . . . . 457

    6.2.2.1 Y2K Issues and Date Types. . . . . . . . . . . 4586.2.2.2 The DATETIME, DATE, and TIMESTAMP Types

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4596.2.2.3 The TIME Type . . . . . . . . . . . . . . . . . . . . . . 4636.2.2.4 The YEAR Type . . . . . . . . . . . . . . . . . . . . . . 464

    6.2.3 String Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4646.2.3.1 The CHAR and VARCHAR Types . . . . . . . . . 4646.2.3.2 The BLOB and TEXT Types . . . . . . . . . . . . 4656.2.3.3 The ENUM Type . . . . . . . . . . . . . . . . . . . . . . 4666.2.3.4 The SET Type . . . . . . . . . . . . . . . . . . . . . . . 467

    6.2.4 Choosing the Right Type for a Column . . . . . . . . . 4686.2.5 Using Column Types from Other Database Engines

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469

  • xi

    6.2.6 Column Type Storage Requirements . . . . . . . . . . . 4696.3 Functions for Use in SELECT and WHERE Clauses . . . . . . . . . 471

    6.3.1 Non-Type-Specific Operators and Functions . . . . 4716.3.1.1 Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . 4716.3.1.2 Comparison Operators . . . . . . . . . . . . . . . 4726.3.1.3 Logical Operators . . . . . . . . . . . . . . . . . . . . 4756.3.1.4 Control Flow Functions . . . . . . . . . . . . . . . 477

    6.3.2 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4786.3.2.1 String Comparison Functions . . . . . . . . . 4866.3.2.2 Case-Sensitivity . . . . . . . . . . . . . . . . . . . . . . 488

    6.3.3 Numeric Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 4896.3.3.1 Arithmetic Operations . . . . . . . . . . . . . . . 4896.3.3.2 Mathematical Functions . . . . . . . . . . . . . . 490

    6.3.4 Date and Time Functions . . . . . . . . . . . . . . . . . . . . . 4966.3.5 Cast Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5096.3.6 Other Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511

    6.3.6.1 Bit Functions . . . . . . . . . . . . . . . . . . . . . . . . 5116.3.6.2 Miscellaneous Functions . . . . . . . . . . . . . . 512

    6.3.7 Functions and Modifiers for Use with GROUP BYClauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521

    6.3.7.1 GROUP BY Functions . . . . . . . . . . . . . . . . . . 5216.3.7.2 GROUP BY Modifiers . . . . . . . . . . . . . . . . . . . 5236.3.7.3 GROUP BY with Hidden Fields . . . . . . . . . . 526

    6.4 Data Manipulation: SELECT, INSERT, UPDATE, DELETE . . . . 5276.4.1 SELECT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527

    6.4.1.1 JOIN Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 5326.4.1.2 UNION Syntax . . . . . . . . . . . . . . . . . . . . . . . . 534

    6.4.2 HANDLER Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5346.4.3 INSERT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535

    6.4.3.1 INSERT ... SELECT Syntax . . . . . . . . . . . 5386.4.3.2 INSERT DELAYED Syntax . . . . . . . . . . . . . . 538

    6.4.4 UPDATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5406.4.5 DELETE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5416.4.6 TRUNCATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5436.4.7 REPLACE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5436.4.8 LOAD DATA INFILE Syntax . . . . . . . . . . . . . . . . . . . . . 5446.4.9 DO Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550

    6.5 Data Definition: CREATE, DROP, ALTER . . . . . . . . . . . . . . . . . . 5516.5.1 CREATE DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . 5516.5.2 DROP DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 5516.5.3 CREATE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 551

    6.5.3.1 Silent Column Specification Changes . . 5606.5.4 ALTER TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 5616.5.5 RENAME TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 5646.5.6 DROP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 5656.5.7 CREATE INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 5656.5.8 DROP INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 566

    6.6 Basic MySQL User Utility Commands . . . . . . . . . . . . . . . . . . 566

  • xii

    6.6.1 USE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5666.6.2 DESCRIBE Syntax (Get Information About Columns)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5676.7 MySQL Transactional and Locking Commands . . . . . . . . . . 567

    6.7.1 START TRANSACTION, COMMIT, and ROLLBACK Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567

    6.7.2 Statements That Cannot Be Rolled Back . . . . . . . 5686.7.3 Statements That Cause an Implicit Commit . . . . 5686.7.4 SAVEPOINT and ROLLBACK TO SAVEPOINT Syntax

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5686.7.5 LOCK TABLES and UNLOCK TABLES Syntax . . . . . . . 5696.7.6 SET TRANSACTION Syntax . . . . . . . . . . . . . . . . . . . . . . 571

    6.8 MySQL Full-text Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5716.8.1 Full-text Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . 5756.8.2 Fine-tuning MySQL Full-text Search . . . . . . . . . . . 5756.8.3 Full-text Search TODO . . . . . . . . . . . . . . . . . . . . . . . 576

    6.9 MySQL Query Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5766.9.1 How the Query Cache Operates . . . . . . . . . . . . . . . . 5776.9.2 Query Cache Configuration . . . . . . . . . . . . . . . . . . . . 5786.9.3 Query Cache Options in SELECT . . . . . . . . . . . . . . . 5796.9.4 Query Cache Status and Maintenance . . . . . . . . . . 579

    7 MySQL Table Types . . . . . . . . . . . . . . . . . . . . . 5817.1 MyISAM Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581

    7.1.1 Space Needed for Keys . . . . . . . . . . . . . . . . . . . . . . . . 5847.1.2 MyISAM Table Formats . . . . . . . . . . . . . . . . . . . . . . . . 584

    7.1.2.1 Static (Fixed-length) Table Characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585

    7.1.2.2 Dynamic Table Characteristics . . . . . . . . 5857.1.2.3 Compressed Table Characteristics . . . . . 586

    7.1.3 MyISAM Table Problems . . . . . . . . . . . . . . . . . . . . . . . 5867.1.3.1 Corrupted MyISAM Tables . . . . . . . . . . . . . 5877.1.3.2 Clients is using or hasn’t closed the table

    properly. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5877.2 MERGE Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588

    7.2.1 MERGE Table Problems . . . . . . . . . . . . . . . . . . . . . . . . 5907.3 ISAM Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5917.4 HEAP Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5917.5 InnoDB Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592

    7.5.1 InnoDB Tables Overview . . . . . . . . . . . . . . . . . . . . . . 5937.5.2 InnoDB in MySQL Version 3.23 . . . . . . . . . . . . . . . 5937.5.3 InnoDB Startup Options . . . . . . . . . . . . . . . . . . . . . . 5947.5.4 Creating InnoDB Tablespace . . . . . . . . . . . . . . . . . . 600

    7.5.4.1 If Something Goes Wrong in DatabaseCreation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601

    7.5.5 Creating InnoDB Tables . . . . . . . . . . . . . . . . . . . . . . 6017.5.5.1 Converting MyISAM Tables to InnoDB

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602

  • xiii

    7.5.5.2 FOREIGN KEY Constraints . . . . . . . . . . . . . 6027.5.6 Adding and Removing InnoDB Data and Log Files

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6057.5.7 Backing up and Recovering an InnoDB Database

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6057.5.7.1 Forcing recovery . . . . . . . . . . . . . . . . . . . . . 6067.5.7.2 Checkpoints . . . . . . . . . . . . . . . . . . . . . . . . . 607

    7.5.8 Moving an InnoDB Database to Another Machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608

    7.5.9 InnoDB Transaction Model and Locking . . . . . . . . 6087.5.9.1 InnoDB and SET ... TRANSACTION

    ISOLATION LEVEL ... . . . . . . . . . . . . . . . . . . . . 6097.5.9.2 Consistent Non-Locking Read . . . . . . . . . 6107.5.9.3 Locking Reads SELECT ... FOR UPDATE and

    SELECT ... LOCK IN SHARE MODE . . . . . . . . . . 6107.5.9.4 Next-key Locking: Avoiding the Phantom

    Problem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6117.5.9.5 Locks Set by Different SQL Statements in

    InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6127.5.9.6 Deadlock Detection and Rollback. . . . . . 6137.5.9.7 An Example of How the Consistent Read

    Works in InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . 6137.5.9.8 How to cope with deadlocks? . . . . . . . . . 614

    7.5.10 Performance Tuning Tips . . . . . . . . . . . . . . . . . . . . 6157.5.10.1 SHOW INNODB STATUS and the InnoDB

    Monitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6167.5.11 Implementation of Multi-versioning . . . . . . . . . . . 6187.5.12 Table and Index Structures . . . . . . . . . . . . . . . . . . . 619

    7.5.12.1 Physical Structure of an Index . . . . . . . 6207.5.12.2 Insert Buffering . . . . . . . . . . . . . . . . . . . . . 6207.5.12.3 Adaptive Hash Indexes . . . . . . . . . . . . . . 6207.5.12.4 Physical Record Structure . . . . . . . . . . . 6217.5.12.5 How an AUTO_INCREMENT Column Works

    in InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6217.5.13 File Space Management and Disk I/O . . . . . . . . . 622

    7.5.13.1 Disk I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . 6227.5.13.2 File Space Management . . . . . . . . . . . . . 6237.5.13.3 Defragmenting a Table . . . . . . . . . . . . . . 623

    7.5.14 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6247.5.15 Restrictions on InnoDB Tables . . . . . . . . . . . . . . . 6247.5.16 InnoDB Change History. . . . . . . . . . . . . . . . . . . . . . 625

    7.5.16.1 MySQL/InnoDB-4.0.14, July 22, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625

    7.5.16.2 MySQL/InnoDB-3.23.57, June 20, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626

    7.5.16.3 MySQL/InnoDB-4.0.13, May 20, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627

    7.5.16.4 MySQL/InnoDB-4.1.0, April 3, 2003 . . 628

  • xiv

    7.5.16.5 MySQL/InnoDB-3.23.56, March 17, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628

    7.5.16.6 MySQL/InnoDB-4.0.12, March 18, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628

    7.5.16.7 MySQL/InnoDB-4.0.11, February 25, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628

    7.5.16.8 MySQL/InnoDB-4.0.10, February 4, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629

    7.5.16.9 MySQL/InnoDB-3.23.55, January 24, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629

    7.5.16.10 MySQL/InnoDB-4.0.9, January 14, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630

    7.5.16.11 MySQL/InnoDB-4.0.8, January 7, 2003. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630

    7.5.16.12 MySQL/InnoDB-4.0.7, December 26,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    7.5.16.13 MySQL/InnoDB-4.0.6, December 19,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    7.5.16.14 MySQL/InnoDB-3.23.54, December 12,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    7.5.16.15 MySQL/InnoDB-4.0.5, November 18,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    7.5.16.16 MySQL/InnoDB-3.23.53, October 9, 2002. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632

    7.5.16.17 MySQL/InnoDB-4.0.4, October 2, 2002. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633

    7.5.16.18 MySQL/InnoDB-4.0.3, August 28, 2002. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634

    7.5.16.19 MySQL/InnoDB-3.23.52, August 16,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634

    7.5.16.20 MySQL/InnoDB-4.0.2, July 10, 2002. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636

    7.5.16.21 MySQL/InnoDB-3.23.51, June 12, 2002. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636

    7.5.16.22 MySQL/InnoDB-3.23.50, April 23, 2002. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636

    7.5.16.23 MySQL/InnoDB-3.23.49, February 17,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637

    7.5.16.24 MySQL/InnoDB-3.23.48, February 9,2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637

    7.5.16.25 MySQL/InnoDB-3.23.47, December 28,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638

    7.5.16.26 MySQL/InnoDB-4.0.1, December 23,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638

    7.5.16.27 MySQL/InnoDB-3.23.46, November 30,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639

    7.5.16.28 MySQL/InnoDB-3.23.45, November 23,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639

  • xv

    7.5.16.29 MySQL/InnoDB-3.23.44, November 2,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639

    7.5.16.30 MySQL/InnoDB-3.23.43, October 4, 2001. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

    7.5.16.31 MySQL/InnoDB-3.23.42, September 9,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

    7.5.16.32 MySQL/InnoDB-3.23.41, August 13,2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

    7.5.16.33 MySQL/InnoDB-3.23.40, July 16, 2001. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

    7.5.16.34 MySQL/InnoDB-3.23.39, June 13, 2001. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640

    7.5.16.35 MySQL/InnoDB-3.23.38, May 12, 2001. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641

    7.5.17 InnoDB Contact Information . . . . . . . . . . . . . . . . . . 6417.6 BDB or BerkeleyDB Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641

    7.6.1 Overview of BDB Tables . . . . . . . . . . . . . . . . . . . . . . . 6417.6.2 Installing BDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6427.6.3 BDB startup options . . . . . . . . . . . . . . . . . . . . . . . . . . . 6427.6.4 Characteristics of BDB tables: . . . . . . . . . . . . . . . . . . 6437.6.5 Things we need to fix for BDB in the near future:

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6447.6.6 Operating systems supported by BDB . . . . . . . . . . . 6447.6.7 Restrictions on BDB Tables . . . . . . . . . . . . . . . . . . . . 6457.6.8 Errors That May Occur When Using BDB Tables

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645

    8 Introduction to MaxDB . . . . . . . . . . . . . . . . . . 6468.1 History of MaxDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6468.2 Licensing and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6468.3 Basic Concepts of MaxDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6468.4 Feature Differences between MaxDB and MySQL . . . . . . . . 6468.5 Interoperability Features between MaxDB and MySQL . . . 6478.6 MaxDB-related Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6478.7 Reserved Words in MaxDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6488.8 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6508.9 Column Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650

  • xvi

    9 National Character Sets and Unicode . . . . . 6529.1 Character Sets and Collations in General. . . . . . . . . . . . . . . . 6529.2 Character Sets and Collations in MySQL . . . . . . . . . . . . . . . 6539.3 Determining the Default Character Set and Collation . . . . 653

    9.3.1 Server Character Set and Collation . . . . . . . . . . . . 6539.3.2 Database Character Set and Collation . . . . . . . . . . 6549.3.3 Table Character Set and Collation . . . . . . . . . . . . . 6549.3.4 Column Character Set and Collation . . . . . . . . . . . 6559.3.5 Examples of Character Set and Collation Assignment

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6559.3.6 Connection Character Sets and Collations . . . . . . 6579.3.7 Character String Literal Character Set and Collation

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6579.3.8 COLLATE Clause in Various Parts of an SQL Query

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6589.3.9 COLLATE Clause Precedence . . . . . . . . . . . . . . . . . . . 6599.3.10 BINARY Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6599.3.11 Some Special Cases Where the Collation

    Determination is Tricky . . . . . . . . . . . . . . . . . . . . . . . . . 6599.3.12 Collations Must Be for the Right Character Set

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6609.3.13 An example of the Effect of Collation . . . . . . . . . 660

    9.4 Operations Affected by Character Set Support . . . . . . . . . . 6619.4.1 Result Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6619.4.2 CONVERT() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6629.4.3 CAST() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6629.4.4 SHOW CHARACTER SET . . . . . . . . . . . . . . . . . . . . . . . . . . 6629.4.5 SHOW COLLATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6639.4.6 SHOW CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . 6639.4.7 SHOW FULL COLUMNS . . . . . . . . . . . . . . . . . . . . . . . . . . . 664

    9.5 Unicode Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6649.6 UTF8 for Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6659.7 Compatibility with Other DBMSs . . . . . . . . . . . . . . . . . . . . . . 6659.8 New Character Set Configuration File format . . . . . . . . . . . . 6669.9 National Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6669.10 Upgrading from MySQL 4.0. . . . . . . . . . . . . . . . . . . . . . . . . . . 666

    9.10.1 4.0 Character Sets and Corresponding 4.1Character Set/Collation Pairs. . . . . . . . . . . . . . . . . . . . 667

    9.11 The Character Sets and Collations that MySQL Supports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668

    9.11.1 The Unicode Character Sets . . . . . . . . . . . . . . . . . . 6699.11.2 Platform Specific Character Sets . . . . . . . . . . . . . . 6699.11.3 Character Sets for South Europe and Middle East

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6699.11.4 The Asian Character Sets . . . . . . . . . . . . . . . . . . . . 6699.11.5 The Baltic Character Sets . . . . . . . . . . . . . . . . . . . . 6709.11.6 The Cyrillic Character Sets. . . . . . . . . . . . . . . . . . . 6709.11.7 The Central European Character Sets . . . . . . . . . 671

  • xvii

    9.11.8 The West European Character Sets . . . . . . . . . . . 672

    10 Spatial Extensions in MySQL . . . . . . . . . . . 67410.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67410.2 The OpenGIS Geometry Model . . . . . . . . . . . . . . . . . . . . . . . 674

    10.2.1 The Geometry Class Hierarchy . . . . . . . . . . . . . . . 67510.2.2 Class Geometry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67610.2.3 Class Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67710.2.4 Class Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67710.2.5 Class LineString . . . . . . . . . . . . . . . . . . . . . . . . . . . 67810.2.6 Class Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67810.2.7 Class Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67810.2.8 Class GeometryCollection . . . . . . . . . . . . . . . . . . 67910.2.9 Class MultiPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . 67910.2.10 Class MultiCurve . . . . . . . . . . . . . . . . . . . . . . . . . . 67910.2.11 Class MultiLineString . . . . . . . . . . . . . . . . . . . . . 68010.2.12 Class MultiSurface . . . . . . . . . . . . . . . . . . . . . . . . 68010.2.13 Class MultiPolygon . . . . . . . . . . . . . . . . . . . . . . . . 680

    10.3 Supported Spatial Data Formats . . . . . . . . . . . . . . . . . . . . . . 68110.3.1 Well-Known Text (WKT) Format . . . . . . . . . . . . . 68110.3.2 Well-Known Binary (WKB) Format. . . . . . . . . . . 682

    10.4 Creating a Spatially Enabled MySQL Database. . . . . . . . . 68210.4.1 MySQL Spatial Datatypes . . . . . . . . . . . . . . . . . . . 68310.4.2 Creating Spatial Values . . . . . . . . . . . . . . . . . . . . . . 683

    10.4.2.1 Creating Geometry Values Using WKTFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683

    10.4.2.2 Creating Geometry Values Using WKBFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684

    10.4.2.3 Creating Geometry Values UsingMySQL-Specific Functions . . . . . . . . . . . . . . . . 685

    10.4.3 Creating Spatial Columns . . . . . . . . . . . . . . . . . . . . 68610.4.4 Populating Spatial Columns . . . . . . . . . . . . . . . . . . 68610.4.5 Fetching Spatial Data . . . . . . . . . . . . . . . . . . . . . . . . 688

    10.4.5.1 Fetching Spatial Data in Internal Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688

    10.4.5.2 Fetching Spatial Data in WKT Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688

    10.4.5.3 Fetching Spatial Data in WKB Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688

    10.5 Analysing Spatial Information . . . . . . . . . . . . . . . . . . . . . . . . . 68810.5.1 Functions to Convert Geometries Between Formats

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68910.5.2 Geometry Property Analysis Functions . . . . . . . . 689

    10.5.2.1 General Geometry Property AnalysisFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689

    10.5.2.2 Point Property Analysis Functions . . . 69110.5.2.3 LineString Property Analysis Functions

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691

  • xviii

    10.5.2.4 MultiLineString Property AnalysisFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693

    10.5.2.5 Polygon Property Analysis Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693

    10.5.2.6 MultiPolygon Property AnalysisFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694

    10.5.2.7 GeometryCollection Property AnalysisFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

    10.5.3 Functions That Create New Geometries FromExisting Ones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

    10.5.3.1 Geometry Functions That Produce NewGeometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

    10.5.3.2 Spatial Operators . . . . . . . . . . . . . . . . . . . 69610.5.4 Functions For Testing Spatial Relations Between

    Geometric Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69610.5.5 Relations On Geometry Minimal Bounding

    Rectangles (MBRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69610.5.6 Functions That Test Spatial Relationships Between

    Geometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69710.6 Optimising Spatial Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 698

    10.6.1 Creating Spatial Indexes . . . . . . . . . . . . . . . . . . . . . 69910.6.2 Using a Spatial Index . . . . . . . . . . . . . . . . . . . . . . . . 700

    10.7 MySQL Conformance and Compatibility . . . . . . . . . . . . . . . 70210.7.1 GIS Features That Are Not Yet Implemented . . 702

    11 MySQL APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . 70311.1 MySQL C API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703

    11.1.1 C API Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70311.1.2 C API Function Overview . . . . . . . . . . . . . . . . . . . . 70611.1.3 C API Function Descriptions . . . . . . . . . . . . . . . . . 710

    11.1.3.1 mysql_affected_rows() . . . . . . . . . . . . 71011.1.3.2 mysql_change_user() . . . . . . . . . . . . . . 71111.1.3.3 mysql_character_set_name(). . . . . . . 71211.1.3.4 mysql_close() . . . . . . . . . . . . . . . . . . . . . 71311.1.3.5 mysql_connect() . . . . . . . . . . . . . . . . . . . 71311.1.3.6 mysql_create_db() . . . . . . . . . . . . . . . . 71411.1.3.7 mysql_data_seek() . . . . . . . . . . . . . . . . 71511.1.3.8 mysql_debug() . . . . . . . . . . . . . . . . . . . . . 71511.1.3.9 mysql_drop_db() . . . . . . . . . . . . . . . . . . . 71611.1.3.10 mysql_dump_debug_info() . . . . . . . . . 71611.1.3.11 mysql_eof() . . . . . . . . . . . . . . . . . . . . . . 71711.1.3.12 mysql_errno() . . . . . . . . . . . . . . . . . . . . 71811.1.3.13 mysql_error() . . . . . . . . . . . . . . . . . . . . 71911.1.3.14 mysql_escape_string() . . . . . . . . . . . 71911.1.3.15 mysql_fetch_field() . . . . . . . . . . . . . 72011.1.3.16 mysql_fetch_fields() . . . . . . . . . . . . 72011.1.3.17 mysql_fetch_field_direct() . . . . . 72111.1.3.18 mysql_fetch_lengths() . . . . . . . . . . . 722

  • xix

    11.1.3.19 mysql_fetch_row() . . . . . . . . . . . . . . . 72311.1.3.20 mysql_field_count() . . . . . . . . . . . . . 72411.1.3.21 mysql_field_seek() . . . . . . . . . . . . . . 72511.1.3.22 mysql_field_tell() . . . . . . . . . . . . . . 72611.1.3.23 mysql_free_result() . . . . . . . . . . . . . 72611.1.3.24 mysql_get_client_info() . . . . . . . . . 72611.1.3.25 mysql_get_server_version() . . . . . 72711.1.3.26 mysql_get_host_info() . . . . . . . . . . . 72711.1.3.27 mysql_get_proto_info() . . . . . . . . . . 72811.1.3.28 mysql_get_server_info() . . . . . . . . . 72811.1.3.29 mysql_info() . . . . . . . . . . . . . . . . . . . . . 72811.1.3.30 mysql_init() . . . . . . . . . . . . . . . . . . . . . 72911.1.3.31 mysql_insert_id() . . . . . . . . . . . . . . . 72911.1.3.32 mysql_kill() . . . . . . . . . . . . . . . . . . . . . 73011.1.3.33 mysql_list_dbs() . . . . . . . . . . . . . . . . . 73111.1.3.34 mysql_list_fields() . . . . . . . . . . . . . 73111.1.3.35 mysql_list_processes() . . . . . . . . . . 73211.1.3.36 mysql_list_tables() . . . . . . . . . . . . . 73311.1.3.37 mysql_num_fields() . . . . . . . . . . . . . . 73311.1.3.38 mysql_num_rows() . . . . . . . . . . . . . . . . . 73511.1.3.39 mysql_options() . . . . . . . . . . . . . . . . . . 73511.1.3.40 mysql_ping() . . . . . . . . . . . . . . . . . . . . . 73711.1.3.41 mysql_query() . . . . . . . . . . . . . . . . . . . . 73811.1.3.42 mysql_real_connect() . . . . . . . . . . . . 73811.1.3.43 mysql_real_escape_string() . . . . . 74111.1.3.44 mysql_real_query() . . . . . . . . . . . . . . 74211.1.3.45 mysql_reload() . . . . . . . . . . . . . . . . . . . 74311.1.3.46 mysql_row_seek() . . . . . . . . . . . . . . . . . 74411.1.3.47 mysql_row_tell() . . . . . . . . . . . . . . . . . 74411.1.3.48 mysql_select_db() . . . . . . . . . . . . . . . 74411.1.3.49 mysql_sqlstate() . . . . . . . . . . . . . . . . . 74511.1.3.50 mysql_shutdown() . . . . . . . . . . . . . . . . . 74611.1.3.51 mysql_stat() . . . . . . . . . . . . . . . . . . . . . 74611.1.3.52 mysql_store_result() . . . . . . . . . . . . 74711.1.3.53 mysql_thread_id() . . . . . . . . . . . . . . . 74811.1.3.54 mysql_use_result() . . . . . . . . . . . . . . 74811.1.3.55 mysql_commit() . . . . . . . . . . . . . . . . . . . 74911.1.3.56 mysql_rollback() . . . . . . . . . . . . . . . . . 75011.1.3.57 mysql_autocommit() . . . . . . . . . . . . . . 75011.1.3.58 mysql_more_results() . . . . . . . . . . . . 75011.1.3.59 mysql_next_result() . . . . . . . . . . . . . 751

    11.1.4 C API Prepared Statements . . . . . . . . . . . . . . . . . . 75111.1.5 C API Prepared Statement Datatypes. . . . . . . . . 75211.1.6 C API Prepared Statement Function Overview

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75411.1.7 C API Prepared Statement Function Descriptions

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75611.1.7.1 mysql_prepare() . . . . . . . . . . . . . . . . . . . 757

  • xx

    11.1.7.2 mysql_param_count() . . . . . . . . . . . . . . 75811.1.7.3 mysql_get_metadata() . . . . . . . . . . . . . 75811.1.7.4 mysql_bind_param() . . . . . . . . . . . . . . . 75911.1.7.5 mysql_execute() . . . . . . . . . . . . . . . . . . . 76011.1.7.6 mysql_stmt_affected_rows(). . . . . . . 76411.1.7.7 mysql_bind_result() . . . . . . . . . . . . . . 76511.1.7.8 mysql_stmt_store_result() . . . . . . . . 76611.1.7.9 mysql_stmt_data_seek() . . . . . . . . . . . 76711.1.7.10 mysql_stmt_row_seek() . . . . . . . . . . . 76711.1.7.11 mysql_stmt_row_tell() . . . . . . . . . . . 76811.1.7.12 mysql_stmt_num_rows() . . . . . . . . . . . 76811.1.7.13 mysql_fetch() . . . . . . . . . . . . . . . . . . . . 76811.1.7.14 mysql_send_long_data() . . . . . . . . . . 77411.1.7.15 mysql_stmt_close() . . . . . . . . . . . . . . 77611.1.7.16 mysql_stmt_errno() . . . . . . . . . . . . . . 77611.1.7.17 mysql_stmt_error() . . . . . . . . . . . . . . 77711.1.7.18 mysql_stmt_sqlstate() . . . . . . . . . . . 777

    11.1.8 C API Handling of Multiple Query Execution . . 77811.1.9 C API Handling of Date and Time Values . . . . . 77911.1.10 C API Threaded Function Descriptions . . . . . . 780

    11.1.10.1 my_init() . . . . . . . . . . . . . . . . . . . . . . . . 78011.1.10.2 mysql_thread_init() . . . . . . . . . . . . . 78011.1.10.3 mysql_thread_end() . . . . . . . . . . . . . . 78111.1.10.4 mysql_thread_safe() . . . . . . . . . . . . . 781

    11.1.11 C API Embedded Server Function Descriptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781

    11.1.11.1 mysql_server_init() . . . . . . . . . . . . . 78111.1.11.2 mysql_server_end() . . . . . . . . . . . . . . 783

    11.1.12 Common questions and problems when using theC API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783

    11.1.12.1 Why Is It that After mysql_query()Returns Success, mysql_store_result()Sometimes Returns NULL? . . . . . . . . . . . . . . . . 783

    11.1.12.2 What Results Can I Get From a Query?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783

    11.1.12.3 How Can I Get the Unique ID for theLast Inserted Row? . . . . . . . . . . . . . . . . . . . . . . 784

    11.1.12.4 Problems Linking with the C API . . . 78411.1.13 Building Client Programs . . . . . . . . . . . . . . . . . . . 78511.1.14 How to Make a Threaded Client . . . . . . . . . . . . . 78511.1.15 libmysqld, the Embedded MySQL Server Library

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78711.1.15.1 Overview of the Embedded MySQL

    Server Library . . . . . . . . . . . . . . . . . . . . . . . . . . . 78711.1.15.2 Compiling Programs with libmysqld

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78711.1.15.3 Restrictions when using the Embedded

    MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 787

  • xxi

    11.1.15.4 Using Option Files with the EmbeddedServer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788

    11.1.15.5 Things left to do in Embedded Server(TODO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788

    11.1.15.6 A Simple Embedded Server Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788

    11.1.15.7 Licensing the Embedded Server . . . . . 79211.2 MySQL ODBC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 792

    11.2.1 How to Install MyODBC . . . . . . . . . . . . . . . . . . . . . 79211.2.2 How to Fill in the Various Fields in the ODBC

    Administrator Program . . . . . . . . . . . . . . . . . . . . . . . . . 79311.2.3 Connect parameters for MyODBC . . . . . . . . . . . . 79411.2.4 How to Report Problems with MyODBC . . . . . . 79511.2.5 Programs Known to Work with MyODBC . . . . . 79611.2.6 How to Get the Value of an AUTO_INCREMENT

    Column in ODBC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80011.2.7 Reporting Problems with MyODBC. . . . . . . . . . . 801

    11.3 MySQL Java Connectivity (JDBC) . . . . . . . . . . . . . . . . . . . . 80211.4 MySQL PHP API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802

    11.4.1 Common Problems with MySQL and PHP . . . . 80211.5 MySQL Perl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802

    11.5.1 DBI with DBD::mysql . . . . . . . . . . . . . . . . . . . . . . . . 80311.5.2 The DBI Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . 80311.5.3 More DBI/DBD Information . . . . . . . . . . . . . . . . . . . 809

    11.6 MySQL C++ API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80911.6.1 Borland C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809

    11.7 MySQL Python API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80911.8 MySQL Tcl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81011.9 MySQL Eiffel Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810

    12 Error Handling in MySQL . . . . . . . . . . . . . . 81112.1 Error Returns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811

    13 Extending MySQL . . . . . . . . . . . . . . . . . . . . . . 81813.1 MySQL Internals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818

    13.1.1 MySQL Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81813.1.2 MySQL Test Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . 818

    13.1.2.1 Running the MySQL Test Suite . . . . . . 81913.1.2.2 Extending the MySQL Test Suite . . . . 81913.1.2.3 Reporting Bugs in the MySQL Test Suite

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82013.2 Adding New Functions to MySQL . . . . . . . . . . . . . . . . . . . . . 821

    13.2.1 CREATE FUNCTION/DROP FUNCTION Syntax . . . . . 82113.2.2 Adding a New User-definable Function . . . . . . . . 822

    13.2.2.1 UDF Calling Sequences for simplefunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824

    13.2.2.2 UDF Calling Sequences for aggregatefunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825

  • xxii

    13.2.2.3 Argument Processing . . . . . . . . . . . . . . . . 82613.2.2.4 Return Values and Error Handling . . . 82713.2.2.5 Compiling and Installing User-definable

    Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82813.2.3 Adding a New Native Function . . . . . . . . . . . . . . . 829

    13.3 Adding New Procedures to MySQL . . . . . . . . . . . . . . . . . . . . 83113.3.1 Procedure Analyse . . . . . . . . . . . . . . . . . . . . . . . . . . . 83113.3.2 Writing a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . 831

    Appendix A Problems and Common Errors . . 832A.1 How to Determine What Is Causing Problems . . . . . . . . . . 832A.2 Common Errors When Using MySQL . . . . . . . . . . . . . . . . . . 833

    A.2.1 Access denied Error . . . . . . . . . . . . . . . . . . . . . . . . . 833A.2.2 MySQL server has gone away Error . . . . . . . . . . . . 833A.2.3 Can’t connect to [local] MySQL server Error

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 834A.2.4 Client does not support authentication

    protocol error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836A.2.5 Host ’...’ is blocked Error . . . . . . . . . . . . . . . . . 836A.2.6 Too many connections Error . . . . . . . . . . . . . . . . . 837A.2.7 Some non-transactional changed tables

    couldn’t be rolled back Error . . . . . . . . . . . . . . . . . 837A.2.8 Out of memory Error . . . . . . . . . . . . . . . . . . . . . . . . . 837A.2.9 Packet too large Error . . . . . . . . . . . . . . . . . . . . . . 838A.2.10 Communication Errors / Aborted Connection

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 838A.2.11 The table is full Error . . . . . . . . . . . . . . . . . . . . 839A.2.12 Can’t create/write to file Error . . . . . . . . . . 840A.2.13 Commands out of sync Error in Client . . . . . . . . 840A.2.14 Ignoring user Error . . . . . . . . . . . . . . . . . . . . . . . . 841A.2.15 Table ’xxx’ doesn’t exist Error . . . . . . . . . . . 841A.2.16 Can’t initialize character set xxx error . . 841A.2.17 File Not Found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842

    A.3 Installation Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843A.3.1 Problems When Linking with the MySQL Client

    Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843A.3.2 How to Run MySQL As a Normal User . . . . . . . . 843A.3.3 Problems with File Permissions . . . . . . . . . . . . . . . 844

    A.4 Administration Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . 845A.4.1 What To Do If MySQL Keeps Crashing . . . . . . . . 845A.4.2 How to Reset a Forgotten Root Password . . . . . . 847A.4.3 How MySQL Handles a Full Disk. . . . . . . . . . . . . . 848A.4.4 Where MySQL Stores Temporary Files . . . . . . . . 848A.4.5 How to Protect or Change the MySQL Socket File

    ‘/tmp/mysql.sock’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849A.4.6 Time Zone Problems . . . . . . . . . . . . . . . . . . . . . . . . . 850

    A.5 Query Related Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850A.5.1 Case-Sensitivity in Searches . . . . . . . . . . . . . . . . . . . 850

  • xxiii

    A.5.2 Problems Using DATE Columns . . . . . . . . . . . . . . . . 850A.5.3 Problems with NULL Values . . . . . . . . . . . . . . . . . . . 852A.5.4 Problems with alias . . . . . . . . . . . . . . . . . . . . . . . . . 853A.5.5 Deleting Rows from Related Tables . . . . . . . . . . . . 853A.5.6 Solving Problems with No Matching Rows . . . . . 853A.5.7 Problems with Floating-Point Comparison . . . . . 854

    A.6 Optimiser Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856A.6.1 How to avoid table scan,,, . . . . . . . . . . . . . . . . . . . . 856

    A.7 Table Definition Related Issues . . . . . . . . . . . . . . . . . . . . . . . . 857A.7.1 Problems with ALTER TABLE. . . . . . . . . . . . . . . . . . . 857A.7.2 How To Change the Order of Columns in a Table

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857A.7.3 TEMPORARY TABLE problems . . . . . . . . . . . . . 858

    Appendix B Contributed Programs . . . . . . . . . 859B.1 APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859B.2 Converters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 861B.3 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 862

    Appendix C Credits. . . . . . . . . . . . . . . . . . . . . . . . 864C.1 Developers at MySQL AB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864C.2 Contributors to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867C.3 Supporters to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873

    Appendix D MySQL Change History . . . . . . . . 874D.1 Changes in release 5.0.0 (Development) . . . . . . . . . . . . . . . . . 874D.2 Changes in release 4.1.x (Alpha) . . . . . . . . . . . . . . . . . . . . . . . 874

    D.2.1 Changes in release 4.1.1 (to be released soon) . . 875D.2.2 Changes in release 4.1.0 (03 Apr 2003: Alpha) . . 878

    D.3 Changes in release 4.0.x (Production) . . . . . . . . . . . . . . . . . . 880D.3.1 Changes in release 4.0.17 (not released yet) . . . . 881D.3.2 Changes in release 4.0.16 (17 Oct 2003) . . . . . . . . 881D.3.3 Changes in release 4.0.15 (03 Sep 2003) . . . . . . . . 883D.3.4 Changes in release 4.0.14 (18 Jul 2003) . . . . . . . . 887D.3.5 Changes in release 4.0.13 (16 May 2003) . . . . . . . 891D.3.6 Changes in release 4.0.12 (15 Mar 2003: Production)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 894D.3.7 Changes in release 4.0.11 (20 Feb 2003) . . . . . . . . 896D.3.8 Changes in release 4.0.10 (29 Jan 2003) . . . . . . . . 897D.3.9 Changes in release 4.0.9 (09 Jan 2003) . . . . . . . . . 898D.3.10 Changes in release 4.0.8 (07 Jan 2003) . . . . . . . . 898D.3.11 Changes in release 4.0.7 (20 Dec 2002) . . . . . . . . 899D.3.12 Changes in release 4.0.6 (14 Dec 2002: Gamma)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899D.3.13 Changes in release 4.0.5 (13 Nov 2002) . . . . . . . 901D.3.14 Changes in release 4.0.4 (29 Sep 2002) . . . . . . . . 903D.3.15 Changes in release 4.0.3 (26 Aug 2002: Beta) . . 905

  • xxiv

    D.3.16 Changes in release 4.0.2 (01 Jul 2002) . . . . . . . . 906D.3.17 Changes in release 4.0.1 (23 Dec 2001) . . . . . . . . 910D.3.18 Changes in release 4.0.0 (Oct 2001: Alpha). . . . 911

    D.4 Changes in release 3.23.x (Recent; still supported). . . . . . . 912D.4.1 Changes in release 3.23.59 (not released yet) . . . 913D.4.2 Changes in release 3.23.58 (11 Sep 2003) . . . . . . . 913D.4.3 Changes in release 3.23.57 (06 Jun 2003) . . . . . . . 914D.4.4 Changes in release 3.23.56 (13 Mar 2003) . . . . . . 915D.4.5 Changes in release 3.23.55 (23 Jan 2003) . . . . . . . 916D.4.6 Changes in release 3.23.54 (05 Dec 2002) . . . . . . . 917D.4.7 Changes in release 3.23.53 (09 Oct 2002) . . . . . . . 917D.4.8 Changes in release 3.23.52 (14 Aug 2002) . . . . . . 918D.4.9 Changes in release 3.23.51 (31 May 2002) . . . . . . 919D.4.10 Changes in release 3.23.50 (21 Apr 2002) . . . . . 920D.4.11 Changes in release 3.23.49 . . . . . . . . . . . . . . . . . . . 921D.4.12 Changes in release 3.23.48 (07 Feb 2002) . . . . . . 921D.4.13 Changes in release 3.23.47 (27 Dec 2001) . . . . . . 922D.4.14 Changes in release 3.23.46 (29 Nov 2001) . . . . . 922D.4.15 Changes in release 3.23.45 (22 Nov 2001) . . . . . 922D.4.16 Changes in release 3.23.44 (31 Oct 2001) . . . . . . 923D.4.17 Changes in release 3.23.43 (04 Oct 2001) . . . . . . 924D.4.18 Changes in release 3.23.42 (08 Sep 2001) . . . . . . 924D.4.19 Changes in release 3.23.41 (11 Aug 2001) . . . . . 925D.4.20 Changes in release 3.23.40 . . . . . . . . . . . . . . . . . . . 926D.4.21 Changes in release 3.23.39 (12 Jun 2001) . . . . . . 926D.4.22 Changes in release 3.23.38 (09 May 2001) . . . . . 927D.4.23 Changes in release 3.23.37 (17 Apr 2001) . . . . . 927D.4.24 Changes in release 3.23.36 (27 Mar 2001) . . . . . 928D.4.25 Changes in release 3.23.35 (15 Mar 2001) . . . . . 929D.4.26 Changes in release 3.23.34a . . . . . . . . . . . . . . . . . . 929D.4.27 Changes in release 3.23.34 (10 Mar 2001) . . . . . 929D.4.28 Changes in release 3.23.33 (09 Feb 2001) . . . . . . 930D.4.29 Changes in release 3.23.32 (22 Jan 2001:

    Production) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931D.4.30 Changes in release 3.23.31 (17 Jan 2001) . . . . . . 932D.4.31 Changes in release 3.23.30 (04 Jan 2001) . . . . . . 932D.4.32 Changes in release 3.23.29 (16 Dec 2000) . . . . . . 933D.4.33 Changes in release 3.23.28 (22 Nov 2000: Gamma)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935D.4.34 Changes in release 3.23.27 (24 Oct 2000) . . . . . . 936D.4.35 Changes in release 3.23.26 (18 Oct 2000) . . . . . . 937D.4.36 Changes in release 3.23.25 (29 Sep 2000) . . . . . . 938D.4.37 Changes in release 3.23.24 (08 Sep 2000) . . . . . . 939D.4.38 Changes in release 3.23.23 (01 Sep 2000) . . . . . . 939D.4.39 Changes in release 3.23.22 (31 Jul 2000) . . . . . . 940D.4.40 Changes in release 3.23.21 . . . . . . . . . . . . . . . . . . . 941D.4.41 Changes in release 3.23.20 . . . . . . . . . . . . . . . . . . . 941D.4.42 Changes in release 3.23.19 . . . . . . . . . . . . . . . . . . . 942

  • xxv

    D.4.43 Changes in release 3.23.18 . . . . . . . . . . . . . . . . . . . 942D.4.44 Changes in release 3.23.17 . . . . . . . . . . . . . . . . . . . 942D.4.45 Changes in release 3.23.16 . . . . . . . . . . . . . . . . . . . 943D.4.46 Changes in release 3.23.15 (May 2000: Beta) . . 944D.4.47 Changes in release 3.23.14 . . . . . . . . . . . . . . . . . . . 944D.4.48 Changes in release 3.23.13 . . . . . . . . . . . . . . . . . . . 945D.4.49 Changes in release 3.23.12 (07 Mar 2000) . . . . . 945D.4.50 Changes in release 3.23.11 . . . . . . . . . . . . . . . . . . . 946D.4.51 Changes in release 3.23.10 . . . . . . . . . . . . . . . . . . . 947D.4.52 Changes in release 3.23.9 . . . . . . . . . . . . . . . . . . . . 947D.4.53 Changes in release 3.23.8 (02 Jan 2000) . . . . . . . 948D.4.54 Changes in release 3.23.7 (10 Dec 1999) . . . . . . . 948D.4.55 Changes in release 3.23.6 . . . . . . . . . . . . . . . . . . . . 949D.4.56 Changes in release 3.23.5 (20 Oct 1999) . . . . . . . 950D.4.57 Changes in release 3.23.4 (28 Sep 1999) . . . . . . . 950D.4.58 Changes in release 3.23.3 . . . . . . . . . . . . . . . . . . . . 951D.4.59 Changes in release 3.23.2 (09 Aug 1999) . . . . . . 951D.4.60 Changes in release 3.23.1 . . . . . . . . . . . . . . . . . . . . 952D.4.61 Changes in release 3.23.0 (05 Aug 1999: Alpha)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952D.5 Changes in release 3.22.x (Old; discontinued) . . . . . . . . . . . 954

    D.5.1 Changes in release 3.22.35 . . . . . . . . . . . . . . . . . . . . 954D.5.2 Changes in release 3.22.34 . . . . . . . . . . . . . . . . . . . . 955D.5.3 Changes in release 3.22.33 . . . . . . . . . . . . . . . . . . . . 955D.5.4 Changes in release 3.22.32 (14 Feb 2000) . . . . . . . 955D.5.5 Changes in release 3.22.31 . . . . . . . . . . . . . . . . . . . . 955D.5.6 Changes in release 3.22.30 . . . . . . . . . . . . . . . . . . . . 955D.5.7 Changes in release 3.22.29 (02 Jan 2000) . . . . . . . 955D.5.8 Changes in release 3.22.28 (20 Oct 1999) . . . . . . . 956D.5.9 Changes in release 3.22.27 . . . . . . . . . . . . . . . . . . . . 956D.5.10 Changes in release 3.22.26 (16 Sep 1999) . . . . . . 956D.5.11 Changes in release 3.22.25 . . . . . . . . . . . . . . . . . . . 956D.5.12 Changes in release 3.22.24 (05 Jul 1999) . . . . . . 956D.5.13 Changes in release 3.22.23 (08 Jun 1999) . . . . . . 957D.5.14 Changes in release 3.22.22 (30 Apr 1999) . . . . . 957D.5.15 Changes in release 3.22.21 . . . . . . . . . . . . . . . . . . . 957D.5.16 Changes in release 3.22.20 (18 Mar 1999) . . . . . 958D.5.17 Changes in release 3.22.19 (Mar 1999: Production)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958D.5.18 Changes in release 3.22.18 . . . . . . . . . . . . . . . . . . . 958D.5.19 Changes in release 3.22.17 . . . . . . . . . . . . . . . . . . . 958D.5.20 Changes in release 3.22.16 (Feb 1999: Gamma)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958D.5.21 Changes in release 3.22.15 . . . . . . . . . . . . . . . . . . . 959D.5.22 Changes in release 3.22.14 . . . . . . . . . . . . . . . . . . . 959D.5.23 Changes in release 3.22.13 . . . . . . . . . . . . . . . . . . . 959D.5.24 Changes in release 3.22.12 . . . . . . . . . . . . . . . . . . . 960D.5.25 Changes in release 3.22.11 . . . . . . . . . . . . . . . . . . . 960

  • xxvi

    D.5.26 Changes in release 3.22.10 . . . . . . . . . . . . . . . . . . . 961D.5.27 Changes in release 3.22.9 . . . . . . . . . . . . . . . . . . . . 961D.5.28 Changes in release 3.22.8 . . . . . . . . . . . . . . . . . . . . 962D.5.29 Changes in release 3.22.7 (Sep 1998: Beta) . . . . 962D.5.30 Changes in release 3.22.6 . . . . . . . . . . . . . . . . . . . . 963D.5.31 Changes in release 3.22.5 . . . . . . . . . . . . . . . . . . . . 963D.5.32 Changes in release 3.22.4 . . . . . . . . . . . . . . . . . . . . 965D.5.33 Changes in release 3.22.3 . . . . . . . . . . . . . . . . . . . . 965D.5.34 Changes in release 3.22.2 . . . . . . . . . . . . . . . . . . . . 965D.5.35 Changes in release 3.22.1 (Jun 1998: Alpha) . . 966D.5.36 Changes in release 3.22.0 . . . . . . . . . . . . . . . . . . . . 967

    D.6 Changes in release 3.21.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968D.6.1 Changes in release 3.21.33 . . . . . . . . . . . . . . . . . . . . 968D.6.2 Changes in release 3.21.32 . . . . . . . . . . . . . . . . . . . . 968D.6.3 Changes in release 3.21.31 . . . . . . . . . . . . . . . . . . . . 969D.6.4 Changes in release 3.21.30 . . . . . . . . . . . . . . . . . . . . 969D.6.5 Changes in release 3.21.29 . . . . . . . . . . . . . . . . . . . . 969D.6.6 Changes in release 3.21.28 . . . . . . . . . . . . . . . . . . . . 970D.6.7 Changes in release 3.21.27 . . . . . . . . . . . . . . . . . . . . 970D.6.8 Changes in release 3.21.26 . . . . . . . . . . . . . . . . . . . . 970D.6.9 Changes in release 3.21.25 . . . . . . . . . . . . . . . . . . . . 971D.6.10 Changes in release 3.21.24 . . . . . . . . . . . . . . . . . . . 971D.6.11 Changes in release 3.21.23 . . . . . . . . . . . . . . . . . . . 971D.6.12 Changes in release 3.21.22 . . . . . . . . . . . . . . . . . . . 972D.6.13 Changes in release 3.21.21a . . . . . . . . . . . . . . . . . . 972D.6.14 Changes in release 3.21.21 . . . . . . . . . . . . . . . . . . . 972D.6.15 Changes in release 3.21.20 . . . . . . . . . . . . . . . . . . . 973D.6.16 Changes in release 3.21.19 . . . . . . . . . . . . . . . . . . . 973D.6.17 Changes in release 3.21.18 . . . . . . . . . . . . . . . . . . . 973D.6.18 Changes in release 3.21.17 . . . . . . . . . . . . . . . . . . . 973D.6.19 Changes in release 3.21.16 . . . . . . . . . . . . . . . . . . . 974D.6.20 Changes in release 3.21.15 . . . . . . . . . . . . . . . . . . . 974D.6.21 Changes in release 3.21.14b . . . . . . . . . . . . . . . . . . 975D.6.22 Changes in release 3.21.14a . . . . . . . . . . . . . . . . . . 975D.6.23 Changes in release 3.21.13 . . . . . . . . . . . . . . . . . . . 976D.6.24 Changes in release 3.21.12 . . . . . . . . . . . . . . . . . . . 976D.6.25 Changes in release 3.21.11 . . . . . . . . . . . . . . . . . . . 977D.6.26 Changes in release 3.21.10 . . . . . . . . . . . . . . . . . . . 977D.6.27 Changes in release 3.21.9 . . . . . . . . . . . . . . . . . . . . 977D.6.28 Changes in release 3.21.8 . . . . . . . . . . . . . . . . . . . . 978D.6.29 Changes in release 3.21.7 . . . . . . . . . . . . . . . . . . . . 978D.6.30 Changes in release 3.21.6 . . . . . . . . . . . . . . . . . . . . 978D.6.31 Changes in release 3.21.5 . . . . . . . . . . . . . . . . . . . . 979D.6.32 Changes in release 3.21.4 . . . . . . . . . . . . . . . . . . . . 979D.6.33 Changes in release 3.21.3 . . . . . . . . . . . . . . . . . . . . 979D.6.34 Changes in release 3.21.2 . . . . . . . . . . . . . . . . . . . . 980D.6.35 Changes in release 3.21.0 . . . . . . . . . . . . . . . . . . . . 981

    D.7 Changes in release 3.20.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 982

  • xxvii

    D.7.1 Changes in release 3.20.18 . . . . . . . . . . . . . . . . . . . . 982D.7.2 Changes in release 3.20.17 . . . . . . . . . . . . . . . . . . . . 982D.7.3 Changes in release 3.20.16 . . . . . . . . . . . . . . . . . . . . 983D.7.4 Changes in release 3.20.15 . . . . . . . . . . . . . . . . . . . . 983D.7.5 Changes in release 3.20.14 . . . . . . . . . . . . . . . . . . . . 984D.7.6 Changes in release 3.20.13 . . . . . . . . . . . . . . . . . . . . 984D.7.7 Changes in release 3.20.11 . . . . . . . . . . . . . . . . . . . . 985D.7.8 Changes in release 3.20.10 . . . . . . . . . . . . . . . . . . . . 985D.7.9 Changes in release 3.20.9 . . . . . . . . . . . . . . . . . . . . . 985D.7.10 Changes in release 3.20.8 . . . . . . . . . . . . . . . . . . . . 985D.7.11 Changes in release 3.20.7 . . . . . . . . . . . . . . . . . . . . 986D.7.12 Changes in release 3.20.6 . . . . . . . . . . . . . . . . . . . . 986D.7.13 Changes in release 3.20.3 . . . . . . . . . . . . . . . . . . . . 987D.7.14 Changes in release 3.20.0 . . . . . . . . . . . . . . . . . . . . 988

    D.8 Changes in release 3.19.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988D.8.1 Changes in release 3.19.5 . . . . . . . . . . . . . . . . . . . . . 988D.8.2 Changes in release 3.19.4 . . . . . . . . . . . . . . . . . . . . . 989D.8.3 Changes in release 3.19.3 . . . . . . . . . . . . . . . . . . . . . 989

    Appendix E Porting to Other Systems . . . . . . 990E.1 Debugging a MySQL server . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991

    E.1.1 Compiling MYSQL for Debugging . . . . . . . . . . . . . 991E.1.2 Creating Trace Files . . . . . . . . . . . . . . . . . . . . . . . . . . 992E.1.3 Debugging mysqld under gdb . . . . . . . . . . . . . . . . . 993E.1.4 Using a Stack Trace . . . . . . . . . . . . . . . . . . . . . . . . . . 994E.1.5 Using Log Files to Find Cause of Errors in mysqld

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 995E.1.6 Making a Test Case If You Experience Table

    Corruption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996E.2 Debugging a MySQL client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996E.3 The DBUG Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997E.4 Locking methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 998E.5 Comments about RTS threads . . . . . . . . . . . . . . . . . . . . . . . . . 999E.6 Differences between different thread packages . . . . . . . . . . 1001

    Appendix F Environment Variables . . . . . . . . 1003

    Appendix G MySQL Regular Expressions . . 1004

    Appendix H GNU General Public License . . 1007

    Appendix I GNU Lesser General Public License. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013

    SQL command, type and function index . . . . . 1022

    Concept Index . . . . . . . . . . .