refman-5.1-en.a4. 11.50MB 2013-07-11 22:07:17

MySQL 5.1 Reference Manual

MySQL 5.1 Reference Manual
Abstract
This is the MySQL Reference Manual. It documents MySQL 5.1 through 5.1.16-beta.
Due to a build slippage, binary distributions of MySQL 5.1.12 contained neither NDB Cluster
nor Partitioning. We apologize for any inconvenience. Please upgrade to 5.1.14. if you build
from source, you can execute configure with the --with-ndbcluster and -with-partition options.
Document generated on: 2007-03-06 (revision: 5184)
Copyright 1997-2007 MySQL AB
This documentation is NOT distributed under a GPL license. Use of this documentation is subject to the following terms:
You may create a printed copy of this documentation solely for your own personal use. Conversion to other formats is allowed as long as the actual content is not altered or edited in any way. You shall not publish or distribute this documentation
in any form or on any media, except if you distribute the documentation in a manner similar to how MySQL disseminates it
(that is, electronically for download on a Web site with the software) or on a CD-ROM or similar medium, provided however
that the documentation is disseminated together with the software on the same medium. Any other use, such as any dissemination of printed copies or use of this documentation, in whole or in part, in another publication, requires the prior written consent from an authorized representative of MySQL AB. MySQL AB reserves any and all rights to this documentation not expressly granted above.
Please email for more information.

Table of Contents
Preface ............................................................................................................. xxii
1. General Information ........................................................................................... 1
1.1. About This Manual .................................................................................. 1

1.2. Conventions Used in This Manual .............................................................. 2
1.3. Overview of MySQL AB .......................................................................... 4
1.4. Overview of the MySQL Database Management System ................................ 4
1.4.1. What is MySQL? .......................................................................... 4
1.4.2. History of MySQL ........................................................................ 6
1.4.3. The Main Features of MySQL ......................................................... 6
1.5. Overview of the MaxDB Database Management System ................................. 9
1.5.1. What is MaxDB? .......................................................................... 9
1.5.2. History of MaxDB .......................................................................10
1.5.3. Features of MaxDB ......................................................................10
1.5.4. Licensing and Support ..................................................................11
1.5.5. Feature Differences Between MaxDB and MySQL ............................11
1.5.6. Interoperability Features Between MaxDB and MySQL ......................12
1.5.7. MaxDB-Related Links ..................................................................12
1.6. MySQL Development Roadmap ................................................................12
1.6.1. What's New in MySQL 5.1 ............................................................13
1.6.2. What's Planned for MySQL 5.2 ......................................................15
1.7. MySQL Information Sources ....................................................................15
1.7.1. MySQL Mailing Lists ...................................................................15
1.7.2. MySQL Community Support at the MySQL Forums ..........................18

1.7.3. MySQL Community Support on Internet Relay Chat (IRC) ..................18
1.8. How to Report Bugs or Problems ..............................................................18
1.9. MySQL Standards Compliance .................................................................23
1.9.1. What Standards MySQL Follows ....................................................23
1.9.2. Selecting SQL Modes ...................................................................23
1.9.3. Running MySQL in ANSI Mode ....................................................23
1.9.4. MySQL Extensions to Standard SQL ...............................................24
1.9.5. MySQL Differences from Standard SQL ..........................................27
1.9.6. How MySQL Deals with Constraints ...............................................32
2. Installing and Upgrading MySQL ........................................................................36
2.1. General Installation Issues .......................................................................36
2.1.1. Operating Systems Supported by MySQL Community Server ..............37
2.1.2. Choosing Which MySQL Distribution to Install .................................39
2.1.3. How to Get MySQL .....................................................................49
2.1.4. Verifying Package Integrity Using MD5 Checksums or GnuPG ............49
2.1.5. Installation Layouts ......................................................................51
2.2. Standard MySQL Installation Using a Binary Distribution .............................53
2.3. Installing MySQL on Windows .................................................................53
2.3.1. Choosing An Installation Package ...................................................54
2.3.2. Installing MySQL with the Automated Installer .................................55

2.3.3. Using the MySQL Installation Wizard .............................................55
2.3.4. Using the Configuration Wizard .....................................................58
2.3.5. Installing MySQL from a Noinstall Zip Archive ................................62
2.3.6. Extracting the Install Archive .........................................................62
2.3.7. Creating an Option File .................................................................63
2.3.8. Selecting a MySQL Server type ......................................................64
2.3.9. Starting the Server for the First Time ...............................................64
2.3.10. Starting MySQL from the Windows Command Line .........................66
2.3.11. Starting MySQL as a Windows Service ..........................................66
2.3.12. Testing The MySQL Installation ...................................................69
2.3.13. Troubleshooting a MySQL Installation Under Windows ....................69
2.3.14. Upgrading MySQL on Windows ...................................................71
2.3.15. MySQL on Windows Compared to MySQL on Unix ........................71
2.4. Installing MySQL on Linux ......................................................................74
iv

MySQL 5.1 Reference Manual

2.5. Installing MySQL on Mac OS X ...............................................................76
2.6. Installing MySQL on Solaris ....................................................................78

2.7. Installing MySQL on NetWare .................................................................79
2.8. Installing MySQL on Other Unix-Like Systems ...........................................81
2.9. MySQL Installation Using a Source Distribution ..........................................83
2.9.1. Source Installation Overview .........................................................84
2.9.2. Typical configure Options ........................................................86
2.9.3. Installing from the Development Source Tree ....................................90
2.9.4. Dealing with Problems Compiling MySQL .......................................93
2.9.5. MIT-pthreads Notes .....................................................................95
2.9.6. Installing MySQL from Source on Windows .....................................97
2.9.7. Compiling MySQL Clients on Windows ........................................ 100
2.10. Post-Installation Setup and Testing ........................................................ 100
2.10.1. Windows Post-Installation Procedures .......................................... 101
2.10.2. Unix Post-Installation Procedures ................................................ 101
2.10.3. Securing the Initial MySQL Accounts .......................................... 111
2.11. Upgrading MySQL ............................................................................. 114
2.11.1. Upgrading from MySQL 5.0 to 5.1 .............................................. 115
2.11.2. Copying MySQL Databases to Another Machine ........................... 119
2.12. Downgrading MySQL ......................................................................... 120
2.12.1. Downgrading to MySQL 5.0 ...................................................... 121
2.13. Operating System-Specific Notes ........................................................... 121

2.13.1. Linux Notes ............................................................................ 121
2.13.2. Mac OS X Notes ...................................................................... 128
2.13.3. Solaris Notes ........................................................................... 128
2.13.4. BSD Notes .............................................................................. 132
2.13.5. Other Unix Notes ..................................................................... 135
2.13.6. OS/2 Notes ............................................................................. 149
2.14. Environment Variables ........................................................................ 150
2.15. Perl Installation Notes ......................................................................... 151
2.15.1. Installing Perl on Unix .............................................................. 151
2.15.2. Installing ActiveState Perl on Windows ........................................ 152
2.15.3. Problems Using the Perl DBI/DBD Interface .................................. 153
3. Tutorial ......................................................................................................... 156
3.1. Connecting to and Disconnecting from the Server ....................................... 156
3.2. Entering Queries .................................................................................. 157
3.3. Creating and Using a Database ................................................................ 160
3.3.1. Creating and Selecting a Database ................................................. 161
3.3.2. Creating a Table ........................................................................ 161
3.3.3. Loading Data into a Table ........................................................... 162
3.3.4. Retrieving Information from a Table ............................................. 164
3.4. Getting Information About Databases and Tables ....................................... 175

3.5. Using mysql in Batch Mode ................................................................. 176
3.6. Examples of Common Queries ................................................................ 177
3.6.1. The Maximum Value for a Column ............................................... 178
3.6.2. The Row Holding the Maximum of a Certain Column ...................... 178
3.6.3. Maximum of Column per Group ................................................... 178
3.6.4. The Rows Holding the Group-wise Maximum of a Certain Field ......... 179
3.6.5. Using User-Defined Variables ...................................................... 179
3.6.6. Using Foreign Keys ................................................................... 180
3.6.7. Searching on Two Keys .............................................................. 181
3.6.8. Calculating Visits Per Day ........................................................... 181
3.6.9. Using AUTO_INCREMENT .......................................................... 182
3.7. Queries from the Twin Project ................................................................ 183
3.7.1. Find All Non-distributed Twins .................................................... 184
3.7.2. Show a Table of Twin Pair Status ................................................. 185
3.8. Using MySQL with Apache ................................................................... 186
4. Using MySQL Programs .................................................................................. 187
4.1. Overview of MySQL Programs ............................................................... 187
4.2. Invoking MySQL Programs ................................................................... 188
4.3. Specifying Program Options ................................................................... 189
4.3.1. Using Options on the Command Line ............................................ 189

4.3.2. Using Option Files ..................................................................... 191
v

MySQL 5.1 Reference Manual

4.3.3. Using Environment Variables to Specify Options ............................. 196
4.3.4. Using Options to Set Program Variables ......................................... 196
5. Database Administration .................................................................................. 198
5.1. Overview of Server-Side Programs .......................................................... 198
5.2. mysqld — The MySQL Server ............................................................. 199
5.2.1. Option and Variable Reference ..................................................... 200
5.2.2. Command Options ..................................................................... 213
5.2.3. System Variables ....................................................................... 225
5.2.4. Using System Variables .............................................................. 252
5.2.5. Status Variables ......................................................................... 260
5.2.6. SQL Modes .............................................................................. 271
5.2.7. The Shutdown Process ................................................................ 276
5.2.8. Server-Side Help ....................................................................... 277
5.3. MySQL Server Startup Programs ............................................................ 277
5.3.1. mysqld_safe — MySQL Server Startup Script ............................ 278

5.3.2. mysql.server — MySQL Server Startup Script .......................... 281
5.3.3. mysqld_multi — Manage Multiple MySQL Servers .................... 281
5.4. mysqlmanager — The MySQL Instance Manager .................................. 284
5.4.1. MySQL Instance Manager Command Options ................................. 285
5.4.2. MySQL Instance Manager Configuration Files ................................ 288
5.4.3. Starting the MySQL Server with MySQL Instance Manager .............. 289
5.4.4. Instance Manager User and Password Management .......................... 291
5.4.5. MySQL Server Instance Status Monitoring ..................................... 293
5.4.6. Connecting to MySQL Instance Manager ....................................... 294
5.4.7. MySQL Instance Manager Commands ........................................... 294
5.5. Installation-Related Programs ................................................................. 298
5.5.1. make_win_bin_dist — Package MySQL Distribution as ZIP Archive
........................................................................................................ 298
5.5.2. mysql_create_system_tables — Initialize MySQL System Tables
........................................................................................................ 299
5.5.3. mysql_fix_privilege_tables — Upgrade MySQL System Tables
........................................................................................................ 299
5.5.4. mysql_install_db — MySQL Data Directory Initialization Script 299
5.5.5. mysql_upgrade — Check Tables for MySQL Upgrade ................ 301
5.5.6. mysql_tzinfo_to_sql — Load the Time Zone Tables .............. 302

5.6. General Security Issues ......................................................................... 302
5.6.1. General Security Guidelines ......................................................... 302
5.6.2. Making MySQL Secure Against Attackers ..................................... 305
5.6.3. Security-Related mysqld Options ................................................ 306
5.6.4. Security Issues with LOAD DATA LOCAL ..................................... 308
5.6.5. How to Run MySQL as a Normal User .......................................... 309
5.7. The MySQL Access Privilege System ...................................................... 309
5.7.1. What the Privilege System Does ................................................... 310
5.7.2. How the Privilege System Works .................................................. 310
5.7.3. Privileges Provided by MySQL .................................................... 314
5.7.4. Connecting to the MySQL Server ................................................. 317
5.7.5. Access Control, Stage 1: Connection Verification ............................ 318
5.7.6. Access Control, Stage 2: Request Verification ................................. 322
5.7.7. When Privilege Changes Take Effect ............................................. 324
5.7.8. Causes of Access denied Errors ............................................. 325
5.7.9. Password Hashing as of MySQL 4.1 .............................................. 329
5.8. MySQL User Account Management ........................................................ 334
5.8.1. MySQL Usernames and Passwords ............................................... 334
5.8.2. Adding New User Accounts to MySQL ......................................... 335
5.8.3. Removing User Accounts from MySQL ......................................... 338

5.8.4. Limiting Account Resources ........................................................ 338
5.8.5. Assigning Account Passwords ...................................................... 340
5.8.6. Keeping Your Password Secure .................................................... 341
5.8.7. Using Secure Connections ........................................................... 342
5.9. Backup and Recovery ........................................................................... 349
5.9.1. Database Backups ...................................................................... 349
5.9.2. Example Backup and Recovery Strategy ........................................ 351
5.9.3. Point-in-Time Recovery .............................................................. 354
vi

MySQL 5.1 Reference Manual

5.9.4. Table Maintenance and Crash Recovery ......................................... 356
5.10. MySQL Localization and International Usage .......................................... 366
5.10.1. The Character Set Used for Data and Sorting ................................. 366
5.10.2. Setting the Error Message Language ............................................ 367
5.10.3. Adding a New Character Set ...................................................... 368
5.10.4. The Character Definition Arrays ................................................. 369
5.10.5. String Collating Support ............................................................ 370
5.10.6. Multi-Byte Character Support ..................................................... 370

5.10.7. Problems With Character Sets .................................................... 370
5.10.8. MySQL Server Time Zone Support ............................................. 371
5.10.9. MySQL Server Locale Support ................................................... 374
5.11. MySQL Server Logs ........................................................................... 376
5.11.1. Selecting General Query and Slow Query Log Output Destinations ... 377
5.11.2. The Error Log ......................................................................... 378
5.11.3. The General Query Log ............................................................. 379
5.11.4. The Binary Log ....................................................................... 380
5.11.5. The Slow Query Log ................................................................ 383
5.11.6. Server Log Maintenance ............................................................ 384
5.12. Running Multiple MySQL Servers on the Same Machine ........................... 385
5.12.1. Running Multiple Servers on Windows ........................................ 387
5.12.2. Running Multiple Servers on Unix .............................................. 390
5.12.3. Using Client Programs in a Multiple-Server Environment ................ 391
5.13. The MySQL Query Cache .................................................................... 392
5.13.1. How the Query Cache Operates .................................................. 392
5.13.2. Query Cache SELECT Options ................................................... 394
5.13.3. Query Cache Configuration ........................................................ 394
5.13.4. Query Cache Status and Maintenance .......................................... 396
6. Replication .................................................................................................... 398
6.1. Replication Configuration ...................................................................... 399
6.1.1. How to Set Up Replication .......................................................... 399
6.1.2. Replication Formats ................................................................... 407
6.1.3. Replication Options and Variables ................................................ 412
6.1.4. Common Replication Administration Tasks .................................... 419
6.2. Replication Solutions ............................................................................ 421
6.2.1. Using Replication for Backups ..................................................... 422
6.2.2. Using Replication with different Master and Slave Storage Engines ..... 423
6.2.3. Using Replication for Scale-out .................................................... 425
6.2.4. Replicating Different Databases to Different Slaves .......................... 426
6.2.5. Improving Replication Performance .............................................. 427
6.2.6. Switching Masters During Failover ............................................... 428
6.2.7. Setting up Replication using SSL .................................................. 430
6.3. Replication Notes and Tips .................................................................... 432
6.3.1. Replication Features and Issues .................................................... 432
6.3.2. Replication Compatibility Between MySQL Versions ....................... 438
6.3.3. Upgrading a Replication Setup ..................................................... 438
6.3.4. Replication FAQ ....................................................................... 439
6.3.5. Troubleshooting Replication ........................................................ 442
6.3.6. How to Report Replication Bugs or Problems .................................. 444
6.4. Replication Implementation .................................................................... 444
6.4.1. Replication Implementation Details ............................................... 445
6.4.2. Replication Master Thread States .................................................. 446
6.4.3. Replication Slave I/O Thread States .............................................. 447
6.4.4. Replication Slave SQL Thread States ............................................. 448
6.4.5. Replication Relay and Status Files ................................................ 448
6.4.6. How Servers Evaluate Replication Rules ........................................ 450
7. Optimization .................................................................................................. 454
7.1. Optimization Overview ......................................................................... 454
7.1.1. MySQL Design Limitations and Tradeoffs ..................................... 454
7.1.2. Designing Applications for Portability ........................................... 455
7.1.3. What We Have Used MySQL For ................................................. 456
7.1.4. The MySQL Benchmark Suite ...................................................... 456
7.1.5. Using Your Own Benchmarks ...................................................... 457
7.2. Optimizing SELECT and Other Statements ............................................... 458
vii

MySQL 5.1 Reference Manual

7.2.1. Optimizing Queries with EXPLAIN .............................................. 458
7.2.2. Estimating Query Performance ..................................................... 467
7.2.3. Speed of SELECT Queries ........................................................... 468
7.2.4. WHERE Clause Optimization ........................................................ 468
7.2.5. Range Optimization ................................................................... 470
7.2.6. Index Merge Optimization ........................................................... 473
7.2.7. IS NULL Optimization .............................................................. 475
7.2.8. DISTINCT Optimization ............................................................ 476
7.2.9. LEFT JOIN and RIGHT JOIN Optimization ............................... 477
7.2.10. Nested Join Optimization ........................................................... 478
7.2.11. Outer Join Simplification ........................................................... 483
7.2.12. ORDER BY Optimization .......................................................... 485
7.2.13. GROUP BY Optimization .......................................................... 487
7.2.14. LIMIT Optimization ................................................................ 488
7.2.15. How to Avoid Table Scans ......................................................... 489
7.2.16. Speed of INSERT Statements ..................................................... 490
7.2.17. Speed of UPDATE Statements ..................................................... 492
7.2.18. Speed of DELETE Statements ..................................................... 492
7.2.19. Other Optimization Tips ............................................................ 492
7.3. Locking Issues ..................................................................................... 494
7.3.1. Locking Methods ....................................................................... 494
7.3.2. Table Locking Issues .................................................................. 496
7.3.3. Concurrent Inserts ...................................................................... 498
7.4. Optimizing Database Structure ................................................................ 498
7.4.1. Design Choices ......................................................................... 499
7.4.2. Make Your Data as Small as Possible ............................................ 499
7.4.3. Column Indexes ........................................................................ 500
7.4.4. Multiple-Column Indexes ............................................................ 501
7.4.5. How MySQL Uses Indexes .......................................................... 501
7.4.6. The MyISAM Key Cache ............................................................. 504
7.4.7. MyISAM Index Statistics Collection .............................................. 508
7.4.8. How MySQL Opens and Closes Tables .......................................... 510
7.4.9. Drawbacks to Creating Many Tables in the Same Database ................ 511
7.5. Optimizing the MySQL Server ............................................................... 511
7.5.1. System Factors and Startup Parameter Tuning ................................. 511
7.5.2. Tuning Server Parameters ............................................................ 512
7.5.3. Controlling Query Optimizer Performance ...................................... 516
7.5.4. How Compiling and Linking Affects the Speed of MySQL ................ 517
7.5.5. How MySQL Uses Memory ........................................................ 518
7.5.6. How MySQL Uses DNS ............................................................. 520
7.6. Disk Issues .......................................................................................... 520
7.6.1. Using Symbolic Links ................................................................ 521
8. Client and Utility Programs .............................................................................. 524
8.1. Overview of Client and Utility Programs .................................................. 524
8.2. my_print_defaults — Display Options from Option Files ................... 526
8.3. myisam_ftdump — Display Full-Text Index information ......................... 527
8.4. myisamchk — MyISAM Table-Maintenance Utility ................................. 528
8.4.1. myisamchk General Options ...................................................... 529
8.4.2. myisamchk Check Options ........................................................ 531
8.4.3. myisamchk Repair Options ....................................................... 531
8.4.4. Other myisamchk Options ......................................................... 533
8.4.5. myisamchk Memory Usage ....................................................... 534
8.5. myisamlog — Display MyISAM Log File Contents ................................. 534
8.6. myisampack — Generate Compressed, Read-Only MyISAM Tables ........... 535
8.7. mysql — The MySQL Command-Line Tool ............................................ 541
8.7.1. mysql Options ......................................................................... 541
8.7.2. mysql Commands .................................................................... 546
8.7.3. mysql Server-Side Help ............................................................ 549
8.7.4. Executing SQL Statements from a Text File .................................... 550
8.7.5. mysql Tips .............................................................................. 551
8.8. mysqlaccess — Client for Checking Access Privileges ........................... 552
8.9. mysqladmin — Client for Administering a MySQL Server ....................... 554
8.10. mysqlbinlog — Utility for Processing Binary Log Files ........................ 559
viii

MySQL 5.1 Reference Manual

8.11. mysqlcheck — A Table Maintenance and Repair Program ...................... 565
8.12. mysqldump — A Database Backup Program ......................................... 568
8.13. mysqlhotcopy — A Database Backup Program ................................... 577
8.14. mysqlimport — A Data Import Program ............................................ 580
8.15. mysqlshow — Display Database, Table, and Column Information ............. 582
8.16. mysqlslap — Load Emulation Client .................................................. 584
8.17. mysql_zap — Kill Processes That Match a Pattern ................................ 587
8.18. perror — Explain Error Codes ........................................................... 587
8.19. replace — A String-Replacement Utility ............................................. 588
9. Language Structure ......................................................................................... 590
9.1. Literal Values ...................................................................................... 590
9.1.1. Strings ..................................................................................... 590
9.1.2. Numbers .................................................................................. 592
9.1.3. Hexadecimal Values ................................................................... 592
9.1.4. Boolean Values ......................................................................... 593
9.1.5. Bit-Field Values ........................................................................ 593
9.1.6. NULL Values ............................................................................ 593
9.2. Identifiers ........................................................................................... 593
9.2.1. Identifier Qualifiers .................................................................... 595
9.2.2. Identifier Case Sensitivity ............................................................ 595
9.2.3. Mapping of Identifiers to Filenames .............................................. 597
9.2.4. Function Name Parsing and Resolution .......................................... 598
9.3. Reserved Words ................................................................................... 602
9.4. User-Defined Variables ......................................................................... 604
9.5. Comment Syntax .................................................................................. 606
10. Character Set Support .................................................................................... 607
10.1. Character Sets and Collations in General ................................................. 607
10.2. Character Sets and Collations in MySQL ................................................ 608
10.3. Specifying Character Sets and Collations ................................................ 609
10.3.1. Server Character Set and Collation .............................................. 609
10.3.2. Database Character Set and Collation ........................................... 610
10.3.3. Table Character Set and Collation ............................................... 610
10.3.4. Column Character Set and Collation ............................................ 611
10.3.5. Character String Literal Character Set and Collation ....................... 612
10.3.6. National Character Set .............................................................. 613
10.3.7. Examples of Character Set and Collation Assignment ..................... 614
10.3.8. Compatibility with Other DBMSs ............................................... 614
10.4. Connection Character Sets and Collations ............................................... 615
10.5. Collation Issues .................................................................................. 617
10.5.1. Using COLLATE in SQL Statements ............................................ 617
10.5.2. COLLATE Clause Precedence ..................................................... 617
10.5.3. BINARY Operator .................................................................... 618
10.5.4. Some Special Cases Where the Collation Determination Is Tricky ..... 618
10.5.5. Collations Must Be for the Right Character Set .............................. 619
10.5.6. An Example of the Effect of Collation .......................................... 620
10.6. Operations Affected by Character Set Support .......................................... 620
10.6.1. Result Strings .......................................................................... 620
10.6.2. CONVERT() and CAST() ........................................................ 621
10.6.3. SHOW Statements and INFORMATION_SCHEMA ........................... 622
10.7. Unicode Support ................................................................................ 623
10.8. UTF-8 for Metadata ............................................................................ 624
10.9. Column Character Set Conversion ......................................................... 625
10.10. Character Sets and Collations That MySQL Supports ............................... 626
10.10.1. Unicode Character Sets ............................................................ 626
10.10.2. West European Character Sets .................................................. 629
10.10.3. Central European Character Sets ............................................... 630
10.10.4. South European and Middle East Character Sets ........................... 631
10.10.5. Baltic Character Sets ............................................................... 632
10.10.6. Cyrillic Character Sets ............................................................. 632
10.10.7. Asian Character Sets ............................................................... 633
11. Data Types .................................................................................................. 637
11.1. Data Type Overview ........................................................................... 637
11.1.1. Overview of Numeric Types ...................................................... 637
ix

MySQL 5.1 Reference Manual

11.1.2. Overview of Date and Time Types .............................................. 640
11.1.3. Overview of String Types .......................................................... 641
11.1.4. Data Type Default Values .......................................................... 644
11.2. Numeric Types ................................................................................... 645
11.3. Date and Time Types .......................................................................... 647
11.3.1. The DATETIME, DATE, and TIMESTAMP Types ........................... 648
11.3.2. The TIME Type ....................................................................... 653
11.3.3. The YEAR Type ....................................................................... 654
11.3.4. Year 2000 Issues and Date Types ................................................ 654
11.4. String Types ...................................................................................... 655
11.4.1. The CHAR and VARCHAR Types ................................................. 655
11.4.2. The BINARY and VARBINARY Types ......................................... 656
11.4.3. The BLOB and TEXT Types ....................................................... 657
11.4.4. The ENUM Type ....................................................................... 658
11.4.5. The SET Type ......................................................................... 660
11.5. Data Type Storage Requirements ........................................................... 662
11.6. Choosing the Right Type for a Column ................................................... 665
11.7. Using Data Types from Other Database Engines ....................................... 665
12. Functions and Operators ................................................................................. 667
12.1. Operators .......................................................................................... 667
12.1.1. Operator Precedence ................................................................. 667
12.1.2. Type Conversion in Expression Evaluation ................................... 668
12.1.3. Comparison Functions and Operators ........................................... 669
12.1.4. Logical Operators ..................................................................... 673
12.2. Control Flow Functions ....................................................................... 674
12.3. String Functions ................................................................................. 676
12.3.1. String Comparison Functions ..................................................... 685
12.3.2. Regular Expressions ................................................................. 688
12.4. Numeric Functions .............................................................................. 691
12.4.1. Arithmetic Operators ................................................................ 691
12.4.2. Mathematical Functions ............................................................ 693
12.5. Date and Time Functions ..................................................................... 699
12.6. What Calendar Is Used By MySQL? ...................................................... 714
12.7. Full-Text Search Functions ................................................................... 714
12.7.1. Boolean Full-Text Searches ....................................................... 718
12.7.2. Full-Text Searches with Query Expansion ..................................... 720
12.7.3. Full-Text Stopwords ................................................................. 721
12.7.4. Full-Text Restrictions ............................................................... 723
12.7.5. Fine-Tuning MySQL Full-Text Search ......................................... 724
12.8. Cast Functions and Operators ................................................................ 725
12.9. XML Functions .................................................................................. 728
12.10. Other Functions ................................................................................ 732
12.10.1. Bit Functions ......................................................................... 732
12.10.2. Encryption and Compression Functions ...................................... 733
12.10.3. Information Functions ............................................................. 737
12.10.4. Miscellaneous Functions .......................................................... 742
12.11. Functions and Modifiers for Use with GROUP BY Clauses ....................... 745
12.11.1. GROUP BY (Aggregate) Functions ............................................ 745
12.11.2. GROUP BY Modifiers ............................................................. 749
12.11.3. GROUP BY and HAVING with Hidden Fields .............................. 751
13. SQL Statement Syntax ................................................................................... 753
13.1. Data Definition Statements ................................................................... 753
13.1.1. ALTER DATABASE Syntax ....................................................... 753
13.1.2. ALTER TABLE Syntax ............................................................. 753
13.1.3. ALTER LOGFILE GROUP Syntax ............................................. 761
13.1.4. ALTER TABLESPACE Syntax ................................................... 762
13.1.5. ALTER SERVER Syntax ........................................................... 762
13.1.6. CREATE DATABASE Syntax ..................................................... 763
13.1.7. CREATE INDEX Syntax ........................................................... 763
13.1.8. CREATE TABLE Syntax ........................................................... 765
13.1.9. CREATE LOGFILE GROUP Syntax ........................................... 780
13.1.10. CREATE TABLESPACE Syntax ............................................... 780
13.1.11. CREATE SERVER Syntax ....................................................... 781
x

MySQL 5.1 Reference Manual

13.1.12. DROP DATABASE Syntax ....................................................... 782
13.1.13. DROP INDEX Syntax ............................................................. 783
13.1.14. DROP TABLE Syntax ............................................................. 783
13.1.15. DROP LOGFILE GROUP Syntax ............................................. 783
13.1.16. DROP TABLESPACE Syntax ................................................... 784
13.1.17. DROP SERVER Syntax ........................................................... 784
13.1.18. RENAME DATABASE Syntax ................................................... 784
13.1.19. RENAME TABLE Syntax ......................................................... 785
13.2. Data Manipulation Statements ............................................................... 785
13.2.1. DELETE Syntax ....................................................................... 785
13.2.2. DO Syntax ............................................................................... 788
13.2.3. HANDLER Syntax ..................................................................... 788
13.2.4. INSERT Syntax ....................................................................... 789
13.2.5. LOAD DATA INFILE Syntax ................................................... 796
13.2.6. REPLACE Syntax ..................................................................... 804
13.2.7. SELECT Syntax ....................................................................... 805
13.2.8. Subquery Syntax ...................................................................... 819
13.2.9. TRUNCATE Syntax ................................................................... 828
13.2.10. UPDATE Syntax ..................................................................... 829
13.3. MySQL Utility Statements ................................................................... 830
13.3.1. DESCRIBE Syntax ................................................................... 830
13.3.2. HELP Syntax ........................................................................... 831
13.3.3. USE Syntax ............................................................................. 833
13.4. MySQL Transactional and Locking Statements ........................................ 833
13.4.1. START TRANSACTION, COMMIT, and ROLLBACK Syntax ............ 833
13.4.2. Statements That Cannot Be Rolled Back ....................................... 835
13.4.3. Statements That Cause an Implicit Commit ................................... 835
13.4.4. SAVEPOINT and ROLLBACK TO SAVEPOINT Syntax ................ 836
13.4.5. LOCK TABLES and UNLOCK TABLES Syntax ............................ 837
13.4.6. SET TRANSACTION Syntax ..................................................... 839
13.4.7. XA Transactions ...................................................................... 840
13.5. Database Administration Statements ...................................................... 843
13.5.1. Account Management Statements ................................................ 843
13.5.2. Table Maintenance Statements .................................................... 853
13.5.3. SET Syntax ............................................................................. 859
13.5.4. SHOW Syntax ........................................................................... 864
13.5.5. Other Administrative Statements ................................................. 890
13.6. Replication Statements ........................................................................ 894
13.6.1. SQL Statements for Controlling Master Servers ............................. 894
13.6.2. SQL Statements for Controlling Slave Servers ............................... 897
13.7. SQL Syntax for Prepared Statements ...................................................... 905
14. Storage Engines and Table Types ..................................................................... 908
14.1. Overview of MySQL Storage Engine Architecture .................................... 908
14.1.1. The Common Database Server Layer ........................................... 909
14.1.2. Pluggable Storage Engine Architecture ......................................... 910
14.2. Supported Storage Engines ................................................................... 910
14.2.1. Choosing a Storage Engine ........................................................ 911
14.2.2. Comparing Transaction and Non-Transaction Engines .................... 912
14.2.3. Other Storage Engines .............................................................. 912
14.3. Setting the Storage Engine .................................................................... 913
14.4. The MyISAM Storage Engine ................................................................ 914
14.4.1. MyISAM Startup Options ........................................................... 916
14.4.2. Space Needed for Keys ............................................................. 917
14.4.3. MyISAM Table Storage Formats ................................................. 917
14.4.4. MyISAM Table Problems ........................................................... 920
14.5. The InnoDB Storage Engine ................................................................ 921
14.5.1. InnoDB Overview ................................................................... 921
14.5.2. InnoDB Contact Information ..................................................... 922
14.5.3. InnoDB Configuration ............................................................. 922
14.5.4. InnoDB Startup Options and System Variables ............................. 928
14.5.5. Creating the InnoDB Tablespace ................................................ 934
14.5.6. Creating and Using InnoDB Tables ............................................ 935
14.5.7. Adding and Removing InnoDB Data and Log Files ....................... 942
xi

MySQL 5.1 Reference Manual

14.5.8. Backing Up and Recovering an InnoDB Database ......................... 943
14.5.9. Moving an InnoDB Database to Another Machine ......................... 946
14.5.10. InnoDB Transaction Model and Locking ................................... 946
14.5.11. InnoDB Performance Tuning Tips ............................................ 955
14.5.12. Implementation of Multi-Versioning .......................................... 961
14.5.13. InnoDB Table and Index Structures .......................................... 962
14.5.14. InnoDB File Space Management and Disk I/O ............................ 964
14.5.15. InnoDB Error Handling .......................................................... 966
14.5.16. Restrictions on InnoDB Tables ................................................ 971
14.5.17. InnoDB Trouble

Dokumen yang terkait