Oracle 5.0, MySQL 5.0 Reference Manual

Page 1
MySQL 5.0 Reference Manual
Page 2
MySQL 5.0 Reference Manual
Abstract
This is the MySQL™ Reference Manual. It documents MySQL 5.0 through 5.0.96.
End of Product Lifecycle
Active development for MySQL Database Server version 5.0 has ended. Oracle offers various support offerings which may be of interest. For details and more information, see the MySQL section of the Lifetime Support Policy for Oracle Technology Products (http://www.oracle.com/us/support/lifetime­support/index.html). Please consider upgrading to a recent version.
MySQL 5.0 features. This manual describes features that are not included in every edition of MySQL 5.0 and such features may not be included in the edition of MySQL 5.0 licensed to you. If you have any questions about the features included in your edition of MySQL 5.0, refer to your MySQL 5.0 license agreement or contact your Oracle representative.
For release notes detailing the changes in each release, see the MySQL 5.0 Release Notes. For legal information, see the Legal Notices. Document generated on: 2013-04-16 (revision: 34918)
General Administrators MySQL
Enterprise
Developers & Functionality
Connectors & APIs
HA/Scalability
Tutorial Installation &
Upgrades
MySQL Enterprise Edition
MySQL Workbench
Connectors and APIs
» HA/Scalability Guide
Server Administration
» MySQL Installer MySQL
Enterprise Monitor
Globalization Connector/J MySQL and
DRBD
SQL Syntax » Security MySQL
Enterprise Backup
Optimization Connector/ODBC memcached
Storage Engines » Startup /
Shutdown
MySQL Enterprise Security
Functions and Operators
Connector/Net MySQL and
Virtualization
Server Option / Variable Reference
» Backup and Recovery Overview
MySQL Enterprise Audit
Views and Stored Programs
Connector/ Python
MySQL Proxy
» Release Notes » MySQL Utilities MySQL Thread
Pool
Precision Math PHP Replication
» MySQL Version Reference
» Linux/Unix Platform Guide
Spatial
Extensions
C API
FAQs » Windows
Platform Guide
Restrictions and
Limitations
Connector/C
» Mac OS X
Platform Guide
Connector/C++
» Solaris Platform
Guide
» MySQL for
Excel
» Building from
Source
Page 3
iii
Table of Contents
Preface and Legal Notices .......................................................................................................... xix
1. General Information .................................................................................................................. 1
1.1. About This Manual ......................................................................................................... 2
1.2. Typographical and Syntax Conventions ........................................................................... 3
1.3. Overview of the MySQL Database Management System .................................................. 4
1.3.1. What is MySQL? ................................................................................................. 4
1.3.2. The Main Features of MySQL .............................................................................. 6
1.3.3. History of MySQL ................................................................................................ 8
1.4. What Is New in MySQL 5.0 ............................................................................................ 9
1.5. MySQL Development History ........................................................................................ 11
1.6. MySQL Information Sources ......................................................................................... 11
1.6.1. MySQL Mailing Lists .......................................................................................... 11
1.6.2. MySQL Community Support at the MySQL Forums ............................................. 14
1.6.3. MySQL Community Support on Internet Relay Chat (IRC) ................................... 14
1.6.4. MySQL Enterprise ............................................................................................. 14
1.7. How to Report Bugs or Problems .................................................................................. 14
1.8. MySQL Standards Compliance ..................................................................................... 19
1.8.1. What Standards MySQL Follows ........................................................................ 19
1.8.2. Selecting SQL Modes ........................................................................................ 19
1.8.3. Running MySQL in ANSI Mode .......................................................................... 20
1.8.4. MySQL Extensions to Standard SQL .................................................................. 20
1.8.5. MySQL Differences from Standard SQL ............................................................. 23
1.8.6. How MySQL Deals with Constraints ................................................................... 28
1.9. Credits ......................................................................................................................... 32
1.9.1. Contributors to MySQL ...................................................................................... 32
1.9.2. Documenters and translators ............................................................................. 36
1.9.3. Packages that support MySQL ........................................................................... 37
1.9.4. Tools that were used to create MySQL ............................................................... 38
1.9.5. Supporters of MySQL ........................................................................................ 38
2. Installing and Upgrading MySQL ............................................................................................. 41
2.1. MySQL Installation Overview ........................................................................................ 42
2.2. Determining your current MySQL version ...................................................................... 42
2.3. Notes for MySQL Enterprise Server .............................................................................. 43
2.3.1. Enterprise Server Distribution Types ................................................................... 44
2.3.2. Upgrading MySQL Enterprise Server .................................................................. 44
2.4. Notes for MySQL Community Server ............................................................................. 44
2.4.1. Overview of MySQL Community Server Installation ............................................. 44
2.4.2. Operating Systems Supported by MySQL Community Server ............................... 45
2.4.3. Choosing Which MySQL Distribution to Install ..................................................... 46
2.5. How to Get MySQL ...................................................................................................... 50
2.6. Verifying Package Integrity Using MD5 Checksums or GnuPG ......................................... 50
2.6.1. Verifying the MD5 Checksum ............................................................................. 50
2.6.2. Signature Checking Using GnuPG ....................................................................... 51
2.6.3. Signature Checking Using Gpg4win for Windows ............................................... 53
2.6.4. Signature Checking Using RPM ........................................................................... 57
2.7. Installation Layouts ....................................................................................................... 58
2.8. Compiler-Specific Build Characteristics .......................................................................... 59
2.9. Standard MySQL Installation from a Binary Distribution .................................................. 60
2.10. Installing MySQL on Microsoft Windows ...................................................................... 60
2.10.1. Choosing An Installation Package .................................................................... 61
2.10.2. Installing MySQL on Microsoft Windows Using an MSI Package ......................... 62
2.10.3. MySQL Server Instance Configuration Wizard ................................................... 67
2.10.4. Installing MySQL on Microsoft Windows Using a noinstall Zip Archive ........... 79
2.10.5. Troubleshooting a MySQL Installation Under Windows ...................................... 86
2.10.6. Upgrading MySQL on Windows ........................................................................ 87
Page 4
MySQL 5.0 Reference Manual
iv
2.10.7. Windows Postinstallation Procedures ................................................................ 88
2.10.8. Installing MySQL from Source on Windows ....................................................... 90
2.11. Installing MySQL on Mac OS X .................................................................................. 95
2.12. Installing MySQL from RPM Packages on Linux .......................................................... 97
2.13. Installing MySQL on Solaris ...................................................................................... 100
2.14. Installing MySQL on i5/OS ........................................................................................ 101
2.15. Installing MySQL on NetWare ................................................................................... 105
2.16. Installing MySQL from Generic Binaries on Other Unix-Like Systems ........................... 107
2.17. Installing MySQL from Source ................................................................................... 109
2.17.1. Installing MySQL from a Standard Source Distribution ..................................... 110
2.17.2. Installing MySQL from a Development Source Tree ......................................... 113
2.17.3. MySQL Source-Configuration Options ............................................................. 115
2.17.4. Dealing with Problems Compiling MySQL ....................................................... 123
2.17.5. Compiling and Linking an Optimized mysqld Server ....................................... 126
2.18. Postinstallation Setup and Testing ............................................................................. 127
2.18.1. Unix Postinstallation Procedures ..................................................................... 127
2.18.2. Securing the Initial MySQL Accounts .............................................................. 138
2.19. Upgrading or Downgrading MySQL ........................................................................... 142
2.19.1. Upgrading MySQL ......................................................................................... 142
2.19.2. Downgrading MySQL ..................................................................................... 153
2.19.3. Checking Whether Tables or Indexes Must Be Rebuilt ..................................... 154
2.19.4. Rebuilding or Repairing Tables or Indexes ...................................................... 156
2.19.5. Copying MySQL Databases to Another Machine ............................................. 158
2.20. Operating System-Specific Notes .............................................................................. 159
2.20.1. Linux Notes ................................................................................................... 159
2.20.2. Mac OS X Notes ........................................................................................... 165
2.20.3. Solaris Notes ................................................................................................. 165
2.20.4. BSD Notes .................................................................................................... 169
2.20.5. Other Unix Notes ........................................................................................... 172
2.20.6. OS/2 Notes ................................................................................................... 187
2.21. Environment Variables .............................................................................................. 187
2.22. Perl Installation Notes ............................................................................................... 188
2.22.1. Installing Perl on Unix .................................................................................... 189
2.22.2. Installing ActiveState Perl on Windows ........................................................... 190
2.22.3. Problems Using the Perl DBI/DBD Interface ..................................................... 190
3. Tutorial ................................................................................................................................. 193
3.1. Connecting to and Disconnecting from the Server ........................................................ 193
3.2. Entering Queries ........................................................................................................ 194
3.3. Creating and Using a Database .................................................................................. 197
3.3.1. Creating and Selecting a Database .................................................................. 198
3.3.2. Creating a Table .............................................................................................. 199
3.3.3. Loading Data into a Table ................................................................................ 200
3.3.4. Retrieving Information from a Table .................................................................. 201
3.4. Getting Information About Databases and Tables ......................................................... 213
3.5. Using mysql in Batch Mode ....................................................................................... 214
3.6. Examples of Common Queries .................................................................................... 216
3.6.1. The Maximum Value for a Column ................................................................... 216
3.6.2. The Row Holding the Maximum of a Certain Column ......................................... 216
3.6.3. Maximum of Column per Group ....................................................................... 217
3.6.4. The Rows Holding the Group-wise Maximum of a Certain Column ...................... 217
3.6.5. Using User-Defined Variables ........................................................................... 218
3.6.6. Using Foreign Keys ......................................................................................... 218
3.6.7. Searching on Two Keys ................................................................................... 220
3.6.8. Calculating Visits Per Day ................................................................................ 220
3.6.9. Using AUTO_INCREMENT ................................................................................. 220
3.7. Using MySQL with Apache ......................................................................................... 222
4. MySQL Programs .................................................................................................................. 223
4.1. Overview of MySQL Programs .................................................................................... 224
Page 5
MySQL 5.0 Reference Manual
v
4.2. Using MySQL Programs ............................................................................................. 229
4.2.1. Invoking MySQL Programs ............................................................................... 229
4.2.2. Connecting to the MySQL Server ..................................................................... 229
4.2.3. Specifying Program Options ............................................................................. 232
4.2.4. Setting Environment Variables .......................................................................... 243
4.3. MySQL Server and Server-Startup Programs ............................................................... 244
4.3.1. mysqld — The MySQL Server ........................................................................ 244
4.3.2. mysqld_safe — MySQL Server Startup Script ................................................ 245
4.3.3. mysql.server — MySQL Server Startup Script .............................................. 249
4.3.4. mysqld_multi — Manage Multiple MySQL Servers ........................................ 250
4.4. MySQL Installation-Related Programs ......................................................................... 254
4.4.1. comp_err — Compile MySQL Error Message File ............................................ 254
4.4.2. make_win_bin_dist — Package MySQL Distribution as Zip Archive ............... 255
4.4.3. make_win_src_distribution — Create Source Distribution for Windows ...... 256
4.4.4. mysqlbug — Generate Bug Report ................................................................. 257
4.4.5. mysql_fix_privilege_tables — Upgrade MySQL System Tables .............. 257
4.4.6. mysql_install_db — Initialize MySQL Data Directory ................................... 258
4.4.7. mysql_secure_installation — Improve MySQL Installation Security .......... 259
4.4.8. mysql_tzinfo_to_sql — Load the Time Zone Tables .................................. 260
4.4.9. mysql_upgrade — Check Tables for MySQL Upgrade .................................... 260
4.5. MySQL Client Programs ............................................................................................. 262
4.5.1. mysql — The MySQL Command-Line Tool ...................................................... 262
4.5.2. mysqladmin — Client for Administering a MySQL Server ................................. 282
4.5.3. mysqlcheck — A Table Maintenance Program ................................................ 288
4.5.4. mysqldump — A Database Backup Program .................................................... 293
4.5.5. mysqlimport — A Data Import Program ......................................................... 308
4.5.6. mysqlshow — Display Database, Table, and Column Information ...................... 312
4.6. MySQL Administrative and Utility Programs ................................................................. 315
4.6.1. innochecksum — Offline InnoDB File Checksum Utility .................................... 315
4.6.2. myisam_ftdump — Display Full-Text Index information .................................... 316
4.6.3. myisamchk — MyISAM Table-Maintenance Utility ............................................ 317
4.6.4. myisamlog — Display MyISAM Log File Contents ............................................ 333
4.6.5. myisampack — Generate Compressed, Read-Only MyISAM Tables .................. 334
4.6.6. mysqlaccess — Client for Checking Access Privileges .................................... 339
4.6.7. mysqlbinlog — Utility for Processing Binary Log Files .................................... 342
4.6.8. mysqldumpslow — Summarize Slow Query Log Files ...................................... 350
4.6.9. mysqlhotcopy — A Database Backup Program .............................................. 352
4.6.10. mysqlmanager — The MySQL Instance Manager .......................................... 354
4.6.11. mysql_convert_table_format — Convert Tables to Use a Given Storage
Engine ...................................................................................................................... 364
4.6.12. mysql_explain_log — Use EXPLAIN on Statements in Query Log .............. 365
4.6.13. mysql_find_rows — Extract SQL Statements from Files .............................. 366
4.6.14. mysql_fix_extensions — Normalize Table File Name Extensions .............. 366
4.6.15. mysql_setpermission — Interactively Set Permissions in Grant Tables ........ 367
4.6.16. mysql_tableinfo — Generate Database Metadata ...................................... 367
4.6.17. mysql_waitpid — Kill Process and Wait for Its Termination .......................... 369
4.6.18. mysql_zap — Kill Processes That Match a Pattern ........................................ 370
4.7. MySQL Program Development Utilities ........................................................................ 370
4.7.1. msql2mysql — Convert mSQL Programs for Use with MySQL ......................... 371
4.7.2. mysql_config — Display Options for Compiling Clients .................................. 371
4.7.3. my_print_defaults — Display Options from Option Files .............................. 372
4.7.4. resolve_stack_dump — Resolve Numeric Stack Trace Dump to Symbols ....... 373
4.8. Miscellaneous Programs ............................................................................................. 373
4.8.1. perror — Explain Error Codes ....................................................................... 373
4.8.2. replace — A String-Replacement Utility ......................................................... 374
4.8.3. resolveip — Resolve Host name to IP Address or Vice Versa ........................ 375
5. MySQL Server Administration ................................................................................................ 377
5.1. The MySQL Server .................................................................................................... 377
Page 6
MySQL 5.0 Reference Manual
vi
5.1.1. Server Option and Variable Reference .............................................................. 378
5.1.2. Server Configuration Defaults ........................................................................... 399
5.1.3. Server Command Options ................................................................................ 399
5.1.4. Server System Variables .................................................................................. 425
5.1.5. Using System Variables ................................................................................... 507
5.1.6. Server Status Variables ................................................................................... 516
5.1.7. Server SQL Modes .......................................................................................... 534
5.1.8. Server-Side Help ............................................................................................. 541
5.1.9. Server Response to Signals ............................................................................. 541
5.1.10. The Shutdown Process .................................................................................. 542
5.2. MySQL Server Logs ................................................................................................... 543
5.2.1. The Error Log .................................................................................................. 543
5.2.2. The General Query Log ................................................................................... 544
5.2.3. The Binary Log ................................................................................................ 545
5.2.4. The Slow Query Log ........................................................................................ 548
5.2.5. Server Log Maintenance .................................................................................. 549
5.3. Running Multiple MySQL Instances on One Machine ................................................... 550
5.3.1. Setting Up Multiple Data Directories ................................................................. 552
5.3.2. Running Multiple MySQL Instances on Windows ............................................... 553
5.3.3. Running Multiple MySQL Instances on Unix ...................................................... 555
5.3.4. Using Client Programs in a Multiple-Server Environment .................................... 556
6. Security ................................................................................................................................ 559
6.1. General Security Issues .............................................................................................. 559
6.1.1. Security Guidelines .......................................................................................... 560
6.1.2. Keeping Passwords Secure ............................................................................. 561
6.1.3. Making MySQL Secure Against Attackers ......................................................... 569
6.1.4. Security-Related mysqld Options and Variables ............................................... 570
6.1.5. How to Run MySQL as a Normal User ............................................................. 571
6.1.6. Security Issues with LOAD DATA LOCAL ......................................................... 572
6.1.7. Client Programming Security Guidelines ........................................................... 573
6.2. The MySQL Access Privilege System .......................................................................... 574
6.2.1. Privileges Provided by MySQL ......................................................................... 575
6.2.2. Privilege System Grant Tables ......................................................................... 579
6.2.3. Specifying Account Names ............................................................................... 583
6.2.4. Access Control, Stage 1: Connection Verification .............................................. 585
6.2.5. Access Control, Stage 2: Request Verification ................................................... 588
6.2.6. When Privilege Changes Take Effect ................................................................ 590
6.2.7. Causes of Access-Denied Errors ...................................................................... 590
6.3. MySQL User Account Management ............................................................................. 595
6.3.1. User Names and Passwords ............................................................................ 595
6.3.2. Adding User Accounts ..................................................................................... 597
6.3.3. Removing User Accounts ................................................................................. 600
6.3.4. Setting Account Resource Limits ...................................................................... 600
6.3.5. Assigning Account Passwords .......................................................................... 602
6.3.6. Using SSL for Secure Connections ................................................................... 603
6.3.7. Connecting to MySQL Remotely from Windows with SSH .................................. 614
6.3.8. SQL-Based MySQL Account Activity Auditing .................................................... 614
7. Backup and Recovery ........................................................................................................... 617
7.1. Backup and Recovery Types ...................................................................................... 618
7.2. Database Backup Methods ......................................................................................... 620
7.3. Example Backup and Recovery Strategy ..................................................................... 622
7.3.1. Establishing a Backup Policy ............................................................................ 623
7.3.2. Using Backups for Recovery ............................................................................ 625
7.3.3. Backup Strategy Summary ............................................................................... 625
7.4. Using mysqldump for Backups ................................................................................... 625
7.4.1. Dumping Data in SQL Format with mysqldump ................................................ 626
7.4.2. Reloading SQL-Format Backups ....................................................................... 627
7.4.3. Dumping Data in Delimited-Text Format with mysqldump .................................. 627
Page 7
MySQL 5.0 Reference Manual
vii
7.4.4. Reloading Delimited-Text Format Backups ........................................................ 628
7.4.5. mysqldump Tips ............................................................................................. 629
7.5. Point-in-Time (Incremental) Recovery Using the Binary Log .......................................... 631
7.5.1. Point-in-Time Recovery Using Event Times ....................................................... 632
7.5.2. Point-in-Time Recovery Using Event Positions .................................................. 632
7.6. MyISAM Table Maintenance and Crash Recovery ........................................................ 633
7.6.1. Using myisamchk for Crash Recovery ............................................................. 634
7.6.2. How to Check MyISAM Tables for Errors .......................................................... 634
7.6.3. How to Repair MyISAM Tables ......................................................................... 635
7.6.4. MyISAM Table Optimization .............................................................................. 637
7.6.5. Setting Up a MyISAM Table Maintenance Schedule ........................................... 638
8. Optimization .......................................................................................................................... 639
8.1. Optimization Overview ................................................................................................ 640
8.1.1. MySQL Design Limitations and Tradeoffs ......................................................... 640
8.1.2. Designing Applications for Portability ................................................................ 640
8.1.3. The MySQL Benchmark Suite .......................................................................... 641
8.1.4. Using Your Own Benchmarks .......................................................................... 642
8.2. Obtaining Query Execution Plan Information ................................................................ 643
8.2.1. Optimizing Queries with EXPLAIN .................................................................... 643
8.2.2. EXPLAIN Output Format .................................................................................. 643
8.2.3. EXPLAIN EXTENDED Output Format ................................................................ 652
8.2.4. Estimating Query Performance ......................................................................... 654
8.3. Optimizing SQL Statements ........................................................................................ 654
8.3.1. Optimizing SELECT Statements ........................................................................ 654
8.3.2. Optimizing Non-SELECT Statements ................................................................. 685
8.3.3. Other Optimization Tips ................................................................................... 689
8.4. Controlling the Query Optimizer .................................................................................. 691
8.5. Optimization and Indexes ........................................................................................... 692
8.5.1. Column Indexes .............................................................................................. 692
8.5.2. Multiple-Column Indexes .................................................................................. 692
8.5.3. How MySQL Uses Indexes .............................................................................. 694
8.5.4. MyISAM Index Statistics Collection ................................................................... 696
8.6. Buffering and Caching ................................................................................................ 698
8.6.1. The MyISAM Key Cache .................................................................................. 698
8.6.2. The InnoDB Buffer Pool .................................................................................. 702
8.6.3. The MySQL Query Cache ................................................................................ 703
8.7. Locking Issues ........................................................................................................... 709
8.7.1. Internal Locking Methods ................................................................................. 709
8.7.2. Table Locking Issues ....................................................................................... 711
8.7.3. Concurrent Inserts ........................................................................................... 712
8.7.4. External Locking .............................................................................................. 713
8.8. Optimizing Database Structure .................................................................................... 714
8.8.1. Make Your Data as Small as Possible .............................................................. 714
8.8.2. Using PROCEDURE ANALYSE ........................................................................... 715
8.8.3. How MySQL Opens and Closes Tables ............................................................ 716
8.8.4. Disadvantages of Creating Many Tables in the Same Database ......................... 717
8.8.5. How MySQL Uses Internal Temporary Tables ................................................... 717
8.9. Optimizing the MySQL Server ..................................................................................... 718
8.9.1. System Factors and Startup Parameter Tuning ................................................. 718
8.9.2. Tuning Server Parameters ............................................................................... 718
8.9.3. How MySQL Uses Threads for Client Connections ............................................ 723
8.9.4. How MySQL Uses Memory .............................................................................. 724
8.9.5. Disk Issues ..................................................................................................... 725
8.9.6. Using Symbolic Links ....................................................................................... 726
8.9.7. Enabling Large Page Support .......................................................................... 729
8.9.8. DNS Lookup Optimization and the Host Cache ................................................. 730
8.10. Examining Thread Information ................................................................................... 731
8.10.1. Thread Command Values ............................................................................... 732
Page 8
MySQL 5.0 Reference Manual
viii
8.10.2. General Thread States ................................................................................... 734
8.10.3. Delayed-Insert Thread States ......................................................................... 739
8.10.4. Query Cache Thread States ........................................................................... 740
8.10.5. Replication Master Thread States ................................................................... 740
8.10.6. Replication Slave I/O Thread States ............................................................... 741
8.10.7. Replication Slave SQL Thread States ............................................................. 742
8.10.8. Replication Slave Connection Thread States ................................................... 742
8.10.9. MySQL Cluster Thread States ........................................................................ 743
9. Language Structure ............................................................................................................... 745
9.1. Literal Values ............................................................................................................. 745
9.1.1. String Literals .................................................................................................. 745
9.1.2. Number Literals ............................................................................................... 747
9.1.3. Date and Time Literals ..................................................................................... 748
9.1.4. Hexadecimal Literals ........................................................................................ 750
9.1.5. Boolean Literals ............................................................................................... 750
9.1.6. Bit-Field Literals ............................................................................................... 750
9.1.7. NULL Values ................................................................................................... 751
9.2. Schema Object Names ............................................................................................... 751
9.2.1. Identifier Qualifiers ........................................................................................... 753
9.2.2. Identifier Case Sensitivity ................................................................................. 754
9.2.3. Function Name Parsing and Resolution ............................................................ 755
9.3. Reserved Words ........................................................................................................ 758
9.4. User-Defined Variables ............................................................................................... 761
9.5. Expression Syntax ...................................................................................................... 764
9.6. Comment Syntax ........................................................................................................ 766
10. Globalization ....................................................................................................................... 767
10.1. Character Set Support .............................................................................................. 767
10.1.1. Character Sets and Collations in General ........................................................ 768
10.1.2. Character Sets and Collations in MySQL ........................................................ 769
10.1.3. Specifying Character Sets and Collations ........................................................ 770
10.1.4. Connection Character Sets and Collations ...................................................... 776
10.1.5. Configuring the Character Set and Collation for Applications ............................ 778
10.1.6. Character Set for Error Messages .................................................................. 780
10.1.7. Collation Issues ............................................................................................. 780
10.1.8. String Repertoire ............................................................................................ 787
10.1.9. Operations Affected by Character Set Support ................................................ 788
10.1.10. Unicode Support .......................................................................................... 791
10.1.11. UTF-8 for Metadata ...................................................................................... 792
10.1.12. Column Character Set Conversion ................................................................ 793
10.1.13. Character Sets and Collations That MySQL Supports .................................... 794
10.2. Setting the Error Message Language ........................................................................ 804
10.3. Adding a Character Set ............................................................................................ 805
10.3.1. Character Definition Arrays ............................................................................. 807
10.3.2. String Collating Support for Complex Character Sets ....................................... 808
10.3.3. Multi-Byte Character Support for Complex Character Sets ................................ 808
10.4. Adding a Collation to a Character Set ....................................................................... 808
10.4.1. Collation Implementation Types ...................................................................... 809
10.4.2. Choosing a Collation ID ................................................................................. 811
10.4.3. Adding a Simple Collation to an 8-Bit Character Set ........................................ 812
10.4.4. Adding a UCA Collation to a Unicode Character Set ........................................ 813
10.5. Character Set Configuration ...................................................................................... 816
10.6. MySQL Server Time Zone Support ............................................................................ 816
10.6.1. Staying Current with Time Zone Changes ....................................................... 819
10.6.2. Time Zone Leap Second Support ................................................................... 820
10.7. MySQL Server Locale Support .................................................................................. 821
11. Data Types ......................................................................................................................... 825
11.1. Data Type Overview ................................................................................................. 825
11.1.1. Numeric Type Overview ................................................................................. 825
Page 9
MySQL 5.0 Reference Manual
ix
11.1.2. Date and Time Type Overview ....................................................................... 829
11.1.3. String Type Overview ..................................................................................... 830
11.1.4. Numeric Types .............................................................................................. 834
11.1.5. Date and Time Types .................................................................................... 838
11.1.6. String Types .................................................................................................. 848
11.1.7. Data Type Default Values .............................................................................. 856
11.2. Data Type Storage Requirements ............................................................................. 858
11.3. Choosing the Right Type for a Column ...................................................................... 861
11.4. Using Data Types from Other Database Engines ....................................................... 861
12. Functions and Operators ..................................................................................................... 863
12.1. Function and Operator Reference ............................................................................. 864
12.2. Type Conversion in Expression Evaluation ................................................................ 871
12.3. Operators ................................................................................................................. 872
12.3.1. Operator Precedence ..................................................................................... 873
12.3.2. Comparison Functions and Operators ............................................................. 874
12.3.3. Logical Operators .......................................................................................... 880
12.3.4. Assignment Operators .................................................................................... 881
12.4. Control Flow Functions ............................................................................................. 882
12.5. String Functions ....................................................................................................... 884
12.5.1. String Comparison Functions .......................................................................... 895
12.5.2. Regular Expressions ...................................................................................... 899
12.6. Numeric Functions and Operators ............................................................................. 904
12.6.1. Arithmetic Operators ...................................................................................... 905
12.6.2. Mathematical Functions .................................................................................. 907
12.7. Date and Time Functions .......................................................................................... 915
12.8. What Calendar Is Used By MySQL? .......................................................................... 934
12.9. Full-Text Search Functions ....................................................................................... 934
12.9.1. Natural Language Full-Text Searches ............................................................. 935
12.9.2. Boolean Full-Text Searches ........................................................................... 938
12.9.3. Full-Text Searches with Query Expansion ....................................................... 940
12.9.4. Full-Text Stopwords ....................................................................................... 941
12.9.5. Full-Text Restrictions ..................................................................................... 944
12.9.6. Fine-Tuning MySQL Full-Text Search ............................................................. 944
12.9.7. Adding a Collation for Full-Text Indexing ......................................................... 946
12.10. Cast Functions and Operators ................................................................................. 948
12.11. Bit Functions .......................................................................................................... 950
12.12. Encryption and Compression Functions ................................................................... 952
12.13. Information Functions .............................................................................................. 957
12.14. Miscellaneous Functions ......................................................................................... 964
12.15. Functions and Modifiers for Use with GROUP BY Clauses ......................................... 968
12.15.1. GROUP BY (Aggregate) Functions ................................................................ 968
12.15.2. GROUP BY Modifiers .................................................................................... 972
12.15.3. MySQL Extensions to GROUP BY ................................................................. 975
12.16. Spatial Extensions .................................................................................................. 976
12.16.1. Introduction to MySQL Spatial Support .......................................................... 976
12.16.2. The OpenGIS Geometry Model .................................................................... 977
12.16.3. Supported Spatial Data Formats ................................................................... 983
12.16.4. Creating a Spatially Enabled MySQL Database ............................................. 984
12.16.5. Spatial Analysis Functions ............................................................................ 989
12.16.6. Optimizing Spatial Analysis ........................................................................... 998
12.16.7. MySQL Conformance and Compatibility ...................................................... 1001
12.17. Precision Math ...................................................................................................... 1001
12.17.1. Types of Numeric Values ........................................................................... 1002
12.17.2. DECIMAL Data Type Changes .................................................................... 1002
12.17.3. Expression Handling ................................................................................... 1004
12.17.4. Rounding Behavior ..................................................................................... 1005
12.17.5. Precision Math Examples ........................................................................... 1006
13. SQL Statement Syntax ...................................................................................................... 1011
Page 10
MySQL 5.0 Reference Manual
x
13.1. Data Definition Statements ...................................................................................... 1012
13.1.1. ALTER DATABASE Syntax ........................................................................... 1012
13.1.2. ALTER FUNCTION Syntax ........................................................................... 1012
13.1.3. ALTER PROCEDURE Syntax ......................................................................... 1013
13.1.4. ALTER TABLE Syntax ................................................................................. 1013
13.1.5. ALTER VIEW Syntax ................................................................................... 1020
13.1.6. CREATE DATABASE Syntax ......................................................................... 1020
13.1.7. CREATE FUNCTION Syntax ......................................................................... 1021
13.1.8. CREATE INDEX Syntax ............................................................................... 1021
13.1.9. CREATE PROCEDURE and CREATE FUNCTION Syntax .................................. 1023
13.1.10. CREATE TABLE Syntax ............................................................................. 1029
13.1.11. CREATE TRIGGER Syntax ......................................................................... 1047
13.1.12. CREATE VIEW Syntax ............................................................................... 1050
13.1.13. DROP DATABASE Syntax ........................................................................... 1054
13.1.14. DROP FUNCTION Syntax ........................................................................... 1055
13.1.15. DROP INDEX Syntax ................................................................................. 1055
13.1.16. DROP PROCEDURE and DROP FUNCTION Syntax ........................................ 1056
13.1.17. DROP TABLE Syntax ................................................................................. 1056
13.1.18. DROP TRIGGER Syntax ............................................................................. 1056
13.1.19. DROP VIEW Syntax ................................................................................... 1057
13.1.20. RENAME TABLE Syntax ............................................................................. 1057
13.1.21. TRUNCATE TABLE Syntax ......................................................................... 1058
13.2. Data Manipulation Statements ................................................................................. 1059
13.2.1. CALL Syntax ................................................................................................ 1059
13.2.2. DELETE Syntax ............................................................................................ 1060
13.2.3. DO Syntax .................................................................................................... 1064
13.2.4. HANDLER Syntax .......................................................................................... 1064
13.2.5. INSERT Syntax ............................................................................................ 1065
13.2.6. LOAD DATA INFILE Syntax ....................................................................... 1072
13.2.7. REPLACE Syntax .......................................................................................... 1081
13.2.8. SELECT Syntax ............................................................................................ 1082
13.2.9. Subquery Syntax .......................................................................................... 1098
13.2.10. UPDATE Syntax .......................................................................................... 1108
13.3. MySQL Transactional and Locking Statements ......................................................... 1110
13.3.1. START TRANSACTION, COMMIT, and ROLLBACK Syntax ............................... 1110
13.3.2. Statements That Cannot Be Rolled Back ....................................................... 1113
13.3.3. Statements That Cause an Implicit Commit ................................................... 1113
13.3.4. SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT, and
Syntax .................................................................................................................... 1114
13.3.5. LOCK TABLES and UNLOCK TABLES Syntax ................................................ 1114
13.3.6. SET TRANSACTION Syntax ......................................................................... 1119
13.3.7. XA Transactions .......................................................................................... 1121
13.4. Replication Statements ........................................................................................... 1125
13.4.1. SQL Statements for Controlling Master Servers ............................................. 1125
13.4.2. SQL Statements for Controlling Slave Servers ............................................... 1127
13.5. SQL Syntax for Prepared Statements ...................................................................... 1133
13.5.1. PREPARE Syntax .......................................................................................... 1136
13.5.2. EXECUTE Syntax .......................................................................................... 1136
13.5.3. DEALLOCATE PREPARE Syntax ................................................................... 1136
13.6. MySQL Compound-Statement Syntax ...................................................................... 1137
13.6.1. BEGIN ... END Compound-Statement Syntax ............................................ 1137
13.6.2. Statement Label Syntax ............................................................................... 1137
13.6.3. DECLARE Syntax .......................................................................................... 1138
13.6.4. Variables in Stored Programs ....................................................................... 1138
13.6.5. Flow Control Statements .............................................................................. 1140
13.6.6. Cursors ....................................................................................................... 1144
13.6.7. Condition Handling ....................................................................................... 1145
13.7. Database Administration Statements ........................................................................ 1149
Page 11
MySQL 5.0 Reference Manual
xi
13.7.1. Account Management Statements ................................................................. 1149
13.7.2. Table Maintenance Statements ..................................................................... 1162
13.7.3. User-Defined Function Statements ................................................................ 1169
13.7.4. SET Syntax .................................................................................................. 1170
13.7.5. SHOW Syntax ................................................................................................ 1173
13.7.6. Other Administrative Statements ................................................................... 1205
13.8. MySQL Utility Statements ....................................................................................... 1210
13.8.1. DESCRIBE Syntax ........................................................................................ 1210
13.8.2. EXPLAIN Syntax .......................................................................................... 1210
13.8.3. HELP Syntax ................................................................................................ 1211
13.8.4. USE Syntax .................................................................................................. 1213
14. Storage Engines ................................................................................................................ 1215
14.1. The MyISAM Storage Engine ................................................................................... 1218
14.1.1. MyISAM Startup Options ............................................................................... 1220
14.1.2. Space Needed for Keys ............................................................................... 1222
14.1.3. MyISAM Table Storage Formats .................................................................... 1222
14.1.4. MyISAM Table Problems .............................................................................. 1224
14.2. The InnoDB Storage Engine ................................................................................... 1226
14.2.1. InnoDB Configuration .................................................................................. 1226
14.2.2. InnoDB Startup Options and System Variables ............................................. 1234
14.2.3. Creating and Using InnoDB Tables .............................................................. 1254
14.2.4. Adding, Removing, or Resizing InnoDB Data and Log Files ........................... 1259
14.2.5. Backing Up and Recovering an InnoDB Database ......................................... 1261
14.2.6. Moving an InnoDB Database to Another Machine ......................................... 1264
14.2.7. The InnoDB Transaction Model and Locking ................................................. 1264
14.2.8. InnoDB Multi-Versioning .............................................................................. 1275
14.2.9. InnoDB Table and Index Structures .............................................................. 1276
14.2.10. InnoDB Disk I/O and File Space Management ............................................ 1279
14.2.11. InnoDB Error Handling .............................................................................. 1280
14.2.12. InnoDB Performance Tuning and Troubleshooting ....................................... 1284
14.2.13. Limits on InnoDB Tables ........................................................................... 1297
14.3. The MERGE Storage Engine ..................................................................................... 1300
14.3.1. MERGE Table Advantages and Disadvantages ............................................... 1302
14.3.2. MERGE Table Problems ................................................................................ 1303
14.4. The MEMORY (HEAP) Storage Engine ....................................................................... 1305
14.5. The BDB (BerkeleyDB) Storage Engine .................................................................. 1307
14.5.1. Operating Systems Supported by BDB .......................................................... 1308
14.5.2. Installing BDB ............................................................................................... 1308
14.5.3. BDB Startup Options ..................................................................................... 1309
14.5.4. Characteristics of BDB Tables ....................................................................... 1310
14.5.5. Restrictions on BDB Tables ........................................................................... 1312
14.5.6. Errors That May Occur When Using BDB Tables ............................................ 1312
14.6. The EXAMPLE Storage Engine ................................................................................. 1313
14.7. The FEDERATED Storage Engine ............................................................................. 1313
14.7.1. Description of the FEDERATED Storage Engine .............................................. 1313
14.7.2. How to Use FEDERATED Tables ................................................................... 1314
14.7.3. Limitations of the FEDERATED Storage Engine ............................................... 1315
14.8. The ARCHIVE Storage Engine ................................................................................. 1316
14.9. The CSV Storage Engine ......................................................................................... 1317
14.10. The BLACKHOLE Storage Engine ........................................................................... 1318
15. High Availability and Scalability .......................................................................................... 1321
15.1. Oracle VM Template for MySQL Enterprise Edition ................................................... 1324
15.2. Overview of MySQL with DRBD/Pacemaker/Corosync/Oracle Linux ........................... 1324
15.3. Overview of MySQL with Windows Failover Clustering .............................................. 1327
15.4. Using MySQL within an Amazon EC2 Instance ........................................................ 1329
15.4.1. Setting Up MySQL on an EC2 AMI ............................................................... 1330
15.4.2. EC2 Instance Limitations .............................................................................. 1331
15.4.3. Deploying a MySQL Database Using EC2 ..................................................... 1331
Page 12
MySQL 5.0 Reference Manual
xii
15.5. Using ZFS Replication ............................................................................................ 1334
15.5.1. Using ZFS for File System Replication .......................................................... 1335
15.5.2. Configuring MySQL for ZFS Replication ........................................................ 1336
15.5.3. Handling MySQL Recovery with ZFS ............................................................ 1337
15.6. Using MySQL with memcached ............................................................................... 1337
15.6.1. Installing memcached ................................................................................... 1339
15.6.2. Using memcached ....................................................................................... 1340
15.6.3. Developing a memcached Application ........................................................... 1358
15.6.4. Getting memcached Statistics ....................................................................... 1381
15.6.5. memcached FAQ ......................................................................................... 1390
15.7. MySQL Proxy ......................................................................................................... 1392
15.7.1. MySQL Proxy Supported Platforms ............................................................... 1393
15.7.2. Installing MySQL Proxy ................................................................................ 1394
15.7.3. MySQL Proxy Command Options ................................................................. 1396
15.7.4. MySQL Proxy Scripting ................................................................................ 1405
15.7.5. Using MySQL Proxy ..................................................................................... 1420
15.7.6. MySQL Proxy FAQ ...................................................................................... 1425
16. Replication ........................................................................................................................ 1431
16.1. Replication Configuration ........................................................................................ 1432
16.1.1. How to Set Up Replication ........................................................................... 1433
16.1.2. Replication and Binary Logging Options and Variables ................................... 1441
16.1.3. Common Replication Administration Tasks .................................................... 1473
16.2. Replication Implementation ...................................................................................... 1475
16.2.1. Replication Implementation Details ................................................................ 1476
16.2.2. Replication Relay and Status Logs ............................................................... 1478
16.2.3. How Servers Evaluate Replication Filtering Rules .......................................... 1480
16.3. Replication Solutions ............................................................................................... 1486
16.3.1. Using Replication for Backups ...................................................................... 1487
16.3.2. Using Replication with Different Master and Slave Storage Engines ................ 1488
16.3.3. Using Replication for Scale-Out .................................................................... 1489
16.3.4. Replicating Different Databases to Different Slaves ........................................ 1490
16.3.5. Improving Replication Performance ............................................................... 1492
16.3.6. Switching Masters During Failover ................................................................ 1493
16.3.7. Setting Up Replication Using SSL ................................................................. 1495
16.4. Replication Notes and Tips ..................................................................................... 1497
16.4.1. Replication Features and Issues ................................................................... 1497
16.4.2. Replication Compatibility Between MySQL Versions ....................................... 1508
16.4.3. Upgrading a Replication Setup ..................................................................... 1509
16.4.4. Troubleshooting Replication .......................................................................... 1510
16.4.5. How to Report Replication Bugs or Problems ................................................ 1511
17. MySQL Cluster .................................................................................................................. 1513
17.1. MySQL Cluster Overview ........................................................................................ 1514
17.1.1. MySQL Cluster Core Concepts ..................................................................... 1516
17.1.2. MySQL Cluster Nodes, Node Groups, Replicas, and Partitions ....................... 1518
17.1.3. MySQL Cluster Hardware, Software, and Networking Requirements ................ 1520
17.1.4. MySQL Cluster Development History ............................................................ 1521
17.1.5. Known Limitations of MySQL Cluster ............................................................ 1522
17.2. MySQL Cluster Installation and Upgrades ................................................................ 1530
17.2.1. Installing MySQL Cluster on Linux ................................................................ 1533
17.2.2. Initial Configuration of MySQL Cluster ........................................................... 1537
17.2.3. Initial Startup of MySQL Cluster .................................................................... 1539
17.2.4. MySQL Cluster Example with Tables and Data .............................................. 1540
17.2.5. Safe Shutdown and Restart of MySQL Cluster .............................................. 1543
17.2.6. Upgrading and Downgrading MySQL Cluster ................................................. 1544
17.3. MySQL Cluster Configuration .................................................................................. 1546
17.3.1. Quick Test Setup of MySQL Cluster ............................................................. 1546
17.3.2. MySQL Cluster Configuration Files ............................................................... 1548
17.3.3. Overview of MySQL Cluster Configuration Parameters ................................... 1593
Page 13
MySQL 5.0 Reference Manual
xiii
17.3.4. MySQL Server Options and Variables for MySQL Cluster ............................... 1607
17.3.5. Using High-Speed Interconnects with MySQL Cluster .................................... 1616
17.4. MySQL Cluster Programs ....................................................................................... 1618
17.4.1. ndbd — The MySQL Cluster Data Node Daemon .......................................... 1618
17.4.2. ndb_mgmd — The MySQL Cluster Management Server Daemon .................... 1623
17.4.3. ndb_mgm — The MySQL Cluster Management Client .................................... 1626
17.4.4. ndb_config — Extract MySQL Cluster Configuration Information .................. 1627
17.4.5. ndb_cpcd — Automate Testing for NDB Development .................................. 1631
17.4.6. ndb_delete_all — Delete All Rows from an NDB Table ............................. 1631
17.4.7. ndb_desc — Describe NDB Tables ............................................................. 1632
17.4.8. ndb_drop_index — Drop Index from an NDB Table .................................... 1633
17.4.9. ndb_drop_table — Drop an NDB Table .................................................... 1634
17.4.10. ndb_error_reporter — NDB Error-Reporting Utility ................................ 1635
17.4.11. ndb_print_backup_file — Print NDB Backup File Contents ................... 1635
17.4.12. ndb_print_schema_file — Print NDB Schema File Contents .................. 1636
17.4.13. ndb_print_sys_file — Print NDB System File Contents ......................... 1636
17.4.14. ndb_restore — Restore a MySQL Cluster Backup .................................... 1637
17.4.15. ndb_select_all — Print Rows from an NDB Table .................................. 1642
17.4.16. ndb_select_count — Print Row Counts for NDB Tables .......................... 1645
17.4.17. ndb_show_tables — Display List of NDB Tables ...................................... 1645
17.4.18. ndb_size.pl — NDBCLUSTER Size Requirement Estimator ..................... 1647
17.4.19. ndb_waiter — Wait for MySQL Cluster to Reach a Given Status ................ 1648
17.4.20. Options Common to MySQL Cluster Programs — Options Common to MySQL
Cluster Programs .................................................................................................... 1650
17.5. Management of MySQL Cluster ............................................................................... 1653
17.5.1. Summary of MySQL Cluster Start Phases ..................................................... 1653
17.5.2. Commands in the MySQL Cluster Management Client ................................... 1655
17.5.3. Online Backup of MySQL Cluster ................................................................. 1656
17.5.4. MySQL Server Usage for MySQL Cluster ...................................................... 1660
17.5.5. Performing a Rolling Restart of a MySQL Cluster ........................................... 1661
17.5.6. Event Reports Generated in MySQL Cluster .................................................. 1663
17.5.7. MySQL Cluster Log Messages ..................................................................... 1671
17.5.8. MySQL Cluster Single User Mode ................................................................ 1682
17.5.9. Quick Reference: MySQL Cluster SQL Statements ........................................ 1683
17.5.10. MySQL Cluster Security Issues ................................................................... 1684
18. Stored Programs and Views .............................................................................................. 1693
18.1. Defining Stored Programs ....................................................................................... 1693
18.2. Using Stored Routines (Procedures and Functions) .................................................. 1694
18.2.1. Stored Routine Syntax ................................................................................. 1695
18.2.2. Stored Routines and MySQL Privileges ......................................................... 1696
18.2.3. Stored Routine Metadata .............................................................................. 1696
18.2.4. Stored Procedures, Functions, Triggers, and LAST_INSERT_ID() ................. 1697
18.3. Using Triggers ........................................................................................................ 1697
18.3.1. Trigger Syntax ............................................................................................. 1697
18.3.2. Trigger Metadata .......................................................................................... 1700
18.4. Using Views ........................................................................................................... 1700
18.4.1. View Syntax ................................................................................................. 1700
18.4.2. View Processing Algorithms ......................................................................... 1700
18.4.3. Updatable and Insertable Views .................................................................... 1702
18.4.4. View Metadata ............................................................................................. 1704
18.5. Access Control for Stored Programs and Views ....................................................... 1704
18.6. Binary Logging of Stored Programs ......................................................................... 1705
19. INFORMATION_SCHEMA Tables .......................................................................................... 1715
19.1. The INFORMATION_SCHEMA CHARACTER_SETS Table ............................................ 1717
19.2. The INFORMATION_SCHEMA COLLATIONS Table .................................................... 1717
19.3. The INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY
Table .............................................................................................................................. 1718
19.4. The INFORMATION_SCHEMA COLUMNS Table ......................................................... 1718
Page 14
MySQL 5.0 Reference Manual
xiv
19.5. The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table ...................................... 1719
19.6. The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table ........................................ 1720
19.7. The INFORMATION_SCHEMA PROFILING Table ..................................................... 1721
19.8. The INFORMATION_SCHEMA ROUTINES Table ....................................................... 1722
19.9. The INFORMATION_SCHEMA SCHEMATA Table ....................................................... 1723
19.10. The INFORMATION_SCHEMA SCHEMA_PRIVILEGES Table .................................... 1723
19.11. The INFORMATION_SCHEMA STATISTICS Table .................................................. 1723
19.12. The INFORMATION_SCHEMA TABLES Table .......................................................... 1724
19.13. The INFORMATION_SCHEMA TABLE_CONSTRAINTS Table .................................... 1725
19.14. The INFORMATION_SCHEMA TABLE_PRIVILEGES Table ...................................... 1726
19.15. The INFORMATION_SCHEMA TRIGGERS Table ...................................................... 1726
19.16. The INFORMATION_SCHEMA USER_PRIVILEGES Table ........................................ 1728
19.17. The INFORMATION_SCHEMA VIEWS Table ............................................................ 1728
19.18. Extensions to SHOW Statements ............................................................................. 1729
20. Connectors and APIs ......................................................................................................... 1733
20.1. MySQL Connector/ODBC ........................................................................................ 1737
20.1.1. Connector/ODBC Versions ........................................................................... 1738
20.1.2. Connector/ODBC Introduction ....................................................................... 1739
20.1.3. Connector/ODBC Installation ........................................................................ 1742
20.1.4. Configuring Connector/ODBC ....................................................................... 1752
20.1.5. Connector/ODBC Examples .......................................................................... 1772
20.1.6. Connector/ODBC Reference ......................................................................... 1798
20.1.7. Connector/ODBC Notes and Tips ................................................................. 1804
20.1.8. Connector/ODBC Support ............................................................................ 1814
20.2. MySQL Connector/Net ............................................................................................ 1815
20.2.1. Connector/Net Versions ................................................................................ 1816
20.2.2. Connector/Net Installation ............................................................................. 1818
20.2.3. Connector/Net Visual Studio Integration ........................................................ 1826
20.2.4. Connector/Net Tutorials ................................................................................ 1856
20.2.5. Connector/Net Programming ......................................................................... 1896
20.2.6. Connector/Net Connection String Options Reference ..................................... 1935
20.2.7. Connector/Net API Reference ....................................................................... 1942
20.2.8. Connector/Net Support ................................................................................. 2045
20.2.9. Connector/Net FAQ ...................................................................................... 2046
20.3. MySQL Connector/J ................................................................................................ 2047
20.3.1. Overview of MySQL Connector/J .................................................................. 2047
20.3.2. Connector/J Versions ................................................................................... 2047
20.3.3. Connector/J Installation ................................................................................ 2049
20.3.4. Connector/J Examples ................................................................................. 2053
20.3.5. Connector/J (JDBC) Reference ..................................................................... 2054
20.3.6. JDBC Concepts ........................................................................................... 2087
20.3.7. Connection Pooling with Connector/J ............................................................ 2096
20.3.8. Load Balancing with Connector/J .................................................................. 2099
20.3.9. Failover with Connector/J ............................................................................. 2101
20.3.10. Using the Connector/J Interceptor Classes .................................................. 2103
20.3.11. Using Connector/J with Tomcat .................................................................. 2103
20.3.12. Using Connector/J with JBoss .................................................................... 2105
20.3.13. Using Connector/J with Spring .................................................................... 2106
20.3.14. Using Connector/J with GlassFish ............................................................... 2110
20.3.15. Troubleshooting Connector/J Applications ................................................... 2116
20.3.16. Connector/J Support ................................................................................... 2124
20.4. MySQL Connector/C ............................................................................................... 2125
20.4.1. MySQL Connector/C Supported Platforms ..................................................... 2126
20.4.2. MySQL Connector/C Distribution Contents .................................................... 2126
20.4.3. Obtaining MySQL Connector/C ..................................................................... 2126
20.4.4. Installing MySQL Connector/C from a Binary Distribution ................................ 2127
20.4.5. Installing MySQL Connector/C from Source ................................................... 2127
20.4.6. Testing MySQL Connector/C ........................................................................ 2129
Page 15
MySQL 5.0 Reference Manual
xv
20.4.7. Building MySQL Connector/C Applications .................................................... 2129
20.5. libmysqld, the Embedded MySQL Server Library ...................................................... 2129
20.6. MySQL C API ......................................................................................................... 2130
20.6.1. MySQL C API Implementations .................................................................... 2131
20.6.2. Example C API Client Programs ................................................................... 2132
20.6.3. Building and Running C API Client Programs ................................................ 2132
20.6.4. C API Data Structures .................................................................................. 2135
20.6.5. C API Function Overview ............................................................................. 2139
20.6.6. C API Function Descriptions ......................................................................... 2144
20.6.7. C API Prepared Statements ......................................................................... 2191
20.6.8. C API Prepared Statement Data Structures ................................................... 2191
20.6.9. C API Prepared Statement Function Overview ............................................... 2197
20.6.10. C API Prepared Statement Function Descriptions ........................................ 2200
20.6.11. C API Threaded Function Descriptions ........................................................ 2221
20.6.12. C API Embedded Server Function Descriptions ........................................... 2223
20.6.13. Common Questions and Problems When Using the C API ............................ 2223
20.6.14. Controlling Automatic Reconnection Behavior .............................................. 2225
20.6.15. C API Support for Multiple Statement Execution .......................................... 2226
20.6.16. C API Prepared Statement Problems .......................................................... 2228
20.6.17. C API Prepared Statement Handling of Date and Time Values ...................... 2228
20.6.18. C API Support for Prepared CALL Statements ............................................. 2229
20.7. MySQL PHP API .................................................................................................... 2230
20.7.1. Overview of the MySQL PHP drivers ............................................................ 2230
20.7.2. Original MySQL API (Mysql) ........................................................................ 2237
20.7.3. MySQL Improved Extension (Mysqli) .......................................................... 2306
20.7.4. MySQL Functions (PDO_MYSQL) (MySQL (PDO)) ....................................... 2520
20.7.5. MySQL Native Driver (Mysqlnd) .................................................................. 2524
20.7.6. Mysqlnd replication and load balancing plugin (mysqlnd_ms) ......................... 2556
20.7.7. Mysqlnd query result cache plugin (mysqlnd_qc) ......................................... 2657
20.7.8. Mysqlnd user handler plugin (mysqlnd_uh) .................................................. 2708
20.7.9. Mysqlnd connection multiplexing plugin (mysqlnd_mux) ................................ 2791
20.7.10. Mysqlnd Memcache plugin (mysqlnd_memcache) ....................................... 2795
20.7.11. Connector/PHP .......................................................................................... 2804
20.7.12. Common Problems with MySQL and PHP ................................................... 2804
20.7.13. Enabling Both mysql and mysqli in PHP .................................................. 2804
20.8. MySQL Perl API ..................................................................................................... 2805
20.9. MySQL Python API ................................................................................................. 2806
20.10. MySQL Ruby APIs ................................................................................................ 2806
20.10.1. The MySQL/Ruby API ................................................................................ 2806
20.10.2. The Ruby/MySQL API ................................................................................ 2806
20.11. MySQL Tcl API ..................................................................................................... 2806
20.12. MySQL Eiffel Wrapper .......................................................................................... 2806
21. Extending MySQL .............................................................................................................. 2807
21.1. MySQL Internals ..................................................................................................... 2807
21.1.1. MySQL Threads ........................................................................................... 2807
21.1.2. The MySQL Test Suite ................................................................................. 2808
21.2. Adding New Functions to MySQL ............................................................................ 2808
21.2.1. Features of the User-Defined Function Interface ............................................ 2809
21.2.2. Adding a New User-Defined Function ........................................................... 2809
21.2.3. Adding a New Native Function ..................................................................... 2819
21.3. Debugging and Porting MySQL ............................................................................... 2820
21.3.1. Debugging a MySQL Server ......................................................................... 2821
21.3.2. Debugging a MySQL Client .......................................................................... 2827
21.3.3. The DBUG Package .................................................................................... 2827
22. MySQL Enterprise Edition .................................................................................................. 2831
22.1. MySQL Enterprise Monitor ...................................................................................... 2831
22.2. MySQL Enterprise Backup ...................................................................................... 2832
22.3. MySQL Enterprise Security ..................................................................................... 2832
Page 16
MySQL 5.0 Reference Manual
xvi
22.4. MySQL Enterprise Audit .......................................................................................... 2833
22.5. MySQL Thread Pool ............................................................................................... 2833
A. Licenses for Third-Party Components .................................................................................. 2835
A.1. Ant-Contrib License .................................................................................................. 2837
A.2. ANTLR 3.3 License .................................................................................................. 2838
A.3. Boost Library License ............................................................................................... 2838
A.4. c3p0 JDBC Library License ...................................................................................... 2839
A.5. dtoa.c License ....................................................................................................... 2839
A.6. Editline Library (libedit) License ........................................................................... 2839
A.7. Fred Fish's Dbug Library License .............................................................................. 2841
A.8. GLib License (for MySQL Proxy) ............................................................................... 2842
A.9. GNU General Public License Version 2.0, June 1991 ................................................. 2843
A.10. GNU Lesser General Public License Version 2.1, February 1999 .............................. 2848
A.11. GNU Libtool License .............................................................................................. 2855
A.12. GNU Readline License ........................................................................................... 2856
A.13. jboss-common-jdbc-wrapper.jar License .................................................................. 2856
A.14. lib_sql.cc License ............................................................................................. 2856
A.15. libevent License ................................................................................................. 2857
A.16. Libiconv License ..................................................................................................... 2858
A.17. libintl License ................................................................................................... 2859
A.18. LPeg Library License ............................................................................................. 2859
A.19. Lua (liblua) License ................................................................................................ 2860
A.20. LuaFileSystem Library License ............................................................................ 2860
A.21. md5 (Message-Digest Algorithm 5) License ............................................................. 2861
A.22. OpenSSL v1.0 License ........................................................................................... 2861
A.23. PCRE License ........................................................................................................ 2862
A.24. RegEX-Spencer Library License .............................................................................. 2863
A.25. RFC 3174 - US Secure Hash Algorithm 1 (SHA1) License ........................................ 2864
A.26. Richard A. O'Keefe String Library License ............................................................... 2864
A.27. SHA-1 in C License ................................................................................................ 2865
A.28. Simple Logging Facade for Java (SLF4J) License .................................................... 2865
A.29. zlib License ......................................................................................................... 2865
A.30. ZLIB.NET License .................................................................................................. 2866
B. MySQL 5.0 Frequently Asked Questions .............................................................................. 2867
B.1. MySQL 5.0 FAQ: General ........................................................................................ 2867
B.2. MySQL 5.0 FAQ: Storage Engines ............................................................................ 2869
B.3. MySQL 5.0 FAQ: Server SQL Mode ......................................................................... 2869
B.4. MySQL 5.0 FAQ: Stored Procedures and Functions ................................................... 2870
B.5. MySQL 5.0 FAQ: Triggers ........................................................................................ 2874
B.6. MySQL 5.0 FAQ: Views ........................................................................................... 2876
B.7. MySQL 5.0 FAQ: INFORMATION_SCHEMA ................................................................. 2877
B.8. MySQL 5.0 FAQ: Migration ....................................................................................... 2878
B.9. MySQL 5.0 FAQ: Security ........................................................................................ 2878
B.10. MySQL 5.0 FAQ: MySQL Cluster ............................................................................ 2879
B.11. MySQL 5.0 FAQ: MySQL Chinese, Japanese, and Korean Character Sets ................ 2891
B.12. MySQL 5.0 FAQ: Connectors & APIs ...................................................................... 2903
B.13. MySQL 5.0 FAQ: Replication .................................................................................. 2903
C. Errors, Error Codes, and Common Problems ....................................................................... 2909
C.1. Sources of Error Information ..................................................................................... 2909
C.2. Types of Error Values .............................................................................................. 2909
C.3. Server Error Codes and Messages ........................................................................... 2910
C.4. Client Error Codes and Messages ............................................................................ 2941
C.5. Problems and Common Errors .................................................................................. 2945
C.5.1. How to Determine What Is Causing a Problem ............................................... 2945
C.5.2. Common Errors When Using MySQL Programs .............................................. 2946
C.5.3. Installation-Related Issues ............................................................................. 2959
C.5.4. Administration-Related Issues ........................................................................ 2959
C.5.5. Query-Related Issues .................................................................................... 2966
Page 17
MySQL 5.0 Reference Manual
xvii
C.5.6. Optimizer-Related Issues ............................................................................... 2973
C.5.7. Table Definition-Related Issues ...................................................................... 2974
C.5.8. Known Issues in MySQL ............................................................................... 2975
D. MySQL Release Notes ........................................................................................................ 2979
E. Restrictions and Limits ........................................................................................................ 2981
E.1. Restrictions on Stored Programs ............................................................................... 2981
E.2. Restrictions on Server-Side Cursors .......................................................................... 2983
E.3. Restrictions on Subqueries ....................................................................................... 2984
E.4. Restrictions on Views ............................................................................................... 2985
E.5. Restrictions on XA Transactions ............................................................................... 2987
E.6. Restrictions on Character Sets .................................................................................. 2988
E.7. Limits in MySQL ...................................................................................................... 2988
E.7.1. Limits of Joins ............................................................................................... 2988
E.7.2. Limits on Number of Databases and Tables .................................................... 2988
E.7.3. Limits on Table Size ...................................................................................... 2989
E.7.4. Limits on Table Column Count and Row Size ................................................. 2990
E.7.5. Limits Imposed by .frm File Structure ........................................................... 2991
E.7.6. Windows Platform Limitations ......................................................................... 2992
General Index ......................................................................................................................... 2995
C Function Index ..................................................................................................................... 3055
Command Index ...................................................................................................................... 3063
Function Index ........................................................................................................................ 3087
INFORMATION_SCHEMA Index ................................................................................................. 3103
Join Types Index ..................................................................................................................... 3105
Operator Index ........................................................................................................................ 3107
Option Index ........................................................................................................................... 3111
Privileges Index ....................................................................................................................... 3155
SQL Modes Index ................................................................................................................... 3159
Statement/Syntax Index ........................................................................................................... 3161
System Variable Index ............................................................................................................. 3191
Status Variable Index .............................................................................................................. 3205
Transaction Isolation Level Index ............................................................................................. 3211
Page 18
xviii
Page 19
xix
Preface and Legal Notices
This is the Reference Manual for the MySQL Database System, version 5.0, through release 5.0.96. Differences between minor versions of MySQL 5.0 are noted in the present text with reference to release numbers (5.0.x). For license information, see the Legal Notices. This product may contain third-party code. For license information on third-party code, see Appendix A, Licenses for Third-Party
Components.
This manual is not intended for use with older versions of the MySQL software due to the many functional and other differences between MySQL 5.0 and previous versions. If you are using an earlier release of the MySQL software, please refer to the appropriate manual. For example, MySQL 3.23, 4.0,
4.1 Reference Manual covers the 4.1 series of MySQL software releases.
If you are using MySQL 5.1, please refer to the MySQL 5.1 Reference Manual.
Legal Notices
Copyright © 1997, 2013, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing
restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error­free. If you find any errors, please report them to us in writing.
If this software or related documentation is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are "commercial computer software" or "commercial technical data" pursuant to the applicable Federal Acquisition Regulation and agency­specific supplemental regulations. As such, the use, duplication, disclosure, modification, and adaptation shall be subject to the restrictions and license terms set forth in the applicable Government contract, and, to the extent applicable by the terms of the Government contract, the additional rights set forth in FAR 52.227-19, Commercial Computer Software License (December 2007). Oracle USA, Inc., 500 Oracle Parkway, Redwood City, CA 94065.
This software is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications which may create a risk of personal injury. If you use this software in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure the safe use of this software. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software in dangerous applications.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. MySQL is a trademark of Oracle Corporation and/or its affiliates, and shall not be used without Oracle's express written authorization. Other names may be trademarks of their respective owners.
This software and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services.
This document in any form, software or printed matter, contains proprietary information that is the exclusive property of Oracle. Your access to and use of this material is subject to the terms and
Page 20
Legal Notices
xx
conditions of your Oracle Software License and Service Agreement, which has been executed and with which you agree to comply. This document and information contained herein may not be disclosed, copied, reproduced, or distributed to anyone outside Oracle without prior written consent of Oracle or as specifically provided below. This document is not part of your license agreement nor can it be incorporated into any contractual agreement with Oracle or its subsidiaries or affiliates.
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 Oracle 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 Oracle. Oracle and/ or its affiliates reserve any and all rights to this documentation not expressly granted above.
For more information on the terms of this license, or for details on how the MySQL documentation is built and produced, please visit MySQL Contact & Questions.
For additional licensing information, including licenses for third-party libraries used by MySQL products, see Preface and Legal Notices.
For help with using MySQL, please visit either the MySQL Forums or MySQL Mailing Lists where you can discuss your issues with other MySQL users.
For additional documentation on MySQL products, including translations of the documentation into other languages, and downloadable versions in variety of formats, including HTML and PDF formats, see the MySQL Documentation Library.
Page 21
1
Chapter 1. General Information
Table of Contents
1.1. About This Manual ................................................................................................................. 2
1.2. Typographical and Syntax Conventions ................................................................................... 3
1.3. Overview of the MySQL Database Management System .......................................................... 4
1.3.1. What is MySQL? ......................................................................................................... 4
1.3.2. The Main Features of MySQL ...................................................................................... 6
1.3.3. History of MySQL ........................................................................................................ 8
1.4. What Is New in MySQL 5.0 .................................................................................................... 9
1.5. MySQL Development History ................................................................................................ 11
1.6. MySQL Information Sources ................................................................................................. 11
1.6.1. MySQL Mailing Lists .................................................................................................. 11
1.6.2. MySQL Community Support at the MySQL Forums ..................................................... 14
1.6.3. MySQL Community Support on Internet Relay Chat (IRC) ........................................... 14
1.6.4. MySQL Enterprise ..................................................................................................... 14
1.7. How to Report Bugs or Problems ......................................................................................... 14
1.8. MySQL Standards Compliance ............................................................................................. 19
1.8.1. What Standards MySQL Follows ................................................................................ 19
1.8.2. Selecting SQL Modes ................................................................................................ 19
1.8.3. Running MySQL in ANSI Mode .................................................................................. 20
1.8.4. MySQL Extensions to Standard SQL .......................................................................... 20
1.8.5. MySQL Differences from Standard SQL ..................................................................... 23
1.8.6. How MySQL Deals with Constraints ........................................................................... 28
1.9. Credits ................................................................................................................................. 32
1.9.1. Contributors to MySQL .............................................................................................. 32
1.9.2. Documenters and translators ..................................................................................... 36
1.9.3. Packages that support MySQL ................................................................................... 37
1.9.4. Tools that were used to create MySQL ....................................................................... 38
1.9.5. Supporters of MySQL ................................................................................................ 38
End of Product Lifecycle
Active development for MySQL Database Server version 5.0 has ended. Oracle offers various support offerings which may be of interest. For details and more information, see the MySQL section of the Lifetime Support Policy for Oracle Technology Products (http:// www.oracle.com/us/support/lifetime-support/index.html). Please consider upgrading to a recent version.
The MySQL™ 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 software. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. MySQL is a trademark of Oracle Corporation and/ or its affiliates, and shall not be used by Customer without Oracle's express written authorization. Other names may be trademarks of their respective owners.
The MySQL software is Dual Licensed. Users can choose to use the MySQL software as an Open Source product under the terms of the GNU General Public License (http://www.fsf.org/licenses/) or can purchase a standard commercial license from Oracle. See http://www.mysql.com/company/legal/ licensing/ for more information on our licensing policies.
The following list describes some sections of particular interest in this manual:
• For a discussion of MySQL Database Server capabilities, see Section 1.3.2, “The Main Features of
MySQL”.
Page 22
About This Manual
2
• For an overview of new MySQL features, see Section 1.4, “What Is New in MySQL 5.0”. For information about the changes in each version, see the Release Notes.
• For installation instructions, see Chapter 2, Installing and Upgrading MySQL. For information about upgrading MySQL, see Section 2.19.1, “Upgrading MySQL”.
• For a tutorial introduction to the MySQL Database Server, see Chapter 3, Tutorial.
• For information about configuring and administering MySQL Server, see Chapter 5, MySQL Server
Administration.
• For information about security in MySQL, see Chapter 6, Security.
• For information about setting up replication servers, see Chapter 16, Replication.
• For information about MySQL Enterprise, the commercial MySQL release with advanced features and management tools, see Chapter 22, MySQL Enterprise Edition.
• For answers to a number of questions that are often asked concerning the MySQL Database Server and its capabilities, see Appendix B, MySQL 5.0 Frequently Asked Questions.
• For a history of new features and bugfixes, see the Release Notes.
Important
To report problems or bugs, please use the instructions at Section 1.7, “How
to Report Bugs or Problems”. If you find a sensitive security bug in MySQL
Server, please let us know immediately by sending an email message to
<secalert_us@oracle.com>. Exception: Support customers should report
all problems, including security bugs, to Oracle Support.
1.1. About This Manual
This is the Reference Manual for the MySQL Database System, version 5.0, through release 5.0.96. Differences between minor versions of MySQL 5.0 are noted in the present text with reference to release numbers (5.0.x). For license information, see the Legal Notices. This product may contain third-party code. For license information on third-party code, see Appendix A, Licenses for Third-Party
Components.
This manual is not intended for use with older versions of the MySQL software due to the many functional and other differences between MySQL 5.0 and previous versions. If you are using an earlier release of the MySQL software, please refer to the appropriate manual. For example, MySQL 3.23, 4.0,
4.1 Reference Manual covers the 4.1 series of MySQL software releases.
If you are using MySQL 5.1, please refer to the MySQL 5.1 Reference Manual. Because this manual serves as a reference, it does not provide general instruction on SQL or relational
database concepts. It also does not teach you how to use your operating system or command-line interpreter.
The MySQL Database Software is under constant development, and the Reference Manual is updated frequently as well. The most recent version of the manual is available online in searchable form at
http://dev.mysql.com/doc/. Other formats also are available there, including HTML, PDF, and Windows
CHM versions. The Reference Manual source files are written in DocBook XML format. The HTML version and other
formats are produced automatically, primarily using the DocBook XSL stylesheets. For information about DocBook, see http://docbook.org/
If you have questions about using MySQL, you can ask them using our mailing lists or forums. See
Section 1.6.1, “MySQL Mailing Lists”, and Section 1.6.2, “MySQL Community Support at the MySQL
Page 23
Typographical and Syntax Conventions
3
Forums”. If you have suggestions concerning additions or corrections to the manual itself, please send
them to the http://www.mysql.com/company/contact/. This manual was originally written by David Axmark and Michael “Monty” Widenius. It is maintained by
the MySQL Documentation Team, consisting of Paul DuBois, Stefan Hinz, Philip Olson, John Russell, and Jon Stephens.
1.2. Typographical and Syntax Conventions
This manual uses certain typographical conventions:
Text in this style is used for SQL statements; database, table, and column names; program listings and source code; and environment variables. Example: “To reload the grant tables, use the
FLUSH PRIVILEGES statement.”
Text in this style indicates input that you type in examples.
Text in this style indicates the names of executable programs and scripts, examples being
mysql (the MySQL command-line client program) and mysqld (the MySQL server executable).
Text in this style is used for variable input for which you should substitute a value of your own choosing.
Text in this style is used for emphasis.
Text in this style is used in table headings and to convey especially strong emphasis.
Text in this style is used to indicate a program option that affects how the program is executed, or that supplies information that is needed for the program to function in a certain way. Example: “The --host option (short form -h) tells the mysql client program the hostname or IP address of the MySQL server that it should connect to”.
• File names and directory names are written like this: “The global my.cnf file is located in the /etc directory.”
• Character sequences are written like this: “To specify a wildcard, use the ‘%’ character.”
When commands are shown that are meant to be executed from within a particular program, the prompt shown preceding the command indicates which command to use. For example, shell> indicates a command that you execute from your login shell, root-shell> is similar but should be executed as root, and mysql> indicates a statement that you execute from the mysql client program:
shell> type a shell command here root-shell> type a shell command as root here mysql> type a mysql statement here
In some areas different systems may be distinguished from each other to show that commands should be executed in two different environments. For example, while working with replication the commands might be prefixed with master and slave:
master> type a mysql command on the replication master here slave> type a mysql command on the replication slave here
The “shell” is your command interpreter. On Unix, this is typically a program such as sh, csh, or bash. On Windows, the equivalent program is command.com or cmd.exe, typically run in a console window.
When you enter a command or statement shown in an example, do not type the prompt shown in the example.
Database, table, and column names must often be substituted into statements. To indicate that such substitution is necessary, this manual uses db_name, tbl_name, and col_name. For example, you might see a statement like this:
mysql> SELECT col_name FROM db_name.tbl_name;
Page 24
Overview of the MySQL Database Management System
4
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 any lettercase. This manual uses uppercase.
In syntax descriptions, square brackets (“[” and “]”) indicate optional words or clauses. For example, in the following statement, IF EXISTS is optional:
DROP TABLE [IF EXISTS] tbl_name
When a syntax element consists of a number of alternatives, the alternatives are separated by vertical bars (“|”). When one member from a set of choices may be chosen, the alternatives are listed within square brackets (“[” and “]”):
TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
When one member from a set of choices must be chosen, the alternatives are listed within braces (“{” and “}”):
{DESCRIBE | DESC} tbl_name [col_name | wild]
An ellipsis (...) indicates the omission of a section of a statement, typically to provide a shorter version of more complex syntax. For example, SELECT ... INTO OUTFILE is shorthand for the form of SELECT statement that has an INTO OUTFILE clause following other parts of the statement.
An ellipsis can also indicate that the preceding syntax element of a statement may be repeated. In the following example, multiple reset_option values may be given, with each of those after the first preceded by commas:
RESET reset_option [,reset_option] ...
Commands for setting shell variables are shown using Bourne shell syntax. For example, the sequence to set the CC environment variable and run the configure command looks like this in Bourne shell syntax:
shell> CC=gcc ./configure
If you are using csh or tcsh, you must issue commands somewhat differently:
shell> setenv CC gcc shell> ./configure
1.3. Overview of the MySQL Database Management System
1.3.1. What is MySQL?
MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by Oracle Corporation.
The MySQL Web site (http://www.mysql.com/) provides the latest information about MySQL software.
MySQL is a database management system. A database is a structured collection of data. It may be anything from a simple shopping list to
a picture gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server. Since computers are very good at handling large amounts of data, database management systems play a central role in computing, as standalone utilities, or as parts of other applications.
MySQL databases are relational.
Page 25
What is MySQL?
5
A relational database stores data in separate tables rather than putting all the data in one big storeroom. The database structures are organized into physical files optimized for speed. The logical model, with objects such as databases, tables, views, rows, and columns, offers a flexible programming environment. You set up rules governing the relationships between different data fields, such as one-to-one, one-to-many, unique, required or optional, and “pointers” between different tables. The database enforces these rules, so that with a well-designed database, your application never sees inconsistent, duplicate, orphan, out-of-date, or missing data.
The SQL part of “MySQL” stands for “Structured Query Language”. SQL is the most common standardized language used to access databases. Depending on your programming environment, you might enter SQL directly (for example, to generate reports), embed SQL statements into code written in another language, or use a language-specific API that hides the SQL syntax.
SQL is defined by the ANSI/ISO SQL Standard. The SQL standard has been evolving since 1986 and several versions exist. In this manual, “SQL-92” refers to the standard released in 1992, “SQL:1999” refers to the standard released in 1999, and “SQL:2003” refers to the current version of the standard. We use the phrase “the SQL standard” to mean the current version of the SQL Standard at any time.
MySQL software is Open Source. Open Source means that it is possible for anyone to use and modify the software. Anybody can
download the MySQL software from the Internet and use it without paying anything. If you wish, you may study the source code and change it to suit your needs. The MySQL software uses the GPL (GNU General Public License), http://www.fsf.org/licenses/, to define what you may and may not do with the software in different situations. If you feel uncomfortable with the GPL or need to embed MySQL code into a commercial application, you can buy a commercially licensed version from us. See the MySQL Licensing Overview for more information (http://www.mysql.com/company/legal/ licensing/).
The MySQL Database Server is very fast, reliable, scalable, and easy to use. If that is what you are looking for, you should give it a try. MySQL Server can run comfortably on a
desktop or laptop, alongside your other applications, web servers, and so on, requiring little or no attention. If you dedicate an entire machine to MySQL, you can adjust the settings to take advantage of all the memory, CPU power, and I/O capacity available. MySQL can also scale up to clusters of machines, networked together.
You can find a performance comparison of MySQL Server with other database managers on our benchmark page. See Section 8.1.3, “The MySQL Benchmark Suite”.
MySQL Server was originally developed to handle large databases much faster than existing solutions and has been successfully used in highly demanding production environments for several years. Although under constant development, MySQL Server today offers a rich and useful set of functions. Its connectivity, speed, and security make MySQL Server highly suited for accessing databases on the Internet.
MySQL Server works in client/server or embedded systems. The MySQL Database Software is a client/server system that consists of a multi-threaded SQL
server that supports different backends, several different client programs and libraries, administrative tools, and a wide range of application programming interfaces (APIs).
We also provide MySQL Server as an embedded multi-threaded library that you can link into your application to get a smaller, faster, easier-to-manage standalone product.
A large amount of contributed MySQL software is available. MySQL Server has a practical set of features developed in close cooperation with our users. It is
very likely that your favorite application or language supports the MySQL Database Server.
Page 26
The Main Features of MySQL
6
The official way to pronounce “MySQL” is “My Ess Que Ell” (not “my sequel”), but we do not mind if you pronounce it as “my sequel” or in some other localized way.
1.3.2. The Main Features of MySQL
This section describes some of the important characteristics of the MySQL Database Software. See also Section 1.5, “MySQL Development History”. In most respects, the roadmap applies to all versions of MySQL. For information about features as they are introduced into MySQL on a series-specific basis, see the “In a Nutshell” section of the appropriate Manual:
• MySQL 5.6: MySQL 5.6 in a Nutshell
• MySQL 5.5: MySQL 5.5 in a Nutshell
• MySQL 5.1: MySQL 5.1 in a Nutshell
• MySQL 5.0: MySQL 5.0 in a Nutshell
Internals and Portability:
• Written in C and C++.
• Tested with a broad range of different compilers.
• Works on many different platforms. See Section 2.4.2, “Operating Systems Supported by MySQL
Community Server”.
• For portability, uses CMake in MySQL 5.5 and up. Previous series use GNU Automake, Autoconf, and Libtool.
• Tested with Purify (a commercial memory leakage detector) as well as with Valgrind, a GPL tool (http://developer.kde.org/~sewardj/).
• Uses multi-layered server design with independent modules.
• Designed to be fully multi-threaded using kernel threads, to easily use multiple CPUs if they are available.
• Provides transactional and nontransactional storage engines.
• Uses very fast B-tree disk tables (MyISAM) with index compression.
• Designed to make it relatively easy to add other storage engines. This is useful if you want to provide an SQL interface for an in-house database.
• Uses a very fast thread-based memory allocation system.
• Executes very fast joins using an optimized nested-loop join.
• Implements in-memory hash tables, which are used as temporary tables.
• Implements SQL functions using a highly optimized class library that should be as fast as possible. Usually there is no memory allocation at all after query initialization.
• Provides the server as a separate program for use in a client/server networked environment, and as a library that can be embedded (linked) into standalone applications. Such applications can be used in isolation or in environments where no network is available.
Data Types:
• Many data types: signed/unsigned integers 1, 2, 3, 4, and 8 bytes long, FLOAT, DOUBLE, CHAR,
VARCHAR, BINARY, VARBINARY, TEXT, BLOB, DATE, TIME, DATETIME, TIMESTAMP, YEAR, SET, ENUM, and OpenGIS spatial types. See Chapter 11, Data Types.
• Fixed-length and variable-length string types.
Page 27
The Main Features of MySQL
7
Statements and Functions:
• Full operator and function support in the SELECT list and WHERE clause of queries. For example:
mysql> SELECT CONCAT(first_name, ' ', last_name)
-> FROM citizen
-> WHERE income/dependents > 10000 AND age > 30;
• Full support for SQL GROUP BY and ORDER BY clauses. Support for group functions (COUNT() [970], AVG() [969], STD() [971], SUM() [972], MAX() [971], MIN() [971], and
GROUP_CONCAT() [970]).
• Support for LEFT OUTER JOIN and RIGHT OUTER JOIN with both standard SQL and ODBC syntax.
• Support for aliases on tables and columns as required by standard SQL.
• Support for DELETE, INSERT, REPLACE, and UPDATE to return the number of rows that were changed (affected), or to return the number of rows matched instead by setting a flag when connecting to the server.
• Support for MySQL-specific SHOW statements that retrieve information about databases, storage engines, tables, and indexes. MySQL 5.0 adds support for the INFORMATION_SCHEMA database, implemented according to standard SQL.
• An EXPLAIN statement to show how the optimizer resolves a query.
• Independence of function names from table or column names. For example, ABS is a valid column name. The only restriction is that for a function call, no spaces are permitted between the function name and the “(” that follows it. See Section 9.3, “Reserved Words”.
• You can refer to tables from different databases in the same statement.
Security:
• A privilege and password system that is very flexible and secure, and that enables host-based verification.
• Password security by encryption of all password traffic when you connect to a server.
Scalability and Limits:
• Support for large databases. We use MySQL Server with databases that contain 50 million records. We also know of users who use MySQL Server with 200,000 tables and about 5,000,000,000 rows.
• Support for up to 64 indexes per table (32 before MySQL 4.1.2). Each index may consist of 1 to 16 columns or parts of columns. The maximum index width is 767 bytes for InnoDB tables, or 1000 for
MyISAM; before MySQL 4.1.2, the limit is 500 bytes. An index may use a prefix of a column for CHAR, VARCHAR, BLOB, or TEXT column types.
Connectivity:
• Clients can connect to MySQL Server using several protocols:
• Clients can connect using TCP/IP sockets on any platform.
• On Windows systems in the NT family (NT, 2000, XP, 2003, or Vista), clients can connect using
named pipes if the server is started with the --enable-named-pipe [407] option. In MySQL
4.1 and higher, Windows servers also support shared-memory connections if started with the --
shared-memory [420] option. Clients can connect through shared memory by using the -­protocol=memory option.
• On Unix systems, clients can connect using Unix domain socket files.
Page 28
History of MySQL
8
• MySQL client programs can be written in many languages. A client library written in C is available for clients written in C or C++, or for any language that provides C bindings.
• APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and Tcl are available, enabling MySQL clients to be written in many languages. See Chapter 20, Connectors and APIs.
• The Connector/ODBC (MyODBC) interface provides MySQL support for client programs that use ODBC (Open Database Connectivity) connections. For example, you can use MS Access to connect to your MySQL server. Clients can be run on Windows or Unix. Connector/ODBC source is available. All ODBC 2.5 functions are supported, as are many others. See Section 20.1, “MySQL Connector/
ODBC”.
• The Connector/J interface provides MySQL support for Java client programs that use JDBC connections. Clients can be run on Windows or Unix. Connector/J source is available. See
Section 20.3, “MySQL Connector/J”.
• MySQL Connector/Net enables developers to easily create .NET applications that require secure, high-performance data connectivity with MySQL. It implements the required ADO.NET interfaces and integrates into ADO.NET aware tools. Developers can build applications using their choice of .NET languages. MySQL Connector/Net is a fully managed ADO.NET driver written in 100% pure C#. See
Section 20.2, “MySQL Connector/Net”.
Localization:
• The server can provide error messages to clients in many languages. See Section 10.2, “Setting the
Error Message Language”.
• Full support for several different character sets, including latin1 (cp1252), german, big5, ujis, and more. For example, the Scandinavian characters “å”, “ä” and “ö” are permitted in table and column names. Unicode support is available as of MySQL 4.1.
• All data is saved in the chosen character set.
• Sorting and comparisons are done according to the chosen character set and collation (using
latin1 and Swedish collation by default). It is possible to change this when the MySQL server is
started. To see an example of very advanced sorting, look at the Czech sorting code. MySQL Server supports many different character sets that can be specified at compile time and runtime.
• As of MySQL 4.1, the server time zone can be changed dynamically, and individual clients can specify their own time zone. Section 10.6, “MySQL Server Time Zone Support”.
Clients and Tools:
• MySQL includes several client and utility programs. These include both command-line programs such as mysqldump and mysqladmin, and graphical programs such as MySQL Workbench.
• MySQL Server has built-in support for SQL statements to check, optimize, and repair tables. These statements are available from the command line through the mysqlcheck client. MySQL also includes myisamchk, a very fast command-line utility for performing these operations on MyISAM tables. See Chapter 4, MySQL Programs.
• MySQL programs can be invoked with the --help or -? option to obtain online assistance.
1.3.3. History of MySQL
We started out with the intention of using the mSQL database system to connect to our tables using our own fast low-level (ISAM) routines. However, after some testing, we came to the conclusion that
mSQL was not fast enough or flexible enough for our needs. This resulted in a new SQL interface to our
database but with almost the same API interface as mSQL. This API was designed to enable third-party code that was written for use with mSQL to be ported easily for use with MySQL.
MySQL is named after co-founder Monty Widenius's daughter, My.
Page 29
What Is New in MySQL 5.0
9
The name of the MySQL Dolphin (our logo) is “Sakila,” which was chosen 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 feminine 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.4. What Is New in MySQL 5.0
The following features are implemented in MySQL 5.0:
Information Schema. The introduction of the INFORMATION_SCHEMA database in MySQL 5.0 provided a standards-compliant means for accessing the MySQL Server's metadata; that is, data about the databases (schemas) on the server and the objects which they contain. See Chapter 19,
INFORMATION_SCHEMA Tables.
Instance Manager. Can be used to start and stop the MySQL Server, even from a remote host. See Section 4.6.10, “mysqlmanager — The MySQL Instance Manager”.
Precision Math. MySQL 5.0 introduced stricter criteria for acceptance or rejection of data, and implemented a new library for fixed-point arithmetic. These contributed to a much higher degree of accuracy for mathematical operations and greater control over invalid values. See Section 12.17,
“Precision Math”.
Storage Engines. New storage engines were added and performance of others was improved.
• New storage engines in MySQL 5.0 include ARCHIVE and FEDERATED. See Section 14.8, “The
ARCHIVE Storage Engine”, and Section 14.7, “The FEDERATED Storage Engine”.
• Performance Improvements in the InnoDB Storage Engine:
• New compact storage format which can save up to 20% of the disk space required in previous MySQL/InnoDB versions.
• Faster recovery from a failed or aborted ALTER TABLE.
• Faster implementation of TRUNCATE TABLE.
(See Section 14.2, “The InnoDB Storage Engine”.)
• Performance Improvements in the NDBCLUSTER Storage Engine:
• Faster handling of queries that use IN and BETWEEN.
• Condition pushdown: In cases involving the comparison of an unindexed column with a constant, this condition is “pushed down” to the cluster where it is evaluated in all partitions simultaneously, eliminating the need to send nonmatching records over the network. This can make such queries 10 to 100 times faster than in MySQL 4.1 Cluster.
See Section 13.8.2, “EXPLAIN Syntax”, for more information.
(See Chapter 17, MySQL Cluster.)
Stored Routines. MySQL 5.0 added support for stored procedures and stored functions. See
Section 18.2, “Using Stored Routines (Procedures and Functions)”.
Triggers. MySQL 5.0 added limited support for triggers. See Section 18.3, “Using Triggers”.
Views. MySQL 5.0 added support for named, updatable views. See Section 18.4, “Using Views”.
Cursors. Elementary support for server-side cursors. For information about using cursors within stored routines, see Section 13.6.6, “Cursors”. For information about using cursors from within the C API, see Section 20.6.10.3, “mysql_stmt_attr_set().
Page 30
What Is New in MySQL 5.0
10
Strict Mode and Standard Error Handling. MySQL 5.0 added a strict mode where by it follows standard SQL in a number of ways in which it did not previously. Support for standard SQLSTATE error messages was also implemented. See Section 5.1.7, “Server SQL Modes”.
VARCHAR Data Type. The effective maximum length of a VARCHAR column was increased to 65,535 bytes, and stripping of trailing whitespace was eliminated. VARCHAR in MySQL 5.0 is more efficient than in previous versions, due to the elimination of the old (and nonstandard) removal of trailing spaces during retrieval. (The actual maximum length of a VARCHAR is determined by the maximum row size and the character set you use. The maximum effective column length is subject to a row size of 65,535 bytes, which is shared among all columns.) See Section 11.1.6, “String Types”.
BIT Data Type. A true BIT column type is available that can be used to store numbers in binary notation. This type is much more efficient for storage and retrieval of Boolean values than the workarounds required in MySQL in versions previous to 5.0. See Section 11.1.1, “Numeric Type
Overview”.
Optimizer enhancements. Several optimizer improvements were made to improve the speed of certain types of queries and in the handling of certain types. These include:
• MySQL 5.0 introduces a new “greedy” optimizer which can greatly reduce the time required to
arrive at a query execution plan. This is particularly noticeable where several tables are to be joined and no good join keys can otherwise be found. Without the greedy optimizer, the complexity of the search for an execution plan is calculated as N!, where N is the number of tables to be joined. The greedy optimizer reduces this to N!/(D-1)!, where D is the depth of the search. Although the greedy optimizer does not guarantee the best possible of all execution plans (this is currently being worked on), it can reduce the time spent arriving at an execution plan for a join involving a great many tables—30, 40, or more—by a factor of as much as 1,000. This should eliminate most if not all situations where users thought that the optimizer had hung when trying to perform joins across many tables.
• Use of the Index Merge method to obtain better optimization of AND [880] and OR [881]
relations over different keys. (Previously, these were optimized only where both relations in the
WHERE clause involved the same key.) This also applies to other one-to-one comparison operators
(>, <, and so on), including = and the IN operator. This means that MySQL can use multiple indexes in retrieving results for conditions such as WHERE key1 > 4 OR key2 < 7 and even combinations of conditions such as WHERE (key1 > 4 OR key2 < 7) AND (key3 >= 10
OR key4 = 1). See Section 8.3.1.4, “Index Merge Optimization”.
• A new equality detector finds and optimizes “hidden” equalities in joins. For example, a WHERE
clause such as
t1.c1=t2.c2 AND t2.c2=t3.c3 AND t1.c1 < 5
implies these other conditions
t1.c1=t3.c3 AND t2.c2 < 5 AND t3.c3 < 5
These optimizations can be applied with any combination of AND [880] and OR [881] operators. See Section 8.3.1.9, “Nested Join Optimization”, and Section 8.3.1.10, “Outer Join Simplification”.
• Optimization of NOT IN and NOT BETWEEN relations, reducing or eliminating table scans for
queries making use of them by mean of range analysis. The performance of MySQL with regard to these relations now matches its performance with regard to IN and BETWEEN.
XA Transactions. MySQL 5.0 supports XA (distributed) transactions. See Section 13.3.7, “XA
Transactions”.
Page 31
MySQL Development History
11
1.5. MySQL Development History
This section describes the general MySQL development history, including major features implemented in or planned for various MySQL releases. The following sections provide information for each release series.
The current production release series is MySQL 5.1, which was declared stable for production use as of MySQL 5.1.30, released in November 2008. The previous production release series was MySQL
5.0, which was declared stable for production use as of MySQL 5.0.15, released in October 2005. “General Availability status” means that future 5.1 and 5.0 development is limited only to bugfixes. For the older MySQL 4.1, 4.0, and 3.23 series, only critical bugfixes are made.
Before upgrading from one release series to the next, please see the notes in Section 2.19.1,
“Upgrading MySQL”.
The most requested features and the versions in which they were implemented are summarized in the following table.
Feature MySQL Series
Unions 4.0 Subqueries 4.1 R-trees 4.1 (for the MyISAM storage engine) Stored procedures and functions 5.0 Views 5.0 Cursors 5.0 XA transactions 5.0 Triggers 5.0 and 5.1 Event scheduler 5.1 Partitioning 5.1 Pluggable storage engine API 5.1 Plugin API 5.1 InnoDB Plugin 5.1 Row-based replication 5.1 Server log tables 5.1
1.6. MySQL Information Sources
This section lists sources of additional information that you may find helpful, such as the MySQL mailing lists and user forums, and Internet Relay Chat.
1.6.1. MySQL Mailing Lists
This section introduces the MySQL mailing lists and provides guidelines as to how the lists should be used. When you subscribe to a mailing list, you receive all postings to the list as email messages. You can also send your own questions and answers to the list.
To subscribe to or unsubscribe from any of the mailing lists described in this section, visit http://
lists.mysql.com/. For most of them, you can select the regular version of the list where you get
individual messages, or a digest version where you get one large message per day. Please do not send messages about subscribing or unsubscribing to any of the mailing lists, because
such messages are distributed automatically to thousands of other users.
Page 32
MySQL Mailing Lists
12
Your local site may have many subscribers to a MySQL mailing list. If so, the site may have a local mailing list, so that messages sent from lists.mysql.com to your site are propagated to the local list. In such cases, please contact your system administrator to be added to or dropped from the local MySQL list.
To have traffic for a mailing list go to a separate mailbox in your mail program, set up a filter based on the message headers. You can use either the List-ID: or Delivered-To: headers to identify list messages.
The MySQL mailing lists are as follows:
announce The list for announcements of new versions of MySQL and related programs. This is a low-volume
list to which all MySQL users should subscribe.
mysql The main list for general MySQL discussion. Please note that some topics are better discussed on
the more-specialized lists. If you post to the wrong list, you may not get an answer.
bugs The list for people who want to stay informed about issues reported since the last release of MySQL
or who want to be actively involved in the process of bug hunting and fixing. See Section 1.7, “How
to Report Bugs or Problems”.
internals The list for people who work on the MySQL code. This is also the forum for discussions on MySQL
development and for posting patches.
mysqldoc The list for people who work on the MySQL documentation.
benchmarks The list for anyone interested in performance issues. Discussions concentrate on database
performance (not limited to MySQL), but also include broader categories such as performance of the kernel, file system, disk system, and so on.
packagers The list for discussions on packaging and distributing MySQL. This is the forum used by distribution
maintainers to exchange ideas on packaging MySQL and on ensuring that MySQL looks and feels as similar as possible on all supported platforms and operating systems.
java The list for discussions about the MySQL server and Java. It is mostly used to discuss JDBC drivers
such as MySQL Connector/J.
win32 The list for all topics concerning the MySQL software on Microsoft operating systems, such as
Windows 9x, Me, NT, 2000, XP, and 2003.
myodbc The list for all topics concerning connecting to the MySQL server with ODBC.
gui-tools
Page 33
MySQL Mailing Lists
13
The list for all topics concerning MySQL graphical user interface tools such as MySQL Workbench.
cluster The list for discussion of MySQL Cluster.
dotnet The list for discussion of the MySQL server and the .NET platform. It is mostly related to MySQL
Connector/Net.
plusplus The list for all topics concerning programming with the C++ API for MySQL.
perl The list for all topics concerning Perl support for MySQL with DBD::mysql.
If you're unable to get an answer to your questions from a MySQL mailing list or forum, one option is to purchase support from Oracle. This puts you in direct contact with MySQL developers.
The following MySQL mailing lists are in languages other than English. These lists are not operated by Oracle.
<mysql-france-subscribe@yahoogroups.com> A French mailing list.
<list@tinc.net> A Korean mailing list. To subscribe, email subscribe mysql your@email.address to this list.
<mysql-de-request@lists.4t2.com> A German mailing list. To subscribe, email subscribe mysql-de your@email.address to this
list. You can find information about this mailing list at http://www.4t2.com/mysql/.
<mysql-br-request@listas.linkway.com.br> A Portuguese mailing list. To subscribe, email subscribe mysql-br your@email.address to
this list.
<mysql-alta@elistas.net> A Spanish mailing list. To subscribe, email subscribe mysql your@email.address to this list.
1.6.1.1. Guidelines for Using the Mailing Lists
Please do not post mail messages from your browser with HTML mode turned on. Many users do not read mail with a browser.
When you answer a question sent to a mailing list, if you consider your answer to have broad interest, you may want to post it to the list instead of replying directly to the individual who asked. Try to make your answer general enough that people other than the original poster may benefit from it. When you post to the list, please make sure that your answer is not a duplication of a previous answer.
Try to summarize the essential part of the question in your reply. Do not feel obliged to quote the entire original message.
When answers are sent to you individually and not to the mailing list, it is considered good etiquette to summarize the answers and send the summary to the mailing list so that others may have the benefit of responses you received that helped you solve your problem.
Page 34
MySQL Community Support at the MySQL Forums
14
1.6.2. MySQL Community Support at the MySQL Forums
The forums at http://forums.mysql.com are an important community resource. Many forums are available, grouped into these general categories:
• Migration
• MySQL Usage
• MySQL Connectors
• Programming Languages
• Tools
• 3rd-Party Applications
• Storage Engines
• MySQL Technology
• SQL Standards
• Business
1.6.3. MySQL Community Support on Internet Relay Chat (IRC)
In addition to the various MySQL mailing lists and forums, you can find experienced community people on Internet Relay Chat (IRC). These are the best networks/channels currently known to us:
freenode (see http://www.freenode.net/ for servers)
#mysql is primarily for MySQL questions, but other database and general SQL questions are welcome. Questions about PHP, Perl, or C in combination with MySQL are also common.
If you are looking for IRC client software to connect to an IRC network, take a look at xChat (http://
www.xchat.org/). X-Chat (GPL licensed) is available for Unix as well as for Windows platforms (a free
Windows build of X-Chat is available at http://www.silverex.org/download/).
1.6.4. MySQL Enterprise
Oracle offers technical support in the form of MySQL Enterprise. For organizations that rely on the MySQL DBMS for business-critical production applications, MySQL Enterprise is a commercial subscription offering which includes:
• MySQL Enterprise Server
• MySQL Enterprise Monitor
• Monthly Rapid Updates and Quarterly Service Packs
• MySQL Knowledge Base
• 24x7 Technical and Consultative Support
MySQL Enterprise is available in multiple tiers, giving you the flexibility to choose the level of service that best matches your needs. For more information, see MySQL Enterprise.
1.7. How to Report Bugs or Problems
Before posting a bug report about a problem, please try to verify that it is a bug and that it has not been reported already:
Page 35
How to Report Bugs or Problems
15
• Start by searching the MySQL online manual at http://dev.mysql.com/doc/. We try to keep the manual up to date by updating it frequently with solutions to newly found problems. In addition, the release notes accompanying the manual can be particularly useful since it is quite possible that a newer version contains a solution to your problem. The release notes are available at the location just given for the manual.
• If you get a parse error for an SQL statement, please check your syntax closely. If you cannot find something wrong with it, it is extremely likely that your current version of MySQL Server doesn't support the syntax you are using. If you are using the current version and the manual doesn't cover the syntax that you are using, MySQL Server doesn't support your statement.
If the manual covers the syntax you are using, but you have an older version of MySQL Server, you should check the MySQL change history to see when the syntax was implemented. In this case, you have the option of upgrading to a newer version of MySQL Server.
• For solutions to some common problems, see Section C.5, “Problems and Common Errors”.
• Search the bugs database at http://bugs.mysql.com/ to see whether the bug has been reported and fixed.
• Search the MySQL mailing list archives at http://lists.mysql.com/. See Section 1.6.1, “MySQL Mailing
Lists”.
• You can also use http://www.mysql.com/search/ to search all the Web pages (including the manual) that are located at the MySQL Web site.
If you cannot find an answer in the manual, the bugs database, or the mailing list archives, check with your local MySQL expert. If you still cannot find an answer to your question, please use the following guidelines for reporting the bug.
The normal way to report bugs is to visit http://bugs.mysql.com/, which is the address for our bugs database. This database is public and can be browsed and searched by anyone. If you log in to the system, you can enter new reports.
Bugs posted in the bugs database at http://bugs.mysql.com/ that are corrected for a given release are noted in the release notes.
If you find a sensitive security bug in MySQL Server, please let us know immediately by sending an email message to <secalert_us@oracle.com>. Exception: Support customers should report all problems, including security bugs, to Oracle Support at http://support.oracle.com/.
To discuss problems with other users, you can use one of the MySQL mailing lists. Section 1.6.1,
“MySQL Mailing Lists”.
Writing a good bug report takes patience, but doing it right the first time saves time both for us and for yourself. A good bug report, containing a full test case for the bug, makes it very likely that we will fix the bug in the next release. This section helps you write your report correctly so that you do not waste your time doing things that may not help us much or at all. Please read this section carefully and make sure that all the information described here is included in your report.
Preferably, you should test the problem using the latest production or development version of MySQL Server before posting. Anyone should be able to repeat the bug by just using mysql test <
script_file on your test case or by running the shell or Perl script that you include in the bug report.
Any bug that we are able to repeat has a high chance of being fixed in the next MySQL release. It is most helpful when a good description of the problem is included in the bug report. That is, give a
good example of everything you did that led to the problem and describe, in exact detail, the problem itself. The best reports are those that include a full example showing how to reproduce the bug or problem. See MySQL Internals: Porting to Other Systems.
Remember that it is possible for us to respond to a report containing too much information, but not to one containing too little. People often omit facts because they think they know the cause of a problem
Page 36
How to Report Bugs or Problems
16
and assume that some details do not matter. A good principle to follow is that if you are in doubt about stating something, state it. It is faster and less troublesome to write a couple more lines in your report than to wait longer for the answer if we must ask you to provide information that was missing from the initial report.
The most common errors made in bug reports are (a) not including the version number of the MySQL distribution that you use, and (b) not fully describing the platform on which the MySQL server is installed (including the platform type and version number). These are highly relevant pieces of information, and in 99 cases out of 100, the bug report is useless without them. Very often we get questions like, “Why doesn't this work for me?” Then we find that the feature requested wasn't implemented in that MySQL version, or that a bug described in a report has been fixed in newer MySQL versions. Errors often are platform-dependent. In such cases, it is next to impossible for us to fix anything without knowing the operating system and the version number of the platform.
If you compiled MySQL from source, remember also to provide information about your compiler if it is related to the problem. Often people find bugs in compilers and think the problem is MySQL­related. Most compilers are under development all the time and become better version by version. To determine whether your problem depends on your compiler, we need to know what compiler you used. Note that every compiling problem should be regarded as a bug and reported accordingly.
If a program produces an error message, it is very important to include the message in your report. If we try to search for something from the archives, it is better that the error message reported exactly matches the one that the program produces. (Even the lettercase should be observed.) It is best to copy and paste the entire error message into your report. You should never try to reproduce the message from memory.
If you have a problem with Connector/ODBC (MyODBC), please try to generate a trace file and send it with your report. See Section 20.1.8.2, “How to Report Connector/ODBC Problems or Bugs”.
If your report includes long query output lines from test cases that you run with the mysql command­line tool, you can make the output more readable by using the --vertical [270] option or the \G statement terminator. The EXPLAIN SELECT example later in this section demonstrates the use of \G.
Please include the following information in your report:
• The version number of the MySQL distribution you are using (for example, MySQL 5.0.19). You can find out which version you are running by executing mysqladmin version. The mysqladmin program can be found in the bin directory under your MySQL installation directory.
• The manufacturer and model of the machine on which you experience the problem.
• The operating system name and version. If you work with Windows, you can usually get the name and version number by double-clicking your My Computer icon and pulling down the “Help/About Windows” menu. For most Unix-like operating systems, you can get this information by executing the command uname -a.
• Sometimes the amount of memory (real and virtual) is relevant. If in doubt, include these values.
• If you are using a source distribution of the MySQL software, include the name and version number of the compiler that you used. If you have a binary distribution, include the distribution name.
• If the problem occurs during compilation, include the exact error messages and also a few lines of context around the offending code in the file where the error occurs.
• If mysqld died, you should also report the statement that crashed mysqld. You can usually get this information by running mysqld with query logging enabled, and then looking in the log after mysqld crashes. See MySQL Internals: Porting to Other Systems.
• If a database table is related to the problem, include the output from the SHOW CREATE TABLE
db_name.tbl_name statement in the bug report. This is a very easy way to get the definition of
Page 37
How to Report Bugs or Problems
17
any table in a database. The information helps us create a situation matching the one that you have experienced.
• The SQL mode in effect when the problem occurred can be significant, so please report the value of the sql_mode [495] system variable. For stored procedure, stored function, and trigger objects, the relevant sql_mode [495] value is the one in effect when the object was created. For a stored procedure or function, the SHOW CREATE PROCEDURE or SHOW CREATE FUNCTION statement shows the relevant SQL mode, or you can query INFORMATION_SCHEMA for the information:
SELECT ROUTINE_SCHEMA, ROUTINE_NAME, SQL_MODE FROM INFORMATION_SCHEMA.ROUTINES;
For triggers, you can use this statement:
SELECT EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE, TRIGGER_NAME, SQL_MODE FROM INFORMATION_SCHEMA.TRIGGERS;
• For performance-related bugs or problems with SELECT statements, you should always include the output of EXPLAIN SELECT ..., and at least the number of rows that the SELECT statement produces. You should also include the output from SHOW CREATE TABLE tbl_name for each table that is involved. The more information you provide about your situation, the more likely it is that someone can help you.
The following is an example of a very good bug report. The statements are run using the mysql command-line tool. Note the use of the \G statement terminator for statements that would otherwise provide very long output lines that are difficult to read.
mysql> SHOW VARIABLES; mysql> SHOW COLUMNS FROM ...\G <output from SHOW COLUMNS> mysql> EXPLAIN SELECT ...\G <output from EXPLAIN> mysql> FLUSH STATUS; mysql> SELECT ...; <A short version of the output from SELECT,
including the time taken to run the query>
mysql> SHOW STATUS; <output from SHOW STATUS>
• If a bug or problem occurs while running mysqld, try to provide an input script that reproduces the anomaly. This script should include any necessary source files. The more closely the script can reproduce your situation, the better. If you can make a reproducible test case, you should upload it to be attached to the bug report.
If you cannot provide a script, you should at least include the output from mysqladmin variables
extended-status processlist in your report to provide some information on how your system
is performing.
• If you cannot produce a test case with only a few rows, or if the test table is too big to be included in the bug report (more than 10 rows), you should dump your tables using mysqldump and create a
README file that describes your problem. Create a compressed archive of your files using tar and gzip or zip. After you initiate a bug report for our bugs database at http://bugs.mysql.com/, click the
Files tab in the bug report for instructions on uploading the archive to the bugs database.
• If you believe that the MySQL server produces a strange result from a statement, include not only the result, but also your opinion of what the result should be, and an explanation describing the basis for your opinion.
• When you provide an example of the problem, it is better to use the table names, variable names, and so forth that exist in your actual situation than to come up with new names. The problem could be related to the name of a table or variable. These cases are rare, perhaps, but it is better to be safe than sorry. After all, it should be easier for you to provide an example that uses your actual situation, and it is by all means better for us. If you have data that you do not want to be visible to others in the bug report, you can upload it using the Files tab as previously described. If the
Page 38
How to Report Bugs or Problems
18
information is really top secret and you do not want to show it even to us, go ahead and provide an example using other names, but please regard this as the last choice.
• Include all the options given to the relevant programs, if possible. For example, indicate the options that you use when you start the mysqld server, as well as the options that you use to run any MySQL client programs. The options to programs such as mysqld and mysql, and to the
configure script, are often key to resolving problems and are very relevant. It is never a bad idea
to include them. If your problem involves a program written in a language such as Perl or PHP, please include the language processor's version number, as well as the version for any modules that the program uses. For example, if you have a Perl script that uses the DBI and DBD::mysql modules, include the version numbers for Perl, DBI, and DBD::mysql.
• If your question is related to the privilege system, please include the output of mysqlaccess, the output of mysqladmin reload, and all the error messages you get when trying to connect. When you test your privileges, you should first run mysqlaccess. After this, execute mysqladmin
reload version and try to connect with the program that gives you trouble. mysqlaccess can be
found in the bin directory under your MySQL installation directory.
• If you have a patch for a bug, do include it. But do not assume that the patch is all we need, or that we can use it, if you do not provide some necessary information such as test cases showing the bug that your patch fixes. We might find problems with your patch or we might not understand it at all. If so, we cannot use it.
If we cannot verify the exact purpose of the patch, we will not use it. Test cases help us here. Show that the patch handles all the situations that may occur. If we find a borderline case (even a rare one) where the patch will not work, it may be useless.
• Guesses about what the bug is, why it occurs, or what it depends on are usually wrong. Even the MySQL team cannot guess such things without first using a debugger to determine the real cause of a bug.
• Indicate in your bug report that you have checked the reference manual and mail archive so that others know you have tried to solve the problem yourself.
• If your data appears corrupt or you get errors when you access a particular table, first check your tables with CHECK TABLE. If that statement reports any errors:
• The InnoDB crash recovery mechanism handles cleanup when the server is restarted after being
killed, so in typical operation there is no need to “repair” tables. If you encounter an error with
InnoDB tables, restart the server and see whether the problem persists, or whether the error
affected only cached data in memory. If data is corrupted on disk, consider restarting with the
innodb_force_recovery [1243] option enabled so that you can dump the affected tables.
• For non-transactional tables, try to repair them with REPAIR TABLE or with myisamchk. See
Chapter 5, MySQL Server Administration.
If you are running Windows, please verify the value of lower_case_table_names [466] using the SHOW VARIABLES LIKE 'lower_case_table_names' statement. This variable affects how the server handles lettercase of database and table names. Its effect for a given value should be as described in Section 9.2.2, “Identifier Case Sensitivity”.
• If you often get corrupted tables, you should try to find out when and why this happens. In this case, the error log in the MySQL data directory may contain some information about what happened. (This is the file with the .err suffix in the name.) See Section 5.2.1, “The Error Log”. Please include any relevant information from this file in your bug report. Normally mysqld should never crash a table if nothing killed it in the middle of an update. If you can find the cause of mysqld dying, it is much easier for us to provide you with a fix for the problem. See Section C.5.1, “How to Determine What Is
Causing a Problem”.
• If possible, download and install the most recent version of MySQL Server and check whether it solves your problem. All versions of the MySQL software thoroughly tested and should work without
Page 39
MySQL Standards Compliance
19
problems. We believe in making everything as backward-compatible as possible, and you should be able to switch MySQL versions without difficulty. See Section 2.4.3, “Choosing Which MySQL
Distribution to Install”.
1.8. MySQL Standards Compliance
This section describes how MySQL relates to the ANSI/ISO SQL standards. MySQL Server has many extensions to the SQL standard, and here you can find out what they are and how to use them. You can also find information about functionality missing from MySQL Server, and how to work around some of the differences.
The SQL standard has been evolving since 1986 and several versions exist. In this manual, “SQL-92” refers to the standard released in 1992, “SQL:1999” refers to the standard released in 1999, “SQL:2003” refers to the standard released in 2003, and “SQL:2008” refers to the most recent version of the standard, released in 2008. We use the phrase “the SQL standard” or “standard SQL” to mean the current version of the SQL Standard at any time.
One of our main goals with the product is to continue to work toward compliance with the SQL standard, but without sacrificing speed or reliability. We are not afraid to add extensions to SQL or support for non-SQL features if this greatly increases the usability of MySQL Server for a large segment of our user base. The HANDLER interface is an example of this strategy. See Section 13.2.4,
HANDLER Syntax”.
We continue to support transactional and nontransactional databases to satisfy both mission-critical 24/7 usage and heavy Web or logging usage.
MySQL Server was originally designed to work with medium-sized databases (10-100 million rows, or about 100MB per table) on small computer systems. Today MySQL Server handles terabyte­sized databases, but the code can also be compiled in a reduced version suitable for hand-held and embedded devices. The compact design of the MySQL server makes development in both directions possible without any conflicts in the source tree.
Currently, we are not targeting real-time support, although MySQL replication capabilities offer significant functionality.
MySQL supports high-availability database clustering using the NDBCLUSTER storage engine. See
Chapter 17, MySQL Cluster.
XML support is to be implemented in a future version of the database server.
1.8.1. What Standards MySQL Follows
Our aim is to support the full ANSI/ISO SQL standard, but without making concessions to speed and quality of the code.
ODBC levels 0 to 3.51.
1.8.2. Selecting SQL Modes
The MySQL server can operate in different SQL modes, and can apply these modes differentially for different clients. This capability enables each application to tailor the server's operating mode to its own requirements.
SQL modes control aspects of server operation such as what SQL syntax MySQL should support and what kind of data validation checks it should perform. This makes it easier to use MySQL in different environments and to use MySQL together with other database servers.
You can set the default SQL mode by starting mysqld with the --sql-mode="mode_value" [422] option. You can also change the mode at runtime by setting the sql_mode [495] system variable with a SET [GLOBAL|SESSION] sql_mode='mode_value' statement.
Page 40
Running MySQL in ANSI Mode
20
For more information on setting the SQL mode, see Section 5.1.7, “Server SQL Modes”.
1.8.3. Running MySQL in ANSI Mode
You can tell mysqld to run in ANSI mode with the --ansi [401] startup option. Running the server in ANSI mode is the same as starting it with the following options:
--transaction-isolation=SERIALIZABLE --sql-mode=ANSI
You can achieve the same effect at runtime by executing these two statements:
SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE; SET GLOBAL sql_mode = 'ANSI';
You can see that setting the sql_mode [495] system variable to 'ANSI' enables all SQL mode options that are relevant for ANSI mode as follows:
mysql> SET GLOBAL sql_mode='ANSI'; mysql> SELECT @@global.sql_mode;
-> 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI'
Running the server in ANSI mode with --ansi [401] is not quite the same as setting the SQL mode to 'ANSI'. The --ansi [401] option affects the SQL mode and also sets the transaction isolation level. Setting the SQL mode to 'ANSI' has no effect on the isolation level.
See Section 5.1.3, “Server Command Options”, and Section 1.8.2, “Selecting SQL Modes”.
1.8.4. MySQL Extensions to Standard SQL
MySQL Server supports some extensions that you probably won't find in other SQL DBMSs. Be warned that if you use them, your code won't be portable to other SQL servers. In some cases, you can write code that includes MySQL extensions, but is still portable, by using comments of the following form:
/*! MySQL-specific code */
In this case, MySQL Server parses and executes the code within the comment as it would any other SQL statement, but other SQL servers will ignore the extensions. For example, MySQL Server recognizes the STRAIGHT_JOIN keyword in the following statement, but other servers will not:
SELECT /*! STRAIGHT_JOIN */ col1 FROM table1,table2 WHERE ...
If you add a version number after the “!” character, the syntax within the comment is executed only if the MySQL version is greater than or equal to the specified version number. The TEMPORARY keyword in the following comment is executed only by servers from MySQL 3.23.02 or higher:
CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
The following descriptions list MySQL extensions, organized by category.
• Organization of data on disk MySQL Server maps each database to a directory under the MySQL data directory, and maps tables
within a database to file names in the database directory. This has a few implications:
• Database and table names are case sensitive in MySQL Server on operating systems that
have case-sensitive file names (such as most Unix systems). See Section 9.2.2, “Identifier Case
Sensitivity”.
• You can use standard system commands to back up, rename, move, delete, and copy tables that
are managed by the MyISAM storage engine. For example, it is possible to rename a MyISAM table
Page 41
MySQL Extensions to Standard SQL
21
by renaming the .MYD, .MYI, and .frm files to which the table corresponds. (Nevertheless, it is preferable to use RENAME TABLE or ALTER TABLE ... RENAME and let the server rename the files.)
Database and table names cannot contain path name separator characters (“/”, “\”).
• General language syntax
• By default, strings can be enclosed by either “"” or “'”, not just by “'”. (If the
ANSI_QUOTES [535] SQL mode is enabled, strings can be enclosed only by “'” and the server
interprets strings enclosed by “"” as identifiers.)
• “\” is the escape character in strings.
• In SQL statements, you can access tables from different databases with the db_name.tbl_name syntax. Some SQL servers provide the same functionality but call this User space. MySQL Server doesn't support tablespaces such as used in statements like this: CREATE TABLE
ralph.my_table ... IN my_tablespace.
• SQL statement syntax
• The ANALYZE TABLE, CHECK TABLE, OPTIMIZE TABLE, and REPAIR TABLE statements.
• The CREATE DATABASE, DROP DATABASE, and ALTER DATABASE statements. See
Section 13.1.6, “CREATE DATABASE Syntax”, Section 13.1.13, “DROP DATABASE Syntax”, and Section 13.1.1, “ALTER DATABASE Syntax”.
• The DO statement.
EXPLAIN SELECT to obtain a description of how tables are processed by the query optimizer.
• The FLUSH and RESET statements.
• The SET statement. See Section 13.7.4, “SET Syntax”.
• The SHOW statement. See Section 13.7.5, “SHOW Syntax”. The information produced by many of the MySQL-specific SHOW statements can be obtained in more standard fashion by using SELECT to query INFORMATION_SCHEMA. See Chapter 19, INFORMATION_SCHEMA Tables.
• Use of LOAD DATA INFILE. In many cases, this syntax is compatible with Oracle's LOAD DATA
INFILE. See Section 13.2.6, “LOAD DATA INFILE Syntax”.
• Use of RENAME TABLE. See Section 13.1.20, “RENAME TABLE Syntax”.
• Use of REPLACE instead of DELETE plus INSERT. See Section 13.2.7, “REPLACE Syntax”.
• Use of CHANGE col_name, DROP col_name, or DROP INDEX, IGNORE or RENAME in ALTER
TABLE statements. Use of multiple ADD, ALTER, DROP, or CHANGE clauses in an ALTER TABLE
statement. See Section 13.1.4, “ALTER TABLE Syntax”.
• Use of index names, indexes on a prefix of a column, and use of INDEX or KEY in CREATE TABLE statements. See Section 13.1.10, “CREATE TABLE Syntax”.
• Use of TEMPORARY or IF NOT EXISTS with CREATE TABLE.
• Use of IF EXISTS with DROP TABLE and DROP DATABASE.
• The capability of dropping multiple tables with a single DROP TABLE statement.
• The ORDER BY and LIMIT clauses of the UPDATE and DELETE statements.
INSERT INTO tbl_name SET col_name = ... syntax.
Page 42
MySQL Extensions to Standard SQL
22
• The DELAYED clause of the INSERT and REPLACE statements.
• The LOW_PRIORITY clause of the INSERT, REPLACE, DELETE, and UPDATE statements.
• Use of INTO OUTFILE or INTO DUMPFILE in SELECT statements. See Section 13.2.8, “SELECT
Syntax”.
• Options such as STRAIGHT_JOIN or SQL_SMALL_RESULT in SELECT statements.
• You don't need to name all selected columns in the GROUP BY clause. This gives better performance for some very specific, but quite normal queries. See Section 12.15, “Functions and
Modifiers for Use with GROUP BY Clauses”.
• You can specify ASC and DESC with GROUP BY, not just with ORDER BY.
• The ability to set variables in a statement with the := assignment operator. See Section 9.4, “User-
Defined Variables”.
• Data types
• The MEDIUMINT, SET, and ENUM data types, and the various BLOB and TEXT data types.
• The AUTO_INCREMENT, BINARY, NULL, UNSIGNED, and ZEROFILL data type attributes.
• Functions and operators
• To make it easier for users who migrate from other SQL environments, MySQL Server supports aliases for many functions. For example, all string functions support both standard SQL syntax and ODBC syntax.
• MySQL Server understands the || [881] and && [880] operators to mean logical OR and AND, as in the C programming language. In MySQL Server, || [881] and OR [881] are synonyms, as are && [880] and AND [880]. Because of this nice syntax, MySQL Server doesn't support the standard SQL || [881] operator for string concatenation; use CONCAT() [887] instead. Because CONCAT() [887] takes any number of arguments, it is easy to convert use of the
|| [881] operator to MySQL Server.
• Use of COUNT(DISTINCT value_list) [970] where value_list has more than one element.
• String comparisons are case-insensitive by default, with sort ordering determined by the collation of the current character set, which is latin1 (cp1252 West European) by default. If you don't like this, you should declare your columns with the BINARY attribute or use the BINARY cast, which causes comparisons to be done using the underlying character code values rather than a lexical ordering.
• The % [911] operator is a synonym for MOD() [911]. That is, N % M is equivalent to
MOD(N,M) [911]. % [911] is supported for C programmers and for compatibility with
PostgreSQL.
• The = [875], <> [876], <= [876], < [876], >= [876], > [876], << [951], >> [951],
<=> [876], AND [880], OR [881], or LIKE [896] operators may be used in expressions in the
output column list (to the left of the FROM) in SELECT statements. For example:
mysql> SELECT col1=1 AND col2=2 FROM my_table;
• The LAST_INSERT_ID() [961] function returns the most recent AUTO_INCREMENT value. See
Section 12.13, “Information Functions”.
LIKE [896] is permitted on numeric values.
Page 43
MySQL Differences from Standard SQL
23
• The REGEXP [899] and NOT REGEXP [899] extended regular expression operators.
CONCAT() [887] or CHAR() [886] with one argument or more than two arguments. (In MySQL Server, these functions can take a variable number of arguments.)
• The BIT_COUNT() [952], CASE [883], ELT() [888], FROM_DAYS() [923],
FORMAT() [889], IF() [883], PASSWORD() [956], ENCRYPT() [955], MD5() [955], ENCODE() [955], DECODE() [954], PERIOD_ADD() [926], PERIOD_DIFF() [926], TO_DAYS() [930], and WEEKDAY() [933] functions.
• Use of TRIM() [894] to trim substrings. Standard SQL supports removal of single characters only.
• The GROUP BY functions STD() [971], BIT_OR() [969], BIT_AND() [969],
BIT_XOR() [969], and GROUP_CONCAT() [970]. See Section 12.15, “Functions and Modifiers
for Use with GROUP BY Clauses”.
1.8.5. MySQL Differences from Standard SQL
We try to make MySQL Server follow the ANSI SQL standard and the ODBC SQL standard, but MySQL Server performs operations differently in some cases:
• For VARCHAR columns, trailing spaces are removed when the value is stored. (This is fixed in MySQL
5.0.3). See Section C.5.8, “Known Issues in MySQL”.
• In some cases, CHAR columns are silently converted to VARCHAR columns when you define a table or alter its structure. (This no longer occurs as of MySQL 5.0.3). See Section 13.1.10.3, “Silent
Column Specification Changes”.
• There are several differences between the MySQL and standard SQL privilege systems. For example, in MySQL, privileges for a table are not automatically revoked when you delete a table. You must explicitly issue a REVOKE statement to revoke privileges for a table. For more information, see Section 13.7.1.5, “REVOKE Syntax”.
• The CAST() [948] function does not support cast to REAL or BIGINT. See Section 12.10, “Cast
Functions and Operators”.
• Standard SQL requires that a HAVING clause in a SELECT statement be able to refer to columns in the GROUP BY clause. This cannot be done before MySQL 5.0.2.
1.8.5.1. SELECT INTO TABLE
MySQL Server doesn't support the SELECT ... INTO TABLE Sybase SQL extension. Instead, MySQL Server supports the INSERT INTO ... SELECT standard SQL syntax, which is basically the same thing. See Section 13.2.5.1, “INSERT ... SELECT Syntax”. For example:
INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
Alternatively, you can use SELECT ... INTO OUTFILE or CREATE TABLE ... SELECT. You can use SELECT ... INTO with user-defined variables. The same syntax can also be used
inside stored routines using cursors and local variables. See Section 13.2.8.1, “SELECT ... INTO
Syntax”.
1.8.5.2. UPDATE
If you access a column from the table to be updated in an expression, UPDATE uses the current value of the column. The second assignment in the following statement sets col2 to the current (updated)
col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This
behavior differs from standard SQL.
Page 44
MySQL Differences from Standard SQL
24
UPDATE t1 SET col1 = col1 + 1, col2 = col1;
1.8.5.3. Transactions and Atomic Operations
MySQL Server (version 3.23-max and all versions 4.0 and above) supports transactions with the
InnoDB and BDB transactional storage engines. InnoDB provides full ACID compliance. See
Chapter 14, Storage Engines. For information about InnoDB differences from standard SQL with
regard to treatment of transaction errors, see Section 14.2.11, “InnoDB Error Handling”. The other nontransactional storage engines in MySQL Server (such as MyISAM) follow a different
paradigm for data integrity called “atomic operations.” In transactional terms, MyISAM tables effectively always operate in autocommit = 1 [436] mode. Atomic operations often offer comparable integrity with higher performance.
Because MySQL Server supports both paradigms, you can decide whether your applications are best served by the speed of atomic operations or the use of transactional features. This choice can be made on a per-table basis.
As noted, the tradeoff for transactional versus nontransactional storage engines lies mostly in performance. Transactional tables have significantly higher memory and disk space requirements, and more CPU overhead. On the other hand, transactional storage engines such as InnoDB also offer many significant features. MySQL Server's modular design enables the concurrent use of different storage engines to suit different requirements and deliver optimum performance in all situations.
But how do you use the features of MySQL Server to maintain rigorous integrity even with the nontransactional MyISAM tables, and how do these features compare with the transactional storage engines?
• If your applications are written in a way that is dependent on being able to call ROLLBACK rather than COMMIT in critical situations, transactions are more convenient. Transactions also ensure that unfinished updates or corrupting activities are not committed to the database; the server is given the opportunity to do an automatic rollback and your database is saved.
If you use nontransactional tables, MySQL Server in almost all cases enables you to resolve potential problems by including simple checks before updates and by running simple scripts that check the databases for inconsistencies and automatically repair or warn if such an inconsistency occurs. You can normally fix tables perfectly with no data integrity loss just by using the MySQL log or even adding one extra log.
• More often than not, critical transactional updates can be rewritten to be atomic. Generally speaking, all integrity problems that transactions solve can be done with LOCK TABLES or atomic updates, ensuring that there are no automatic aborts from the server, which is a common problem with transactional database systems.
• To be safe with MySQL Server, regardless of whether you use transactional tables, you only need to have backups and have binary logging turned on. When that is true, you can recover from any situation that you could with any other transactional database system. It is always good to have backups, regardless of which database system you use.
The transactional paradigm has its advantages and disadvantages. Many users and application developers depend on the ease with which they can code around problems where an abort appears to be necessary, or is necessary. However, even if you are new to the atomic operations paradigm, or more familiar with transactions, do consider the speed benefit that nontransactional tables can offer on the order of three to five times the speed of the fastest and most optimally tuned transactional tables.
In situations where integrity is of highest importance, MySQL Server offers transaction-level reliability and integrity even for nontransactional tables. If you lock tables with LOCK TABLES, all updates stall until integrity checks are made. If you obtain a READ LOCAL lock (as opposed to a write lock) for a table that enables concurrent inserts at the end of the table, reads are permitted, as are inserts by other clients. The newly inserted records are not be seen by the client that has the read lock until
Page 45
MySQL Differences from Standard SQL
25
it releases the lock. With INSERT DELAYED, you can write inserts that go into a local queue until the locks are released, without having the client wait for the insert to complete. See Section 8.7.3,
“Concurrent Inserts”, and Section 13.2.5.2, “INSERT DELAYED Syntax”.
“Atomic,” in the sense that we mean it, is nothing magical. It only means that you can be sure that while each specific update is running, no other user can interfere with it, and there can never be an automatic rollback (which can happen with transactional tables if you are not very careful). MySQL Server also guarantees that there are no dirty reads.
Following are some techniques for working with nontransactional tables:
• Loops that need transactions normally can be coded with the help of LOCK TABLES, and you don't need cursors to update records on the fly.
• To avoid using ROLLBACK, you can employ the following strategy:
1. Use LOCK TABLES to lock all the tables you want to access.
2. Test the conditions that must be true before performing the update.
3. Update if the conditions are satisfied.
4. Use UNLOCK TABLES to release your locks. This is usually a much faster method than using transactions with possible rollbacks, although not
always. The only situation this solution doesn't handle is when someone kills the threads in the middle of an update. In that case, all locks are released but some of the updates may not have been executed.
• You can also use functions to update records in a single operation. You can get a very efficient application by using the following techniques:
• Modify columns relative to their current value.
• Update only those columns that actually have changed. For example, when we are updating customer information, we update only the customer data that
has changed and test only that none of the changed data, or data that depends on the changed data, has changed compared to the original row. The test for changed data is done with the WHERE clause in the UPDATE statement. If the record wasn't updated, we give the client a message: “Some of the data you have changed has been changed by another user.” Then we show the old row versus the new row in a window so that the user can decide which version of the customer record to use.
This gives us something that is similar to column locking but is actually even better because we only update some of the columns, using values that are relative to their current values. This means that typical UPDATE statements look something like these:
UPDATE tablename SET pay_back=pay_back+125;
UPDATE customer SET customer_date='current_date', address='new address', phone='new phone', money_owed_to_us=money_owed_to_us-125 WHERE customer_id=id AND address='old address' AND phone='old phone';
This is very efficient and works even if another client has changed the values in the pay_back or
money_owed_to_us columns.
• In many cases, users have wanted LOCK TABLES or ROLLBACK for the purpose of managing unique identifiers. This can be handled much more efficiently without locking or rolling back by
Page 46
MySQL Differences from Standard SQL
26
using an AUTO_INCREMENT column and either the LAST_INSERT_ID() [961] SQL function or the mysql_insert_id() C API function. See Section 12.13, “Information Functions”, and
Section 20.6.6.37, “mysql_insert_id().
You can generally code around the need for row-level locking. Some situations really do need it, and
InnoDB tables support row-level locking. Otherwise, with MyISAM tables, you can use a flag column
in the table and do something like the following:
UPDATE tbl_name SET row_flag=1 WHERE id=ID;
MySQL returns 1 for the number of affected rows if the row was found and row_flag wasn't 1 in the original row. You can think of this as though MySQL Server changed the preceding statement to:
UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;
1.8.5.4. Foreign Keys
The InnoDB storage engine supports checking of foreign key constraints, including CASCADE, ON
DELETE, and ON UPDATE. See Section 14.2.3.4, “InnoDB and FOREIGN KEY Constraints”.
For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE
TABLE statements, but does not use or store it. In the future, the implementation will be extended
to store this information in the table specification file so that it may be retrieved by mysqldump and ODBC. At a later stage, foreign key constraints will be implemented for MyISAM tables as well.
Foreign key enforcement offers several benefits to database developers:
• Assuming proper design of the relationships, foreign key constraints make it more difficult for a programmer to introduce an inconsistency into the database.
• Centralized checking of constraints by the database server makes it unnecessary to perform these checks on the application side. This eliminates the possibility that different applications may not all check the constraints in the same way.
• Using cascading updates and deletes can simplify the application code.
• Properly designed foreign key rules aid in documenting relationships between tables.
Do keep in mind that these benefits come at the cost of additional overhead for the database server to perform the necessary checks. Additional checking by the server affects performance, which for some applications may be sufficiently undesirable as to be avoided if possible. (Some major commercial applications have coded the foreign key logic at the application level for this reason.)
MySQL gives database developers the choice of which approach to use. If you don't need foreign keys and want to avoid the overhead associated with enforcing referential integrity, you can choose another storage engine instead, such as MyISAM. (For example, the MyISAM storage engine offers very fast performance for applications that perform only INSERT and SELECT operations. In this case, the table has no holes in the middle and the inserts can be performed concurrently with retrievals. See
Section 8.7.3, “Concurrent Inserts”.)
If you choose not to take advantage of referential integrity checks, keep the following considerations in mind:
• In the absence of server-side foreign key relationship checking, the application itself must handle relationship issues. For example, it must take care to insert rows into tables in the proper order, and to avoid creating orphaned child records. It must also be able to recover from errors that occur in the middle of multiple-record insert operations.
• If ON DELETE is the only referential integrity capability an application needs, you can achieve a similar effect as of MySQL Server 4.0 by using multiple-table DELETE statements to delete rows from many tables with a single statement. See Section 13.2.2, “DELETE Syntax”.
Page 47
MySQL Differences from Standard SQL
27
• A workaround for the lack of ON DELETE is to add the appropriate DELETE statements to your application when you delete records from a table that has a foreign key. In practice, this is often as quick as using foreign keys and is more portable.
Be aware that the use of foreign keys can sometimes lead to problems:
• Foreign key support addresses many referential integrity issues, but it is still necessary to design key relationships carefully to avoid circular rules or incorrect combinations of cascading deletes.
• It is not uncommon for a DBA to create a topology of relationships that makes it difficult to restore individual tables from a backup. (MySQL alleviates this difficulty by enabling you to temporarily disable foreign key checks when reloading a table that depends on other tables. See
Section 14.2.3.4, “InnoDB and FOREIGN KEY Constraints”. As of MySQL 4.1.1, mysqldump
generates dump files that take advantage of this capability automatically when they are reloaded.)
Foreign keys in SQL are used to check and enforce referential integrity, not to join tables. If you want to get results from multiple tables from a SELECT statement, you do this by performing a join between them:
SELECT * FROM t1 INNER JOIN t2 ON t1.id = t2.id;
See Section 13.2.8.2, “JOIN Syntax”, and Section 3.6.6, “Using Foreign Keys”. The FOREIGN KEY syntax without ON DELETE ... is often used by ODBC applications to produce
automatic WHERE clauses.
1.8.5.5. '--' as the Start of a Comment
Standard SQL uses the C syntax /* this is a comment */ for comments, and MySQL Server supports this syntax as well. MySQL also support extensions to this syntax that enable MySQL-specific SQL to be embedded in the comment, as described in Section 9.6, “Comment Syntax”.
Standard SQL uses “--” as a start-comment sequence. MySQL Server uses “#” as the start comment character. MySQL Server 3.23.3 and up also supports a variant of the “--” comment style. That is, the “--” start-comment sequence must be followed by a space (or by a control character such as a newline). The space is required to prevent problems with automatically generated SQL queries that use constructs such as the following, where we automatically insert the value of the payment for payment:
UPDATE account SET credit=credit-payment
Consider about what happens if payment has a negative value such as -1:
UPDATE account SET credit=credit--1
credit--1 is a legal expression in SQL, but “--” is interpreted as the start of a comment, part of
the expression is discarded. The result is a statement that has a completely different meaning than intended:
UPDATE account SET credit=credit
The statement produces no change in value at all. This illustrates that permitting comments to start with “--” can have serious consequences.
Using our implementation requires a space following the “--” for it to be recognized as a start-comment sequence in MySQL Server 3.23.3 and newer. Therefore, credit--1 is safe to use.
Another safe feature is that the mysql command-line client ignores lines that start with “--”. The following information is relevant only if you are running a MySQL version earlier than 3.23.3: If you have an SQL script in a text file that contains “--” comments, you should use the replace utility
as follows to convert the comments to use “#” characters before executing the script:
Page 48
How MySQL Deals with Constraints
28
shell> replace " --" " #" < text-file-with-funny-comments.sql \ | mysql db_name
That is safer than executing the script in the usual way:
shell> mysql db_name < text-file-with-funny-comments.sql
You can also edit the script file “in place” to change the “--” comments to “#” comments:
shell> replace " --" " #" -- text-file-with-funny-comments.sql
Change them back with this command:
shell> replace " #" " --" -- text-file-with-funny-comments.sql
See Section 4.8.2, “replace — A String-Replacement Utility”.
1.8.6. How MySQL Deals with Constraints
MySQL enables you to work both with transactional tables that permit rollback and with nontransactional tables that do not. Because of this, constraint handling is a bit different in MySQL than in other DBMSs. We must handle the case when you have inserted or updated a lot of rows in a nontransactional table for which changes cannot be rolled back when an error occurs.
The basic philosophy is that MySQL Server tries to produce an error for anything that it can detect while parsing a statement to be executed, and tries to recover from any errors that occur while executing the statement. We do this in most cases, but not yet for all.
The options MySQL has when an error occurs are to stop the statement in the middle or to recover as well as possible from the problem and continue. By default, the server follows the latter course. This means, for example, that the server may coerce illegal values to the closest legal values.
Beginning with MySQL 5.0.2, several SQL mode options are available to provide greater control over handling of bad data values and whether to continue statement execution or abort when errors occur. Using these options, you can configure MySQL Server to act in a more traditional fashion that is like other DBMSs that reject improper input. The SQL mode can be set globally at server startup to affect all clients. Individual clients can set the SQL mode at runtime, which enables each client to select the behavior most appropriate for its requirements. See Section 5.1.7, “Server SQL Modes”.
The following sections describe how MySQL Server handles different types of constraints.
1.8.6.1. PRIMARY KEY and UNIQUE Index Constraints
Normally, errors occurs for data-change statements (such as INSERT or UPDATE) that would violate primary-key, unique-key, or foreign-key constraints. If you are using a transactional storage engine such as InnoDB, MySQL automatically rolls back the statement. If you are using a nontransactional storage engine, MySQL stops processing the statement at the row for which the error occurred and leaves any remaining rows unprocessed.
MySQL supports an IGNORE keyword for INSERT, UPDATE, and so forth. If you use it, MySQL ignores primary-key or unique-key violations and continues processing with the next row. See the section for the statement that you are using (Section 13.2.5, “INSERT Syntax”, Section 13.2.10, “UPDATE Syntax”, and so forth).
You can get information about the number of rows actually inserted or updated with the
mysql_info() C API function. You can also use the SHOW WARNINGS statement. See
Section 20.6.6.35, “mysql_info(), and Section 13.7.5.37, “SHOW WARNINGS Syntax”.
Currently, only InnoDB tables support foreign keys. See Section 14.2.3.4, “InnoDB and FOREIGN KEY
Constraints”.
Page 49
How MySQL Deals with Constraints
29
1.8.6.2. FOREIGN KEY Constraints
Foreign keys let you cross-reference related data across tables, and foreign key constraints help keep this spread-out data consistent.
MySQL supports ON UPDATE and ON DELETE foreign key references in CREATE TABLE and ALTER
TABLE statements. The available referential actions are RESTRICT (the default), CASCADE, SET NULL,
and NO ACTION.
SET DEFAULT is also supported by the MySQL Server but is currently rejected as invalid by InnoDB.
Since MySQL does not support deferred constraint checking, NO ACTION is treated as RESTRICT. For the exact syntax supported by MySQL for foreign keys, see Section 13.1.10.2, “Using FOREIGN KEY
Constraints”.
MATCH FULL, MATCH PARTIAL, and MATCH SIMPLE are allowed, but their use should be avoided,
as they cause the MySQL Server to ignore any ON DELETE or ON UPDATE clause used in the same statement. MATCH options do not have any other effect in MySQL, which in effect enforces MATCH
SIMPLE semantics full-time.
MySQL requires that foreign key columns be indexed; if you create a table with a foreign key constraint but no index on a given column, an index is created.
You can obtain information about foreign keys from the INFORMATION_SCHEMA.KEY_COLUMN_USAGE table. An example of a query against this table is shown here:
mysql> SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME > FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE > WHERE REFERENCED_TABLE_SCHEMA IS NOT NULL; +--------------+---------------+-------------+-----------------+ | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME | +--------------+---------------+-------------+-----------------+ | fk1 | myuser | myuser_id | f | | fk1 | product_order | customer_id | f2 | | fk1 | product_order | product_id | f1 | +--------------+---------------+-------------+-----------------+ 3 rows in set (0.01 sec)
Information about foreign keys on InnoDB tables can also be found in the INNODB_SYS_FOREIGN and
INNODB_SYS_FOREIGN_COLS tables, in the INFORMATION_SCHEMA database.
Currently, only InnoDB tables support foreign keys. See Section 14.2.3.4, “InnoDB and FOREIGN KEY
Constraints”, for information specific to foreign key support in InnoDB.
Deviations from SQL Standards
MySQL's implementation of foreign keys differs from the SQL standard in the following key respects:
• If there are several rows in the parent table that have the same referenced key value, InnoDB acts in foreign key checks as if the other parent rows with the same key value do not exist. For example, if you have defined a RESTRICT type constraint, and there is a child row with several parent rows,
InnoDB does not permit the deletion of any of those parent rows. InnoDB performs cascading operations through a depth-first algorithm, based on records in the
indexes corresponding to the foreign key constraints.
• A FOREIGN KEY constraint that references a non-UNIQUE key is not standard SQL but rather an
InnoDB extension.
• If ON UPDATE CASCADE or ON UPDATE SET NULL recurses to update the same table it has previously updated during the same cascade, it acts like RESTRICT. This means that you cannot use self-referential ON UPDATE CASCADE or ON UPDATE SET NULL operations. This is to prevent infinite loops resulting from cascaded updates. A self-referential ON DELETE SET NULL, on the
Page 50
How MySQL Deals with Constraints
30
other hand, is possible, as is a self-referential ON DELETE CASCADE. Cascading operations may not be nested more than 15 levels deep.
• In an SQL statement that inserts, deletes, or updates many rows, foreign key constraints (like unique constraints) are checked row-by-row. When performing foreign key checks, InnoDB sets shared row­level locks on child or parent records that it must examine. MySQL checks foreign key constraints immediately; the check is not deferred to transaction commit. According to the SQL standard, the default behavior should be deferred checking. That is, constraints are only checked after the entire SQL statement has been processed. This means that it is not possible to delete a row that refers to itself using a foreign key.
For information how InnoDB foreign keys differ from the SQL standard, see Section 14.2.3.4, “InnoDB
and FOREIGN KEY Constraints”.
1.8.6.3. Constraints on Invalid Data
Before MySQL 5.0.2, MySQL is forgiving of illegal or improper data values and coerces them to legal values for data entry. In MySQL 5.0.2 and up, that remains the default behavior, but you can change the server SQL mode to select more traditional treatment of bad values such that the server rejects them and aborts the statement in which they occur. Section 5.1.7, “Server SQL Modes”.
This section describes the default (forgiving) behavior of MySQL, as well as the strict SQL mode and how it differs.
If you are not using strict mode, then whenever you insert an “incorrect” value into a column, such as a NULL into a NOT NULL column or a too-large numeric value into a numeric column, MySQL sets the column to the “best possible value” instead of producing an error: The following rules describe in more detail how this works:
• If you try to store an out of range value into a numeric column, MySQL Server instead stores zero, the smallest possible value, or the largest possible value, whichever is closest to the invalid value.
• For strings, MySQL stores either the empty string or as much of the string as can be stored in the column.
• If you try to store a string that doesn't start with a number into a numeric column, MySQL Server stores 0.
• Invalid values for ENUM and SET columns are handled as described in Section 1.8.6.4, “ENUM and
SET Constraints”.
• MySQL enables you to store certain incorrect date values into DATE and DATETIME columns (such as '2000-02-31' or '2000-02-00'). The idea is that it is not the job of the SQL server to validate dates. If MySQL can store a date value and retrieve exactly the same value, MySQL stores it as given. If the date is totally wrong (outside the server's ability to store it), the special “zero” date value
'0000-00-00' is stored in the column instead.
• If you try to store NULL into a column that doesn't take NULL values, an error occurs for single­row INSERT statements. For multiple-row INSERT statements or for INSERT INTO ... SELECT statements, MySQL Server stores the implicit default value for the column data type. In general, this is 0 for numeric types, the empty string ('') for string types, and the “zero” value for date and time types. Implicit default values are discussed in Section 11.1.7, “Data Type Default Values”.
• If an INSERT statement specifies no value for a column, MySQL inserts its default value if the column definition includes an explicit DEFAULT clause. If the definition has no such DEFAULT clause, MySQL inserts the implicit default value for the column data type.
The reason for using the preceding rules in nonstrict mode is that we can't check these conditions until the statement has begun executing. We can't just roll back if we encounter a problem after updating a few rows, because the storage engine may not support rollback. The option of terminating the statement is not that good; in this case, the update would be “half done,” which is probably the worst
Page 51
How MySQL Deals with Constraints
31
possible scenario. In this case, it is better to “do the best you can” and then continue as if nothing happened.
In MySQL 5.0.2 and up, you can select stricter treatment of input values by using the
STRICT_TRANS_TABLES [539] or STRICT_ALL_TABLES [539] SQL modes:
SET sql_mode = 'STRICT_TRANS_TABLES'; SET sql_mode = 'STRICT_ALL_TABLES';
STRICT_TRANS_TABLES [539] enables strict mode for transactional storage engines, and also to
some extent for nontransactional engines. It works like this:
• For transactional storage engines, bad data values occurring anywhere in a statement cause the statement to abort and roll back.
• For nontransactional storage engines, a statement aborts if the error occurs in the first row to be inserted or updated. (When the error occurs in the first row, the statement can be aborted to leave the table unchanged, just as for a transactional table.) Errors in rows after the first do not abort the statement, because the table has already been changed by the first row. Instead, bad data values are adjusted and result in warnings rather than errors. In other words, with
STRICT_TRANS_TABLES [539], a wrong value causes MySQL to roll back all updates done so far,
if that can be done without changing the table. But once the table has been changed, further errors result in adjustments and warnings.
For even stricter checking, enable STRICT_ALL_TABLES [539]. This is the same as
STRICT_TRANS_TABLES [539] except that for nontransactional storage engines, errors abort
the statement even for bad data in rows following the first row. This means that if an error occurs partway through a multiple-row insert or update for a nontransactional table, a partial update results. Earlier rows are inserted or updated, but those from the point of the error on are not. To avoid this for nontransactional tables, either use single-row statements or else use STRICT_TRANS_TABLES [539] if conversion warnings rather than errors are acceptable. To avoid problems in the first place, do not use MySQL to check column content. It is safest (and often faster) to let the application ensure that it passes only legal values to the database.
With either of the strict mode options, you can cause errors to be treated as warnings by using INSERT
IGNORE or UPDATE IGNORE rather than INSERT or UPDATE without IGNORE.
1.8.6.4. ENUM and SET Constraints
ENUM and SET columns provide an efficient way to define columns that can contain only a given set
of values. See Section 11.1.6.4, “The ENUM Type”, and Section 11.1.6.5, “The SET Type”. However, before MySQL 5.0.2, ENUM and SET columns do not provide true constraints on entry of invalid data:
ENUM columns always have a default value. If you specify no default value, then it is NULL for columns that can have NULL, otherwise it is the first enumeration value in the column definition.
• If you insert an incorrect value into an ENUM column or if you force a value into an ENUM column with
IGNORE, it is set to the reserved enumeration value of 0, which is displayed as an empty string in
string context.
• If you insert an incorrect value into a SET column, the incorrect value is ignored. For example, if the column can contain the values 'a', 'b', and 'c', an attempt to assign 'a,x,b,y' results in a value of 'a,b'.
As of MySQL 5.0.2, you can configure the server to use strict SQL mode. See Section 5.1.7, “Server
SQL Modes”. With strict mode enabled, the definition of a ENUM or SET column does act as a constraint
on values entered into the column. An error occurs for values that do not satisfy these conditions:
• An ENUM value must be one of those listed in the column definition, or the internal numeric equivalent thereof. The value cannot be the error value (that is, 0 or the empty string). For a column defined as
ENUM('a','b','c'), values such as '', 'd', or 'ax' are illegal and are rejected.
Page 52
Credits
32
• A SET value must be the empty string or a value consisting only of the values listed in the column definition separated by commas. For a column defined as SET('a','b','c'), values such as 'd' or 'a,b,c,d' are illegal and are rejected.
Errors for invalid values can be suppressed in strict mode if you use INSERT IGNORE or UPDATE
IGNORE. In this case, a warning is generated rather than an error. For ENUM, the value is inserted as
the error member (0). For SET, the value is inserted as given except that any invalid substrings are deleted. For example, 'a,x,b,y' results in a value of 'a,b'.
1.9. Credits
The following sections list developers, contributors, and supporters that have helped to make MySQL what it is today.
1.9.1. Contributors to MySQL
Although Oracle Corporation and/or its affiliates own all copyrights in the MySQL server and the
MySQL manual, we wish to recognize those who have made contributions of one kind or another to
the MySQL distribution. Contributors are listed here, in somewhat random order:
• Gianmassimo Vigazzola <qwerg@mbox.vol.it> or <qwerg@tin.it> The initial port to Win32/NT.
• Per Eric Olsson For constructive criticism and real testing of the dynamic record format.
• Irena Pancirov <irena@mail.yacc.it> Win32 port with Borland compiler. mysqlshutdown.exe and mysqlwatch.exe.
• David J. Hughes For the effort to make a shareware SQL database. At TcX, the predecessor of MySQL AB, we
started with mSQL, but found that it couldn't satisfy our purposes so instead we wrote an SQL interface to our application builder Unireg. mysqladmin and mysql client are programs that were largely influenced by their mSQL counterparts. We have put a lot of effort into making the MySQL syntax a superset of mSQL. Many of the API's ideas are borrowed from mSQL to make it easy to port free mSQL programs to the MySQL API. The MySQL software doesn't contain any code from mSQL. Two files in the distribution (client/insert_test.c and client/select_test.c) are based on the corresponding (noncopyrighted) files in the mSQL distribution, but are modified as examples showing the changes necessary to convert code from mSQL to MySQL Server. (mSQL is copyrighted David J. Hughes.)
• Patrick Lynch For helping us acquire http://www.mysql.com/.
• Fred Lindberg For setting up qmail to handle the MySQL mailing list and for the incredible help we got in managing
the MySQL mailing lists.
• Igor Romanenko <igor@frog.kiev.ua>
mysqldump (previously msqldump, but ported and enhanced by Monty).
• Yuri Dario For keeping up and extending the MySQL OS/2 port.
Page 53
Contributors to MySQL
33
• Tim Bunce Author of mysqlhotcopy.
• Zarko Mocnik <zarko.mocnik@dem.si> Sorting for Slovenian language.
• "TAMITO" <tommy@valley.ne.jp> The _MB character set macros and the ujis and sjis character sets.
• Joshua Chamas <joshua@chamas.com> Base for concurrent insert, extended date syntax, debugging on NT, and answering on the MySQL
mailing list.
• Yves Carlier <Yves.Carlier@rug.ac.be>
mysqlaccess, a program to show the access rights for a user.
• Rhys Jones <rhys@wales.com> (And GWE Technologies Limited) For one of the early JDBC drivers.
• Dr Xiaokun Kelvin ZHU <X.Zhu@brad.ac.uk> Further development of one of the early JDBC drivers and other MySQL-related Java tools.
• James Cooper <pixel@organic.com> For setting up a searchable mailing list archive at his site.
• Rick Mehalick <Rick_Mehalick@i-o.com> For xmysql, a graphical X client for MySQL Server.
• Doug Sisk <sisk@wix.com> For providing RPM packages of MySQL for Red Hat Linux.
• Diemand Alexander V. <axeld@vial.ethz.ch> For providing RPM packages of MySQL for Red Hat Linux-Alpha.
• Antoni Pamies Olive <toni@readysoft.es> For providing RPM versions of a lot of MySQL clients for Intel and SPARC.
• Jay Bloodworth <jay@pathways.sde.state.sc.us> For providing RPM versions for MySQL 3.21.
• David Sacerdote <davids@secnet.com> Ideas for secure checking of DNS host names.
• Wei-Jou Chen <jou@nematic.ieo.nctu.edu.tw> Some support for Chinese(BIG5) characters.
• Wei He <hewei@mail.ied.ac.cn> A lot of functionality for the Chinese(GBK) character set.
Page 54
Contributors to MySQL
34
• Jan Pazdziora <adelton@fi.muni.cz> Czech sorting order.
• Zeev Suraski <bourbon@netvision.net.il>
FROM_UNIXTIME() [923] time formatting, ENCRYPT() [955] functions, and bison advisor.
Active mailing list member.
• Luuk de Boer <luuk@wxs.nl> Ported (and extended) the benchmark suite to DBI/DBD. Have been of great help with crash-me
and running benchmarks. Some new date functions. The mysql_setpermission script.
• Alexis Mikhailov <root@medinf.chuvashia.su> User-defined functions (UDFs); CREATE FUNCTION and DROP FUNCTION.
• Andreas F. Bobak <bobak@relog.ch> The AGGREGATE extension to user-defined functions.
• Ross Wakelin <R.Wakelin@march.co.uk> Help to set up InstallShield for MySQL-Win32.
• Jethro Wright III <jetman@li.net> The libmysql.dll library.
• James Pereria <jpereira@iafrica.com> Mysqlmanager, a Win32 GUI tool for administering MySQL Servers.
• Curt Sampson <cjs@portal.ca> Porting of MIT-pthreads to NetBSD/Alpha and NetBSD 1.3/i386.
• Martin Ramsch <m.ramsch@computer.org> Examples in the MySQL Tutorial.
• Steve Harvey For making mysqlaccess more secure.
• Konark IA-64 Centre of Persistent Systems Private Limited
http://www.pspl.co.in/konark/. Help with the Win64 port of the MySQL server.
• Albert Chin-A-Young. Configure updates for Tru64, large file support and better TCP wrappers support.
• John Birrell Emulation of pthread_mutex() for OS/2.
• Benjamin Pflugmann Extended MERGE tables to handle INSERTS. Active member on the MySQL mailing lists.
• Jocelyn Fournier Excellent spotting and reporting innumerable bugs (especially in the MySQL 4.1 subquery code).
Page 55
Contributors to MySQL
35
• Marc Liyanage Maintaining the Mac OS X packages and providing invaluable feedback on how to create Mac OS X
packages.
• Robert Rutherford Providing invaluable information and feedback about the QNX port.
• Previous developers of NDB Cluster Lots of people were involved in various ways summer students, master thesis students, employees.
In total more than 100 people so too many to mention here. Notable name is Ataullah Dabaghi who up until 1999 contributed around a third of the code base. A special thanks also to developers of the AXE system which provided much of the architectural foundations for NDB Cluster with blocks, signals and crash tracing functionality. Also credit should be given to those who believed in the ideas enough to allocate of their budgets for its development from 1992 to present time.
• Google Inc. We wish to recognize Google Inc. for contributions to the MySQL distribution: Mark Callaghan's SMP
Performance patches and other patches.
Other contributors, bugfinders, and testers: James H. Thompson, Maurizio Menghini, Wojciech Tryc, Luca Berra, Zarko Mocnik, Wim Bonis, Elmar Haneke, <jehamby@lightside>,
<psmith@BayNetworks.com>, <duane@connect.com.au>, Ted Deppner <ted@psyber.com>,
Mike Simons, Jaakko Hyvatti. And lots of bug report/patches from the folks on the mailing list. A big tribute goes to those that help us answer questions on the MySQL mailing lists:
• Daniel Koch <dkoch@amcity.com> Irix setup.
• Luuk de Boer <luuk@wxs.nl> Benchmark questions.
• Tim Sailer <tps@users.buoy.com>
DBD::mysql questions.
• Boyd Lynn Gerber <gerberb@zenez.com> SCO-related questions.
• Richard Mehalick <RM186061@shellus.com>
xmysql-related questions and basic installation questions.
• Zeev Suraski <bourbon@netvision.net.il> Apache module configuration questions (log & auth), PHP-related questions, SQL syntax-related
questions and other general questions.
• Francesc Guasch <frankie@citel.upc.es> General questions.
• Jonathan J Smith <jsmith@wtp.net>
Page 56
Documenters and translators
36
Questions pertaining to OS-specifics with Linux, SQL syntax, and other things that might need some work.
• David Sklar <sklar@student.net> Using MySQL from PHP and Perl.
• Alistair MacDonald <A.MacDonald@uel.ac.uk> Is flexible and can handle Linux and perhaps HP-UX.
• John Lyon <jlyon@imag.net> Questions about installing MySQL on Linux systems, using either .rpm files or compiling from
source.
• Lorvid Ltd. <lorvid@WOLFENET.com> Simple billing/license/support/copyright issues.
• Patrick Sherrill <patrick@coconet.com> ODBC and VisualC++ interface questions.
• Randy Harmon <rjharmon@uptimecomputers.com>
DBD, Linux, some SQL syntax questions.
1.9.2. Documenters and translators
The following people have helped us with writing the MySQL documentation and translating the documentation or error messages in MySQL.
• Paul DuBois Ongoing help with making this manual correct and understandable. That includes rewriting Monty's
and David's attempts at English into English as other people know it.
• Kim Aldale Helped to rewrite Monty's and David's early attempts at English into English.
• Michael J. Miller Jr. <mke@terrapin.turbolift.com> For the first MySQL manual. And a lot of spelling/language fixes for the FAQ (that turned into the
MySQL manual a long time ago).
• Yan Cailin First translator of the MySQL Reference Manual into simplified Chinese in early 2000 on which
the Big5 and HK coded (http://mysql.hitstar.com/) versions were based. Personal home page at
linuxdb.yeah.net.
• Jay Flaherty <fty@mediapulse.com> Big parts of the Perl DBI/DBD section in the manual.
• Paul Southworth <pauls@etext.org>, Ray Loyzaga <yar@cs.su.oz.au> Proof-reading of the Reference Manual.
• Therrien Gilbert <gilbert@ican.net>, Jean-Marc Pouyot <jmp@scalaire.fr>
Page 57
Packages that support MySQL
37
French error messages.
• Petr Snajdr, <snajdr@pvt.net> Czech error messages.
• Jaroslaw Lewandowski <jotel@itnet.com.pl> Polish error messages.
• Miguel Angel Fernandez Roiz Spanish error messages.
• Roy-Magne Mo <rmo@www.hivolda.no> Norwegian error messages and testing of MySQL 3.21.xx.
• Timur I. Bakeyev <root@timur.tatarstan.ru> Russian error messages.
<brenno@dewinter.com> & Filippo Grassilli <phil@hyppo.com> Italian error messages.
• Dirk Munzinger <dirk@trinity.saar.de> German error messages.
• Billik Stefan <billik@sun.uniag.sk> Slovak error messages.
• Stefan Saroiu <tzoompy@cs.washington.edu> Romanian error messages.
• Peter Feher Hungarian error messages.
• Roberto M. Serqueira Portuguese error messages.
• Carsten H. Pedersen Danish error messages.
• Arjen Lentz Dutch error messages, completing earlier partial translation (also work on consistency and spelling).
1.9.3. Packages that support MySQL
The following is a list of creators/maintainers of some of the most important API/packages/applications that a lot of people use with MySQL.
We cannot list every possible package here because the list would then be way to hard to maintain. For other packages, please refer to the software portal at http://solutions.mysql.com/software/.
• Tim Bunce, Alligator Descartes
Page 58
Tools that were used to create MySQL
38
For the DBD (Perl) interface.
• Andreas Koenig <a.koenig@mind.de> For the Perl interface for MySQL Server.
• Jochen Wiedmann <wiedmann@neckar-alb.de> For maintaining the Perl DBD::mysql module.
• Eugene Chan <eugene@acenet.com.sg> For porting PHP for MySQL Server.
• Georg Richter MySQL 4.1 testing and bug hunting. New PHP 5.0 mysqli extension (API) for use with MySQL 4.1
and up.
• Giovanni Maruzzelli <maruzz@matrice.it> For porting iODBC (Unix ODBC).
• Xavier Leroy <Xavier.Leroy@inria.fr> The author of LinuxThreads (used by the MySQL Server on Linux).
1.9.4. Tools that were used to create MySQL
The following is a list of some of the tools we have used to create MySQL. We use this to express our thanks to those that has created them as without these we could not have made MySQL what it is today.
• Free Software Foundation From whom we got an excellent compiler (gcc), an excellent debugger (gdb and the libc library
(from which we have borrowed strto.c to get some code working in Linux).
• Free Software Foundation & The XEmacs development team For a really great editor/environment.
• Julian Seward Author of valgrind, an excellent memory checker tool that has helped us find a lot of otherwise
hard to find bugs in MySQL.
• Dorothea Lütkehaus and Andreas Zeller For DDD (The Data Display Debugger) which is an excellent graphical front end to gdb).
1.9.5. Supporters of MySQL
Although Oracle Corporation and/or its affiliates own all copyrights in the MySQL server and the MySQL manual, we wish to recognize the following companies, which helped us finance the development of the MySQL server, such as by paying us for developing a new feature or giving us hardware for development of the MySQL server.
• VA Linux / Andover.net Funded replication.
Page 59
Supporters of MySQL
39
• NuSphere Editing of the MySQL manual.
• Stork Design studio The MySQL Web site in use between 1998-2000.
• Intel Contributed to development on Windows and Linux platforms.
• Compaq Contributed to Development on Linux/Alpha.
• SWSoft Development on the embedded mysqld version.
• FutureQuest The --skip-show-database [421] option.
Page 60
40
Page 61
41
Chapter 2. Installing and Upgrading MySQL
Table of Contents
2.1. MySQL Installation Overview ................................................................................................ 42
2.2. Determining your current MySQL version .............................................................................. 42
2.3. Notes for MySQL Enterprise Server ...................................................................................... 43
2.3.1. Enterprise Server Distribution Types ........................................................................... 44
2.3.2. Upgrading MySQL Enterprise Server .......................................................................... 44
2.4. Notes for MySQL Community Server .................................................................................... 44
2.4.1. Overview of MySQL Community Server Installation ..................................................... 44
2.4.2. Operating Systems Supported by MySQL Community Server ....................................... 45
2.4.3. Choosing Which MySQL Distribution to Install ............................................................. 46
2.5. How to Get MySQL .............................................................................................................. 50
2.6. Verifying Package Integrity Using MD5 Checksums or GnuPG ................................................ 50
2.6.1. Verifying the MD5 Checksum ..................................................................................... 50
2.6.2. Signature Checking Using GnuPG ............................................................................... 51
2.6.3. Signature Checking Using Gpg4win for Windows ....................................................... 53
2.6.4. Signature Checking Using RPM ................................................................................... 57
2.7. Installation Layouts ............................................................................................................... 58
2.8. Compiler-Specific Build Characteristics .................................................................................. 59
2.9. Standard MySQL Installation from a Binary Distribution .......................................................... 60
2.10. Installing MySQL on Microsoft Windows .............................................................................. 60
2.10.1. Choosing An Installation Package ............................................................................ 61
2.10.2. Installing MySQL on Microsoft Windows Using an MSI Package ................................. 62
2.10.3. MySQL Server Instance Configuration Wizard ........................................................... 67
2.10.4. Installing MySQL on Microsoft Windows Using a noinstall Zip Archive ................... 79
2.10.5. Troubleshooting a MySQL Installation Under Windows .............................................. 86
2.10.6. Upgrading MySQL on Windows ................................................................................ 87
2.10.7. Windows Postinstallation Procedures ........................................................................ 88
2.10.8. Installing MySQL from Source on Windows ............................................................... 90
2.11. Installing MySQL on Mac OS X .......................................................................................... 95
2.12. Installing MySQL from RPM Packages on Linux .................................................................. 97
2.13. Installing MySQL on Solaris .............................................................................................. 100
2.14. Installing MySQL on i5/OS ................................................................................................ 101
2.15. Installing MySQL on NetWare ........................................................................................... 105
2.16. Installing MySQL from Generic Binaries on Other Unix-Like Systems .................................. 107
2.17. Installing MySQL from Source ........................................................................................... 109
2.17.1. Installing MySQL from a Standard Source Distribution ............................................. 110
2.17.2. Installing MySQL from a Development Source Tree ................................................. 113
2.17.3. MySQL Source-Configuration Options ..................................................................... 115
2.17.4. Dealing with Problems Compiling MySQL ............................................................... 123
2.17.5. Compiling and Linking an Optimized mysqld Server ............................................... 126
2.18. Postinstallation Setup and Testing ..................................................................................... 127
2.18.1. Unix Postinstallation Procedures ............................................................................. 127
2.18.2. Securing the Initial MySQL Accounts ...................................................................... 138
2.19. Upgrading or Downgrading MySQL ................................................................................... 142
2.19.1. Upgrading MySQL ................................................................................................. 142
2.19.2. Downgrading MySQL ............................................................................................. 153
2.19.3. Checking Whether Tables or Indexes Must Be Rebuilt ............................................. 154
2.19.4. Rebuilding or Repairing Tables or Indexes .............................................................. 156
2.19.5. Copying MySQL Databases to Another Machine ..................................................... 158
2.20. Operating System-Specific Notes ...................................................................................... 159
2.20.1. Linux Notes ........................................................................................................... 159
2.20.2. Mac OS X Notes ................................................................................................... 165
2.20.3. Solaris Notes ......................................................................................................... 165
Page 62
MySQL Installation Overview
42
2.20.4. BSD Notes ............................................................................................................ 169
2.20.5. Other Unix Notes ................................................................................................... 172
2.20.6. OS/2 Notes ........................................................................................................... 187
2.21. Environment Variables ...................................................................................................... 187
2.22. Perl Installation Notes ....................................................................................................... 188
2.22.1. Installing Perl on Unix ............................................................................................ 189
2.22.2. Installing ActiveState Perl on Windows ................................................................... 190
2.22.3. Problems Using the Perl DBI/DBD Interface ............................................................. 190
End of Product Lifecycle
Active development for MySQL Database Server version 5.0 has ended. Oracle offers various support offerings which may be of interest. For details and more information, see the MySQL section of the Lifetime Support Policy for Oracle Technology Products (http:// www.oracle.com/us/support/lifetime-support/index.html). Please consider upgrading to a recent version.
2.1. MySQL Installation Overview
This chapter describes how to obtain and install MySQL. You can choose to install MySQL Enterprise or MySQL Community Server:
• MySQL Enterprise is Oracle Corporation's commercial offering for modern enterprise businesses. It includes MySQL Enterprise Server and the services provided by MySQL Network. To install MySQL Enterprise, see Section 2.3, “Notes for MySQL Enterprise Server”.
• MySQL Community Server is for users who are comfortable configuring and administering MySQL by themselves. To install MySQL Community Server, see Section 2.4, “Notes for MySQL Community
Server”.
If you plan to upgrade an existing version of MySQL to a newer version rather than install MySQL for the first time, see Section 2.19.1, “Upgrading MySQL”, for information about upgrade procedures and about issues that you should consider before upgrading.
If you are interested in migrating to MySQL from another database system, you may wish to read
Section B.8, “MySQL 5.0 FAQ: Migration”, which contains answers to some common questions
concerning migration issues.
2.2. Determining your current MySQL version
To determine the version and release of your currently installed MySQL installation, there are a number of options.
• Using a command client (mysql), the server version of the MySQL server to which you are connected is shown once you are connected. The server version information includes community or
enterprise accordingly.
For example, here is the output from a MySQL Community Server edition installed on Linux:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.0.27-standard MySQL Community Edition - Standard (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
This is an example of the output from MySQL Enterprise Server on Windows:
Welcome to the MySQL monitor. Commands end with ; or \g.
Page 63
Notes for MySQL Enterprise Server
43
Your MySQL connection id is 2 Server version: 5.0.28-enterprise-gpl-nt MySQL Enterprise Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
• You may also determine the version information using the version variables. Both the version [425] and version_comment [505] variables contain version information for the server to which you are connected. Use the SHOW VARIABLES statement to obtain the information you want, as shown in this example:
mysql> SHOW VARIABLES LIKE "%version%"; +-------------------------+------------------------------------------+ | Variable_name | Value | +-------------------------+------------------------------------------+ | protocol_version | 10 | | version | 5.0.27-standard | | version_comment | MySQL Community Edition - Standard (GPL) | | version_compile_machine | i686 | | version_compile_os | pc-linux-gnu | +-------------------------+------------------------------------------+ 5 rows in set (0.04 sec)
You can also obtain server version information in the mysql client using the SELECT
VERSION() [964] statement. In addition, MySQL Workbench also shows the server version in the
Server Status tab. However, in both of these cases, only the value of version is shown.
• The STATUS command displays the version as well as version comment information. For example:
mysql> STATUS;
-------------­./client/mysql Ver 14.12 Distrib 5.0.29, for pc-linux-gnu (i686) using readline 5.0
Connection id: 8 Current database: Current user: mc@localhost SSL: Not in use Current pager: /usr/bin/less Using outfile: '' Using delimiter: ; Server version: 5.0.27-standard MySQL Community Edition - Standard (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /tmp/mysql.sock Uptime: 1 day 3 hours 58 min 43 sec
Threads: 2 Questions: 17 Slow queries: 0 Opens: 11 Flush tables: 1 Open tables: 6 Queries per second avg: 0.000
--------------
2.3. Notes for MySQL Enterprise Server
To obtain MySQL Enterprise, visit http://enterprise.mysql.com if you're a customer. Otherwise, visit http://www.mysql.com/products/enterprise/. The platforms that are officially supported for MySQL Enterprise are listed at http://www.mysql.com/support/supportedplatforms.html.
MySQL Enterprise Server is available for download in the form of Quarterly Service Pack (QSP) or Monthly Rapid Update (MRU) binary releases.
To install MySQL Enterprise Server, you should use the latest available Quarterly Service Pack (QSP). This includes an accumulation of the bug fixes provided in all predecessor QSP and MRU releases.
MRU releases are provided on a monthly basis and represent the most current Enterprise Server bug fixes. Each MRU is an accumulation of the bug fixes included in its predecessor. Customers should standardize on the latest MRU release only if it includes a needed bug fix.
Page 64
Enterprise Server Distribution Types
44
2.3.1. Enterprise Server Distribution Types
Enterprise Server releases will be created for the following packages from the MySQL 5.0 tree:
mysql-enterprise: Released under a commercial license and includes the following storage engines: MyISAM, MEMORY, MERGE, InnoDB, ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED.
mysql-enterprise-gpl: Same as mysql-enterprise, but released under the GPL.
mysql-cluster: mysql-enterprise plus MySQL Cluster (NDB).
mysql-classic: Released under a commercial license, does not include InnoDB.
mysql-community: Same as mysql-enterprise-gpl, but available for the community, and released every 6 months.
To satisfy different user requirements, we provide several servers. mysqld is an optimized server that is a smaller, faster binary. mysqld-debug is compiled with debugging support but is otherwise configured identically to the nondebug server.
Each of these servers is compiled from the same source distribution, though with different configuration options. All native MySQL clients can connect to servers from either MySQL version.
2.3.2. Upgrading MySQL Enterprise Server
When upgrading to MySQL Enterprise from Community Server you need only follow the installation process to install and upgrade the packages to the latest version provided by MySQL Enterprise. You will also need to install the latest MySQL Enterprise Service Pack and any outstanding MySQL Hot-fix packs.
Be aware, however, that you must take into account any of the changes when moving between major releases. You should also check the Release Notes for details on major changes between revisions of MySQL Enterprise Server.
You should also review the notes and advice contained within Section 2.19.1, “Upgrading MySQL”.
2.4. Notes for MySQL Community Server
2.4.1. Overview of MySQL Community Server Installation
1. Determine whether MySQL runs and is supported on your platform. Not all platforms are
equally suitable for running MySQL, and not all platforms on which MySQL is known to run are officially supported by Oracle Corporation. For a list of platforms on which MySQL Community Server runs, see Section 2.4.2, “Operating Systems Supported by MySQL Community Server”.
2. Choose which distribution to install. Several versions of MySQL are available, and most are
available in multiple distribution formats. You can choose from prepackaged distributions containing binary (precompiled) programs or source code. When in doubt, use a binary distribution. We also provide public access to our current source trees for those who want to see our most recent developments and to help us test new code. To determine which version and type of distribution you should use, see Section 2.4.3, “Choosing Which MySQL Distribution to Install”.
3. Download the distribution that you want to install. For download instructions, see
Section 2.5, “How to Get MySQL”. To verify the integrity of the distribution, use the instructions in Section 2.6, “Verifying Package Integrity Using MD5 Checksums or GnuPG.
4. Install the distribution. To install MySQL from a binary distribution, use the instructions
in Section 2.9, “Standard MySQL Installation from a Binary Distribution”. To install MySQL from a source distribution or from the current development source tree, use the instructions in
Section 2.17, “Installing MySQL from Source”.
Page 65
Operating Systems Supported by MySQL Community Server
45
If you encounter installation difficulties, see Section 2.20, “Operating System-Specific Notes”, for information on solving problems for particular platforms.
5. Perform any necessary postinstallation setup. After installing MySQL, read Section 2.18,
“Postinstallation Setup and Testing”, which contains important information about making sure the
MySQL server is working properly. It also describes how to secure the initial MySQL user accounts, which have no passwords until you assign passwords. The information in this section applies whether you install MySQL using a binary or source distribution.
6. Perform setup for running benchmarks (optional). If you want to use the MySQL benchmark scripts, Perl support for MySQL must be available. See Section 2.22, “Perl Installation Notes”, for more information.
The sections immediately following this one contain necessary information about choosing, downloading, and verifying your distribution. The instructions in later sections of the chapter describe how to install the distribution that you choose. For binary distributions, see the instructions in
Section 2.9, “Standard MySQL Installation from a Binary Distribution”. To build MySQL from source,
use the instructions in Section 2.17, “Installing MySQL from Source”.
2.4.2. Operating Systems Supported by MySQL Community Server
This section lists the operating systems on which MySQL Community Server is known to run.
Important
Oracle Corporation does not necessarily provide official support for all the platforms listed in this section. For information about those platforms that are officially supported, see http://www.mysql.com/support/supportedplatforms.html on the MySQL Web site.
We use GNU Autoconf, so it is possible to port MySQL to all modern systems that have a C++ compiler and a working implementation of POSIX threads. (Thread support is needed for the server. To compile only the client code, the only requirement is a C++ compiler.)
MySQL has been reported to compile successfully on the following combinations of operating system and thread package.
• AIX 4.x and 5.x with native threads. See Section 2.20.5.3, “IBM-AIX notes”. AIX 5.3 should be
upgraded to technology level 7 (5300-07).
• Amiga.
• FreeBSD 5.x and up with native threads.
• HP-UX 11.x with native threads. See Section 2.20.5.2, “HP-UX Version 11.x Notes”.
• Linux. Builds on all recent Linux distributions based on the 2.6 kernel. See Section 2.20.1, “Linux
Notes”.
• Mac OS X. See Section 2.11, “Installing MySQL on Mac OS X”.
• NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha. See Section 2.20.4.2, “NetBSD Notes”.
• Novell NetWare 6.0 and 6.5. See Section 2.15, “Installing MySQL on NetWare”.
• SCO OpenServer 5.0.X with a recent port of the FSU Pthreads package. See Section 2.20.5.8, “SCO
UNIX and OpenServer 5.0.x Notes”.
• SCO Openserver 6.0.x. See Section 2.20.5.9, “SCO OpenServer 6.0.x Notes”.
• SCO UnixWare 7.1.x. See Section 2.20.5.10, “SCO UnixWare 7.1.x and OpenUNIX 8.0.0 Notes”.
Page 66
Choosing Which MySQL Distribution to Install
46
• SGI Irix 6.x with native threads. See Section 2.20.5.7, “SGI Irix Notes”.
• Solaris 2.5 and above with native threads on SPARC and x86. See Section 2.20.3, “Solaris Notes”.
• Tru64 Unix. See Section 2.20.5.5, “Alpha-DEC-UNIX Notes (Tru64)”.
• Windows 2000, XP, Windows Server 2003, Windows Vista, and Windows Server 2008. See
Section 2.10, “Installing MySQL on Microsoft Windows”.
MySQL has also been known to run on other systems in the past. See Section 2.20, “Operating
System-Specific Notes”. Some porting effort might be required for current versions of MySQL on these
systems. Not all platforms are equally well suited for running MySQL. How well a certain platform is suited for a
high-load mission-critical MySQL server is determined by the following factors:
General stability of the thread library. A platform may have an excellent reputation otherwise, but MySQL is only as stable as the thread library it calls, even if everything else is perfect.
The capability of the kernel and the thread library to take advantage of symmetric multi- processor (SMP) systems. When a process creates a thread, it should be possible for that thread to run on a CPU different from the original process.
Multi-threading and handling of mutexes. The capability of the kernel and the thread library to run many threads that acquire and release a mutex over a short critical region frequently without excessive context switches. If the implementation of pthread_mutex_lock() does not easily yield CPU time, this hurts MySQL tremendously. If this issue is not taken care of, adding extra CPUs actually makes MySQL slower.
File system stability and performance. MySQL's stability and performance are directly affected by those of the operating platform's file system. In particular, where large tables are in use, performance is affected by the ability of the file system to deal with large files at all and to deal with them efficiently.
Expertise with the platform. If we know a platform well, we enable platform-specific optimizations and fixes at compile time. We can also provide advice on configuring your system optimally for MySQL. This is also affected by the amount of testing we have done internally for similar configurations, as well as by the number of users that have run MySQL successfully on the platform in similar configurations. If these figures are high, the likelihood of encountering platform­specific surprises is much smaller.
2.4.3. Choosing Which MySQL Distribution to Install
When preparing to install MySQL, you should decide which version to use. MySQL development occurs in several release series, and you can pick the one that best fits your needs. After deciding which version to install, you can choose a distribution format. Releases are available in binary or source format.
2.4.3.1. Choosing Which Version of MySQL to Install
The first decision to make is whether you want to use a production (stable) release or a development release. In the MySQL development process, multiple release series co-exist, each at a different stage of maturity.
Production Releases
• MySQL 5.6: Latest General Availability (Production) release
• MySQL 5.5: Previous General Availability (Production) release
• MySQL 5.1: Older General Availability (Production) release
Page 67
Choosing Which MySQL Distribution to Install
47
• MySQL 5.0: Older Production release nearing the end of the product lifecycle MySQL 4.1, 4.0, and 3.23 are old releases that are no longer supported. See http://www.mysql.com/about/legal/lifecycle/ for information about support policies and schedules. Normally, if you are beginning to use MySQL for the first time or trying to port it to some system for
which there is no binary distribution, use the most recent General Availability series listed in the preceding descriptions. All MySQL releases, even those from development series, are checked with the MySQL benchmarks and an extensive test suite before being issued.
If you are running an older system and want to upgrade, but do not want to take the chance of having a nonseamless upgrade, you should upgrade to the latest version in the same release series you are using (where only the last part of the version number is newer than yours). We have tried to fix only fatal bugs and make only small, relatively “safe” changes to that version.
If you want to use new features not present in the production release series, you can use a version from a development series. Be aware that development releases are not as stable as production releases.
We do not use a complete code freeze because this prevents us from making bugfixes and other fixes that must be done. We may add small things that should not affect anything that currently works in a production release. Naturally, relevant bugfixes from an earlier series propagate to later series.
If you want to use the very latest sources containing all current patches and bugfixes, you can use one of our source code repositories (see Section 2.17.2, “Installing MySQL from a Development Source
Tree”). These are not “releases” as such, but are available as previews of the code on which future
releases are to be based. The naming scheme in MySQL 5.0 uses release names that consist of three numbers and a suffix; for
example, mysql-5.0.14-rc. The numbers within the release name are interpreted as follows:
• The first number (5) is the major version and describes the file format. All MySQL 5 releases have the same file format.
• The second number (0) is the release level. Taken together, the major version and release level constitute the release series number.
• The third number (14) is the version number within the release series. This is incremented for each new release. Usually you want the latest version for the series you have chosen.
For each minor update, the last number in the version string is incremented. When there are major new features or minor incompatibilities with previous versions, the second number in the version string is incremented. When the file format changes, the first number is increased.
Release names also include a suffix to indicates the stability level of the release. Releases within a series progress through a set of suffixes to indicate how the stability level improves. The possible suffixes are:
alpha indicates that the release is for preview purposes only. Known bugs should be documented in the Release Notes. Most alpha releases implement new commands and extensions. Active development that may involve major code changes can occur in an alpha release. However, we do conduct testing before issuing a release.
beta indicates that the release is appropriate for use with new development. Within beta releases, the features and compatibility should remain consistent. However, beta releases may contain numerous and major unaddressed bugs.
No APIs, externally visible structures, or columns for SQL statements will change during future beta, release candidate, or production releases.
Page 68
Choosing Which MySQL Distribution to Install
48
rc indicates a Release Candidate. Release candidates are believed to be stable, having passed all of MySQL's internal testing, and with all known fatal runtime bugs fixed. However, the release has not been in widespread use long enough to know for sure that all bugs have been identified. Only minor fixes are added. (A release candidate is what formerly was known as a gamma release.)
• If there is no suffix, it indicates that the release is a General Availability (GA) or Production release. GA releases are stable, having successfully passed through all earlier release stages and are believed to be reliable, free of serious bugs, and suitable for use in production systems. Only critical bugfixes are applied to the release.
All releases of MySQL are run through our standard tests and benchmarks to ensure that they are relatively safe to use. Because the standard tests are extended over time to check for all previously found bugs, the test suite keeps getting better.
All releases have been tested at least with these tools:
An internal test suite. The mysql-test directory contains an extensive set of test cases. We run these tests for every server binary. See Section 21.1.2, “The MySQL Test Suite”, for more information about this test suite.
The MySQL benchmark suite. This suite runs a range of common queries. It is also a test to determine whether the latest batch of optimizations actually made the code faster. See Section 8.1.3,
“The MySQL Benchmark Suite”.
We also perform additional integration and nonfunctional testing of the latest MySQL version in our internal production environment. Integration testing is done with different connectors, storage engines, replication modes, backup, partitioning, stored programs, and so forth in various combinations. Additional nonfunctional testing is done in areas of performance, concurrency, stress, high volume, upgrade and downgrade.
2.4.3.2. Choosing a Distribution Format
After choosing which version of MySQL to install, you should decide whether to use a binary distribution or a source distribution. In most cases, you should probably use a binary distribution, if one exists for your platform. Binary distributions are available in native format for many platforms, such as RPM files for Linux or PKG package installers for Mac OS X or Solaris. Distributions also are available as Zip archives or compressed tar files.
Reasons to choose a binary distribution include the following:
• Binary distributions generally are easier to install than source distributions.
• To satisfy different user requirements, we provide several servers in binary distributions. mysqld is an optimized server that is a smaller, faster binary. mysqld-debug is compiled with debugging support.
Each of these servers is compiled from the same source distribution, though with different configuration options. All native MySQL clients can connect to servers from either MySQL version.
Under some circumstances, you may be better off installing MySQL from a source distribution:
• You want to install MySQL at some explicit location. The standard binary distributions are ready to run at any installation location, but you might require even more flexibility to place MySQL components where you want.
• You want to configure mysqld to ensure that features are available that might not be included in the standard binary distributions. Here is a list of the most common extra options that you may want to use to ensure feature availability:
--with-berkeley-db (not available on all platforms)
--with-libwrap
Page 69
Choosing Which MySQL Distribution to Install
49
--with-named-z-libs (this is done for some of the binaries)
--with-debug[=full] [122]
• You want to configure mysqld without some features that are included in the standard binary distributions. For example, distributions normally are compiled with support for all character sets. If you want a smaller MySQL server, you can recompile it with support for only the character sets you need.
• You want to use the latest sources from one of the Bazaar repositories to have access to all current bugfixes. For example, if you have found a bug and reported it to the MySQL development team, the bugfix is committed to the source repository and you can access it there. The bugfix does not appear in a release until a release actually is issued.
• You want to read (or modify) the C and C++ code that makes up MySQL. For this purpose, you should get a source distribution, because the source code is always the ultimate manual.
• Source distributions contain more tests and examples than binary distributions.
2.4.3.3. How and When Updates Are Released
MySQL is evolving quite rapidly and we want to share new developments with other MySQL users. We try to produce a new release whenever we have new and useful features that others also seem to have a need for.
We also try to help users who request features that are easy to implement. We take note of what our licensed users want, and we especially take note of what our support customers want and try to help them in this regard.
No one is required to download a new release. The Release Notes help you determine whether the new release has something you really want.
We use the following policy when updating MySQL:
• Enterprise Server releases are meant to appear every 18 months, supplemented by quarterly service packs and monthly rapid updates. Community Server releases are meant to appear 2–3 times per year.
• Releases are issued within each series. For each release, the last number in the version is one more than the previous release within the same series.
• Binary distributions for some platforms are made by us for major releases. Other people may make binary distributions for other systems, but probably less frequently.
• We make fixes available as soon as we have identified and corrected small or noncritical but annoying bugs. The fixes are available in source form immediately from our public Bazaar repositories, and are included in the next release.
• If by any chance a security vulnerability or critical bug is found in a release, our policy is to fix it in a new release as soon as possible. (We would like other companies to do this, too!)
2.4.3.4. MySQL Binaries Compiled by Oracle Corporation
Oracle Corporation provides a set of binary distributions of MySQL. In addition to binaries provided in platform-specific package formats, we offer binary distributions for a number of platforms in the form of compressed tar files (.tar.gz files). See Section 2.9, “Standard MySQL Installation from a Binary
Distribution”. For Windows distributions, see Section 2.10, “Installing MySQL on Microsoft Windows”.
If you want to compile MySQL from a source distribution, see Section 2.17, “Installing MySQL from
Source”. To compile a debug version of MySQL, see Section 2.17.3, “MySQL Source-Configuration Options” for options that enable debugging.
Page 70
How to Get MySQL
50
2.5. How to Get MySQL
Check our downloads page at http://dev.mysql.com/downloads/ for information about the current version of MySQL and for downloading instructions. For a complete up-to-date list of MySQL download mirror sites, see http://dev.mysql.com/downloads/mirrors.html. You can also find information there about becoming a MySQL mirror site and how to report a bad or out-of-date mirror.
To obtain the latest development source, see Section 2.17.2, “Installing MySQL from a Development
Source Tree”.
2.6. Verifying Package Integrity Using MD5 Checksums or GnuPG
After you have downloaded the MySQL package that suits your needs and before you attempt to install it, you should make sure that it is intact and has not been tampered with. There are three means of integrity checking:
• MD5 checksums
• Cryptographic signatures using GnuPG, the GNU Privacy Guard
• For RPM packages, the built-in RPM integrity verification mechanism The following sections describe how to use these methods. If you notice that the MD5 checksum or GPG signatures do not match, first try to download the
respective package one more time, perhaps from another mirror site.
2.6.1. Verifying the MD5 Checksum
After you have downloaded a MySQL package, you should make sure that its MD5 checksum matches the one provided on the MySQL download pages. Each package has an individual checksum that you can verify against the package that you downloaded. The correct MD5 checksum is listed on the downloads page for each MySQL product, and you will compare it against the MD5 checksum of the file (product) that you download.
Each operating system and setup offers its own version of tools for checking the MD5 checksum. Typically the command is named md5sum, or it may be named md5, and some operating systems do not ship it at all. On Linux, it is part of the GNU Text Utilities package, which is available for a wide range of platforms. You can also download the source code from http://www.gnu.org/software/textutils/. If you have OpenSSL installed, you can use the command openssl md5 package_name instead. A Windows implementation of the md5 command line utility is available from http://www.fourmilab.ch/
md5/. winMd5Sum is a graphical MD5 checking tool that can be obtained from http://www.nullriver.com/ index/products/winmd5sum. Our Microsoft Windows examples will assume the name md5.exe.
Linux and Microsoft Windows examples:
shell> md5sum mysql-standard-5.0.96-linux-i686.tar.gz aaab65abbec64d5e907dcd41b8699945 mysql-standard-5.0.96-linux-i686.tar.gz
shell> md5.exe mysql-installer-community-5.0.96.msi aaab65abbec64d5e907dcd41b8699945 mysql-installer-community-5.0.96.msi
You should verify that the resulting checksum (the string of hexadecimal digits) matches the one displayed on the download page immediately below the respective package.
Note
Make sure to verify the checksum of the archive file (for example, the .zip,
.tar.gz, or .msi file) and not of the files that are contained inside of the
archive. In other words, verify the file before extracting its contents.
Page 71
Signature Checking Using GnuPG
51
2.6.2. Signature Checking Using GnuPG
Another method of verifying the integrity and authenticity of a package is to use cryptographic signatures. This is more reliable than using MD5 checksums, but requires more work.
We sign MySQL downloadable packages with GnuPG (GNU Privacy Guard). GnuPG is an Open Source alternative to the well-known Pretty Good Privacy (PGP) by Phil Zimmermann. See http://
www.gnupg.org/ for more information about GnuPG and how to obtain and install it on your system.
Most Linux distributions ship with GnuPG installed by default. For more information about GnuPG, see
http://www.openpgp.org/.
To verify the signature for a specific package, you first need to obtain a copy of our public GPG build key, which you can download from http://pgp.mit.edu/. The key that you want to obtain is named
mysql-build@oss.oracle.com. Alternatively, you can cut and paste the key directly from the
following text:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: PGP Universal 2.9.1 (Build 347)
mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3 RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3 BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q2TXlTUUwgUmVs ZWFzZSBFbmdpbmVlcmluZyA8bXlzcWwtYnVpbGRAb3NzLm9yYWNsZS5jb20+iGYE ExECACYCGyMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAUCTnc+KgUJE/sCFQAKCRCM cY07UHLh9SbMAJ4l1+qBz2BZNSGCZwwA6YbhGPC7FwCgp8z5TzIw4YQuL5NGJ/sy 0oSazqmJASIEEAECAAwFAk53QS4FAwASdQAACgkQlxC4m8pXrXwJ8Qf/be/UO9mq foc2sMyhwMpN4/fdBWwfLkA12FXQDOQMvwH9HsmEjnfUgYKXschZRi+DuHXe1P7l 8G2aQLubhBsQf9ejKvRFTzuWMQkdIq+6Koulxv6ofkCcv3d1xtO2W7nb5yxcpVBP rRfGFGebJvZa58DymCNgyGtAU6AOz4veavNmI2+GIDQsY66+tYDvZ+CxwzdYu+HD V9HmrJfc6deM0mnBn7SRjqzxJPgoTQhihTav6q/R5/2p5NvQ/H84OgS6GjosfGc2 duUDzCP/kheMRKfzuyKCOHQPtJuIj8++gfpHtEU7IDUX1So3c9n0PdpeBvclsDbp RnCNxQWU4mBot7kCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/lxaZo JYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRiRjd1 DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE7zaD 5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fmLe11 EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p/1oI Dznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqqa8CG rRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSafanFv wFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOWI39E cyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42LmuQT5N dKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt926s/y mfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZWhe7 0YGNPw1yjWJT1IhUBBgRAgAMBQJOdz3tBQkT+wG4ABIHZUdQRwABAQkQjHGNO1By 4fUUmwCbBYr2+bBEn/L2BOcnw9Z/QFWuhRMAoKVgCFm5fadQ3Afi+UQlAcOphrnJ =Eto8
-----END PGP PUBLIC KEY BLOCK-----
To import the build key into your personal public GPG keyring, use gpg --import. For example, if you have saved the key in a file named mysql_pubkey.asc, the import command looks like this:
shell> gpg --import mysql_pubkey.asc gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported gpg: Total number processed: 1 gpg: imported: 1 gpg: no ultimately trusted keys found
You can also download the key from the public keyserver using the public key id, 5072E1F5:
shell> gpg --recv-keys 5072E1F5 gpg: requesting key 5072E1F5 from hkp server keys.gnupg.net gpg: key 5072E1F5: "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Page 72
Signature Checking Using GnuPG
52
1 new user ID gpg: key 5072E1F5: "MySQL Release Engineering <mysql-build@oss.oracle.com>" 53 new signatures gpg: no ultimately trusted keys found gpg: Total number processed: 1 gpg: new user IDs: 1 gpg: new signatures: 53
If you want to import the key into your RPM configuration to validate RPM install packages, you should be able to import the key directly:
shell> rpm --import mysql_pubkey.asc
If you experience problems or require RPM specific information, see Section 2.6.4, “Signature
Checking Using RPM.
After you have downloaded and imported the public build key, download your desired MySQL package and the corresponding signature, which also is available from the download page. The signature file has the same name as the distribution file with an .asc extension, as shown by the examples in the following table.
Table 2.1. MySQL Package and Signature Files for Source files
File Type File Name
Distribution file mysql-standard-5.0.96-linux-i686.tar.gz Signature file mysql-standard-5.0.96-linux-i686.tar.gz.asc
Make sure that both files are stored in the same directory and then run the following command to verify the signature for the distribution file:
shell> gpg --verify package_name.asc
If the downloaded package is valid, you will see a "Good signature" similar to:
shell> gpg --verify mysql-standard-5.0.96-linux-i686.tar.gz.asc gpg: Signature made Tue 01 Feb 2011 02:38:30 AM CST using DSA key ID 5072E1F5 gpg: Good signature from "MySQL Release Engineering <mysql-build@oss.oracle.com>"
The Good signature message indicates that the file signature is valid, when compared to the signature listed on our site. But you might also see warnings, like so:
shell> gpg --verify mysql-standard-5.0.96-linux-i686.tar.gz.asc gpg: Signature made Wed 23 Jan 2013 02:25:45 AM PST using DSA key ID 5072E1F5 gpg: checking the trustdb gpg: no ultimately trusted keys found gpg: Good signature from "MySQL Release Engineering <mysql-build@oss.oracle.com>" gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
That is normal, as they depend on your setup and configuration. Here are explanations for these warnings:
gpg: no ultimately trusted keys found: This means that the specific key is not "ultimately trusted" by you or your web of trust, which is okay for the purposes of verifying file signatures.
WARNING: This key is not certified with a trusted signature! There is no indication that the signature belongs to the owner.: This refers to your level of trust in your belief that you possess our real public key. This is a personal decision. Ideally, a MySQL developer would hand you the key in person, but more commonly, you downloaded it. Was the download tampered with? Probably not, but this decision is up to you. Setting up a web of trust is one method for trusting them.
See the GPG documentation for more information on how to work with public keys.
Page 73
Signature Checking Using Gpg4win for Windows
53
2.6.3. Signature Checking Using Gpg4win for Windows
The Section 2.6.2, “Signature Checking Using GnuPG section describes how to verify MySQL downloads using GPG. That guide also applies to Microsoft Windows, but another option is to use a GUI tool like Gpg4win. You may use a different tool but our examples are based on Gpg4win, and utilize its bundled Kleopatra GUI.
Download and install Gpg4win, and then load Kleopatra. The dialog should look similar to:
Figure 2.1. Initial screen after loading Kleopatra
Next, add the MySQL Release Engineering certificate. Do this by clicking File, Lookup Certificates on Server. Type "Mysql Release Engineering" into the search box and press Search.
Figure 2.2. Finding the MySQL Release Engineering certificate
Page 74
Signature Checking Using Gpg4win for Windows
54
Select the "MySQL Release Engineering" certificate. The Fingerprint and Key-ID must be "5072E1F5", or choose Details... to confirm the certificate is valid. Now, import it by clicking Import. An import dialog will be displayed, choose Okay, and this certificate will now be listed under the Imported Certificates tab.
Next, configure the trust level for our certificate. Select our certificate, then from the main menu select
Certificates, Change Owner Trust.... We suggest choosing I believe checks are very accurate for our
certificate, as otherwise you might not be able to verify our signature. Select I believe checks are very
accurate and then press OK.
Figure 2.3. Changing the Trust level
Next, verify the downloaded MySQL package file. This requires files for both the packaged file, and the signature. The signature file must have the same name as the packaged file but with an appended
.asc extension, as shown by the example in the following table. The signature is linked to on the
downloads page for each MySQL product. You must create the .asc file with this signature.
Table 2.2. MySQL Package and Signature Files for MySQL Installer for Microsoft Windows
File Type File Name
Distribution file mysql-installer-community-5.0.96.msi Signature file mysql-installer-community-5.0.96.msi.asc
Make sure that both files are stored in the same directory and then run the following command to verify the signature for the distribution file. Either drag and drop the signature (.asc) file into Kleopatra, or load the dialog from File, Decrypt/Verify Files..., and then choose either the .msi or .asc file.
Page 75
Signature Checking Using Gpg4win for Windows
55
Figure 2.4. The Decrypt/Verify Files dialog
Click Decrypt/Verify to check the file. The two most common results will look like the following, and although the yellow warning looks problematic, the following means that the file check passed with success. You may now run this installer.
Page 76
Signature Checking Using Gpg4win for Windows
56
Figure 2.5. The Decrypt/Verify Results: Good
Seeing a red "The signature is bad" error means the file is invalid. Do not execute the MSI file if you see this error.
Page 77
Signature Checking Using RPM
57
Figure 2.6. The Decrypt/Verify Results: Bad
The Section 2.6.2, “Signature Checking Using GnuPG section explains why you probably don't see a green Good signature result.
2.6.4. Signature Checking Using RPM
For RPM packages, there is no separate signature. RPM packages have a built-in GPG signature and MD5 checksum. You can verify a package by running the following command:
shell> rpm --checksig package_name.rpm
Example:
shell> rpm --checksig MySQL-server-5.0.96-0.glibc23.i386.rpm MySQL-server-5.0.96-0.glibc23.i386.rpm: md5 gpg OK
Note
If you are using RPM 4.1 and it complains about (GPG) NOT OK (MISSING
KEYS: GPG#5072e1f5), even though you have imported the MySQL public
build key into your own GPG keyring, you need to import the key into the RPM keyring first. RPM 4.1 no longer uses your personal GPG keyring (or GPG itself). Rather, RPM maintains a separate keyring because it is a system-wide application and a user's GPG public keyring is a user-specific file. To import the MySQL public key into the RPM keyring, first obtain the key, then use rpm --
import to import the key. For example:
Page 78
Installation Layouts
58
shell> gpg --export -a 5072e1f5 > 5072e1f5.asc shell> rpm --import 5072e1f5.asc
Alternatively, rpm also supports loading the key directly from a URL, and you can use this manual page:
shell> rpm --import http://dev.mysql.com/doc/refman/5.0/en/checking-gpg-signature.html
If you need to obtain the MySQL public key, see Section 2.6.2, “Signature Checking Using GnuPG.
2.7. Installation Layouts
This section describes the default layout of the directories created by installing binary or source distributions provided by Oracle Corporation. A distribution provided by another vendor might use a layout different from those shown here.
For MySQL 5.0 on Windows, the default installation directory is C:\Program Files\MySQL\MySQL
Server 5.0. (Some Windows users prefer to install in C:\mysql, the directory that formerly was
used as the default. However, the layout of the subdirectories remains the same.) The installation directory has the following subdirectories:
Table 2.3. MySQL Installation Layout for Windows
Directory Contents of Directory
bin Client programs and the mysqld server data Log files, databases examples Example programs and scripts include Include (header) files lib Libraries scripts Utility scripts share Miscellaneous support files, including error messages,
character set files, sample configuration files, SQL for database installation
Installations created from our Linux RPM distributions result in files under the following system directories:
Table 2.4. MySQL Installation Layout for Linux RPM
Directory Contents of Directory
/usr/bin Client programs and scripts /usr/sbin The mysqld server /var/lib/mysql Log files, databases /usr/share/info Manual in Info format /usr/share/man Unix man pages /usr/include/mysql Include (header) files /usr/lib/mysql Libraries /usr/share/mysql Miscellaneous support files, including error messages,
character set files, sample configuration files, SQL for database installation
/usr/share/sql-bench Benchmarks
Page 79
Compiler-Specific Build Characteristics
59
On Unix, a tar file binary distribution is installed by unpacking it at the installation location you choose (typically /usr/local/mysql) and creates the following directories in that location:
Table 2.5. MySQL Installation Layout for Generic Unix/Linux Binary Package
Directory Contents of Directory
bin Client programs and the mysqld server data Log files, databases docs Manual in Info format man Unix manual pages include Include (header) files lib Libraries scripts mysql_install_db share/mysql Miscellaneous support files, including error messages,
character set files, sample configuration files, SQL for database installation
sql-bench Benchmarks
By default, when you install MySQL after compiling it from a source distribution, the installation step installs files under /usr/local. Components are installed in the directories shown in the following table. To configure particular installation locations, use the options described at Section 2.17.3,
“MySQL Source-Configuration Options”.
Table 2.6. MySQL Layout for Installation from Source
Directory Contents of Directory
bin Client programs and scripts include/mysql Include (header) files Docs Manual in Info format man Unix manual pages lib/mysql Libraries libexec The mysqld server share/mysql Miscellaneous support files, including error messages, character
set files, sample configuration files, SQL for database installation
sql-bench Benchmarks var Log files, databases
Within its installation directory, the layout of a source installation differs from that of a binary installation in the following ways:
• The mysqld server is installed in the libexec directory rather than in the bin directory.
• The data directory is var rather than data.
mysql_install_db is installed in the bin directory rather than in the scripts directory.
• The header file and library directories are include/mysql and lib/mysql rather than include and lib.
To create your own binary installation from a compiled source distribution, execute the scripts/
make_binary_distribution script from the top directory of the source distribution.
2.8. Compiler-Specific Build Characteristics
Page 80
Standard MySQL Installation from a Binary Distribution
60
In some cases, the compiler used to build MySQL affects the features available for use. The notes in this section apply for binary distributions provided by Oracle Corporation or that you compile yourself from source.
icc (Intel C++ Compiler) Builds
A server built with icc has these characteristics:
• SSL support is not included.
2.9. Standard MySQL Installation from a Binary Distribution
The next several sections cover the installation of MySQL on platforms where we offer packages using the native packaging format of the respective platform. (This is also known as performing a binary installation.) However, binary distributions of MySQL are available for many other platforms as well. See Section 2.16, “Installing MySQL from Generic Binaries on Other Unix-Like Systems”, for generic installation instructions for these packages that apply to all platforms.
See Section 2.4, “Notes for MySQL Community Server”, for more information on what other binary distributions are available and how to obtain them.
2.10. Installing MySQL on Microsoft Windows
A native Windows distribution of MySQL has been available since version 3.21 and represents a sizable percentage of the daily downloads of MySQL. This section describes the process for installing MySQL on Windows.
Note
If you are upgrading MySQL from an existing installation older than MySQL
4.1.5, you must first perform the procedure described in Section 2.10.6,
“Upgrading MySQL on Windows”.
To run MySQL on Windows, you need the following:
• A Windows operating system such as XP, Vista, and Server 2003. Newer versions of Windows than these are not supported. Windows 95/98/ME/2000 and versions of Windows older than these are no longer supported. For supported platform information, see http://www.mysql.com/support/
supportedplatforms/database.html.
A Windows operating system permits you to run the MySQL server as a service. See
Section 2.10.4.7, “Starting MySQL as a Windows Service”.
Generally, you should install MySQL on Windows using an account that has administrator rights. Otherwise, you may encounter problems with certain operations such as editing the PATH environment variable or accessing the Service Control Manager.
• TCP/IP protocol support.
• Enough space on the hard drive to unpack, install, and create the databases in accordance with your requirements (generally a minimum of 200 megabytes is recommended.)
For a list of limitations within the Windows version of MySQL, see Section E.7.6, “Windows Platform
Limitations”.
There may also be other requirements, depending on how you plan to use MySQL:
• If you plan to connect to the MySQL server using ODBC, you need a Connector/ODBC driver. See
Chapter 20, Connectors and APIs.
Page 81
Choosing An Installation Package
61
• If you need tables with a size larger than 4GB, install MySQL on an NTFS or newer file system. Do not forget to use MAX_ROWS and AVG_ROW_LENGTH when you create tables. See Section 13.1.10,
CREATE TABLE Syntax”.
MySQL for Windows is available in several distribution formats:
• Binary distributions are available that contain a setup program that installs everything you need so that you can start the server immediately. Another binary distribution format contains an archive that you simply unpack in the installation location and then configure yourself. For details, see
Section 2.10.1, “Choosing An Installation Package”.
• The source distribution contains all the code and support files for building the executables using the Visual Studio compiler system.
Generally speaking, you should use a binary distribution that includes an installer. It is simpler to use than the others, and you need no additional tools to get MySQL up and running. The installer for the Windows version of MySQL, combined with a GUI Configuration Wizard, automatically installs MySQL, creates an option file, starts the server, and secures the default user accounts.
Caution
Using virus scanning software such as Norton/Symantec Anti-Virus on directories containing MySQL data and temporary tables can cause issues, both in terms of the performance of MySQL and the virus-scanning software mis­identifying the contents of the files as containing spam. This is because of the fingerprinting mechanism used by the virus scanning software, and the way in which MySQL rapidly updates different files, which may be identified as a potential security risk.
After installing MySQL Server, it is recommended that you disable virus scanning on the main directory (datadir [446]) being used to store your MySQL table data. There is usually a system built into the virus scanning software to permit certain directories to be specifically ignored during virus scanning.
In addition, by default, MySQL creates temporary files in the standard Windows temporary directory. To prevent the temporary files also being scanned, you should configure a separate temporary directory for MySQL temporary files and add this to the virus scanning exclusion list. To do this, add a configuration option for the tmpdir [424] parameter to your my.ini configuration file. For more information, see Section 2.10.4.2, “Creating an Option File”.
The following section describes how to install MySQL on Windows using a binary distribution. To use an installation package that does not include an installer, follow the procedure described in
Section 2.10.4, “Installing MySQL on Microsoft Windows Using a noinstall Zip Archive”. To install
using a source distribution, see Section 2.10.8, “Installing MySQL from Source on Windows”. MySQL distributions for Windows can be downloaded from http://dev.mysql.com/downloads/. See
Section 2.5, “How to Get MySQL”.
2.10.1. Choosing An Installation Package
For MySQL 5.0, there are three installation package formats to choose from when installing MySQL on Windows:
The Essentials package. This package has a file name similar to mysql-essential-5.0.96-
win32.msi and contains the minimum set of files needed to install MySQL on Windows, including
the Configuration Wizard. This package does not include optional components such as the embedded server and benchmark suite.
Page 82
Installing MySQL on Microsoft Windows Using an MSI Package
62
The Complete package. This package has a file name similar to mysql-5.0.96-win32.zip and contains all files needed for a complete Windows installation, including the Configuration Wizard. This package includes optional components such as the embedded server and benchmark suite.
The no-install archive. This package has a file name similar to mysql-noinstall-5.0.96-
win32.zip and contains all the files found in the Complete install package, with the exception of the
Configuration Wizard. This package does not include an automated installer, and must be manually installed and configured.
The Essentials package is recommended for most users. It is provided as an .msi file for use with the Windows Installer. The Complete and Noinstall distributions are packaged as Zip archives. To use them, you must have a tool that can unpack .zip files.
Your choice of install package affects the installation process you must follow. If you choose to install either an Essentials or Complete install package, see Section 2.10.2, “Installing MySQL on Microsoft
Windows Using an MSI Package”. If you choose to install a Noinstall archive, see Section 2.10.4, “Installing MySQL on Microsoft Windows Using a noinstall Zip Archive”.
2.10.2. Installing MySQL on Microsoft Windows Using an MSI Package
New MySQL users can use the MySQL Installation Wizard and MySQL Configuration Wizard to install MySQL on Windows. These are designed to install and configure MySQL in such a way that new users can immediately get started using MySQL.
The MySQL Installation Wizard and MySQL Configuration Wizard are available in the Essentials and Complete install packages. They are recommended for most standard MySQL installations. Exceptions include users who need to install multiple instances of MySQL on a single server host and advanced users who want complete control of server configuration.
2.10.2.1. Using the MySQL Installation Wizard
MySQL Installation Wizard is an installer for the MySQL server that uses the latest installer technologies for Microsoft Windows. The MySQL Installation Wizard, in combination with the MySQL Configuration Wizard, enables a user to install and configure a MySQL server that is ready for use immediately after installation.
The MySQL Installation Wizard is the standard installer for all MySQL server distributions, version
4.1.5 and higher. Users of previous versions of MySQL need to shut down and remove their existing
MySQL installations manually before installing MySQL with the MySQL Installation Wizard. See
Section 2.10.2.1.6, “Upgrading MySQL with the Installation Wizard”, for more information on upgrading
from a previous version. The Microsoft Windows Installer (MSI) is the standard for application installations on Windows 2000
and later versions. The MySQL Installation Wizard makes use of this technology to provide a smoother and more flexible installation process.
The Microsoft Windows Installer Engine was updated with the release of Windows XP; those using a previous version of Windows can reference this Microsoft Knowledge Base article for information on upgrading to the latest version of the Windows Installer Engine.
In addition, Microsoft has introduced the WiX (Windows Installer XML) toolkit, which is the first highly acknowledged Open Source project from Microsoft. We have switched to WiX because it is an Open Source project and it enables us to handle the complete Windows installation process in a flexible manner using scripts.
Improving the MySQL Installation Wizard depends on the support and feedback of users. If you find that the MySQL Installation Wizard is lacking some feature important to you, or if you discover a bug, please report it in our bugs database using the instructions given in Section 1.7, “How to Report Bugs
or Problems”.
Page 83
Installing MySQL on Microsoft Windows Using an MSI Package
63
2.10.2.1.1. Downloading and Starting the MySQL Installation Wizard
MySQL installation packages can be downloaded from http://dev.mysql.com/downloads/. If the package you download is contained within a Zip archive, you need to extract the archive first.
Note
If you are installing on Windows Vista or newer, it is best to open a network port for MySQL to use before beginning the installation. To do this, first ensure that you are logged in as an Administrator, then go to the Control Panel and double-click the Windows Firewall icon. Choose the Allow a program
through Windows Firewall option and click the Add port button. Enter MySQL into the Name text box and 3306 (or other port of your choice) into
the Port number text box. Also ensure that the TCP protocol radio button is selected. If you wish, you can also limit access to the MySQL server by choosing the Change scope button. Confirm your choices by clicking the OK button. If you do not open a port prior to installation, you cannot configure the MySQL server immediately after installation. Additionally, when running the MySQL Installation Wizard on Windows Vista or newer, ensure that you are logged in as a user with administrative rights.
The process for starting the wizard depends on the contents of the installation package you download. If there is a setup.exe file present, double-click it to start the installation process. If there is an .msi file present, double-click it to start the installation process.
2.10.2.1.2. Choosing an Installation Type
There are three installation types available: Typical, Complete, and Custom.
Page 84
Installing MySQL on Microsoft Windows Using an MSI Package
64
The Typical installation type installs the MySQL server, the mysql command-line client, and the command-line utilities. The command-line clients and utilities include mysqldump, myisamchk, and several other tools to help you manage the MySQL server.
The Complete installation type installs all components included in the installation package. The full installation package includes components such as the embedded server library, the benchmark suite, support scripts, and documentation.
The Custom installation type gives you complete control over which packages you wish to install and the installation path that is used. See Section 2.10.2.1.3, “The Custom Installation Dialog”, for more information on performing a custom install.
If you choose the Typical or Complete installation types and click the Next button, you advance to the confirmation screen to verify your choices and begin the installation. If you choose the Custom installation type and click the Next button, you advance to the custom installation dialog, described in
Section 2.10.2.1.3, “The Custom Installation Dialog”.
2.10.2.1.3. The Custom Installation Dialog
If you wish to change the installation path or the specific components that are installed by the MySQL Installation Wizard, choose the Custom installation type.
Page 85
Installing MySQL on Microsoft Windows Using an MSI Package
65
A tree view on the left side of the custom install dialog lists all available components. Components that are not installed have a red X icon; components that are installed have a gray icon. To change whether a component is installed, click that component's icon and choose a new option from the drop-down list that appears.
You can change the default installation path by clicking the Change... button to the right of the displayed installation path.
After choosing your installation components and installation path, click the Next button to advance to the confirmation dialog.
2.10.2.1.4. The Confirmation Dialog
Once you choose an installation type and optionally choose your installation components, you advance to the confirmation dialog. Your installation type and installation path are displayed for you to review.
Page 86
Installing MySQL on Microsoft Windows Using an MSI Package
66
To install MySQL if you are satisfied with your settings, click the Install button. To change your settings, click the Back button. To exit the MySQL Installation Wizard without installing MySQL, click the Cancel button.
After installation is complete, you have the option of registering with the MySQL Web site. Registration gives you access to post in the MySQL forums at forums.mysql.com, along with the ability to report bugs at bugs.mysql.com and to subscribe to our newsletter. The final screen of the installer provides a summary of the installation and gives you the option to launch the MySQL Configuration Wizard, which you can use to create a configuration file, install the MySQL service, and configure security settings.
2.10.2.1.5. Changes Made by MySQL Installation Wizard
Once you click the Install button, the MySQL Installation Wizard begins the installation process and makes certain changes to your system which are described in the sections that follow.
Changes to the Registry
The MySQL Installation Wizard creates one Windows registry key in a typical install situation, located in
HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB.
The MySQL Installation Wizard creates a key named after the major version of the server that is being installed, such as MySQL Server 5.0. It contains two string values, Location and Version. The
Location string contains the path to the installation directory. In a default installation it contains C: \Program Files\MySQL\MySQL Server 5.0\. The Version string contains the release number.
For example, for an installation of MySQL Server 5.0.96, the key contains a value of 5.0.96. These registry keys are used to help external tools identify the installed location of the MySQL server,
preventing a complete scan of the hard-disk to determine the installation path of the MySQL server.
Page 87
MySQL Server Instance Configuration Wizard
67
The registry keys are not required to run the server, and if you install MySQL using the noinstall Zip archive, the registry keys are not created.
Changes to the Start Menu
The MySQL Installation Wizard creates a new entry in the Windows Start menu under a common MySQL menu heading named after the major version of MySQL that you have installed. For example, if you install MySQL 5.0, the MySQL Installation Wizard creates a MySQL Server 5.0 section in the Start menu.
The following entries are created within the new Start menu section:
• MySQL Command-Line Client: This is a shortcut to the mysql command-line client and is configured to connect as the root user. The shortcut prompts for a root user password when you connect.
• MySQL Server Instance Config Wizard: This is a shortcut to the MySQL Configuration Wizard. Use this shortcut to configure a newly installed server, or to reconfigure an existing server.
• MySQL Documentation: This is a link to the MySQL server documentation that is stored locally in the MySQL server installation directory. This option is not available when the MySQL server is installed using the Essentials installation package.
Changes to the File System
The MySQL Installation Wizard by default installs the MySQL 5.0 server to C:\Program
Files\MySQL\MySQL Server 5.0, where Program Files is the default location for applications
in your system, and 5.0 is the major version of your MySQL server. This is the recommended location for the MySQL server, replacing the former default location C:\mysql.
By default, all MySQL applications are stored in a common directory at C:\Program Files\MySQL, where Program Files is the default location for applications in your Windows installation. A typical MySQL installation on a developer machine might look like this:
C:\Program Files\MySQL\MySQL Server 5.0 C:\Program Files\MySQL\MySQL Workbench 5.1 OSS
This approach makes it easier to manage and maintain all MySQL applications installed on a particular system.
2.10.2.1.6. Upgrading MySQL with the Installation Wizard
The MySQL Installation Wizard can perform server upgrades automatically using the upgrade capabilities of MSI. That means you do not need to remove a previous installation manually before installing a new release. The installer automatically shuts down and removes the previous MySQL service before installing the new version.
Automatic upgrades are available only when upgrading between installations that have the same major and minor version numbers. For example, you can upgrade automatically from MySQL 5.0.5 to MySQL
5.0.6, but not from MySQL 4.1 to MySQL 5.0.
See Section 2.10.6, “Upgrading MySQL on Windows”.
2.10.3. MySQL Server Instance Configuration Wizard
The MySQL Server Instance Configuration Wizard helps automate the process of configuring your server. It creates a custom MySQL configuration file (my.ini or my.cnf) by asking you a series of questions and then applying your responses to a template to generate the configuration file that is tuned to your installation.
The MySQL Server Instance Configuration Wizard is included with the MySQL 5.0 server. The MySQL Server Instance Configuration Wizard is only available for Windows.
Page 88
MySQL Server Instance Configuration Wizard
68
2.10.3.1. Starting the MySQL Server Instance Configuration Wizard
The MySQL Server Instance Configuration Wizard is normally started as part of the installation process. You should only need to run the MySQL Server Instance Configuration Wizard again when you need to change the configuration parameters of your server.
If you chose not to open a port prior to installing MySQL on Windows Vista or newer, you can choose to use the MySQL Server Configuration Wizard after installation. However, you must open a port in the Windows Firewall. To do this see the instructions given in Section 2.10.2.1.1, “Downloading and
Starting the MySQL Installation Wizard”. Rather than opening a port, you also have the option of
adding MySQL as a program that bypasses the Windows Firewall. One or the other option is sufficient —you need not do both. Additionally, when running the MySQL Server Configuration Wizard on Windows Vista or newer, ensure that you are logged in as a user with administrative rights.
You can launch the MySQL Configuration Wizard by clicking the MySQL Server Instance Config Wizard entry in the MySQL section of the Windows Start menu.
Alternatively, you can navigate to the bin directory of your MySQL installation and launch the
MySQLInstanceConfig.exe file directly.
The MySQL Server Instance Configuration Wizard places the my.ini file in the installation directory for the MySQL server. This helps associate configuration files with particular server instances.
To ensure that the MySQL server knows where to look for the my.ini file, an argument similar to this is passed to the MySQL server as part of the service installation:
--defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini"
Here, C:\Program Files\MySQL\MySQL Server 5.0 is replaced with the installation path to the MySQL Server. The --defaults-file [240] option instructs the MySQL server to read the specified file for configuration options when it starts.
Page 89
MySQL Server Instance Configuration Wizard
69
Apart from making changes to the my.ini file by running the MySQL Server Instance Configuration Wizard again, you can modify it by opening it with a text editor and making any necessary changes. You can also modify the server configuration with the http://www.mysql.com/products/administrator/ utility. For more information about server configuration, see Section 5.1.3, “Server Command Options”.
MySQL clients and utilities such as the mysql and mysqldump command-line clients are not able to locate the my.ini file located in the server installation directory. To configure the client and utility applications, create a new my.ini file in the Windows installation directory (for example, C:
\WINDOWS).
Under Windows Server 2003, Windows Server 2000 and Windows XP, MySQL Server Instance Configuration Wizard will configure MySQL to work as a Windows service. To start and stop MySQL you use the Services application that is supplied as part of the Windows Administrator Tools.
2.10.3.2. Choosing a Maintenance Option
If the MySQL Server Instance Configuration Wizard detects an existing configuration file, you have the option of either reconfiguring your existing server, or removing the server instance by deleting the configuration file and stopping and removing the MySQL service.
To reconfigure an existing server, choose the Re-configure Instance option and click the Next button. Any existing configuration file is not overwritten, but renamed (within the same directory) using a timestamp (Windows) or sequential number (Linux). To remove the existing server instance, choose the Remove Instance option and click the Next button.
If you choose the Remove Instance option, you advance to a confirmation window. Click the Execute button. The MySQL Server Configuration Wizard stops and removes the MySQL service, and then deletes the configuration file. The server installation and its data folder are not removed.
If you choose the Re-configure Instance option, you advance to the Configuration Type dialog where you can choose the type of installation that you wish to configure.
2.10.3.3. Choosing a Configuration Type
When you start the MySQL Server Instance Configuration Wizard for a new MySQL installation, or choose the Re-configure Instance option for an existing installation, you advance to the Configuration Type dialog.
Page 90
MySQL Server Instance Configuration Wizard
70
There are two configuration types available: Detailed Configuration and Standard Configuration. The Standard Configuration option is intended for new users who want to get started with MySQL quickly without having to make many decisions about server configuration. The Detailed Configuration option is intended for advanced users who want more fine-grained control over server configuration.
If you are new to MySQL and need a server configured as a single-user developer machine, the Standard Configuration should suit your needs. Choosing the Standard Configuration option causes the MySQL Configuration Wizard to set all configuration options automatically with the exception of Service Options and Security Options.
The Standard Configuration sets options that may be incompatible with systems where there are existing MySQL installations. If you have an existing MySQL installation on your system in addition to the installation you wish to configure, the Detailed Configuration option is recommended.
To complete the Standard Configuration, please refer to the sections on Service Options and Security Options in Section 2.10.3.10, “The Service Options Dialog”, and Section 2.10.3.11, “The Security
Options Dialog”, respectively.
2.10.3.4. The Server Type Dialog
There are three different server types available to choose from. The server type that you choose affects the decisions that the MySQL Server Instance Configuration Wizard makes with regard to memory, disk, and processor usage.
Page 91
MySQL Server Instance Configuration Wizard
71
• Developer Machine: Choose this option for a typical desktop workstation where MySQL is intended only for personal use. It is assumed that many other desktop applications are running. The MySQL server is configured to use minimal system resources.
• Server Machine: Choose this option for a server machine where the MySQL server is running alongside other server applications such as FTP, email, and Web servers. The MySQL server is configured to use a moderate portion of the system resources.
• Dedicated MySQL Server Machine: Choose this option for a server machine that is intended to run only the MySQL server. It is assumed that no other applications are running. The MySQL server is configured to use all available system resources.
Note
By selecting one of the preconfigured configurations, the values and settings of various options in your my.cnf or my.ini will be altered accordingly. The default values and options as described in the reference manual may therefore be different to the options and values that were created during the execution of the configuration wizard.
2.10.3.5. The Database Usage Dialog
The Database Usage dialog enables you to indicate the storage engines that you expect to use when creating MySQL tables. The option you choose determines whether the InnoDB storage engine is available and what percentage of the server resources are available to InnoDB.
Page 92
MySQL Server Instance Configuration Wizard
72
• Multifunctional Database: This option enables both the InnoDB and MyISAM storage engines and divides resources evenly between the two. This option is recommended for users who use both storage engines on a regular basis.
• Transactional Database Only: This option enables both the InnoDB and MyISAM storage engines, but dedicates most server resources to the InnoDB storage engine. This option is recommended for users who use InnoDB almost exclusively and make only minimal use of MyISAM.
• Non-Transactional Database Only: This option disables the InnoDB storage engine completely and dedicates all server resources to the MyISAM storage engine. This option is recommended for users who do not use InnoDB.
The Configuration Wizard uses a template to generate the server configuration file. The Database Usage dialog sets one of the following option strings:
Multifunctional Database: MIXED Transactional Database Only: INNODB Non-Transactional Database Only: MYISAM
When these options are processed through the default template (my-template.ini) the result is:
Multifunctional Database: default-storage-engine=InnoDB _myisam_pct=50
Transactional Database Only: default-storage-engine=InnoDB _myisam_pct=5
Non-Transactional Database Only: default-storage-engine=MyISAM
Page 93
MySQL Server Instance Configuration Wizard
73
_myisam_pct=100 skip-innodb
The _myisam_pct value is used to calculate the percentage of resources dedicated to MyISAM. The remaining resources are allocated to InnoDB.
2.10.3.6. The InnoDB Tablespace Dialog
Some users may want to locate the InnoDB tablespace files in a different location than the MySQL server data directory. Placing the tablespace files in a separate location can be desirable if your system has a higher capacity or higher performance storage device available, such as a RAID storage system.
To change the default location for the InnoDB tablespace files, choose a new drive from the drop-down list of drive letters and choose a new path from the drop-down list of paths. To create a custom path, click the ... button.
If you are modifying the configuration of an existing server, you must click the Modify button before you change the path. In this situation you must move the existing tablespace files to the new location manually before starting the server.
2.10.3.7. The Concurrent Connections Dialog
To prevent the server from running out of resources, it is important to limit the number of concurrent connections to the MySQL server that can be established. The Concurrent Connections dialog enables you to choose the expected usage of your server, and sets the limit for concurrent connections accordingly. It is also possible to set the concurrent connection limit manually.
Page 94
MySQL Server Instance Configuration Wizard
74
• Decision Support (DSS)/OLAP: Choose this option if your server does not require a large number of concurrent connections. The maximum number of connections is set at 100, with an average of 20 concurrent connections assumed.
• Online Transaction Processing (OLTP): Choose this option if your server requires a large number of concurrent connections. The maximum number of connections is set at 500.
• Manual Setting: Choose this option to set the maximum number of concurrent connections to the server manually. Choose the number of concurrent connections from the drop-down box provided, or enter the maximum number of connections into the drop-down box if the number you desire is not listed.
2.10.3.8. The Networking and Strict Mode Options Dialog
Use the Networking Options dialog to enable or disable TCP/IP networking and to configure the port number that is used to connect to the MySQL server.
Page 95
MySQL Server Instance Configuration Wizard
75
TCP/IP networking is enabled by default. To disable TCP/IP networking, uncheck the box next to the Enable TCP/IP Networking option.
Port 3306 is used by default. To change the port used to access MySQL, choose a new port number from the drop-down box or type a new port number directly into the drop-down box. If the port number you choose is in use, you are prompted to confirm your choice of port number.
Set the Server SQL Mode to either enable or disable strict mode. Enabling strict mode (default) makes MySQL behave more like other database management systems. If you run applications that rely on
MySQL's old “forgiving” behavior, make sure to either adapt those applications or to disable strict mode. For more information about strict mode, see Section 5.1.7, “Server SQL Modes”.
2.10.3.9. The Character Set Dialog
The MySQL server supports multiple character sets and it is possible to set a default server character set that is applied to all tables, columns, and databases unless overridden. Use the Character Set dialog to change the default character set of the MySQL server.
Page 96
MySQL Server Instance Configuration Wizard
76
• Standard Character Set: Choose this option if you want to use latin1 as the default server character set. latin1 is used for English and many Western European languages.
• Best Support For Multilingualism: Choose this option if you want to use utf8 as the default server character set. This is a Unicode character set that can store characters from many different languages.
• Manual Selected Default Character Set / Collation: Choose this option if you want to pick the server's default character set manually. Choose the desired character set from the provided drop-down list.
2.10.3.10. The Service Options Dialog
On Windows platforms, the MySQL server can be installed as a Windows service. When installed this way, the MySQL server can be started automatically during system startup, and even restarted automatically by Windows in the event of a service failure.
The MySQL Server Instance Configuration Wizard installs the MySQL server as a service by default, using the service name MySQL. If you do not wish to install the service, uncheck the box next to the Install As Windows Service option. You can change the service name by picking a new service name from the drop-down box provided or by entering a new service name into the drop-down box.
Note
Service names can include any legal character except forward (/) or backward (\) slashes, and must be less than 256 characters long.
Warning
If you are installing multiple versions of MySQL onto the same machine, you must choose a different service name for each version that you install. If you
Page 97
MySQL Server Instance Configuration Wizard
77
do not choose a different service for each installed version then the service manager information will be inconsistent and this will cause problems when you try to uninstall a previous version.
If you have already installed multiple versions using the same service name, you must manually edit the contents of the HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\Services parameters within the Windows registry to
update the association of the service name with the correct server version. Typically, when installing multiple versions you create a service name based on
the version information. For example, you might install MySQL 5.x as mysql5, or specific versions such as MySQL 5.0.56 as mysql50056.
To install the MySQL server as a service but not have it started automatically at startup, uncheck the box next to the Launch the MySQL Server Automatically option.
2.10.3.11. The Security Options Dialog
It is strongly recommended that you set a root password for your MySQL server, and the MySQL Server Instance Configuration Wizard requires by default that you do so. If you do not wish to set a
root password, uncheck the box next to the Modify Security Settings option.
To set the root password, enter the desired password into both the New root password and Confirm boxes. If you are reconfiguring an existing server, you need to enter the existing root password into the Current root password box.
To permit root logins from across the network, check the box next to the Enable root access from remote machines option. This decreases the security of your root account.
Page 98
MySQL Server Instance Configuration Wizard
78
To create an anonymous user account, check the box next to the Create An Anonymous Account option. Creating an anonymous account can decrease server security and cause login and permission difficulties. For this reason, it is not recommended.
2.10.3.12. The Confirmation Dialog
The final dialog in the MySQL Server Instance Configuration Wizard is the Confirmation Dialog. To start the configuration process, click the Execute button. To return to a previous dialog, click the Back button. To exit the MySQL Server Instance Configuration Wizard without configuring the server, click the Cancel button.
After you click the Execute button, the MySQL Server Instance Configuration Wizard performs a series of tasks and displays the progress onscreen as the tasks are performed.
The MySQL Server Instance Configuration Wizard first determines configuration file options based on your choices using a template prepared by MySQL developers and engineers. This template is named
my-template.ini and is located in your server installation directory.
Wizard creates and starts the service. If you are reconfiguring an existing service, the MySQL Server Instance Configuration Wizard restarts the service to apply your configuration changes.
If you chose to set a root password, the MySQL Configuration Wizard connects to the server, sets your new root password, and applies any other security settings you may have selected.
After the MySQL Server Instance Configuration Wizard has completed its tasks, it displays a summary. Click the Finish button to exit the MySQL Server Configuration Wizard.
Page 99
Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
79
2.10.4. Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
Users who are installing from the Noinstall package can use the instructions in this section to manually install MySQL. The process for installing MySQL from a Zip archive is as follows:
1. Extract the archive to the desired install directory
2. Create an option file
3. Choose a MySQL server type
4. Start the MySQL server
5. Secure the default user accounts This process is described in the sections that follow.
2.10.4.1. Extracting the Install Archive
To install MySQL manually, do the following:
1. If you are upgrading from a previous version please refer to Section 2.10.6, “Upgrading MySQL on
Windows”, before beginning the upgrade process.
2. Make sure that you are logged in as a user with administrator privileges.
3. Choose an installation location. Traditionally, the MySQL server is installed in C:\mysql. The MySQL Installation Wizard installs MySQL under C:\Program Files\MySQL. If you do not install MySQL at C:\mysql, you must specify the path to the install directory during startup or in an option file. See Section 2.10.4.2, “Creating an Option File”.
4. Extract the install archive to the chosen installation location using your preferred Zip archive tool. Some tools may extract the archive to a folder within your chosen installation location. If this occurs, you can move the contents of the subfolder into the chosen installation location.
2.10.4.2. Creating an Option File
If you need to specify startup options when you run the server, you can indicate them on the command line or place them in an option file. For options that are used every time the server starts, you may find it most convenient to use an option file to specify your MySQL configuration. This is particularly true under the following circumstances:
• The installation or data directory locations are different from the default locations (C:\Program
Files\MySQL\MySQL Server 5.0 and C:\Program Files\MySQL\MySQL Server
5.0\data).
• You need to tune the server settings.
When the MySQL server starts on Windows, it looks for option files in several locations, such as the Windows directory, C:\, and the MySQL installation directory (for the full list of locations, see
Section 4.2.3.3, “Using Option Files”). The Windows directory typically is named something like C:
\WINDOWS. You can determine its exact location from the value of the WINDIR environment variable
using the following command:
shell> echo %WINDIR%
MySQL looks for options in each location first in the my.ini file, and then in the my.cnf file. However, to avoid confusion, it is best if you use only one file. If your PC uses a boot loader where C: is not the boot drive, your only option is to use the my.ini file. Whichever option file you use, it must be a plain text file.
Page 100
Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
80
You can also make use of the example option files included with your MySQL distribution; see
Section 5.1.2, “Server Configuration Defaults”.
An option file can be created and modified with any text editor, such as Notepad. For example, if MySQL is installed in E:\mysql and the data directory is in E:\mydata\data, you can create an option file containing a [mysqld] section to specify values for the basedir and datadir options:
[mysqld] # set basedir to your installation path basedir=E:/mysql # set datadir to the location of your data directory datadir=E:/mydata/data
Note that Windows path names are specified in option files using (forward) slashes rather than backslashes. If you do use backslashes, double them:
[mysqld] # set basedir to your installation path basedir=E:\\mysql # set datadir to the location of your data directory datadir=E:\\mydata\\data
The rules for use of backslash in option file values are given in Section 4.2.3.3, “Using Option Files”. On Windows, the MySQL installer places the data directory directly under the directory where you
install MySQL. If you would like to use a data directory in a different location, you should copy the entire contents of the data directory to the new location. For example, if MySQL is installed in C:
\Program Files\MySQL\MySQL Server 5.0, the data directory is by default in C:\Program Files\MySQL\MySQL Server 5.0\data. If you want to use E:\mydata as the data directory
instead, you must do two things:
1. Move the entire data directory and all of its contents from C:\Program Files\MySQL\MySQL
Server 5.0\data to E:\mydata.
2. Use a --datadir [404] option to specify the new data directory location each time you start the server.
2.10.4.3. Selecting a MySQL Server Type
The following table shows the available servers for Windows in MySQL 5.0.
Binary Description
mysqld-nt Optimized binary with named-pipe support mysqld Optimized binary without named-pipe support mysqld-debug Like mysqld-nt, but compiled with full debugging and automatic memory
allocation checking
All of the preceding binaries are optimized for modern Intel processors, but should work on any Intel i386-class or higher processor.
Each of the servers in a distribution support the same set of storage engines. The SHOW ENGINES statement displays which engines a given server supports.
All Windows MySQL 5.0 servers have support for symbolic linking of database directories. MySQL supports TCP/IP on all Windows platforms. MySQL servers on Windows support named pipes
as indicated in the following list. However, the default is to use TCP/IP regardless of platform. (Named pipes are slower than TCP/IP in many Windows configurations.)
Use of named pipes is subject to these conditions:
Loading...