+ All Categories
Home > Documents > MySQL - Manual

MySQL - Manual

Date post: 08-Dec-2016
Category:
Upload: hoangdiep
View: 227 times
Download: 8 times
Share this document with a friend
787
MySQL Reference Manual Copyright c 1997-2001 MySQL AB
Transcript
  • MySQL Reference Manual

    Copyright c 1997-2001 MySQL AB

  • i

    Table of Contents

    1 General Information About MySQL. . . . . . . . . 11.1 MySQL, MySQL AB, and Open Source . . . . . . . . . . . . . . . . . . . 2

    1.1.1 What Is MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.2 What Is MySQL AB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.1.3 About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.1.4 Conventions Used in This Manual . . . . . . . . . . . . . . . . 51.1.5 History of MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.1.6 The Main Features of MySQL . . . . . . . . . . . . . . . . . . . 61.1.7 How Stable Is MySQL? . . . . . . . . . . . . . . . . . . . . . . . . . 81.1.8 How Big Can MySQL Tables Be? . . . . . . . . . . . . . . . 111.1.9 Year 2000 Compliance . . . . . . . . . . . . . . . . . . . . . . . . . 11

    1.2 MySQL Information Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.2.1 Books About MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . 131.2.2 General SQL Information and Tutorials . . . . . . . . . 191.2.3 Useful MySQL-related Links . . . . . . . . . . . . . . . . . . . . 191.2.4 MySQL Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    1.2.4.1 The MySQL Mailing Lists . . . . . . . . . . . . . 291.2.4.2 Asking Questions or Reporting Bugs . . . . 311.2.4.3 How to Report Bugs or Problems . . . . . . 311.2.4.4 Guidelines for Answering Question on the

    Mailing List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361.3 MySQL Licensing and Support . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    1.3.1 MySQL Licensing Policy . . . . . . . . . . . . . . . . . . . . . . . 361.3.2 Copyrights Used by MySQL . . . . . . . . . . . . . . . . . . . . 37

    1.3.2.1 Copyright Changes . . . . . . . . . . . . . . . . . . . . 381.3.3 Example Licensing Situations . . . . . . . . . . . . . . . . . . . 38

    1.3.3.1 Selling Products that use MySQL . . . . . . 381.3.3.2 ISP MySQL Services . . . . . . . . . . . . . . . . . . 391.3.3.3 Running a Web Server Using MySQL . . . 39

    1.3.4 MySQL Licensing and Support Costs. . . . . . . . . . . . 391.3.4.1 Payment information . . . . . . . . . . . . . . . . . . 401.3.4.2 Contact Information. . . . . . . . . . . . . . . . . . . 41

    1.3.5 Types of Commercial Support . . . . . . . . . . . . . . . . . . 421.3.5.1 Basic E-mail Support . . . . . . . . . . . . . . . . . . 421.3.5.2 Extended E-mail Support . . . . . . . . . . . . . . 431.3.5.3 Login Support . . . . . . . . . . . . . . . . . . . . . . . . 431.3.5.4 Extended Login Support . . . . . . . . . . . . . . . 441.3.5.5 Telephone Support . . . . . . . . . . . . . . . . . . . . 441.3.5.6 Support for other table handlers. . . . . . . . 45

    1.4 How Standards-compatible Is MySQL? . . . . . . . . . . . . . . . . . . . 451.4.1 MySQL Extensions to ANSI SQL92 . . . . . . . . . . . . . 451.4.2 MySQL Differences Compared to ANSI SQL92 . . . 471.4.3 Running MySQL in ANSI Mode . . . . . . . . . . . . . . . . 48

  • ii

    1.4.4 Functionality Missing from MySQL . . . . . . . . . . . . . 481.4.4.1 Sub-selects . . . . . . . . . . . . . . . . . . . . . . . . . . . 481.4.4.2 SELECT INTO TABLE . . . . . . . . . . . . . . . . . . . 491.4.4.3 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . 491.4.4.4 Stored Procedures and Triggers . . . . . . . . 511.4.4.5 Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . 511.4.4.6 Why We Did Not Implement Foreign Keys

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521.4.4.7 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531.4.4.8 -- as the Start of a Comment . . . . . . . . . 53

    1.4.5 What Standards Does MySQL Follow? . . . . . . . . . . 541.4.6 How to Cope Without COMMIT/ROLLBACK . . . . . . . . 541.4.7 Known errors and design deficiencies in MySQL . . 55

    1.5 How MySQL Compares to Other Databases . . . . . . . . . . . . . . 591.5.1 How MySQL Compares to mSQL . . . . . . . . . . . . . . . . 59

    1.5.1.1 How to Convert mSQL Tools for MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

    1.5.1.2 How mSQL and MySQL Client/ServerCommunications Protocols Differ . . . . . . . . . . . 62

    1.5.1.3 How mSQL 2.0 SQL Syntax Differs fromMySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

    1.5.2 How MySQL Compares to PostgreSQL . . . . . . . . . . 651.5.2.1 MySQL and PostgreSQL development

    strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651.5.2.2 Featurewise Comparison of MySQL and

    PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661.5.2.3 Benchmarking MySQL and PostgreSQL

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691.6 MySQL and the future (The TODO) . . . . . . . . . . . . . . . . . . . . 72

    1.6.1 Things that should be in 4.0 . . . . . . . . . . . . . . . . . . . . 731.6.2 Things that must be done in the real near future

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741.6.3 Things that have to be done sometime . . . . . . . . . . 781.6.4 Some things we dont have any plans to do . . . . . . 79

    2 MySQL Installation . . . . . . . . . . . . . . . . . . . . . . . 802.1 Quick Standard Installation of MySQL . . . . . . . . . . . . . . . . . . . 80

    2.1.1 Installing MySQL on Linux . . . . . . . . . . . . . . . . . . . . . 802.1.2 Installing MySQL on Windows . . . . . . . . . . . . . . . . . 81

    2.2 General Installation Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 822.2.1 How to Get MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 822.2.2 Operating Systems Supported by MySQL . . . . . . . 852.2.3 Which MySQL Version to Use . . . . . . . . . . . . . . . . . . 872.2.4 Installation Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892.2.5 How and When Updates Are Released . . . . . . . . . . . 902.2.6 MySQL Binaries Compiled by MySQL AB . . . . . . . 90

    2.3 Installing a MySQL Source Distribution . . . . . . . . . . . . . . . . . . 922.3.1 Quick Installation Overview . . . . . . . . . . . . . . . . . . . . 93

  • iii

    2.3.2 Applying Patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952.3.3 Typical configure Options . . . . . . . . . . . . . . . . . . . . 952.3.4 Installing from the Development Source Tree. . . . . 982.3.5 Problems Compiling? . . . . . . . . . . . . . . . . . . . . . . . . . . 992.3.6 MIT-pthreads Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 101

    2.4 Post-installation Setup and Testing . . . . . . . . . . . . . . . . . . . . . 1022.4.1 Problems Running mysql_install_db . . . . . . . . . 1062.4.2 Problems Starting the MySQL Server . . . . . . . . . . 1072.4.3 Starting and Stopping MySQL Automatically . . . 109

    2.5 Upgrading/Downgrading MySQL . . . . . . . . . . . . . . . . . . . . . . . 1102.5.1 Upgrading From Version 3.23 to Version 4.0 . . . . 1112.5.2 Upgrading From Version 3.22 to Version 3.23 . . . 1112.5.3 Upgrading from Version 3.21 to Version 3.22 . . . . 1132.5.4 Upgrading from Version 3.20 to Version 3.21 . . . . 1132.5.5 Upgrading to Another Architecture . . . . . . . . . . . . 114

    2.6 Operating System Specific Notes . . . . . . . . . . . . . . . . . . . . . . . 1152.6.1 Linux Notes (All Linux Versions) . . . . . . . . . . . . . . 115

    2.6.1.1 Linux Notes for Binary Distributions . . 1192.6.1.2 Linux x86 Notes . . . . . . . . . . . . . . . . . . . . . 1202.6.1.3 Linux SPARC Notes . . . . . . . . . . . . . . . . . 1212.6.1.4 Linux Alpha Notes . . . . . . . . . . . . . . . . . . . 1212.6.1.5 Linux PowerPC Notes . . . . . . . . . . . . . . . . 1212.6.1.6 Linux MIPS Notes . . . . . . . . . . . . . . . . . . . 1222.6.1.7 Linux IA64 Notes . . . . . . . . . . . . . . . . . . . . 122

    2.6.2 Windows Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222.6.2.1 Starting MySQL on Windows 95 or

    Windows 98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1222.6.2.2 Starting MySQL on Windows NT or

    Windows 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . 1232.6.2.3 Running MySQL on Windows. . . . . . . . . 1242.6.2.4 Connecting to a Remote MySQL from

    Windows with SSH . . . . . . . . . . . . . . . . . . . . . . 1252.6.2.5 Splitting Data Across Different Disks on

    Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1262.6.2.6 Compiling MySQL Clients on Windows

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1262.6.2.7 MySQL-Windows Compared to Unix

    MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1272.6.3 Solaris Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

    2.6.3.1 Solaris 2.7/2.8 Notes . . . . . . . . . . . . . . . . . 1312.6.3.2 Solaris x86 Notes . . . . . . . . . . . . . . . . . . . . 132

    2.6.4 BSD Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1322.6.4.1 FreeBSD Notes . . . . . . . . . . . . . . . . . . . . . . 1332.6.4.2 NetBSD notes . . . . . . . . . . . . . . . . . . . . . . . 1342.6.4.3 OpenBSD Notes . . . . . . . . . . . . . . . . . . . . . 1342.6.4.4 OpenBSD 2.5 Notes . . . . . . . . . . . . . . . . . . 1342.6.4.5 OpenBSD 2.8 Notes . . . . . . . . . . . . . . . . . . 1342.6.4.6 BSD/OS Notes . . . . . . . . . . . . . . . . . . . . . . 134

  • iv

    2.6.4.7 BSD/OS Version 2.x Notes . . . . . . . . . . . 1342.6.4.8 BSD/OS Version 3.x Notes . . . . . . . . . . . 1352.6.4.9 BSD/OS Version 4.x Notes . . . . . . . . . . . 135

    2.6.5 Mac OS X Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1352.6.5.1 Mac OS X Public Beta . . . . . . . . . . . . . . . 1362.6.5.2 Mac OS X Server . . . . . . . . . . . . . . . . . . . . 136

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1362.6.6.2 HP-UX Version 10.20 Notes. . . . . . . . . . . 1372.6.6.3 HP-UX Version 11.x Notes. . . . . . . . . . . . 1372.6.6.4 IBM-AIX notes . . . . . . . . . . . . . . . . . . . . . . 1392.6.6.5 SunOS 4 Notes . . . . . . . . . . . . . . . . . . . . . . 1402.6.6.6 Alpha-DEC-UNIX Notes (Tru64) . . . . . . 1412.6.6.7 Alpha-DEC-OSF1 Notes . . . . . . . . . . . . . . 1422.6.6.8 SGI Irix Notes . . . . . . . . . . . . . . . . . . . . . . . 1432.6.6.9 SCO Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 1442.6.6.10 SCO Unixware Version 7.0 Notes . . . . . 146

    2.6.7 OS/2 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1462.6.8 BeOS Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1472.6.9 Novell Netware Notes . . . . . . . . . . . . . . . . . . . . . . . . . 147

    3 Introduction to MySQL: A MySQL Tutorial. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1483.1 Connecting to and Disconnecting from the Server . . . . . . . . 1483.2 Entering Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1493.3 Creating and Using a Database . . . . . . . . . . . . . . . . . . . . . . . . . 152

    3.3.1 Creating and Selecting a Database . . . . . . . . . . . . . 1533.3.2 Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1543.3.3 Loading Data into a Table . . . . . . . . . . . . . . . . . . . . 1553.3.4 Retrieving Information from a Table . . . . . . . . . . . 156

    3.3.4.1 Selecting All Data . . . . . . . . . . . . . . . . . . . 1563.3.4.2 Selecting Particular Rows . . . . . . . . . . . . . 1573.3.4.3 Selecting Particular Columns . . . . . . . . . 1583.3.4.4 Sorting Rows . . . . . . . . . . . . . . . . . . . . . . . . 1593.3.4.5 Date Calculations . . . . . . . . . . . . . . . . . . . . 1613.3.4.6 Working with NULL Values . . . . . . . . . . . . 1643.3.4.7 Pattern Matching . . . . . . . . . . . . . . . . . . . . 1643.3.4.8 Counting Rows . . . . . . . . . . . . . . . . . . . . . . 1673.3.4.9 Using More Than one Table . . . . . . . . . . 169

    3.4 Getting Information About Databases and Tables . . . . . . . 1703.5 Examples of Common Queries . . . . . . . . . . . . . . . . . . . . . . . . . . 171

    3.5.1 The Maximum Value for a Column . . . . . . . . . . . . 1723.5.2 The Row Holding the Maximum of a Certain

    Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1723.5.3 Maximum of Column per Group . . . . . . . . . . . . . . . 1733.5.4 The Rows Holding the Group-wise Maximum of a

    Certain Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

  • v

    3.5.5 Using user variables. . . . . . . . . . . . . . . . . . . . . . . . . . . 1743.5.6 Using Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 1753.5.7 Searching on Two Keys . . . . . . . . . . . . . . . . . . . . . . . 1763.5.8 Calculating visits per day . . . . . . . . . . . . . . . . . . . . . 177

    3.6 Using mysql in Batch Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1773.7 Queries from Twin Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

    3.7.1 Find all Non-distributed Twins . . . . . . . . . . . . . . . . 1793.7.2 Show a Table on Twin Pair Status . . . . . . . . . . . . . 181

    3.8 Using MySQL with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

    4 MySQL Database Administration . . . . . . . . . 1834.1 Configuring MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

    4.1.1 mysqld Command-line Options . . . . . . . . . . . . . . . . 1834.1.2 my.cnf Option Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 1874.1.3 Installing Many Servers on the Same Machine . . 1904.1.4 Running Multiple MySQL Servers on the Same

    Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1914.2 General Security Issues and the MySQL Access Privilege

    System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1924.2.1 General Security Guidelines . . . . . . . . . . . . . . . . . . . 1924.2.2 How to Make MySQL Secure Against Crackers . . 1954.2.3 Startup Options for mysqld Concerning Security

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1964.2.4 What the Privilege System Does . . . . . . . . . . . . . . . 1974.2.5 How the Privilege System Works . . . . . . . . . . . . . . . 1974.2.6 Privileges Provided by MySQL . . . . . . . . . . . . . . . . 2004.2.7 Connecting to the MySQL Server . . . . . . . . . . . . . . 2024.2.8 Access Control, Stage 1: Connection Verification

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2034.2.9 Access Control, Stage 2: Request Verification . . . 2064.2.10 Causes of Access denied Errors . . . . . . . . . . . . . . 208

    4.3 MySQL User Account Management . . . . . . . . . . . . . . . . . . . . . 2124.3.1 GRANT and REVOKE Syntax . . . . . . . . . . . . . . . . . . . . . 2124.3.2 MySQL User Names and Passwords . . . . . . . . . . . . 2154.3.3 When Privilege Changes Take Effect . . . . . . . . . . . 2164.3.4 Setting Up the Initial MySQL Privileges. . . . . . . . 2174.3.5 Adding New Users to MySQL . . . . . . . . . . . . . . . . . 2184.3.6 Setting Up Passwords . . . . . . . . . . . . . . . . . . . . . . . . . 2214.3.7 Keeping Your Password Secure . . . . . . . . . . . . . . . . 222

    4.4 Disaster Prevention and Recovery . . . . . . . . . . . . . . . . . . . . . . 2234.4.1 Database Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2234.4.2 BACKUP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 2244.4.3 RESTORE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 2244.4.4 CHECK TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 2254.4.5 REPAIR TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 2264.4.6 Using myisamchk for Table Maintenance and Crash

    Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2274.4.6.1 myisamchk Invocation Syntax . . . . . . . . . 227

  • vi

    4.4.6.2 General Options for myisamchk . . . . . . . 2284.4.6.3 Check Options for myisamchk . . . . . . . . . 2294.4.6.4 Repair Options for myisamchk . . . . . . . . 2304.4.6.5 Other Options for myisamchk . . . . . . . . . 2314.4.6.6 myisamchk Memory Usage . . . . . . . . . . . . 2324.4.6.7 Using myisamchk for Crash Recovery . . 2334.4.6.8 How to Check Tables for Errors . . . . . . . 2344.4.6.9 How to Repair Tables . . . . . . . . . . . . . . . . 2344.4.6.10 Table Optimization . . . . . . . . . . . . . . . . . 237

    4.4.7 Setting Up a Table Maintenance Regimen . . . . . . 2374.4.8 Getting Information About a Table . . . . . . . . . . . . 238

    4.5 Database Administration Language Reference . . . . . . . . . . . 2444.5.1 OPTIMIZE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . 2444.5.2 ANALYZE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 2444.5.3 FLUSH Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2454.5.4 KILL Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2464.5.5 SHOW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

    4.5.5.1 Retrieving information about Database,Tables, Columns, and Indexes . . . . . . . . . . . . . 247

    4.5.5.2 SHOW TABLE STATUS . . . . . . . . . . . . . . . . . . 2484.5.5.3 SHOW STATUS . . . . . . . . . . . . . . . . . . . . . . . . . 2484.5.5.4 SHOW VARIABLES . . . . . . . . . . . . . . . . . . . . . 2524.5.5.5 SHOW LOGS . . . . . . . . . . . . . . . . . . . . . . . . . . . 2614.5.5.6 SHOW PROCESSLIST . . . . . . . . . . . . . . . . . . . 2614.5.5.7 SHOW GRANTS . . . . . . . . . . . . . . . . . . . . . . . . . 2624.5.5.8 SHOW CREATE TABLE . . . . . . . . . . . . . . . . . . 262

    4.6 MySQL Localization and International Usage . . . . . . . . . . . 2624.6.1 The Character Set Used for Data and Sorting . . . 262

    4.6.1.1 German character set . . . . . . . . . . . . . . . . 2634.6.2 Non-English Error Messages . . . . . . . . . . . . . . . . . . . 2634.6.3 Adding a New Character Set . . . . . . . . . . . . . . . . . . 2644.6.4 The character definition arrays . . . . . . . . . . . . . . . . 2654.6.5 String Collating Support . . . . . . . . . . . . . . . . . . . . . . 2664.6.6 Multi-byte Character Support . . . . . . . . . . . . . . . . . 266

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2674.7.2 safe mysqld, the wrapper around mysqld . . . . . . . 2684.7.3 mysqld multi, program for managing multiple

    MySQL servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2704.7.4 myisampack, The MySQL Compressed Read-only

    Table Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2734.7.5 mysqld-max, An extended mysqld server . . . . . . . 279

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2814.8.2 The Command-line Tool . . . . . . . . . . . . . . . . . . . . . . 2824.8.3 mysqladmin, Administrating a MySQL Server . . 288

  • vii

    4.8.4 Using mysqlcheck for Table Maintenance and CrashRecovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

    4.8.5 mysqldump, Dumping Table Structure and Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

    4.8.6 mysqlhotcopy, Copying MySQL Databases andTables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

    4.8.7 mysqlimport, Importing Data from Text Files . . . 2964.8.8 Showing Databases, Tables, and Columns . . . . . . 2994.8.9 perror, Explaining Error Codes . . . . . . . . . . . . . . . . 2994.8.10 How to Run SQL Commands from a Text File . . 299

    4.9 The MySQL Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3004.9.1 The Error Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3004.9.2 The General Query Log . . . . . . . . . . . . . . . . . . . . . . . 3004.9.3 The Update Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3014.9.4 The Binary Update Log . . . . . . . . . . . . . . . . . . . . . . . 3014.9.5 The Slow Query Log . . . . . . . . . . . . . . . . . . . . . . . . . . 3034.9.6 Log File Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . 303

    4.10 Replication in MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3044.10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3044.10.2 Replication Implementation Overview . . . . . . . . . 3044.10.3 How To Set Up Replication . . . . . . . . . . . . . . . . . . 3054.10.4 Replication Features and Known Problems . . . . 3064.10.5 Replication Options in my.cnf . . . . . . . . . . . . . . . . 3084.10.6 SQL Commands Related to Replication . . . . . . . 3114.10.7 Replication FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3134.10.8 Troubleshooting Replication . . . . . . . . . . . . . . . . . . 316

    5 MySQL Optimization . . . . . . . . . . . . . . . . . . . . 3195.1 Optimization Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

    5.1.1 MySQL Design Limitations/Tradeoffs . . . . . . . . . . 3195.1.2 Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3205.1.3 What Have We Used MySQL For? . . . . . . . . . . . . . 3215.1.4 The MySQL Benchmark Suite . . . . . . . . . . . . . . . . . 3215.1.5 Using Your Own Benchmarks . . . . . . . . . . . . . . . . . . 323

    5.2 Optimizing SELECTs and Other Queries . . . . . . . . . . . . . . . . . 3235.2.1 EXPLAIN Syntax (Get Information About a SELECT)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3245.2.2 Estimating Query Performance . . . . . . . . . . . . . . . . 3295.2.3 Speed of SELECT Queries . . . . . . . . . . . . . . . . . . . . . . 3295.2.4 How MySQL Optimizes WHERE Clauses . . . . . . . . . 3305.2.5 How MySQL Optimizes DISTINCT . . . . . . . . . . . . . 3315.2.6 How MySQL Optimizes LEFT JOIN and RIGHT JOIN

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3325.2.7 How MySQL Optimizes LIMIT . . . . . . . . . . . . . . . . . 3325.2.8 Speed of INSERT Queries . . . . . . . . . . . . . . . . . . . . . . 3335.2.9 Speed of UPDATE Queries . . . . . . . . . . . . . . . . . . . . . . 3345.2.10 Speed of DELETE Queries . . . . . . . . . . . . . . . . . . . . . 3355.2.11 Other Optimization Tips . . . . . . . . . . . . . . . . . . . . . 335

  • viii

    5.3 Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3385.3.1 How MySQL Locks Tables . . . . . . . . . . . . . . . . . . . . 3385.3.2 Table Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . 338

    5.4 Optimizing Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . 3405.4.1 Design Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3405.4.2 Get Your Data as Small as Possible . . . . . . . . . . . . 3405.4.3 How MySQL Uses Indexes . . . . . . . . . . . . . . . . . . . . 3415.4.4 Column Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3435.4.5 Multiple-Column Indexes . . . . . . . . . . . . . . . . . . . . . . 3445.4.6 How MySQL Opens and Closes Tables . . . . . . . . . 3455.4.7 Drawbacks to Creating Large Numbers of Tables in

    the Same Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3465.4.8 Why So Many Open tables? . . . . . . . . . . . . . . . . . . . 346

    5.5 Optimizing the MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . 3465.5.1 System/Compile Time and Startup Parameter

    Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3465.5.2 Tuning Server Parameters . . . . . . . . . . . . . . . . . . . . . 3475.5.3 How Compiling and Linking Affects the Speed of

    MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3495.5.4 How MySQL Uses Memory . . . . . . . . . . . . . . . . . . . . 3505.5.5 How MySQL uses DNS . . . . . . . . . . . . . . . . . . . . . . . 3515.5.6 SET Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352

    5.6 Disk Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3545.6.1 Using Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . 355

    5.6.1.1 Using Symbolic Links for Databases . . . 3565.6.1.2 Using Symbolic Links for Tables . . . . . . 356

    6 MySQL Language Reference . . . . . . . . . . . . . 3586.1 Language Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358

    6.1.1 Literals: How to Write Strings and Numbers . . . . 3586.1.1.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3586.1.1.2 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3606.1.1.3 Hexadecimal Values . . . . . . . . . . . . . . . . . . 3606.1.1.4 NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . 360

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

    6.1.3 Case Sensitivity in Names . . . . . . . . . . . . . . . . . . . . . 3626.1.4 User Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3626.1.5 Comment Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3636.1.6 Is MySQL Picky About Reserved Words? . . . . . . . 364

    6.2 Column Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3656.2.1 Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3706.2.2 Date and Time Types . . . . . . . . . . . . . . . . . . . . . . . . . 372

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3736.2.2.3 The TIME Type . . . . . . . . . . . . . . . . . . . . . . 3766.2.2.4 The YEAR Type . . . . . . . . . . . . . . . . . . . . . . 377

  • ix

    6.2.3 String Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3786.2.3.1 The CHAR and VARCHAR Types . . . . . . . . . 3786.2.3.2 The BLOB and TEXT Types . . . . . . . . . . . . 3796.2.3.3 The ENUM Type . . . . . . . . . . . . . . . . . . . . . . 3806.2.3.4 The SET Type . . . . . . . . . . . . . . . . . . . . . . . 381

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3826.2.6 Column Type Storage Requirements . . . . . . . . . . . 383

    6.3 Functions for Use in SELECT and WHERE Clauses . . . . . . . . . 3846.3.1 Non-Type-Specific Operators and Functions . . . . 385

    6.3.1.1 Parenthesis . . . . . . . . . . . . . . . . . . . . . . . . . . 3856.3.1.2 Comparison Operators . . . . . . . . . . . . . . . 3856.3.1.3 Logical Operators . . . . . . . . . . . . . . . . . . . . 3886.3.1.4 Control Flow Functions . . . . . . . . . . . . . . . 389

    6.3.2 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3906.3.2.1 String Comparison Functions . . . . . . . . . 3976.3.2.2 Case Sensitivity . . . . . . . . . . . . . . . . . . . . . . 399

    6.3.3 Numeric Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 4006.3.3.1 Arithmetic Operations . . . . . . . . . . . . . . . 4006.3.3.2 Mathematical Functions . . . . . . . . . . . . . . 401

    6.3.4 Date and Time Functions . . . . . . . . . . . . . . . . . . . . . 4056.3.5 Other Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413

    6.3.5.1 Bit Functions . . . . . . . . . . . . . . . . . . . . . . . . 4136.3.5.2 Miscellaneous Functions . . . . . . . . . . . . . . 414

    6.4 Data Manipulation: SELECT, INSERT, UPDATE, DELETE . . . . 4176.4.1 SELECT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

    6.4.1.1 JOIN Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 4216.4.2 UNION Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4226.4.3 INSERT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423

    6.4.3.1 INSERT ... SELECT Syntax . . . . . . . . . . . 4246.4.4 INSERT DELAYED syntax . . . . . . . . . . . . . . . . . . . . . . . 4256.4.5 UPDATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4266.4.6 DELETE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4276.4.7 TRUNCATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4286.4.8 REPLACE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4296.4.9 LOAD DATA INFILE Syntax . . . . . . . . . . . . . . . . . . . . . 429

    6.5 Data Definition: CREATE, DROP, ALTER . . . . . . . . . . . . . . . . . . 4356.5.1 CREATE DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . 4356.5.2 DROP DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 4356.5.3 CREATE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 436

    6.5.3.1 Silent Column Specification Changes . . 4436.5.4 ALTER TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 4436.5.5 RENAME TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 4476.5.6 DROP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 4476.5.7 CREATE INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 4476.5.8 DROP INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 448

    6.6 Basic MySQL User Utility Commands . . . . . . . . . . . . . . . . . . 448

  • x

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4496.7 MySQL Transactional and Locking Commands . . . . . . . . . . 449

    6.7.1 BEGIN/COMMIT/ROLLBACK Syntax . . . . . . . . . . . . . . . 4496.7.2 LOCK TABLES/UNLOCK TABLES Syntax . . . . . . . . . . . 4506.7.3 SET TRANSACTION Syntax . . . . . . . . . . . . . . . . . . . . . . 452

    6.8 HANDLER Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4526.9 MySQL Full-text Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453

    6.9.1 Fulltext restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . 4556.9.2 Fine-tuning MySQL Full-text Search . . . . . . . . . . . 4556.9.3 New Features of Full-text Search to Appear in

    MySQL 4.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4556.9.4 Full-text Search TODO . . . . . . . . . . . . . . . . . . . . . . . 456

    7 MySQL Table Types . . . . . . . . . . . . . . . . . . . . . 4577.1 MyISAM Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

    7.1.1 Space Needed for Keys . . . . . . . . . . . . . . . . . . . . . . . . 4607.1.2 MyISAM Table Formats . . . . . . . . . . . . . . . . . . . . . . 460

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

    7.1.2.2 Dynamic Table Characteristics . . . . . . . . 4617.1.2.3 Compressed Table Characteristics . . . . . 462

    7.1.3 MyISAM table problems. . . . . . . . . . . . . . . . . . . . . . . 4627.1.3.1 Corrupted MyISAM tables. . . . . . . . . . . . 4637.1.3.2 Clients is using or hasnt closed the table

    properly. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4637.2 MERGE Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4647.3 ISAM Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4667.4 HEAP Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4677.5 BDB or Berkeley DB Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 468

    7.5.1 Overview of BDB Tables . . . . . . . . . . . . . . . . . . . . . . 4687.5.2 Installing BDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4687.5.3 BDB startup options . . . . . . . . . . . . . . . . . . . . . . . . . . 4697.5.4 Some characteristic of BDB tables: . . . . . . . . . . . . . . 4697.5.5 Some things we need to fix for BDB in the near

    future: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4707.5.6 Operating systems supported by BDB . . . . . . . . . . 4717.5.7 Errors You May Get When Using BDB Tables . . 471

    7.6 InnoDB Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4727.6.1 InnoDB tables overview . . . . . . . . . . . . . . . . . . . . . . . 4727.6.2 InnoDB startup options . . . . . . . . . . . . . . . . . . . . . . . 4727.6.3 Creating InnoDB table space . . . . . . . . . . . . . . . . . . 475

    7.6.3.1 If something goes wrong in databasecreation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476

    7.6.4 Creating InnoDB tables . . . . . . . . . . . . . . . . . . . . . . . 4767.6.4.1 Converting MyISAM tables to InnoDB

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477

  • xi

    7.6.5 Adding and removing InnoDB data and log files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477

    7.6.6 Backing up and recovering an InnoDB database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478

    7.6.6.1 Checkpoints . . . . . . . . . . . . . . . . . . . . . . . . . 4797.6.7 Moving an InnoDB database to another machine

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4807.6.8 InnoDB transaction model . . . . . . . . . . . . . . . . . . . . 480

    7.6.8.1 Consistent read . . . . . . . . . . . . . . . . . . . . . . 4807.6.8.2 Locking reads . . . . . . . . . . . . . . . . . . . . . . . . 4817.6.8.3 Next-key locking: avoiding the phantom

    problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4817.6.8.4 Locks set by different SQL statements in

    InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4827.6.8.5 Deadlock detection and rollback . . . . . . . 4837.6.8.6 An example of how the consistent read

    works in InnoDB. . . . . . . . . . . . . . . . . . . . . . . . . 4837.6.9 Performance tuning tips . . . . . . . . . . . . . . . . . . . . . . . 484

    7.6.9.1 The InnoDB Monitor . . . . . . . . . . . . . . . . . 4857.6.10 Implementation of multiversioning . . . . . . . . . . . . 4877.6.11 Table and index structures . . . . . . . . . . . . . . . . . . . 488

    7.6.11.1 Physical structure of an index . . . . . . . . 4887.6.11.2 Insert buffering . . . . . . . . . . . . . . . . . . . . . 4897.6.11.3 Adaptive hash indexes . . . . . . . . . . . . . . . 4897.6.11.4 Physical record structure . . . . . . . . . . . . 4897.6.11.5 How an auto-increment column works in

    InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4907.6.12 File space management and disk i/o . . . . . . . . . . 490

    7.6.12.1 Disk i/o . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4907.6.12.2 File space management . . . . . . . . . . . . . . 4917.6.12.3 Defragmenting a table . . . . . . . . . . . . . . . 492

    7.6.13 Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4927.6.14 Some restrictions on InnoDB tables . . . . . . . . . . . 4937.6.15 InnoDB contact information . . . . . . . . . . . . . . . . . . 493

    8 MySQL APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4958.1 MySQL PHP API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495

    8.1.1 Common Problems with MySQL and PHP . . . . . 4958.2 MySQL Perl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495

    8.2.1 DBI with DBD::mysql . . . . . . . . . . . . . . . . . . . . . . . . . 4958.2.2 The DBI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4968.2.3 More DBI/DBD Information . . . . . . . . . . . . . . . . . . . . 501

    8.3 MySQL ODBC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5028.3.1 How To Install MyODBC . . . . . . . . . . . . . . . . . . . . . 5028.3.2 How to Fill in the Various Fields in the ODBC

    Administrator Program . . . . . . . . . . . . . . . . . . . . . . . . . 5038.3.3 Connect parameters for MyODBC . . . . . . . . . . . . . 5048.3.4 How to Report Problems with MyODBC . . . . . . . 505

  • xii

    8.3.5 Programs Known to Work with MyODBC . . . . . . 5058.3.6 How to Get the Value of an AUTO_INCREMENT

    Column in ODBC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5108.3.7 Reporting Problems with MyODBC . . . . . . . . . . . . 510

    8.4 MySQL C API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5118.4.1 C API Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5128.4.2 C API Function Overview . . . . . . . . . . . . . . . . . . . . . 5148.4.3 C API Function Descriptions . . . . . . . . . . . . . . . . . . 518

    8.4.3.1 mysql_affected_rows() . . . . . . . . . . . . . 5188.4.3.2 mysql_close() . . . . . . . . . . . . . . . . . . . . . . 5198.4.3.3 mysql_connect() . . . . . . . . . . . . . . . . . . . . 5208.4.3.4 mysql_change_user() . . . . . . . . . . . . . . . 5208.4.3.5 mysql_character_set_name() . . . . . . . . 5218.4.3.6 mysql_create_db() . . . . . . . . . . . . . . . . . . 5228.4.3.7 mysql_data_seek() . . . . . . . . . . . . . . . . . . 5228.4.3.8 mysql_debug() . . . . . . . . . . . . . . . . . . . . . . 5238.4.3.9 mysql_drop_db() . . . . . . . . . . . . . . . . . . . . 5238.4.3.10 mysql_dump_debug_info() . . . . . . . . . . 5248.4.3.11 mysql_eof() . . . . . . . . . . . . . . . . . . . . . . . 5248.4.3.12 mysql_errno() . . . . . . . . . . . . . . . . . . . . . 5268.4.3.13 mysql_error() . . . . . . . . . . . . . . . . . . . . . 5268.4.3.14 mysql_escape_string() . . . . . . . . . . . . 5278.4.3.15 mysql_fetch_field() . . . . . . . . . . . . . . 5278.4.3.16 mysql_fetch_fields() . . . . . . . . . . . . . 5288.4.3.17 mysql_fetch_field_direct(). . . . . . . 5288.4.3.18 mysql_fetch_lengths() . . . . . . . . . . . . 5298.4.3.19 mysql_fetch_row() . . . . . . . . . . . . . . . . 5308.4.3.20 mysql_field_count() . . . . . . . . . . . . . . 5318.4.3.21 mysql_field_seek() . . . . . . . . . . . . . . . 5328.4.3.22 mysql_field_tell() . . . . . . . . . . . . . . . 5338.4.3.23 mysql_free_result() . . . . . . . . . . . . . . 5338.4.3.24 mysql_get_client_info() . . . . . . . . . . 5338.4.3.25 mysql_get_host_info() . . . . . . . . . . . . 5348.4.3.26 mysql_get_proto_info() . . . . . . . . . . . 5348.4.3.27 mysql_get_server_info() . . . . . . . . . . 5348.4.3.28 mysql_info() . . . . . . . . . . . . . . . . . . . . . . 5358.4.3.29 mysql_init() . . . . . . . . . . . . . . . . . . . . . . 5358.4.3.30 mysql_insert_id() . . . . . . . . . . . . . . . . 5368.4.3.31 mysql_kill() . . . . . . . . . . . . . . . . . . . . . . 5378.4.3.32 mysql_list_dbs() . . . . . . . . . . . . . . . . . . 5378.4.3.33 mysql_list_fields() . . . . . . . . . . . . . . 5388.4.3.34 mysql_list_processes() . . . . . . . . . . . 5388.4.3.35 mysql_list_tables() . . . . . . . . . . . . . . 5398.4.3.36 mysql_num_fields() . . . . . . . . . . . . . . . 5408.4.3.37 mysql_num_rows() . . . . . . . . . . . . . . . . . . 5418.4.3.38 mysql_options() . . . . . . . . . . . . . . . . . . . 5418.4.3.39 mysql_ping() . . . . . . . . . . . . . . . . . . . . . . 5438.4.3.40 mysql_query() . . . . . . . . . . . . . . . . . . . . . 544

  • xiii

    8.4.3.41 mysql_real_connect() . . . . . . . . . . . . . 5448.4.3.42 mysql_real_escape_string(). . . . . . . 5478.4.3.43 mysql_real_query() . . . . . . . . . . . . . . . 5488.4.3.44 mysql_reload() . . . . . . . . . . . . . . . . . . . . 5498.4.3.45 mysql_row_seek() . . . . . . . . . . . . . . . . . . 5498.4.3.46 mysql_row_tell() . . . . . . . . . . . . . . . . . . 5508.4.3.47 mysql_select_db() . . . . . . . . . . . . . . . . 5508.4.3.48 mysql_shutdown() . . . . . . . . . . . . . . . . . . 5518.4.3.49 mysql_stat() . . . . . . . . . . . . . . . . . . . . . . 5518.4.3.50 mysql_store_result() . . . . . . . . . . . . . 5528.4.3.51 mysql_thread_id() . . . . . . . . . . . . . . . . 5538.4.3.52 mysql_use_result() . . . . . . . . . . . . . . . 553

    8.4.4 C Threaded Function Descriptions . . . . . . . . . . . . . 5548.4.4.1 my_init() . . . . . . . . . . . . . . . . . . . . . . . . . . 5548.4.4.2 mysql_thread_init() . . . . . . . . . . . . . . . 5558.4.4.3 mysql_thread_end() . . . . . . . . . . . . . . . . 555

    8.4.5 C Embedded Server Function Descriptions . . . . . . 5558.4.5.1 mysql_server_init() . . . . . . . . . . . . . . . 5568.4.5.2 mysql_server_end() . . . . . . . . . . . . . . . . 557

    8.4.6 Common questions and problems when using the CAPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557

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

    8.4.6.2 What Results Can I Get From a Query?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557

    8.4.6.3 How Can I Get the Unique ID for the LastInserted Row? . . . . . . . . . . . . . . . . . . . . . . . . . . . 558

    8.4.6.4 Problems Linking with the C API . . . . . 5588.4.7 Building Client Programs . . . . . . . . . . . . . . . . . . . . . 5598.4.8 How to Make a Threaded Client . . . . . . . . . . . . . . . 5598.4.9 libmysqld, the Embedded MySQL Server Library

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5608.4.9.1 Overview of the Embedded MySQL Server

    Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5608.4.9.2 Compiling Programs with libmysqld . . 5618.4.9.3 A Simple Embedded Server Example . . 5618.4.9.4 Licensing the Embedded Server . . . . . . . 567

    8.5 MySQL C++ APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5678.5.1 Borland C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568

    8.6 MySQL Java Connectivity (JDBC) . . . . . . . . . . . . . . . . . . . . . 5688.7 MySQL Python APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5688.8 MySQL Tcl APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5688.9 MySQL Eiffel wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568

  • xiv

    9 Extending MySQL . . . . . . . . . . . . . . . . . . . . . . . 5699.1 Adding New Functions to MySQL . . . . . . . . . . . . . . . . . . . . . . 569

    9.1.1 CREATE FUNCTION/DROP FUNCTION Syntax . . . . . . . 5699.1.2 Adding a New User-definable Function . . . . . . . . . 570

    9.1.2.1 UDF Calling Sequences . . . . . . . . . . . . . . . 5719.1.2.2 Argument Processing . . . . . . . . . . . . . . . . . 5729.1.2.3 Return Values and Error Handling . . . . 5739.1.2.4 Compiling and Installing User-definable

    Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5749.1.3 Adding a New Native Function . . . . . . . . . . . . . . . . 575

    9.2 Adding New Procedures to MySQL . . . . . . . . . . . . . . . . . . . . . 5779.2.1 Procedure Analyse . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5779.2.2 Writing a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . 577

    9.3 MySQL Internals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5779.3.1 MySQL Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5789.3.2 MySQL Test Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578

    9.3.2.1 Running the MySQL Test Suite . . . . . . . 5789.3.2.2 Extending the MySQL Test Suite . . . . . 5799.3.2.3 Reporting Bugs in the MySQL Test Suite

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580

    Appendix A Problems and Common Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582A.1 How to Determine What Is Causing Problems . . . . . . . . . . 582A.2 Some Common Errors When Using MySQL . . . . . . . . . . . . . 583

    A.2.1 Access denied Error . . . . . . . . . . . . . . . . . . . . . . . . . 583A.2.2 MySQL server has gone away Error . . . . . . . . . . . . 583A.2.3 Cant connect to [local] MySQL server error

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584A.2.4 Host ... is blocked Error . . . . . . . . . . . . . . . . . 585A.2.5 Too many connections Error . . . . . . . . . . . . . . . . . 586A.2.6 Some non-transactional changed tables

    couldnt be rolled back Error . . . . . . . . . . . . . . . . . 586A.2.7 Out of memory Error . . . . . . . . . . . . . . . . . . . . . . . . . 587A.2.8 Packet too large Error . . . . . . . . . . . . . . . . . . . . . . 587A.2.9 Communication Errors / Aborted Connection . . 587A.2.10 The table is full Error . . . . . . . . . . . . . . . . . . . . 588A.2.11 Cant create/write to file Error . . . . . . . . . . 588A.2.12 Commands out of sync Error in Client . . . . . . . . 589A.2.13 Ignoring user Error . . . . . . . . . . . . . . . . . . . . . . . . 589A.2.14 Table xxx doesnt exist Error . . . . . . . . . . . 590A.2.15 Cant initialize character set xxx error. . . . 590A.2.16 File Not Found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590

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

    Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591A.3.2 How to Run MySQL As a Normal User . . . . . . . . 592A.3.3 Problems with File Permissions . . . . . . . . . . . . . . . 593

  • xv

    A.4 Administration Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . 593A.4.1 What To Do If MySQL Keeps Crashing . . . . . . . . 594A.4.2 How to Reset a Forgotten Password . . . . . . . . . . . 596A.4.3 How MySQL Handles a Full Disk . . . . . . . . . . . . . . 596A.4.4 Where MySQL Stores Temporary Files . . . . . . . . 597A.4.5 How to Protect or change the MySQL socket file

    /tmp/mysql.sock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597A.4.6 Time Zone Problems . . . . . . . . . . . . . . . . . . . . . . . . . 598

    A.5 Query Related Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598A.5.1 Case Sensitivity in Searches . . . . . . . . . . . . . . . . . . . 598A.5.2 Problems Using DATE Columns . . . . . . . . . . . . . . . . 599A.5.3 Problems with NULL Values . . . . . . . . . . . . . . . . . . . 599A.5.4 Problems with alias . . . . . . . . . . . . . . . . . . . . . . . . . 600A.5.5 Deleting Rows from Related Tables . . . . . . . . . . . . 601A.5.6 Solving Problems with No Matching Rows . . . . . 601

    A.6 Table Definition Related Issues . . . . . . . . . . . . . . . . . . . . . . . . 602A.6.1 Problems with ALTER TABLE. . . . . . . . . . . . . . . . . . . 602A.6.2 How To Change the Order of Columns in a Table

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602A.6.3 TEMPORARY TABLE problems . . . . . . . . . . . . . 603

    Appendix B Some MySQL Users . . . . . . . . . . . 604B.1 General News Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604B.2 Some Web Search Engines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604B.3 Some Information Search Engines Concentrated on Some

    Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604B.4 Online Magazines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605B.5 Web Sites that Use MySQL as a Backend . . . . . . . . . . . . . . . 605B.6 Some Domain/Internet/Web and Related Services . . . . . . . 606B.7 Web Sites that Use PHP and MySQL . . . . . . . . . . . . . . . . . . . 606B.8 Some MySQL Consultants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607B.9 Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607B.10 Uncategorized Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607

    Appendix C MySQL customer usage. . . . . . . . 610

  • xvi

    Appendix D Contributed Programs. . . . . . . . . 611D.1 APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611D.2 Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614D.3 Web Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618D.4 Performance Benchmarking Tools . . . . . . . . . . . . . . . . . . . . . . 619D.5 Authentication Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619D.6 Converters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620D.7 Using MySQL with Other Products . . . . . . . . . . . . . . . . . . . . 621D.8 Useful Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621D.9 RPMs for Common Tools (Most Are for RedHat 6.1) . . . . 622D.10 Useful Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622D.11 Windows programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623D.12 Uncategorized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623

    Appendix E Credits . . . . . . . . . . . . . . . . . . . . . . . 624E.1 Developers at MySQL AB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624E.2 Contributors to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626E.3 Supporters to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    Appendix F MySQL change history . . . . . . . . 633F.1 Changes in release 4.0.x (Development; Alpha) . . . . . . . . . . 633

    F.1.1 Changes in release 4.0.0 . . . . . . . . . . . . . . . . . . . . . . . 633F.2 Changes in release 3.23.x (Stable) . . . . . . . . . . . . . . . . . . . . . . 634

    F.2.1 Changes in release 3.23.43 . . . . . . . . . . . . . . . . . . . . 635F.2.2 Changes in release 3.23.42 . . . . . . . . . . . . . . . . . . . . 635F.2.3 Changes in release 3.23.41 . . . . . . . . . . . . . . . . . . . . 636F.2.4 Changes in release 3.23.40 . . . . . . . . . . . . . . . . . . . . 636F.2.5 Changes in release 3.23.39 . . . . . . . . . . . . . . . . . . . . 637F.2.6 Changes in release 3.23.38 . . . . . . . . . . . . . . . . . . . . 637F.2.7 Changes in release 3.23.37 . . . . . . . . . . . . . . . . . . . . 638F.2.8 Changes in release 3.23.36 . . . . . . . . . . . . . . . . . . . . 639F.2.9 Changes in release 3.23.35 . . . . . . . . . . . . . . . . . . . . 640F.2.10 Changes in release 3.23.34a . . . . . . . . . . . . . . . . . . 640F.2.11 Changes in release 3.23.34 . . . . . . . . . . . . . . . . . . . 640F.2.12 Changes in release 3.23.33 . . . . . . . . . . . . . . . . . . . 641F.2.13 Changes in release 3.23.32 . . . . . . . . . . . . . . . . . . . 642F.2.14 Changes in release 3.23.31 . . . . . . . . . . . . . . . . . . . 643F.2.15 Changes in release 3.23.30 . . . . . . . . . . . . . . . . . . . 643F.2.16 Changes in release 3.23.29 . . . . . . . . . . . . . . . . . . . 644F.2.17 Changes in release 3.23.28 . . . . . . . . . . . . . . . . . . . 646F.2.18 Changes in release 3.23.27 . . . . . . . . . . . . . . . . . . . 647F.2.19 Changes in release 3.23.26 . . . . . . . . . . . . . . . . . . . 648F.2.20 Changes in release 3.23.25 . . . . . . . . . . . . . . . . . . . 649F.2.21 Changes in release 3.23.24 . . . . . . . . . . . . . . . . . . . 650F.2.22 Changes in release 3.23.23 . . . . . . . . . . . . . . . . . . . 650F.2.23 Changes in release 3.23.22 . . . . . . . . . . . . . . . . . . . 651F.2.24 Changes in release 3.23.21 . . . . . . . . . . . . . . . . . . . 652

  • xvii

    F.2.25 Changes in release 3.23.20 . . . . . . . . . . . . . . . . . . . 653F.2.26 Changes in release 3.23.19 . . . . . . . . . . . . . . . . . . . 653F.2.27 Changes in release 3.23.18 . . . . . . . . . . . . . . . . . . . 653F.2.28 Changes in release 3.23.17 . . . . . . . . . . . . . . . . . . . 654F.2.29 Changes in release 3.23.16 . . . . . . . . . . . . . . . . . . . 654F.2.30 Changes in release 3.23.15 . . . . . . . . . . . . . . . . . . . 655F.2.31 Changes in release 3.23.14 . . . . . . . . . . . . . . . . . . . 656F.2.32 Changes in release 3.23.13 . . . . . . . . . . . . . . . . . . . 656F.2.33 Changes in release 3.23.12 . . . . . . . . . . . . . . . . . . . 657F.2.34 Changes in release 3.23.11 . . . . . . . . . . . . . . . . . . . 657F.2.35 Changes in release 3.23.10 . . . . . . . . . . . . . . . . . . . 658F.2.36 Changes in release 3.23.9 . . . . . . . . . . . . . . . . . . . . 658F.2.37 Changes in release 3.23.8 . . . . . . . . . . . . . . . . . . . . 659F.2.38 Changes in release 3.23.7 . . . . . . . . . . . . . . . . . . . . 660F.2.39 Changes in release 3.23.6 . . . . . . . . . . . . . . . . . . . . 660F.2.40 Changes in release 3.23.5 . . . . . . . . . . . . . . . . . . . . 661F.2.41 Changes in release 3.23.4 . . . . . . . . . . . . . . . . . . . . 662F.2.42 Changes in release 3.23.3 . . . . . . . . . . . . . . . . . . . . 662F.2.43 Changes in release 3.23.2 . . . . . . . . . . . . . . . . . . . . 663F.2.44 Changes in release 3.23.1 . . . . . . . . . . . . . . . . . . . . 664F.2.45 Changes in release 3.23.0 . . . . . . . . . . . . . . . . . . . . 664

    F.3 Changes in release 3.22.x (Older; Still supported) . . . . . . . . 666F.3.1 Changes in release 3.22.35 . . . . . . . . . . . . . . . . . . . . 666F.3.2 Changes in release 3.22.34 . . . . . . . . . . . . . . . . . . . . 666F.3.3 Changes in release 3.22.33 . . . . . . . . . . . . . . . . . . . . 666F.3.4 Changes in release 3.22.32 . . . . . . . . . . . . . . . . . . . . 666F.3.5 Changes in release 3.22.31 . . . . . . . . . . . . . . . . . . . . 667F.3.6 Changes in release 3.22.30 . . . . . . . . . . . . . . . . . . . . 667F.3.7 Changes in release 3.22.29 . . . . . . . . . . . . . . . . . . . . 667F.3.8 Changes in release 3.22.28 . . . . . . . . . . . . . . . . . . . . 667F.3.9 Changes in release 3.22.27 . . . . . . . . . . . . . . . . . . . . 668F.3.10 Changes in release 3.22.26 . . . . . . . . . . . . . . . . . . . 668F.3.11 Changes in release 3.22.25 . . . . . . . . . . . . . . . . . . . 668F.3.12 Changes in release 3.22.24 . . . . . . . . . . . . . . . . . . . 668F.3.13 Changes in release 3.22.23 . . . . . . . . . . . . . . . . . . . 669F.3.14 Changes in release 3.22.22 . . . . . . . . . . . . . . . . . . . 669F.3.15 Changes in release 3.22.21 . . . . . . . . . . . . . . . . . . . 669F.3.16 Changes in release 3.22.20 . . . . . . . . . . . . . . . . . . . 670F.3.17 Changes in release 3.22.19 . . . . . . . . . . . . . . . . . . . 670F.3.18 Changes in release 3.22.18 . . . . . . . . . . . . . . . . . . . 670F.3.19 Changes in release 3.22.17 . . . . . . . . . . . . . . . . . . . 670F.3.20 Changes in release 3.22.16 . . . . . . . . . . . . . . . . . . . 670F.3.21 Changes in release 3.22.15 . . . . . . . . . . . . . . . . . . . 671F.3.22 Changes in release 3.22.14 . . . . . . . . . . . . . . . . . . . 671F.3.23 Changes in release 3.22.13 . . . . . . . . . . . . . . . . . . . 671F.3.24 Changes in release 3.22.12 . . . . . . . . . . . . . . . . . . . 672F.3.25 Changes in release 3.22.11 . . . . . . . . . . . . . . . . . . . 672F.3.26 Changes in release 3.22.10 . . . . . . . . . . . . . . . . . . . 673

  • xviii

    F.3.27 Changes in release 3.22.9 . . . . . . . . . . . . . . . . . . . . 673F.3.28 Changes in release 3.22.8 . . . . . . . . . . . . . . . . . . . . 674F.3.29 Changes in release 3.22.7 . . . . . . . . . . . . . . . . . . . . 674F.3.30 Changes in release 3.22.6 . . . . . . . . . . . . . . . . . . . . 675F.3.31 Changes in release 3.22.5 . . . . . . . . . . . . . . . . . . . . 675F.3.32 Changes in release 3.22.4 . . . . . . . . . . . . . . . . . . . . 677F.3.33 Changes in release 3.22.3 . . . . . . . . . . . . . . . . . . . . 678F.3.34 Changes in release 3.22.2 . . . . . . . . . . . . . . . . . . . . 678F.3.35 Changes in release 3.22.1 . . . . . . . . . . . . . . . . . . . . 678F.3.36 Changes in release 3.22.0 . . . . . . . . . . . . . . . . . . . . 679

    F.4 Changes in release 3.21.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680F.4.1 Changes in release 3.21.33 . . . . . . . . . . . . . . . . . . . . 680F.4.2 Changes in release 3.21.32 . . . . . . . . . . . . . . . . . . . . 681F.4.3 Changes in release 3.21.31 . . . . . . . . . . . . . . . . . . . . 681F.4.4 Changes in release 3.21.30 . . . . . . . . . . . . . . . . . . . . 681F.4.5 Changes in release 3.21.29 . . . . . . . . . . . . . . . . . . . . 682F.4.6 Changes in release 3.21.28 . . . . . . . . . . . . . . . . . . . . 682F.4.7 Changes in release 3.21.27 . . . . . . . . . . . . . . . . . . . . 682F.4.8 Changes in release 3.21.26 . . . . . . . . . . . . . . . . . . . . 683F.4.9 Changes in release 3.21.25 . . . . . . . . . . . . . . . . . . . . 683F.4.10 Changes in release 3.21.24 . . . . . . . . . . . . . . . . . . . 683F.4.11 Changes in release 3.21.23 . . . . . . . . . . . . . . . . . . . 684F.4.12 Changes in release 3.21.22 . . . . . . . . . . . . . . . . . . . 684F.4.13 Changes in release 3.21.21a . . . . . . . . . . . . . . . . . . 685F.4.14 Changes in release 3.21.21 . . . . . . . . . . . . . . . . . . . 685F.4.15 Changes in release 3.21.20 . . . . . . . . . . . . . . . . . . . 685F.4.16 Changes in release 3.21.19 . . . . . . . . . . . . . . . . . . . 686F.4.17 Changes in release 3.21.18 . . . . . . . . . . . . . . . . . . . 686F.4.18 Changes in release 3.21.17 . . . . . . . . . . . . . . . . . . . 686F.4.19 Changes in release 3.21.16 . . . . . . . . . . . . . . . . . . . 687F.4.20 Changes in release 3.21.15 . . . . . . . . . . . . . . . . . . . 687F.4.21 Changes in release 3.21.14b . . . . . . . . . . . . . . . . . . 688F.4.22 Changes in release 3.21.14a . . . . . . . . . . . . . . . . . . 688F.4.23 Changes in release 3.21.13 . . . . . . . . . . . . . . . . . . . 688F.4.24 Changes in release 3.21.12 . . . . . . . . . . . . . . . . . . . 689F.4.25 Changes in release 3.21.11 . . . . . . . . . . . . . . . . . . . 690F.4.26 Changes in release 3.21.10 . . . . . . . . . . . . . . . . . . . 690F.4.27 Changes in release 3.21.9 . . . . . . . . . . . . . . . . . . . . 690F.4.28 Changes in release 3.21.8 . . . . . . . . . . . . . . . . . . . . 691F.4.29 Changes in release 3.21.7 . . . . . . . . . . . . . . . . . . . . 691F.4.30 Changes in release 3.21.6 . . . . . . . . . . . . . . . . . . . . 692F.4.31 Changes in release 3.21.5 . . . . . . . . . . . . . . . . . . . . 692F.4.32 Changes in release 3.21.4 . . . . . . . . . . . . . . . . . . . . 692F.4.33 Changes in release 3.21.3 . . . . . . . . . . . . . . . . . . . . 692F.4.34 Changes in release 3.21.2 . . . . . . . . . . . . . . . . . . . . 693F.4.35 Changes in release 3.21.0 . . . . . . . . . . . . . . . . . . . . 694

    F.5 Changes in release 3.20.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695F.5.1 Changes in release 3.20.18 . . . . . . . . . . . . . . . . . . . . 695

  • xix

    F.5.2 Changes in release 3.20.17 . . . . . . . . . . . . . . . . . . . . 696F.5.3 Changes in release 3.20.16 . . . . . . . . . . . . . . . . . . . . 696F.5.4 Changes in release 3.20.15 . . . . . . . . . . . . . . . . . . . . 697F.5.5 Changes in release 3.20.14 . . . . . . . . . . . . . . . . . . . . 697F.5.6 Changes in release 3.20.13 . . . . . . . . . . . . . . . . . . . . 698F.5.7 Changes in release 3.20.11 . . . . . . . . . . . . . . . . . . . . 698F.5.8 Changes in release 3.20.10 . . . . . . . . . . . . . . . . . . . . 698F.5.9 Changes in release 3.20.9. . . . . . . . . . . . . . . . . . . . . . 699F.5.10 Changes in release 3.20.8 . . . . . . . . . . . . . . . . . . . . 699F.5.11 Changes in release 3.20.7 . . . . . . . . . . . . . . . . . . . . 699F.5.12 Changes in release 3.20.6 . . . . . . . . . . . . . . . . . . . . 700F.5.13 Changes in release 3.20.3 . . . . . . . . . . . . . . . . . . . . 701F.5.14 Changes in release 3.20.0 . . . . . . . . . . . . . . . . . . . . 701

    F.6 Changes in release 3.19.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702F.6.1 Changes in release 3.19.5. . . . . . . . . . . . . . . . . . . . . . 702F.6.2 Changes in release 3.19.4. . . . . . . . . . . . . . . . . . . . . . 702F.6.3 Changes in release 3.19.3. . . . . . . . . . . . . . . . . . . . . . 703

    Appendix G Comments on porting to othersystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704G.1 Debugging a MySQL server . . . . . . . . . . . . . . . . . . . . . . . . . . . 705

    G.1.1 Compiling MYSQL for debugging. . . . . . . . . . . . . . 705G.1.2 Creating trace files . . . . . . . . . . . . . . . . . . . . . . . . . . . 706G.1.3 Debugging mysqld under gdb . . . . . . . . . . . . . . . . . 707G.1.4 Using a stack trace . . . . . . . . . . . . . . . . . . . . . . . . . . . 708G.1.5 Using log files to find cause of errors in mysqld . . 709G.1.6 Making a test case when you experience table

    corruption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709G.2 Debugging a MySQL client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710G.3 The DBUG package. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710G.4 Locking methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712G.5 Comments about RTS threads . . . . . . . . . . . . . . . . . . . . . . . . . 713G.6 Differences between different thread packages . . . . . . . . . . . 715

    Appendix H Environment Variables . . . . . . . . 716

    Appendix I Description of MySQL regularexpression syntax . . . . . . . . . . . . . . . . . . . . . . . 717

    Appendix J What is Unireg? . . . . . . . . . . . . . . . 720

  • xx

    Appendix K GNU GENERAL PUBLICLICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721K.1 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721K.2 TERMS AND CONDITIONS FOR COPYING,

    DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . 722K.3 How to Apply These Terms to Your New Programs . . . . . 726

    Appendix L GNU LESSER GENERAL PUBLICLICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727L.1 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727L.2 TERMS AND CONDITIONS FOR COPYING,

    DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . 728L.3 How to Apply These Terms to Your New Libraries . . . . . . 735

    Appendix M Pieces of the manual in transit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736M.1 Installing a MySQL Binary Distribution . . . . . . . . . . . . . . . 736M.2 Perl Installation Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . 738

    M.2.1 Installing Perl on Unix . . . . . . . . . . . . . . . . . . . . . . . 738M.2.2 Installing ActiveState Perl on Windows . . . . . . . 739M.2.3 Installing the MySQL Perl Distribution on Windows

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740M.2.4 Problems Using the Perl DBI/DBD Interface . . . . 740

    M.3 Functions for Use with GROUP BY Clauses . . . . . . . . . . . . . . . 741

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

    Concept Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753

  • Chapter 1: General Information About MySQL 1

    1 General Information About MySQL

    This is the MySQL reference manual; it documents MySQL Version 4.0.0-alpha. As MySQLis work in progress, the manual gets updated frequently. There is a very good chance thatthis version is out of date, unless you are looking at it online. The most recent version ofthis manual is available at http://www.mysql.com/documentation/index.html in manydifferent formats. If you have a hard time finding information in the manual, you can trythe searchable PHP version at http://www.mysql.com/doc.MySQL is a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Lan-guage) database server.MySQL is free software. It is licensed with the GNU GENERAL PUBLIC LICENSEhttp://www.gnu.org/. See Section 1.3 [Licensing and Support], page 36.The MySQL home page (http://www.mysql.com/) provides the latest information aboutMySQL.The following list describes some useful sections of the manual: For information about the company behind MySQL, see Section 1.1.2 [What is MySQL

    AB], page 3. For a discussion of MySQLs capabilities, see Section 1.1.6 [Features], page 6. For installation instructions, see Chapter 2 [Installing], page 80. For tips on porting MySQL to new architectures or operating systems, see Appendix G

    [Porting], page 704. For information about upgrading from a Version 3.23 release, see Section 2.5.1

    [Upgrading-from-3.23], page 111. For information about upgrading from a Version 3.22 release, see Section 2.5.2

    [Upgrading-from-3.22], page 111. For a tutorial introduction to MySQL, see Chapter 3 [Tutorial], page 148. For examples of SQL and benchmarking information, see the benchmarking directory

    (sql-bench in the distribution). For a history of new features and bug fixes, see Appendix F [News], page 633. For a list of currently known bugs and misfeatures, see Section 1.4.7 [Bugs], page 56. For future plans, see Section 1.6 [TODO], page 72. For a list of all the contributors to this project, see Appendix E [Credits], page 624.

    IMPORTANT:

    Reports of errors (often called bugs), as well as questions and comments, should be sentto the mailing list at [email protected]. See Section 1.2.4.3 [Bug reports], page 31.The mysqlbug script should be used to generate bug reports. For source distributions, themysqlbug script can be found in the scripts directory. For binary distributions, mysqlbugcan be found in the bin directory. If you have found a sensitive security bug in MySQL,you should send an email to [email protected] you have any suggestions concerning additions or corrections to this manual, please sendthem to the manual team at [email protected].

  • 2 MySQL Technical Reference for Version 4.0.0-alpha

    This is a reference manual; it does not provide general instruction on SQL or relationaldatabase concepts. If you want general information about SQL, see Section 1.2.2 [General-SQL], page 19. For books that focus more specifically on MySQL, see Section 1.2.1 [MySQL-Books], page 13.

    1.1 MySQL, MySQL AB, and Open Source

    1.1.1 What Is MySQL

    MySQL, the most popular Open Source SQL database, is provided by MySQL AB. MySQLAB is a commercial company that builds its business providing services around the MySQLdatabase. See Section 1.1.2 [What is MySQL AB], page 3.

    MySQL is a database management system.A database is a structured collection of data. It may be anything from a sim-ple shopping list to a picture gallery or the vast amounts of information ina corporate network. To add, access, and process data stored in a computerdatabase, you need a database management system such as MySQL. Since com-puters are very good at handling large amounts of data, database managementplays a central role in computing, as stand-alone utilities, or as parts of otherapplications.

    MySQL is a relational database management system.A relational database stores data in separate tables rather than putting all thedata in one big storeroom. This adds speed and flexibility. The tables are linkedby defined relations making it possible to combine data from several tables onrequest. The SQL part of MySQL stands for "Structured Query Language" -the most common standardized language used to access databases.

    MySQL is Open Source Software.Open Source means that it is possible for anyone to use and modify. Anybodycan download MySQL from the Internet and use it without paying anything.Anybody so inclined can study the source code and change it to fit their needs.MySQL uses the GPL (GNU General Public License) http://www.gnu.org,to define what you may and may not do with the software in different situa-tions. If you feel uncomfortable with the GPL or need to embed MySQL intoa commercial application you can buy a commercially licensed version from us.

    Why use MySQL?MySQL is very fast, reliable, and easy to use. If that is what you are lookingfor, you should give it a try. MySQL also has a very practical set of featuresdeveloped in very close cooperation with our users. You can find a performancecomparison of MySQL to some other database managers on our benchmarkpage. See Section 5.1.4 [MySQL Benchmarks], page 322.MySQL was originally developed to handle very large databases much fasterthan existing solutions and has been successfully used in highly demanding pro-

  • Chapter 1: General Information About MySQL 3

    duction environments for several years. Though under constant development,MySQL today offers a rich and very useful set of functions. The connectivity,speed, and security make MySQL highly suited for accessing databases on theInternet.

    The technical features of MySQLFor advanced technical information, see Chapter 6 [Reference], page 358.MySQL is a client/server system that consists of a multi-threaded SQL serverthat supports different backends, several different client programs and libraries,administrative tools, and several programming interfaces.We also provide MySQL as a multi-threaded library which you can link intoyour application to get a smaller, faster, easier to manage product.

    MySQL has a lot of contributed software available.It is very likely that you will find that your favorite application or languagealready supports MySQL.

    The official way to pronounce MySQL is My Ess Que Ell (not MY-SEQUEL). But wetry to avoid correcting people who say MY-SEQUEL.

    1.1.2 What Is MySQL AB

    MySQL AB is the Swedish company owned and run by the MySQL founders and maindevelopers. We are dedicated to developing MySQL and spreading our database to newusers. MySQL AB owns the copyright to the MySQL server source code and the MySQLtrademark. A significant amount of revenues from our services goes to developing MySQL.See Section 1.1.1 [What-is], page 2.

    MySQL AB has been profitable providing MySQL from the start. We dont get any outsidefunding, but have earned all our money ourselves.

    We are searching after partners that would like to support our development of MySQL sothat we could accelerate the development pace. If you are interested in doing this, you canemail [email protected] about this!

    MySQL AB has currently 20+ people (http://www.mysql.com/development/team.html)on its payroll and is growing rapidly.

    Our main sources of income are:

    Commercial high quality support for MySQL provided by the MySQL developersthemselves. If you are interested in purchasing a support contract, please visithttps://order.mysql.com/ to view our support options or to order support.

    Consulting services. We have developers and consultants in 12 countries and part-ners in many other countries that can help you with almost any MySQL related is-sues. If you need consulting services, please email a good description of your needs [email protected]! If we cant handle this ourselves we can usually find a partner or adeveloper that can help you with your problems.

    We sell licenses for using MySQL as an embedded database. See Section 1.3.4 [Cost],page 39. If you have a commercial product for which you need a fast, high quality

  • 4 MySQL Technical Reference for Version 4.0.0-alpha

    database, but you cant afford to make your product Open Source, you can buy the rightto use the MySQL server under a normal commercial copyright. If you are interestedin this you can buy MySQL licenses at https://order.mysql.com/ or contact us [email protected].

    Advertising. http://www.mysql.com/ is a very popular web site with more than10,000,000 page views per months (January 2001). By putting a banner on this youare guaranteed to reach a lot of potential customers in the Open source, Linux anddatabase community. If you are interested in this email [email protected].

    We are building a partner program to be able to provide MySQL services in everycountry. If you are interested in becoming a partner of MySQL AB please visithttp://www.mysql.com/information/partners.html or email [email protected].

    We provide MySQL training through our partner programs. For more information,please email [email protected].

    The MySQL brand has, since 1995, been associated with speed and reliability, and isknown to be something you can depend upon. If you are interested in using the MySQLtrademark in your marketing, you can email [email protected] about this.

    The MySQL core values show our dedication to MySQL and Open Source.We want MySQL to be: The best and the most used database in the world. Available and affordable for all. Easy to use. Continuously improved while remaining fast and safe. Fun to use and improve. Free from bugs.

    MySQL AB and the people of MySQL AB: Promote Open Source Philosophy and support the Open Source Community. Aim to be good citizens. Prefer partners that share our values and mind-set. Answer mail and give support. Are a virtual company, networking with others. Work against software patents.

    1.1.3 About This Manual

    This manual is currently available in Texinfo, plain text, Info, HTML, PostScript, andPDF versions. The primary document is the Texinfo file. The HTML version is producedautomatically using a modified version of texi2html. The plain text and Info versions areproduced with makeinfo. The Postscript version is produced using texi2dvi and dvips.The PDF version is produced with pdftex.This manual is written and maintained by David Axmark, Michael (Monty) Widenius,Jeremy Cole, and Paul DuBois. For other contributors, see Appendix E [Credits], page 624.

  • Chapter 1: General Information About MySQL 5

    1.1.4 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.

    filenameConstant-width font with surrounding quotes is used for filenames and path-names. Example: The distribution is installed under the /usr/local/ direc-tory.

    c Constant-width font with surrounding quotes is also used to indicate charactersequences. Example: To specify a wild card, use the % character.

    italic Italic font is used for emphasis, like this.

    boldface Boldface font is used for access privilege names (for example, do not grant theprocess privilege lightly) and occasionally to convey especially strong empha-sis.

    When commands are shown that are meant to be executed by a particular program, theprogram is indicated by a prompt shown before the command. For example, shell> indi-cates a command that you execute from your login shell, and mysql> indicates a commandthat you execute from the mysql client program:

    shell> type a shell command heremysql> type a mysql command here

    Shell commands are shown using Bourne shell syntax. If you are using a csh-style shell,you may need to issue commands slightly differently. For example, the sequence to set anenvironment variable and run a command looks like this in Bourne shell syntax:

    shell> VARNAME=value some_command

    For csh, you would execute the sequence like this:shell> setenv VARNAME valueshell> some_command

    Often, database, table, and column names must be substituted into commands. To indicatethat 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 owndatabase, table, and column names, perhaps like this:

    mysql> SELECT author_name FROM biblio_db.author_list;

    SQL statements may be written in uppercase or lowercase. When this manual shows a SQLstatement, uppercase is used for particular keywords if those keywords are under discussion(to emphasize them) and lowercase is used for the rest of the statement. For example, youmight see the following in a discussion of the SELECT statement:

  • 6 MySQL Technical Reference for Version 4.0.0-alpha

    mysql> SELECT count(*) FROM tbl_name;

    On the other hand, in a discussion of the COUNT() function, the same statement would bewritten like this:

    mysql> select COUNT(*) from tbl_name;

    If no particular emphasis is intended, all keywords are written uniformly in uppercase.In syntax descriptions, square brackets ([ and ]) are used to indicate optional words orclauses:

    DROP TABLE [IF EXISTS] tbl_name

    When a syntax element consists of a number of alternatives, the alternatives are separated byvertical bars (|). When one member from a set of choices may be chosen, the alternativesare 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 withinbraces ({ and }):

    {DESCRIBE | DESC} tbl_name {col_name | wild}

    1.1.5 History of MySQL

    We once started out with the intention of using mSQL to connect to our tables using ourown fast low-level (ISAM) routines. However, after some testing we came to the conclusionthat mSQL was not fast enough nor flexible enough for our needs. This resulted in a newSQL interface to our database but with almost the same API interface as mSQL. This APIwas chosen to ease porting of third-party code.The derivation of the name MySQL is not perfectly clear. Our base directory and a largenumber of our libraries and tools have had the prefix my for well over 10 years. However,Montys daughter (some years younger) is also named My. Which of the two gave its nameto MySQL is still a mystery, even for us.

    1.1.6 The Main Features of MySQL

    The following list describes some of the important characteristics of MySQL: Fully multi-threaded using kernel threads. This means it can easily use multiple CPUs

    if available. C, C++, Eiffel, Java, Perl, PHP, Python and Tcl APIs. See Chapter 8 [Clients],

    page 495. Works on many different platforms. See Section 2.2.2 [Which OS], page 85. 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,and ENUM types. See Section 6.2 [Column types], page 366.

    Very fast joins using an optimized one-sweep multi-join. Full operator and function support in the SELECT and WHERE parts of queries. For

    example:

  • Chapter 1: General Information About MySQL 7

    mysql> SELECT CONCAT(first_name, " ", last_name) FROM tbl_nameWHERE income/dependents > 10000 AND age > 30;

    SQL functions are implemented through a highly optimized class library and shouldbe as fast as possible! Usually there isnt any memory allocation at all after queryinitialization.

    Full support for SQL GROUP BY and ORDER BY clauses. Support for group functions(COUNT(), COUNT(DISTINCT ...), AVG(), STD(), SUM(), MAX() and MIN()).

    Support for LEFT OUTER JOIN and RIGHT OUTER JOIN with ANSI SQL and ODBC syn-tax.

    You can mix tables from different databases in the same query (as of Version 3.22). A privilege and password system that is very flexible and secure, and allows host-based

    verification. Passwords are secure because all password traffic is encrypted when youconnect to a server.

    ODBC (Open-DataBase-Connectivity) support for Win32 (with source). All ODBC2.5 functions and many others. For example, you can use MS Access to connect toyour MySQL server. See Section 8.3 [ODBC], page 502.

    Very fast B-tree disk tables with index compression. Up to 32 indexes per table are allowed. Each index may consist of 1 to 16 columns or

    parts of columns. The maximum index length is 500 bytes (this may be changed whencompiling MySQL). An index may use a prefix of a CHAR or VARCHAR field.

    Fixed-length and variable-length records. In-memory hash tables which are used as temporary tables. Handles large databases. We are using MySQL with some databases that contain

    50,000,000 records and we know of users that uses MySQL with 60,000 tables andabout 5,000,000,000 rows

    All columns have default values. You can use INSERT to insert a subset of a tablescolumns; those columns that are not explicitly given values are set to their defaultvalues.

    Uses GNU Automake, Autoconf, and Libtool for portability. Written in C and C++. Tested with a broad range of different compilers. A very fast thread-based memory allocation system. No memory leaks. MySQL has been tested with Purify, a commercial memory leakage

    detector. Includes myisamchk, a very fast utility for table checking, optimization, and repair. All

    of the functionality of myisamchk is also available through the SQL interface as well.See Chapter 4 [MySQL Database Administration], page 183.

    Full support for several different character sets, including ISO-8859-1 (Latin1), german,big5, ujis, and more. For example, the Scandinavian characters a, a and o areallowed in table and column names.

    All data are saved in the chosen character set. All comparisons for normal stringcolumns are case insensitive.

    Sorting is done according to the chosen character set (the Swedish way by default). Itis possible to change this when the MySQL server is started up. To see an example of

  • 8 MySQL Technical Reference for Version 4.0.0-alpha

    very advanced sorting, look at the Czech sorting code. MySQL supports many differentcharacter sets that can be specified at compile and run time.

    Aliases on tables and columns are allowed as in the SQL92 standard. 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 aflag when connecting to the server.

    Function names do not clash with table or column names. For example, ABS is a validcolumn name. The only restriction is that for a function call, no spaces are allowedbetween the function name and the ( that follows it. See Section 6.1.6 [Reservedwords], page 364.

    All MySQL programs can be invoked with the --help or -? options to obtain onlineassistance.

    The server can provide error messages to clients in many languages. See Section 4.6.2[Languages], page 263.

    Clients may connect to the MySQL server using TCP/IP Sockets, Unix Sockets (Unix),or Named Pipes (NT).

    The MySQL-specific SHOW command can be used to retrieve information aboutdatabases, tables, and indexes. The EXPLAIN command can be used to determinehow the optimizer resolves a query.

    1.1.7 How Stable Is MySQL?

    This section addresses the questions How stable is MySQL? and Can I depend on MySQLin this project? We will try to clarify some issues and to answer some of the more importantquestions that seem to concern many people. This section has been put together frominformation gathered from the mailing list (which is very active in reporting bugs).At TcX, MySQL has worked without any problems in our projects since mid-1996. WhenMySQL was released to a wider public, we noticed that there were some pieces of untestedcode that were quickly found by the new users who made queries in a manner differentthan our own. Each new release has had fewer portability problems than the previous one(even though each has had many new features).Each release of MySQL has been usable, and there have been problems only when usersstart to use code from the gray zones. Naturally, outside users dont know what thegray zones are; this section attempts to indicate those that are currently known. Thedescriptions deal with Version 3.23 of MySQL. All known and reported bugs are fixed inthe latest version, with the exception of the bugs listed in the bugs section, which are thingsthat are design-related. See Section 1.4.7 [Bugs], page 56.MySQL is written in multiple layers and different independent modules. These modules arelisted below with an indication of how well-tested each of them is:

    The ISAM table handler StableThis manages storage and retrieval of all data in MySQL Version 3.22 andearlier. In all MySQL releases there hasnt been a single (reported) bug in thiscode. The only known way to get a corrupted table is to kill the server in the

  • Chapter 1: General Information About MySQL 9

    middle of an update. Even that is unlikely to destroy any data beyond rescue,because all data are flushed to disk between each query. There hasnt been asingle bug report about lost data because of bugs in MySQL.

    The MyISAM table handler StableThis is new in MySQL Version 3.23. Its largely based on the ISAM table codebut has a lot of new and very useful features.

    The parser and lexical analyser StableThere hasnt been a single reported bug in this system for a long time.

    The C client code StableNo known problems. In early Version 3.20 releases, there were some limitationsin the send/receive buffer size. As of Version 3.21, the buffer size is now dynamicup to a default of 16M.

    Standard client programs StableThese include mysql, mysqladmin, mysqlshow, mysqldump, and mysqlimport.

    Basic SQL StableThe basic SQL function system and string classes and dynamic memory han-dling. Not a single reported bug in this system.

    Query optimizer Stable

    Range optimizer Stable

    Join optimizer Stable

    Locking GammaThis is very system-dependent. On some systems there are big problems usingstandard OS locking (fcntl()). In these cases, you should run the MySQLdaemon with the --skip-locking flag. Problems are known to occur on someLinux systems, and on SunOS when using NFS-mounted file systems.

    Linux threads StableThe major problem found has been with the fcntl() call, which is fixed byusing the --skip-locking option to mysqld. Some people have reported lockupproblems with Version 0.5. LinuxThreads will need to be recompiled if you planto use 1000+ concurrent connections. Although it is possible to run that manyconnections with the default LinuxThreads (however, you will never go above1021), the default stack spacing of 2 MB makes the application unstable, andwe have been able to reproduce a coredump after creating 1021 idle connections.See Section 2.6.1 [Linux], page 115.

    Solaris 2.5+ pthreads StableWe use this for all our production work.

    MIT-pthreads (Other systems) StableThere have been no reported bugs since Version 3.20.15 and no known bugssince Version 3.20.16. On some systems, there is a misfeature where someoperations are quite slow (a 1/20 second sleep is done between each query). Ofcourse, MIT-pthreads may slow down everything a bit, but index-based SELECTstatements are usually done in one time frame so there shouldnt be a mutexlocking/thread juggling.

  • 10 MySQL Technical Reference for Version 4.0.0-alpha

    Other thread implementions Beta - GammaThe ports to other systems are still very new and may have bugs, possibly inMySQL, but most often in the thread implementation itself.

    LOAD DATA ..., INSERT ... SELECT StableSome people thought they had found bugs here, but these usually have turnedout to be misunderstandings. Please check the manual before reporting prob-lems!

    ALTER TABLE StableS


Recommended