Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PDF MySQL Reference Manual 1st Edition Michael Widenius Download

Download as pdf or txt
Download as pdf or txt
You are on page 1of 84

Full download ebook at ebookname.

com

MySQL Reference Manual 1st Edition Michael


Widenius

https://ebookname.com/product/mysql-reference-manual-1st-
edition-michael-widenius/

OR CLICK BUTTON

DOWLOAD NOW

Download more ebook from https://ebookname.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Murach s PHP and MySQL training reference 2nd Edition


Joel Murach

https://ebookname.com/product/murach-s-php-and-mysql-training-
reference-2nd-edition-joel-murach/

The Definitive Guide to MySQL 2nd Edition Michael


Kofler

https://ebookname.com/product/the-definitive-guide-to-mysql-2nd-
edition-michael-kofler/

Beginning PHP Apache MySQL web development Michael K.


Glass

https://ebookname.com/product/beginning-php-apache-mysql-web-
development-michael-k-glass/

Structural Engineering Reference Manual 8th Edition


Alan Williams

https://ebookname.com/product/structural-engineering-reference-
manual-8th-edition-alan-williams/
C A Reference Manual 5th Edition Samuel P. Harbison

https://ebookname.com/product/c-a-reference-manual-5th-edition-
samuel-p-harbison/

XML Pocket Reference 3rd Edition Michael Fitzgerald

https://ebookname.com/product/xml-pocket-reference-3rd-edition-
michael-fitzgerald/

Ruby Pocket Reference 1st ed Edition Michael James


Fitzgerald

https://ebookname.com/product/ruby-pocket-reference-1st-ed-
edition-michael-james-fitzgerald/

Manual of Inpatient Psychiatry 1st Edition Michael I.


Casher

https://ebookname.com/product/manual-of-inpatient-psychiatry-1st-
edition-michael-i-casher/

Litt s Drug Eruption Reference Manual Including Drug


Interactions 13th Edition Litt

https://ebookname.com/product/litt-s-drug-eruption-reference-
manual-including-drug-interactions-13th-edition-litt/
i

Table of Contents

1 General Information . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Conventions Used in This Manual . . . . . . . . . . . . . . . . 2
1.2 What Is MySQL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 History of MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 The Main Features of MySQL . . . . . . . . . . . . . . . . . . . 5
1.2.3 How Stable Is MySQL? . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.4 How Big Can MySQL Tables Be? . . . . . . . . . . . . . . . . 9
1.2.5 Year 2000 Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 What Is MySQL AB? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.1 The Business Model and Services of MySQL AB . . 12
1.3.1.1 Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3.1.2 Training and Certification . . . . . . . . . . . . . 12
1.3.1.3 Consulting . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.1.4 Commercial Licenses . . . . . . . . . . . . . . . . . . 13
1.3.1.5 Partnering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.1.6 Advertising . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.3.2 Contact Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4 MySQL Support and Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4.1 Support Offered by MySQL AB. . . . . . . . . . . . . . . . . 15
1.4.2 Copyrights and Licenses Used by MySQL. . . . . . . . 16
1.4.3 MySQL Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4.3.1 Using the MySQL Software Under a
Commercial License . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.3.2 Using the MySQL Software for Free Under
GPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.4 MySQL AB Logos and Trademarks . . . . . . . . . . . . . 18
1.4.4.1 The Original MySQL Logo. . . . . . . . . . . . . 18
1.4.4.2 MySQL Logos that may be Used Without
Written Permission . . . . . . . . . . . . . . . . . . . . . . . 19
1.4.4.3 When do you need a Written Permission to
use MySQL Logos? . . . . . . . . . . . . . . . . . . . . . . . 19
1.4.4.4 MySQL AB Partnership Logos . . . . . . . . . 19
1.4.4.5 Using the word MySQL in Printed Text or
Presentations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4.4.6 Using the word MySQL in Company and
Product Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.5 MySQL 4.0 In A Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.5.1 Features Available From MySQL 4.0 . . . . . . . . . . . . 20
1.5.2 Embedded MySQL Server . . . . . . . . . . . . . . . . . . . . . . 21
1.6 MySQL 4.1 In A Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.6.1 Features Available From MySQL 4.1 . . . . . . . . . . . . 22
1.6.2 Stepwise Rollout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ii

1.6.3Ready for Immediate Development Use . . . . . . . . . . 24


1.6.4MySQL 5.0, The Next Development Release . . . . . 24
1.7 MySQLInformation Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.7.1MySQL Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.7.1.1 The MySQL Mailing Lists . . . . . . . . . . . . . 24
1.7.1.2 Asking Questions or Reporting Bugs. . . . 27
1.7.1.3 How to Report Bugs or Problems . . . . . . 27
1.7.1.4 Guidelines for Answering Questions on the
Mailing List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.7.2 MySQL Community Support on IRC (Internet Relay
Chat) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.8 How Standards-compatible Is MySQL?. . . . . . . . . . . . . . . . . . . 32
1.8.1 What Standards Does MySQL Follow? . . . . . . . . . . 33
1.8.2 Running MySQL in ANSI Mode . . . . . . . . . . . . . . . . 33
1.8.3 MySQL Extensions To The SQL-92 Standard . . . . 34
1.8.4 MySQL Differences Compared To SQL-92 . . . . . . . 36
1.8.4.1 SubSELECTs . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.8.4.2 SELECT INTO TABLE . . . . . . . . . . . . . . . . . . . 38
1.8.4.3 Transactions and Atomic Operations . . . 38
1.8.4.4 Stored Procedures and Triggers . . . . . . . . 41
1.8.4.5 Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.8.4.6 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
1.8.4.7 ‘--’ as the Start of a Comment. . . . . . . . . 43
1.8.5 How MySQL deals with constraints . . . . . . . . . . . . . 43
1.8.5.1 Constraint PRIMARY KEY / UNIQUE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.8.5.2 Constraint NOT NULL and DEFAULT values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.8.5.3 Constraint ENUM and SET . . . . . . . . . . . . . . 45
1.8.6 Known Errors and Design Deficiencies in MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.8.6.1 Errors in 3.23 Fixed in a Later MySQL
Version. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.8.6.2 Open Bugs / Design Deficiencies in MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.9 MySQL and The Future (The TODO) . . . . . . . . . . . . . . . . . . . 50
1.9.1 New Features Planned For 4.1 . . . . . . . . . . . . . . . . . . 50
1.9.2 New Features Planned For 5.0 . . . . . . . . . . . . . . . . . . 50
1.9.3 New Features Planned For 5.1 . . . . . . . . . . . . . . . . . . 51
1.9.4 New Features Planned For The Near Future . . . . . 52
1.9.5 New Features Planned For The Mid-Term Future
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.9.6 New Features We Don’t Plan To Do . . . . . . . . . . . . 56
1.10 How MySQL Compares to Other Databases . . . . . . . . . . . . . 56
1.10.1 How MySQL Compares to mSQL . . . . . . . . . . . . . . . 56
1.10.1.1 How to Convert mSQL Tools for MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
iii

1.10.1.2 How mSQL and MySQL Client/Server


Communications Protocols Differ . . . . . . . . . . . 59
1.10.1.3 How mSQL 2.0 SQL Syntax Differs from
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.10.2 How MySQL Compares to PostgreSQL . . . . . . . . . 62
1.10.2.1 MySQL and PostgreSQL development
strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
1.10.2.2 Featurewise Comparison of MySQL and
PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
1.10.2.3 Benchmarking MySQL and PostgreSQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

2 MySQL Installation . . . . . . . . . . . . . . . . . . . . . . . 71
2.1 Quick Standard Installation of MySQL. . . . . . . . . . . . . . . . . . . 71
2.1.1 Installing MySQL on Linux. . . . . . . . . . . . . . . . . . . . . 71
2.1.2 Installing MySQL on Windows . . . . . . . . . . . . . . . . . 73
2.1.2.1 Installing the Binaries . . . . . . . . . . . . . . . . . 74
2.1.2.2 Preparing the Windows MySQL
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
2.1.2.3 Starting the Server for the First Time . . 76
2.1.3 Installing MySQL on Mac OS X . . . . . . . . . . . . . . . . 76
2.1.4 Installing MySQL on NetWare . . . . . . . . . . . . . . . . . . 78
2.1.4.1 Installing the MySQL for NetWare Binaries
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
2.2 General Installation Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.2.1 How to Get MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.2.2 Verifying Package Integrity Using MD5 Checksums or
GnuPG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.2.3 Operating Systems Supported by MySQL . . . . . . . 82
2.2.4 Which MySQL Version to Use . . . . . . . . . . . . . . . . . . 84
2.2.5 Installation Layouts. . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
2.2.6 How and When Updates Are Released. . . . . . . . . . . 87
2.2.7 Release Philosophy - No Known Bugs in Releases
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
2.2.8 MySQL Binaries Compiled by MySQL AB. . . . . . . 89
2.2.9 Installing a MySQL Binary Distribution . . . . . . . . . 93
2.3 Installing a MySQL Source Distribution. . . . . . . . . . . . . . . . . . 96
2.3.1 Quick Installation Overview . . . . . . . . . . . . . . . . . . . . 97
2.3.2 Applying Patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
2.3.3 Typical configure Options . . . . . . . . . . . . . . . . . . . 100
2.3.4 Installing from the Development Source Tree . . . 102
2.3.5 Problems Compiling MySQL? . . . . . . . . . . . . . . . . . 105
2.3.6 MIT-pthreads Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 108
2.3.7 Windows Source Distribution . . . . . . . . . . . . . . . . . . 109
2.4 Post-installation Setup and Testing . . . . . . . . . . . . . . . . . . . . . 110
2.4.1 Problems Running mysql_install_db . . . . . . . . . 114
2.4.2 Problems Starting the MySQL Server . . . . . . . . . . 115
2.4.3 Starting and Stopping MySQL Automatically . . . 117
iv

2.5 Upgrading/Downgrading MySQL . . . . . . . . . . . . . . . . . . . . . . . 118


2.5.1 Upgrading From Version 4.0 to 4.1 . . . . . . . . . . . . . 119
2.5.1.1 Preparing to Upgrade From Version 4.0 to
4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
2.5.1.2 What to do when upgrading from 4.0 to 4.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
2.5.2 Upgrading From Version 3.23 to 4.0 . . . . . . . . . . . . 121
2.5.3 Upgrading From Version 3.22 to 3.23 . . . . . . . . . . . 124
2.5.4 Upgrading from Version 3.21 to 3.22 . . . . . . . . . . . 126
2.5.5 Upgrading from Version 3.20 to 3.21 . . . . . . . . . . . 126
2.5.6 Upgrading to Another Architecture . . . . . . . . . . . . 127
2.5.7 Upgrading MySQL under Windows . . . . . . . . . . . . 128
2.6 Operating System Specific Notes . . . . . . . . . . . . . . . . . . . . . . . 129
2.6.1 Linux Notes (All Linux Versions) . . . . . . . . . . . . . . 129
2.6.1.1 Linux Notes for Binary Distributions . . 132
2.6.1.2 Linux x86 Notes . . . . . . . . . . . . . . . . . . . . . 134
2.6.1.3 Linux SPARC Notes . . . . . . . . . . . . . . . . . 134
2.6.1.4 Linux Alpha Notes . . . . . . . . . . . . . . . . . . . 135
2.6.1.5 Linux PowerPC Notes . . . . . . . . . . . . . . . . 135
2.6.1.6 Linux MIPS Notes . . . . . . . . . . . . . . . . . . . 136
2.6.1.7 Linux IA-64 Notes . . . . . . . . . . . . . . . . . . . 136
2.6.2 Windows Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
2.6.2.1 Starting MySQL on Windows 95, 98, or Me
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
2.6.2.2 Starting MySQL on Windows NT, 2000, or
XP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
2.6.2.3 Running MySQL on Windows. . . . . . . . . 138
2.6.2.4 Connecting to MySQL Remotely from
Windows with SSH . . . . . . . . . . . . . . . . . . . . . . 140
2.6.2.5 Distributing Data Across Different Disks on
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
2.6.2.6 Compiling MySQL Clients on Windows
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
2.6.2.7 MySQL for Windows Compared to Unix
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
2.6.3 Solaris Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
2.6.3.1 Solaris 2.7/2.8 Notes . . . . . . . . . . . . . . . . . 146
2.6.3.2 Solaris x86 Notes . . . . . . . . . . . . . . . . . . . . 147
2.6.4 BSD Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
2.6.4.1 FreeBSD Notes . . . . . . . . . . . . . . . . . . . . . . 147
2.6.4.2 NetBSD Notes . . . . . . . . . . . . . . . . . . . . . . . 149
2.6.4.3 OpenBSD 2.5 Notes . . . . . . . . . . . . . . . . . . 149
2.6.4.4 OpenBSD 2.8 Notes . . . . . . . . . . . . . . . . . . 149
2.6.4.5 BSD/OS Version 2.x Notes . . . . . . . . . . . 149
2.6.4.6 BSD/OS Version 3.x Notes . . . . . . . . . . . 150
2.6.4.7 BSD/OS Version 4.x Notes . . . . . . . . . . . 150
2.6.5 Mac OS X Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
2.6.5.1 Mac OS X 10.x . . . . . . . . . . . . . . . . . . . . . . 151
v

2.6.5.2 Mac OS X Server 1.2 (Rhapsody) . . . . . 151


2.6.6 Other Unix Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
2.6.6.1 HP-UX Notes for Binary Distributions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
2.6.6.2 HP-UX Version 10.20 Notes. . . . . . . . . . . 152
2.6.6.3 HP-UX Version 11.x Notes. . . . . . . . . . . . 152
2.6.6.4 IBM-AIX notes . . . . . . . . . . . . . . . . . . . . . . 154
2.6.6.5 SunOS 4 Notes . . . . . . . . . . . . . . . . . . . . . . 155
2.6.6.6 Alpha-DEC-UNIX Notes (Tru64). . . . . . 156
2.6.6.7 Alpha-DEC-OSF/1 Notes . . . . . . . . . . . . . 157
2.6.6.8 SGI Irix Notes . . . . . . . . . . . . . . . . . . . . . . . 158
2.6.6.9 SCO Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 159
2.6.6.10 SCO UnixWare Version 7.1.x Notes . . 161
2.6.7 OS/2 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
2.6.8 Novell NetWare Notes . . . . . . . . . . . . . . . . . . . . . . . . 162
2.6.9 BeOS Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
2.7 Perl Installation Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
2.7.1 Installing Perl on Unix . . . . . . . . . . . . . . . . . . . . . . . . 163
2.7.2 Installing ActiveState Perl on Windows . . . . . . . . 164
2.7.3 Installing the MySQL Perl Distribution on Windows
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
2.7.4 Problems Using the Perl DBI/DBD Interface . . . . . 164

3 Tutorial Introduction . . . . . . . . . . . . . . . . . . . . 167


3.1 Connecting to and Disconnecting from the Server . . . . . . . . 167
3.2 Entering Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
3.3 Creating and Using a Database. . . . . . . . . . . . . . . . . . . . . . . . . 171
3.3.1 Creating and Selecting a Database . . . . . . . . . . . . . 172
3.3.2 Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
3.3.3 Loading Data into a Table . . . . . . . . . . . . . . . . . . . . 174
3.3.4 Retrieving Information from a Table . . . . . . . . . . . 175
3.3.4.1 Selecting All Data . . . . . . . . . . . . . . . . . . . 175
3.3.4.2 Selecting Particular Rows . . . . . . . . . . . . . 176
3.3.4.3 Selecting Particular Columns . . . . . . . . . 177
3.3.4.4 Sorting Rows . . . . . . . . . . . . . . . . . . . . . . . . 179
3.3.4.5 Date Calculations . . . . . . . . . . . . . . . . . . . . 180
3.3.4.6 Working with NULL Values . . . . . . . . . . . . 183
3.3.4.7 Pattern Matching . . . . . . . . . . . . . . . . . . . . 183
3.3.4.8 Counting Rows . . . . . . . . . . . . . . . . . . . . . . 186
3.3.4.9 Using More Than one Table . . . . . . . . . . 188
3.4 Getting Information About Databases and Tables . . . . . . . 190
3.5 Examples of Common Queries . . . . . . . . . . . . . . . . . . . . . . . . . . 191
3.5.1 The Maximum Value for a Column . . . . . . . . . . . . 192
3.5.2 The Row Holding the Maximum of a Certain
Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
3.5.3 Maximum of Column per Group . . . . . . . . . . . . . . . 192
3.5.4 The Rows Holding the Group-wise Maximum of a
Certain Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
vi

3.5.5 Using user variables. . . . . . . . . . . . . . . . . . . . . . . . . . . 194


3.5.6 Using Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
3.5.7 Searching on Two Keys . . . . . . . . . . . . . . . . . . . . . . . 196
3.5.8 Calculating Visits Per Day . . . . . . . . . . . . . . . . . . . . 196
3.5.9 Using AUTO_INCREMENT. . . . . . . . . . . . . . . . . . . . . . . . 197
3.6 Using mysql in Batch Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
3.7 Queries from Twin Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
3.7.1 Find all Non-distributed Twins . . . . . . . . . . . . . . . . 200
3.7.2 Show a Table on Twin Pair Status . . . . . . . . . . . . . 202
3.8 Using MySQL with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

4 Database Administration . . . . . . . . . . . . . . . . . 204


4.1 Configuring MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
4.1.1 mysqld Command-line Options . . . . . . . . . . . . . . . . 204
4.1.2 ‘my.cnf’ Option Files . . . . . . . . . . . . . . . . . . . . . . . . . 211
4.1.3 Running Multiple MySQL Servers on the Same
Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
4.1.3.1 Running Multiple Servers on Windows
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
4.1.3.2 Running Multiple Servers on Unix . . . . . 218
4.1.3.3 Using Client Programs in a Multiple-Server
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
4.2 General Security Issues and the MySQL Access Privilege
System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
4.2.1 General Security Guidelines . . . . . . . . . . . . . . . . . . . 220
4.2.2 How to Make MySQL Secure Against Crackers . . 223
4.2.3 Startup Options for mysqld Concerning Security
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
4.2.4 Security issues with LOAD DATA LOCAL . . . . . . . . . . 225
4.2.5 What the Privilege System Does . . . . . . . . . . . . . . . 226
4.2.6 How the Privilege System Works. . . . . . . . . . . . . . . 226
4.2.7 Privileges Provided by MySQL . . . . . . . . . . . . . . . . 229
4.2.8 Connecting to the MySQL Server . . . . . . . . . . . . . . 232
4.2.9 Access Control, Stage 1: Connection Verification
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
4.2.10 Access Control, Stage 2: Request Verification . . 236
4.2.11 Password Hashing in MySQL 4.1 . . . . . . . . . . . . . 238
4.2.12 Causes of Access denied Errors . . . . . . . . . . . . . . 242
4.3 MySQL User Account Management . . . . . . . . . . . . . . . . . . . . . 246
4.3.1 GRANT and REVOKE Syntax . . . . . . . . . . . . . . . . . . . . . 247
4.3.2 MySQL User Names and Passwords . . . . . . . . . . . . 251
4.3.3 When Privilege Changes Take Effect . . . . . . . . . . . 252
4.3.4 Setting Up the Initial MySQL Privileges. . . . . . . . 252
4.3.5 Adding New Users to MySQL . . . . . . . . . . . . . . . . . 254
4.3.6 Limiting user resources. . . . . . . . . . . . . . . . . . . . . . . . 256
4.3.7 Setting Up Passwords . . . . . . . . . . . . . . . . . . . . . . . . . 257
4.3.8 Keeping Your Password Secure . . . . . . . . . . . . . . . . 258
4.3.9 Using Secure Connections . . . . . . . . . . . . . . . . . . . . . 259
vii

4.3.9.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259


4.3.9.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . 260
4.3.9.3 Setting Up SSL Certificates for MySQL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
4.3.9.4 GRANT Options . . . . . . . . . . . . . . . . . . . . . . . 264
4.4 Disaster Prevention and Recovery . . . . . . . . . . . . . . . . . . . . . . 266
4.4.1 Database Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
4.4.2 BACKUP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 267
4.4.3 RESTORE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 267
4.4.4 CHECK TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 268
4.4.5 REPAIR TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 269
4.4.6 Using myisamchk for Table Maintenance and Crash
Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
4.4.6.1 myisamchk Invocation Syntax . . . . . . . . . 271
4.4.6.2 General Options for myisamchk . . . . . . . 272
4.4.6.3 Check Options for myisamchk . . . . . . . . . 273
4.4.6.4 Repair Options for myisamchk . . . . . . . . 274
4.4.6.5 Other Options for myisamchk . . . . . . . . . 275
4.4.6.6 myisamchk Memory Usage . . . . . . . . . . . . 275
4.4.6.7 Using myisamchk for Crash Recovery . . 276
4.4.6.8 How to Check Tables for Errors . . . . . . . 277
4.4.6.9 How to Repair Tables . . . . . . . . . . . . . . . . 278
4.4.6.10 Table Optimisation . . . . . . . . . . . . . . . . . 280
4.4.7 Setting Up a Table Maintenance Regimen . . . . . . 280
4.4.8 Getting Information About a Table . . . . . . . . . . . . 281
4.5 Database Administration Language Reference . . . . . . . . . . . 286
4.5.1 OPTIMIZE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . 286
4.5.2 ANALYZE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 287
4.5.3 FLUSH Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
4.5.4 RESET Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
4.5.5 PURGE MASTER LOGS Syntax . . . . . . . . . . . . . . . . . . . . 289
4.5.6 KILL Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
4.5.7 SHOW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
4.5.7.1 Retrieving information about Database,
Tables, Columns, and Indexes . . . . . . . . . . . . . 290
4.5.7.2 SHOW TABLE STATUS . . . . . . . . . . . . . . . . . . 292
4.5.7.3 SHOW STATUS . . . . . . . . . . . . . . . . . . . . . . . . . 292
4.5.7.4 SHOW VARIABLES . . . . . . . . . . . . . . . . . . . . . 296
4.5.7.5 SHOW [BDB] LOGS . . . . . . . . . . . . . . . . . . . . . 306
4.5.7.6 SHOW PROCESSLIST . . . . . . . . . . . . . . . . . . . 306
4.5.7.7 SHOW GRANTS . . . . . . . . . . . . . . . . . . . . . . . . . 308
4.5.7.8 SHOW CREATE TABLE . . . . . . . . . . . . . . . . . . 308
4.5.7.9 SHOW WARNINGS | ERRORS . . . . . . . . . . . . . 308
4.5.7.10 SHOW TABLE TYPES . . . . . . . . . . . . . . . . . . 310
4.5.7.11 SHOW PRIVILEGES . . . . . . . . . . . . . . . . . . . 311
4.6 MySQL Localisation and International Usage. . . . . . . . . . . . 311
4.6.1 The Character Set Used for Data and Sorting . . . 311
4.6.1.1 German character set . . . . . . . . . . . . . . . . 312
viii

4.6.2 Non-English Error Messages . . . . . . . . . . . . . . . . . . . 312


4.6.3 Adding a New Character Set . . . . . . . . . . . . . . . . . . 313
4.6.4 The Character Definition Arrays . . . . . . . . . . . . . . . 314
4.6.5 String Collating Support . . . . . . . . . . . . . . . . . . . . . . 315
4.6.6 Multi-byte Character Support . . . . . . . . . . . . . . . . . 315
4.6.7 Problems With Character Sets. . . . . . . . . . . . . . . . . 315
4.7 MySQL Server-Side Scripts and Utilities . . . . . . . . . . . . . . . . 316
4.7.1 Overview of the Server-Side Scripts and Utilities
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
4.7.2 mysqld_safe, The Wrapper Around mysqld . . . . 317
4.7.3 mysqld_multi, A Program for Managing Multiple
MySQL Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
4.7.4 myisampack, The MySQL Compressed Read-only
Table Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
4.7.5 mysqld-max, An Extended mysqld Server. . . . . . . 328
4.8 MySQL Client-Side Scripts and Utilities . . . . . . . . . . . . . . . . 330
4.8.1 Overview of the Client-Side Scripts and Utilities
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
4.8.2 mysql, The Command-line Tool. . . . . . . . . . . . . . . . 331
4.8.3 mysqladmin, Administrating a MySQL Server . . 339
4.8.4 Using mysqlcheck for Table Maintenance and Crash
Recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
4.8.5 mysqldump, Dumping Table Structure and Data
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
4.8.6 mysqlhotcopy, Copying MySQL Databases and
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
4.8.7 mysqlimport, Importing Data from Text Files . . 348
4.8.8 mysqlshow, Showing Databases, Tables, and
Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
4.8.9 mysql_config, Get compile options for compiling
clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
4.8.10 perror, Explaining Error Codes . . . . . . . . . . . . . . 352
4.8.11 How to Run SQL Commands from a Text File . . 352
4.9 The MySQL Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
4.9.1 The Error Log. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
4.9.2 The General Query Log . . . . . . . . . . . . . . . . . . . . . . . 353
4.9.3 The Update Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
4.9.4 The Binary Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
4.9.5 The Slow Query Log . . . . . . . . . . . . . . . . . . . . . . . . . . 357
4.9.6 Log File Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . 357
4.10 Replication in MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
4.10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
4.10.2 Replication Implementation Overview . . . . . . . . . 358
4.10.3 Replication Implementation Details . . . . . . . . . . . 360
4.10.4 How To Set Up Replication . . . . . . . . . . . . . . . . . . 361
4.10.5 Replication Features and Known Problems . . . . 364
4.10.6 Replication Options in ‘my.cnf’ . . . . . . . . . . . . . . 367
4.10.7 SQL Commands Related to Replication . . . . . . . 374
ix

4.10.7.1 START SLAVE (slave) . . . . . . . . . . . . . . . . . 375


4.10.7.2 STOP SLAVE (slave) . . . . . . . . . . . . . . . . . . 375
4.10.7.3 SET SQL_LOG_BIN=0|1 (master) . . . . . . 375
4.10.7.4 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n
(slave) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
4.10.7.5 RESET MASTER (master) . . . . . . . . . . . . . . 375
4.10.7.6 RESET SLAVE (slave) . . . . . . . . . . . . . . . . . 375
4.10.7.7 LOAD TABLE tblname FROM MASTER (slave)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
4.10.7.8 LOAD DATA FROM MASTER (slave). . . . . . . 376
4.10.7.9 CHANGE MASTER TO master_def_list
(slave) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
4.10.7.10 MASTER_POS_WAIT() (slave) . . . . . . . . . 378
4.10.7.11 SHOW MASTER STATUS (master). . . . . . . 378
4.10.7.12 SHOW SLAVE HOSTS (master) . . . . . . . . . 378
4.10.7.13 SHOW SLAVE STATUS (slave) . . . . . . . . . 378
4.10.7.14 SHOW MASTER LOGS (master) . . . . . . . . . 380
4.10.7.15 SHOW BINLOG EVENTS (master). . . . . . . 380
4.10.7.16 PURGE MASTER LOGS (master) . . . . . . . . 380
4.10.8 Replication FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
4.10.9 Troubleshooting Replication . . . . . . . . . . . . . . . . . . 385

5 MySQL Optimisation . . . . . . . . . . . . . . . . . . . . 388


5.1 Optimisation Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
5.1.1 MySQL Design Limitations/Tradeoffs . . . . . . . . . . 388
5.1.2 Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
5.1.3 What Have We Used MySQL For? . . . . . . . . . . . . . 390
5.1.4 The MySQL Benchmark Suite . . . . . . . . . . . . . . . . . 391
5.1.5 Using Your Own Benchmarks. . . . . . . . . . . . . . . . . . 392
5.2 Optimising SELECTs and Other Queries . . . . . . . . . . . . . . . . . 392
5.2.1 EXPLAIN Syntax (Get Information About a SELECT)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
5.2.2 Estimating Query Performance . . . . . . . . . . . . . . . . 399
5.2.3 Speed of SELECT Queries . . . . . . . . . . . . . . . . . . . . . . 400
5.2.4 How MySQL Optimises WHERE Clauses . . . . . . . . . 400
5.2.5 How MySQL Optimises IS NULL . . . . . . . . . . . . . . . 402
5.2.6 How MySQL Optimises DISTINCT. . . . . . . . . . . . . . 403
5.2.7 How MySQL Optimises LEFT JOIN and RIGHT JOIN
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
5.2.8 How MySQL Optimises ORDER BY . . . . . . . . . . . . . . 404
5.2.9 How MySQL Optimises LIMIT . . . . . . . . . . . . . . . . . 406
5.2.10 Speed of INSERT Queries . . . . . . . . . . . . . . . . . . . . . 406
5.2.11 Speed of UPDATE Queries . . . . . . . . . . . . . . . . . . . . . 408
5.2.12 Speed of DELETE Queries . . . . . . . . . . . . . . . . . . . . . 408
5.2.13 Other Optimisation Tips . . . . . . . . . . . . . . . . . . . . . 408
5.3 Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
5.3.1 How MySQL Locks Tables . . . . . . . . . . . . . . . . . . . . 411
5.3.2 Table Locking Issues . . . . . . . . . . . . . . . . . . . . . . . . . . 412
x

5.4 Optimising Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . 413


5.4.1 Design Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
5.4.2 Get Your Data as Small as Possible . . . . . . . . . . . . 414
5.4.3 How MySQL Uses Indexes . . . . . . . . . . . . . . . . . . . . 415
5.4.4 Column Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
5.4.5 Multiple-Column Indexes. . . . . . . . . . . . . . . . . . . . . . 417
5.4.6 Why So Many Open tables? . . . . . . . . . . . . . . . . . . . 418
5.4.7 How MySQL Opens and Closes Tables . . . . . . . . . 419
5.4.8 Drawbacks to Creating Large Numbers of Tables in
the Same Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
5.5 Optimising the MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . 420
5.5.1 System/Compile Time and Startup Parameter
Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
5.5.2 Tuning Server Parameters . . . . . . . . . . . . . . . . . . . . . 421
5.5.3 How Compiling and Linking Affects the Speed of
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
5.5.4 How MySQL Uses Memory . . . . . . . . . . . . . . . . . . . . 424
5.5.5 How MySQL uses DNS . . . . . . . . . . . . . . . . . . . . . . . 425
5.5.6 SET Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
5.6 Disk Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
5.6.1 Using Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . 431
5.6.1.1 Using Symbolic Links for Databases . . . 431
5.6.1.2 Using Symbolic Links for Tables . . . . . . 431

6 MySQL Language Reference . . . . . . . . . . . . . 433


6.1 Language Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
6.1.1 Literals: How to Write Strings and Numbers . . . . 433
6.1.1.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
6.1.1.2 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
6.1.1.3 Hexadecimal Values . . . . . . . . . . . . . . . . . . 435
6.1.1.4 NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . 435
6.1.2 Database, Table, Index, Column, and Alias Names
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
6.1.3 Case Sensitivity in Names . . . . . . . . . . . . . . . . . . . . . 437
6.1.4 User Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
6.1.5 System Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
6.1.6 Comment Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
6.1.7 Is MySQL Picky About Reserved Words?. . . . . . . 442
6.2 Column Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
6.2.1 Numeric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
6.2.2 Date and Time Types . . . . . . . . . . . . . . . . . . . . . . . . . 451
6.2.2.1 Y2K Issues and Date Types. . . . . . . . . . . 452
6.2.2.2 The DATETIME, DATE, and TIMESTAMP Types
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
6.2.2.3 The TIME Type . . . . . . . . . . . . . . . . . . . . . . 456
6.2.2.4 The YEAR Type . . . . . . . . . . . . . . . . . . . . . . 457
6.2.3 String Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
6.2.3.1 The CHAR and VARCHAR Types . . . . . . . . . 458
xi

6.2.3.2 The BLOB and TEXT Types . . . . . . . . . . . . 458


6.2.3.3 The ENUM Type . . . . . . . . . . . . . . . . . . . . . . 459
6.2.3.4 The SET Type . . . . . . . . . . . . . . . . . . . . . . . 461
6.2.4 Choosing the Right Type for a Column. . . . . . . . . 462
6.2.5 Using Column Types from Other Database Engines
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
6.2.6 Column Type Storage Requirements . . . . . . . . . . . 463
6.3 Functions for Use in SELECT and WHERE Clauses . . . . . . . . . 464
6.3.1 Non-Type-Specific Operators and Functions . . . . 465
6.3.1.1 Parentheses. . . . . . . . . . . . . . . . . . . . . . . . . . 465
6.3.1.2 Comparison Operators . . . . . . . . . . . . . . . 465
6.3.1.3 Logical Operators . . . . . . . . . . . . . . . . . . . . 468
6.3.1.4 Control Flow Functions. . . . . . . . . . . . . . . 470
6.3.2 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
6.3.2.1 String Comparison Functions . . . . . . . . . 479
6.3.2.2 Case-Sensitivity . . . . . . . . . . . . . . . . . . . . . . 482
6.3.3 Numeric Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
6.3.3.1 Arithmetic Operations . . . . . . . . . . . . . . . 482
6.3.3.2 Mathematical Functions . . . . . . . . . . . . . . 483
6.3.4 Date and Time Functions . . . . . . . . . . . . . . . . . . . . . 489
6.3.5 Cast Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
6.3.6 Other Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
6.3.6.1 Bit Functions . . . . . . . . . . . . . . . . . . . . . . . . 499
6.3.6.2 Miscellaneous Functions . . . . . . . . . . . . . . 500
6.3.7 Functions and Modifiers for Use with GROUP BY
Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
6.3.7.1 GROUP BY Functions . . . . . . . . . . . . . . . . . . 507
6.3.7.2 GROUP BY Modifiers . . . . . . . . . . . . . . . . . . . 510
6.4 Data Manipulation: SELECT, INSERT, UPDATE, DELETE . . . . 513
6.4.1 SELECT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
6.4.1.1 JOIN Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 518
6.4.1.2 UNION Syntax . . . . . . . . . . . . . . . . . . . . . . . . 520
6.4.2 HANDLER Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
6.4.3 INSERT Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
6.4.3.1 INSERT ... SELECT Syntax . . . . . . . . . . . 524
6.4.4 INSERT DELAYED Syntax . . . . . . . . . . . . . . . . . . . . . . . 524
6.4.5 UPDATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
6.4.6 DELETE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
6.4.7 TRUNCATE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
6.4.8 REPLACE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
6.4.9 LOAD DATA INFILE Syntax . . . . . . . . . . . . . . . . . . . . . 530
6.4.10 DO Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
6.5 Data Definition: CREATE, DROP, ALTER . . . . . . . . . . . . . . . . . . 537
6.5.1 CREATE DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . 537
6.5.2 DROP DATABASE Syntax . . . . . . . . . . . . . . . . . . . . . . . . 537
6.5.3 CREATE TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 537
6.5.3.1 Silent Column Specification Changes . . 545
6.5.4 ALTER TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 546
xii

6.5.5 RENAME TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 550


6.5.6 DROP TABLE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
6.5.7 CREATE INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 551
6.5.8 DROP INDEX Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
6.6 Basic MySQL User Utility Commands . . . . . . . . . . . . . . . . . . 551
6.6.1 USE Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
6.6.2 DESCRIBE Syntax (Get Information About Columns)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
6.7 MySQL Transactional and Locking Commands . . . . . . . . . . 552
6.7.1 BEGIN/COMMIT/ROLLBACK Syntax . . . . . . . . . . . . . . . 552
6.7.2 LOCK TABLES/UNLOCK TABLES Syntax . . . . . . . . . . . 553
6.7.3 SET TRANSACTION Syntax . . . . . . . . . . . . . . . . . . . . . . 555
6.8 MySQL Full-text Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
6.8.1 Full-text Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . 559
6.8.2 Fine-tuning MySQL Full-text Search . . . . . . . . . . . 559
6.8.3 Full-text Search TODO . . . . . . . . . . . . . . . . . . . . . . . 560
6.9 MySQL Query Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
6.9.1 How The Query Cache Operates . . . . . . . . . . . . . . . 561
6.9.2 Query Cache Configuration . . . . . . . . . . . . . . . . . . . . 562
6.9.3 Query Cache Options in SELECT . . . . . . . . . . . . . . . 563
6.9.4 Query Cache Status and Maintenance . . . . . . . . . . 563

7 MySQL Table Types . . . . . . . . . . . . . . . . . . . . . 565


7.1 MyISAM Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
7.1.1 Space Needed for Keys . . . . . . . . . . . . . . . . . . . . . . . . 568
7.1.2 MyISAM Table Formats . . . . . . . . . . . . . . . . . . . . . . . . 568
7.1.2.1 Static (Fixed-length) Table Characteristics
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
7.1.2.2 Dynamic Table Characteristics . . . . . . . . 569
7.1.2.3 Compressed Table Characteristics . . . . . 570
7.1.3 MyISAM Table Problems . . . . . . . . . . . . . . . . . . . . . . . 570
7.1.3.1 Corrupted MyISAM Tables . . . . . . . . . . . . . 571
7.1.3.2 Clients is using or hasn’t closed the table
properly. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
7.2 MERGE Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
7.2.1 MERGE Table Problems . . . . . . . . . . . . . . . . . . . . . . . . 574
7.3 ISAM Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
7.4 HEAP Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
7.5 InnoDB Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
7.5.1 InnoDB Tables Overview . . . . . . . . . . . . . . . . . . . . . . 577
7.5.2 InnoDB in MySQL Version 3.23 . . . . . . . . . . . . . . . 577
7.5.3 InnoDB Startup Options . . . . . . . . . . . . . . . . . . . . . . 578
7.5.4 Creating InnoDB Tablespace . . . . . . . . . . . . . . . . . . 584
7.5.4.1 If Something Goes Wrong in Database
Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
7.5.5 Creating InnoDB Tables . . . . . . . . . . . . . . . . . . . . . . 585
7.5.5.1 Converting MyISAM Tables to InnoDB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
xiii

7.5.5.2 Foreign Key Constraints . . . . . . . . . . . . . . 586


7.5.6 Adding and Removing InnoDB Data and Log Files
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
7.5.7 Backing up and Recovering an InnoDB Database
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
7.5.7.1 Checkpoints . . . . . . . . . . . . . . . . . . . . . . . . . 590
7.5.8 Moving an InnoDB Database to Another Machine
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
7.5.9 InnoDB Transaction Model . . . . . . . . . . . . . . . . . . . . 591
7.5.9.1 Consistent Read . . . . . . . . . . . . . . . . . . . . . 593
7.5.9.2 Locking Reads . . . . . . . . . . . . . . . . . . . . . . . 593
7.5.9.3 Next-key Locking: Avoiding the Phantom
Problem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
7.5.9.4 Locks Set by Different SQL Statements in
InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
7.5.9.5 Deadlock Detection and Rollback. . . . . . 596
7.5.9.6 An Example of How the Consistent Read
Works in InnoDB . . . . . . . . . . . . . . . . . . . . . . . . 596
7.5.9.7 How to cope with deadlocks? . . . . . . . . . 597
7.5.9.8 Performance Tuning Tips . . . . . . . . . . . . . 598
7.5.9.9 The InnoDB Monitor . . . . . . . . . . . . . . . . . 599
7.5.10 Implementation of Multi-versioning . . . . . . . . . . . 601
7.5.11 Table and Index Structures . . . . . . . . . . . . . . . . . . . 602
7.5.11.1 Physical Structure of an Index . . . . . . . 603
7.5.11.2 Insert Buffering . . . . . . . . . . . . . . . . . . . . . 603
7.5.11.3 Adaptive Hash Indexes . . . . . . . . . . . . . . 603
7.5.11.4 Physical Record Structure . . . . . . . . . . . 603
7.5.11.5 How an Auto-increment Column Works in
InnoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
7.5.12 File Space Management and Disk I/O . . . . . . . . . 604
7.5.12.1 Disk I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
7.5.12.2 File Space Management . . . . . . . . . . . . . 605
7.5.12.3 Defragmenting a Table . . . . . . . . . . . . . . 606
7.5.13 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
7.5.14 Restrictions on InnoDB Tables . . . . . . . . . . . . . . . 606
7.5.15 InnoDB Change History. . . . . . . . . . . . . . . . . . . . . . 608
7.5.15.1 MySQL/InnoDB-4.0.14, June x, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
7.5.15.2 MySQL/InnoDB-4.0.13, May 20, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
7.5.15.3 MySQL/InnoDB-4.1.0, April 3, 2003 . . 609
7.5.15.4 MySQL/InnoDB-3.23.56, March 17, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
7.5.15.5 MySQL/InnoDB-4.0.12, March 18, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
7.5.15.6 MySQL/InnoDB-4.0.11, February 25, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
xiv

7.5.15.7 MySQL/InnoDB-4.0.10, February 4, 2003


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
7.5.15.8 MySQL/InnoDB-3.23.55, January 24, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
7.5.15.9 MySQL/InnoDB-4.0.9, January 14, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
7.5.15.10 MySQL/InnoDB-4.0.8, January 7, 2003
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
7.5.15.11 MySQL/InnoDB-4.0.7, December 26,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
7.5.15.12 MySQL/InnoDB-4.0.6, December 19,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
7.5.15.13 MySQL/InnoDB-3.23.54, December 12,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
7.5.15.14 MySQL/InnoDB-4.0.5, November 18,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
7.5.15.15 MySQL/InnoDB-3.23.53, October 9, 2002
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
7.5.15.16 MySQL/InnoDB-4.0.4, October 2, 2002
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
7.5.15.17 MySQL/InnoDB-4.0.3, August 28, 2002
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
7.5.15.18 MySQL/InnoDB-3.23.52, August 16,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
7.5.15.19 MySQL/InnoDB-4.0.2, July 10, 2002
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
7.5.15.20 MySQL/InnoDB-3.23.51, June 12, 2002
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
7.5.15.21 MySQL/InnoDB-3.23.50, April 23, 2002
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
7.5.15.22 MySQL/InnoDB-3.23.49, February 17,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
7.5.15.23 MySQL/InnoDB-3.23.48, February 9,
2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
7.5.15.24 MySQL/InnoDB-3.23.47, December 28,
2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
7.5.15.25 MySQL/InnoDB-4.0.1, December 23,
2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
7.5.15.26 MySQL/InnoDB-3.23.46, November 30,
2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
7.5.15.27 MySQL/InnoDB-3.23.45, November 23,
2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
7.5.15.28 MySQL/InnoDB-3.23.44, November 2,
2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
7.5.15.29 MySQL/InnoDB-3.23.43, October 4, 2001
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
7.5.15.30 MySQL/InnoDB-3.23.42, September 9,
2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
xv

7.5.15.31 MySQL/InnoDB-3.23.41, August 13,


2001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
7.5.15.32 MySQL/InnoDB-3.23.40, July 16, 2001
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
7.5.15.33 MySQL/InnoDB-3.23.39, June 13, 2001
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
7.5.15.34 MySQL/InnoDB-3.23.38, May 12, 2001
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
7.5.16 InnoDB Contact Information . . . . . . . . . . . . . . . . . 622
7.6 BDB or BerkeleyDB Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
7.6.1 Overview of BDB Tables . . . . . . . . . . . . . . . . . . . . . . . 622
7.6.2 Installing BDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
7.6.3 BDB startup options . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
7.6.4 Characteristics of BDB tables: . . . . . . . . . . . . . . . . . . 624
7.6.5 Things we need to fix for BDB in the near future:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
7.6.6 Operating systems supported by BDB . . . . . . . . . . . 625
7.6.7 Restrictions on BDB Tables . . . . . . . . . . . . . . . . . . . . 626
7.6.8 Errors That May Occur When Using BDB Tables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626

8 National Character Sets and Unicode in


MySQL 4.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
8.1 Character Sets and Collations in General. . . . . . . . . . . . . . . . 628
8.2 Character Sets and Collations in MySQL . . . . . . . . . . . . . . . 629
8.3 Determining The Default Character Set And Collation . . . 629
8.3.1 Server Character Set and Collation . . . . . . . . . . . . 629
8.3.2 Database Character Set and Collation . . . . . . . . . . 630
8.3.3 Table Character Set and Collation . . . . . . . . . . . . . 630
8.3.4 Column Character Set and Collation . . . . . . . . . . . 631
8.3.5 Examples of Character Set and Collation Assignment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
8.3.6 Connection Character Sets and Collations . . . . . . 633
8.3.7 Character String Literal Character Set and Collation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
8.3.8 COLLATE Clause in Various Parts of an SQL Query
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
8.3.9 COLLATE Clause Precedence . . . . . . . . . . . . . . . . . . . 635
8.3.10 BINARY Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
8.3.11 Some Special Cases Where the Collation
Determination is Tricky . . . . . . . . . . . . . . . . . . . . . . . . . 635
8.3.12 Collations Must Be for the Right Character Set
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
8.3.13 An example of the Effect of Collation . . . . . . . . . 636
8.4 Operations Affected by Character Set Support . . . . . . . . . . 637
8.4.1 Result Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
8.4.2 CONVERT() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
8.4.3 CAST() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
xvi

8.4.4 SHOW CHARACTER SET . . . . . . . . . . . . . . . . . . . . . . . . . . 638


8.4.5 SHOW COLLATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
8.4.6 SHOW CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . 639
8.4.7 SHOW FULL FIELDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
8.5 Unicode Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
8.6 UTF8 for Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
8.7 Compatibility with Other DBMSs . . . . . . . . . . . . . . . . . . . . . . 641
8.8 New Character Set Configuration File format. . . . . . . . . . . . 642
8.9 National Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642
8.10 Upgrading from MySQL 4.0. . . . . . . . . . . . . . . . . . . . . . . . . . . 642
8.10.1 4.0 Character Sets and Corresponding 4.1
Character Set/Collation Pairs. . . . . . . . . . . . . . . . . . . . 643
8.11 The Character Sets and Collations that MySQL Supports
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
8.11.1 The Unicode Character Sets . . . . . . . . . . . . . . . . . . 645
8.11.2 Platform Specific Character Sets . . . . . . . . . . . . . . 645
8.11.3 Character Sets for South Europe and Middle East
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
8.11.4 The Asian Character Sets . . . . . . . . . . . . . . . . . . . . 645
8.11.5 The Baltic Character Sets . . . . . . . . . . . . . . . . . . . . 646
8.11.6 The Cyrillic Character Sets. . . . . . . . . . . . . . . . . . . 646
8.11.7 The Central European Character Sets . . . . . . . . . 647
8.11.8 The West European Character Sets . . . . . . . . . . . 648

9 MySQL APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650


9.1 MySQL C API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
9.1.1 C API Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
9.1.2 C API Function Overview . . . . . . . . . . . . . . . . . . . . . 653
9.1.3 C API Function Descriptions . . . . . . . . . . . . . . . . . . 657
9.1.3.1 mysql_affected_rows() . . . . . . . . . . . . . 657
9.1.3.2 mysql_change_user() . . . . . . . . . . . . . . . 658
9.1.3.3 mysql_character_set_name(). . . . . . . . 659
9.1.3.4 mysql_close() . . . . . . . . . . . . . . . . . . . . . . 660
9.1.3.5 mysql_connect() . . . . . . . . . . . . . . . . . . . . 660
9.1.3.6 mysql_create_db(). . . . . . . . . . . . . . . . . . 661
9.1.3.7 mysql_data_seek(). . . . . . . . . . . . . . . . . . 662
9.1.3.8 mysql_debug() . . . . . . . . . . . . . . . . . . . . . . 662
9.1.3.9 mysql_drop_db() . . . . . . . . . . . . . . . . . . . . 663
9.1.3.10 mysql_dump_debug_info() . . . . . . . . . . 663
9.1.3.11 mysql_eof() . . . . . . . . . . . . . . . . . . . . . . . 664
9.1.3.12 mysql_errno() . . . . . . . . . . . . . . . . . . . . . 665
9.1.3.13 mysql_error() . . . . . . . . . . . . . . . . . . . . . 666
9.1.3.14 mysql_escape_string() . . . . . . . . . . . . 666
9.1.3.15 mysql_fetch_field() . . . . . . . . . . . . . . 666
9.1.3.16 mysql_fetch_fields() . . . . . . . . . . . . . 667
9.1.3.17 mysql_fetch_field_direct(). . . . . . . 668
9.1.3.18 mysql_fetch_lengths() . . . . . . . . . . . . 669
9.1.3.19 mysql_fetch_row() . . . . . . . . . . . . . . . . 669
xvii

9.1.3.20 mysql_field_count() . . . . . . . . . . . . . . 671


9.1.3.21 mysql_field_seek() . . . . . . . . . . . . . . . 672
9.1.3.22 mysql_field_tell() . . . . . . . . . . . . . . . 672
9.1.3.23 mysql_free_result() . . . . . . . . . . . . . . 673
9.1.3.24 mysql_get_client_info() . . . . . . . . . . 673
9.1.3.25 mysql_get_server_version(). . . . . . . 673
9.1.3.26 mysql_get_host_info() . . . . . . . . . . . . 674
9.1.3.27 mysql_get_proto_info() . . . . . . . . . . . 674
9.1.3.28 mysql_get_server_info() . . . . . . . . . . 675
9.1.3.29 mysql_info() . . . . . . . . . . . . . . . . . . . . . . 675
9.1.3.30 mysql_init() . . . . . . . . . . . . . . . . . . . . . . 676
9.1.3.31 mysql_insert_id() . . . . . . . . . . . . . . . . 676
9.1.3.32 mysql_kill() . . . . . . . . . . . . . . . . . . . . . . 677
9.1.3.33 mysql_list_dbs() . . . . . . . . . . . . . . . . . . 677
9.1.3.34 mysql_list_fields() . . . . . . . . . . . . . . 678
9.1.3.35 mysql_list_processes() . . . . . . . . . . . 679
9.1.3.36 mysql_list_tables() . . . . . . . . . . . . . . 679
9.1.3.37 mysql_num_fields() . . . . . . . . . . . . . . . 680
9.1.3.38 mysql_num_rows() . . . . . . . . . . . . . . . . . . 681
9.1.3.39 mysql_options() . . . . . . . . . . . . . . . . . . . 682
9.1.3.40 mysql_ping() . . . . . . . . . . . . . . . . . . . . . . 684
9.1.3.41 mysql_query() . . . . . . . . . . . . . . . . . . . . . 684
9.1.3.42 mysql_real_connect() . . . . . . . . . . . . . 685
9.1.3.43 mysql_real_escape_string(). . . . . . . 688
9.1.3.44 mysql_real_query() . . . . . . . . . . . . . . . 689
9.1.3.45 mysql_reload() . . . . . . . . . . . . . . . . . . . . 690
9.1.3.46 mysql_row_seek() . . . . . . . . . . . . . . . . . . 690
9.1.3.47 mysql_row_tell() . . . . . . . . . . . . . . . . . . 691
9.1.3.48 mysql_select_db() . . . . . . . . . . . . . . . . 691
9.1.3.49 mysql_sqlstate() . . . . . . . . . . . . . . . . . . 692
9.1.3.50 mysql_shutdown() . . . . . . . . . . . . . . . . . . 692
9.1.3.51 mysql_stat() . . . . . . . . . . . . . . . . . . . . . . 693
9.1.3.52 mysql_store_result() . . . . . . . . . . . . . 694
9.1.3.53 mysql_thread_id() . . . . . . . . . . . . . . . . 695
9.1.3.54 mysql_use_result() . . . . . . . . . . . . . . . 695
9.1.3.55 mysql_commit() . . . . . . . . . . . . . . . . . . . . 696
9.1.3.56 mysql_rollback() . . . . . . . . . . . . . . . . . . 697
9.1.3.57 mysql_autocommit() . . . . . . . . . . . . . . . 697
9.1.3.58 mysql_more_results() . . . . . . . . . . . . . 697
9.1.3.59 mysql_next_result() . . . . . . . . . . . . . . 698
9.1.4 C API Prepared Statements . . . . . . . . . . . . . . . . . . . 698
9.1.5 C API Prepared Statements DataTypes . . . . . . . . 698
9.1.6 C API Prepared Statements Function Overview
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
9.1.7 C API Prepared Statement Function Descriptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702
9.1.7.1 mysql_prepare() . . . . . . . . . . . . . . . . . . . . 702
9.1.7.2 mysql_param_count() . . . . . . . . . . . . . . . 703
xviii

9.1.7.3 mysql_prepare_result() . . . . . . . . . . . . 704


9.1.7.4 mysql_bind_param() . . . . . . . . . . . . . . . . 705
9.1.7.5 mysql_execute() . . . . . . . . . . . . . . . . . . . . 706
9.1.7.6 mysql_stmt_affected_rows(). . . . . . . . 710
9.1.7.7 mysql_bind_result() . . . . . . . . . . . . . . . 711
9.1.7.8 mysql_stmt_store_result() . . . . . . . . . 712
9.1.7.9 mysql_stmt_data_seek() . . . . . . . . . . . . 713
9.1.7.10 mysql_stmt_row_seek() . . . . . . . . . . . . 713
9.1.7.11 mysql_stmt_row_tell() . . . . . . . . . . . . 714
9.1.7.12 mysql_stmt_num_rows() . . . . . . . . . . . . 714
9.1.7.13 mysql_fetch() . . . . . . . . . . . . . . . . . . . . . 715
9.1.7.14 mysql_send_long_data() . . . . . . . . . . . 719
9.1.7.15 mysql_stmt_close() . . . . . . . . . . . . . . . 720
9.1.7.16 mysql_stmt_errno() . . . . . . . . . . . . . . . 721
9.1.7.17 mysql_stmt_error() . . . . . . . . . . . . . . . 722
9.1.7.18 mysql_stmt_sqlstate() . . . . . . . . . . . . 722
9.1.8 C API Handling multiple query executions . . . . . 723
9.1.9 C API Handling DATE, TIME and TIMESTAMP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
9.1.10 C API Threaded Function Descriptions . . . . . . . 724
9.1.10.1 my_init() . . . . . . . . . . . . . . . . . . . . . . . . . 725
9.1.10.2 mysql_thread_init() . . . . . . . . . . . . . . 725
9.1.10.3 mysql_thread_end() . . . . . . . . . . . . . . . 725
9.1.10.4 mysql_thread_safe() . . . . . . . . . . . . . . 726
9.1.11 C API Embedded Server Function Descriptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
9.1.11.1 mysql_server_init() . . . . . . . . . . . . . . 726
9.1.11.2 mysql_server_end() . . . . . . . . . . . . . . . 727
9.1.12 Common questions and problems when using the C
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
9.1.12.1 Why Is It that After mysql_query()
Returns Success, mysql_store_result()
Sometimes Returns NULL? . . . . . . . . . . . . . . . . 727
9.1.12.2 What Results Can I Get From a Query?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
9.1.12.3 How Can I Get the Unique ID for the Last
Inserted Row? . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
9.1.12.4 Problems Linking with the C API . . . . 729
9.1.13 Building Client Programs . . . . . . . . . . . . . . . . . . . . 729
9.1.14 How to Make a Threaded Client . . . . . . . . . . . . . . 729
9.1.15 libmysqld, the Embedded MySQL Server Library
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
9.1.15.1 Overview of the Embedded MySQL Server
Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
9.1.15.2 Compiling Programs with libmysqld
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
9.1.15.3 Restrictions when using the Embedded
MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
xix

9.1.15.4 Using Option Files with the Embedded


Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
9.1.15.5 Things left to do in Embedded Server
(TODO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
9.1.15.6 A Simple Embedded Server Example
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
9.1.15.7 Licensing the Embedded Server . . . . . . 736
9.2 MySQL ODBC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737
9.2.1 How To Install MyODBC . . . . . . . . . . . . . . . . . . . . . 737
9.2.2 How to Fill in the Various Fields in the ODBC
Administrator Program . . . . . . . . . . . . . . . . . . . . . . . . . 738
9.2.3 Connect parameters for MyODBC . . . . . . . . . . . . . 738
9.2.4 How to Report Problems with MyODBC . . . . . . . 740
9.2.5 Programs Known to Work with MyODBC . . . . . . 740
9.2.6 How to Get the Value of an AUTO_INCREMENT
Column in ODBC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
9.2.7 Reporting Problems with MyODBC. . . . . . . . . . . . 745
9.3 MySQL Java Connectivity (JDBC) . . . . . . . . . . . . . . . . . . . . . 746
9.4 MySQL PHP API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746
9.4.1 Common Problems with MySQL and PHP . . . . . 746
9.5 MySQL Perl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
9.5.1 DBI with DBD::mysql . . . . . . . . . . . . . . . . . . . . . . . . . 747
9.5.2 The DBI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
9.5.3 More DBI/DBD Information . . . . . . . . . . . . . . . . . . . . 753
9.6 MySQL C++ API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753
9.6.1 Borland C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753
9.7 MySQL Python API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
9.8 MySQL Tcl API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
9.9 MySQL Eiffel Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
9.10 Error Returns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754

10 Spatial Extensions in MySQL . . . . . . . . . . . 761


10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
10.2 The OpenGIS Geometry Model . . . . . . . . . . . . . . . . . . . . . . . 761
10.2.1 The Geometry Class Hierarchy . . . . . . . . . . . . . . . 762
10.2.2 Class Geometry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
10.2.3 Class Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
10.2.4 Class Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
10.2.5 Class LineString . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
10.2.6 Class Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
10.2.7 Class Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
10.2.8 Class GeometryCollection . . . . . . . . . . . . . . . . . . 766
10.2.9 Class MultiPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . 766
10.2.10 Class MultiCurve . . . . . . . . . . . . . . . . . . . . . . . . . . 766
10.2.11 Class MultiLineString . . . . . . . . . . . . . . . . . . . . . 767
10.2.12 Class MultiSurface . . . . . . . . . . . . . . . . . . . . . . . . 767
10.2.13 Class MultiPolygon . . . . . . . . . . . . . . . . . . . . . . . . 767
10.3 Supported Spatial Data Formats . . . . . . . . . . . . . . . . . . . . . . 768
xx

10.3.1 Well-Known Text (WKT) Representation . . . . . 768


10.3.2 Well-Known Binary (WKB) Representation . . . 769
10.3.2.1 WKB Basic Types . . . . . . . . . . . . . . . . . . 769
10.3.2.2 WKB Building Blocks . . . . . . . . . . . . . . . 769
10.3.2.3 WKB Representation of Geometry Values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770
10.3.2.4 WKB Examples . . . . . . . . . . . . . . . . . . . . 771
10.4 Creating a Spatially Enabled MySQL Database. . . . . . . . . 772
10.4.1 MySQL Spatial Data Types . . . . . . . . . . . . . . . . . . 772
10.4.2 Creating Spatial Values . . . . . . . . . . . . . . . . . . . . . . 772
10.4.2.1 Creating Geometry Values Using WKT
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772
10.4.2.2 Creating Geometry Values Using WKB
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773
10.4.2.3 Creating Geometry Values Using
MySQL-Specific Functions . . . . . . . . . . . . . . . . 774
10.4.3 Creating Spatial Columns . . . . . . . . . . . . . . . . . . . . 775
10.4.4 Populating Spatial Columns . . . . . . . . . . . . . . . . . . 775
10.4.4.1 Examples Of Using WKT Functions . . 775
10.4.5 Fetching Spatial Data . . . . . . . . . . . . . . . . . . . . . . . . 776
10.4.5.1 Fetching Spatial Data Using WKT
Representation . . . . . . . . . . . . . . . . . . . . . . . . . . 776
10.4.5.2 Fetching Spatial Data Using WKB
Representation . . . . . . . . . . . . . . . . . . . . . . . . . . 777
10.5 Analysing Spatial Information. . . . . . . . . . . . . . . . . . . . . . . . . 777
10.5.1 Functions To Convert Geometries Between Formats
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777
10.5.2 Functions To Analyse Geometry Properties . . . . 778
10.5.2.1 Basic Functions To Analyse Geometry
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 778
10.5.2.2 Functions To Analyse Point Properties
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
10.5.2.3 Functions To Analyse LineString
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
10.5.2.4 Functions To Analyse MultiLineString
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
10.5.2.5 Functions To Analyse Polygon Properties
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
10.5.2.6 Functions To Analyse MultiPolygon
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782
10.5.2.7 Functions To Analyse
GeometryCollection Properties . . . . . . . . . . 783
10.5.3 Functions That Create New Geometries From
Existing Ones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
10.5.3.1 Geometry Functions That Produce New
Geometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
10.5.3.2 Spatial Operators . . . . . . . . . . . . . . . . . . . 784
xxi

10.5.4 Functions For Testing Spatial Relations Between


Geometric Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
10.5.5 Relations On Geometry Minimal Bounding
Rectangles (MBRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
10.5.6 Functions That Test Spatial Relationships Between
Geometries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785
10.6 Optimising Spatial Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 786
10.6.1 Creating Spatial Indexes . . . . . . . . . . . . . . . . . . . . . 786
10.6.2 Using a Spatial Index . . . . . . . . . . . . . . . . . . . . . . . . 787
10.7 MySQL Conformance And Compatibility . . . . . . . . . . . . . . 789
10.7.1 GIS Features That Are Not Yet Implemented . . 789

11 Extending MySQL . . . . . . . . . . . . . . . . . . . . . . 791


11.1 MySQL Internals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
11.1.1 MySQL Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
11.1.2 MySQL Test Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
11.1.2.1 Running the MySQL Test Suite . . . . . . 792
11.1.2.2 Extending the MySQL Test Suite . . . . 792
11.1.2.3 Reporting Bugs in the MySQL Test Suite
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
11.2 Adding New Functions to MySQL . . . . . . . . . . . . . . . . . . . . . 794
11.2.1 CREATE FUNCTION/DROP FUNCTION Syntax . . . . . 794
11.2.2 Adding a New User-definable Function . . . . . . . . 795
11.2.2.1 UDF Calling Sequences for simple
functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797
11.2.2.2 UDF Calling Sequences for aggregate
functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
11.2.2.3 Argument Processing . . . . . . . . . . . . . . . . 798
11.2.2.4 Return Values and Error Handling . . . 800
11.2.2.5 Compiling and Installing User-definable
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
11.2.3 Adding a New Native Function . . . . . . . . . . . . . . . 802
11.3 Adding New Procedures to MySQL . . . . . . . . . . . . . . . . . . . . 803
11.3.1 Procedure Analyse. . . . . . . . . . . . . . . . . . . . . . . . . . . 803
11.3.2 Writing a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . 804

Appendix A Problems and Common Errors . . 805


A.1 How to Determine What Is Causing Problems . . . . . . . . . . 805
A.2 Common Errors When Using MySQL . . . . . . . . . . . . . . . . . . 806
A.2.1 Access denied Error . . . . . . . . . . . . . . . . . . . . . . . . . 806
A.2.2 MySQL server has gone away Error. . . . . . . . . . . . 806
A.2.3 Can’t connect to [local] MySQL server Error
............................................... 807
A.2.4 Client does not support authentication
protocol error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809
A.2.5 Host ’...’ is blocked Error . . . . . . . . . . . . . . . . . 809
A.2.6 Too many connections Error . . . . . . . . . . . . . . . . . 809
xxii

A.2.7 Some non-transactional changed tables


couldn’t be rolled back Error . . . . . . . . . . . . . . . . . 810
A.2.8 Out of memory Error . . . . . . . . . . . . . . . . . . . . . . . . . 810
A.2.9 Packet too large Error . . . . . . . . . . . . . . . . . . . . . . 810
A.2.10 Communication Errors / Aborted Connection
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811
A.2.11 The table is full Error . . . . . . . . . . . . . . . . . . . . 812
A.2.12 Can’t create/write to file Error . . . . . . . . . . 813
A.2.13 Commands out of sync Error in Client . . . . . . . . 813
A.2.14 Ignoring user Error . . . . . . . . . . . . . . . . . . . . . . . . 813
A.2.15 Table ’xxx’ doesn’t exist Error . . . . . . . . . . . 814
A.2.16 Can’t initialize character set xxx error . . 814
A.2.17 File Not Found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814
A.3 Installation Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815
A.3.1 Problems When Linking with the MySQL Client
Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815
A.3.2 How to Run MySQL As a Normal User . . . . . . . . 816
A.3.3 Problems with File Permissions . . . . . . . . . . . . . . . 817
A.4 Administration Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . 818
A.4.1 What To Do If MySQL Keeps Crashing. . . . . . . . 818
A.4.2 How to Reset a Forgotten Root Password . . . . . . 820
A.4.3 How MySQL Handles a Full Disk. . . . . . . . . . . . . . 821
A.4.4 Where MySQL Stores Temporary Files . . . . . . . . 821
A.4.5 How to Protect or Change the MySQL Socket File
‘/tmp/mysql.sock’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 822
A.4.6 Time Zone Problems . . . . . . . . . . . . . . . . . . . . . . . . . 822
A.5 Query Related Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823
A.5.1 Case-Sensitivity in Searches . . . . . . . . . . . . . . . . . . . 823
A.5.2 Problems Using DATE Columns . . . . . . . . . . . . . . . . 823
A.5.3 Problems with NULL Values . . . . . . . . . . . . . . . . . . . 824
A.5.4 Problems with alias . . . . . . . . . . . . . . . . . . . . . . . . . 825
A.5.5 Deleting Rows from Related Tables . . . . . . . . . . . . 825
A.5.6 Solving Problems with No Matching Rows . . . . . 826
A.5.7 Problems with Floating-Point Comparison . . . . . 826
A.6 Optimiser Related Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
A.6.1 How to avoid table scan,,, . . . . . . . . . . . . . . . . . . . . 829
A.7 Table Definition Related Issues . . . . . . . . . . . . . . . . . . . . . . . . 829
A.7.1 Problems with ALTER TABLE. . . . . . . . . . . . . . . . . . . 830
A.7.2 How To Change the Order of Columns in a Table
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 830
A.7.3 TEMPORARY TABLE problems . . . . . . . . . . . . . 831

Appendix B Contributed Programs . . . . . . . . . 832


B.1 APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832
B.2 Converters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 834
B.3 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836
xxiii

Appendix C Credits . . . . . . . . . . . . . . . . . . . . . . . . 837


C.1 Developers at MySQL AB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
C.2 Contributors to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840
C.3 Supporters to MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846

Appendix D MySQL Change History . . . . . . . . 847


D.1 Changes in release 5.0.0 (Development). . . . . . . . . . . . . . . . . 847
D.2 Changes in release 4.1.x (Alpha) . . . . . . . . . . . . . . . . . . . . . . . 847
D.2.1 Changes in release 4.1.1 (not released yet) . . . . . 848
D.2.2 Changes in release 4.1.0 (03 Apr 2003: Alpha) . . 850
D.3 Changes in release 4.0.x (Production) . . . . . . . . . . . . . . . . . . 852
D.3.1 Changes in release 4.0.15 (not released yet) . . . . 852
D.3.2 Changes in release 4.0.14 (to be released soon) . . 852
D.3.3 Changes in release 4.0.13 (16 May 2003) . . . . . . . 856
D.3.4 Changes in release 4.0.12 (15 Mar 2003: Production)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
D.3.5 Changes in release 4.0.11 (20 Feb 2003) . . . . . . . . 861
D.3.6 Changes in release 4.0.10 (29 Jan 2003) . . . . . . . . 862
D.3.7 Changes in release 4.0.9 (09 Jan 2003) . . . . . . . . . 863
D.3.8 Changes in release 4.0.8 (07 Jan 2003) . . . . . . . . . 864
D.3.9 Changes in release 4.0.7 (20 Dec 2002) . . . . . . . . . 864
D.3.10 Changes in release 4.0.6 (14 Dec 2002: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864
D.3.11 Changes in release 4.0.5 (13 Nov 2002) . . . . . . . 866
D.3.12 Changes in release 4.0.4 (29 Sep 2002) . . . . . . . . 868
D.3.13 Changes in release 4.0.3 (26 Aug 2002: Beta) . . 870
D.3.14 Changes in release 4.0.2 (01 Jul 2002) . . . . . . . . 871
D.3.15 Changes in release 4.0.1 (23 Dec 2001) . . . . . . . . 875
D.3.16 Changes in release 4.0.0 (Oct 2001: Alpha). . . . 876
D.4 Changes in release 3.23.x (Recent; still supported). . . . . . . 877
D.4.1 Changes in release 3.23.58 (not released yet) . . . 878
D.4.2 Changes in release 3.23.57 (06 Jun 2003) . . . . . . . 878
D.4.3 Changes in release 3.23.56 (13 Mar 2003) . . . . . . 879
D.4.4 Changes in release 3.23.55 (23 Jan 2003) . . . . . . . 880
D.4.5 Changes in release 3.23.54 (05 Dec 2002) . . . . . . . 881
D.4.6 Changes in release 3.23.53 (09 Oct 2002) . . . . . . . 882
D.4.7 Changes in release 3.23.52 (14 Aug 2002) . . . . . . 882
D.4.8 Changes in release 3.23.51 (31 May 2002) . . . . . . 883
D.4.9 Changes in release 3.23.50 (21 Apr 2002). . . . . . . 884
D.4.10 Changes in release 3.23.49 . . . . . . . . . . . . . . . . . . . 885
D.4.11 Changes in release 3.23.48 (07 Feb 2002) . . . . . . 885
D.4.12 Changes in release 3.23.47 (27 Dec 2001). . . . . . 886
D.4.13 Changes in release 3.23.46 (29 Nov 2001) . . . . . 886
D.4.14 Changes in release 3.23.45 (22 Nov 2001) . . . . . 887
D.4.15 Changes in release 3.23.44 (31 Oct 2001) . . . . . . 887
D.4.16 Changes in release 3.23.43 (04 Oct 2001) . . . . . . 888
D.4.17 Changes in release 3.23.42 (08 Sep 2001) . . . . . . 889
D.4.18 Changes in release 3.23.41 (11 Aug 2001) . . . . . 889
xxiv

D.4.19 Changes in release 3.23.40 . . . . . . . . . . . . . . . . . . . 890


D.4.20 Changes in release 3.23.39 (12 Jun 2001) . . . . . . 891
D.4.21 Changes in release 3.23.38 (09 May 2001) . . . . . 891
D.4.22 Changes in release 3.23.37 (17 Apr 2001) . . . . . 892
D.4.23 Changes in release 3.23.36 (27 Mar 2001) . . . . . 893
D.4.24 Changes in release 3.23.35 (15 Mar 2001) . . . . . 893
D.4.25 Changes in release 3.23.34a . . . . . . . . . . . . . . . . . . 893
D.4.26 Changes in release 3.23.34 (10 Mar 2001) . . . . . 893
D.4.27 Changes in release 3.23.33 (09 Feb 2001) . . . . . . 894
D.4.28 Changes in release 3.23.32 (22 Jan 2001:
Production) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896
D.4.29 Changes in release 3.23.31 (17 Jan 2001) . . . . . . 896
D.4.30 Changes in release 3.23.30 (04 Jan 2001) . . . . . . 897
D.4.31 Changes in release 3.23.29 (16 Dec 2000). . . . . . 898
D.4.32 Changes in release 3.23.28 (22 Nov 2000: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
D.4.33 Changes in release 3.23.27 (24 Oct 2000) . . . . . . 901
D.4.34 Changes in release 3.23.26 (18 Oct 2000) . . . . . . 901
D.4.35 Changes in release 3.23.25 (29 Sep 2000) . . . . . . 902
D.4.36 Changes in release 3.23.24 (08 Sep 2000) . . . . . . 903
D.4.37 Changes in release 3.23.23 (01 Sep 2000) . . . . . . 903
D.4.38 Changes in release 3.23.22 (31 Jul 2000) . . . . . . 905
D.4.39 Changes in release 3.23.21 . . . . . . . . . . . . . . . . . . . 905
D.4.40 Changes in release 3.23.20 . . . . . . . . . . . . . . . . . . . 906
D.4.41 Changes in release 3.23.19 . . . . . . . . . . . . . . . . . . . 906
D.4.42 Changes in release 3.23.18 . . . . . . . . . . . . . . . . . . . 906
D.4.43 Changes in release 3.23.17 . . . . . . . . . . . . . . . . . . . 907
D.4.44 Changes in release 3.23.16 . . . . . . . . . . . . . . . . . . . 907
D.4.45 Changes in release 3.23.15 (May 2000: Beta) . . 908
D.4.46 Changes in release 3.23.14 . . . . . . . . . . . . . . . . . . . 909
D.4.47 Changes in release 3.23.13 . . . . . . . . . . . . . . . . . . . 909
D.4.48 Changes in release 3.23.12 (07 Mar 2000) . . . . . 910
D.4.49 Changes in release 3.23.11 . . . . . . . . . . . . . . . . . . . 910
D.4.50 Changes in release 3.23.10 . . . . . . . . . . . . . . . . . . . 911
D.4.51 Changes in release 3.23.9 . . . . . . . . . . . . . . . . . . . . 911
D.4.52 Changes in release 3.23.8 (02 Jan 2000) . . . . . . . 912
D.4.53 Changes in release 3.23.7 (10 Dec 1999) . . . . . . . 912
D.4.54 Changes in release 3.23.6 . . . . . . . . . . . . . . . . . . . . 913
D.4.55 Changes in release 3.23.5 (20 Oct 1999) . . . . . . . 914
D.4.56 Changes in release 3.23.4 (28 Sep 1999) . . . . . . . 915
D.4.57 Changes in release 3.23.3 . . . . . . . . . . . . . . . . . . . . 915
D.4.58 Changes in release 3.23.2 (09 Aug 1999) . . . . . . 916
D.4.59 Changes in release 3.23.1 . . . . . . . . . . . . . . . . . . . . 917
D.4.60 Changes in release 3.23.0 (05 Aug 1999: Alpha)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917
D.5 Changes in release 3.22.x (Old; discontinued) . . . . . . . . . . . 919
D.5.1 Changes in release 3.22.35 . . . . . . . . . . . . . . . . . . . . 919
D.5.2 Changes in release 3.22.34 . . . . . . . . . . . . . . . . . . . . 919
xxv

D.5.3 Changes in release 3.22.33 . . . . . . . . . . . . . . . . . . . . 919


D.5.4 Changes in release 3.22.32 (14 Feb 2000) . . . . . . . 919
D.5.5 Changes in release 3.22.31 . . . . . . . . . . . . . . . . . . . . 919
D.5.6 Changes in release 3.22.30 . . . . . . . . . . . . . . . . . . . . 919
D.5.7 Changes in release 3.22.29 (02 Jan 2000) . . . . . . . 920
D.5.8 Changes in release 3.22.28 (20 Oct 1999) . . . . . . . 920
D.5.9 Changes in release 3.22.27 . . . . . . . . . . . . . . . . . . . . 920
D.5.10 Changes in release 3.22.26 (16 Sep 1999) . . . . . . 920
D.5.11 Changes in release 3.22.25 . . . . . . . . . . . . . . . . . . . 921
D.5.12 Changes in release 3.22.24 (05 Jul 1999) . . . . . . 921
D.5.13 Changes in release 3.22.23 (08 Jun 1999) . . . . . . 921
D.5.14 Changes in release 3.22.22 (30 Apr 1999) . . . . . 921
D.5.15 Changes in release 3.22.21 . . . . . . . . . . . . . . . . . . . 922
D.5.16 Changes in release 3.22.20 (18 Mar 1999) . . . . . 922
D.5.17 Changes in release 3.22.19 (Mar 1999: Production)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922
D.5.18 Changes in release 3.22.18 . . . . . . . . . . . . . . . . . . . 922
D.5.19 Changes in release 3.22.17 . . . . . . . . . . . . . . . . . . . 922
D.5.20 Changes in release 3.22.16 (Feb 1999: Gamma)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
D.5.21 Changes in release 3.22.15 . . . . . . . . . . . . . . . . . . . 923
D.5.22 Changes in release 3.22.14 . . . . . . . . . . . . . . . . . . . 923
D.5.23 Changes in release 3.22.13 . . . . . . . . . . . . . . . . . . . 924
D.5.24 Changes in release 3.22.12 . . . . . . . . . . . . . . . . . . . 924
D.5.25 Changes in release 3.22.11 . . . . . . . . . . . . . . . . . . . 924
D.5.26 Changes in release 3.22.10 . . . . . . . . . . . . . . . . . . . 925
D.5.27 Changes in release 3.22.9 . . . . . . . . . . . . . . . . . . . . 926
D.5.28 Changes in release 3.22.8 . . . . . . . . . . . . . . . . . . . . 926
D.5.29 Changes in release 3.22.7 (Sep 1998: Beta) . . . . 927
D.5.30 Changes in release 3.22.6 . . . . . . . . . . . . . . . . . . . . 927
D.5.31 Changes in release 3.22.5 . . . . . . . . . . . . . . . . . . . . 928
D.5.32 Changes in release 3.22.4 . . . . . . . . . . . . . . . . . . . . 929
D.5.33 Changes in release 3.22.3 . . . . . . . . . . . . . . . . . . . . 930
D.5.34 Changes in release 3.22.2 . . . . . . . . . . . . . . . . . . . . 930
D.5.35 Changes in release 3.22.1 (Jun 1998: Alpha) . . 930
D.5.36 Changes in release 3.22.0 . . . . . . . . . . . . . . . . . . . . 931
D.6 Changes in release 3.21.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932
D.6.1 Changes in release 3.21.33 . . . . . . . . . . . . . . . . . . . . 933
D.6.2 Changes in release 3.21.32 . . . . . . . . . . . . . . . . . . . . 933
D.6.3 Changes in release 3.21.31 . . . . . . . . . . . . . . . . . . . . 933
D.6.4 Changes in release 3.21.30 . . . . . . . . . . . . . . . . . . . . 933
D.6.5 Changes in release 3.21.29 . . . . . . . . . . . . . . . . . . . . 934
D.6.6 Changes in release 3.21.28 . . . . . . . . . . . . . . . . . . . . 934
D.6.7 Changes in release 3.21.27 . . . . . . . . . . . . . . . . . . . . 934
D.6.8 Changes in release 3.21.26 . . . . . . . . . . . . . . . . . . . . 935
D.6.9 Changes in release 3.21.25 . . . . . . . . . . . . . . . . . . . . 935
D.6.10 Changes in release 3.21.24 . . . . . . . . . . . . . . . . . . . 935
D.6.11 Changes in release 3.21.23 . . . . . . . . . . . . . . . . . . . 936
xxvi

D.6.12 Changes in release 3.21.22 . . . . . . . . . . . . . . . . . . . 936


D.6.13 Changes in release 3.21.21a . . . . . . . . . . . . . . . . . . 937
D.6.14 Changes in release 3.21.21 . . . . . . . . . . . . . . . . . . . 937
D.6.15 Changes in release 3.21.20 . . . . . . . . . . . . . . . . . . . 937
D.6.16 Changes in release 3.21.19 . . . . . . . . . . . . . . . . . . . 937
D.6.17 Changes in release 3.21.18 . . . . . . . . . . . . . . . . . . . 938
D.6.18 Changes in release 3.21.17 . . . . . . . . . . . . . . . . . . . 938
D.6.19 Changes in release 3.21.16 . . . . . . . . . . . . . . . . . . . 938
D.6.20 Changes in release 3.21.15 . . . . . . . . . . . . . . . . . . . 939
D.6.21 Changes in release 3.21.14b . . . . . . . . . . . . . . . . . . 940
D.6.22 Changes in release 3.21.14a . . . . . . . . . . . . . . . . . . 940
D.6.23 Changes in release 3.21.13 . . . . . . . . . . . . . . . . . . . 940
D.6.24 Changes in release 3.21.12 . . . . . . . . . . . . . . . . . . . 941
D.6.25 Changes in release 3.21.11 . . . . . . . . . . . . . . . . . . . 941
D.6.26 Changes in release 3.21.10 . . . . . . . . . . . . . . . . . . . 942
D.6.27 Changes in release 3.21.9 . . . . . . . . . . . . . . . . . . . . 942
D.6.28 Changes in release 3.21.8 . . . . . . . . . . . . . . . . . . . . 942
D.6.29 Changes in release 3.21.7 . . . . . . . . . . . . . . . . . . . . 943
D.6.30 Changes in release 3.21.6 . . . . . . . . . . . . . . . . . . . . 943
D.6.31 Changes in release 3.21.5 . . . . . . . . . . . . . . . . . . . . 943
D.6.32 Changes in release 3.21.4 . . . . . . . . . . . . . . . . . . . . 943
D.6.33 Changes in release 3.21.3 . . . . . . . . . . . . . . . . . . . . 944
D.6.34 Changes in release 3.21.2 . . . . . . . . . . . . . . . . . . . . 944
D.6.35 Changes in release 3.21.0 . . . . . . . . . . . . . . . . . . . . 945
D.7 Changes in release 3.20.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946
D.7.1 Changes in release 3.20.18 . . . . . . . . . . . . . . . . . . . . 946
D.7.2 Changes in release 3.20.17 . . . . . . . . . . . . . . . . . . . . 947
D.7.3 Changes in release 3.20.16 . . . . . . . . . . . . . . . . . . . . 948
D.7.4 Changes in release 3.20.15 . . . . . . . . . . . . . . . . . . . . 948
D.7.5 Changes in release 3.20.14 . . . . . . . . . . . . . . . . . . . . 948
D.7.6 Changes in release 3.20.13 . . . . . . . . . . . . . . . . . . . . 949
D.7.7 Changes in release 3.20.11 . . . . . . . . . . . . . . . . . . . . 949
D.7.8 Changes in release 3.20.10 . . . . . . . . . . . . . . . . . . . . 950
D.7.9 Changes in release 3.20.9 . . . . . . . . . . . . . . . . . . . . . 950
D.7.10 Changes in release 3.20.8 . . . . . . . . . . . . . . . . . . . . 950
D.7.11 Changes in release 3.20.7 . . . . . . . . . . . . . . . . . . . . 950
D.7.12 Changes in release 3.20.6 . . . . . . . . . . . . . . . . . . . . 951
D.7.13 Changes in release 3.20.3 . . . . . . . . . . . . . . . . . . . . 952
D.7.14 Changes in release 3.20.0 . . . . . . . . . . . . . . . . . . . . 952
D.8 Changes in release 3.19.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
D.8.1 Changes in release 3.19.5 . . . . . . . . . . . . . . . . . . . . . 953
D.8.2 Changes in release 3.19.4 . . . . . . . . . . . . . . . . . . . . . 953
D.8.3 Changes in release 3.19.3 . . . . . . . . . . . . . . . . . . . . . 954
xxvii

Appendix E Porting to Other Systems . . . . . . 955


E.1 Debugging a MySQL server. . . . . . . . . . . . . . . . . . . . . . . . . . . . 956
E.1.1 Compiling MYSQL for Debugging . . . . . . . . . . . . . 956
E.1.2 Creating Trace Files . . . . . . . . . . . . . . . . . . . . . . . . . . 957
E.1.3 Debugging mysqld under gdb . . . . . . . . . . . . . . . . . 958
E.1.4 Using a Stack Trace . . . . . . . . . . . . . . . . . . . . . . . . . . 959
E.1.5 Using Log Files to Find Cause of Errors in mysqld
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
E.1.6 Making a Test Case If You Experience Table
Corruption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
E.2 Debugging a MySQL client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
E.3 The DBUG Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
E.4 Locking methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963
E.5 Comments about RTS threads . . . . . . . . . . . . . . . . . . . . . . . . . 964
E.6 Differences between different thread packages . . . . . . . . . . . 966

Appendix F Environment Variables . . . . . . . . . 968

Appendix G MySQL Regular Expressions . . . 969

Appendix H GNU General Public License . . . 972

Appendix I GNU Lesser General Public License


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978

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

Concept Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996


Chapter 1: General Information 1

1 General Information
The MySQL ° R
software delivers a very fast, multi-threaded, multi-user, and robust SQL
(Structured Query Language) database server. MySQL Server is intended for mission-
critical, heavy-load production systems as well as for embedding into mass-deployed soft-
ware. MySQL is a trademark of MySQL AB.
The MySQL software is Dual Licensed. Users can choose to use the MySQL software as an
Open Source/Free Software product under the terms of the GNU General Public License
(http://www.gnu.org/licenses/) or can purchase a standard commercial license from
MySQL AB. See Section 1.4 [Licensing and Support], page 15.
The MySQL web site (http://www.mysql.com/) provides the latest information about the
MySQL software.
The following list describes some sections of particular interest in this manual:
• For information about the company behind the MySQL Database Server, see Section 1.3
[What is MySQL AB], page 11.
• For a discussion about the capabilities of the MySQL Database Server, see Section 1.2.2
[Features], page 5.
• For installation instructions, see Chapter 2 [Installing], page 71.
• For tips on porting the MySQL Database Software to new architectures or operating
systems, see Appendix E [Porting], page 955.
• For information about upgrading from a Version 4.0 release, see Section 2.5.1
[Upgrading-from-4.0], page 119.
• For information about upgrading from a Version 3.23 release, see Section 2.5.2
[Upgrading-from-3.23], page 121.
• For information about upgrading from a Version 3.22 release, see Section 2.5.3
[Upgrading-from-3.22], page 124.
• For a tutorial introduction to the MySQL Database Server, see Chapter 3 [Tutorial],
page 167.
• 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 D [News], page 847.
• For a list of currently known bugs and misfeatures, see Section 1.8.6 [Bugs], page 45.
• For future plans, see Section 1.9 [TODO], page 50.
• For a list of all the contributors to this project, see Appendix C [Credits], page 837.
Important:
Reports of errors (often called bugs), as well as questions and comments, should be sent to
the mailing list at mysql@lists.mysql.com. See Section 1.7.1.3 [Bug reports], page 27.
The mysqlbug script should be used to generate bug reports.
For source distributions, the mysqlbug script can be found in the ‘scripts’ directory. For
binary distributions, mysqlbug can be found in the ‘bin’ directory (‘/usr/bin’ for the
MySQL-server RPM package).
If you have found a sensitive security bug in MySQL Server, you should send an e-mail to
security@mysql.com.
2 MySQL Technical Reference for Version 4.1.1-alpha

1.1 About This Manual

This is the MySQL reference manual; it documents MySQL up to Version 4.1.1-alpha. Func-
tional changes are always indicated with reference to the version, so this manual is also suit-
able if you are using an older version of the MySQL software (such as 3.23 or 4.0-production).
There are also references for version 5.0 (development).
Being a reference manual, it does not provide general instruction on SQL or relational
database concepts.
As the MySQL Database Software is under constant development, the manual is
also updated frequently. The most recent version of this manual is available at
http://www.mysql.com/documentation/ in many different formats, including HTML,
PDF, and Windows HLP versions.
The primary document is the Texinfo file. The HTML version is produced automatically
using a modified version of texi2html. The plain text and Info versions are produced
with makeinfo. The PostScript version is produced using texi2dvi and dvips. The PDF
version is produced with pdftex.
If you have a hard time finding information in the manual, you can try our searchable
version at http://www.mysql.com/doc/.
If you have any suggestions concerning additions or corrections to this manual, please send
them to the documentation team at docs@mysql.com.
This manual was initially written by David Axmark and Michael (Monty) Widenius. It is
currently maintained by Michael (Monty) Widenius, Arjen Lentz, and Paul DuBois. For
other contributors, see Appendix C [Credits], page 837.
The copyright (2003) to this manual is owned by the Swedish company MySQL AB. See
Section 1.4.2 [Copyright], page 16.

1.1.1 Conventions Used in This Manual

This manual uses certain typographical conventions:


constant Constant-width font is used for command names and options; SQL statements;
database, table, and column names; C and Perl code; and environment vari-
ables. Example: “To see how mysqladmin works, invoke it with the --help
option.”
‘filename’
Constant-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 character
sequences. Example: “To specify a wildcard, use the ‘%’ character.”
italic Italic font is used for emphasis, like this.
boldface Boldface font is used in table headings and to convey especially strong emphasis.
Chapter 1: General Information 3

When commands are shown that are meant to be executed by a particular program, the
program 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 command
that you execute from the mysql client program:
shell> type a shell command here
mysql> 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 an
environment variable and run a command looks like this in Bourne shell syntax:
shell> VARNAME=value some_command
For csh, you would execute the sequence like this:
shell> setenv VARNAME value
shell> some_command
Database, table, and column names must often be substituted into commands. To indicate
that such substitution is necessary, this manual uses db_name, tbl_name, and col_name.
For example, you might see a statement like this:
mysql> SELECT col_name FROM db_name.tbl_name;
This means that if you were to enter a similar statement, you would supply your own
database, table, and column names, perhaps like this:
mysql> SELECT author_name FROM biblio_db.author_list;
SQL keywords are not case-sensitive and may be written in uppercase or lowercase. This
manual uses uppercase.
In syntax descriptions, square brackets (‘[’ and ‘]’) are used to indicate optional words or
clauses. For example, in the following statement, IF EXISTS is optional:
DROP TABLE [IF EXISTS] tbl_name
When a syntax element consists of a number of alternatives, the alternatives are separated by
vertical bars (‘|’). When one member from a set of choices may be chosen, the alternatives
are listed within square brackets (‘[’ and ‘]’):
TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
When one member from a set of choices must be chosen, the alternatives are listed within
braces (‘{’ and ‘}’):
{DESCRIBE | DESC} tbl_name {col_name | wild}

1.2 What Is MySQL?

MySQL, the most popular Open Source SQL database, is developed, distributed, and sup-
ported by MySQL AB. MySQL AB is a commercial company, founded by the MySQL developers,
that builds its business providing services around the MySQL database. See Section 1.3 [What
is MySQL AB], page 11.
The MySQL web site (http://www.mysql.com/) provides the latest information about MySQL
software and MySQL AB.
4 MySQL Technical Reference for Version 4.1.1-alpha

MySQL is a database management system.


A database is a structured collection of data. It may be anything from a simple
shopping list to a picture gallery or the vast amounts of information in a corpo-
rate network. To add, access, and process data stored in a computer database,
you need a database management system such as MySQL Server. Since com-
puters are very good at handling large amounts of data, database management
systems play a central role in computing, as stand-alone utilities or as parts of
other applications.
MySQL is a relational database management system.
A relational database stores data in separate tables rather than putting all the
data in one big storeroom. This adds speed and flexibility. The SQL part of
“MySQL” stands for “Structured Query Language”. SQL is the most common
standardised language used to access databases and is defined by the ANSI/ISO
SQL Standard.(The SQL standard has been evolving since 1986 and several
versions exist. In this manual, ”SQL-92” refers to the standard released in
1992, ”SQL-99” refers to the standard released in 1999, and ”SQL:2003” refers
to the version of the standard that is expected to be released in mid-2003.We use
the term ”the SQL standard” to mean the current version of the SQL Standard
at any time.)
MySQL software is Open Source.
Open Source means that it is possible for anyone to use and modify the software.
Anybody can download the MySQL software from the Internet and use it without
paying anything. If you wish, you may study the source code and change it
to suit your needs. The MySQL software uses the GPL (GNU General Public
License), http://www.gnu.org/licenses/, to define what you may and may
not do with the software in different situations. If you feel uncomfortable with
the GPL or need to embed MySQL code into a commercial application you can buy
a commercially licensed version from us. See Section 1.4.3 [MySQL licenses],
page 16.
Why use the MySQL Database Server?
The MySQL Database Server is very fast, reliable, and easy to use. If that is
what you are looking for, you should give it a try. MySQL Server also has a
practical set of features developed in close cooperation with our users. You can
find a performance comparison of MySQL Server with other database managers
on our benchmark page. See Section 5.1.4 [MySQL Benchmarks], page 391.
MySQL Server was originally developed to handle large databases much faster
than existing solutions and has been successfully used in highly demanding pro-
duction environments for several years. Though under constant development,
MySQL Server today offers a rich and useful set of functions. Its connectivity,
speed, and security make MySQL Server highly suited for accessing databases
on the Internet.
The technical features of MySQL Server
For advanced technical information, see Chapter 6 [Reference], page 433. The
MySQL Database Software is a client/server system that consists of a multi-
threaded SQL server that supports different backends, several different client
Chapter 1: General Information 5

programs and libraries, administrative tools, and a wide range of programming


interfaces (APIs).
We also provide MySQL Server as a multi-threaded library which you can link
into your application to get a smaller, faster, easier-to-manage product.
There is a large amount of contributed MySQL software available.
It is very likely that you will find that your favorite application or language
already supports the MySQL Database Server.
The official way to pronounce MySQL is “My Ess Que Ell” (not “my sequel”), but we don’t
mind if you pronounce it as “my sequel” or in some other localised way.

1.2.1 History of MySQL

We started out with the intention of using mSQL to connect to our tables using our own
fast low-level (ISAM) routines. However, after some testing we came to the conclusion that
mSQL was not fast enough nor flexible enough for our needs. This resulted in a new SQL
interface to our database but with almost the same API interface as mSQL. This API was
chosen to ease porting of third-party code.
The derivation of the name MySQL is not clear. Our base directory and a large number of
our libraries and tools have had the prefix “my” for well over 10 years. However, co-founder
Monty Widenius’s daughter (some years younger) is also named My. Which of the two gave
its name to MySQL is still a mystery, even for us.
The name of the MySQL Dolphin (our logo) is Sakila. Sakila was chosen by the founders
of MySQL AB from a huge list of names suggested by users in our "Name the Dolphin"
contest. The winning name was submitted by Ambrose Twebaze, an open source software
developer from Swaziland, Africa. According to Ambrose, the name Sakila has its roots
in SiSwati, the local language of Swaziland. Sakila is also the name of a town in Arusha,
Tanzania, near Ambrose’s country of origin, Uganda.

1.2.2 The Main Features of MySQL

The following list describes some of the important characteristics of the MySQL Database
Software. See Section 1.5 [MySQL 4.0 In A Nutshell], page 20.
Internals and Portability
• Written in C and C++. Tested with a broad range of different compilers.
• Works on many different platforms. See Section 2.2.3 [Which OS], page 82.
• Uses GNU Automake, Autoconf, and Libtool for portability.
• APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and Tcl. See
Chapter 9 [Clients], page 650.
• Fully multi-threaded using kernel threads. This means it can easily use
multiple CPUs if available.
• Transactional and non-transactional storage engines.
• Very fast B-tree disk tables (MyISAM) with index compression.
6 MySQL Technical Reference for Version 4.1.1-alpha

• Relatively easy to add another storage engine. This is useful if you want
to add an SQL interface to an in-house database.
• A very fast thread-based memory allocation system.
• Very fast joins using an optimised one-sweep multi-join.
• In-memory hash tables which are used as temporary tables.
• SQL functions are implemented through a highly optimised class library
and should be as fast as possible. Usually there isn’t any memory allocation
at all after query initialisation.
• The MySQL code gets tested with Purify (a commercial mem-
ory leakage detector) as well as with Valgrind, a GPL tool
(http://developer.kde.org/~sewardj/).
• Available as client/server or embedded (linked) version.
Column Types
• Many column types: signed/unsigned integers 1, 2, 3, 4, and 8 bytes
long, FLOAT, DOUBLE, CHAR, VARCHAR, TEXT, BLOB, DATE, TIME, DATETIME,
TIMESTAMP, YEAR, SET, and ENUM types. See Section 6.2 [Column types],
page 445.
• Fixed-length and variable-length records.
Commands and Functions
• Full operator and function support in the SELECT and WHERE clauses of
queries. For example:
mysql> SELECT CONCAT(first_name, " ", last_name)
-> FROM tbl_name
-> WHERE income/dependents > 10000 AND age > 30;
• Full support for SQL GROUP BY and ORDER BY clauses. Support for group
functions (COUNT(), COUNT(DISTINCT ...), AVG(), STD(), SUM(), MAX(),
MIN(), and GROUP_CONCAT()).
• Support for LEFT OUTER JOIN and RIGHT OUTER JOIN with both standard
SQL and ODBC syntax.
• Support for aliases on tables and columns as required by SQL-92.
• DELETE, INSERT, REPLACE, and UPDATE return the number of rows that were
changed (affected). It is possible to return the number of rows matched
instead by setting a flag when connecting to the server.
• The MySQL-specific SHOW command can be used to retrieve information
about databases, tables, and indexes. The EXPLAIN command can be used
to determine how the optimiser resolves a query.
• Function names do not clash with table or column names. For example,
ABS is a valid column name. The only restriction is that for a function call,
no spaces are allowed between the function name and the ‘(’ that follows
it. See Section 6.1.7 [Reserved words], page 442.
• You can mix tables from different databases in the same query (as of Ver-
sion 3.22).
Chapter 1: General Information 7

Security
• 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 you connect to a server.
Scalability and Limits
• Handles large databases. We use MySQL Server with databases that con-
tain 50 million records. We also know of users that use MySQL Server with
60,000 tables and about 5,000,000,000 rows.
• Up to 32 indexes per table are allowed. Each index may consist of 1 to
16 columns or parts of columns. The maximum index width is 500 bytes
(this may be changed when compiling MySQL Server). An index may use
a prefix of a CHAR or VARCHAR field.
Connectivity
• Clients may connect to the MySQL server using TCP/IP Sockets, Unix Sock-
ets (Unix), or Named Pipes (NT).
• ODBC (Open-DataBase-Connectivity) support for Win32 (with source).
All ODBC 2.5 functions are supported, as are many others. For example,
you can use MS Access to connect to your MySQL server. See Section 9.2
[ODBC], page 737.
Localisation
• The server can provide error messages to clients in many languages. See
Section 4.6.2 [Languages], page 313.
• Full support for several different character sets, including ISO-8859-1
(Latin1), german, big5, ujis, and more. For example, the Scandinavian
characters ‘^
a’, ‘ä’ and ‘ö’ are allowed in table and column names.
• All data is saved in the chosen character set. All comparisons for normal
string columns are case-insensitive.
• Sorting is done according to the chosen character set (the Swedish way by
default). It is possible to change this when the MySQL server is started. To
see an example of very advanced sorting, look at the Czech sorting code.
MySQL Server supports many different character sets that can be specified
at compile and runtime.
Clients and Tools
• Includes myisamchk, a very fast utility for table checking, optimisation,
and repair. All of the functionality of myisamchk is also available through
the SQL interface. See Chapter 4 [MySQL Database Administration],
page 204.
• All MySQL programs can be invoked with the --help or -? options to obtain
online assistance.

1.2.3 How Stable Is MySQL?

This section addresses the questions “How stable is MySQL Server? ” and “Can I depend
on MySQL Server in this project? ” We will try to clarify these issues and answer some
8 MySQL Technical Reference for Version 4.1.1-alpha

important questions that concern many potential users. The information in this section is
based on data gathered from the mailing list, which is very active in identifying problems
as well as reporting types of use.
Original code stems back from the early ’80s, providing a stable code base, and the ISAM ta-
ble format remains backward-compatible. At TcX, the predecessor of MySQL AB, MySQL code
has worked in projects since mid-1996, without any problems. When the MySQL Database
Software was released to a wider public, our new users quickly found some pieces of
“untested code”. Each new release since then has had fewer portability problems (even
though each new release has also had many new features).
Each release of the MySQL Server has been usable. Problems have occurred only when
users try code from the “gray zones.” Naturally, new users don’t know what the gray zones
are; this section therefore attempts to document those areas that are currently known.
The descriptions mostly deal with Version 3.23 and 4.0 of MySQL Server. All known and
reported bugs are fixed in the latest version, with the exception of those listed in the bugs
section, which are things that are design-related. See Section 1.8.6 [Bugs], page 45.
The MySQL Server design is multi-layered with independent modules. Some of the newer
modules are listed here with an indication of how well-tested each of them is:
Replication – Gamma
Large server clusters using replication are in production use, with good results.
Work on enhanced replication features is continuing in MySQL 4.x.
InnoDB tables – Stable (in 3.23 from 3.23.49)
The InnoDB transactional storage engine has been declared stable in the MySQL
3.23 tree, starting from version 3.23.49. InnoDB is being used in large, heavy-
load production systems.
BDB tables – Gamma
The Berkeley DB code is very stable, but we are still improving the BDB trans-
actional storage engine interface in MySQL Server, so it will take some time
before this is as well tested as the other table types.
FULLTEXT – Beta
Full-text search works but is not yet widely used. Important enhancements
have been implemented in MySQL 4.0.
MyODBC 3.51 (uses ODBC SDK 3.51) – Stable
In wide production use. Some issues brought up appear to be application-
related and independent of the ODBC driver or underlying database server.
Automatic recovery of MyISAM tables – Gamma
This status applies only to the new code in the MyISAM storage engine that
checks if the table was closed properly on open and executes an automatic
check/repair of the table if it wasn’t.
Bulk-insert – Alpha
New feature in MyISAM tables in MySQL 4.0 for faster insert of many rows.
Locking – Gamma
This is very system-dependent. On some systems there are big problems using
standard OS locking (fcntl()). In these cases, you should run mysqld with the
Chapter 1: General Information 9

--skip-external-locking flag. Problems are known to occur on some Linux


systems, and on SunOS when using NFS-mounted filesystems.
MySQL AB provides high-quality support for paying customers, and the MySQL mailing list
usually provides answers to common questions. Bugs are usually fixed right away with a
patch; for serious bugs, there is almost always a new release.

1.2.4 How Big Can MySQL Tables Be?

MySQL Version 3.22 had a 4 GB (4 gigabyte) limit on table size. With the MyISAM table
type in MySQL Version 3.23, the maximum table size was pushed up to 8 million terabytes
(2 ^ 63 bytes).
Note, however, that operating systems have their own file-size limits. Here are some exam-
ples:
Operating System File-Size Limit
Linux-Intel 32 bit 2 GB, 4GB or more, depends on Linux
version
Linux-Alpha 8 TB (?)
Solaris 2.5.1 2 GB (possible 4GB with patch)
Solaris 2.6 4 GB (can be changed with flag)
Solaris 2.7 Intel 4 GB
Solaris 2.7 UltraSPARC 512 GB
On Linux 2.2 you can get tables larger than 2 GB in size by using the LFS patch for the
ext2 filesystem. On Linux 2.4 patches also exist for ReiserFS to get support for big files.
In effect, then, the table size for MySQL databases is normally limited by the operating
system.
By default, MySQL tables have a maximum size of about 4 GB. You can check the maximum
table size for a table with the SHOW TABLE STATUS command or with the myisamchk -dv
table_name. See Section 4.5.7 [SHOW], page 290.
If you need a table that will be larger than 4 GB in size (and your operating system supports
this), set the AVG_ROW_LENGTH and MAX_ROWS parameters accordingly when you create your
table. See Section 6.5.3 [CREATE TABLE], page 538. You can also set these parameters
later, with ALTER TABLE. See Section 6.5.4 [ALTER TABLE], page 546.
If your big table is a read-only table, you could use myisampack to merge and compress
many tables into one. myisampack usually compresses a table by at least 50%, so you can
have, in effect, much bigger tables. See Section 4.7.4 [myisampack], page 322.
You can get around the operating system file limit for MyISAM data files using the RAID
option. See Section 6.5.3 [CREATE TABLE], page 538.
Another solution can be the included MERGE library, which allows you to handle a collection
of identical tables as one. See Section 7.2 [MERGE tables], page 572.

1.2.5 Year 2000 Compliance

The MySQL Server itself has no problems with Year 2000 (Y2K) compliance:
10 MySQL Technical Reference for Version 4.1.1-alpha

• MySQL Server uses Unix time functions and has no problems with dates until 2069.
All 2-digit years are considered to be in the range 1970 to 2069, which means that if
you store 01 in a YEAR column, MySQL Server treats it as 2001.
• All MySQL date functions are stored in one file, ‘sql/time.cc’, and are coded very
carefully to be year 2000-safe.
• In MySQL Version 3.22 and later, the YEAR column type can store years 0 and 1901 to
2155 in one byte and display them using two or four digits.
You may run into problems with applications that use MySQL Server in a way that is not
Y2K-safe. For example, many old applications store or manipulate years using 2-digit values
(which are ambiguous) rather than 4-digit values. This problem may be compounded by
applications that use values such as 00 or 99 as “missing” value indicators.
Unfortunately, these problems may be difficult to fix because different applications may be
written by different programmers, each of whom may use a different set of conventions and
date-handling functions.
Here is a simple demonstration illustrating that MySQL Server doesn’t have any problems
with dates until the year 2030:
mysql> DROP TABLE IF EXISTS y2k;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE y2k (date DATE,


-> date_time DATETIME,
-> time_stamp TIMESTAMP);
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO y2k VALUES


-> ("1998-12-31","1998-12-31 23:59:59",19981231235959),
-> ("1999-01-01","1999-01-01 00:00:00",19990101000000),
-> ("1999-09-09","1999-09-09 23:59:59",19990909235959),
-> ("2000-01-01","2000-01-01 00:00:00",20000101000000),
-> ("2000-02-28","2000-02-28 00:00:00",20000228000000),
-> ("2000-02-29","2000-02-29 00:00:00",20000229000000),
-> ("2000-03-01","2000-03-01 00:00:00",20000301000000),
-> ("2000-12-31","2000-12-31 23:59:59",20001231235959),
-> ("2001-01-01","2001-01-01 00:00:00",20010101000000),
-> ("2004-12-31","2004-12-31 23:59:59",20041231235959),
-> ("2005-01-01","2005-01-01 00:00:00",20050101000000),
-> ("2030-01-01","2030-01-01 00:00:00",20300101000000),
-> ("2050-01-01","2050-01-01 00:00:00",20500101000000);
Query OK, 13 rows affected (0.01 sec)
Records: 13 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM y2k;


+------------+---------------------+----------------+
| date | date_time | time_stamp |
+------------+---------------------+----------------+
Chapter 1: General Information 11

| 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |


| 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
| 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
| 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
| 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
| 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
| 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
| 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
| 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
| 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
| 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
| 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
| 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
+------------+---------------------+----------------+
13 rows in set (0.00 sec)

This example shows that the DATE and DATETIME data types will not give any problems
with future dates (they handle dates until the year 9999).
The TIMESTAMP data type, which is used to store the current time, supports values that
range from 19700101000000 to 20300101000000 on 32-bit machines (signed value). On
64-bit machines, TIMESTAMP handles values up to 2106 (unsigned value).
Even though MySQL Server is Y2K-compliant, it is your responsibility to provide unambigu-
ous input. See Section 6.2.2.1 [Y2K issues], page 452 for MySQL Server’s rules for dealing
with ambiguous date input data (data containing 2-digit year values).

1.3 What Is MySQL AB?

MySQL AB is the company of the MySQL founders and main developers. MySQL AB was origi-
nally established in Sweden by David Axmark, Allan Larsson, and Michael Monty Widenius.
The developers of the MySQL server are all employed by the company. We are a virtual or-
ganisation with people in a dozen countries around the world. We communicate extensively
over the Net every day with one another and with our users, supporters, and partners.
We are dedicated to developing the MySQL software and spreading our database to new users.
MySQL AB owns the copyright to the MySQL source code, the MySQL logo and trademark, and
this manual. See Section 1.2 [What-is], page 3.
The MySQL core values show our dedication to MySQL and Open Source.
We want the MySQL Database Software to be:
• The best and the most widely used database in the world.
• Available to, and affordable by all.
• Easy to use.
• Continuously improving while remaining fast and safe.
• Fun to use and improve.
• Free from bugs.
12 MySQL Technical Reference for Version 4.1.1-alpha

MySQL AB and the people at 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 e-mail and provide support.
• Are a virtual company, networking with others.
• Work against software patents.
The MySQL web site (http://www.mysql.com/) provides the latest information about MySQL
and MySQL AB.

1.3.1 The Business Model and Services of MySQL AB

One of the most common questions we encounter is: “How can you make a living from
something you give away for free? ” This is how.
MySQL AB makes money on support, services, commercial licenses, and royalties. We use
these revenues to fund product development and to expand the MySQL business.
The company has been profitable since its inception. In October 2001, we accepted ven-
ture financing from leading Scandinavian investors and a handful of business angels. This
investment is used to solidify our business model and build a basis for sustainable growth.

1.3.1.1 Support

MySQL AB is run and owned by the founders and main developers of the MySQL database. The
developers are committed to giving support to customers and other users in order to stay
in touch with their needs and problems. All our support is given by qualified developers.
Really tricky questions are answered by Michael Monty Widenius, principal author of the
MySQL Server. See Section 1.4.1 [Support], page 15.
For more information and ordering support at various levels, see http://www.mysql.com/support/
or contact our sales staff at sales@mysql.com.

1.3.1.2 Training and Certification

MySQL AB delivers MySQL and related training worldwide. We offer both open courses and
in-house courses tailored to the specific needs of your company. MySQL Training is also
available through our partners, the Authorised MySQL Training Centers.
Our training material uses the same example databases used in our documentation and
our sample applications, and is always updated to reflect the latest MySQL version. Our
trainers are backed by the development team to guarantee the quality of the training and
the continuous development of the course material. This also ensures that no questions
raised during the courses remain unanswered.
Attending our training courses will enable you to achieve your MySQL application goals. You
will also:
• Save time.
Chapter 1: General Information 13

• Improve the performance of your application(s).


• Reduce or eliminate the need for additional hardware, decreasing cost.
• Enhance security.
• Increase customers’ and co-workers’ satisfaction.
• Prepare yourself for MySQL Certification.
If you are interested in our training as a potential participant or as a training partner,
please visit the training section at http://www.mysql.com/training/ or contact us at:
training@mysql.com.
For details about the MySQL Certification Program, please see http://www.mysql.com/certification/.

1.3.1.3 Consulting

MySQL AB and its Authorised Partners offer consulting services to users of MySQL Server
and to those who embed MySQL Server in their own software, all over the world.
Our consultants can help you design and tune your databases, construct efficient queries,
tune your platform for optimal performance, resolve migration issues, set up replication,
build robust transactional applications, and more. We also help customers embed MySQL
Server in their products and applications for large-scale deployment.
Our consultants work in close collaboration with our development team, which ensures the
technical quality of our professional services. Consulting assignments range from 2-day
power-start sessions to projects that span weeks and months. Our expertise not only covers
MySQL Server—it also extends into programming and scripting languages such as PHP,
Perl, and more.
If you are interested in our consulting services or want to become a consulting partner,
please visit the consulting section of our web site at http://www.mysql.com/consulting/
or contact our consulting staff at consulting@mysql.com.

1.3.1.4 Commercial Licenses

The MySQL database is released under the GNU General Public License (GPL). This means
that the MySQL software can be used free of charge under the GPL. If you do not want
to be bound by the GPL terms (such as the requirement that your application must also
be GPL, you may purchase a commercial license for the same product from MySQL AB; see
http://www.mysql.com/products/pricing.html. Since MySQL AB owns the copyright to
the MySQL source code, we are able to employ Dual Licensing, which means that the same
product is available under GPL and under a commercial license. This does not in any way
affect the Open Source commitment of MySQL AB. For details about when a commercial
license is required, please see Section 1.4.3 [MySQL licenses], page 16.
We also sell commercial licenses of third-party Open Source GPL software that adds value
to MySQL Server. A good example is the InnoDB transactional storage engine that offers
ACID support, row-level locking, crash recovery, multi-versioning, foreign key support, and
more. See Section 7.5 [InnoDB], page 577.
14 MySQL Technical Reference for Version 4.1.1-alpha

1.3.1.5 Partnering

MySQL AB has a worldwide partner programme that covers training courses, consulting and
support, publications, plus reselling and distributing MySQL and related products. MySQL AB
Partners get visibility on the http://www.mysql.com/ web site and the right to use special
versions of the MySQL trademarks to identify their products and promote their business.
If you are interested in becoming a MySQL AB Partner, please e-mail partner@mysql.com.
The word MySQL and the MySQL dolphin logo are trademarks of MySQL AB. See Section 1.4.4
[MySQL AB Logos and Trademarks], page 18. These trademarks represent a significant
value that the MySQL founders have built over the years.

1.3.1.6 Advertising

The MySQL web site (http://www.mysql.com/) is popular among developers and users. In
October 2001, we served 10 million page views. Our visitors represent a group that makes
purchase decisions and recommendations for both software and hardware. Twelve percent of
our visitors authorise purchase decisions, and only nine percent are not involved in purchase
decisions at all. More than 65% have made one or more online business purchases within
the last half-year, and 70% plan to make one in the next few months.

1.3.2 Contact Information

The MySQL web site (http://www.mysql.com/) provides the latest information about MySQL
and MySQL AB.
For press services and inquiries not covered in our News releases (http://www.mysql.com/news/),
please send an e-mail to press@mysql.com.
If you have a valid support contract with MySQL AB, you will get timely, precise answers to
your technical questions about the MySQL software. For more information, see Section 1.4.1
[Support], page 15. On our web site, see http://www.mysql.com/support/, or send an
e-mail to sales@mysql.com.
For information about MySQL training, please visit the training section at
http://www.mysql.com/training/. If you have restricted access to the Internet, please
contact the MySQL AB training staff via e-mail at training@mysql.com. See Section 1.3.1.2
[Business Services Training], page 12.
For information on the MySQL Certification Program, please see http://www.mysql.com/certification
See Section 1.3.1.2 [Business Services Training], page 12.
If you’re interested in consulting, please visit the consulting section of our web site at
http://www.mysql.com/consulting/. If you have restricted access to the Internet, please
contact the MySQL AB consulting staff via e-mail at consulting@mysql.com. See Sec-
tion 1.3.1.3 [Business Services Consulting], page 13.
Commercial licenses may be purchased online at https://order.mysql.com/. There you
will also find information on how to fax your purchase order to MySQL AB. More information
about licensing can be found at http://www.mysql.com/products/pricing.html. If you
have questions regarding licensing or you want a quote for a high-volume license deal,
Chapter 1: General Information 15

please fill in the contact form on our web site (http://www.mysql.com/) or send an e-mail
message to licensing@mysql.com (for licensing questions) or to sales@mysql.com (for
sales inquiries). See Section 1.4.3 [MySQL licenses], page 16.
If you represent a business that is interested in partnering with MySQL AB, please send an
e-mail to partner@mysql.com. See Section 1.3.1.5 [Business Services Partnering], page 14.
For more information on the MySQL trademark policy, refer to http://www.mysql.com/company/trademark.
or send an e-mail to trademark@mysql.com. See Section 1.4.4 [MySQL AB Logos and
Trademarks], page 18.
If you are interested in any of the MySQL AB jobs listed in our jobs section
(http://www.mysql.com/company/jobs/), please send an e-mail to jobs@mysql.com.
Please do not send your CV as an attachment, but rather as plain text at the end of your
e-mail message.
For general discussion among our many users, please direct your attention to the appropriate
mailing list. See Section 1.7.1 [Questions], page 24.
Reports of errors (often called bugs), as well as questions and comments, should be sent to
the mailing list at mysql@lists.mysql.com. If you have found a sensitive security bug in
the MySQL Server, please send an e-mail to security@mysql.com. See Section 1.7.1.3 [Bug
reports], page 27.
If you have benchmark results that we can publish, please contact us via e-mail at
benchmarks@mysql.com.
If you have suggestions concerning additions or corrections to this manual, please send them
to the manual team via e-mail at docs@mysql.com.
For questions or comments about the workings or content of the MySQL web site
(http://www.mysql.com/), please send an e-mail to webmaster@mysql.com.
MySQL AB has a privacy policy, which can be read at http://www.mysql.com/company/privacy.html.
For any queries regarding this policy, please send an e-mail to privacy@mysql.com.
For all other inquires, please send an e-mail to info@mysql.com.

1.4 MySQL Support and Licensing

This section describes MySQL support and licensing arrangements.

1.4.1 Support Offered by MySQL AB

Technical support from MySQL AB means individualised answers to your unique problems
direct from the software engineers who code the MySQL database engine.
We try to take a broad and inclusive view of technical support. Almost any problem
involving MySQL software is important to us if it’s important to you. Typically customers
seek help on how to get different commands and utilities to work, remove performance
bottlenecks, restore crashed systems, understand operating system or networking impacts
on MySQL, set up best practices for backup and recovery, utilise APIs, and so on. Our
support covers only the MySQL server and our own utilities, not third-party products that
access the MySQL server, though we try to help with these where we can.
16 MySQL Technical Reference for Version 4.1.1-alpha

Detailed information about our various support options is given at http://www.mysql.com/support/,


where support contracts can also be ordered online. If you have restricted access to the
Internet, please contact our sales staff via e-mail at sales@mysql.com.
Technical support is like life insurance. You can live happily without it for years, but when
your hour arrives it becomes critically important, yet it’s too late to buy it. If you use
MySQL Server for important applications and encounter sudden difficulties, it may be too
time consuming to figure out all the answers yourself. You may need immediate access to
the most experienced MySQL troubleshooters available, those employed by MySQL AB.

1.4.2 Copyrights and Licenses Used by MySQL

MySQL AB owns the copyright to the MySQL source code, the MySQL logos and trademarks
and this manual. See Section 1.3 [What is MySQL AB], page 11. Several different licenses
are relevant to the MySQL distribution:
1. All the MySQL-specific source in the server, the mysqlclient library and the client, as
well as the GNU readline library is covered by the GNU General Public License. See
Appendix H [GPL license], page 972. The text of this license can be found as the file
‘COPYING’ in the distribution.
2. The GNU getopt library is covered by the GNU Lesser General Public License. See
Appendix I [LGPL license], page 978.
3. Some parts of the source (the regexp library) are covered by a Berkeley-style copyright.
4. Older versions of MySQL (3.22 and earlier) are subject to a stricter license
(http://www.mysql.com/products/mypl.html). See the documentation of the
specific version for information.
5. The MySQL reference manual is currently not distributed under a GPL-style license. Use
of the manual is subject to the following terms:
• Conversion to other formats is allowed, but the actual content may not be altered
or edited in any way.
• You may create a printed copy for your own personal use.
• For all other uses, such as selling printed copies or using (parts of) the manual in
another publication, prior written agreement from MySQL AB is required.
Please send an e-mail to docs@mysql.com for more information or if you are interested
in doing a translation.
For information about how the MySQL licenses work in practice, please refer to Section 1.4.3
[MySQL licenses], page 16. Also see Section 1.4.4 [MySQL AB Logos and Trademarks],
page 18.

1.4.3 MySQL Licenses

The MySQL software is released under the GNU General Public License (GPL),
which is probably the best known Open Source license. The formal terms of
the GPL license can be found at http://www.gnu.org/licenses/. See also
http://www.gnu.org/licenses/gpl-faq.html and http://www.gnu.org/philosophy/enforcing-gpl.h
Chapter 1: General Information 17

Since the MySQL software is released under the GPL, it may often be used for free, but
for certain uses you may want or need to buy commercial licenses from MySQL AB at
https://order.mysql.com/. See http://www.mysql.com/products/licensing.html for
more information.
Older versions of MySQL (3.22 and earlier) are subject to a stricter license
(http://www.mysql.com/products/mypl.html). See the documentation of the specific
version for information.
Please note that the use of the MySQL software under commercial license, GPL, or the old
MySQL license does not automatically give you the right to use MySQL AB trademarks. See
Section 1.4.4 [MySQL AB Logos and Trademarks], page 18.

1.4.3.1 Using the MySQL Software Under a Commercial License

The GPL license is contagious in the sense that when a program is linked to a GPL program
all the source code for all the parts of the resulting product must also be released under
the GPL. If you do not follow this GPL requirement, you break the license terms and forfeit
your right to use the GPL program altogether. You also risk damages.
You need a commercial license:
• When you link a program with any GPL code from the MySQL software and don’t want
the resulting product to be licensed under GPL, perhaps because you want to build a
commercial product or keep the added non-GPL code closed source for other reasons.
When purchasing commercial licenses, you are not using the MySQL software under GPL
even though it’s the same code.
• When you distribute a non-GPL application that only works with the MySQL software
and ship it with the MySQL software. This type of solution is considered to be linking
even if it’s done over a network.
• When you distribute copies of the MySQL software without providing the source code
as required under the GPL license.
• When you want to support the further development of the MySQL database even if you
don’t formally need a commercial license. Purchasing support directly from MySQL AB
is another good way of contributing to the development of the MySQL software, with
immediate advantages for you. See Section 1.4.1 [Support], page 15.
If you require a license, you will need one for each installation of the MySQL software. This
covers any number of CPUs on a machine, and there is no artificial limit on the number of
clients that connect to the server in any way.
For commercial licenses, please visit our website at http://www.mysql.com/products/licensing.html.
For support contracts, see http://www.mysql.com/support/. If you have special needs
or you have restricted access to the Internet, please contact our sales staff via e-mail at
sales@mysql.com.

1.4.3.2 Using the MySQL Software for Free Under GPL

You can use the MySQL software for free under the GPL if you adhere to the
conditions of the GPL. For additional details, including answers to common ques-
18 MySQL Technical Reference for Version 4.1.1-alpha

tions about the GPL, see the generic FAQ from the Free Software Foundation at
http://www.gnu.org/licenses/gpl-faq.html. Common uses of the GPL include:
• When you distribute both your own application and the MySQL source code under the
GPL with your product.
• When you distribute the MySQL source code bundled with other programs that are not
linked to or dependent on the MySQL system for their functionality even if you sell the
distribution commercially. This is called mere aggregation in the GPL license.
• When you are not distributing any part of the MySQL system, you can use it for free.
• When you are an Internet Service Provider (ISP), offering web hosting with MySQL
servers for your customers. We encourage people to use ISPs that have MySQL support,
as this will give them the confidence that their ISP will, in fact, have the resources to
solve any problems they may experience with the MySQL installation. Even if an ISP
does not have a commercial license for MySQL Server, their customers should at least
be given read access to the source of the MySQL installation so that the customers can
verify that it is correctly patched.
• When you use the MySQL database software in conjunction with a web server, you do
not need a commercial license (so long as it is not a product you distribute). This is
true even if you run a commercial web server that uses MySQL Server, because you are
not distributing any part of the MySQL system. However, in this case we would like you
to purchase MySQL support because the MySQL software is helping your enterprise.
If your use of MySQL database software does not require a commercial license, we encourage
you to purchase support from MySQL AB anyway. This way you contribute toward MySQL
development and also gain immediate advantages for yourself. See Section 1.4.1 [Support],
page 15.
If you use the MySQL database software in a commercial context such that you profit by its
use, we ask that you further the development of the MySQL software by purchasing some
level of support. We feel that if the MySQL database helps your business, it is reasonable to
ask that you help MySQL AB. (Otherwise, if you ask us support questions, you are not only
using for free something into which we’ve put a lot a work, you’re asking us to provide free
support, too.)

1.4.4 MySQL AB Logos and Trademarks

Many users of the MySQL database want to display the MySQL AB dolphin logo
on their web sites, books, or boxed products. We welcome and encourage this,
although it should be noted that the word MySQL and the MySQL dolphin logo are
trademarks of MySQL AB and may only be used as stated in our trademark policy at
http://www.mysql.com/company/trademark.html.

1.4.4.1 The Original MySQL Logo

The MySQL dolphin logo was designed by the Finnish advertising agency Priority in 2001.
The dolphin was chosen as a suitable symbol for the MySQL database since it is a smart, fast,
and lean animal, effortlessly navigating oceans of data. We also happen to like dolphins.
Chapter 1: General Information 19

The original MySQL logo may only be used by representatives of MySQL AB and by those
having a written agreement allowing them to do so.

1.4.4.2 MySQL Logos that may be Used Without Written


Permission

We have designed a set of special Conditional Use logos that may be downloaded from
our web site at http://www.mysql.com/press/logos.html and used on third-party web
sites without written permission from MySQL AB. The use of these logos is not entirely
unrestricted but, as the name implies, subject to our trademark policy that is also available
on our web site. You should read through the trademark policy if you plan to use them.
The requirements are basically as follows:
• Use the logo you need as displayed on the http://www.mysql.com/ site. You may
scale it to fit your needs, but may not change colours or design, or alter the graphics
in any way.
• Make it evident that you, and not MySQL AB, are the creator and owner of the site that
displays the MySQL trademark.
• Don’t use the trademark in a way that is detrimental to MySQL AB or to the value of
MySQL AB trademarks. We reserve the right to revoke the right to use the MySQL AB
trademark.
• If you use the trademark on a web site, make it clickable, leading directly to
http://www.mysql.com/.
• If you are use the MySQL database under GPL in an application, your application must
be Open Source and must be able to connect to a MySQL server.
Contact us via e-mail at trademark@mysql.com to inquire about special arrangements to
fit your needs.

1.4.4.3 When do you need a Written Permission to use MySQL


Logos?

You need written permission from MySQL AB before using MySQL logos in the following cases:
• When displaying any MySQL AB logo anywhere except on your web site.
• When displaying any MySQL AB logo except the Conditional Use logos mentioned pre-
viously on web sites or elsewhere.
Due to legal and commercial reasons we monitor the use of MySQL trademarks on prod-
ucts, books, and other items. We usually require a fee for displaying MySQL AB logos on
commercial products, since we think it is reasonable that some of the revenue is returned
to fund further development of the MySQL database.

1.4.4.4 MySQL AB Partnership Logos

MySQL partnership logos may be used only by companies and persons having a written
partnership agreement with MySQL AB. Partnerships include certification as a MySQL trainer
or consultant. For more information, please see Section 1.3.1.5 [Partnering], page 14.
20 MySQL Technical Reference for Version 4.1.1-alpha

1.4.4.5 Using the word MySQL in Printed Text or Presentations

MySQL AB welcomes references to the MySQL database, but it should be noted that the word
MySQL is a trademark of MySQL AB. Because of this, you must append the trademark symbol
(TM) to the first or most prominent use of the word MySQL in a text and, where appropriate,
state that MySQL is a trademark of MySQL AB. For more information, please refer to our
trademark policy at http://www.mysql.com/company/trademark.html.

1.4.4.6 Using the word MySQL in Company and Product Names

Use of the word MySQL in product or company names or in Internet domain names is not
allowed without written permission from MySQL AB.

1.5 MySQL 4.0 In A Nutshell

Long promised by MySQL AB and long awaited by our users, MySQL Server 4.0 is now
available in production version.
MySQL 4.0 is available for download from http://www.mysql.com/ and from our mirrors.
MySQL 4.0 has been tested by a large number of users and is in production use at many
large sites.
The major new features of MySQL Server 4.0 are geared toward our existing business and
community users, enhancing the MySQL database software as the solution for mission-
critical, heavy-load database systems. Other new features target the users of embedded
databases.
MySQL Version 4.0.12 was declared stable for production use in March 2003. This means
that, in future, only bug fixes will be done for the 4.0 release series and only critical bug fixes
will be done for the older 3.23 series. See Section 2.5.2 [Upgrading-from-3.23], page 121.
New features to the MySQL software are being added to MySQL 4.1 which is now also
available (alpha version). See Section 1.6 [MySQL 4.1 In A Nutshell], page 22.

1.5.1 Features Available From MySQL 4.0

Speed enhancements
• MySQL 4.0 has a query cache that can give a huge speed boost to appli-
cations with repetitive queries. See Section 6.9 [Query Cache], page 560.
• Version 4.0 further increases the speed of MySQL Server in a number
of areas, such as bulk INSERTs, searching on packed indexes, creation of
FULLTEXT indexes, and COUNT(DISTINCT).
Embedded MySQL Server introduced
• The new Embedded Server library (instead of client/server) can easily be
used in standalone and embedded applications. See Section 1.5.2 [Nutshell
Embedded MySQL], page 22.
Chapter 1: General Information 21

InnoDB storage engine as standard


• The InnoDB storage engine is now offered as a standard feature of the
MySQL server. This means full support for ACID transactions, foreign keys
with cascading UPDATE/DELETE, and row-level locking are now stan-
dard features. See Section 7.5 [InnoDB], page 577.

New functionality
• The enhanced FULLTEXT search properties of MySQL Server 4.0 enables
FULLTEXT indexing of large text masses with both binary and natural-
language searching logic. You can customise minimal word length and
define your own stop word lists in any human language, enabling a new
set of applications to be built on MySQL Server. See Section 6.8 [Fulltext
Search], page 555.

Standards compliance, portability, and migration


• Features to simplify migration from other database systems to MySQL
Server include TRUNCATE TABLE (as in Oracle) and IDENTITY as a synonym
for automatically incremented keys (as in Sybase).
• Many users will also be happy to learn that MySQL Server now supports
the UNION statement, a long-awaited standard SQL feature.
• MySQL can now run natively on the Novell NetWare 6.0 platform. See
Section 2.6.8 [Novell NetWare], page 162.

Internationalisation
• Our German, Austrian, and Swiss users will note that MySQL now supports
a new character set, latin1_de, which ensures that the German sorting
order sorts words with umlauts in the same order as do German telephone
books.

Usability enhancements
In the process of building features for new users, we have not forgotten requests
from our community of loyal users.
• Most mysqld parameters (startup options) can now be set without taking
down the servers. This is a convenient feature for Database Administrators
(DBAs). See Section 5.5.6 [SET OPTION], page 426.
• Multi-table DELETE and UPDATE statements have been added..
• Support has been added for symbolic linking to MyISAM at the table
level (and not just the database level as before) and for enabling symlink
handling by default on Windows.
• SQL_CALC_FOUND_ROWS and FOUND_ROWS() are new functions that make it
possible to find out the number of rows a SELECT query that includes a
LIMIT clause would have returned without that clause.

The news section of this manual includes a more in-depth list of features. See Section D.3
[News-4.0.x], page 852.
22 MySQL Technical Reference for Version 4.1.1-alpha

1.5.2 Embedded MySQL Server

libmysqld makes MySQL Server suitable for a vastly expanded realm of applications. Using
the embedded MySQL server library, one can embed MySQL Server into various applications
and electronics devices, where the end user has no knowledge of there actually being an
underlying database. Embedded MySQL Server is ideal for use behind the scenes in Internet
appliances, public kiosks, turnkey hardware/software combination units, high performance
Internet servers, self-contained databases distributed on CD-ROM, and so on.
Many users of libmysqld will benefit from the MySQL Dual Licensing. For those not
wishing to be bound by the GPL, the software is also made available under a commercial
license. The embedded MySQL library uses the same interface as the normal client library,
so it is convenient and easy to use. See Section 9.1.15 [libmysqld], page 731.

1.6 MySQL 4.1 In A Nutshell

MySQL Server 4.0 laid the foundation for new features such as nested subqueries and Uni-
code (implemented in version 4.1) and for the work on SQL-99 stored procedures being done
for version 5.0. These features come at the top of the wish list of many of our customers.
With these additions, critics of the MySQL Database Server have to be more imaginative
than ever in pointing out deficiencies in the MySQL Database Management System. Already
well-known for its stability, speed, and ease of use, MySQL Server will be able to fulfill the
requirement checklists of very demanding buyers.

1.6.1 Features Available From MySQL 4.1

The features listed in this section are implemented in MySQL 4.1. Few other features are
still planned for MySQL 4.1. See Section 1.9.1 [TODO MySQL 4.1], page 50.
Most new features being coded, such as stored procedures, will be available in MySQL 5.0.
See Section 1.9.2 [TODO MySQL 5.0], page 50.
Support for subqueries and derived tables
• Subqueries are now supported. Here is an example:
SELECT * FROM t1 WHERE t1.a=(SELECT t2.b FROM t2);

SELECT * FROM t1 WHERE (1,2,3) IN (SELECT a,b,c FROM t2);


• Derived tables (unnamed views) are now supported. Basically, a derived
table is a subquery in the FROM clause of a SELECT statement. Here is an
example:
SELECT t1.a FROM t1, (SELECT * FROM t2) t3 WHERE t1.a=t3.a;
Speed enhancements
• Faster binary protocol with prepared statements and parameter binding.
See Section 9.1.4 [C API Prepared statements], page 698.
• BTREE indexing is now supported for HEAP tables, significantly improving
response time for non-exact searches.
Another random document with
no related content on Scribd:
Ogni reporter faceva bottino di nomi e di documenti onde metterli a
disposizione del proprio giornale, il quale, a seconda del partito
politico, delle sue attinenze e delle influenze, ne usava a proposito
ed a sproposito. Miscela di verità e di calunnie, di esagerazioni e di
pietose o interessate soppressioni. La confusione degli innocenti ai
colpevoli giovava al Governo, che frattanto sopprimeva nomi,
sottraeva documenti, a beneficio de’ suoi, o per ricattare gli avversari
più temibili, col silenzio momentaneo, forte della minaccia di
rivelazioni successive...
Giuliano, il quale, assestati i suoi affari coll’Istituto Romano, munito
della dichiarazione del saldo completo d’ogni suo conto col detto
Istituto, si credeva ormai al sicuro da ogni accusa, vedeva invece
ogni giorno il proprio nome correre su per i giornali, con quelli dei
più compromessi fra i malfattori politici.
Nelle liste, astutamente divulgate dai magistrati, il suo nome
compariva pur sempre fra i debitori... Una sua dichiarazione formale,
stampata sull’Ordine e sul Parlamentare, non servì. Ormai lo si
accusava di aver offerti servigi politici al direttore dell’Istituto, e lo si
additava come uno fra quelli contro cui l’autorità giudiziaria avrebbe
proceduto.
Giorni terribili quelli, di umiliazioni, di agitazioni, di terrori...
Ruggeri nell’ora triste era ritornato, e Lastri non abbandonava il
giovane amico.
Ma, pur troppo, l’autorità giudiziaria nelle lettere di pura cortesia
dell’on. Sicuri si ostinava a trovare un reato... L’intervento
dell’onorevole Lastri non aveva servito... Le vittime si volevano, per
poter salvare i rei influenti, altolocati, potenti... L’opinione pubblica
era assetata di riparazioni, di soddisfazioni... Nel 93 la ghigliottina,
ora la morte civile.
La marchesa Giulia, vera eroina, per salvare l’amante aveva messo in
gioco tutte le influenze della contessa Marcellin, non risparmiandosi
per proprio conto.
Avvocato difensore irresistibile per la bellezza affascinante, il casato
illustre, le ricchezze, era corsa per tutti i ministeri, aveva perorato
presso tutti gli alti magistrati, aveva bussato a tutte le porte di
personaggi politici, non chiedendo grazia, invocando giustizia.
Giuliano, incapace alla lotta, si era ripiegato su sè stesso, chiudendo
gli occhî, come i bambini per non veder la folgore, turandosi gli
orecchî, impaurito dal fragore del tuono.
Spinto alla Camera dalla volontà di Ruggeri, alla quale non sapeva
resistere, sotto la rispettata protezione dell’onorevole Lastri,
occupava ogni giorno il proprio banco di deputato,
nell’atteggiamento di colpevole piuttosto che di innocente.
In quel mattino correva voce che alla presidenza fossero giunte le
domande a procedere contro alcuni deputati.
Giuliano, pallido come cadavere, stava assiso al suo banco, straziato
dal dubbio d’essere compreso fra gli accusati... Gli sembrava che
tutti gli sguardi fossero rivolti su di lui. Per nascondere il proprio
turbamento fingeva scrivere, ma in realtà non tracciava che parole
senza senso... Non udì una sillaba della lettura del verbale, gli
pareva sognare... il sogno tormentoso della notte del suo primo
viaggio di deputato da Miralto, la stessa visione, le risa ed i cachinni
dei colleghi, che lo beffeggiavano, la stessa apparizione; là in alto,
come in una nube, Adele e il suo bimbo!...
La carta su cui la mano inconsciente tracciava i caratteri era bagnata
di lacrime...
L’onorevole Boemi, brav’uomo, vicino di banco a Giuliano... a
susurrargli all’orecchio:
— Coraggio, Sicuri... Tutti ti rendono giustizia... Via! Sii uomo!
Giuliano, richiamato alla realtà, si asciugò frettolosamente gli occhi,
serrando riconoscente la mano al collega...
Un silenzio di tomba s’era fatto nell’aula affollata... I deputati, scesi
nell’emiciclo, all’invito del presidente ritornavano ai loro posti,
compresi della gravità della situazione sentendo tutta l’importanza
delle comunicazioni preannunziate.
Le tribune erano gremite. Pure sarebbesi detto che gli spettatori
rattenessero il respiro per meglio udire, tant’era il silenzio.
Spettacolo imponente, solenne, emozionante quanto quello di una
degradazione militare.
Un colpo di campanello, ed il presidente annunziò essergli
pervenuta, inviata dall’autorità giudiziaria, la domanda di
autorizzazione a procedere contro un deputato.
La comunicazione era aspettata, pure un bisbiglio si sollevò
dall’assemblea, bisbiglio subito represso dagli zittìi universali e da un
rintocco del campanello. Udite! Udite!
Per nessuna catastrofe di dramma, a nessuna Corte d’Assise,
nell’imminenza del verdetto, l’ansiosa aspettazione del pubblico fu
maggiormente tesa.
La lettera del procuratore del re al presidente della Camera
particolareggiava minutamente le prime indagini della giustizia dopo
l’arresto degli imputati appartenenti all’Istituto Romano e complici.
Dalle deposizioni degli accusati, dai documenti sequestrati appariva
che ingenti somme di danaro furono spese dall’Istituto nell’intento di
ottenere l’approvazione della «legge per la proroga del privilegio
della emissione dei biglietti di banca», legge dal Parlamento votata
infatti.
Giuliano, ricordando di aver appunto scritto qualche cosa in
proposito al direttore dell’Istituto, non dubitava più di essere
compreso fra gli accusati; si sentiva morire, avrebbe voluto essere
cento metri sotterra.
Nella tensione d’animo in cui si trovava, tanto apparsagli chiara la
propria compromissione, sarebbe svenuto, se, in quel mentre, un
usciere non gli avesse recato una lettera dai noti caratteri... L’aperse
e, con difficoltà per la vista ottenebrata, potè decifrare:
«Giuliano,
«Ritorno ora dall’ufficio del procuratore generale. Nessuna accusa
contro di te.
«L’inchiesta trovò regolarissimi i tuoi conti... Le tue lettere
inconcludenti... Salvo! Ed io, nella felice certezza, ti amo ancor più.
«Giulia.»

L’onorevole Sicuri non credette a’ suoi occhî... Rilesse nuovamente


per convincersi di non aver errato... Alzò lo sguardo alla tribuna della
presidenza, come per aver un’affermazione di quella notizia che
poteva essere una pietosa bugia; riconobbe l’amica, indovinò il di lei
sorriso... Giulia salutava scuotendo leggermente il fazzoletto,
raggiante di gioja.
La lettura del presidente continuava nel più profondo silenzio,
appena turbato tratto tratto da qualche bisbiglio... Il nome del
deputato accusato, De Respi, era stato pronunziato, e il documento
assumeva il carattere d’una fiera requisitoria, che non doveva essere
l’ultima, perchè il magistrato preannunziava nuove procedure contro
altri deputati.
Gli articoli invocati del Codice penale erano il 168, il 63, il 171, il 172
ed il 204; ognuno dei quali comminava più anni di carcere.
Come un brivido di terrore, forse di pietà, corse per l’assemblea.
Impressione profonda, terribile.
Terminata la lettura, i banchi, le gallerie si spopolarono.
Scena indimenticabile... Il deputato De Respi, il colpito dall’accusa
giudiziaria, era rimasto solo al suo banco, in atteggiamento in
apparenza impassibile, quasi sorridente. Si alzò, con mano ferma
raccolse le carte, e fattone un plico, che mise sotto braccio, si
dispose ad uscire. Ristette; nella di lui mente d’artista balenò forse
un ricordo, come al narratore, che assisteva dalle tribune pubbliche a
quel dramma: il plotone di fucilazione del maresciallo Ney,
rappresentato dal pennello di Gérome... I soldati guidati da
un’ufficiale, i quali, ad eccidio compiuto, se ne vanno riguardando
con pietà paurosa la vittima inanimata, stesa al suolo bocconi. Così
gli onorevoli, uscenti a frotte dall’aula, si volgevano al colpito dalla
morte civile con sguardo pietoso ed impaurito... La solennità
dell’esecuzione li aveva commossi.
Nessuno dubitava della di lui reità, per il rapido patrimonio
ammassato, per la nomea di audace affarista; ma il collega così
ucciso dalla spada della giustizia, che lo coglieva al sommo della
popolarità, alla vigilia di afferrare l’ambito portafogli, era sì
miseranda catastrofe, che atterriva... I complici suoi, minacciati
anch’essi dal rigido magistrato, s’eran dileguati esterrefatti.
L’onorevole De Respi ristette e, portata una mano al cuore, come per
uno spasimo improvviso, ricadde a sedere. Un coraggioso collega
accorse a lui, l’esempio fu imitato da altri e, l’infelice, nell’ora fatale
dell’espiazione, ebbe il conforto della generosa pietà anche di
qualche avversario.
Di tutto ciò nulla aveva notato Giuliano, che, abbandonata l’aula,
saliva alla tribuna della presidenza, onde ringraziare Giulia, ed
effondere tutta la riconoscenza per l’amica devota, tutta la gioja per
lo scampato pericolo.
L’emozione aveva spezzata la debole fibra. La lieta notizia, giuntagli
tanto improvvisamente, il repentino passaggio dai dubbî accascianti
alla consolante certezza della propria innocenza riconosciuta, avevan
potuto più del supplizio sì lungamente durato; quando fu al limitare
della tribuna, non resse e svenne stramazzando a terra, mal
sostenuto dall’usciere, che, vedendolo barcollare, gli era accorso in
ajuto.
Dai pochi presenti nel corridojo fu scambiato per il deputato De
Respi... l’accusato.
La marchesa Giulia gli prestò le prime cure nell’appartamento della
presidenza. Appena potè reggersi, Giuliano, ospitato nella carrozza
della marchesa, fu ricondotto al di lui appartamento, preceduto da
Ruggeri, avvertito dell’accaduto.
Divorato dalla febbre, fu posto a letto delirante. Febbre cerebrale,
avea dichiarato il medico, sollecitamente chiamato.
Al capezzale, silenziosi, Giulia ed Ettore, che, avversarî fra loro,
dall’amicizia e dall’amore erano stati riuniti nella stessa opera di
carità. Entrambi testimonî dei vaneggiamenti del povero naufrago,
da entrambi, con affetto sì diverso, egualmente amato.
Dei due afflitti, in quei momenti di ansia, sarebbe stata Giulia la più
infelice, non udendo mai il proprio nome pronunziato dal
febbricitante, il quale nel delirio non invocava che Adele; più infelice
sarebbe stata, se Ettore non avesse portato in cuore ben altro
tormento.
L’ultimo addio a Stella era stato dato sulla bara della madre.
Ultimo addio, senza speranza di ritorno. La morente aveva ribadito
nel testamento il divieto alla figlia. Per ciò il notajo Invernizzi erasi
mostrato a conoscenza dell’amore di Ettore, che avrebbe già portato
oltre l’oceano la propria disperazione se l’amicizia per Giuliano non
gli avesse imposto di rimanere, guida ed ajuto, nelle disastrose
peripezie.
Dissi avversarî, Giulia ed Ettore... Non per antipatie personali. Ettore
era l’amico della famiglia Sicuri; Giulia l’intrusa, che la felicità di
quella famiglia aveva distrutta.
Giulia istintivamente indovinava tutta l’avversione che Ruggeri
doveva nutrire per lei e lo detestava, protesta perenne contro
l’amore di Giuliano, ad essa perenne rimprovero.
Entrambi al letto del delirante, egualmente solleciti nel soccorrerlo,
non avevan discorso che a monosillabi e sempre per cose attinenti al
loro mandato, alla loro missione di infermieri.
Il medico era ritornato a sera; la febbre era aumentata, il pericolo si
aggravava. Giulia non si era allontanata dal capezzale che alla
venuta del medico; quando se ne fu andato, rientrò nella camera del
malato per chiedere premurosamente notizia del responso della
scienza.
— Giuliano è sempre più aggravato; a me incombe l’obbligo di
avvertire la contessa Sicuri... Sarà bene, quindi, ch’ella lasci il posto
di suora a chi ha il dovere ed il diritto di occuparlo.
— Mi scaccia? chiese quasi supplicante Giulia.
— Non lo dica... La parola è dura e non risponde alla verità. Vi sono
esigenze più forti della nostra volontà... Sarà mia cura mandarle
notizie replicatamente ogni giorno. Ella deve comprendere che la
contessa, già abbastanza infelice, non deve incontrarla qui.
Giulia non rispose; non aveva argomento da opporre. Solo
argomento il suo amore, la ragione appunto per cui la di lei presenza
in quella casa diveniva incompatibile. Lo comprese e chinò il capo
rassegnata.
— Quando verrà la contessa? chiese, gli occhî pieni di lacrime.
— Non so... Le telegraferò ora... Domani certamente.
— Dunque fino a domani? Acconsente?
— Dovrei dirle di no. Fra poco la notizia della malattia di Giuliano
sarà divulgata... I visitatori affluiranno... Ho data la consegna di non
lasciar passare alcuno, eccezione per l’onorevole Lastri; ma una
indiscrezione dei domestici... Se la contessa venisse a sapere che il
suo posto era preso da lei...
Giulia asciugò gli occhî e lentamente, a ritroso, raccolse i suoi oggetti
sparsi per la camera, il cappello, i guanti, l’ombrellino, l’enorme
portafogli in lampasso antico trapunto, con lentezza, per ritardare di
qualche minuto la sua andata; assestò il cappello davanti lo
specchio. Quando non ebbe altri pretesti a ritardare, posò sul
tavolino da notte del malato una boccetta d’oro da sali, ricordo, della
visita sua, e fattasi incontro a Ruggeri, il quale, ritto, ai piedi del
letto, la considerava commosso, gli porse la piccola mano
inguantata:
— Conto sulla sua parola, signor Ruggeri; mi mandi notizie tre o
quattro volte al giorno... E... e, soggiunse, se la contessa non
venisse, mi richiami.
Ettore promise... Giulia, riavvicinatasi al capezzale del caro malato,
inchinatasi graziosamente, depose un lungo bacio sulla fronte
infocata... Il malato si scosse, aperse gli occhî, fissò attonito Giulia,
un sorriso gli sfiorò le labbra, e ricadde nel sopore.
— Mi ha riconosciuta, mormorò ad Ettore raggiante di speranza... Il
medico si è ingannato... Si ricordi! Se non venisse, mi richiami... Il
cuore mi dice che non verrà.
— Impossibile, replicò Ettore.
La marchesa uscì mandando ancora un saluto al suo povero
Giuliano.
CAPITOLO XXI.
Cospirazioni.

La marchesa si era apposta al vero; la contessa Adele non accorse


alla chiamata di Ettore.
Le indiscrezioni dei giornali avevano prevenuto il di lui richiamo.
Che cosa non sanno i corrispondenti telegrafici di Roma ai giornali
del mondo intiero?
Quando non sanno inducono, qualche volta inventano senza bisogno
di induzioni, e spesso indovinano.
Non vi è polizia meglio fatta di quella dei reporters, che ne sanno
sempre assai più e più sollecitamente delle questure internazionali...
Quantunque concorrenti nella gara alla notizia, allo scandalo,
all’incidente, sono fra essi legati da un certa solidarietà, mutuo
soccorso nel comunicarsi reciprocamente le informazioni,
subordinatamente all’ora dell’uscita dei rispettivi giornali.
Spedita la primizia al proprio foglio in tempo utile per l’edizione più
prossima, la informazione, la notizia ed anche il canard inventato di
pianta diventa di dominio pubblico nella sala della stampa, al palazzo
di San Silvestro, grande cucina di manicaretti offerti alla pubblica
curiosità affamata d’Italia e dell’orbe.
Appena divulgatasi la notizia del malessere sopraggiunto al deputato
Sicuri, fu un via vai degli informatori giornalistici per attingere i
particolari... L’usciere della tribuna della presidenza fu intervistato
come un grande personaggio politico. Si sapeva che il deputato era
stato condotto alla sua abitazione nella carrozza della marchesa. Il
portiere di Giuliano fu assediato... Per quanto discreto, non potè
negare che la marchesa Giulia fosso presso il malato; la carrozza
rimasta alla porta quasi l’intiera giornata ne era la prova evidente, e
sui fili telegrafici, con ogni sorta di esagerazioni, correva la notizia
che l’onorevole Sicuri era amorosamente vegliato dalla bella
marchesa. Seguivano le iniziali. A seconda, poi del carattere del
corrispondente, dell’indole del giornale, commenti, indiscrezioni, più
o meno vere, più o meno fantastiche.
Lo sdegno della contessa Adele mutò in ira feroce, in odio. Ed alla
chiamata di Ruggeri rispondeva:
«Ben altri doveri mi trattengono a Miralto: il mio bimbo malato, la
povera Stella, la mia orfana, inconsolabile per la grande sventura... A
Roma turberei gli amori di un uomo indegno che non ha più famiglia
avendola ripudiata.»
Ruggeri non riconosceva in quella lettera la mite, affettuosa
contessa. La donna offesa nel suo amore, nella propria dignità,
aveva trasformato la dolce sposa in nemesi...

*
* *
Mentre Giuliano andava migliorando, assistito ogni giorno da Giulia,
ad onta delle proteste di Ettore, altro dramma politico svolgevasi, al
quale la voce pubblica voleva ad ogni patto accomunare il nome di
Giuliano.
Il deputato De Respi, il colpito dalla giustizia, era stato ferito a
morte. Il mandato di comparizione del giudice aveva seguito
immediatamente l’autorizzazione a procedere.
L’evidenza delle prove della di lui colpabilità non lo indussero a
confessare... Ma rientrato, disfatto dalla lotta impegnata col giudice,
si metteva a letto per non più rialzarsi.
Il pubblico che non crede alla logica di certi scioglimenti, lo proclamò
suicida, e vi furono i pietosi che lo compiansero vittima.
Il funerale fu sontuoso e celebravasi appunto il giorno nel quale
Giuliano, convalescente, per la prima volta affacciavasi alla finestra.
Il corteo funebre si avviava alla stazione, la salma dovendo essere
inumata nel cimitero del paesello nativo.
La banda municipale romana che precedeva il feretro eseguiva una
marcia straziante, tutta lamenti e gemiti di dolore... Al defunto,
strappato dalla morte all’azione della giustizia, rendevansi solenni gli
onori ufficiali, dovuti ai rappresentanti della nazione... Il carro
riboccava di corone. Le notabilità parlamentari lo seguivano, poi
lunga fila di carrozze signorili, fra due siepi di popolo, più attonito
che curioso. Attonito per quelle onoranze rese all’accusato da dieci
giorni in balìa agli spietati commenti della stampa, alle rivelazioni
schiaccianti di fatti innegabili, ormai dall’universale ammessi e
condannati.
— Chi è morto? chiese Giuliano all’onorevole Lastri che lo reggeva al
davanzale.
— Un disgraziato! Un’altra vittima dell’ambizione, della sensualità,
della megalomania... Vittima, ma colpevole, ha espiato colla morte...
Invochiamo l’oblìo sulla sua bara...
— Ma, chi? Chi è?
— Fu il deputato De Respi.
— Morto? Come? Suicida?
— Forse. I medici dicono aneurisma; il pubblico replica veleno.
Giuliano ancor debole si ritrasse come impaurito dalla finestra e
s’adagiò su d’una poltrona soggiungendo:
— Sarebbe stato assai meglio anche per me morire così.
— Bravo! per accomunarti ai colpevoli, ai ladri. Che c’entri tu coi
corrotti, coi corruttori?... Ti sei mangiato il tuo, hai fatto male; ma di
ciò non devi render conto al pubblico... Se tu sapessi! Nel caso tuo
ve ne sono cento alla Camera... Te l’ho detto: Montecitorio è un
ammazzatojo di riputazioni, è un abisso per i piccoli patrimonî... Tu
sei giovane. Hai l’avvenire per te, il tempo di riparare alle tue
balordaggini.
— Giovane! L’avvenire... Ho perduto la famiglia... E non ho di che
vivere.
— Si rimedia a tutto... Ritorna a Miralto...
— Impossibile...
Si coperse il volto colle mani, per nascondere le lacrime.
— Eravamo troppo felici!... soggiunse singhiozzando.
Da lungi gemevano, strazianti, gli ottoni... Lastri, non sapendo quale
conforto porgere alla disperazione del giovane protetto, stette
silenzioso scrollando il capo in atto di pietà.
Giuliano soggiunse:
— Partirò con Ettore, se mi vorrà compagno. Darò le dimissioni alla
Camera.
— Oh, non ora! Sarebbero interpretate come una confessione di
colpabilità... Un congedo... Poi, al tuo ritorno, che spero vicino, tutto
sarà assestato... A Miralto, soggiunse sorridente, ti accoglieranno
come il figliuol prodigo... Prodigo davvero, povero Giuliano!
«Ma l’avrai la forza di partire, di rompere ogni rapporto colla... colla
marchesa?
Non rispose; vagava collo sguardo azzurro impaurito per la camera,
tutta piena di cari ricordi... E quasi avesse fatto un esame di
coscienza, un lungo esame:
— Spero di sì!
— La speranza bisogna tradurla in certezza. È necessario... La
lontananza ed il tempo guariscono i più grandi dolori!
«Se saprete osare, potrete entrambi ritrovare la calma, se non la
felicità. Per te anche la famiglia. È un dovere sacrosanto per
entrambi.
— L’adempirò! mormorò Giuliano.
— Giuramento da marinajo, pensò Lastri...
Poi con amorevolezza che non si sarebbe potuta supporre nel ruvido,
vecchio parlamentare:
— La musica è cessata, finalmente. Tra poco la salma di quel
disgraziato sarà in viaggio. Il romanzo è finito. Quegli ha cominciato
di te a rovescio... Anch’egli forse, come te, portava a Montecitorio
illusioni e propositi generosi... Ma, povero, fu costretto alle prime
transazioni da esigenze che, se potessero essere valutate sulla
bilancia della rigida morale, varrebbero forse l’assoluzione.
«Sventuratamente, su quella via è soltanto il primo passo che
costa... E le seduzioni sono tali e tante... tali e tanti gli esempî dei
fortunati saliti in alto non per i meriti loro, per l’audacia e l’intrigo,
che in quell’ospedale di malarici ch’è Montecitorio, l’onestà finisce col
sembrare un fardello troppo pesante a chi vuol far cammino.
«E infatti, pochi gli integri che sono arrivati anche in tempi migliori,
pochissimi quelli che arriveranno in seguito. Giuliano, il sigaro ti dà
noja? chiese facendo pausa l’onorevole Lastri, per lasciar tempo
all’amico di meditare su ciò ch’egli aveva detto, e tempo a prepararsi
a ciò che stava per dirgli.
Il convalescente accennò col capo di no.
Chi fosse stato presente a quel colloquio avrebbe certamente
ripensato al consulto del dottor Nero, di Alfredo De Vigny, al giovane
nevropatico Stello. La Ragione e l’Imaginazione.
Giuliano, come Stello malato ed annichilito dai disinganni giovanili; il
Lastri fisiologo freddo e stringente nelle sue deduzioni, quanto il
dottor Nero.
— Quegli, continuò l’onorevole Lastri, povero, si arricchì ed al
momento di afferrare pel ciuffo definitivamente la Fortuna che lo
lusingava facendogli balenare imminenti i più alti onori, moriva
suicida per salvarsi dall’onta di una condanna infamante.
«Tu, ricco, sei stato rovinato e per poco non sei morto disonorato.
Ed ora che ti manca anche l’indipendenza, la felice indipendenza
dell’agiatezza, vorresti ricominciare?
«Una buona idea ti è venuta; seguila, parti con Ruggeri...
Riconquisterai al ritorno, colla famiglia, la felicità perduta... Spezza la
catena infiorata di rose che ti costringe a Roma... L’odio della
contessa Adele è amore... È l’ira dell’amore tradito... Te assente,
nessun motivo di continuare negli atti legali per la separazione,
vendetta della quale essa sarebbe la prima vittima. Credi a me! non
si domanda la testa di un uomo indifferente, ed Erodiade non
avrebbe voluta quella di Giovanni Battista, se non l’avesse
pazzamente amato...
«Deciditi... Al ritorno, la calma nelle gioje della casa, che colla tua
indole, col tuo carattere, non avresti mai dovuto abbandonare.
Giuliano, il capo rovesciato sullo schienale della poltrona, lacrimava
assentendo.
— Lo prometti? riprese l’onorevole Lastri.
— Lo prometto! rispose con voce strozzata il malato.
— Sta bene... Lascia fare a me ed a Ruggeri. Sopratutto non una
parola alla marchesa de’ nostri progetti. Essa, come sai, deve
assentarsi alcuni giorni dovendo assistere al processo di divorzio
intentato contro il marito.
«La tua malattia ritardò la sua partenza per Parigi... Ora deve
inesorabilmente recarvisi, e tu non sei in istato di accompagnarla...
Durante l’assenza vi imbarcherete. Ne hai il coraggio, te lo senti?
— Sì! rispose flebilmente Giuliano...
— È una trista azione, riprese Lastri, ne convengo... Necessaria! Ad
estremi mali, estremi rimedî.
Giuliano assentiva senza poter staccare lo sguardo dal ritratto ad olio
di Giulia, sorridente nella cornice dorata come nelle ore felici, per
sempre trascorse... Assentiva baciando di soppiatto la boccetta d’oro
di sali, ritrovata sul tavolino da notte al suo svegliarsi dai delirî della
febbre.
Senza volontà nel vigore della salute, nello stato di debolezza in cui
si trovava, Giuliano non sarebbe stato capace di opposizione alcuna.
La sua volontà era quella degli altri; soggetto prezioso per uno
studioso dei fenomeni ipnotici, ogni atto di lui era effetto di una
suggestione estranea.
Se in quelle ore di sconforto, la contessa Adele non fosse stata
trattenuta lontana dall’orgoglio ferito, Giuliano sarebbe forse
ritornato a Miralto, senza rimpianto... La partenza della marchesa
Giulia parve provvidenziale a Lastri ed a Ruggeri, che si lusingavano
di aver causa vinta. Strapparlo alla politica ed all’amore di Giulia era
salvarlo.

*
* *
Gli addìi della marchesa furono tristi, anch’essa era punta da un
presentimento... Ma, l’assenza doveva essere sì breve, otto, dieci
giorni al più... Lastri e Ruggeri diffidando del loro malato, ebbero
cura di non lasciarli soli... Però Giuliano mantenne il silenzio
coll’amica sulla cospirazione ordita. E Giulia partì.
— Quel tuo Giuliano mi ha fatto commettere la cattiva azione più
grossa della mia vita, diceva Lastri all’amico Ruggeri, al ritorno dalla
stazione ove erasi recato a salutare la marchesa. La buona
intenzione non attenua nulla. Ci ho il cuore grosso. Ingannare come
abbiamo fatto quella gentile creatura tutta amore e devozione fu un
delitto.
— Lo sarebbe se non si trattasse della pace di una famiglia, di ridare
il padre ad un orfano.
— Quel che vuoi! Ma la marchesa partendo ci guardava con certi
occhî, dubbiosi e supplicanti ad un tempo, che io ne ero commosso...
Non lo dimenticherò mai più quello sguardo e quel sorriso che
pareva pianto. L’abbiamo ingannata, poveretta, come de’ veri
malfattori.
«Mondaccio birbone, quello nel quale bisogna mentire, ingannare
anche a fin di bene!
CAPITOLO XXII.
In mare!

La marchesa Giulia giungeva da Parigi alla stazione Termini di Roma


alle 7 del mattino. Quanto le eran sembrati lunghi i dodici giorni
d’assenza, e quale supplizio le trentacinque ore del viaggio,
nell’ansia, nell’impazienza di arrivare. La velocità vertiginosa del
treno direttissimo, lentezza da tartaruga. Avrebbe voluto aver l’ali
per giungere più presto.
I presentimenti neri che l’avevano accompagnata da Roma a Parigi,
ormai erano giustificati. Da sei giorni non aveva ricevuto un solo
saluto di Giuliano, non una risposta ai telegrammi, alle lettere
innamorate; da sei giorni, ora per ora, senza interruzione inviati.
Che era mai avvenuto? La contessa Marcellin, interpellata
urgentemente, non aveva saputo telegrafarle altro che Giuliano s’era
assentato da Roma, assenza certamente breve, perchè non le aveva
neppur fatta la visita doverosa di congedo. Prima della partenza da
Parigi, Giulia aveva prevenuto l’amico dell’ora dell’arrivo; aveva
ritelegrafato da Modane, da Torino; ritenevasi certa di incontrarlo
alla stazione.
Quale disinganno quando, affacciatasi ansiosa allo sportello dello
sleeping-car, non scorse fra gli aspettanti sotto la tettoja nessun
volto amico: solo il domestico gallonato, che premurosamente le si
fece incontro per ajutarla a scendere, a raccogliere il bagaglio.
— Il conte Sicuri?
Il domestico, meravigliato, atteggiò la fisionomia ad interrogante.
— È forse nuovamente ammalato?
— Non lo so, signora marchesa... Qui alla stazione non l’ho veduto.
Ricordando la manìa di Ruggeri e le di lui immancabili visite
mattutine alla stazione, Giulia sperò vederlo... Ruggeri quel mattino
era venuto meno alle sue abitudini.. I viaggiatori eran già tutti
usciti... Ormai vana l’attesa.
Salendo in carrozza, la marchesa diè ordine di fermarsi alla vicina
abitazione del conte.
Era là che la più triste sorpresa aspettava l’infelice Giulia.
La marchesa scese dalla carrozza precipitosamente, e rivoltasi al
portiere intento a scopare, che riconosciutala si era messo alla
posizione militare:
— Il conte Sicuri?
— Il conte Sicuri, signora marchesa? Non lo sa? Non abita più qui.
— Non abita più qui? ripetè atterrita la giovine donna.
Con voce strozzata dall’emozione soggiunse:
— Dove è andato ad abitare?
— Partito!...
E le additò un cartello affisso all’ingresso del portone col tradizionale
Est locanda.
— Partito?
Si sentiva morire, le gambe non la reggevano, dovette aggrapparsi
alla rampa della scala... La vertigine. Un singhiozzo le uscì dal petto:
— Partito!
Con uno sforzo sovrumano tentò dominare l’emozione, per chiedere,
per informarsi, per sapere, sapere tutto; ma impossibile... Il portiere,
che sospettò la tempesta agitantesi nel cuore della signora, le
offerse una seggiola e la invitò a sedersi dietro il suo casotto vetrato,
affinchè i passanti non potessero vederla.
— Si sieda, eccellenza... Se avessi saputo, non le avrei detto...
Scusi... Ma io credevo... Ora si tranquillizzi...
Essa lo guardava supplichevole; sentiva che se avesse pronunziata
una parola sarebbe scoppiata in pianto, e invitavalo a parlare collo
sguardo.
— Il signor conte è sloggiato dieci giorni fa, in fretta e furia; i mobili
furono imballati e spediti non so dove... Ho ordine di mandare alla
Camera tutta la corrispondenza, i giornali che arrivano all’indirizzo
del signor conte.
«Veda, ve ne sono qui due, di telegrammi, l’uno arrivò jersera, l’altro
stanotte...
E presentava a Giulia i due dispacci.
Questa, ancor prima che il portiere potesse opporsi, lacerò la parte
ingommata del piego, impaziente di saper di più; nella speranza di
aver indizî, qualche indicazione, l’aperse e lesse:

«Giungerò domattina 7.34... attendimi stazione...»


«Giulia.»

Ironia feroce! Gettò il foglio e stette muta, annichilita, incerta sulla


decisione da prendere, incapace di una risoluzione; le lacrime le
rigavano il volto; non potendo singhiozzare si sentiva soffocare.
— Partito! Fuggito! Certamente a Miralto! Povera me!
Al pensiero di essere abbandonata da Giuliano, non si era mai
soffermata. Negli impeti più acuti di gelosia aveva bensì, qualche
volta, momenti di rimorso, di dubbio, di scoraggiamento, intraveduto
il pericolo della venuta in Roma della contessa Sicuri, pericolo
possibile, non probabile ormai, e Giulia nella coscienza del fascino su
Giuliano si tranquillava, certa del predominio sulla rivale... pur
ribellandosi all’idea: del partage... Avrebbe lottato, avrebbe vinto!
Ora, non lotta possibile, il tradimento, l’abbandono!
— Non mi ha amata mai... Bastarono sei giorni... Che dico! due
giorni d’assenza, e mi fuggiva coll’inganno... La sua ultima lettera era
tutta amore. Presentimenti tristi... Ma quando si ama, chi non è
turbato al pensiero dell’avvenire? I presentimenti suoi erano
menzogne... Partirò per Miralto! L’ho a me richiamato una volta,
perchè non ora?
E l’orgoglio offeso di Giulia protestava.
— Mendicare nuovamente amore, mentre egli, il miserabile, rifugge
da me? La vendetta!
«Quale vendetta? se io l’amo, l’amo come una misera pazza?
Una risoluzione! Asciugato il pianto, risalì in carrozza.
— Alla Camera dei deputati!
Alla posta della Camera avrebbe avuto l’indirizzo di Giuliano... E
l’ebbe. Non Miralto. Napoli, Hôtel Royal des Étrangers!
Un raggio di gioja, di speranza, balenò nella mente ottenebrata della
marchesa.
— Napoli! Dunque non mi ha abbandonata per la contessa... Napoli!
A che fare a Napoli? Ah!
«Indovino tutto... Per partire con Ruggeri... Partire! La vedremo,
signor Ruggeri! Non mi fa paura! Se non fossi più in tempo?.... Se
fossero partiti?
Risalendo in carrozza, lanciò al cocchiere l’ordine:
— Alla stazione! presto! presto! Alla carriera, urlò la marchesa al
cocchiere che non era partito abbastanza sollecito.
— Per Napoli? Il treno per Napoli, chiese Giulia febbricitante
all’inserviente ferroviario.
— Ora! signora. Solleciti; alle 8.20... Fra dieci minuti, soggiunse
dopo aver data un’occhiata all’orologio.
Il domestico riconsegnò il bagaglio ai facchini, e per ordine della
signora che le porse un biglietto da cento si affrettò allo sportello
— Un primo Napoli.
Dopo dieci minuti il treno partiva, troppo lento per Giulia, torturata
dagli spasimi dell’impazienza.

*
* *
A sera, quando giunse la cameriera di Giulia, partita da Parigi col
grosso bagaglio nel treno successivo a quello preso dalla sua
signora, a sera la cameriera, riferendo alla contessa Marcellin,
inquieta di non aver veduta la nipote, sorpresa dal nuovo viaggio da
essa intrapreso, diceva:
— Ah, contessa, la mia signora è impazzita! Avevo ordine di
raggiungerla a Torino, ove mi avrebbe aspettata, e non vi si è
neppure fermata... Giungo a Roma, ed è ripartita.
— Per quell’imbecille, pensò la contessa, punta da rimorso. La colpa
è mia! Maledetta la sera che ho fatto licenziare la carrozza di Giulia.
Chi poteva sapere che si sarebbero tanto presto combinati, e che la
loro relazione avrebbe presa la piega tragica che quella matta di
Giulia le ha data? Volevo farne un sottosegretario di Stato, invece ho
appioppato a Giulia un fallito.
Nella più grande inquietudine scrisse al commendatore Cerasi,
perchè mettesse la polizia di Napoli in moto e le mandasse notizie
della sua Giulia.

*
* *
Destino? Fatalità? Provvidenza? Se la marchesa Giulia si fosse
arrestata a Torino per attendervi la cameriera come era stato suo
primo pensiero, sarebbe giunta a Napoli troppo tardi, e l’epilogo di
questo triste racconto sarebbe stato tutt’altro. Il piroscafo della
Orient Line salpato per Plymouth-Londra e la marchesa, novella
Didone, avrebbe invano richiamato l’amico attraverso la immensità
dell’oceano.
Giulia giunse all’Hôtel des Étrangers in uno stato indescrivibile...
Pazza, veramente pazza...
— Il conte Sicuri?
— È in casa...
— Il numero della sua camera?...
— Se la signora desidera vederlo, dovrà avere la pazienza di
attenderlo in sala di ricevimento.
— Come vorrete... Aspetterò, ma chiamatelo subito.
— Chi devo annunciare?
— Inutile il nome. Dite che una signora l’attende per cosa urgente.
Condotta alla sala di ricevimento, le forze, che nel parossismo
l’avevano sostenuta, vennero meno... Cadde più che non si sedesse
su d’un divano, in preda ai dubbî più atroci...
— Se Giuliano fosse sordo alle mie preghiere! Se resistesse? Se la
decisione fosse irrevocabile... Oh misera me! Misera me! La
vendetta? E come? Ucciderlo, suicidarmi poi...
Giuliano entrò, Giulia mandò un grido e si slanciò nelle sue braccia,
rompendo in pianto.
Finalmente poteva piangere e l’angoscia che la soffocava si mutò in
gioja suprema... Aveva il suo Giuliano fra le braccia, e nessuno,
nessuno al mondo, ormai, avrebbe potuto rapirglielo.
Non una parola, singulti e scoppî di risa.
Giuliano, commosso, respirava a larghi polmoni ne’ capelli bruni di
Giulia il profumo inebbriante; anch’egli era felice, anch’egli in
quell’istante di delizia infinita era muto, e serrava forsennato alla vita
l’elegante, flessuosa personcina dell’amante, come se avesse voluto
spezzarla nell’abbraccio furente.
Una vecchia dama inglese, che inavvertita stava nella penombra, in
fondo del salone, a quell’amplesso un po’ troppo espansivo e
sconveniente in quel luogo, sorse scandalizzata... Pensando poi che
in quella sala pubblica, dalle porte vetrate semiaperte tanta
affettuosa espansione non poteva essere che legalizzata e
santificata, sorrise compiacente a tanto affetto ed uscì tossendo per
avvertire gli sposi, incontratisi certamente dopo lunga separazione,
della sua presenza... Uscì senza pur mormorare il minimo shocking,
pensando invece:
— Quanto sanno amarsi gli italiani!
E riguardò benevola, chiudendo con fracasso la porta, secondo
avvertimento a Giuliano, che si svincolò, susurrando nell’orecchio di
Giulia:
— C’è gente che ci osserva.
— Che m’importa? disse Giulia. Ti amo!... Non partirai. Non è vero
che non partirai?
— No! no, non partirò... A te, per te, con te, oggi e sempre!
Perdonami, ero tanto infelice!
— Se ti perdono! Ho sofferto, sai, ho sofferto l’inferno... Ma ti
perdono perchè ti amo, perchè, ormai, sono certa del tuo amore.
Ed abbracciò nuovamente l’amico, mormorando:
— Sempre!

*
* *
Quando Giuliano bussò all’uscio della camera di Ettore, nessuno
rispose.
Questi credendo che il compagno fosse nel salotto attiguo, aperse
senz’altro l’uscio e con sorpresa vide l’amico curvato sul letto, il volto
nascosto nel guanciale, il capo fra le mani, atteggiamento da
disperato.
— Ettore! Ettore! gridò Giuliano allarmato... Che hai?
Ettore si rizzò sorpreso, la fisionomia sconvolta, contraffatta come da
una grande sofferenza fisica.
— Chi è là! urlò, senza riconoscere Giuliano. Dopo un istante:
— Ah, sei tu?
— Ettore, che hai? Tu sei malato?
Questi, rimettendosi:
— No! non è nulla... Un capogiro. Ora tutto è passato... La fatica di
questi giorni... Ho scritto troppo... Poi l’imbarco di tutto il materiale...
Non è nulla, ti dico! soggiunse imperiosamente, allo scuotere del
capo di Giuliano in atto di incredulità.
Poi per divergere il discorso:
— Hai tutto preparato? Ci imbarcheremo stasera alle 8. Il vapore
salperà alle 10.
Giuliano non rispose; non sapeva come avvertire l’amico della sua
nuova decisione... Stette titubante...
— Dei nuovi dubbî? Nuove indecisioni?
— Sì... Giulia è arrivata; impossibile partire.
— Giulia arrivata? Impossibile partire? Ma ci pensi? Le tue promesse?
I tuoi propositi? L’annunzio del tuo viaggio?
— Non insistere... Ti dico, che è impossibile...
— Impossibile? È necessario! urlò Ettore sdegnato, percotendo col
pugno lo scrittojo al quale si era appoggiato. Miserabile! saresti
capace anche di questa viltà? Che si dirà di te? Sarai il ridicolo di
Roma, come già per poco non ne fosti il ludibrio.
Giuliano non rispose, il furore dell’amico era giustificato, lo sentiva;
ma sentiva pure che di distaccarsi nuovamente dalla marchesa non
aveva il coraggio...
Si ritirò dicendo una menzogna:
— Hai ragione, ci penserò, vedrò di persuaderla...

*
* *
A sera, quando Ruggeri si recava all’Immacolatella per imbarcarsi,
Giuliano viaggiava per Roma coll’amica...
Quest’ultimo abbandono rattristò profondamente Ruggeri, già tanto
infelice. Partiva colla disperazione in cuore.
Il giorno innanzi, mentre affaccendato nella sua camera d’albergo
stava facendo gli ultimi preparativi al lungo viaggio, il fattorino gli
aveva portato un pacco postale recante il timbro di Miralto.
Indicibile l’emozione provata pensando fossero le sue lettere
rinviategli da Stella.
Non osava aprirlo, il coraggio gli veniva meno. Aveva troppo sofferto,
troppo soffriva.
Presa una decisione eroica, l’aperse. Le sue lettere infatti ed un
involto in un fazzoletto bianco di seta allacciato da un nastro nero.
Sciolse tremante il nodo.
Un grido di sorpresa, di dolore. Le due lunghe, lussureggianti treccie
brune di Stella, barbaramente recise, ultimo ricordo, ultimo saluto di
suor Maria.
Suor Maria! così era firmata la lettera della fanciulla, lettera
straziante nel laconismo sublime.
Ettore impazziva.
Dapprima, come un senso di gioja nell’egoismo d’amante, nella
certezza che Stella non sarebbe stata d’altri mai, fedele alla
promessa, ai giuramenti; ma la gioja brutale fu soffocata dal
rimorso...
— Povera Stella! Sepolta viva in un convento...
E cadde ginocchioni piangendo sulle treccie nere che andava
coprendo di baci.
— È troppo! È troppo!
L’idea del suicidio gli balenò per la prima volta.
— Io morto, essa sarò sciolta da ogni voto; potrà ritornare alla vita,
essere forse felice.
Anche Giuliano l’abbandonava... Troppi, troppi sconforti, troppi
disinganni, troppo dolore. La sua esistenza non aveva più scopo.

*
* *
Il maestoso piroscafo dell’Orient Line navigava veloce nell’Atlantico.
La notte serena, il mare tranquillo, miriadi di stelle in cielo,
scintillante il mare, specchio all’infinito azzurro.
A bordo, silenzio profondo, la respirazione affannosa della macchina,
il friggìo monotono dell’acqua spumeggiante, tagliata dalla prua
acuminata della nave, frullata dal roteare dell’elica, null’altro.
Quando un tonfo ed un grido da poppa:
— Un uomo in mare!
— Un uomo in mare! ripeterono gli uomini di quarto...
L’elica si arrestò come per incanto; i marinaî accorsero solleciti
sbucando dai boccaporti di prua, a guisa di ombre da’ sepolcri
scoperchiati.
Le imbarcazioni furono calate, per due ore una ricerca affannosa,
senza risultato.
Ettore non era più... Degna tomba l’oceano all’immensità del suo
dolore.
*
* *
L’inchiesta di bordo appurò che il suicida si era a notte recato in
macchina ed aveva gettato alle fiamme un fascio di carte. Le sue, le
lettere di Stella.
Lasciava un piego per il deputato Lastri. In quel piego una lunga
lettera alla contessa Sicuri, madre adottiva di Stella; l’ardente
preghiera di strapparla al chiostro.

*
* *
Un poscritto diceva: «Le lettere alle fiamme; le care treccie della mia
Stella adorata, con me nelle profondità dell’Atlantico.»
Alla notizia del triste dramma il commendator Cerasi ebbe una
lacrima. Fenomeno incredibile di sensibilità nel lungo funzionario.
Parlando poi del ritorno di Giuliano alla contessa Marcellin, esclamò:
— Volevamo farne un uomo di Stato e non abbiamo fatto che un
Monsieur Alphonse...
«Prima di creare dei deputati, in avvenire, mi garantirò ben bene del
colore dei loro occhi.
«Quegli occhî blu furono fatali!

FINE.
INDICE

Capitolo
I. Partenza! Pag. 5
II. Finalmente solo! 17
III. In viaggio 29
IV. Roma! 38
V. Il sottoprefetto Cerasi e l’amico
Ferretti 45
VI. Un racconto di Poe 62
VII. A Belvedere 74
VIII. Da Roma a Miralto 90
IX. Un dietroscena politico 112
X. Eros 127
XI. Nella bolgia 145
XII. Intrighi e amore 160
XIII. La seduta reale 179
XIV. Intermezzo 195
XV. La farmacia 210
XVI. Delusioni. — Tristezze 223
XVII. Il crack 237
XVIII. I due voti di Stella 250
XIX. L’interpellanza 273
XX. La bufera 289
XXI. Cospirazioni 300
XXII. In mare! 308
Nota del Trascrittore

Ortografia e punteggiatura originali sono state


mantenute, correggendo senza annotazione minimi errori
tipografici.
Copertina creata dal trascrittore e posta nel pubblico
dominio.

You might also like