home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2004 July / INTERNET119.ISO / pc / software / windows / building / mysql / data1.cab / Documentation / Docs / manual.txt < prev   
Encoding:
Text File  |  2004-02-11  |  2.9 MB  |  74,780 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1. START-INFO-DIR-ENTRY
  2. * mysql: (mysql).               MySQL documentation.
  3. END-INFO-DIR-ENTRY
  4.  
  5. Table of Contents
  6. *****************
  7.  
  8.  
  9. General Information
  10.   About This Manual
  11.     Conventions Used in This Manual
  12.   Overview of the MySQL Database Management System
  13.     History of MySQL
  14.     The Main Features of MySQL
  15.     MySQL Stability
  16.     How Big MySQL Tables Can Be
  17.     Year 2000 Compliance
  18.   Overview of MySQL AB
  19.     The Business Model and Services of MySQL AB
  20.       Support
  21.       Training and Certification
  22.       Consulting
  23.       Commercial Licenses
  24.       Partnering
  25.     Contact Information
  26.   MySQL Support and Licensing
  27.     Support Offered by MySQL AB
  28.     Copyrights and Licenses Used by MySQL
  29.     MySQL Licenses
  30.       Using the MySQL Software Under a Commercial License
  31.       Using the MySQL Software for Free Under GPL
  32.     MySQL AB Logos and Trademarks
  33.       The Original MySQL Logo
  34.       MySQL Logos that may be Used Without Written Permission
  35.       When You Need Written Permission to Use MySQL Logos
  36.       MySQL AB Partnership Logos
  37.       Using the Word `MySQL' in Printed Text or Presentations
  38.       Using the Word `MySQL' in Company and Product Names
  39.   MySQL Development Roadmap
  40.     MySQL 4.0 in a Nutshell
  41.       Features Available in MySQL 4.0
  42.       The Embedded MySQL Server
  43.     MySQL 4.1 in a Nutshell
  44.       Features Available in MySQL 4.1
  45.       Stepwise Rollout
  46.       Ready for Immediate Development Use
  47.     MySQL 5.0, The Next Development Release
  48.   MySQL and the Future (The TODO)
  49.     New Features Planned for 4.1
  50.     New Features Planned for 5.0
  51.     New Features Planned for 5.1
  52.     New Features Planned for the Near Future
  53.     New Features Planned for the Mid-Term Future
  54.     New Features We Don't Plan to Implement
  55.   MySQL Information Sources
  56.     MySQL Mailing Lists
  57.       The MySQL Mailing Lists
  58.       Asking Questions or Reporting Bugs
  59.       How to Report Bugs or Problems
  60.       Guidelines for Answering Questions on the Mailing List
  61.     MySQL Community Support on IRC (Internet Relay Chat)
  62.   MySQL Standards Compliance
  63.     What Standards MySQL Follows
  64.     Selecting SQL Modes
  65.     Running MySQL in ANSI Mode
  66.     MySQL Extensions to the SQL-92 Standard
  67.     MySQL Differences Compared to SQL-92
  68.       Subqueries
  69.       `SELECT INTO TABLE'
  70.       Transactions and Atomic Operations
  71.       Stored Procedures and Triggers
  72.       Foreign Keys
  73.       Views
  74.       `--' as the Start of a Comment
  75.     How MySQL Deals with Constraints
  76.       Constraint PRIMARY KEY / UNIQUE
  77.       Constraint `NOT NULL' and `DEFAULT' values
  78.       Constraint `ENUM' and `SET'
  79.     Known Errors and Design Deficiencies in MySQL
  80.       Errors in 3.23 Fixed in a Later MySQL Version
  81.       Errors in 4.0 Fixed in a Later MySQL Version
  82.       Open Bugs / Design Deficiencies in MySQL
  83.  
  84. Installing MySQL
  85.   General Installation Issues
  86.     Operating Systems Supported by MySQL
  87.     Choosing Which MySQL Distribution to Install
  88.       Choosing Which Version of MySQL to Install
  89.       Choosing a Distribution Format
  90.       How and When Updates Are Released
  91.       Release Philosophy--No Known Bugs in Releases
  92.       MySQL Binaries Compiled by MySQL AB
  93.     How to Get MySQL
  94.     Verifying Package Integrity Using MD5 Checksums or `GnuPG'
  95.     Installation Layouts
  96.   Standard MySQL Installation Using a Binary Distribution
  97.     Installing MySQL on Windows
  98.       Windows System Requirements
  99.       Installing a Windows Binary Distribution
  100.       Preparing the Windows MySQL Environment
  101.       Selecting a Windows Server
  102.       Starting the Server for the First Time
  103.       Starting MySQL from the Windows Command Line
  104.       Starting MySQL as a Windows Service
  105.       Running MySQL Client Programs on Windows
  106.       MySQL on Windows Compared to MySQL on Unix
  107.     Installing MySQL on Linux
  108.     Installing MySQL on Mac OS X
  109.     Installing MySQL on NetWare
  110.     Installing MySQL on HP-UX
  111.     Installing MySQL on Other Unix-like Systems
  112.   MySQL Installation Using a Source Distribution
  113.     Quick Source Installation Overview
  114.     Typical `configure' Options
  115.     Installing from the Development Source Tree
  116.     Dealing With Problems Compiling MySQL
  117.     MIT-pthreads Notes
  118.     Installing MySQL from Source on Windows
  119.       Building MySQL Using VC++
  120.       Creating a Windows Source Package from the Latest Development Source
  121.     Compiling MySQL Clients on Windows
  122.   Post-installation Setup and Testing
  123.     Windows Post-installation Procedures
  124.     Unix Post-installation Procedures
  125.       Problems Running `mysql_install_db'
  126.       Starting and Stopping MySQL Automatically
  127.       Starting and Troubleshooting the MySQL Server
  128.   Upgrading/Downgrading MySQL
  129.     Upgrading from Version 4.1 to 5.0
  130.     Upgrading from Version 4.0 to 4.1
  131.     Upgrading from Version 3.23 to 4.0
  132.     Upgrading from Version 3.22 to 3.23
  133.     Upgrading from Version 3.21 to 3.22
  134.     Upgrading from Version 3.20 to 3.21
  135.     Upgrading MySQL under Windows
  136.     Upgrading the Grant Tables
  137.     Copying MySQL Databases to Another Machine
  138.   Operating System Specific Notes
  139.     Linux Notes
  140.       Linux Operating System Notes
  141.       Linux Binary Distribution Notes
  142.       Linux Source Distribution Notes
  143.       Linux Post-installation Notes
  144.       Linux x86 Notes
  145.       Linux SPARC Notes
  146.       Linux Alpha Notes
  147.       Linux PowerPC Notes
  148.       Linux MIPS Notes
  149.       Linux IA-64 Notes
  150.     Mac OS X Notes
  151.       Mac OS X 10.x (Darwin)
  152.       Mac OS X Server 1.2 (Rhapsody)
  153.     Solaris Notes
  154.       Solaris 2.7/2.8 Notes
  155.       Solaris x86 Notes
  156.     BSD Notes
  157.       FreeBSD Notes
  158.       NetBSD Notes
  159.       OpenBSD 2.5 Notes
  160.       OpenBSD 2.8 Notes
  161.       BSD/OS Version 2.x Notes
  162.       BSD/OS Version 3.x Notes
  163.       BSD/OS Version 4.x Notes
  164.     Other Unix Notes
  165.       HP-UX Version 10.20 Notes
  166.       HP-UX Version 11.x Notes
  167.       IBM-AIX notes
  168.       SunOS 4 Notes
  169.       Alpha-DEC-UNIX Notes (Tru64)
  170.       Alpha-DEC-OSF/1 Notes
  171.       SGI Irix Notes
  172.       SCO Notes
  173.       SCO UnixWare Version 7.1.x Notes
  174.     OS/2 Notes
  175.     BeOS Notes
  176.   Perl Installation Notes
  177.     Installing Perl on Unix
  178.     Installing ActiveState Perl on Windows
  179.     Problems Using the Perl `DBI'/`DBD' Interface
  180.  
  181. MySQL Tutorial
  182.   Connecting to and Disconnecting from the Server
  183.   Entering Queries
  184.   Creating and Using a Database
  185.     Creating and Selecting a Database
  186.     Creating a Table
  187.     Loading Data into a Table
  188.     Retrieving Information from a Table
  189.       Selecting All Data
  190.       Selecting Particular Rows
  191.       Selecting Particular Columns
  192.       Sorting Rows
  193.       Date Calculations
  194.       Working with `NULL' Values
  195.       Pattern Matching
  196.       Counting Rows
  197.       Using More Than one Table
  198.   Getting Information About Databases and Tables
  199.   Using `mysql' in Batch Mode
  200.   Examples of Common Queries
  201.     The Maximum Value for a Column
  202.     The Row Holding the Maximum of a Certain Column
  203.     Maximum of Column per Group
  204.     The Rows Holding the Group-wise Maximum of a Certain Field
  205.     Using User Variables
  206.     Using Foreign Keys
  207.     Searching on Two Keys
  208.     Calculating Visits Per Day
  209.     Using `AUTO_INCREMENT'
  210.   Queries from the Twin Project
  211.     Find All Non-distributed Twins
  212.     Show a Table of Twin Pair Status
  213.   Using MySQL with Apache
  214.  
  215. Using MySQL Programs
  216.   Overview of MySQL Programs
  217.   Invoking MySQL Programs
  218.   Specifying Program Options
  219.     Using Options on the Command Line
  220.     Using Option Files
  221.     Using Environment Variables to Specify Options
  222.     Using Options to Set Program Variables
  223.  
  224. Database Administration
  225.   The MySQL Server and Server Startup Scripts
  226.     Overview of the Server-Side Scripts and Utilities
  227.     `mysqld-max', An Extended `mysqld' Server
  228.     `mysqld_safe', The Wrapper Around `mysqld'
  229.     `mysql.server', A Server Startup Script for Run Directories
  230.     `mysqld_multi', A Program for Managing Multiple MySQL Servers
  231.   Configuring MySQL
  232.     `mysqld' Command-line Options
  233.     The Server SQL Mode
  234.   General Security Issues
  235.     General Security Guidelines
  236.     Making MySQL Secure Against Attackers
  237.     Startup Options for `mysqld' Concerning Security
  238.     Security Issues with `LOAD DATA LOCAL'
  239.   The MySQL Access Privilege System
  240.     What the Privilege System Does
  241.     How the Privilege System Works
  242.     Privileges Provided by MySQL
  243.     Connecting to the MySQL Server
  244.     Access Control, Stage 1: Connection Verification
  245.     Access Control, Stage 2: Request Verification
  246.     Password Hashing in MySQL 4.1
  247.     Causes of `Access denied' Errors
  248.   MySQL User Account Management
  249.     MySQL Usernames and Passwords
  250.     When Privilege Changes Take Effect
  251.     Setting Up the Initial MySQL Privileges
  252.     Adding New Users to MySQL
  253.     Deleting Users from MySQL
  254.     Limiting user resources
  255.     Setting Up Passwords
  256.     Keeping Your Password Secure
  257.     Using Secure Connections
  258.       Basics
  259.       Requirements
  260.       Setting Up SSL Certificates for MySQL
  261.       SSL `GRANT' Options
  262.       SSL Command-line Options
  263.       Connecting to MySQL Remotely from Windows with SSH
  264.   Disaster Prevention and Recovery
  265.     Database Backups
  266.     Using `myisamchk' for Table Maintenance and Crash Recovery
  267.       `myisamchk' Invocation Syntax
  268.       General Options for `myisamchk'
  269.       Check Options for `myisamchk'
  270.       Repair Options for myisamchk
  271.       Other Options for `myisamchk'
  272.       `myisamchk' Memory Usage
  273.       Using `myisamchk' for Crash Recovery
  274.       How to Check Tables for Errors
  275.       How to Repair Tables
  276.       Table Optimization
  277.     Setting Up a Table Maintenance Regimen
  278.     Getting Information About a Table
  279.   MySQL Localization and International Usage
  280.     The Character Set Used for Data and Sorting
  281.       German character set
  282.     Non-English Error Messages
  283.     Adding a New Character Set
  284.     The Character Definition Arrays
  285.     String Collating Support
  286.     Multi-byte Character Support
  287.     Problems With Character Sets
  288.   The MySQL Log Files
  289.     The Error Log
  290.     The General Query Log
  291.     The Update Log
  292.     The Binary Log
  293.     The Slow Query Log
  294.     Log File Maintenance
  295.   Running Multiple MySQL Servers on the Same Machine
  296.     Running Multiple Servers on Windows
  297.       Starting Multiple Windows Servers at the Command Line
  298.       Starting Multiple Windows Servers as Services
  299.     Running Multiple Servers on Unix
  300.     Using Client Programs in a Multiple-Server Environment
  301.  
  302. Replication in MySQL
  303.   Introduction to Replication
  304.   Replication Implementation Overview
  305.   Replication Implementation Details
  306.   How to Set Up Replication
  307.   Upgrading a Replication Setup - Mixing Different MySQL Versions
  308.   Replication Features and Known Problems
  309.   Replication Startup Options
  310.   Replication FAQ
  311.   Troubleshooting Replication
  312.   Reporting Replication Bugs
  313.  
  314. MySQL Optimization
  315.   Optimization Overview
  316.     MySQL Design Limitations/Tradeoffs
  317.     Portability
  318.     What We Have Used MySQL For
  319.     The MySQL Benchmark Suite
  320.     Using Your Own Benchmarks
  321.   Optimizing `SELECT' Statements and Other Queries
  322.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  323.     Estimating Query Performance
  324.     Speed of `SELECT' Queries
  325.     How MySQL Optimizes `WHERE' Clauses
  326.     How MySQL Optimizes `OR' Clauses
  327.     How MySQL Optimizes `IS NULL'
  328.     How MySQL Optimizes `DISTINCT'
  329.     How MySQL Optimizes `LEFT JOIN' and `RIGHT JOIN'
  330.     How MySQL Optimizes `ORDER BY'
  331.     How MySQL Optimizes `LIMIT'
  332.     Speed of `INSERT' Queries
  333.     Speed of `UPDATE' Queries
  334.     Speed of `DELETE' Queries
  335.     Other Optimization Tips
  336.   Locking Issues
  337.     How MySQL Locks Tables
  338.     Table Locking Issues
  339.   Optimizing Database Structure
  340.     Design Choices
  341.     Get Your Data as Small as Possible
  342.     How MySQL Uses Indexes
  343.     Column Indexes
  344.     Multiple-Column Indexes
  345.     The MyISAM Key Cache
  346.       Shared Key Cache Access
  347.       Multiple Key Caches
  348.       Midpoint Insertion Strategy
  349.       Index Preloading
  350.       Key Cache Block Size
  351.       Restructuring a Key Cache
  352.     How MySQL Counts Open Tables
  353.     How MySQL Opens and Closes Tables
  354.     Drawbacks to Creating Large Numbers of Tables in the Same Database
  355.   Optimizing the MySQL Server
  356.     System/Compile Time and Startup Parameter Tuning
  357.     Tuning Server Parameters
  358.     How Compiling and Linking Affects the Speed of MySQL
  359.     How MySQL Uses Memory
  360.     How MySQL uses DNS
  361.     `SET' Syntax
  362.   Disk Issues
  363.     Using Symbolic Links
  364.       Using Symbolic Links for Databases on Unix
  365.       Using Symbolic Links for Tables on Unix
  366.       Using Symbolic Links for Databases on Windows
  367.  
  368. MySQL Client and Utility Programs
  369.   Overview of the Client-Side Scripts and Utilities
  370.   `mysql', The Command-line Tool
  371.     How to Run SQL Commands from a Text File
  372.   `mysqlcc', The MySQL Control Center
  373.   `mysqladmin', Administering a MySQL Server
  374.   `mysqlbinlog', Executing the queries from a binary log
  375.   Using `mysqlcheck' for Table Maintenance and Crash Recovery
  376.   `mysqldump', Dumping Table Structure and Data
  377.   `mysqlhotcopy', Copying MySQL Databases and Tables
  378.   `mysqlimport', Importing Data from Text Files
  379.   `mysqlshow', Showing Databases, Tables, and Columns
  380.   `myisampack', The MySQL Compressed Read-only Table Generator
  381.   `mysql_config', Get compile options for compiling clients
  382.   `perror', Explaining Error Codes
  383.  
  384. MySQL Language Reference
  385.  
  386. Language Structure
  387.   Literal Values
  388.     Strings
  389.     Numbers
  390.     Hexadecimal Values
  391.     Boolean Values
  392.     `NULL' Values
  393.   Database, Table, Index, Column, and Alias Names
  394.     Identifier Qualifiers
  395.     Identifier Case Sensitivity
  396.   User Variables
  397.   System Variables
  398.     Dynamic System Variables
  399.     Structured System Variables
  400.   Comment Syntax
  401.   Treatment of Reserved Words in MySQL
  402.  
  403. Column Types
  404.   Numeric Types
  405.   Date and Time Types
  406.     Y2K Issues and Date Types
  407.     The `DATETIME', `DATE', and `TIMESTAMP' Types
  408.     The `TIME' Type
  409.     The `YEAR' Type
  410.   String Types
  411.     The `CHAR' and `VARCHAR' Types
  412.     The `BLOB' and `TEXT' Types
  413.     The `ENUM' Type
  414.     The `SET' Type
  415.   Choosing the Right Type for a Column
  416.   Using Column Types from Other Database Engines
  417.   Column Type Storage Requirements
  418.  
  419. Functions and Operators
  420.   Non-Type-Specific Operators and Functions
  421.     Parentheses
  422.     Comparison Operators
  423.     Logical Operators
  424.     Control Flow Functions
  425.   String Functions
  426.     String Comparison Functions
  427.     Case-Sensitivity
  428.   Numeric Functions
  429.     Arithmetic Operations
  430.     Mathematical Functions
  431.   Date and Time Functions
  432.   Cast Functions
  433.   Other Functions
  434.     Bit Functions
  435.     Encryption Functions
  436.     Information Functions
  437.     Miscellaneous Functions
  438.   Functions and Modifiers for Use with `GROUP BY' Clauses
  439.     `GROUP BY' Functions
  440.     `GROUP BY' Modifiers
  441.     `GROUP BY' with Hidden Fields
  442.  
  443. SQL Statement Syntax
  444.   Data Manipulation Statements
  445.     `DELETE' Syntax
  446.     `DO' Syntax
  447.     `HANDLER' Syntax
  448.     `INSERT' Syntax
  449.       `INSERT ... SELECT' Syntax
  450.       `INSERT DELAYED' Syntax
  451.     `LOAD DATA INFILE' Syntax
  452.     `REPLACE' Syntax
  453.     `SELECT' Syntax
  454.       `JOIN' Syntax
  455.       `UNION' Syntax
  456.     Subquery Syntax
  457.       The Subquery as Scalar Operand
  458.       Comparisons Using Subqueries
  459.       Subqueries with `ANY', `IN', and `SOME'
  460.       Subqueries with `ALL'
  461.       Correlated Subqueries
  462.       `EXISTS' and `NOT EXISTS'
  463.       Row Subqueries
  464.       Subqueries in the `FROM' clause
  465.       Subquery Errors
  466.       Optimizing Subqueries
  467.       Rewriting Subqueries for Earlier MySQL Versions
  468.     `TRUNCATE' Syntax
  469.     `UPDATE' Syntax
  470.   Data Definition Statements
  471.     `ALTER DATABASE' Syntax
  472.     `ALTER TABLE' Syntax
  473.     `CREATE DATABASE' Syntax
  474.     `CREATE INDEX' Syntax
  475.     `CREATE TABLE' Syntax
  476.       Silent Column Specification Changes
  477.     `DROP DATABASE' Syntax
  478.     `DROP INDEX' Syntax
  479.     `DROP TABLE' Syntax
  480.     `RENAME TABLE' Syntax
  481.   Basic MySQL User Utility Statements
  482.     `DESCRIBE' Syntax (Get Information About Columns)
  483.     `USE' Syntax
  484.   MySQL Transactional and Locking Statements
  485.     `START TRANSACTION', `COMMIT', and `ROLLBACK' Syntax
  486.     Statements That Cannot Be Rolled Back
  487.     Statements That Cause an Implicit Commit
  488.     `SAVEPOINT' and `ROLLBACK TO SAVEPOINT' Syntax
  489.     `LOCK TABLES' and `UNLOCK TABLES' Syntax
  490.     `SET TRANSACTION' Syntax
  491.   Database Administration Statements
  492.     Account Management Statements
  493.       `GRANT' and `REVOKE' Syntax
  494.     Table Maintenance Statements
  495.       `ANALYZE TABLE' Syntax
  496.       `BACKUP TABLE' Syntax
  497.       `CHECK TABLE' Syntax
  498.       `CHECKSUM TABLE' Syntax
  499.       `OPTIMIZE TABLE' Syntax
  500.       `REPAIR TABLE' Syntax
  501.       `RESTORE TABLE' Syntax
  502.     `SHOW' Syntax
  503.       Retrieving Information about Database, Tables, Columns, and Indexes
  504.       `SHOW TABLE STATUS'
  505.       `SHOW STATUS'
  506.       `SHOW VARIABLES'
  507.       `SHOW [BDB] LOGS'
  508.       `SHOW PROCESSLIST'
  509.       `SHOW GRANTS'
  510.       `SHOW CREATE TABLE'
  511.       `SHOW WARNINGS | ERRORS'
  512.       `SHOW TABLE TYPES'
  513.       `SHOW PRIVILEGES'
  514.     Other Administrative Statements
  515.       `CACHE INDEX' Syntax
  516.       `FLUSH' Syntax
  517.       `KILL' Syntax
  518.       `LOAD INDEX INTO CACHE' Syntax
  519.       `PURGE MASTER LOGS' Syntax
  520.       `RESET' Syntax
  521.   Replication Statements
  522.     SQL Statements for Controlling Master Servers
  523.       `PURGE MASTER LOGS'
  524.       `RESET MASTER'
  525.       `SET SQL_LOG_BIN'
  526.       `SHOW BINLOG EVENTS'
  527.       `SHOW MASTER STATUS'
  528.       `SHOW MASTER LOGS'
  529.       `SHOW SLAVE HOSTS'
  530.     SQL Statements for Controlling Slave Servers
  531.       `CHANGE MASTER TO'
  532.       `LOAD DATA FROM MASTER'
  533.       `LOAD TABLE tbl_name FROM MASTER'
  534.       `MASTER_POS_WAIT()'
  535.       `RESET SLAVE'
  536.       `SET GLOBAL SQL_SLAVE_SKIP_COUNTER'
  537.       `SHOW SLAVE STATUS'
  538.       `START SLAVE'
  539.       `STOP SLAVE'
  540.   MySQL Full-text Search
  541.     Full-text Restrictions
  542.     Fine-tuning MySQL Full-text Search
  543.     Full-text Search TODO
  544.   MySQL Query Cache
  545.     How the Query Cache Operates
  546.     Query Cache Configuration
  547.     Query Cache Options in `SELECT'
  548.     Query Cache Status and Maintenance
  549.  
  550. MySQL Table Types
  551.   `MyISAM' Tables
  552.     Space Needed for Keys
  553.     `MyISAM' Table Formats
  554.       Static (Fixed-length) Table Characteristics
  555.       Dynamic Table Characteristics
  556.       Compressed Table Characteristics
  557.     `MyISAM' Table Problems
  558.       Corrupted `MyISAM' Tables
  559.       Clients is using or hasn't closed the table properly
  560.   `MERGE' Tables
  561.     `MERGE' Table Problems
  562.   `HEAP' Tables
  563.   `InnoDB' Tables
  564.     InnoDB Tables Overview
  565.     InnoDB in MySQL Version 3.23
  566.     InnoDB Startup Options
  567.     Creating InnoDB Tablespace
  568.       If Something Goes Wrong in Database Creation
  569.     Creating InnoDB Tables
  570.       Converting MyISAM Tables to InnoDB
  571.       `FOREIGN KEY' Constraints
  572.       Multiple tablespaces - putting each table into its own .ibd file
  573.     Adding and Removing InnoDB Data and Log Files
  574.     Backing up and Recovering an InnoDB Database
  575.       Forcing recovery
  576.       Checkpoints
  577.     Moving an InnoDB Database to Another Machine
  578.     InnoDB Transaction Model and Locking
  579.       InnoDB and `SET ... TRANSACTION ISOLATION LEVEL ...'
  580.       Consistent Non-Locking Read
  581.       Locking Reads `SELECT ... FOR UPDATE' and `SELECT ... LOCK IN SHARE MODE'
  582.       Next-key Locking: Avoiding the Phantom Problem
  583.       Locks Set by Different SQL Statements in `InnoDB'
  584.       Deadlock Detection and Rollback
  585.       An Example of How the Consistent Read Works in `InnoDB'
  586.       How to Cope With Deadlocks
  587.     Performance Tuning Tips
  588.       `SHOW INNODB STATUS' and the `InnoDB' Monitors
  589.     Implementation of Multi-versioning
  590.     Table and Index Structures
  591.       Physical Structure of an Index
  592.       Insert Buffering
  593.       Adaptive Hash Indexes
  594.       Physical Record Structure
  595.       How an `AUTO_INCREMENT' Column Works in InnoDB
  596.     File Space Management and Disk I/O
  597.       Disk I/O
  598.       File Space Management
  599.       Defragmenting a Table
  600.     Error Handling
  601.     Restrictions on InnoDB Tables
  602.     InnoDB Change History
  603.       MySQL/InnoDB-5.0.0, December 24, 2003
  604.       MySQL/InnoDB-4.0.17, December 17, 2003
  605.       MySQL/InnoDB-4.1.1, December 4, 2003
  606.       MySQL/InnoDB-4.0.16, October 22, 2003
  607.       MySQL/InnoDB-3.23.58, September 15, 2003
  608.       MySQL/InnoDB-4.0.15, September 10, 2003
  609.       MySQL/InnoDB-4.0.14, July 22, 2003
  610.       MySQL/InnoDB-3.23.57, June 20, 2003
  611.       MySQL/InnoDB-4.0.13, May 20, 2003
  612.       MySQL/InnoDB-4.1.0, April 3, 2003
  613.       MySQL/InnoDB-3.23.56, March 17, 2003
  614.       MySQL/InnoDB-4.0.12, March 18, 2003
  615.       MySQL/InnoDB-4.0.11, February 25, 2003
  616.       MySQL/InnoDB-4.0.10, February 4, 2003
  617.       MySQL/InnoDB-3.23.55, January 24, 2003
  618.       MySQL/InnoDB-4.0.9, January 14, 2003
  619.       MySQL/InnoDB-4.0.8, January 7, 2003
  620.       MySQL/InnoDB-4.0.7, December 26, 2002
  621.       MySQL/InnoDB-4.0.6, December 19, 2002
  622.       MySQL/InnoDB-3.23.54, December 12, 2002
  623.       MySQL/InnoDB-4.0.5, November 18, 2002
  624.       MySQL/InnoDB-3.23.53, October 9, 2002
  625.       MySQL/InnoDB-4.0.4, October 2, 2002
  626.       MySQL/InnoDB-4.0.3, August 28, 2002
  627.       MySQL/InnoDB-3.23.52, August 16, 2002
  628.       MySQL/InnoDB-4.0.2, July 10, 2002
  629.       MySQL/InnoDB-3.23.51, June 12, 2002
  630.       MySQL/InnoDB-3.23.50, April 23, 2002
  631.       MySQL/InnoDB-3.23.49, February 17, 2002
  632.       MySQL/InnoDB-3.23.48, February 9, 2002
  633.       MySQL/InnoDB-3.23.47, December 28, 2001
  634.       MySQL/InnoDB-4.0.1, December 23, 2001
  635.       MySQL/InnoDB-3.23.46, November 30, 2001
  636.       MySQL/InnoDB-3.23.45, November 23, 2001
  637.       MySQL/InnoDB-3.23.44, November 2, 2001
  638.       MySQL/InnoDB-3.23.43, October 4, 2001
  639.       MySQL/InnoDB-3.23.42, September 9, 2001
  640.       MySQL/InnoDB-3.23.41, August 13, 2001
  641.       MySQL/InnoDB-3.23.40, July 16, 2001
  642.       MySQL/InnoDB-3.23.39, June 13, 2001
  643.       MySQL/InnoDB-3.23.38, May 12, 2001
  644.     `InnoDB' Contact Information
  645.   `BDB' or `BerkeleyDB' Tables
  646.     Overview of `BDB' Tables
  647.     Installing `BDB'
  648.     `BDB' Startup Options
  649.     Characteristics of `BDB' Tables
  650.     Things We Need to Fix for `BDB' in the Near Future
  651.     Operating Systems Supported by `BDB'
  652.     Restrictions on `BDB' Tables
  653.     Errors That May Occur When Using `BDB' Tables
  654.   `ISAM' Tables
  655.  
  656. Introduction to MaxDB
  657.   History of MaxDB
  658.   Licensing and Support
  659.   Basic Concepts of MaxDB
  660.   Feature Differences between MaxDB and MySQL
  661.   Interoperability Features between MaxDB and MySQL
  662.   MaxDB-related Links
  663.   Reserved Words in MaxDB
  664.   Functions
  665.   Column Types
  666.  
  667. National Character Sets and Unicode
  668.   Character Sets and Collations in General
  669.   Character Sets and Collations in MySQL
  670.   Determining the Default Character Set and Collation
  671.     Server Character Set and Collation
  672.     Database Character Set and Collation
  673.     Table Character Set and Collation
  674.     Column Character Set and Collation
  675.     Examples of Character Set and Collation Assignment
  676.     Connection Character Sets and Collations
  677.     Character String Literal Character Set and Collation
  678.     `COLLATE' Clause in Various Parts of an SQL Query
  679.     `COLLATE' Clause Precedence
  680.     `BINARY' Operator
  681.     Some Special Cases Where the Collation Determination is Tricky
  682.     Collations Must Be for the Right Character Set
  683.     An example of the Effect of Collation
  684.   Operations Affected by Character Set Support
  685.     Result Strings
  686.     `CONVERT()'
  687.     `CAST()'
  688.     `SHOW CHARACTER SET'
  689.     `SHOW COLLATION'
  690.     `SHOW CREATE DATABASE'
  691.     `SHOW FULL COLUMNS'
  692.   Unicode Support
  693.   UTF8 for Metadata
  694.   Compatibility with Other DBMSs
  695.   New Character Set Configuration File format
  696.   National Character Set
  697.   Upgrading from MySQL 4.0
  698.     4.0 Character Sets and Corresponding 4.1 Character Set/Collation Pairs
  699.   The Character Sets and Collations that MySQL Supports
  700.     The Unicode Character Sets
  701.     Platform Specific Character Sets
  702.     Character Sets for South Europe and Middle East
  703.     The Asian Character Sets
  704.     The Baltic Character Sets
  705.     The Cyrillic Character Sets
  706.     The Central European Character Sets
  707.     The West European Character Sets
  708.  
  709. Spatial Extensions in MySQL
  710.   Introduction
  711.   The OpenGIS Geometry Model
  712.     The Geometry Class Hierarchy
  713.     Class `Geometry'
  714.     Class `Point'
  715.     Class `Curve'
  716.     Class `LineString'
  717.     Class `Surface'
  718.     Class `Polygon'
  719.     Class `GeometryCollection'
  720.     Class `MultiPoint'
  721.     Class `MultiCurve'
  722.     Class `MultiLineString'
  723.     Class `MultiSurface'
  724.     Class `MultiPolygon'
  725.   Supported Spatial Data Formats
  726.     Well-Known Text (WKT) Format
  727.     Well-Known Binary (WKB) Format
  728.   Creating a Spatially Enabled MySQL Database
  729.     MySQL Spatial Datatypes
  730.     Creating Spatial Values
  731.       Creating Geometry Values Using WKT Functions
  732.       Creating Geometry Values Using WKB Functions
  733.       Creating Geometry Values Using MySQL-Specific Functions
  734.     Creating Spatial Columns
  735.     Populating Spatial Columns
  736.     Fetching Spatial Data
  737.       Fetching Spatial Data in Internal Format
  738.       Fetching Spatial Data in WKT Format
  739.       Fetching Spatial Data in WKB Format
  740.   Analyzing Spatial Information
  741.     Geometry Format Conversion Functions
  742.     `Geometry' Functions
  743.       General Geometry Functions
  744.       `Point' Functions
  745.       `LineString' Functions
  746.       `MultiLineString' Functions
  747.       `Polygon' Functions
  748.       `MultiPolygon' Functions
  749.       `GeometryCollection' Functions
  750.     Functions That Create New Geometries from Existing Ones
  751.       Geometry Functions That Produce New Geometries
  752.       Spatial Operators
  753.     Functions for Testing Spatial Relations Between Geometric Objects
  754.     Relations on Geometry Minimal Bounding Rectangles (MBRs)
  755.     Functions That Test Spatial Relationships Between Geometries
  756.   Optimizing Spatial Analysis
  757.     Creating Spatial Indexes
  758.     Using a Spatial Index
  759.   MySQL Conformance and Compatibility
  760.     GIS Features That Are Not Yet Implemented
  761.  
  762. Stored Procedures and Functions
  763.   Stored Procedure Syntax
  764.     Maintaining Stored Procedures
  765.       `CREATE PROCEDURE' and `CREATE FUNCTION'
  766.       `ALTER PROCEDURE' and `ALTER FUNCTION'
  767.       `DROP PROCEDURE' and `DROP FUNCTION'
  768.       `SHOW CREATE PROCEDURE' and `SHOW CREATE FUNCTION'
  769.     `SHOW PROCEDURE STATUS' and `SHOW FUNCTION STATUS'
  770.     `CALL'
  771.     `BEGIN ... END' Compound Statement
  772.     `DECLARE' Statement
  773.     Variables in Stored Procedures
  774.       `DECLARE' Local Variables
  775.       Variable `SET' Statement
  776.       `SELECT ... INTO' Statement
  777.     Conditions and Handlers
  778.       `DECLARE' Conditions
  779.       `DECLARE' Handlers
  780.     Cursors
  781.       Declaring Cursors
  782.       Cursor `OPEN' Statement
  783.       Cursor `FETCH' Statement
  784.       Cursor `CLOSE' Statement
  785.     Flow Control Constructs
  786.       `IF' Statement
  787.       `CASE' Statement
  788.       `LOOP' Statement
  789.       `LEAVE' Statement
  790.       `ITERATE' Statement
  791.       `REPEAT' Statement
  792.       `WHILE' Statement
  793.  
  794. MySQL APIs
  795.   MySQL C API
  796.     C API Datatypes
  797.     C API Function Overview
  798.     C API Function Descriptions
  799.       `mysql_affected_rows()'
  800.       `mysql_change_user()'
  801.       `mysql_character_set_name()'
  802.       `mysql_close()'
  803.       `mysql_connect()'
  804.       `mysql_create_db()'
  805.       `mysql_data_seek()'
  806.       `mysql_debug()'
  807.       `mysql_drop_db()'
  808.       `mysql_dump_debug_info()'
  809.       `mysql_eof()'
  810.       `mysql_errno()'
  811.       `mysql_error()'
  812.       `mysql_escape_string()'
  813.       `mysql_fetch_field()'
  814.       `mysql_fetch_fields()'
  815.       `mysql_fetch_field_direct()'
  816.       `mysql_fetch_lengths()'
  817.       `mysql_fetch_row()'
  818.       `mysql_field_count()'
  819.       `mysql_field_seek()'
  820.       `mysql_field_tell()'
  821.       `mysql_free_result()'
  822.       `mysql_get_client_info()'
  823.       `mysql_get_client_version()'
  824.       `mysql_get_host_info()'
  825.       `mysql_get_proto_info()'
  826.       `mysql_get_server_info()'
  827.       `mysql_get_server_version()'
  828.       `mysql_info()'
  829.       `mysql_init()'
  830.       `mysql_insert_id()'
  831.       `mysql_kill()'
  832.       `mysql_list_dbs()'
  833.       `mysql_list_fields()'
  834.       `mysql_list_processes()'
  835.       `mysql_list_tables()'
  836.       `mysql_num_fields()'
  837.       `mysql_num_rows()'
  838.       `mysql_options()'
  839.       `mysql_ping()'
  840.       `mysql_query()'
  841.       `mysql_real_connect()'
  842.       `mysql_real_escape_string()'
  843.       `mysql_real_query()'
  844.       `mysql_reload()'
  845.       `mysql_row_seek()'
  846.       `mysql_row_tell()'
  847.       `mysql_select_db()'
  848.       `mysql_set_server_option()'
  849.       `mysql_shutdown()'
  850.       `mysql_sqlstate()'
  851.       `mysql_ssl_set()'
  852.       `mysql_stat()'
  853.       `mysql_store_result()'
  854.       `mysql_thread_id()'
  855.       `mysql_use_result()'
  856.       `mysql_warning_count()'
  857.       `mysql_commit()'
  858.       `mysql_rollback()'
  859.       `mysql_autocommit()'
  860.       `mysql_more_results()'
  861.       `mysql_next_result()'
  862.     C API Prepared Statements
  863.     C API Prepared Statement Datatypes
  864.     C API Prepared Statement Function Overview
  865.     C API Prepared Statement Function Descriptions
  866.       `mysql_bind_param()'
  867.       `mysql_bind_result()'
  868.       `mysql_execute()'
  869.       `mysql_fetch()'
  870.       `mysql_fetch_column()'
  871.       `mysql_get_metadata()'
  872.       `mysql_param_count()'
  873.       `mysql_param_result()'
  874.       `mysql_prepare()'
  875.       `mysql_send_long_data()'
  876.       `mysql_stmt_affected_rows()'
  877.       `mysql_stmt_close()'
  878.       `mysql_stmt_data_seek()'
  879.       `mysql_stmt_errno()'
  880.       `mysql_stmt_error()'
  881.       `mysql_stmt_free_result()'
  882.       `mysql_stmt_num_rows()'
  883.       `mysql_stmt_reset()'
  884.       `mysql_stmt_row_seek()'
  885.       `mysql_stmt_row_tell()'
  886.       `mysql_stmt_sqlstate()'
  887.       `mysql_stmt_store_result()'
  888.     C API Handling of Multiple Query Execution
  889.     C API Handling of Date and Time Values
  890.     C API Threaded Function Descriptions
  891.       `my_init()'
  892.       `mysql_thread_init()'
  893.       `mysql_thread_end()'
  894.       `mysql_thread_safe()'
  895.     C API Embedded Server Function Descriptions
  896.       `mysql_server_init()'
  897.       `mysql_server_end()'
  898.     Common questions and problems when using the C API
  899.       Why `mysql_store_result()' Sometimes Returns `NULL' After `mysql_query()' Returns Success
  900.       What Results You Can Get from a Query
  901.       How to Get the Unique ID for the Last Inserted Row
  902.       Problems Linking with the C API
  903.     Building Client Programs
  904.     How to Make a Threaded Client
  905.     libmysqld, the Embedded MySQL Server Library
  906.       Overview of the Embedded MySQL Server Library
  907.       Compiling Programs with `libmysqld'
  908.       Restrictions when using the Embedded MySQL Server
  909.       Using Option Files with the Embedded Server
  910.       Things left to do in Embedded Server (TODO)
  911.       A Simple Embedded Server Example
  912.       Licensing the Embedded Server
  913.   MySQL ODBC Support
  914.     How to Install MyODBC
  915.     How to Fill in the Various Fields in the ODBC Administrator Program
  916.     Connect parameters for MyODBC
  917.     How to Report Problems with MyODBC
  918.     Programs Known to Work with MyODBC
  919.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  920.     Reporting Problems with MyODBC
  921.   MySQL Java Connectivity (JDBC)
  922.   MySQL PHP API
  923.     Common Problems with MySQL and PHP
  924.   MySQL Perl API
  925.   MySQL C++ API
  926.     Borland C++
  927.   MySQL Python API
  928.   MySQL Tcl API
  929.   MySQL Eiffel Wrapper
  930.  
  931. Error Handling in MySQL
  932.   Error Returns
  933.  
  934. Extending MySQL
  935.   MySQL Internals
  936.     MySQL Threads
  937.     MySQL Test Suite
  938.       Running the MySQL Test Suite
  939.       Extending the MySQL Test Suite
  940.       Reporting Bugs in the MySQL Test Suite
  941.   Adding New Functions to MySQL
  942.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  943.     Adding a New User-defined Function
  944.       UDF Calling Sequences for simple functions
  945.       UDF Calling Sequences for aggregate functions
  946.       Argument Processing
  947.       Return Values and Error Handling
  948.       Compiling and Installing User-defined Functions
  949.     Adding a New Native Function
  950.   Adding New Procedures to MySQL
  951.     Procedure Analyse
  952.     Writing a Procedure
  953.  
  954. Problems and Common Errors
  955.   How to Determine What Is Causing Problems
  956.   Common Errors When Using MySQL
  957.     `Access denied' Error
  958.     `MySQL server has gone away' Error
  959.     `Can't connect to [local] MySQL server' Error
  960.     `Client does not support authentication protocol' error
  961.     `Host '...' is blocked' Error
  962.     `Too many connections' Error
  963.     `Some non-transactional changed tables couldn't be rolled back' Error
  964.     `Out of memory' Error
  965.     `Packet too large' Error
  966.     Communication Errors / Aborted Connection
  967.     `The table is full' Error
  968.     `Can't create/write to file' Error
  969.     `Commands out of sync' Error in Client
  970.     `Ignoring user' Error
  971.     `Table 'xxx' doesn't exist' Error
  972.     `Can't initialize character set xxx' error
  973.     File Not Found
  974.   Installation Related Issues
  975.     Problems When Linking with the MySQL Client Library
  976.     How to Run MySQL As a Normal User
  977.     Problems with File Permissions
  978.   Administration Related Issues
  979.     What To Do If MySQL Keeps Crashing
  980.     How to Reset a Forgotten Root Password
  981.     How MySQL Handles a Full Disk
  982.     Where MySQL Stores Temporary Files
  983.     How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'
  984.     Time Zone Problems
  985.   Query Related Issues
  986.     Case-Sensitivity in Searches
  987.     Problems Using `DATE' Columns
  988.     Problems with `NULL' Values
  989.     Problems with `alias'
  990.     Deleting Rows from Related Tables
  991.     Solving Problems with No Matching Rows
  992.     Problems with Floating-Point Comparison
  993.   Optimizer Related Issues
  994.     How to avoid table scan,,,
  995.   Table Definition Related Issues
  996.     Problems with `ALTER TABLE'.
  997.     How To Change the Order of Columns in a Table
  998.     TEMPORARY TABLE problems
  999.  
  1000. Credits
  1001.   Developers at MySQL AB
  1002.   Contributors to MySQL
  1003.   Documenters and translators
  1004.   Libraries used by and included with MySQL
  1005.   Packages that support MySQL
  1006.   Tools that were used to create MySQL
  1007.   Supporters of MySQL
  1008.  
  1009. MySQL Change History
  1010.   Changes in release 5.0.x (Development)
  1011.     Changes in release 5.0.1 (not released yet)
  1012.     Changes in release 5.0.0 (22 Dec 2003: Alpha)
  1013.   Changes in release 4.1.x (Alpha)
  1014.     Changes in release 4.1.2 (not released yet)
  1015.     Changes in release 4.1.1 (01 Dec 2003)
  1016.     Changes in release 4.1.0 (03 Apr 2003: Alpha)
  1017.   Changes in release 4.0.x (Production)
  1018.     Changes in release 4.0.19 (not released yet)
  1019.     Changes in release 4.0.18 (to be released soon)
  1020.     Changes in release 4.0.17 (14 Dec 2003)
  1021.     Changes in release 4.0.16 (17 Oct 2003)
  1022.     Changes in release 4.0.15 (03 Sep 2003)
  1023.     Changes in release 4.0.14 (18 Jul 2003)
  1024.     Changes in release 4.0.13 (16 May 2003)
  1025.     Changes in release 4.0.12 (15 Mar 2003: Production)
  1026.     Changes in release 4.0.11 (20 Feb 2003)
  1027.     Changes in release 4.0.10 (29 Jan 2003)
  1028.     Changes in release 4.0.9 (09 Jan 2003)
  1029.     Changes in release 4.0.8 (07 Jan 2003)
  1030.     Changes in release 4.0.7 (20 Dec 2002)
  1031.     Changes in release 4.0.6 (14 Dec 2002: Gamma)
  1032.     Changes in release 4.0.5 (13 Nov 2002)
  1033.     Changes in release 4.0.4 (29 Sep 2002)
  1034.     Changes in release 4.0.3 (26 Aug 2002: Beta)
  1035.     Changes in release 4.0.2 (01 Jul 2002)
  1036.     Changes in release 4.0.1 (23 Dec 2001)
  1037.     Changes in release 4.0.0 (Oct 2001: Alpha)
  1038.   Changes in release 3.23.x (Recent; still supported)
  1039.     Changes in release 3.23.59 (not released yet)
  1040.     Changes in release 3.23.58 (11 Sep 2003)
  1041.     Changes in release 3.23.57 (06 Jun 2003)
  1042.     Changes in release 3.23.56 (13 Mar 2003)
  1043.     Changes in release 3.23.55 (23 Jan 2003)
  1044.     Changes in release 3.23.54 (05 Dec 2002)
  1045.     Changes in release 3.23.53 (09 Oct 2002)
  1046.     Changes in release 3.23.52 (14 Aug 2002)
  1047.     Changes in release 3.23.51 (31 May 2002)
  1048.     Changes in release 3.23.50 (21 Apr 2002)
  1049.     Changes in release 3.23.49
  1050.     Changes in release 3.23.48 (07 Feb 2002)
  1051.     Changes in release 3.23.47 (27 Dec 2001)
  1052.     Changes in release 3.23.46 (29 Nov 2001)
  1053.     Changes in release 3.23.45 (22 Nov 2001)
  1054.     Changes in release 3.23.44 (31 Oct 2001)
  1055.     Changes in release 3.23.43 (04 Oct 2001)
  1056.     Changes in release 3.23.42 (08 Sep 2001)
  1057.     Changes in release 3.23.41 (11 Aug 2001)
  1058.     Changes in release 3.23.40
  1059.     Changes in release 3.23.39 (12 Jun 2001)
  1060.     Changes in release 3.23.38 (09 May 2001)
  1061.     Changes in release 3.23.37 (17 Apr 2001)
  1062.     Changes in release 3.23.36 (27 Mar 2001)
  1063.     Changes in release 3.23.35 (15 Mar 2001)
  1064.     Changes in release 3.23.34a
  1065.     Changes in release 3.23.34 (10 Mar 2001)
  1066.     Changes in release 3.23.33 (09 Feb 2001)
  1067.     Changes in release 3.23.32 (22 Jan 2001: Production)
  1068.     Changes in release 3.23.31 (17 Jan 2001)
  1069.     Changes in release 3.23.30 (04 Jan 2001)
  1070.     Changes in release 3.23.29 (16 Dec 2000)
  1071.     Changes in release 3.23.28 (22 Nov 2000: Gamma)
  1072.     Changes in release 3.23.27 (24 Oct 2000)
  1073.     Changes in release 3.23.26 (18 Oct 2000)
  1074.     Changes in release 3.23.25 (29 Sep 2000)
  1075.     Changes in release 3.23.24 (08 Sep 2000)
  1076.     Changes in release 3.23.23 (01 Sep 2000)
  1077.     Changes in release 3.23.22 (31 Jul 2000)
  1078.     Changes in release 3.23.21
  1079.     Changes in release 3.23.20
  1080.     Changes in release 3.23.19
  1081.     Changes in release 3.23.18
  1082.     Changes in release 3.23.17
  1083.     Changes in release 3.23.16
  1084.     Changes in release 3.23.15 (May 2000: Beta)
  1085.     Changes in release 3.23.14
  1086.     Changes in release 3.23.13
  1087.     Changes in release 3.23.12 (07 Mar 2000)
  1088.     Changes in release 3.23.11
  1089.     Changes in release 3.23.10
  1090.     Changes in release 3.23.9
  1091.     Changes in release 3.23.8 (02 Jan 2000)
  1092.     Changes in release 3.23.7 (10 Dec 1999)
  1093.     Changes in release 3.23.6
  1094.     Changes in release 3.23.5 (20 Oct 1999)
  1095.     Changes in release 3.23.4 (28 Sep 1999)
  1096.     Changes in release 3.23.3
  1097.     Changes in release 3.23.2 (09 Aug 1999)
  1098.     Changes in release 3.23.1
  1099.     Changes in release 3.23.0 (05 Aug 1999: Alpha)
  1100.   Changes in release 3.22.x (Old; discontinued)
  1101.     Changes in release 3.22.35
  1102.     Changes in release 3.22.34
  1103.     Changes in release 3.22.33
  1104.     Changes in release 3.22.32 (14 Feb 2000)
  1105.     Changes in release 3.22.31
  1106.     Changes in release 3.22.30
  1107.     Changes in release 3.22.29 (02 Jan 2000)
  1108.     Changes in release 3.22.28 (20 Oct 1999)
  1109.     Changes in release 3.22.27
  1110.     Changes in release 3.22.26 (16 Sep 1999)
  1111.     Changes in release 3.22.25
  1112.     Changes in release 3.22.24 (05 Jul 1999)
  1113.     Changes in release 3.22.23 (08 Jun 1999)
  1114.     Changes in release 3.22.22 (30 Apr 1999)
  1115.     Changes in release 3.22.21
  1116.     Changes in release 3.22.20 (18 Mar 1999)
  1117.     Changes in release 3.22.19 (Mar 1999: Production)
  1118.     Changes in release 3.22.18
  1119.     Changes in release 3.22.17
  1120.     Changes in release 3.22.16 (Feb 1999: Gamma)
  1121.     Changes in release 3.22.15
  1122.     Changes in release 3.22.14
  1123.     Changes in release 3.22.13
  1124.     Changes in release 3.22.12
  1125.     Changes in release 3.22.11
  1126.     Changes in release 3.22.10
  1127.     Changes in release 3.22.9
  1128.     Changes in release 3.22.8
  1129.     Changes in release 3.22.7 (Sep 1998: Beta)
  1130.     Changes in release 3.22.6
  1131.     Changes in release 3.22.5
  1132.     Changes in release 3.22.4
  1133.     Changes in release 3.22.3
  1134.     Changes in release 3.22.2
  1135.     Changes in release 3.22.1 (Jun 1998: Alpha)
  1136.     Changes in release 3.22.0
  1137.   Changes in release 3.21.x
  1138.     Changes in release 3.21.33
  1139.     Changes in release 3.21.32
  1140.     Changes in release 3.21.31
  1141.     Changes in release 3.21.30
  1142.     Changes in release 3.21.29
  1143.     Changes in release 3.21.28
  1144.     Changes in release 3.21.27
  1145.     Changes in release 3.21.26
  1146.     Changes in release 3.21.25
  1147.     Changes in release 3.21.24
  1148.     Changes in release 3.21.23
  1149.     Changes in release 3.21.22
  1150.     Changes in release 3.21.21a
  1151.     Changes in release 3.21.21
  1152.     Changes in release 3.21.20
  1153.     Changes in release 3.21.19
  1154.     Changes in release 3.21.18
  1155.     Changes in release 3.21.17
  1156.     Changes in release 3.21.16
  1157.     Changes in release 3.21.15
  1158.     Changes in release 3.21.14b
  1159.     Changes in release 3.21.14a
  1160.     Changes in release 3.21.13
  1161.     Changes in release 3.21.12
  1162.     Changes in release 3.21.11
  1163.     Changes in release 3.21.10
  1164.     Changes in release 3.21.9
  1165.     Changes in release 3.21.8
  1166.     Changes in release 3.21.7
  1167.     Changes in release 3.21.6
  1168.     Changes in release 3.21.5
  1169.     Changes in release 3.21.4
  1170.     Changes in release 3.21.3
  1171.     Changes in release 3.21.2
  1172.     Changes in release 3.21.0
  1173.   Changes in release 3.20.x
  1174.     Changes in release 3.20.18
  1175.     Changes in release 3.20.17
  1176.     Changes in release 3.20.16
  1177.     Changes in release 3.20.15
  1178.     Changes in release 3.20.14
  1179.     Changes in release 3.20.13
  1180.     Changes in release 3.20.11
  1181.     Changes in release 3.20.10
  1182.     Changes in release 3.20.9
  1183.     Changes in release 3.20.8
  1184.     Changes in release 3.20.7
  1185.     Changes in release 3.20.6
  1186.     Changes in release 3.20.3
  1187.     Changes in release 3.20.0
  1188.   Changes in release 3.19.x
  1189.     Changes in release 3.19.5
  1190.     Changes in release 3.19.4
  1191.     Changes in release 3.19.3
  1192.  
  1193. Porting to Other Systems
  1194.   Debugging a MySQL server
  1195.     Compiling MYSQL for Debugging
  1196.     Creating Trace Files
  1197.     Debugging mysqld under gdb
  1198.     Using a Stack Trace
  1199.     Using Log Files to Find Cause of Errors in mysqld
  1200.     Making a Test Case If You Experience Table Corruption
  1201.   Debugging a MySQL client
  1202.   The DBUG Package
  1203.   Locking methods
  1204.   Comments about RTS threads
  1205.   Differences between different thread packages
  1206.  
  1207. Environment Variables
  1208.  
  1209. MySQL Regular Expressions
  1210.  
  1211. GNU General Public License
  1212.  
  1213. SQL command, type and function index
  1214.  
  1215. Concept Index
  1216.  
  1217.  
  1218. This is the Reference Manual for the `MySQL Database System'.  This
  1219. version refers to the 4.0.18 version of `MySQL Server' but it is also
  1220. applicable for any older version (such as 3.23 and 4.0-production) as
  1221. changes are always indicated. There are also references for version 5.0
  1222. (development).
  1223.  
  1224. General Information
  1225. *******************
  1226.  
  1227. The `MySQL' (R) software delivers a very fast, multi-threaded,
  1228. multi-user, and robust `SQL' (`Structured Query Language') database
  1229. server.  `MySQL Server' is intended for mission-critical, heavy-load
  1230. production systems as well as for embedding into mass-deployed software.
  1231. `MySQL' is a trademark of `MySQL AB'.
  1232.  
  1233. The `MySQL' software is `Dual Licensed'. Users can choose to use the
  1234. `MySQL' software as an `Open Source'/`Free Software' product under the
  1235. terms of the `GNU General Public License'
  1236. (`http://www.fsf.org/licenses/') or can purchase a standard commercial
  1237. license from `MySQL AB'.  *Note Licensing and Support::.
  1238.  
  1239. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1240. information about the `MySQL' software.
  1241.  
  1242. The following list describes some sections of particular interest in
  1243. this manual:
  1244.  
  1245.    * For information about the company behind the `MySQL Database
  1246.      Server', see *Note What is MySQL AB::.
  1247.  
  1248.    * For a discussion about the capabilities of the `MySQL Database
  1249.      Server', see *Note Features::.
  1250.  
  1251.    * For installation instructions, see *Note Installing::.
  1252.  
  1253.    * For tips on porting the `MySQL Database Software' to new
  1254.      architectures or operating systems, see *Note Porting::.
  1255.  
  1256.    * For information about upgrading from a Version 4.0 release, see
  1257.      *Note Upgrading-from-4.0::.
  1258.  
  1259.    * For information about upgrading from a Version 3.23 release, see
  1260.      *Note Upgrading-from-3.23::.
  1261.  
  1262.    * For information about upgrading from a Version 3.22 release, see
  1263.      *Note Upgrading-from-3.22::.
  1264.  
  1265.    * For a tutorial introduction to the `MySQL Database Server', see
  1266.      *Note Tutorial::.
  1267.  
  1268.    * For examples of `SQL' and benchmarking information, see the
  1269.      benchmarking directory (`sql-bench' in the distribution).
  1270.  
  1271.    * For a history of new features and bug fixes, see *Note News::.
  1272.  
  1273.    * For a list of currently known bugs and misfeatures, see *Note
  1274.      Bugs::.
  1275.  
  1276.    * For future plans, see *Note TODO::.
  1277.  
  1278.    * For a list of all the contributors to this project, see *Note
  1279.      Credits::.
  1280.  
  1281. *Important*:
  1282.  
  1283. Reports of errors (often called bugs), as well as questions and
  1284. comments, should be sent to the general MySQL mailing list.  *Note
  1285. Mailing-list::.  *Note Bug reports::.
  1286.  
  1287. The `mysqlbug' script should be used to generate bug reports on Unix.
  1288. (Windows distributions contain a file `mysqlbug.txt' in the base
  1289. directory that can be used as a template for a bug report.)
  1290.  
  1291. For source distributions, the `mysqlbug' script can be found in the
  1292. `scripts' directory. For binary distributions, `mysqlbug' can be found
  1293. in the `bin' directory (`/usr/bin' for the `MySQL-server' RPM package).
  1294.  
  1295. If you have found a sensitive security bug in `MySQL Server', please let
  1296. us know immediately by sending an email message to <security@mysql.com>.
  1297.  
  1298. About This Manual
  1299. =================
  1300.  
  1301. This is the `MySQL' reference manual; it documents `MySQL' up to
  1302. Version 4.0.18. Functional changes are always indicated with reference
  1303. to the version, so this manual is also suitable if you are using an
  1304. older version of the `MySQL' software (such as 3.23 or 4.0-production).
  1305. There are also references for version 5.0 (development).
  1306.  
  1307. Being a reference manual, it does not provide general instruction on
  1308. `SQL' or relational database concepts. It also will not teach you how to
  1309. use your operating system or command line interpreter.
  1310.  
  1311. As the `MySQL Database Software' is under constant development, the
  1312. manual is also updated frequently.  The most recent version of this
  1313. manual is available at `http://www.mysql.com/documentation/' in many
  1314. different formats, including HTML, PDF, and Windows HLP versions.
  1315.  
  1316. The primary document is the Texinfo file.  The HTML version is produced
  1317. automatically using a modified version of `texi2html'.  The plain text
  1318. and Info versions are produced with `makeinfo'.  The PostScript version
  1319. is produced using `texi2dvi' and `dvips'.  The PDF version is produced
  1320. with `pdftex'.
  1321.  
  1322. The index can assist you in finding information in the manual. For
  1323. online use, you can try the searchable version of the manual available
  1324. at `http://www.mysql.com/doc/'.
  1325.  
  1326. If you have any suggestions concerning additions or corrections to this
  1327. manual, please send them to the documentation team at <docs@mysql.com>.
  1328.  
  1329. This manual was initially written by David Axmark and Michael (Monty)
  1330. Widenius. It is now maintained by the MySQL Documentation Team,
  1331. consisting of Arjen Lentz, Paul DuBois and Stefan Hinz.  For the many
  1332. other contributors, see *Note Credits::.
  1333.  
  1334. The copyright (2004) to this manual is owned by the Swedish company
  1335. `MySQL AB'. *Note Copyright::.
  1336.  
  1337. Conventions Used in This Manual
  1338. -------------------------------
  1339.  
  1340. This manual uses certain typographical conventions:
  1341.  
  1342. `constant'
  1343.      Constant-width font is used for command names and options; SQL
  1344.      statements; database, table, and column names; C and Perl code;
  1345.      and environment variables.  Example: "To see how `mysqladmin'
  1346.      works, invoke it with the `--help' option."
  1347.  
  1348. `filename'
  1349.      Constant-width font with surrounding quotes is used for filenames
  1350.      and pathnames.  Example: "The distribution is installed under the
  1351.      `/usr/local/' directory."
  1352.  
  1353. `c'
  1354.      Constant-width font with surrounding quotes is also used to
  1355.      indicate character sequences.  Example: "To specify a wildcard,
  1356.      use the `%' character."
  1357.  
  1358. _italic_
  1359.      Italic font is used for emphasis, _like this_.
  1360.  
  1361. *boldface*
  1362.      Boldface font is used in table headings and to convey *especially
  1363.      strong emphasis*.
  1364.  
  1365. When commands are shown that are meant to be executed by a particular
  1366. program, the program is indicated by a prompt shown before the command.
  1367. For example, `shell>' indicates a command that you execute from your
  1368. login shell, and `mysql>' indicates a statement that you execute from
  1369. the `mysql' client program:
  1370.  
  1371.      shell> type a shell command here
  1372.      mysql> type a mysql statement here
  1373.  
  1374. The "shell" is your command interpreter. On Unix, this is typically a
  1375. program such as `sh' or `csh'. On Windows, the equivalent is
  1376. `command.com' or `cmd.exe', typically run in a Windows console.
  1377.  
  1378. Note that to enter a command or statement from an example, you do not
  1379. type the prompt shown in the example.
  1380.  
  1381. Commands to set shell variables are shown using Bourne shell syntax.
  1382. If you are using `csh' or `tcsh', you will need to issue commands
  1383. somewhat differently.  For example, the sequence to set an environment
  1384. variable and run a command looks like this in Bourne shell syntax:
  1385.  
  1386.      shell> VARNAME=value some_command
  1387.  
  1388. For `csh' or `tcsh', you would execute the sequence like this:
  1389.  
  1390.      shell> setenv VARNAME value
  1391.      shell> some_command
  1392.  
  1393. Database, table, and column names must often be substituted into
  1394. commands.  To indicate that such substitution is necessary, this manual
  1395. uses `db_name', `tbl_name', and `col_name'.  For example, you might see
  1396. a statement like this:
  1397.  
  1398.      mysql> SELECT col_name FROM db_name.tbl_name;
  1399.  
  1400. This means that if you were to enter a similar statement, you would
  1401. supply your own database, table, and column names, perhaps like this:
  1402.  
  1403.      mysql> SELECT author_name FROM biblio_db.author_list;
  1404.  
  1405. SQL keywords are not case sensitive and may be written in uppercase or
  1406. lowercase.  This manual uses uppercase.
  1407.  
  1408. In syntax descriptions, square brackets (`[' and `]') are used to
  1409. indicate optional words or clauses.  For example, in the following
  1410. statement, `IF EXISTS' is optional:
  1411.  
  1412.      DROP TABLE [IF EXISTS] tbl_name
  1413.  
  1414. When a syntax element consists of a number of alternatives, the
  1415. alternatives are separated by vertical bars (`|').  When one member
  1416. from a set of choices *may* be chosen, the alternatives are listed
  1417. within square brackets (`[' and `]'):
  1418.  
  1419.      TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  1420.  
  1421. When one member from a set of choices *must* be chosen, the
  1422. alternatives are listed within braces (`{' and `}'):
  1423.  
  1424.      {DESCRIBE | DESC} tbl_name {col_name | wild}
  1425.  
  1426. An ellipsis (`...') indicates the omission of a section of a statement,
  1427. typically to provide a shorter version of more complex syntax. For
  1428. example, `INSERT ... SELECT' is shorthand for the form of `INSERT'
  1429. statement that is followed by a `SELECT' statement.
  1430.  
  1431. An ellipsis can also indicate that the preceding syntax element of a
  1432. statement may be repeated. In the following example, multiple
  1433. `reset_option' values may be given, with each of those after the first
  1434. preceded by commas:
  1435.  
  1436.      RESET reset_option [,reset_option] ...
  1437.  
  1438. Overview of the MySQL Database Management System
  1439. ================================================
  1440.  
  1441. `MySQL', the most popular `Open Source' SQL database management system,
  1442. is developed, distributed, and supported by `MySQL AB'.  `MySQL AB' is a
  1443. commercial company, founded by the MySQL developers, that builds its
  1444. business by providing services around the `MySQL' database management
  1445. system.  *Note What is MySQL AB::.
  1446.  
  1447. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1448. information about `MySQL' software and `MySQL AB'.
  1449.  
  1450. `MySQL' is a database management system.
  1451.      A database is a structured collection of data.  It may be anything
  1452.      from a simple shopping list to a picture gallery or the vast
  1453.      amounts of information in a corporate network.  To add, access,
  1454.      and process data stored in a computer database, you need a
  1455.      database management system such as `MySQL' Server.  Since
  1456.      computers are very good at handling large amounts of data,
  1457.      database management systems play a central role in computing, as
  1458.      stand-alone utilities or as parts of other applications.
  1459.  
  1460. MySQL is a relational database management system.
  1461.      A relational database stores data in separate tables rather than
  1462.      putting all the data in one big storeroom.  This adds speed and
  1463.      flexibility.  The `SQL' part of "`MySQL'" stands for "`Structured
  1464.      Query Language'". SQL is the most common standardized language
  1465.      used to access databases and is defined by the ANSI/ISO SQL
  1466.      Standard.(The SQL standard has been evolving since 1986 and
  1467.      several versions exist. In this manual, "`SQL-92'" refers to the
  1468.      standard released in 1992, "`SQL-99'" refers to the standard
  1469.      released in 1999, and "`SQL:2003'" refers to the next version of
  1470.      the standard.  We use the term "`the SQL standard'" to mean the
  1471.      current version of the SQL Standard at any time.)
  1472.  
  1473. MySQL software is `Open Source'.
  1474.      `Open Source' means that it is possible for anyone to use and
  1475.      modify the software.  Anybody can download the `MySQL' software
  1476.      from the Internet and use it without paying anything.  If you
  1477.      wish, you may study the source code and change it to suit your
  1478.      needs.  The `MySQL' software uses the `GPL' (`GNU General Public
  1479.      License'), `http://www.fsf.org/licenses/', to define what you may
  1480.      and may not do with the software in different situations.  If you
  1481.      feel uncomfortable with the `GPL' or need to embed `MySQL' code
  1482.      into a commercial application, you can buy a commercially licensed
  1483.      version from us.  *Note MySQL licenses::.
  1484.  
  1485. Why use the MySQL Database Server?
  1486.      The `MySQL Database Server' is very fast, reliable, and easy to
  1487.      use.  If that is what you are looking for, you should give it a
  1488.      try.  `MySQL Server' also has a practical set of features
  1489.      developed in close cooperation with our users.  You can find a
  1490.      performance comparison of `MySQL Server' with other database
  1491.      managers on our benchmark page.  *Note MySQL Benchmarks::.
  1492.  
  1493.      `MySQL Server' was originally developed to handle large databases
  1494.      much faster than existing solutions and has been successfully used
  1495.      in highly demanding production environments for several years.
  1496.      Though under constant development, `MySQL Server' today offers a
  1497.      rich and useful set of functions.  Its connectivity, speed, and
  1498.      security make `MySQL Server' highly suited for accessing databases
  1499.      on the Internet.
  1500.  
  1501. The technical features of MySQL Server
  1502.      The `MySQL Database Software' is a client/server system that
  1503.      consists of a multi-threaded `SQL' server that supports different
  1504.      backends, several different client programs and libraries,
  1505.      administrative tools, and a wide range of application programming
  1506.      interfaces (APIs).
  1507.  
  1508.      We also provide `MySQL Server' as a multi-threaded library which
  1509.      you can link into your application to get a smaller, faster,
  1510.      easier-to-manage product.
  1511.  
  1512. There is a large amount of contributed MySQL software available.
  1513.      It is very likely that you will find that your favorite
  1514.      application or language already supports the `MySQL Database
  1515.      Server'.
  1516.  
  1517. The official way to pronounce `MySQL' is "My Ess Que Ell" (not "my
  1518. sequel"), but we don't mind if you pronounce it as "my sequel" or in
  1519. some other localized way.
  1520.  
  1521. History of MySQL
  1522. ----------------
  1523.  
  1524. We started out with the intention of using `mSQL' to connect to our
  1525. tables using our own fast low-level (ISAM) routines. However, after some
  1526. testing, we came to the conclusion that `mSQL' was not fast enough or
  1527. flexible enough for our needs.  This resulted in a new SQL interface to
  1528. our database but with almost the same API interface as `mSQL'.  This
  1529. API was designed to allow third-party code that was written for use
  1530. with `mSQL' to be ported easily for use with `MySQL'.
  1531.  
  1532. The derivation of the name `MySQL' is not clear.  Our base directory
  1533. and a large number of our libraries and tools have had the prefix "my"
  1534. for well over 10 years.  However, co-founder Monty Widenius's daughter
  1535. is also named My.  Which of the two gave its name to `MySQL' is still a
  1536. mystery, even for us.
  1537.  
  1538. The name of the MySQL Dolphin (our logo) is `Sakila'. `Sakila' was
  1539. chosen by the founders of MySQL AB from a huge list of names suggested
  1540. by users in our "Name the Dolphin" contest. The winning name was
  1541. submitted by Ambrose Twebaze, an open source software developer from
  1542. Swaziland, Africa.  According to Ambrose, the name Sakila has its roots
  1543. in SiSwati, the local language of Swaziland. Sakila is also the name of
  1544. a town in Arusha, Tanzania, near Ambrose's country of origin, Uganda.
  1545.  
  1546. The Main Features of MySQL
  1547. --------------------------
  1548.  
  1549. The following list describes some of the important characteristics of
  1550. the `MySQL Database Software'. *Note MySQL 4.0 Nutshell::.
  1551.  
  1552. Internals and Portability
  1553.         * Written in C and C++.
  1554.  
  1555.         * Tested with a broad range of different compilers.
  1556.  
  1557.         * Works on many different platforms.  *Note Which OS::.
  1558.  
  1559.         * Uses GNU Automake, Autoconf, and Libtool for portability.
  1560.  
  1561.         * APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and
  1562.           Tcl are available.  *Note Clients::.
  1563.  
  1564.         * Fully multi-threaded using kernel threads.  This means it can
  1565.           easily use multiple CPUs if they are available.
  1566.  
  1567.         * Provides transactional and non-transactional storage engines.
  1568.  
  1569.         * Uses very fast B-tree disk tables (`MyISAM') with index
  1570.           compression.
  1571.  
  1572.         * Relatively easy to add another storage engine. This is useful
  1573.           if you want to add an SQL interface to an in-house database.
  1574.  
  1575.         * A very fast thread-based memory allocation system.
  1576.  
  1577.         * Very fast joins using an optimized one-sweep multi-join.
  1578.  
  1579.         * In-memory hash tables which are used as temporary tables.
  1580.  
  1581.         * SQL functions are implemented using a highly optimized class
  1582.           library and should be as fast as possible.  Usually there is
  1583.           no memory allocation at all after query initialization.
  1584.  
  1585.         * The `MySQL' code is tested with Purify (a commercial memory
  1586.           leakage detector) as well as with Valgrind, a `GPL' tool
  1587.           (`http://developer.kde.org/~sewardj/').
  1588.  
  1589.         * The server is available as a separate program for use in a
  1590.           client/server networked environment.  It is also available as
  1591.           a library that can be embedded (linked) into standalone
  1592.           applications. Such applications can be used in isolation or
  1593.           in environments where no network is available.
  1594.  
  1595. Column Types
  1596.         * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8
  1597.           bytes long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT',
  1598.           `BLOB', `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR',
  1599.           `SET', `ENUM', and OpenGIS geometry types.  *Note Column
  1600.           types::.
  1601.  
  1602.         * Fixed-length and variable-length records.
  1603.  
  1604. Commands and Functions
  1605.         * Full operator and function support in the `SELECT' and `WHERE'
  1606.           clauses of queries.  For example:
  1607.  
  1608.                mysql> SELECT CONCAT(first_name, ' ', last_name)
  1609.                    -> FROM tbl_name
  1610.                    -> WHERE income/dependents > 10000 AND age > 30;
  1611.  
  1612.         * Full support for SQL `GROUP BY' and `ORDER BY' clauses.
  1613.           Support for group functions (`COUNT()', `COUNT(DISTINCT ...)',
  1614.           `AVG()', `STD()', `SUM()', `MAX()', `MIN()', and
  1615.           `GROUP_CONCAT()').
  1616.  
  1617.         * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with
  1618.           both standard SQL and ODBC syntax.
  1619.  
  1620.         * Support for aliases on tables and columns as required by
  1621.           SQL-92.
  1622.  
  1623.         * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number
  1624.           of rows that were changed (affected).  It is possible to
  1625.           return the number of rows matched instead by setting a flag
  1626.           when connecting to the server.
  1627.  
  1628.         * The `MySQL'-specific `SHOW' command can be used to retrieve
  1629.           information about databases, tables, and indexes.  The
  1630.           `EXPLAIN' command can be used to determine how the optimizer
  1631.           resolves a query.
  1632.  
  1633.         * Function names do not clash with table or column names.  For
  1634.           example, `ABS' is a valid column name.  The only restriction
  1635.           is that for a function call, no spaces are allowed between
  1636.           the function name and the `(' that follows it.  *Note
  1637.           Reserved words::.
  1638.  
  1639.         * You can mix tables from different databases in the same query
  1640.           (as of Version 3.22).
  1641.  
  1642. Security
  1643.         * A privilege and password system that is very flexible and
  1644.           secure, and allows host-based verification.  Passwords are
  1645.           secure because all password traffic is encrypted when you
  1646.           connect to a server.
  1647.  
  1648. Scalability and Limits
  1649.         * Handles large databases.  We use `MySQL Server' with
  1650.           databases that contain 50 million records. We also know of
  1651.           users that use `MySQL Server' with 60,000 tables and about
  1652.           5,000,000,000 rows.
  1653.  
  1654.         * Up to 32 indexes per table are allowed.  Each index may
  1655.           consist of 1 to 16 columns or parts of columns.  The maximum
  1656.           index width is 500 bytes (this may be changed when compiling
  1657.           `MySQL Server').  An index may use a prefix of a `CHAR' or
  1658.           `VARCHAR' column.
  1659.  
  1660. Connectivity
  1661.         * Clients may connect to the `MySQL' server using TCP/IP sockets
  1662.           on any platform.  On Windows systems in the NT family (NT,
  1663.           2000, or XP), clients may connect using named pipes. On Unix
  1664.           systems, clients may connect using Unix domain socket files.
  1665.  
  1666.         * The Connector/ODBC interface provides `MySQL' support for
  1667.           client programs that use ODBC (Open-DataBase-Connectivity)
  1668.           connections.  For example, you can use MS Access to connect
  1669.           to your `MySQL' server.  Clients may be run on Windows or
  1670.           Unix.  Connector/ODBC source is available.  All ODBC 2.5
  1671.           functions are supported, as are many others.  *Note ODBC::.
  1672.  
  1673.         * The Connector/JDBC interface provides `MySQL' support for
  1674.           Java client programs that use JDBC connections.  Clients may
  1675.           be run on Windows or Unix.  Connector/JDBC source is
  1676.           available.  *Note Java::.
  1677.  
  1678. Localization
  1679.         * The server can provide error messages to clients in many
  1680.           languages.  *Note Languages::.
  1681.  
  1682.         * Full support for several different character sets, including
  1683.           ISO-8859-1 (Latin1), german, big5, ujis, and more.  For
  1684.           example, the Scandinavian characters `a^', `a"' and `o"' are
  1685.           allowed in table and column names.  Unicode support is
  1686.           available as of `MySQL' 4.1.
  1687.  
  1688.         * All data is saved in the chosen character set.  All
  1689.           comparisons for normal string columns are case-insensitive.
  1690.  
  1691.         * Sorting is done according to the chosen character set (the
  1692.           Swedish way by default).  It is possible to change this when
  1693.           the `MySQL' server is started.  To see an example of very
  1694.           advanced sorting, look at the Czech sorting code.  `MySQL
  1695.           Server' supports many different character sets that can be
  1696.           specified at compile and runtime.
  1697.  
  1698. Clients and Tools
  1699.         * The MySQL server has built-in support for SQL statements to
  1700.           check, optimize, and repair tables.  These statements are
  1701.           available from the command line through the `mysqlcheck'
  1702.           client. MySQL also includes `myisamchk', a very fast
  1703.           command-line utility for performing these operations on
  1704.           `MyISAM' tables.  *Note MySQL Database Administration::.
  1705.  
  1706.         * All `MySQL' programs can be invoked with the `--help' or `-?'
  1707.           options to obtain online assistance.
  1708.  
  1709. MySQL Stability
  1710. ---------------
  1711.  
  1712. This section addresses the questions "_How stable is MySQL Server?_"
  1713. and "_Can I depend on MySQL Server in this project?_" We will try to
  1714. clarify these issues and answer some important questions that concern
  1715. many potential users. The information in this section is based on data
  1716. gathered from the mailing list, which is very active in identifying
  1717. problems as well as reporting types of use.
  1718.  
  1719. The original code stems back to the early 1980s. It provides a stable
  1720. code base, and the ISAM table format used by the original storage engine
  1721. remains backward-compatible.  At TcX, the predecessor of `MySQL AB',
  1722. `MySQL' code has worked in projects since mid-1996, without any
  1723. problems.  When the `MySQL Database Software' initially was released to
  1724. a wider public, our new users quickly found some pieces of "untested
  1725. code". Each new release since then has had fewer portability problems
  1726. (even though each new release has also had many new features).
  1727.  
  1728. Each release of the `MySQL Server' has been usable. Problems have
  1729. occurred only when users try code from the "gray zones."  Naturally,
  1730. new users don't know what the gray zones are; this section therefore
  1731. attempts to document those areas that are currently known.  The
  1732. descriptions mostly deal with Version 3.23 and 4.0 of `MySQL Server'.
  1733. All known and reported bugs are fixed in the latest version, with the
  1734. exception of those listed in the bugs section, which are
  1735. design-related.  *Note Bugs::.
  1736.  
  1737. The `MySQL Server' design is multi-layered with independent modules.
  1738. Some of the newer modules are listed here with an indication of how
  1739. well-tested each of them is:
  1740.  
  1741. *Replication -- Gamma*
  1742.      Large groups of servers using replication are in production use,
  1743.      with good results. Work on enhanced replication features is
  1744.      continuing in `MySQL' 5.x.
  1745.  
  1746. *`InnoDB' tables -- Stable (in 3.23 from 3.23.49)*
  1747.      The `InnoDB' transactional storage engine has been declared stable
  1748.      in the `MySQL' 3.23 tree, starting from version 3.23.49.  `InnoDB'
  1749.      is being used in large, heavy-load production systems.
  1750.  
  1751. *`BDB' tables -- Gamma*
  1752.      The `Berkeley DB' code is very stable, but we are still improving
  1753.      the `BDB' transactional storage engine interface in `MySQL
  1754.      Server', so it will take some time before this is as well tested
  1755.      as the other table types.
  1756.  
  1757. *Full-text searches -- Beta*
  1758.      Full-text searching works but is not yet widely used.  Important
  1759.      enhancements have been implemented in `MySQL' 4.0.
  1760.  
  1761. *`Connector/ODBC 3.51' (uses ODBC SDK 3.51) -- Stable*
  1762.      In wide production use. Some issues brought up appear to be
  1763.      application-related and independent of the ODBC driver or
  1764.      underlying database server.
  1765.  
  1766. *Automatic recovery of `MyISAM' tables -- Gamma*
  1767.      This status applies only to the new code in the `MyISAM' storage
  1768.      engine that checks if the table was closed properly on open and
  1769.      executes an automatic check/repair of the table if it wasn't.
  1770.  
  1771. *Bulk-insert -- Alpha*
  1772.      New feature in `MyISAM' tables in `MySQL' 4.0 for faster insert of
  1773.      many rows.
  1774.  
  1775. *Locking -- Gamma*
  1776.      This is very system-dependent.  On some systems there are big
  1777.      problems using standard operating system locking (`fcntl()').  In
  1778.      these cases, you should run `mysqld' with the
  1779.      `--skip-external-locking' flag.  Problems are known to occur on
  1780.      some Linux systems, and on SunOS when using NFS-mounted
  1781.      filesystems.
  1782.  
  1783. Paying customers receive high-quality support directly from MySQL AB.
  1784. MySQL AB also provides the MySQL mailing list as a community resource
  1785. where anyone may ask questions.
  1786.  
  1787. Bugs are usually fixed right away with a patch. For serious bugs, there
  1788. is almost always a new release.
  1789.  
  1790. How Big MySQL Tables Can Be
  1791. ---------------------------
  1792.  
  1793. `MySQL' Version 3.22 had a 4 GB (4 gigabyte) limit on table size. With
  1794. the `MyISAM' storage engine in `MySQL' Version 3.23, the maximum table
  1795. size was increased to 8 million terabytes (2 ^ 63 bytes). With this
  1796. larger allowed table size, the maximum effective table size for `MySQL'
  1797. databases now normally is determined by operating system constraints on
  1798. file sizes, not by MySQL internal limits.
  1799.  
  1800. The `InnoDB' storage engine maintains `InnoDB' tables within a
  1801. tablespace that can be created from several files. This allows a table
  1802. to exceed the maximum individual file size. The tablespace can include
  1803. raw disk partitions, which allows extremely large tables. The maximum
  1804. tablespace size is 64 TB.
  1805.  
  1806. The following table lists some examples of operating system file-size
  1807. limits:
  1808.  
  1809. *Operating System*     *File-Size Limit*
  1810. Linux-Intel 32-bit     2 GB, much more when using LFS
  1811. Linux-Alpha            8 TB (?)
  1812. Solaris 2.5.1          2 GB (4GB possible with patch)
  1813. Solaris 2.6            4 GB (can be changed with flag)
  1814. Solaris 2.7 Intel      4 GB
  1815. Solaris 2.7            512 GB
  1816. UltraSPARC             
  1817.  
  1818. On Linux 2.2, you can get `MyISAM' tables larger than 2 GB in size by
  1819. using the LFS patch for the ext2 filesystem. On Linux 2.4, patches also
  1820. exist for ReiserFS to get support for big files. Most current Linux
  1821. distributions are based on kernel 2.4 and already include all the
  1822. required Large File Support (LFS) patches. However, the maximum
  1823. available file size still depends on several factors, one of them being
  1824. the file system used to store MySQL tables.
  1825.  
  1826. For a very detailed overview about LFS in Linux, have a look at Andreas
  1827. Jaeger's "Large File Support in Linux" page at
  1828. <http://www.suse.de/~aj/linux_lfs.html>.
  1829.  
  1830. By default, `MySQL' creates `MyISAM' tables with an internal structure
  1831. that allows a maximum size of about 4 GB.  You can check the maximum
  1832. table size for a table with the `SHOW TABLE STATUS' command or with the
  1833. `myisamchk -dv table_name'.  *Note `SHOW': SHOW.
  1834.  
  1835. If you need a `MyISQM' table that will be larger than 4 GB in size (and
  1836. your operating system supports large files), the `CREATE TABLE'
  1837. statement allows `AVG_ROW_LENGTH' and `MAX_ROWS' options.  *Note
  1838. `CREATE TABLE': CREATE TABLE.  You can also change these options with
  1839. `ALTER TABLE' after the table has been created, to increase the table's
  1840. maximum allowable size.  *Note `ALTER TABLE': ALTER TABLE.
  1841.  
  1842. Other ways to work around file-size limits for `MyISAM' tables are as
  1843. follows:
  1844.  
  1845.    * If your large table is read-only, you can use `myisampack' to
  1846.      compress it.  `myisampack' usually compresses a table by at least
  1847.      50%, so you can have, in effect, much bigger tables.  `myisampack'
  1848.      also can merge multiple tables into a single table.  *Note
  1849.      `myisampack': myisampack.
  1850.  
  1851.    * Another way to get around the operating system file limit for
  1852.      `MyISAM' datafiles is by using the `RAID' options.  *Note `CREATE
  1853.      TABLE': CREATE TABLE.
  1854.  
  1855.    * `MySQL' includes a `MERGE' library that allows you to handle a
  1856.      collection of `MyISAM' tables that have identical structure as a
  1857.      single `MERGE' table.  *Note `MERGE' tables: MERGE.
  1858.  
  1859.  
  1860. Year 2000 Compliance
  1861. --------------------
  1862.  
  1863. The `MySQL Server' itself has no problems with Year 2000 (Y2K)
  1864. compliance:
  1865.  
  1866.    * `MySQL Server' uses Unix time functions that handle dates into the
  1867.      year `2037' for `TIMESTAMP' values. For `DATE' and `DATETIME'
  1868.      values, dates through the year `9999' are accepted.
  1869.  
  1870.    * All `MySQL' date functions are implemented in one source file,
  1871.      `sql/time.cc', and are coded very carefully to be year 2000-safe.
  1872.  
  1873.    * In `MySQL' Version 3.22 and later, the `YEAR' column type can
  1874.      store years `0' and `1901' to `2155' in one byte and display them
  1875.      using two or four digits.  All 2-digit years are considered to be
  1876.      in the range `1970' to `2069', which means that if you store `01'
  1877.      in a `YEAR' column, `MySQL Server' treats it as `2001'.
  1878.  
  1879. The following simple demonstration illustrates that `MySQL Server'
  1880. doesn't have any problems with dates until after the year 2030:
  1881.  
  1882.      mysql> DROP TABLE IF EXISTS y2k;
  1883.      Query OK, 0 rows affected (0.01 sec)
  1884.      
  1885.      mysql> CREATE TABLE y2k (date DATE,
  1886.          ->                   date_time DATETIME,
  1887.          ->                   time_stamp TIMESTAMP);
  1888.      Query OK, 0 rows affected (0.00 sec)
  1889.      
  1890.      mysql> INSERT INTO y2k VALUES
  1891.          -> ('1998-12-31','1998-12-31 23:59:59',19981231235959),
  1892.          -> ('1999-01-01','1999-01-01 00:00:00',19990101000000),
  1893.          -> ('1999-09-09','1999-09-09 23:59:59',19990909235959),
  1894.          -> ('2000-01-01','2000-01-01 00:00:00',20000101000000),
  1895.          -> ('2000-02-28','2000-02-28 00:00:00',20000228000000),
  1896.          -> ('2000-02-29','2000-02-29 00:00:00',20000229000000),
  1897.          -> ('2000-03-01','2000-03-01 00:00:00',20000301000000),
  1898.          -> ('2000-12-31','2000-12-31 23:59:59',20001231235959),
  1899.          -> ('2001-01-01','2001-01-01 00:00:00',20010101000000),
  1900.          -> ('2004-12-31','2004-12-31 23:59:59',20041231235959),
  1901.          -> ('2005-01-01','2005-01-01 00:00:00',20050101000000),
  1902.          -> ('2030-01-01','2030-01-01 00:00:00',20300101000000),
  1903.          -> ('2050-01-01','2050-01-01 00:00:00',20500101000000);
  1904.      Query OK, 13 rows affected (0.01 sec)
  1905.      Records: 13  Duplicates: 0  Warnings: 0
  1906.      
  1907.      mysql> SELECT * FROM y2k;
  1908.      +------------+---------------------+----------------+
  1909.      | date       | date_time           | time_stamp     |
  1910.      +------------+---------------------+----------------+
  1911.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1912.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1913.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1914.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1915.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1916.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1917.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1918.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1919.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1920.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1921.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  1922.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  1923.      | 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
  1924.      +------------+---------------------+----------------+
  1925.      13 rows in set (0.00 sec)
  1926.  
  1927. The final `TIMESTAMP' column value is zero because the final year
  1928. (`2050') exceeds the `TIMESTAMP' maximum.  The `TIMESTAMP' datatype,
  1929. which is used to store the current time, supports values that range
  1930. from `19700101000000' to `20300101000000' on 32-bit machines (signed
  1931. value).  On 64-bit machines, `TIMESTAMP' handles values up to `2106'
  1932. (unsigned value).
  1933.  
  1934. The example also shows that the `DATE' and `DATETIME' datatypes have no
  1935. problems with the dates used. They handle dates through the year `9999'.
  1936.  
  1937. Although `MySQL Server' itself is Y2K-safe, you may run into problems
  1938. if you use it with applications that are not Y2K-safe.  For example,
  1939. many old applications store or manipulate years using 2-digit values
  1940. (which are ambiguous) rather than 4-digit values.  This problem may be
  1941. compounded by applications that use values such as `00' or `99' as
  1942. "missing" value indicators.  Unfortunately, these problems may be
  1943. difficult to fix because different applications may be written by
  1944. different programmers, each of whom may use a different set of
  1945. conventions and date-handling functions.
  1946.  
  1947. Thus, even though `MySQL Server' has no Y2K problems, it is the
  1948. application's responsibility to provide unambiguous input.  See *Note
  1949. Y2K issues:: for `MySQL Server''s rules for dealing with ambiguous date
  1950. input data that contains 2-digit year values.
  1951.  
  1952. Overview of MySQL AB
  1953. ====================
  1954.  
  1955. `MySQL AB' is the company of the `MySQL' founders and main developers.
  1956. `MySQL AB' was originally established in Sweden by David Axmark, Allan
  1957. Larsson, and Michael "Monty" Widenius.
  1958.  
  1959. The developers of the `MySQL' server are all employed by the company.
  1960. We are a virtual organization with people in a dozen countries around
  1961. the world. We communicate extensively over the Internet every day with
  1962. one another and with our users, supporters, and partners.
  1963.  
  1964. We are dedicated to developing the `MySQL' database software and
  1965. promoting it to new users. `MySQL AB' owns the copyright to the `MySQL'
  1966. source code, the `MySQL' logo and trademark, and this manual. *Note
  1967. What-is::.
  1968.  
  1969. The `MySQL' core values show our dedication to `MySQL' and `Open
  1970. Source'.
  1971.  
  1972. We want the `MySQL Database Software' to be:
  1973.    * The best and the most widely used database in the world
  1974.  
  1975.    * Available to, and affordable by all
  1976.  
  1977.    * Easy to use
  1978.  
  1979.    * Continuously improving while remaining fast and safe
  1980.  
  1981.    * Fun to use and improve
  1982.  
  1983.    * Free from bugs
  1984.  
  1985. `MySQL AB' and the people at `MySQL AB':
  1986.    * Promote `Open Source' philosophy and support the `Open Source'
  1987.      community
  1988.  
  1989.    * Aim to be good citizens
  1990.  
  1991.    * Prefer partners that share our values and mind-set
  1992.  
  1993.    * Answer email and provide support
  1994.  
  1995.    * Are a virtual company, networking with others
  1996.  
  1997.    * Work against software patents
  1998.  
  1999. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  2000. information about `MySQL' and `MySQL AB'.
  2001.  
  2002. By the way, the "AB" part of the company name is the acronym for the
  2003. Swedish "aktiebolag", or "stock company."  It translates to "MySQL,
  2004. Inc." In fact, MySQL Inc. and MySQL GmbH are examples of MySQL AB
  2005. subsidiaries. They are located in the US and Germany, respectively.
  2006.  
  2007. The Business Model and Services of MySQL AB
  2008. -------------------------------------------
  2009.  
  2010. One of the most common questions we encounter is: "_How can you make a
  2011. living from something you give away for free?_" This is how:
  2012.  
  2013.    * `MySQL AB' makes money on support, services, commercial licenses,
  2014.      and royalties.
  2015.  
  2016.    * We use these revenues to fund product development and to expand
  2017.      the `MySQL' business.
  2018.  
  2019. The company has been profitable since its inception. In October 2001,
  2020. we accepted venture financing from leading Scandinavian investors and a
  2021. handful of business angels. This investment is used to solidify our
  2022. business model and build a basis for sustainable growth.
  2023.  
  2024. Support
  2025. .......
  2026.  
  2027. `MySQL AB' is run and owned by the founders and main developers of the
  2028. `MySQL' database. The developers are committed to providing support to
  2029. customers and other users in order to stay in touch with their needs
  2030. and problems. All our support is provided by qualified developers.
  2031. Really tricky questions are answered by Michael `Monty' Widenius,
  2032. principal author of the `MySQL Server'.  *Note Support::.
  2033.  
  2034. For more information and ordering support at various levels, see
  2035. `http://www.mysql.com/support/' or contact our sales staff at
  2036. <sales@mysql.com>.
  2037.  
  2038. Training and Certification
  2039. ..........................
  2040.  
  2041. `MySQL AB' delivers `MySQL' and related training worldwide.  We offer
  2042. both open courses and in-house courses tailored to the specific needs
  2043. of your company. `MySQL Training' is also available through our
  2044. partners, the `Authorized MySQL Training Centers'.
  2045.  
  2046. Our training material uses the same example databases used in our
  2047. documentation and our sample applications, and is always updated to
  2048. reflect the latest `MySQL' version. Our trainers are backed by the
  2049. development team to guarantee the quality of the training and the
  2050. continuous development of the course material. This also ensures that
  2051. no questions raised during the courses remain unanswered.
  2052.  
  2053. Attending our training courses will enable you to achieve your `MySQL'
  2054. application goals. You will also:
  2055.    * Save time.
  2056.  
  2057.    * Improve the performance of your applications.
  2058.  
  2059.    * Reduce or eliminate the need for additional hardware, decreasing
  2060.      cost.
  2061.  
  2062.    * Enhance security.
  2063.  
  2064.    * Increase customers' and co-workers' satisfaction.
  2065.  
  2066.    * Prepare yourself for `MySQL Certification'.
  2067.  
  2068. If you are interested in our training as a potential participant or as
  2069. a training partner, please visit the training section at
  2070. `http://www.mysql.com/training/' or contact us at: <training@mysql.com>.
  2071.  
  2072. For details about the `MySQL Certification Program', please see
  2073. `http://www.mysql.com/certification/'.
  2074.  
  2075. Consulting
  2076. ..........
  2077.  
  2078. `MySQL AB' and its `Authorized Partners' offer consulting services to
  2079. users of `MySQL Server' and to those who embed `MySQL Server' in their
  2080. own software, all over the world.
  2081.  
  2082. Our consultants can help you design and tune your databases, construct
  2083. efficient queries, tune your platform for optimal performance, resolve
  2084. migration issues, set up replication, build robust transactional
  2085. applications, and more.  We also help customers embed `MySQL Server' in
  2086. their products and applications for large-scale deployment.
  2087.  
  2088. Our consultants work in close collaboration with our development team,
  2089. which ensures the technical quality of our professional services.
  2090. Consulting assignments range from 2-day power-start sessions to
  2091. projects that span weeks and months. Our expertise not only covers
  2092. `MySQL Server'--it also extends into programming and scripting
  2093. languages such as PHP, Perl, and more.
  2094.  
  2095. If you are interested in our consulting services or want to become a
  2096. consulting partner, please visit the consulting section of our web site
  2097. at `http://www.mysql.com/consulting/' or contact our consulting staff
  2098. at <consulting@mysql.com>.
  2099.  
  2100. Commercial Licenses
  2101. ...................
  2102.  
  2103. The `MySQL' database is released under the `GNU General Public License'
  2104. (`GPL').  This means that the `MySQL' software can be used free of
  2105. charge under the `GPL'. If you do not want to be bound by the `GPL'
  2106. terms (such as the requirement that your application must also be
  2107. `GPL'), you may purchase a commercial license for the same product from
  2108. `MySQL AB'; see `http://www.mysql.com/products/pricing.html'.  Since
  2109. `MySQL AB' owns the copyright to the `MySQL' source code, we are able
  2110. to employ `Dual Licensing', which means that the same product is
  2111. available under `GPL' and under a commercial license. This does not in
  2112. any way affect the `Open Source' commitment of `MySQL AB'. For details
  2113. about when a commercial license is required, please see *Note MySQL
  2114. licenses::.
  2115.  
  2116. We also sell commercial licenses of third-party `Open Source GPL'
  2117. software that adds value to `MySQL Server'. A good example is the
  2118. `InnoDB' transactional storage engine that offers `ACID' support,
  2119. row-level locking, crash recovery, multi-versioning, foreign key
  2120. support, and more. *Note InnoDB::.
  2121.  
  2122. Partnering
  2123. ..........
  2124.  
  2125. `MySQL AB' has a worldwide partner program that covers training
  2126. courses, consulting and support, publications, plus reselling and
  2127. distributing `MySQL' and related products. `MySQL AB Partners' get
  2128. visibility on the `http://www.mysql.com/' web site and the right to use
  2129. special versions of the `MySQL' trademarks to identify their products
  2130. and promote their business.
  2131.  
  2132. If you are interested in becoming a `MySQL AB Partner', please email
  2133. <partner@mysql.com>.
  2134.  
  2135. The word `MySQL' and the `MySQL' dolphin logo are trademarks of `MySQL
  2136. AB'. *Note MySQL AB Logos and Trademarks::.  These trademarks represent
  2137. a significant value that the `MySQL' founders have built over the years.
  2138.  
  2139. The `MySQL' web site (`http://www.mysql.com/') is popular among
  2140. developers and users. In December 2003, we served 16 million page views.
  2141. Our visitors represent a group that makes purchase decisions and
  2142. recommendations for both software and hardware. Twelve percent of our
  2143. visitors authorize purchase decisions, and only nine percent are not
  2144. involved in purchase decisions at all. More than 65% have made one or
  2145. more online business purchases within the last half-year, and 70% plan
  2146. to make one in the next few months.
  2147.  
  2148. Contact Information
  2149. -------------------
  2150.  
  2151. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  2152. information about `MySQL' and `MySQL AB'.
  2153.  
  2154. For press services and inquiries not covered in our News releases
  2155. (`http://www.mysql.com/news/'), please send email to <press@mysql.com>.
  2156.  
  2157. If you have a valid support contract with `MySQL AB', you will get
  2158. timely, precise answers to your technical questions about the `MySQL'
  2159. software. For more information, see *Note Support::.  On our web site,
  2160. see `http://www.mysql.com/support/', or send an email message to
  2161. <sales@mysql.com>.
  2162.  
  2163. For information about `MySQL' training, please visit the training
  2164. section at `http://www.mysql.com/training/'. If you have restricted
  2165. access to the Internet, please contact the `MySQL AB' training staff
  2166. via email at <training@mysql.com>.  *Note Business Services Training::.
  2167.  
  2168. For information on the `MySQL Certification Program', please see
  2169. `http://www.mysql.com/certification/'.  *Note Business Services
  2170. Training::.
  2171.  
  2172. If you're interested in consulting, please visit the consulting section
  2173. of our web site at `http://www.mysql.com/consulting/'. If you have
  2174. restricted access to the Internet, please contact the `MySQL AB'
  2175. consulting staff via email at <consulting@mysql.com>.  *Note Business
  2176. Services Consulting::.
  2177.  
  2178. Commercial licenses may be purchased online at
  2179. `https://order.mysql.com/'. There you will also find information on how
  2180. to fax your purchase order to `MySQL AB'. More information about
  2181. licensing can be found at `http://www.mysql.com/products/pricing.html'.
  2182. If you have questions regarding licensing or you want a quote for a
  2183. high-volume license deal, please fill in the contact form on our web
  2184. site (`http://www.mysql.com/') or send email to <licensing@mysql.com>
  2185. (for licensing questions) or to <sales@mysql.com> (for sales inquiries).
  2186. *Note MySQL licenses::.
  2187.  
  2188. If you represent a business that is interested in partnering with
  2189. `MySQL AB', please send email to <partner@mysql.com>.  *Note Business
  2190. Services Partnering::.
  2191.  
  2192. For more information on the `MySQL' trademark policy, refer to
  2193. `http://www.mysql.com/company/trademark.html' or send email to
  2194. <trademark@mysql.com>.  *Note MySQL AB Logos and Trademarks::.
  2195.  
  2196. If you are interested in any of the `MySQL AB' jobs listed in our jobs
  2197. section (`http://www.mysql.com/company/jobs/'), please send email to
  2198. <jobs@mysql.com>.  Please do not send your CV as an attachment, but
  2199. rather as plain text at the end of your email message.
  2200.  
  2201. For general discussion among our many users, please direct your
  2202. attention to the appropriate mailing list.  *Note Questions::.
  2203.  
  2204. Reports of errors (often called bugs), as well as questions and
  2205. comments, should be sent to the general MySQL mailing list.  *Note
  2206. Mailing-list::.  If you have found a sensitive security bug in `MySQL
  2207. Server', please let us know immediately by sending an email message to
  2208. <security@mysql.com>.  *Note Bug reports::.
  2209.  
  2210. If you have benchmark results that we can publish, please contact us
  2211. via email at <benchmarks@mysql.com>.
  2212.  
  2213. If you have suggestions concerning additions or corrections to this
  2214. manual, please send them to the manual team via email at
  2215. <docs@mysql.com>.
  2216.  
  2217. For questions or comments about the workings or content of the `MySQL'
  2218. web site (`http://www.mysql.com/'), please send email to
  2219. <webmaster@mysql.com>.
  2220.  
  2221. `MySQL AB' has a privacy policy, which can be read at
  2222. `http://www.mysql.com/company/privacy.html'.  For any queries regarding
  2223. this policy, please send email to <privacy@mysql.com>.
  2224.  
  2225. For all other inquires, please send an email to <info@mysql.com>.
  2226.  
  2227. MySQL Support and Licensing
  2228. ===========================
  2229.  
  2230. This section describes `MySQL' support and licensing arrangements.
  2231.  
  2232. Support Offered by MySQL AB
  2233. ---------------------------
  2234.  
  2235. Technical support from `MySQL AB' means individualized answers to your
  2236. unique problems direct from the software engineers who code the `MySQL'
  2237. database engine.
  2238.  
  2239. We try to take a broad and inclusive view of technical support. Almost
  2240. any problem involving `MySQL' software is important to us if it's
  2241. important to you.  Typically customers seek help on how to get
  2242. different commands and utilities to work, remove performance
  2243. bottlenecks, restore crashed systems, understand the impact of
  2244. operating system or networking issues on `MySQL', set up best practices
  2245. for backup and recovery, utilize APIs, and so on.  Our support covers
  2246. only the `MySQL' server and our own utilities, not third-party products
  2247. that access the `MySQL' server, though we try to help with these where
  2248. we can.
  2249.  
  2250. Detailed information about our various support options is given at
  2251. `http://www.mysql.com/support/', where support contracts can also be
  2252. ordered online. If you have restricted access to the Internet, please
  2253. contact our sales staff via email at <sales@mysql.com>.
  2254.  
  2255. Technical support is like life insurance. You can live happily without
  2256. it for years. However, when your hour arrives, it becomes critically
  2257. important, but it's too late to buy it.  If you use `MySQL Server' for
  2258. important applications and encounter sudden difficulties, it may be too
  2259. time consuming to figure out all the answers yourself. You may need
  2260. immediate access to the most experienced `MySQL' troubleshooters
  2261. available, those employed by `MySQL AB'.
  2262.  
  2263. Copyrights and Licenses Used by MySQL
  2264. -------------------------------------
  2265.  
  2266. `MySQL AB' owns the copyright to the `MySQL' source code, the `MySQL'
  2267. logos and trademarks and this manual.  *Note What is MySQL AB::.
  2268. Several different licenses are relevant to the `MySQL' distribution:
  2269.  
  2270.   1. All the `MySQL'-specific source in the server, the `mysqlclient'
  2271.      library and the client, as well as the `GNU' `readline' library is
  2272.      covered by the `GNU General Public License'.  *Note GPL license::.
  2273.      The text of this license can be found as the file `COPYING' in the
  2274.      distribution.
  2275.  
  2276.   2. The `GNU' `getopt' library is covered by the `GNU Lesser General
  2277.      Public License'.  See <http://www.fsf.org/licenses/>.
  2278.  
  2279.   3. Some parts of the source (the `regexp' library) are covered by a
  2280.      Berkeley-style copyright.
  2281.  
  2282.   4. Older versions of `MySQL' (3.22 and earlier) are subject to a
  2283.      stricter license (`http://www.mysql.com/products/mypl.html').  See
  2284.      the documentation of the specific version for information.
  2285.  
  2286.   5. The `MySQL' reference manual is currently *not* distributed under
  2287.      a `GPL'-style license. Use of the manual is subject to the
  2288.      following terms:
  2289.         * Conversion to other formats is allowed, but the actual content
  2290.           may not be altered or edited in any way.
  2291.  
  2292.         * You may create a printed copy for your own personal use.
  2293.  
  2294.         * For all other uses, such as selling printed copies or using
  2295.           (parts of) the manual in another publication, prior written
  2296.           agreement from `MySQL AB' is required.
  2297.      Please send an email message to <docs@mysql.com> for more
  2298.      information or if you are interested in doing a translation.
  2299.  
  2300. For information about how the `MySQL' licenses work in practice, please
  2301. refer to *Note MySQL licenses::.  Also see *Note MySQL AB Logos and
  2302. Trademarks::.
  2303.  
  2304. MySQL Licenses
  2305. --------------
  2306.  
  2307. The `MySQL' software is released under the `GNU General Public License'
  2308. (`GPL'), which is probably the best known `Open Source' license.  The
  2309. formal terms of the `GPL' license can be found at
  2310. `http://www.fsf.org/licenses/'.  See also
  2311. `http://www.fsf.org/licenses/gpl-faq.html' and
  2312. `http://www.gnu.org/philosophy/enforcing-gpl.html'.
  2313.  
  2314. Since the `MySQL' software is released under the `GPL', it may often be
  2315. used for free, but for certain uses you may want or need to buy
  2316. commercial licenses from `MySQL AB' at `https://order.mysql.com/'.  See
  2317. `http://www.mysql.com/products/licensing.html' for more information.
  2318.  
  2319. Older versions of `MySQL' (3.22 and earlier) are subject to a stricter
  2320. license (`http://www.mysql.com/products/mypl.html').  See the
  2321. documentation of the specific version for information.
  2322.  
  2323. Please note that the use of the `MySQL' software under commercial
  2324. license, `GPL', or the old `MySQL' license does not automatically give
  2325. you the right to use `MySQL AB' trademarks.  *Note MySQL AB Logos and
  2326. Trademarks::.
  2327.  
  2328. Using the MySQL Software Under a Commercial License
  2329. ...................................................
  2330.  
  2331. The `GPL' license is contagious in the sense that when a program is
  2332. linked to a `GPL' program all the source code for all the parts of the
  2333. resulting product must also be released under the `GPL'.  If you do not
  2334. follow this `GPL' requirement, you break the license terms and forfeit
  2335. your right to use the `GPL' program altogether.  You also risk damages.
  2336.  
  2337. You need a commercial license:
  2338.  
  2339.    * When you link a program with any `GPL' code from the `MySQL'
  2340.      software and don't want the resulting product to be licensed under
  2341.      `GPL', perhaps because you want to build a commercial product or
  2342.      keep the added non-`GPL' code closed source for other reasons.
  2343.      When purchasing commercial licenses, you are not using the `MySQL'
  2344.      software under `GPL' even though it's the same code.
  2345.  
  2346.    * When you distribute a non-`GPL' application that *only* works with
  2347.      the `MySQL' software and ship it with the `MySQL' software. This
  2348.      type of solution is considered to be linking even if it's done
  2349.      over a network.
  2350.  
  2351.    * When you distribute copies of the `MySQL' software without
  2352.      providing the source code as required under the `GPL' license.
  2353.  
  2354.    * When you want to support the further development of the `MySQL'
  2355.      database even if you don't formally need a commercial license.
  2356.      Purchasing support directly from `MySQL AB' is another good way of
  2357.      contributing to the development of the `MySQL' software, with
  2358.      immediate advantages for you.  *Note Support::.
  2359.  
  2360. If you require a license, you will need one for each installation of the
  2361. `MySQL' software. This covers any number of CPUs on a machine, and there
  2362. is no artificial limit on the number of clients that connect to the
  2363. server in any way.
  2364.  
  2365. For commercial licenses, please visit our website at
  2366. `http://www.mysql.com/products/licensing.html'.  For support contracts,
  2367. see `http://www.mysql.com/support/'.  If you have special needs or you
  2368. have restricted access to the Internet, please contact our sales staff
  2369. via email at <sales@mysql.com>.
  2370.  
  2371. Using the MySQL Software for Free Under GPL
  2372. ...........................................
  2373.  
  2374. You can use the `MySQL' software for free under the `GPL' if you adhere
  2375. to the conditions of the `GPL'.  For additional details, including
  2376. answers to common questions about the `GPL', see the generic FAQ from
  2377. the Free Software Foundation at
  2378. `http://www.fsf.org/licenses/gpl-faq.html'.  Common uses of the `GPL'
  2379. include:
  2380.  
  2381.    * When you distribute both your own application and the `MySQL'
  2382.      source code under the `GPL' with your product.
  2383.  
  2384.    * When you distribute the `MySQL' source code bundled with other
  2385.      programs that are not linked to or dependent on the `MySQL' system
  2386.      for their functionality even if you sell the distribution
  2387.      commercially.  This is called mere aggregation in the `GPL'
  2388.      license.
  2389.  
  2390.    * When you are not distributing *any* part of the `MySQL' system,
  2391.      you can use it for free.
  2392.  
  2393.    * When you are an Internet Service Provider (ISP), offering web
  2394.      hosting with `MySQL' servers for your customers.  We encourage
  2395.      people to use ISPs that have MySQL support, as this will give them
  2396.      the confidence that their ISP will, in fact, have the resources to
  2397.      solve any problems they may experience with the `MySQL'
  2398.      installation. Even if an ISP does not have a commercial license
  2399.      for `MySQL Server', their customers should at least be given read
  2400.      access to the source of the `MySQL' installation so that the
  2401.      customers can verify that it is correctly patched.
  2402.  
  2403.    * When you use the `MySQL' database software in conjunction with a
  2404.      web server, you do not need a commercial license (so long as it is
  2405.      not a product you distribute). This is true even if you run a
  2406.      commercial web server that uses `MySQL Server', because you are not
  2407.      distributing any part of the `MySQL' system. However, in this case
  2408.      we would like you to purchase `MySQL' support because the `MySQL'
  2409.      software is helping your enterprise.
  2410.  
  2411. If your use of `MySQL' database software does not require a commercial
  2412. license, we encourage you to purchase support from `MySQL AB' anyway.
  2413. This way you contribute toward `MySQL' development and also gain
  2414. immediate advantages for yourself. *Note Support::.
  2415.  
  2416. If you use the `MySQL' database software in a commercial context such
  2417. that you profit by its use, we ask that you further the development of
  2418. the `MySQL' software by purchasing some level of support.  We feel that
  2419. if the `MySQL' database helps your business, it is reasonable to ask
  2420. that you help `MySQL AB'.  (Otherwise, if you ask us support questions,
  2421. you are not only using for free something into which we've put a lot a
  2422. work, you're asking us to provide free support, too.)
  2423.  
  2424. MySQL AB Logos and Trademarks
  2425. -----------------------------
  2426.  
  2427. Many users of the `MySQL' database want to display the `MySQL AB'
  2428. dolphin logo on their web sites, books, or boxed products. We welcome
  2429. and encourage this, although it should be noted that the word `MySQL'
  2430. and the `MySQL' dolphin logo are trademarks of `MySQL AB' and may only
  2431. be used as stated in our trademark policy at
  2432. `http://www.mysql.com/company/trademark.html'.
  2433.  
  2434. The Original MySQL Logo
  2435. .......................
  2436.  
  2437. The `MySQL' dolphin logo was designed by the Finnish advertising agency
  2438. Priority in 2001.  The dolphin was chosen as a suitable symbol for the
  2439. `MySQL' database management system, which is like a smart, fast, and
  2440. lean animal, effortlessly navigating oceans of data. We also happen to
  2441. like dolphins.
  2442.  
  2443. The original `MySQL' logo may only be used by representatives of `MySQL
  2444. AB' and by those having a written agreement allowing them to do so.
  2445.  
  2446. MySQL Logos that may be Used Without Written Permission
  2447. .......................................................
  2448.  
  2449. We have designed a set of special _Conditional Use_ logos that may be
  2450. downloaded from our web site at `http://www.mysql.com/press/logos.html'
  2451. and used on third-party web sites without written permission from
  2452. `MySQL AB'.  The use of these logos is not entirely unrestricted but,
  2453. as the name implies, subject to our trademark policy that is also
  2454. available on our web site. You should read through the trademark policy
  2455. if you plan to use them. The requirements are basically as follows:
  2456.  
  2457.    * Use the logo you need as displayed on the `http://www.mysql.com/'
  2458.      site. You may scale it to fit your needs, but may not change
  2459.      colors or design, or alter the graphics in any way.
  2460.  
  2461.    * Make it evident that you, and not `MySQL AB', are the creator and
  2462.      owner of the site that displays the `MySQL' trademark.
  2463.  
  2464.    * Don't use the trademark in a way that is detrimental to `MySQL AB'
  2465.      or to the value of `MySQL AB' trademarks. We reserve the right to
  2466.      revoke the right to use the `MySQL AB' trademark.
  2467.  
  2468.    * If you use the trademark on a web site, make it clickable, leading
  2469.      directly to `http://www.mysql.com/'.
  2470.  
  2471.    * If you use the `MySQL' database under `GPL' in an application,
  2472.      your application must be `Open Source' and must be able to connect
  2473.      to a `MySQL' server.
  2474.  
  2475. Contact us via email at <trademark@mysql.com> to inquire about special
  2476. arrangements to fit your needs.
  2477.  
  2478. When You Need Written Permission to Use MySQL Logos
  2479. ...................................................
  2480.  
  2481. You need written permission from `MySQL AB' before using `MySQL' logos
  2482. in the following cases:
  2483.  
  2484.    * When displaying any `MySQL AB' logo anywhere except on your web
  2485.      site.
  2486.  
  2487.    * When displaying any `MySQL AB' logo except the _Conditional Use_
  2488.      logos mentioned previously on web sites or elsewhere.
  2489.  
  2490. Due to legal and commercial reasons we monitor the use of MySQL
  2491. trademarks on products, books, and other items. We usually require a
  2492. fee for displaying `MySQL AB' logos on commercial products, since we
  2493. think it is reasonable that some of the revenue is returned to fund
  2494. further development of the `MySQL' database.
  2495.  
  2496. MySQL AB Partnership Logos
  2497. ..........................
  2498.  
  2499. `MySQL' partnership logos may be used only by companies and persons
  2500. having a written partnership agreement with `MySQL AB'. Partnerships
  2501. include certification as a `MySQL' trainer or consultant.  For more
  2502. information, please see *Note Partnering: Business Services Partnering.
  2503.  
  2504. Using the Word `MySQL' in Printed Text or Presentations
  2505. .......................................................
  2506.  
  2507. `MySQL AB' welcomes references to the `MySQL' database, but it should
  2508. be noted that the word `MySQL' is a trademark of `MySQL AB'.  Because
  2509. of this, you must append the trademark symbol (`TM') to the first or
  2510. most prominent use of the word `MySQL' in a text and, where
  2511. appropriate, state that `MySQL' is a trademark of `MySQL AB'. For more
  2512. information, please refer to our trademark policy at
  2513. `http://www.mysql.com/company/trademark.html'.
  2514.  
  2515. Using the Word `MySQL' in Company and Product Names
  2516. ...................................................
  2517.  
  2518. Use of the word `MySQL' in product or company names or in Internet
  2519. domain names is not allowed without written permission from `MySQL AB'.
  2520.  
  2521. MySQL Development Roadmap
  2522. =========================
  2523.  
  2524. This section provides a snapshot of the MySQL development roadmap,
  2525. including major features implemented or planned for MySQL 4.0, 4.1,
  2526. 5.0, and 5.1.  The following sections provide information for each
  2527. release series.
  2528.  
  2529. The production release series is MySQL 4.0, which was declared stable
  2530. for production use as of Version 4.0.12, released in March 2003. This
  2531. means that future 4.0 development will be limited only to making bug
  2532. fixes. For the older MySQL 3.23 series, only critical bug fixes will be
  2533. made.
  2534.  
  2535. Active MySQL development currently is taking place in the MySQL 4.1 and
  2536. 5.0 release series. This means that new features are being added to
  2537. MySQL 4.1 and MySQL 5.0. Both 4.1 and 5.0 are available now in alpha
  2538. status.
  2539.  
  2540. Before upgrading from one release series to the next, please see the
  2541. notes at *Note Upgrade::.
  2542.  
  2543. Plans for some of the most requested features are summarized in the
  2544. following table.
  2545.  
  2546. *Feature*              *MySQL version*
  2547. Unions                 4.0
  2548. Subqueries             4.1
  2549. R-trees                4.1 (for `MyISAM' tables)
  2550. Stored procedures      5.0
  2551. Views                  5.0 or 5.1
  2552. Cursors                5.0
  2553. Foreign keys           5.1 (already implemented in 3.23 for
  2554.                        `InnoDB')
  2555. Triggers               5.1
  2556. Full outer join        5.1
  2557. Constraints            5.1
  2558.  
  2559. MySQL 4.0 in a Nutshell
  2560. -----------------------
  2561.  
  2562. Long awaited by our users, MySQL Server 4.0 is now available in
  2563. production status.
  2564.  
  2565. MySQL 4.0 is available for download from `http://www.mysql.com/' and
  2566. from our mirrors. MySQL 4.0 has been tested by a large number of users
  2567. and is in production use at many large sites.
  2568.  
  2569. The major new features of MySQL Server 4.0 are geared toward our
  2570. existing business and community users, enhancing the MySQL database
  2571. software as the solution for mission-critical, heavy-load database
  2572. systems.  Other new features target the users of embedded databases.
  2573.  
  2574. Features Available in MySQL 4.0
  2575. ...............................
  2576.  
  2577. Speed enhancements
  2578.         * MySQL 4.0 has a query cache that can give a huge speed boost
  2579.           to applications with repetitive queries. *Note Query Cache::.
  2580.  
  2581.         * Version 4.0 further increases the speed of MySQL Server in a
  2582.           number of areas, such as bulk `INSERT' statements, searching
  2583.           on packed indexes, full-text searching (using `FULLTEXT'
  2584.           indexes), and `COUNT(DISTINCT)'.
  2585.  
  2586. Embedded MySQL Server introduced
  2587.         * The new Embedded Server library can easily be used to create
  2588.           standalone and embedded applications.  The embedded server
  2589.           provides an alternative to using MySQL in a client/server
  2590.           environment.  *Note Nutshell Embedded MySQL::.
  2591.  
  2592. InnoDB storage engine as standard
  2593.         * The `InnoDB' storage engine is now offered as a standard
  2594.           feature of the `MySQL' server. This means full support for
  2595.           ACID transactions, foreign keys with cascading `UPDATE' and
  2596.           `DELETE', and row-level locking are now standard features.
  2597.           *Note `InnoDB': InnoDB.
  2598.  
  2599. New functionality
  2600.         * The enhanced `FULLTEXT' search properties of MySQL Server 4.0
  2601.           enables `FULLTEXT' indexing of large text masses with both
  2602.           binary and natural-language searching logic. You can
  2603.           customize minimal word length and define your own stop word
  2604.           lists in any human language, enabling a new set of
  2605.           applications to be built with MySQL Server.  *Note Fulltext
  2606.           Search::.
  2607.  
  2608. Standards compliance, portability, and migration
  2609.         * Many users will also be happy to learn that MySQL Server now
  2610.           supports the `UNION' statement, a long-awaited standard SQL
  2611.           feature.
  2612.  
  2613.         * MySQL now runs natively on the Novell NetWare 6.0 platform.
  2614.           *Note NetWare installation::.
  2615.  
  2616.         * Features to simplify migration from other database systems to
  2617.           MySQL Server include `TRUNCATE TABLE' (as in Oracle).
  2618.  
  2619. Internationalization
  2620.         * Our German, Austrian, and Swiss users will note that `MySQL'
  2621.           now supports a new character set, `latin1_de', which ensures
  2622.           that the _German sorting order_ sorts words with umlauts in
  2623.           the same order as do German telephone books.
  2624.  
  2625. Usability enhancements
  2626.      In the process of implementing features for new users, we have not
  2627.      forgotten requests from our loyal community of existing users.
  2628.  
  2629.         * Most `mysqld' parameters (startup options) can now be set
  2630.           without taking down the server. This is a convenient feature
  2631.           for database administrators (DBAs).  *Note `SET OPTION': SET
  2632.           OPTION.
  2633.  
  2634.         * Multiple-table `DELETE' and `UPDATE' statements have been
  2635.           added..
  2636.  
  2637.         * On Windows, symbolic link handling at the database level is
  2638.           enabled by default.  On Unix, the `MyISAM' storage engine now
  2639.           supports symbolic linking at the table level (and not just
  2640.           the database level as before).
  2641.  
  2642.         * `SQL_CALC_FOUND_ROWS' and `FOUND_ROWS()' are new functions
  2643.           that make it possible to find out the number of rows a
  2644.           `SELECT' query that includes a `LIMIT' clause would have
  2645.           returned without that clause.
  2646.  
  2647. The news section of this manual includes a more in-depth list of
  2648. features.  *Note News-4.0.x::.
  2649.  
  2650. The Embedded MySQL Server
  2651. .........................
  2652.  
  2653. The `libmysqld' embedded server library makes MySQL Server suitable for
  2654. a vastly expanded realm of applications. By using this library,
  2655. developers can embed MySQL Server into various applications and
  2656. electronics devices, where the end user has no knowledge of there
  2657. actually being an underlying database. Embedded MySQL Server is ideal
  2658. for use behind the scenes in Internet appliances, public kiosks, turnkey
  2659. hardware/software combination units, high performance Internet servers,
  2660. self-contained databases distributed on CD-ROM, and so on.
  2661.  
  2662. Many users of `libmysqld' will benefit from the MySQL _Dual Licensing_.
  2663. For those not wishing to be bound by the `GPL', the software is also
  2664. made available under a commercial license.  The embedded MySQL library
  2665. uses the same interface as the normal client library, so it is
  2666. convenient and easy to use.  *Note `libmysqld': libmysqld.
  2667.  
  2668. MySQL 4.1 in a Nutshell
  2669. -----------------------
  2670.  
  2671. MySQL Server 4.0 laid the foundation for new features implemented in
  2672. MySQL 4.1, such as subqueries and Unicode support, and for the work on
  2673. stored procedures being done in version 5.0.  These features come at
  2674. the top of the wish list of many of our customers.
  2675.  
  2676. With these additions, critics of the MySQL Database Server have to be
  2677. more imaginative than ever in pointing out deficiencies in the MySQL
  2678. database management system. Already well-known for its stability,
  2679. speed, and ease of use, MySQL Server will be able to fulfill the
  2680. requirement checklists of very demanding buyers.
  2681.  
  2682. Features Available in MySQL 4.1
  2683. ...............................
  2684.  
  2685. The features listed in this section are implemented in MySQL 4.1. A few
  2686. other features are still planned for MySQL 4.1. *Note TODO MySQL 4.1::.
  2687.  
  2688. Most new features being coded are or will be available in MySQL 5.0.
  2689. *Note TODO MySQL 5.0::.
  2690.  
  2691. Support for subqueries and derived tables
  2692.         * A subquery is a `SELECT' statement nested within another
  2693.           statement.  A derived table (an unnamed view) is a subquery
  2694.           in the `FROM' clause of another statement.  *Note
  2695.           Subqueries::.
  2696.  
  2697. Speed enhancements
  2698.         * Faster binary client/server protocol with support for
  2699.           prepared statements and parameter binding.  *Note C API
  2700.           Prepared statements::.
  2701.  
  2702.         * `BTREE' indexing is now supported for `HEAP' tables,
  2703.           significantly improving response time for non-exact searches.
  2704.  
  2705. New functionality
  2706.         * `CREATE TABLE table_name2 LIKE table_name1' allows you to
  2707.           create, with a single statement, a new table with a structure
  2708.           exactly like that of an existing table.
  2709.  
  2710.         * The MyISAM storage engine now supports OpenGIS spatial types
  2711.           for storing geographical data.  *Note Spatial extensions in
  2712.           MySQL::.
  2713.  
  2714.         * Replication can be done over SSL connections.
  2715.  
  2716. Standards compliance, portability, and migration
  2717.         * The new client/server protocol adds the ability to pass
  2718.           multiple warnings to the client, rather than only a single
  2719.           result. This makes operations such as bulk data loading much
  2720.           easier to track.
  2721.  
  2722.         * `SHOW WARNINGS' shows warnings for the last command.  *Note
  2723.           `SHOW WARNINGS': SHOW WARNINGS.
  2724.  
  2725. Internationalization
  2726.         * To support applications that require the use of local
  2727.           languages, the MySQL software now offers extensive Unicode
  2728.           support through the `utf8' and `ucs2' character sets.
  2729.  
  2730.         * Character sets can now be defined per column, table, and
  2731.           database.  This allows for a high degree of flexibility in
  2732.           application design, particularly for multi-language web sites.
  2733.  
  2734.         * For documentation for this improved character set support,
  2735.           see *Note Charset::.
  2736.  
  2737. Usability enhancements
  2738.         * In response to popular demand, we have added a server-based
  2739.           `HELP' command that can be used to get help information for
  2740.           SQL statements.  The advantage of having this information on
  2741.           the server side is that the information is always applicable
  2742.           to the particular server version that you actually are using.
  2743.           Because this information is available by issuing a SQL
  2744.           statement, any client can be written to access it.  For
  2745.           example, the `help' command of the `mysql' command-line client
  2746.           has been modified to have this capability.
  2747.  
  2748.         * In the new client/server protocol, multiple statements can be
  2749.           issued with a single call.  *Note C API multiple queries::.
  2750.  
  2751.         * The new client/server protocol also supports returning
  2752.           multiple result sets.  This might occur as a result of
  2753.           sending multiple statements, for example.
  2754.  
  2755.         * A new `INSERT ... ON DUPLICATE KEY UPDATE ...' syntax has been
  2756.           implemented. This allows you to `UPDATE' an existing row if
  2757.           the `INSERT' would have caused a duplicate in a `PRIMARY' or
  2758.           `UNIQUE' key (index).  *Note `INSERT': INSERT.
  2759.  
  2760.         * A new aggregate function, `GROUP_CONCAT()' adds the extremely
  2761.           useful capability of concatenating column values from grouped
  2762.           rows into a single result string.  *Note Group by functions
  2763.           and modifiers::.
  2764.  
  2765. The news section of this manual includes a more in-depth list of
  2766. features.  *Note News-4.1.x::.
  2767.  
  2768. Stepwise Rollout
  2769. ................
  2770.  
  2771. New features are being added to MySQL 4.1. The alpha version is already
  2772. available for download. *Note Nutshell Ready for Immediate Use::.
  2773.  
  2774. The set of features that are being added to version 4.1 is mostly
  2775. fixed. Additional development is already ongoing for version 5.0.
  2776. MySQL 4.1 will go through the steps of _Alpha_ (during which time new
  2777. features might still be added/changed), _Beta_ (when we have feature
  2778. freeze and only bug corrections will be done), and _Gamma_ (indicating
  2779. that a production release is just weeks ahead).  At the end of this
  2780. process, MySQL 4.1 will become the new production release.
  2781.  
  2782. Ready for Immediate Development Use
  2783. ...................................
  2784.  
  2785. MySQL 4.1 is currently in the alpha stage, and binaries are available
  2786. for download at `http://www.mysql.com/downloads/mysql-4.1.html'.  All
  2787. binary releases pass our extensive test suite without any errors on the
  2788. platforms on which we test.  *Note News-4.1.x::.
  2789.  
  2790. For those wishing to use the most recent development source for MySQL
  2791. 4.1, we make our 4.1 BitKeeper repository publicly available.  *Note
  2792. Installing source tree::.
  2793.  
  2794. MySQL 5.0, The Next Development Release
  2795. ---------------------------------------
  2796.  
  2797. New development for MySQL is focused on the 5.0 release, featuring
  2798. Stored Procedures and other new features.  *Note TODO MySQL 5.0::.
  2799.  
  2800. For those wishing to take a look at the bleeding edge of MySQL
  2801. development, we make our BitKeeper repository for MySQL version 5.0
  2802. publicly available.  *Note Installing source tree::.  As of December
  2803. 2003, binary builds of version 5.0 are also available.
  2804.  
  2805. MySQL and the Future (The TODO)
  2806. ===============================
  2807.  
  2808. This section summarizes the features that we plan to implement in
  2809. `MySQL Server'. The items are ordered by release series. Within a list,
  2810. items are shown in approximately the order they will be done.
  2811.  
  2812. *Note:* If you are an enterprise level user with an urgent need for a
  2813. particular feature, please contact <sales@mysql.com> to discuss
  2814. sponsoring options. Targeted financing by sponsor companies allows us
  2815. to allocate additional resources for specific purposes.  One example of
  2816. a feature sponsored in the past is replication.
  2817.  
  2818. New Features Planned for 4.1
  2819. ----------------------------
  2820.  
  2821. The features below are not yet implemented in MySQL 4.1, but are planned
  2822. for implementation before MySQL 4.1 moves into its beta phase.  For a
  2823. list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  2824. features::.
  2825.  
  2826.    * Stable OpenSSL support (MySQL 4.0 supports rudimentary, not 100%
  2827.      tested, support for OpenSSL).
  2828.  
  2829.    * More testing of prepared statements.
  2830.  
  2831.    * More testing of multiple character sets for one table.
  2832.  
  2833. New Features Planned for 5.0
  2834. ----------------------------
  2835.  
  2836. The following features are planned for inclusion into MySQL 5.0.  Some
  2837. of the features such as stored procedures are complete and are included
  2838. in MySQL 5.0 alpha, which is available now.  Others such as cursors are
  2839. only partially available. Expect these and other features to mature and
  2840. be fully supported in upcoming releases.
  2841.  
  2842. Note that because we have many developers that are working on different
  2843. projects, there will also be many additional features. There is also a
  2844. small chance that some of these features will be added to MySQL 4.1.
  2845. For a list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  2846. features::.
  2847.  
  2848. For those wishing to take a look at the bleeding edge of MySQL
  2849. development, we make our BitKeeper repository for MySQL version 5.0
  2850. publicly available.  *Note Installing source tree::.  As of December
  2851. 2003, binary builds of version 5.0 are also available.
  2852.  
  2853. Stored Procedures
  2854.         * Stored procedures are currently implemented, based on the
  2855.           SQL:2003 standard.  *Note Stored Procedures::.
  2856.  
  2857.           We will also implement a framework to hook in external
  2858.           languages, and (where possible) compatibility with, for
  2859.           example, PL/SQL and T-SQL.
  2860.  
  2861. New functionality
  2862.         * Elementary cursor support.  *Note Cursors::.
  2863.  
  2864.         * The ability to specify explicitly for `MyISAM' tables that an
  2865.           index should be created as an `RTREE' index.  (In MySQL 4.1,
  2866.           `RTREE' indexes are used internally for geometrical data that
  2867.           use GIS datatypes, but cannot be created on request.)
  2868.  
  2869.         * Dynamic length rows for `HEAP' tables.
  2870.  
  2871. Standards compliance, portability and migration
  2872.         * Add true `VARCHAR' support (column lengths longer than 255,
  2873.           and no stripping of trailing whitespace).  (There is already
  2874.           support for this in the `MyISAM' storage engine, but it is
  2875.           not yet available at the user level.)
  2876.  
  2877. Speed enhancements
  2878.         * `SHOW COLUMNS FROM table_name' (used by `mysql' client to
  2879.           allow expansions of column names) should not open the table,
  2880.           only the definition file. This will require less memory and
  2881.           be much faster.
  2882.  
  2883.         * Allow `DELETE' on `MyISAM' tables to use the record cache.
  2884.           To do this, we need to update the threads record cache when
  2885.           we update the `.MYD' file.
  2886.  
  2887.         * Better support for `MEMORY' (`HEAP') tables:
  2888.              * Dynamic length rows.
  2889.  
  2890.              * Faster row handling (less copying).
  2891.  
  2892. Usability enhancements
  2893.         * Resolving the issue of `RENAME TABLE' on a table used in an
  2894.           active `MERGE' table possibly corrupting the table.
  2895.  
  2896. The news section of this manual includes a more in-depth list of
  2897. features.  *Note News-5.0.x::.
  2898.  
  2899. New Features Planned for 5.1
  2900. ----------------------------
  2901.  
  2902. New functionality
  2903.         * `FOREIGN KEY' support for all table types, not just `InnoDB'.
  2904.  
  2905.         * Column-level constraints.
  2906.  
  2907.         * Fail-safe replication.
  2908.  
  2909.         * Online backup with very low performance penalty.  The online
  2910.           backup will make it easy to add a new replication slave
  2911.           without taking down the master.
  2912.  
  2913. Speed enhancements
  2914.         * New text based table definition file format (`.frm' files)
  2915.           and a table cache for table definitions.  This will enable us
  2916.           to do faster queries of table structures and do more
  2917.           efficient foreign key support.
  2918.  
  2919.         * Optimize the `BIT' type to take 1 bit. (`BIT' now takes 1
  2920.           byte; it is treated as a synonym for `TINYINT'.)
  2921.  
  2922. Usability enhancements
  2923.         * Add options to the client/server protocol to get progress
  2924.           notes for long running commands.
  2925.  
  2926.         * Implement `RENAME DATABASE'. To make this safe for all
  2927.           storage engines, it should work as follows:
  2928.              * Create the new database.
  2929.  
  2930.              * For every table do a rename of the table to another
  2931.                database, as we do with the `RENAME' command.
  2932.  
  2933.              * Drop the old database.
  2934.  
  2935.         * New internal file interface change.  This will make all file
  2936.           handling much more general and make it easier to add
  2937.           extensions like RAID.
  2938.  
  2939. New Features Planned for the Near Future
  2940. ----------------------------------------
  2941.  
  2942. New functionality
  2943.         * Oracle-like `CONNECT BY PRIOR ...' to search tree-like
  2944.           (hierarchical) structures.
  2945.  
  2946.         * Add all missing SQL-92 and ODBC 3.0 types.
  2947.  
  2948.         * Add `SUM(DISTINCT)'.
  2949.  
  2950.         * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do
  2951.           a concurrent insert at the end of a table if the table is
  2952.           read-locked.
  2953.  
  2954.         * Allow variables to be updated in `UPDATE' statements. For
  2955.           example: `UPDATE TABLE foo SET @a=a+b,a=@a, b=@a+c'.
  2956.  
  2957.         * Change when user variables are updated so that one can use
  2958.           them with `GROUP BY', as in the following example: `SELECT
  2959.           id, @a:=COUNT(*), SUM(sum_col)/@a FROM table_name GROUP BY
  2960.           id'.
  2961.  
  2962.         * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  2963.           `TIMESTAMP' and `AUTO_INCREMENT' fields.
  2964.  
  2965.         * Add `LOAD DATA INFILE ... UPDATE' syntax that works like this:
  2966.              * For tables with primary keys, if an input record
  2967.                contains a primary key value, existing rows matching
  2968.                that primary key value are updated from the remainder of
  2969.                the input columns. However, columns corresponding to
  2970.                columns that are *missing* from the input record are not
  2971.                touched.
  2972.  
  2973.              * For tables with primary keys, if an input record does
  2974.                not contain the primary key value or is missing some
  2975.                part of the key, the record is treated as `LOAD DATA
  2976.                INFILE ... REPLACE INTO'.
  2977.  
  2978.         * Make `LOAD DATA INFILE' understand syntax like:
  2979.                LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
  2980.                     TEXT_FIELDS (text_field1, text_field2, text_field3)
  2981.                     SET table_field1=CONCAT(text_field1, text_field2),
  2982.                         table_field3=23
  2983.                     IGNORE text_field3
  2984.           This can be used to skip over extra columns in the text file,
  2985.           or update columns based on expressions of the read data.
  2986.  
  2987.         * New functions for working with `SET' type columns:
  2988.              * `ADD_TO_SET(value,set)'
  2989.  
  2990.              * `REMOVE_FROM_SET(value,set)'
  2991.  
  2992.         * If you abort `mysql' in the middle of a query, you should open
  2993.           another connection and kill the old running query.
  2994.           Alternatively, an attempt should be made to detect this in
  2995.           the server.
  2996.  
  2997.         * Add a storage engine interface for table information so that
  2998.           you can use it as a system table. This would be a bit slow if
  2999.           you requested information about all tables, but very
  3000.           flexible.  `SHOW INFO FROM tbl_name' for basic table
  3001.           information should be implemented.
  3002.  
  3003.         * Allow `SELECT a FROM table_name1 LEFT JOIN table_name2 USING
  3004.           (a)'; in this case `a' is assumed to come from the
  3005.           `table_name1' table.
  3006.  
  3007.         * `DELETE' and `REPLACE' options to the `UPDATE' statement
  3008.           (this will delete rows when one gets a duplicate key error
  3009.           while updating).
  3010.  
  3011.         * Change the format of `DATETIME' to store fractions of seconds.
  3012.  
  3013.         * Make it possible to use the new GNU `regexp' library instead
  3014.           of the current one (the new library should be much faster
  3015.           than the current one).
  3016.  
  3017. Standards compliance, portability and migration
  3018.         * Don't add automatic `DEFAULT' values to columns.  Produce an
  3019.           error for any `INSERT' statement that is missing a value for
  3020.           a column that has no `DEFAULT'.
  3021.  
  3022.         * Add `ANY()', `EVERY()', and `SOME()' group functions. In
  3023.           standard SQL, these work only on boolean columns, but we can
  3024.           extend these to work on any columns or expressions by
  3025.           treating 0 values as FALSE and non-zero values as TRUE.
  3026.  
  3027.         * Fix the type of `MAX(column)' to be the same as the column
  3028.           type:
  3029.                mysql> CREATE TABLE t1 (a DATE);
  3030.                mysql> INSERT INTO t1 VALUES (NOW());
  3031.                mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
  3032.                mysql> SHOW COLUMNS FROM t2;
  3033.  
  3034. Speed enhancements
  3035.         * Don't allow more than a defined number of threads to run
  3036.           `MyISAM' recovery at the same time.
  3037.  
  3038.         * Change `INSERT ... SELECT' to optionally use concurrent
  3039.           inserts.
  3040.  
  3041.         * Add an option to periodically flush key pages for tables with
  3042.           delayed keys if they haven't been used in a while.
  3043.  
  3044.         * Allow join on key parts (optimization issue).
  3045.  
  3046.         * Add a log file analyzer that can parse out information about
  3047.           which tables are hit most often, how often multiple-table
  3048.           joins are executed, etc.  This should help users identify
  3049.           areas of table design that could be optimized to execute much
  3050.           more efficient queries.
  3051.  
  3052. Internationalization
  3053.  
  3054. Usability enhancements
  3055.         * Return the original column types when doing `SELECT
  3056.           MIN(column) ... GROUP BY'.
  3057.  
  3058.         * Make it possible to specify `long_query_time' with a
  3059.           granularity in microseconds.
  3060.  
  3061.         * Link the `myisampack' code into the server so that it can
  3062.           perform `PACK' or `COMPRESS' operations.
  3063.  
  3064.         * Add a temporary key buffer cache during
  3065.           `INSERT/DELETE/UPDATE' so that we can gracefully recover if
  3066.           the index file gets full.
  3067.  
  3068.         * If you perform an `ALTER TABLE' on a table that is symlinked
  3069.           to another disk, create temporary tables on that disk.
  3070.  
  3071.         * Implement a `DATE/DATETIME' type that handles time zone
  3072.           information properly, to make dealing with dates in different
  3073.           time zones easier.
  3074.  
  3075.         * Fix `configure' so that one can compile all libraries (like
  3076.           `MyISAM') without threads.
  3077.  
  3078.         * Allow SQL variables as `LIMIT' arguments, for example, `LIMIT
  3079.           @a,@b'.
  3080.  
  3081.         * Automatic output from `mysql' to a web browser.
  3082.  
  3083.         * `LOCK DATABASES' (with various options).
  3084.  
  3085.         * Many more variables for `SHOW STATUS'.  Records reads and
  3086.           updates.  Selects on a single table and selects with joins.
  3087.           Mean number of tables in select. Number of `ORDER BY' and
  3088.           `GROUP BY' queries.
  3089.  
  3090.         * `mysqladmin copy database new-database'; this requires a
  3091.           `COPY' operation to be added to `mysqld'.
  3092.  
  3093.         * Processlist output should indicate the number of
  3094.           queries/threads.
  3095.  
  3096.         * `SHOW HOSTS' for printing information about the hostname
  3097.           cache.
  3098.  
  3099.         * Change table names from empty strings to `NULL' for
  3100.           calculated columns.
  3101.  
  3102.         * Don't use `Item_copy_string' on numerical values to avoid
  3103.           number->string->number conversion in case of: `SELECT
  3104.           COUNT(*)*(id+0) FROM table_name GROUP BY id'
  3105.  
  3106.         * Change so that `ALTER TABLE' doesn't abort clients that
  3107.           execute `INSERT DELAYED'.
  3108.  
  3109.         * Fix so that when columns are referenced in an `UPDATE' clause,
  3110.           they contain the old values from before the update started.
  3111.  
  3112. New operating systems
  3113.         * Port the MySQL clients to LynxOS.
  3114.  
  3115. New Features Planned for the Mid-Term Future
  3116. --------------------------------------------
  3117.  
  3118.    * Implement function:
  3119.      `get_changed_tables(timeout,table1,table2,...)'.
  3120.  
  3121.    * Change reading through tables to use memmap when possible. Now only
  3122.      compressed tables use memmap.
  3123.  
  3124.    * Make the automatic timestamp code nicer.  Add timestamps to the
  3125.      update log with `SET TIMESTAMP=#;'.
  3126.  
  3127.    * Use read/write mutex in some places to get more speed.
  3128.  
  3129.    * Simple views (implemented in stepwise fashion up to full
  3130.      functionality).  *Note ANSI diff Views::.
  3131.  
  3132.    * Automatically close some tables if a table, temporary table, or
  3133.      temporary file gets error 23 (too many open files).
  3134.  
  3135.    * Better constant propagation. When an occurrence of `col_name=n' is
  3136.      found in an expression, for some constant `n', replace other
  3137.      occurrences of `col_name' within the expression with `n'.
  3138.      Currently, this is done only for some simple cases.
  3139.  
  3140.    * Change all const expressions with calculated expressions if
  3141.      possible.
  3142.  
  3143.    * Optimize key = expression comparisons. At the moment only key =
  3144.      field or key = constant comparisons are optimized.
  3145.  
  3146.    * Join some of the copy functions for nicer code.
  3147.  
  3148.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  3149.      better error messages.
  3150.  
  3151.    * Change the parser to use only one rule per different number of
  3152.      arguments in function.
  3153.  
  3154.    * Use of full calculation names in the order part (for ACCESS97).
  3155.  
  3156.    * `MINUS', `INTERSECT', and `FULL OUTER JOIN'.  (Currently `UNION'
  3157.      [in 4.0] and `LEFT|RIGHT OUTER JOIN' are supported.)
  3158.  
  3159.    * Allow `SQL_OPTION MAX_SELECT_TIME=#', for placing a time limit on
  3160.      a query.
  3161.  
  3162.    * Allow updates to be logged to a database.
  3163.  
  3164.    * Enhance `LIMIT' to allow retrieval of data from the end of a
  3165.      result set.
  3166.  
  3167.    * Alarm around client connect/read/write functions.
  3168.  
  3169.    * Please note the changes to `mysqld_safe': according to FSSTND
  3170.      (which Debian tries to follow) PID files should go into
  3171.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  3172.      be nice if you could put the "DATADIR" in the first declaration of
  3173.      "pidfile" and "log", so the placement of these files can be
  3174.      changed with a single statement.
  3175.  
  3176.    * Allow a client to request logging.
  3177.  
  3178.    * Allow the `LOAD DATA INFILE' statement to read files that have
  3179.      been compressed with `gzip'.
  3180.  
  3181.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  3182.  
  3183.    * Change to use semaphores when counting threads.  One should first
  3184.      implement a semaphore library for MIT-pthreads.
  3185.  
  3186.    * Add full support for `JOIN' with parentheses.
  3187.  
  3188.    * As an alternative to the one-thread-per-connection model, manage a
  3189.      pool of threads to handle queries.
  3190.  
  3191.    * Allow `GET_LOCK()' to obtain more than one lock.  When doing this,
  3192.      one must also handle the possible deadlocks this change will
  3193.      introduce.
  3194.  
  3195. New Features We Don't Plan to Implement
  3196. ---------------------------------------
  3197.  
  3198. We aim toward full compliance with SQL-92/SQL-99, so there are no
  3199. features we plan not to implement.
  3200.  
  3201. MySQL Information Sources
  3202. =========================
  3203.  
  3204. MySQL Mailing Lists
  3205. -------------------
  3206.  
  3207. This section introduces you to the MySQL mailing lists and provides
  3208. some guidelines as to how the lists should be used. When you subscribe
  3209. to a mailing list, you will receive all postings to the list as email
  3210. messages. You can also to send your own questions and answers to the
  3211. list.
  3212.  
  3213. The MySQL Mailing Lists
  3214. .......................
  3215.  
  3216. To subscribe to or unsubscribe from any of the mailing lists described
  3217. in this section, visit `http://lists.mysql.com/'.  Please *do not* send
  3218. messages about subscribing or unsubscribing to any of the mailing
  3219. lists, because such messages are distributed automatically to thousands
  3220. of other users.
  3221.  
  3222. Your local site may have many subscribers to a MySQL mailing list.  If
  3223. so, the site may have a local mailing list, so that messages sent from
  3224. `lists.mysql.com' to your site are propagated to the local list.  In
  3225. such cases, please contact your system administrator to be added to or
  3226. dropped from the local MySQL list.
  3227.  
  3228. If you wish to have traffic for a mailing list go to a separate mailbox
  3229. in your mail program, set up a filter based on the message headers.
  3230. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  3231. list messages.
  3232.  
  3233. The MySQL mailing lists are as follows:
  3234.  
  3235. ``announce''
  3236.      This list is for announcements of new versions of MySQL and related
  3237.      programs.  This is a low-volume list to which all MySQL users
  3238.      should subscribe.
  3239.  
  3240. ``mysql''
  3241.      This is the main list for general MySQL discussion.  Please note
  3242.      that some topics are better discussed on the more-specialized
  3243.      lists.  If you post to the wrong list, you may not get an answer.
  3244.  
  3245. ``mysql-digest''
  3246.      This is the `mysql' list in digest form.  Subscribing to this list
  3247.      means you will get all list messages, sent as one large mail
  3248.      message once a day.
  3249.  
  3250. ``bugs''
  3251.      This list will be of interest to you if you want to stay informed
  3252.      about issues reported since the last release of `MySQL' or if you
  3253.      want to be actively involved in the process of bug hunting and
  3254.      fixing.  *Note Bug reports::.
  3255.  
  3256. ``bugs-digest''
  3257.      This is the `bugs' list in digest form.
  3258.  
  3259. ``internals''
  3260.      This list is for people who work on the MySQL code.  This is also
  3261.      the forum for discussions on MySQL development and post patches.
  3262.  
  3263. ``internals-digest''
  3264.      This is the `internals' list in digest form.
  3265.  
  3266. ``mysqldoc''
  3267.      This list is for people who work on the MySQL documentation:
  3268.      people from MySQL AB, translators, and other community members.
  3269.  
  3270. ``mysqldoc-digest''
  3271.      This is the `mysqldoc' list in digest form.
  3272.  
  3273. ``benchmarks''
  3274.      This list is for anyone interested in performance issues.
  3275.      Discussions concentrate on database performance (not limited to
  3276.      MySQL) but also include broader categories such as performance of
  3277.      the kernel, file system, disk system, and so on.
  3278.  
  3279. ``benchmarks-digest''
  3280.      This is the `benchmarks' list in digest form.
  3281.  
  3282. ``packagers''
  3283.      This list is for discussions on packaging and distributing MySQL.
  3284.      This is the forum used by distribution maintainers to exchange
  3285.      ideas on packaging MySQL and on ensuring that MySQL looks and
  3286.      feels as similar as possible on all supported platforms and
  3287.      operating systems.
  3288.  
  3289. ``packagers-digest''
  3290.      This is the `packagers' list in digest form.
  3291.  
  3292. ``java''
  3293.      This list is for discussions about the MySQL server and Java.It is
  3294.      mostly used to discuss JDBC drivers, including MySQL Connector/J.
  3295.  
  3296. ``java-digest''
  3297.      This is the `java' list in digest form.
  3298.  
  3299. ``win32''
  3300.      This list is for all topics concerning the MySQL software on
  3301.      Microsoft operating systems, such as Windows 9x/Me/NT/2000/XP.
  3302.  
  3303. ``win32-digest''
  3304.      This is the `win32' list in digest form.
  3305.  
  3306. ``myodbc''
  3307.      This list is for all topics concerning connecting to the MySQL
  3308.      server with ODBC.
  3309.  
  3310. ``myodbc-digest''
  3311.      This is the `myodbc' list in digest form.
  3312.  
  3313. ``mysqlcc''
  3314.      This list is for all topics concerning the `MySQL Control Center'
  3315.      graphical client.
  3316.  
  3317. ``mysqlcc-digest''
  3318.      This is the `mysqlcc' list in digest form.
  3319.  
  3320. ``plusplus''
  3321.      This list is for all topics concerning programming with the C++
  3322.      API to MySQL.
  3323.  
  3324. ``plusplus-digest''
  3325.      This is the `plusplus' list in digest form.
  3326.  
  3327. ``msql-mysql-modules''
  3328.      This list is for all topics concerning the Perl support for MySQL
  3329.      with `msql-mysql-modules', which is now named `DBD::mysql'.
  3330.  
  3331. ``msql-mysql-modules-digest''
  3332.      This is the `msql-mysql-modules' list in digest form.
  3333.  
  3334. If you're unable to get an answer to your questions from a `MySQL'
  3335. mailing list, one option is to purchase support from MySQL AB. This
  3336. will put you in direct contact with MySQL developers. *Note Support::.
  3337.  
  3338. The following table shows some MySQL mailing lists in languages other
  3339. than English.  These lists are not operated by MySQL AB.
  3340.  
  3341. `<mysql-france-subscribe@yahoogroups.com>'
  3342.      A French mailing list.
  3343.  
  3344. `<list@tinc.net>'
  3345.      A Korean mailing list.  Email `subscribe mysql your@email.address'
  3346.      to this list.
  3347.  
  3348. `<mysql-de-request@lists.4t2.com>'
  3349.      A German mailing list.  Email `subscribe mysql-de
  3350.      your@email.address' to this list.  You can find information about
  3351.      this mailing list at `http://www.4t2.com/mysql/'.
  3352.  
  3353. `<mysql-br-request@listas.linkway.com.br>'
  3354.      A Portuguese mailing list.  Email `subscribe mysql-br
  3355.      your@email.address' to this list.
  3356.  
  3357. `<mysql-alta@elistas.net>'
  3358.      A Spanish mailing list.  Email `subscribe mysql
  3359.      your@email.address' to this list.
  3360.  
  3361. Asking Questions or Reporting Bugs
  3362. ..................................
  3363.  
  3364. Before posting a bug report or question, please do the following:
  3365.  
  3366.    * Start by searching the MySQL online manual at
  3367.      `http://www.mysql.com/doc/'.  We try to keep the manual up to date
  3368.      by updating it frequently with solutions to newly found problems.
  3369.      The change history appendix
  3370.      (`http://www.mysql.com/doc/en/News.html') can be particularly
  3371.      useful since it is quite possible that a newer version already
  3372.      contains a solution to your problem.
  3373.  
  3374.    * Search in the bugs database at `http://bugs.mysql.com/' to see
  3375.      whether the bug has already been reported and fixed.
  3376.  
  3377.    * Search the MySQL mailing list archives at
  3378.      `http://lists.mysql.com/'.
  3379.  
  3380.    * You can also use `http://www.mysql.com/search/' to search all the
  3381.      web pages (including the manual) that are located at the MySQL AB
  3382.      web site.
  3383.  
  3384. If you can't find an answer in the manual or the archives, check with
  3385. your local MySQL expert.  If you still can't find an answer to your
  3386. question, please follow the guidelines on sending mail to a MySQL
  3387. mailing list, outlined in the next section, before contacting us.
  3388.  
  3389. How to Report Bugs or Problems
  3390. ..............................
  3391.  
  3392. The normal place to report bugs is `http://bugs.mysql.com/', which is
  3393. the address for our bugs database.  This database is public, and can be
  3394. browsed and searched by anyone.  If you log into the system, you will
  3395. also be able to enter new reports.
  3396.  
  3397. Writing a good bug report takes patience, but doing it right the first
  3398. time saves time both for us and for yourself.  A good bug report,
  3399. containing a full test case for the bug, makes it very likely that we
  3400. will fix the bug in the next release.  This section will help you write
  3401. your report correctly so that you don't waste your time doing things
  3402. that may not help us much or at all.
  3403.  
  3404. We encourage everyone to use the `mysqlbug' script to generate a bug
  3405. report (or a report about any problem).  `mysqlbug' can be found in the
  3406. `scripts' directory (source distribution) and in the `bin' directory
  3407. under your MySQL installation directory (binary distribution).  If you
  3408. are unable to use `mysqlbug' (for instance, if you are running on
  3409. Windows), it is still vital that you include all the necessary
  3410. information noted in this section (most importantly a description of
  3411. the operating system and the MySQL version).
  3412.  
  3413. The `mysqlbug' script helps you generate a report by determining much
  3414. of the following information automatically, but if something important
  3415. is missing, please include it with your message.  Please read this
  3416. section carefully and make sure that all the information described here
  3417. is included in your report.
  3418.  
  3419. Preferably, you should test the problem using the latest production or
  3420. development version of MySQL Server before posting.  Anyone should be
  3421. able to repeat the bug by just using '`mysql test < script'' on the
  3422. included test case or by running the shell or Perl script that is
  3423. included in the bug report.
  3424.  
  3425. All bugs posted in the bugs database at `http://bugs.mysql.com/' will
  3426. be corrected or documented in the next MySQL release. If only minor
  3427. code changes are needed to correct a problem, we will also post a patch
  3428. that fixes the problem.
  3429.  
  3430. If you have found a sensitive security bug in MySQL, please send an
  3431. email to <security@mysql.com>.
  3432.  
  3433. If you have a repeatable bug report, please report it to the bugs
  3434. database at `http://bugs.mysql.com/'.  Note that even in this case it's
  3435. good to run the `mysqlbug' script first to find information about your
  3436. system.  Any bug that we are able to repeat has a high chance of being
  3437. fixed in the next MySQL release.
  3438.  
  3439. To report other problems, you can use one of the MySQL mailing lists.
  3440.  
  3441. Remember that it is possible for us to respond to a message containing
  3442. too much information, but not to one containing too little.  People
  3443. often omit facts because they think they know the cause of a problem
  3444. and assume that some details don't matter.  A good principle is: If you
  3445. are in doubt about stating something, state it.  It is faster and less
  3446. troublesome to write a couple more lines in your report than to wait
  3447. longer for the answer if we must ask you to provide information that
  3448. was missing from the initial report.
  3449.  
  3450. The most common errors made in bug reports are (a) not including the
  3451. version number of the MySQL distribution used and (b) not fully
  3452. describing the platform on which the MySQL server is installed
  3453. (including the platform type and version number).  This is highly
  3454. relevant information, and in 99 cases out of 100 the bug report is
  3455. useless without it.  Very often we get questions like, "Why doesn't
  3456. this work for me?" Then we find that the feature requested wasn't
  3457. implemented in that MySQL version, or that a bug described in a report
  3458. has already been fixed in newer MySQL versions.  Sometimes the error is
  3459. platform-dependent; in such cases, it is next to impossible for us to
  3460. fix anything without knowing the operating system and the version
  3461. number of the platform.
  3462.  
  3463. If you compiled MySQL from source, remember also to provide information
  3464. about your compiler, if it is related to the problem.  Often people
  3465. find bugs in compilers and think the problem is MySQL-related.  Most
  3466. compilers are under development all the time and become better version
  3467. by version.  To determine whether your problem depends on your
  3468. compiler, we need to know what compiler you use.  Note that every
  3469. compiling problem should be regarded as a bug and reported accordingly.
  3470.  
  3471. It is most helpful when a good description of the problem is included
  3472. in the bug report.  That is, give a good example of everything you did
  3473. that led to the problem and describe, in exact detail, the problem
  3474. itself.  The best reports are those that include a full example showing
  3475. how to reproduce the bug or problem.  *Note Reproduceable test case::.
  3476.  
  3477. If a program produces an error message, it is very important to include
  3478. the message in your report.  If we try to search for something from the
  3479. archives using programs, it is better that the error message reported
  3480. exactly matches the one that the program produces.  (Even the case
  3481. should be observed.)  You should never try to remember what the error
  3482. message was; instead, copy and paste the entire message into your
  3483. report.
  3484.  
  3485. If you have a problem with Connector/ODBC (MyODBC), please try to
  3486. generate a MyODBC trace file and send it with your report.  *Note
  3487. MyODBC bug report::.
  3488.  
  3489. Please remember that many of the people who will read your report will
  3490. do so using an 80-column display.  When generating reports or examples
  3491. using the `mysql' command-line tool, you should therefore use the
  3492. `--vertical' option (or the `\G' statement terminator) for output that
  3493. would exceed the available width for such a display (for example, with
  3494. the `EXPLAIN SELECT' statement; see the example later in this section).
  3495.  
  3496. Please include the following information in your report:
  3497.  
  3498.    * The version number of the MySQL distribution you are using (for
  3499.      example, MySQL Version 4.0.12). You can find out which version you
  3500.      are running by executing `mysqladmin version'.  `mysqladmin' can be
  3501.      found in the `bin' directory under your MySQL installation
  3502.      directory.
  3503.  
  3504.    * The manufacturer and model of the machine on which you experience
  3505.      the problem.
  3506.  
  3507.    * The operating system name and version.  If you work with Windows,
  3508.      you can usually get the name and version number by double-clicking
  3509.      your "My Computer" icon and pulling down the "Help/About Windows"
  3510.      menu.  For most Unix-like operating systems, you can get this
  3511.      information by executing the command `uname -a'.
  3512.  
  3513.    * Sometimes the amount of memory (real and virtual) is relevant. If
  3514.      in doubt, include these values.
  3515.  
  3516.    * If you are using a source distribution of the MySQL software, the
  3517.      name and version number of the compiler used is needed.  If you
  3518.      have a binary distribution, the distribution name is needed.
  3519.  
  3520.    * If the problem occurs during compilation, include the exact error
  3521.      messages and also a few lines of context around the offending code
  3522.      in the file where the error occurrs.
  3523.  
  3524.    * If `mysqld' died, you should also report the query that crashed
  3525.      `mysqld'.  You can usually find this out by running `mysqld' with
  3526.      logging enabled.  *Note Using log files::.
  3527.  
  3528.    * If a database table is related to the problem, include the output
  3529.      from `mysqldump --no-data db_name tbl_name1 tbl_name2 ...'.  This
  3530.      is very easy to do and is a powerful way to get information about
  3531.      any table in a database.  The information will help us create a
  3532.      situation matching the one you have.
  3533.  
  3534.    * For speed-related bugs or problems with `SELECT' statements, you
  3535.      should always include the output of `EXPLAIN SELECT ...', and at
  3536.      least the number of rows that the `SELECT' statement produces.  You
  3537.      should also include the output from `SHOW CREATE TABLE tbl_name'
  3538.      for each involved table. The more information you give about your
  3539.      situation, the more likely it is that someone can help you.
  3540.  
  3541.      The following is an example of a very good bug report. It should
  3542.      be posted with the `mysqlbug' script.  The example uses the `mysql'
  3543.      command-line tool. Note the use of the `\G' statement terminator
  3544.      for statements whose output width would otherwise exceed that of
  3545.      an 80-column display device.
  3546.  
  3547.           mysql> SHOW VARIABLES;
  3548.           mysql> SHOW COLUMNS FROM ...\G
  3549.                  <output from SHOW COLUMNS>
  3550.           mysql> EXPLAIN SELECT ...\G
  3551.                  <output from EXPLAIN>
  3552.           mysql> FLUSH STATUS;
  3553.           mysql> SELECT ...;
  3554.                  <A short version of the output from SELECT,
  3555.                  including the time taken to run the query>
  3556.           mysql> SHOW STATUS;
  3557.                  <output from SHOW STATUS>
  3558.  
  3559.    * If a bug or problem occurs while running `mysqld', try to provide
  3560.      an input script that will reproduce the anomaly.  This script
  3561.      should include any necessary source files.  The more closely the
  3562.      script can reproduce your situation, the better.  If you can make
  3563.      a reproducible test case, you should post it on
  3564.      `http://bugs.mysql.com/' for high-priority treatment.
  3565.  
  3566.      If you can't provide a script, you should at least include the
  3567.      output from `mysqladmin variables extended-status processlist' in
  3568.      your mail to provide some information on how your system is
  3569.      performing.
  3570.  
  3571.    * If you can't produce a test case with only a few rows, or if the
  3572.      test table is too big to be mailed to the mailing list (more than
  3573.      10 rows), you should dump your tables using `mysqldump' and create
  3574.      a `README' file that describes your problem.
  3575.  
  3576.      Create a compressed archive of your files using `tar' and `gzip'
  3577.      or `zip', and use `ftp' to transfer the archive to
  3578.      `ftp://support.mysql.com/pub/mysql/secret/'.  Then enter the
  3579.      problem into our bugs database at `http://bugs.mysql.com/'.
  3580.  
  3581.    * If you think that the MySQL server produces a strange result from
  3582.      a query, include not only the result, but also your opinion of
  3583.      what the result should be, and an account describing the basis for
  3584.      your opinion.
  3585.  
  3586.    * When giving an example of the problem, it's better to use the
  3587.      variable names, table names, etc., that exist in your actual
  3588.      situation than to come up with new names.  The problem could be
  3589.      related to the name of a variable or table.  These cases are rare,
  3590.      perhaps, but it is better to be safe than sorry.  After all, it
  3591.      should be easier for you to provide an example that uses your
  3592.      actual situation, and it is by all means better for us.  In case
  3593.      you have data you don't want to show to others, you can use `ftp'
  3594.      to transfer it to `ftp://support.mysql.com/pub/mysql/secret/'.  If
  3595.      the data is really top secret and you don't want to show it even
  3596.      to us, then go ahead and provide an example using other names, but
  3597.      please regard this as the last choice.
  3598.  
  3599.    * Include all the options given to the relevant programs, if
  3600.      possible.  For example, indicate the options that you use when you
  3601.      start the `mysqld' server as well as the options that you use to
  3602.      run any MySQL client programs.  The options to programs like
  3603.      `mysqld' and `mysql', and to the `configure' script, are often
  3604.      keys to answers and are very relevant.  It is never a bad idea to
  3605.      include them.  If you use any modules, such as Perl or PHP, please
  3606.      include the version numbers of those as well.
  3607.  
  3608.    * If your question is related to the privilege system, please
  3609.      include the output of `mysqlaccess', the output of `mysqladmin
  3610.      reload', and all the error messages you get when trying to
  3611.      connect.  When you test your privileges, you should first run
  3612.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  3613.      and try to connect with the program that gives you trouble.
  3614.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  3615.      installation directory.
  3616.  
  3617.    * If you have a patch for a bug, do include it.  But don't assume
  3618.      the patch is all we need, or that we will use it, if you don't
  3619.      provide some necessary information such as test cases showing the
  3620.      bug that your patch fixes.  We might find problems with your patch
  3621.      or we might not understand it at all; if so, we can't use it.
  3622.  
  3623.      If we can't verify exactly what the purpose of the patch is, we
  3624.      won't use it.  Test cases will help us here.  Show that the patch
  3625.      will handle all the situations that may occur.  If we find a
  3626.      borderline case (even a rare one) where the patch won't work, it
  3627.      may be useless.
  3628.  
  3629.    * Guesses about what the bug is, why it occurs, or what it depends on
  3630.      are usually wrong.  Even the MySQL team can't guess such things
  3631.      without first using a debugger to determine the real cause of a
  3632.      bug.
  3633.  
  3634.    * Indicate in your bug report that you have checked the reference
  3635.      manual and mail archive so that others know you have tried to
  3636.      solve the problem yourself.
  3637.  
  3638.    * If you get a `parse error', please check your syntax closely.  If
  3639.      you can't find something wrong with it, it's extremely likely that
  3640.      your current version of MySQL Server doesn't support the syntax
  3641.      you are using.  If you are using the current version and the
  3642.      manual at `http://www.mysql.com/doc/' doesn't cover the syntax you
  3643.      are using, MySQL Server doesn't support your query.  In this case,
  3644.      your only options are to implement the syntax yourself or email
  3645.      <licensing@mysql.com> and ask for an offer to implement it.
  3646.  
  3647.      If the manual covers the syntax you are using, but you have an
  3648.      older version of MySQL Server, you should check the MySQL change
  3649.      history to see when the syntax was implemented.  In this case, you
  3650.      have the option of upgrading to a newer version of MySQL Server.
  3651.      *Note News::.
  3652.  
  3653.    * If your problem is that your data appears corrupt or you get errors
  3654.      when you access a particular table, you should first check and
  3655.      then try to repair your tables with `CHECK TABLE' and `REPAIR
  3656.      TABLE' or with `myisamchk'.  *Note MySQL Database Administration::.
  3657.  
  3658.      If you are running Windows, please check that
  3659.      `lower_case_table_names is 1 or 2' with `SHOW VARIABLES LIKE
  3660.      'lower_case_table_names''.
  3661.  
  3662.    * If you often get corrupted tables, you should try to find out when
  3663.      and why this happens.  In this case, the error log in the MySQL
  3664.      data directory may contain some information about what happened.
  3665.      (This is the file with the `.err' suffix in the name.)  *Note
  3666.      Error log::.  Please include any relevant information from this
  3667.      file in your bug report.  Normally `mysqld' should *never* crash a
  3668.      table if nothing killed it in the middle of an update.  If you can
  3669.      find the cause of `mysqld' dying, it's much easier for us to
  3670.      provide you with a fix for the problem.  *Note What is crashing::.
  3671.  
  3672.    * If possible, download and install the most recent version of MySQL
  3673.      Server and check whether it solves your problem.  All versions of
  3674.      the MySQL software are thoroughly tested and should work without
  3675.      problems.  We believe in making everything as backward-compatible
  3676.      as possible, and you should be able to switch MySQL versions
  3677.      without difficulty.  *Note Which version::.
  3678.  
  3679. If you are a support customer, please cross-post the bug report to
  3680. <mysql-support@mysql.com> for higher-priority treatment, as well as to
  3681. the appropriate mailing list to see whether someone else has
  3682. experienced (and perhaps solved) the problem.
  3683.  
  3684. For information on reporting bugs in `MyODBC', see *Note ODBC
  3685. Problems::.
  3686.  
  3687. For solutions to some common problems, see *Note Problems::.
  3688.  
  3689. When answers are sent to you individually and not to the mailing list,
  3690. it is considered good etiquette to summarize the answers and send the
  3691. summary to the mailing list so that others may have the benefit of
  3692. responses you received that helped you solve your problem.
  3693.  
  3694. Guidelines for Answering Questions on the Mailing List
  3695. ......................................................
  3696.  
  3697. If you consider your answer to have broad interest, you may want to
  3698. post it to the mailing list instead of replying directly to the
  3699. individual who asked.  Try to make your answer general enough that
  3700. people other than the original poster may benefit from it.  When you
  3701. post to the list, please make sure that your answer is not a
  3702. duplication of a previous answer.
  3703.  
  3704. Try to summarize the essential part of the question in your reply;
  3705. don't feel obliged to quote the entire original message.
  3706.  
  3707. Please don't post mail messages from your browser with HTML mode turned
  3708. on.  Many users don't read mail with a browser.
  3709.  
  3710. MySQL Community Support on IRC (Internet Relay Chat)
  3711. ----------------------------------------------------
  3712.  
  3713. In addition to the various MySQL mailing lists, you can find experienced
  3714. community people on `IRC' (`Internet Relay Chat').  These are the best
  3715. networks/channels currently known to us:
  3716.  
  3717.    * *freenode* (see `http://www.freenode.net/' for servers)
  3718.         * `#mysql' Primarily MySQL questions but other database and SQL
  3719.           questions welcome.
  3720.  
  3721.         * `#mysqlphp' Questions about MySQL+PHP, a popular combination.
  3722.  
  3723.         * `#mysqlperl' Questions about MySQL+Perl, another popular
  3724.           combination.
  3725.  
  3726.    * *EFnet* (see `http://www.efnet.org/' for servers)
  3727.         * `#mysql' MySQL questions.
  3728.  
  3729. If you are looking for IRC client software to connect to an IRC network,
  3730. take a look at `X-Chat' (`http://www.xchat.org/').  X-Chat (GPL
  3731. licensed) is available for Unix as well as for Windows platforms.
  3732.  
  3733. MySQL Standards Compliance
  3734. ==========================
  3735.  
  3736. This section describes how MySQL relates to the ANSI/ISO SQL standards.
  3737. MySQL Server has many extensions to the SQL standard, and here you will
  3738. find out what they are and how to use them.  You will also find
  3739. information about functionality missing from MySQL Server, and how to
  3740. work around some differences.
  3741.  
  3742. Our goal is to not restrict MySQL Server usability for any usage
  3743. without a very good reason for doing so.  Even if we don't have the
  3744. resources to perform  development for every possible use, we are always
  3745. willing to help and offer suggestions to people who are trying to use
  3746. MySQL Server in new territories.
  3747.  
  3748. One of our main goals with the product is to continue to work toward
  3749. compliance with the SQL-99 standard, but without sacrificing speed or
  3750. reliability.  We are not afraid to add extensions to SQL or support for
  3751. non-SQL features if this greatly increases the usability of MySQL
  3752. Server for a large segment of our user base.  (The new `HANDLER'
  3753. interface in MySQL Server 4.0 is an example of this strategy. *Note
  3754. `HANDLER': HANDLER.)
  3755.  
  3756. We will continue to support transactional and non-transactional
  3757. databases to satisfy both mission-critical 24/7 usage and heavy
  3758. web/logging usage.
  3759.  
  3760. MySQL Server was designed from the start to work with medium size
  3761. databases (10-100 million rows, or about 100 MB per table) on small
  3762. computer systems.  We will continue to extend MySQL Server to work even
  3763. better with terabyte-size databases, as well as to make it possible to
  3764. compile a reduced MySQL version that is more suitable for hand-held
  3765. devices and embedded usage.  The compact design of the MySQL server
  3766. makes development in both of these directions possible without any
  3767. conflicts in the source tree.
  3768.  
  3769. We are currently not targeting realtime support, though you can already
  3770. do a lot of things with our replication capabilities.
  3771.  
  3772. Database cluster support is planned to begin sometime in 2004 through
  3773. implementation of a new storage engine.
  3774.  
  3775. We are looking at providing XML support in the database server.
  3776.  
  3777. What Standards MySQL Follows
  3778. ----------------------------
  3779.  
  3780. Entry-level SQL-92. ODBC levels 0-3.51.
  3781.  
  3782. We are aiming toward supporting the full SQL-99 standard, but without
  3783. making concessions to speed and quality of the code.
  3784.  
  3785. Selecting SQL Modes
  3786. -------------------
  3787.  
  3788. The MySQL server can operate in different SQL modes, and can apply these
  3789. modes differentially for different clients. This allows applications to
  3790. tailor server operation to their own requirements.
  3791.  
  3792. Modes define what SQL syntax MySQL should support and what kind of
  3793. validation checks it should perform on the data.  This makes it easier
  3794. to use MySQL in a lot of different environments and to use MySQL
  3795. together with other database servers.
  3796.  
  3797. You can set the default SQL mode by starting `mysqld' with the
  3798. `--sql-mode="modes"' option. Beginning with MySQL 4.1, you can also
  3799. change the mode after startup time by setting the `sql_mode' variable
  3800. with a `SET [SESSION|GLOBAL] sql_mode='modes'' statement.
  3801.  
  3802. For more information on setting the server mode, see *Note Server SQL
  3803. mode::.
  3804.  
  3805. Running MySQL in ANSI Mode
  3806. --------------------------
  3807.  
  3808. You can tell `mysqld' to use the ANSI mode with the `--ansi' startup
  3809. option. *Note Server options::.
  3810.  
  3811. Running the server in ANSI mode is the same as starting it with these
  3812. options:
  3813.  
  3814.      --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  3815.      --transaction-isolation=SERIALIZABLE
  3816.  
  3817. In MySQL 4.1, you can achieve the same effect with these two statements:
  3818.  
  3819.      SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3820.      SET GLOBAL sql_mode =
  3821.        "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY";
  3822.  
  3823. *Note SQL mode::.
  3824.  
  3825. In MySQL 4.1.1, the `sql_mode' options shown can be also be set with:
  3826.  
  3827.      SET GLOBAL sql_mode="ansi";
  3828.  
  3829. In this case, the value of the `sql_mode' variable will be set to all
  3830. options that are relevant for ANSI mode. You can check the result by
  3831. doing:
  3832.  
  3833.      mysql> SET GLOBAL sql_mode="ansi";
  3834.      mysql> SELECT @@GLOBAL.sql_mode;
  3835.              -> "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI"
  3836.  
  3837. MySQL Extensions to the SQL-92 Standard
  3838. ---------------------------------------
  3839.  
  3840. MySQL Server includes some extensions that you probably will not find in
  3841. other SQL databases.  Be warned that if you use them, your code will
  3842. not be portable to other SQL servers.  In some cases, you can write
  3843. code that includes MySQL extensions, but is still portable, by using
  3844. comments of the form `/*! ... */'.  In this case, MySQL Server will
  3845. parse and execute the code within the comment as it would any other
  3846. MySQL statement, but other SQL servers will ignore the extensions.  For
  3847. example:
  3848.  
  3849.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  3850.  
  3851. If you add a version number after the `'!'' character, the syntax within
  3852. the comment will be executed only if the MySQL version is equal to or
  3853. newer than the specified version number:
  3854.  
  3855.      CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
  3856.  
  3857. This means that if you have Version 3.23.02 or newer, MySQL Server will
  3858. use the `TEMPORARY' keyword.
  3859.  
  3860. The following descriptions list MySQL extensions, organized by category.
  3861.  
  3862. Organization of data on disk
  3863.      MySQL Server maps each database to a directory under the MySQL
  3864.      data directory, and tables within a database to filenames in the
  3865.      database directory.  This has a few implications:
  3866.  
  3867.         * Database names and table names are case sensitive in MySQL
  3868.           Server on operating systems that have case sensitive
  3869.           filenames (like most Unix systems). *Note Name case
  3870.           sensitivity::.
  3871.  
  3872.         * Database, table, index, column, or alias names may begin with
  3873.           a digit (but may not consist solely of digits).
  3874.  
  3875.         * You can use standard system commands to back up, rename,
  3876.           move, delete, and copy tables that are managed by the
  3877.           `MyISAM' or `ISAM' storage engines.  For example, to rename a
  3878.           `MyISQM' table, rename the `.MYD', `.MYI', and `.frm' files
  3879.           to which the table corresponds.
  3880.  
  3881. General language syntax
  3882.         * Strings may be enclosed by either `"' or `'', not just by `''.
  3883.  
  3884.         * Use of `\' as an escape character in strings.
  3885.  
  3886.         * In SQL statements, you can access tables from different
  3887.           databases with the `db_name.tbl_name' syntax.  Some SQL
  3888.           servers provide the same functionality but call this `User
  3889.           space'.  MySQL Server doesn't support tablespaces such as
  3890.           used in statements like this: `CREATE TABLE
  3891.           ralph.my_table...IN my_tablespace'.
  3892.  
  3893.  
  3894. SQL statement syntax
  3895.         * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and
  3896.           `REPAIR TABLE' statements.
  3897.  
  3898.         * The `CREATE DATABASE' and `DROP DATABASE' statements.  *Note
  3899.           `CREATE DATABASE': CREATE DATABASE.
  3900.  
  3901.         * The `DO' statement.
  3902.  
  3903.         * `EXPLAIN SELECT' to get a description of how tables are
  3904.           joined.
  3905.  
  3906.         * The `FLUSH' and `RESET' statements.
  3907.  
  3908.         * The `SET' statement. *Note `SET': SET OPTION.
  3909.  
  3910.         * The `SHOW' statement.  *Note `SHOW': SHOW.
  3911.  
  3912.         * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  3913.           compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD
  3914.           DATA': LOAD DATA.
  3915.  
  3916.         * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  3917.  
  3918.         * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note
  3919.           `REPLACE': REPLACE.
  3920.  
  3921.         * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  3922.           `IGNORE' or `RENAME' in an `ALTER TABLE' statement.  Use of
  3923.           multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  3924.           `ALTER TABLE' statement.  *Note `ALTER TABLE': ALTER TABLE.
  3925.  
  3926.         * Use of index names, indexes on a prefix of a field, and use of
  3927.           `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  3928.           TABLE': CREATE TABLE.
  3929.  
  3930.         * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  3931.  
  3932.         * Use of `IF EXISTS' with `DROP TABLE'.
  3933.  
  3934.         * You can drop multiple tables with a single `DROP TABLE'
  3935.           statement.
  3936.  
  3937.         * The `ORDER BY' and `LIMIT' clauses of the `UPDATE' and
  3938.           `DELETE' statements.
  3939.  
  3940.         * `INSERT INTO ... SET col_name = ...' syntax.
  3941.  
  3942.         * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  3943.  
  3944.         * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE',
  3945.           `DELETE', and `UPDATE' statements.
  3946.  
  3947.         * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT'
  3948.           statement. *Note `SELECT': SELECT.
  3949.  
  3950.         * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  3951.  
  3952.         * You don't need to name all selected columns in the `GROUP BY'
  3953.           part.  This gives better performance for some very specific,
  3954.           but quite normal queries.  *Note Group by functions and
  3955.           modifiers::.
  3956.  
  3957.         * You can specify `ASC' and `DESC' with `GROUP BY'.
  3958.  
  3959.         * The ability to set variables in a statement with the `:='
  3960.           assignment operator:
  3961.                mysql> SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg
  3962.                    -> FROM test_table;
  3963.                mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  3964.  
  3965.  
  3966. Column types
  3967.         * The column types `MEDIUMINT', `SET', `ENUM', and the
  3968.           different `BLOB' and `TEXT' types.
  3969.  
  3970.         * The column attributes `AUTO_INCREMENT', `BINARY', `NULL',
  3971.           `UNSIGNED', and `ZEROFILL'.
  3972.  
  3973. Functions and operators
  3974.         * To make it easier for users who come from other SQL
  3975.           environments, MySQL Server supports aliases for many
  3976.           functions. For example, all string functions support both
  3977.           standard SQL syntax and ODBC syntax.
  3978.  
  3979.         * MySQL Server understands the `||' and `&&' operators to mean
  3980.           logical OR and AND, as in the C programming language.  In
  3981.           MySQL Server, `||' and `OR' are synonyms, as are `&&' and
  3982.           `AND'.  Because of this nice syntax, MySQL Server doesn't
  3983.           support the standard SQL-99 `||' operator for string
  3984.           concatenation; use `CONCAT()' instead. Because `CONCAT()'
  3985.           takes any number of arguments, it's easy to convert use of
  3986.           the `||' operator to MySQL Server.
  3987.  
  3988.         * Use of `COUNT(DISTINCT list)' where `list' has more than one
  3989.           element.
  3990.  
  3991.         * All string comparisons are case-insensitive by default, with
  3992.           sort ordering determined by the current character set
  3993.           (ISO-8859-1 Latin1 by default).  If you don't like this, you
  3994.           should declare your columns with the `BINARY' attribute or
  3995.           use the `BINARY' cast, which causes comparisons to be done
  3996.           according to the ASCII order used on the MySQL server host.
  3997.  
  3998.         * The `%' operator is a synonym for `MOD()'.  That is, `N % M'
  3999.           is equivalent to `MOD(N,M)'.  `%' is supported for C
  4000.           programmers and for compatibility with PostgreSQL.
  4001.  
  4002.         * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  4003.           `OR', or `LIKE' operators may be used in column comparisons
  4004.           to the left of the `FROM' in `SELECT' statements.  For
  4005.           example:
  4006.  
  4007.                mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  4008.  
  4009.         * The `LAST_INSERT_ID()' function.  *Note Information
  4010.           functions::.
  4011.  
  4012.         * `LIKE' is allowed on numeric columns.
  4013.  
  4014.         * The `REGEXP' and `NOT REGEXP' extended regular expression
  4015.           operators.
  4016.  
  4017.         * `CONCAT()' or `CHAR()' with one argument or more than two
  4018.           arguments.  (In MySQL Server, these functions can take any
  4019.           number of arguments.)
  4020.  
  4021.         * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()',
  4022.           `FORMAT()', `IF()', `PASSWORD()', `ENCRYPT()', `MD5()',
  4023.           `ENCODE()', `DECODE()', `PERIOD_ADD()', `PERIOD_DIFF()',
  4024.           `TO_DAYS()', or `WEEKDAY()' functions.
  4025.  
  4026.         * Use of `TRIM()' to trim substrings.  SQL-99 supports removal
  4027.           of single characters only.
  4028.  
  4029.         * The `GROUP BY' functions `STD()', `BIT_OR()', `BIT_AND()',
  4030.           `BIT_XOR()', and `GROUP_CONCAT()'.  *Note Group by functions
  4031.           and modifiers::.
  4032.  
  4033. For a prioritized list indicating when new extensions will be added to
  4034. MySQL Server, you should consult the online MySQL TODO list at
  4035. `http://www.mysql.com/doc/en/TODO.html'.  That is the latest version of
  4036. the TODO list in this manual. *Note TODO::.
  4037.  
  4038. MySQL Differences Compared to SQL-92
  4039. ------------------------------------
  4040.  
  4041. We try to make MySQL Server follow the ANSI SQL standard
  4042. (SQL-92/SQL-99) and the ODBC SQL standard, but MySQL Server performs
  4043. operations differently in some cases:
  4044.  
  4045.    * For `VARCHAR' columns, trailing spaces are removed when the value
  4046.      is stored. *Note Bugs::.
  4047.  
  4048.    * In some cases, `CHAR' columns are silently converted to `VARCHAR'
  4049.      columns when you define a table or alter its structure.  *Note
  4050.      Silent column changes::.
  4051.  
  4052.    * Privileges for a table are not automatically revoked when you
  4053.      delete a table. You must explicitly issue a `REVOKE' statement to
  4054.      revoke privileges for a table. *Note `GRANT': GRANT.
  4055.  
  4056. Subqueries
  4057. ..........
  4058.  
  4059. MySQL Version 4.1 supports subqueries and derived tables.  A subquery
  4060. is a `SELECT' statement nested within another statement.  A derived
  4061. table (an unnamed view) is a subquery in the `FROM' clause of another
  4062. statement.  *Note Subqueries::.
  4063.  
  4064. For MySQL versions older than 4.1, most subqueries can be rewritten
  4065. using joins or other methods.  See *Note Rewriting subqueries:: for
  4066. examples that show how to do this.
  4067.  
  4068. `SELECT INTO TABLE'
  4069. ...................
  4070.  
  4071. MySQL Server doesn't support the Sybase SQL extension: `SELECT ... INTO
  4072. TABLE ...'.  Instead, MySQL Server supports the SQL-99 syntax `INSERT
  4073. INTO ... SELECT ...', which is basically the same thing. *Note `INSERT
  4074. SELECT': INSERT SELECT.
  4075.  
  4076.      INSERT INTO tblTemp2 (fldID)
  4077.             SELECT tblTemp1.fldOrder_ID
  4078.             FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;
  4079.  
  4080. Alternatively, you can use `SELECT INTO OUTFILE ...' or `CREATE TABLE
  4081. ... SELECT'.
  4082.  
  4083. From version 5.0, MySQL supports `SELECT ... INTO' with user variables.
  4084. The same syntax may also be used inside stored procedures using cursors
  4085. and local variables.  *Note SELECT INTO Statement::.
  4086.  
  4087. Transactions and Atomic Operations
  4088. ..................................
  4089.  
  4090. MySQL Server (version 3.23-max and all versions 4.0 and above) supports
  4091. transactions with the `InnoDB' and `BDB' transactional storage engines.
  4092. `InnoDB' provides _full_ `ACID' compliance.  *Note Table types::.
  4093.  
  4094. The other non-transactional storage engines in MySQL Server (such as
  4095. `MyISAM') follow a different paradigm for data integrity called
  4096. "`Atomic Operations'." In transactional terms, `MyISAM' tables
  4097. effectively always operate in `AUTOCOMMIT=1' mode.  Atomic operations
  4098. often offer comparable integrity with higher performance.
  4099.  
  4100. With MySQL Server supporting both paradigms, you can decide whether your
  4101. applications are best served by the speed of atomic operations or the
  4102. use of transactional features. This choice can be made on a per-table
  4103. basis.
  4104.  
  4105. As noted, the trade off for transactional vs. non-transactional table
  4106. types lies mostly in performance. Transactional tables have
  4107. significantly higher memory and diskspace requirements, and more CPU
  4108. overhead.  On the other hand, transactional table types such as
  4109. `InnoDB' also offer many significant features. MySQL Server's modular
  4110. design allows the concurrent use of different storage engines to suit
  4111. different requirements and deliver optimum performance in all
  4112. situations.
  4113.  
  4114. But how does one use the features of MySQL Server to maintain rigorous
  4115. integrity even with the non-transactional `MyISAM' tables, and how do
  4116. these features compare with the transactional table types?
  4117.  
  4118.   1. If your applications are written in a way that is dependent on
  4119.      being able to call `ROLLBACK' rather than `COMMIT' in critical
  4120.      situations, transactions are more convenient. Transactions also
  4121.      ensure that unfinished updates or corrupting activities are not
  4122.      committed to the database; the server is given the opportunity to
  4123.      do an automatic rollback and your database is saved.
  4124.  
  4125.      If you use non-transactional tables, MySQL Server in almost all
  4126.      cases allows you to resolve potential problems by including simple
  4127.      checks before updates and by running simple scripts that check the
  4128.      databases for inconsistencies and automatically repair or warn if
  4129.      such an inconsistency occurs. Note that just by using the MySQL
  4130.      log or even adding one extra log, one can normally fix tables
  4131.      perfectly with no data integrity loss.
  4132.  
  4133.   2. More often than not, critical transactional updates can be
  4134.      rewritten to be atomic. Generally speaking, all integrity problems
  4135.      that transactions solve can be done with `LOCK TABLES' or atomic
  4136.      updates, ensuring that you never will get an automatic abort from
  4137.      the server, which is a common problem with transactional database
  4138.      systems.
  4139.  
  4140.   3. Even a transactional system can lose data if the server goes down.
  4141.      The difference between different systems lies in just how small the
  4142.      time-lap is where they could lose data. No system is 100% secure,
  4143.      only "secure enough." Even Oracle, reputed to be the safest of
  4144.      transactional database systems, is reported to sometimes lose data
  4145.      in such situations.
  4146.  
  4147.      To be safe with MySQL Server, whether using transactional tables
  4148.      or not, you only need to have backups and have binary logging
  4149.      turned on. With this you can recover from any situation that you
  4150.      could with any other transactional database system.  It is always
  4151.      good to have backups, independent of which database system you use.
  4152.  
  4153. The transactional paradigm has its benefits and its drawbacks. Many
  4154. users and application developers depend on the ease with which they can
  4155. code around problems where an abort appears to be, or is necessary.
  4156. However, even if you are new to the atomic operations paradigm, or more
  4157. familiar with transactions, do consider the speed benefit that
  4158. non-transactional tables can offer on the order of three to five times
  4159. the speed of the fastest and most optimally tuned transactional tables.
  4160.  
  4161. In situations where integrity is of highest importance, MySQL Server
  4162. offers transaction-level reliability and integrity even for
  4163. non-transactional tables.  If you lock tables with `LOCK TABLES', all
  4164. updates will stall until any integrity checks are made. If you obtain a
  4165. `READ LOCAL' lock (as opposed to a write lock) for a table that allows
  4166. concurrent inserts at the end of the table, reads are allowed, as are
  4167. inserts by other clients.  The new inserted records will not be seen by
  4168. the client that has the read lock until it releases the lock.  With
  4169. `INSERT DELAYED' you can queue inserts into a local queue, until the
  4170. locks are released, without having the client wait for the insert to
  4171. complete. *Note INSERT DELAYED::.
  4172.  
  4173. "Atomic," in the sense that we mean it, is nothing magical. It only
  4174. means that you can be sure that while each specific update is running,
  4175. no other user can interfere with it, and there will never be an
  4176. automatic rollback (which can happen with transactional tables if you
  4177. are not very careful).  MySQL Server also guarantees that there will
  4178. not be any dirty reads.
  4179.  
  4180. Following are some techniques for working with non-transactional tables:
  4181.  
  4182.    * Loops that need transactions normally can be coded with the help of
  4183.      `LOCK TABLES', and you don't need cursors to update records on the
  4184.      fly.
  4185.  
  4186.    * To avoid using `ROLLBACK', you can use the following strategy:
  4187.  
  4188.        1. Use `LOCK TABLES ...' to lock all the tables you want to
  4189.           access.
  4190.  
  4191.        2. Test the conditions that must be true before performing the
  4192.           update.
  4193.  
  4194.        3. Update if everything is okay.
  4195.  
  4196.        4. Use `UNLOCK TABLES' to release your locks.
  4197.  
  4198.      This is usually a much faster method than using transactions with
  4199.      possible rollbacks, although not always. The only situation this
  4200.      solution doesn't handle is when someone kills the threads in the
  4201.      middle of an update. In this case, all locks will be released but
  4202.      some of the updates may not have been executed.
  4203.  
  4204.    * You can also use functions to update records in a single operation.
  4205.      You can get a very efficient application by using the following
  4206.      techniques:
  4207.  
  4208.         * Modify fields relative to their current value.
  4209.  
  4210.         * Update only those fields that actually have changed.
  4211.  
  4212.      For example, when we are doing updates to some customer
  4213.      information, we update only the customer data that has changed and
  4214.      test only that none of the changed data, or data that depends on
  4215.      the changed data, has changed compared to the original row. The
  4216.      test for changed data is done with the `WHERE' clause in the
  4217.      `UPDATE' statement. If the record wasn't updated, we give the
  4218.      client a message: "Some of the data you have changed has been
  4219.      changed by another user." Then we show the old row versus the new
  4220.      row in a window, so the user can decide which version of the
  4221.      customer record he should use.
  4222.  
  4223.      This gives us something that is similar to column locking but is
  4224.      actually even better because we only update some of the columns,
  4225.      using values that are relative to their current values.  This
  4226.      means that typical `UPDATE' statements look something like these:
  4227.  
  4228.           UPDATE tablename SET pay_back=pay_back+125;
  4229.           
  4230.           UPDATE customer
  4231.             SET
  4232.               customer_date='current_date',
  4233.               address='new address',
  4234.               phone='new phone',
  4235.               money_he_owes_us=money_he_owes_us-125
  4236.             WHERE
  4237.               customer_id=id AND address='old address' AND phone='old phone';
  4238.  
  4239.      As you can see, this is very efficient and works even if another
  4240.      client has changed the values in the `pay_back' or
  4241.      `money_he_owes_us' columns.
  4242.  
  4243.    * In many cases, users have wanted `LOCK TABLES' and/or `ROLLBACK'
  4244.      for the purpose of managing unique identifiers.  This can be
  4245.      handled much more efficiently without locking or rolling back by
  4246.      using an `AUTO_INCREMENT' column and either the SQL function
  4247.      `LAST_INSERT_ID()' or the C API function `mysql_insert_id()'.
  4248.      *Note Information functions::.  *Note `mysql_insert_id()':
  4249.      mysql_insert_id.
  4250.  
  4251.      You can generally code around the need for row-level locking. Some
  4252.      situations really do need it, and `InnoDB' tables support
  4253.      row-level locking. With `MyISAM' tables, you can use a flag column
  4254.      in the table and do something like the following:
  4255.  
  4256.           UPDATE tbl_name SET row_flag=1 WHERE id=ID;
  4257.  
  4258.      MySQL returns 1 for the number of affected rows if the row was
  4259.      found and `row_flag' wasn't already 1 in the original row.
  4260.  
  4261.      You can think of it as though MySQL Server changed the preceding
  4262.      query to:
  4263.  
  4264.           UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;
  4265.  
  4266. Stored Procedures and Triggers
  4267. ..............................
  4268.  
  4269. Stored procedures are implemented in MySQL version 5.0.  *Note Stored
  4270. Procedures::.
  4271.  
  4272. Triggers are scheduled for implementation in MySQL version 5.1. A
  4273. trigger is effectively a type of stored procedure, one that is invoked
  4274. when a particular event occurs.  For example, you could set up a stored
  4275. procedure that is triggered each time a record is deleted from a
  4276. transactional table and that stored procedure automatically deletes the
  4277. corresponding customer from a customer table when all their
  4278. transactions are deleted.
  4279.  
  4280. Foreign Keys
  4281. ............
  4282.  
  4283. In MySQL Server 3.23.44 and up, the `InnoDB' storage engine supports
  4284. checking of foreign key constraints, including `CASCADE', `ON DELETE',
  4285. and `ON UPDATE'. *Note InnoDB foreign key constraints::.
  4286.  
  4287. For storage engines other than `InnoDB', MySQL Server parses the
  4288. `FOREIGN KEY' syntax in `CREATE TABLE' statements, but does not use or
  4289. store it. In the future, the implementation will be extended to store
  4290. this information in the table specification file so that it may be
  4291. retrieved by `mysqldump' and ODBC.  At a later stage, foreign key
  4292. constraints will be implemented for `MyISAM' tables as well.
  4293.  
  4294. Foreign key enforcement offers several benefits to database developers:
  4295.  
  4296.    * Assuming proper design of the relationships, foreign key
  4297.      constraints make it more difficult for a programmer to introduce
  4298.      an inconsistency into the database.
  4299.  
  4300.    * Centralized checking of constraints by the database server makes it
  4301.      unnecessary to perform these checks on the application side. This
  4302.      eliminates the possibility that different applications may not all
  4303.      check the constraints in the same way.
  4304.  
  4305.    * Using cascading updates and deletes can simplify the application
  4306.      code.
  4307.  
  4308.    * Properly designed foreign key rules aid in documenting
  4309.      relationships between tables.
  4310.  
  4311. Do keep in mind that these benefits come at the cost of additional
  4312. overhead for the database server to perform the necessary checks.
  4313. Additional checking by the server affects performance, which for some
  4314. applications may be sufficiently undesirable as to be avoided if
  4315. possible.  (Some major commercial applications have coded the
  4316. foreign-key logic at the application level for this reason.)
  4317.  
  4318. MySQL gives database developers the choice of which approach to use. If
  4319. you don't need foreign keys and want to avoid the overhead associated
  4320. with enforcing referential integrity, you can choose another table type
  4321. instead, such as `MyISAM'. (For example, the `MyISAM' storage engine
  4322. offers very fast performance for applications that perform only
  4323. `INSERT' and `SELECT' operations, because the inserts can be performed
  4324. concurrently with retrievals.  *Note Table locking::.)
  4325.  
  4326. If you choose not to take advantage of referential integrity checks,
  4327. keep the following considerations in mind:
  4328.  
  4329.    * In the absence of server-side foreign key relationship checking,
  4330.      the application itself must handle relationship issues.  For
  4331.      example, it must take care to insert rows into tables in the proper
  4332.      order, and to avoid creating orphaned child records. It must also
  4333.      be able to recover from errors that occur in the middle of
  4334.      multiple-record insert operations.
  4335.  
  4336.    * If `ON DELETE' is the only referential integrity capability an
  4337.      application needs, note that as of MySQL Server 4.0, you can use
  4338.      multiple-table `DELETE' statements to delete rows from many tables
  4339.      with a single statement. *Note `DELETE': DELETE.
  4340.  
  4341.    * A workaround for the lack of `ON DELETE' is to add the appropriate
  4342.      `DELETE' statement to your application when you delete records
  4343.      from a table that has a foreign key. In practice, this is often as
  4344.      quick as using foreign keys, and is more portable.
  4345.  
  4346.  
  4347. Be aware that the use of foreign keys can in some instances lead to
  4348. problems:
  4349.  
  4350.    * Foreign key support addresses many referential integrity issues,
  4351.      but it is still necessary to design key relationships carefully to
  4352.      avoid circular rules or incorrect combinations of cascading
  4353.      deletes.
  4354.  
  4355.    * It is not uncommon for a DBA to create a topology of relationships
  4356.      that makes it difficult to restore individual tables from a backup.
  4357.      (MySQL alleviates this difficulty by allowing you to temporarily
  4358.      disable foreign key checks when reloading a table that depends on
  4359.      other tables.  *Note InnoDB foreign key constraints::.  As of
  4360.      MySQL 4.1.1, `mysqldump' generates dump files that take advantage
  4361.      of this capability automatically when reloaded.)
  4362.  
  4363. Note that foreign keys in SQL are used to check and enforce referential
  4364. integrity, not to join tables.  If you want to get results from multiple
  4365. tables from a `SELECT' statement, you do this by performing a join
  4366. between them:
  4367.  
  4368.      SELECT * FROM table1,table2 WHERE table1.id = table2.id;
  4369.  
  4370. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  4371.  
  4372. The `FOREIGN KEY' syntax without `ON DELETE ...' is often used by ODBC
  4373. applications to produce automatic `WHERE' clauses.
  4374.  
  4375. Views
  4376. .....
  4377.  
  4378. Views are currently being implemented, and will appear in the 5.0 or 5.1
  4379. version of MySQL Server.  Unnamed views (_derived tables_, a subquery
  4380. in the `FROM' clause of a `SELECT') are already implemented in version
  4381. 4.1.
  4382.  
  4383. Historically, MySQL Server has been most used in applications and on web
  4384. systems where the application writer has full control over database
  4385. usage. Usage has shifted over time, and so we find that an increasing
  4386. number of users now regard views as an important feature.
  4387.  
  4388. Views are useful for allowing users to access a set of relations
  4389. (tables) as if it were a single table, and limiting their access to
  4390. just that.  Views can also be used to restrict access to rows (a subset
  4391. of a particular table).  One does not require views to restrict access
  4392. to columns, as MySQL Server has a sophisticated privilege system.
  4393. *Note Privilege system::.
  4394.  
  4395. Many DBMS don't allow updates to a view. Instead, you have to perform
  4396. the updates on the individual tables.  In designing an implementation
  4397. of views, our goal, as much as is possible within the confines of SQL,
  4398. is full compliance with "*Codd's Rule #6*" for relational database
  4399. systems: All views that are theoretically updatable, should in practice
  4400. also be updatable.
  4401.  
  4402. `--' as the Start of a Comment
  4403. ..............................
  4404.  
  4405. Some other SQL databases use `--' to start comments.  MySQL Server uses
  4406. `#' as the start comment character. You can also use the C comment
  4407. style `/* this is a comment */' with MySQL Server.  *Note Comments::.
  4408.  
  4409. MySQL Server Version 3.23.3 and above support the `--' comment style,
  4410. provided the comment is followed by a space (or by a control character
  4411. such as a newline). The requirement for a space is to prevent problems
  4412. with automatically generated SQL queries that have used something like
  4413. the following code, where we automatically insert the value of the
  4414. payment for `!payment!':
  4415.  
  4416.      UPDATE tbl_name SET credit=credit-!payment!
  4417.  
  4418. Think about what happens if the value of `payment' is a negative value
  4419. such as `-1':
  4420.  
  4421.      UPDATE tbl_name SET credit=credit--1
  4422.  
  4423. `credit--1' is a legal expression in SQL, but if `--' is interpreted as
  4424. the start of a comment, part of the expression is discarded. The result
  4425. is a statement that has a completely different meaning than intended:
  4426.  
  4427.      UPDATE tbl_name SET credit=credit
  4428.  
  4429. The statement produces no change in value at all!  This illustrates that
  4430. allowing comments to start with `--' can have serious consequences.
  4431.  
  4432. Using our implementation of this method of commenting in MySQL Server
  4433. Version 3.23.3 and up, `credit--1' is actually safe.
  4434.  
  4435. Another safe feature is that the `mysql' command-line client removes
  4436. all lines that start with `--'.
  4437.  
  4438. The following information is relevant only if you are running a MySQL
  4439. version earlier than 3.23.3:
  4440.  
  4441. If you have an SQL program in a text file that contains `--' comments,
  4442. you should use the `replace' utility as follows to convert the comments
  4443. to use `#' characters:
  4444.  
  4445.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  4446.               | mysql database
  4447.  
  4448. instead of the usual:
  4449.  
  4450.      shell> mysql database < text-file-with-funny-comments.sql
  4451.  
  4452. You can also edit the command file "in place" to change the `--'
  4453. comments to `#' comments:
  4454.  
  4455.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  4456.  
  4457. Change them back with this command:
  4458.  
  4459.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  4460.  
  4461. How MySQL Deals with Constraints
  4462. --------------------------------
  4463.  
  4464. MySQL allows you to work with both transactional tables that allow
  4465. rollback and non-transactional tables that do not, so constraint
  4466. handling is a bit different in MySQL than in other databases.
  4467.  
  4468. We have to handle the case when you have updated a lot of rows in a
  4469. non-transactional table that cannot roll back when an error occurs.
  4470.  
  4471. The basic philosophy is to try to give an error for anything that we can
  4472. detect at compile time but try to recover from any errors we get at
  4473. runtime.  We do this in most cases, but not yet for all. *Note TODO
  4474. future::.
  4475.  
  4476. The options MySQL has when an error occurs are to stop the statement in
  4477. the middle or to recover as well as possible from the problem and
  4478. continue.
  4479.  
  4480. The following sections describe what happens for the different types of
  4481. constraints.
  4482.  
  4483. Constraint PRIMARY KEY / UNIQUE
  4484. ...............................
  4485.  
  4486. Normally you will get an error when you try to `INSERT' or `UPDATE' a
  4487. row that causes a primary key, unique key or foreign key violation.  If
  4488. you are using a transactional storage engine such as `InnoDB', MySQL
  4489. will automatically roll back the transaction.  If you are using a
  4490. non-transactional storage engine, MySQL will stop at the incorrect row
  4491. and leave any remaining rows unprocessed.
  4492.  
  4493. To make life easier, MySQL supports an `IGNORE' keyword for most
  4494. commands that can cause a key violation (such as `INSERT IGNORE' and
  4495. `UPDATE IGNORE'). In this case, MySQL will ignore any key violation and
  4496. continue with processing the next row.  You can get information about
  4497. what MySQL did with the `mysql_info()' API function.  *Note
  4498. `mysql_info()': mysql_info.  In MySQL 4.1 and up, you also can use the
  4499. `SHOW WARNINGS' statement.  *Note SHOW WARNINGS::.
  4500.  
  4501. Note that for the moment only `InnoDB' tables support foreign keys.
  4502. *Note InnoDB foreign key constraints::.  Foreign key support in
  4503. `MyISAM' tables is scheduled for implementation in MySQL 5.1.
  4504.  
  4505. Constraint `NOT NULL' and `DEFAULT' values
  4506. ..........................................
  4507.  
  4508. To be able to support easy handling of non-transactional tables all
  4509. columns in MySQL have default values.
  4510.  
  4511. If you insert an "incorrect" value in a column, such as a `NULL' in a
  4512. `NOT NULL' column or a too-large numerical value in a numerical column,
  4513. MySQL sets the column to the "best possible value" instead of producing
  4514. an error.  For numerical values, this is either 0, the smallest
  4515. possible value or the largest possible value. For strings, this is
  4516. either the empty string or the longest possible string that can be in
  4517. the column.
  4518.  
  4519. This means that if you try to store `NULL' into a column that doesn't
  4520. take `NULL' values, MySQL Server instead stores 0 or `''' (the empty
  4521. string). This last behavior can, for single row inserts, be changed
  4522. with the `-DDONT_USE_DEFAULT_FIELDS' compile option.) *Note `configure'
  4523. options: configure options.  This causes `INSERT' statements to
  4524. generate an error unless you explicitly specify values for all columns
  4525. that require a non-`NULL' value.
  4526.  
  4527. The reason for the preceding rules is that we can't check these
  4528. conditions until the query has begun executing.  We can't just roll
  4529. back if we encounter a problem after updating a few rows, because the
  4530. table type may not support rollback.  The option of terminating the
  4531. statement is not that good; in this case, the update would be "half
  4532. done," which is probably the worst possible scenario.  In this case
  4533. it's better to "do the best you can" and then continue as if nothing
  4534. happened.
  4535.  
  4536. This means that you should generally not use MySQL to check column
  4537. content.  Instead, the application should ensure that is passes only
  4538. legal values to MySQL.
  4539.  
  4540. In MySQL 5.0, we plan to improve this by providing warnings when
  4541. automatic column conversions occur, plus an option to let you roll back
  4542. statements that attempt to perform a disallowed column value
  4543. assignment, as long as the statement uses only transactional tables.
  4544.  
  4545. Constraint `ENUM' and `SET'
  4546. ...........................
  4547.  
  4548. In MySQL 4.x, `ENUM' is not a real constraint, but is a more efficient
  4549. way to define columns that can only contain a given set of values.
  4550. This is because of the same reasons `NOT NULL' is not honored.  *Note
  4551. constraint NOT NULL::.
  4552.  
  4553. If you insert an incorrect value into an `ENUM' column, it will be set
  4554. to the reserved enumeration value `0', which will be displayed as an
  4555. empty string in string context. *Note ENUM::.
  4556.  
  4557. If you insert an incorrect value into a `SET' column, the incorrect
  4558. value is ignored. For example, if the column can contain the values
  4559. `'a'', `'b'', and `'c'', an attempt to assign `'a,x,b,y'' results in a
  4560. value of `'a,b''.  *Note SET::.
  4561.  
  4562. Known Errors and Design Deficiencies in MySQL
  4563. ---------------------------------------------
  4564.  
  4565. Errors in 3.23 Fixed in a Later MySQL Version
  4566. .............................................
  4567.  
  4568. The following known errors or bugs are not fixed in MySQL 3.23 because
  4569. fixing them would involve changing a lot of code that could introduce
  4570. other even worse bugs. The bugs are also classified as "not fatal" or
  4571. "bearable."
  4572.  
  4573.    * You can get a deadlock if you use `LOCK TABLE' to lock multiple
  4574.      tables and then in the same connection use `DROP TABLE' to drop
  4575.      one of them while another thread is trying to lock it.  (To break
  4576.      the deadlock, you can use `KILL' to terminate any of the threads
  4577.      involved.) This issue is resolved in MySQL 4.0.12.
  4578.  
  4579.    * `SELECT MAX(key_column) FROM t1,t2,t3...' where one of the tables
  4580.      are empty doesn't return `NULL' but instead returns the maximum
  4581.      value for the column.  This issue is resolved in MySQL 4.0.11.
  4582.  
  4583.    * `DELETE FROM heap_table' without a `WHERE' clause doesn't work on
  4584.      a locked `HEAP' table.
  4585.  
  4586. Errors in 4.0 Fixed in a Later MySQL Version
  4587. ............................................
  4588.  
  4589. The following known errors or bugs are not fixed in MySQL 4.0 because
  4590. fixing them would involve changing a lot of code that could introduce
  4591. other even worse bugs. The bugs are also classified as "not fatal" or
  4592. "bearable."
  4593.  
  4594.    * In a `UNION', the first `SELECT' determines the type, `max_length'
  4595.      and `NULL' properties for the resulting columns.  This issue is
  4596.      resolved in MySQL 4.1.1; the property values are based on the rows
  4597.      from all `UNION' parts.
  4598.  
  4599. Open Bugs / Design Deficiencies in MySQL
  4600. ........................................
  4601.  
  4602. The following problems are known and fixing them is a high priority:
  4603.  
  4604.    * Dropping a `FOREIGN KEY' constraint doesn't work in replication as
  4605.      the constraint may have another name.
  4606.  
  4607.    * You cannot mix `UNION ALL' and `UNION DISTINCT' in the same query.
  4608.      If you use `ALL' for one `UNION', it is used for all of them.
  4609.  
  4610.    * If one user has a long running transaction and another user drops a
  4611.      table that is updated in the transaction, there is small chance
  4612.      that the binary log may contain the `DROP TABLE' command before
  4613.      the table is used in the transaction itself.  We plan to fix this
  4614.      in 5.0 by having the `DROP TABLE' wait until the table is not used
  4615.      in any transaction.
  4616.  
  4617.    * When inserting a big integer value (between 2^63 and 2^64-1) into a
  4618.      decimal/string column, it is inserted as a negative value because
  4619.      the number is evaluated in a signed integer context. It is planned
  4620.      to be fixed in 4.1.
  4621.  
  4622.    * `FLUSH TABLES WITH READ LOCK' does not block `CREATE TABLE' or
  4623.      `COMMIT', which make cause a problem with the binary log position
  4624.      when doing a full backup of tables and the binary log.
  4625.  
  4626.    * `ANALYZE TABLE' on a `BDB' table may in some cases make the table
  4627.      unusable until one has restarted `mysqld'.  If this happens, you
  4628.      will see errors of the following form in the MySQL error file:
  4629.  
  4630.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  4631.  
  4632.    * MySQL accepts parentheses in the `FROM' part of a `SELECT'
  4633.      statement, but silently ignores them.  The reason for not giving
  4634.      an error is that many clients that automatically generate queries
  4635.      add parentheses in the `FROM' part even where they are not needed.
  4636.  
  4637.    * Concatenating many `RIGHT JOINS' or combining `LEFT' and `RIGHT'
  4638.      join in the same query may not give a correct answer as MySQL only
  4639.      generates `NULL' rows for the table preceding a `LEFT' or before a
  4640.      `RIGHT' join.  This will be fixed in 5.0 at the same time we add
  4641.      support for parentheses in the `FROM' part.
  4642.  
  4643.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  4644.      running multiple-statement transactions until all those
  4645.      transactions complete.  (The transaction will probably be ignored.)
  4646.  
  4647.    * `ANALYZE TABLE', `OPTIMIZE TABLE', and `REPAIR TABLE' may cause
  4648.      problems on tables for which you are using `INSERT DELAYED'.
  4649.  
  4650.    * Doing a `LOCK TABLE ...' and `FLUSH TABLES ...' doesn't guarantee
  4651.      that there isn't a half-finished transaction in progress on the
  4652.      table.
  4653.  
  4654.    * `BDB' tables are a bit slow to open. If you have many `BDB' tables
  4655.      in a database, it will take a long time to use the `mysql' client
  4656.      on the database if you are not using the `-A' option or if you are
  4657.      using `rehash'. This is especially notable when you have a large
  4658.      table cache.
  4659.  
  4660.    * Replication uses query-level logging: The master writes the
  4661.      executed queries to the binary log. This is a very fast, compact,
  4662.      and efficient logging method that works perfectly in most cases.
  4663.      Though we have never heard of it actually occurring, it is
  4664.      theoretically possible for the data on the master and slave to
  4665.      become different if a query is designed in such a way that the
  4666.      data modification is non-deterministic, that is, left to the will
  4667.      of the query optimizer. (That generally is not a good practice
  4668.      anyway, even outside of replication!)  For example:
  4669.  
  4670.         - `CREATE ... SELECT' or `INSERT ... SELECT'  statements that
  4671.           insert zero or `NULL' values into an `AUTO_INCREMENT' column.
  4672.  
  4673.         - `DELETE' if you are deleting rows from a table which has
  4674.           foreign keys with `ON DELETE CASCADE' properties.
  4675.  
  4676.         - `REPLACE ... SELECT', `INSERT IGNORE ... SELECT' if you have
  4677.           duplicate key values in the inserted data.
  4678.      *IF and only if all these queries have NO `ORDER BY' clause
  4679.      guaranteeing a deterministic order*.
  4680.  
  4681.      Indeed, for example for `INSERT ... SELECT' with no `ORDER BY',
  4682.      the `SELECT' may return rows in a different order (which will
  4683.      result in a row having different ranks, hence getting a different
  4684.      number in the `auto_increment' column), depending on the choices
  4685.      made by the optimizers on the master and slave. A query will be
  4686.      optimized differently on the master and slave only if:
  4687.  
  4688.         - The files used by the two queries are not exactly the same;
  4689.           for example `OPTIMIZE TABLE' was run on the master tables and
  4690.           not on the slave tables (to fix this, since MySQL 4.1.1,
  4691.           `OPTIMIZE', `ANALYZE' and `REPAIR' are written to the binary
  4692.           log).
  4693.  
  4694.         - The table is stored in a different storage engine on the
  4695.           master than on the slave. (It is possible to use different
  4696.           storage engines on the master and slave. For example, you can
  4697.           use `InnoDB' on the master, but `MyISAM' on the slave if the
  4698.           slave has less available disk space.)
  4699.  
  4700.         - MySQL buffer sizes (`key_buffer_size', etc.) are different on
  4701.           the master and slave.
  4702.  
  4703.         - The master and slave run different MySQL versions, and the
  4704.           optimizer code is different between these versions.
  4705.  
  4706.      This problem may also affect database restoration using
  4707.      `mysqlbinlog|mysql'.
  4708.  
  4709.      The easiest way to avoid this problem in all cases is add an
  4710.      `ORDER BY' clause to such non-deterministic queries to ensure that
  4711.      the rows are always stored or modified in the same order.  In
  4712.      future MySQL versions, we will automatically add an `ORDER BY'
  4713.      clause when needed.
  4714.  
  4715.  
  4716. The following problems are known and will be fixed in due time:
  4717.  
  4718.    * Log files are based on hostnames (if you don't specify a file name
  4719.      with the startup option). For now you have to use options like
  4720.      `--log-bin=old_host_name-bin' if you change your host name to
  4721.      something else. Another option is to just rename the old files to
  4722.      reflect your hostname change. *Note Server options::.
  4723.  
  4724.    * `mysqlbinlog' will not delete temporary files left after a `LOAD
  4725.      DATA INFILE' command. *Note `mysqlbinlog': mysqlbinlog.
  4726.  
  4727.    * `RENAME' doesn't work with `TEMPORARY' tables or tables used in a
  4728.      `MERGE' table.
  4729.  
  4730.    * When using the `RPAD()' function in a query that has to be
  4731.      resolved by using a temporary table, all resulting strings will
  4732.      have rightmost spaces removed. This is an example of such a query:
  4733.  
  4734.           SELECT RPAD(t1.column1, 50, ' ') AS f2, RPAD(t2.column2, 50, ' ') AS f1
  4735.           FROM table1 as t1 LEFT JOIN table2 AS t2 ON t1.record=t2.joinID
  4736.           ORDER BY t2.record;
  4737.  
  4738.      The final result of this bug is that you will not be able to get
  4739.      spaces on the right side of the resulting values. The problem also
  4740.      occurs for any other string function that adds spaces to the right.
  4741.  
  4742.      The reason for this is due to the fact that `HEAP' tables, which
  4743.      are used first for temporary tables, are not capable of handling
  4744.      `VARCHAR' columns.
  4745.  
  4746.      This behavior exists in all versions of MySQL.  It will be fixed
  4747.      in one of the 4.1 series releases.
  4748.  
  4749.    * Due to the way table definition files are stored, you cannot use
  4750.      character 255 (`CHAR(255)') in table names, column names, or
  4751.      enumerations.  This is scheduled to be fixed in version 5.1 when
  4752.      we have new table definition format files.
  4753.  
  4754.    * When using `SET CHARACTER SET', you can't use translated
  4755.      characters in database, table, and column names.
  4756.  
  4757.    * You can't use `_' or `%' with `ESCAPE' in `LIKE ... ESCAPE'.
  4758.  
  4759.    * If you have a `DECIMAL' column with a  number stored in different
  4760.      formats (+01.00, 1.00, 01.00), `GROUP BY' may regard each value as
  4761.      a different value.
  4762.  
  4763.    * `DELETE FROM merge_table' used without a `WHERE' clause will clear
  4764.      only the mapping for the table, not delete everything in the
  4765.      mapped tables.
  4766.  
  4767.    * You cannot build the server in another directory when using
  4768.      MIT-pthreads. Because this requires changes to MIT-pthreads, we
  4769.      are not likely to fix this. *Note MIT-pthreads::.
  4770.  
  4771.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  4772.      or `DISTINCT'. Only the first `max_sort_length' bytes are used
  4773.      when comparing `BLOB' values in these cases.  The default value of
  4774.      `max_sort_length' value is 1024. It can be changed at server
  4775.      startup time.  A workaround for most cases is to use a substring.
  4776.      For example: `SELECT DISTINCT LEFT(blob,2048) FROM tbl_name'.
  4777.  
  4778.    * Numeric calculations are done with `BIGINT' or `DOUBLE' (both are
  4779.      normally 64 bits long). It depends on the function which precision
  4780.      one gets. The general rule is that bit functions are done with
  4781.      `BIGINT' precision, `IF', and `ELT()' with `BIGINT' or `DOUBLE'
  4782.      precision and the rest with `DOUBLE' precision.  You should try to
  4783.      avoid using unsigned long long values if they resolve to be bigger
  4784.      than 63 bits (9223372036854775807) for anything other than bit
  4785.      fields.  MySQL Server 4.0 has better `BIGINT' handling than 3.23.
  4786.  
  4787.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  4788.      have all trailing spaces removed when retrieved. For `CHAR' types
  4789.      this is okay. The bug is that in MySQL Server, `VARCHAR' columns
  4790.      are treated the same way.
  4791.  
  4792.    * You can only have up to 255 `ENUM' and `SET' columns in one table.
  4793.  
  4794.    * In `MIN()', `MAX()', and other aggregate functions, MySQL
  4795.      currently compares `ENUM' and `SET' columns by their string value
  4796.      rather than by the string's relative position in the set.
  4797.  
  4798.    * `mysqld_safe' redirects all messages from `mysqld' to the `mysqld'
  4799.      log.  One problem with this is that if you execute `mysqladmin
  4800.      refresh' to close and reopen the log, `stdout' and `stderr' are
  4801.      still redirected to the old log.  If you use `--log' extensively,
  4802.      you should edit `mysqld_safe' to log to `'hostname'.err' instead
  4803.      of `'hostname'.log' so you can easily reclaim the space for the
  4804.      old log by deleting the old one and executing `mysqladmin refresh'.
  4805.  
  4806.    * In the `UPDATE' statement, columns are updated from left to right.
  4807.      If you refer to an updated column, you will get the updated value
  4808.      instead of the original value. For example:
  4809.  
  4810.           mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
  4811.  
  4812.      This will increment `KEY' by `2', not `1'.
  4813.  
  4814.    * You can refer to multiple temporary tables in the same query, but
  4815.      you cannot refer to any given temporary table more than once.  For
  4816.      example, the following doesn't work:
  4817.  
  4818.           mysql> SELECT * FROM temporary_table, temporary_table AS t2;
  4819.  
  4820.    * The optimizer may handle `DISTINCT' differently if you are using
  4821.      'hidden' columns in a join or not.  In a join, hidden columns are
  4822.      counted as part of the result (even if they are not shown) while in
  4823.      normal queries hidden columns don't participate in the `DISTINCT'
  4824.      comparison.  We will probably change this in the future to never
  4825.      compare the hidden columns when executing `DISTINCT'.
  4826.  
  4827.      An example of this is:
  4828.  
  4829.           SELECT DISTINCT mp3id FROM band_downloads
  4830.                  WHERE userid = 9 ORDER BY id DESC;
  4831.  
  4832.      and
  4833.  
  4834.           SELECT DISTINCT band_downloads.mp3id
  4835.                  FROM band_downloads,band_mp3
  4836.                  WHERE band_downloads.userid = 9
  4837.                  AND band_mp3.id = band_downloads.mp3id
  4838.                  ORDER BY band_downloads.id DESC;
  4839.  
  4840.      In the second case you may in MySQL Server 3.23.x get two
  4841.      identical rows in the result set (because the values in the hidden
  4842.      `id' column may differ).
  4843.  
  4844.      Note that this happens only for queries where you don't have the
  4845.      `ORDER BY' columns in the result, something that you are not
  4846.      allowed to do in SQL-92.
  4847.  
  4848.    * Because MySQL Server allows you to work with table types that don't
  4849.      support transactions, and thus can't roll back data, some things
  4850.      behave a little differently in MySQL Server than in other SQL
  4851.      servers.  This is just to ensure that MySQL Server never needs to
  4852.      do a rollback for an SQL statement.  This may be a little awkward
  4853.      at times as column values must be checked in the application, but
  4854.      this will actually give you a nice speed increase as it allows
  4855.      MySQL Server to do some optimizations that otherwise would be very
  4856.      hard to do.
  4857.  
  4858.      If you set a column to an incorrect value, MySQL Server will,
  4859.      instead of doing a rollback, store the `best possible value' in
  4860.      the column:
  4861.  
  4862.         - If you try to store a value outside the range in a numerical
  4863.           column, MySQL Server instead stores the smallest or largest
  4864.           possible value in the column.
  4865.  
  4866.         - If you try to store a string that doesn't start with a number
  4867.           into a numerical column, MySQL Server stores 0.
  4868.  
  4869.         - If you try to store `NULL' into a column that doesn't allow
  4870.           `NULL' values, MySQL Server stores 0 or `''' (the empty
  4871.           string) in it instead. (This behavior can, however, be
  4872.           changed with the `-DDONT_USE_DEFAULT_FIELDS' compile option.)
  4873.  
  4874.         - MySQL allows you to store some wrong date values into `DATE'
  4875.           and `DATETIME' columns (like `'2000-02-31'' or
  4876.           `'2000-02-00'').  The idea is that it's not the job of the
  4877.           SQL server to validate dates. If MySQL can store a date value
  4878.           and retrieve exactly the same value, MySQL stores it as
  4879.           given.  If the date is totally wrong (outside the server's
  4880.           ability to store it), the special date value `'0000-00-00''
  4881.           is stored in the column instead.
  4882.  
  4883.         - If you set an `ENUM' column to an unsupported value, it is
  4884.           set to the error value `empty string', with numeric value 0.
  4885.  
  4886.         - If you set a `SET' column to an unsupported value, the value
  4887.           is ignored.
  4888.  
  4889.  
  4890.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  4891.      in some cases the `PROCEDURE' will not transform the columns.
  4892.  
  4893.    * Creation of a table of type `MERGE' doesn't check if the underlying
  4894.      tables are of compatible types.
  4895.  
  4896.    * MySQL Server can't yet handle `NaN', `-Inf', and `Inf' values in
  4897.      `DOUBLE' columns. Using these will cause problems when trying to
  4898.      export and import data. We should as an intermediate solution
  4899.      change `NaN' to `NULL' (if possible) and `-Inf' and `Inf' to the
  4900.      minimum respective maximum possible `double' value.
  4901.  
  4902.    * If you use `ALTER TABLE' to first add a `UNIQUE' index to a table
  4903.      used in a `MERGE' table and then use `ALTER TABLE' to add a normal
  4904.      index on the `MERGE' table, the key order will be different for
  4905.      the tables if there was an old key that was not unique in the
  4906.      table. This is because `ALTER TABLE' puts `UNIQUE' indexes before
  4907.      normal indexes to be able to detect duplicate keys as early as
  4908.      possible.
  4909.  
  4910. The following are known bugs in earlier versions of MySQL:
  4911.  
  4912.    * You can get a hung thread if you do a `DROP TABLE' on a table that
  4913.      is one among many tables that is locked with `LOCK TABLES'.
  4914.  
  4915.    * In the following case you can get a core dump:
  4916.  
  4917.         - Delayed insert handler has pending inserts to a table.
  4918.  
  4919.         - `LOCK table' with `WRITE'.
  4920.  
  4921.         - `FLUSH TABLES'.
  4922.  
  4923.    * Before MySQL Server Version 3.23.2 an `UPDATE' that updated a key
  4924.      with a `WHERE' on the same key may have failed because the key was
  4925.      used to search for records and the same row may have been found
  4926.      multiple times:
  4927.  
  4928.           UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
  4929.  
  4930.      A workaround is to use:
  4931.  
  4932.           mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
  4933.  
  4934.      This will work because MySQL Server will not use an index on
  4935.      expressions in the `WHERE' clause.
  4936.  
  4937.    * Before MySQL Server Version 3.23, all numeric types were treated as
  4938.      fixed-point fields. That means you had to specify how many decimals
  4939.      a floating-point field should have. All results were returned with
  4940.      the correct number of decimals.
  4941.  
  4942. For platform-specific bugs, see the sections about compiling and
  4943. porting.  *Note Installing source::.  *Note Porting::.
  4944.  
  4945. Installing MySQL
  4946. ****************
  4947.  
  4948. This chapter describes how to obtain and install MySQL:
  4949.  
  4950.   1. *Determine whether your platform is supported.*  Please note that
  4951.      not all supported systems are equally good for running MySQL on
  4952.      them.  On some it is much more robust and efficient than others.
  4953.      See *Note Which OS:: for details.
  4954.  
  4955.   2. *Choose a distribution to install.*  Several versions of MySQL are
  4956.      available, and most are available in serveral distribution
  4957.      formats.  You can choose from pre-packaged distributions
  4958.      containing binary (precompiled) programs or source code.  When in
  4959.      doubt, use a binary distribution.  We also provide public access
  4960.      to our current source tree, for those who want to see our most
  4961.      recent developments and help us test new code.  To determine which
  4962.      version and type of distribution you should use, see *Note Which
  4963.      version::.
  4964.  
  4965.   3. *Download the distribution that you want to install.* For a list
  4966.      of sites from which you can obtain MySQL, see *Note Getting MySQL:
  4967.      Getting MySQL.  You can verify the integrity of the distribution
  4968.      using the instructions in *Note Verifying Package Integrity::.
  4969.  
  4970.   4. *Install the distribution.*  For binary distributions, use the
  4971.      instructions in in *Note Installing binary::.  For source
  4972.      distributions, use the instructions in *Note Installing source::.
  4973.      Additional installation procedures include the following:
  4974.  
  4975.         * For post-installation procedures, see *Note
  4976.           Post-installation::.  These procedures apply whether you
  4977.           install MySQL using a binary or source distribution.
  4978.  
  4979.         * If you plan to upgrade an existing version of MySQL to a
  4980.           newer version rather than installing MySQL for the first
  4981.           time, see *Note Upgrade:: for information about upgrade
  4982.           procedures and about issues that you should consider before
  4983.           upgrading.
  4984.  
  4985.         * If you want to run the MySQL benchmark scripts, Perl support
  4986.           for MySQL must be available.  *Note Perl support::.
  4987.  
  4988.  
  4989.  
  4990. The last part of the chapter provides information on system-specific
  4991. problems you may run into.
  4992.  
  4993. General Installation Issues
  4994. ===========================
  4995.  
  4996. Before installing MySQL, you should do the following:
  4997.  
  4998.   1. Determine whether or not MySQL runs on your platform.
  4999.  
  5000.   2. Choose a distribution to install.
  5001.  
  5002.   3. Download the distribution and verify its integrity.
  5003.  
  5004.  
  5005. This section contains the information necessary to carry out these
  5006. steps.  After doing so, you can use the instructions in later sections
  5007. of the chapter to install the distribution that you choose.
  5008.  
  5009. Operating Systems Supported by MySQL
  5010. ------------------------------------
  5011.  
  5012. This section lists the operating systems on which you can expect to be
  5013. able to run MySQL.
  5014.  
  5015. We use GNU Autoconf, so it is possible to port MySQL to all modern
  5016. systems that have a C++ compiler and a working implementation of POSIX
  5017. threads.  (Thread suport is needed for the server. To compile only the
  5018. client code, the only requirement is a C++ compiler.) We use and
  5019. develop the software ourselves primarily on Linux (SuSE and Red Hat),
  5020. FreeBSD, and Sun Solaris (Versions 8 and 9).
  5021.  
  5022. MySQL has been reported to compile successfully on the following
  5023. combinations of operating system and thread package.  Note that for many
  5024. operating systems, native thread support works only in the latest
  5025. versions.
  5026.  
  5027.    * AIX 4.x, 5.x with native threads.  *Note IBM-AIX::.
  5028.  
  5029.    * Amiga.
  5030.  
  5031.    * BSDI 2.x with the MIT-pthreads package.  *Note BSDI::.
  5032.  
  5033.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  5034.  
  5035.    * DEC Unix 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  5036.  
  5037.    * FreeBSD 2.x with the MIT-pthreads package.  *Note FreeBSD::.
  5038.  
  5039.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  5040.  
  5041.    * FreeBSD 4.x with Linuxthreads.  *Note FreeBSD::.
  5042.  
  5043.    * HP-UX 10.20 with the DCE threads or the MIT-pthreads package.
  5044.      *Note HP-UX 10.20::.
  5045.  
  5046.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  5047.  
  5048.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  5049.      Linux::.
  5050.  
  5051.    * Mac OS X.  *Note Mac OS X::.
  5052.  
  5053.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make).
  5054.      *Note NetBSD::.
  5055.  
  5056.    * Novell NetWare 6.0.  *Note NetWare installation::.
  5057.  
  5058.    * OpenBSD > 2.5 with native threads. OpenBSD < 2.5 with the
  5059.      MIT-pthreads package.  *Note OpenBSD::.
  5060.  
  5061.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  5062.  
  5063.    * SCO OpenServer with a recent port of the FSU Pthreads package.
  5064.      *Note SCO::.
  5065.  
  5066.    * SCO UnixWare 7.1.x.  *Note SCO UnixWare::.
  5067.  
  5068.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  5069.  
  5070.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  5071.      Solaris::.
  5072.  
  5073.    * SunOS 4.x with the MIT-pthreads package.  *Note Solaris::.
  5074.  
  5075.    * Tru64 Unix
  5076.  
  5077.    * Windows 9x, Me, NT, 2000, and XP.  *Note Windows installation::.
  5078.  
  5079. Not all platforms are equally well-suited for running MySQL. How well a
  5080. certain platform is suited for a high-load mission-critical MySQL
  5081. server is determined by the following factors:
  5082.  
  5083.    * General stability of the thread library. A platform may have an
  5084.      excellent reputation otherwise, but MySQL will be only as stable
  5085.      as the thread library if that library is unstable in the code that
  5086.      is called by MySQL, even if everything else is perfect.
  5087.  
  5088.    * The ability of the kernel and/or thread library to take advantage
  5089.      of symmetric multi-processor (SMP) systems. In other words, when a
  5090.      process creates a thread, it should be possible for that thread to
  5091.      run on a different CPU than the original process.
  5092.  
  5093.    * The ability of the kernel and/or the thread library to run many
  5094.      threads which acquire and release a mutex over a short critical
  5095.      region frequently without excessive context switches. In other
  5096.      words, if the implementation of `pthread_mutex_lock()' is too
  5097.      anxious to yield CPU time, this will hurt MySQL tremendously. If
  5098.      this issue is not taken care of, adding extra CPUs will actually
  5099.      make MySQL slower.
  5100.  
  5101.    * General filesystem stability and performance.
  5102.  
  5103.    * If your tables are big, the ability of the filesystem to deal with
  5104.      large files at all and to deal with them efficiently.
  5105.  
  5106.    * Our level of expertise here at MySQL AB with the platform. If we
  5107.      know a platform well, we enable platform-specific optimizations
  5108.      and fixes at compile time. We can also provide advice on
  5109.      configuring your system optimally for MySQL.
  5110.  
  5111.    * The amount of testing we have done internally for similar
  5112.      configurations.
  5113.  
  5114.    * The number of users that have successfully run MySQL on that
  5115.      platform in similar configurations. If this number is high, the
  5116.      chances of encountering platform-specific surprises are much
  5117.      smaller.
  5118.  
  5119. Based on the preceding criteria, the best platforms for running MySQL
  5120. at this point are x86 with SuSE Linux 8.2, 2.4 kernel, and ReiserFS (or
  5121. any similar Linux distribution) and SPARC with Solaris (2.7-9). FreeBSD
  5122. comes third, but we really hope it will join the top club once the
  5123. thread library is improved. We also hope that at some point we will be
  5124. able to include into the top category all other platforms on which
  5125. MySQL currently compiles and runs okay, but not quite with the same
  5126. level of stability and performance.  This will require some effort on
  5127. our part in cooperation with the developers of the operating system and
  5128. library components that MySQL depends on. If you are interested in
  5129. improving one of those components, are in a position to influence its
  5130. development, and need more detailed instructions on what MySQL needs to
  5131. run better, send an email message to the MySQL internals mailing list.
  5132. *Note Mailing-list::.
  5133.  
  5134. Please note that the purpose of the preceding comparison is not to say
  5135. that one operating system is better or worse than another in general.
  5136. We are talking only about choosing an OS for the specific purpose of
  5137. running MySQL.  With this in mind, the result of this comparison would
  5138. be different if we considered more factors. And in some cases, the
  5139. reason one OS is better than the other could simply be that we have put
  5140. forth more effort into testing on and optimizing for that particular
  5141. platform.  We are just stating our observations to help you decide
  5142. which platform to use MySQL in your setup.
  5143.  
  5144. Choosing Which MySQL Distribution to Install
  5145. --------------------------------------------
  5146.  
  5147. When preparing to install MySQL, you should decide which version to
  5148. use.  MySQL development occurs in several release series, and you can
  5149. pick the one that best fits your needs.  After deciding which version
  5150. to install, you can choose a distribution format.  Releases are
  5151. available in binary or source format.
  5152.  
  5153. Choosing Which Version of MySQL to Install
  5154. ..........................................
  5155.  
  5156. The first decision to make is whether you want to use a production
  5157. (stable) release or a development release.  In the MySQL development
  5158. process, multiple release series co-exist, each at a different stage of
  5159. maturity:
  5160.  
  5161.    * MySQL 5.0 is the newest development release series and is under
  5162.      very active development for new features. Until recently it was
  5163.      available only in preview form from the BitKeeper source
  5164.      repository. An early alpha release has now been issued to allow
  5165.      more widespread testing.
  5166.  
  5167.    * MySQL 4.1 is a development release series to which major new
  5168.      features have been added. It is still at alpha status. Sources and
  5169.      binaries are available for use and testing on development systems.
  5170.  
  5171.    * MySQL 4.0 is the current stable/production-quality release series.
  5172.      New releases are issued for bugfixes. No new features are added
  5173.      that could diminish the code stability.
  5174.  
  5175.    * MySQL 3.23 is the old stable/production-quality release series.
  5176.      This series is retired, so new releases are issued only to fix
  5177.      critical bugs.
  5178.  
  5179.  
  5180. We don't believe in a complete freeze, as this also leaves out bug
  5181. fixes and things that "must be done."  "Somewhat frozen" means that we
  5182. may add small things that "almost surely will not affect anything
  5183. that's already working." Naturally, relevant bugfixes from an earlier
  5184. series propagate to later series.
  5185.  
  5186.    * Normally, if you are beginning to use MySQL for the first time or
  5187.      trying to port it to some system for which there is no binary
  5188.      distribution, we recommend going with the production release
  5189.      series. Currently this is MySQL 4.0.  Note that all MySQL
  5190.      releases, even those from development series, are checked with the
  5191.      MySQL benchmarks and an extensive test suite before being issued.
  5192.  
  5193.    * If you are running an old system and want to upgrade, but don't
  5194.      want to take chances with a non-seamless upgrade, you should
  5195.      upgrade to the latest version in the same release series you are
  5196.      using (where only the last part of the version number is newer
  5197.      than yours).  We have tried to fix only fatal bugs and make small,
  5198.      relatively safe changes to that version.
  5199.  
  5200.    * If you want to use new features not present in the production
  5201.      release series, you can use a version from a development series.
  5202.      Note that development releases are not as stable as production
  5203.      releases.
  5204.  
  5205.    * If you want to use the very latest sources containing all current
  5206.      patches and bugfixes, you can use one of our BitKeeper
  5207.      repositories.  These are not "releases" as such, but are available
  5208.      as previews of the code on which future releases will be based.
  5209.  
  5210. The MySQL naming scheme uses release names that consist of three
  5211. numbers and a suffix, for example, `mysql-4.1.0-alpha'.  The numbers
  5212. within the release name are is interpreted like this:
  5213.  
  5214.    * The first number (`4') is the major version and also describes the
  5215.      file format.  All Version 4 releases have the same file format.
  5216.  
  5217.    * The second number (`1') is the release level.  Taken together, the
  5218.      major version and release level constitute the release series
  5219.      number.
  5220.  
  5221.    * The third number (`0') is the version number within the release
  5222.      series.  This is incremented for each new release.  Usually you
  5223.      want the latest version for the series you have chosen.
  5224.  
  5225.  
  5226. For each minor update, the last number in the version string is
  5227. incremented.  When there are major new features or minor
  5228. incompatibilities with previous versions, the second number in the
  5229. version string is incremented.  When the file format changes, the first
  5230. number is increased.
  5231.  
  5232. Release names also include a suffix to indicates the stability level of
  5233. the release.  Releases within a series progress through a set of
  5234. suffixes to indicate how the stability level improves.  The possible
  5235. suffixes are:
  5236.  
  5237.    * `alpha' indicates that the release contains some large section of
  5238.      new code that hasn't been 100% tested.  Known bugs (usually there
  5239.      are none) should be documented in the News section.  *Note News::.
  5240.      There are also new commands and extensions in most alpha
  5241.      releases.  Active development that may involve major code changes
  5242.      can occur in an alpha release, but everything will be tested
  5243.      before issuing a release.  For this reason, there should be no
  5244.      known bugs in any MySQL release.
  5245.  
  5246.    * `beta' means that all new code has been tested.  No major new
  5247.      features that could cause corruption in old code are added.  There
  5248.      should be no known bugs.  A version changes from alpha to beta
  5249.      when there haven't been any reported fatal bugs within an alpha
  5250.      version for at least a month and we have no plans to add any
  5251.      features that could make any old command unreliable.
  5252.  
  5253.    * `gamma' is a beta that has been around a while and seems to work
  5254.      fine.  Only minor fixes are added.  This is what many other
  5255.      companies call a release.
  5256.  
  5257.    * If there is no suffix, it means that the version has been run for a
  5258.      while at many different sites with no reports of bugs other than
  5259.      platform-specific bugs.  Only critical bug fixes are applied to the
  5260.      release. This is what we call a production (stable) release.
  5261.  
  5262. MySQL uses a naming scheme that is slightly different from most other
  5263. products.  In general, it's relatively safe to use any version that has
  5264. been out for a couple of weeks without being replaced with a new
  5265. version within the release series.
  5266.  
  5267. All releases of MySQL are run through our standard tests and benchmarks
  5268. to ensure that they are relatively safe to use.  Because the standard
  5269. tests are extended over time to check for all previously found bugs,
  5270. the test suite keeps getting better.
  5271.  
  5272. Note that all releases have been tested at least with:
  5273.  
  5274. An internal test suite
  5275.      The `mysql-test' directory contains an extensive set of test cases.
  5276.      We run these tests for virtually every server binary.  See *Note
  5277.      MySQL test suite:: for more information about this test suite.
  5278.  
  5279. The MySQL benchmark suite
  5280.      This suite runs a range of common queries.  It is also a test to
  5281.      see whether the latest batch of optimizations actually made the
  5282.      code faster.  *Note MySQL Benchmarks::.
  5283.  
  5284. The `crash-me' test
  5285.      This test tries to determine what features the database supports
  5286.      and what its capabilities and limitations are.  *Note MySQL
  5287.      Benchmarks::.
  5288.  
  5289. Another test is that we use the newest MySQL version in our internal
  5290. production environment, on at least one machine.  We have more than 100
  5291. gigabytes of data to work with.
  5292.  
  5293. Choosing a Distribution Format
  5294. ..............................
  5295.  
  5296. After choosing which version of MySQL to install, you should decide
  5297. whether to use a binary distribution or a source distribution.  In most
  5298. cases you should probably use a binary distribution, if one exists for
  5299. your platform. Binary distributions are available in native format for
  5300. many platforms, such as RPM files for Linux or DMG package installers
  5301. for Mac OS X. Distributions also are available as Zip archives or
  5302. compressed `tar' files.
  5303.  
  5304. Reasons to choose a binary distribution include the following:
  5305.  
  5306.    * Binary distributions generally are easier to install than source
  5307.      distributions.
  5308.  
  5309.    * To satisfy different user requirements, we provide two different
  5310.      binary versions: one compiled with the non-transactional storage
  5311.      engines (a small, fast binary), and one configured with the most
  5312.      important extended options like transaction-safe tables.  Both
  5313.      versions are compiled from the same source distribution.  All
  5314.      native MySQL clients can connect to both MySQL versions.
  5315.  
  5316.      The extended MySQL binary distribution is marked with the `-max'
  5317.      suffix and is configured with the same options as `mysqld-max'.
  5318.      *Note `mysqld-max': mysqld-max.
  5319.  
  5320.      If you want to use the `MySQL-Max' RPM, you must first install the
  5321.      standard `MySQL-server' RPM.
  5322.  
  5323.  
  5324. Circumstances under which you probably will be better off with a source
  5325. installation include the following:
  5326.  
  5327.    * You want to install MySQL at some explicit location.  The standard
  5328.      binary distributions are "ready to run" at any place, but you may
  5329.      want to have even more flexibility to place MySQL components where
  5330.      you want.
  5331.  
  5332.    * You want to configure `mysqld' with some extra features that are
  5333.      not in the standard binary distributions.  Here is a list of the
  5334.      most common extra options that you may want to use:
  5335.  
  5336.         * `--with-innodb' (default for MySQL 4.0 and onwards)
  5337.  
  5338.         * `--with-berkeley-db' (not available on all platforms)
  5339.  
  5340.         * `--with-raid'
  5341.  
  5342.         * `--with-libwrap'
  5343.  
  5344.         * `--with-named-z-libs' (This is done for some of the binaries)
  5345.  
  5346.         * `--with-debug[=full]'
  5347.  
  5348.    * You want to configure `mysqld' without some features that are
  5349.      included in the standard binary distributions. For example,
  5350.      distributions normally are compiled with support for all character
  5351.      sets. If you want a smaller MySQL server, you can recompile it
  5352.      with support for only the character sets you need.
  5353.  
  5354.    * You have a special compiler (like `pgcc') or want to use compiler
  5355.      options that are better optimized for your processor.  Binary
  5356.      distributions are compiled with options that should work on a
  5357.      variety of processors from the same processor family.
  5358.  
  5359.    * You want to use the latest sources from one of the BitKeeper
  5360.      repositories to have access to all current bugfixes. For example,
  5361.      if you have found a bug and reported it to the MySQL development
  5362.      team, the bugfix will be committed to the source repository and you
  5363.      can access it there.  The bugfix will not appear in a release until
  5364.      a release actually is issued.
  5365.  
  5366.    * You want to read (or modify) the C and C++ code that makes up
  5367.      MySQL. For this purpose, you should get a source distribution,
  5368.      because the source code is always the ultimate manual.  Source
  5369.      distributions also contain more tests and examples than binary
  5370.      distributions.
  5371.  
  5372.  
  5373. How and When Updates Are Released
  5374. .................................
  5375.  
  5376. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  5377. new developments with other MySQL users.  We try to make a release when
  5378. we have very useful features that others seem to have a need for.
  5379.  
  5380. We also try to help out users who request features that are easy to
  5381. implement.  We take note of what our licensed users want to have, and
  5382. we especially take note of what our extended email supported customers
  5383. want and try to help them out.
  5384.  
  5385. No one has to download a new release.  The News section will tell you if
  5386. the new release has something you really want.  *Note News::.
  5387.  
  5388. We use the following policy when updating MySQL:
  5389.  
  5390.    * Releases are issued within each release series. For each release,
  5391.      the last number in the version is one more than the previous
  5392.      release within the same series.
  5393.  
  5394.    * Production (stable) releases are meant to appear about 1-2 times a
  5395.      year, but if small bugs are found, a release with only bug fixes
  5396.      will be issued.
  5397.  
  5398.    * Working releases/bug fixes to old releases are meant to appear
  5399.      about every 4-8 weeks.
  5400.  
  5401.    * Binary distributions for some platforms are made by us for major
  5402.      releases.  Other people may make binary distributions for other
  5403.      systems, but probably less frequently.
  5404.  
  5405.    * We usually make fixes available as soon as we have identified and
  5406.      corrected small or non-critical but annoying bugs. The fixes are
  5407.      available immediately from our public BitKeeper repositories, and
  5408.      will be included in the next release.
  5409.  
  5410.    * If by any chance a fatal bug is found in a release, we will make a
  5411.      new release as soon as possible.  We would like other companies to
  5412.      do this, too.
  5413.  
  5414. Release Philosophy--No Known Bugs in Releases
  5415. .............................................
  5416.  
  5417. We put a lot of time and effort into making our releases bug free.  To
  5418. our knowledge, we have not released a single MySQL version with any
  5419. _known_ "fatal" repeatable bugs.  (A fatal bug is something that
  5420. crashes MySQL under normal usage, produces incorrect answers for normal
  5421. queries, or has a security problem.)
  5422.  
  5423. We have documented all open problems, bugs, and issues that are
  5424. dependent on design decisions.  *Note Bugs::.
  5425.  
  5426. Our aim is to fix everything that is fixable without risk of making a
  5427. stable MySQL version less stable. In certain cases, this means we can
  5428. fix an issue in the development versions, but not in the stable
  5429. (production) version. Naturally, we document such issues so that users
  5430. are aware.
  5431.  
  5432. Here is a description of how our build process works:
  5433.    * We monitor bugs from our customer support list, the bugs database
  5434.      at `http://bugs.mysql.com/', and the MySQL external mailing lists.
  5435.  
  5436.    * All reported bugs for live versions are entered into the bugs
  5437.      database.
  5438.  
  5439.    * When we fix a bug, we always try to make a test case for it and
  5440.      include it into our test system to ensure that the bug will never
  5441.      recur without being detected. (About 90% of all fixed bugs have a
  5442.      test case.)
  5443.  
  5444.    * We also create test cases for all new features we add to MySQL.
  5445.  
  5446.    * Before we start to build a new MySQL release, we ensure that all
  5447.      reported repeatable bugs for the MySQL version (3.23.x, 4.0.x, etc)
  5448.      are fixed.  If something is impossible to fix (due to some internal
  5449.      design decision in MySQL) we document this in the manual.  *Note
  5450.      Bugs::.
  5451.  
  5452.    * We do a build on all platforms for which we support binaries (15+
  5453.      platforms) and run our test suite and benchmark suite on all of
  5454.      them.
  5455.  
  5456.    * We will not publish a binary for a platform for which the test or
  5457.      benchmark suite fails.  If it's a general error in the source, we
  5458.      fix this and do the build plus tests on all systems again, from
  5459.      scratch.
  5460.  
  5461.    * The build and test process takes 2-3 days).  If we receive a
  5462.      report regarding a fatal bug during this process (for example, one
  5463.      that causes a core dump), we fix the problem and restart the build
  5464.      process.
  5465.  
  5466.    * After publishing the binaries on `http://www.mysql.com/', we send
  5467.      out an announcement message to the `mysql' and `announce' mailing
  5468.      lists.  *Note Mailing-list::.  The announcement message contains a
  5469.      list of all changes to the release and any known problems with the
  5470.      release.  (The "known problems" section in the release notes has
  5471.      only been needed in a handful of releases.)
  5472.  
  5473.    * To quickly give our users access to the latest MySQL features, we
  5474.      do a new MySQL release every 4-8 weeks.  Source code snapshots are
  5475.      built daily and are available at
  5476.      `http://downloads.mysql.com/snapshots.php'.
  5477.  
  5478.    * If we, after the release is done, get any bug reports that there
  5479.      was (after all) anything critically wrong with the build on a
  5480.      specific platform, we will fix this at once and build a new `'a''
  5481.      release for that platform. Thanks to our large user base, problems
  5482.      are found quickly.
  5483.  
  5484.    * Our track record for making good releases is quite good.  In the
  5485.      last 150 releases, we had to do a new build for less than 10
  5486.      releases (in 3 of these cases, the bug was a faulty `glibc'
  5487.      library on one of our build machines that took us a long time to
  5488.      track down).
  5489.  
  5490. MySQL Binaries Compiled by MySQL AB
  5491. ...................................
  5492.  
  5493. As a service, we at MySQL AB provide a set of binary distributions of
  5494. MySQL that are compiled at our site or at sites where customers kindly
  5495. have given us access to their machines.
  5496.  
  5497. In addition to the binaries provided in platform-specific package
  5498. formats (see *Note Quick Standard Installation::), we do offer binary
  5499. distributions for a number of platforms in the form of of compressed
  5500. tar files (`.tar.gz').
  5501.  
  5502. These distributions are generated using the script
  5503. `Build-tools/Do-compile' which compiles the source code and creates the
  5504. binary `tar.gz' archive using `scripts/make_binary_distribution' These
  5505. binaries are configured and built with the following compilers and
  5506. options.
  5507.  
  5508. Binaries built on MySQL AB development systems:
  5509.  
  5510. Linux 2.4.xx x86 with `gcc' 2.95.3:
  5511.      `CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2
  5512.      -mcpu=pentiumpro -felide-constructors" ./configure
  5513.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5514.      --enable-thread-safe-client --enable-local-infile
  5515.      --enable-assembler --disable-shared
  5516.      --with-client-ldflags=-all-static
  5517.      --with-mysqld-ldflags=-all-static'
  5518.  
  5519. Linux 2.4.xx Intel Itanium 2 with `ecc' (Intel C++ Itanium Compiler 7.0):
  5520.      `CC=ecc CFLAGS="-O2 -tpp2 -ip -nolib_inline" CXX=ecc CXXFLAGS="-O2
  5521.      -tpp2 -ip -nolib_inline" ./configure --prefix=/usr/local/mysql
  5522.      --with-extra-charsets=complex --enable-thread-safe-client
  5523.      --enable-local-infile'
  5524.  
  5525. Linux 2.4.xx Intel Itanium with `ecc' (Intel C++ Itanium Compiler 7.0):
  5526.      `CC=ecc CFLAGS=-tpp1 CXX=ecc CXXFLAGS=-tpp1 ./configure
  5527.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5528.      --enable-thread-safe-client --enable-local-infile'
  5529.  
  5530. Linux 2.4.xx alpha with `ccc' (Compaq C V6.2-505 / Compaq C++ V6.3-006):
  5531.      `CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
  5532.      generic -noexceptions -nortti" ./configure
  5533.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5534.      --enable-thread-safe-client --enable-local-infile
  5535.      --with-mysqld-ldflags=-non_shared
  5536.      --with-client-ldflags=-non_shared --disable-shared'
  5537.  
  5538. Linux 2.4.xx s390 with `gcc' 2.95.3:
  5539.      `CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors"
  5540.      ./configure --prefix=/usr/local/mysql
  5541.      --with-extra-charsets=complex --enable-thread-safe-client
  5542.      --enable-local-infile --disable-shared
  5543.      --with-client-ldflags=-all-static
  5544.      --with-mysqld-ldflags=-all-static'
  5545.  
  5546. Linux 2.4.xx x86_64 (AMD64) with `gcc' 3.2.1:
  5547.      `CXX=gcc ./configure --prefix=/usr/local/mysql
  5548.      --with-extra-charsets=complex --enable-thread-safe-client
  5549.      --enable-local-infile  --disable-shared'
  5550.  
  5551. Sun Solaris 8 x86 with `gcc' 3.2.3:
  5552.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5553.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5554.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5555.      --localstatedir=/usr/local/mysql/data
  5556.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5557.      --enable-thread-safe-client --enable-local-infile
  5558.      --disable-shared --with-innodb'
  5559.  
  5560. Sun Solaris 8 SPARC with `gcc' 3.2:
  5561.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5562.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5563.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5564.      --with-extra-charsets=complex --enable-thread-safe-client
  5565.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5566.      --with-named-curses-libs=-lcurses --disable-shared'
  5567.  
  5568. Sun Solaris 8 SPARC 64-bit with `gcc' 3.2:
  5569.      `CC=gcc CFLAGS="-O3 -m64 -fno-omit-frame-pointer" CXX=gcc
  5570.      CXXFLAGS="-O3 -m64 -fno-omit-frame-pointer -felide-constructors
  5571.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  5572.      --with-extra-charsets=complex --enable-thread-safe-client
  5573.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5574.      --with-named-curses-libs=-lcurses --disable-shared'
  5575.  
  5576. Sun Solaris 9 SPARC with `gcc' 2.95.3:
  5577.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5578.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5579.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5580.      --with-extra-charsets=complex --enable-thread-safe-client
  5581.      --enable-local-infile --enable-assembler
  5582.      --with-named-curses-libs=-lcurses --disable-shared'
  5583.  
  5584. Sun Solaris 9 SPARC with `cc-5.0' (Sun Forte 5.0):
  5585.      `CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
  5586.      -D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
  5587.      ./configure --prefix=/usr/local/mysql
  5588.      --with-extra-charsets=complex --enable-thread-safe-client
  5589.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5590.      --enable-thread-safe-client --disable-shared'
  5591.  
  5592. IBM AIX 4.3.2 ppc with `gcc' 3.2.3:
  5593.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2
  5594.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  5595.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5596.      --with-extra-charsets=complex --enable-thread-safe-client
  5597.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  5598.  
  5599. IBM AIX 4.3.3 ppc with `xlC_r' (IBM Visual Age C/C++ 6.0):
  5600.      `CC=xlc_r CFLAGS="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  5601.      CXX=xlC_r CXXFLAGS ="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  5602.      ./configure --prefix=/usr/local/mysql
  5603.      --localstatedir=/usr/local/mysql/data
  5604.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5605.      --enable-thread-safe-client --enable-local-infile
  5606.      --with-named-z-libs=no --disable-shared --with-innodb'
  5607.  
  5608. IBM AIX 5.1.0 ppc with `gcc' 3.3:
  5609.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-O2
  5610.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  5611.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5612.      --with-extra-charsets=complex --with-server-suffix="-pro"
  5613.      --enable-thread-safe-client --enable-local-infile
  5614.      --with-named-z-libs=no --disable-shared'
  5615.  
  5616. HP-UX 10.20 pa-risc1.1 with `gcc' 3.1:
  5617.      `CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc
  5618.      CXXFLAGS="-DHPUX -I/opt/dce /include -felide-constructors
  5619.      -fno-exceptions -fno-rtti -O3 -fPIC" ./configure
  5620.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5621.      --enable-thread-safe-client --enable-local-infile  --with-pthread
  5622.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  5623.      --disable-shared'
  5624.  
  5625. HP-UX 11.11 pa-risc2.0 64bit with `aCC' (HP ANSI C++ B3910B A.03.33):
  5626.      `CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
  5627.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5628.      --enable-thread-safe-client --enable-local-infile --disable-shared'
  5629.  
  5630. HP-UX 11.11 pa-risc2.0 32bit with `aCC' (HP ANSI C++ B3910B A.03.33):
  5631.      `CC=cc CXX=aCC CFLAGS="+DAportable" CXXFLAGS="+DAportable"
  5632.      ./configure --prefix=/usr/local/mysql
  5633.      --localstatedir=/usr/local/mysql/data
  5634.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5635.      --enable-thread-safe-client --enable-local-infile
  5636.      --disable-shared --with-innodb'
  5637.  
  5638. Apple Mac OS X 10.2 powerpc with `gcc' 3.1:
  5639.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5640.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5641.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5642.      --with-extra-charsets=complex --enable-thread-safe-client
  5643.      --enable-local-infile  --disable-shared'
  5644.  
  5645. FreeBSD 4.7 i386 with `gcc' 2.95.4:
  5646.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  5647.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5648.      --enable-thread-safe-client --enable-local-infile
  5649.      --enable-assembler --with-named-z-libs=not-used --disable-shared'
  5650.  
  5651. QNX Neutrino 6.2.1 i386 with `gcc' 2.95.3qnx-nto 20010315:
  5652.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5653.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5654.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5655.      --with-extra-charsets=complex --enable-thread-safe-client
  5656.      --enable-local-infile  --disable-shared'
  5657.  
  5658. The following binaries are built on third-party systems kindly provided
  5659. to MySQL AB by other users. Please note that these are only provided as
  5660. a courtesy. Since MySQL AB does not have full control over these
  5661. systems, we can provide only limited support for the binaries built on
  5662. these systems.
  5663.  
  5664. SCO Unix 3.2v5.0.6 i386 with `gcc' 2.95.3:
  5665.      `CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3
  5666.      -mpentium -felide-constructors" ./configure
  5667.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5668.      --enable-thread-safe-client --enable-local-infile
  5669.      --with-named-z-libs=no --enable-thread-safe-client
  5670.      --disable-shared'
  5671.  
  5672. SCO OpenUnix 8.0.0 i386 with `CC' 3.2:
  5673.      `CC=cc CFLAGS="-O" CXX=CC ./configure --prefix=/usr/local/mysql
  5674.      --with-extra-charsets=complex --enable-thread-safe-client
  5675.      --enable-local-infile --with-named-z-libs=no
  5676.      --enable-thread-safe-client --disable-shared'
  5677.  
  5678. Compaq Tru64 OSF/1 V5.1 732 alpha with `cc/cxx' (Compaq C V6.3-029i / DIGITAL C++ V6.1-027):
  5679.      `CC="cc -pthread" CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline
  5680.      speed -speculate all" CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias
  5681.      -fast -inline speed -speculate all -noexceptions -nortti"
  5682.      ./configure --prefix=/usr/local/mysql
  5683.      --with-extra-charsets=complex --enable-thread-safe-client
  5684.      --enable-local-infile --with-prefix=/usr/local/mysql
  5685.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  5686.      --disable-shared --with-mysqld-ldflags=-all-static'
  5687.  
  5688. SGI Irix 6.5 IP32 with `gcc' 3.0.1:
  5689.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
  5690.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5691.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5692.      --with-extra-charsets=complex --enable-thread-safe-client
  5693.      --enable-local-infile  --disable-shared'
  5694.  
  5695. FreeBSD/sparc64 5.0 with `gcc' 3.2.1:
  5696.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  5697.      --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
  5698.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  5699.      --enable-thread-safe-client --enable-local-infile --disable-shared
  5700.      --with-innodb'
  5701.  
  5702. The following compile options have been used for binary packages MySQL
  5703. AB used to provide in the past. These binaries are no longer being
  5704. updated, but the compile options are listed here for reference purposes.
  5705.  
  5706. Linux 2.2.xx SPARC with `egcs' 1.1.2:
  5707.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5708.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5709.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5710.      --with-extra-charsets=complex --enable-thread-safe-client
  5711.      --enable-local-infile --enable-assembler --disable-shared'
  5712.  
  5713. Linux 2.2.x with x686 with `gcc' 2.95.2:
  5714.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  5715.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  5716.      --prefix=/usr/local/mysql --enable-assembler
  5717.      --with-mysqld-ldflags=-all-static --disable-shared
  5718.      --with-extra-charsets=complex'
  5719.  
  5720. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1:
  5721.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  5722.      --prefix=/usr/local/mysql --disable-shared
  5723.      --with-extra-charsets=complex --enable-assembler'
  5724.  
  5725. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or `gcc' 2.95.2 and newer:
  5726.      `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors
  5727.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  5728.      --with-low-memory --with-extra-charsets=complex --enable-assembler'
  5729.  
  5730. SunOS 5.6 i86pc with `gcc' 2.8.1:
  5731.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5732.      --with-low-memory --with-extra-charsets=complex'
  5733.  
  5734. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1:
  5735.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  5736.      --with-extra-charsets=complex'
  5737.  
  5738. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2:
  5739.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5740.      --with-extra-charsets=complex'
  5741.  
  5742. AIX 2 4 with `gcc' 2.7.2.2:
  5743.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5744.      --with-extra-charsets=complex'
  5745.  
  5746. Anyone who has more optimal options for any of the preceding
  5747. configurations listed can always mail them to the MySQL internals
  5748. mailing list.  *Note Mailing-list::.
  5749.  
  5750. RPM distributions prior to MySQL Version 3.22 are user-contributed.
  5751. Beginning with Version 3.22, the RPM distributions are generated by us
  5752. at MySQL AB.
  5753.  
  5754. If you want to compile a debug version of MySQL, you should add
  5755. `--with-debug' or `--with-debug=full' to the preceding configure lines
  5756. and remove any `-fomit-frame-pointer' options.
  5757.  
  5758. For the Windows distribution, please see *Note Windows installation::.
  5759.  
  5760. How to Get MySQL
  5761. ----------------
  5762.  
  5763. Check the MySQL homepage (`http://www.mysql.com/') for information
  5764. about the current version and for downloading instructions.
  5765.  
  5766. Our main mirror is located at `http://mirrors.sunsite.dk/mysql/'.
  5767.  
  5768. For a complete up-to-date list of MySQL web/download mirrors, see
  5769. `http://www.mysql.com/downloads/mirrors.html'.  There you will also
  5770. find information about becoming a MySQL mirror site and how to report a
  5771. bad or out-of-date mirror.
  5772.  
  5773. Verifying Package Integrity Using MD5 Checksums or `GnuPG'
  5774. ----------------------------------------------------------
  5775.  
  5776. After you have downloaded the MySQL package that suits your needs and
  5777. before you attempt to install it, you should make sure it is intact and
  5778. has not been tampered with.
  5779.  
  5780. MySQL AB offers three means of integrity checking:
  5781.  
  5782.    * MD5 checksums
  5783.  
  5784.    * Cryptographic signatures using `GnuPG', the GNU Privacy Guard
  5785.  
  5786.    * For RPM packages, the built-in RPM integrity verification mechanism
  5787.  
  5788.  
  5789. The following sections describe how to use these methods.
  5790.  
  5791. Verifying the `MD5 Checksum'
  5792. ----------------------------
  5793.  
  5794. After you have downloaded the package, you should make sure that the MD5
  5795. checksum matches the one provided on the MySQL download pages. Each
  5796. package has an individual checksum that you can verify with the
  5797. following command, where `package_name' is the name of the package you
  5798. downloaded:
  5799.  
  5800.      shell> md5sum package_name
  5801.  
  5802. Note, that not all operating systems support the `md5sum' command--on
  5803. some it is simply called `md5', others do not ship it at all. On Linux,
  5804. it is part of the `GNU Text Utilities' package, which is available for
  5805. a wide range of platforms. You can download the source code from
  5806. `http://www.gnu.org/software/textutils/' as well. If you have `OpenSSL'
  5807. installed, you can also use the command `openssl md5 package_name'
  5808. instead. A DOS/Windows implementation of the `md5' command is available
  5809. from `http://www.fourmilab.ch/md5/'.
  5810.  
  5811. Example:
  5812.      shell> md5sum mysql-standard-4.0.17-pc-linux-i686.tar.gz
  5813.      60f5fe969d61c8f82e4f7f62657e1f06
  5814.                      mysql-standard-4.0.17-pc-linux-i686.tar.gz
  5815.  
  5816. You should verify that the resulting checksum (the string of hexadecimal
  5817. digits) matches the one displayed on the download page immediately
  5818. below the respective package.
  5819.  
  5820. Signature Checking Using `GnuPG'
  5821. --------------------------------
  5822.  
  5823. Another method of verifying the integrity and authenticity of a package
  5824. is to use cryptographic signatures. This is more reliable than using MD5
  5825. checksums, but requires more work.
  5826.  
  5827. Beginning with MySQL 4.0.10 (February 2003), MySQL AB started signing
  5828. downloadable packages with `GnuPG' (`GNU Privacy Guard').  `GnuPG' is
  5829. an Open Source alternative to the very well-known `Pretty Good Privacy'
  5830. (`PGP') by Phil Zimmermann.  See `http://www.gnupg.org/' for more
  5831. information about `GnuPG' and how to obtain and install it on your
  5832. system. Most Linux distributions already ship with `GnuPG' installed by
  5833. default.  For more information about `OpenPGP', see
  5834. `http://www.openpgp.org/'.
  5835.  
  5836. To verify the signature for a specific package, you first need to
  5837. obtain a copy of MySQL AB's public GPG build key <build@mysql.com>. You
  5838. can either cut and paste it directly from here, or obtain it from
  5839. `http://www.keyserver.net/'.
  5840.  
  5841.      Key ID:
  5842.      pub  1024D/5072E1F5 2003-02-03
  5843.           MySQL Package signing key (www.mysql.com) <build@mysql.com>
  5844.      Fingerprint: A4A9 4068 76FC BD3C 4567  70C8 8C71 8D3B 5072 E1F5
  5845.      
  5846.      Public Key (ASCII-armored):
  5847.      
  5848.      -----BEGIN PGP PUBLIC KEY BLOCK-----
  5849.      Version: GnuPG v1.0.6 (GNU/Linux)
  5850.      Comment: For info see http://www.gnupg.org
  5851.      
  5852.      mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3
  5853.      RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ
  5854.      fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3
  5855.      BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW
  5856.      hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV
  5857.      K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE
  5858.      kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI
  5859.      QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep
  5860.      rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFj
  5861.      a2FnZSBzaWduaW5nIGtleSAod3d3Lm15c3FsLmNvbSkgPGJ1aWxkQG15c3FsLmNv
  5862.      bT6IXQQTEQIAHQUCPj6jDAUJCWYBgAULBwoDBAMVAwIDFgIBAheAAAoJEIxxjTtQ
  5863.      cuH1cY4AnilUwTXn8MatQOiG0a/bPxrvK/gCAJ4oinSNZRYTnblChwFaazt7PF3q
  5864.      zIhMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAn1mxHijft00bKXvu
  5865.      cSo/pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJ
  5866.      YiKJAAoJELb1zU3GuiQ/lpEAoIhpp6BozKI8p6eaabzF5MlJH58pAKCu/ROofK8J
  5867.      Eg2aLos+5zEYrB/LsrkCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/l
  5868.      xaZoJYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRi
  5869.      Rjd1DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE
  5870.      7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fm
  5871.      Le11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p
  5872.      /1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqq
  5873.      a8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSaf
  5874.      anFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOW
  5875.      I39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42Lmu
  5876.      QT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt92
  5877.      6s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZ
  5878.      Whe70YGNPw1yjWJT1IhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4A
  5879.      n3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uUq/SlsQ==
  5880.      =YJkx
  5881.      -----END PGP PUBLIC KEY BLOCK-----
  5882.  
  5883. You can import this key into your public GPG keyring by using `gpg
  5884. --import'. See the GPG documentation for more info on how to work with
  5885. public keys.
  5886.  
  5887. After you have downloaded and imported the public build key, download
  5888. your desired MySQL package and the corresponding signature, which also
  5889. is available from the download page.  The signature file has the same
  5890. name as the distribution file with an `.asc' extension. For example:
  5891.  
  5892. Distribution file      `mysql-standard-4.0.17-pc-linux-i686.tar.gz'
  5893. Signature file         `mysql-standard-4.0.17-pc-linux-i686.tar.gz.asc'
  5894.  
  5895. Make sure that both files are stored in the same directory and then run
  5896. the following command to verify the signature for the distribution file:
  5897.  
  5898.      shell> gpg --verify package_name.asc
  5899.  
  5900. Example:
  5901.  
  5902.      shell> gpg --verify mysql-standard-4.0.17-pc-linux-i686.tar.gz.asc
  5903.      gpg: Warning: using insecure memory!
  5904.      gpg: Signature made Mon 03 Feb 2003 08:50:39 PM MET using DSA key ID 5072E1F5
  5905.      gpg: Good signature from
  5906.           "MySQL Package signing key (www.mysql.com) <build@mysql.com>"
  5907.  
  5908. The "Good signature" message indicates that everything is all right.
  5909.  
  5910. Signature Checking Using `RPM'
  5911. ------------------------------
  5912.  
  5913. For RPM packages, there is no separate signature. RPM packages actually
  5914. have a built-in GPG signature and MD5 checksum. You can verify a
  5915. package by running the following command:
  5916.  
  5917.      shell> rpm --checksig package_name.rpm
  5918.  
  5919. Example:
  5920.  
  5921.      shell> rpm --checksig MySQL-server-4.0.10-0.i386.rpm
  5922.      MySQL-server-4.0.10-0.i386.rpm: md5 gpg OK
  5923.  
  5924. *Note:* If you are using RPM 4.1 and it complains about `(GPG) NOT OK
  5925. (MISSING KEYS: GPG#5072e1f5)' (even though you have imported it into
  5926. your GPG public keyring), you need to import the key into the RPM
  5927. keyring first. RPM 4.1 no longer uses your GPG keyring (and GPG
  5928. itself), but rather maintains its own keyring (because it's a
  5929. system-wide application and the GPG public keyring is a user-specific
  5930. file). To import the MySQL public key into the RPM keyring, use `rpm
  5931. --import'. For example, if you have the public key stored in a file
  5932. named `mysql_pubkey.asc', import it using this command:
  5933.  
  5934.      shell> rpm --import mysql_pubkey.asc
  5935.  
  5936. If you notice that the MD5 checksum or GPG signatures do not match,
  5937. first try to download the respective package one more time, perhaps
  5938. from another mirror site. If you repeatedly cannot successfully verify
  5939. the integrity of the package, please notify us about such incidents
  5940. including the full package name and the download site you have been
  5941. using at <webmaster@mysql.com> or <build@mysql.com>.  Do not report
  5942. downloading problems using the bug-reporting system.
  5943.  
  5944. Installation Layouts
  5945. --------------------
  5946.  
  5947. This section describes the default layout of the directories created by
  5948. installing binary and source distributions.
  5949.  
  5950. On Windows, the default installation directory is `C:\mysql', which has
  5951. the following subdirectories:
  5952.  
  5953. *Directory*               *Contents of directory*
  5954. `bin'                     Client programs and the
  5955.                           `mysqld' server
  5956. `data'                    Log files, databases
  5957. `Docs'                    Documentation
  5958. `examples'                Example programs and scripts
  5959. `include'                 Include (header) files
  5960. `lib'                     Libraries
  5961. `scripts'                 Utility scripts
  5962. `share'                   Error message files
  5963.  
  5964. Installations created from Linux RPM distributions result in files under
  5965. the following system directories:
  5966.  
  5967. *Directory*               *Contents of directory*
  5968. `/usr/bin'                Client programs
  5969. `/usr/sbin'               `mysqld' server
  5970. `/var/lib/mysql'          Log files, databases
  5971. `/usr/share/doc/packages' Documentation
  5972. `include'                 Include (header) files
  5973. `lib'                     Libraries
  5974. `scripts'                 `mysql_install_db'
  5975. `/usr/share/mysql'        Error message and character set
  5976.                           files
  5977. `sql-bench'               Benchmarks
  5978.  
  5979. On Unix, a `tar' file binary distribution is installed by unpacking it
  5980. at the installation location you choose (typically `/usr/local/mysql')
  5981. and creates the following directories in that location:
  5982.  
  5983. *Directory*               *Contents of directory*
  5984. `bin'                     Client programs and the
  5985.                           `mysqld' server
  5986. `data'                    Log files, databases
  5987. `docs'                    Documentation, ChangeLog
  5988. `include'                 Include (header) files
  5989. `lib'                     Libraries
  5990. `scripts'                 `mysql_install_db'
  5991. `share/mysql'             Error message files
  5992. `sql-bench'               Benchmarks
  5993.  
  5994. A source distribution is installed after you configure and compile it.
  5995. By default, the installation step installs files under `/usr/local', in
  5996. the following subdirectories:
  5997.  
  5998. *Directory*               *Contents of directory*
  5999. `bin'                     Client programs and scripts
  6000. `include/mysql'           Include (header) files
  6001. `info'                    Documentation in Info format
  6002. `lib/mysql'               Libraries
  6003. `libexec'                 The `mysqld' server
  6004. `share/mysql'             Error message files
  6005. `sql-bench'               Benchmarks and `crash-me' test
  6006. `var'                     Databases and log files
  6007.  
  6008. Within an installation directory, the layout of a source installation
  6009. differs from that of a binary installation in the following ways:
  6010.  
  6011.    * The `mysqld' server is installed in the `libexec' directory rather
  6012.      than in the `bin' directory.
  6013.  
  6014.    * The data directory is `var' rather than `data'.
  6015.  
  6016.    * `mysql_install_db' is installed in the `bin' directory rather than
  6017.      in the `scripts' directory.
  6018.  
  6019.    * The header file and library directories are `include/mysql' and
  6020.      `lib/mysql' rather than `include' and `lib'.
  6021.  
  6022. You can create your own binary installation from a compiled source
  6023. distribution by executing the `scripts/make_binary_distribution' script
  6024. from the top directory of the source distribution.
  6025.  
  6026. Standard MySQL Installation Using a Binary Distribution
  6027. =======================================================
  6028.  
  6029. This section covers the installation of MySQL on platforms where we
  6030. offer packages using the native packaging format of the respective
  6031. platform. (This is also known as performing a "binary install.")
  6032. However, binary distributions of MySQL are available for many other
  6033. platforms as well. See *Note Installing binary:: for generic
  6034. installation instructions for these packages that apply to all
  6035. platforms.
  6036.  
  6037. See *Note General Installation Issues:: for more information on what
  6038. other binary distributions are available and how to obtain them.
  6039.  
  6040. Installing MySQL on Windows
  6041. ---------------------------
  6042.  
  6043. The installation process for MySQL on Windows has the following steps:
  6044.  
  6045.   1. Install the distribution.
  6046.  
  6047.   2. Set up an option file if necessary.
  6048.  
  6049.   3. Select the server you want to use.
  6050.  
  6051.   4. Start the server.
  6052.  
  6053.   5. Assign passwords to the initial MySQL accounts.
  6054.  
  6055.  
  6056. MySQL for Windows is available in two distribution formats:
  6057.  
  6058.    * The binary distribution contains a setup program that installs
  6059.      everything you need so that you can start the server immediately.
  6060.  
  6061.    * The source distribution contains all the code and support files
  6062.      for building the executables using the VC++ 6.0 compiler.
  6063.  
  6064.  
  6065. Generally speaking, you should use the binary distribution. It's
  6066. simpler, and you need no additional tools to get MySQL up and running.
  6067.  
  6068. This section describes how to install MySQL on Windows using a binary
  6069. distribution.  To install using a source distribution, see *Note
  6070. Windows source build::.
  6071.  
  6072. Windows System Requirements
  6073. ...........................
  6074.  
  6075. To run MySQL on Windows, you need the following:
  6076.  
  6077.    * A 32-bit Windows operating system such as 9x, Me, NT, 2000, or XP.
  6078.      The NT family (Windows NT, 2000, and XP) permits you to run the
  6079.      MySQL server as a service. *Note NT start::.
  6080.  
  6081.    * TCP/IP protocol support.
  6082.  
  6083.    * A copy of the MySQL binary distribution for Windows, which can be
  6084.      downloaded from `http://www.mysql.com/downloads/'.
  6085.  
  6086.      Note: The distribution files are supplied with a zipped format and
  6087.      we recommend the use of an adequate FTP client with resume feature
  6088.      to avoid corruption of files during the download process.
  6089.  
  6090.    * A `ZIP' program to unpack the distribution file.
  6091.  
  6092.    * Enough space on the hard drive to unpack, install, and create the
  6093.      databases in accordance with your requirements.
  6094.  
  6095.    * If you plan to connect to the MySQL server via ODBC, you also need
  6096.      the `MyODBC' driver. *Note ODBC::.
  6097.  
  6098.    * If you need tables with a size larger than 4 GB, install MySQL on
  6099.      an NTFS or newer filesystem. Don't forget to use `MAX_ROWS' and
  6100.      `AVG_ROW_LENGTH' when you create tables.  *Note `CREATE TABLE':
  6101.      CREATE TABLE.
  6102.  
  6103.  
  6104. Installing a Windows Binary Distribution
  6105. ........................................
  6106.  
  6107. To install MySQL on Windows using a binary distribution, follow this
  6108. procedure:
  6109.  
  6110.   1. If you are working on a Windows NT, 2000, or XP machine, make sure
  6111.      you have logged in as a user with administrator privileges.
  6112.  
  6113.   2. If you are doing an upgrade of an earlier MySQL installation, it
  6114.      is necessary to stop the current server.  On Windows NT, 2000, or
  6115.      XP machines, if you are running the server as a Windows service,
  6116.      stop it as follows from the command prompt:
  6117.  
  6118.           C:\> NET STOP MySQL
  6119.  
  6120.      If you plan to use a different server after the upgrade (for
  6121.      example, if you want to run `mysqld-max' rather than `mysqld'),
  6122.      remove the existing service:
  6123.  
  6124.           C:\mysql\bin> mysqld --remove
  6125.  
  6126.      You can reinstall the service to use the proper server after
  6127.      upgrading.
  6128.  
  6129.      If you are not running the MySQL server as a service, stop it like
  6130.      this:
  6131.  
  6132.           C:\mysql\bin> mysqladmin -u root shutdown
  6133.  
  6134.   3. Exit the `WinMySQLAdmin' program if it is running.
  6135.  
  6136.   4. Unzip the distribution file to a temporary directory.
  6137.  
  6138.   5. Run the `setup.exe' program to begin the installation process.  If
  6139.      you want to install MySQL into a location other than the default
  6140.      directory (`C:\mysql'), use the `Browse' button to specify your
  6141.      preferred directory. If you do not install MySQL into the default
  6142.      location, you will need to specify the location whenever you start
  6143.      the server. The easiest way to do this is to use an option file,
  6144.      as described in *Note Windows prepare environment::.
  6145.  
  6146.   6. Finish the install process.
  6147.  
  6148.  
  6149. *Important note:* Early alpha Windows distributions for MySQL 4.1 do
  6150. not contain any installer program.  A 4.1 distribution is a ZIP file
  6151. that you just unzip in the location where you want to install MySQL.
  6152. For example, to install `mysql-4.1.1-alpha-win.zip' as `C:\mysql', unzip
  6153. the distribution file on the `C:' drive, then rename the resulting
  6154. `mysql-4.1.1-alpha' directory to `mysql'.
  6155.  
  6156. If you are upgrading to MySQL 4.1 from an earlier version, you will
  6157. want to preserve your existing `data' directory that contains the grant
  6158. tables in the `mysql' database and your own databases.  Before
  6159. installing 4.1, stop the server if it is running, and save your `data'
  6160. directory to another location. Then either rename the existing
  6161. `C:\mysql' directory or remove it.  Install 4.1 as described in the
  6162. preceding paragraph, and then replace its `data' directory with your
  6163. old `data' directory.  Start the new server and update the grant
  6164. tables.  This will avoid loss of your current databases.  *Note
  6165. Upgrading-grant-tables::.
  6166.  
  6167. Preparing the Windows MySQL Environment
  6168. .......................................
  6169.  
  6170. If you need to specify startup options when you run the server, you can
  6171. indicate them on the command line or place them in an option file. For
  6172. options that will be used every time the server starts, you will find
  6173. it most convenient to use an option file to specify your MySQL
  6174. configuration. This is true particularly under the following
  6175. circumstances:
  6176.  
  6177.    * The installation or data directory locations are different from
  6178.      the default locations (`C:\mysql' and `C:\mysql\data').
  6179.  
  6180.    * You need to tune the server settings.  For example, to use the
  6181.      `InnoDB' transactional tables in MySQL version 3.23, you must
  6182.      manually create two new directories to hold the `InnoDB' data and
  6183.      log files--such as, `C:\ibdata' and `C:\iblogs'.  You will also
  6184.      need to add some extra lines to the option file, as described in
  6185.      *Note `InnoDB' start: InnoDB start.  (As of MySQL 4.0, InnoDB
  6186.      creates its datafiles and log files in the data directory by
  6187.      default. This means you need not configure InnoDB explicitly.  You
  6188.      may still do so if you wish, and an option file will be useful in
  6189.      this case, too.)
  6190.  
  6191.  
  6192. On Windows, the MySQL installer places the data directory directly under
  6193. the directory where you install MySQL.  If you would like to use a data
  6194. directory in a different location, you should copy the entire contents
  6195. of the `data' directory to the new location. For example, by default,
  6196. the installer places MySQL in `C:\mysql' and the data directory in
  6197. `C:\mysql\data'. If you want to use a data directory of `E:\mydata',
  6198. you must do two things:
  6199.  
  6200.    * Move the data directory from `C:\mysql\data' to `E:\mydata'.
  6201.  
  6202.    * Use a `--datadir' option to specify the new data directory location
  6203.      each time you start the server.
  6204.  
  6205.  
  6206. When the MySQL server starts on Windows, it looks for options in two
  6207. files:  The `my.ini' file in the Windows directory, and the `C:\my.cnf'
  6208. file.  The Windows directory typically is named something like
  6209. `C:\WINDOWS' or `C:\WinNT'.  You can determine its exact location from
  6210. the value of the `WINDIR' environment variable using the following
  6211. command:
  6212.  
  6213.      C:\> echo %WINDIR%
  6214.  
  6215. MySQL looks for options first in the `my.ini' file, then in the
  6216. `my.cnf' file.  However, to avoid confusion, it's best if you use only
  6217. one file.  If your PC uses a boot loader where the `C:' drive isn't the
  6218. boot drive, your only option is to use the `my.ini' file.  Whichever
  6219. one you use, it must be a plain text file.
  6220.  
  6221. An option file can be created and modified with any text editor, such
  6222. as the `Notepad' program.  For example, if MySQL is installed at
  6223. `D:\mysql' and the data directory is located as `D:\mydata\data', you
  6224. can create the option file and set up a `[mysqld]' section to specify
  6225. values for the `basedir' and `datadir' parameters:
  6226.  
  6227.      [mysqld]
  6228.      # set basedir to your installation path
  6229.      basedir=D:/mysql
  6230.      # set datadir to the location of your data directory
  6231.      datadir=D:/mydata/data
  6232.  
  6233. Note that Windows pathnames are specified in option files using forward
  6234. slashes rather than backslashes.  If you do use backslashes, you must
  6235. double them.
  6236.  
  6237. Another way to manage an option file is to use the the `WinMySQLAdmin'
  6238. tool. You can find `WinMySQLAdmin' in the `bin' directory of your MySQL
  6239. installation, as well as a help file containing instructions for using
  6240. it. `WinMySQLAdmin' has the capability of editing your option file, but
  6241. note these points:
  6242.  
  6243.    * `WinMySQLAdmin' uses only the `my.ini' file.
  6244.  
  6245.    * If `WinMySQLAdmin' finds a `C:\my.cnf' file, it will in fact rename
  6246.      it to `C:\my_cnf.bak' to disable it.
  6247.  
  6248.  
  6249. Now you are ready to test starting the server.
  6250.  
  6251. Selecting a Windows Server
  6252. ..........................
  6253.  
  6254. Starting with MySQL 3.23.38, the Windows distribution includes both the
  6255. normal and the MySQL-Max server binaries.  Here is a list of the
  6256. different MySQL servers from which you can choose:
  6257.  
  6258. *Binary*       *Description*
  6259. `mysqld'       Compiled with full debugging and automatic memory
  6260.                allocation checking, symbolic links, and `InnoDB' and
  6261.                `BDB' tables.
  6262. `mysqld-opt'   Optimized binary.  From version 4.0 on, `InnoDB' is
  6263.                enabled.  Before 4.0, this server includes no
  6264.                transactional table support.
  6265. `mysqld-nt'    Optimized binary for NT/2000/XP with support for named
  6266.                pipes.
  6267. `mysqld-max'   Optimized binary with support for symbolic links, and
  6268.                `InnoDB' and `BDB' tables.
  6269. `mysqld-max-nt'Like `mysqld-max', but compiled with support for named
  6270.                pipes.
  6271.  
  6272. All of the preceding binaries are optimized for modern Intel processors
  6273. but should work on any Intel i386-class or higher processor.
  6274.  
  6275. MySQL supports TCP/IP on all Windows platforms. The `mysqld-nt' and
  6276. `mysql-max-nt' servers support named pipes on NT, 2000, and XP.
  6277. However, the default is to use TCP/IP regardless of the platform.
  6278. (Named pipes are slower than TCP/IP in many Windows configurations.)
  6279.  
  6280. Named pipe use is subject to these conditions:
  6281.  
  6282.    * Starting from MySQL 3.23.50, named pipes are enabled only if you
  6283.      start the server with the `--enable-named-pipe' option.  It is now
  6284.      necessary to use this option explicitly because some users have
  6285.      experienced problems shutting down the MySQL server when named
  6286.      pipes are used.
  6287.  
  6288.    * Named pipe connections are allowed only by the `mysqld-nt' or
  6289.      `mysqld-max-nt' servers, and only if the server is run on a
  6290.      version of Windows that supports named pipes (NT, 2000, XP).
  6291.  
  6292.    * These servers can be run on Windows 98 or Me, but only if TCP/IP
  6293.      is installed; named pipe connections cannot be used.
  6294.  
  6295.    * On Windows 95, these servers cannot be used.
  6296.  
  6297.  
  6298. Starting the Server for the First Time
  6299. ......................................
  6300.  
  6301. On Windows 95, 98, or Me, MySQL clients always connect to the server
  6302. using TCP/IP.  (This will allow any machine on your network to connect
  6303. to your MySQL server.)  Because of this, you must make sure that TCP/IP
  6304. support is installed on your machine before starting MySQL.  You can
  6305. find TCP/IP on your Windows CD-ROM.
  6306.  
  6307. Note that if you are using an old Windows 95 release (for example,
  6308. OSR2), it's likely that you have an old Winsock package; MySQL requires
  6309. Winsock 2! You can get the newest Winsock from
  6310. `http://www.microsoft.com/'.  Windows 98 has the new Winsock 2 library,
  6311. so it is unnecessary to update the library.
  6312.  
  6313. On NT-based systems such as Windows NT, 2000, or XP, clients have two
  6314. options. They can use TCP/IP, or they can use a named pipe if the server
  6315. supports named pipe connections.
  6316.  
  6317. For information about which server binary to run, see *Note Windows
  6318. prepare environment::.
  6319.  
  6320. This section gives a general overview of starting the MySQL server.
  6321. The following sections provide more specific information for particular
  6322. versions of Windows.
  6323.  
  6324. The examples in these sections assume that MySQL is installed under the
  6325. default location of `C:\mysql'. Adjust the pathnames shown in the
  6326. examples if you have MySQL installed in a different location.
  6327.  
  6328. Testing is best done from a command prompt in a console window (a "DOS
  6329. window"). This way you can have the server display status messages in
  6330. the window where they are easy to see.  If something is wrong with your
  6331. configuration, these messages will make it easier for you to identify
  6332. and fix any problems.
  6333.  
  6334. Make sure you are in the directory where the server is located, then
  6335. enter this command:
  6336.  
  6337.      C:\mysql\bin> mysqld --console
  6338.  
  6339. For servers that include `InnoDB' support, you should see the following
  6340. messages as the server starts:
  6341.  
  6342.      InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist:
  6343.      InnoDB: a new database to be created!
  6344.      InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200
  6345.      InnoDB: Database physically writes the file full: wait...
  6346.      InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created
  6347.      InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280
  6348.      InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created
  6349.      InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280
  6350.      InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created
  6351.      InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280
  6352.      InnoDB: Doublewrite buffer not found: creating new
  6353.      InnoDB: Doublewrite buffer created
  6354.      InnoDB: creating foreign key constraint system tables
  6355.      InnoDB: foreign key constraint system tables created
  6356.      011024 10:58:25  InnoDB: Started
  6357.  
  6358. When the server finishes its startup sequence, you should see something
  6359. like this, which indicates that the server is ready to service client
  6360. connections:
  6361.  
  6362.      mysqld: ready for connections
  6363.      Version: '4.0.14-log'  socket: ''  port: 3306
  6364.  
  6365. The server will continue to write to the console any further diagnostic
  6366. output it produces.  You can open a new console window in which to run
  6367. client programs.
  6368.  
  6369. If you omit the `--console' option, the server writes diagnostic output
  6370. to the error log in the data directory. The error log is the file with
  6371. the `.err' extension.
  6372.  
  6373. The accounts that are listed in the MySQL grant tables initially have no
  6374. passwords.  After starting the server, you should set up passwords for
  6375. them using the instructions in *Note Post-installation::.
  6376.  
  6377. Starting MySQL from the Windows Command Line
  6378. ............................................
  6379.  
  6380. The MySQL server can be started manually from the command line.  This
  6381. can be done on any version of Windows.
  6382.  
  6383. To start the `mysqld' server from the command line, you should start a
  6384. console window (a "DOS" window) and enter this command:
  6385.  
  6386.      shell> C:\mysql\bin\mysqld
  6387.  
  6388. On non-NT versions of Windows, this will start `mysqld' in the
  6389. background. That is, after the server starts, you should see another
  6390. command prompt. If you start the server this way on Windows NT, 2000,
  6391. or XP, the server will run in the foreground and no command prompt will
  6392. appear until the server exits.  Because of this, you should open
  6393. another console window to run client programs while the server is
  6394. running.
  6395.  
  6396. You can stop the MySQL server by executing this command:
  6397.  
  6398.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  6399.  
  6400. This invokes the MySQL administrative utility `mysqladmin' to connect
  6401. to the server and tell it to shut down. The command connects as `root',
  6402. which is the default administrative account in the MySQL grant system.
  6403. Please note that users in the MySQL grant system are wholly independent
  6404. from any login users under Windows.
  6405.  
  6406. If `mysqld' doesn't start, check the error log to see whether the
  6407. server wrote any messages there to indicate the cause of the problem.
  6408. The error log is located in the `C:\mysql\data' directory. It is the
  6409. file with a suffix of `.err'. You can also try to start the server as
  6410. `mysqld --console'; in this case, you may get some useful information
  6411. on the screen that may help solve the problem.
  6412.  
  6413. The last option is to start `mysqld' with `--standalone --debug'.  In
  6414. this case `mysqld' will write a log file `C:\mysqld.trace' that should
  6415. contain the reason why `mysqld' doesn't start. *Note Making trace
  6416. files::.
  6417.  
  6418. Use `mysqld --help' to display all the options that `mysqld'
  6419. understands!
  6420.  
  6421. Starting MySQL as a Windows Service
  6422. ...................................
  6423.  
  6424. On the NT family (Windows NT, 2000, or XP), the recommended way to run
  6425. MySQL is to install it as a Windows service. Then Windows starts and
  6426. stops the MySQL server automatically when Windows starts and stops. A
  6427. server installed as a service can also be controlled from the command
  6428. line using `NET' commands, or with the graphical `Services' utility.
  6429.  
  6430. The `Services' utility (the Windows `Service Control Manager') can be
  6431. found in the Windows `Control Panel' (under `Administrative Tools' on
  6432. Windows 2000). It is advisable to close the `Services' utility while
  6433. performing server installation or removal operations from this command
  6434. line.  This prevents some odd errors.
  6435.  
  6436. To get MySQL to work with TCP/IP on Windows NT 4, you must install
  6437. service pack 3 (or newer)!
  6438.  
  6439. Before installing MySQL as a Windows service, you should first stop the
  6440. current server if it is running by using the following command:
  6441.  
  6442.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  6443.  
  6444. This invokes the MySQL administrative utility `mysqladmin' to connect
  6445. to the server and tell it to shut down. The command connects as `root',
  6446. which is the default administrative account in the MySQL grant system.
  6447. Please note that users in the MySQL grant system are wholly independent
  6448. from any login users under Windows.
  6449.  
  6450. Now install the server as a service:
  6451.  
  6452.      shell> mysqld --install
  6453.  
  6454. If you have problems installing `mysqld' as a service using just the
  6455. server name, try installing it using its full pathname:
  6456.  
  6457.      shell> C:\mysql\bin\mysqld --install
  6458.  
  6459. As of MySQL 4.0.2, you can specify a specific service name after the
  6460. `--install' option.  As of MySQL 4.0.3, you can in addition specify a
  6461. `--defaults-file' option after the service name to indicate where the
  6462. server should obtain options when it starts. The rules that determine
  6463. the service name and option files the server uses are as follows:
  6464.  
  6465.    * If you specify no service name, the server uses the default
  6466.      service name of `MySQL' and the server reads options from the
  6467.      `[mysqld]' group in the standard option files.
  6468.  
  6469.    * If you specify a service name after the `--install' option, the
  6470.      server ignores the `[mysqld]' option group and instead reads
  6471.      options from the group that has the same name as the service. The
  6472.      server reads options from the standard option files.
  6473.  
  6474.    * If you specify a `--defaults-file' option after the service name,
  6475.      the server ignores the standard option files and reads options
  6476.      only from the `[mysqld]' group of the named file.
  6477.  
  6478.  
  6479. *Note:* Prior to MySQL 4.0.17, a server installed as a Windows service
  6480. has problems starting if its pathname or the service name contains
  6481. spaces. For this reason, avoid installing MySQL in a directory such as
  6482. `C:\Program Files' or using a service name containing spaces.
  6483.  
  6484. In the usual case that you install the server with `--install' but no
  6485. service name, the server is installed with a service name of `MySQL'.
  6486.  
  6487. As a more complex example, consider the following command (which should
  6488. be entered on a single line):
  6489.  
  6490.      shell> C:\mysql\bin\mysqld --install mysql
  6491.                 --defaults-file=C:\my-opts.cnf
  6492.  
  6493. Here, a service name is given after the `--install' option. If no
  6494. `--defaults-file' option had been given, this command would have the
  6495. effect of causing the server to read the `[mysql]' group from the
  6496. standard option files. (This would be a bad idea, because that option
  6497. group is for use by the `mysql' client program.) However, because the
  6498. `--defaults-file' option is present, the server reads options only from
  6499. the named file, and only from the `[mysqld]' option group.
  6500.  
  6501. You can also specify options as "`Start parameters'" in the Windows
  6502. `Services' utility before you start the MySQL service.
  6503.  
  6504. Once a MySQL server is installed as a service, Windows will start the
  6505. service automatically whenever Windows starts.  The service also can be
  6506. started immediately from the `Services' utility, or by using the
  6507. command `NET START MySQL'.  The `NET' command is not case sensitive.
  6508.  
  6509. Please note that when run as a service, `mysqld' has no access to a
  6510. console window, so no messages can be seen there.  If `mysqld' doesn't
  6511. start, check the error log to see whether the server wrote any messages
  6512. there to indicate the cause of the problem.  The error log is located
  6513. in the `C:\mysql\data' directory. It is the file with a suffix of
  6514. `.err'.
  6515.  
  6516. When `mysqld' is running as a service, it can be stopped by using the
  6517. `Services' utility, the command `NET STOP MySQL', or the command
  6518. `mysqladmin shutdown'. If the service is running when Windows shuts
  6519. down, Windows will stop the server automatically.
  6520.  
  6521. From MySQL version 3.23.44, you have the choice of installing the
  6522. server as a `Manual' service if you don't wish the service to be
  6523. started automatically during the boot process. To do this, use the
  6524. `--install-manual' option rather than the `--install' option:
  6525.  
  6526.      shell> C:\mysql\bin\mysqld --install-manual
  6527.  
  6528. To remove a server that is installed as a service, first stop it if it
  6529. is running. Then use the `--remove' option to remove it:
  6530.  
  6531.      shell> mysqld --remove
  6532.  
  6533. For MySQL versions older than 3.23.49, one problem with automatic MySQL
  6534. service shutdown is that Windows waited only for a few seconds for the
  6535. shutdown to complete, then killed the database server process if the
  6536. time limit was exceeded. This had the potential to cause problems.
  6537. (For example, the `InnoDB' storage engine had to perform crash recovery
  6538. at the next startup.) Starting from MySQL version 3.23.49, Windows
  6539. waits longer for the MySQL server shutdown to complete. If you notice
  6540. this still is not enough for your installation, it is safest not to run
  6541. the MySQL server as a service. Instead, start it from the command-line
  6542. prompt, and stop it with `mysqladmin shutdown'.
  6543.  
  6544. This change to tell Windows to wait longer when stopping the MySQL
  6545. server works for Windows 2000 and XP. It does not work for Windows NT,
  6546. where Windows waits only 20 seconds for a service to shut down, and
  6547. after that kills the service process. You can increase this default by
  6548. opening the Registry Editor `\winnt\system32\regedt32.exe' and editing
  6549. the value of `WaitToKillServiceTimeout' at
  6550. `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' in the Registry
  6551. tree. Specify the new larger value in milliseconds.  For example, the
  6552. value 120000 tells Windows NT to wait up to 120 seconds.
  6553.  
  6554. If you don't want to start `mysqld' as a service, you can start it from
  6555. the command line the same way as for versions of Windows that are not
  6556. based on NT.  For instructions, see *Note Win95 start::.
  6557.  
  6558. Running MySQL Client Programs on Windows
  6559. ........................................
  6560.  
  6561. You can test whether the MySQL server is working by executing any of the
  6562. following commands:
  6563.  
  6564.      C:\> C:\mysql\bin\mysqlshow
  6565.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  6566.      C:\> C:\mysql\bin\mysqladmin version status proc
  6567.      C:\> C:\mysql\bin\mysql test
  6568.  
  6569. If `mysqld' is slow to respond to TCP/IP connections from client
  6570. programs on Windows 9x/Me, there is probably a problem with your DNS.
  6571. In this case, start `mysqld' with the `--skip-name-resolve' option and
  6572. use only `localhost' and IP numbers in the `Host' column of the MySQL
  6573. grant tables.
  6574.  
  6575. You can force a MySQL client to use a named pipe connection rather than
  6576. TCP/IP  by specifying the `--pipe' option or by specifying `.' (period)
  6577. as the host name.  Use the `--socket' option to specify the name of the
  6578. pipe.  In MySQL 4.1, you should use the `--protocol=PIPE' option.
  6579.  
  6580. There are two versions of the MySQL command-line tool:
  6581. *Binary*       *Description*
  6582. `mysql'        Compiled on native Windows, offering limited text editing
  6583.                capabilities.
  6584. `mysqlc'       Compiled with the Cygnus GNU compiler and libraries,
  6585.                which offers `readline' editing.
  6586.  
  6587. If you want to use `mysqlc', you must have a copy of the
  6588. `cygwinb19.dll' library installed somewhere that `mysqlc' can find it.
  6589. Current distributions of MySQL include this library in the same
  6590. directory as `mysqlc' (the `bin' directory under the base directory of
  6591. your MySQL installation). If your distribution does not have the
  6592. `cygwinb19.dll' library in the `bin' directory, look for it in the
  6593. `lib' directory and copy it to your Windows system directory
  6594. (`\Windows\system' or similar place).
  6595.  
  6596. MySQL on Windows Compared to MySQL on Unix
  6597. ..........................................
  6598.  
  6599. MySQL for Windows has by now proven itself to be very stable. The
  6600. Windows version of MySQL has the same features as the corresponding
  6601. Unix version, with the following exceptions:
  6602.  
  6603. *Windows 95 and threads*
  6604.      Windows 95 leaks about 200 bytes of main memory for each thread
  6605.      creation.  Each connection in MySQL creates a new thread, so you
  6606.      shouldn't run `mysqld' for an extended time on Windows 95 if your
  6607.      server handles many connections!  Other versions of Windows don't
  6608.      suffer from this bug.
  6609.  
  6610. *Concurrent reads*
  6611.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  6612.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  6613.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  6614.      level interface with a virtual interface so that we can use the
  6615.      `readfile()'/`writefile()' interface on NT/2000/XP to get more
  6616.      speed.  The current implementation limits the number of open files
  6617.      MySQL can use to 1024, which means that you will not be able to
  6618.      run as many concurrent threads on NT/2000/XP as on Unix.
  6619.  
  6620. *Blocking read*
  6621.      MySQL uses a blocking read for each connection, which has the
  6622.      following implications:
  6623.  
  6624.         * A connection will not be disconnected automatically after 8
  6625.           hours, as happens with the Unix version of MySQL.
  6626.  
  6627.         * If a connection hangs, it's impossible to break it without
  6628.           killing MySQL.
  6629.  
  6630.         * `mysqladmin kill' will not work on a sleeping connection.
  6631.  
  6632.         * `mysqladmin shutdown' can't abort as long as there are
  6633.           sleeping connections.
  6634.  
  6635.      We plan to fix this problem when our Windows developers have
  6636.      figured out a nice workaround.
  6637.  
  6638. *`DROP DATABASE'*
  6639.      You can't drop a database that is in use by some thread.
  6640.  
  6641. *Killing MySQL from the task manager*
  6642.      You can't kill MySQL from the task manager or with the shutdown
  6643.      utility in Windows 95.  You must take it down with `mysqladmin
  6644.      shutdown'.
  6645.  
  6646. *Case-insensitive names*
  6647.      Filenames are not case sensitive on Windows, so MySQL database and
  6648.      table names are also not case sensitive on Windows.  The only
  6649.      restriction is that database and table names must be specified
  6650.      using the same case throughout a given statement.  *Note Name case
  6651.      sensitivity::.
  6652.  
  6653. *The `\' pathname separator character*
  6654.      Pathname components in Windows 95 are separated by the `\'
  6655.      character, which is also the escape character in MySQL.  If you
  6656.      are using `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', use
  6657.      Unix style filenames with `/' characters:
  6658.  
  6659.           mysql> LOAD DATA INFILE "C:/tmp/skr.txt" INTO TABLE skr;
  6660.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  6661.  
  6662.      Alternatively, you must double the `\' character:
  6663.  
  6664.           mysql> LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
  6665.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  6666.  
  6667. *Problems with pipes.*
  6668.      Pipes doesn't work reliably in the Windows command-line prompt.
  6669.      If the pipe includes the character `^Z' / `CHAR(24)', Windows will
  6670.      think it has encountered end-of-file and abort the program.
  6671.  
  6672.      This is mainly a problem when you try to apply a binary log as
  6673.      follows:
  6674.  
  6675.           mysqlbinlog binary-log-name | mysql --user=root
  6676.  
  6677.      If you get a problem applying the log and suspect it's because of
  6678.      an `^Z' / `CHAR(24)' character you can use the following
  6679.      workaround:
  6680.  
  6681.           mysqlbinlog binary-log-file --result-file=/tmp/bin.sql
  6682.           mysql --user=root --execute "source /tmp/bin.sql"
  6683.  
  6684.      The latter command also can be used to reliably read in any SQL
  6685.      file that may contain binary data.
  6686.  
  6687. *`Can't open named pipe' error*
  6688.      If you use a MySQL Version 3.22 server on NT with the newest MySQL
  6689.      client programs, you will get the following error:
  6690.  
  6691.           error 2017: can't open named pipe to host: . pipe...
  6692.  
  6693.      This is because the release version of MySQL uses named pipes on NT
  6694.      by default.  You can avoid this error by using the
  6695.      `--host=localhost' option to the new MySQL clients or create an
  6696.      option file `C:\my.cnf' that contains the following information:
  6697.  
  6698.           [client]
  6699.           host = localhost
  6700.  
  6701.      Starting from 3.23.50, named pipes are enabled only if `mysqld-nt'
  6702.      or `mysqld-max-nt' is started with `--enable-named-pipe'.
  6703.  
  6704. *`Access denied for user' error*
  6705.      If you attempt to run a MySQL client program to connect to a server
  6706.      running on the same machine, but get the error `Access denied for
  6707.      user: 'some-user@unknown' to database 'mysql'', this means that
  6708.      MySQL can't resolve your hostname properly.
  6709.  
  6710.      To fix this, you should create a file `\windows\hosts' with the
  6711.      following information:
  6712.  
  6713.           127.0.0.1       localhost
  6714.  
  6715. *`ALTER TABLE'*
  6716.      While you are executing an `ALTER TABLE' statement, the table is
  6717.      locked from being used by other threads.  This has to do with the
  6718.      fact that on Windows, you can't delete a file that is in use by
  6719.      another threads.  In the future, we may find some way to work
  6720.      around this problem.
  6721.  
  6722. *`DROP TABLE'*
  6723.      `DROP TABLE' on a table that is in use by a `MERGE' table will not
  6724.      work on Windows because the `MERGE' handler does the table mapping
  6725.      hidden from the upper layer of MySQL.  Because Windows doesn't
  6726.      allow you to drop files that are open, you first must flush all
  6727.      `MERGE' tables (with `FLUSH TABLES') or drop the `MERGE' table
  6728.      before dropping the table.  We will fix this at the same time we
  6729.      introduce views.
  6730.  
  6731. *`DATA DIRECTORY' and `INDEX DIRECTORY'*
  6732.      The `DATA DIRECTORY' and `INDEX DIRECTORY' options for `CREATE
  6733.      TABLE' are ignored on Windows, because Windows doesn't support
  6734.      symbolic links.  These options also are ignored on systems that
  6735.      have a non-functional `realpath()' call.
  6736.  
  6737. Here are some open issues for anyone who might want to help us improve
  6738. MySQL on Windows:
  6739.  
  6740.    * Add some nice start and shutdown icons to the MySQL installation.
  6741.  
  6742.    * It would be really nice to be able to kill `mysqld' from the task
  6743.      manager.  For the moment, you must use `mysqladmin shutdown'.
  6744.  
  6745.    * Port `readline' to Windows for use in the `mysql' command-line
  6746.      tool.
  6747.  
  6748.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  6749.      `mysqladmin', and `mysqldump') would be nice.
  6750.  
  6751.    * It would be nice if the socket read and write functions in `net.c'
  6752.      were interruptible. This would make it possible to kill open
  6753.      threads with `mysqladmin kill' on Windows.
  6754.  
  6755.    * Add macros to use the faster thread-safe increment/decrement
  6756.      methods provided by Windows.
  6757.  
  6758. Installing MySQL on Linux
  6759. -------------------------
  6760.  
  6761. The recommended way to install MySQL on Linux is by using the RPM
  6762. packages. The MySQL RPMs are currently built on a SuSE Linux 7.3 system
  6763. but should work on most versions of Linux that support `rpm' and use
  6764. `glibc'.
  6765.  
  6766. If you have problems with an RPM file (for example, if you receive the
  6767. error "`Sorry, the host 'xxxx' could not be looked up'"), see *Note
  6768. Binary notes-Linux::.
  6769.  
  6770. In most cases, you only need to install the `MySQL-server' and
  6771. `MySQL-client' packages to get a functional MySQL installation. The
  6772. other packages are not required for a standard installation.  If you
  6773. want to run a MySQL-Max server that has additional capabilities, you
  6774. should install the `MySQL-Max' RPM. However, you should do so only _
  6775. after_ installing the `MySQL-server' RPM.  *Note `mysqld-max':
  6776. mysqld-max.
  6777.  
  6778. If you get a dependency failure when trying to install the MySQL 4.0
  6779. packages (for example, "`error: removing these packages would break
  6780. dependencies: libmysqlclient.so.10 is needed by ...'"), you should also
  6781. install the package `MySQL-shared-compat', which includes both the
  6782. shared libraries for backward compatibility (`libmysqlclient.so.12' for
  6783. MySQL 4.0 and `libmysqlclient.so.10' for MySQL 3.23).
  6784.  
  6785. Many Linux distributions still ship with MySQL 3.23 and they usually
  6786. link applications dynamically to save disk space. If these shared
  6787. libraries are in a separate package (for example, `MySQL-shared'), it is
  6788. sufficient to simply leave this package installed and just upgrade the
  6789. MySQL server and client packages (which are statically linked and do
  6790. not depend on the shared libraries). For distributions that include the
  6791. shared libraries in the same package as the MySQL server (for example,
  6792. Red Hat Linux), you could either install our 3.23 `MySQL-shared' RPM,
  6793. or use the `MySQL-shared-compat' package instead.
  6794.  
  6795. The following RPM packages are available:
  6796.  
  6797.    * `MySQL-server-VERSION.i386.rpm'
  6798.  
  6799.      The MySQL server.  You will need this unless you only want to
  6800.      connect to a MySQL server running on another machine. Please note:
  6801.      Server RPM files were called `MySQL-VERSION.i386.rpm' before MySQL
  6802.      4.0.10. That is, they did not have `-server' in the name.
  6803.  
  6804.    * `MySQL-Max-VERSION.i386.rpm'
  6805.  
  6806.      The MySQL-Max server. This server has additional capabilities that
  6807.      the one provided in the `MySQL-server' RPM does not.  You must
  6808.      install the `MySQL-server' RPM first, because the `MySQL-Max' RPM
  6809.      depends on it.
  6810.  
  6811.    * `MySQL-client-VERSION.i386.rpm'
  6812.  
  6813.      The standard MySQL client programs. You probably always want to
  6814.      install this package.
  6815.  
  6816.    * `MySQL-bench-VERSION.i386.rpm'
  6817.  
  6818.      Tests and benchmarks. Requires Perl and the `DBD::mysql' module.
  6819.  
  6820.    * `MySQL-devel-VERSION.i386.rpm'
  6821.  
  6822.      The libraries and include files that are needed if you want to
  6823.      compile other MySQL clients, such as the Perl modules.
  6824.  
  6825.    * `MySQL-shared-VERSION.i386.rpm'
  6826.  
  6827.      This package contains the shared libraries (`libmysqlclient.so*')
  6828.      that certain languages and applications need to dynamically load
  6829.      and use MySQL.
  6830.  
  6831.    * `MySQL-shared-compat-VERSION.i386.rpm'
  6832.  
  6833.      This package includes the shared libraries for both MySQL 3.23 and
  6834.      MySQL 4.0. Install this package instead of `MySQL-shared', if you
  6835.      have applications installed that are dynamically linked against
  6836.      MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking
  6837.      the library dependencies. This package is available since MySQL
  6838.      4.0.13.
  6839.  
  6840.    * `MySQL-embedded-VERSION.i386.rpm'
  6841.  
  6842.      The embedded MySQL server library (from MySQL 4.0).
  6843.  
  6844.    * `MySQL-VERSION.src.rpm'
  6845.  
  6846.      This contains the source code for all of the previous packages. It
  6847.      can also be used to rebuild the RPMs on other architectures (for
  6848.      example, Alpha or SPARC).
  6849.  
  6850. To see all files in an RPM package (for example, a `MySQL-server' RPM),
  6851. run:
  6852.  
  6853.      shell> rpm -qpl MySQL-server-VERSION.i386.rpm
  6854.  
  6855. To perform a standard minimal installation, run:
  6856.  
  6857.      shell> rpm -i MySQL-server-VERSION.i386.rpm
  6858.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  6859.  
  6860. To install just the client package, run:
  6861.  
  6862.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  6863.  
  6864. RPM provides a feature to verify the integrity and authenticity of
  6865. packages before installing them. If you would like to learn more about
  6866. this feature please see *Note Verifying Package Integrity::.
  6867.  
  6868. The server RPM places data under the `/var/lib/mysql' directory. The
  6869. RPM also creates the appropriate entries in `/etc/init.d/' to start the
  6870. server automatically at boot time. (This means that if you have
  6871. performed a previous installation and have made changes to its startup
  6872. script, you may want to make a copy of the script so you don't lose it
  6873. when you install a newer RPM.) See *Note Automatic start:: for more
  6874. information on how MySQL can be started automatically on system startup.
  6875.  
  6876. If you want to install the MySQL RPM on older Linux distributions that
  6877. do not support initialization scripts in `/etc/init.d' (directly or via
  6878. a symlink), you should create a symbolic link that points to the
  6879. location where your initialization scripts actually are installed. For
  6880. example, if that location is `/etc/rc.d/init.d', use these commands
  6881. before installing the RPM to create `/etc/init.d' as a symbolic link
  6882. that points there:
  6883.  
  6884.      shell> cd /etc; ln -s rc.d/init.d .
  6885.  
  6886. However, all current major Linux distributions should already support
  6887. the new directory layout that uses `/etc/init.d', because it is
  6888. required for LSB (Linux Standard Base) compliance.
  6889.  
  6890. If the RPM files that you install include `MySQL-server', the `mysqld'
  6891. server should be up and running after installation.  You should now be
  6892. able to start using MySQL.  *Note Post-installation::.
  6893.  
  6894. If something goes wrong, you can find more information in the binary
  6895. installation chapter. *Note Installing binary::.
  6896.  
  6897. Installing MySQL on Mac OS X
  6898. ----------------------------
  6899.  
  6900. Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.2
  6901. ("Jaguar") using a Mac OS X binary package in `PKG' format instead of
  6902. the binary tarball distribution. Please note that older versions of Mac
  6903. OS X (for example, 10.1.x) are not supported by this package.
  6904.  
  6905. The package is located inside a disk image (`.dmg') file, that you
  6906. first need to mount by double-clicking its icon in the Finder. It should
  6907. then mount the image and display its contents.
  6908.  
  6909. *NOTE*: Before proceeding with the installation, be sure to shut down
  6910. all running MySQL server instances by either using the MySQL Manager
  6911. Application (on Mac OS X Server) or via `mysqladmin shutdown' on the
  6912. command line.
  6913.  
  6914. To actually install the MySQL PKG file, double click on the package
  6915. icon. This launches the Mac OS X Package Installer, which will guide
  6916. you through the installation of MySQL.
  6917.  
  6918. Due to a bug in the Mac OS X package installer, you may sometimes see
  6919. the error message `You cannot install this software on this disk.
  6920. (null)' in the destination disk selection dialogue. If this error
  6921. occurs, simply click the `Go Back' button once to return to the
  6922. previous screen. Then click `Continue' to advance to the destination
  6923. disk selection again, and you should be able to choose the destination
  6924. disk correctly. We have reported this bug to Apple and they are
  6925. investigating this problem.
  6926.  
  6927. The Mac OS X PKG of MySQL will install itself into
  6928. `/usr/local/mysql-<version>' and will also install a symbolic link
  6929. `/usr/local/mysql', pointing to the new location. If a directory named
  6930. `/usr/local/mysql' already exists, it will be renamed to
  6931. `/usr/local/mysql.bak' first. Additionally, it will install the grant
  6932. tables in the `mysql' database by executing `mysql_install_db' after
  6933. the installation.
  6934.  
  6935. The installation layout is similar to the one of the binary
  6936. distribution; all MySQL binaries are located in the directory
  6937. `/usr/local/mysql/bin'.  The MySQL socket file is created as
  6938. `/tmp/mysql.sock' by default.  *Note Installation layouts::.
  6939.  
  6940. MySQL installation requires a Mac OS X user account named `mysql' (a
  6941. user account with this name should exist by default on Mac OS X 10.2
  6942. and up).
  6943.  
  6944. If you are running Mac OS X Server, you already have a version of MySQL
  6945. installed.  The versions of MySQL that ship with Mac OS X Server
  6946. versions are shown in the following table:
  6947.  
  6948. *Mac OS X Server       *MySQL Version*
  6949. Version*               
  6950. 10.2-10.2.2            3.23.51
  6951. 10.2.3-10.2.6          3.23.53
  6952. 10.3                   4.0.14
  6953. 10.3.2                 4.0.16
  6954.  
  6955. This manual section covers the installation of the official MySQL Mac
  6956. OS X PKG only.  Make sure to read Apple's help about installing MySQL
  6957. (Run the "Help View" application, select "Mac OS X Server" help, and do
  6958. a search for "MySQL" and read the item entitled "Installing MySQL").
  6959.  
  6960. Especially note that for pre-installed versions of MySQL on Mac OS X
  6961. Server, you should start `mysqld' with `safe_mysqld' instead of
  6962. `mysqld_safe' if the MySQL is older than version 4.0.
  6963.  
  6964. If you previously used Marc Liyanage's MySQL packages for Mac OS X from
  6965. `http://www.entropy.ch', you can simply follow the update instructions
  6966. for packages using the binary installation layout as given on his pages.
  6967.  
  6968. If you are upgrading from Marc's 3.23.xx versions or from the Mac OS X
  6969. Server version of MySQL to the official MySQL PKG, you also need to
  6970. convert the existing MySQL privilege tables to the current format,
  6971. because some new security privileges have been added.  *Note
  6972. Upgrading-grant-tables::.
  6973.  
  6974. If you would like to automatically start up MySQL during system bootup,
  6975. you also need to install the MySQL Startup Item. Starting with MySQL
  6976. 4.0.15, it is part of the Mac OS X installation disk images as a
  6977. separate installation package. Simply double-click the
  6978. `MySQLStartupItem.pkg' icon and follow the instructions to install it.
  6979.  
  6980. Note that the Startup Item need be installed only once! There is no
  6981. need to install it each time you upgrade the MySQL package later.
  6982.  
  6983. The Startup Item will be installed into `/Library/StartupItems/MySQL'.
  6984. It adds a variable `MYSQLCOM=-YES-' to the system configuration file
  6985. `/etc/hostconfig'. If you would like to disable the automatic startup
  6986. of MySQL, simply change this variable to `MYSQLCOM=-NO-'.
  6987.  
  6988. On Mac OS X Server, the default MySQL installation uses the variable
  6989. `MYSQL' in `/etc/hostconfig'.  The MySQL AB Startup Item installer
  6990. disables this variable by setting it to `MYSQL=-NO-'. This avoids boot
  6991. time conflicts with the `MYSQLCOM' variable used by the MySQL AB
  6992. Startup Item.  However, it does not shut down an already running MySQL
  6993. server.
  6994.  
  6995. After the installation, you can start up MySQL by running the following
  6996. commands in a terminal window. Please note that you must have
  6997. administrator privileges to perform this task.
  6998.  
  6999. If you have installed the Startup Item:
  7000.  
  7001.      shell> sudo /Library/StartupItems/MySQL/MySQL start
  7002.      (Enter your password, if necessary)
  7003.      (Press Control-D or enter "exit" to exit the shell)
  7004.  
  7005. If you don't use the Startup Item, enter the following command sequence:
  7006.  
  7007.      shell> cd /usr/local/mysql
  7008.      shell> sudo ./bin/mysqld_safe
  7009.      (Enter your password, if necessary)
  7010.      (Press Control-Z)
  7011.      shell> bg
  7012.      (Press Control-D or enter "exit" to exit the shell)
  7013.  
  7014. You should now be able to connect to the MySQL server, for example, by
  7015. running `/usr/local/mysql/bin/mysql'.
  7016.  
  7017. If you are installing MySQL for the first time, *please remember to set
  7018. a password for the MySQL `root' user!*
  7019.  
  7020. This is done with the following two commands:
  7021.  
  7022.      /usr/local/mysql/bin/mysqladmin -u root password <password>
  7023.      /usr/local/mysql/bin/mysqladmin -u root -h `hostname` password <password>
  7024.  
  7025. Please make sure that the `hostname' command in the second line is
  7026. enclosed by *backtick* characters (``'), so the shell can replace it
  7027. with the output of the command (which is the hostname of your system)!
  7028.  
  7029. You might want to also add aliases to your shell's resource file to
  7030. access `mysql' and `mysqladmin' from the command line. The syntax for
  7031. `tcsh' is:
  7032.  
  7033.      alias mysql /usr/local/mysql/bin/mysql
  7034.      alias mysqladmin /usr/local/mysql/bin/mysqladmin
  7035.  
  7036. For `bash', use:
  7037.  
  7038.      alias mysql=/usr/local/mysql/bin/mysql
  7039.      alias mysqladmin=/usr/local/mysql/bin/mysqladmin
  7040.  
  7041. Even better, add `/usr/local/mysql/bin' to your `PATH' environment
  7042. variable. For example, add the following line to your `$HOME/.tcshrc'
  7043. file if your shell is `tcsh':
  7044.  
  7045.      setenv PATH ${PATH}:/usr/local/mysql/bin
  7046.  
  7047. If no `.tcshrc' file exists in your home directory, create it with a
  7048. text editor.
  7049.  
  7050. If you are upgrading an existing installation, please note that
  7051. installing a new MySQL PKG does not remove the directory of an older
  7052. installation. Unfortunately, the Mac OS X Installer does not yet offer
  7053. the functionality required to properly upgrade previously installed
  7054. packages.
  7055.  
  7056. To use your existing databases with the new installation, you'll need
  7057. to copy the contents of the old data directory to the new data
  7058. directory. Make sure neither the old server nor the new one is running
  7059. when you do this.  After you have copied over the MySQL database files
  7060. from the previous installation and have successfully started the new
  7061. server, you should consider removing the old installation files to save
  7062. disk space.  Additionally, you should also remove older versions of the
  7063. Package Receipt directories located in
  7064. `/Library/Receipts/mysql-<version>.pkg'.
  7065.  
  7066. Installing MySQL on NetWare
  7067. ---------------------------
  7068.  
  7069. Porting `MySQL' to `NetWare' was an effort spearheaded by `Novell'.
  7070. Novell customers will be pleased to note that NetWare 6.5 will ship
  7071. with bundled MySQL binaries, complete with an automatic commercial use
  7072. license for all servers running that version of NetWare.
  7073.  
  7074. As of version 4.0.11, the MySQL server is available for Novell NetWare
  7075. in binary package form.  MySQL for NetWare is compiled using a
  7076. combination of `Metrowerks CodeWarrior for NetWare' and special
  7077. cross-compilation versions of the GNU autotools.
  7078.  
  7079. In order to host MySQL, the NetWare server must meet these requirements:
  7080.  
  7081.    * NetWare version 6.5, or NetWare 6.0 with Support Pack 3 installed
  7082.      (You can obtain this at
  7083.      `http://support.novell.com/filefinder/13659/index.html').  The
  7084.      system must meet Novell's minimum requirements to run the
  7085.      respective version of NetWare.
  7086.  
  7087.    * MySQL data, as well as the binaries themselves, must be installed
  7088.      on an NSS volume; traditional volumes are not supported.
  7089.  
  7090. The binary package for NetWare can be obtained at
  7091. `http://www.mysql.com/downloads/'.
  7092.  
  7093. To install MySQL for NetWare, use the following procedure:
  7094.  
  7095.   1. If you are upgrading from a prior installation, stop the MySQL
  7096.      server.  This is done from the server console, using the following
  7097.      command:
  7098.  
  7099.           SERVER:  mysqladmin -u root shutdown
  7100.  
  7101.   2. Log on to the target server from a client machine with access to
  7102.      the location where you will install MySQL.
  7103.  
  7104.   3. Extract the binary package zip file onto the server. Be sure to
  7105.      allow the paths in the zip file to be used. It is safe to simply
  7106.      extract the file to `SYS:\'.
  7107.  
  7108.      If you are upgrading from a prior installation, you may need to
  7109.      copy the data directory (for example, `SYS:MYSQL\DATA') now, as
  7110.      well as `my.cnf' if you have customized it. You can then delete
  7111.      the old copy of MySQL.
  7112.  
  7113.   4. You may wish to rename the directory to something more consistent
  7114.      and easy to use. We recommend using `SYS:MYSQL'; examples in the
  7115.      manual will use this to refer to the installation directory in
  7116.      general.
  7117.  
  7118.   5. At the server console, add a search path for the directory
  7119.      containing the MySQL NLMs. For example:
  7120.  
  7121.           SERVER:  SEARCH ADD SYS:MYSQL\BIN
  7122.  
  7123.   6. Install the initial database, if needed, by executing
  7124.      `mysql_install_db' at the server console.
  7125.  
  7126.   7. Start the MySQL server using `mysqld_safe' at the server console.
  7127.  
  7128.   8. To finish the installation, you should also add the following
  7129.      commands to `autoexec.ncf'. For example, if your MySQL
  7130.      installation is in `SYS:MYSQL' and you want MySQL to start
  7131.      automatically, you could add these lines:
  7132.  
  7133.           #Starts the MySQL 4.0.x database server
  7134.           SEARCH ADD SYS:MYSQL\BIN
  7135.           MYSQLD_SAFE
  7136.  
  7137.      If you are running MySQL on NetWare 6.0, we strongly suggest that
  7138.      you use the `--skip-external-locking' option on the command line:
  7139.  
  7140.           #Starts the MySQL 4.0.x database server
  7141.           SEARCH ADD SYS:MYSQL\BIN
  7142.           MYSQLD_SAFE --skip-external-locking
  7143.  
  7144.      It will also be neccesary to use `CHECK TABLE' and `REPAIR TABLE'
  7145.      instead of `myisamchk', because `myisamchk' makes use of external
  7146.      locking.  External locking is known to have problems on NetWare
  7147.      6.0; the problem has been eliminated in NetWare 6.5.
  7148.  
  7149.  
  7150. If there was an existing installation of MySQL on the server, be sure
  7151. to check for existing MySQL startup commands in `autoexec.ncf', and
  7152. edit or delete them as necessary.
  7153.  
  7154. Installing MySQL on HP-UX
  7155. -------------------------
  7156.  
  7157. Binary distributions of MySQL for HP-UX are distributed as HP depot
  7158. files or as `tar' files.  To use the depot file you must be running at
  7159. least HP-UX 10.x to have access to HP's software depot tools.  To
  7160. install the HP-UX `tar.gz' distribution, you must have a copy of GNU
  7161. `tar'.
  7162.  
  7163. The HP version of MySQL was compiled on an HP 9000/8xx server under
  7164. HP-UX 10.20, and uses MIT-pthreads.  It is known to work well under
  7165. this configuration.  MySQL Version 3.22.26 and newer can also be built
  7166. with HP's native thread package.
  7167.  
  7168. Other configurations that may work:
  7169.  
  7170.    * HP 9000/7xx running HP-UX 10.20+
  7171.  
  7172.    * HP 9000/8xx running HP-UX 10.30
  7173.  
  7174. The following configurations almost definitely won't work:
  7175.  
  7176.    * HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
  7177.  
  7178.    * HP 9000/7xx or 8xx running HP-UX 9.x
  7179.  
  7180. To install the distribution, use one of the commands here, where
  7181. `/path/to/depot' is the full pathname of the depot file:
  7182.  
  7183.    * To install everything, including the server, client and
  7184.      development tools:
  7185.  
  7186.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
  7187.  
  7188.    * To install only the server:
  7189.  
  7190.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
  7191.  
  7192.    * To install only the client package:
  7193.  
  7194.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
  7195.  
  7196.    * To install only the development tools:
  7197.  
  7198.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
  7199.  
  7200. The depot places binaries and libraries in `/opt/mysql' and data in
  7201. `/var/opt/mysql'. The depot also creates the appropriate entries in
  7202. `/etc/init.d' and `/etc/rc2.d' to start the server automatically at
  7203. boot time.  Obviously, this entails being `root' to install.
  7204.  
  7205. Installing MySQL on Other Unix-like Systems
  7206. -------------------------------------------
  7207.  
  7208. This section covers the installation of MySQL binary distributions that
  7209. are provided for various platforms in the form of `tar' files (files
  7210. with a `.tar.gz' extension).  See *Note MySQL binaries:: for a detailed
  7211. list.
  7212.  
  7213. In addition to these generic packages, we also offer binaries in
  7214. platform-specific package formats for selected platforms.  See *Note
  7215. Quick Standard Installation:: for more information on how to install
  7216. these.
  7217.  
  7218. You need the following tools to install a MySQL `tar' file binary
  7219. distribution:
  7220.  
  7221.    * GNU `gunzip' to uncompress the distribution.
  7222.  
  7223.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  7224.      to work. Some operating systems come with a pre-installed version
  7225.      of `tar' that is known to have problems.  For example, Sun `tar'
  7226.      and Mac OS X `tar' are known to have problems with long filenames.
  7227.      In such cases, you should install GNU `tar' first.  On Mac OS X,
  7228.      you can use the pre-installed `gnutar' program.
  7229.  
  7230. If you run into problems, *please always use `mysqlbug'* when posting
  7231. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  7232. `mysqlbug' gathers system information that will help others solve your
  7233. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  7234. a solution to your problem.  You will find `mysqlbug' in the `bin'
  7235. directory after you unpack the distribution.  *Note Bug reports::.
  7236.  
  7237. The basic commands you must execute to install and use a MySQL binary
  7238. distribution are:
  7239.  
  7240.      shell> groupadd mysql
  7241.      shell> useradd -g mysql mysql
  7242.      shell> cd /usr/local
  7243.      shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  7244.      shell> ln -s full-path-to-mysql-VERSION-OS mysql
  7245.      shell> cd mysql
  7246.      shell> scripts/mysql_install_db
  7247.      shell> chown -R root  .
  7248.      shell> chown -R mysql data
  7249.      shell> chgrp -R mysql .
  7250.      shell> bin/mysqld_safe --user=mysql &
  7251.  
  7252. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7253. `bin/mysqld_safe' in the final command.
  7254.  
  7255. A more detailed description follows.
  7256.  
  7257. To install a binary distribution, follow these steps, then proceed to
  7258. *Note Post-installation::, for post-installation setup and testing:
  7259.  
  7260.   1. Add a user and group for `mysqld' to run as:
  7261.  
  7262.           shell> groupadd mysql
  7263.           shell> useradd -g mysql mysql
  7264.  
  7265.      These commands add the `mysql' group and the `mysql' user.  The
  7266.      syntax for `useradd' and `groupadd' may differ slightly on
  7267.      different versions of Unix.  They may also be called `adduser' and
  7268.      `addgroup'.  You may wish to call the user and group something
  7269.      else instead of `mysql'.
  7270.  
  7271.   2. Pick the directory under which you want to unpack the
  7272.      distribution, and move into it. In the following example, we
  7273.      unpack the distribution under `/usr/local' (The following
  7274.      instructions, therefore, assume you have permission to create
  7275.      files and directories in `/usr/local'.  If that directory is
  7276.      protected, you will need to perform the installation as `root'.)
  7277.  
  7278.   3. Obtain a distribution file from one of the sites listed in *Note
  7279.      Getting MySQL: Getting MySQL.
  7280.  
  7281.      MySQL `tar' file binary distributions have names like
  7282.      `mysql-VERSION-OS.tar.gz', where `VERSION' is a number (for
  7283.      example, `4.0.17'), and `OS' indicates the type of operating
  7284.      system for which the distribution is intended (for example,
  7285.      `pc-linux-gnu-i586').  For a given release, binary distributions
  7286.      for all platforms are built from the same MySQL source
  7287.      distribution.
  7288.  
  7289.   4. Change into the intended installation directory:
  7290.  
  7291.           shell> cd /usr/local
  7292.  
  7293.   5. Unpack the distribution, which will create the installation
  7294.      directory.  Then create a symbolic link to that directory:
  7295.  
  7296.           shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  7297.           shell> ln -s full-path-to-mysql-VERSION-OS mysql
  7298.  
  7299.      The `tar' command creates a directory named `mysql-VERSION-OS'.
  7300.      The `ln' command makes a symbolic link to that directory.  This
  7301.      lets you refer more easily to the installation directory as
  7302.      `/usr/local/mysql'.
  7303.  
  7304.      With GNU `tar', no separate invocation of `gunzip' is necessary.
  7305.      You can replace the first line with the following alternative
  7306.      command to uncompress and extract the distribution:
  7307.  
  7308.           shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
  7309.  
  7310.   6. Change into the installation directory:
  7311.  
  7312.           shell> cd mysql
  7313.  
  7314.      You will find several files and subdirectories in the `mysql'
  7315.      directory.  The most important for installation purposes are the
  7316.      `bin' and `scripts' subdirectories.
  7317.  
  7318.     `bin'
  7319.           This directory contains client programs and the server.  You
  7320.           should add the full pathname of this directory to your `PATH'
  7321.           environment variable so that your shell finds the MySQL
  7322.           programs properly. *Note Environment variables::.
  7323.  
  7324.     `scripts'
  7325.           This directory contains the `mysql_install_db' script used to
  7326.           initialize the `mysql' database containing the grant tables
  7327.           that store the server access permissions.
  7328.  
  7329.   7. If you haven't installed MySQL before, you must create the MySQL
  7330.      grant tables:
  7331.  
  7332.           shell> scripts/mysql_install_db
  7333.  
  7334.      Note that for MySQL versions older than Version 3.22.10,
  7335.      `mysql_install_db' left the server running after creating the grant
  7336.      tables.  This is no longer true; you will need to restart the
  7337.      server after performing the remaining steps in this procedure.
  7338.  
  7339.   8. Change ownership of program binaries to `root' and ownership of
  7340.      the data directory to the user that you will run `mysqld' as.
  7341.      Assuming that you are located in the installation directory
  7342.      (`/usr/local/mysql'), the commands look like this:
  7343.  
  7344.           shell> chown -R root  .
  7345.           shell> chown -R mysql data
  7346.           shell> chgrp -R mysql .
  7347.  
  7348.      The first command changes the `owner' attribute of the files to the
  7349.      `root' user. The second changes the `owner' attribute of the data
  7350.      directory to the `mysql' user. The third changes the `group'
  7351.      attribute to the `mysql' group.
  7352.  
  7353.   9. If you would like MySQL to start automatically when you boot your
  7354.      machine, you can copy `support-files/mysql.server' to the location
  7355.      where your system has its startup files.  More information can be
  7356.      found in the `support-files/mysql.server' script itself and in
  7357.      *Note Automatic start::.
  7358.  
  7359.  10. You can set up new accounts using the `bin/mysql_setpermission'
  7360.      script if you install the `DBI' and `DBD::mysql' Perl modules.
  7361.      For instructions, see *Note Perl support::.
  7362.  
  7363.  11. If you would like to use `mysqlaccess' and have the MySQL
  7364.      distribution in some non-standard place, you must change the
  7365.      location where `mysqlaccess' expects to find the `mysql' client.
  7366.      Edit the `bin/mysqlaccess' script at approximately line 18.
  7367.      Search for a line that looks like this:
  7368.  
  7369.           $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
  7370.  
  7371.      Change the path to reflect the location where `mysql' actually is
  7372.      stored on your system.  If you do not do this, you will get a
  7373.      `Broken pipe' error when you run `mysqlaccess'.
  7374.  
  7375.  
  7376. After everything has been unpacked and installed, you should test your
  7377. distribution.
  7378.  
  7379. You can start the MySQL server with the following command:
  7380.  
  7381.      shell> bin/mysqld_safe --user=mysql &
  7382.  
  7383. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7384. `bin/mysqld_safe' in the command.
  7385.  
  7386. Now proceed to *Note `mysqld_safe': mysqld_safe, and *Note
  7387. Post-installation::.
  7388.  
  7389. MySQL Installation Using a Source Distribution
  7390. ==============================================
  7391.  
  7392. Before you proceed with the source installation, check first to see
  7393. whether our binary is available for your platform and whether it will
  7394. work for you. We put a lot of effort into making sure that our binaries
  7395. are built with the best possible options.
  7396.  
  7397. You need the following tools to build and install MySQL from source:
  7398.  
  7399.    * GNU `gunzip' to uncompress the distribution.
  7400.  
  7401.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  7402.      to work. Some `tar' implementations that come pre-installed with
  7403.      the operating system (for example, Sun `tar') is known to have
  7404.      problems with long file names). In that case, you should install
  7405.      GNU `tar' first.
  7406.  
  7407.    * A working ANSI C++ compiler.  `gcc' 2.95.2 or later, `egcs' 1.0.2
  7408.      or later or `egcs 2.91.66', SGI C++, and SunPro C++ are some of the
  7409.      compilers that are known to work.  `libg++' is not needed when
  7410.      using `gcc'.  `gcc' 2.7.x has a bug that makes it impossible to
  7411.      compile some perfectly legal C++ files, such as `sql/sql_base.cc'.
  7412.      If you only have `gcc' 2.7.x, you must upgrade your `gcc' to be
  7413.      able to compile MySQL. `gcc' 2.8.1 is also known to have problems
  7414.      on some platforms, so it should be avoided if a new compiler
  7415.      exists for the platform.
  7416.  
  7417.      `gcc' 2.95.2 or later is recommended when compiling MySQL Version
  7418.      3.23.x.
  7419.  
  7420.    * A good `make' program.  GNU `make' is always recommended and is
  7421.      sometimes required.  If you have problems, we recommend trying GNU
  7422.      `make' 3.75 or newer.
  7423.  
  7424. If you are using a recent version of `gcc', recent enough to understand
  7425. the `-fno-exceptions' option, it is *very important* that you use it.
  7426. Otherwise, you may compile a binary that crashes randomly. We also
  7427. recommend that you use `-felide-constructors' and `-fno-rtti' along
  7428. with `-fno-exceptions'. When in doubt, do the following:
  7429.  
  7430.  
  7431.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
  7432.             -fno-exceptions -fno-rtti" ./configure \
  7433.             --prefix=/usr/local/mysql --enable-assembler \
  7434.             --with-mysqld-ldflags=-all-static
  7435.  
  7436. On most systems this will give you a fast and stable binary.
  7437.  
  7438. If you run into problems, *please always use `mysqlbug'* when posting
  7439. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  7440. `mysqlbug' gathers system information that will help others solve your
  7441. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  7442. a solution to your problem.  You will find `mysqlbug' in the `scripts'
  7443. directory after you unpack the distribution.  *Note Bug reports::.
  7444.  
  7445. Quick Source Installation Overview
  7446. ----------------------------------
  7447.  
  7448. The basic commands you must execute to install a MySQL source
  7449. distribution are:
  7450.  
  7451.      shell> groupadd mysql
  7452.      shell> useradd -g mysql mysql
  7453.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  7454.      shell> cd mysql-VERSION
  7455.      shell> ./configure --prefix=/usr/local/mysql
  7456.      shell> make
  7457.      shell> make install
  7458.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  7459.      shell> cd /usr/local/mysql
  7460.      shell> bin/mysql_install_db
  7461.      shell> chown -R root  .
  7462.      shell> chown -R mysql var
  7463.      shell> chgrp -R mysql .
  7464.      shell> bin/mysqld_safe --user=mysql &
  7465.  
  7466. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7467. `bin/mysqld_safe' in the final command.
  7468.  
  7469. If you start from a source RPM, do the following:
  7470.  
  7471.      shell> rpm --rebuild --clean MySQL-VERSION.src.rpm
  7472.  
  7473. This will make a binary RPM that you can install.
  7474.  
  7475. A more detailed description follows.
  7476.  
  7477. To install a source distribution, follow these steps, then proceed to
  7478. *Note Post-installation::, for post-installation initialization and
  7479. testing:
  7480.  
  7481.   1. Add a user and group for `mysqld' to run as:
  7482.  
  7483.           shell> groupadd mysql
  7484.           shell> useradd -g mysql mysql
  7485.  
  7486.      These commands add the `mysql' group and the `mysql' user.  The
  7487.      syntax for `useradd' and `groupadd' may differ slightly on
  7488.      different versions of Unix.  They may also be called `adduser' and
  7489.      `addgroup'.  You may wish to call the user and group something
  7490.      else instead of `mysql'.
  7491.  
  7492.   2. Pick the directory under which you want to unpack the
  7493.      distribution, and move into it.
  7494.  
  7495.   3. Obtain a distribution file from one of the sites listed in *Note
  7496.      Getting MySQL: Getting MySQL.  MySQL source distributions are
  7497.      provided as compressed `tar' archives and have names like
  7498.      `mysql-VERSION.tar.gz', where `VERSION' is a number like
  7499.      `4.0.18'.
  7500.  
  7501.   4. Unpack the distribution into the current directory:
  7502.           shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
  7503.  
  7504.      This command creates a directory named `mysql-VERSION'.
  7505.  
  7506.      With GNU `tar', no separate invocation of `gunzip' is necessary.
  7507.      You can use the following alternative command to uncompress and
  7508.      extract the distribution:
  7509.  
  7510.           shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
  7511.  
  7512.   5. Change into the top-level directory of the unpacked distribution:
  7513.  
  7514.           shell> cd mysql-VERSION
  7515.  
  7516.      Note that currently you must configure and build MySQL from this
  7517.      top-level directory.  You cannot build it in a different directory.
  7518.  
  7519.   6. Configure the release and compile everything:
  7520.  
  7521.           shell> ./configure --prefix=/usr/local/mysql
  7522.           shell> make
  7523.  
  7524.      When you run `configure', you might want to specify some options.
  7525.      Run `./configure --help' for a list of options.  *Note `configure'
  7526.      options: configure options, discusses some of the more useful
  7527.      options.
  7528.  
  7529.      If `configure' fails and you are going to send mail to a MySQL
  7530.      mailing list to ask for assistance, please include any lines from
  7531.      `config.log' that you think can help solve the problem.  Also
  7532.      include the last couple of lines of output from `configure'.  Post
  7533.      the bug report using the `mysqlbug' script.  *Note Bug reports::.
  7534.  
  7535.      If the compile fails, see *Note Compilation problems::, for help
  7536.      with a number of common problems.
  7537.  
  7538.   7. Install the distribution:
  7539.  
  7540.           shell> make install
  7541.  
  7542.      If you want to set up an option file, use one of those present in
  7543.      the `support-files' directory as template. For example:
  7544.  
  7545.           shell> cp support-files/my-medium.cnf /etc/my.cnf
  7546.  
  7547.      You might need to run these commands as `root'.
  7548.  
  7549.      If you want to configure support for `InnoDB' tables, you should
  7550.      edit the `/etc/my.cnf' file, remove the `#' character before the
  7551.      option lines that start with `innodb_...', and modify the option
  7552.      values to be what you want.  *Note Option files::, and *Note
  7553.      InnoDB start::.
  7554.  
  7555.   8. Change location into the installation directory:
  7556.  
  7557.           shell> cd /usr/local/mysql
  7558.  
  7559.   9. If you haven't installed MySQL before, you must create the MySQL
  7560.      grant tables:
  7561.  
  7562.           shell> bin/mysql_install_db
  7563.  
  7564.      Note that for MySQL versions older than Version 3.22.10,
  7565.      `mysql_install_db' left the server running after creating the grant
  7566.      tables.  This is no longer true; you will need to restart the
  7567.      server after performing the remaining steps in this procedure.
  7568.  
  7569.  10. Change ownership of binaries to `root' and ownership of the data
  7570.      directory to the user that you will run `mysqld' as.  Assuming
  7571.      that you are located in the installation directory
  7572.      (`/usr/local/mysql'), the commands look like this:
  7573.  
  7574.           shell> chown -R root  .
  7575.           shell> chown -R mysql var
  7576.           shell> chgrp -R mysql .
  7577.  
  7578.      The first command changes the `owner' attribute of the files to the
  7579.      `root' user. The second changes the `owner' attribute of the data
  7580.      directory to the `mysql' user. The third changes the `group'
  7581.      attribute to the `mysql' group.
  7582.  
  7583.  11. If you would like MySQL to start automatically when you boot your
  7584.      machine, you can copy `support-files/mysql.server' to the location
  7585.      where your system has its startup files.  More information can be
  7586.      found in the `support-files/mysql.server' script itself and in
  7587.      *Note Automatic start::.
  7588.  
  7589.  12. You can set up new accounts using the `bin/mysql_setpermission'
  7590.      script if you install the `DBI' and `DBD::mysql' Perl modules.
  7591.      For instructions, see *Note Perl support::.
  7592.  
  7593.  
  7594. After everything has been installed, you should initialize and test your
  7595. distribution using this command:
  7596.  
  7597.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  7598.  
  7599. For versions of MySQL older than 4.0, substitute `bin/safe_mysqld' for
  7600. `bin/mysqld_safe' in the command.
  7601.  
  7602. If that command fails immediately and prints `mysqld ended', you can
  7603. find some information in the file `mysql-data-directory/'hostname'.err'.
  7604. The likely reason is that you already have another `mysqld' server
  7605. running.  *Note Multiple servers::.
  7606.  
  7607. Now proceed to *Note Post-installation::.
  7608.  
  7609. Typical `configure' Options
  7610. ---------------------------
  7611.  
  7612. The `configure' script gives you a great deal of control over how you
  7613. configure a MySQL source distribution.  Typically you do this using
  7614. options on the `configure' command-line.  You can also affect
  7615. `configure' using certain environment variables.  *Note Environment
  7616. variables::.  For a list of options supported by `configure', run this
  7617. command:
  7618.  
  7619.      shell> ./configure --help
  7620.  
  7621. Some of the more commonly used `configure' options are described here:
  7622.  
  7623.    * To compile just the MySQL client libraries and client programs and
  7624.      not the server, use the `--without-server' option:
  7625.  
  7626.           shell> ./configure --without-server
  7627.  
  7628.      If you don't have a C++ compiler, `mysql' will not compile (it is
  7629.      the one client program that requires C++).  In this case, you can
  7630.      remove the code in `configure' that tests for the C++ compiler and
  7631.      then run `./configure' with the `--without-server' option. The
  7632.      compile step will still try to build `mysql', but you can ignore
  7633.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  7634.      tell it to continue with the rest of the build even if errors
  7635.      occur.)
  7636.  
  7637.    * If you want to get an embedded MySQL library (`libmysqld.a') you
  7638.      should use the `--with-embedded-server' option.
  7639.  
  7640.    * If you don't want your log files and database directories located
  7641.      under `/usr/local/var', use a `configure' command, something like
  7642.      one of these:
  7643.  
  7644.           shell> ./configure --prefix=/usr/local/mysql
  7645.           shell> ./configure --prefix=/usr/local \
  7646.                      --localstatedir=/usr/local/mysql/data
  7647.  
  7648.      The first command changes the installation prefix so that
  7649.      everything is installed under `/usr/local/mysql' rather than the
  7650.      default of `/usr/local'.  The second command preserves the default
  7651.      installation prefix, but overrides the default location for
  7652.      database directories (normally `/usr/local/var') and changes it to
  7653.      `/usr/local/mysql/data'.  After you have compiled MySQL, you can
  7654.      change these options with option files. *Note Option files::.
  7655.  
  7656.    * If you are using Unix and you want the MySQL socket located
  7657.      somewhere other than the default location (normally in the
  7658.      directory `/tmp' or `/var/run') use a `configure' command like
  7659.      this:
  7660.  
  7661.           shell> ./configure \
  7662.                      --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  7663.  
  7664.      Note that the given file must be an absolute pathname.  You can
  7665.      also later change the location of `mysql.sock' by using a MySQL
  7666.      option file. *Note Problems with `mysql.sock': Problems with
  7667.      mysql.sock.
  7668.  
  7669.    * If you want to compile statically linked programs (for example, to
  7670.      make a binary distribution, to get more speed, or to work around
  7671.      problems with some Red Hat Linux distributions), run `configure'
  7672.      like this:
  7673.  
  7674.           shell> ./configure --with-client-ldflags=-all-static \
  7675.                      --with-mysqld-ldflags=-all-static
  7676.  
  7677.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  7678.      installed, you can tell `configure' to use `gcc' as your C++
  7679.      compiler:
  7680.  
  7681.           shell> CC=gcc CXX=gcc ./configure
  7682.  
  7683.      When you use `gcc' as your C++ compiler, it will not attempt to
  7684.      link in `libg++' or `libstdc++'.  This may be a good idea to do
  7685.      even if you have the above libraries installed, as some versions
  7686.      of these libraries have caused strange problems for MySQL users in
  7687.      the past.
  7688.  
  7689.      The following list indicates some compilers and environment
  7690.      variable settings that are commonly used with each one.
  7691.  
  7692.  
  7693.  
  7694.     `gcc' 2.7.2:
  7695.           `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"'
  7696.  
  7697.     `egcs' 1.0.3a:
  7698.           `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors \
  7699.           -fno-exceptions -fno-rtti"'
  7700.  
  7701.     `gcc' 2.95.2:
  7702.           `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  7703.           \ -felide-constructors -fno-exceptions -fno-rtti"'
  7704.  
  7705.     `pgcc' 2.90.29 or newer:
  7706.           `CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
  7707.           CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \
  7708.           -felide-constructors -fno-exceptions -fno-rtti"'
  7709.  
  7710.      In most cases you can get a reasonably optimal MySQL binary by
  7711.      using the options from the preceding list and adding the following
  7712.      options to the `configure' line:
  7713.  
  7714.           --prefix=/usr/local/mysql --enable-assembler \
  7715.           --with-mysqld-ldflags=-all-static
  7716.  
  7717.      The full `configure' line would, in other words, be something like
  7718.      the following for all recent `gcc' versions:
  7719.  
  7720.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  7721.           -felide-constructors -fno-exceptions -fno-rtti" ./configure \
  7722.           --prefix=/usr/local/mysql --enable-assembler \
  7723.           --with-mysqld-ldflags=-all-static
  7724.  
  7725.      The binaries we provide on the MySQL web site at
  7726.      `http://www.mysql.com/' are all compiled with full optimization and
  7727.      should be perfect for most users.  *Note MySQL binaries::.  There
  7728.      are some configuration setings you can tweak to make an even
  7729.      faster binary, but this is only for advanced users.  *Note Compile
  7730.      and link options::.
  7731.  
  7732.      If the build fails and produces errors about your compiler or
  7733.      linker not being able to create the shared library
  7734.      `libmysqlclient.so.#' (`#' is a version number), you can work
  7735.      around this problem by giving the `--disable-shared' option to
  7736.      `configure'.  In this case, `configure' will not build a shared
  7737.      `libmysqlclient.so.#' library.
  7738.  
  7739.    * You can configure MySQL not to use `DEFAULT' column values for
  7740.      non-`NULL' columns (that is, columns that are not allowed to be
  7741.      `NULL'). *Note constraint NOT NULL::.
  7742.  
  7743.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  7744.  
  7745.      The effect of this flag is to cause any `INSERT' statement to fail
  7746.      unless it provides explicit values for all columns that require a
  7747.      non-`NULL' value.
  7748.  
  7749.    * By default, MySQL uses the ISO-8859-1 (Latin1) character set. To
  7750.      change the default set, use the `--with-charset' option:
  7751.           shell> ./configure --with-charset=CHARSET
  7752.      `CHARSET' may be one of `big5', `cp1251', `cp1257', `czech',
  7753.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  7754.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  7755.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  7756.      `win1251ukr'.  *Note Character sets::.
  7757.  
  7758.      If you want to convert characters between the server and the
  7759.      client, you should take a look at the `SET CHARACTER SET' command.
  7760.      *Note `SET': SET OPTION.
  7761.  
  7762.      *Warning:* If you change character sets after having created any
  7763.      tables, you will have to run `myisamchk -r -q
  7764.      --set-character-set=charset' on every table. Your indexes may be
  7765.      sorted incorrectly otherwise.  (This can happen if you install
  7766.      MySQL, create some tables, then reconfigure MySQL to use a
  7767.      different character set and reinstall it.)
  7768.  
  7769.      With the `configure' option `--with-extra-charsets=LIST', you can
  7770.      define which additional character sets should be compiled into the
  7771.      server.  `LIST' is either a list of character sets separated with
  7772.      spaces, `complex' to include all characters that can't be
  7773.      dynamically loaded, or `all' to include all character sets into
  7774.      the binaries.
  7775.  
  7776.    * To configure MySQL with debugging code, use the `--with-debug'
  7777.      option:
  7778.           shell> ./configure --with-debug
  7779.      This causes a safe memory allocator to be included that can find
  7780.      some errors and that provides output about what is happening.
  7781.      *Note Debugging server::.
  7782.  
  7783.    * If your client programs are using threads, you also must compile a
  7784.      thread-safe version of the MySQL client library with the
  7785.      `--enable-thread-safe-client' configure options. This will create a
  7786.      `libmysqlclient_r' library with which you should link your threaded
  7787.      applications.  *Note Threaded clients::.
  7788.  
  7789.    * Options that pertain to particular systems can be found in the
  7790.      system-specific section of this manual.  *Note Operating System
  7791.      Specific Notes::.
  7792.  
  7793. Installing from the Development Source Tree
  7794. -------------------------------------------
  7795.  
  7796. *Caution*: You should read this section only if you are interested in
  7797. helping us test our new code. If you just want to get MySQL up and
  7798. running on your system, you should use a standard release distribution
  7799. (either a binary or source distribution will do).
  7800.  
  7801. To obtain our most recent development source tree, use these
  7802. instructions:
  7803.  
  7804.   1. Download `BitKeeper' from
  7805.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  7806.      `Bitkeeper' 3.0 or newer to access our repository.
  7807.  
  7808.   2. Follow the instructions to install it.
  7809.  
  7810.   3. After `BitKeeper' is installed, first go to the directory you want
  7811.      to work from, and then use one of the following commands to clone
  7812.      the MySQL version branch of your choice:
  7813.  
  7814.      To clone the old 3.23 branch, use this command:
  7815.  
  7816.           shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
  7817.  
  7818.      To clone the 4.0 stable (production) branch, use this command:
  7819.  
  7820.           shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
  7821.  
  7822.      To clone the 4.1 alpha branch, use this command:
  7823.  
  7824.           shell> bk clone bk://mysql.bkbits.net/mysql-4.1 mysql-4.1
  7825.  
  7826.      To clone the 5.0 development branch, use this command:
  7827.  
  7828.           shell> bk clone bk://mysql.bkbits.net/mysql-5.0 mysql-5.0
  7829.  
  7830.      In the preceding examples the source tree will be set up in the
  7831.      `mysql-3.23/', `mysql-4.0/', `mysql-4.1/', or `mysql-5.0/'
  7832.      subdirectory of your current directory.
  7833.  
  7834.      If you are behind a firewall and can only initiate HTTP
  7835.      connections, you can also use `BitKeeper' via HTTP.
  7836.  
  7837.      If you are required to use a proxy server, set the environment
  7838.      variable `http_proxy' to point to your proxy:
  7839.  
  7840.           shell> export http_proxy="http://your.proxy.server:8080/"
  7841.  
  7842.      Now, simply replace the `bk://' with `http://' when doing a clone.
  7843.      Example:
  7844.  
  7845.           shell> bk clone http://mysql.bkbits.net/mysql-4.1 mysql-4.1
  7846.  
  7847.      The initial download of the source tree may take a while,
  7848.      depending on the speed of your connection--please be patient.
  7849.  
  7850.   4. You will need GNU `make', `autoconf' 2.53 (or newer), `automake'
  7851.      1.5, `libtool' 1.4, and `m4' to run the next set of commands. Even
  7852.      though many operating systems already come with their own
  7853.      implementation of `make', chances are high that the compilation
  7854.      will fail with strange error messages. Therefore, it is highly
  7855.      recommended that you use GNU `make' (sometimes named `gmake')
  7856.      instead.
  7857.  
  7858.      Fortunately, a large number of operating systems already ship with
  7859.      the GNU toolchain preinstalled or supply installable packages of
  7860.      these. In any case, they can also be downloaded from the following
  7861.      locations:
  7862.  
  7863.         * <http://www.gnu.org/software/autoconf/>
  7864.  
  7865.         * <http://www.gnu.org/software/automake/>
  7866.  
  7867.         * <http://www.gnu.org/software/libtool/>
  7868.  
  7869.         * <http://www.gnu.org/software/make/>
  7870.  
  7871.      If you are trying to configure MySQL 4.1 or later, you will also
  7872.      need GNU `bison' 1.75 or later.  Older versions of `bison' may
  7873.      report this error:
  7874.  
  7875.           sql_yacc.yy:#####: fatal error: maximum table size (32767) exceeded
  7876.  
  7877.      Note: The maximum table size is not actually exceeded, the error
  7878.      is caused by bugs in older versions of `bison'.
  7879.  
  7880.      Versions of MySQL before version 4.1 may also compile with other
  7881.      `yacc' implementations (for example, BSD `yacc' 91.7.30). For later
  7882.      versions, GNU `bison' is required.
  7883.  
  7884.      The following example shows the typical commands required to
  7885.      configure a source tree. The first `cd' command changes location
  7886.      into the top-level directory of the tree; replace `mysql-4.0' with
  7887.      the appropriate directory name.
  7888.  
  7889.           shell> cd mysql-4.0
  7890.           shell> bk -r edit
  7891.           shell> aclocal; autoheader; autoconf; automake
  7892.           shell> (cd innobase; aclocal; autoheader; autoconf; automake)
  7893.           shell> (cd bdb/dist; sh s_all)
  7894.           shell> ./configure  # Add your favorite options here
  7895.           make
  7896.  
  7897.      The command lines that change directory into the `innobase' and
  7898.      `bdb/dist' directories are used to configure the `InnoDB' and
  7899.      Berkeley DB (`BDB') storage engines.  You can omit these command
  7900.      lines if you to not require `InnoDB' or `BDB' support.
  7901.  
  7902.      If you get some strange error during this stage, check that you
  7903.      really have `libtool' installed.
  7904.  
  7905.      A collection of our standard configuration scripts is located in
  7906.      the `BUILD/' subdirectory.  You may find it more convenient to use
  7907.      the `BUILD/compile-pentium-debug' script than the preceding set of
  7908.      shell commands.. To compile on a different architecture, modify
  7909.      the script by removing flags that are Pentium-specific.
  7910.  
  7911.   5. When the build is done, run `make install'.  Be careful with this
  7912.      on a production machine; the command may overwrite your live
  7913.      release installation.  If you have another installation of MySQL,
  7914.      we recommend that you run `./configure' with different values for
  7915.      the `--prefix', `--with-tcp-port', and `--unix-socket-path' options
  7916.      than those used for your production server.
  7917.  
  7918.   6. Play hard with your new installation and try to make the new
  7919.      features crash.  Start by running `make test'.  *Note MySQL test
  7920.      suite::.
  7921.  
  7922.   7. If you have gotten to the `make' stage and the distribution does
  7923.      not compile, please report it in our bugs database at
  7924.      `http://bugs.mysql.com/'.  If you have installed the latest
  7925.      versions of the required GNU tools, and they crash trying to
  7926.      process our configuration files, please report that also.
  7927.      However, if you execute `aclocal' and get a `command not found'
  7928.      error or a similar problem, do not report it.  Instead, make sure
  7929.      all the necessary tools are installed and that your `PATH'
  7930.      variable is set correctly so that your shell can find them.
  7931.  
  7932.   8. After the initial `bk clone' operation to obtain the source tree,
  7933.      you should run `bk pull' periodically to get updates.
  7934.  
  7935.   9. You can examine the change history for the tree with all the diffs
  7936.      by using `bk revtool'.  If you see some funny diffs or code that
  7937.      you have a question about, do not hesitate to send email to the
  7938.      MySQL internals mailing list.  *Note Mailing-list::.  Also, if you
  7939.      think you have a better idea on how to do something, send an email
  7940.      message to the same address with a patch.  `bk diffs' will produce
  7941.      a patch for you after you have made changes to the source. If you
  7942.      do not have the time to code your idea, just send a description.
  7943.  
  7944.  10. `BitKeeper' has a nice help utility that you can access via `bk
  7945.      helptool'.
  7946.  
  7947.  11. Please note that any commits (`bk ci' or `bk citool') will trigger
  7948.      the posting of a message with the changeset to our internals
  7949.      mailing list, as well as the usual openlogging.org submission with
  7950.      just the changeset comments.  Generally, you wouldn't need to use
  7951.      commit (since the public tree will not allow `bk push'), but
  7952.      rather use the `bk diffs' method described previously.
  7953.  
  7954.  
  7955. You can also browse changesets, comments, and source code online. For
  7956. example, to browse this information for MySQL 4.1, go to
  7957. `http://mysql.bkbits.net:8080/mysql-4.1'.
  7958.  
  7959. The manual is in a separate tree which can be cloned with:
  7960.  
  7961.      shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
  7962.  
  7963. There are also public BitKeeper trees for MySQL Control Center and
  7964. Connector/ODBC. They can be cloned respectively as follows.
  7965.  
  7966. To clone MySQL Control center, use this command:
  7967.  
  7968.      shell> bk clone http://mysql.bkbits.net/mysqlcc mysqlcc
  7969.  
  7970. To clone Connector/ODBC, use this command:
  7971.  
  7972.      shell> bk clone http://mysql.bkbits.net/myodbc3 myodbc3
  7973.  
  7974. Dealing With Problems Compiling MySQL
  7975. -------------------------------------
  7976.  
  7977. All MySQL programs compile cleanly for us with no warnings on Solaris
  7978. or Linux using `gcc'.  On other systems, warnings may occur due to
  7979. differences in system include files.  See *Note MIT-pthreads:: for
  7980. warnings that may occur when using MIT-pthreads.  For other problems,
  7981. check the following list.
  7982.  
  7983. The solution to many problems involves reconfiguring.  If you do need to
  7984. reconfigure, take note of the following:
  7985.  
  7986.    * If `configure' is run after it already has been run, it may use
  7987.      information that was gathered during its previous invocation.  This
  7988.      information is stored in `config.cache'.  When `configure' starts
  7989.      up, it looks for that file and reads its contents if it exists, on
  7990.      the assumption that the information is still correct.  That
  7991.      assumption is invalid when you reconfigure.
  7992.  
  7993.    * Each time you run `configure', you must run `make' again to
  7994.      recompile.  However, you may want to remove old object files from
  7995.      previous builds first because they were compiled using different
  7996.      configuration options.
  7997.  
  7998. To prevent old configuration information or object files from being
  7999. used, run these commands before re-running `configure':
  8000.  
  8001.      shell> rm config.cache
  8002.      shell> make clean
  8003.  
  8004. Alternatively, you can run `make distclean'.
  8005.  
  8006. The following list describes some of the problems when compiling MySQL
  8007. that have been found to occur most often:
  8008.  
  8009.    * If you get errors when compiling `sql_yacc.cc', such as the ones
  8010.      shown here, you have probably run out of memory or swap space:
  8011.  
  8012.           Internal compiler error: program cc1plus got fatal signal 11
  8013.      or:
  8014.           Out of virtual memory
  8015.      or:
  8016.           Virtual memory exhausted
  8017.  
  8018.      The problem is that `gcc' requires huge amounts of memory to
  8019.      compile `sql_yacc.cc' with inline functions.  Try running
  8020.      `configure' with the `--with-low-memory' option:
  8021.  
  8022.           shell> ./configure --with-low-memory
  8023.  
  8024.      This option causes `-fno-inline' to be added to the compile line
  8025.      if you are using `gcc' and `-O0' if you are using something else.
  8026.      You should try the `--with-low-memory' option even if you have so
  8027.      much memory and swap space that you think you can't possibly have
  8028.      run out.  This problem has been observed to occur even on systems
  8029.      with generous hardware configurations, and the `--with-low-memory'
  8030.      option usually fixes it.
  8031.  
  8032.    * By default, `configure' picks `c++' as the compiler name and GNU
  8033.      `c++' links with `-lg++'.  If you are using `gcc', that behavior
  8034.      can cause problems during configuration such as this:
  8035.  
  8036.           configure: error: installation or configuration problem:
  8037.           C++ compiler cannot create executables.
  8038.  
  8039.      You might also observe problems during compilation related to
  8040.      `g++', `libg++', or `libstdc++'.
  8041.  
  8042.      One cause of these problems is that you may not have `g++', or you
  8043.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  8044.      the `config.log' file.  It should contain the exact reason why
  8045.      your C++ compiler didn't work.  To work around these problems, you
  8046.      can use `gcc' as your C++ compiler.  Try setting the environment
  8047.      variable `CXX' to `"gcc -O3"'.  For example:
  8048.  
  8049.           shell> CXX="gcc -O3" ./configure
  8050.  
  8051.      This works because `gcc' compiles C++ sources as well as `g++'
  8052.      does, but does not link in `libg++' or `libstdc++' by default.
  8053.  
  8054.      Another way to fix these problems is to install `g++', `libg++',
  8055.      and `libstdc++'.  We would however like to recommend you to not
  8056.      use `libg++' or `libstdc++' with MySQL as this will only increase
  8057.      the binary size of mysqld without giving you any benefits.  Some
  8058.      versions of these libraries have also caused strange problems for
  8059.      MySQL users in the past.
  8060.  
  8061.      Using `gcc' as the C++ compiler is also required, if you want to
  8062.      compile MySQL with RAID functionality (see *Note CREATE TABLE::
  8063.      for more info on RAID table type) and you are using GNU `gcc'
  8064.      version 3 and above. If you get errors like the ones below during
  8065.      the linking stage when you configure MySQL to compile with the
  8066.      option `--with-raid', try to use `gcc' as your C++ compiler by
  8067.      defining the above mentioned environment variable `CXX':
  8068.  
  8069.           gcc -O3 -DDBUG_OFF -rdynamic -o isamchk isamchk.o sort.o  libnisam.a
  8070.           ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a
  8071.            -lpthread -lz -lcrypt -lnsl -lm -lpthread
  8072.           ../mysys/libmysys.a(raid.o)(.text+0x79): In function
  8073.           `my_raid_create':: undefined reference to `operator new(unsigned)'
  8074.           ../mysys/libmysys.a(raid.o)(.text+0xdd): In function
  8075.           `my_raid_create':: undefined reference to `operator delete(void*)'
  8076.           ../mysys/libmysys.a(raid.o)(.text+0x129): In function
  8077.           `my_raid_open':: undefined reference to `operator new(unsigned)'
  8078.           ../mysys/libmysys.a(raid.o)(.text+0x189): In function
  8079.           `my_raid_open':: undefined reference to `operator delete(void*)'
  8080.           ../mysys/libmysys.a(raid.o)(.text+0x64b): In function
  8081.           `my_raid_close':: undefined reference to `operator delete(void*)'
  8082.           collect2: ld returned 1 exit status
  8083.  
  8084.    * If your compile fails with errors, such as any of the following,
  8085.      you must upgrade your version of `make' to GNU `make':
  8086.  
  8087.           making all in mit-pthreads
  8088.           make: Fatal error in reader: Makefile, line 18:
  8089.           Badly formed macro assignment
  8090.      or:
  8091.           make: file `Makefile' line 18: Must be a separator (:
  8092.      or:
  8093.           pthread.h: No such file or directory
  8094.  
  8095.      Solaris and FreeBSD are known to have troublesome `make' programs.
  8096.  
  8097.      GNU `make' Version 3.75 is known to work.
  8098.  
  8099.    * If you want to define flags to be used by your C or C++ compilers,
  8100.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  8101.      environment variables.  You can also specify the compiler names
  8102.      this way using `CC' and `CXX'.  For example:
  8103.  
  8104.           shell> CC=gcc
  8105.           shell> CFLAGS=-O3
  8106.           shell> CXX=gcc
  8107.           shell> CXXFLAGS=-O3
  8108.           shell> export CC CFLAGS CXX CXXFLAGS
  8109.  
  8110.      See *Note MySQL binaries::, for a list of flag definitions that
  8111.      have been found to be useful on various systems.
  8112.  
  8113.    * If you get an error message like this, you need to upgrade your
  8114.      `gcc' compiler:
  8115.  
  8116.           client/libmysql.c:273: parse error before `__attribute__'
  8117.  
  8118.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  8119.      or `egcs' 1.0.3a instead.
  8120.  
  8121.    * If you get errors such as those shown here when compiling `mysqld',
  8122.      `configure' didn't correctly detect the type of the last argument
  8123.      to `accept()', `getsockname()', or `getpeername()':
  8124.  
  8125.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  8126.                type of the pointer value ''length'' is ''unsigned long'',
  8127.                which is not compatible with ''int''.
  8128.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  8129.  
  8130.      To fix this, edit the `config.h' file (which is generated by
  8131.      `configure').  Look for these lines:
  8132.  
  8133.           /* Define as the base type of the last arg to accept */
  8134.           #define SOCKET_SIZE_TYPE XXX
  8135.  
  8136.      Change `XXX' to `size_t' or `int', depending on your operating
  8137.      system.  (Note that you will have to do this each time you run
  8138.      `configure' because `configure' regenerates `config.h'.)
  8139.  
  8140.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  8141.      the build process doesn't need to create `sql_yacc.cc', because
  8142.      MySQL comes with an already generated copy.  However, if you do
  8143.      need to re-create it, you might encounter this error:
  8144.  
  8145.           "sql_yacc.yy", line xxx fatal: default action causes potential...
  8146.  
  8147.      This is a sign that your version of `yacc' is deficient.  You
  8148.      probably need to install `bison' (the GNU version of `yacc') and
  8149.      use that instead.
  8150.  
  8151.    * On Debian Linux 3.0, you need to install `gawk' instead of the
  8152.      default `mawk', if you want to compile MySQL 4.1 or higher with
  8153.      Berkeley DB support.
  8154.  
  8155.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  8156.      with the `--with-debug' option, then recompile and link your
  8157.      clients with the new client library.  *Note Debugging client::.
  8158.  
  8159.    * If you get a compilation error on Linux (e.g. SuSE Linux 8.1 or
  8160.      Red Hat Linux 7.3) similar to the following one:
  8161.  
  8162.           libmysql.c:1329: warning: passing arg 5 of `gethostbyname_r' from
  8163.           incompatible pointer type
  8164.           libmysql.c:1329: too few arguments to function `gethostbyname_r'
  8165.           libmysql.c:1329: warning: assignment makes pointer from integer
  8166.           without a cast
  8167.           make[2]: *** [libmysql.lo] Error 1
  8168.  
  8169.      By default, the `configure' script attempts to determine the
  8170.      correct number of arguments by using `g++' the GNU C++ compiler.
  8171.      This test yields wrong results, if `g++' is not installed. There
  8172.      are two ways to work around this problem:
  8173.  
  8174.         * Make sure that the GNU C++ `g++' is installed. On some Linux
  8175.           distributions, the required package is called `gpp', on
  8176.           others it is named `gcc-c++'.
  8177.  
  8178.         * Use `gcc' as your C++ compiler by setting the `CXX'
  8179.           environment variable to `gcc':
  8180.                export CXX="gcc"
  8181.  
  8182.      Please note that you need to run `configure' again afterwards.
  8183.  
  8184.  
  8185. MIT-pthreads Notes
  8186. ------------------
  8187.  
  8188. This section describes some of the issues involved in using
  8189. MIT-pthreads.
  8190.  
  8191. Note that on Linux you should *not* use MIT-pthreads but use the
  8192. installed LinuxThreads implementation instead.  *Note Linux::.
  8193.  
  8194. If your system does not provide native thread support, you will need to
  8195. build MySQL using the MIT-pthreads package.  This includes older
  8196. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  8197. *Note Which OS::.
  8198.  
  8199. Note that, beginning with MySQL 4.0.2, MIT-pthreads are no longer part
  8200. of the source distribution. If you require this package, you need to
  8201. download it separately from
  8202. <http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz>
  8203.  
  8204. After downloading, extract this source archive into the top level of the
  8205. MySQL source directory. It will create a new subdirectory
  8206. `mit-pthreads'.
  8207.  
  8208.    * On most systems, you can force MIT-pthreads to be used by running
  8209.      `configure' with the `--with-mit-threads' option:
  8210.  
  8211.           shell> ./configure --with-mit-threads
  8212.  
  8213.      Building in a non-source directory is not supported when using
  8214.      MIT-pthreads because we want to minimise our changes to this code.
  8215.  
  8216.    * The checks that determine whether to use MIT-pthreads occur only
  8217.      during the part of the configuration process that deals with the
  8218.      server code.  If you have configured the distribution using
  8219.      `--without-server' to build only the client code, clients will not
  8220.      know whether MIT-pthreads is being used and will use Unix socket
  8221.      connections by default.  Because Unix socket files do not work
  8222.      under MIT-pthreads on some platforms, this means you will need to
  8223.      use `-h' or `--host' when you run client programs.
  8224.  
  8225.    * When MySQL is compiled using MIT-pthreads, system locking is
  8226.      disabled by default for performance reasons.  You can tell the
  8227.      server to use system locking with the `--external-locking' option.
  8228.      This is only needed if you want to be able to run two MySQL
  8229.      servers against the same datafiles (not recommended).
  8230.  
  8231.    * Sometimes the pthread `bind()' command fails to bind to a socket
  8232.      without any error message (at least on Solaris).  The result is
  8233.      that all connections to the server fail.  For example:
  8234.  
  8235.           shell> mysqladmin version
  8236.           mysqladmin: connect to server at '' failed;
  8237.           error: 'Can't connect to mysql server on localhost (146)'
  8238.  
  8239.      The solution to this is to kill the `mysqld' server and restart it.
  8240.      This has only happened to us when we have forced down the server
  8241.      and done a restart immediately.
  8242.  
  8243.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  8244.      with `SIGINT' (break).  This is only noticeable when you run
  8245.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  8246.      terminate before the interrupt is served and the process stops.
  8247.  
  8248.    * When linking, you may receive warning messages like these (at
  8249.      least on Solaris); they can be ignored:
  8250.  
  8251.           ld: warning: symbol `_iob' has differing sizes:
  8252.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  8253.           file /usr/lib/libc.so value=0x140);
  8254.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  8255.           ld: warning: symbol `__iob' has differing sizes:
  8256.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  8257.           file /usr/lib/libc.so value=0x140);
  8258.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  8259.  
  8260.    * Some other warnings also can be ignored:
  8261.  
  8262.           implicit declaration of function `int strtoll(...)'
  8263.           implicit declaration of function `int strtoul(...)'
  8264.  
  8265.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  8266.      isn't needed, but may be interesting for someone.)
  8267.  
  8268. Installing MySQL from Source on Windows
  8269. ---------------------------------------
  8270.  
  8271. These instructions describe how to build MySQL binaries from source for
  8272. versions 4.1 and above on Windows. Instructions are provided for
  8273. building binaries from a standard source distribution or from the
  8274. BitKeeper tree that contains the latest development source.
  8275.  
  8276. *Note:* The instructions in this document are strictly for users who
  8277. want to test MySQL on Windows from the latest source distribution or
  8278. from the BitKeeper tree.  For production use, MySQL AB does not advise
  8279. using a MySQL server built by yourself from source.  Normally, it is
  8280. best to use precompiled binary distributions of MySQL that are built
  8281. specifically for optimal performance on Windows by MySQL AB.
  8282. Instructions for installing a binary distributions are available at
  8283. *Note Windows installation::.
  8284.  
  8285. To build MySQL on Windows from source, you need the following compiler
  8286. and resources available on your Windows system:
  8287.  
  8288.    * VC++ 6.0 compiler (updated with 4 or 5 SP and pre-processor
  8289.      package).  The pre-processor package is necessary for the macro
  8290.      assembler.  More details at:
  8291.      `http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/faq.aspx'.
  8292.  
  8293.    * Approximately 45 MB disk space.
  8294.  
  8295.    * 64 MB RAM.
  8296.  
  8297.  
  8298. You'll also need a MySQL source distribution for Windows.  There are
  8299. two ways you can get a source distribution for MySQL version 4.1 and
  8300. above:
  8301.  
  8302.   1. Obtain a source distribution packaged by MySQL AB for the
  8303.      particular version of MySQL in which you are interested.
  8304.      Prepackaged source distributions are available for released
  8305.      versions of MySQL and can be obtained from
  8306.      `http://www.mysql.com/downloads/'.
  8307.  
  8308.   2. You can package a source distribution yourself from the latest
  8309.      BitKeeper developer source tree. If you plan to do this, you must
  8310.      create the package on a Unix system and then transfer it to your
  8311.      Windows system.  (The reason for this is that some of the
  8312.      configuration and build steps require tools that work only on
  8313.      Unix.)  The BitKeeper approach thus requires:
  8314.  
  8315.         * A system running Unix, or a Unix-like system such as Linux.
  8316.  
  8317.         * BitKeeper 3.0 installed on that system. You can obtain
  8318.           BitKeeper from `http://www.bitkeeper.com/'.
  8319.  
  8320.  
  8321.  
  8322. If you are using a Windows source distribution, you can go directly to
  8323. *Note Windows VC++ Build::. To build from the BitKeeper tree, proceed to
  8324. *Note Windows BitKeeper Build::.
  8325.  
  8326. If you find something not working as expected, or you have suggestions
  8327. about ways to improve the current build process on Windows, please send
  8328. a message to the `win32' mailing list.  *Note Mailing-list::.
  8329.  
  8330. Building MySQL Using VC++
  8331. .........................
  8332.  
  8333. *Note:* MySQL 4.1 and above VC++ workspace files are compatible with
  8334. Microsoft Visual Studio 6.0 and above(7.0/.NET) editions and tested by
  8335. MySQL AB staff before each release.
  8336.  
  8337. Follow this procedure to build MySQL:
  8338.  
  8339.   1. Create a work directory (for example, `workdir').
  8340.  
  8341.   2. Unpack the source distribution in the aforementioned directory
  8342.      using `WinZip' or other Windows tools that can read `.zip' files.
  8343.  
  8344.   3. Start the VC++ 6.0 compiler.
  8345.  
  8346.   4. In the `File' menu, select `Open Workspace'.
  8347.  
  8348.   5. Open the `mysql.dsw' workspace you find in the work directory.
  8349.  
  8350.   6. From the `Build' menu, select the `Set Active Configuration' menu.
  8351.  
  8352.   7. Click over the screen selecting `mysqld - Win32 Debug' and click
  8353.      OK.
  8354.  
  8355.   8. Press `F7' to begin the build of the debug server, libraries, and
  8356.      some client applications.
  8357.  
  8358.   9. Compile the release versions that you want, in the same way.
  8359.  
  8360.  10. Debug versions of the programs and libraries are placed in the
  8361.      `client_debug' and `lib_debug' directories.  Release versions of
  8362.      the programs and libraries are placed in the `client_release' and
  8363.      `lib_release' directories.  Note that if you want to build both
  8364.      debug and release versions, you can select the "build all" option
  8365.      from the `Build' menu.
  8366.  
  8367.  11. Test the server.  The server built using the preceding instructions
  8368.      will expect that the MySQL base directory and data directory are
  8369.      `C:\mysql' and `C:\mysql\data' by default. If you want to test
  8370.      your server using the source tree root directory and its data
  8371.      directory as the base directory and data directory, you will need
  8372.      to tell the server their pathnames. You can either do this on the
  8373.      command line with the `--basedir' and `--datadir' options, or
  8374.      place appropriate options in an option file (`C:\my.cnf' or the
  8375.      `my.ini' file in your Windows directory). If you have an existing
  8376.      data directory elsewhere that you want to use, you can specify its
  8377.      pathname instead.
  8378.  
  8379.  12. Start your server from the `client_release' or `client_debug'
  8380.      directory, depending on which server you want to use. The general
  8381.      server startup instructions are at *Note Windows installation::.
  8382.      You'll need to to adapt the instructions appropriately if you want
  8383.      to use a different base directory or data directory.
  8384.  
  8385.  13. When the server is running in standalone fashion or as a service
  8386.      based on your configuration, try to connect to it from the `mysql'
  8387.      interactive command line utility that exists in your
  8388.      `client_release' or `client_debug' directory.
  8389.  
  8390.  
  8391. When you are satisifed that the programs you have built are working
  8392. correctly, stop the server. Then install MySQL as follows:
  8393.  
  8394.   1. Create the directories where you want to install MySQL.  For
  8395.      example, to install into `C:\mysql', use these commands:
  8396.  
  8397.           C:
  8398.           mkdir \mysql
  8399.           mkdir \mysql\bin
  8400.           mkdir \mysql\data
  8401.           mkdir \mysql\share
  8402.           mkdir \mysql\scripts
  8403.  
  8404.      If you want to compile other clients and link them to MySQL, you
  8405.      should also create several additional directories:
  8406.  
  8407.           mkdir \mysql\include
  8408.           mkdir \mysql\lib
  8409.           mkdir \mysql\lib\debug
  8410.           mkdir \mysql\lib\opt
  8411.  
  8412.      If you want to benchmark MySQL, create this directory:
  8413.  
  8414.           mkdir \mysql\sql-bench
  8415.  
  8416.      Benchmarking requires Perl support.
  8417.  
  8418.   2. From the `workdir' directory, copy into the `C:\mysql' directory
  8419.      the following directories:
  8420.  
  8421.           copy client_release\*.exe C:\mysql\bin
  8422.           copy client_debug\mysqld.exe C:\mysql\bin\mysqld-debug.exe
  8423.           xcopy scripts\*.* C:\mysql\scripts /E
  8424.           xcopy share\*.* C:\mysql\share /E
  8425.  
  8426.      If you want to compile other clients and link them to MySQL, you
  8427.      should also copy several libraries and header files:
  8428.  
  8429.           copy lib_debug\mysqlclient.lib C:\mysql\lib\debug
  8430.           copy lib_debug\libmysql.* C:\mysql\lib\debug
  8431.           copy lib_debug\zlib.* C:\mysql\lib\debug
  8432.           copy lib_release\mysqlclient.lib C:\mysql\lib\opt
  8433.           copy lib_release\libmysql.* C:\mysql\lib\opt
  8434.           copy lib_release\zlib.* C:\mysql\lib\opt
  8435.           copy include\*.h C:\mysql\include
  8436.           copy libmysql\libmysql.def C:\mysql\include
  8437.  
  8438.      If you want to benchmark MySQL, you should also do this:
  8439.  
  8440.           xcopy sql-bench\*.* C:\mysql\bench /E
  8441.  
  8442.  
  8443. Set up and start the server in the same way as for the binary Windows
  8444. distribution.  *Note Windows installation::.
  8445.  
  8446. Creating a Windows Source Package from the Latest Development Source
  8447. ....................................................................
  8448.  
  8449. To create a Windows source package from the current BitKeeper source
  8450. tree, use the following instructions. Please note that this procedure
  8451. must be performed on a system running a Unix or Unix-like operating
  8452. system.  (The procedure is known to work well on Linux, for example.)
  8453.  
  8454.   1. Clone the BitKeeper source tree for MySQL (version 4.1 or above,
  8455.      as desired).  For more information how to clone the source tree,
  8456.      see the instructions at *Note Installing source tree::.
  8457.  
  8458.   2. Configure and build the distribution so that you have a server
  8459.      binary to work with.  One way to do this is to run the following
  8460.      command in the top-level directory of your source tree:
  8461.  
  8462.           shell> ./BUILD/compile-pentium-max
  8463.  
  8464.   3. After making sure that the build process completed successfully,
  8465.      run the following utility script from top-level directory of your
  8466.      source tree:
  8467.  
  8468.           shell> ./scripts/make_win_src_distribution
  8469.  
  8470.      This script creates a Windows source package, to be used on your
  8471.      Windows system.  You can supply different options to the script
  8472.      based on your needs. It accepts the following options:
  8473.  
  8474.           --debug   Print information about script operations, do not create package
  8475.           --tmp     Specify the temporary location
  8476.           --suffix  Suffix name for the package
  8477.           --dirname Directory name to copy files (intermediate)
  8478.           --silent  Do not print verbose list of files processed
  8479.           --tar     Create tar.gz package instead of .zip package
  8480.           --help    Show this help message
  8481.  
  8482.      By default, `make_win_src_distribution' creates a zipped archive
  8483.      with the name `mysql-VERSION-win-src.zip', where `VERSION'
  8484.      represents the version of your MySQL source tree.
  8485.  
  8486.   4. Copy or upload to your Windows machine the Windows source package
  8487.      that you have just created. To compile it, use the instructions in
  8488.      *Note Windows VC++ Build::.
  8489.  
  8490.  
  8491. Compiling MySQL Clients on Windows
  8492. ----------------------------------
  8493.  
  8494. In your source files, you should include `my_global.h' before `mysql.h':
  8495.  
  8496.      #include <my_global.h>
  8497.      #include <mysql.h>
  8498.  
  8499. `my_global.h' includes any other files needed for Windows compatibility
  8500. (such as `windows.h') if you compile your program on Windows.
  8501.  
  8502. You can either link your code with the dynamic `libmysql.lib' library,
  8503. which is just a wrapper to load in `libmysql.dll' on demand, or link
  8504. with the static `mysqlclient.lib' library.
  8505.  
  8506. Note that because the MySQL client libraries are compiled as threaded
  8507. libraries, you should also compile your code to be multi-threaded!
  8508.  
  8509. Post-installation Setup and Testing
  8510. ===================================
  8511.  
  8512. There are some issues you should address after installing MySQL.  For
  8513. example, on Unix, you should create the MySQL grant tables.  On all
  8514. platforms, an important security concern is that the initial accounts
  8515. in the grant tables have no passwords.  You should assign passwords to
  8516. prevent unauthorized access to the MySQL server.
  8517.  
  8518. The following sections describe post-installation procedures for Windows
  8519. systems and for Unix systems.
  8520.  
  8521. Windows Post-installation Procedures
  8522. ------------------------------------
  8523.  
  8524. On Windows, the grant tables do not have to be created. MySQL Windows
  8525. distributions include the grant tables already set up in the `mysql'
  8526. database under the `data' directory.  However, you should assign
  8527. passwords to the accounts.
  8528.  
  8529. The default privileges on Windows give all local users full privileges
  8530. to all databases without specifying a password.  To make MySQL more
  8531. secure, you should set a password for all users and remove the row in
  8532. the `mysql.user' table that has `Host='localhost'' and `User='''.
  8533.  
  8534. You should also add a password for the `root' user. The following
  8535. example starts by removing the anonymous user that has all privileges,
  8536. then sets a `root' user password:
  8537.  
  8538.      C:\> C:\mysql\bin\mysql mysql
  8539.      mysql> DELETE FROM user WHERE Host='localhost' AND User='';
  8540.      mysql> FLUSH PRIVILEGES;
  8541.      mysql> QUIT
  8542.      C:\> C:\mysql\bin\mysqladmin -u root password your_password
  8543.  
  8544. After you've set the password, if you want to shut down the `mysqld'
  8545. server, you can do so using this command:
  8546.  
  8547.      C:\> mysqladmin --user=root --password=your_password shutdown
  8548.  
  8549. If you are using a server from a _very_ old version of MySQL, the
  8550. `mysqladmin' command to set the password will fail with an error:
  8551. `parse error near 'SET password''.  The solution to this problem is to
  8552. upgrade to a newer version of MySQL.
  8553.  
  8554. With the current MySQL versions you can easily add new users and change
  8555. privileges with `GRANT' and `REVOKE' commands.  *Note `GRANT': GRANT.
  8556.  
  8557. Unix Post-installation Procedures
  8558. ---------------------------------
  8559.  
  8560. After you install MySQL on Unix, you need to initialize the grant
  8561. tables, start the server, and make sure that the server works okay.
  8562. You may also wish to arrange for the server to be started and stopped
  8563. automatically when your system starts and stops.
  8564.  
  8565. Normally you install the grant tables and start the server like this
  8566. for installation from a source distribution:
  8567.  
  8568.      shell> cd mysql_installation_directory
  8569.      shell> bin/mysql_install_db
  8570.      shell> bin/mysqld_safe --user=mysql &
  8571.  
  8572. For a binary distribution (not RPM or PKG packages), do this:
  8573.  
  8574.      shell> cd mysql_installation_directory
  8575.      shell> scripts/mysql_install_db
  8576.      shell> bin/mysqld_safe --user=mysql &
  8577.  
  8578. The `mysql_install_db' script creates the `mysql' database that holds
  8579. all database privileges, and the `test' database that you can use to
  8580. test MySQL. The script also creates privilege table entries for `root'
  8581. accounts and anonymous-user accounts.  The entries are created without
  8582. passwords.  The `mysqld_safe' script starts the `mysqld' server.  (For
  8583. versions of MySQL older than 4.0, use `safe_mysqld' rather than
  8584. `mysqld_safe'.)
  8585.  
  8586. `mysql_install_db' will not overwrite any old privilege tables, so it
  8587. should be safe to run in any circumstances.  If you don't want to have
  8588. the `test' database you can remove it with `mysqladmin -u root drop
  8589. test' after starting the server.
  8590.  
  8591. Testing is most easily done from the top-level directory of the MySQL
  8592. distribution.  For a binary distribution, this is your installation
  8593. directory (typically something like `/usr/local/mysql').  For a source
  8594. distribution, this is the main directory of your MySQL source tree.
  8595.  
  8596. In the commands shown in this section and in the following subsections,
  8597. `BINDIR' is the path to the location in which programs like
  8598. `mysqladmin' and `mysqld_safe' are installed.  For a binary
  8599. distribution, this is the `bin' directory within the distribution.  For
  8600. a source distribution, `BINDIR' is probably `/usr/local/bin', unless
  8601. you specified an installation directory other than `/usr/local' when
  8602. you ran `configure'.  `EXECDIR' is the location in which the `mysqld'
  8603. server is installed.  For a binary distribution, this is the same as
  8604. `BINDIR'.  For a source distribution, `EXECDIR' is probably
  8605. `/usr/local/libexec'.
  8606.  
  8607. Testing is described in detail:
  8608.  
  8609.   1. If necessary, start the `mysqld' server and set up the initial
  8610.      MySQL grant tables containing the privileges that determine how
  8611.      users are allowed to connect to the server.  This is normally done
  8612.      with the `mysql_install_db' script:
  8613.  
  8614.           shell> scripts/mysql_install_db
  8615.  
  8616.      Typically, `mysql_install_db' needs to be run only the first time
  8617.      you install MySQL.  Therefore, if you are upgrading an existing
  8618.      installation, you can skip this step.  (However,
  8619.      `mysql_install_db' is quite safe to use and will not update any
  8620.      tables that already exist, so if you are unsure of what to do, you
  8621.      can always run `mysql_install_db'.)
  8622.  
  8623.      `mysql_install_db' creates six tables (`user', `db', `host',
  8624.      `tables_priv', `columns_priv', and `func') in the `mysql'
  8625.      database.  A description of the initial privileges is given in
  8626.      *Note Default privileges::.  Briefly, these privileges allow the
  8627.      MySQL `root' user to do anything, and allow anybody to create or
  8628.      use databases with a name of `test' or starting with `test_'.
  8629.  
  8630.      If you don't set up the grant tables, the following error will
  8631.      appear in the log file when you start the server:
  8632.  
  8633.           mysqld: Can't find file: 'host.frm'
  8634.  
  8635.      This may also happen with a binary MySQL distribution if you don't
  8636.      start MySQL by executing exactly `./bin/mysqld_safe'.  *Note
  8637.      `mysqld_safe': mysqld_safe.
  8638.  
  8639.      You might need to run `mysql_install_db' as `root'.  However, if
  8640.      you prefer, you can run the MySQL server as an unprivileged
  8641.      (non-`root') user, provided that the user can read and write files
  8642.      in the database directory.  Instructions for running MySQL as an
  8643.      unprivileged user are given in *Note Changing MySQL user: Changing
  8644.      MySQL user.
  8645.  
  8646.      If you have problems with `mysql_install_db', see *Note
  8647.      `mysql_install_db': mysql_install_db.
  8648.  
  8649.      There are some alternatives to running the `mysql_install_db'
  8650.      script as it is provided in the MySQL distribution:
  8651.  
  8652.         * You may want to edit `mysql_install_db' before running it, to
  8653.           change the initial privileges that are installed into the
  8654.           grant tables.  This is useful if you want to install MySQL on
  8655.           a lot of machines with the same privileges.  In this case you
  8656.           probably should need only to add a few extra `INSERT'
  8657.           statements to the `mysql.user' and `mysql.db' tables.
  8658.  
  8659.         * If you want to change the contents of the grant tables after
  8660.           installing them, you can run `mysql_install_db', then use
  8661.           `mysql -u root mysql' to connect to the grant tables as the
  8662.           MySQL `root' user and issue SQL statements to modify the
  8663.           grant tables directly.
  8664.  
  8665.         * It is possible to re-create the grant tables completely after
  8666.           they have already been created.  You might want to do this if
  8667.           you've already installed the tables but then want to
  8668.           re-create them after editing `mysql_install_db'.
  8669.  
  8670.      For more information about these alternatives, see *Note Default
  8671.      privileges::.
  8672.  
  8673.   2. Start the MySQL server like this:
  8674.  
  8675.           shell> cd mysql_installation_directory
  8676.           shell> bin/mysqld_safe &
  8677.  
  8678.      For versions of MySQL older than 4.0, substitute `bin/safe_mysqld'
  8679.      for `bin/mysqld_safe' in the final command.
  8680.  
  8681.      If you have problems starting the server, see *Note Starting
  8682.      server::.
  8683.  
  8684.   3. Use `mysqladmin' to verify that the server is running.  The
  8685.      following commands provide a simple test to check that the server
  8686.      is up and responding to connections:
  8687.  
  8688.           shell> BINDIR/mysqladmin version
  8689.           shell> BINDIR/mysqladmin variables
  8690.  
  8691.      The output from `mysqladmin version' varies slightly depending on
  8692.      your platform and version of MySQL, but should be similar to that
  8693.      shown here:
  8694.  
  8695.           shell> BINDIR/mysqladmin version
  8696.           mysqladmin  Ver 8.40 Distrib 4.0.18, for linux on i586
  8697.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  8698.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  8699.           and you are welcome to modify and redistribute it under the GPL license
  8700.           
  8701.           
  8702.           Server version          4.0.18-log
  8703.           Protocol version        10
  8704.           Connection              Localhost via Unix socket
  8705.           TCP port                3306
  8706.           UNIX socket             /tmp/mysql.sock
  8707.           Uptime:                 16 sec
  8708.           
  8709.           Threads: 1  Questions: 9  Slow queries: 0
  8710.           Opens: 7  Flush tables: 2  Open tables: 0
  8711.           Queries per second avg: 0.000
  8712.           Memory in use: 132K  Max memory used: 16773K
  8713.  
  8714.      To see what else you can do with `mysqladmin', invoke it with the
  8715.      `--help' option.
  8716.  
  8717.   4. Verify that you can shut down the server:
  8718.  
  8719.           shell> BINDIR/mysqladmin -u root shutdown
  8720.  
  8721.   5. Verify that you can restart the server.  Do this using
  8722.      `mysqld_safe' or by invoking `mysqld' directly.  For example:
  8723.  
  8724.           shell> BINDIR/mysqld_safe --log &
  8725.  
  8726.      If `mysqld_safe' fails, try running it from the MySQL installation
  8727.      directory (if you are not already there).  If that doesn't work,
  8728.      see *Note Starting server::.
  8729.  
  8730.   6. Run some simple tests to verify that the server is working.  The
  8731.      output should be similar to what is shown here:
  8732.  
  8733.           shell> BINDIR/mysqlshow
  8734.           +-----------+
  8735.           | Databases |
  8736.           +-----------+
  8737.           | mysql     |
  8738.           +-----------+
  8739.           
  8740.           shell> BINDIR/mysqlshow mysql
  8741.           Database: mysql
  8742.           +--------------+
  8743.           |    Tables    |
  8744.           +--------------+
  8745.           | columns_priv |
  8746.           | db           |
  8747.           | func         |
  8748.           | host         |
  8749.           | tables_priv  |
  8750.           | user         |
  8751.           +--------------+
  8752.           
  8753.           shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql
  8754.           +------+--------+------+
  8755.           | host | db     | user |
  8756.           +------+--------+------+
  8757.           | %    | test   |      |
  8758.           | %    | test_% |      |
  8759.           +------+--------+------+
  8760.  
  8761.      There is also a benchmark suite in the `sql-bench' directory
  8762.      (under the MySQL installation directory) that you can use to
  8763.      compare how MySQL performs on different platforms. The benchmark
  8764.      suite is written in Perl. It uses the Perl DBI module to provide a
  8765.      database-independent interface to the various databases. The
  8766.      following additional Perl modules are required to run the
  8767.      benchmark suite:
  8768.  
  8769.           DBI
  8770.           DBD::mysql
  8771.           Data::Dumper
  8772.           Data::ShowTable
  8773.  
  8774.      These modules can be obtained from CPAN `http://www.cpan.org/'.
  8775.      *Note Perl installation::.
  8776.  
  8777.      The `sql-bench/Results' directory contains the results from many
  8778.      runs against different databases and platforms.  To run all tests,
  8779.      execute these commands:
  8780.  
  8781.           shell> cd sql-bench
  8782.           shell> run-all-tests
  8783.  
  8784.      If you don't have the `sql-bench' directory, you probably
  8785.      installed MySQL using RPM files other than the source RPM.  (The
  8786.      source RPM includes the `sql-bench' benchmark directory.)  In this
  8787.      case, you must first install the benchmark suite before you can
  8788.      use it.  Beginning with MySQL Version 3.22, there are separate
  8789.      benchmark RPM files named `mysql-bench-VERSION-i386.rpm' that
  8790.      contain benchmark code and data.
  8791.  
  8792.      If you have a source distribution, there are also tests in its
  8793.      `tests' subdirectory that you can run. For example, to run
  8794.      `auto_increment.tst', do this:
  8795.  
  8796.           shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
  8797.  
  8798.      The expected result of the test can be found in the
  8799.      `./tests/auto_increment.res' file.
  8800.  
  8801. Problems Running `mysql_install_db'
  8802. ...................................
  8803.  
  8804. The purpose of the `mysql_install_db' script is to generate new MySQL
  8805. privilege tables.  It will not overwrite existing MySQL privilege
  8806. tables, and it will not affect any other data.
  8807.  
  8808. If you want to re-create your privilege tables, you should take down
  8809. the `mysqld' server, if it's running, and then do something like:
  8810.  
  8811.      mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  8812.      mysql_install_db
  8813.  
  8814. This section lists problems you might encounter when you run
  8815. `mysql_install_db':
  8816.  
  8817. *`mysql_install_db' doesn't install the grant tables*
  8818.      You may find that `mysql_install_db' fails to install the grant
  8819.      tables and terminates after displaying the following messages:
  8820.  
  8821.           Starting mysqld daemon with databases from XXXXXX
  8822.           mysqld ended
  8823.  
  8824.      In this case, you should examine the log file very carefully.  The
  8825.      log should be located in the directory `XXXXXX' named by the error
  8826.      message, and should indicate why `mysqld' didn't start.  If you
  8827.      don't understand what happened, include the log when you post a
  8828.      bug report.  *Note Bug reports::.
  8829.  
  8830. *There is already a `mysqld' process running*
  8831.      In this case, you probably don't have to run `mysql_install_db' at
  8832.      all.  You have to run `mysql_install_db' only once, when you
  8833.      install MySQL the first time.
  8834.  
  8835. *Installing a second `mysqld' server doesn't work when one server is running*
  8836.      This can happen when you already have an existing MySQL
  8837.      installation, but want to put a new installation in a different
  8838.      location (for example, for testing, or perhaps you simply want to
  8839.      run two installations at the same time).  Generally the problem
  8840.      that occurs when you try to run the second server is that it tries
  8841.      to use the same socket and port as the old one.  In this case you
  8842.      will get the error message: `Can't start server: Bind on TCP/IP
  8843.      port: Address already in use' or `Can't start server: Bind on unix
  8844.      socket...'. *Note Multiple servers::.
  8845.  
  8846. *You don't have write access to `/tmp'*
  8847.      If you don't have write access to create a socket file at the
  8848.      default place (in `/tmp') or permission to create temporary files
  8849.      in `/tmp,' you will get an error when running `mysql_install_db'
  8850.      or when starting or using `mysqld'.
  8851.  
  8852.      You can specify a different socket and temporary directory as
  8853.      follows:
  8854.  
  8855.           shell> TMPDIR=/some_tmp_dir/
  8856.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
  8857.           shell> export TMPDIR MYSQL_UNIX_PORT
  8858.  
  8859.      See *Note Problems with `mysql.sock': Problems with mysql.sock.
  8860.  
  8861.      `some_tmp_dir' should be the path to some directory for which you
  8862.      have write permission. *Note Environment variables::.
  8863.  
  8864.      After this, you should be able to run `mysql_install_db' and start
  8865.      the server with these commands:
  8866.  
  8867.           shell> scripts/mysql_install_db
  8868.           shell> BINDIR/mysqld_safe &
  8869.  
  8870. *`mysqld' crashes immediately*
  8871.      If you are running Red Hat Version 5.0 with a version of `glibc'
  8872.      older than 2.0.7-5, you should make sure you have installed all
  8873.      `glibc' patches.  There is a lot of information about this in the
  8874.      MySQL mail archives.  Links to the mail archives are available
  8875.      online at `http://lists.mysql.com/'.  Also, see *Note Linux::.
  8876.  
  8877.      You can also start `mysqld' manually using the
  8878.      `--skip-grant-tables' option and add the privilege information
  8879.      yourself using `mysql':
  8880.  
  8881.           shell> BINDIR/mysqld_safe --skip-grant-tables &
  8882.           shell> BINDIR/mysql -u root mysql
  8883.  
  8884.      From `mysql', manually execute the SQL commands in
  8885.      `mysql_install_db'.  Make sure you run `mysqladmin
  8886.      flush-privileges' or `mysqladmin reload' afterward to tell the
  8887.      server to reload the grant tables.
  8888.  
  8889. Starting and Stopping MySQL Automatically
  8890. .........................................
  8891.  
  8892. Generally, you start the `mysqld' server in one of these ways:
  8893.  
  8894.    * By invoking `mysqld' directly. This works on any platform.
  8895.  
  8896.    * By running the MySQL server as a Windows service.  This can be
  8897.      done on Windows NT, 2000, and XP.  For instructions, see *Note NT
  8898.      start::.
  8899.  
  8900.    * By invoking `mysql.server'.  This script is used primarily at
  8901.      system startup and shutdown on systems that use System V-style run
  8902.      directories. It is described more fully later in this section.
  8903.  
  8904.    * By invoking `mysqld_safe', which tries to determine the proper
  8905.      options for `mysqld' and then runs it with those options.  This
  8906.      script is used on systems based on BSD Unix. It also is invoked by
  8907.      `mysql.server'.  *Note `mysqld_safe': mysqld_safe.
  8908.  
  8909. The `mysql.server' and `mysqld_safe' scripts can be used to start the
  8910. server automatically at system startup time. `mysql.server' can also be
  8911. used to stop the server.
  8912.  
  8913. The `mysql.server' script can be used to start or stop the server by
  8914. invoking it with `start' or `stop' arguments:
  8915.  
  8916.      shell> mysql.server start
  8917.      shell> mysql.server stop
  8918.  
  8919. `mysql.server' can be found in the `share/mysql' directory under the
  8920. MySQL installation directory or in the `support-files' directory of the
  8921. MySQL source tree.
  8922.  
  8923. Note that if you use the Linux RPM package
  8924. (`MySQL-server-VERSION.rpm'), the `mysql.server' script has already
  8925. been installed as `/etc/init.d/mysql'. You don't have to install it
  8926. manually. See *Note Linux-RPM:: for more information on the Linux RPM
  8927. packages.
  8928.  
  8929. On Mac OS X, you can install a separate MySQL Startup Item package to
  8930. enable the automatic startup of MySQL on system bootup.  See *Note Mac
  8931. OS X installation:: for details.
  8932.  
  8933. Before `mysql.server' starts the server, it changes the directory to
  8934. the MySQL installation directory, then invokes `mysqld_safe'.  You
  8935. might need to edit `mysql.server' if you have a binary distribution
  8936. that you've installed in a non-standard location.  Modify it to `cd'
  8937. into the proper directory before it runs `mysqld_safe'. If you want the
  8938. server to run as some specific user, add an appropriate `user' line to
  8939. the `/etc/my.cnf' file, as shown later in this section.
  8940.  
  8941. `mysql.server stop' brings down the server by sending a signal to it.
  8942. You can also stop the server manually by executing `mysqladmin
  8943. shutdown'.
  8944.  
  8945. You need to add these start and stop commands to the appropriate places
  8946. in your `/etc/rc*' files when you want to start up MySQL automatically
  8947. on your server.
  8948.  
  8949. On most current Linux distributions, it is sufficient to copy the file
  8950. `mysql.server' into the `/etc/init.d' directory (or `/etc/rc.d/init.d'
  8951. on older Red Hat systems). Afterwards, run the following command to
  8952. enable the startup of MySQL on system bootup:
  8953.  
  8954.      shell> chkconfig --add mysql.server
  8955.  
  8956. On FreeBSD startup scripts generally should go in
  8957. `/usr/local/etc/rc.d/'. The `rc(8)' manual page also states that
  8958. scripts in this directory are only executed, if their basename matches
  8959. the shell globbing pattern `*.sh'. Any other files or directories
  8960. present within the directory are silently ignored. In other words, on
  8961. FreeBSD you should install the file `mysql.server' as
  8962. `/usr/local/etc/rc.d/mysql.server.sh' to enable automatic startup.
  8963.  
  8964. As an alternative to the above, some operating systems also use
  8965. `/etc/rc.local' or `/etc/init.d/boot.local' to start additional
  8966. services on bootup. To start up MySQL using this method, you could
  8967. append something like the following to it:
  8968.  
  8969.      /bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
  8970.  
  8971. You can also add options for `mysql.server' in a global `/etc/my.cnf'
  8972. file.  A typical `/etc/my.cnf' file might look like this:
  8973.  
  8974.      [mysqld]
  8975.      datadir=/usr/local/mysql/var
  8976.      socket=/var/tmp/mysql.sock
  8977.      port=3306
  8978.      user=mysql
  8979.      
  8980.      [mysql.server]
  8981.      basedir=/usr/local/mysql
  8982.  
  8983. The `mysql.server' script understands the following options: `datadir',
  8984. `basedir', and `pid-file'.
  8985.  
  8986. The following table shows which option groups each startup script reads
  8987. from option files:
  8988.  
  8989. *Script*    *Option groups*
  8990. `mysqld'    `[mysqld]', `[server]' and `[mysqld-major-version]'
  8991. `mysql.server'`[mysql.server]', `[mysqld]', and `[server]'
  8992. `mysqld_safe'`[mysqld]', `[server]', and `[mysqld_safe]'
  8993.  
  8994. For backward compatibility, `mysql.server' also reads the
  8995. `[mysql_server]' group and `mysqld_safe' also reads the `[safe_mysqld]'
  8996. group. However, you should update your option files to use the
  8997. `[mysql.server]' and `[mysqld_safe]' groups instead.
  8998.  
  8999. *Note Option files::.
  9000.  
  9001. Starting and Troubleshooting the MySQL Server
  9002. .............................................
  9003.  
  9004. If you are going to use storage engines that support transactional
  9005. tables (`InnoDB', `BDB'), you should first create a `my.cnf' file and
  9006. set startup options for the engines you plan to use. *Note Table
  9007. types::.
  9008.  
  9009. When the `mysqld' server starts, it changes location to the data
  9010. directory.  This is where it expects to write log files and the pid
  9011. (process ID) file, and where it expects to find databases.
  9012.  
  9013. The data directory location is hardwired in when the distribution is
  9014. compiled.  However, if `mysqld' expects to find the data directory
  9015. somewhere other than where it really is on your system, it will not work
  9016. properly.  If you have problems with incorrect paths, you can find out
  9017. what options `mysqld' allows and what the default path settings are by
  9018. invoking `mysqld' with the `--help' option.  You can override the
  9019. defaults by specifying the correct pathnames as command-line arguments
  9020. to `mysqld'.  (These options can be used with `mysqld_safe' as well.)
  9021.  
  9022. Normally you should need to tell `mysqld' only the base directory under
  9023. which MySQL is installed.  You can do this with the `--basedir' option.
  9024. You can also use `--help' to check the effect of changing path options
  9025. (note that `--help' *must* be the final option of the `mysqld'
  9026. command).  For example:
  9027.  
  9028.      shell> EXECDIR/mysqld --basedir=/usr/local --help
  9029.  
  9030. Once you determine the path settings you want, start the server without
  9031. the `--help' option.
  9032.  
  9033. Whichever method you use to start the server, if it fails to start up
  9034. correctly, check the log file to see if you can find out why.  Log files
  9035. are located in the data directory (typically `/usr/local/mysql/data'
  9036. for a binary distribution, `/usr/local/var' for a source distribution,
  9037. and `\mysql\data\mysql.err' on Windows).  Look in the data directory for
  9038. files with names of the form `host_name.err' and `host_name.log' where
  9039. `host_name' is the name of your server host.  Then check the last few
  9040. lines of these files:
  9041.  
  9042.      shell> tail host_name.err
  9043.      shell> tail host_name.log
  9044.  
  9045. Look for something like the following in the log file:
  9046.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  9047.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  9048.      000729 14:50:10  Can't init databases
  9049.  
  9050. This means that you didn't start `mysqld' with `--bdb-no-recover' and
  9051. Berkeley DB found something wrong with its log files when it tried to
  9052. recover your databases.  To be able to continue, you should move away
  9053. the old Berkeley DB log file from the database directory to some other
  9054. place, where you can later examine it.  The log files are named
  9055. `log.0000000001', where the number will increase over time.
  9056.  
  9057. If you are running `mysqld' with `BDB' table support and `mysqld' core
  9058. dumps at start this could be because of some problems with the `BDB'
  9059. recovery log.  In this case you can try starting `mysqld' with
  9060. `--bdb-no-recover'.  If this helps, then you should remove all `log.*'
  9061. files from the data directory and try starting `mysqld' again.
  9062.  
  9063. If you get the following error, it means that some other program (or
  9064. another `mysqld' server) is already using the TCP/IP port or socket
  9065. `mysqld' is trying to use:
  9066.  
  9067.      Can't start server: Bind on TCP/IP port: Address already in use
  9068. or:
  9069.      Can't start server: Bind on unix socket...
  9070.  
  9071. Use `ps' to make sure that you don't have another `mysqld' server
  9072. running.  If you can't find another server running, you can try to
  9073. execute the command `telnet your-host-name tcp-ip-port-number' and press
  9074. Enter a couple of times.  If you don't get an error message like
  9075. `telnet: Unable to connect to remote host: Connection refused',
  9076. something is using the TCP/IP port `mysqld' is trying to use.  See
  9077. *Note mysql_install_db:: and *Note Multiple servers::.
  9078.  
  9079. If `mysqld' is currently running, you can find out what path settings
  9080. it is using by executing this command:
  9081.  
  9082.      shell> mysqladmin variables
  9083.  
  9084. or:
  9085.  
  9086.      shell> mysqladmin -h 'your-host-name' variables
  9087.  
  9088. If you get `Errcode 13', which means `Permission denied', when starting
  9089. `mysqld' this means that you didn't have the right to read/create files
  9090. in the MySQL database or log directory. In this case you should either
  9091. start `mysqld' as the `root' user or change the permissions for the
  9092. involved files and directories so that you have the right to use them.
  9093.  
  9094. If `mysqld_safe' starts the server but you can't connect to it, you
  9095. should make sure you have an entry in `/etc/hosts' that looks like this:
  9096.  
  9097.      127.0.0.1       localhost
  9098.  
  9099. This problem occurs only on systems that don't have a working thread
  9100. library and for which MySQL must be configured to use MIT-pthreads.
  9101.  
  9102. If you can't get `mysqld' to start you can try to make a trace file to
  9103. find the problem. *Note Making trace files::.
  9104.  
  9105. If you are using `InnoDB' tables, refer to the `InnoDB'-specific startup
  9106. options.  *Note InnoDB start::.
  9107.  
  9108. If you are using `BDB' (Berkeley DB) tables, you should familiarise
  9109. yourself with the different `BDB'-specific startup options.  *Note BDB
  9110. start::.
  9111.  
  9112. Upgrading/Downgrading MySQL
  9113. ===========================
  9114.  
  9115. As a general rule, we recommend that when upgrading from one release
  9116. series to another, you should go to the next series rather than
  9117. skipping a series. For example, if you currently are running MySQL 3.23
  9118. and wish to upgrade to a newer series, upgrade to MySQL 4.0 rather than
  9119. to 4.1 or 5.0.
  9120.  
  9121. Before you do an upgrade, you should back up your old databases.
  9122.  
  9123. You can always move the MySQL format files and datafiles between
  9124. different versions on the same architecture as long as you have the
  9125. same base version of MySQL. The current base version is 4. If you
  9126. change the character set when running MySQL, you must run `myisamchk -r
  9127. -q --set-character-set=charset' on all tables.  Otherwise, your indexes
  9128. may not be ordered correctly, because changing the character set may
  9129. also change the sort order.
  9130.  
  9131. If you are cautious about using new versions, you can always rename
  9132. your old `mysqld' to something like `mysqld-old-version-number'.  If
  9133. your new `mysqld' then does something unexpected, you can simply shut
  9134. it down and restart with your old `mysqld'.
  9135.  
  9136. If, after an upgrade, you experience problems with recompiled client
  9137. programs, such as `Commands out of sync' or unexpected core dumps, you
  9138. probably have used an old header or library file when compiling your
  9139. programs.  In this case you should check the date for your `mysql.h'
  9140. file and `libmysqlclient.a' library to verify that they are from the new
  9141. MySQL distribution.  If not, please recompile your programs.
  9142.  
  9143. If problems occur, such as that the new `mysqld' server doesn't want to
  9144. start or that you can't connect without a password, check that you don't
  9145. have some old `my.cnf' file from your old installation.  You can check
  9146. this with: `program-name --print-defaults'.  If this outputs anything
  9147. other than the program name, you have an active `my.cnf' file that
  9148. affects server operation.
  9149.  
  9150. It is a good idea to rebuild and reinstall the Perl `DBD::mysql' module
  9151. whenever you install a new release of MySQL. The same applies to other
  9152. MySQL interfaces as well, such as the Python `MySQLdb' module.
  9153.  
  9154. Upgrading from Version 4.1 to 5.0
  9155. ---------------------------------
  9156.  
  9157. In general, you should do the following when upgrading to MySQL 5.0
  9158. from an earlier version:
  9159.  
  9160.    * Read the 5.0 news items to see what significant new features you
  9161.      can use in 5.0.  *Note News-5.0.x::.
  9162.  
  9163.    * If you are running MySQL Server on Windows, please also see *Note
  9164.      Windows upgrading::.
  9165.  
  9166.    * If you are using replication, please also see *Note Replication
  9167.      Upgrade:: for information on upgrading your replication setup.
  9168.  
  9169.    * MySQL 5.0 adds support for stored procedures. This support
  9170.      requires the `proc' table in the `mysql' database.  To create this
  9171.      file you should run the `mysql_fix_privilege_tables' script.  This
  9172.      is described in *Note Upgrading-grant-tables::.
  9173.  
  9174.  
  9175. Upgrading from Version 4.0 to 4.1
  9176. ---------------------------------
  9177.  
  9178. Several visible behaviors have changed between MySQL 4.0 and MySQL 4.1
  9179. to fix some critical bugs and make MySQL more compatible with the ANSI
  9180. SQL standard. These changes may affect your applications.
  9181.  
  9182. Some of the 4.1 behaviors can be tested in 4.0 before performing a full
  9183. upgrade to 4.1. We have added to later MySQL 4.0 releases (from 4.0.12
  9184. on) a `--new' startup option for `mysqld'.
  9185.  
  9186. This option gives you the 4.1 behavior for the most critical changes.
  9187. You can also enable these behaviors for a given client connection with
  9188. the `SET @@new=1' command, or turn them off if they are on with `SET
  9189. @@new=0'.
  9190.  
  9191. If you believe that some of the 4.1 changes will affect you, we
  9192. recommend that before upgrading to 4.1, you download the latest MySQL
  9193. 4.0 version and run it with the `--new' option by adding the following
  9194. to your config file:
  9195.  
  9196.      [mysqld-4.0]
  9197.      new
  9198.  
  9199. That way you can test the new behaviors in 4.0 to make sure that your
  9200. applications work with them. This will help you have a smooth painless
  9201. transition when you perform a full upgrade to 4.1 later.  Doing it the
  9202. above way will ensure that you don't accidently later run the 4.1
  9203. version with the `--new' option.
  9204.  
  9205. The following list describes changes that may affect applications and
  9206. that you should watch out for when upgrading to version 4.1:
  9207.  
  9208.    * `TIMESTAMP' is now returned as a string in `'YYYY-MM-DD HH:MM:SS''
  9209.      format.  (The `--new' option can be used from 4.0.12 on to make a
  9210.      4.0 server behave as 4.1 in this respect.)  If you want to have
  9211.      the value returned as a number (like Version 4.0 does) you should
  9212.      add +0 to `TIMESTAMP' columns when you retrieve them:
  9213.  
  9214.           mysql> SELECT ts_col + 0 FROM tbl_name;
  9215.  
  9216.      Display widths for `TIMESTAMP' columns are no longer supported.
  9217.      For example, if you declare a column as `TIMESTAMP(10)', the `(10)'
  9218.      is ignored.
  9219.  
  9220.      These changes were necessary for SQL standards compliance. In a
  9221.      future version, a further change will be made (backward compatible
  9222.      with this change), allowing the timestamp length to indicate the
  9223.      desired number of digits for fractions of a second.
  9224.  
  9225.    * Binary values such as `0xFFDF' now are assumed to be strings
  9226.      instead of numbers.  This fixes some problems with character sets
  9227.      where it's convenient to input a string as a binary value.  With
  9228.      this change, you should use `CAST()' if you want to compare binary
  9229.      values numerically as integers:
  9230.  
  9231.           mysql> SELECT CAST(0xFEFF AS UNSIGNED INTEGER) < CAST(0xFF AS UNSIGNED INTEGER);
  9232.                   -> 0
  9233.  
  9234.      If you don't use `CAST()', a lexical string comparison will be
  9235.      done:
  9236.  
  9237.           mysql> SELECT 0xFEFF < 0xFF;
  9238.                   -> 1
  9239.  
  9240.      Using binary items in a numeric context or comparing them using the
  9241.      `=' operator should work as before.  (The `--new' option can be
  9242.      used from 4.0.13 on to make a 4.0 server behave as 4.1 in this
  9243.      respect.)
  9244.  
  9245.    * For functions that produce a `DATE', `DATETIME', or `TIME' value,
  9246.      the result returned to the client now is fixed up to have a
  9247.      temporal type. For example, in MySQL 4.1, you get this result:
  9248.  
  9249.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  9250.               -> '2001-01-01 00:00:00'
  9251.  
  9252.      In MySQL 4.0, the result is different:
  9253.  
  9254.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  9255.               -> '2001-01-01'
  9256.  
  9257.    * `DEFAULT' values no longer can be specified for `AUTO_INCREMENT'
  9258.      columns. (In 4.0, a `DEFAULT' value is silently ignored; in 4.1,
  9259.      an error occurs).
  9260.  
  9261.    * `LIMIT' no longer accept negative arguments.  Use
  9262.      18446744073709551615 instead of -1.
  9263.  
  9264.    * `SERIALIZE' is no longer a valid mode value for the `sql_mode'
  9265.      variable.  You should use `SET TRANSACTION ISOLATION LEVEL
  9266.      SERIALIZABLE' instead. `SERIALIZE' is no longer valid for the
  9267.      `--sql-mode' option for `mysqld', either. Use
  9268.      `--transaction-isolation=SERIALIZABLE' instead.
  9269.  
  9270.    * All tables and string columns now have a character set.  *Note
  9271.      Charset::.  Character set information is displayed by `SHOW CREATE
  9272.      TABLE' and `mysqldump'.  (MySQL versions 4.0.6 and above can read
  9273.      the new dump files; older versions cannot.)
  9274.  
  9275.    * The table definition format used in `.frm' files has changed
  9276.      slightly in 4.1.  MySQL 4.0 versions from 4.0.11 on can read the
  9277.      new `.frm' format directly, but older versions cannot.  If you
  9278.      need to move tables from 4.1 to a version earlier than 4.0.11, you
  9279.      should use `mysqldump'.  *Note `mysqldump': mysqldump.
  9280.  
  9281.    * If you are running multiple servers on the same Windows machine,
  9282.      you should use a different `--shared_memory_base_name' option on
  9283.      all machines.
  9284.  
  9285.    * The interface to aggregated UDF functions has changed a bit. You
  9286.      must now declare a `xxx_clear()' function for each aggregate
  9287.      function `XXX()'.
  9288.  
  9289.  
  9290. In general, upgrading to 4.1 from an earlier MySQL version involves the
  9291. following steps:
  9292.  
  9293.    * Check the changes listed earlier in this section to see whether
  9294.      there are any that may affect your applications.
  9295.  
  9296.    * Read the 4.1 news items to see what significant new features you
  9297.      can use in 4.1.  *Note News-4.1.x::.
  9298.  
  9299.    * If you are running MySQL Server on Windows, please also see *Note
  9300.      Windows upgrading::.
  9301.  
  9302.      *Important note:* Early alpha Windows distributions for MySQL 4.1
  9303.      do not contain any installer program.  See *Note Windows binary
  9304.      installation:: for instructions on how to install such a
  9305.      distribution.
  9306.  
  9307.    * If you are using replication, please also see *Note Replication
  9308.      Upgrade:: for information on upgrading your replication setup.
  9309.  
  9310.    * After upgrading, update the grant tables to generate the new
  9311.      longer `Password' column that is needed for secure handling of
  9312.      passwords.  The procedure uses `mysql_fix_privilege_tables' and is
  9313.      described in *Note Upgrading-grant-tables::.
  9314.  
  9315.  
  9316. The password hashing mechanism has changed in 4.1 to provide better
  9317. security, but this may cause compatibility problems if you still have
  9318. clients that use the client library from 4.0 or earlier.  (It is very
  9319. likely that you will have 4.0 clients in situations where clients
  9320. connect from remote hosts that have not yet upgraded to 4.1).  The
  9321. following list indicates some possible upgrade strategies.  They
  9322. represent various tradeoffs between the goal of compatibility with old
  9323. clients and the goal of security.
  9324.  
  9325.    * Don't upgrade to 4.1. No behavior will change, but you cannot use
  9326.      any of the new features provided by the 4.1 client/server protocol,
  9327.      either.  (MySQL 4.1 has an extended client/server protocol that
  9328.      offers such features as prepared statements and multiple result
  9329.      sets.)  *Note C API Prepared statements::.
  9330.  
  9331.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  9332.      widen the `Password' column in the `user' table so that it can
  9333.      hold long password hashes.  But run the server with the
  9334.      `--old-passwords' option to provide backward compatibility that
  9335.      allows pre-4.1 clients to continue to connect to their short-hash
  9336.      accounts.  Eventually, when all your clients are upgraded to 4.1,
  9337.      you can stop using the `--old-passwords' server option. You can
  9338.      also change the passwords for your MySQL accounts to use the new
  9339.      more secure format.
  9340.  
  9341.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  9342.      widen the `Password' column in the `user' table.  If you know that
  9343.      all clients also have been upgraded to 4.1, don't run the server
  9344.      with the `--old-passwords' option.  Instead, change the passwords
  9345.      on all existing accounts so that they have the new format.  A
  9346.      pure-4.1 installation is the most secure.
  9347.  
  9348.  
  9349. Further background on password hashing with respect to client
  9350. authentication and password-changing operations may be found in *Note
  9351. Password hashing::.
  9352.  
  9353. Upgrading from Version 3.23 to 4.0
  9354. ----------------------------------
  9355.  
  9356. In general, you should do the following when upgrading to MySQL 4.0
  9357. from an earlier version:
  9358.  
  9359.    * After upgrading, update the grant tables to add new privileges and
  9360.      features.  The procedure uses the `mysql_fix_privilege_tables'
  9361.      script and is described in *Note Upgrading-grant-tables::.
  9362.  
  9363.    * Edit any MySQL startup scripts or configure files to not use any
  9364.      of the deprecated options described later in this section.
  9365.  
  9366.    * Convert your old `ISAM' files to `MyISAM' files with the
  9367.      `mysql_convert_table_format database' script. (This is a Perl
  9368.      script; it requires that DBI be installed.) To convert the tables
  9369.      in a given database, use this command:
  9370.  
  9371.           shell> mysql_convert_table_format database db_name
  9372.  
  9373.      Note that this should only be used if all tables in the given
  9374.      database are `ISAM' or `MyISAM' tables. To avoid converting tables
  9375.      of other types to `MyISAM', you can explicitly list the names of
  9376.      your `ISAM' tables after the database name on the command line.
  9377.      You can also issue a `ALTER TABLE table_name TYPE=MyISAM'
  9378.      statement for each `ISAM' table to convert it to `MyISAM'.
  9379.  
  9380.      To find out the table type for a given table, use this statement:
  9381.  
  9382.           mysql> SHOW TABLE STATUS LIKE 'tbl_name';
  9383.  
  9384.    * Ensure that you don't have any MySQL clients that use shared
  9385.      libraries (like the Perl `DBD::mysql' module). If you do, you
  9386.      should recompile them, because the data structures used in
  9387.      `libmysqlclient.so' have changed.  The same applies to other MySQL
  9388.      interfaces as well, such as the Python `MySQLdb' module.
  9389.  
  9390.    * If you are running MySQL Server on Windows, please also see *Note
  9391.      Windows upgrading::.
  9392.  
  9393.    * If you are using replication, please also see *Note Replication
  9394.      Upgrade:: for information on upgrading your replication setup.
  9395.  
  9396.  
  9397. MySQL 4.0 will work even if you don't do the above, but you will not be
  9398. able to use the new security privileges that MySQL 4.0 and you may run
  9399. into problems when upgrading later to MySQL 4.1 or newer.  The `ISAM'
  9400. file format still works in MySQL 4.0 but it's deprecated and will be
  9401. disabled (not compiled in by default) in MySQL 4.1. `MyISAM' tables
  9402. should be used instead.
  9403.  
  9404. Old clients should work with a Version 4.0 server without any problems.
  9405.  
  9406. Even if you do the above, you can still downgrade to MySQL 3.23.52 or
  9407. newer if you run into problems with the MySQL 4.0 series.  In this
  9408. case, you must use `mysqldump' to dump any tables that use full-text
  9409. indexes and reload the dump file into the 3.23 server.  This is
  9410. necessary because 4.0 uses a new format for full-text indexing.
  9411.  
  9412. The following is a more complete list that tells what you must watch out
  9413. for when upgrading to version 4.0:
  9414.  
  9415.    * MySQL 4.0 has a lot of new privileges in the `mysql.user' table.
  9416.      *Note `GRANT': GRANT.
  9417.  
  9418.      To get these new privileges to work, you must update the grant
  9419.      tables.  The procedure is described in *Note
  9420.      Upgrading-grant-tables::.  Until you do this, all users have the
  9421.      `SHOW DATABASES', `CREATE TEMPORARY TABLES', and `LOCK TABLES'
  9422.      privileges. `SUPER' and `EXECUTE' privileges take their value from
  9423.      `PROCESS'.  `REPLICATION SLAVE' and `REPLICATION CLIENT' take their
  9424.      values from `FILE'.
  9425.  
  9426.      If you have any scripts that create new users, you may want to
  9427.      change them to use the new privileges.  If you are not using
  9428.      `GRANT' commands in the scripts, this is a good time to change
  9429.      your scripts to use `GRANT' instead of modifying the grant tables
  9430.      directly..
  9431.  
  9432.      From version 4.0.2 on, the option `--safe-show-database' is
  9433.      deprecated (and no longer does anything). *Note Privileges
  9434.      options::.
  9435.  
  9436.      If you get `Access denied' errors for new users in version 4.0.2
  9437.      and up, you should check if you need some of the new grants that
  9438.      you didn't need before.  In particular, you will need `REPLICATION
  9439.      SLAVE' (instead of `FILE') for new slaves.
  9440.  
  9441.    * `safe_mysqld' is renamed to `mysqld_safe'.  For backward
  9442.      compatibility, binary distributions will for some time include
  9443.      `safe_mysqld' as a symlink to `mysqld_safe'.
  9444.  
  9445.    * InnoDB support is now included by default in binary distributions.
  9446.      If you build MySQL from source, InnoDB is configured in by default.
  9447.      If you do not use InnoDB and want to save memory when running a
  9448.      server that has InnoDB support enabled, use the `--skip-innodb'
  9449.      server startup option. To compile MySQL without InnoDB support,
  9450.      run `configure' with the `--without-innodb' option.
  9451.  
  9452.    * The startup parameters `myisam_max_extra_sort_file_size' and
  9453.      `myisam_max_extra_sort_file_size' are now given in bytes (they
  9454.      were given in megabytes before 4.0.3).
  9455.  
  9456.    * External system locking of `MyISAM'/`ISAM' files is now turned off
  9457.      by default.  Your can turn this on by doing `--external-locking'.
  9458.      (However, this is never needed for most users.)
  9459.  
  9460.    * The following startup variables/options have been renamed:
  9461.  
  9462.      *Old Name*                         *New Name*
  9463.      `myisam_bulk_insert_tree_size'     `bulk_insert_buffer_size'
  9464.      `query_cache_startup_type'         `query_cache_type'
  9465.      `record_buffer'                    `read_buffer_size'
  9466.      `record_rnd_buffer'                `read_rnd_buffer_size'
  9467.      `sort_buffer'                      `sort_buffer_size'
  9468.      `warnings'                         `log-warnings'
  9469.      `--err-log'                        `--log-error' (for `mysqld_safe')
  9470.  
  9471.      The startup options `record_buffer', `sort_buffer' and `warnings'
  9472.      will still work in MySQL 4.0 but are deprecated.
  9473.  
  9474.    * The following SQL variables have changed name.
  9475.  
  9476.      *Old Name*                         *New Name*
  9477.      `SQL_BIG_TABLES'                   `BIG_TABLES'
  9478.      `SQL_LOW_PRIORITY_UPDATES'         `LOW_PRIORITY_UPDATES'
  9479.      `SQL_MAX_JOIN_SIZE'                `MAX_JOIN_SIZE'
  9480.      `SQL_QUERY_CACHE_TYPE'             `QUERY_CACHE_TYPE'
  9481.      The old names still work in MySQL 4.0 but are deprecated.
  9482.  
  9483.    * You have to use `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=#' instead of
  9484.      `SET SQL_SLAVE_SKIP_COUNTER=#'.
  9485.  
  9486.    * The `mysqld' startup options `--skip-locking' and
  9487.      `--enable-locking' were renamed to `--skip-external-locking' and
  9488.      `--external-locking'.
  9489.  
  9490.    * `SHOW MASTER STATUS' now returns an empty set if binary logging is
  9491.      not enabled.
  9492.  
  9493.    * `SHOW SLAVE STATUS' now returns an empty set if slave is not
  9494.      initialized.
  9495.  
  9496.    * `mysqld' now has the option `--temp-pool' enabled by default as
  9497.      this gives better performance with some operating systems (most
  9498.      notably Linux).
  9499.  
  9500.    * `DOUBLE' and `FLOAT' columns now honor the `UNSIGNED' flag on
  9501.      storage (before, `UNSIGNED' was ignored for these columns).
  9502.  
  9503.    * `ORDER BY col_name DESC' sorts `NULL' values last, as of MySQL
  9504.      4.0.11. In 3.23 and in earlier 4.0 versions, this was not always
  9505.      consistent.
  9506.  
  9507.    * `SHOW INDEX' has two more columns (`Null' and `Index_type') than
  9508.      it had in 3.23.
  9509.  
  9510.    * `CHECK', `LOCALTIME' and `LOCALTIMESTAMP' are now reserved words.
  9511.  
  9512.    * The result of all bitwise operators (`|', `&', `<<', `>>', and
  9513.      `~')) is now unsigned.  This may cause problems if you are using
  9514.      them in a context where you want a signed result.  *Note Cast
  9515.      Functions::.
  9516.  
  9517.    * *Note:* when you use subtraction between integer values where one
  9518.      is of type `UNSIGNED', the result will be unsigned.  In other
  9519.      words, before upgrading to MySQL 4.0, you should check your
  9520.      application for cases where you are subtracting a value from an
  9521.      unsigned entity and want a negative answer or subtracting an
  9522.      unsigned value from an integer column. You can disable this
  9523.      behavior by using the `--sql-mode=NO_UNSIGNED_SUBTRACTION' option
  9524.      when starting `mysqld'.  *Note Cast Functions::.
  9525.  
  9526.    * To use `MATCH ... AGAINST (... IN BOOLEAN MODE)' with your tables,
  9527.      you need to rebuild them with `REPAIR TABLE table_name USE_FRM'.
  9528.  
  9529.    * `LOCATE()' and `INSTR()' are case-sensitive if one of the
  9530.      arguments is a binary string. Otherwise they are case-insensitive.
  9531.  
  9532.    * `STRCMP()' now uses the current character set when performing
  9533.      comparisons.  This makes the default comparison behavior case
  9534.      insensitive unless one or both of the operands are binary strings.
  9535.  
  9536.    * `HEX(string)' now returns the characters in `string' converted to
  9537.      hexadecimal.  If you want to convert a number to hexadecimal, you
  9538.      should ensure that you call `HEX()' with a numeric argument.
  9539.  
  9540.    * In 3.23, `INSERT INTO ... SELECT' always had `IGNORE' enabled.  In
  9541.      4.0.1, MySQL will stop (and possibly roll back) by default in case
  9542.      of an error unless you specify `IGNORE'.
  9543.  
  9544.    * The old C API functions `mysql_drop_db()', `mysql_create_db()', and
  9545.      `mysql_connect()' are no longer supported unless you compile MySQL
  9546.      with `CFLAGS=-DUSE_OLD_FUNCTIONS'.  However, it is preferable to
  9547.      change client programs to use the new 4.0 API instead.
  9548.  
  9549.    * In the `MYSQL_FIELD' structure, `length' and `max_length' have
  9550.      changed from `unsigned int' to `unsigned long'. This should not
  9551.      cause any problems, except that they may generate warning messages
  9552.      when used as arguments in the `printf()' class of functions.
  9553.  
  9554.    * You should use `TRUNCATE TABLE' when you want to delete all rows
  9555.      from a table and you don't need to obtain a count of the number of
  9556.      rows that were deleted.  (`DELETE FROM table_name' returns a row
  9557.      count in 4.0, and `TRUNCATE TABLE' is faster.)
  9558.  
  9559.    * You will get an error if you have an active `LOCK TABLES' or
  9560.      transaction when trying to execute `TRUNCATE TABLE' or `DROP
  9561.      DATABASE'.
  9562.  
  9563.    * You should use integers to store values in `BIGINT' columns
  9564.      (instead of using strings, as you did in MySQL 3.23).  Using
  9565.      strings will still work, but using integers is more efficient.
  9566.  
  9567.    * The format of `SHOW OPEN TABLES' has changed.
  9568.  
  9569.    * Multi-threaded clients should use `mysql_thread_init()' and
  9570.      `mysql_thread_end()'. *Note Threaded clients::.
  9571.  
  9572.    * If you want to recompile the Perl `DBD::mysql' module, use a recent
  9573.      version.  Version 2.9003 is recommended. Versions older than
  9574.      1.2218 should not be used because they use the deprecated
  9575.      `mysql_drop_db()' call.
  9576.  
  9577.    * `RAND(seed)' returns a different random number series in 4.0 than
  9578.      in 3.23; this was done to further differentiate `RAND(seed)' and
  9579.      `RAND(seed+1)'.
  9580.  
  9581.    * The default type returned by `IFNULL(A,B)' is now set to be the
  9582.      more 'general' of the types of `A' and `B'. (The
  9583.      general-to-specific order is string, `REAL' or `INTEGER').
  9584.  
  9585.  
  9586. Upgrading from Version 3.22 to 3.23
  9587. -----------------------------------
  9588.  
  9589. MySQL Version 3.23 supports tables of the new `MyISAM' type and the old
  9590. `ISAM' type.  You don't have to convert your old tables to use these
  9591. with Version 3.23.  By default, all new tables will be created with
  9592. type `MyISAM' (unless you start `mysqld' with the
  9593. `--default-table-type=isam' option). You can convert an `ISAM' table to
  9594. `MyISAM' format with `ALTER TABLE table_name TYPE=MyISAM' or the Perl
  9595. script `mysql_convert_table_format'.
  9596.  
  9597. Version 3.22 and 3.21 clients will work without any problems with a
  9598. Version 3.23 server.
  9599.  
  9600. The following list tells what you have to watch out for when upgrading
  9601. to Version 3.23:
  9602.  
  9603.    * All tables that use the `tis620' character set must be fixed with
  9604.      `myisamchk -r' or `REPAIR TABLE'.
  9605.  
  9606.    * If you do a `DROP DATABASE' on a symbolically linked database,
  9607.      both the link and the original database are deleted.  (This didn't
  9608.      happen in 3.22 because `configure' didn't detect the availability
  9609.      of the `readlink()' system call.)
  9610.  
  9611.    * `OPTIMIZE TABLE' now works only for `MyISAM' tables.  For other
  9612.      table types, you can use `ALTER TABLE' to optimize the table.
  9613.      During `OPTIMIZE TABLE', the table is now locked to prevent it
  9614.      from being used by other threads.
  9615.  
  9616.    * The MySQL client `mysql' is now by default started with the option
  9617.      `--no-named-commands (-g)'. This option can be disabled with
  9618.      `--enable-named-commands (-G)'. This may cause incompatibility
  9619.      problems in some cases--for example, in SQL scripts that use named
  9620.      commands without a semicolon.  Long format commands still work
  9621.      from the first line.
  9622.  
  9623.    * Date functions that work on parts of dates (like `MONTH()') will
  9624.      now return 0 for `0000-00-00' dates. (In MySQL 3.22, these
  9625.      functions returned `NULL'.)
  9626.  
  9627.    * If you are using the `german' character sort order for `ISAM'
  9628.      tables, you must repair them with `isamchk -r', because we have
  9629.      made some changes in the sort order.
  9630.  
  9631.    * The default return type of `IF()' now depends on both arguments
  9632.      and not only the first argument.
  9633.  
  9634.    * `AUTO_INCREMENT' columns should not be used to store negative
  9635.      numbers. The reason for this is that negative numbers caused
  9636.      problems when wrapping from -1 to 0.  You should not store 0 in
  9637.      `AUTO_INCREMENT' columns, either; `CHECK TABLE' will complain
  9638.      about 0 values because they may change if you dump and restore the
  9639.      table.  `AUTO_INCREMENT' for `MyISAM' tables is now handled at a
  9640.      lower level and is much faster than before. In addition, for
  9641.      `MyISAM' tables, old numbers are no longer reused, even if you
  9642.      delete rows from the table.
  9643.  
  9644.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  9645.      `THEN', and `WHEN' are now reserved words.
  9646.  
  9647.    * `FLOAT(X)' is now a true floating-point type and not a value with a
  9648.      fixed number of decimals.
  9649.  
  9650.    * When declaring columns using a `DECIMAL(length,dec)' type, the
  9651.      `length' argument no longer includes a place for the sign or the
  9652.      decimal point.
  9653.  
  9654.    * A `TIME' string must now be of one of the following formats:
  9655.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  9656.      `[[[[[H]H]H]H]MM]SS[.fraction]'.
  9657.  
  9658.    * `LIKE' now compares strings using the same character comparison
  9659.      rules as for the `=' operator.  If you require the old behavior,
  9660.      you can compile MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  9661.  
  9662.    * `REGEXP' is now case-insensitive if neither of the strings are
  9663.      binary strings.
  9664.  
  9665.    * When you check or repair `MyISAM' (`.MYI') tables, you should use
  9666.      the `CHECK TABLE' statement or the `myisamchk' command. For `ISAM'
  9667.      (`.ISM') tables, use the `isamchk' command.
  9668.  
  9669.    * If you want your `mysqldump' files to be compatible between MySQL
  9670.      Version 3.22 and Version 3.23, you should not use the `--opt' or
  9671.      `--all' option to `mysqldump'.
  9672.  
  9673.    * Check all your calls to `DATE_FORMAT()' to make sure there is a
  9674.      `%' before each format character.  (MySQL Version 3.22 and later
  9675.      already allowed this syntax.)
  9676.  
  9677.    * `mysql_fetch_fields_direct()' is now a function (it used to be a
  9678.      macro) and it returns a pointer to a `MYSQL_FIELD' instead of a
  9679.      `MYSQL_FIELD'.
  9680.  
  9681.    * `mysql_num_fields()' can no longer be used on a `MYSQL*' object
  9682.      (it's now a function that takes a `MYSQL_RES*' value as an
  9683.      argument). With a `MYSQL*' object, you should now use
  9684.      `mysql_field_count()' instead.
  9685.  
  9686.    * In MySQL Version 3.22, the output of `SELECT DISTINCT ...' was
  9687.      almost always sorted.  In Version 3.23, you must use `GROUP BY' or
  9688.      `ORDER BY' to obtain sorted output.
  9689.  
  9690.    * `SUM()' now returns `NULL' instead of 0 if there are no matching
  9691.      rows. This is required by SQL-99.
  9692.  
  9693.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  9694.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  9695.      expression as `NOT NULL' = `NULL'.
  9696.  
  9697.    * `LPAD()' and `RPAD()' now shorten the result string if it's longer
  9698.      than the length argument.
  9699.  
  9700. Upgrading from Version 3.21 to 3.22
  9701. -----------------------------------
  9702.  
  9703. Nothing that affects compatibility has changed between versions 3.21
  9704. and 3.22.  The only pitfall is that new tables that are created with
  9705. `DATE' type columns will use the new way to store the date. You can't
  9706. access these new columns from an old version of `mysqld'.
  9707.  
  9708. After installing MySQL Version 3.22, you should start the new server
  9709. and then run the `mysql_fix_privilege_tables' script. This will add the
  9710. new privileges that you need to use the `GRANT' command.  If you forget
  9711. this, you will get `Access denied' when you try to use `ALTER TABLE',
  9712. `CREATE INDEX', or `DROP INDEX'. The procedure for updating the grant
  9713. tables is described in *Note Upgrading-grant-tables::.
  9714.  
  9715. The C API interface to `mysql_real_connect()' has changed.  If you have
  9716. an old client program that calls this function, you must place a `0' for
  9717. the new `db' argument (or recode the client to send the `db' element
  9718. for faster connections).  You must also call `mysql_init()' before
  9719. calling `mysql_real_connect()'.  This change was done to allow the new
  9720. `mysql_options()' function to save options in the `MYSQL' handler
  9721. structure.
  9722.  
  9723. The `mysqld' variable `key_buffer' has been renamed to
  9724. `key_buffer_size', but you can still use the old name in your startup
  9725. files.
  9726.  
  9727. Upgrading from Version 3.20 to 3.21
  9728. -----------------------------------
  9729.  
  9730. If you are running a version older than Version 3.20.28 and want to
  9731. switch to Version 3.21, you need to do the following:
  9732.  
  9733. You can start the `mysqld' Version 3.21 server with the
  9734. `--old-protocol' option to use it with clients from a Version 3.20
  9735. distribution.  In this case, the new client function `mysql_errno()'
  9736. will not return any server error, only `CR_UNKNOWN_ERROR' (but it works
  9737. for client errors), and the server uses the old pre-3.21 `password()'
  9738. checking rather than the new method.
  9739.  
  9740. If you are *not* using the `--old-protocol' option to `mysqld', you
  9741. will need to make the following changes:
  9742.  
  9743.    * All client code must be recompiled. If you are using ODBC, you
  9744.      must get the new `MyODBC' 2.x driver.
  9745.  
  9746.    * The script `scripts/add_long_password' must be run to convert the
  9747.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  9748.  
  9749.    * All passwords must be reassigned in the `mysql.user' table (to get
  9750.      62-bit rather than 31-bit passwords).
  9751.  
  9752.    * The table format hasn't changed, so you don't have to convert any
  9753.      tables.
  9754.  
  9755.  
  9756. MySQL Version 3.20.28 and above can handle the new `user' table format
  9757. without affecting clients. If you have a MySQL version earlier than
  9758. Version 3.20.28, passwords will no longer work with it if you convert
  9759. the `user' table. So to be safe, you should first upgrade to at least
  9760. Version 3.20.28 and then upgrade to Version 3.21.
  9761.  
  9762. The new client code works with a 3.20.x `mysqld' server, so if you
  9763. experience problems with 3.21.x, you can use the old 3.20.x server
  9764. without having to recompile the clients again.
  9765.  
  9766. If you are not using the `--old-protocol' option to `mysqld', old
  9767. clients will be unable to connect and will issue the following error
  9768. message:
  9769.  
  9770.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  9771.  
  9772. The Perl DBI interface also supports the old `mysqlperl' interface.
  9773. The only change you have to make if you use `mysqlperl' is to change
  9774. the arguments to the `connect()' function.  The new arguments are:
  9775. `host', `database', `user', and `password' (note that the `user' and
  9776. `password' arguments have changed places).
  9777.  
  9778. The following changes may affect queries in old applications:
  9779.  
  9780.    * `HAVING' must now be specified before any `ORDER BY' clause.
  9781.  
  9782.    * The parameters to `LOCATE()' have been swapped.
  9783.  
  9784.    * There are some new reserved words. The most notable are `DATE',
  9785.      `TIME', and `TIMESTAMP'.
  9786.  
  9787.  
  9788. Upgrading MySQL under Windows
  9789. -----------------------------
  9790.  
  9791. When upgrading MySQL under Windows, please follow these steps:
  9792.  
  9793.   1. Download the latest Windows distribution of MySQL.
  9794.  
  9795.   2. Choose a time of day with low usage, where a maintenance break is
  9796.      acceptable.
  9797.  
  9798.   3. Alert the users that still are active about the maintenance break.
  9799.  
  9800.   4. Stop the running MySQL Server (for example, with `NET STOP MySQL'
  9801.      or with the `Services' utility if you are running MySQL as a
  9802.      service, or with `mysqladmin shutdown' otherwise).
  9803.  
  9804.   5. Exit the `WinMySQLAdmin' program if it is running.
  9805.  
  9806.   6. Run the installation script of the Windows distribution, by
  9807.      clicking the "Install" button in WinZip and following the
  9808.      installation steps of the script.
  9809.  
  9810.      *Important note:* Early alpha Windows distributions for MySQL 4.1
  9811.      do not contain any installer program.  See *Note Windows binary
  9812.      installation:: for instructions on how to install such a
  9813.      distribution.
  9814.  
  9815.   7. You may either overwrite your old MySQL installation (usually
  9816.      located at `C:\mysql'), or install it into a different directory,
  9817.      such as `C:\mysql4'. Overwriting the old installation is
  9818.      recommended.
  9819.  
  9820.   8. Restart the server (for example, with `NET START MySQL' if you run
  9821.      MySQL as a service, or by invoking `mysqld' directly otherwise).
  9822.  
  9823.   9. Update the grant tables. The procedure is described in *Note
  9824.      Upgrading-grant-tables::.
  9825.  
  9826.  
  9827. Possible error situations:
  9828.      A system error has occurred.
  9829.      System error 1067 has occurred.
  9830.      The process terminated unexpectedly.
  9831.  
  9832. This error means that your `my.cnf' file (by default `C:\my.cnf')
  9833. contains an option that cannot be recognized by MySQL. You can verify
  9834. that this is the case by trying to restart MySQL with the `my.cnf' file
  9835. renamed, for example, to `my_cnf.old' to prevent the server from using
  9836. it.  Once you have verified it, you need to identify which option is
  9837. the culprit. Create a new `my.cnf' file and move parts of the old file
  9838. to it (restarting the server after you move each part) until you
  9839. determine which option causes server startup to fail.
  9840.  
  9841. Upgrading the Grant Tables
  9842. --------------------------
  9843.  
  9844. Some releases introduce changes to the structure of the grant tables
  9845. (the tables in the `mysql' database) to add new  privileges or
  9846. features. To make sure that your grant tables are current when you
  9847. update to a new version of MySQL, you should update your grant tables
  9848. as well.
  9849.  
  9850. On Unix or Unix-like systems, update the grant tables by running the
  9851. `mysql_fix_privilege_tables' script:
  9852.  
  9853.      shell> mysql_fix_privilege_tables
  9854.  
  9855. You must run this script while the server is running. It attempts to
  9856. connect to the server running on the local host as `root'.  If your
  9857. `root' account requires a password, indicate the password on the
  9858. command line.  For MySQL 4.1 and up, specify the password like this:
  9859.  
  9860.      shell> mysql_fix_privilege_tables --password=root_password
  9861.  
  9862. Prior to MySQL 4.1, specify the password like this:
  9863.  
  9864.      shell> mysql_fix_privilege_tables root_password
  9865.  
  9866. The `mysql_fix_privilege_tables' script performs any actions necessary
  9867. to convert your grant tables to the current format. You may see some
  9868. `Duplicate column name' warnings as it runs; they can be ignored.
  9869.  
  9870. After running the script, stop the server and restart it.
  9871.  
  9872. On Windows systems, there isn't an easy way to update the grant tables
  9873. until MySQL 4.0.15.  From version 4.0.15 on, MySQL distributions
  9874. include a `mysql_fix_privilege_tables.sql' SQL script that you can run
  9875. using the `mysql' client.  If your MySQL installation is located at
  9876. `C:\mysql', the commands look like this:
  9877.  
  9878.      C:\mysql\bin> mysql -u root -p mysql
  9879.      
  9880.      mysql> SOURCE C:\mysql\scripts\mysql_fix_privilege_tables.sql
  9881.  
  9882. If your installation is located in some other directory, adjust the
  9883. pathnames appropriately.
  9884.  
  9885. The `mysql' command will prompt you for the `root' password; enter it
  9886. when prompted.
  9887.  
  9888. As with the Unix procedure, you may see some `Duplicate column name'
  9889. warnings as `mysql' processes the statements in the
  9890. `mysql_fix_privilege_tables.sql' script; they can be ignored.
  9891.  
  9892. After running the script, stop the server and restart it.
  9893.  
  9894. Copying MySQL Databases to Another Machine
  9895. ------------------------------------------
  9896.  
  9897. If you are using MySQL Version 3.23 or later, you can copy the `.frm',
  9898. `.MYI', and `.MYD' files for `MyISAM' tables between different
  9899. architectures that support the same floating-point format.  (MySQL
  9900. takes care of any byte-swapping issues.)  *Note `MyISAM' Tables: MyISAM.
  9901.  
  9902. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  9903. respectively) are architecture-dependent and in some cases operating
  9904. system-dependent.  If you want to move your applications to another
  9905. machine that has a different architecture or operating system than your
  9906. current machine, you should not try to move a database by simply copying
  9907. the files to the other machine. Use `mysqldump' instead.
  9908.  
  9909. By default, `mysqldump' will create a file containing SQL statements.
  9910. You can then transfer the file to the other machine and feed it as input
  9911. to the `mysql' client.
  9912.  
  9913. Try `mysqldump --help' to see what options are available.  If you are
  9914. moving the data to a newer version of MySQL, you should use `mysqldump
  9915. --opt' to take advantage of any optimizations that result in a dump
  9916. file that is smaller and can be processed faster.
  9917.  
  9918. The easiest (although not the fastest) way to move a database between
  9919. two machines is to run the following commands on the machine on which
  9920. the database is located:
  9921.  
  9922.      shell> mysqladmin -h 'other hostname' create db_name
  9923.      shell> mysqldump --opt db_name \
  9924.              | mysql -h 'other hostname' db_name
  9925.  
  9926. If you want to copy a database from a remote machine over a slow
  9927. network, you can use:
  9928.  
  9929.      shell> mysqladmin create db_name
  9930.      shell> mysqldump -h 'other hostname' --opt --compress db_name \
  9931.              | mysql db_name
  9932.  
  9933. You can also store the result in a file, then transfer the file to the
  9934. target machine and load the file into the database there.  For example,
  9935. you can dump a database to a file on the source machine like this:
  9936.  
  9937.      shell> mysqldump --quick db_name | gzip > db_name.contents.gz
  9938.  
  9939. (The file created in this example is compressed.) Transfer the file
  9940. containing the database contents to the target machine and run these
  9941. commands there:
  9942.  
  9943.      shell> mysqladmin create db_name
  9944.      shell> gunzip < db_name.contents.gz | mysql db_name
  9945.  
  9946. You can also use `mysqldump' and `mysqlimport' to transfer the database.
  9947. For big tables, this is much faster than simply using `mysqldump'.  In
  9948. the following commands, `DUMPDIR' represents the full pathname of the
  9949. directory you use to store the output from `mysqldump'.
  9950.  
  9951. First, create the directory for the output files and dump the database:
  9952.  
  9953.      shell> mkdir DUMPDIR
  9954.      shell> mysqldump --tab=DUMPDIR db_name
  9955.  
  9956. Then transfer the files in the `DUMPDIR' directory to some corresponding
  9957. directory on the target machine and load the files into MySQL there:
  9958.  
  9959.      shell> mysqladmin create db_name           # create database
  9960.      shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
  9961.      shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables
  9962.  
  9963. Also, don't forget to copy the `mysql' database because that's where the
  9964. grant tables (`user', `db', `host') are stored.  You may have to run
  9965. commands as the MySQL `root' user on the new machine until you have the
  9966. `mysql' database in place.
  9967.  
  9968. After you import the `mysql' database on the new machine, execute
  9969. `mysqladmin flush-privileges' so that the server reloads the grant table
  9970. information.
  9971.  
  9972. Operating System Specific Notes
  9973. ===============================
  9974.  
  9975. Linux Notes
  9976. -----------
  9977.  
  9978. This section discusses issues that have been found to occur on Linux.
  9979. The first few subsections describe general operating sytem-related
  9980. issues, problems that can occur when using binary or source
  9981. distributions, and post-installation issues. The remaining subsections
  9982. discuss problems that occur with Linux on specific platforms.
  9983.  
  9984. Note that most of these problems occur on older versions of Linux. If
  9985. you are running a recent version, you likely will see none of them.
  9986.  
  9987. Linux Operating System Notes
  9988. ............................
  9989.  
  9990. MySQL needs at least Linux Version 2.0.
  9991.  
  9992. *Warning:* We have seen some strange problems with Linux 2.2.14 and
  9993. MySQL on SMP systems.  We also have reports from some MySQL users that
  9994. they have encountered serious stability problems using MySQL with
  9995. kernel 2.2.14.  If you are using this kernel, you should upgrade to
  9996. 2.2.19 (or newer) or to a 2.4 kernel.  If you have a multiple-CPU box,
  9997. then you should seriously consider using 2.4 as this will give you a
  9998. significant speed boost.  Your system also will be more stable.
  9999.  
  10000. When using LinuxThreads you will see a minimum of three `mysqld'
  10001. processes running.  These are in fact threads.  There will be one
  10002. thread for the LinuxThreads manager, one thread to handle connections,
  10003. and one thread to handle alarms and signals.
  10004.  
  10005. Linux Binary Distribution Notes
  10006. ...............................
  10007.  
  10008. The Linux-Intel binary and RPM releases of MySQL are configured for the
  10009. highest possible speed.  We are always trying to use the fastest stable
  10010. compiler available.
  10011.  
  10012. The binary release is linked with `-static', which means you do not
  10013. normally need to worry about which version of the system libraries you
  10014. have. You need not install LinuxThreads, either.  A program linked with
  10015. `-static' is slightly larger than a dynamically linked program, but
  10016. also slightly faster (3-5%).  However, one problem with a statically
  10017. linked program is that you can't use user-defined functions (UDFs).  If
  10018. you are going to write or use UDFs (this is something for C or C++
  10019. programmers only), you must compile MySQL yourself using dynamic
  10020. linking.
  10021.  
  10022. A known issue with binary distributions is that on older Linux systems
  10023. that use `libc' (such as Red Hat 4.x or Slackware), you will get some
  10024. non-fatal problems with hostname resolution. If your system uses `libc'
  10025. rather than `glibc2', you probably will encounter some difficulties
  10026. with hostname resolution and `getpwnam()'. This happens because `glibc'
  10027. unfortunately depends on some external libraries to implement hostname
  10028. resolution and `getpwent()', even when compiled with `-static').  These
  10029. problems manifest themselves in two ways:
  10030.  
  10031.    * You probably will see  the following error message when you run
  10032.      `mysql_install_db':
  10033.  
  10034.           Sorry, the host 'xxxx' could not be looked up
  10035.  
  10036.      You can deal with this by executing `mysql_install_db --force',
  10037.      which will not execute the `resolveip' test in `mysql_install_db'.
  10038.      The downside is that you can't use hostnames in the grant tables:
  10039.      Except for `localhost', you must use IP numbers instead.  If you
  10040.      are using an old version of MySQL that doesn't support `--force',
  10041.      you must manually remove the `resolveip' test in `mysql_install'
  10042.      using an editor.
  10043.  
  10044.    * You also may see the following error when you try to run `mysqld'
  10045.      with the `--user' option:
  10046.  
  10047.           getpwnam: No such file or directory
  10048.  
  10049.      To work around this, start `mysqld' with `su' rather than by
  10050.      specifying the `--user' option. This causes the system itself to
  10051.      change the user ID of the `mysqld' process so that `mysqld' need
  10052.      not do so.
  10053.  
  10054.  
  10055. Another solution, which solves both problems, is to not use a binary
  10056. distribution.  Get a MySQL source distribution (an RPM or the `tar.gz'
  10057. distribution) and install that instead.
  10058.  
  10059. On some Linux 2.2 versions, you may get the error `Resource temporarily
  10060. unavailable' when clients make a lot of new connections to a `mysqld'
  10061. server over TCP/IP.  The problem is that Linux has a delay between the
  10062. time that you close a TCP/IP socket and the time that the system
  10063. actually frees it.  There is only room for a finite number of TCP/IP
  10064. slots, so you will encounter the resource-unavailable error if clients
  10065. attempt too many new TCP/IP connections during a short time. For
  10066. example, you may see the error when you run the MySQL `test-connect'
  10067. benchmark over TCP/IP.
  10068.  
  10069. We have inquired about this problem a few times on different Linux
  10070. mailing lists but have never been able to find a suitable resolution.
  10071. The only known "fix" is for the clients to use persistent connections,
  10072. or, if you are running the database server and clients on the same
  10073. machine, to use Unix socket file connections rather than TCP/IP
  10074. connections.
  10075.  
  10076. Linux Source Distribution Notes
  10077. ...............................
  10078.  
  10079. The following notes regarding `glibc' apply only to the situation when
  10080. you build MySQL yourself. If you are running Linux on an x86 machine,
  10081. in most cases it is much better for you to just use our binary. We link
  10082. our binaries against the best patched version of `glibc' we can come up
  10083. with and with the best compiler options, in an attempt to make it
  10084. suitable for a high-load server.  For a typical user, even for setups
  10085. with a lot of concurrent connections or tables exceeding the 2G limit,
  10086. our binary is the best choice in most cases.  After reading the
  10087. following text, if you are in doubt about what to do, try our binary
  10088. first to see whether it meets your needs.  If you discover that our
  10089. binary is not good enough, then you may want to try your own build.  In
  10090. that case, we would appreciate a note about it, so we can build a
  10091. better binary next time.
  10092.  
  10093. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  10094. version that doesn't have `glibc2', you must install LinuxThreads
  10095. before trying to compile MySQL.   You can get LinuxThreads at
  10096. `http://www.mysql.com/downloads/os-linux.html'.
  10097.  
  10098. Note that `glibc' versions before and including Version 2.1.1 have a
  10099. fatal bug in `pthread_mutex_timedwait()' handling, which is used when
  10100. you issue `INSERT DELAYED' statements.  We recommend that you not use
  10101. `INSERT DELAYED' before upgrading `glibc'.
  10102.  
  10103. Note that Linux kernel and the LinuxThread library can by default only
  10104. have 1024 threads.  If you plan to have more than 1000 concurrent
  10105. connections, you will need to make some changes to LinuxThreads:
  10106.  
  10107.    * Increase `PTHREAD_THREADS_MAX' in
  10108.      `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  10109.      `STACK_SIZE' in `linuxthreads/internals.h' to 256 KB. The paths
  10110.      are relative to the root of `glibc'. (Note that MySQL will not be
  10111.      stable with around 600-1000 connections if `STACK_SIZE' is the
  10112.      default of 2 MB.)
  10113.  
  10114.    * Recompile LinuxThreads to produce a new `libpthread.a' library,
  10115.      and relink MySQL against it.
  10116.  
  10117.  
  10118. The page `http://www.volano.com/linuxnotes.html' contains additional
  10119. information about circumventing thread limits in LinuxThreads.
  10120.  
  10121. There is another issue that greatly hurts MySQL performance, especially
  10122. on SMP systems.  The mutex implementation in LinuxThreads in `glibc'
  10123. 2.1 is very bad for programs with many threads that hold the mutex only
  10124. for a short time.  This produces a paradoxical result: If you link
  10125. MySQL against an unmodified LinuxThreads, removing processors from an
  10126. SMP actually improves MySQL performance in many cases.  We have made a
  10127. patch available for `glibc' 2.1.3 to correct this behavior
  10128. (`http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch').
  10129.  
  10130. With `glibc' 2.2.2, MySQL version 3.23.36 will use the adaptive mutex,
  10131. which is much better than even the patched one in `glibc' 2.1.3. Be
  10132. warned, however, that under some conditions, the current mutex code in
  10133. `glibc' 2.2.2 overspins, which hurts MySQL performance. The likelihood
  10134. that this condition will occur can be reduced by renicing the `mysqld'
  10135. process to the highest priority. We have also been able to correct the
  10136. overspin behavior with a patch, available at
  10137. `http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch'.  It
  10138. combines the correction of overspin, maximum number of threads, and
  10139. stack spacing all in one. You will need to apply it in the
  10140. `linuxthreads' directory with `patch -p0
  10141. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  10142. form in future releases of `glibc' 2.2. In any case, if you link
  10143. against `glibc' 2.2.2, you still need to correct `STACK_SIZE' and
  10144. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  10145. some more acceptable values for high-load MySQL setup in the future, so
  10146. that the commands needed to produce your own build can be reduced to
  10147. `./configure; make; make install'.
  10148.  
  10149. We recommend that you use the above patches to build a special static
  10150. version of `libpthread.a' and use it only for statically linking
  10151. against MySQL. We know that the patches are safe for MySQL and
  10152. significantly improve its performance, but we cannot say anything about
  10153. other applications. If you link other applications that require
  10154. LinuxThreads against the patched static version of the library, or
  10155. build a patched shared version and install it on your system, you are
  10156. doing it at your own risk.
  10157.  
  10158. If you experience any strange problems during the installation of
  10159. MySQL, or with some common utilities hanging, it is very likely that
  10160. they are either library or compiler related. If this is the case, using
  10161. our binary will resolve them.
  10162.  
  10163. If you link your own MySQL client programs, you may see the following
  10164. error at runtime:
  10165.  
  10166.      ld.so.1: fatal: libmysqlclient.so.#:
  10167.      open failed: No such file or directory
  10168.  
  10169. This problem can be avoided by one of the following methods:
  10170.  
  10171.    * Link clients with the `-Wl,r/full-path-to-libmysqlclient.so' flag
  10172.      rather than with `-Lpath').
  10173.  
  10174.    * Copy `libmysqclient.so' to `/usr/lib'.
  10175.  
  10176.    * Add the pathname of the directory where `libmysqlclient.so' is
  10177.      located to the `LD_RUN_PATH' environment variable before running
  10178.      your client.
  10179.  
  10180. If you are using the Fujitsu compiler (`fcc/FCC'), you will have some
  10181. problems compiling MySQL because the Linux header files are very `gcc'
  10182. oriented.  The following `configure' line should work with `fcc/FCC':
  10183.  
  10184.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE \
  10185.          -DCONST=const -DNO_STRTOLL_PROTO" \
  10186.      CXX=FCC CXXFLAGS="-O -K fast -K lib \
  10187.          -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE \
  10188.          -DCONST=const -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO \
  10189.          '-D_EXTERN_INLINE=static __inline'" \
  10190.      ./configure \
  10191.          --prefix=/usr/local/mysql --enable-assembler \
  10192.          --with-mysqld-ldflags=-all-static --disable-shared \
  10193.          --with-low-memory
  10194.  
  10195. Linux Post-installation Notes
  10196. .............................
  10197.  
  10198. `mysql.server' can be found in the `share/mysql' directory under the
  10199. MySQL installation directory or in the `support-files' directory of the
  10200. MySQL source tree.  You can install it as `/etc/init.d/mysql' for
  10201. automatic MySQL startup and shutdown.  *Note Automatic start::.
  10202.  
  10203. If MySQL can't open enough files or connections, it may be that you
  10204. haven't configured Linux to handle enough files.
  10205.  
  10206. In Linux 2.2 and onward, you can check the number of allocated file
  10207. handles as follows:
  10208.  
  10209.      shell> cat /proc/sys/fs/file-max
  10210.      shell> cat /proc/sys/fs/dquot-max
  10211.      shell> cat /proc/sys/fs/super-max
  10212.  
  10213. If you have more than 16 MB of memory, you should add something like the
  10214. following to your init scripts (for example, `/etc/init.d/boot.local'
  10215. on SuSE Linux):
  10216.  
  10217.      echo 65536 > /proc/sys/fs/file-max
  10218.      echo 8192 > /proc/sys/fs/dquot-max
  10219.      echo 1024 > /proc/sys/fs/super-max
  10220.  
  10221. You can also run the `echo' commands from the command line as `root',
  10222. but these settings will be lost the next time your computer reboots.
  10223.  
  10224. Alternatively, you can set these parameters on bootup by using the
  10225. `sysctl' tool, which is used by many Linux distributions (SuSE has
  10226. added it as well, beginning with SuSE Linux 8.0). Just put the following
  10227. values into a file named `/etc/sysctl.conf':
  10228.  
  10229.      # Increase some values for MySQL
  10230.      fs.file-max = 65536
  10231.      fs.dquot-max = 8192
  10232.      fs.super-max = 1024
  10233.  
  10234. You should also add the following to `/etc/my.cnf':
  10235.  
  10236.      [mysqld_safe]
  10237.      open-files-limit=8192
  10238.  
  10239. This should allow the server a limit of 8192 for the combined number of
  10240. connections and open files.
  10241.  
  10242. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  10243. stacks in the address space.  It needs to be large enough so that there
  10244. will be plenty of room for the stack of each individual thread, but
  10245. small enough to keep the stack of some threads from running into the
  10246. global `mysqld' data.  Unfortunately, as we have experimentally
  10247. discovered, the Linux implementation of `mmap()' will successfully
  10248. unmap an already mapped region if you ask it to map out an address
  10249. already in use, zeroing out the data on the entire page, instead of
  10250. returning an error.  So, the safety of `mysqld' or any other threaded
  10251. application depends on "gentlemanly" behavior of the code that creates
  10252. threads.  The user must take measures to make sure the number of
  10253. running threads at any time is sufficiently low for thread stacks to
  10254. stay away from the global heap.  With `mysqld', you should enforce this
  10255. behavior by setting a reasonable value for the `max_connections'
  10256. variable.
  10257.  
  10258. If you build MySQL yourself, you can patch LinuxThreads for better
  10259. stack use.  *Note Source notes-Linux::.  If you do not want to patch
  10260. LinuxThreads, you should set `max_connections' to a value no higher
  10261. than 500.  It should be even less if you have a large key buffer,  large
  10262. heap tables, or some other things that make `mysqld' allocate a lot of
  10263. memory, or if you are running a 2.2 kernel with a 2G patch. If you are
  10264. using our binary or RPM version 3.23.25 or later, you can safely set
  10265. `max_connections' at 1500, assuming no large key buffer or heap tables
  10266. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  10267. the more threads you can safely create.  We recommend values between
  10268. 128K and 256K.
  10269.  
  10270. If you use a lot of concurrent connections, you may suffer from a
  10271. "feature" in the 2.2 kernel that attempts to prevent fork bomb attacks
  10272. by penalizing a process for forking or cloning a child.  This causes
  10273. MySQL not to scale well as you increase the number of concurrent
  10274. clients.  On single-CPU systems, we have seen this manifested as very
  10275. slow thread creation: It may take a long time to connect to MySQL (as
  10276. long as 1 minute), and it may take just as long to shut it down.  On
  10277. multiple-CPU systems, we have observed a gradual drop in query speed as
  10278. the number of clients increases.  In the process of trying to find a
  10279. solution, we have received a kernel patch from one of our users who
  10280. claimed it made a lot of difference for his site.  The patch is
  10281. available at `http://www.mysql.com/Downloads/Patches/linux-fork.patch'.
  10282. We have now done rather extensive testing of this patch on both
  10283. development and production systems.  It has significantly improved
  10284. MySQL performance without causing any problems and we now recommend it
  10285. to our users who still run high-load servers on 2.2 kernels.
  10286.  
  10287. This issue has been fixed in the 2.4 kernel, so if you are not satisfied
  10288. with the current performance of your system, rather than patching your
  10289. 2.2 kernel, it might be easier to upgrade to 2.4. On SMP systems,
  10290. upgrading also will give you a nice SMP boost in addition to fixing the
  10291. fairness bug.
  10292.  
  10293. We have tested MySQL on the 2.4 kernel on a 2-CPU machine and found
  10294. MySQL scales *much* better. There was virtually no slowdown on query
  10295. throughput all the way up to 1000 clients, and the MySQL scaling factor
  10296. (computed as the ratio of maximum throughput to the throughput for one
  10297. client) was 180%.  We have observed similar results on a 4-CPU system:
  10298. Virtually no slowdown as the number of clients was increased up to 1000,
  10299. and a 300% scaling factor. Based on these results, for a high-load SMP
  10300. server using a 2.2 kernel, we definitely recommend upgrading to the 2.4
  10301. kernel at this point.
  10302.  
  10303. We have discovered that it is essential to run `mysqld' process with
  10304. the highest possible priority on the 2.4 kernel to achieve maximum
  10305. performance.  This can be done by adding a `renice -20 $$' command to
  10306. `mysqld_safe'. In our testing on a 4-CPU machine, increasing the
  10307. priority gave 60% throughput increase with 400 clients.
  10308.  
  10309. We are currently also trying to collect more information on how well
  10310. MySQL performs on 2.4 kernel on 4-way and 8-way systems. If you have
  10311. access such a system and have done some benchmarks, please send an email
  10312. message to <benchmarks@mysql.com> with the results. We will review them
  10313. for inclusion in the manual.
  10314.  
  10315. If you see a dead `mysqld' server process with `ps', this usually means
  10316. that you have found a bug in MySQL or you have a corrupted table. *Note
  10317. Crashing::.
  10318.  
  10319. To get a core dump on Linux if `mysqld' dies with a `SIGSEGV' signal,
  10320. you can start `mysqld' with the `--core-file' option.  Note that you
  10321. also probably need to raise the `core file size' by adding `ulimit -c
  10322. 1000000' to `mysqld_safe' or starting `mysqld_safe' with
  10323. `--core-file-size=1000000'.  *Note `mysqld_safe': mysqld_safe.
  10324.  
  10325. Linux x86 Notes
  10326. ...............
  10327.  
  10328. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  10329. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  10330. have been some problems with the `glibc' RPMs from Red Hat, so if you
  10331. have problems, check whether there are any updates.  The `glibc'
  10332. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  10333.  
  10334. If you are using Red Hat 8.0 or a new `glibc' 2.2.x library, you may see
  10335. `mysqld' die in `gethostbyaddr()'. This happens because the new `glibc'
  10336. library requires a stack size greater than 128K for this call.  To fix
  10337. the problem, start `mysqld' with the `--thread-stack=192K' option.
  10338. (Use `-O thread_stack=192K' before MySQL 4.)  This stack size is now
  10339. the default on MySQL 4.0.10 and above, so you should not see the
  10340. problem.
  10341.  
  10342. If you are using `gcc' 3.0 and above to compile MySQL, you must install
  10343. the `libstdc++v3' library before compiling MySQL; if you don't do this,
  10344. you will get an error about a missing `__cxa_pure_virtual' symbol
  10345. during linking.
  10346.  
  10347. On some older Linux distributions, `configure' may produce an error
  10348. like this:
  10349.  
  10350.      Syntax error in sched.h. Change _P to __P in the
  10351.      /usr/include/sched.h file.
  10352.      See the Installation chapter in the Reference Manual.
  10353.  
  10354. Just do what the error message says. Add an extra underscore to the
  10355. `_P' macro name that has only one underscore, then try again.
  10356.  
  10357. You may get some warnings when compiling. Those shown here can be
  10358. ignored:
  10359.  
  10360.      mysqld.cc -o objs-thread/mysqld.o
  10361.      mysqld.cc: In function `void init_signals()':
  10362.      mysqld.cc:315: warning: assignment of negative value `-1' to
  10363.      `long unsigned int'
  10364.      mysqld.cc: In function `void * signal_hand(void *)':
  10365.      mysqld.cc:346: warning: assignment of negative value `-1' to
  10366.      `long unsigned int'
  10367.  
  10368. If `mysqld' always dumps core when it starts, the problem may be that
  10369. you have an old `/lib/libc.a'.  Try renaming it, then remove
  10370. `sql/mysqld' and do a new `make install' and try again.  This problem
  10371. has been reported on some Slackware installations.
  10372.  
  10373. If you get the following error when linking `mysqld', it means that
  10374. your `libg++.a' is not installed correctly:
  10375.  
  10376.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  10377.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  10378.  
  10379. You can avoid using `libg++.a' by running `configure' like this:
  10380.  
  10381.      shell> CXX=gcc ./configure
  10382.  
  10383. Linux SPARC Notes
  10384. .................
  10385.  
  10386. In some implementations, `readdir_r()' is broken.  The symptom is that
  10387. the `SHOW DATABASES' statement always returns an empty set.  This can
  10388. be fixed by removing `HAVE_READDIR_R' from `config.h' after configuring
  10389. and before compiling.
  10390.  
  10391. Linux Alpha Notes
  10392. .................
  10393.  
  10394. MySQL Version 3.23.12 is the first MySQL version that is tested on
  10395. Linux-Alpha.  If you plan to use MySQL on Linux-Alpha, you should
  10396. ensure that you have this version or newer.
  10397.  
  10398. We have tested MySQL on Alpha with our benchmarks and test suite, and
  10399. it appears to work nicely.
  10400.  
  10401. We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP,
  10402. kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler
  10403. (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.
  10404.  
  10405. You can find the above compilers at
  10406. `http://www.support.compaq.com/alpha-tools/'.  By using these compilers
  10407. rather than `gcc', we get about 9-14% better MySQL performance.
  10408.  
  10409. Note that until MySQL version 3.23.52 and 4.0.2, we optimized the
  10410. binary for the current CPU only (by using the `-fast' compile option).
  10411. This means that for older versions, you can use our Alpha binaries only
  10412. if you have an Alpha EV6 processor.
  10413.  
  10414. For all following releases, we added the `-arch generic' flag to our
  10415. compile options, which makes sure the binary runs on all Alpha
  10416. processors. We also compile statically to avoid library problems.  The
  10417. `configure' command looks like this:
  10418.  
  10419.      CC=ccc CFLAGS="-fast -arch generic" CXX=cxx \
  10420.      CXXFLAGS="-fast -arch generic -noexceptions -nortti" \
  10421.      ./configure --prefix=/usr/local/mysql --disable-shared \
  10422.          --with-extra-charsets=complex --enable-thread-safe-client \
  10423.          --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  10424.  
  10425. If you want to use `egcs', the following `configure' line worked for us:
  10426.  
  10427.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
  10428.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  10429.          -fno-exceptions -fno-rtti" \
  10430.      ./configure --prefix=/usr/local/mysql --disable-shared
  10431.  
  10432. Some known problems when running MySQL on Linux-Alpha:
  10433.  
  10434.    * Debugging threaded applications like MySQL will not work with `gdb
  10435.      4.18'.  You should use `gdb' 5.1 instead!
  10436.  
  10437.    * If you try linking `mysqld' statically when using `gcc', the
  10438.      resulting image will dump core at startup time.  In other words,
  10439.      *don't* use `--with-mysqld-ldflags=-all-static' with `gcc'.
  10440.  
  10441. Linux PowerPC Notes
  10442. ...................
  10443.  
  10444. MySQL should work on MkLinux with the newest `glibc' package (tested
  10445. with `glibc' 2.0.7).
  10446.  
  10447. Linux MIPS Notes
  10448. ................
  10449.  
  10450. To get MySQL to work on Qube2 (Linux Mips), you need the newest `glibc'
  10451. libraries. `glibc-2.0.7-29C2' is known to work.  You must also use the
  10452. `egcs' C++ compiler (`egcs-1.0.2-9', `gcc 2.95.2' or newer).
  10453.  
  10454. Linux IA-64 Notes
  10455. .................
  10456.  
  10457. To get MySQL to compile on Linux IA-64, we use the following `configure'
  10458. command for building with `gcc' 2.96:
  10459.  
  10460.      CC=gcc \
  10461.      CFLAGS="-O3 -fno-omit-frame-pointer" \
  10462.      CXX=gcc \
  10463.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  10464.          -fno-exceptions -fno-rtti" \
  10465.      ./configure --prefix=/usr/local/mysql \
  10466.          "--with-comment=Official MySQL binary" \
  10467.          --with-extra-charsets=complex
  10468.  
  10469. On IA-64, the MySQL client binaries use shared libraries. This means
  10470. that if you install our binary distribution at a location other than
  10471. `/usr/local/mysql', you need to add the path of the directory where you
  10472. have `libmysqlclient.so' installed either to the `/etc/ld.so.conf' file
  10473. or to the value of your `LD_LIBRARY_PATH' environment variable.
  10474.  
  10475. *Note Link errors::.
  10476.  
  10477. Mac OS X Notes
  10478. --------------
  10479.  
  10480. On Mac OS X, `tar' cannot handle long filenames. If you need to unpack a
  10481. `.tar.gz' distribution, use `gnutar' instead.
  10482.  
  10483. Mac OS X 10.x (Darwin)
  10484. ......................
  10485.  
  10486. MySQL should work without any problems on Mac OS X 10.x (Darwin).
  10487.  
  10488. Our binary for Mac OS X is compiled on Darwin 6.3 with the following
  10489. `configure' line:
  10490.  
  10491.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  10492.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  10493.          -fno-exceptions -fno-rtti" \
  10494.      ./configure --prefix=/usr/local/mysql \
  10495.          --with-extra-charsets=complex --enable-thread-safe-client \
  10496.          --enable-local-infile --disable-shared
  10497.  
  10498. *Note Mac OS X installation::.
  10499.  
  10500. Mac OS X Server 1.2 (Rhapsody)
  10501. ..............................
  10502.  
  10503. For current versions of Mac OS X Server, no operating system changes are
  10504. necessary before compiling MySQL.  Compiling for the Server platform is
  10505. the same as for the client version of Mac OS X. (However, note that
  10506. MySQL comes preinstalled on Mac OS X Server, so you need not build it
  10507. yourself.)
  10508.  
  10509. For older versions (Mac OS X Server 1.2, a.k.a. Rhapsody), you must
  10510. first install a pthread package before trying to configure MySQL.
  10511.  
  10512. *Note Mac OS X installation::.
  10513.  
  10514. Solaris Notes
  10515. -------------
  10516.  
  10517. On Solaris, you may run into trouble even before you get the MySQL
  10518. distribution unpacked!  Solaris `tar' can't handle long file names, so
  10519. you may see an error like this when you unpack MySQL:
  10520.  
  10521.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,\
  10522.      informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  10523.      tar: directory checksum error
  10524.  
  10525. In this case, you must use GNU `tar' (`gtar') to unpack the
  10526. distribution.  You can find a precompiled copy for Solaris at
  10527. `http://www.mysql.com/downloads/os-solaris.html'.
  10528.  
  10529. Sun native threads only work on Solaris 2.5 and higher.  For Version
  10530. 2.4 and earlier, MySQL will automatically use MIT-pthreads.  *Note
  10531. MIT-pthreads::.
  10532.  
  10533. If you get the following error from `configure', it means that you have
  10534. something wrong with your compiler installation:
  10535.  
  10536.      checking for restartable system calls... configure: error can not
  10537.      run test programs while cross compiling
  10538.  
  10539. In this case you should upgrade your compiler to a newer version.  You
  10540. may also be able to solve this problem by inserting the following row
  10541. into the `config.cache' file:
  10542.  
  10543.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  10544.  
  10545. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  10546. 2.95.2 or 3.2. You can find this at `http://gcc.gnu.org/'.  Note that
  10547. `egcs' 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  10548.  
  10549. The recommended `configure' line when using `gcc' 2.95.2 is:
  10550.  
  10551.      CC=gcc CFLAGS="-O3" \
  10552.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  10553.      ./configure --prefix=/usr/local/mysql --with-low-memory \
  10554.      --enable-assembler
  10555.  
  10556. If you have an UltraSPARC system, you can get 4% better performance by
  10557. adding `-mcpu=v8 -Wa,-xarch=v8plusa' to the `CFLAGS' and `CXXFLAGS'
  10558. environment variables.
  10559.  
  10560. If you have Sun's Forte 5.0 (or newer) compiler, you can run
  10561. `configure' like this:
  10562.  
  10563.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt" \
  10564.      CXX=CC CXXFLAGS="-noex -mt" \
  10565.      ./configure --prefix=/usr/local/mysql --enable-assembler
  10566.  
  10567. To create a 64-bit binary with Sun's Forte compiler, use the following
  10568. configuration options:
  10569.  
  10570.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
  10571.      CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS="-xarch=v9" \
  10572.      ./configure --prefix=/usr/local/mysql --enable-assembler
  10573.  
  10574. To create a 64bit Solaris binary using `gcc', add `-m64' to `CFLAGS'
  10575. and `CXXFLAGS'. Note that this works only with MySQL 4.0 and up - MySQL
  10576. 3.23 does not include the required modifications to support this.
  10577.  
  10578. In the MySQL benchmarks, we got a 4% speedup on an UltraSPARC when using
  10579. Forte 5.0 in 32-bit mode compared to using `gcc' 3.2 with `-mcpu' flags.
  10580.  
  10581. If you create a 64-bit `mysqld' binary, it is 4% slower than the 32-bit
  10582. binary, but can handle more threads and memory.
  10583.  
  10584. If you get a problem with `fdatasync' or `sched_yield', you can fix
  10585. this by adding `LIBS=-lrt' to the configure line
  10586.  
  10587. For older compilers than WorkShop 5.3, you may have to edit the
  10588. `configure' script to change this line:
  10589.  
  10590.      #if !defined(__STDC__) || __STDC__ != 1
  10591.  
  10592. To this:
  10593.  
  10594.      #if !defined(__STDC__)
  10595.  
  10596. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  10597. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  10598. (broken compiler or broken include file).
  10599.  
  10600. If `mysqld' issues the following error message when you run it, you have
  10601. tried to compile MySQL with the Sun compiler without enabling the
  10602. multi-thread option (`-mt'):
  10603.  
  10604.      libc internal error: _rmutex_unlock: rmutex not held
  10605.  
  10606. Add `-mt' to `CFLAGS' and `CXXFLAGS' and recompile.
  10607.  
  10608. If you are using the SFW version of `gcc' (which comes with Solaris 8),
  10609. you must add `/opt/sfw/lib' to the environment variable
  10610. `LD_LIBRARY_PATH' before running `configure'.
  10611.  
  10612. If you are using the `gcc' available from `sunfreeware.com', you may
  10613. have many problems.  To avoid this, you should recompile `gcc' and GNU
  10614. `binutils' on the machine where you will be running them.
  10615.  
  10616. If you get the following error when compiling MySQL with `gcc', it
  10617. means that your `gcc' is not configured for your version of Solaris:
  10618.  
  10619.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  10620.      ./thr_alarm.c: In function `signal_hand':
  10621.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  10622.  
  10623. The proper thing to do in this case is to get the newest version of
  10624. `gcc' and compile it with your current `gcc' compiler!  At least for
  10625. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  10626. include files that will break all programs that use threads, and
  10627. possibly other programs!
  10628.  
  10629. Solaris doesn't provide static versions of all system libraries
  10630. (`libpthreads' and `libdl'), so you can't compile MySQL with
  10631. `--static'.  If you try to do so, you will get one of the following
  10632. errors:
  10633.  
  10634.      ld: fatal: library -ldl: not found
  10635.      undefined reference to `dlopen'
  10636.      cannot find -lrt
  10637.  
  10638. If you link your own MySQL client programs, you may see the following
  10639. error at runtime:
  10640.  
  10641.      ld.so.1: fatal: libmysqlclient.so.#:
  10642.      open failed: No such file or directory
  10643.  
  10644. This problem can be avoided by one of the following methods:
  10645.  
  10646.    * Link clients with the `-Wl,r/full-path-to-libmysqlclient.so' flag
  10647.      rather than with `-Lpath').
  10648.  
  10649.    * Copy `libmysqclient.so' to `/usr/lib'.
  10650.  
  10651.    * Add the pathname of the directory where `libmysqlclient.so' is
  10652.      located to the `LD_RUN_PATH' environment variable before running
  10653.      your client.
  10654.  
  10655. If you have problems with `configure' trying to link with `-lz' when
  10656. you don't have `zlib' installed, you have two options:
  10657.  
  10658.    * If you want to be able to use the compressed communication
  10659.      protocol, you need to get and install `zlib' from `ftp.gnu.org'.
  10660.  
  10661.    * Run `configure' with the `--with-named-z-libs=no' option when
  10662.      building MySQL.
  10663.  
  10664. If you are using `gcc' and have problems with loading user-defined
  10665. functions (UDFs) into MySQL, try adding `-lgcc' to the link line for
  10666. the UDF.
  10667.  
  10668. If you would like MySQL to start automatically, you can copy
  10669. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  10670. link to it named `/etc/rc3.d/S99mysql.server'.
  10671.  
  10672. If too many processes try to connect very rapidly to `mysqld', you will
  10673. see this error in the MySQL log:
  10674.  
  10675.      Error in accept: Protocol error
  10676.  
  10677. You might try starting the server with the `--back_log=50' option as a
  10678. workaround for this.  (Use `-O back_log=50' before MySQL 4.)
  10679.  
  10680. Solaris doesn't support core files for `setuid()' applications, so you
  10681. can't get a core file from `mysqld' if you are using the `--user'
  10682. option.
  10683.  
  10684. Solaris 2.7/2.8 Notes
  10685. .....................
  10686.  
  10687. You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  10688. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  10689.  
  10690. MySQL Version 3.23.4 and above should be able to detect new versions of
  10691. Solaris automatically and enable workarounds for the following problems!
  10692.  
  10693. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  10694. following error when you use `gcc':
  10695.  
  10696.      /usr/include/widec.h:42: warning: `getwc' redefined
  10697.      /usr/include/wchar.h:326: warning: this is the location of the previous
  10698.      definition
  10699.  
  10700. If this occurs, you can fix the problem by copying
  10701. `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include' and
  10702. changing line 41 from this:
  10703.  
  10704.      #if     !defined(lint) && !defined(__lint)
  10705.  
  10706. To this:
  10707.  
  10708.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  10709.  
  10710. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  10711. way, after you make the fix, you should remove `config.cache' and run
  10712. `configure' again!
  10713.  
  10714. If you get the following errors when you run `make', it's because
  10715. `configure' didn't detect the `curses.h' file (probably because of the
  10716. error in `/usr/include/widec.h'):
  10717.  
  10718.      In file included from mysql.cc:50:
  10719.      /usr/include/term.h:1060: syntax error before `,'
  10720.      /usr/include/term.h:1081: syntax error before `;'
  10721.  
  10722. The solution to this is to do one of the following:
  10723.  
  10724.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  10725.      ./configure'.
  10726.  
  10727.    * Edit `/usr/include/widec.h' as indicated above and re-run
  10728.      `configure'.
  10729.  
  10730.    * Remove the `#define HAVE_TERM' line from the `config.h' file and
  10731.      run `make' again.
  10732.  
  10733. If your linker can't find `-lz' when linking client programs, the
  10734. problem is probably that your `libz.so' file is installed in
  10735. `/usr/local/lib'.  You can fix this by one of the following methods:
  10736.  
  10737.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  10738.  
  10739.    * Add a link to `libz.so' from `/lib'.
  10740.  
  10741.    * If you are using Solaris 8, you can install the optional `zlib'
  10742.      from your Solaris 8 CD distribution.
  10743.  
  10744.    * Run `configure' with the `--with-named-z-libs=no' option when
  10745.      building MySQL.
  10746.  
  10747. Solaris x86 Notes
  10748. .................
  10749.  
  10750. On Solaris 8 on x86, `mysqld' will dump core if you remove the debug
  10751. symbols using `strip'.
  10752.  
  10753. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  10754. problems with core dumps under load, you should use the following
  10755. `configure' command:
  10756.  
  10757.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  10758.      CXX=gcc \
  10759.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  10760.          -fno-exceptions -fno-rtti -DHAVE_CURSES_H" \
  10761.      ./configure --prefix=/usr/local/mysql
  10762.  
  10763. This will avoid problems with the `libstdc++' library and with C++
  10764. exceptions.
  10765.  
  10766. If this doesn't help, you should compile a debug version and run it
  10767. with a trace file or under `gdb'.  *Note Using `gdb' on `mysqld': Using
  10768. gdb on mysqld.
  10769.  
  10770. BSD Notes
  10771. ---------
  10772.  
  10773. This section provides information about using MySQL on BSD variants.
  10774.  
  10775. FreeBSD Notes
  10776. .............
  10777.  
  10778. FreeBSD 4.x or newer is recommended for running MySQL, because the
  10779. thread package is much more integrated.  To get a secure and stable
  10780. system, you should use only FreeBSD kernels that are marked `-RELEASE'.
  10781.  
  10782. The easiest (and preferred) way to install MySQL is to use the
  10783. `mysql-server' and `mysql-client' ports available at
  10784. `http://www.freebsd.org/'.  Using these ports gives you the following
  10785. benefits:
  10786.  
  10787.    * A working MySQL with all optimizations enabled that are known to
  10788.      work on your version of FreeBSD.
  10789.  
  10790.    * Automatic configuration and build.
  10791.  
  10792.    * Startup scripts installed in `/usr/local/etc/rc.d'.
  10793.  
  10794.    * The ability to use `pkg_info -L' to see which files are installed.
  10795.  
  10796.    * The ability to use `pkg_delete' to remove MySQL if you no longer
  10797.      want it on your machine.
  10798.  
  10799. It is recommended you use MIT-pthreads on FreeBSD 2.x, and native
  10800. threads on Versions 3 and up. It is possible to run with native threads
  10801. on some late 2.2.x versions but you may encounter problems shutting
  10802. down `mysqld'.
  10803.  
  10804. Unfortunately, certain function calls on FreeBSD are not yet fully
  10805. thread-safe.  Most notably, this includes the `gethostbyname()'
  10806. function, which is used by MySQL to convert hostnames into IP
  10807. addresses. Under certain circumstances, the `mysqld' process will
  10808. suddenly cause 100% CPU load and will be unresponsive. If you encounter
  10809. this problem, try to start up MySQL using the `--skip-name-resolve'
  10810. option.
  10811.  
  10812. Alternatively, you can link MySQL on FreeBSD 4.x against the
  10813. LinuxThreads library, which avoids a few of the problems that the
  10814. native FreeBSD thread implementation has. For a very good comparison of
  10815. LinuxThreads vs. native threads, see Jeremy Zawodny's article `FreeBSD
  10816. or Linux for your MySQL Server?' at
  10817. `http://jeremy.zawodny.com/blog/archives/000697.html'.
  10818.  
  10819. A known problem when using LinuxThreads on FreeBSD is that
  10820. `wait_timeout' is not working (probably a signal handling problem in
  10821. FreeBSD/LinuxThreads).  This is supposed to be fixed in FreeBSD 5.0.
  10822. The symptom is that persistent connections can hang for a very long
  10823. time without getting closed down.
  10824.  
  10825. The MySQL build process require GNU make (`gmake') to work.  If GNU
  10826. `make' is not available, you must install it first before compiling
  10827. MySQL.
  10828.  
  10829. The recommended way to compile and install MySQL on FreeBSD with `gcc'
  10830. (2.95.2 and up) is:
  10831.  
  10832.      shell> CC=gcc CFLAGS="-O2 -fno-strength-reduce" \
  10833.                 CXX=gcc CXXFLAGS="-O2 -fno-rtti -fno-exceptions \
  10834.                 -felide-constructors -fno-strength-reduce" \
  10835.                 ./configure --prefix=/usr/local/mysql --enable-assembler
  10836.      shell> gmake
  10837.      shell> gmake install
  10838.      shell> cd /usr/local/mysql
  10839.      shell> bin/mysql_install_db
  10840.      shell> bin/mysqld_safe &
  10841.  
  10842. If you notice that `configure' will use MIT-pthreads, you should read
  10843. the MIT-pthreads notes.  *Note MIT-pthreads::.
  10844.  
  10845. If you get an error from `make install' that it can't find
  10846. `/usr/include/pthreads', `configure' didn't detect that you need
  10847. MIT-pthreads. To fix this problem, remove `config.cache', then re-run
  10848. `configure' with the `--with-mit-threads' option.
  10849.  
  10850. Be sure your name resolver setup is correct.  Otherwise, you may
  10851. experience resolver delays or failures when connecting to `mysqld'.
  10852. Also make sure that the `localhost' entry in the `/etc/hosts' file is
  10853. correct.  The file should start with a line similar to this:
  10854.  
  10855.      127.0.0.1       localhost localhost.your.domain
  10856.  
  10857. FreeBSD is known to have a very low default file handle limit.  *Note
  10858. Not enough file handles::.  Start the server by using the
  10859. `--open-files-limit' option for `mysqld_safe', or raise the limits for
  10860. the `mysqld' user in `/etc/login.conf' and rebuild it with `cap_mkdb
  10861. /etc/login.conf'.  Also be sure you set the appropriate class for this
  10862. user in the password file if you are not using the default (use `chpass
  10863. mysqld-user-name').  *Note `mysqld_safe': mysqld_safe.
  10864.  
  10865. If you have a lot of memory, you should consider rebuilding the kernel
  10866. to allow MySQL to use more than 512M of RAM.  Take a look at `option
  10867. MAXDSIZ' in the LINT config file for more information.
  10868.  
  10869. If you get problems with the current date in MySQL, setting the `TZ'
  10870. variable will probably help.  *Note Environment variables::.
  10871.  
  10872. NetBSD Notes
  10873. ............
  10874.  
  10875. To compile on NetBSD you need GNU `make'. Otherwise, the build process
  10876. will fail when `make' tries to run `lint' on C++ files.
  10877.  
  10878. OpenBSD 2.5 Notes
  10879. .................
  10880.  
  10881. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  10882. the following options:
  10883.  
  10884.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  10885.  
  10886. OpenBSD 2.8 Notes
  10887. .................
  10888.  
  10889. Our users have reported that OpenBSD 2.8 has a threading bug which
  10890. causes problems with MySQL.  The OpenBSD Developers have fixed the
  10891. problem, but as of January 25th, 2001, it's only available in the
  10892. "-current" branch.  The symptoms of this threading bug are: slow
  10893. response, high load, high CPU usage, and crashes.
  10894.  
  10895. If you get an error like `Error in accept:: Bad file descriptor' or
  10896. error 9 when trying to open tables or directories, the problem is
  10897. probably that you haven't allocated enough file descriptors for MySQL.
  10898.  
  10899. In this case, try starting `mysqld_safe' as `root' with the following
  10900. options:
  10901.  
  10902.      shell> mysqld_safe --user=mysql --open-files-limit=2048 &
  10903.  
  10904. BSD/OS Version 2.x Notes
  10905. ........................
  10906.  
  10907. If you get the following error when compiling MySQL, your `ulimit'
  10908. value for virtual memory is too low:
  10909.  
  10910.      item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  10911.      item_func.h:28: virtual memory exhausted
  10912.      make[2]: *** [item_func.o] Error 1
  10913.  
  10914. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  10915. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  10916. users have reported problems with `bash' and `ulimit'.
  10917.  
  10918. If you are using `gcc', you may also use have to use the
  10919. `--with-low-memory' flag for `configure' to be able to compile
  10920. `sql_yacc.cc'.
  10921.  
  10922. If you get problems with the current date in MySQL, setting the `TZ'
  10923. variable will probably help.  *Note Environment variables::.
  10924.  
  10925. BSD/OS Version 3.x Notes
  10926. ........................
  10927.  
  10928. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  10929. BSDIpatch M300-038.
  10930.  
  10931. Use the following command when configuring MySQL:
  10932.  
  10933.      shell> env CXX=shlicc++ CC=shlicc2 \
  10934.             ./configure \
  10935.                 --prefix=/usr/local/mysql \
  10936.                 --localstatedir=/var/mysql \
  10937.                 --without-perl \
  10938.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10939.  
  10940. The following is also known to work:
  10941.  
  10942.      shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  10943.             ./configure \
  10944.                 --prefix=/usr/local/mysql \
  10945.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10946.  
  10947. You can change the directory locations if you wish, or just use the
  10948. defaults by not specifying any locations.
  10949.  
  10950. If you have problems with performance under heavy load, try using the
  10951. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  10952. with the same priority; on BSDI Version 3.1, this gives better
  10953. performance (at least until BSDI fixes their thread scheduler).
  10954.  
  10955. If you get the error `virtual memory exhausted' while compiling, you
  10956. should try using `ulimit -v 80000' and run `make' again.  If this
  10957. doesn't work and you are using `bash', try switching to `csh' or `sh';
  10958. some BSDI users have reported problems with `bash' and `ulimit'.
  10959.  
  10960. BSD/OS Version 4.x Notes
  10961. ........................
  10962.  
  10963. BSDI Version 4.x has some thread-related bugs.  If you want to use
  10964. MySQL on this, you should install all thread-related patches.  At least
  10965. M400-023 should be installed.
  10966.  
  10967. On some BSDI Version 4.x systems, you may get problems with shared
  10968. libraries.  The symptom is that you can't execute any client programs,
  10969. for example, `mysqladmin'.  In this case you need to reconfigure not to
  10970. use shared libraries with the `--disable-shared' option to configure.
  10971.  
  10972. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  10973. after a while can't open tables.  This is because some library/system
  10974. related bug causes `mysqld' to change current directory without asking
  10975. for this!
  10976.  
  10977. The fix is to either upgrade MySQL to at least version 3.23.34 or, after
  10978. running `configure', remove the line `#define HAVE_REALPATH' from
  10979. `config.h' before running make.
  10980.  
  10981. Note that the above means that you can't symbolic link a database
  10982. directories to another database directory or symbolic link a table to
  10983. another database on BSDI!  (Making a symbolic link to another disk is
  10984. okay).
  10985.  
  10986. Other Unix Notes
  10987. ----------------
  10988.  
  10989. HP-UX Version 10.20 Notes
  10990. .........................
  10991.  
  10992. There are a couple of small problems when compiling MySQL on HP-UX.  We
  10993. recommend that you use `gcc' instead of the HP-UX native compiler,
  10994. because `gcc' produces better code!
  10995.  
  10996. We recommend using `gcc' 2.95 on HP-UX.  Don't use high optimization
  10997. flags (like `-O6') as they may not be safe on HP-UX.
  10998.  
  10999. The following `configure' line should work with `gcc' 2.95:
  11000.  
  11001.      CFLAGS="-I/opt/dce/include -fpic" \
  11002.      CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
  11003.      -fno-rtti" \
  11004.      CXX=gcc \
  11005.      ./configure --with-pthread \
  11006.          --with-named-thread-libs='-ldce' \
  11007.          --prefix=/usr/local/mysql --disable-shared
  11008.  
  11009. The following `configure' line should work with `gcc' 3.1:
  11010.  
  11011.      CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc \
  11012.      CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors \
  11013.          -fno-exceptions -fno-rtti -O3 -fPIC" \
  11014.      ./configure --prefix=/usr/local/mysql \
  11015.          --with-extra-charsets=complex --enable-thread-safe-client \
  11016.          --enable-local-infile  --with-pthread \
  11017.          --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  11018.          --disable-shared
  11019.  
  11020. HP-UX Version 11.x Notes
  11021. ........................
  11022.  
  11023. For HP-UX Version 11.x, we recommend MySQL Version 3.23.15 or later.
  11024.  
  11025. Because of some critical bugs in the standard HP-UX libraries, you
  11026. should install the following patches before trying to run MySQL on
  11027. HP-UX 11.0:
  11028.  
  11029.      PHKL_22840 Streams cumulative
  11030.      PHNE_22397 ARPA cumulative
  11031.  
  11032. This will solve the problem of getting `EWOULDBLOCK' from `recv()' and
  11033. `EBADF' from `accept()' in threaded applications.
  11034.  
  11035. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  11036. will get the error:
  11037.  
  11038.      In file included from /usr/include/unistd.h:11,
  11039.                       from ../include/global.h:125,
  11040.                       from mysql_priv.h:15,
  11041.                       from item.cc:19:
  11042.      /usr/include/sys/unistd.h:184: declaration of C function ...
  11043.      /usr/include/sys/pthread.h:440: previous declaration ...
  11044.      In file included from item.h:306,
  11045.                       from mysql_priv.h:158,
  11046.                       from item.cc:19:
  11047.  
  11048. The problem is that HP-UX doesn't define `pthreads_atfork()'
  11049. consistently.  It has conflicting prototypes in
  11050. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440
  11051. (details below).
  11052.  
  11053. One solution is to copy `/usr/include/sys/unistd.h' into
  11054. `mysql/include' and edit `unistd.h' and change it to match the
  11055. definition in `pthread.h'.  Here's the diff:
  11056.  
  11057.      183,184c183,184
  11058.      <      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  11059.      <                                                void (*child)());
  11060.      ---
  11061.      >      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  11062.      >                                                void (*child)(void));
  11063.  
  11064. After this, the following `configure' line should work:
  11065.  
  11066.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc \
  11067.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" \
  11068.      ./configure --prefix=/usr/local/mysql --disable-shared
  11069.  
  11070. If you are using MySQL 4.0.5 with the HP-UX compiler, you can use the
  11071. following command (which has been tested with `cc' B.11.11.04):
  11072.  
  11073.      CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure \
  11074.          --with-extra-character-set=complex
  11075.  
  11076. You can ignore any errors of the following type:
  11077.  
  11078.      aCC: warning 901: unknown option: `-3': use +help for online
  11079.      documentation
  11080.  
  11081. If you get the following error from `configure', check that you don't
  11082. have the path to the K&R compiler before the path to the HP-UX C and
  11083. C++ compiler:
  11084.  
  11085.      checking for cc option to accept ANSI C... no
  11086.      configure: error: MySQL requires a ANSI C compiler (and a C++ compiler).
  11087.      Try gcc. See the Installation chapter in the Reference Manual.
  11088.  
  11089. Another reason for not being able to compile is that you didn't define
  11090. the `+DD64' flags above.
  11091.  
  11092. Another possibility for HP-UX 11 is to use MySQL binaries for HP-UX
  11093. 10.20.  We have received reports from some users that these binaries
  11094. work fine on HP-UX 11.00. If you encounter problems, be sure to check
  11095. your HP-UX patch level.
  11096.  
  11097. IBM-AIX notes
  11098. .............
  11099.  
  11100. Automatic detection of `xlC' is missing from Autoconf, so a number of
  11101. variables need to be set before running `configure'. The following
  11102. example uses the IBM compiler:
  11103.  
  11104.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  11105.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  11106.      export CFLAGS="-I /usr/local/include"
  11107.      export LDFLAGS="-L /usr/local/lib"
  11108.      export CPPFLAGS=$CFLAGS
  11109.      export CXXFLAGS=$CFLAGS
  11110.      
  11111.      ./configure --prefix=/usr/local \
  11112.                      --localstatedir=/var/mysql \
  11113.                      --sysconfdir=/etc/mysql \
  11114.                      --sbindir='/usr/local/bin' \
  11115.                      --libexecdir='/usr/local/bin' \
  11116.                      --enable-thread-safe-client \
  11117.                      --enable-large-files
  11118.  
  11119. Above are the options used to compile the MySQL distribution that can
  11120. be found at `http://www-frec.bull.com/'.
  11121.  
  11122. If you change the `-O3' to `-O2' in the preceding `configure' line, you
  11123. must also remove the `-qstrict' option (this is a limitation in the IBM
  11124. C compiler).
  11125.  
  11126. If you are using `gcc' or `egcs' to compile MySQL, you *must* use the
  11127. `-fno-exceptions' flag, because the exception handling in `gcc'/`egcs'
  11128. is not thread-safe!  (This is tested with `egcs' 1.1.)  There are also
  11129. some known problems with IBM's assembler that may cause it to generate
  11130. bad code when used with `gcc'.
  11131.  
  11132. We recommend the following `configure' line with `egcs' and `gcc 2.95'
  11133. on AIX:
  11134.  
  11135.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  11136.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  11137.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  11138.      ./configure --prefix=/usr/local/mysql --with-low-memory
  11139.  
  11140. The `-Wa,-many' is necessary for the compile to be successful.  IBM is
  11141. aware of this problem but is in to hurry to fix it because of the
  11142. workaround available.  We don't know if the `-fno-exceptions' is
  11143. required with `gcc 2.95', but as MySQL doesn't use exceptions and the
  11144. above option generates faster code, we recommend that you should always
  11145. use this option with `egcs / gcc'.
  11146.  
  11147. If you get a problem with assembler code, try changing the `-mcpu=xxx'
  11148. option to match your CPU. Typically `power2', `power', or `powerpc' may
  11149. need to be used.  Alternatively, you might need to use `604' or `604e'.
  11150. We are not positive but suspect that `power' would likely be safe most
  11151. of the time, even on a power2 machine.
  11152.  
  11153. If you don't know what your CPU is, execute a `uname -m' command.  It
  11154. will produce a string that looks like `000514676700', with a format of
  11155. `xxyyyyyymmss' where `xx' and `ss' are always `00', `yyyyyy' is a
  11156. unique system ID and `mm' is the ID of the CPU Planar.  A chart of
  11157. these values can be found at
  11158. `http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  11159. This will give you a machine type and a machine model you can use to
  11160. determine what type of CPU you have.
  11161.  
  11162. If you have problems with signals (MySQL dies unexpectedly under high
  11163. load) you may have found an OS bug with threads and signals.  In this
  11164. case you can tell MySQL not to use signals by configuring with:
  11165.  
  11166.      shell> CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  11167.             CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
  11168.             -DDONT_USE_THR_ALARM" \
  11169.             ./configure --prefix=/usr/local/mysql --with-debug \
  11170.                 --with-low-memory
  11171.  
  11172. This doesn't affect the performance of MySQL, but has the side effect
  11173. that you can't kill clients that are "sleeping" on a connection with
  11174. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  11175. die when it issues its next command.
  11176.  
  11177. On some versions of AIX, linking with `libbind.a' makes `getservbyname'
  11178. core dump.  This is an AIX bug and should be reported to IBM.
  11179.  
  11180. For AIX 4.2.1 and `gcc', you have to make the following changes.
  11181.  
  11182. After configuring, edit `config.h' and `include/my_config.h' and change
  11183. the line that says this:
  11184.  
  11185.      #define HAVE_SNPRINTF 1
  11186.  
  11187. to this:
  11188.  
  11189.      #undef HAVE_SNPRINTF
  11190.  
  11191. And finally, in `mysqld.cc' you need to add a prototype for initgoups.
  11192.  
  11193.      #ifdef _AIX41
  11194.      extern "C" int initgroups(const char *,int);
  11195.      #endif
  11196.  
  11197. If you need to allocate a lot of memory to the `mysqld' process, it's
  11198. not enough to just use `ulimit -d unlimited'. You may also have to
  11199. modify `mysqld_safe' to add a line something like this:
  11200.  
  11201.      export LDR_CNTRL='MAXDATA=0x80000000'
  11202.  
  11203. You can find more about using a lot of memory at:
  11204. `http://publib16.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/lrg_prg_support.htm'.
  11205.  
  11206. SunOS 4 Notes
  11207. .............
  11208.  
  11209. On SunOS 4, MIT-pthreads is needed to compile MySQL. This in turn means
  11210. you will need GNU `make'.
  11211.  
  11212. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  11213. You can use the following `configure' line to avoid this problem:
  11214.  
  11215.      shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
  11216.  
  11217. When compiling `readline', you may get warnings about duplicate defines.
  11218. These may be ignored.
  11219.  
  11220. When compiling `mysqld', there will be some `implicit declaration of
  11221. function' warnings. These may be ignored.
  11222.  
  11223. Alpha-DEC-UNIX Notes (Tru64)
  11224. ............................
  11225.  
  11226. If you are using `egcs' 1.1.2 on Digital Unix, you should upgrade to
  11227. `gcc' 2.95.2, because `egcs' on DEC has some serious bugs!
  11228.  
  11229. When compiling threaded programs under Digital Unix, the documentation
  11230. recommends using the `-pthread' option for `cc' and `cxx' and the
  11231. `-lmach -lexc' libraries (in addition to `-lpthread').  You should run
  11232. `configure' something like this:
  11233.  
  11234.      CC="cc -pthread" CXX="cxx -pthread -O" \
  11235.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  11236.  
  11237. When compiling `mysqld', you may see a couple of warnings like this:
  11238.  
  11239.      mysqld.cc: In function void handle_connections()':
  11240.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  11241.      accept(int,sockadddr *, int *)'
  11242.  
  11243. You can safely ignore these warnings.  They occur because `configure'
  11244. can detect only errors, not warnings.
  11245.  
  11246. If you start the server directly from the command-line, you may have
  11247. problems with it dying when you log out.  (When you log out, your
  11248. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  11249. the server like this:
  11250.  
  11251.      shell> nohup mysqld [options] &
  11252.  
  11253. `nohup' causes the command following it to ignore any `SIGHUP' signal
  11254. sent from the terminal.  Alternatively, start the server by running
  11255. `mysqld_safe', which invokes `mysqld' using `nohup' for you.  *Note
  11256. `mysqld_safe': mysqld_safe.
  11257.  
  11258. If you get a problem when compiling `mysys/get_opt.c', just remove the
  11259. `#define _NO_PROTO' line from the start of that file!
  11260.  
  11261. If you are using Compaq's CC compiler, the following `configure' line
  11262. should work:
  11263.  
  11264.      CC="cc -pthread"
  11265.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  11266.      CXX="cxx -pthread"
  11267.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all \
  11268.          -arch host -noexceptions -nortti"
  11269.      export CC CFLAGS CXX CXXFLAGS
  11270.      ./configure \
  11271.          --prefix=/usr/local/mysql \
  11272.          --with-low-memory \
  11273.          --enable-large-files \
  11274.          --enable-shared=yes \
  11275.          --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  11276.      gnumake
  11277.  
  11278. If you get a problem with `libtool', when compiling with shared
  11279. libraries as above, when linking `mysql', you should be able to get
  11280. around this by issuing:
  11281.  
  11282.      cd mysql
  11283.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  11284.          -O4 -ansi_alias -ansi_args -fast -inline speed \
  11285.          -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  11286.          -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  11287.          ../readline/libreadline.a -lcurses \
  11288.          ../libmysql/.libs/libmysqlclient.so  -lm
  11289.      cd ..
  11290.      gnumake
  11291.      gnumake install
  11292.      scripts/mysql_install_db
  11293.  
  11294. Alpha-DEC-OSF/1 Notes
  11295. .....................
  11296.  
  11297. If you have problems compiling and have DEC `CC' and `gcc' installed,
  11298. try running `configure' like this:
  11299.  
  11300.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  11301.      ./configure --prefix=/usr/local/mysql
  11302.  
  11303. If you get problems with the `c_asm.h' file, you can create and use a
  11304. 'dummy' `c_asm.h' file with:
  11305.  
  11306.      touch include/c_asm.h
  11307.      CC=gcc CFLAGS=-I./include \
  11308.      CXX=gcc CXXFLAGS=-O3 \
  11309.      ./configure --prefix=/usr/local/mysql
  11310.  
  11311. Note that the following problems with the `ld' program can be fixed by
  11312. downloading the latest DEC (Compaq) patch kit from:
  11313. `http://ftp.support.compaq.com/public/unix/'.
  11314.  
  11315. On OSF/1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  11316. 878)" the compiler had some strange behavior (undefined `asm' symbols).
  11317. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  11318. errors occurring while linking `mysqld').  On this system, we have
  11319. managed to compile MySQL with the following `configure' line, after
  11320. replacing `/bin/ld' with the version from OSF 4.0C:
  11321.  
  11322.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  11323.  
  11324. With the Digital compiler "C++ V6.1-029", the following should work:
  11325.  
  11326.      CC=cc -pthread
  11327.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  11328.             -arch host
  11329.      CXX=cxx -pthread
  11330.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  11331.                -arch host -noexceptions -nortti
  11332.      export CC CFLAGS CXX CXXFLAGS
  11333.      ./configure --prefix=/usr/mysql/mysql --with-mysqld-ldflags=-all-static \
  11334.                  --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
  11335.  
  11336. In some versions of OSF/1, the `alloca()' function is broken. Fix this
  11337. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  11338.  
  11339. The `alloca()' function also may have an incorrect prototype in
  11340. `/usr/include/alloca.h'.  This warning resulting from this can be
  11341. ignored.
  11342.  
  11343. `configure' will use the following thread libraries automatically:
  11344. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  11345.  
  11346. When using `gcc', you can also try running `configure' like this:
  11347.  
  11348.      shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ...
  11349.  
  11350. If you have problems with signals (MySQL dies unexpectedly under high
  11351. load), you may have found an OS bug with threads and signals. In this
  11352. case you can tell MySQL not to use signals by configuring with:
  11353.  
  11354.      shell> CFLAGS=-DDONT_USE_THR_ALARM \
  11355.             CXXFLAGS=-DDONT_USE_THR_ALARM \
  11356.             ./configure ...
  11357.  
  11358. This doesn't affect the performance of MySQL, but has the side effect
  11359. that you can't kill clients that are "sleeping" on a connection with
  11360. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  11361. die when it issues its next command.
  11362.  
  11363. With `gcc' 2.95.2, you will probably run into the following compile
  11364. error:
  11365.  
  11366.      sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
  11367.      Please submit a full bug report.
  11368.  
  11369. To fix this you should change to the `sql' directory and do a "cut and
  11370. paste" of the last `gcc' line, but change `-O3' to `-O0' (or add `-O0'
  11371. immediately after `gcc' if you don't have any `-O' option on your
  11372. compile line).  After this is done you can just change back to the
  11373. top-level directly and run `make' again.
  11374.  
  11375. SGI Irix Notes
  11376. ..............
  11377.  
  11378. If you are using Irix Version 6.5.3 or newer `mysqld' will be able to
  11379. create threads only if you run it as a user with `CAP_SCHED_MGT'
  11380. privileges (like `root') or give the `mysqld' server this privilege
  11381. with the following shell command:
  11382.  
  11383.      shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  11384.  
  11385. You may have to undefine some symbols in `config.h' after running
  11386. `configure' and before compiling.
  11387.  
  11388. In some Irix implementations, the `alloca()' function is broken.  If the
  11389. `mysqld' server dies on some `SELECT' statements, remove the lines from
  11390. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  11391. `mysqladmin create' doesn't work, remove the line from `config.h' that
  11392. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  11393. line as well.
  11394.  
  11395. SGI recommends that you install all of the patches on this page as a
  11396. set:
  11397. `http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html'
  11398.  
  11399. At the very minimum, you should install the latest kernel rollup, the
  11400. latest `rld' rollup, and the latest `libc' rollup.
  11401.  
  11402. You definitely need all the POSIX patches on this page, for pthreads
  11403. support:
  11404.  
  11405. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  11406.  
  11407. If you get the something like the following error when compiling
  11408. `mysql.cc':
  11409.  
  11410.      "/usr/include/curses.h", line 82: error(1084): invalid combination of type
  11411.  
  11412. Type the following in the top-level directory of your MySQL source tree:
  11413.  
  11414.      shell> extra/replace bool curses_bool < /usr/include/curses.h \
  11415.                 > include/curses.h
  11416.      shell> make
  11417.  
  11418. There have also been reports of scheduling problems.  If only one
  11419. thread is running, performance is slow.  Avoid this by starting another
  11420. client.  This may lead to a 2-to-10-fold increase in execution speed
  11421. thereafter for the other thread.  This is a poorly understood problem
  11422. with Irix threads; you may have to improvise to find solutions until
  11423. this can be fixed.
  11424.  
  11425. If you are compiling with `gcc', you can use the following `configure'
  11426. command:
  11427.  
  11428.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  11429.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
  11430.          --with-named-thread-libs=-lpthread
  11431.  
  11432. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  11433. following is reported to work
  11434.  
  11435.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  11436.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  11437.      -I/usr/local/include -L/usr/local/lib' \
  11438.      ./configure --prefix=/usr/local/mysql --with-innodb --with-berkeley-db \
  11439.          --with-libwrap=/usr/local \
  11440.          --with-named-curses-libs=/usr/local/lib/libncurses.a
  11441.  
  11442. SCO Notes
  11443. .........
  11444.  
  11445. The current port is tested only on "sco3.2v5.0.5", "sco3.2v5.0.6" and
  11446. "sco3.2v5.0.7" systems.  There has also been a lot of progress on a
  11447. port to "sco 3.2v4.2".
  11448.  
  11449. For the moment the recommended compiler on OpenServer is `gcc' 2.95.2.
  11450. With this you should be able to compile MySQL with just:
  11451.  
  11452.      CC=gcc CXX=gcc ./configure ... (options)
  11453.  
  11454.   1. For OpenServer 5.0.x you need to use gcc-2.95.2p1 or newer from the
  11455.      Skunkware.  `http://www.sco.com/skunkware/' and choose browser
  11456.      OpenServer packages or by ftp to ftp2.caldera.com in the
  11457.      `pub/skunkware/osr5/devtools/gcc' directory.
  11458.  
  11459.   2. You need the port of GCC 2.5.x for this product and the Development
  11460.      system.  They are required on this version of SCO Unix.  You cannot
  11461.      just use the GCC Dev system.
  11462.  
  11463.   3. You should get the FSU Pthreads package and install it first.
  11464.      This can be found at
  11465.      `http://moss.csc.ncsu.edu/~mueller/ftp/pub/PART/pthreads.tar.gz'.
  11466.      You can also get a precompiled package from
  11467.      `http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz'.
  11468.  
  11469.   4. FSU Pthreads can be compiled with SCO Unix 4.2 with tcpip.  Or
  11470.      OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0), with the SCO
  11471.      Development System installed using a good port of GCC 2.5.x ODT or
  11472.      OS 3.0 you will need a good port of GCC 2.5.x There are a lot of
  11473.      problems without a good port.  The port for this product requires
  11474.      the SCO Unix Development system.  Without it, you are missing the
  11475.      libraries and the linker that is needed.
  11476.  
  11477.   5. To build FSU Pthreads on your system, do the following:
  11478.  
  11479.        1. Run `./configure' in the `threads/src' directory and select
  11480.           the SCO OpenServer option. This command copies
  11481.           `Makefile.SCO5' to `Makefile'.
  11482.  
  11483.        2. Run `make'.
  11484.  
  11485.        3. To install in the default `/usr/include' directory, login as
  11486.           root, then `cd' to the `thread/src' directory, and run `make
  11487.           install'.
  11488.  
  11489.   6. Remember to use GNU `make' when making MySQL.
  11490.  
  11491.   7. If you don't start `mysqld_safe' as `root', you probably will get
  11492.      only the default 110 open files per process.  `mysqld' will write
  11493.      a note about this in the log file.
  11494.  
  11495.   8. With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or
  11496.      newer.  You should also use `gcc' 2.95.2 or newer!
  11497.  
  11498.      The following `configure' command should work:
  11499.  
  11500.           shell> ./configure --prefix=/usr/local/mysql --disable-shared
  11501.  
  11502.   9. With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or
  11503.      newer.  The following `configure' command should work:
  11504.  
  11505.           shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  11506.                  ./configure \
  11507.                      --prefix=/usr/local/mysql \
  11508.                      --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  11509.                      --with-named-curses-libs="-lcurses"
  11510.  
  11511.      You may get some problems with some include files. In this case,
  11512.      you can find new SCO-specific include files at
  11513.      `http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz'.
  11514.      You should unpack this file in the `include' directory of your
  11515.      MySQL source tree.
  11516.  
  11517. SCO development notes:
  11518.  
  11519.    * MySQL should automatically detect FSU Pthreads and link `mysqld'
  11520.      with `-lgthreads -lsocket -lgthreads'.
  11521.  
  11522.    * The SCO development libraries are re-entrant in FSU Pthreads.  SCO
  11523.      claims that its libraries' functions are re-entrant, so they must
  11524.      be re-entrant with FSU Pthreads.  FSU Pthreads on OpenServer tries
  11525.      to use the SCO scheme to make re-entrant libraries.
  11526.  
  11527.    * FSU Pthreads (at least the version at `http://www.mysql.com/')
  11528.      comes linked with GNU `malloc'.  If you encounter problems with
  11529.      memory usage, make sure that `gmalloc.o' is included in
  11530.      `libgthreads.a' and `libgthreads.so'.
  11531.  
  11532.    * In FSU Pthreads, the following system calls are pthreads-aware:
  11533.      `read()', `write()', `getmsg()', `connect()', `accept()',
  11534.      `select()', and `wait()'.
  11535.  
  11536.    * The CSSA-2001-SCO.35.2 (the patch is listed in custom as
  11537.      erg711905-dscr_remap security patch (version 2.0.0) breaks FSU
  11538.      threads and makes `mysqld' unstable.  You have to remove this one
  11539.      if you want to run `mysqld' on an OpenServer 5.0.6 machine.
  11540.  
  11541.    * SCO provides Operating Systems Patches at
  11542.      `ftp://ftp.sco.com/pub/openserver5' for OpenServer 5.0.x
  11543.  
  11544.    * SCO provides security fixes and `libsocket.so.2' at
  11545.      `ftp://ftp.sco.com/pub/security/OpenServer' and
  11546.      `ftp://ftp.sco.com/pub/security/sse' for OpenServer 5.0.x
  11547.  
  11548.    * pre-OSR506 security fixes. Also, the `telnetd' fix at
  11549.      `ftp://stage.caldera.com/pub/security/openserver/' or
  11550.      `ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/'
  11551.      as both `libsocket.so.2' and `libresolv.so.1' with instructions for
  11552.      installing on pre-OSR506 systems.
  11553.  
  11554.      It's probably a good idea to install the above patches before
  11555.      trying to compile/use MySQL.
  11556.  
  11557. SCO UnixWare Version 7.1.x Notes
  11558. ................................
  11559.  
  11560. On UnixWare 7.1.0, you must use a version of MySQL at least as recent as
  11561. 3.22.13 to get fixes for some portability and OS problems.
  11562.  
  11563. We have been able to compile MySQL with the following `configure'
  11564. command on UnixWare Version 7.1.x:
  11565.  
  11566.      CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
  11567.  
  11568. If you want to use `gcc', you must use `gcc' 2.95.2 or newer.
  11569.  
  11570.      CC=gcc CXX=g++ ./configure --prefix=/usr/local/mysql
  11571.  
  11572.   1. SCO provides Operating Systems Patches at
  11573.      `ftp://ftp.sco.com/pub/unixware7' for UnixWare 7.1.1 and 7.1.3 and
  11574.      at `ftp://ftp.sco.com/pub/openunix8' for OpenUNIX 8.0.0.
  11575.  
  11576.   2. SCO provides information about Security Fixes at
  11577.      `ftp://ftp.sco.com/pub/security/OpenUNIX' for OpenUNIX and at
  11578.      `ftp://ftp.sco.com/pub/security/UnixWare' for UnixWare.
  11579.  
  11580. OS/2 Notes
  11581. ----------
  11582.  
  11583. MySQL uses quite a few open files. Because of this, you should add
  11584. something like the following to your `CONFIG.SYS' file:
  11585.  
  11586.      SET EMXOPT=-c -n -h1024
  11587.  
  11588. If you don't do this, you will probably run into the following error:
  11589.  
  11590.      File 'xxxx' not found (Errcode: 24)
  11591.  
  11592. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  11593. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  11594. of the Pthreads library.  MySQL must be installed on a partition with a
  11595. type that supports long filenames, such as HPFS, FAT32, etc.
  11596.  
  11597. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  11598. not work with replacement shells such as `4OS2.EXE'.
  11599.  
  11600. The `scripts/mysql-install-db' script has been renamed.  It is now
  11601. called `install.cmd' and is a REXX script, which will set up the default
  11602. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  11603.  
  11604. Dynamic module support is compiled in but not fully tested. Dynamic
  11605. modules should be compiled using the Pthreads run-time library.
  11606.  
  11607.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  11608.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  11609.      mv example.dll example.udf
  11610.  
  11611. *Note:* Due to limitations in OS/2, UDF module name stems must not
  11612. exceed 8 characters. Modules are stored in the `/mysql2/udf' directory;
  11613. the `safe-mysqld.cmd' script will put this directory in the
  11614. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  11615. extensions are ignored--it is assumed to be `.udf'.  For example, in
  11616. Unix, the shared module might be named `example.so' and you would load
  11617. a function from it like this:
  11618.  
  11619.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
  11620.  
  11621. In OS/2, the module would be named `example.udf', but you would not
  11622. specify the module extension:
  11623.  
  11624.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
  11625.  
  11626. BeOS Notes
  11627. ----------
  11628.  
  11629. We have in the past talked with some BeOS developers that have said that
  11630. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  11631.  
  11632. Perl Installation Notes
  11633. =======================
  11634.  
  11635. Perl support for MySQL is provided by means of the `DBI'/`DBD' client
  11636. interface. The interface requires Perl Version 5.6.0 or later.  It
  11637. *will not work* if you have an older version of Perl.
  11638.  
  11639. If you want to use transactions with Perl DBI, you need to have
  11640. `DBD::mysql' version 1.2216 or newer. Version 2.9003 or newer is
  11641. recommended.
  11642.  
  11643. As of Version 3.22.8, Perl support is no longer included with MySQL
  11644. distributions. You can obtain the necessary modules from
  11645. `http://search.cpan.org' for Unix, or using the ActiveState `ppm'
  11646. program on Windows. The following sections describe how to do this.
  11647.  
  11648. Perl support for MySQL must be installed if you want to run the MySQL
  11649. benchmark scripts.  *Note MySQL Benchmarks::.
  11650.  
  11651. Installing Perl on Unix
  11652. -----------------------
  11653.  
  11654. MySQL Perl support requires that you've installed MySQL client
  11655. programming support (libraries and header files).  Most installation
  11656. methods install the necesssary files. However, if you installed MySQL
  11657. from RPM files on Linux, be sure that you've installed the developer
  11658. RPM.  The client programs are in the client RPM, but client programming
  11659. support is in the developer RPM.
  11660.  
  11661. If you want to install Perl support, the files you will need can be
  11662. obtained from the CPAN (Comprehensive Perl Archive Network) at
  11663. `http://search.cpan.org'.
  11664.  
  11665. The easiest way to install Perl modules on Unix is to use the `CPAN'
  11666. module. For example:
  11667.  
  11668.      shell> perl -MCPAN -e shell
  11669.      cpan> install DBI
  11670.      cpan> install DBD::mysql
  11671.  
  11672. The `DBD::mysql' installation runs a number of tests.  These tests
  11673. require being able to connect to the local MySQL server as the
  11674. anonymous user with no password. If you have removed anonymous accounts
  11675. or assigned them passwords, the tests fail. You can use `force install
  11676. DBD::mysql' to ignore the failed tests.
  11677.  
  11678. `DBI' requires the `Data::Dumper' module. It may already be installed;
  11679. if not, you should install it before installing `DBI'.
  11680.  
  11681. It is also possible to download the module distributions in the form of
  11682. compressed `tar' archives and build the modules manually. For example,
  11683. to unpack and build a DBI distribution, use a procedure such as this:
  11684.  
  11685.   1. Unpack the distribution into the current directory:
  11686.           shell> gunzip < DBI-VERSION.tar.gz | tar xvf -
  11687.      This command creates a directory named `DBI-VERSION'.
  11688.  
  11689.   2. Change into the top-level directory of the unpacked distribution:
  11690.           shell> cd DBI-VERSION
  11691.  
  11692.   3. Build the distribution and compile everything:
  11693.           shell> perl Makefile.PL
  11694.           shell> make
  11695.           shell> make test
  11696.           shell> make install
  11697.  
  11698. The `make test' command is important because it verifies that the
  11699. module is working.  Note that when you run that command during the
  11700. `DBD::mysql' installation to exercise the interface code, the MySQL
  11701. server must be running or the test will fail.
  11702.  
  11703. It is a good idea to rebuild and reinstall the `DBD::mysql'
  11704. distribution whenever you install a new release of MySQL, particularly
  11705. if you notice symptoms such as that all your `DBI' scripts fail after
  11706. you upgrade MySQL.
  11707.  
  11708. If you don't have access rights to install Perl modules in the system
  11709. directory or if you want to install local Perl modules, the following
  11710. reference may be useful:
  11711.  
  11712.      `http://servers.digitaldaze.com/extensions/perl/modules.html#modules'
  11713.  
  11714. Look under the heading `Installing New Modules that Require Locally
  11715. Installed Modules'.
  11716.  
  11717. Installing ActiveState Perl on Windows
  11718. --------------------------------------
  11719.  
  11720. On Windows, you should do the following to install the MySQL `DBD'
  11721. module with ActiveState Perl:
  11722.  
  11723.    * Get ActiveState Perl from
  11724.      `http://www.activestate.com/Products/ActivePerl/' and install it.
  11725.  
  11726.    * Open a console window (a "DOS window").
  11727.  
  11728.    * If required, set the `HTTP_proxy' variable. For example, you might
  11729.      try:
  11730.  
  11731.           set HTTP_proxy=my.proxy.com:3128
  11732.  
  11733.    * Start the PPM program:
  11734.  
  11735.           C:\> c:\perl\bin\ppm.pl
  11736.  
  11737.    * If you have not already done so, install `DBI':
  11738.  
  11739.           ppm> install DBI
  11740.  
  11741.    * If this succeeds, run the following command:
  11742.  
  11743.           install \
  11744.           ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
  11745.  
  11746. The above should work at least with ActiveState Perl Version 5.6.
  11747.  
  11748. If you can't get the above to work, you should instead install the
  11749. `MyODBC' driver and connect to the MySQL server through ODBC:
  11750.  
  11751.      use DBI;
  11752.      $dbh= DBI->connect("DBI:ODBC:$dsn",$user,$password) ||
  11753.        die "Got error $DBI::errstr when connecting to $dsn\n";
  11754.  
  11755. Problems Using the Perl `DBI'/`DBD' Interface
  11756. ---------------------------------------------
  11757.  
  11758. If Perl reports that it can't find the `../mysql/mysql.so' module, then
  11759. the problem is probably that Perl can't locate the shared library
  11760. `libmysqlclient.so'.
  11761.  
  11762. You should be able to fix this by one of the following methods:
  11763.  
  11764.    * Compile the `DBD::mysql' distribution with `perl Makefile.PL
  11765.      -static -config' rather than `perl Makefile.PL'.
  11766.  
  11767.    * Copy `libmysqlclient.so' to the directory where your other shared
  11768.      libraries are located (probably `/usr/lib' or `/lib').
  11769.  
  11770.    * Modify the `-L' options used to compile `DBD::mysql' to reflect
  11771.      the actual location of `libmysqlclient.so'.
  11772.  
  11773.    * On Linux you can add the pathname of the directory where
  11774.      `libmysqlclient.so' is located to the `/etc/ld.so.conf' file.
  11775.  
  11776.    * Add the pathname of the directory where `libmysqlclient.so' is
  11777.      located to the `LD_RUN_PATH' environment variable. Some systems use
  11778.      `LD_LIBRARY_PATH' instead.
  11779.  
  11780. Note that you may also need to modify the `-L' options if there are
  11781. other libraries that the linker fails to find. For example, if the
  11782. linker cannot find `libc' because it is in `/lib' and the link command
  11783. specifies `-L/usr/lib', change the `-L' option to `-L/lib' or add
  11784. `-L/lib' to the existing link command.
  11785.  
  11786. If you get the following errors from `DBD::mysql', you are probably
  11787. using `gcc' (or using an old binary compiled with `gcc'):
  11788.  
  11789.      /usr/bin/perl: can't resolve symbol '__moddi3'
  11790.      /usr/bin/perl: can't resolve symbol '__divdi3'
  11791.  
  11792. Add `-L/usr/lib/gcc-lib/... -lgcc' to the link command when the
  11793. `mysql.so' library gets built (check the output from `make' for
  11794. `mysql.so' when you compile the Perl client).  The `-L' option should
  11795. specify the pathname of the directory where `libgcc.a' is located on
  11796. your system.
  11797.  
  11798. Another cause of this problem may be that Perl and MySQL aren't both
  11799. compiled with `gcc'.  In this case, you can solve the mismatch by
  11800. compiling both with `gcc'.
  11801.  
  11802. You may see the following error from `DBD::mysql' when you run the
  11803. tests:
  11804.  
  11805.      t/00base............install_driver(mysql) failed:
  11806.      Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
  11807.      ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
  11808.      uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
  11809.  
  11810. This means that you need to include the `-lz' compression library on the
  11811. link line. That can be done by changing the following line in the file
  11812. `lib/DBD/mysql/Install.pm':
  11813.  
  11814.      $sysliblist .= " -lm";
  11815.  
  11816. Change that line to:
  11817.  
  11818.      $sysliblist .= " -lm -lz";
  11819.  
  11820. After this, you *must* run `make realclean' and then proceed with the
  11821. installation from the beginning.
  11822.  
  11823. If you want to install DBI on SCO, you have to edit the `Makefile' in
  11824. DBI-xxx and each subdirectory.
  11825.  
  11826. Note that the following assumes `gcc' 2.95.2 or newer:
  11827.  
  11828.      OLD:                                  NEW:
  11829.      CC = cc                               CC = gcc
  11830.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  11831.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  11832.      
  11833.      LD = ld                               LD = gcc -G -fpic
  11834.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  11835.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  11836.      
  11837.      LD = ld                               LD = gcc -G -fpic
  11838.      OPTIMISE = -Od                        OPTIMISE = -O1
  11839.      
  11840.      OLD:
  11841.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  11842.      
  11843.      NEW:
  11844.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  11845.  
  11846. This is because the Perl dynaloader will not load the `DBI' modules if
  11847. they were compiled with `icc' or `cc'.
  11848.  
  11849. If you want to use the Perl module on a system that doesn't support
  11850. dynamic linking (like SCO) you can generate a static version of Perl
  11851. that includes `DBI' and `DBD::mysql'.  The way this works is that you
  11852. generate a version of Perl with the `DBI' code linked in and install it
  11853. on top of your current Perl.  Then you use that to build a version of
  11854. Perl that additionally has the `DBD' code linked in, and install that.
  11855.  
  11856. On SCO, you must have the following environment variables set:
  11857.  
  11858.      shell> LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
  11859.      or:
  11860.      shell> LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11861.      /usr/progressive/lib:/usr/skunk/lib
  11862.      shell> LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11863.      /usr/progressive/lib:/usr/skunk/lib
  11864.      shell> MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
  11865.      /usr/skunk/man:
  11866.  
  11867. First, create a Perl that includes a statically linked `DBI' module by
  11868. running these commands in the directory where your `DBI' distribution is
  11869. located:
  11870.  
  11871.      shell> perl Makefile.PL -static -config
  11872.      shell> make
  11873.      shell> make install
  11874.      shell> make perl
  11875.  
  11876. Then you must install the new Perl. The output of `make perl' will
  11877. indicate the exact `make' command you will need to execute to perform
  11878. the installation.  On SCO, this is `make -f Makefile.aperl inst_perl
  11879. MAP_TARGET=perl'.
  11880.  
  11881. Next, use the just-created Perl to create another Perl that also
  11882. includes a statically linked `DBD::mysql' by running these commands in
  11883. the directory where your `DBD::mysql' distribution is located:
  11884.  
  11885.      shell> perl Makefile.PL -static -config
  11886.      shell> make
  11887.      shell> make install
  11888.      shell> make perl
  11889.  
  11890. Finally, you should install this new Perl.  Again, the output of `make
  11891. perl' indicates the command to use.
  11892.  
  11893. MySQL Tutorial
  11894. **************
  11895.  
  11896. This chapter provides a tutorial introduction to MySQL by showing how
  11897. to use the `mysql' client program to create and use a simple database.
  11898. `mysql' (sometimes referred to as the "terminal monitor" or just
  11899. "monitor") is an interactive program that allows you to connect to a
  11900. MySQL server, run queries, and view the results.  `mysql' may also be
  11901. used in batch mode: you place your queries in a file beforehand, then
  11902. tell `mysql' to execute the contents of the file.  Both ways of using
  11903. `mysql' are covered here.
  11904.  
  11905. To see a list of options provided by `mysql', invoke it with the
  11906. `--help' option:
  11907.  
  11908.      shell> mysql --help
  11909.  
  11910. This chapter assumes that `mysql' is installed on your machine and that
  11911. a MySQL server is available to which you can connect.  If this is not
  11912. true, contact your MySQL administrator.  (If *you* are the
  11913. administrator, you will need to consult other sections of this manual.)
  11914.  
  11915. This chapter describes the entire process of setting up and using a
  11916. database.  If you are interested only in accessing an already-existing
  11917. database, you may want to skip over the sections that describe how to
  11918. create the database and the tables it contains.
  11919.  
  11920. Because this chapter is tutorial in nature, many details are necessarily
  11921. omitted.  Consult the relevant sections of the manual for more
  11922. information on the topics covered here.
  11923.  
  11924. Connecting to and Disconnecting from the Server
  11925. ===============================================
  11926.  
  11927. To connect to the server, you'll usually need to provide a MySQL
  11928. username when you invoke `mysql' and, most likely, a password.  If the
  11929. server runs on a machine other than the one where you log in, you'll
  11930. also need to specify a hostname.  Contact your administrator to find
  11931. out what connection parameters you should use to connect (that is, what
  11932. host, username, and password to use).  Once you know the proper
  11933. parameters, you should be able to connect like this:
  11934.  
  11935.      shell> mysql -h host -u user -p
  11936.      Enter password: ********
  11937.  
  11938. `host' and `user' represent the hostname where your MySQL server is
  11939. running and the username of your MySQL account.  Substitute appropriate
  11940. values for your setup.  The `********' represents your password; enter
  11941. it when `mysql' displays the `Enter password:' prompt.
  11942.  
  11943. If that works, you should see some introductory information followed by
  11944. a `mysql>' prompt:
  11945.  
  11946.      shell> mysql -h host -u user -p
  11947.      Enter password: ********
  11948.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  11949.      Your MySQL connection id is 25338 to server version: 4.0.14-log
  11950.      
  11951.      Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  11952.      
  11953.      mysql>
  11954.  
  11955. The prompt tells you that `mysql' is ready for you to enter commands.
  11956.  
  11957. Some MySQL installations allow users to connect as the anonymous
  11958. (unnamed) user to the server running on the local host.  If this is the
  11959. case on your machine, you should be able to connect to that server by
  11960. invoking `mysql' without any options:
  11961.  
  11962.      shell> mysql
  11963.  
  11964. After you have connected successfully, you can disconnect any time by
  11965. typing `QUIT' (or `\q') at the `mysql>' prompt:
  11966.  
  11967.      mysql> QUIT
  11968.      Bye
  11969.  
  11970. On Unix, you can also disconnect by pressing Control-D.
  11971.  
  11972. Most examples in the following sections assume you are connected to the
  11973. server.  They indicate this by the `mysql>' prompt.
  11974.  
  11975. Entering Queries
  11976. ================
  11977.  
  11978. Make sure you are connected to the server, as discussed in the previous
  11979. section.  Doing so will not in itself select any database to work with,
  11980. but that's okay.  At this point, it's more important to find out a
  11981. little about how to issue queries than to jump right in creating
  11982. tables, loading data into them, and retrieving data from them.  This
  11983. section describes the basic principles of entering commands, using
  11984. several queries you can try out to familiarise yourself with how
  11985. `mysql' works.
  11986.  
  11987. Here's a simple command that asks the server to tell you its version
  11988. number and the current date.  Type it in as shown here following the
  11989. `mysql>' prompt and press Enter:
  11990.  
  11991.      mysql> SELECT VERSION(), CURRENT_DATE;
  11992.      +--------------+--------------+
  11993.      | VERSION()    | CURRENT_DATE |
  11994.      +--------------+--------------+
  11995.      | 3.22.20a-log | 1999-03-19   |
  11996.      +--------------+--------------+
  11997.      1 row in set (0.01 sec)
  11998.      mysql>
  11999.  
  12000. This query illustrates several things about `mysql':
  12001.  
  12002.    * A command normally consists of an SQL statement followed by a
  12003.      semicolon.  (There are some exceptions where a semicolon may be
  12004.      omitted.  `QUIT', mentioned earlier, is one of them.  We'll get to
  12005.      others later.)
  12006.  
  12007.    * When you issue a command, `mysql' sends it to the server for
  12008.      execution and displays the results, then prints another `mysql>'
  12009.      prompt to indicate that it is ready for another command.
  12010.  
  12011.    * `mysql' displays query output in tabular form (rows and columns).
  12012.      The first row contains labels for the columns.  The rows following
  12013.      are the query results.  Normally, column labels are the names of
  12014.      the columns you fetch from database tables.  If you're retrieving
  12015.      the value of an expression rather than a table column (as in the
  12016.      example just shown), `mysql' labels the column using the
  12017.      expression itself.
  12018.  
  12019.    * `mysql' shows how many rows were returned and how long the query
  12020.      took to execute, which gives you a rough idea of server
  12021.      performance.  These values are imprecise because they represent
  12022.      wall clock time (not CPU or machine time), and because they are
  12023.      affected by factors such as server load and network latency.  (For
  12024.      brevity, the "rows in set" line is not shown in the remaining
  12025.      examples in this chapter.)
  12026.  
  12027. Keywords may be entered in any lettercase.  The following queries are
  12028. equivalent:
  12029.  
  12030.      mysql> SELECT VERSION(), CURRENT_DATE;
  12031.      mysql> select version(), current_date;
  12032.      mysql> SeLeCt vErSiOn(), current_DATE;
  12033.  
  12034. Here's another query.  It demonstrates that you can use `mysql' as a
  12035. simple calculator:
  12036.  
  12037.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  12038.      +-------------+---------+
  12039.      | SIN(PI()/4) | (4+1)*5 |
  12040.      +-------------+---------+
  12041.      |    0.707107 |      25 |
  12042.      +-------------+---------+
  12043.  
  12044. The queries shown thus far have been relatively short, single-line
  12045. statements.  You can even enter multiple statements on a single line.
  12046. Just end each one with a semicolon:
  12047.  
  12048.      mysql> SELECT VERSION(); SELECT NOW();
  12049.      +--------------+
  12050.      | VERSION()    |
  12051.      +--------------+
  12052.      | 3.22.20a-log |
  12053.      +--------------+
  12054.      
  12055.      +---------------------+
  12056.      | NOW()               |
  12057.      +---------------------+
  12058.      | 1999-03-19 00:15:33 |
  12059.      +---------------------+
  12060.  
  12061. A command need not be given all on a single line, so lengthy commands
  12062. that require several lines are not a problem.  `mysql' determines where
  12063. your statement ends by looking for the terminating semicolon, not by
  12064. looking for the end of the input line.  (In other words, `mysql'
  12065. accepts free-format input:  it collects input lines but does not
  12066. execute them until it sees the semicolon.)
  12067.  
  12068. Here's a simple multiple-line statement:
  12069.  
  12070.      mysql> SELECT
  12071.          -> USER()
  12072.          -> ,
  12073.          -> CURRENT_DATE;
  12074.      +--------------------+--------------+
  12075.      | USER()             | CURRENT_DATE |
  12076.      +--------------------+--------------+
  12077.      | joesmith@localhost | 1999-03-18   |
  12078.      +--------------------+--------------+
  12079.  
  12080. In this example, notice how the prompt changes from `mysql>' to `->'
  12081. after you enter the first line of a multiple-line query.  This is how
  12082. `mysql' indicates that it hasn't seen a complete statement and is
  12083. waiting for the rest.  The prompt is your friend, because it provides
  12084. valuable feedback.  If you use that feedback, you will always be aware
  12085. of what `mysql' is waiting for.
  12086.  
  12087. If you decide you don't want to execute a command that you are in the
  12088. process of entering, cancel it by typing `\c':
  12089.  
  12090.      mysql> SELECT
  12091.          -> USER()
  12092.          -> \c
  12093.      mysql>
  12094.  
  12095. Here, too, notice the prompt.  It switches back to `mysql>' after you
  12096. type `\c', providing feedback to indicate that `mysql' is ready for a
  12097. new command.
  12098.  
  12099. The following table shows each of the prompts you may see and
  12100. summarizes what they mean about the state that `mysql' is in:
  12101.  
  12102. *Prompt**Meaning*
  12103. `mysql>'Ready for new command.
  12104. `       Waiting for next line of multiple-line command.
  12105. ->'     
  12106. `       Waiting for next line, collecting a string that begins
  12107. '>'     with a single quote (`'').
  12108. `       Waiting for next line, collecting a string that begins
  12109. ">'     with a double quote (`"').
  12110. `       Waiting for next line, collecting an identifier that
  12111. `>'     begins with a backtick (``').
  12112.  
  12113. Multiple-line statements commonly occur by accident when you intend to
  12114. issue a command on a single line, but forget the terminating semicolon.
  12115. In this case, `mysql' waits for more input:
  12116.  
  12117.      mysql> SELECT USER()
  12118.          ->
  12119.  
  12120. If this happens to you (you think you've entered a statement but the
  12121. only response is a `->' prompt), most likely `mysql' is waiting for the
  12122. semicolon.  If you don't notice what the prompt is telling you, you
  12123. might sit there for a while before realising what you need to do.
  12124. Enter a semicolon to complete the statement, and `mysql' will execute
  12125. it:
  12126.  
  12127.      mysql> SELECT USER()
  12128.          -> ;
  12129.      +--------------------+
  12130.      | USER()             |
  12131.      +--------------------+
  12132.      | joesmith@localhost |
  12133.      +--------------------+
  12134.  
  12135. The `'>' and `">' prompts occur during string collection.  In MySQL,
  12136. you can write strings surrounded by either `'' or `"' characters (for
  12137. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  12138. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  12139. that you've entered a line containing a string that begins with a `''
  12140. or `"' quote character, but have not yet entered the matching quote
  12141. that terminates the string.  That's fine if you really are entering a
  12142. multiple-line string, but how likely is that?  Not very.  More often,
  12143. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  12144. quote character.  For example:
  12145.  
  12146.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  12147.          ">
  12148.  
  12149. If you enter this `SELECT' statement, then press Enter and wait for the
  12150. result, nothing will happen.  Instead of wondering why this query takes
  12151. so long, notice the clue provided by the `">' prompt.  It tells you
  12152. that `mysql' expects to see the rest of an unterminated string.  (Do
  12153. you see the error in the statement?  The string `"Smith' is missing the
  12154. second quote.)
  12155.  
  12156. At this point, what do you do?  The simplest thing is to cancel the
  12157. command.  However, you cannot just type `\c' in this case, because
  12158. `mysql' interprets it as part of the string that it is collecting!
  12159. Instead, enter the closing quote character (so `mysql' knows you've
  12160. finished the string), then type `\c':
  12161.  
  12162.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  12163.          "> "\c
  12164.      mysql>
  12165.  
  12166. The prompt changes back to `mysql>', indicating that `mysql' is ready
  12167. for a new command.
  12168.  
  12169. The ``>' prompt is similar to th `'>' and `">' prompts, but indicates
  12170. that you have begun but not completed a backtick-quoted identifier.
  12171.  
  12172. It's important to know what the `'>', `">', and ``>' prompts signify,
  12173. because if you mistakenly enter an unterminated string, any further
  12174. lines you type will appear to be ignored by `mysql'--including a line
  12175. containing `QUIT'!  This can be quite confusing, especially if you
  12176. don't know that you need to supply the terminating quote before you can
  12177. cancel the current command.
  12178.  
  12179. Creating and Using a Database
  12180. =============================
  12181.  
  12182. Now that you know how to enter commands, it's time to access a database.
  12183.  
  12184. Suppose you have several pets in your home (your menagerie) and you'd
  12185. like to keep track of various types of information about them.  You can
  12186. do so by creating tables to hold your data and loading them with the
  12187. desired information.  Then you can answer different sorts of questions
  12188. about your animals by retrieving data from the tables.  This section
  12189. shows you how to:
  12190.  
  12191.    * Create a database
  12192.  
  12193.    * Create a table
  12194.  
  12195.    * Load data into the table
  12196.  
  12197.    * Retrieve data from the table in various ways
  12198.  
  12199.    * Use multiple tables
  12200.  
  12201. The menagerie database will be simple (deliberately), but it is not
  12202. difficult to think of real-world situations in which a similar type of
  12203. database might be used.  For example, a database like this could be
  12204. used by a farmer to keep track of livestock, or by a veterinarian to
  12205. keep track of patient records.  A menagerie distribution containing
  12206. some of the queries and sample data used in the following sections can
  12207. be obtained from the MySQL web site.  It's available in either
  12208. compressed `tar' format
  12209. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz') or
  12210. Zip format
  12211. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip').
  12212.  
  12213. Use the `SHOW' statement to find out what databases currently exist on
  12214. the server:
  12215.  
  12216.      mysql> SHOW DATABASES;
  12217.      +----------+
  12218.      | Database |
  12219.      +----------+
  12220.      | mysql    |
  12221.      | test     |
  12222.      | tmp      |
  12223.      +----------+
  12224.  
  12225. The list of databases is probably different on your machine, but the
  12226. `mysql' and `test' databases are likely to be among them.  The `mysql'
  12227. database is required because it describes user access privileges.  The
  12228. `test' database is often provided as a workspace for users to try
  12229. things out.
  12230.  
  12231. Note that you may not see all databases if you don't have the `SHOW
  12232. DATABASES' privilege. *Note `GRANT': GRANT.
  12233.  
  12234. If the `test' database exists, try to access it:
  12235.  
  12236.      mysql> USE test
  12237.      Database changed
  12238.  
  12239. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  12240. terminate such statements with a semicolon if you like; it does no
  12241. harm.)  The `USE' statement is special in another way, too:  it must be
  12242. given on a single line.
  12243.  
  12244. You can use the `test' database (if you have access to it) for the
  12245. examples that follow, but anything you create in that database can be
  12246. removed by anyone else with access to it.  For this reason, you should
  12247. probably ask your MySQL administrator for permission to use a database
  12248. of your own.  Suppose you want to call yours `menagerie'.  The
  12249. administrator needs to execute a command like this:
  12250.  
  12251.      mysql> GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';
  12252.  
  12253. where `your_mysql_name' is the MySQL username assigned to you and
  12254. `your_client_host' is the host from which you connect to the server.
  12255.  
  12256. Creating and Selecting a Database
  12257. ---------------------------------
  12258.  
  12259. If the administrator creates your database for you when setting up your
  12260. permissions, you can begin using it.  Otherwise, you need to create it
  12261. yourself:
  12262.  
  12263.      mysql> CREATE DATABASE menagerie;
  12264.  
  12265. Under Unix, database names are case-sensitive (unlike SQL keywords), so
  12266. you must always refer to your database as `menagerie', not as
  12267. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  12268. table names.  (Under Windows, this restriction does not apply, although
  12269. you must refer to databases and tables using the same lettercase
  12270. throughout a given query.)
  12271.  
  12272. Creating a database does not select it for use; you must do that
  12273. explicitly.  To make `menagerie' the current database, use this command:
  12274.  
  12275.      mysql> USE menagerie
  12276.      Database changed
  12277.  
  12278. Your database needs to be created only once, but you must select it for
  12279. use each time you begin a `mysql' session.  You can do this by issuing a
  12280. `USE' statement as shown in the example.  Alternatively, you can select
  12281. the database on the command-line when you invoke `mysql'.  Just specify
  12282. its name after any connection parameters that you might need to
  12283. provide.  For example:
  12284.  
  12285.      shell> mysql -h host -u user -p menagerie
  12286.      Enter password: ********
  12287.  
  12288. Note that `menagerie' is not your password on the command just shown.
  12289. If you want to supply your password on the command-line after the `-p'
  12290. option, you must do so with no intervening space (for example, as
  12291. `-pmypassword', not as `-p mypassword').  However, putting your
  12292. password on the command-line is not recommended, because doing so
  12293. exposes it to snooping by other users logged in on your machine.
  12294.  
  12295. Creating a Table
  12296. ----------------
  12297.  
  12298. Creating the database is the easy part, but at this point it's empty, as
  12299. `SHOW TABLES' will tell you:
  12300.  
  12301.      mysql> SHOW TABLES;
  12302.      Empty set (0.00 sec)
  12303.  
  12304. The harder part is deciding what the structure of your database should
  12305. be: what tables you will need and what columns will be in each of them.
  12306.  
  12307. You'll want a table that contains a record for each of your pets.  This
  12308. can be called the `pet' table, and it should contain, as a bare minimum,
  12309. each animal's name.  Because the name by itself is not very
  12310. interesting, the table should contain other information.  For example,
  12311. if more than one person in your family keeps pets, you might want to
  12312. list each animal's owner.  You might also want to record some basic
  12313. descriptive information such as species and sex.
  12314.  
  12315. How about age?  That might be of interest, but it's not a good thing to
  12316. store in a database.  Age changes as time passes, which means you'd
  12317. have to update your records often.  Instead, it's better to store a
  12318. fixed value such as date of birth.  Then, whenever you need age, you
  12319. can calculate it as the difference between the current date and the
  12320. birth date.  MySQL provides functions for doing date arithmetic, so
  12321. this is not difficult.  Storing birth date rather than age has other
  12322. advantages, too:
  12323.  
  12324.    * You can use the database for tasks such as generating reminders
  12325.      for upcoming pet birthdays.  (If you think this type of query is
  12326.      somewhat silly, note that it is the same question you might ask in
  12327.      the context of a business database to identify clients to whom
  12328.      you'll soon need to send out birthday greetings, for that
  12329.      computer-assisted personal touch.)
  12330.  
  12331.    * You can calculate age in relation to dates other than the current
  12332.      date.  For example, if you store death date in the database, you
  12333.      can easily calculate how old a pet was when it died.
  12334.  
  12335. You can probably think of other types of information that would be
  12336. useful in the `pet' table, but the ones identified so far are
  12337. sufficient for now: name, owner, species, sex, birth, and death.
  12338.  
  12339. Use a `CREATE TABLE' statement to specify the layout of your table:
  12340.  
  12341.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  12342.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  12343.  
  12344. `VARCHAR' is a good choice for the `name', `owner', and `species'
  12345. columns because the column values will vary in length.  The lengths of
  12346. those columns need not all be the same, and need not be `20'.  You can
  12347. pick any length from `1' to `255', whatever seems most reasonable to
  12348. you.  (If you make a poor choice and it turns out later that you need a
  12349. longer field, MySQL provides an `ALTER TABLE' statement.)
  12350.  
  12351. Several types of values can be chosen to represent sex in animal
  12352. records, such as `"m"' and `"f"', or perhaps `"male"' and `"female"'.
  12353. It's simplest to use the single characters `"m"' and `"f"'.
  12354.  
  12355. The use of the `DATE' datatype for the `birth' and `death' columns is a
  12356. fairly obvious choice.
  12357.  
  12358. Now that you have created a table, `SHOW TABLES' should produce some
  12359. output:
  12360.  
  12361.      mysql> SHOW TABLES;
  12362.      +---------------------+
  12363.      | Tables in menagerie |
  12364.      +---------------------+
  12365.      | pet                 |
  12366.      +---------------------+
  12367.  
  12368. To verify that your table was created the way you expected, use a
  12369. `DESCRIBE' statement:
  12370.  
  12371.      mysql> DESCRIBE pet;
  12372.      +---------+-------------+------+-----+---------+-------+
  12373.      | Field   | Type        | Null | Key | Default | Extra |
  12374.      +---------+-------------+------+-----+---------+-------+
  12375.      | name    | varchar(20) | YES  |     | NULL    |       |
  12376.      | owner   | varchar(20) | YES  |     | NULL    |       |
  12377.      | species | varchar(20) | YES  |     | NULL    |       |
  12378.      | sex     | char(1)     | YES  |     | NULL    |       |
  12379.      | birth   | date        | YES  |     | NULL    |       |
  12380.      | death   | date        | YES  |     | NULL    |       |
  12381.      +---------+-------------+------+-----+---------+-------+
  12382.  
  12383. You can use `DESCRIBE' any time, for example, if you forget the names of
  12384. the columns in your table or what types they have.
  12385.  
  12386. Loading Data into a Table
  12387. -------------------------
  12388.  
  12389. After creating your table, you need to populate it.  The `LOAD DATA' and
  12390. `INSERT' statements are useful for this.
  12391.  
  12392. Suppose your pet records can be described as shown here.  (Observe that
  12393. MySQL expects dates in `'YYYY-MM-DD'' format; this may be different
  12394. from what you are used to.)
  12395.  
  12396. *name*  *owner* *species**sex**birth*        *death*
  12397. Fluffy  Harold  cat     f    1993-02-04     
  12398. Claws   Gwen    cat     m    1994-03-17     
  12399. Buffy   Harold  dog     f    1989-05-13     
  12400. Fang    Benny   dog     m    1990-08-27     
  12401. Bowser  Diane   dog     m    1979-08-31     1995-07-29
  12402. Chirpy  Gwen    bird    f    1998-09-11     
  12403. WhistlerGwen    bird         1997-12-09     
  12404. Slim    Benny   snake   m    1996-04-29     
  12405.  
  12406. Because you are beginning with an empty table, an easy way to populate
  12407. it is to create a text file containing a row for each of your animals,
  12408. then load the contents of the file into the table with a single
  12409. statement.
  12410.  
  12411. You could create a text file `pet.txt' containing one record per line,
  12412. with values separated by tabs, and given in the order in which the
  12413. columns were listed in the `CREATE TABLE' statement.  For missing
  12414. values (such as unknown sexes or death dates for animals that are still
  12415. living), you can use `NULL' values.  To represent these in your text
  12416. file, use `\N' (backslash, capital-N).  For example, the record for
  12417. Whistler the bird would look like this (where the whitespace between
  12418. values is a single tab character):
  12419.  
  12420. *name*  *owner* *species**sex**birth*        *death*
  12421. `Whistler'`Gwen'  `bird'  `\N' `1997-12-09'   `\N'
  12422.  
  12423. To load the text file `pet.txt' into the `pet' table, use this command:
  12424.  
  12425.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  12426.  
  12427. Note that if you created the file on Windows with an editor that uses
  12428. `\r\n' as a line terminator, you should use:
  12429.  
  12430.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet
  12431.          -> LINES TERMINATED BY '\r\n';
  12432.  
  12433. You can specify the column value separator and end of line marker
  12434. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  12435. are tab and linefeed.  These are sufficient for the statement to read
  12436. the file `pet.txt' properly.
  12437.  
  12438. If the statement fails, it is likely that your MySQL installation does
  12439. not have local file capability enabled by default.  See *Note `LOAD
  12440. DATA LOCAL': LOAD DATA LOCAL for information on how to change this.
  12441.  
  12442. When you want to add new records one at a time, the `INSERT' statement
  12443. is useful.  In its simplest form, you supply values for each column, in
  12444. the order in which the columns were listed in the `CREATE TABLE'
  12445. statement.  Suppose Diane gets a new hamster named Puffball.  You could
  12446. add a new record using an `INSERT' statement like this:
  12447.  
  12448.      mysql> INSERT INTO pet
  12449.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  12450.  
  12451. Note that string and date values are specified as quoted strings here.
  12452. Also, with `INSERT', you can insert `NULL' directly to represent a
  12453. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  12454.  
  12455. From this example, you should be able to see that there would be a lot
  12456. more typing involved to load your records initially using several
  12457. `INSERT' statements rather than a single `LOAD DATA' statement.
  12458.  
  12459. Retrieving Information from a Table
  12460. -----------------------------------
  12461.  
  12462. The `SELECT' statement is used to pull information from a table.  The
  12463. general form of the statement is:
  12464.  
  12465.      SELECT what_to_select
  12466.      FROM which_table
  12467.      WHERE conditions_to_satisfy;
  12468.  
  12469. `what_to_select' indicates what you want to see.  This can be a list of
  12470. columns, or `*' to indicate "all columns." `which_table' indicates the
  12471. table from which you want to retrieve data.  The `WHERE' clause is
  12472. optional.  If it's present, `conditions_to_satisfy' specifies
  12473. conditions that rows must satisfy to qualify for retrieval.
  12474.  
  12475. Selecting All Data
  12476. ..................
  12477.  
  12478. The simplest form of `SELECT' retrieves everything from a table:
  12479.  
  12480.      mysql> SELECT * FROM pet;
  12481.      +----------+--------+---------+------+------------+------------+
  12482.      | name     | owner  | species | sex  | birth      | death      |
  12483.      +----------+--------+---------+------+------------+------------+
  12484.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  12485.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  12486.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  12487.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  12488.      | Bowser   | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
  12489.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  12490.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  12491.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  12492.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  12493.      +----------+--------+---------+------+------------+------------+
  12494.  
  12495. This form of `SELECT' is useful if you want to review your entire table,
  12496. for instance, after you've just loaded it with your initial dataset.
  12497. For example, you may happen to think that the birth date for Bowser
  12498. doesn't seem quite right.  Consulting your original pedigree papers,
  12499. you find that the correct birth year should be 1989, not 1979.
  12500.  
  12501. There are least a couple of ways to fix this:
  12502.  
  12503.    * Edit the file `pet.txt' to correct the error, then empty the table
  12504.      and reload it using `DELETE' and `LOAD DATA':
  12505.  
  12506.           mysql> DELETE FROM pet;
  12507.           mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  12508.  
  12509.      However, if you do this, you must also re-enter the record for
  12510.      Puffball.
  12511.  
  12512.    * Fix only the erroneous record with an `UPDATE' statement:
  12513.  
  12514.           mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
  12515.  
  12516.      The `UPDATE' changes only the record in question and does not
  12517.      require you to reload the table.
  12518.  
  12519. Selecting Particular Rows
  12520. .........................
  12521.  
  12522. As shown in the preceding section, it is easy to retrieve an entire
  12523. table.  Just omit the `WHERE' clause from the `SELECT' statement.  But
  12524. typically you don't want to see the entire table, particularly when it
  12525. becomes large.  Instead, you're usually more interested in answering a
  12526. particular question, in which case you specify some constraints on the
  12527. information you want.  Let's look at some selection queries in terms of
  12528. questions about your pets that they answer.
  12529.  
  12530. You can select only particular rows from your table.  For example, if
  12531. you want to verify the change that you made to Bowser's birth date,
  12532. select Bowser's record like this:
  12533.  
  12534.      mysql> SELECT * FROM pet WHERE name = "Bowser";
  12535.      +--------+-------+---------+------+------------+------------+
  12536.      | name   | owner | species | sex  | birth      | death      |
  12537.      +--------+-------+---------+------+------------+------------+
  12538.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12539.      +--------+-------+---------+------+------------+------------+
  12540.  
  12541. The output confirms that the year is correctly recorded now as 1989,
  12542. not 1979.
  12543.  
  12544. String comparisons normally are case-insensitive, so you can specify the
  12545. name as `"bowser"', `"BOWSER"', etc.  The query result will be the same.
  12546.  
  12547. You can specify conditions on any column, not just `name'.  For example,
  12548. if you want to know which animals were born after 1998, test the `birth'
  12549. column:
  12550.  
  12551.      mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
  12552.      +----------+-------+---------+------+------------+-------+
  12553.      | name     | owner | species | sex  | birth      | death |
  12554.      +----------+-------+---------+------+------------+-------+
  12555.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  12556.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  12557.      +----------+-------+---------+------+------------+-------+
  12558.  
  12559. You can combine conditions, for example, to locate female dogs:
  12560.  
  12561.      mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
  12562.      +-------+--------+---------+------+------------+-------+
  12563.      | name  | owner  | species | sex  | birth      | death |
  12564.      +-------+--------+---------+------+------------+-------+
  12565.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12566.      +-------+--------+---------+------+------------+-------+
  12567.  
  12568. The preceding query uses the `AND' logical operator.  There is also an
  12569. `OR' operator:
  12570.  
  12571.      mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
  12572.      +----------+-------+---------+------+------------+-------+
  12573.      | name     | owner | species | sex  | birth      | death |
  12574.      +----------+-------+---------+------+------------+-------+
  12575.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  12576.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  12577.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  12578.      +----------+-------+---------+------+------------+-------+
  12579.  
  12580. `AND' and `OR' may be intermixed, though `AND' has higher precedence
  12581. than `OR'.  If you use both operators, it's a good idea to use
  12582. parentheses to indicate explicitly how conditions should be grouped:
  12583.  
  12584.      mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
  12585.          -> OR (species = "dog" AND sex = "f");
  12586.      +-------+--------+---------+------+------------+-------+
  12587.      | name  | owner  | species | sex  | birth      | death |
  12588.      +-------+--------+---------+------+------------+-------+
  12589.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12590.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12591.      +-------+--------+---------+------+------------+-------+
  12592.  
  12593. Selecting Particular Columns
  12594. ............................
  12595.  
  12596. If you don't want to see entire rows from your table, just name the
  12597. columns in which you're interested, separated by commas.  For example,
  12598. if you want to know when your animals were born, select the `name' and
  12599. `birth' columns:
  12600.  
  12601.      mysql> SELECT name, birth FROM pet;
  12602.      +----------+------------+
  12603.      | name     | birth      |
  12604.      +----------+------------+
  12605.      | Fluffy   | 1993-02-04 |
  12606.      | Claws    | 1994-03-17 |
  12607.      | Buffy    | 1989-05-13 |
  12608.      | Fang     | 1990-08-27 |
  12609.      | Bowser   | 1989-08-31 |
  12610.      | Chirpy   | 1998-09-11 |
  12611.      | Whistler | 1997-12-09 |
  12612.      | Slim     | 1996-04-29 |
  12613.      | Puffball | 1999-03-30 |
  12614.      +----------+------------+
  12615.  
  12616. To find out who owns pets, use this query:
  12617.  
  12618.      mysql> SELECT owner FROM pet;
  12619.      +--------+
  12620.      | owner  |
  12621.      +--------+
  12622.      | Harold |
  12623.      | Gwen   |
  12624.      | Harold |
  12625.      | Benny  |
  12626.      | Diane  |
  12627.      | Gwen   |
  12628.      | Gwen   |
  12629.      | Benny  |
  12630.      | Diane  |
  12631.      +--------+
  12632.  
  12633. However, notice that the query simply retrieves the `owner' field from
  12634. each record, and some of them appear more than once.  To minimise the
  12635. output, retrieve each unique output record just once by adding the
  12636. keyword `DISTINCT':
  12637.  
  12638.      mysql> SELECT DISTINCT owner FROM pet;
  12639.      +--------+
  12640.      | owner  |
  12641.      +--------+
  12642.      | Benny  |
  12643.      | Diane  |
  12644.      | Gwen   |
  12645.      | Harold |
  12646.      +--------+
  12647.  
  12648. You can use a `WHERE' clause to combine row selection with column
  12649. selection.  For example, to get birth dates for dogs and cats only, use
  12650. this query:
  12651.  
  12652.      mysql> SELECT name, species, birth FROM pet
  12653.          -> WHERE species = "dog" OR species = "cat";
  12654.      +--------+---------+------------+
  12655.      | name   | species | birth      |
  12656.      +--------+---------+------------+
  12657.      | Fluffy | cat     | 1993-02-04 |
  12658.      | Claws  | cat     | 1994-03-17 |
  12659.      | Buffy  | dog     | 1989-05-13 |
  12660.      | Fang   | dog     | 1990-08-27 |
  12661.      | Bowser | dog     | 1989-08-31 |
  12662.      +--------+---------+------------+
  12663.  
  12664. Sorting Rows
  12665. ............
  12666.  
  12667. You may have noticed in the preceding examples that the result rows are
  12668. displayed in no particular order.  It's often easier to examine query
  12669. output when the rows are sorted in some meaningful way.  To sort a
  12670. result, use an `ORDER BY' clause.
  12671.  
  12672. Here are animal birthdays, sorted by date:
  12673.  
  12674.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  12675.      +----------+------------+
  12676.      | name     | birth      |
  12677.      +----------+------------+
  12678.      | Buffy    | 1989-05-13 |
  12679.      | Bowser   | 1989-08-31 |
  12680.      | Fang     | 1990-08-27 |
  12681.      | Fluffy   | 1993-02-04 |
  12682.      | Claws    | 1994-03-17 |
  12683.      | Slim     | 1996-04-29 |
  12684.      | Whistler | 1997-12-09 |
  12685.      | Chirpy   | 1998-09-11 |
  12686.      | Puffball | 1999-03-30 |
  12687.      +----------+------------+
  12688.  
  12689. On character type columns, sorting--like all other comparison
  12690. operations--is normally performed in a case-insensitive fashion.  This
  12691. means that the order will be undefined for columns that are identical
  12692. except for their case. You can force a case-sensitive sort for a column
  12693. by using the `BINARY' cast: `ORDER BY BINARY col_name'.
  12694.  
  12695. The default sort order is ascending, with smallest values first.  To
  12696. sort in reverse (descending) order, add the `DESC' keyword to the name
  12697. of the column you are sorting by:
  12698.  
  12699.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  12700.      +----------+------------+
  12701.      | name     | birth      |
  12702.      +----------+------------+
  12703.      | Puffball | 1999-03-30 |
  12704.      | Chirpy   | 1998-09-11 |
  12705.      | Whistler | 1997-12-09 |
  12706.      | Slim     | 1996-04-29 |
  12707.      | Claws    | 1994-03-17 |
  12708.      | Fluffy   | 1993-02-04 |
  12709.      | Fang     | 1990-08-27 |
  12710.      | Bowser   | 1989-08-31 |
  12711.      | Buffy    | 1989-05-13 |
  12712.      +----------+------------+
  12713.  
  12714. You can sort on multiple columns, and you can sort columns in different
  12715. directions.  For example, to sort by type of animal in ascending order,
  12716. then by birth date within animal type in descending order (youngest
  12717. animals first), use the following query:
  12718.  
  12719.      mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
  12720.      +----------+---------+------------+
  12721.      | name     | species | birth      |
  12722.      +----------+---------+------------+
  12723.      | Chirpy   | bird    | 1998-09-11 |
  12724.      | Whistler | bird    | 1997-12-09 |
  12725.      | Claws    | cat     | 1994-03-17 |
  12726.      | Fluffy   | cat     | 1993-02-04 |
  12727.      | Fang     | dog     | 1990-08-27 |
  12728.      | Bowser   | dog     | 1989-08-31 |
  12729.      | Buffy    | dog     | 1989-05-13 |
  12730.      | Puffball | hamster | 1999-03-30 |
  12731.      | Slim     | snake   | 1996-04-29 |
  12732.      +----------+---------+------------+
  12733.  
  12734. Note that the `DESC' keyword applies only to the column name immediately
  12735. preceding it (`birth'); it does not affect the `species' column sort
  12736. order.
  12737.  
  12738. Date Calculations
  12739. .................
  12740.  
  12741. MySQL provides several functions that you can use to perform
  12742. calculations on dates, for example, to calculate ages or extract parts
  12743. of dates.
  12744.  
  12745. To determine how many years old each of your pets is, compute the
  12746. difference in the year part of the current date and the birth date, then
  12747. subtract one if the current date occurs earlier in the calendar year
  12748. than the birth date.  The following query shows, for each pet, the
  12749. birth date, the current date, and the age in years.
  12750.  
  12751.      mysql> SELECT name, birth, CURDATE(),
  12752.          -> (YEAR(CURDATE())-YEAR(birth))
  12753.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  12754.          -> AS age
  12755.          -> FROM pet;
  12756.      +----------+------------+------------+------+
  12757.      | name     | birth      | CURDATE()  | age  |
  12758.      +----------+------------+------------+------+
  12759.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  12760.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  12761.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  12762.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  12763.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  12764.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  12765.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  12766.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  12767.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  12768.      +----------+------------+------------+------+
  12769.  
  12770. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  12771. off the rightmost five characters that represent the `MM-DD' (calendar
  12772. year) part of the date.  The part of the expression that compares the
  12773. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  12774. down a year if `CURDATE()' occurs earlier in the year than `birth'.
  12775. The full expression is somewhat ungainly, so an alias (`age') is used
  12776. to make the output column label more meaningful.
  12777.  
  12778. The query works, but the result could be scanned more easily if the rows
  12779. were presented in some order.  This can be done by adding an `ORDER BY
  12780. name' clause to sort the output by name:
  12781.  
  12782.      mysql> SELECT name, birth, CURDATE(),
  12783.          -> (YEAR(CURDATE())-YEAR(birth))
  12784.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  12785.          -> AS age
  12786.          -> FROM pet ORDER BY name;
  12787.      +----------+------------+------------+------+
  12788.      | name     | birth      | CURDATE()  | age  |
  12789.      +----------+------------+------------+------+
  12790.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  12791.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  12792.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  12793.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  12794.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  12795.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  12796.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  12797.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  12798.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  12799.      +----------+------------+------------+------+
  12800.  
  12801. To sort the output by `age' rather than `name', just use a different
  12802. `ORDER BY' clause:
  12803.  
  12804.      mysql> SELECT name, birth, CURDATE(),
  12805.          -> (YEAR(CURDATE())-YEAR(birth))
  12806.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  12807.          -> AS age
  12808.          -> FROM pet ORDER BY age;
  12809.      +----------+------------+------------+------+
  12810.      | name     | birth      | CURDATE()  | age  |
  12811.      +----------+------------+------------+------+
  12812.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  12813.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  12814.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  12815.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  12816.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  12817.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  12818.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  12819.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  12820.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  12821.      +----------+------------+------------+------+
  12822.  
  12823. A similar query can be used to determine age at death for animals that
  12824. have died.  You determine which animals these are by checking whether
  12825. the `death' value is `NULL'.  Then, for those with non-`NULL' values,
  12826. compute the difference between the `death' and `birth' values:
  12827.  
  12828.      mysql> SELECT name, birth, death,
  12829.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  12830.          -> AS age
  12831.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  12832.      +--------+------------+------------+------+
  12833.      | name   | birth      | death      | age  |
  12834.      +--------+------------+------------+------+
  12835.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  12836.      +--------+------------+------------+------+
  12837.  
  12838. The query uses `death IS NOT NULL' rather than `death <> NULL' because
  12839. `NULL' is a special value that cannot be compared using the usual
  12840. comparison operators.  This is discussed later.  *Note Working with
  12841. `NULL': Working with NULL.
  12842.  
  12843. What if you want to know which animals have birthdays next month?  For
  12844. this type of calculation, year and day are irrelevant; you simply want
  12845. to extract the month part of the `birth' column.  MySQL provides several
  12846. date-part extraction functions, such as `YEAR()', `MONTH()', and
  12847. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  12848. how it works, run a simple query that displays the value of both
  12849. `birth' and `MONTH(birth)':
  12850.  
  12851.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  12852.      +----------+------------+--------------+
  12853.      | name     | birth      | MONTH(birth) |
  12854.      +----------+------------+--------------+
  12855.      | Fluffy   | 1993-02-04 |            2 |
  12856.      | Claws    | 1994-03-17 |            3 |
  12857.      | Buffy    | 1989-05-13 |            5 |
  12858.      | Fang     | 1990-08-27 |            8 |
  12859.      | Bowser   | 1989-08-31 |            8 |
  12860.      | Chirpy   | 1998-09-11 |            9 |
  12861.      | Whistler | 1997-12-09 |           12 |
  12862.      | Slim     | 1996-04-29 |            4 |
  12863.      | Puffball | 1999-03-30 |            3 |
  12864.      +----------+------------+--------------+
  12865.  
  12866. Finding animals with birthdays in the upcoming month is easy, too.
  12867. Suppose the current month is April.  Then the month value is `4' and
  12868. you look for animals born in May (month `5') like this:
  12869.  
  12870.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  12871.      +-------+------------+
  12872.      | name  | birth      |
  12873.      +-------+------------+
  12874.      | Buffy | 1989-05-13 |
  12875.      +-------+------------+
  12876.  
  12877. There is a small complication if the current month is December.  You
  12878. don't just add one to the month number (`12') and look for animals born
  12879. in month `13', because there is no such month.  Instead, you look for
  12880. animals born in January (month `1').
  12881.  
  12882. You can even write the query so that it works no matter what the current
  12883. month is.  That way you don't have to use a particular month number in
  12884. the query.  `DATE_ADD()' allows you to add a time interval to a given
  12885. date.  If you add a month to the value of `CURDATE()', then extract the
  12886. month part with `MONTH()', the result produces the month in which to
  12887. look for birthdays:
  12888.  
  12889.      mysql> SELECT name, birth FROM pet
  12890.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(), INTERVAL 1 MONTH));
  12891.  
  12892. A different way to accomplish the same task is to add `1' to get the
  12893. next month after the current one (after using the modulo function
  12894. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  12895.  
  12896.      mysql> SELECT name, birth FROM pet
  12897.          -> WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1;
  12898.  
  12899. Note that `MONTH' returns a number between `1' and `12'. And
  12900. `MOD(something,12)' returns a number between `0' and `11'. So the
  12901. addition has to be after the `MOD()', otherwise we would go from
  12902. November (`11') to January (`1').
  12903.  
  12904. Working with `NULL' Values
  12905. ..........................
  12906.  
  12907. The `NULL' value can be surprising until you get used to it.
  12908. Conceptually, `NULL' means missing value or unknown value and it is
  12909. treated somewhat differently than other values.  To test for `NULL',
  12910. you cannot use the arithmetic comparison operators such as `=', `<', or
  12911. `<>'.  To demonstrate this for yourself, try the following query:
  12912.  
  12913.      mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
  12914.      +----------+-----------+----------+----------+
  12915.      | 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |
  12916.      +----------+-----------+----------+----------+
  12917.      |     NULL |      NULL |     NULL |     NULL |
  12918.      +----------+-----------+----------+----------+
  12919.  
  12920. Clearly you get no meaningful results from these comparisons.  Use the
  12921. `IS NULL' and `IS NOT NULL' operators instead:
  12922.  
  12923.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  12924.      +-----------+---------------+
  12925.      | 1 IS NULL | 1 IS NOT NULL |
  12926.      +-----------+---------------+
  12927.      |         0 |             1 |
  12928.      +-----------+---------------+
  12929.  
  12930. Note that in MySQL, `0' or `NULL' means false and anything else means
  12931. true. The default truth value from a boolean operation is `1'.
  12932.  
  12933. This special treatment of `NULL' is why, in the previous section, it
  12934. was necessary to determine which animals are no longer alive using
  12935. `death IS NOT NULL' instead of `death <> NULL'.
  12936.  
  12937. Two `NULL' values are regarded as equal in a `GROUP BY'.
  12938.  
  12939. When doing an `ORDER BY', `NULL' values are presented first if you do
  12940. `ORDER BY ... ASC' and last if you do `ORDER BY ... DESC'.
  12941.  
  12942. Note that MySQL 4.0.2 to 4.0.10 incorrectly always sorts `NULL' values
  12943. first regardless of the sort direction.
  12944.  
  12945. Pattern Matching
  12946. ................
  12947.  
  12948. MySQL provides standard SQL pattern matching as well as a form of
  12949. pattern matching based on extended regular expressions similar to those
  12950. used by Unix utilities such as `vi', `grep', and `sed'.
  12951.  
  12952. SQL pattern matching allows you to use `_' to match any single
  12953. character and `%' to match an arbitrary number of characters (including
  12954. zero characters).  In MySQL, SQL patterns are case-insensitive by
  12955. default.  Some examples are shown here.  Note that you do not use `='
  12956. or `<>' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  12957. comparison operators instead.
  12958.  
  12959. To find names beginning with `b':
  12960.  
  12961.      mysql> SELECT * FROM pet WHERE name LIKE "b%";
  12962.      +--------+--------+---------+------+------------+------------+
  12963.      | name   | owner  | species | sex  | birth      | death      |
  12964.      +--------+--------+---------+------+------------+------------+
  12965.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  12966.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  12967.      +--------+--------+---------+------+------------+------------+
  12968.  
  12969. To find names ending with `fy':
  12970.  
  12971.      mysql> SELECT * FROM pet WHERE name LIKE "%fy";
  12972.      +--------+--------+---------+------+------------+-------+
  12973.      | name   | owner  | species | sex  | birth      | death |
  12974.      +--------+--------+---------+------+------------+-------+
  12975.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  12976.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  12977.      +--------+--------+---------+------+------------+-------+
  12978.  
  12979. To find names containing a `w':
  12980.  
  12981.      mysql> SELECT * FROM pet WHERE name LIKE "%w%";
  12982.      +----------+-------+---------+------+------------+------------+
  12983.      | name     | owner | species | sex  | birth      | death      |
  12984.      +----------+-------+---------+------+------------+------------+
  12985.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  12986.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12987.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  12988.      +----------+-------+---------+------+------------+------------+
  12989.  
  12990. To find names containing exactly five characters, use fives instances of
  12991. the `_' pattern character:
  12992.  
  12993.      mysql> SELECT * FROM pet WHERE name LIKE "_____";
  12994.      +-------+--------+---------+------+------------+-------+
  12995.      | name  | owner  | species | sex  | birth      | death |
  12996.      +-------+--------+---------+------+------------+-------+
  12997.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12998.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12999.      +-------+--------+---------+------+------------+-------+
  13000.  
  13001. The other type of pattern matching provided by MySQL uses extended
  13002. regular expressions.  When you test for a match for this type of
  13003. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  13004. `NOT RLIKE', which are synonyms).
  13005.  
  13006. Some characteristics of extended regular expressions are:
  13007.  
  13008.    * `.' matches any single character.
  13009.  
  13010.    * A character class `[...]' matches any character within the
  13011.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  13012.      a range of characters, use a dash.  `[a-z]' matches any letter,
  13013.      whereas `[0-9]' matches any digit.
  13014.  
  13015.    * `*' matches zero or more instances of the thing preceding it.  For
  13016.      example, `x*' matches any number of `x' characters, `[0-9]*'
  13017.      matches any number of digits, and `.*' matches any number of
  13018.      anything.
  13019.  
  13020.    * A `REGEXP' pattern match succeed if the pattern matches anywhere
  13021.      in the value being tested.  (This differs from a `LIKE' pattern
  13022.      match, which succeeds only if the pattern matches the entire
  13023.      value.)
  13024.  
  13025.    * To anchor a pattern so that it must match the beginning or end of
  13026.      the value being tested, use `^' at the beginning or `$' at the end
  13027.      of the pattern.
  13028.  
  13029. To demonstrate how extended regular expressions work, the `LIKE' queries
  13030. shown previously are rewritten here to use `REGEXP'.
  13031.  
  13032. To find names beginning with `b', use `^' to match the beginning of the
  13033. name:
  13034.  
  13035.      mysql> SELECT * FROM pet WHERE name REGEXP "^b";
  13036.      +--------+--------+---------+------+------------+------------+
  13037.      | name   | owner  | species | sex  | birth      | death      |
  13038.      +--------+--------+---------+------+------------+------------+
  13039.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  13040.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  13041.      +--------+--------+---------+------+------------+------------+
  13042.  
  13043. Prior to MySQL Version 3.23.4, `REGEXP' is case-sensitive, and the
  13044. previous query will return no rows. In this case, to match either
  13045. lowercase or uppercase `b', use this query instead:
  13046.  
  13047.      mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
  13048.  
  13049. From MySQL 3.23.4 on, if you really want to force a `REGEXP' comparison
  13050. to be case-sensitive, use the `BINARY' keyword to make one of the
  13051. strings a binary string. This query will match only lowercase `b' at
  13052. the beginning of a name:
  13053.  
  13054.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY "^b";
  13055.  
  13056. To find names ending with `fy', use `$' to match the end of the name:
  13057.  
  13058.      mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
  13059.      +--------+--------+---------+------+------------+-------+
  13060.      | name   | owner  | species | sex  | birth      | death |
  13061.      +--------+--------+---------+------+------------+-------+
  13062.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  13063.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  13064.      +--------+--------+---------+------+------------+-------+
  13065.  
  13066. To find names containing a `w', use this query:
  13067.  
  13068.      mysql> SELECT * FROM pet WHERE name REGEXP "w";
  13069.      +----------+-------+---------+------+------------+------------+
  13070.      | name     | owner | species | sex  | birth      | death      |
  13071.      +----------+-------+---------+------+------------+------------+
  13072.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  13073.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  13074.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  13075.      +----------+-------+---------+------+------------+------------+
  13076.  
  13077. Because a regular expression pattern matches if it occurs anywhere in
  13078. the value, it is not necessary in the previous query to put a wildcard
  13079. on either side of the pattern to get it to match the entire value like
  13080. it would be if you used an SQL pattern.
  13081.  
  13082. To find names containing exactly five characters, use `^' and `$' to
  13083. match the beginning and end of the name, and five instances of `.' in
  13084. between:
  13085.  
  13086.      mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
  13087.      +-------+--------+---------+------+------------+-------+
  13088.      | name  | owner  | species | sex  | birth      | death |
  13089.      +-------+--------+---------+------+------------+-------+
  13090.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  13091.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  13092.      +-------+--------+---------+------+------------+-------+
  13093.  
  13094. You could also write the previous query using the `{n}'
  13095. "repeat-`n'-times" operator:
  13096.  
  13097.      mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
  13098.      +-------+--------+---------+------+------------+-------+
  13099.      | name  | owner  | species | sex  | birth      | death |
  13100.      +-------+--------+---------+------+------------+-------+
  13101.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  13102.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  13103.      +-------+--------+---------+------+------------+-------+
  13104.  
  13105. Counting Rows
  13106. .............
  13107.  
  13108. Databases are often used to answer the question, "How often does a
  13109. certain type of data occur in a table?"  For example, you might want to
  13110. know how many pets you have, or how many pets each owner has, or you
  13111. might want to perform various kinds of census operations on your
  13112. animals.
  13113.  
  13114. Counting the total number of animals you have is the same question as
  13115. "How many rows are in the `pet' table?" because there is one record per
  13116. pet.  `COUNT(*)' counts the number of rows, so the query to count your
  13117. animals looks like this:
  13118.  
  13119.      mysql> SELECT COUNT(*) FROM pet;
  13120.      +----------+
  13121.      | COUNT(*) |
  13122.      +----------+
  13123.      |        9 |
  13124.      +----------+
  13125.  
  13126. Earlier, you retrieved the names of the people who owned pets.  You can
  13127. use `COUNT()' if you want to find out how many pets each owner has:
  13128.  
  13129.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  13130.      +--------+----------+
  13131.      | owner  | COUNT(*) |
  13132.      +--------+----------+
  13133.      | Benny  |        2 |
  13134.      | Diane  |        2 |
  13135.      | Gwen   |        3 |
  13136.      | Harold |        2 |
  13137.      +--------+----------+
  13138.  
  13139. Note the use of `GROUP BY' to group together all records for each
  13140. `owner'.  Without it, all you get is an error message:
  13141.  
  13142.      mysql> SELECT owner, COUNT(*) FROM pet;
  13143.      ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  13144.      with no GROUP columns is illegal if there is no GROUP BY clause
  13145.  
  13146. `COUNT()' and `GROUP BY' are useful for characterising your data in
  13147. various ways.  The following examples show different ways to perform
  13148. animal census operations.
  13149.  
  13150. Number of animals per species:
  13151.  
  13152.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  13153.      +---------+----------+
  13154.      | species | COUNT(*) |
  13155.      +---------+----------+
  13156.      | bird    |        2 |
  13157.      | cat     |        2 |
  13158.      | dog     |        3 |
  13159.      | hamster |        1 |
  13160.      | snake   |        1 |
  13161.      +---------+----------+
  13162.  
  13163. Number of animals per sex:
  13164.  
  13165.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  13166.      +------+----------+
  13167.      | sex  | COUNT(*) |
  13168.      +------+----------+
  13169.      | NULL |        1 |
  13170.      | f    |        4 |
  13171.      | m    |        4 |
  13172.      +------+----------+
  13173.  
  13174. (In this output, `NULL' indicates that the sex is unknown.)
  13175.  
  13176. Number of animals per combination of species and sex:
  13177.  
  13178.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  13179.      +---------+------+----------+
  13180.      | species | sex  | COUNT(*) |
  13181.      +---------+------+----------+
  13182.      | bird    | NULL |        1 |
  13183.      | bird    | f    |        1 |
  13184.      | cat     | f    |        1 |
  13185.      | cat     | m    |        1 |
  13186.      | dog     | f    |        1 |
  13187.      | dog     | m    |        2 |
  13188.      | hamster | f    |        1 |
  13189.      | snake   | m    |        1 |
  13190.      +---------+------+----------+
  13191.  
  13192. You need not retrieve an entire table when you use `COUNT()'.  For
  13193. example, the previous query, when performed just on dogs and cats,
  13194. looks like this:
  13195.  
  13196.      mysql> SELECT species, sex, COUNT(*) FROM pet
  13197.          -> WHERE species = "dog" OR species = "cat"
  13198.          -> GROUP BY species, sex;
  13199.      +---------+------+----------+
  13200.      | species | sex  | COUNT(*) |
  13201.      +---------+------+----------+
  13202.      | cat     | f    |        1 |
  13203.      | cat     | m    |        1 |
  13204.      | dog     | f    |        1 |
  13205.      | dog     | m    |        2 |
  13206.      +---------+------+----------+
  13207.  
  13208. Or, if you wanted the number of animals per sex only for known-sex
  13209. animals:
  13210.  
  13211.      mysql> SELECT species, sex, COUNT(*) FROM pet
  13212.          -> WHERE sex IS NOT NULL
  13213.          -> GROUP BY species, sex;
  13214.      +---------+------+----------+
  13215.      | species | sex  | COUNT(*) |
  13216.      +---------+------+----------+
  13217.      | bird    | f    |        1 |
  13218.      | cat     | f    |        1 |
  13219.      | cat     | m    |        1 |
  13220.      | dog     | f    |        1 |
  13221.      | dog     | m    |        2 |
  13222.      | hamster | f    |        1 |
  13223.      | snake   | m    |        1 |
  13224.      +---------+------+----------+
  13225.  
  13226. Using More Than one Table
  13227. .........................
  13228.  
  13229. The `pet' table keeps track of which pets you have.  If you want to
  13230. record other information about them, such as events in their lives like
  13231. visits to the vet or when litters are born, you need another table.
  13232. What should this table look like? It needs:
  13233.  
  13234.    * To contain the pet name so you know which animal each event
  13235.      pertains to.
  13236.  
  13237.    * A date so you know when the event occurred.
  13238.  
  13239.    * A field to describe the event.
  13240.  
  13241.    * An event type field, if you want to be able to categorise events.
  13242.  
  13243. Given these considerations, the `CREATE TABLE' statement for the
  13244. `event' table might look like this:
  13245.  
  13246.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  13247.          -> type VARCHAR(15), remark VARCHAR(255));
  13248.  
  13249. As with the `pet' table, it's easiest to load the initial records by
  13250. creating a tab-delimited text file containing the information:
  13251.  
  13252. *name*      *date*      *type*      *remark*
  13253. Fluffy      1995-05-15  litter      4 kittens, 3 female, 1
  13254.                                     male
  13255. Buffy       1993-06-23  litter      5 puppies, 2 female, 3
  13256.                                     male
  13257. Buffy       1994-06-19  litter      3 puppies, 3 female
  13258. Chirpy      1999-03-21  vet         needed beak straightened
  13259. Slim        1997-08-03  vet         broken rib
  13260. Bowser      1991-10-12  kennel      
  13261. Fang        1991-10-12  kennel      
  13262. Fang        1998-08-28  birthday    Gave him a new chew toy
  13263. Claws       1998-03-17  birthday    Gave him a new flea
  13264.                                     collar
  13265. Whistler    1998-12-09  birthday    First birthday
  13266.  
  13267. Load the records like this:
  13268.  
  13269.      mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
  13270.  
  13271. Based on what you've learned from the queries you've run on the `pet'
  13272. table, you should be able to perform retrievals on the records in the
  13273. `event' table; the principles are the same.  But when is the `event'
  13274. table by itself insufficient to answer questions you might ask?
  13275.  
  13276. Suppose you want to find out the ages at which each pet had its
  13277. litters. We saw earlier how to calculate ages from two dates.  The
  13278. litter date of the mother is in the `event' table, but to calculate her
  13279. age on that date you need her birth date, which is stored in the `pet'
  13280. table.  This means the query requires both tables:
  13281.  
  13282.      mysql> SELECT pet.name,
  13283.          -> (YEAR(date)-YEAR(birth)) - (RIGHT(date,5)<RIGHT(birth,5)) AS age,
  13284.          -> remark
  13285.          -> FROM pet, event
  13286.          -> WHERE pet.name = event.name AND type = "litter";
  13287.      +--------+------+-----------------------------+
  13288.      | name   | age  | remark                      |
  13289.      +--------+------+-----------------------------+
  13290.      | Fluffy |    2 | 4 kittens, 3 female, 1 male |
  13291.      | Buffy  |    4 | 5 puppies, 2 female, 3 male |
  13292.      | Buffy  |    5 | 3 puppies, 3 female         |
  13293.      +--------+------+-----------------------------+
  13294.  
  13295. There are several things to note about this query:
  13296.  
  13297.    * The `FROM' clause lists two tables because the query needs to pull
  13298.      information from both of them.
  13299.  
  13300.    * When combining (joining) information from multiple tables, you
  13301.      need to specify how records in one table can be matched to records
  13302.      in the other.  This is easy because they both have a `name'
  13303.      column.  The query uses `WHERE' clause to match up records in the
  13304.      two tables based on the `name' values.
  13305.  
  13306.    * Because the `name' column occurs in both tables, you must be
  13307.      specific about which table you mean when referring to the column.
  13308.      This is done by prepending the table name to the column name.
  13309.  
  13310. You need not have two different tables to perform a join.  Sometimes it
  13311. is useful to join a table to itself, if you want to compare records in
  13312. a table to other records in that same table.  For example, to find
  13313. breeding pairs among your pets, you can join the `pet' table with
  13314. itself to produce candidate pairs of males and females of like species:
  13315.  
  13316.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  13317.          -> FROM pet AS p1, pet AS p2
  13318.          -> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
  13319.      +--------+------+--------+------+---------+
  13320.      | name   | sex  | name   | sex  | species |
  13321.      +--------+------+--------+------+---------+
  13322.      | Fluffy | f    | Claws  | m    | cat     |
  13323.      | Buffy  | f    | Fang   | m    | dog     |
  13324.      | Buffy  | f    | Bowser | m    | dog     |
  13325.      +--------+------+--------+------+---------+
  13326.  
  13327. In this query, we specify aliases for the table name in order to refer
  13328. to the columns and keep straight which instance of the table each
  13329. column reference is associated with.
  13330.  
  13331. Getting Information About Databases and Tables
  13332. ==============================================
  13333.  
  13334. What if you forget the name of a database or table, or what the
  13335. structure of a given table is (for example, what its columns are
  13336. called)?  MySQL addresses this problem through several statements that
  13337. provide information about the databases and tables it supports.
  13338.  
  13339. You have already seen `SHOW DATABASES', which lists the databases
  13340. managed by the server.  To find out which database is currently
  13341. selected, use the `DATABASE()' function:
  13342.  
  13343.      mysql> SELECT DATABASE();
  13344.      +------------+
  13345.      | DATABASE() |
  13346.      +------------+
  13347.      | menagerie  |
  13348.      +------------+
  13349.  
  13350. If you haven't selected any database yet, the result is `NULL' (or the
  13351. empty string before MySQL 4.1.1).
  13352.  
  13353. To find out what tables the current database contains (for example, when
  13354. you're not sure about the name of a table), use this command:
  13355.  
  13356.      mysql> SHOW TABLES;
  13357.      +---------------------+
  13358.      | Tables in menagerie |
  13359.      +---------------------+
  13360.      | event               |
  13361.      | pet                 |
  13362.      +---------------------+
  13363.  
  13364. If you want to find out about the structure of a table, the `DESCRIBE'
  13365. command is useful; it displays information about each of a table's
  13366. columns:
  13367.  
  13368.      mysql> DESCRIBE pet;
  13369.      +---------+-------------+------+-----+---------+-------+
  13370.      | Field   | Type        | Null | Key | Default | Extra |
  13371.      +---------+-------------+------+-----+---------+-------+
  13372.      | name    | varchar(20) | YES  |     | NULL    |       |
  13373.      | owner   | varchar(20) | YES  |     | NULL    |       |
  13374.      | species | varchar(20) | YES  |     | NULL    |       |
  13375.      | sex     | char(1)     | YES  |     | NULL    |       |
  13376.      | birth   | date        | YES  |     | NULL    |       |
  13377.      | death   | date        | YES  |     | NULL    |       |
  13378.      +---------+-------------+------+-----+---------+-------+
  13379.  
  13380. `Field' indicates the column name, `Type' is the datatype for the
  13381. column, `NULL' indicates whether the column can contain `NULL' values,
  13382. `Key' indicates whether the column is indexed, and `Default' specifies
  13383. the column's default value.
  13384.  
  13385. If you have indexes on a table, `SHOW INDEX FROM tbl_name' produces
  13386. information about them.
  13387.  
  13388. Using `mysql' in Batch Mode
  13389. ===========================
  13390.  
  13391. In the previous sections, you used `mysql' interactively to enter
  13392. queries and view the results.  You can also run `mysql' in batch mode.
  13393. To do this, put the commands you want to run in a file, then tell
  13394. `mysql' to read its input from the file:
  13395.  
  13396.      shell> mysql < batch-file
  13397.  
  13398. If you are running `mysql' under Windows and have some special
  13399. characters in the file that cause problems, you can do this:
  13400.  
  13401.      dos> mysql -e "source batch-file"
  13402.  
  13403. If you need to specify connection parameters on the command line, the
  13404. command might look like this:
  13405.  
  13406.      shell> mysql -h host -u user -p < batch-file
  13407.      Enter password: ********
  13408.  
  13409. When you use `mysql' this way, you are creating a script file, then
  13410. executing the script.
  13411.  
  13412. If you want the script to continue even if some of the statements in it
  13413. produce errors, you should use the `--force' command-line option.
  13414.  
  13415. Why use a script?  Here are a few reasons:
  13416.  
  13417.    * If you run a query repeatedly (say, every day or every week),
  13418.      making it a script allows you to avoid retyping it each time you
  13419.      execute it.
  13420.  
  13421.    * You can generate new queries from existing ones that are similar
  13422.      by copying and editing script files.
  13423.  
  13424.    * Batch mode can also be useful while you're developing a query,
  13425.      particularly for multiple-line commands or multiple-statement
  13426.      sequences of commands.  If you make a mistake, you don't have to
  13427.      retype everything.  Just edit your script to correct the error,
  13428.      then tell `mysql' to execute it again.
  13429.  
  13430.    * If you have a query that produces a lot of output, you can run the
  13431.      output through a pager rather than watching it scroll off the top
  13432.      of your screen:
  13433.  
  13434.           shell> mysql < batch-file | more
  13435.  
  13436.    * You can catch the output in a file for further processing:
  13437.  
  13438.           shell> mysql < batch-file > mysql.out
  13439.  
  13440.    * You can distribute your script to other people so they can run the
  13441.      commands, too.
  13442.  
  13443.    * Some situations do not allow for interactive use, for example,
  13444.      when you run a query from a `cron' job.  In this case, you must
  13445.      use batch mode.
  13446.  
  13447. The default output format is different (more concise) when you run
  13448. `mysql' in batch mode than when you use it interactively.  For example,
  13449. the output of `SELECT DISTINCT species FROM pet' looks like this when
  13450. `mysql' is run interactively:
  13451.  
  13452.      +---------+
  13453.      | species |
  13454.      +---------+
  13455.      | bird    |
  13456.      | cat     |
  13457.      | dog     |
  13458.      | hamster |
  13459.      | snake   |
  13460.      +---------+
  13461.  
  13462. In batch mode, the output looks like this instead:
  13463.  
  13464.      species
  13465.      bird
  13466.      cat
  13467.      dog
  13468.      hamster
  13469.      snake
  13470.  
  13471. If you want to get the interactive output format in batch mode, use
  13472. `mysql -t'.  To echo to the output the commands that are executed, use
  13473. `mysql -vvv'.
  13474.  
  13475. You can also use scripts from the `mysql' prompt by using the `source'
  13476. command:
  13477.  
  13478.      mysql> source filename;
  13479.  
  13480. Examples of Common Queries
  13481. ==========================
  13482.  
  13483. Here are examples of how to solve some common problems with MySQL.
  13484.  
  13485. Some of the examples use the table `shop' to hold the price of each
  13486. article (item number) for certain traders (dealers).  Supposing that
  13487. each trader has a single fixed price per article, then (`article',
  13488. `dealer') is a primary key for the records.
  13489.  
  13490. Start the command-line tool `mysql' and select a database:
  13491.  
  13492.      shell> mysql your-database-name
  13493.  
  13494. (In most MySQL installations, you can use the database name `test').
  13495.  
  13496. You can create and populate the example table with these statements:
  13497.  
  13498.      mysql> CREATE TABLE shop (
  13499.          -> article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  13500.          -> dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  13501.          -> price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  13502.          -> PRIMARY KEY(article, dealer));
  13503.      mysql> INSERT INTO shop VALUES
  13504.          -> (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
  13505.          -> (3,'D',1.25),(4,'D',19.95);
  13506.  
  13507. After issuing the statements, the table should have the following
  13508. contents:
  13509.  
  13510.      mysql> SELECT * FROM shop;
  13511.      +---------+--------+-------+
  13512.      | article | dealer | price |
  13513.      +---------+--------+-------+
  13514.      |    0001 | A      |  3.45 |
  13515.      |    0001 | B      |  3.99 |
  13516.      |    0002 | A      | 10.99 |
  13517.      |    0003 | B      |  1.45 |
  13518.      |    0003 | C      |  1.69 |
  13519.      |    0003 | D      |  1.25 |
  13520.      |    0004 | D      | 19.95 |
  13521.      +---------+--------+-------+
  13522.  
  13523. The Maximum Value for a Column
  13524. ------------------------------
  13525.  
  13526. "What's the highest item number?"
  13527.  
  13528.      SELECT MAX(article) AS article FROM shop;
  13529.      
  13530.      +---------+
  13531.      | article |
  13532.      +---------+
  13533.      |       4 |
  13534.      +---------+
  13535.  
  13536. The Row Holding the Maximum of a Certain Column
  13537. -----------------------------------------------
  13538.  
  13539. "Find number, dealer, and price of the most expensive article."
  13540.  
  13541. In SQL-99 (and MySQL Version 4.1) this is easily done with a subquery:
  13542.  
  13543.      SELECT article, dealer, price
  13544.      FROM   shop
  13545.      WHERE  price=(SELECT MAX(price) FROM shop);
  13546.  
  13547. In MySQL versions prior to 4.1, just do it in two steps:
  13548.  
  13549.   1. Get the maximum price value from the table with a `SELECT'
  13550.      statement.
  13551.           mysql> SELECT MAX(price) FROM shop;
  13552.           +------------+
  13553.           | MAX(price) |
  13554.           +------------+
  13555.           |      19.95 |
  13556.           +------------+
  13557.  
  13558.   2. Using the value 19.95 shown by the previous query to be the maximum
  13559.      article price, write a query to locate and display the
  13560.      corresponding record:
  13561.           mysql> SELECT article, dealer, price
  13562.               -> FROM   shop
  13563.               -> WHERE  price=19.95;
  13564.           +---------+--------+-------+
  13565.           | article | dealer | price |
  13566.           +---------+--------+-------+
  13567.           |    0004 | D      | 19.95 |
  13568.           +---------+--------+-------+
  13569.  
  13570. Another solution is to sort all rows descending by price and only get
  13571. the first row using the MySQL-specific `LIMIT' clause:
  13572.  
  13573.      SELECT article, dealer, price
  13574.      FROM   shop
  13575.      ORDER BY price DESC
  13576.      LIMIT 1;
  13577.  
  13578. *NOTE*:  If there were several most expensive articles, each with a
  13579. price of 19.95, the `LIMIT' solution would show only one of them!
  13580.  
  13581. Maximum of Column per Group
  13582. ---------------------------
  13583.  
  13584. "What's the highest price per article?"
  13585.  
  13586.      SELECT article, MAX(price) AS price
  13587.      FROM   shop
  13588.      GROUP BY article
  13589.      
  13590.      +---------+-------+
  13591.      | article | price |
  13592.      +---------+-------+
  13593.      |    0001 |  3.99 |
  13594.      |    0002 | 10.99 |
  13595.      |    0003 |  1.69 |
  13596.      |    0004 | 19.95 |
  13597.      +---------+-------+
  13598.  
  13599. The Rows Holding the Group-wise Maximum of a Certain Field
  13600. ----------------------------------------------------------
  13601.  
  13602. "For each article, find the dealer or dealers with the most expensive
  13603. price."
  13604.  
  13605. In SQL-99 (and MySQL Version 4.1 or greater), the problem can be solved
  13606. with a subquery like this:
  13607.  
  13608.      SELECT article, dealer, price
  13609.      FROM   shop s1
  13610.      WHERE  price=(SELECT MAX(s2.price)
  13611.                    FROM shop s2
  13612.                    WHERE s1.article = s2.article);
  13613.  
  13614. In MySQL versions prior to 4.1, it's best do it in several steps:
  13615.  
  13616.   1. Get the list of (article,maxprice) pairs.
  13617.  
  13618.   2. For each article, get the corresponding rows that have the stored
  13619.      maximum price.
  13620.  
  13621. This can easily be done with a temporary table and a join:
  13622.  
  13623.      CREATE TEMPORARY TABLE tmp (
  13624.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  13625.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  13626.      
  13627.      LOCK TABLES shop READ;
  13628.      
  13629.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  13630.      
  13631.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  13632.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  13633.      
  13634.      UNLOCK TABLES;
  13635.      
  13636.      DROP TABLE tmp;
  13637.  
  13638. If you don't use a `TEMPORARY' table, you must also lock the `tmp'
  13639. table.
  13640.  
  13641. "Can it be done with a single query?"
  13642.  
  13643. Yes, but only by using a quite inefficient trick called the "MAX-CONCAT
  13644. trick":
  13645.  
  13646.      SELECT article,
  13647.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  13648.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  13649.      FROM   shop
  13650.      GROUP BY article;
  13651.      
  13652.      +---------+--------+-------+
  13653.      | article | dealer | price |
  13654.      +---------+--------+-------+
  13655.      |    0001 | B      |  3.99 |
  13656.      |    0002 | A      | 10.99 |
  13657.      |    0003 | C      |  1.69 |
  13658.      |    0004 | D      | 19.95 |
  13659.      +---------+--------+-------+
  13660.  
  13661. The last example can be made a bit more efficient by doing the
  13662. splitting of the concatenated column in the client.
  13663.  
  13664. Using User Variables
  13665. --------------------
  13666.  
  13667. You can use MySQL user variables to remember results without having to
  13668. store them in temporary variables in the client.  *Note Variables::.
  13669.  
  13670. For example, to find the articles with the highest and lowest price you
  13671. can do this:
  13672.  
  13673.      mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
  13674.      mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
  13675.      +---------+--------+-------+
  13676.      | article | dealer | price |
  13677.      +---------+--------+-------+
  13678.      |    0003 | D      |  1.25 |
  13679.      |    0004 | D      | 19.95 |
  13680.      +---------+--------+-------+
  13681.  
  13682. Using Foreign Keys
  13683. ------------------
  13684.  
  13685. In MySQL 3.23.44 and up, `InnoDB' tables support checking of foreign
  13686. key constraints. *Note `InnoDB': InnoDB.  See also *Note ANSI diff
  13687. Foreign Keys::.
  13688.  
  13689. You don't actually need foreign keys to join two tables.  For table
  13690. types other than `InnoDB'), the only things MySQL currently doesn't do
  13691. are 1) `CHECK' to make sure that the keys you use really exist in the
  13692. table or tables you're referencing and 2) automatically delete rows
  13693. from a table with a foreign key definition. Using your keys to join
  13694. tables will work just fine:
  13695.  
  13696.      CREATE TABLE person (
  13697.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  13698.          name CHAR(60) NOT NULL,
  13699.          PRIMARY KEY (id)
  13700.      );
  13701.      
  13702.      CREATE TABLE shirt (
  13703.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  13704.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  13705.          color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  13706.          owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),
  13707.          PRIMARY KEY (id)
  13708.      );
  13709.      
  13710.      
  13711.      INSERT INTO person VALUES (NULL, 'Antonio Paz');
  13712.      
  13713.      INSERT INTO shirt VALUES
  13714.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  13715.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  13716.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  13717.      
  13718.      
  13719.      INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
  13720.      
  13721.      INSERT INTO shirt VALUES
  13722.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  13723.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  13724.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  13725.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  13726.      
  13727.      
  13728.      SELECT * FROM person;
  13729.      +----+---------------------+
  13730.      | id | name                |
  13731.      +----+---------------------+
  13732.      |  1 | Antonio Paz         |
  13733.      |  2 | Lilliana Angelovska |
  13734.      +----+---------------------+
  13735.      
  13736.      SELECT * FROM shirt;
  13737.      +----+---------+--------+-------+
  13738.      | id | style   | color  | owner |
  13739.      +----+---------+--------+-------+
  13740.      |  1 | polo    | blue   |     1 |
  13741.      |  2 | dress   | white  |     1 |
  13742.      |  3 | t-shirt | blue   |     1 |
  13743.      |  4 | dress   | orange |     2 |
  13744.      |  5 | polo    | red    |     2 |
  13745.      |  6 | dress   | blue   |     2 |
  13746.      |  7 | t-shirt | white  |     2 |
  13747.      +----+---------+--------+-------+
  13748.      
  13749.      
  13750.      SELECT s.* FROM person p, shirt s
  13751.       WHERE p.name LIKE 'Lilliana%'
  13752.         AND s.owner = p.id
  13753.         AND s.color <> 'white';
  13754.      
  13755.      +----+-------+--------+-------+
  13756.      | id | style | color  | owner |
  13757.      +----+-------+--------+-------+
  13758.      |  4 | dress | orange |     2 |
  13759.      |  5 | polo  | red    |     2 |
  13760.      |  6 | dress | blue   |     2 |
  13761.      +----+-------+--------+-------+
  13762.  
  13763. Searching on Two Keys
  13764. ---------------------
  13765.  
  13766. MySQL doesn't yet optimize when you search on two different keys
  13767. combined with `OR' (searching on one key with different `OR' parts is
  13768. optimized quite well):
  13769.  
  13770.      SELECT field1_index, field2_index FROM test_table
  13771.      WHERE field1_index = '1' OR  field2_index = '1'
  13772.  
  13773. The reason is that we haven't yet had time to come up with an efficient
  13774. way to handle this in the general case. (The `AND' handling is, in
  13775. comparison, now completely general and works very well.)
  13776.  
  13777. In MySQL 4.0 and up, you can solve this problem efficiently by using a
  13778. `UNION' that combines the output of two separate `SELECT' statements.
  13779. *Note UNION::.  Each `SELECT' searches only one key and can be
  13780. optimized:
  13781.  
  13782.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
  13783.      UNION
  13784.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  13785.  
  13786. Prior to MySQL 4.0, you can achieve the same effect by using a
  13787. `TEMPORARY' table and separate `SELECT' statements.  This type of
  13788. optimization is also very good if you are using very complicated
  13789. queries where the SQL server does the optimizations in the wrong order.
  13790.  
  13791.      CREATE TEMPORARY TABLE tmp
  13792.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
  13793.      INSERT INTO tmp
  13794.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  13795.      SELECT * from tmp;
  13796.      DROP TABLE tmp;
  13797.  
  13798. The above way to solve this query is in effect a `UNION' of two queries.
  13799.  
  13800. Calculating Visits Per Day
  13801. --------------------------
  13802.  
  13803. The following example shows how you can use the bit group functions to
  13804. calculate the number of days per month a user has visited a web page.
  13805.  
  13806.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL,
  13807.                   day INT(2) UNSIGNED ZEROFILL);
  13808.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),
  13809.                  (2000,2,23),(2000,2,23);
  13810.  
  13811. The example table contains year-month-day values representing visits by
  13812. users to the page. To determine how many different days in each month
  13813. these visits occur, use this query:
  13814.  
  13815.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
  13816.             GROUP BY year,month;
  13817.  
  13818. Which returns:
  13819.  
  13820.      +------+-------+------+
  13821.      | year | month | days |
  13822.      +------+-------+------+
  13823.      | 2000 |    01 |    3 |
  13824.      | 2000 |    02 |    2 |
  13825.      +------+-------+------+
  13826.  
  13827. The query calculates how many different days appear in the table for
  13828. each year/month combination, with automatic removal of duplicate
  13829. entries.
  13830.  
  13831. Using `AUTO_INCREMENT'
  13832. ----------------------
  13833.  
  13834. The `AUTO_INCREMENT' attribute can be used to generate a unique
  13835. identity for new rows:
  13836.  
  13837.      CREATE TABLE animals (
  13838.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13839.                   name CHAR(30) NOT NULL,
  13840.                   PRIMARY KEY (id)
  13841.                   );
  13842.      INSERT INTO animals (name) VALUES ("dog"),("cat"),("penguin"),
  13843.                                        ("lax"),("whale"),("ostrich");
  13844.      SELECT * FROM animals;
  13845.  
  13846. Which returns:
  13847.  
  13848.      +----+---------+
  13849.      | id | name    |
  13850.      +----+---------+
  13851.      |  1 | dog     |
  13852.      |  2 | cat     |
  13853.      |  3 | penguin |
  13854.      |  4 | lax     |
  13855.      |  5 | whale   |
  13856.      |  6 | ostrich |
  13857.      +----+---------+
  13858.  
  13859. You can retrieve the most recent `AUTO_INCREMENT' value with the
  13860. `LAST_INSERT_ID()' SQL function or the `mysql_insert_id()' C API
  13861. function.  Note: For a multiple-row insert,
  13862. `LAST_INSERT_ID()'/`mysql_insert_id()' will actually return the
  13863. `AUTO_INCREMENT' key from the *first* of the inserted rows.  This
  13864. allows multiple-row inserts to be reproduced correctly on other servers
  13865. in a replication setup.
  13866.  
  13867. For `MyISAM' and `BDB' tables you can specify `AUTO_INCREMENT' on a
  13868. secondary column in a multiple-column index.  In this case, the
  13869. generated value for the `AUTO_INCREMENT' column is calculated as
  13870. `MAX(auto_increment_column)+1) WHERE prefix=given-prefix'.  This is
  13871. useful when you want to put data into ordered groups.
  13872.  
  13873.      CREATE TABLE animals (
  13874.                   grp ENUM('fish','mammal','bird') NOT NULL,
  13875.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13876.                   name CHAR(30) NOT NULL,
  13877.                   PRIMARY KEY (grp,id)
  13878.                   );
  13879.      INSERT INTO animals (grp,name) VALUES("mammal","dog"),("mammal","cat"),
  13880.                        ("bird","penguin"),("fish","lax"),("mammal","whale"),
  13881.                        ("bird","ostrich");
  13882.      SELECT * FROM animals ORDER BY grp,id;
  13883.  
  13884. Which returns:
  13885.  
  13886.      +--------+----+---------+
  13887.      | grp    | id | name    |
  13888.      +--------+----+---------+
  13889.      | fish   |  1 | lax     |
  13890.      | mammal |  1 | dog     |
  13891.      | mammal |  2 | cat     |
  13892.      | mammal |  3 | whale   |
  13893.      | bird   |  1 | penguin |
  13894.      | bird   |  2 | ostrich |
  13895.      +--------+----+---------+
  13896.  
  13897. Note that in this case (when the `AUTO_INCREMENT' column is part of a
  13898. multiple-column index), `AUTO_INCREMENT' values will be reused if you
  13899. delete the row with the biggest `AUTO_INCREMENT' value in any group.
  13900. This happens even for `MyISAM' tables, for which `AUTO_INCREMENT'
  13901. values normally are not reused.)
  13902.  
  13903. Queries from the Twin Project
  13904. =============================
  13905.  
  13906. At Analytikerna and Lentus, we have been doing the systems and field
  13907. work for a big research project. This project is a collaboration
  13908. between the Institute of Environmental Medicine at Karolinska
  13909. Institutet Stockholm and the Section on Clinical Research in Aging and
  13910. Psychology at the University of Southern California.
  13911.  
  13912. The project involves a screening part where all twins in Sweden older
  13913. than 65 years are interviewed by telephone. Twins who meet certain
  13914. criteria are passed on to the next stage. In this latter stage, twins
  13915. who want to participate are visited by a doctor/nurse team. Some of the
  13916. examinations include physical and neuropsychological examination,
  13917. laboratory testing, neuroimaging, psychological status assessment, and
  13918. family history collection. In addition, data are collected on medical
  13919. and environmental risk factors.
  13920.  
  13921. More information about Twin studies can be found at:
  13922. `http://www.mep.ki.se/twinreg/index_en.html'
  13923.  
  13924. The latter part of the project is administered with a web interface
  13925. written using Perl and MySQL.
  13926.  
  13927. Each night all data from the interviews is moved into a MySQL database.
  13928.  
  13929. Find All Non-distributed Twins
  13930. ------------------------------
  13931.  
  13932. The following query is used to determine who goes into the second part
  13933. of the project:
  13934.  
  13935.      SELECT
  13936.              CONCAT(p1.id, p1.tvab) + 0 AS tvid,
  13937.              CONCAT(p1.christian_name, " ", p1.surname) AS Name,
  13938.              p1.postal_code AS Code,
  13939.              p1.city AS City,
  13940.              pg.abrev AS Area,
  13941.              IF(td.participation = "Aborted", "A", " ") AS A,
  13942.              p1.dead AS dead1,
  13943.              l.event AS event1,
  13944.              td.suspect AS tsuspect1,
  13945.              id.suspect AS isuspect1,
  13946.              td.severe AS tsevere1,
  13947.              id.severe AS isevere1,
  13948.              p2.dead AS dead2,
  13949.              l2.event AS event2,
  13950.              h2.nurse AS nurse2,
  13951.              h2.doctor AS doctor2,
  13952.              td2.suspect AS tsuspect2,
  13953.              id2.suspect AS isuspect2,
  13954.              td2.severe AS tsevere2,
  13955.              id2.severe AS isevere2,
  13956.              l.finish_date
  13957.      FROM
  13958.              twin_project AS tp
  13959.              /* For Twin 1 */
  13960.              LEFT JOIN twin_data AS td ON tp.id = td.id
  13961.                        AND tp.tvab = td.tvab
  13962.              LEFT JOIN informant_data AS id ON tp.id = id.id
  13963.                        AND tp.tvab = id.tvab
  13964.              LEFT JOIN harmony AS h ON tp.id = h.id
  13965.                        AND tp.tvab = h.tvab
  13966.              LEFT JOIN lentus AS l ON tp.id = l.id
  13967.                        AND tp.tvab = l.tvab
  13968.              /* For Twin 2 */
  13969.              LEFT JOIN twin_data AS td2 ON p2.id = td2.id
  13970.                        AND p2.tvab = td2.tvab
  13971.              LEFT JOIN informant_data AS id2 ON p2.id = id2.id
  13972.                        AND p2.tvab = id2.tvab
  13973.              LEFT JOIN harmony AS h2 ON p2.id = h2.id
  13974.                        AND p2.tvab = h2.tvab
  13975.              LEFT JOIN lentus AS l2 ON p2.id = l2.id
  13976.                        AND p2.tvab = l2.tvab,
  13977.              person_data AS p1,
  13978.              person_data AS p2,
  13979.              postal_groups AS pg
  13980.      WHERE
  13981.              /* p1 gets main twin and p2 gets his/her twin. */
  13982.              /* ptvab is a field inverted from tvab */
  13983.              p1.id = tp.id AND p1.tvab = tp.tvab AND
  13984.              p2.id = p1.id AND p2.ptvab = p1.tvab AND
  13985.              /* Just the sceening survey */
  13986.              tp.survey_no = 5 AND
  13987.              /* Skip if partner died before 65 but allow emigration (dead=9) */
  13988.              (p2.dead = 0 OR p2.dead = 9 OR
  13989.               (p2.dead = 1 AND
  13990.                (p2.death_date = 0 OR
  13991.                 (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
  13992.                  >= 65))))
  13993.              AND
  13994.              (
  13995.              /* Twin is suspect */
  13996.              (td.future_contact = 'Yes' AND td.suspect = 2) OR
  13997.              /* Twin is suspect - Informant is Blessed */
  13998.              (td.future_contact = 'Yes' AND td.suspect = 1
  13999.                                         AND id.suspect = 1) OR
  14000.              /* No twin - Informant is Blessed */
  14001.              (ISNULL(td.suspect) AND id.suspect = 1
  14002.                                  AND id.future_contact = 'Yes') OR
  14003.              /* Twin broken off - Informant is Blessed */
  14004.              (td.participation = 'Aborted'
  14005.               AND id.suspect = 1 AND id.future_contact = 'Yes') OR
  14006.              /* Twin broken off - No inform - Have partner */
  14007.              (td.participation = 'Aborted' AND ISNULL(id.suspect)
  14008.                                            AND p2.dead = 0))
  14009.              AND
  14010.              l.event = 'Finished'
  14011.              /* Get at area code */
  14012.              AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
  14013.              /* Not already distributed */
  14014.              AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
  14015.              /* Has not refused or been aborted */
  14016.              AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
  14017.              OR h.status = 'Died' OR h.status = 'Other')
  14018.      ORDER BY
  14019.              tvid;
  14020.  
  14021. Some explanations:
  14022. `CONCAT(p1.id, p1.tvab) + 0 AS tvid'
  14023.      We want to sort on the concatenated `id' and `tvab' in numerical
  14024.      order. Adding `0' to the result causes MySQL to treat the result
  14025.      as a number.
  14026.  
  14027. column `id'
  14028.      This identifies a pair of twins. It is a key in all tables.
  14029.  
  14030. column `tvab'
  14031.      This identifies a twin in a pair. It has a value of `1' or `2'.
  14032.  
  14033. column `ptvab'
  14034.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  14035.      vice versa. It exists to save typing and to make it easier for
  14036.      MySQL to optimize the query.
  14037.  
  14038. This query demonstrates, among other things, how to do lookups on a
  14039. table from the same table with a join (`p1' and `p2'). In the example,
  14040. this is used to check whether a twin's partner died before the age of
  14041. 65. If so, the row is not returned.
  14042.  
  14043. All of the above exist in all tables with twin-related information. We
  14044. have a key on both `id,tvab' (all tables), and `id,ptvab'
  14045. (`person_data') to make queries faster.
  14046.  
  14047. On our production machine (A 200MHz UltraSPARC), this query returns
  14048. about 150-200 rows and takes less than one second.
  14049.  
  14050. The current number of records in the tables used above:
  14051. *Table*            *Rows*
  14052. `person_data'      71074
  14053. `lentus'           5291
  14054. `twin_project'     5286
  14055. `twin_data'        2012
  14056. `informant_data'   663
  14057. `harmony'          381
  14058. `postal_groups'    100
  14059.  
  14060. Show a Table of Twin Pair Status
  14061. --------------------------------
  14062.  
  14063. Each interview ends with a status code called `event'. The query shown
  14064. here is used to display a table over all twin pairs combined by event.
  14065. This indicates in how many pairs both twins are finished, in how many
  14066. pairs one twin is finished and the other refused, and so on.
  14067.  
  14068.      SELECT
  14069.              t1.event,
  14070.              t2.event,
  14071.              COUNT(*)
  14072.      FROM
  14073.              lentus AS t1,
  14074.              lentus AS t2,
  14075.              twin_project AS tp
  14076.      WHERE
  14077.              /* We are looking at one pair at a time */
  14078.              t1.id = tp.id
  14079.              AND t1.tvab=tp.tvab
  14080.              AND t1.id = t2.id
  14081.              /* Just the sceening survey */
  14082.              AND tp.survey_no = 5
  14083.              /* This makes each pair only appear once */
  14084.              AND t1.tvab='1' AND t2.tvab='2'
  14085.      GROUP BY
  14086.              t1.event, t2.event;
  14087.  
  14088. Using MySQL with Apache
  14089. =======================
  14090.  
  14091. There are programs that let you authenticate your users from a MySQL
  14092. database and also let you write your log files into a MySQL table.
  14093.  
  14094. You can change the Apache logging format to be easily readable by MySQL
  14095. by putting the following into the Apache configuration file:
  14096.  
  14097.      LogFormat \
  14098.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  14099.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  14100.  
  14101. To load a log file in that format into MySQL, you can use a statement
  14102. something like this:
  14103.  
  14104.      LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
  14105.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  14106.  
  14107. The named table should be created to have columns that correspond to
  14108. those that the `LogFormat' line writes to the log file.
  14109.  
  14110. Using MySQL Programs
  14111. ********************
  14112.  
  14113. This chapter provides a brief overview of the programs provided by
  14114. MySQL AB and discusses how to specify options when you run these
  14115. programs.  Most programs have options that are specific to their own
  14116. operation, but the syntax for specifying options is similar for all of
  14117. them. Later chapters provide more detailed descriptions of individual
  14118. programs, including which options they recognize.
  14119.  
  14120. Overview of MySQL Programs
  14121. ==========================
  14122.  
  14123. MySQL AB provides several types of programs:
  14124.  
  14125. The MYSQL server and server startup scripts:
  14126.         * `mysqld' is the MySQL server
  14127.  
  14128.         * `mysqld_safe', `mysql.server', and `mysqld_multi' are server
  14129.           startup scripts
  14130.  
  14131.         * `mysql_install_db' initializes the data directory and the
  14132.           initial databases
  14133.  
  14134. Client programs that access the server:
  14135.         * `mysql' is a command-line client for executing SQL statements
  14136.           interactively or in batch mode
  14137.  
  14138.         * `mysqlcc' (MySQL Control Center) is an interactive graphical
  14139.           tool for executing SQL statements and administration
  14140.  
  14141.         * `mysqladmin' is an administrative client
  14142.  
  14143.         * `mysqlcheck' performs table maintenance operations
  14144.  
  14145.         * `mysqldump' and `mysqlhotcopy' make database backups
  14146.  
  14147.         * `mysqlimport' imports data files
  14148.  
  14149.         * `mysqlshow' displays information about databases and tables
  14150.  
  14151. Utility programs that operate independently of the server:
  14152.         * `myisamchk' performs table maintenance operations
  14153.  
  14154.         * `myisampack' produces compressed, read-only tables
  14155.  
  14156.         * `mysqlbinlog' is a tool for processing binary log files
  14157.  
  14158.         * `mysql_config' shows command-line options for compiling MySQL
  14159.           programs
  14160.  
  14161.         * `perror' displays error code meanings
  14162.  
  14163. More information on running the server may be found in *Note Database
  14164. Administration::.  Client and utility programs are described in more
  14165. detail in *Note Client-Side Scripts::.
  14166.  
  14167. Most MySQL distribution formats include all of these programs, except
  14168. for those programs that are platform-specific. (For example, the server
  14169. startup scripts are not used on Windows.) The exception is that RPM
  14170. distributions are more specialized. There is one RPM for the server,
  14171. another for the client programs, and so forth. If you appear to be
  14172. missing one or more programs, see *Note Installing:: for information on
  14173. distributions and what they contain.  It may be that you need to
  14174. install something else.
  14175.  
  14176. Invoking MySQL Programs
  14177. =======================
  14178.  
  14179. To invoke a MySQL program at the command line (that is, from your shell
  14180. or command prompt), enter the program name followed by any options or
  14181. other arguments needed to instruct the program what you want it to do.
  14182. The following commands show some sample program invocations. "`shell>'"
  14183. represents your command prompt; it is not part of what you type.
  14184.  
  14185.      shell> mysql test
  14186.      shell> mysqldump --quote-names personnel
  14187.      shell> mysqladmin extended-status variables
  14188.      shell> mysqlshow --help
  14189.  
  14190. Arguments that begin with a dash are option arguments. They typically
  14191. specify the type of connection a program should make to the server or
  14192. affect its operational mode. Options have a syntax that is described in
  14193. *Note Program Options::.
  14194.  
  14195. Non-option arguments (arguments with no leading dash) provide additional
  14196. information to the program. For example, the `mysql' program interprets
  14197. the first non-option argument as a database name, so the command `mysql
  14198. test' indicates that you want to use the `test' database.
  14199.  
  14200. Later sections that describe individual programs indicate which options
  14201. a program understands and describe the meaning of any additional
  14202. non-option arguments.
  14203.  
  14204. Some options are common to a number of programs. The most common of
  14205. these are the `--host', `--user', and `--password' options that specify
  14206. connection parameters. They indicate the host where the MySQL server is
  14207. running, and the username and password of your MySQL account. All MySQL
  14208. client programs understand these options; they allow you to specify
  14209. which server to connect to and the account to use on that server.
  14210.  
  14211. Note that you may find it necessary to invoke MySQL programs using the
  14212. pathname to the `bin' directory in which they are installed. This is
  14213. likely to be the case if you get a "program not found" error whenever
  14214. you attempt to run a MySQL program from any directory other than the
  14215. `bin' directory.  To make it more convenient to use MySQL, you can add
  14216. the pathname of the `bin' directory to your `PATH' environment variable
  14217. setting. Then to run a program you need only type its name, not its
  14218. entire pathname.
  14219.  
  14220. Consult the documentation for your command interpreter for instructions
  14221. on setting your `PATH'; the syntax for setting environment variables is
  14222. interpreter-specific.
  14223.  
  14224. Specifying Program Options
  14225. ==========================
  14226.  
  14227. You can provide options for MySQL programs in several ways:
  14228.  
  14229.    * On the command line following the program name. This is most
  14230.      common for options that apply to a specific invocation of the
  14231.      program.
  14232.  
  14233.    * In an option file that the program reads when it starts. This is
  14234.      common for options that you want the program to use each time it
  14235.      runs.
  14236.  
  14237.    * In environment variables. These are useful for options that you
  14238.      want to apply each time the program runs, though in practice
  14239.      option files are used more commonly for this purpose.  (*Note
  14240.      Multiple Unix servers:: discusses one situation in which
  14241.      environment variables can be very helpful. It describes a handy
  14242.      technique that uses such variables to specify the TCP/IP port and
  14243.      Unix socket file for both the server and client programs.)
  14244.  
  14245.  
  14246. MySQL programs determine which options are given by examining
  14247. environment variables first, then option files, then the command line.
  14248. If an option is specified multiple times, the last occurrence takes
  14249. precedence.  This means that environment variables have the lowest
  14250. precedence and command-line options the highest.
  14251.  
  14252. You can take advantage of the way that MySQL programs process options by
  14253. specifying the default value for a program's options in an option file.
  14254. Then you need not type them each time you run the program, but can
  14255. override the defaults if necessary by using command-line options.
  14256.  
  14257. Using Options on the Command Line
  14258. ---------------------------------
  14259.  
  14260. Program options specified on the command line follow these rules:
  14261.  
  14262.    * Options are given after the command name.
  14263.  
  14264.    * An option argument begins with one dash or two dashes, depending
  14265.      on whether it has a short name or a long name. Many options have
  14266.      both forms.  For example, `-?' and `--help' are the short and long
  14267.      forms of the option that instructs a MySQL program to display a
  14268.      help message.
  14269.  
  14270.    * Option names are case sensitive.  `-v' and `-V' are both legal and
  14271.      have different meanings. (They are the corresponding short forms
  14272.      of the `--verbose' and `--version' options.)
  14273.  
  14274.    * Some options take a value following the option name.  For example,
  14275.      `-h localhost' or `--host=localhost' indicate the MySQL server
  14276.      host to a client program.  The option value tells the program the
  14277.      name of the host where the MySQL server is running.
  14278.  
  14279.    * For a long option that takes a value, separate the option name and
  14280.      the value by an `=' sign.  For a short option that takes a value,
  14281.      the option value can immediately follow the option letter, or
  14282.      there can be a space between.  (`-hlocalhost' and `-h localhost'
  14283.      are equivalent.)  An exception to this rule is the option for
  14284.      specifying your MySQL password.  This option can be given in long
  14285.      form as `--password=pass_val' or as `--password'. In the latter
  14286.      case (with no password value given), the program will prompt you
  14287.      for the password.  The password option also may be given in short
  14288.      form as `-ppass_val' or as `-p'. However, for the short form, if
  14289.      the password value is given, it must follow the option letter
  14290.      _with no intervening space_. The reason for this is that if a
  14291.      space follows the option letter, the program has no way to tell
  14292.      whether a following argument is supposed to be the password value
  14293.      or some other kind of argument.  Consequently, the following two
  14294.      commands have two completely different meanings:
  14295.  
  14296.           shell> mysql -ptest
  14297.           shell> mysql -p test
  14298.  
  14299.      The first command instructs `mysql' to use a password value of
  14300.      `test', but specifies no default database.  The second instructs
  14301.      `mysql' to prompt for the password value and to use `test' as the
  14302.      default database.
  14303.  
  14304.  
  14305. MySQL 4.0 introduced some additional flexibility in the way you specify
  14306. options. These changes were made in MySQL 4.0.2. Some of them relate to
  14307. the way you specify options that have "enabled" and "disabled" states,
  14308. and to the use of options that may be present in one version of MySQL
  14309. but not another.  Those capabilities are discussed here.  Another
  14310. change pertains to the way you use options to set program variables.
  14311. *Note Program variables:: discusses that topic further.
  14312.  
  14313. Some options control behavior that can be turned on or off. For example,
  14314. the `mysql' client supports a `--column-names' option that determines
  14315. whether or not to display a row of column names at the beginning of
  14316. query results. By default, this option is enabled. However, you may
  14317. want to disable it in some instances, such as when sending the output
  14318. of `mysql' into another program that expects to see only data and not
  14319. an initial header line.
  14320.  
  14321. To disable column names, you can specify the option using any of these
  14322. forms:
  14323.  
  14324.      --disable-column-names
  14325.      --skip-column-names
  14326.      --column-names=0
  14327.  
  14328. The `--disable' and `--skip' prefixes and the `=0' suffix all have the
  14329. same effect of turning the option off.
  14330.  
  14331. The "enabled" form of the option may be specified as:
  14332.  
  14333.      --column-names
  14334.      --enable-column-names
  14335.      --column-names=1
  14336.  
  14337. Another change to option processing introduced in MySQL 4.0 is that you
  14338. can use the `--loose' prefix for command-line options. If an option is
  14339. prefixed by `--loose', the program will not exit with an error if it
  14340. does not recognize the option, but instead will issue only a warning:
  14341.  
  14342.      shell> mysql --loose-no-such-option
  14343.      mysql: WARNING: unknown option '--no-such-option'
  14344.  
  14345. The `--loose' prefix can be useful when you run programs from multiple
  14346. installations of MySQL on the same machine, at least if all the
  14347. versions are as recent as 4.0.2.  This prefix is particularly useful
  14348. when you list options in an option file.  An option that may not be
  14349. recognized by all versions of a program can be given using the `--loose'
  14350. prefix (or `loose' in an option file). Versions of the program that do
  14351. not recognize the option will issue a warning and ignore it. Note that
  14352. this strategy works only if all versions involved are 4.0.2 or later,
  14353. because earlier versions know nothing of the `--loose' convention.
  14354.  
  14355. Using Option Files
  14356. ------------------
  14357.  
  14358. MySQL programs can read startup options from option files (also
  14359. sometimes called configuration files).  Option files provide a
  14360. convenient way to specify commonly used options so they need not be
  14361. entered on the command line each time you run a program.  Option file
  14362. capability is available from MySQL 3.22 on.
  14363.  
  14364. The following programs support option files:  `mysql', `mysqladmin',
  14365. `mysqld', `mysqld_safe', `mysql.server', `mysqldump', `mysqlimport',
  14366. `mysqlshow', `mysqlcheck', `mysqlhotcopy', `myisamchk', and
  14367. `myisampack'.
  14368.  
  14369. On Windows, MySQL programs read startup options from the following
  14370. files:
  14371.  
  14372. *Filename*             *Purpose*
  14373. `windows-dir\my.ini'   Global options
  14374. `C:\my.cnf'            Global options
  14375.  
  14376. `windows-dir' represents the location of your Windows directory.  This
  14377. is commonly `C:\Windows' or `C:\WinNT'. Check the value of the `WINDIR'
  14378. environment vairable to see where this directory is located on your
  14379. system.
  14380.  
  14381. On Unix, MySQL programs read startup options from the following files:
  14382.  
  14383. *Filename*             *Purpose*
  14384. `/etc/my.cnf'          Global options
  14385. `DATADIR/my.cnf'       Server-specific options
  14386. `defaults-extra-file'  The file specified with
  14387.                        `--defaults-extra-file=path', if any
  14388. `~/.my.cnf'            User-specific options
  14389.  
  14390. `DATADIR' represents the location of the MySQL data directory. Typically
  14391. this is `/usr/local/mysql/data' for a binary installation or
  14392. `/usr/local/var' for a source installation.  Note that this is the data
  14393. directory location that was specified at configuration time, not the
  14394. one specified with `--datadir' when `mysqld' starts!  Use of
  14395. `--datadir' at runtime has no effect on where the server looks for
  14396. option files, because it looks for them before processing any
  14397. command-line arguments.
  14398.  
  14399. MySQL looks for option files in the order listed above and reads any
  14400. that exist.  If multiple option files exist, an option specified in a
  14401. file read later takes precedence over the same option specified in a
  14402. file read earlier.
  14403.  
  14404. Any long option that may be given on the command-line when running a
  14405. MySQL program can be given in an option file as well.  To get the list
  14406. of available options for a program, run it with the `--help' option.
  14407.  
  14408. The syntax for specifying options in an option file is similar to
  14409. command-line syntax, except that you omit the leading two dashes. For
  14410. example, `--quick' or `--host=localhost' on the command line are
  14411. specified as `quick' or `host=localhost' in an option file.  To specify
  14412. an option of the form `--loose-opt_name' in an option file, write it as
  14413. `loose-opt_name'.
  14414.  
  14415. Empty lines in option files are ignored. Non-empty lines can take any
  14416. of the following forms:
  14417.  
  14418. `#comment'
  14419. `;comment'
  14420.      Comment lines start with `#' or `;'. As of MySQL 4.0.14, a
  14421.      `#'-comment can start in the middle of a line as well.
  14422.  
  14423. `[group]'
  14424.      `group' is the name of the program or group for which you want to
  14425.      set options.  After a group line, any `option' or `set-variable'
  14426.      lines apply to the named group until the end of the option file or
  14427.      another group line is given.
  14428.  
  14429. `opt_name'
  14430.      This is equivalent to `--opt_name' on the command-line.
  14431.  
  14432. `opt_name=value'
  14433.      This is equivalent to `--opt_name=value' on the command-line.  In
  14434.      an option file, you can have spaces around the `=' character,
  14435.      something that is not true on the command line.  As of MySQL
  14436.      4.0.16, you can quote the value with double quotes or single
  14437.      quotes.  This is useful if the value contains a comment character
  14438.      or whitespace.
  14439.  
  14440. `set-variable = var_name=value'
  14441.      Set the program variable `var_name' to the given value.  This is
  14442.      equivalent to `--set-variable=var_name=value' on the command-line.
  14443.      Spaces are allowed around the first `=' character but not around
  14444.      the second.  This syntax is deprecated as of MySQL 4.0.  See *Note
  14445.      Program variables:: for more information on setting program
  14446.      variables.
  14447.  
  14448. Note that for options and values, all leading and trailing blanks are
  14449. automatically deleted.  You may use the escape sequences `\b', `\t',
  14450. `\n', `\r', `\\', and `\s' in option values to represent the backspace,
  14451. tab, newline, carriage return, and space characters.
  14452.  
  14453. On Windows, if an option value represents a pathname, you should
  14454. specify the value using `/' rather than `\' as the pathname separator.
  14455. If you use `\', you must double it as `\\', because `\' is the escape
  14456. character in MySQL.
  14457.  
  14458. If an option group name is the same as a program name, options in the
  14459. group apply specifically to that program.
  14460.  
  14461. The `[client]' option group is read by all client programs (but not by
  14462. `mysqld'). This allows you to specify options that apply to every
  14463. client. For example, `[client]' is the perfect group to use to specify
  14464. the password that you use to connect to the server.  (But make sure the
  14465. option file is readable and writable only by yourself, so that other
  14466. people cannot find out your password.) Be sure not to put an option in
  14467. the `[client]' group unless it is recognized by _all_ client programs.
  14468.  
  14469. As of MySQL 4.0.14, if you want to create options that should only be
  14470. read by one specific `mysqld' server release series, you can do this
  14471. with `[mysqld-4.0]', `[mysqld-4.1]', and so forth:
  14472.  
  14473.      [mysqld-4.0]
  14474.      new
  14475.  
  14476. The above `new' option will be used only with MySQL server versions
  14477. 4.0.x.
  14478.  
  14479. Here is a typical global option file:
  14480.  
  14481.      [client]
  14482.      port=3306
  14483.      socket=/tmp/mysql.sock
  14484.      
  14485.      [mysqld]
  14486.      port=3306
  14487.      socket=/tmp/mysql.sock
  14488.      key_buffer_size=16M
  14489.      max_allowed_packet=1M
  14490.      
  14491.      [mysqldump]
  14492.      quick
  14493.  
  14494. Here is a typical user option file:
  14495.  
  14496.      [client]
  14497.      # The following password will be sent to all standard MySQL clients
  14498.      password="my_password"
  14499.      
  14500.      [mysql]
  14501.      no-auto-rehash
  14502.      set-variable = connect_timeout=2
  14503.      
  14504.      [mysqlhotcopy]
  14505.      interactive-timeout
  14506.  
  14507. If you have a source distribution, you will find sample option files
  14508. named `my-xxxx.cnf' in the `support-files' directory.  If you have a
  14509. binary distribution, look in the `support-files' directory under your
  14510. MySQL installation directory (typically `C:\mysql' on Windows or
  14511. `/usr/local/mysql' on Unix).  Currently there are sample option files
  14512. for small, medium, large, and very large systems. To experiment with
  14513. one of these files, copy it to `C:\my.cnf' on Windows or to `.my.cnf'
  14514. in your home directory on Unix.
  14515.  
  14516. All MySQL programs that support option files support the following
  14517. command-line options:
  14518.  
  14519. `--no-defaults'
  14520.      Don't read any option files.
  14521.  
  14522. `--print-defaults'
  14523.      Print the program name and all options that it will get from
  14524.      option files.
  14525.  
  14526. `--defaults-file=path_name'
  14527.      Use only the given option file. `path_name' is the full pathname
  14528.      to the file.
  14529.  
  14530. `--defaults-extra-file=path_name'
  14531.      Read this option file after the global option file but before the
  14532.      user option file. `path_name' is the full pathname to the file.
  14533.  
  14534. Note that to work properly, each of these options must immediately
  14535. follow the command name on the command line, with the exception that
  14536. `--print-defaults' may be used immediately after `--defaults-file' or
  14537. `--defaults-extra-file'.
  14538.  
  14539. In shell scripts, you can use the `my_print_defaults' program to parse
  14540. the option files. The following example shows the output that
  14541. `my_print_defaults' might produce when asked to show the options found
  14542. in the `[client]' and `[mysql]' groups:
  14543.  
  14544.  
  14545.      shell> my_print_defaults client mysql
  14546.      --port=3306
  14547.      --socket=/tmp/mysql.sock
  14548.      --no-auto-rehash
  14549.  
  14550. Note for developers:  Option file handling is implemented in the C
  14551. client library simply by processing all matching options (that is,
  14552. options in the appropriate group) before any command-line arguments.
  14553. This works nicely for programs that use the last instance of an option
  14554. that is specified multiple times. If you have a C or C++ program that
  14555. handles multiply specified options this way but doesn't read option
  14556. files, you need add only two lines to give it that capability.  Check
  14557. the source code of any of the standard MySQL clients to see how to do
  14558. this.
  14559.  
  14560. Several other language interfaces to MySQL are based on the C client
  14561. library, and some of them provide a way to access option file contents.
  14562. These include Perl and Python. See the documentation for your preferred
  14563. interface for details.
  14564.  
  14565. Using Environment Variables to Specify Options
  14566. ----------------------------------------------
  14567.  
  14568. To specify an option using an environment variable, set the variable
  14569. using the syntax appropriate for your comment processor. For example,
  14570. on Windows or NetWare, you can set the `USER' variable to specify your
  14571. MySQL account name.  To do so, use this syntax:
  14572.  
  14573.      SET USER=your_name
  14574.  
  14575. The syntax on Unix depends on your shell. Suppose you want to specify
  14576. the TCP/IP port number using the `MYSQL_TCP_PORT' variable. The syntax
  14577. for Bourne shell and variants (`sh', `bash', `zsh', etc.) is:
  14578.  
  14579.      MYSQL_TCP_PORT=3306
  14580.  
  14581. For `csh' and `tcsh', use this syntax:
  14582.  
  14583.      setenv MYSQL_TCP_PORT 3306
  14584.  
  14585. The commands to set environment variables can be executed at your
  14586. command prompt to take effect immediately. These settings persist until
  14587. you log out.  To have the settings take effect each time you log in,
  14588. place the appropriate command or commands in a startup file that your
  14589. command interpreter reads each time it starts. Typical startup files are
  14590. `AUTOEXEC.BAT' for Windows, `.bash_profile' for `bash', or `.tcshrc'
  14591. for `tcsh'. Consult the documentation for your command interpreter for
  14592. specific details.
  14593.  
  14594. *Note Environment variables:: lists all environment variables that
  14595. affect MySQL program operation.
  14596.  
  14597. Using Options to Set Program Variables
  14598. --------------------------------------
  14599.  
  14600. Many MySQL programs have internal variables that can be set at runtime.
  14601. As of MySQL 4.0.2, program variables are set the same way as any other
  14602. long option that takes a value.  For example, `mysql' has a
  14603. `max_allowed_packet' variable that controls the maximum size of its
  14604. communication buffer.  To set the `max_allowed_packet' variable for
  14605. `mysql' to a value of 64 MB, use either of the following commands:
  14606.  
  14607.      shell> mysql --max_allowed_packet=6710740
  14608.      shell> mysql --max_allowed_packet=64M
  14609.  
  14610. The first command specifies the value in bytes. The second specifies
  14611. the value in megabytes. Variable values can have a suffix of `K', `M',
  14612. or `G' (either uppercase or lowercase) to indicate units of kilobytes,
  14613. megabytes, or gigabytes.
  14614.  
  14615. In an option file, the variable setting is given without the leading
  14616. dashes:
  14617.  
  14618.      [mysql]
  14619.      max_allowed_packet=6710740
  14620.  
  14621. Or:
  14622.  
  14623.      [mysql]
  14624.      max_allowed_packet=64M
  14625.  
  14626. If you like, underscores in a variable name can be specified as dashes.
  14627.  
  14628. Prior to MySQL 4.0.2, program variable names are not recognized as
  14629. option names.  Instead, use the `--set-variable' option to assign a
  14630. value to a variable:
  14631.  
  14632.      shell> mysql --set-variable=max_allowed_packet=6710740
  14633.      shell> mysql --set-variable=max_allowed_packet=64M
  14634.  
  14635. In an option file, omit the leading dashes:
  14636.  
  14637.      [mysql]
  14638.      set-variable = max_allowed_packet=6710740
  14639.  
  14640. Or:
  14641.  
  14642.      [mysql]
  14643.      set-variable = max_allowed_packet=64M
  14644.  
  14645. With `--set-variable', underscores in variable names may not be given as
  14646. dashes for versions of MySQL older than 4.0.2.
  14647.  
  14648. The `--set-variable' option is still recognized in MySQL 4.0.2 and up,
  14649. but is deprecated.
  14650.  
  14651. Database Administration
  14652. ***********************
  14653.  
  14654. This chapter covers topics that deal with administering a MySQL
  14655. installation, such as configuring the server, managing user accounts,
  14656. and performing backups.
  14657.  
  14658. The MySQL Server and Server Startup Scripts
  14659. ===========================================
  14660.  
  14661. The MySQL server, `mysqld', is the main program that does most of the
  14662. work in a MySQL installation. The server is accompanied by several
  14663. related scripts that perform setup operations when you install MySQL or
  14664. that are helper programs to assist you in starting and stopping the
  14665. server.
  14666.  
  14667. Overview of the Server-Side Scripts and Utilities
  14668. -------------------------------------------------
  14669.  
  14670. All MySQL programs take many different options. However, every MySQL
  14671. program provides a `--help' option that you can use to get a
  14672. description of the program's options. For example, try `mysqld --help'.
  14673.  
  14674. You can override default options for all standard programs by specifying
  14675. options on the command line or in an option file.  *Note Program
  14676. Options::.
  14677.  
  14678. The following list briefly describes the server-related MySQL programs:
  14679.  
  14680. `mysqld'
  14681.      The SQL daemon (that is, the MySQL server). To use client
  14682.      programs, this program must be running, because clients gain
  14683.      access to databases by connecting the the server.
  14684.  
  14685. `mysqld-max'
  14686.      A version of the server that includes additional features.
  14687.  
  14688. `mysqld_safe'
  14689.      A server startup script.  `mysqld_safe' attempts to start
  14690.      `mysqld-max' if it exists, and `mysqld' otherwise.
  14691.  
  14692. `mysql.server'
  14693.      A server startup script.  This script is used on systems that use
  14694.      run directories containing scripts that start system services for
  14695.      particular run levels. It invokes `mysqld_safe' to start the MySQL
  14696.      server.
  14697.  
  14698. `mysqld_multi'
  14699.      A server startup script that can start or stop multiple servers
  14700.      installed on the system.
  14701.  
  14702. `mysql_install_db'
  14703.      This script creates the MySQL grant tables with default
  14704.      privileges. It is usually executed only once, when first
  14705.      installing MySQL on a system.
  14706.  
  14707. `mysql_fix_privilege_tables'
  14708.      This script is used after an upgrade install operation, to update
  14709.      the grant tables with any changes that were made in newer versions
  14710.      of MySQL.
  14711.  
  14712. There are several other programs that also are run on the server host:
  14713.  
  14714. `myisamchk'
  14715.      A utility to describe, check, optimize, and repair MySQL tables.
  14716.      `myisamchk' is described in *Note Table maintenance::.
  14717.  
  14718. `make_binary_distribution'
  14719.      This program makes a binary release of a compiled MySQL. This
  14720.      could be sent by FTP to `/pub/mysql/Incoming' on
  14721.      `support.mysql.com' for the convenience of other MySQL users.
  14722.  
  14723. `mysqlbug'
  14724.      The MySQL bug reporting script.  It can be be used to send a bug
  14725.      report to the MySQL list. (You can also visit
  14726.      <http://bugs.mysql.com/> to file a bug report online.)
  14727.  
  14728. `mysqld-max', An Extended `mysqld' Server
  14729. -----------------------------------------
  14730.  
  14731. A MySQL-Max server is a version of the `mysqld' MySQL server that is
  14732. configured to include additional features.
  14733.  
  14734. You can find the MySQL-Max binaries at
  14735. `http://www.mysql.com/downloads/mysql-max-4.0.html'.
  14736.  
  14737. The MySQL binary distributions Windows include both the standard server
  14738. (named `mysqld.exe') and the MySQL-Max server (named `mysqld-max.exe').
  14739. `http://www.mysql.com/downloads/mysql-4.0.html'.  *Note Windows
  14740. installation::.
  14741.  
  14742. If you install MySQL on Linux using RPM distributions, install the
  14743. `MySQL-server' RPM first, and then the `MySQL-Max' RPM.  The latter
  14744. presupposes that you have already installed the regular server RPM.
  14745. This process installs a standard server named `mysqld' and a MySQL-Max
  14746. server named `mysqld-max'.
  14747.  
  14748. All other MySQL-Max distributions contain a single server that is named
  14749. `mysqld' but that has the additional features.
  14750.  
  14751. MySQL-Max servers are built by using the following `configure' options:
  14752.  
  14753. *Option*                  *Comment*
  14754. `--with-server-suffix=-max'Add a `-max' suffix to the `mysqld' version
  14755.                           string
  14756. `--with-innodb'           Support for `InnoDB' tables (MySQL 3.23 only)
  14757. `--with-bdb'              Support for Berkeley DB (`BDB') tables
  14758. `CFLAGS=-DUSE_SYMDIR'     Symbolic link support for Windows
  14759.  
  14760. MySQL-Max binary distributions are a convenience for those who wish to
  14761. install precompiled programs. If you build MySQL using a source
  14762. distribution, you can build your own Max-like server by enabling the
  14763. same features at configuration time that the MySQL-Max binary
  14764. distributions are built with.
  14765.  
  14766. MySQL-Max servers always include the `InnoDB' storage engine.  The
  14767. `--with-innodb' option for enabling `InnoDB' support is needed only in
  14768. MySQL 3.23. (In MySQL 4 and up, `InnoDB' is included by default.  so
  14769. you do not need a MySQL-Max server to obtain `InnoDB' support.)
  14770.  
  14771. MySQL-Max servers include the BerkeleyDB (`BDB') storage engine
  14772. whenever possible, but not all platforms support `BDB'.  The following
  14773. table shows which platforms allow MySQL-Max binaries to include `BDB':
  14774.  
  14775. *System*               `BDB'
  14776. Windows/NT             Y
  14777. AIX 4.3                N
  14778. HP-UX 11.0             N
  14779. Linux-Alpha            N
  14780. Linux-Intel            Y
  14781. Linux-IA-64            N
  14782. Solaris-Intel          N
  14783. Solaris-SPARC          Y
  14784. SCO OSR5               Y
  14785. UnixWare               Y
  14786. Mac OS X               N
  14787.  
  14788. As of Version 3.23, all MySQL servers support `MyISAM' tables, because
  14789. `MyISAM' is the default storage engine. To find out which storage
  14790. engines your server supports, issue the following statement:
  14791.  
  14792.      mysql> SHOW VARIABLES LIKE "have_%";
  14793.      +------------------+----------+
  14794.      | Variable_name    | Value    |
  14795.      +------------------+----------+
  14796.      | have_bdb         | NO       |
  14797.      | have_crypt       | YES      |
  14798.      | have_innodb      | YES      |
  14799.      | have_isam        | NO       |
  14800.      | have_raid        | NO       |
  14801.      | have_symlink     | DISABLED |
  14802.      | have_openssl     | NO       |
  14803.      | have_query_cache | YES      |
  14804.      +------------------+----------+
  14805.  
  14806. The values in the second column indicate the server's level of support
  14807. for each feature:
  14808.  
  14809. *Value*     *Meaning*
  14810. `YES'       The feature is supported and is active.
  14811. `NO'        The feature is not supported.
  14812. `DISABLED'  The feature is supported but has been disabled.
  14813.  
  14814. A value of `NO' means that the server was compiled without support for
  14815. the feature, so it cannot be activated at runtime.
  14816.  
  14817. A value of `DISABLED' occurs either because the server was started with
  14818. an option that disables the feature, or because not all options
  14819. required to enable it were given. In the latter case, the
  14820. `hostname.err' file should contain a reason indicating why the option
  14821. is disabled.
  14822.  
  14823. One situation in which you might see `DISABLED' occurs with MySQL 3.23
  14824. when the `InnoDB' storage engine is compiled in. In MySQL 3.23, you
  14825. must supply at least the `innodb_data_file_path' option at runtime to
  14826. set up the `InnoDB' tablespace. Without the options, `InnoDB' disables
  14827. itself.  *Note InnoDB in MySQL 3.23::.  (You can specify configuration
  14828. options for the `BDB' storage engine, too, but `BDB' will not disable
  14829. itself without them.  *Note BDB start::.)
  14830.  
  14831. You may also see `DISABLED' for the `InnoDB', `BDB', or `ISAM' storage
  14832. engines if the server was compiled to support them, but was started
  14833. with the `--skip-innodb', `--skip-bdb', or `--skip-isam' options at
  14834. runtime.
  14835.  
  14836. `mysqld_safe', The Wrapper Around `mysqld'
  14837. ------------------------------------------
  14838.  
  14839. `mysqld_safe' is the recommended way to start a `mysqld' server on
  14840. Unix.  `mysqld_safe' adds some safety features such as restarting the
  14841. server when an error occurs and logging run-time information to a log
  14842. file.
  14843.  
  14844. *Note:* Before MySQL 4.0, `mysqld_safe' is named `safe_mysqld'.  To
  14845. preserve backward compatibility, MySQL binary distributions for some
  14846. time will include `safe_mysqld' as a symbolic link to `mysqld_safe'.
  14847.  
  14848. If you don't use `--mysqld=#' or `--mysqld-version=#' `mysqld_safe'
  14849. will use an executable named `mysqld-max' if it exists. If not,
  14850. `mysqld_safe' will start `mysqld'.
  14851.  
  14852. On Linux, the `MySQL-Max' RPM uses this `mysqld_safe' feature. (It just
  14853. installs the `mysqld-max' executable, so `mysqld_safe' automatically
  14854. uses this executable when `mysqld_safe' is restarted.)
  14855.  
  14856. The preference of `mysqld_safe' for `mysqld-max' over `mysqld' makes it
  14857. very easy to test a new `mysqld' binary in an existing installation.
  14858. Just run `configure' with the options you want and then install the new
  14859. `mysqld' binary as `mysqld-max' in the same directory where your
  14860. existing `mysqld' binary is located.
  14861.  
  14862. On the other hand, this behavior means that if you install a MySQL-Max
  14863. distribution that includes a server named `mysqld-max', then upgrade
  14864. later to a non-Max version of MySQL, `mysqld_safe' will still attempt
  14865. to run the old `mysqld-max' server.  If you perform such an upgrade,
  14866. manually remove the old `mysqld-max' server to ensure that
  14867. `mysqld_safe' runs the new `mysqld' server.
  14868.  
  14869. Normally, you should never edit the `mysqld_safe' script.  Instead, put
  14870. the options to `mysqld_safe' in the `[mysqld_safe]' section in a
  14871. `my.cnf' option file.  *Note Option files::.  `mysqld_safe' reads all
  14872. options from the `[mysqld]', `[server]' and `[mysqld_safe]' sections
  14873. from the option files.  (For backward compatibility, it also reads the
  14874. `[safe_mysqld]' sections, though you should rename such sections to
  14875. `[mysqld_safe]' once you begin using MySQL 4.0 or later.)
  14876.  
  14877. Note that all options specified to `mysqld_safe' on the command-line
  14878. are passed to `mysqld'.  If you wants to use any options for
  14879. `mysqld_safe' that `mysqld' doesn't support, you must specify them in
  14880. the option file.
  14881.  
  14882. Many of the options to `mysqld_safe' are the same as the options to
  14883. `mysqld'. *Note Server options::.
  14884.  
  14885. `mysqld_safe' supports the following options:
  14886.  
  14887. `--basedir=path'
  14888.      The path to the installation directory.
  14889.  
  14890. `--core-file-size=#'
  14891.      The size of the core file `mysqld' should be able to create. Passed
  14892.      to `ulimit -c'.
  14893.  
  14894. `--datadir=path'
  14895.      The path to the data directory.
  14896.  
  14897. `--defaults-extra-file=path'
  14898.      The name of an option file to be read in addition to the usual
  14899.      option files.
  14900.  
  14901. `--defaults-file=path'
  14902.      The name of an option file to be read instead of the usual option
  14903.      files.
  14904.  
  14905. `--err-log=path'
  14906.      Old form of the `--log-error' option, to be used before MySQL 4.0.
  14907.  
  14908. `--log-error=path'
  14909.      Write the error log to the above file. *Note Error log::.
  14910.  
  14911. `--ledir=path'
  14912.      The path to the directory containing the `mysqld' program.  Use
  14913.      this option to explicitly indicate the location of the server.
  14914.  
  14915. `--log=path'
  14916.  
  14917. `--mysqld=prog_name'
  14918.      The name of the server program (in the `ledir' directory) that you
  14919.      want to start.
  14920.  
  14921. `--mysqld-version=suffix'
  14922.      Similar to `--mysqld=' but here you only give the suffix for the
  14923.      server program name. The base name is assumed to be `mysqld'.  For
  14924.      example, if you use `--mysqld-version=max', `mysqld_safe' will
  14925.      start the `mysqld-max' program in the `ledir' directory.  If the
  14926.      argument to `--mysqld-version' is empty, `mysqld' in the `ledir'
  14927.      directory is used.
  14928.  
  14929. `--nice=#'
  14930.      Use the `nice' program to set the server's scheduling priority to
  14931.      the given value.  This option was added in MySQL 4.0.14.
  14932.  
  14933. `--no-defaults'
  14934.      Do not read any option files.
  14935.  
  14936. `--open-files-limit=#'
  14937.      The number of files `mysqld' should be able to open. Passed to
  14938.      `ulimit -n'. Note that you need to start `mysqld_safe' as `root'
  14939.      for this to work properly!
  14940.  
  14941. `--pid-file=path'
  14942.      The path to the process ID file.
  14943.  
  14944. `--port=#'
  14945.      The TCP/IP port number.
  14946.  
  14947. `--socket=path'
  14948.      The Unix socket file path.
  14949.  
  14950. `--timezone=#'
  14951.      Set the time zone (the `TZ') variable to the value of this
  14952.      parameter.
  14953.  
  14954. `--user=#'
  14955. The `mysqld_safe' script is written so that it normally is able to start
  14956. a server that was installed from either a source or a binary
  14957. distribution of MySQL, even those these normally install the server in
  14958. slightly different locations.  *Note Installation layouts::.
  14959. `mysqld_safe' expects one of the following conditions to be true:
  14960.  
  14961.    * The server and databases can be found relative to the directory
  14962.      from which `mysqld_safe' is invoked.  `mysqld_safe' looks under
  14963.      its working directory for `bin' and `data' directories (for binary
  14964.      distributions) or for `libexec' and `var' directories (for source
  14965.      distributions).  This condition should be met if you execute
  14966.      `mysqld_safe' from your MySQL installation directory (for example,
  14967.      `/usr/local/mysql' for a binary distribution).
  14968.  
  14969.    * If the server and databases cannot be found relative to the working
  14970.      directory, `mysqld_safe' attempts to locate them by absolute
  14971.      pathnames.  Typical locations are `/usr/local/libexec' and
  14972.      `/usr/local/var'.  The actual locations are determined from the
  14973.      values configured into the distribution at the time it was built.
  14974.      They should be correct if MySQL is installed in the location
  14975.      specified at configuration time.
  14976.  
  14977. Because `mysqld_safe' will try to find the server and databases relative
  14978. to its own working directory, you can install a binary distribution of
  14979. MySQL anywhere, as long as you start `mysqld_safe' from the MySQL
  14980. installation directory:
  14981.  
  14982.      shell> cd mysql_installation_directory
  14983.      shell> bin/mysqld_safe &
  14984.  
  14985. If `mysqld_safe' fails, even when invoked from the MySQL installation
  14986. directory, you can specify the `--ledir' and `--datadir' options to
  14987. indicate the directories in which the server and databases are located
  14988. on your system.
  14989.  
  14990. In rare cases, it may be necessary to edit `mysqld_safe' to get it to
  14991. start the server properly. If you do this, note that if you upgrade
  14992. MySQL in the future, your modified version of `mysqld_safe' will be
  14993. overwritten, so you should make a copy of your edited version that you
  14994. can reinstall.
  14995.  
  14996. `mysql.server', A Server Startup Script for Run Directories
  14997. -----------------------------------------------------------
  14998.  
  14999. MySQL distributions on Unix include a script named `mysql.server'.  It
  15000. can be used on systems such as Linux and Solaris that use System V-style
  15001. run directories to start and stop system services.
  15002.  
  15003. On Linux systems, the server RPM distribution installs `mysql.server'
  15004. in `/etc/init.d' automatically under the name `mysql'.
  15005.  
  15006. If you install MySQL on Linux using another distribution format, or on
  15007. a System V-style system, you can install the script manually by copying
  15008. it to the `/etc/init.d' directory with the name `mysql'.  Make sure the
  15009. script is executable. (Use `chmod +x mysql'.)
  15010.  
  15011. The commands needed to activate the script depend on your operating
  15012. system.  On Linux, you can use `chkconfig':
  15013.  
  15014.      shell> chkconfig --add mysql
  15015.  
  15016. For other systems, consult your operating system documentation to see
  15017. how to install startup scripts.
  15018.  
  15019. `mysqld_multi', A Program for Managing Multiple MySQL Servers
  15020. -------------------------------------------------------------
  15021.  
  15022. `mysqld_multi' is meant for managing several `mysqld' processes that
  15023. listen for connections on different Unix socket files and TCP/IP ports.
  15024. It can start or stop servers, or report their current status.
  15025.  
  15026. The program searches for groups named `[mysqld#]' in `my.cnf' (or in
  15027. the file named by the `--config-file=...' option on the command line).
  15028. `#' can be any positive integer.  This number is referred to in the
  15029. following discussion as the option group number, or GNR.  Group numbers
  15030. distinquish option groups from one another and are used as arguments to
  15031. `mysqld_multi' to specify which servers you want to start, stop, or
  15032. obtain the status of.  Options listed in these groups are the same as
  15033. you would use in the usual `[mysqld]' group used for starting `mysqld'.
  15034. (See, for example, *Note Automatic start::.) However, when using
  15035. multiple servers it is necessary that each one use its own value for
  15036. options such as the Unix socket file and TCP/IP port number. For more
  15037. information on which options should be specified in a multiple-server
  15038. environment, see *Note Multiple servers::.
  15039.  
  15040. To invoke `mysqld_multi', use the following syntax:
  15041.  
  15042.      shell> mysqld_multi [OPTIONS] {start|stop|report} [GNR[,GNR]...]
  15043.  
  15044. `start', `stop', and `report' indicate the operation you want to
  15045. perform. You can perform the operation on a single server or multiple
  15046. servers, depending on the GNR list that follows the option name.  If
  15047. there is no list, `mysqld_multi' performs the operation for all servers
  15048. in the option file.
  15049.  
  15050. Each GNR value represents an option group number or range of group
  15051. numbers.  The value should be the number at the end of the group name
  15052. in the option file.  For example, the GNR for a group named `[mysqld17]'
  15053. is `17'.  To specify a range of numbers, separate the first and last
  15054. numbers by a dash.  The GNR value 10-13 represents groups `[mysqld10]'
  15055. through `[mysqld13]'.  Multiple groups or group ranges can be specified
  15056. on the command line, separated by commas.  There must be no whitespace
  15057. characters (spaces or tabs) in the GNR list. (Anything after a
  15058. whitespace character is ignored.)
  15059.  
  15060. This command starts a single server using option group `[mysqld17]':
  15061.  
  15062.      shell> mysqld_multi start 17
  15063.  
  15064. This command stops serveral servers, using option groups `[mysql8]' and
  15065. `[mysqld10]' through `[mysqld13]':
  15066.  
  15067.      shell> mysqld_multi start 8,10-13
  15068.  
  15069. For an example of how you might set up an option file, use this command:
  15070.  
  15071.      shell> mysqld_multi --example
  15072.  
  15073. `mysqld_multi' supports the following options:
  15074.  
  15075. `--config-file=...'
  15076.      Specify the name of an alternative option file. This affects where
  15077.      `mysqld_multi' looks for `[mysqld#]' option groups.  It does not
  15078.      affect where `mysqld_multi' reads its own options, which are always
  15079.      taken from the `[mysqld_multi]' group in the usual `my.cnf' file.
  15080.      Without this option, all options are read from the usual `my.cnf'
  15081.      file.
  15082.  
  15083. `--example'
  15084.      Display an example option file.
  15085.  
  15086. `--help'
  15087.      Print this help message and exit.
  15088.  
  15089. `--log=...'
  15090.      Specify the name of the log file. If the file exists, log output
  15091.      is appended to it.
  15092.  
  15093. `--mysqladmin=...'
  15094.      The `mysqladmin' binary to be used to stop servers.
  15095.  
  15096. `--mysqld=...'
  15097.      The `mysqld' binary to be used. Note that you can specify
  15098.      `mysqld_safe' as the value for this option also. The options are
  15099.      passed to `mysqld'. Just make sure you have the directory where
  15100.      `mysqld' is located in your `PATH' environment variable setting or
  15101.      fix `mysqld_safe'.
  15102.  
  15103. `--no-log'
  15104.      Print log information to stdout rather than to the log file. By
  15105.      default, output goes to the log file.
  15106.  
  15107. `--password=...'
  15108.      The password of the MySQL account to use when invoking
  15109.      `mysqladmin'.
  15110.  
  15111. `--tcp-ip'
  15112.      Connect to each MySQL server via the TCP/IP port instead of the
  15113.      Unix socket file.  (If a socket file is missing, the server may
  15114.      still be running, but accessible only via the TCP/IP port.)  By
  15115.      default, connections are made using the Unix socket file.  This
  15116.      option affects `stop' and `report' operations.
  15117.  
  15118. `--user=...'
  15119.      The username of the MySQL account to use when invoking
  15120.      `mysqladmin'.
  15121.  
  15122. `--version'
  15123.      Print the version number and exit.
  15124.  
  15125. Some notes about `mysqld_multi':
  15126.  
  15127.    * Make sure that the MySQL user who is stopping the `mysqld'
  15128.      services (using the `mysqladmin' program) has the same password
  15129.      and username for all the data directories accessed (to the `mysql'
  15130.      database). And make sure that the user has the `SHUTDOWN'
  15131.      privilege! If you have many data directories and many different
  15132.      `mysql' databases with different passwords for the MySQL `root'
  15133.      user, you may want to create a common `multi_admin' user for each
  15134.      using the same password (see below). Example how to do it:
  15135.           shell> mysql -u root -S /tmp/mysql.sock -proot_password -e
  15136.           "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'multipass'"
  15137.      *Note Privileges::.  You will have to do the above for each
  15138.      `mysqld' running in each data directory, that you have (just
  15139.      change the socket, `-S=...').
  15140.  
  15141.    * `pid-file' is very important, if you are using `mysqld_safe' to
  15142.      start `mysqld' (for example, `--mysqld=mysqld_safe') Every
  15143.      `mysqld' should have its own `pid-file'. The advantage using
  15144.      `mysqld_safe' instead of `mysqld' directly here is, that
  15145.      `mysqld_safe' "guards" every `mysqld' process and will restart it,
  15146.      if a `mysqld' process terminates due to a signal sent using `kill
  15147.      -9', or for other reasons such as a segmentation fault. Please
  15148.      note that the `mysqld_safe' script may require that you start it
  15149.      from a certain place. This means that you may have to `cd' to a
  15150.      certain directory, before you start the `mysqld_multi'. If you
  15151.      have problems starting, please see the `mysqld_safe' script. Check
  15152.      especially the lines:
  15153.  
  15154.           --------------------------------------------------------------------------
  15155.           MY_PWD=`pwd`
  15156.           # Check if we are starting this relative (for the binary release)
  15157.           if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
  15158.            -x ./bin/mysqld
  15159.           --------------------------------------------------------------------------
  15160.  
  15161.      *Note `mysqld_safe': mysqld_safe.  The above test should be
  15162.      successful, or you may encounter problems.
  15163.  
  15164.    * Beware of the dangers of using multiple `mysqld' servers with the
  15165.      same data directory.  Use separate data directories, unless you
  15166.      *know* what you are doing!  *Note Multiple servers::.
  15167.  
  15168.    * The Unix socket file and the TCP/IP port must be different for
  15169.      every `mysqld'.
  15170.  
  15171.    * You may want to use option `--user' for `mysqld', but in order to
  15172.      do this you need to run the `mysqld_multi' script as the Unix
  15173.      `root' user. Having the option in the config file doesn't matter;
  15174.      you will just get a warning, if you are not the superuser and the
  15175.      `mysqlds' are started under *your* Unix account. *Important*: Make
  15176.      sure that the `pid-file' and the data directory are
  15177.      read+write(+execute for the latter one) accessible for *that* Unix
  15178.      user, who the specific `mysqld' process is started as. *Do not*
  15179.      use the Unix root account for this, unless you *know* what you are
  15180.      doing!
  15181.  
  15182.    * *Most important*: Before using `mysqld_multi' be sure that you
  15183.      understand the meanings of the options that are passed to the
  15184.      `mysqld' servers and *why* you would want to have separate
  15185.      `mysqld' processes. Starting multiple servers with the same data
  15186.      directory *will not* give you extra performance in a threaded
  15187.      system!  *Note Multiple servers::.
  15188.  
  15189. The following example shows how you might set up an option file for use
  15190. with `mysqld_multi'.  The first and fifth `[mysqld#]' group were
  15191. intentionally left out from the example.  You may have "gaps" in the
  15192. option file. This gives you more flexibility.  The order in which the
  15193. `mysqld' programs are started or stopped depends on the order in which
  15194. they appear in the option file.
  15195.  
  15196.      # This file should probably be in your home dir (~/.my.cnf)
  15197.      # or /etc/my.cnf
  15198.      # Version 2.1 by Jani Tolonen
  15199.      
  15200.      [mysqld_multi]
  15201.      mysqld     = /usr/local/bin/mysqld_safe
  15202.      mysqladmin = /usr/local/bin/mysqladmin
  15203.      user       = multi_admin
  15204.      password   = multipass
  15205.      
  15206.      [mysqld2]
  15207.      socket     = /tmp/mysql.sock2
  15208.      port       = 3307
  15209.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  15210.      datadir    = /usr/local/mysql/var2
  15211.      language   = /usr/local/share/mysql/english
  15212.      user       = john
  15213.      
  15214.      [mysqld3]
  15215.      socket     = /tmp/mysql.sock3
  15216.      port       = 3308
  15217.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  15218.      datadir    = /usr/local/mysql/var3
  15219.      language   = /usr/local/share/mysql/swedish
  15220.      user       = monty
  15221.      
  15222.      [mysqld4]
  15223.      socket     = /tmp/mysql.sock4
  15224.      port       = 3309
  15225.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  15226.      datadir    = /usr/local/mysql/var4
  15227.      language   = /usr/local/share/mysql/estonia
  15228.      user       = tonu
  15229.      
  15230.      [mysqld6]
  15231.      socket     = /tmp/mysql.sock6
  15232.      port       = 3311
  15233.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  15234.      datadir    = /usr/local/mysql/var6
  15235.      language   = /usr/local/share/mysql/japanese
  15236.      user       = jani
  15237.  
  15238. *Note Option files::.
  15239.  
  15240. Configuring MySQL
  15241. =================
  15242.  
  15243. This section discusses MySQL server configuration topics:
  15244.  
  15245.    * Startup options that the server supports.
  15246.  
  15247.    * How to set the server SQL mode.
  15248.  
  15249. `mysqld' Command-line Options
  15250. -----------------------------
  15251.  
  15252. When you start the `mysqld' server, you specify program options using
  15253. any of the methods described in *Note Program Options::. The most
  15254. common methods are to provide options in an option file or on the
  15255. command line. However, in most cases it is desirable to make sure the
  15256. server uses the same options each time it runs. The best way to ensure
  15257. this is to specify server options in an option file.  *Note Option
  15258. files::.
  15259.  
  15260. `mysqld' reads options from the `[mysqld]' and `[server]' groups.
  15261. `mysqld_safe' reads options from the `[mysqld]', `[server]',
  15262. `[mysqld_safe]' and `[safe_mysqld]' groups.  `mysql.server' reads
  15263. options from the `[mysqld]' and `[mysql.server]' groups.  An embedded
  15264. MySQL server usually reads options from the `[server]', `[embedded]'
  15265. and `[xxxxx_SERVER]' groups, where `xxxxx' is the name of the
  15266. application into which the server is embedded.
  15267.  
  15268. `mysqld' accepts many command-line options.  For a list, execute
  15269. `mysqld --help'. Before MySQL 4.1.1, `--help' prints the full help
  15270. message. As of 4.1.1, it prints a brief message; to see the full list,
  15271. use `mysqld --help --verbose'.
  15272.  
  15273. The following list shows some of the most common server options.
  15274. Options used for replication are listed in a separate section, see
  15275. *Note Replication Options::.
  15276.  
  15277. `--ansi'
  15278.      Use SQL-99 syntax instead of MySQL syntax.  *Note ANSI mode::.
  15279.      For more precise control over the server SQL mode, use the
  15280.      `--sql-mode' option instead.
  15281.  
  15282. `--basedir=path, -b path'
  15283.      The path to the installation directory. All paths are usually
  15284.      resolved relative to this.
  15285.  
  15286. `--big-tables'
  15287.      Allow large result sets by saving all temporary sets on file.
  15288.      This option prevents most "table full" errors, but also slows down
  15289.      queries for which in-memory tables would suffice.  Since Version
  15290.      3.23.2, MySQL is able to handle large result sets automatically by
  15291.      using memory for small temporary tables and switching to disk
  15292.      tables where necessary.
  15293.  
  15294. `--bind-address=IP'
  15295.      The IP address to bind to.
  15296.  
  15297. `--console'
  15298.      Write the error log messages to stderr/stdout even if `--log-error'
  15299.      is specified.  On Windows, `mysqld' will not close the console
  15300.      screen if this option is used.
  15301.  
  15302. `--character-sets-dir=path'
  15303.      The directory where character sets are installed.  *Note Character
  15304.      sets::.
  15305.  
  15306. `--chroot=path'
  15307.      Put the `mysqld' server in a closed environment during startup by
  15308.      using the `chroot()' system call. This is a recommended security
  15309.      measure as of MySQL 4.0. (MySQL 3.23 is not able to provide a
  15310.      `chroot()' jail that is 100% closed.)  Note that use of this
  15311.      option somewhat limits `LOAD DATA INFILE' and `SELECT ... INTO
  15312.      OUTFILE'.
  15313.  
  15314. `--core-file'
  15315.      Write a core file if `mysqld' dies.  For some systems, you must
  15316.      also specify the `--core-file-size' option to `mysqld_safe'.
  15317.      *Note `mysqld_safe': mysqld_safe.  Note that on some systems, such
  15318.      as Solaris, you will not get a core file if you are also using the
  15319.      `--user' option.
  15320.  
  15321. `--datadir=path, -h path'
  15322.      The path to the data directory.
  15323.  
  15324. `--debug[=...]'
  15325.      If MySQL is configured with `--with-debug', you can use this
  15326.      option to get a trace file of what `mysqld' is doing.  *Note
  15327.      Making trace files::.
  15328.  
  15329. `--default-character-set=charset'
  15330.      Set the default character set.  *Note Character sets::.
  15331.  
  15332. `--default-table-type=type'
  15333.      Set the default table type for tables.  *Note Table types::.
  15334.  
  15335. `--delay-key-write[= OFF | ON | ALL]'
  15336.      How the `DELAYED KEYS' option should be used.  Delayed key writing
  15337.      causes key buffers not to be flushed between writes for `MyISAM'
  15338.      tables.  `OFF' disables delayed key writes.  `ON' enables delayed
  15339.      key writes for those tables that were created with the `DELAYED
  15340.      KEYS' option.  `ALL' delays key writes for all `MyISAM' tables.
  15341.      Available as of MySQL 4.0.3.  *Note Server parameters::.
  15342.  
  15343. `--delay-key-write-for-all-tables'
  15344.      Old form of `--delay-key-write=ALL' for use prior to MySQL 4.0.3.
  15345.      As of 4.0.3, use `--delay-key-write' instead.
  15346.  
  15347. `--des-key-file=filename'
  15348.      Read the default keys used by `DES_ENCRYPT()' and `DES_DECRYPT()'
  15349.      from this file.
  15350.  
  15351. `--enable-external-locking'
  15352.      Enable system locking.  Note that if you use this option on a
  15353.      system on which `lockd' does not fully work (as on Linux), you
  15354.      will easily get `mysqld' to deadlock.  This option used to be
  15355.      named `--enable-locking'.
  15356.  
  15357. `--enable-named-pipe'
  15358.      Enable support for named pipes.  This option applies only on
  15359.      Windows NT, 2000, and XP systems, and may be used only with the
  15360.      `mysqld-nt' and `mysqld-max-nt' servers that support named pipe
  15361.      connections.
  15362.  
  15363. `--exit-info, -T'
  15364.      This is a bit mask of different flags you can use for debugging the
  15365.      `mysqld' server. Do not use this option unless you know exactly
  15366.      what it does!
  15367.  
  15368. `--flush'
  15369.      Flush all changes to disk after each SQL statement.  Normally MySQL
  15370.      only does a write of all changes to disk after each SQL statement
  15371.      and lets the operating system handle the syncing to disk.  *Note
  15372.      Crashing::.
  15373.  
  15374. `--help, -?'
  15375.      Display a short help message and exit.  Prior to MySQL 4.1.1,
  15376.      `--help' displays the full help message.  As of 4.1.1, it displays
  15377.      an abbreviated message only.  Use both the `--verbose' and
  15378.      `--help' options to see the full message.
  15379.  
  15380. `--init-file=file'
  15381.      Read SQL statements from this file at startup.
  15382.  
  15383. `--language=lang_name, -L lang_name'
  15384.      Client error messages in given language.  `lang_name' may be given
  15385.      as the language name or as the full pathname to the directory
  15386.      where the language files are installed.  *Note Languages::.
  15387.  
  15388. `--log[=file], -l [file]'
  15389.      Log connections and queries to this file. *Note Query log::. If
  15390.      you don't specify a file name, MySQL will use `hostname.log' as
  15391.      filename.
  15392.  
  15393. `--log-bin=[file]'
  15394.      Log all queries that change data to this file. Used for backup and
  15395.      replication.  *Note Binary log::.  If you don't specify a file
  15396.      name, MySQL will use `hostname-bin' as filename.
  15397.  
  15398. `--log-bin-index[=file]'
  15399.      The index file for binary log file names. *Note Binary log::.  If
  15400.      you don't specify file name, MySQL will use `hostname-bin.index' as
  15401.      filename.
  15402.  
  15403. `--log-error[=file]'
  15404.      Log errors and startup messages to this file. *Note Error log::.
  15405.      If you don't specify file name, MySQL will use `hostname.err' as
  15406.      filename.
  15407.  
  15408. `--log-isam[=file]'
  15409.      Log all `ISAM'/`MyISAM' changes to this file (used only when
  15410.      debugging `ISAM'/`MyISAM').
  15411.  
  15412. `--log-long-format'
  15413.      Log some extra information to the log files (update log, binary
  15414.      update log, and slow queries log, whatever log has been
  15415.      activated). For example, username and timestamp are logged for
  15416.      queries. If you are using `--log-slow-queries' and
  15417.      `--log-long-format', then queries that are not using indexes also
  15418.      are logged to the slow query log.  Note that `--log-long-format'
  15419.      is deprecated as of MySQL version 4.1, when `--log-short-format'
  15420.      was introduced (the long log format is the default setting since
  15421.      version 4.1). Also note that starting with MySQL 4.1 the
  15422.      `--log-queries-not-using-indexes' option is available for the
  15423.      purpose of logging queries that do not use indexes to the slow
  15424.      queries log.
  15425.  
  15426. `--log-queries-not-using-indexes'
  15427.      If you are using this option with `--log-slow-queries', then also
  15428.      queries that are not using indexes are logged to the slow query
  15429.      log. This option is available as of MySQL 4.1. *Note Slow query
  15430.      log::.
  15431.  
  15432. `--log-short-format'
  15433.      Log less information to the log files (update log, binary update
  15434.      log, and slow queries log, whatever log has been activated). For
  15435.      example, username and timestamp are not logged for queries. This
  15436.      options was introduced in MySQL 4.1.
  15437.  
  15438. `--log-slow-queries[=file]'
  15439.      Log all queries that have taken more than `long_query_time' seconds
  15440.      to execute to file. Note that the default for the amount of
  15441.      information logged has changed in MySQL 4.1. See the
  15442.      `--log-long-format' and `--log-long-format' options for details.
  15443.      *Note Slow query log::.
  15444.  
  15445. `--log-update[=file]'
  15446.      Log updates to `file.#' where `#' is a unique number if not given.
  15447.      *Note Update log::. The update log is deprecated and is removed in
  15448.      MySQL 5.0.0; you should use the binary log instead (`--log-bin').
  15449.      *Note Binary log::. Starting from version 5.0.0, using
  15450.      `--log-update' will just turn on the binlog instead (*note
  15451.      News-5.0.0::).
  15452.  
  15453. `--log-warnings, -W'
  15454.      Print out warnings like `Aborted connection...' to the `.err'
  15455.      file. Enabling this option is recommended, for example, if you use
  15456.      replication (you will get more information about what is happening,
  15457.      such as messages about network failures and reconnections). *Note
  15458.      Communication errors::.
  15459.  
  15460.      This option used to be called `--warnings'.
  15461.  
  15462. `--low-priority-updates'
  15463.      Table-modifying operations (`INSERT'/`DELETE'/`UPDATE') will have
  15464.      lower priority than selects.  It can also be done via `{INSERT |
  15465.      REPLACE | UPDATE | DELETE} LOW_PRIORITY ...' to lower the priority
  15466.      of only one query, or by `SET LOW_PRIORITY_UPDATES=1' to change
  15467.      the priority in one thread.  *Note Table locking::.
  15468.  
  15469. `--memlock'
  15470.      Lock the `mysqld' process in memory.  This works on systems such as
  15471.      Solaris that support the `mlockall()' system call.  This may help
  15472.      if you have a problem where the operating system is causing
  15473.      `mysqld' to swap on disk.  Note that use of this option requires
  15474.      that you run the server as `root', which is normally not a good
  15475.      idea for security reasons.
  15476.  
  15477. `--myisam-recover [=option[,option...]]]'
  15478.      Set the `MyISAM' storage engine recovery mode.  The option value
  15479.      is any combination of the values of `DEFAULT', `BACKUP', `FORCE'
  15480.      or `QUICK'.  If you specify multiple values, seprate them by
  15481.      commas.  You can also use a value of `""' to disable this option.
  15482.      If this option is used, `mysqld' will on open check if the table
  15483.      is marked as crashed or if the table wasn't closed properly.  (The
  15484.      last option works only if you are running with
  15485.      `--skip-external-locking'.)  If this is the case `mysqld' will run
  15486.      check on the table. If the table was corrupted, `mysqld' will
  15487.      attempt to repair it.
  15488.  
  15489.      The following options affects how the repair works.
  15490.  
  15491.      *Option*   *Description*
  15492.      `DEFAULT'  The same as not giving any option to
  15493.                          `--myisam-recover'.
  15494.      `BACKUP'   If the data table was changed during recover,
  15495.                 save a                     backup of the
  15496.                 `table_name.MYD' datafile as
  15497.                  `table_name-datetime.BAK'.
  15498.      `FORCE'    Run recover even if we will lose more than one
  15499.                 row                     from the `.MYD' file.
  15500.      `QUICK'    Don't check the rows in the table if there
  15501.                 aren't any                     delete blocks.
  15502.  
  15503.      Before a table is automatically repaired, MySQL will add a note
  15504.      about this in the error log.  If you want to be able to recover
  15505.      from most problems without user intervention, you should use the
  15506.      options `BACKUP,FORCE'.  This will force a repair of a table even
  15507.      if some rows would be deleted, but it will keep the old datafile
  15508.      as a backup so that you can later examine what happened.
  15509.  
  15510. `--new'
  15511.      From version 4.0.12, the `--new' option can be used to make the
  15512.      server behave as 4.1 in certain respects, easing a 4.0 to 4.1
  15513.      upgrade:
  15514.         * `TIMESTAMP' is returned as a string with the format
  15515.           `'YYYY-MM-DD HH:MM:SS''.  *Note Column types::.
  15516.  
  15517.      This option can be used to help you see how your applications will
  15518.      behave in MySQL 4.1, without actually upgrading to 4.1.
  15519.  
  15520. `--pid-file=path'
  15521.      The path to pid file used by `mysqld_safe'.
  15522.  
  15523. `--port=num, -P num'
  15524.      The port number to listen for TCP/IP connections.
  15525.  
  15526. `--old-protocol, -o'
  15527.      Use the 3.20 protocol for compatibility with some very old clients.
  15528.      *Note Upgrading-from-3.20::.
  15529.  
  15530. `--one-thread'
  15531.      Only use one thread (for debugging under Linux).  This option is
  15532.      available only if the server is built with debugging enabled.
  15533.      *Note Debugging server::.
  15534.  
  15535. `--open-files-limit='
  15536.      To change the number of file descriptors available to `mysqld'.
  15537.      If this is not set or set to 0, then `mysqld' will use this value
  15538.      to reserve file descriptors to use with `setrlimit()'.  If this
  15539.      value is 0 then `mysqld' will reserve `max_connections*5' or
  15540.      `max_connections + table_cache*2' (whichever is larger) number of
  15541.      files.  You should try increasing this if `mysqld' gives you the
  15542.      error 'Too many open files'.
  15543.  
  15544. `--set-variable=name=value, -O value'
  15545.      Assign a value to a system variable.  Use `--help' to list the
  15546.      variables.  You can find a full description for all variables in
  15547.      the `SHOW VARIABLES' section in this manual.  *Note `SHOW
  15548.      VARIABLES': SHOW VARIABLES.  The section on tuning server
  15549.      parameters includes information on how to optimize them.  *Note
  15550.      Server parameters::.
  15551.  
  15552.      Please note that `--set-variable=name=value' and `-O name=value'
  15553.      syntax is deprecated as of MySQL 4.0.2.  In 4.0.2, you can set
  15554.      variables directly using `--variable-name=value' syntax, and
  15555.      `--set-variable' is no longer needed.
  15556.  
  15557.      If you want to restrict the maximum value a startup option can be
  15558.      set to with `SET', you can define this by using the
  15559.      `--maximum-variable-name' command line option.  *Note `SET
  15560.      OPTION': SET OPTION.
  15561.  
  15562.      Note that when setting a variable to a value, MySQL may
  15563.      automatically correct it to stay within a given range, or adjust
  15564.      the value to the closest allowable value if only certain values
  15565.      are allowed.
  15566.  
  15567. `--safe-mode'
  15568.      Skip some optimize stages.
  15569.  
  15570. `--safe-show-database'
  15571.      With this option, the `SHOW DATABASES' statement returns only those
  15572.      databases for which the user has some kind of privilege.  From
  15573.      version 4.0.2 this option is deprecated and doesn't do anything
  15574.      (the option is enabled by default) as we now have the `SHOW
  15575.      DATABASES' privilege. *Note `GRANT': GRANT.
  15576.  
  15577. `--safe-user-create'
  15578.      If this is enabled, a user can't create new users with the `GRANT'
  15579.      statement, if the user doesn't have `INSERT' privilege to the
  15580.      `mysql.user' table or any column in this table.
  15581.  
  15582. `--skip-bdb'
  15583.      Disable the `BDB' storage engine. This saves memory and may speed
  15584.      up some operations.  Do not use this operation if you require
  15585.      `BDB' tables.
  15586.  
  15587. `--skip-concurrent-insert'
  15588.      Turn off the ability to select and insert at the same time on
  15589.      `MyISAM' tables. (This is only to be used if you think you have
  15590.      found a bug in this feature.)
  15591.  
  15592. `--skip-delay-key-write'
  15593.      Ignore the `DELAY_KEY_WRITE' option for all tables.  As of MySQL
  15594.      4.0.3, you should use `--delay-key-write=OFF' instead.  *Note
  15595.      Server parameters::.
  15596.  
  15597. `--skip-external-locking'
  15598.      Don't use system locking.  To use `isamchk' or `myisamchk' you must
  15599.      shut down the server.  *Note Stability::.  Note that in MySQL
  15600.      Version 3.23, you can use `CHECK TABLE' and `REPAIR TABLE' to
  15601.      check and repair`MyISAM' tables.  This option used to be named
  15602.      `--skip-locking'.
  15603.  
  15604. `--skip-grant-tables'
  15605.      This option causes the server not to use the privilege system at
  15606.      all.  This gives everyone *full access* to all databases!  (You
  15607.      can tell a running server to start using the grant tables again by
  15608.      executing a `mysqladmin flush-privileges' or `mysqladmin reload'
  15609.      command, or by issuing a `FLUSH PRIVILEGES' statement.)
  15610.  
  15611. `--skip-host-cache'
  15612.      Do not use the internal hostname cache for faster name-IP
  15613.      resolution. Instead, query the DNS server every time a client
  15614.      connects.  *Note DNS::.
  15615.  
  15616. `--skip-innodb'
  15617.      Disable the `InnoDB' storage engine.  This saves memory and disk
  15618.      space and may speed up some operations.  Do not use this operation
  15619.      if you require `InnoDB' tables.
  15620.  
  15621. `--skip-isam'
  15622.      Disable the `ISAM' storage engine.  As of MySQL 4.1, `ISAM' is
  15623.      disabled by default, so this option applies only if the server was
  15624.      configured with support for `ISAM'.  This option was added in
  15625.      MySQL 4.1.1.
  15626.  
  15627. `--skip-name-resolve'
  15628.      Do not resolve hostnames when checking client connections. Use
  15629.      only IP numbers. If you use this option, all `Host' column values
  15630.      in the grant tables must be IP numbers or `localhost'.  *Note
  15631.      DNS::.
  15632.  
  15633. `--skip-networking'
  15634.      Don't listen for TCP/IP connections at all.  All interaction with
  15635.      `mysqld' must be made via named pipes (on Windows) or Unix socket
  15636.      files (on Unix).  This option is highly recommended for systems
  15637.      where only local clients are allowed.  *Note DNS::.
  15638.  
  15639. `--skip-new'
  15640.      Don't use new, possibly wrong routines.
  15641.  
  15642. `--skip-symlink'
  15643.      This is the old form of `--skip-symbolic-links', for use before
  15644.      MySQL 4.0.13.
  15645.  
  15646. `--symbolic-links, --skip-symbolic-links'
  15647.      Enable or disable symbolic link support. This option has different
  15648.      effects on Windows and Unix:
  15649.  
  15650.         * On Windows, enabling symbolic links allows you to establish a
  15651.           symbolic link to a database directory by creating a
  15652.           `directory.sym' file that contains the path to the real
  15653.           directory.  *Note Windows symbolic links::.
  15654.  
  15655.         * On Unix, enabling symbolic links means that you can link a
  15656.           `MyISAM' index file or datafile to another directory with the
  15657.           `INDEX DIRECTORY' or `DATA DIRECTORY' options of the `CREATE
  15658.           TABLE' statement.  If you delete or rename the table, the
  15659.           files that its symbolic links point to also are deleted or
  15660.           renamed. *Note `CREATE TABLE': CREATE TABLE.
  15661.  
  15662.      This option was added in MySQL 4.0.13.
  15663.  
  15664. `--skip-safemalloc'
  15665.      If MySQL is configured with `--with-debug=full', all MySQL programs
  15666.      checks for memory overruns during each memory allocation and memory
  15667.      freeing operation.  This checking is very slow, so for the server
  15668.      you can avoid it when you don't need it by using the
  15669.      `--skip-safemalloc' option.
  15670.  
  15671. `--skip-show-database'
  15672.      Don't allow the `SHOW DATABASES' statement, unless the user has the
  15673.      `SHOW DATABASES' privilege.
  15674.  
  15675. `--skip-stack-trace'
  15676.      Don't write stack traces.  This option is useful when you are
  15677.      running `mysqld' under a debugger. On some systems, you also must
  15678.      use this option to get a core file. *Note Debugging server::.
  15679.  
  15680. `--skip-thread-priority'
  15681.      Disable using thread priorities for faster response time.
  15682.  
  15683. `--socket=path'
  15684.      On Unix, this option specifies the Unix socket file to use for
  15685.      local connections. The default value is `/tmp/mysql.sock'.  On
  15686.      Windows, the option specifies the pipe name to use for local
  15687.      connections that use a named pipe. The default value is `MySQL'.
  15688.  
  15689. `--sql-mode=value[,value[,value...]]'
  15690.      Set the SQL mode for MySQL. *Note SQL mode::. This option was
  15691.      added in 3.23.41.
  15692.  
  15693. `--temp-pool'
  15694.      This option causes most temporary files created by the server to
  15695.      use a small set of names, rather than a unique name for each new
  15696.      file. This works around a problem in the Linux kernel dealing with
  15697.      creating many new files with different names. With the old
  15698.      behavior, Linux seems to "leak" memory, as it's being allocated to
  15699.      the directory entry cache rather than to the disk cache.
  15700.  
  15701. `--transaction-isolation=level'
  15702.      Sets the default transaction isolation level, which may be
  15703.      `READ-UNCOMMITTED', `READ-COMMITTED', `REPEATABLE-READ', or
  15704.      `SERIALIZABLE'.  *Note `SET TRANSACTION': SET TRANSACTION.
  15705.  
  15706. `--tmpdir=path, -t path'
  15707.      The path of the directory to use for creating temporary files. It
  15708.      may be useful if your default `/tmp' directory resides on a
  15709.      partition that is too small to hold temporary tables.  Starting
  15710.      from MySQL 4.1, this option accepts several paths that are used in
  15711.      round-robin fashion. Paths should be separated by colon characters
  15712.      (`:') on Unix and semicolon characters (`;') on Windows.  It is
  15713.      possible to set `tmpdir' to point to a memory-based filesystem,
  15714.      except if the MySQL server is a slave replication server. If it is
  15715.      a slave, some of its temporary files are needed to survive a
  15716.      machine's reboot.  (For example, to replicate temporary tables or
  15717.      `LOAD DATA INFILE' statements).  In this case, a memory-based
  15718.      `tmpdir' that is cleared when the machine reboots is not suitable;
  15719.      a disk-based `tmpdir' is necessary.
  15720.  
  15721. `--user={user_name | user_id}, -u {user_name | user_id}'
  15722.      Run the `mysqld' server as the user having the name `user_name' or
  15723.      the numeric user ID `user_id'.  ("User" in this context refers to
  15724.      a system login account, not a MySQL user listed in the grant
  15725.      tables.)
  15726.  
  15727.      This option is *mandatory* when starting `mysqld' as `root'.  The
  15728.      server will change its user ID during its startup sequence,
  15729.      causing it to run as that particular user rather than as `root'.
  15730.      *Note Security guidelines::.
  15731.  
  15732.      Starting from MySQL 3.23.56 and 4.0.12: To avoid a possible
  15733.      security hole where a user adds a `--user=root' option to some
  15734.      `my.cnf' file (thus causing the server to run as `root'), `mysqld'
  15735.      uses only the first `--user' option specified and produces a
  15736.      warning if there are multiple `--user' options. Options in
  15737.      `/etc/my.cnf' and `datadir/my.cnf' are processed before
  15738.      command-line options, so it is recommended that you put a `--user'
  15739.      option in `/etc/my.cnf' and specify a value other than `root'. The
  15740.      option in `/etc/my.cnf' will be found before any other `--user'
  15741.      options, which ensures that the server runs as a user other than
  15742.      `root', and that a warning results if any other `--user' option is
  15743.      found.
  15744.  
  15745. `--version, -V'
  15746.      Display version information and exit.
  15747.  
  15748. You can change the values of most system variables for a running server
  15749. with the `SET' statement. *Note `SET OPTION': SET OPTION.
  15750.  
  15751. The Server SQL Mode
  15752. -------------------
  15753.  
  15754. The MySQL server can operate in different SQL modes, and (as of MySQL
  15755. 4.1) can apply these modes differentially for different clients. This
  15756. allows applications to tailor server operation to their own
  15757. requirements.
  15758.  
  15759. Modes define what SQL syntax MySQL should support and what kind of data
  15760. validation checks it should perform.  This makes it easier to use MySQL
  15761. in different environments and to use MySQL together with other database
  15762. servers.
  15763.  
  15764. You can set the default SQL mode by starting `mysqld' with the
  15765. `--sql-mode="modes"' option. Beginning with MySQL 4.1, you can also
  15766. change the mode after startup time by setting the `sql_mode' variable
  15767. with a `SET [SESSION|GLOBAL] sql_mode='modes'' statement.  Setting the
  15768. `GLOBAL' variable affects the operation of all clients that connect
  15769. from that time on. Setting the `SESSION' variable affects only the
  15770. current client.  `modes' is a list of different modes separated by
  15771. comma (`,') characters.  You can retrieve the current mode by issuing a
  15772. `SELECT @@sql_mode' statement. The default value is empty (no modes
  15773. set).
  15774.  
  15775. The value also can be empty (`--sql-mode=""') if you want to reset it.
  15776.  
  15777. The following table lists the supported modes. The *Version* column
  15778. indicates when each mode value was implemented.
  15779.  
  15780. *Value*        *Version**Meaning*
  15781. `ANSI_QUOTES'  4.0.0   Treat `"' as an identifier quote character (like
  15782.                        the MySQL Server ``' quote character) and not as
  15783.                        a string quote character. You can still use ``'
  15784.                        to quote identifers in ANSI mode. With
  15785.                        `ANSI_QUOTES' enabled, you cannot use double
  15786.                        quotes to quote a literal string, because it will
  15787.                        be intepreted as an identifier.
  15788. `IGNORE_SPACE' 4.0.0   Allow spaces between a function name and the `('
  15789.                        character.  This forces all function names to be
  15790.                        treated as reserved words. As a result, if you
  15791.                        want to access any database, table, or column
  15792.                        name that is a reserved word, you must quote it.
  15793.                        For example, because there is a `USER()'
  15794.                        function, the name of the `user' table in the
  15795.                        `mysql' database and the `User' column in that
  15796.                        table become reserved, so you must quote them:
  15797.                             SELECT "User" FROM mysql."user";
  15798. `NO_AUTO_VALUE_ON_ZERO'4.1.1    `NO_AUTO_VALUE_ON_ZERO' affects handling of
  15799.                        `AUTO_INCREMENT' columns. Normally, you generate
  15800.                        the next sequence number for the column by
  15801.                        inserting either `NULL' or `0' into it.
  15802.                        `NO_AUTO_VALUE_ON_ZERO' suppresses this behavior
  15803.                        for `0' so that only `NULL' generates the next
  15804.                        sequence number. This mode can be useful if `0'
  15805.                        has been stored in a table's `AUTO_INCREMENT'
  15806.                        column. (This is not a recommended practice, by
  15807.                        the way.)  For example, if you dump the table
  15808.                        with `mysqldump' and then reload it, normally
  15809.                        MySQL will generate new sequence numbers when it
  15810.                        encounters the `0' values, resulting in a table
  15811.                        with different contents than the one that was
  15812.                        dumped. Enabling `NO_AUTO_VALUE_ON_ZERO' before
  15813.                        reloading the dump file solves this problem. (As
  15814.                        of MySQL 4.1.1, `mysqldump' automatically
  15815.                        includes statements in the dump output to enable
  15816.                        `NO_AUTO_VALUE_ON_ZERO'.)
  15817. `NO_DIR_IN_CREATE'4.0.15  When creating a table, ignore all `INDEX
  15818.                        DIRECTORY' and `DATA DIRECTORY' directives. This
  15819.                        option is useful on slave replication servers.
  15820. `NO_FIELD_OPTIONS'4.1.1   Don't print MySQL field-specific options in the
  15821.                        output of `SHOW CREATE TABLE'. This mode is used
  15822.                        by `mysqldump' in portability mode.
  15823. `NO_KEY_OPTIONS'4.1.1   Don't print MySQL index-specific options in the
  15824.                        output of `SHOW CREATE TABLE'. This mode is used
  15825.                        by `mysqldump' in portability mode.
  15826. `NO_TABLE_OPTIONS'4.1.1   Don't print MySQL table-specific options (such as
  15827.                        `ENGINE') in the output of `SHOW CREATE TABLE'.
  15828.                        This mode is used by `mysqldump' in portability
  15829.                        mode.
  15830. `NO_UNSIGNED_SUBTRACTION'4.0.2   In subtraction operations, don't mark the result
  15831.                        as `UNSIGNED' if one of the operands is unsigned.
  15832.                        Note that this makes `UNSIGNED BIGINT' not 100%
  15833.                        usable in all contexts. *Note Cast Functions::.
  15834. `ONLY_FULL_GROUP_BY'4.0.0   Don't allow queries which in the `GROUP BY' part
  15835.                        refers to a not selected column.
  15836. `PIPES_AS_CONCAT'4.0.0   Treat `||' as a string concatenation operator
  15837.                        (same as `CONCAT()') rather than as a synonym for
  15838.                        `OR'.
  15839. `REAL_AS_FLOAT'4.0.0   Treat `REAL' as a synonym for `FLOAT' rather than
  15840.                        as a synonym for `DOUBLE'.
  15841.  
  15842. The following special modes are provided as shorthand for combinations
  15843. of mode values from the preceding table:
  15844.  
  15845. *Value*        `Version'*Meaning*
  15846. `ANSI'         4.1.1   `REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY'.
  15847.                        *Note ANSI mode::.
  15848. `DB2'          4.1.1   `PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS'
  15849. `DB2'          4.1.1   `PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS'
  15850. `MAXDB'        4.1.1   `PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS'
  15851. `MSSQL'        4.1.1   `PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS'
  15852. `MYSQL323'     4.1.1   `NO_FIELD_OPTIONS'
  15853. `MYSQL40'      4.1.1   `NO_FIELD_OPTIONS'
  15854. `ORACLE'       4.1.1   `PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS'
  15855. `POSTGRESQL'   4.1.1   `PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS'
  15856.  
  15857. General Security Issues
  15858. =======================
  15859.  
  15860. This section describes some general security issues to be aware of and
  15861. what you can do to make your MySQL installation more secure against
  15862. attack or misuse. For information specifically about the access control
  15863. system that MySQL uses for setting up user accounts and checking
  15864. database access, see *Note Privilege system::.
  15865.  
  15866. General Security Guidelines
  15867. ---------------------------
  15868.  
  15869. Anyone using MySQL on a computer connected to the Internet should read
  15870. this section to avoid the most common security mistakes.
  15871.  
  15872. In discussing security, we emphasize the necessity of fully protecting
  15873. the entire server host (not just the MySQL server) against all types of
  15874. applicable attacks: eavesdropping, altering, playback, and denial of
  15875. service. We do not cover all aspects of availability and fault tolerance
  15876. here.
  15877.  
  15878. MySQL uses security based on Access Control Lists (ACLs) for all
  15879. connections, queries, and other operations that users may attempt to
  15880. perform. There is also some support for SSL-encrypted connections
  15881. between MySQL clients and servers. Many of the concepts discussed here
  15882. are not specific to MySQL at all; the same general ideas apply to
  15883. almost all applications.
  15884.  
  15885. When running MySQL, follow these guidelines whenever possible:
  15886.  
  15887.    * *Do not ever give anyone (except MySQL `root' accounts) access to
  15888.      the `user' table in the `mysql' database!*  This is critical.
  15889.      *The encrypted password is the real password in MySQL.* Anyone who
  15890.      knows the password which is listed in the `user' table and has
  15891.      access to the host listed for the account *can easily log in as
  15892.      that user*.
  15893.  
  15894.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  15895.      statements are used for controlling access to MySQL. Do not grant
  15896.      any more privileges than necessary. Never grant privileges to all
  15897.      hosts.
  15898.  
  15899.      Checklist:
  15900.         - Try `mysql -u root'. If you are able to connect successfully
  15901.           to the server without being asked for a password, you have
  15902.           problems. Anyone can connect to your MySQL server as the MySQL
  15903.           `root' user with full privileges!  Review the MySQL
  15904.           installation instructions, paying particular attention to the
  15905.           item about setting a `root' password.
  15906.  
  15907.         - Use the `SHOW GRANTS' statement and check to see who has
  15908.           access to what.  Then use the `REVOKE' statement to remove
  15909.           those privileges that are not necessary.
  15910.  
  15911.    * Do not store any plain-text passwords in your database. If your
  15912.      computer becomes compromised, the intruder can take the full list
  15913.      of passwords and use them. Instead, use `MD5()', `SHA1()' or some
  15914.      other one-way hashing function.
  15915.  
  15916.    * Do not choose passwords from dictionaries. There are special
  15917.      programs to break them. Even passwords like "xfish98" are very
  15918.      bad.  Much better is "duag98" which contains the same word "fish"
  15919.      but typed one key to the left on a standard QWERTY keyboard.
  15920.      Another method is to use "Mhall" which is taken from the first
  15921.      characters of each word in the sentence "Mary had a little lamb."
  15922.      This is easy to remember and type, but difficult to guess for
  15923.      someone who does not know it.
  15924.  
  15925.    * Invest in a firewall. This protects you from at least 50% of all
  15926.      types of exploits in any software. Put MySQL behind the firewall
  15927.      or in a demilitarized zone (DMZ).
  15928.  
  15929.      Checklist:
  15930.         - Try to scan your ports from the Internet using a tool such as
  15931.           `nmap'. MySQL uses port 3306 by default. This port should not
  15932.           be accessible from untrusted hosts. Another simple way to
  15933.           check whether or not your MySQL port is open is to try the
  15934.           following command from some remote machine, where
  15935.           `server_host' is the host where your MySQL server runs:
  15936.  
  15937.                shell> telnet server_host 3306
  15938.  
  15939.           If you get a connection and some garbage characters, the port
  15940.           is open, and should be closed on your firewall or router,
  15941.           unless you really have a good reason to keep it open. If
  15942.           `telnet' just hangs or the connection is refused, everything
  15943.           is OK; the port is blocked.
  15944.  
  15945.    * Do not trust any data entered by users of your applications. They
  15946.      can try to trick your code by entering special or escaped
  15947.      character sequences in web forms, URLs, or whatever application
  15948.      you have built. Be sure that your application remains secure if a
  15949.      user enters something like "`; DROP DATABASE mysql;'". This is an
  15950.      extreme example, but large security leaks and data loss may occur
  15951.      as a result of hackers using similar techniques, if you do not
  15952.      prepare for them.
  15953.  
  15954.      A common mistake is to protect only string data values.  Remember
  15955.      to check numeric data as well.  If an application generates a
  15956.      query such as `SELECT * FROM table WHERE ID=234' when a user
  15957.      enters the value `234', the user can enter the value `234 OR 1=1'
  15958.      to cause the application to generate the query `SELECT * FROM
  15959.      table WHERE ID=234 OR 1=1'.  As a result, the server retrieves
  15960.      every record in the table.  This exposes every record and causes
  15961.      excessive server load.  The simplest way to protect from this type
  15962.      of attack is to use apostrophes around the numeric constants:
  15963.      `SELECT * FROM table WHERE ID='234''. If the user enters extra
  15964.      information, it all becomes part of the string. In numeric context,
  15965.      MySQL automatically converts this string to a number and strips
  15966.      any trailing non-numeric characters from it.
  15967.  
  15968.      Sometimes people think that if a database contains only publicly
  15969.      available data, it need not be protected. This is incorrect.  Even
  15970.      if it is allowable to display any record in the database, you
  15971.      should still protect against denial of service attacks (for
  15972.      example, those that are based on the technique in the preceding
  15973.      paragraph that causes the server to waste resources). Otherwise,
  15974.      your server becomes unresponsive to legitimate users.
  15975.  
  15976.      Checklist:
  15977.         - Try to enter `'' and `"' in all your web forms. If you get
  15978.           any kind of MySQL error, investigate the problem right away.
  15979.  
  15980.         - Try to modify any dynamic URLs by adding `%22' (`"'), `%23'
  15981.           (`#'), and `%27' (`'') in the URL.
  15982.  
  15983.         - Try to modify datatypes in dynamic URLs from numeric ones to
  15984.           character ones containing characters from previous examples.
  15985.           Your application should be safe against this and similar
  15986.           attacks.
  15987.  
  15988.         - Try to enter characters, spaces, and special symbols rather
  15989.           than numbers in numeric fields. Your application should
  15990.           remove them before passing them to MySQL or else generate an
  15991.           error. Passing unchecked values to MySQL is very dangerous!
  15992.  
  15993.         - Check data sizes before passing them to MySQL.
  15994.  
  15995.         - Consider having your application connect to the database
  15996.           using a different username than the one you use for
  15997.           administrative purposes. Do not give your applications any
  15998.           access privileges they do not need.
  15999.  
  16000.    * Many application programming interfaces provide the means of
  16001.      escaping special characters in data values. Properly used, this
  16002.      prevents application users from entering values that cause the
  16003.      application to generate statements that have a different effect
  16004.      than you intend:
  16005.         - Users of PHP: Use the `mysql_escape_string()' function, which
  16006.           is based on the function of the same name in the MySQL C API.
  16007.           Prior to PHP 4.0.3, use  `addslashes()' instead.
  16008.  
  16009.         - Users of MySQL C API: Use the `mysql_real_escape_string()'
  16010.           API call.
  16011.  
  16012.         - Users of MySQL++: Use the `escape' and `quote' modifiers for
  16013.           query streams.
  16014.  
  16015.         - Users of Perl DBI: Use the `quote()' method or use
  16016.           placeholders.
  16017.  
  16018.         - Users of Java JDBC: Use a `PreparedStatement' object and
  16019.           placeholders.
  16020.  
  16021.      Other programming interfaces may have similar capabilities.
  16022.  
  16023.    * Do not transmit plain (unencrypted) data over the Internet. This
  16024.      information is accessible to everyone who has the time and ability
  16025.      to intercept it and use it for their own purposes. Instead, use an
  16026.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  16027.      connections as of Version 4.0.0.  SSH port-forwarding can be used
  16028.      to create an encrypted (and compressed) tunnel for the
  16029.      communication.
  16030.  
  16031.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  16032.      you can check whether MySQL data streams are unencrypted by
  16033.      issuing a command like the following:
  16034.  
  16035.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  16036.  
  16037.      (This works under Linux and should work with small modifications
  16038.      under other systems.)  Warning: If you do not see plaintext data,
  16039.      this doesn't always mean that the information actually is
  16040.      encrypted. If you need high security, you should consult with a
  16041.      security expert.
  16042.  
  16043. Making MySQL Secure Against Attackers
  16044. -------------------------------------
  16045.  
  16046. When you connect to a MySQL server, you should use a password.  The
  16047. password is not transmitted in clear text over the connection. Password
  16048. handling during the client connection sequence was upgraded in MySQL
  16049. 4.1.1 to be very secure.  If you are using an older version of MySQL,
  16050. or are still using pre-4.1.1-style passwords, the encryption algorithm
  16051. is less strong and with some effort a clever attacker that can sniff
  16052. the traffic between the client and the server can crack the password.
  16053. (See *Note Password hashing:: for a discussion of the different
  16054. password handling methods.)  If the connection between the client and
  16055. the server goes through an untrusted network, you should use an SSH
  16056. tunnel to encrypt the communication.
  16057.  
  16058. All other information is transferred as text that can be read by anyone
  16059. who is able to watch the connection.  If you are concerned about this,
  16060. you can use the compressed protocol (in MySQL Version 3.22 and above)
  16061. to make traffic much more difficult to decipher.  To make the
  16062. connection even more secure, you should use SSH to get an encrypted
  16063. TCP/IP connection between a MySQL server and a MySQL client.  You can
  16064. find an `Open Source' SSH client at `http://www.openssh.org/', and a
  16065. commercial SSH client at `http://www.ssh.com/'.
  16066.  
  16067. If you are using MySQL 4.0 or newer, you can also use internal OpenSSL
  16068. support.  *Note Secure connections::.
  16069.  
  16070. To make a MySQL system secure, you should strongly consider the
  16071. following suggestions:
  16072.  
  16073.    * Use passwords for all MySQL users. A client program does not
  16074.      necessarily know the identify of the person running it. It is
  16075.      common for client/server applications that the user may specify
  16076.      any username to the client program.  For example, anyone can use
  16077.      the `mysql' program to connect as any other person simply by
  16078.      invoking it as `mysql -u other_user db_name' if `other_user' has
  16079.      no password. If all users have a password, connecting using
  16080.      another user's account becomes much more difficult.
  16081.  
  16082.      To change the password for a user, use the `SET PASSWORD'
  16083.      statement.  It is also possible to update the `user' table in the
  16084.      `mysql' database directly.  For example, to change the password of
  16085.      all MySQL accounts that have a username of `root', do this:
  16086.  
  16087.           shell> mysql -u root mysql
  16088.           mysql> UPDATE user SET Password=PASSWORD('new_password')
  16089.               -> WHERE user='root';
  16090.           mysql> FLUSH PRIVILEGES;
  16091.  
  16092.    * Don't run the MySQL server as the Unix `root' user.  This is very
  16093.      dangerous, because any user with the `FILE' privilege will be able
  16094.      to create files as `root' (for example, `~root/.bashrc'). To
  16095.      prevent this, `mysqld' refuses to run as `root' unless that is
  16096.      specified explicitly using a `--user=root' option.
  16097.  
  16098.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  16099.      can also create a separate Unix account named `mysql' to make
  16100.      everything even more secure (use the account only for
  16101.      administering MySQL).  To start `mysqld' as another Unix user, add
  16102.      a `user' option that specifies the username to the `[mysqld]'
  16103.      group of the `/etc/my.cnf' option file or the `my.cnf' option file
  16104.      in the server's data directory. For example:
  16105.  
  16106.           [mysqld]
  16107.           user=mysql
  16108.  
  16109.      This causes the server to start as the designated user whether you
  16110.      start it manually or by using `mysqld_safe' or `mysql.server'.
  16111.      For more details, see *Note Changing MySQL user::.
  16112.  
  16113.      Note that running `mysql' as a Unix user other than `root' does not
  16114.      mean that you need to change the `root' username in the `user'
  16115.      table. Usernames for MySQL accounts have nothing to do with
  16116.      usernames for Unix accounts.
  16117.  
  16118.    * Don't allow the use of symlinks to tables. (This can be disabled
  16119.      with the `--skip-symlink' option.) This is especially important if
  16120.      you run `mysqld' as `root', because anyone that has write access
  16121.      to the server's data directory could then delete any file in the
  16122.      system!  *Note Symbolic links to tables::.
  16123.  
  16124.    * Make sure that the only Unix user with read or write privileges in
  16125.      the database directories is the user that `mysqld' runs as.
  16126.  
  16127.    * Don't grant the `PROCESS' privilege to non-administrative users.
  16128.      The output of `mysqladmin processlist' shows the text of the
  16129.      currently executing queries, so any user who is allowed to execute
  16130.      that command might be able to see if another user issues an
  16131.      `UPDATE user SET password=PASSWORD('not_secure')' query.
  16132.  
  16133.      `mysqld' reserves an extra connection for users who have the
  16134.      `PROCESS' privilege, so that a MySQL `root' user can log in and
  16135.      check server activity even if all normal connections are in use.
  16136.  
  16137.    * Don't grant the `SUPER' privilege to non-administrative users.  It
  16138.      can be used to terminate client connections, change server
  16139.      operation by changing the value of system variables, and control
  16140.      replication servers.
  16141.  
  16142.    * Don't grant the `FILE' privilege to non-administrative users.  Any
  16143.      user that has this privilege can write a file anywhere in the
  16144.      filesystem with the privileges of the `mysqld' daemon!  To make
  16145.      this a bit safer, files generated with `SELECT ... INTO OUTFILE'
  16146.      will not overwrite existing files and are writable by everyone.
  16147.  
  16148.      The `FILE' privilege may also be used to read any file that is
  16149.      world-readable or accessible to the Unix user that the server runs
  16150.      as.  With this privilege, you can read any file into a database
  16151.      table.  This could be abused, for example, by using `LOAD DATA' to
  16152.      load `/etc/passwd' into a table, which then can be displayed with
  16153.      `SELECT'.
  16154.  
  16155.    * If you don't trust your DNS, you should use IP numbers rather than
  16156.      hostnames in the grant tables. In any case, you should be very
  16157.      careful about creating grant table entries using hostname values
  16158.      that contain wildcards!
  16159.  
  16160.    * If you want to restrict the number of connections allowed to a
  16161.      single account, you can do so by setting the
  16162.      `max_user_connections' variable in `mysqld'.  The `GRANT'
  16163.      statement also supports resource control options for limiting the
  16164.      extent of server use allowed to an account.
  16165.  
  16166. Startup Options for `mysqld' Concerning Security
  16167. ------------------------------------------------
  16168.  
  16169. The following `mysqld' options affect security:
  16170.  
  16171. `--local-infile[={0|1}]'
  16172.      If you start the server with `--local-infile=0', clients cannot use
  16173.      `LOCAL' in `LOAD DATA' statements.  *Note `LOAD DATA LOCAL': LOAD
  16174.      DATA LOCAL.
  16175.  
  16176. `--safe-show-database'
  16177.      With this option, the `SHOW DATABASES' statement displays the names
  16178.      of only those databases for which the user has some kind of
  16179.      privilege.  As of version 4.0.2, this option is deprecated and
  16180.      doesn't do anything (it is enabled by default), because there is
  16181.      now a `SHOW DATABASES' privilege that can be used to control
  16182.      access to database names on a per-account basis. *Note `GRANT':
  16183.      GRANT.
  16184.  
  16185. `--safe-user-create'
  16186.      If this is enabled, a user cannot create new users with the `GRANT'
  16187.      statement unless the user has the `INSERT' privilege for the
  16188.      `mysql.user' table.  If you want a user to have the ability to
  16189.      create new users with those privileges that the user has right to
  16190.      grant, you should grant the user the following privilege:
  16191.  
  16192.           mysql> GRANT INSERT(user) ON mysql.user TO 'user'@'hostname';
  16193.  
  16194.      This will ensure that the user can't change any privilege columns
  16195.      directly, but has to use the `GRANT' statement to give privileges
  16196.      to other users.
  16197.  
  16198. `--skip-grant-tables'
  16199.      This option causes the server not to use the privilege system at
  16200.      all. This gives everyone *full access* to all databases!  (You can
  16201.      tell a running server to start using the grant tables again by
  16202.      executing a `mysqladmin flush-privileges' or `mysqladmin reload'
  16203.      command, or by issuing a `FLUSH PRIVILEGES' statement.)
  16204.  
  16205. `--skip-name-resolve'
  16206.      Hostnames are not resolved.  All `Host' column values in the grant
  16207.      tables must be IP numbers or `localhost'.
  16208.  
  16209. `--skip-networking'
  16210.      Don't allow TCP/IP connections over the network.  All connections
  16211.      to `mysqld' must be made via Unix socket files.  This option is
  16212.      unsuitable when using a MySQL version prior to 3.23.27 with the
  16213.      MIT-pthreads package, because Unix socket files were not supported
  16214.      by MIT-pthreads at that time.
  16215.  
  16216. `--skip-show-database'
  16217.      Don't allow the `SHOW DATABASES' statement, unless the user has the
  16218.      `SHOW DATABASES' privilege. As of version 4.0.2, you should no
  16219.      longer need this option. Access now can be granted to specific
  16220.      accounts with the `SHOW DATABASES' privilege.
  16221.  
  16222. Security Issues with `LOAD DATA LOCAL'
  16223. --------------------------------------
  16224.  
  16225. The `LOAD DATA' statement can load a file that is located on the server
  16226. host, or, when the `LOCAL' keyword is specified, a file that is located
  16227. on the client host.
  16228.  
  16229. There are two possible problems with supporting the `LOCAL' version of
  16230. `LOAD DATA' statements:
  16231.  
  16232.    * The reading of the file is initiated from the server, so one could
  16233.      theoretically create a patched MySQL server that could tell the
  16234.      client program to read any file on the client machine that the
  16235.      current user has read access to, when the client issues a query
  16236.      against the table.
  16237.  
  16238.    * In a web environment where the clients are connecting from a web
  16239.      server, a user could use `LOAD DATA LOCAL' to read any files that
  16240.      the web server process has read access to (assuming a user could
  16241.      run any command against the SQL server). In this environment, the
  16242.      client with respect to the MySQL server actually is the web
  16243.      server, not the program being run by the user connecting to the
  16244.      web server.
  16245.  
  16246.  
  16247. To deal with these potential security issues, we changed how `LOAD DATA
  16248. LOCAL' is handled as of MySQL 3.23.49 and MySQL 4.0.2 (4.0.13 on
  16249. Windows):
  16250.  
  16251.    * By default, all MySQL clients and libraries in binary
  16252.      distributions are compiled with the `--enable-local-infile'
  16253.      option, to be compatible with MySQL 3.23.48 and before.
  16254.  
  16255.    * If you build MySQL from source but don't use the
  16256.      `--enable-local-infile' option to `configure', `LOAD DATA LOCAL'
  16257.      cannot be used by any client unless it is written explicitly to
  16258.      invoke `mysql_options(... MYSQL_OPT_LOCAL_INFILE, 0)'.  *Note
  16259.      `mysql_options()': mysql_options.
  16260.  
  16261.    * You can disable all `LOAD DATA LOCAL' commands from the server side
  16262.      by starting `mysqld' with `--local-infile=0'.
  16263.  
  16264.    * For the `mysql' command-line client, `LOAD DATA LOCAL' can be
  16265.      enabled by specifying the `--local-infile[=1]' option, or disabled
  16266.      with the `--local-infile=0' option.  Similarly, for `mysqlimport',
  16267.      the `--local' or `-L' option enable local datafile loading. In any
  16268.      case, successful use of a local loading operation requires that the
  16269.      server is enabled to allow it.
  16270.  
  16271.    * If `LOAD DATA LOCAL INFILE' is disabled, either in the server or
  16272.      the client, a client that attempts to issue such a statement
  16273.      receives the following error message:
  16274.  
  16275.           ERROR 1148: The used command is not allowed with this MySQL version
  16276.  
  16277.  
  16278. The MySQL Access Privilege System
  16279. =================================
  16280.  
  16281. MySQL has an advanced but non-standard security/privilege system.  This
  16282. section describes how it works.
  16283.  
  16284. What the Privilege System Does
  16285. ------------------------------
  16286.  
  16287. The primary function of the MySQL privilege system is to authenticate a
  16288. user connecting from a given host, and to associate that user with
  16289. privileges on a database such as `SELECT', `INSERT', `UPDATE' and
  16290. `DELETE'.
  16291.  
  16292. Additional functionality includes the ability to have an anonymous user
  16293. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  16294. INFILE' and administrative operations.
  16295.  
  16296. How the Privilege System Works
  16297. ------------------------------
  16298.  
  16299. The MySQL privilege system ensures that all users may perform only the
  16300. operations allowed to them.  As a user, when you connect to a MySQL
  16301. server, your identity is determined by *the host from which you
  16302. connect* and *the username you specify*.  The system grants privileges
  16303. according to your identity and *what you want to do*.
  16304.  
  16305. MySQL considers both your hostname and username in identifying you
  16306. because there is little reason to assume that a given username belongs
  16307. to the same person everywhere on the Internet.  For example, the user
  16308. `joe' who connects from `office.com' need not be the same person as the
  16309. user `joe' who connects from `elsewhere.com'.  MySQL handles this by
  16310. allowing you to distinguish users on different hosts that happen to
  16311. have the same name:  you can grant `joe' one set of privileges for
  16312. connections from `office.com', and a different set of privileges for
  16313. connections from `elsewhere.com'.
  16314.  
  16315. MySQL access control involves two stages:
  16316.  
  16317.    * Stage 1: The server checks whether you are even allowed to connect.
  16318.  
  16319.    * Stage 2: Assuming you can connect, the server checks each request
  16320.      you issue to see whether you have sufficient privileges to perform
  16321.      it.  For example, if you try to select rows from a table in a
  16322.      database or drop a table from the database, the server makes sure
  16323.      you have the `SELECT' privilege for the table or the `DROP'
  16324.      privilege for the database.
  16325.  
  16326. Note that if your privileges are changed (either by yourself or someone
  16327. else) while you are connected, those changes will not necessarily take
  16328. effect with your next query or queries. See *Note Privilege changes::
  16329. for details.
  16330.  
  16331. The server uses the `user', `db', and `host' tables in the `mysql'
  16332. database at both stages of access control.  The columns in these grant
  16333. tables are shown here:
  16334.  
  16335. *Table name*   *user*         *db*           *host*
  16336. *Scope         `Host'         `Host'         `Host'
  16337. columns*                                     
  16338.                `User'         `Db'           `Db'
  16339.                `Password'     `User'         
  16340. *Privilege     `Select_priv'  `Select_priv'  `Select_priv'
  16341. columns*                                     
  16342.                `Insert_priv'  `Insert_priv'  `Insert_priv'
  16343.                `Update_priv'  `Update_priv'  `Update_priv'
  16344.                `Delete_priv'  `Delete_priv'  `Delete_priv'
  16345.                `Index_priv'   `Index_priv'   `Index_priv'
  16346.                `Alter_priv'   `Alter_priv'   `Alter_priv'
  16347.                `Create_priv'  `Create_priv'  `Create_priv'
  16348.                `Drop_priv'    `Drop_priv'    `Drop_priv'
  16349.                `Grant_priv'   `Grant_priv'   `Grant_priv'
  16350.                `References_priv'`References_priv'`References_priv'
  16351.                `Reload_priv'                 
  16352.                `Shutdown_priv'               
  16353.                `Process_priv'                
  16354.                `File_priv'                   
  16355.                `Show_db_priv'                
  16356.                `Super_priv'                  
  16357.                `Create_tmp_table_priv'`Create_tmp_table_priv'`Create_tmp_table_priv'
  16358.                `Lock_tables_priv'`Lock_tables_priv'`Lock_tables_priv'
  16359.                `Execute_priv'                
  16360.                `Repl_slave_priv'               
  16361.                `Repl_client_priv'               
  16362.                `ssl_type'                    
  16363.                `ssl_cypher'                  
  16364.                `x509_issuer'                 
  16365.                `x509_cubject'                
  16366.                `max_questions'               
  16367.                `max_updates'                 
  16368.                `max_connections'               
  16369.  
  16370. During the second stage of access control (request verification), the
  16371. server may, if the request involves tables, additionally consult the
  16372. `tables_priv' and `columns_priv' tables that provide finer control at
  16373. the table and column levels.  The columns in these tables are shown
  16374. here:
  16375.  
  16376. *Table name*   *tables_priv*  *columns_priv*
  16377. *Scope         `Host'         `Host'
  16378. columns*                      
  16379.                `Db'           `Db'
  16380.                `User'         `User'
  16381.                `Table_name'   `Table_name'
  16382.                               `Column_name'
  16383. *Privilege     `Table_priv'   `Column_priv'
  16384. columns*                      
  16385.                `Column_priv'  
  16386. *Other         `Timestamp'    `Timestamp'
  16387. columns*                      
  16388.                `Grantor'      
  16389.  
  16390. Each grant table contains scope columns and privilege columns.
  16391.  
  16392. Scope columns determine the scope of each entry (row) in the tables,
  16393. that is, the context in which the entry applies.  For example, a `user'
  16394. table entry with `Host' and `User' values of `'thomas.loc.gov'' and
  16395. `'bob'' would be used for authenticating connections made to the server
  16396. from the host `thomas.loc.gov' by a client that specifies a username of
  16397. `bob'.  Similarly, a `db' table entry with `Host', `User', and `Db'
  16398. column values of `'thomas.loc.gov'', `'bob'' and `'reports'' would be
  16399. used when `bob' connects from the host `thomas.loc.gov' to access the
  16400. `reports' database.  The `tables_priv' and `columns_priv' tables
  16401. contain scope columns indicating tables or table/column combinations to
  16402. which each entry applies.
  16403.  
  16404. For access-checking purposes, comparisons of `Host' values are
  16405. case-insensitive.  `User', `Password', `Db', and `Table_name' values
  16406. are case-sensitive.  `Column_name' values are case-insensitive in MySQL
  16407. Version 3.22.12 or later.
  16408.  
  16409. Privilege columns indicate the privileges granted by a table entry,
  16410. that is, what operations can be performed.  The server combines the
  16411. information in the various grant tables to form a complete description
  16412. of a user's privileges.  The rules used to do this are described in
  16413. *Note Request access::.
  16414.  
  16415. Scope columns contain strings. They are declared as shown here; the
  16416. default value for each is the empty string:
  16417.  
  16418. *Column name*  *Type*
  16419. `Host'         `CHAR(60)'
  16420. `User'         `CHAR(16)'
  16421. `Password'     `CHAR(16)'
  16422. `Db'           `CHAR(64)'
  16423. `Table_name'   `CHAR(60)'
  16424. `Column_name'  `CHAR(60)'
  16425.  
  16426. Before MySQL 3.23, the `Db' column was `CHAR(32)' in some tables and
  16427. `CHAR(60)' in others.
  16428.  
  16429. In the `user', `db' and `host' tables, each privilege is listed in a
  16430. separate column. Each privilege column is declared as `ENUM('N','Y')'
  16431. and can have a value of `'N'' or `'Y''; the default value is `'N''.
  16432.  
  16433. In the `tables_priv' and `columns_priv' tables, the privilege columns
  16434. are declared as `SET' columns. Values in these columns can contain any
  16435. combination of the privileges controlled by the table:
  16436.  
  16437. *Table      *Column     *Possible set elements*
  16438. name*       name*       
  16439. `tables_priv'`Table_priv'`'Select', 'Insert', 'Update',
  16440.                         'Delete', 'Create', 'Drop', 'Grant',
  16441.                         'References', 'Index', 'Alter''
  16442. `tables_priv'`Column_priv'`'Select', 'Insert', 'Update',
  16443.                         'References''
  16444. `columns_priv'`Column_priv'`'Select', 'Insert', 'Update',
  16445.                         'References''
  16446.  
  16447. Briefly, the server uses the grant tables like this:
  16448.  
  16449.    * The `user' table scope columns determine whether to allow or reject
  16450.      incoming connections.  For allowed connections, any privileges
  16451.      granted in the `user' table indicate the user's global (superuser)
  16452.      privileges.  These privileges apply to *all* databases on the
  16453.      server.
  16454.  
  16455.    * The `db' and `host' tables are used together:
  16456.  
  16457.         - The `db' table scope columns determine which users can access
  16458.           which databases from which hosts.  The privilege columns
  16459.           determine which operations are allowed.
  16460.  
  16461.         - The `host' table is used as an extension of the `db' table
  16462.           when you want a given `db' table entry to apply to several
  16463.           hosts.  For example, if you want a user to be able to use a
  16464.           database from several hosts in your network, leave the `Host'
  16465.           value empty in the user's `db' table entry, then populate the
  16466.           `host' table with an entry for each of those hosts.  This
  16467.           mechanism is described more detail in *Note Request access::.
  16468.           Note that the `host' table is not affected by the `GRANT' and
  16469.           `REVOKE' statements. Most MySQL installations need not use
  16470.           this table at all.
  16471.  
  16472.    * The `tables_priv' and `columns_priv' tables are similar to the
  16473.      `db' table, but are more fine-grained: they apply at the table and
  16474.      column levels rather than at the database level.
  16475.  
  16476. Administrative privileges (such as `RELOAD' or `SHUTDOWN') are
  16477. specified only in the `user' table.  This is because administrative
  16478. operations are operations on the server itself and are not
  16479. database-specific, so there is no reason to list these privileges in the
  16480. other grant tables.  In fact, to determine whether you can perform an
  16481. administrative operation, the server need consult only the `user' table.
  16482.  
  16483. The `FILE' privilege also is specified only in the `user' table.  It is
  16484. not an administrative privilege as such, but your ability to read or
  16485. write files on the server host is independent of the database you are
  16486. accessing.
  16487.  
  16488. The `mysqld' server reads the contents of the grant tables once, when it
  16489. starts.  Changes to the grant tables take effect as indicated in *Note
  16490. Privilege changes::.
  16491.  
  16492. When you modify the contents of the grant tables, it is a good idea to
  16493. make sure that your changes set up privileges the way you want.  For
  16494. help in diagnosing problems, see *Note Access denied::.  For advice on
  16495. general security issues, see *Note Security::.
  16496.  
  16497. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  16498. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  16499. with the `--help' option to find out how it works.  Note that
  16500. `mysqlaccess' checks access using only the `user', `db' and `host'
  16501. tables.  It does not check table or column privileges in the
  16502. `tables_priv' or `columns_priv' tables.
  16503.  
  16504. Privileges Provided by MySQL
  16505. ----------------------------
  16506.  
  16507. Information about user privileges is stored in the `user', `db',
  16508. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  16509. database (that is, in the database named `mysql').  The MySQL server
  16510. reads the contents of these tables when it starts and under the
  16511. circumstances indicated in *Note Privilege changes::.
  16512.  
  16513. The names used in this manual to refer to the privileges provided by
  16514. MySQL version 4.0.2 are shown here, along with the table column name
  16515. associated with each privilege in the grant tables and the context in
  16516. which the privilege applies. Further information about the meaning of
  16517. each privilege may be found at *Note `GRANT': GRANT.
  16518.  
  16519. *Privilege* *Column*       *Context*
  16520. `ALTER'     `Alter_priv'   tables
  16521. `DELETE'    `Delete_priv'  tables
  16522. `INDEX'     `Index_priv'   tables
  16523. `INSERT'    `Insert_priv'  tables
  16524. `SELECT'    `Select_priv'  tables
  16525. `UPDATE'    `Update_priv'  tables
  16526. `CREATE'    `Create_priv'  databases, tables, or
  16527.                            indexes
  16528. `DROP'      `Drop_priv'    databases or tables
  16529. `GRANT'     `Grant_priv'   databases or tables
  16530. `REFERENCES'`References_priv'databases or tables
  16531. `CREATE     `Create_tmp_table_priv'server administration
  16532. TEMPORARY                  
  16533. TABLES'                    
  16534. `EXECUTE'   `Execute_priv' server administration
  16535. `FILE'      `File_priv'    file access on server
  16536. `LOCK       `Lock_tables_priv'server administration
  16537. TABLES'                    
  16538. `PROCESS'   `Process_priv' server administration
  16539. `RELOAD'    `Reload_priv'  server administration
  16540. `REPLICATION`Repl_client_priv'server administration
  16541. CLIENT'                    
  16542. `REPLICATION`Repl_slave_priv'server administration
  16543. SLAVE'                     
  16544. `SHOW       `Show_db_priv' server administration
  16545. DATABASES'                 
  16546. `SHUTDOWN'  `Shutdown_priv'server administration
  16547. `SUPER'     `Super_priv'   server administration
  16548.  
  16549. The `SELECT', `INSERT', `UPDATE', and `DELETE' privileges allow you to
  16550. perform operations on rows in existing tables in a database.
  16551.  
  16552. `SELECT' statements require the `SELECT' privilege only if they
  16553. actually retrieve rows from a table.  Some `SELECT' statements do not
  16554. access tables, so they can be executed even without permission for any
  16555. of the databases on the server.  For example, you can use the `mysql'
  16556. client as a simple calculator:
  16557.  
  16558.      mysql> SELECT 1+1;
  16559.      mysql> SELECT PI()*2;
  16560.  
  16561. The `INDEX' privilege allows you to create or drop (remove) indexes.
  16562.  
  16563. The `ALTER' privilege allows you to use `ALTER TABLE'.
  16564.  
  16565. The `CREATE' and `DROP' privileges allow you to create new databases
  16566. and tables, or to drop (remove) existing databases and tables.
  16567.  
  16568. Note that if you grant the `DROP' privilege for the `mysql' database to
  16569. a user, that user can drop the database in which the MySQL access
  16570. privileges are stored!
  16571.  
  16572. The `GRANT' privilege allows you to give to other users those
  16573. privileges you yourself possess.
  16574.  
  16575. The `FILE' privilege gives you permission to read and write files on
  16576. the server using the `LOAD DATA INFILE' and `SELECT ... INTO OUTFILE'
  16577. statements.  Any user to whom this privilege is granted can read any
  16578. world-readable file accessable by the MySQL server and create a new
  16579. world-readable file in any directory where the MySQL server can write.
  16580. The user can also read any file in the current database directory.
  16581. However, the user cannot change any existing file.
  16582.  
  16583. The remaining privileges are used for administrative operations. Many of
  16584. them can be performed by using using the `mysqladmin' program or by
  16585. issuing SQL statements.  The following table shows which `mysqladmin'
  16586. commands each administrative privilege allows you to execute:
  16587.  
  16588. *Privilege* *Commands permitted to privilege holders*
  16589. `RELOAD'    `refresh', `reload', `flush-hosts', `flush-logs',
  16590.             `flush-privileges', `flush-status', `flush-threads',
  16591.             and `flush-tables'
  16592. `SHUTDOWN'  `shutdown'
  16593. `PROCESS'   `processlist'
  16594. `SUPER'     `kill'
  16595.  
  16596. The `reload' command tells the server to re-read the grant tables.  The
  16597. `refresh' command flushes all tables and opens and closes the log
  16598. files.  `flush-privileges' is a synonym for `reload'.  The other
  16599. `flush-*' commands perform functions similar to `refresh' but are more
  16600. limited in scope, and may be preferable in some instances.  For example,
  16601. if you want to flush just the log files, `flush-logs' is a better choice
  16602. than `refresh'.
  16603.  
  16604. The `shutdown' command shuts down the server. This command can be issued
  16605. only from `mysqladmin'. There is no corresponding SQL statement.
  16606.  
  16607. The `processlist' command displays information about the threads
  16608. executing within the server (that is, about the statements that other
  16609. clients are executing).  The `kill' command kills server threads.  You
  16610. can always display or kill your own threads, but you need the `PROCESS'
  16611. privilege to display threads initiated by other users and and the
  16612. `SUPER' privilege to kill them.  *Note `KILL': KILL.
  16613.  
  16614. It is a good idea in general to grant privileges only to those users
  16615. who need them, but you should exercise particular caution in granting
  16616. administrative privileges:
  16617.  
  16618.    * The `GRANT' privilege allows users to give their privileges to
  16619.      other users.  Two users with different privileges and with the
  16620.      `GRANT' privilege are able to combine privileges.
  16621.  
  16622.    * The `ALTER' privilege may be used to subvert the privilege system
  16623.      by renaming tables.
  16624.  
  16625.    * The `FILE' privilege can be abused to read into a database table
  16626.      any world-readable file on the server host or any file in the
  16627.      server's data directory. The contents of that table can then be
  16628.      accessed using `SELECT'.
  16629.  
  16630.    * The `SHUTDOWN' privilege can be abused to deny service to other
  16631.      users entirely by terminating the server.
  16632.  
  16633.    * The `PROCESS' privilege can be used to view the plain text of
  16634.      currently executing queries, including queries that set or change
  16635.      passwords.
  16636.  
  16637.    * The `SUPER' privilege can be used to terminate other clients or
  16638.      change how the server operates.
  16639.  
  16640.    * Privileges granted for the `mysql' database itself can be used to
  16641.      change passwords and other access privilege information.
  16642.      (Passwords are stored encrypted, so a malicious user cannot simply
  16643.      read them to know the plain text password.)  If they can access
  16644.      the `mysql.user' password column, they can use it to log into the
  16645.      MySQL server for the given user.  (With sufficient privileges, the
  16646.      same user can replace a password with a different one.)
  16647.  
  16648. There are some things that you cannot do with the MySQL privilege
  16649. system:
  16650.  
  16651.    * You cannot explicitly specify that a given user should be denied
  16652.      access.  That is, you cannot explicitly match a user and then
  16653.      refuse the connection.
  16654.  
  16655.    * You cannot specify that a user has privileges to create or drop
  16656.      tables in a database but not to create or drop the database itself.
  16657.  
  16658. Connecting to the MySQL Server
  16659. ------------------------------
  16660.  
  16661. MySQL client programs generally require that you specify connection
  16662. parameters when you want to access a MySQL server: the host you want to
  16663. connect to, your username, and your password.  For example, the `mysql'
  16664. client can be started like this, where optional arguments are indicated
  16665. by `[' and `]':
  16666.  
  16667.      shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
  16668.  
  16669. Alternate forms of the `-h', `-u', and `-p' options are
  16670. `--host=host_name', `--user=user_name', and `--password=your_pass'.
  16671. Note that there is _no space_ between `-p' or `--password=' and the
  16672. password following it.
  16673.  
  16674. *Note:* Specifying a password on the command line is not secure!  Any
  16675. user on your system may then find out your password by typing a command
  16676. like: `ps auxww'.  *Note Option files::.
  16677.  
  16678. `mysql' uses default values for connection parameters that are not given
  16679. on the command line:
  16680.  
  16681.    * The default hostname is `localhost'.
  16682.  
  16683.    * The default username is your Unix login name.
  16684.  
  16685.    * No password is supplied if `-p' is missing.
  16686.  
  16687. Thus, for a Unix user `joe', the following commands are equivalent:
  16688.  
  16689.      shell> mysql -h localhost -u joe
  16690.      shell> mysql -h localhost
  16691.      shell> mysql -u joe
  16692.      shell> mysql
  16693.  
  16694. Other MySQL clients behave similarly.
  16695.  
  16696. On Unix systems, you can specify different default values to be used
  16697. when you make a connection, so that you need not enter them on the
  16698. command-line each time you invoke a client program.  This can be done
  16699. in a couple of ways:
  16700.  
  16701.    * You can specify connection parameters in the `[client]' section of
  16702.      the `.my.cnf' option file in your home directory.  The relevant
  16703.      section of the file might look like this:
  16704.  
  16705.           [client]
  16706.           host=host_name
  16707.           user=user_name
  16708.           password=your_pass
  16709.  
  16710.      *Note Option files::.
  16711.  
  16712.    * You can specify connection parameters using environment variables.
  16713.      The host can be specified for `mysql' using `MYSQL_HOST'.  The
  16714.      MySQL username can be specified using `USER' (this is for Windows
  16715.      and NetWare only).  The password can be specified using `MYSQL_PWD'
  16716.      (but this is insecure; see the next section).  *Note Environment
  16717.      variables::.
  16718.  
  16719. Access Control, Stage 1: Connection Verification
  16720. ------------------------------------------------
  16721.  
  16722. When you attempt to connect to a MySQL server, the server accepts or
  16723. rejects the connection based on your identity and whether you can
  16724. verify your identity by supplying the correct password.  If not, the
  16725. server denies access to you completely.  Otherwise, the server accepts
  16726. the connection, then enters Stage 2 and waits for requests.
  16727.  
  16728. Your identity is based on two pieces of information:
  16729.  
  16730.    * The host from which you connect
  16731.  
  16732.    * Your MySQL username
  16733.  
  16734. Identity checking is performed using the three `user' table scope
  16735. columns (`Host', `User', and `Password').  The server accepts the
  16736. connection only if a `user' table entry matches your hostname and user
  16737. name, and you supply the correct password.
  16738.  
  16739. Values in the `user' table scope columns may be specified as follows:
  16740.  
  16741.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  16742.      to indicate the local host.
  16743.  
  16744.    * You can use the wildcard characters `%' and `_' in the `Host'
  16745.      column.
  16746.  
  16747.    * A `Host' value of `'%'' matches any hostname.
  16748.  
  16749.    * A blank `Host' value means that the privilege should be anded with
  16750.      the entry in the `host' table that matches the given hostname.
  16751.      You can find more information about this in the next chapter.
  16752.  
  16753.    * As of MySQL Version 3.23, for `Host' values specified as IP
  16754.      numbers, you can specify a netmask indicating how many address
  16755.      bits to use for the network number. For example:
  16756.  
  16757.           mysql> GRANT ALL PRIVILEGES ON db.*
  16758.               -> TO david@'192.58.197.0/255.255.255.0';
  16759.  
  16760.      This will allow everyone to connect from an IP where the following
  16761.      is true:
  16762.  
  16763.           user_ip & netmask = host_ip.
  16764.  
  16765.      In the above example all IP:s in the interval 192.58.197.0 -
  16766.      192.58.197.255 can connect to the MySQL server.
  16767.  
  16768.    * Wildcard characters are not allowed in the `User' column, but you
  16769.      can specify a blank value, which matches any name.  If the `user'
  16770.      table entry that matches an incoming connection has a blank
  16771.      username, the user is considered to be the anonymous user (the
  16772.      user with no name), rather than the name that the client actually
  16773.      specified.  This means that a blank username is used for all
  16774.      further access checking for the duration of the connection (that
  16775.      is, during Stage 2).
  16776.  
  16777.    * The `Password' column can be blank.  This does not mean that any
  16778.      password matches, it means the user must connect without
  16779.      specifying a password.
  16780.  
  16781. Non-blank `Password' values represent encrypted passwords.  MySQL does
  16782. not store passwords in plaintext form for anyone to see.  Rather, the
  16783. password supplied by a user who is attempting to connect is encrypted
  16784. (using the `PASSWORD()' function). The encrypted password is then used
  16785. when the client/server is checking if the password is correct. (This is
  16786. done without the encrypted password ever traveling over the
  16787. connection.)  Note that from MySQL's point of view the encrypted
  16788. password is the REAL password, so you should not give anyone access to
  16789. it!  In particular, don't give normal users read access to the tables
  16790. in the `mysql' database!  From version 4.1, MySQL employs a different
  16791. password and login mechanism that is secure even if TCP/IP packets are
  16792. sniffed and/or the mysql database is captured.
  16793.  
  16794. The examples here show how various combinations of `Host' and `User'
  16795. values in `user' table entries apply to incoming connections:
  16796.  
  16797. `Host' *value*            `User'      *Connections matched by entry*
  16798.                           *value*     
  16799. `'thomas.loc.gov''        `'fred''    `fred', connecting from
  16800.                                       `thomas.loc.gov'
  16801. `'thomas.loc.gov''        `'''        Any user, connecting from
  16802.                                       `thomas.loc.gov'
  16803. `'%''                     `'fred''    `fred', connecting from any host
  16804. `'%''                     `'''        Any user, connecting from any host
  16805. `'%.loc.gov''             `'fred''    `fred', connecting from any host in
  16806.                                       the `loc.gov' domain
  16807. `'x.y.%''                 `'fred''    `fred', connecting from `x.y.net',
  16808.                                       `x.y.com',`x.y.edu', etc. (this is
  16809.                                       probably not useful)
  16810. `'144.155.166.177''       `'fred''    `fred', connecting from the host
  16811.                                       with IP address `144.155.166.177'
  16812. `'144.155.166.%''         `'fred''    `fred', connecting from any host in
  16813.                                       the `144.155.166' class C subnet
  16814. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  16815.  
  16816. Because you can use IP wildcard values in the `Host' column (for
  16817. example, `'144.155.166.%'' to match every host on a subnet), there is
  16818. the possibility that someone might try to exploit this capability by
  16819. naming a host `144.155.166.somewhere.com'.  To foil such attempts, MySQL
  16820. disallows matching on hostnames that start with digits and a dot. Thus,
  16821. if you have a host named something like `1.2.foo.com', its name will
  16822. never match the `Host' column of the grant tables.  Only an IP number
  16823. can match an IP wildcard value.
  16824.  
  16825. An incoming connection may be matched by more than one entry in the
  16826. `user' table.  For example, a connection from `thomas.loc.gov' by
  16827. `fred' would be matched by several of the entries shown in the preceding
  16828. table.  How does the server choose which entry to use if more than one
  16829. matches?  The server resolves this question by sorting the `user' table
  16830. after reading it at startup time, then looking through the entries in
  16831. sorted order when a user attempts to connect.  The first matching entry
  16832. is the one that is used.
  16833.  
  16834. `user' table sorting works as follows.  Suppose the `user' table looks
  16835. like this:
  16836.  
  16837.      +-----------+----------+-
  16838.      | Host      | User     | ...
  16839.      +-----------+----------+-
  16840.      | %         | root     | ...
  16841.      | %         | jeffrey  | ...
  16842.      | localhost | root     | ...
  16843.      | localhost |          | ...
  16844.      +-----------+----------+-
  16845.  
  16846. When the server reads in the table, it orders the entries with the
  16847. most-specific `Host' values first (`'%'' in the `Host' column means
  16848. "any host" and is least specific).  Entries with the same `Host' value
  16849. are ordered with the most-specific `User' values first (a blank `User'
  16850. value means "any user" and is least specific).  The resulting sorted
  16851. `user' table looks like this:
  16852.  
  16853.      +-----------+----------+-
  16854.      | Host      | User     | ...
  16855.      +-----------+----------+-
  16856.      | localhost | root     | ...
  16857.      | localhost |          | ...
  16858.      | %         | jeffrey  | ...
  16859.      | %         | root     | ...
  16860.      +-----------+----------+-
  16861.  
  16862. When a connection is attempted, the server looks through the sorted
  16863. entries and uses the first match found.  For a connection from
  16864. `localhost' by `jeffrey', the entries with `'localhost'' in the `Host'
  16865. column match first.  Of those, the entry with the blank username
  16866. matches both the connecting hostname and username.  (The
  16867. `'%'/'jeffrey'' entry would have matched, too, but it is not the first
  16868. match in the table.)
  16869.  
  16870. Here is another example.  Suppose the `user' table looks like this:
  16871.  
  16872.      +----------------+----------+-
  16873.      | Host           | User     | ...
  16874.      +----------------+----------+-
  16875.      | %              | jeffrey  | ...
  16876.      | thomas.loc.gov |          | ...
  16877.      +----------------+----------+-
  16878.  
  16879. The sorted table looks like this:
  16880.  
  16881.      +----------------+----------+-
  16882.      | Host           | User     | ...
  16883.      +----------------+----------+-
  16884.      | thomas.loc.gov |          | ...
  16885.      | %              | jeffrey  | ...
  16886.      +----------------+----------+-
  16887.  
  16888. A connection from `thomas.loc.gov' by `jeffrey' is matched by the first
  16889. entry, whereas a connection from `whitehouse.gov' by `jeffrey' is
  16890. matched by the second.
  16891.  
  16892. A common misconception is to think that for a given username, all
  16893. entries that explicitly name that user will be used first when the
  16894. server attempts to find a match for the connection.  This is simply not
  16895. true.  The previous example illustrates this, where a connection from
  16896. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  16897. containing `'jeffrey'' as the `User' column value, but by the entry
  16898. with no username!
  16899.  
  16900. If you have problems connecting to the server, print out the `user'
  16901. table and sort it by hand to see where the first match is being made.
  16902. If connection was successful, but your privileges are not what you
  16903. expected you may use `CURRENT_USER()' function (new in version 4.0.6)
  16904. to see what user/host combination your connection actually matched.
  16905. *Note `CURRENT_USER()': Miscellaneous functions.
  16906.  
  16907. Access Control, Stage 2: Request Verification
  16908. ---------------------------------------------
  16909.  
  16910. Once you establish a connection, the server enters Stage 2.  For each
  16911. request that comes in on the connection, the server checks whether you
  16912. have sufficient privileges to perform it, based on the type of
  16913. operation you wish to perform.  This is where the privilege columns in
  16914. the grant tables come into play.  These privileges can come from any of
  16915. the `user', `db', `host', `tables_priv', or `columns_priv' tables.  The
  16916. grant tables are manipulated with `GRANT' and `REVOKE' commands.  *Note
  16917. `GRANT': GRANT.  (You may find it helpful to refer to *Note
  16918. Privileges::, which lists the columns present in each of the grant
  16919. tables.)
  16920.  
  16921. The `user' table grants privileges that are assigned to you on a global
  16922. basis and that apply no matter what the current database is.  For
  16923. example, if the `user' table grants you the `DELETE' privilege, you can
  16924. delete rows from any database on the server host!  In other words,
  16925. `user' table privileges are superuser privileges.  It is wise to grant
  16926. privileges in the `user' table only to superusers such as server or
  16927. database administrators.  For other users, you should leave the
  16928. privileges in the `user' table set to `'N'' and grant privileges on a
  16929. database-specific basis only, using the `db' and `host' tables.
  16930.  
  16931. The `db' and `host' tables grant database-specific privileges.  Values
  16932. in the scope columns may be specified as follows:
  16933.  
  16934.    * The wildcard characters `%' and `_' can be used in the `Host' and
  16935.      `Db' columns of either table. If you wish to use for instance a
  16936.      `_' character as part of a database name, specify it as `\_' in
  16937.      the `GRANT' command.
  16938.  
  16939.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  16940.      `Host' value in the `db' table means "consult the `host' table for
  16941.      further information."
  16942.  
  16943.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  16944.  
  16945.    * A `'%'' or blank `Db' value in either table means "any database."
  16946.  
  16947.    * A blank `User' value in either table matches the anonymous user.
  16948.  
  16949. The `db' and `host' tables are read in and sorted when the server
  16950. starts (at the same time that it reads the `user' table).  The `db'
  16951. table is sorted on the `Host', `Db', and `User' scope columns, and the
  16952. `host' table is sorted on the `Host' and `Db' scope columns.  As with
  16953. the `user' table, sorting puts the most-specific values first and
  16954. least-specific values last, and when the server looks for matching
  16955. entries, it uses the first match that it finds.
  16956.  
  16957. The `tables_priv' and `columns_priv' tables grant table- and
  16958. column-specific privileges.  Values in the scope columns may be
  16959. specified as follows:
  16960.  
  16961.    * The wildcard characters `%' and `_' can be used in the `Host'
  16962.      column of either table.
  16963.  
  16964.    * A `'%'' or blank `Host' value in either table means "any host."
  16965.  
  16966.    * The `Db', `Table_name' and `Column_name' columns cannot contain
  16967.      wildcards or be blank in either table.
  16968.  
  16969. The `tables_priv' and `columns_priv' tables are sorted on the `Host',
  16970. `Db', and `User' columns.  This is similar to `db' table sorting,
  16971. although the sorting is simpler because only the `Host' column may
  16972. contain wildcards.
  16973.  
  16974. The request verification process is described here.  (If you are
  16975. familiar with the access-checking source code, you will notice that the
  16976. description here differs slightly from the algorithm used in the code.
  16977. The description is equivalent to what the code actually does; it
  16978. differs only to make the explanation simpler.)
  16979.  
  16980. For administrative requests (`SHUTDOWN', `RELOAD', etc.), the server
  16981. checks only the `user' table entry, because that is the only table that
  16982. specifies administrative privileges.  Access is granted if the entry
  16983. allows the requested operation and denied otherwise.  For example, if
  16984. you want to execute `mysqladmin shutdown' but your `user' table entry
  16985. doesn't grant the `SHUTDOWN' privilege to you, access is denied without
  16986. even checking the `db' or `host' tables.  (They contain no
  16987. `Shutdown_priv' column, so there is no need to do so.)
  16988.  
  16989. For database-related requests (`INSERT', `UPDATE', etc.), the server
  16990. first checks the user's global (superuser) privileges by looking in the
  16991. `user' table entry.  If the entry allows the requested operation,
  16992. access is granted.  If the global privileges in the `user' table are
  16993. insufficient, the server determines the user's database-specific
  16994. privileges by checking the `db' and `host' tables:
  16995.  
  16996.   1. The server looks in the `db' table for a match on the `Host',
  16997.      `Db', and `User' columns.  The `Host' and `User' columns are
  16998.      matched to the connecting user's hostname and MySQL username.  The
  16999.      `Db' column is matched to the database the user wants to access.
  17000.      If there is no entry for the `Host' and `User', access is denied.
  17001.  
  17002.   2. If there is a matching `db' table entry and its `Host' column is
  17003.      not blank, that entry defines the user's database-specific
  17004.      privileges.
  17005.  
  17006.   3. If the matching `db' table entry's `Host' column is blank, it
  17007.      signifies that the `host' table enumerates which hosts should be
  17008.      allowed access to the database.  In this case, a further lookup is
  17009.      done in the `host' table to find a match on the `Host' and `Db'
  17010.      columns.  If no `host' table entry matches, access is denied.  If
  17011.      there is a match, the user's database-specific privileges are
  17012.      computed as the intersection (*not* the union!) of the privileges
  17013.      in the `db' and `host' table entries, that is, the privileges that
  17014.      are `'Y'' in both entries.  (This way you can grant general
  17015.      privileges in the `db' table entry and then selectively restrict
  17016.      them on a host-by-host basis using the `host' table entries.)
  17017.  
  17018. After determining the database-specific privileges granted by the `db'
  17019. and `host' table entries, the server adds them to the global privileges
  17020. granted by the `user' table.  If the result allows the requested
  17021. operation, access is granted.  Otherwise, the server checks the user's
  17022. table and column privileges in the `tables_priv' and `columns_priv'
  17023. tables and adds those to the user's privileges.  Access is allowed or
  17024. denied based on the result.
  17025.  
  17026. Expressed in boolean terms, the preceding description of how a user's
  17027. privileges are calculated may be summarized like this:
  17028.  
  17029.      global privileges
  17030.      OR (database privileges AND host privileges)
  17031.      OR table privileges
  17032.      OR column privileges
  17033.  
  17034. It may not be apparent why, if the global `user' entry privileges are
  17035. initially found to be insufficient for the requested operation, the
  17036. server adds those privileges to the database-, table-, and
  17037. column-specific privileges later. The reason is that a request might
  17038. require more than one type of privilege.  For example, if you execute
  17039. an `INSERT ...  SELECT' statement, you need both `INSERT' and `SELECT'
  17040. privileges.  Your privileges might be such that the `user' table entry
  17041. grants one privilege and the `db' table entry grants the other.  In
  17042. this case, you have the necessary privileges to perform the request,
  17043. but the server cannot tell that from either table by itself; the
  17044. privileges granted by the entries in both tables must be combined.
  17045.  
  17046. The `host' table can be used to maintain a list of secure servers.
  17047.  
  17048. At TcX, the `host' table contains a list of all machines on the local
  17049. network. These are granted all privileges.
  17050.  
  17051. You can also use the `host' table to indicate hosts that are *not*
  17052. secure.  Suppose you have a machine `public.your.domain' that is located
  17053. in a public area that you do not consider secure.  You can allow access
  17054. to all hosts on your network except that machine by using `host' table
  17055. entries like this:
  17056.  
  17057.      +--------------------+----+-
  17058.      | Host               | Db | ...
  17059.      +--------------------+----+-
  17060.      | public.your.domain | %  | ... (all privileges set to 'N')
  17061.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  17062.      +--------------------+----+-
  17063.  
  17064. Naturally, you should always test your entries in the grant tables (for
  17065. example, using `mysqlaccess') to make sure your access privileges are
  17066. actually set up the way you think they are.
  17067.  
  17068. Password Hashing in MySQL 4.1
  17069. -----------------------------
  17070.  
  17071. MySQL user accounts are listed in the `user' table of the `mysql'
  17072. database. Each MySQL account is assigned a password, although what is
  17073. stored in the `Password' column of the `user' table is not the
  17074. plaintext version of the password, but a hash value computed from it.
  17075. Password hash values are computed by the `PASSWORD()' function.
  17076.  
  17077. MySQL uses passwords in two phases of client/server communication:
  17078.  
  17079.    * First, when a client attempts to connect to the server, there is an
  17080.      initial authentication step in which the client must present a
  17081.      password that matches the hash value stored in the user table for
  17082.      the account that the client wants to use.
  17083.  
  17084.    * Second, after the client connects, it may set or change the
  17085.      password hashes for accounts listed in the user table (if it has
  17086.      sufficient privileges). The client may do this by using the
  17087.      PASSWORD() function to generate a password hash, or by using the
  17088.      GRANT or SET PASSWORD statements.
  17089.  
  17090.  
  17091. In other words, the server _uses_ hash values during authentication when
  17092. a client first attempts to connect. The server _generates_ hash values
  17093. if a connected client invokes the `PASSWORD()' function or uses a
  17094. `GRANT' or `SET PASSWORD' statement to set or change a password.
  17095.  
  17096. The password hashing mechanism was updated in MySQL 4.1 to provide
  17097. better security and to reduce the risk of passwords being stolen.
  17098. However, this new mechanism is understood only by the 4.1 server and
  17099. 4.1 clients, which can result in some compatibility problems.  A 4.1
  17100. client can connect to a pre-4.1 server, because the client understands
  17101. both the old and new password hashing mechanisms. However, a pre-4.1
  17102. client that attempts to connect to a 4.1 server may run into
  17103. difficulties.  For example, a 4.0 `mysql' client that attempts to
  17104. connect to a 4.1 server may fail with the following error message:
  17105.  
  17106.      shell> mysql
  17107.      Client does not support authentication protocol requested
  17108.      by server; consider upgrading MySQL client
  17109.  
  17110. The following discussion describes the differences between the old and
  17111. new password mechanisms, and what you should do if you upgrade your
  17112. server to 4.1 but need to maintain backward compatibility with pre-4.1
  17113. clients.
  17114.  
  17115. *Note:* This discussion contrasts 4.1 behavior with pre-4.1 behavior,
  17116. but the 4.1 behavior described here actually begins with 4.1.1. MySQL
  17117. 4.1.0 is an "odd" release because it has a slightly different mechanism
  17118. than that implemented in 4.1.1 and up.  Differences between 4.1.0 and
  17119. more recent versions are described later.
  17120.  
  17121. Prior to MySQL 4.1, password hashes computed by the `PASSWORD()'
  17122. function are 16 bytes long.  Such hashes look like this:
  17123.  
  17124.      mysql> SELECT PASSWORD('mypass');
  17125.      +--------------------+
  17126.      | PASSWORD('mypass') |
  17127.      +--------------------+
  17128.      | 6f8c114b58f2ce9e   |
  17129.      +--------------------+
  17130.  
  17131. The `Password' column of the `user' table (in which these hashes are
  17132. stored) also is 16 bytes long before MySQL 4.1.
  17133.  
  17134. As of MySQL 4.1, the `PASSWORD()' function has been modified to produce
  17135. a longer 41-byte hash value:
  17136.  
  17137.      mysql> SELECT PASSWORD('mypass');
  17138.      +-----------------------------------------------+
  17139.      | PASSWORD('mypass')                            |
  17140.      +-----------------------------------------------+
  17141.      | *43c8aa34cdc98eddd3de1fe9a9c2c2a9f92bb2098d75 |
  17142.      +-----------------------------------------------+
  17143.  
  17144. Accordingly, the `Password' column in the `user' table also must be 41
  17145. bytes long to store these values:
  17146.  
  17147.    * If you perform a new installation of MySQL 4.1, the `Password'
  17148.      column will be made 41 bytes long automatically.
  17149.  
  17150.    * If you upgrade an older installation to 4.1, you should run the
  17151.      `mysql_fix_privilege_tables' script to update the length of the
  17152.      `Password' column from 16 to 41 bytes. (The script does not change
  17153.      existing password values, which remain 16 bytes long.)
  17154.  
  17155.  
  17156. A widened `Password' column can store password hashes in both the old
  17157. and new formats. The format of any given password hash value can be
  17158. determined two ways:
  17159.  
  17160.    * The obvious difference is the length (16 bytes versus 41 bytes)
  17161.  
  17162.    * A second difference is that password hashes in the new format
  17163.      always begin with a `*' character, whereas passwords in the old
  17164.      format never do
  17165.  
  17166.  
  17167. The longer password hash format has better cryptographic properties, and
  17168. client authentication based on long hashes is more secure than that
  17169. based on the older short hashes.
  17170.  
  17171. The differences between short and long password hashes are relevant
  17172. both for how the server uses passwords during authentication and for
  17173. how it generates password hashes for connected clients that perform
  17174. password-changing operations.
  17175.  
  17176. The way in which the server uses password hashes during authentication
  17177. is affected by the width of the Password column:
  17178.  
  17179.    * If the column is narrow, only short-hash authentication is used.
  17180.  
  17181.    * If the column is wide, it can hold either short or long hashes, and
  17182.      the server can use either format:
  17183.  
  17184.         * Pre-4.1 clients can connect, though because they know only
  17185.           about the old hashing mechanism, they can authenticate only
  17186.           for accounts that have short hashes.
  17187.  
  17188.         * 4.1 clients can authenticate for accounts that have short or
  17189.           long hashes.
  17190.  
  17191.  
  17192.  
  17193. For short-hash accounts, the authentication process is actually a bit
  17194. more secure for 4.1 clients than for older clients.  In terms of
  17195. security, the gradient from least to most secure is:
  17196.  
  17197.    * Pre-4.1 client authenticating for account with short password hash
  17198.  
  17199.    * 4.1 client authenticating for account with short password hash
  17200.  
  17201.    * 4.1 client authenticating for account with long password hash
  17202.  
  17203.  
  17204. The way in which the server generates password hashes for connected
  17205. clients is affected by the width of the `Password' column and by the
  17206. `--old-passwords' option.  A 4.1 server generates long hashes only if
  17207. certain conditions are met: The `Password' column must be wide enough
  17208. to hold long values and the `--old-passwords' option must not be given.
  17209. These conditions apply as follows:
  17210.  
  17211.    * The `Password' column must be wide enough to hold long hashes (41
  17212.      bytes).  If the column has not been updated and still has the
  17213.      pre-4.1 width (16 bytes), the server notices that long hashes
  17214.      cannot fit into it and generates only short hashes when a client
  17215.      performs password-changing operations using `PASSWORD()', `GRANT',
  17216.      or `SET PASSWORD'.  (This behavior occurs if you have upgraded to
  17217.      4.1 but have not run the `mysql_fix_privilege_tables' script to
  17218.      widen the `Password' column.)
  17219.  
  17220.    * If the `Password' column is wide, it can store either short or long
  17221.      password hashes. In this case, `PASSWORD()', `GRANT', and `SET
  17222.      PASSWORD' will generate long hashes unless the server was started
  17223.      with the `--old-passwords' option. This option forces the server
  17224.      to generate short passsword hashes instead.
  17225.  
  17226.  
  17227. The purpose of the `--old-passwords' option is to allow you to maintain
  17228. backward compatibility with pre-4.1 clients under circumstances where
  17229. the server would otherwise generate long password hashes. It doesn't
  17230. affect authentication (4.1 clients can still use accounts that have
  17231. long password hashes), but it does prevent creation of a long password
  17232. hash in the `user' table as the result of a password-changing
  17233. operation. Were that to occur, the account no longer could be used by
  17234. pre-4.1 clients. Without the `--old-passwords' option, the following
  17235. scenario is possible:
  17236.  
  17237.    * An old client connects to an account that has a short password
  17238.      hash.
  17239.  
  17240.    * The client changes the account's password. Without
  17241.      `--old-passwords', this results in the account having a long
  17242.      password hash.
  17243.  
  17244.    * The next time the old client attempts to connect to the account, it
  17245.      cannot, because the account now requires the new hashing mechanism
  17246.      during authentication. (Once an account has a long password hash in
  17247.      the user table, only 4.1 clients can authenticate for it, because
  17248.      pre-4.1 clients do not understand long hashes.)
  17249.  
  17250.  
  17251. This scenario illustrates that it is dangerous to run a 4.1 server
  17252. without using the `--old-passwords' option if you must support older
  17253. pre-4.1 clients. By running the server with `--old-passwords',
  17254. password-changing operations will not generate long password hashes and
  17255. thus do not cause accounts to become inaccessible to older clients.
  17256. (Those clients cannot inadvertently lock themselves out by changing
  17257. their password and ending up with a long password hash.)
  17258.  
  17259. The downside of the `--old-passwords' option is that any passwords you
  17260. create or change will use short hashes, even for 4.1 clients. Thus, you
  17261. lose the additional security provided by long password hashes. If you
  17262. want to create an account that has a long hash (for example, for use by
  17263. 4.1 clients), you must do so while running the server without
  17264. `--old-passwords'.
  17265.  
  17266. The following scenarios are possible for running a 4.1 server:
  17267.  
  17268. Scenario 1) Narrow `Password' column in user table
  17269.  
  17270.    * Only short hashes can be stored in the `Password' column.
  17271.  
  17272.    * The server uses only short hashes during client authentication.
  17273.  
  17274.    * For connected clients, password hash-generating operations
  17275.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  17276.      exclusively.  Any change to an account's password results in that
  17277.      account having a short password hash.
  17278.  
  17279.    * The `--old-passwords' option can be used but is superfluous because
  17280.      with a narrow `Password' column, the server will be generating
  17281.      short password hashes anyway.
  17282.  
  17283.  
  17284. Scenario 2) Long `Password' column; server not started with
  17285. `--old-passwords' option
  17286.  
  17287.    * Short or long hashes can be stored in the `Password' column.
  17288.  
  17289.    * 4.1 clients can authenticate for accounts that have short or long
  17290.      hashes.
  17291.  
  17292.    * Pre-4.1 clients can authenticate only for accounts that have short
  17293.      hashes.
  17294.  
  17295.    * For connected clients, password hash-generating operations
  17296.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use long hashes
  17297.      exclusively.  Any change to an account's password results in that
  17298.      account having a long password hash.
  17299.  
  17300.    * `OLD_PASSWORD()' may be used to explicitly generate a short hash.
  17301.      For example, to assign an account a short password, use `UPDATE'
  17302.      as follows:
  17303.  
  17304.           mysql> UPDATE user SET Password = OLD_PASSWORD('mypass')
  17305.               -> WHERE Host = 'some_host' AND User = 'some_user';
  17306.           mysql> FLUSH PRIVILEGES;
  17307.  
  17308.  
  17309. As indicated earlier, a danger in this scenario is that it is possible
  17310. for accounts that have a short password hash to become inaccessible to
  17311. pre-4.1 clients. Any change to such an account's password made via
  17312. `GRANT', `SET PASSWORD', or `PASSWORD()' results in the account being
  17313. given a long password hash, and from that point on, no pre-4.1 client
  17314. can authenticate to that account until the client upgrades to 4.1.
  17315.  
  17316. Scenario 3) Long `Password' column; server started with
  17317. `--old-passwords' option
  17318.  
  17319.    * Short or long hashes can be stored in the `Password' column.
  17320.  
  17321.    * 4.1 clients can authenticate for accounts that have short or long
  17322.      hashes (but note that it is possible to create long hashes only
  17323.      when the server is started without `--old-passwords').
  17324.  
  17325.    * Pre-4.1 clients can authenticate only for accounts that have short
  17326.      hashes.
  17327.  
  17328.    * For connected clients, password hash-generating operations
  17329.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  17330.      exclusively.  Any change to an account's password results in that
  17331.      account having a short password hash.
  17332.  
  17333.  
  17334. In this scenario, you cannot create accounts that have long password
  17335. hashes, because `--old-passwords' prevents generation of long hashes.
  17336. Also, if you create an account with a long hash before using the
  17337. `--old-passwords' option, changing the account's password while
  17338. `--old-passwords' is in effect results in the account being given a
  17339. short password, causing it to lose the security benefits of a longer
  17340. hash.
  17341.  
  17342. The disadvantages for these scenarios may be summarized as follows:
  17343.  
  17344. Scenario 1) You cannot take advantage of longer hashes that provide more
  17345. secure authentication.
  17346.  
  17347. Scenario 2) Accounts with short hashes become inaccessible to pre-4.1
  17348. clients if you change their passwords without explicitly using
  17349. `OLD_PASSWORD()'.
  17350.  
  17351. Scenario 3) `--old-passwords' prevents accounts with short hashes from
  17352. becoming inaccessible, but password-changing operations cause accounts
  17353. with long hashes to revert to short hashes, and you cannot change them
  17354. back to long hashes while `--old-passwords' is in effect.
  17355.  
  17356. Implications of Password Hashing Changes for Application Programs
  17357. -----------------------------------------------------------------
  17358.  
  17359. An upgrade to MySQL 4.1 can cause a compatibility issue for
  17360. applications that use `PASSWORD()' to generate passwords for their own
  17361. purposes. (Applications really should not do this, because `PASSWORD()'
  17362. should be used only to manage passwords for MySQL accounts. But some
  17363. applications use `PASSWORD()' for their own purposes anyway.)  If you
  17364. upgrade to 4.1 and run the server under conditions where it generates
  17365. long password hashes, an application that uses `PASSWORD()' for its own
  17366. passwords will break.  The recommended course of action is to modify
  17367. the application to use another function such as `SHA1()' or `MD5()' to
  17368. produce hashed values.  If that is not possible, you can use the
  17369. `OLD_PASSWORD()' function, which is provided to generate short hashes
  17370. in the old format. (But note that `OLD_PASSWORD()' may one day no
  17371. longer be supported.)
  17372.  
  17373. If the server is running under circumstances where it generates short
  17374. hashes, `OLD_PASSWORD()' is available but is equivalent to `PASSWORD()'.
  17375.  
  17376. Password hashing in MySQL 4.1.0 differs from hashing in 4.1.1 and up.
  17377. The 4.1.0 differences are:
  17378.  
  17379.    * Password hashes are 45 bytes long rather than 41 bytes.
  17380.  
  17381.    * The `PASSWORD()' function is non-repeatable.  That is, with a given
  17382.      argument `X', successive calls to `PASSWORD(X)' generate different
  17383.      results.
  17384.  
  17385.  
  17386. Causes of `Access denied' Errors
  17387. --------------------------------
  17388.  
  17389. If you encounter `Access denied' errors when you try to connect to the
  17390. MySQL server, the following list indicates some courses of action you
  17391. can take to correct the problem:
  17392.  
  17393.    * After installing MySQL, did you run the `mysql_install_db' script
  17394.      to set up the initial grant table contents?  If not, do so.  *Note
  17395.      Default privileges::.  Test the initial privileges by executing
  17396.      this command:
  17397.  
  17398.           shell> mysql -u root test
  17399.  
  17400.      The server should let you connect without error.  You should also
  17401.      make sure you have a file `user.MYD' in the MySQL database
  17402.      directory.  Ordinarily, this is `PATH/var/mysql/user.MYD', where
  17403.      `PATH' is the pathname to the MySQL installation root.
  17404.  
  17405.    * After a fresh installation, you should connect to the server and
  17406.      set up your users and their access permissions:
  17407.  
  17408.           shell> mysql -u root mysql
  17409.  
  17410.      The server should let you connect because the MySQL `root' user
  17411.      has no password initially.  That is also a security risk, so
  17412.      setting the `root' password is something you should do while
  17413.      you're setting up your other MySQL users.
  17414.  
  17415.      If you try to connect as `root' and get this error:
  17416.  
  17417.           Access denied for user: '@unknown' to database mysql
  17418.  
  17419.      this means that you don't have an entry in the `user' table with a
  17420.      `User' column value of `'root'' and that `mysqld' cannot resolve
  17421.      the hostname for your client.  In this case, you must restart the
  17422.      server with the `--skip-grant-tables' option and edit your
  17423.      `/etc/hosts' or `\windows\hosts' file to add an entry for your
  17424.      host.
  17425.  
  17426.    * If you get an error like the following:
  17427.  
  17428.           shell> mysqladmin -u root -pxxxx ver
  17429.           Access denied for user: 'root@localhost' (Using password: YES)
  17430.  
  17431.      It means that you are using an incorrect password. *Note
  17432.      Passwords::.
  17433.  
  17434.      If you have forgot the root password, you can restart `mysqld' with
  17435.      `--skip-grant-tables' to change the password.  *Note Resetting
  17436.      permissions::.
  17437.  
  17438.      If you get the above error even if you haven't specified a
  17439.      password, this means that you have an incorrect password in some
  17440.      `my.ini' file. *Note Option files::.  You can avoid using option
  17441.      files with the `--no-defaults' option, as follows:
  17442.  
  17443.           shell> mysqladmin --no-defaults -u root ver
  17444.  
  17445.    * If you updated an existing MySQL installation from a version
  17446.      earlier than Version 3.22.11 to Version 3.22.11 or later, did you
  17447.      run the `mysql_fix_privilege_tables' script?  If not, do so.  The
  17448.      structure of the grant tables changed with MySQL Version 3.22.11
  17449.      when the `GRANT' statement became functional.  *Note
  17450.      Upgrading-grant-tables::.
  17451.  
  17452.    * If your privileges seem to have changed in the middle of a
  17453.      session, it may be that a superuser has changed them.  Reloading
  17454.      the grant tables affects new client connections, but it also
  17455.      affects existing connections as indicated in *Note Privilege
  17456.      changes::.
  17457.  
  17458.    * If you can't get your password to work, remember that you must use
  17459.      the `PASSWORD()' function if you set the password with the
  17460.      `INSERT', `UPDATE', or `SET PASSWORD' statements.  The
  17461.      `PASSWORD()' function is unnecessary if you specify the password
  17462.      using the `GRANT ... IDENTIFIED BY' statement or the `mysqladmin
  17463.      password' command.  *Note Passwords::.
  17464.  
  17465.    * `localhost' is a synonym for your local hostname, and is also the
  17466.      default host to which clients try to connect if you specify no host
  17467.      explicitly.  However, connections to `localhost' do not work if
  17468.      you are using a MySQL version prior to 3.23.27 that uses
  17469.      MIT-pthreads (`localhost' connections are made using Unix socket
  17470.      files, which were not supported by MIT-pthreads at that time).  To
  17471.      avoid this problem on such systems, you should use the `--host'
  17472.      option to name the server host explicitly.  This will make a
  17473.      TCP/IP connection to the `mysqld' server.  In this case, you must
  17474.      have your real hostname in `user' table entries on the server
  17475.      host.  (This is true even if you are running a client program on
  17476.      the same host as the server.)
  17477.  
  17478.    * If you get an `Access denied' error when trying to connect to the
  17479.      database with `mysql -u user_name db_name', you may have a problem
  17480.      with the `user' table. Check this by executing `mysql -u root
  17481.      mysql' and issuing this SQL statement:
  17482.  
  17483.           mysql> SELECT * FROM user;
  17484.  
  17485.      The result should include an entry with the `Host' and `User'
  17486.      columns matching your computer's hostname and your MySQL username.
  17487.  
  17488.    * The `Access denied' error message will tell you who you are trying
  17489.      to log in as, the host from which you are trying to connect, and
  17490.      whether or not you were using a password. Normally, you should
  17491.      have one entry in the `user' table that exactly matches the
  17492.      hostname and username that were given in the error message. For
  17493.      example if you get an error message that contains `Using password:
  17494.      NO', this means that you tried to log in without an password.
  17495.  
  17496.    * If you get the following error when you try to connect from a
  17497.      different host than the one on which the MySQL server is running,
  17498.      then there is no row in the `user' table that matches that host:
  17499.  
  17500.           Host ... is not allowed to connect to this MySQL server
  17501.  
  17502.      You can fix this by using the command-line tool `mysql' (on the
  17503.      server host!) to add a row to the `user', `db', or `host' table
  17504.      for the user/hostname combination from which you are trying to
  17505.      connect and then execute `mysqladmin flush-privileges'.  If you are
  17506.      not running MySQL Version 3.22 and you don't know the IP number or
  17507.      hostname of the machine from which you are connecting, you should
  17508.      put an entry with `'%'' as the `Host' column value in the `user'
  17509.      table and restart `mysqld' with the `--log' option on the server
  17510.      machine.  After trying to connect from the client machine, the
  17511.      information in the MySQL log will indicate how you really did
  17512.      connect.  (Then replace the `'%'' in the `user' table entry with
  17513.      the actual hostname that shows up in the log.  Otherwise, you'll
  17514.      have a system that is insecure.)
  17515.  
  17516.      Another reason for this error on Linux is that you are using a
  17517.      binary MySQL version that is compiled with a different glibc
  17518.      version than the one you are using.  In this case you should
  17519.      either upgrade your OS/glibc or download the source MySQL version
  17520.      and compile this yourself.  A source RPM is normally trivial to
  17521.      compile and install, so this isn't a big problem.
  17522.  
  17523.    * If you get an error message where the hostname is not shown or
  17524.      where the hostname is an IP, even if you try to connect with a
  17525.      hostname:
  17526.  
  17527.           shell> mysqladmin -u root -pxxxx -h some-hostname ver
  17528.           Access denied for user: 'root@' (Using password: YES)
  17529.  
  17530.      This means that MySQL got some error when trying to resolve the IP
  17531.      to a hostname.  In this case you can execute `mysqladmin
  17532.      flush-hosts' to reset the internal DNS cache. *Note DNS::.
  17533.  
  17534.      Some permanent solutions are:
  17535.  
  17536.         - Try to find out what is wrong with your DNS server and fix
  17537.           this.
  17538.  
  17539.         - Specify IPs instead of hostnames in the MySQL privilege
  17540.           tables.
  17541.  
  17542.         - Start `mysqld' with `--skip-name-resolve'.
  17543.  
  17544.         - Start `mysqld' with `--skip-host-cache'.
  17545.  
  17546.         - Connect to `localhost' if you are running the server and the
  17547.           client on the same machine.
  17548.  
  17549.         - Put the client machine names in `/etc/hosts'.
  17550.  
  17551.    * If `mysql -u root test' works but `mysql -h your_hostname -u root
  17552.      test' results in `Access denied', then you may not have the
  17553.      correct name for your host in the `user' table.  A common problem
  17554.      here is that the `Host' value in the user table entry specifies an
  17555.      unqualified hostname, but your system's name resolution routines
  17556.      return a fully qualified domain name (or vice-versa).  For
  17557.      example, if you have an entry with host `'tcx'' in the `user'
  17558.      table, but your DNS tells MySQL that your hostname is
  17559.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  17560.      the `user' table that contains the IP number of your host as the
  17561.      `Host' column value.  (Alternatively, you could add an entry to the
  17562.      `user' table with a `Host' value that contains a wildcard--for
  17563.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  17564.      *insecure* and is *not* recommended!)
  17565.  
  17566.    * If `mysql -u user_name test' works but `mysql -u user_name
  17567.      other_db_name' doesn't work, you don't have an entry for
  17568.      `other_db_name' listed in the `db' table.
  17569.  
  17570.    * If `mysql -u user_name db_name' works when executed on the server
  17571.      machine, but `mysql -h host_name -u user_name db_name' doesn't
  17572.      work when executed on another client machine, you don't have the
  17573.      client machine listed in the `user' table or the `db' table.
  17574.  
  17575.    * If you can't figure out why you get `Access denied', remove from
  17576.      the `user' table all entries that have `Host' values containing
  17577.      wildcards (entries that contain `%' or `_').  A very common error
  17578.      is to insert a new entry with `Host'=`'%'' and `User'=`'some
  17579.      user'', thinking that this will allow you to specify `localhost'
  17580.      to connect from the same machine.  The reason that this doesn't
  17581.      work is that the default privileges include an entry with
  17582.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  17583.      `Host' value `'localhost'' that is more specific than `'%'', it is
  17584.      used in preference to the new entry when connecting from
  17585.      `localhost'!  The correct procedure is to insert a second entry
  17586.      with `Host'=`'localhost'' and `User'=`'some_user'', or to remove
  17587.      the entry with `Host'=`'localhost'' and `User'=`'''.
  17588.  
  17589.    * If you get the following error, you may have a problem with the
  17590.      `db' or `host' table:
  17591.  
  17592.           Access to database denied
  17593.  
  17594.      If the entry selected from the `db' table has an empty value in the
  17595.      `Host' column, make sure there are one or more corresponding
  17596.      entries in the `host' table specifying which hosts the `db' table
  17597.      entry applies to.
  17598.  
  17599.      If you get the error when using the SQL commands `SELECT ...  INTO
  17600.      OUTFILE' or `LOAD DATA INFILE', your entry in the `user' table
  17601.      probably doesn't have the `FILE' privilege enabled.
  17602.  
  17603.    * Remember that client programs will use connection parameters
  17604.      specified in configuration files or environment variables.  *Note
  17605.      Environment variables::.  If a client seems to be sending the
  17606.      wrong default connection parameters when you don't specify them on
  17607.      the command-line, check your environment and the `.my.cnf' file in
  17608.      your home directory.  You might also check the system-wide MySQL
  17609.      configuration files, though it is far less likely that client
  17610.      connection parameters will be specified there. If you get `Access
  17611.      denied' when you run a client without any options, make sure you
  17612.      haven't specified an old password in any of your option files!
  17613.      *Note Option files::.
  17614.  
  17615.    * If you make changes to the grant tables directly (using an
  17616.      `INSERT' or `UPDATE' statement) and your changes seem to be
  17617.      ignored, remember that you must issue a `FLUSH PRIVILEGES'
  17618.      statement or execute a `mysqladmin flush-privileges' command to
  17619.      cause the server to re-read the privilege tables. Otherwise, your
  17620.      changes have no effect until the next time the server is
  17621.      restarted.  Remember that after you set the `root' password with
  17622.      an `UPDATE' command, you won't need to specify it until after you
  17623.      flush the privileges, because the server won't know you've changed
  17624.      the password yet!
  17625.  
  17626.    * If you have access problems with a Perl, PHP, Python, or ODBC
  17627.      program, try to connect to the server with `mysql -u user_name
  17628.      db_name' or `mysql -u user_name -pyour_pass db_name'.  If you are
  17629.      able to connect using the `mysql' client, there is a problem with
  17630.      your program and not with the access privileges.  (Note that there
  17631.      is no space between `-p' and the password; you can also use the
  17632.      `--password=your_pass' syntax to specify the password. If you use
  17633.      the `-p' option alone, MySQL will prompt you for the password.)
  17634.  
  17635.    * For testing, start the `mysqld' daemon with the
  17636.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  17637.      tables and use the `mysqlaccess' script to check whether your
  17638.      modifications have the desired effect.  When you are satisfied
  17639.      with your changes, execute `mysqladmin flush-privileges' to tell
  17640.      the `mysqld' server to start using the new grant tables.  *Note:*
  17641.      Reloading the grant tables overrides the `--skip-grant-tables'
  17642.      option.  This allows you to tell the server to begin using the
  17643.      grant tables again without bringing it down and restarting it.
  17644.  
  17645.    * If everything else fails, start the `mysqld' daemon with a
  17646.      debugging option (for example, `--debug=d,general,query'). This
  17647.      will print host and user information about attempted connections,
  17648.      as well as information about each command issued. *Note Making
  17649.      trace files::.
  17650.  
  17651.    * If you have any other problems with the MySQL grant tables and
  17652.      feel you must post the problem to the mailing list, always provide
  17653.      a dump of the MySQL grant tables. You can dump the tables with the
  17654.      `mysqldump mysql' command. As always, post your problem using the
  17655.      `mysqlbug' script.  *Note Bug reports::.  In some cases you may
  17656.      need to restart `mysqld' with `--skip-grant-tables' to run
  17657.      `mysqldump'.
  17658.  
  17659. MySQL User Account Management
  17660. =============================
  17661.  
  17662. MySQL Usernames and Passwords
  17663. -----------------------------
  17664.  
  17665. There are several distinctions between the way usernames and passwords
  17666. are used by MySQL and the way they are used by Unix or Windows:
  17667.  
  17668.    * Usernames, as used by MySQL for authentication purposes, have
  17669.      nothing to do with Unix usernames (login names) or Windows
  17670.      usernames.  Most MySQL clients by default try to log in using the
  17671.      current Unix user name as the MySQL username, but that is for
  17672.      convenience only.  Client programs allow a different name to be
  17673.      specified with the `-u' or `--user' options. This means that you
  17674.      can't make a database secure in any way unless all MySQL usernames
  17675.      have passwords.  Anyone may attempt to connect to the server using
  17676.      any name, and they will succeed if they specify any name that
  17677.      doesn't have a password.
  17678.  
  17679.    * MySQL usernames can be up to 16 characters long; Unix usernames
  17680.      typically are limited to 8 characters.
  17681.  
  17682.    * MySQL passwords have nothing to do with Unix passwords.  There is
  17683.      no necessary connection between the password you use to log in to
  17684.      a Unix machine and the password you use to access a database on
  17685.      that machine.
  17686.  
  17687.    * MySQL encrypts passwords using a different algorithm than the one
  17688.      used during the Unix login process.  See the descriptions of the
  17689.      `PASSWORD()' and `ENCRYPT()' functions in *Note Encryption
  17690.      functions::.  Note that even if the password is stored
  17691.      'scrambled', and knowing your 'scrambled' password is enough to be
  17692.      able to connect to the MySQL server!  From version 4.1, MySQL
  17693.      employs a different password and login mechanism that is secure
  17694.      even if TCP/IP packets are sniffed and/or the mysql database is
  17695.      captured.
  17696.  
  17697. MySQL users and their privileges are normally created with the `GRANT'
  17698. command. *Note GRANT::.
  17699.  
  17700. When you login to a MySQL server with a command-line client you should
  17701. specify the password with `--password=your-password'.  *Note
  17702. Connecting::.
  17703.  
  17704.      mysql --user=monty --password=guess database_name
  17705.  
  17706. If you want the client to prompt for a password, you should use
  17707. `--password' without any argument
  17708.  
  17709.      mysql --user=monty --password database_name
  17710.  
  17711. or the short form:
  17712.  
  17713.      mysql -u monty -p database_name
  17714.  
  17715. Note that in the last example the password is *not* 'database_name'.
  17716.  
  17717. If you want to use the `-p' option to supply a password you should do so
  17718. like this:
  17719.  
  17720.      mysql -u monty -pguess database_name
  17721.  
  17722. On some systems, the library call that MySQL uses to prompt for a
  17723. password will automatically cut the password to 8 characters. Internally
  17724. MySQL doesn't have any limit for the length of the password.
  17725.  
  17726. When Privilege Changes Take Effect
  17727. ----------------------------------
  17728.  
  17729. When `mysqld' starts, all grant table contents are read into memory and
  17730. become effective at that point.
  17731.  
  17732. Modifications to the grant tables that you perform using `GRANT',
  17733. `REVOKE', or `SET PASSWORD' are noticed by the server immediately.
  17734.  
  17735. If you modify the grant tables manually (using `INSERT', `UPDATE',
  17736. etc.), you should execute a `FLUSH PRIVILEGES' statement or run
  17737. `mysqladmin flush-privileges' or `mysqladmin reload' to tell the server
  17738. to reload the grant tables. Otherwise, your changes will have _no
  17739. effect_ until you restart the server. If you change the grant tables
  17740. manually but forget to reload the privileges, you will be wondering why
  17741. your changes don't seem to make any difference!
  17742.  
  17743. When the server notices that the grant tables have been changed,
  17744. existing client connections are affected as follows:
  17745.  
  17746.    * Table and column privilege changes take effect with the client's
  17747.      next request.
  17748.  
  17749.    * Database privilege changes take effect at the next `USE db_name'
  17750.      command.
  17751.  
  17752.    * Global privilege changes and password changes take effect the next
  17753.      time the client connects.
  17754.  
  17755. Setting Up the Initial MySQL Privileges
  17756. ---------------------------------------
  17757.  
  17758. After installing MySQL, you set up the initial access privileges by
  17759. running `scripts/mysql_install_db'.  *Note Quick install::.  The
  17760. `mysql_install_db' script starts the `mysqld' server, then initializes
  17761. the grant tables to contain the following set of privileges:
  17762.  
  17763.    * The MySQL `root' user is created as a superuser who can do
  17764.      anything.  Connections must be made from the local host.
  17765.  
  17766.      *Note:* The initial `root' password is empty, so anyone can
  17767.      connect as `root' _without a password_ and be granted all
  17768.      privileges.
  17769.  
  17770.    * An anonymous user is created that can do anything with databases
  17771.      that have a name of `'test'' or starting with `'test_''.
  17772.      Connections must be made from the local host.  This means any
  17773.      local user can connect without a password and be treated as the
  17774.      anonymous user.
  17775.  
  17776.    * Other privileges are denied.  For example, normal users can't use
  17777.      `mysqladmin shutdown' or `mysqladmin processlist'.
  17778.  
  17779. *Note:* The default privileges are different for Windows.  *Note
  17780. Windows running::.
  17781.  
  17782. Because your installation is initially wide open, one of the first
  17783. things you should do is specify a password for the MySQL `root' user.
  17784. You can do this as follows (note that you specify the password using
  17785. the `PASSWORD()' function):
  17786.  
  17787.      shell> mysql -u root mysql
  17788.      mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
  17789.  
  17790. Replace `'new_password'' with the password that you want to use.
  17791.  
  17792. If you know what you are doing, you can also directly manipulate the
  17793. privilege tables:
  17794.  
  17795.      shell> mysql -u root mysql
  17796.      mysql> UPDATE user SET Password=PASSWORD('new_password')
  17797.          ->     WHERE user='root';
  17798.      mysql> FLUSH PRIVILEGES;
  17799.  
  17800. Another way to set the password is by using the `mysqladmin' command:
  17801.  
  17802.      shell> mysqladmin -u root password new_password
  17803.  
  17804. Only users with write/update access to the `mysql' database can change
  17805. the password for other users.  All normal users (not anonymous ones)
  17806. can only change their own password with either of the above commands or
  17807. with `SET PASSWORD=PASSWORD('new_password')'.
  17808.  
  17809. Note that if you update the password in the `user' table directly using
  17810. `UPDATE', you must tell the server to re-read the grant tables (with
  17811. `FLUSH PRIVILEGES'), because the change will go unnoticed otherwise.
  17812.  
  17813. Once the `root' password has been set, thereafter you must supply that
  17814. password when you connect to the server as `root'.
  17815.  
  17816. You may wish to leave the `root' password blank so that you don't need
  17817. to specify it while you perform additional setup or testing. However,
  17818. be sure to set it before using your installation for any real
  17819. production work.
  17820.  
  17821. See the `scripts/mysql_install_db' script to see how it sets up the
  17822. default privileges.  You can use this as a basis to see how to add
  17823. other users.
  17824.  
  17825. If you want the initial privileges to be different from those just
  17826. described above, you can modify `mysql_install_db' before you run it.
  17827.  
  17828. To re-create the grant tables completely, remove all the `.frm',
  17829. `.MYI', and `.MYD' files in the directory containing the `mysql'
  17830. database.  (This is the directory named `mysql' under the database
  17831. directory, which is listed when you run `mysqld --help'.) Then run the
  17832. `mysql_install_db' script, possibly after editing it first to have the
  17833. privileges you want.
  17834.  
  17835. *Note:* For MySQL versions older than Version 3.22.10, you should not
  17836. delete the `.frm' files.  If you accidentally do this, you should copy
  17837. them back from your MySQL distribution before running
  17838. `mysql_install_db'.
  17839.  
  17840. Adding New Users to MySQL
  17841. -------------------------
  17842.  
  17843. You can add users two different ways: by using `GRANT' statements or by
  17844. manipulating the MySQL grant tables directly.  The preferred method is
  17845. to use `GRANT' statements, because they are more concise and less
  17846. error-prone. *Note GRANT::.
  17847.  
  17848. There are also several contributed programs (such as `phpMyAdmin') that
  17849. can be used to create and administer users.
  17850.  
  17851. The following examples show how to use the `mysql' client to set up new
  17852. users.  These examples assume that privileges are set up according to
  17853. the defaults described in the previous section.  This means that to
  17854. make changes, you must be on the same machine where `mysqld' is
  17855. running, you must connect as the MySQL `root' user, and the `root' user
  17856. must have the `INSERT' privilege for the `mysql' database and the
  17857. `RELOAD' administrative privilege.  Also, if you have changed the
  17858. `root' user password, you must specify it for the `mysql' commands here.
  17859.  
  17860. First, use the `mysql' program to connect to the server as the MySQL
  17861. `root' user:
  17862.  
  17863.      shell> mysql --user=root mysql
  17864.  
  17865. Then you can add new users by issuing `GRANT' statements:
  17866.  
  17867.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
  17868.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  17869.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@'%'
  17870.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  17871.      mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
  17872.      mysql> GRANT USAGE ON *.* TO dummy@localhost;
  17873.  
  17874. These `GRANT' statements set up three new users:
  17875.  
  17876. `monty'
  17877.      A full superuser who can connect to the server from anywhere, but
  17878.      who must use a password `'some_pass'' to do so.  Note that we must
  17879.      issue `GRANT' statements for both `monty@localhost' and
  17880.      `monty@"%"'.  If we don't add the entry with `localhost', the
  17881.      anonymous user entry for `localhost' that is created by
  17882.      `mysql_install_db' takes precedence when we connect from the local
  17883.      host, because it has a more specific `Host' column value and thus
  17884.      comes earlier in the `user' table sort order.
  17885.  
  17886. `admin'
  17887.      A user who can connect from `localhost' without a password and who
  17888.      is granted the `RELOAD' and `PROCESS' administrative privileges.
  17889.      This allows the user to execute the `mysqladmin reload',
  17890.      `mysqladmin refresh', and `mysqladmin flush-*' commands, as well as
  17891.      `mysqladmin processlist' .  No database-level privileges are
  17892.      granted.  (They can be granted later by issuing additional `GRANT'
  17893.      statements.)
  17894.  
  17895. `dummy'
  17896.      A user who can connect without a password, but only from the local
  17897.      host.  No privileges are granted--the `USAGE' privilege type
  17898.      allows you to create a user with no privileges. It has the effect
  17899.      of setting all the global privileges to `'N''.  It is assumed that
  17900.      you will grant specific privileges to the account later.
  17901.  
  17902. You can also add the same user access information directly by issuing
  17903. `INSERT' statements and then telling the server to reload the grant
  17904. tables:
  17905.  
  17906.      shell> mysql --user=root mysql
  17907.      mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
  17908.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  17909.      mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
  17910.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  17911.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  17912.          ->           Reload_priv='Y', Process_priv='Y';
  17913.      mysql> INSERT INTO user (Host,User,Password)
  17914.          ->                  VALUES('localhost','dummy','');
  17915.      mysql> FLUSH PRIVILEGES;
  17916.  
  17917. Depending on your MySQL version, you may have to use a different number
  17918. of `'Y'' values above. (Versions prior to Version 3.22.11 have fewer
  17919. privilege columns, and versions from 4.0.2 on have more.)  For the
  17920. `admin' user, the more readable extended `INSERT' syntax using `SET'
  17921. that is available starting with Version 3.22.11 is used.
  17922.  
  17923. Note that to set up a superuser, you need only create a `user' table
  17924. entry with the privilege columns set to `'Y''.  No `db' or `host' table
  17925. entries are necessary.
  17926.  
  17927. In the last `INSERT' statement (for the `dummy' user), only the `Host',
  17928. `User', and `Password' columns in the `user' table record are assigned
  17929. values. None of the privilege columns are set explicitly, so MySQL
  17930. assigns them all the default value of `'N''.  This is the same thing
  17931. that `GRANT USAGE' does.
  17932.  
  17933. The following example adds a user `custom' who can access the
  17934. `bankaccount' database only from the local host, the `expenses'
  17935. database only from the host `whitehouse.gov', and the `customer'
  17936. database only from the host `server.domain'.  He wants to use the
  17937. password `obscure' from all three hosts.
  17938.  
  17939. To set up this user's privileges using `GRANT' statements, run these
  17940. commands:
  17941.  
  17942.      shell> mysql --user=root mysql
  17943.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  17944.          ->     ON bankaccount.*
  17945.          ->     TO custom@localhost
  17946.          ->     IDENTIFIED BY 'obscure';
  17947.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  17948.          ->     ON expenses.*
  17949.          ->     TO custom@'whitehouse.gov'
  17950.          ->     IDENTIFIED BY 'obscure';
  17951.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  17952.          ->     ON customer.*
  17953.          ->     TO custom@'server.domain'
  17954.          ->     IDENTIFIED BY 'obscure';
  17955.  
  17956. To set up the user's privileges by modifying the grant tables directly,
  17957. run these commands (note the `FLUSH PRIVILEGES' at the end):
  17958.  
  17959.      shell> mysql --user=root mysql
  17960.      mysql> INSERT INTO user (Host,User,Password)
  17961.          -> VALUES('localhost','custom',PASSWORD('obscure'));
  17962.      mysql> INSERT INTO user (Host,User,Password)
  17963.          -> VALUES('whitehouse.gov','custom',PASSWORD('obscure'));
  17964.      mysql> INSERT INTO user (Host,User,Password)
  17965.          -> VALUES('server.domain','custom',PASSWORD('obscure'));
  17966.      mysql> INSERT INTO db
  17967.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  17968.          ->  Create_priv,Drop_priv)
  17969.          -> VALUES
  17970.          -> ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
  17971.      mysql> INSERT INTO db
  17972.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  17973.          ->  Create_priv,Drop_priv)
  17974.          -> VALUES
  17975.          -> ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
  17976.      mysql> INSERT INTO db
  17977.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  17978.          ->  Create_priv,Drop_priv)
  17979.          -> VALUES('server.domain','customer','custom','Y','Y','Y','Y','Y','Y');
  17980.      mysql> FLUSH PRIVILEGES;
  17981.  
  17982. As in the preceding example that used `INSERT' statements, you may need
  17983. to use a different number of `'Y'' values, depending on your version of
  17984. MySQL.
  17985.  
  17986. The first three `INSERT' statements add `user' table entries that allow
  17987. user `custom' to connect from the various hosts with the given
  17988. password, but grant no permissions (all privileges are set to the
  17989. default value of `'N'').  The next three `INSERT' statements add `db'
  17990. table entries that grant privileges to `custom' for the `bankaccount',
  17991. `expenses', and `customer' databases, but only when accessed from the
  17992. proper hosts.  As usual, after you modify the grant tables directly ,
  17993. you must tell the server to reload them (with `FLUSH PRIVILEGES') so
  17994. that the privilege changes take effect.
  17995.  
  17996. If you want to give a specific user access from any machine in a given
  17997. domain (for example, `mydomain.com'), you can issue a `GRANT' statement
  17998. like the following:
  17999.  
  18000.      mysql> GRANT ...
  18001.          ->     ON *.*
  18002.          ->     TO myusername@'%.mydomain.com'
  18003.          ->     IDENTIFIED BY 'mypassword';
  18004.  
  18005. To do the same thing by modifying the grant tables directly, do this:
  18006.  
  18007.      mysql> INSERT INTO user VALUES ('%.mydomain.com', 'myusername',
  18008.          ->             PASSWORD('mypassword'),...);
  18009.      mysql> FLUSH PRIVILEGES;
  18010.  
  18011. Deleting Users from MySQL
  18012. -------------------------
  18013.  
  18014.      DROP USER user_name
  18015.  
  18016. This command was added to MySQL 4.1.1.
  18017.  
  18018. It deletes a user that doesn't have any privileges.
  18019.  
  18020. To delete a user from MySQL, you should use the following procedure,
  18021. performing the steps in the order shown:
  18022.  
  18023.   1. Check which privileges the user has with `SHOW PRIVILEGES'.  *Note
  18024.      SHOW PRIVILEGES::.
  18025.  
  18026.   2. Delete all privileges from the user with `REVOKE'. *Note GRANT::.
  18027.  
  18028.   3. Delete the user with `DROP USER'.
  18029.  
  18030. If you are using and older MySQL version you should first revoke the
  18031. privileges and then delete the user with:
  18032.  
  18033.      DELETE FROM mysql.user WHERE user='username' and host='hostname';
  18034.      FLUSH PRIVILEGES;
  18035.  
  18036. Limiting user resources
  18037. -----------------------
  18038.  
  18039. Starting from MySQL 4.0.2 one can limit certain resources per user.
  18040.  
  18041. So far, the only available method of limiting usage of MySQL server
  18042. resources has been setting the `max_user_connections' startup variable
  18043. to a non-zero value. But this method is strictly global and does not
  18044. allow for management of individual users, which could be of particular
  18045. interest to Internet Service Providers.
  18046.  
  18047. Therefore, management of three resources is introduced on the
  18048. individual user level:
  18049.  
  18050.    * Number of all queries per hour: All commands that could be run by
  18051.      a user.
  18052.  
  18053.    * Number of all updates per hour: Any command that changes any table
  18054.      or database.
  18055.  
  18056.    * Number of connections made per hour: New connections opened per
  18057.      hour.
  18058.  
  18059. A user in the aforementioned context is a single entry in the `user'
  18060. table, which is uniquely identified by its `user' and `host' columns.
  18061.  
  18062. All users are by default not limited in using the above resources,
  18063. unless the limits are granted to them. These limits can be granted
  18064. *only* via global `GRANT (*.*)', using this syntax:
  18065.  
  18066.      GRANT ... WITH MAX_QUERIES_PER_HOUR N1
  18067.                     MAX_UPDATES_PER_HOUR N2
  18068.                     MAX_CONNECTIONS_PER_HOUR N3;
  18069.  
  18070. One can specify any combination of the above resources.  `N1', `N2',
  18071. and `N3' are integers and represent counts per hour.
  18072.  
  18073. If a user reaches the limit on number of connections within one hour, no
  18074. further connections will be accepted until that hour is up. Similarly,
  18075. if the user reaches the limit on number of queries or updates, further
  18076. queries or updates will be rejected until the hour is up. In all cases,
  18077. an appropriate error message shall be issued.
  18078.  
  18079. Current usage values for a particular user can be flushed (set to zero)
  18080. by issuing a `GRANT' statement with any of the above clauses, including
  18081. a `GRANT' statement with the current values.
  18082.  
  18083. Also, current values for all users will be flushed if privileges are
  18084. reloaded (in the server or using `mysqladmin reload') or if the `FLUSH
  18085. USER_RESOURCES' command is issued.
  18086.  
  18087. The feature is enabled as soon as a single user is granted with any of
  18088. the limiting `GRANT' clauses.
  18089.  
  18090. As a prerequisite for enabling this feature, the `user' table in the
  18091. `mysql' database must contain the additional columns, as defined in the
  18092. table creation scripts `mysql_install_db' and `mysql_install_db.sh' in
  18093. `scripts' subdirectory.
  18094.  
  18095. Setting Up Passwords
  18096. --------------------
  18097.  
  18098. In most cases you should use `GRANT' to set up your users/passwords, so
  18099. the following only applies for advanced users. *Note `GRANT': GRANT.
  18100.  
  18101. The examples in the preceding sections illustrate an important
  18102. principle: when you store a non-empty password using `INSERT' or
  18103. `UPDATE' statements, you must use the `PASSWORD()' function to encrypt
  18104. it.  This is because the `user' table stores passwords in encrypted
  18105. form, not as plaintext.  If you forget that fact, you are likely to
  18106. attempt to set passwords like this:
  18107.  
  18108.      shell> mysql -u root mysql
  18109.      mysql> INSERT INTO user (Host,User,Password)
  18110.          -> VALUES('%','jeffrey','biscuit');
  18111.      mysql> FLUSH PRIVILEGES;
  18112.  
  18113. The result is that the plaintext value `'biscuit'' is stored as the
  18114. password in the `user' table.  When the user `jeffrey' attempts to
  18115. connect to the server using this password, the `mysql' client encrypts
  18116. it with `PASSWORD()', generates an authentication vector based on
  18117. *encrypted* password and a random number, obtained from server, and
  18118. sends the result to the server.  The server uses the `password' value
  18119. in the `user' table (that is *not encrypted* value `'biscuit'') to
  18120. perform the same calculations, and compares results.  The comparison
  18121. fails and the server rejects the connection:
  18122.  
  18123.      shell> mysql -u jeffrey -pbiscuit test
  18124.      Access denied
  18125.  
  18126. Passwords must be encrypted when they are inserted in the `user' table,
  18127. so the `INSERT' statement should have been specified like this instead:
  18128.  
  18129.      mysql> INSERT INTO user (Host,User,Password)
  18130.          -> VALUES('%','jeffrey',PASSWORD('biscuit'));
  18131.  
  18132. You must also use the `PASSWORD()' function when you use `SET PASSWORD'
  18133. statements:
  18134.  
  18135.      mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
  18136.  
  18137. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  18138. the `mysqladmin password' command, the `PASSWORD()' function is
  18139. unnecessary.  They both take care of encrypting the password for you,
  18140. so you would specify a password of `'biscuit'' like this:
  18141.  
  18142.      mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
  18143.  
  18144. or:
  18145.  
  18146.      shell> mysqladmin -u jeffrey password biscuit
  18147.  
  18148. *Note:* `PASSWORD()' is different from Unix password encryption.  *Note
  18149. User names::.
  18150.  
  18151. Keeping Your Password Secure
  18152. ----------------------------
  18153.  
  18154. It is inadvisable to specify your password in a way that exposes it to
  18155. discovery by other users.  The methods you can use to specify your
  18156. password when you run client programs are listed here, along with an
  18157. assessment of the risks of each method:
  18158.  
  18159.    * Never give a normal user access to the `mysql.user' table. Knowing
  18160.      the encrypted password for a user makes it possible to log in as
  18161.      this user.  The passwords are only scrambled so that one shouldn't
  18162.      be able to see the real password you used (if you happen to use a
  18163.      similar password with your other applications).
  18164.  
  18165.    * Use a `-pyour_pass' or `--password=your_pass' option on the command
  18166.      line.  This is convenient but insecure, because your password
  18167.      becomes visible to system status programs (such as `ps') that may
  18168.      be invoked by other users to display command-lines.  (MySQL
  18169.      clients typically overwrite the command-line argument with zeroes
  18170.      during their initialization sequence, but there is still a brief
  18171.      interval during which the value is visible.)
  18172.  
  18173.    * Use a `-p' or `--password' option (with no `your_pass' value
  18174.      specified).  In this case, the client program solicits the
  18175.      password from the terminal:
  18176.  
  18177.           shell> mysql -u user_name -p
  18178.           Enter password: ********
  18179.  
  18180.      The `*' characters represent your password.
  18181.  
  18182.      It is more secure to enter your password this way than to specify
  18183.      it on the command-line because it is not visible to other users.
  18184.      However, this method of entering a password is suitable only for
  18185.      programs that you run interactively.  If you want to invoke a
  18186.      client from a script that runs non-interactively, there is no
  18187.      opportunity to enter the password from the terminal. On some
  18188.      systems, you may even find that the first line of your script is
  18189.      read and interpreted (incorrectly) as your password!
  18190.  
  18191.    * Store your password in a configuration file.  For example, you can
  18192.      list your password in the `[client]' section of the `.my.cnf' file
  18193.      in your home directory:
  18194.  
  18195.           [client]
  18196.           password=your_pass
  18197.  
  18198.      If you store your password in `.my.cnf', the file should not be
  18199.      group or world-readable or -writable.  Make sure the file's access
  18200.      mode is `400' or `600'.
  18201.  
  18202.      *Note Option files::.
  18203.  
  18204.    * You can store your password in the `MYSQL_PWD' environment
  18205.      variable, but this method must be considered extremely insecure
  18206.      and should not be used.  Some versions of `ps' include an option
  18207.      to display the environment of running processes; your password
  18208.      will be in plain sight for all to see if you set `MYSQL_PWD'.
  18209.      Even on systems without such a version of `ps', it is unwise to
  18210.      assume there is no other method to observe process environments.
  18211.      *Note Environment variables::.
  18212.  
  18213. All in all, the safest methods are to have the client program prompt
  18214. for the password or to specify the password in a properly protected
  18215. `.my.cnf' file.
  18216.  
  18217. Using Secure Connections
  18218. ------------------------
  18219.  
  18220. This section describes how to set up secure connections between MySQL
  18221. clients and the server using the Secure Sockets Layer (SSL) protocol.
  18222. It also decribes a way to set up SSH on Windows.
  18223.  
  18224. Basics
  18225. ......
  18226.  
  18227. Beginning with version 4.0.0, MySQL has support for SSL encrypted
  18228. connections. To understand how MySQL uses SSL, it's necessary to
  18229. explain some basic SSL and X509 concepts. People who are already
  18230. familiar with them can skip this part.
  18231.  
  18232. By default, MySQL uses unencrypted connections between the client and
  18233. the server. This means that someone could watch all your traffic and
  18234. look at the data being sent or received.  They could even change the
  18235. data while it is in transit between client and server. Sometimes you
  18236. need to move information over public networks in a secure fashion; in
  18237. such cases, using an unencrypted connection is unacceptable.
  18238.  
  18239. SSL is a protocol that uses different encryption algorithms to ensure
  18240. that data received over a public network can be trusted. It has
  18241. mechanisms to detect any change, loss or replay of data. SSL also
  18242. incorporates algorithms to recognize and provide identity verification
  18243. using the X509 standard.
  18244.  
  18245. Encryption is the way to make any kind of data unreadable. In fact,
  18246. today's practice requires many additional security elements from
  18247. encryption algorithms.  They should resist many kind of known attacks
  18248. like just messing with the order of encrypted messages or replaying data
  18249. twice.
  18250.  
  18251. X509 is a standard that makes it possible to identify someone on the
  18252. Internet.  It is most commonly used in e-commerce applications. In basic
  18253. terms, there should be some company (called a "Certificate Authority")
  18254. that assigns electronic certificates to anyone who needs them.
  18255. Certificates rely on asymmetric encryption algorithms that have two
  18256. encryption keys (a public key and a secret key). A certificate owner
  18257. can prove his identity by showing his certificate to other party. A
  18258. certificate consists of its owner's public key. Any data encrypted with
  18259. this public key can be decrypted only using the corresponding secret
  18260. key, which is held by the owner of the certificate.
  18261.  
  18262. MySQL doesn't use encrypted connections by default, because doing so
  18263. would make the client/server protocol much slower. Any kind of
  18264. additional functionality requires the computer to do additional work and
  18265. encrypting data is a CPU-intensive operation that requires time and can
  18266. delay MySQL main tasks. By default MySQL is tuned to be fast as
  18267. possible.
  18268.  
  18269. If you need more information about SSL, X509, or encryption, you should
  18270. use your favorite Internet search engine and search for keywords in
  18271. which you are interested.
  18272.  
  18273. Requirements
  18274. ............
  18275.  
  18276. To get secure connections to work with MySQL you must do the following:
  18277.  
  18278.   1. Install the OpenSSL library. We have tested MySQL with OpenSSL
  18279.      0.9.6.  `http://www.openssl.org/'.
  18280.  
  18281.   2. Configure MySQL with `--with-vio --with-openssl'.
  18282.  
  18283.   3. If you are using an old MySQL installation, you have to update your
  18284.      `mysql.user' table with some new SSL-related columns.  This is
  18285.      necessary if your grant tables date from a version prior to MySQL
  18286.      4.0.0.  The procedure is described in *Note
  18287.      Upgrading-grant-tables::.
  18288.  
  18289.   4. You can check if a running `mysqld' server supports OpenSSL by
  18290.      examining if `SHOW VARIABLES LIKE 'have_openssl'' returns `YES'.
  18291.  
  18292. Setting Up SSL Certificates for MySQL
  18293. .....................................
  18294.  
  18295. Here is an example for setting up SSL certificates for MySQL:
  18296.  
  18297.      DIR=`pwd`/openssl
  18298.      PRIV=$DIR/private
  18299.      
  18300.      mkdir $DIR $PRIV $DIR/newcerts
  18301.      cp /usr/share/ssl/openssl.cnf $DIR
  18302.      replace ./demoCA $DIR -- $DIR/openssl.cnf
  18303.      
  18304.      # Create necessary files: $database, $serial and $new_certs_dir
  18305.      # directory (optional)
  18306.      
  18307.      touch $DIR/index.txt
  18308.      echo "01" > $DIR/serial
  18309.      
  18310.      #
  18311.      # Generation of Certificate Authority(CA)
  18312.      #
  18313.      
  18314.      openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem \
  18315.          -config $DIR/openssl.cnf
  18316.      
  18317.      # Sample output:
  18318.      # Using configuration from /home/monty/openssl/openssl.cnf
  18319.      # Generating a 1024 bit RSA private key
  18320.      # ................++++++
  18321.      # .........++++++
  18322.      # writing new private key to '/home/monty/openssl/private/cakey.pem'
  18323.      # Enter PEM pass phrase:
  18324.      # Verifying password - Enter PEM pass phrase:
  18325.      # -----
  18326.      # You are about to be asked to enter information that will be incorporated
  18327.      # into your certificate request.
  18328.      # What you are about to enter is what is called a Distinguished Name or a DN.
  18329.      # There are quite a few fields but you can leave some blank
  18330.      # For some fields there will be a default value,
  18331.      # If you enter '.', the field will be left blank.
  18332.      # -----
  18333.      # Country Name (2 letter code) [AU]:FI
  18334.      # State or Province Name (full name) [Some-State]:.
  18335.      # Locality Name (eg, city) []:
  18336.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  18337.      # Organizational Unit Name (eg, section) []:
  18338.      # Common Name (eg, YOUR name) []:MySQL admin
  18339.      # Email Address []:
  18340.      
  18341.      #
  18342.      # Create server request and key
  18343.      #
  18344.      openssl req -new -keyout $DIR/server-key.pem -out \
  18345.          $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
  18346.      
  18347.      # Sample output:
  18348.      # Using configuration from /home/monty/openssl/openssl.cnf
  18349.      # Generating a 1024 bit RSA private key
  18350.      # ..++++++
  18351.      # ..........++++++
  18352.      # writing new private key to '/home/monty/openssl/server-key.pem'
  18353.      # Enter PEM pass phrase:
  18354.      # Verifying password - Enter PEM pass phrase:
  18355.      # -----
  18356.      # You are about to be asked to enter information that will be incorporated
  18357.      # into your certificate request.
  18358.      # What you are about to enter is what is called a Distinguished Name or a DN.
  18359.      # There are quite a few fields but you can leave some blank
  18360.      # For some fields there will be a default value,
  18361.      # If you enter '.', the field will be left blank.
  18362.      # -----
  18363.      # Country Name (2 letter code) [AU]:FI
  18364.      # State or Province Name (full name) [Some-State]:.
  18365.      # Locality Name (eg, city) []:
  18366.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  18367.      # Organizational Unit Name (eg, section) []:
  18368.      # Common Name (eg, YOUR name) []:MySQL server
  18369.      # Email Address []:
  18370.      #
  18371.      # Please enter the following 'extra' attributes
  18372.      # to be sent with your certificate request
  18373.      # A challenge password []:
  18374.      # An optional company name []:
  18375.      
  18376.      #
  18377.      # Remove the passphrase from the key (optional)
  18378.      #
  18379.      
  18380.      openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
  18381.      
  18382.      #
  18383.      # Sign server cert
  18384.      #
  18385.      openssl ca  -policy policy_anything -out $DIR/server-cert.pem \
  18386.          -config $DIR/openssl.cnf -infiles $DIR/server-req.pem
  18387.      
  18388.      # Sample output:
  18389.      # Using configuration from /home/monty/openssl/openssl.cnf
  18390.      # Enter PEM pass phrase:
  18391.      # Check that the request matches the signature
  18392.      # Signature ok
  18393.      # The Subjects Distinguished Name is as follows
  18394.      # countryName           :PRINTABLE:'FI'
  18395.      # organizationName      :PRINTABLE:'MySQL AB'
  18396.      # commonName            :PRINTABLE:'MySQL admin'
  18397.      # Certificate is to be certified until Sep 13 14:22:46 2003 GMT (365 days)
  18398.      # Sign the certificate? [y/n]:y
  18399.      #
  18400.      #
  18401.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  18402.      # Write out database with 1 new entries
  18403.      # Data Base Updated
  18404.      
  18405.      #
  18406.      # Create client request and key
  18407.      #
  18408.      openssl req -new -keyout $DIR/client-key.pem -out \
  18409.          $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
  18410.      
  18411.      # Sample output:
  18412.      # Using configuration from /home/monty/openssl/openssl.cnf
  18413.      # Generating a 1024 bit RSA private key
  18414.      # .....................................++++++
  18415.      # .............................................++++++
  18416.      # writing new private key to '/home/monty/openssl/client-key.pem'
  18417.      # Enter PEM pass phrase:
  18418.      # Verifying password - Enter PEM pass phrase:
  18419.      # -----
  18420.      # You are about to be asked to enter information that will be incorporated
  18421.      # into your certificate request.
  18422.      # What you are about to enter is what is called a Distinguished Name or a DN.
  18423.      # There are quite a few fields but you can leave some blank
  18424.      # For some fields there will be a default value,
  18425.      # If you enter '.', the field will be left blank.
  18426.      # -----
  18427.      # Country Name (2 letter code) [AU]:FI
  18428.      # State or Province Name (full name) [Some-State]:.
  18429.      # Locality Name (eg, city) []:
  18430.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  18431.      # Organizational Unit Name (eg, section) []:
  18432.      # Common Name (eg, YOUR name) []:MySQL user
  18433.      # Email Address []:
  18434.      #
  18435.      # Please enter the following 'extra' attributes
  18436.      # to be sent with your certificate request
  18437.      # A challenge password []:
  18438.      # An optional company name []:
  18439.      
  18440.      #
  18441.      # Remove a passphrase from the key (optional)
  18442.      #
  18443.      openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
  18444.      
  18445.      #
  18446.      # Sign client cert
  18447.      #
  18448.      
  18449.      openssl ca  -policy policy_anything -out $DIR/client-cert.pem \
  18450.          -config $DIR/openssl.cnf -infiles $DIR/client-req.pem
  18451.      
  18452.      # Sample output:
  18453.      # Using configuration from /home/monty/openssl/openssl.cnf
  18454.      # Enter PEM pass phrase:
  18455.      # Check that the request matches the signature
  18456.      # Signature ok
  18457.      # The Subjects Distinguished Name is as follows
  18458.      # countryName           :PRINTABLE:'FI'
  18459.      # organizationName      :PRINTABLE:'MySQL AB'
  18460.      # commonName            :PRINTABLE:'MySQL user'
  18461.      # Certificate is to be certified until Sep 13 16:45:17 2003 GMT (365 days)
  18462.      # Sign the certificate? [y/n]:y
  18463.      #
  18464.      #
  18465.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  18466.      # Write out database with 1 new entries
  18467.      # Data Base Updated
  18468.      
  18469.      #
  18470.      # Create a my.cnf file that you can use to test the certificates
  18471.      #
  18472.      
  18473.      cnf=""
  18474.      cnf="$cnf [client]"
  18475.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  18476.      cnf="$cnf ssl-cert=$DIR/client-cert.pem"
  18477.      cnf="$cnf ssl-key=$DIR/client-key.pem"
  18478.      cnf="$cnf [mysqld]"
  18479.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  18480.      cnf="$cnf ssl-cert=$DIR/server-cert.pem"
  18481.      cnf="$cnf ssl-key=$DIR/server-key.pem"
  18482.      echo $cnf | replace " " '
  18483.      ' > $DIR/my.cnf
  18484.      
  18485.      #
  18486.      # To test MySQL
  18487.      
  18488.      mysqld --defaults-file=$DIR/my.cnf &
  18489.      
  18490.      mysql --defaults-file=$DIR/my.cnf
  18491.  
  18492. You can also test your setup by modifying the above `my.cnf' file to
  18493. refer to the demo certificates in the mysql-source-dist/SSL direcory.
  18494.  
  18495. SSL `GRANT' Options
  18496. ...................
  18497.  
  18498. MySQL can check X509 certificate attributes in addition to the normal
  18499. username/password scheme. All the usual options are still required
  18500. (username, password, IP address mask, database/table name).
  18501.  
  18502. There are different possibilities to limit connections:
  18503.  
  18504.    * Without any SSL or X509 options, all kind of encrypted/unencrypted
  18505.      connections are allowed if the username and password are valid.
  18506.  
  18507.    * `REQUIRE SSL' option limits the server to allow only SSL encrypted
  18508.      connections. Note that this option can be omitted if there are any
  18509.      ACL records which allow non-SSL connections.
  18510.  
  18511.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  18512.               -> IDENTIFIED BY 'goodsecret' REQUIRE SSL;
  18513.  
  18514.    * `REQUIRE X509' means that the client should have a valid
  18515.      certificate but we do not care about the exact certificate, issuer
  18516.      or subject.  The only restriction is that it should be possible to
  18517.      verify its signature with one of the CA certificates.
  18518.  
  18519.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  18520.               -> IDENTIFIED BY 'goodsecret' REQUIRE X509;
  18521.  
  18522.    * `REQUIRE ISSUER 'issuer'' places a restriction on connection
  18523.      attempts: The client must present a valid X509 certificate issued
  18524.      by CA `'issuer''.  Using X509 certificates always implies
  18525.      encryption, so the `SSL' option is unneccessary.
  18526.  
  18527.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  18528.               -> IDENTIFIED BY 'goodsecret'
  18529.               -> REQUIRE ISSUER 'C=FI, ST=Some-State, L=Helsinki,
  18530.               '> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com';
  18531.  
  18532.    * `REQUIRE SUBJECT 'subject'' requires clients to have valid X509
  18533.      certificate with subject `'subject'' on it. If the client presents
  18534.      a certificate that is valid but has a different `'subject'', the
  18535.      connection is disallowed.
  18536.  
  18537.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  18538.               -> IDENTIFIED BY 'goodsecret'
  18539.               -> REQUIRE SUBJECT 'C=EE, ST=Some-State, L=Tallinn,
  18540.               '> O=MySQL demo client certificate,
  18541.               '> CN=Tonu Samuel/Email=tonu@mysql.com';
  18542.  
  18543.    * `REQUIRE CIPHER 'cipher'' is needed to assure enough strong ciphers
  18544.      and keylengths will be used. SSL itself can be weak if old
  18545.      algorithms with short encryption keys are used. Using this option,
  18546.      we can ask for some exact cipher method to allow a connection.
  18547.  
  18548.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  18549.               -> IDENTIFIED BY 'goodsecret'
  18550.               -> REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';
  18551.  
  18552.      The `SUBJECT', `ISSUER', and `CIPHER' options can be combined in
  18553.      the `REQUIRE' clause like this:
  18554.  
  18555.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  18556.               -> IDENTIFIED BY 'goodsecret'
  18557.               -> REQUIRE SUBJECT 'C=EE, ST=Some-State, L=Tallinn,
  18558.               '> O=MySQL demo client certificate,
  18559.               '> CN=Tonu Samuel/Email=tonu@mysql.com'
  18560.               -> AND ISSUER 'C=FI, ST=Some-State, L=Helsinki,
  18561.               '> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com'
  18562.               -> AND CIPHER 'EDH-RSA-DES-CBC3-SHA';
  18563.  
  18564.      Starting from MySQL 4.0.4 the `AND' keyword is optional between
  18565.      `REQUIRE' options.
  18566.  
  18567.      The order of the options does not matter, but no option can be
  18568.      specified twice.
  18569.  
  18570. SSL Command-line Options
  18571. ........................
  18572.  
  18573. The following table lists options that are used for specifying the use
  18574. of SSL, certificate files, and key files.  These options are available
  18575. beginning with MySQL 4.0. They may be given on the command line or in
  18576. option files.
  18577.  
  18578. `--ssl'
  18579.      For the server, specifies that the server allows SSL connections.
  18580.      For a client program, allows the client to connect to the server
  18581.      using SSL.  This option itself is not sufficient to cause an SSL
  18582.      connection to be used.  You must also specify the `--ssl-ca',
  18583.      `--ssl-cert', and `--ssl-key' options.
  18584.  
  18585.      Note that this option doesn't *require* an SSL connection.  For
  18586.      example, if the server or client are compiled without SSL support,
  18587.      a normal unencrypted connection will be used.
  18588.  
  18589.      The secure way to ensure that a SSL connection will be used is to
  18590.      create an account on the server that includes a `REQUIRE SSL'
  18591.      clause in the `GRANT' statement.  Then use this account to connect
  18592.      to the server, with both a server and client that have SSL support
  18593.      enabled.
  18594.  
  18595.      You can use this option to indicate that the connection should not
  18596.      use SSL.  Do this by specifying the option as `--skip-ssl' or
  18597.      `--ssl=0'.
  18598.  
  18599. `--ssl-ca=file_name'
  18600.      The path to a file with a list of trusted SSL CAs.
  18601.  
  18602. `--ssl-capath=directory_name'
  18603.      The path to a directory that contains trusted SSL CA certificates
  18604.      in pem format.
  18605.  
  18606. `--ssl-cert=file_name'
  18607.      The name of the SSL certificate file to use used for establishing
  18608.      a secure connection.
  18609.  
  18610. `--ssl-cipher=cipher_list'
  18611.      A list of allowable ciphers to use for SSL encryption.
  18612.      `cipher_list' has the same format as the `openssl ciphers' command.
  18613.  
  18614.      Example: `--ssl-cipher=ALL:-AES:-EXP'
  18615.  
  18616. `--ssl-key=file_name'
  18617.      The name of the SSL key file to use used for establishing a secure
  18618.      connection.
  18619.  
  18620. Connecting to MySQL Remotely from Windows with SSH
  18621. ..................................................
  18622.  
  18623. Here is a note about how to connect to get a secure connection to remote
  18624. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  18625.  
  18626.   1. Install an SSH client on your Windows machine.  As a user, the
  18627.      best non-free one I've found is from `SecureCRT' from
  18628.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  18629.      `http://www.f-secure.com/'. You can also find some free ones on
  18630.      `Google' at
  18631.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  18632.  
  18633.   2. Start your Windows SSH client.  Set `Host_Name =
  18634.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  18635.      your server. This `userid' value may not be the same as the
  18636.      username of your MySQL account.
  18637.  
  18638.   3. Set up port forwarding. Either do a remote forward (Set
  18639.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  18640.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  18641.      `host: localhost', `remote port: 3306').
  18642.  
  18643.   4. Save everything, otherwise you'll have to redo it the next time.
  18644.  
  18645.   5. Log in to your server with the SSH session you just created.
  18646.  
  18647.   6. On your Windows machine, start some ODBC application (such as
  18648.      Access).
  18649.  
  18650.   7. Create a new file in Windows and link to MySQL using the ODBC
  18651.      driver the same way you normally do, except type in `localhost'
  18652.      for the MySQL host server--not `yourmysqlservername'.
  18653.  
  18654. You should now have an ODBC connection to MySQL, encrypted using SSH.
  18655.  
  18656. Disaster Prevention and Recovery
  18657. ================================
  18658.  
  18659. This section discusses how to make database backups and how to perform
  18660. table maintenance.  The syntax of the SQL statements described here is
  18661. given in *Note Database Administration::.
  18662.  
  18663. Database Backups
  18664. ----------------
  18665.  
  18666. Because MySQL tables are stored as files, it is easy to do a backup. To
  18667. get a consistent backup, do a `LOCK TABLES' on the relevant tables
  18668. followed by `FLUSH TABLES' for the tables.  *Note `LOCK TABLES': LOCK
  18669. TABLES.  *Note `FLUSH': FLUSH.  You only need a read lock; this allows
  18670. other threads to continue to query the tables while you are making a
  18671. copy of the files in the database directory.  The `FLUSH TABLE' is
  18672. needed to ensure that the all active index pages is written to disk
  18673. before you start the backup.
  18674.  
  18675. Starting from 3.23.56 and 4.0.12 `BACKUP TABLE' will not allow you to
  18676. overwrite existing files as this would be a security risk.
  18677.  
  18678. If you want to make an SQL level backup of a table, you can use `SELECT
  18679. INTO OUTFILE' or `BACKUP TABLE'. *Note SELECT::.  *Note BACKUP TABLE::.
  18680.  
  18681. Another way to back up a database is to use the `mysqldump' program or
  18682. the `mysqlhotcopy script'. *Note `mysqldump': mysqldump.  *Note
  18683. `mysqlhotcopy': mysqlhotcopy.
  18684.  
  18685.   1. Do a full backup of your database:
  18686.  
  18687.           shell> mysqldump --tab=/path/to/some/dir --opt db_name
  18688.  
  18689.      or:
  18690.  
  18691.           shell> mysqlhotcopy db_name /path/to/some/dir
  18692.  
  18693.      You can also simply copy all table files (`*.frm', `*.MYD', and
  18694.      `*.MYI' files) as long as the server isn't updating anything.  The
  18695.      script `mysqlhotcopy' does use this method.  (But note that these
  18696.      methods will not work if your database contains `InnoDB' tables.
  18697.      `InnoDB' does not store table contents in database directories,
  18698.      and `mysqlhotcopy' works only for `MyISAM' and `ISAM' tables.)
  18699.  
  18700.   2. Stop `mysqld' if it's running, then start it with the
  18701.      `--log-bin[=file_name]' option.  *Note Binary log::. The binary
  18702.      log files provide you with the information you need to replicate
  18703.      changes to the database that are made subsequent to the point at
  18704.      which you executed `mysqldump'.
  18705.  
  18706. If your MySQL server is a slave, whatever backup method you choose,
  18707. when you backup your slave's data, you should also backup the
  18708. `master.info' and `relay-log.info' files which are always needed to
  18709. resume replication after you restore the slave's data. If your slave is
  18710. subject to replicating `LOAD DATA INFILE' commands, you should also
  18711. backup the `SQL_LOAD-*' files which may exist in the directory
  18712. specified by the `--slave-load-tmpdir' option. (This location defaults
  18713. to the value of the `tmpdir' variable if not specified.) The slave will
  18714. need these files to resume replication of any interrupted `LOAD DATA
  18715. INFILE' operations.
  18716.  
  18717. If you have to restore something, try to recover your tables using
  18718. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  18719. all cases.  If `myisamchk' fails, try the following procedure (this
  18720. will work only if you have started MySQL with `--log-bin', see *Note
  18721. Binary log::):
  18722.  
  18723.   1. Restore the original `mysqldump' backup, or binary backup.
  18724.  
  18725.   2. Execute the following command to re-run the updates in the binary
  18726.      log:
  18727.  
  18728.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  18729.  
  18730.      In your case you may want to re-run only certain binlogs, from
  18731.      certain positions (usually you want to re-run all binlogs from the
  18732.      date of the restored backup, possibly excepted some wrong queries).
  18733.      See *Note mysqlbinlog:: for more information on the `mysqlbinlog'
  18734.      utility and how to use it.
  18735.  
  18736.      If you are using the update log (which is removed in MySQL 5.0.0)
  18737.      you can execute the content of the update log like this:
  18738.  
  18739.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  18740.  
  18741. `ls' is used to get all the update log files in the right order.
  18742.  
  18743. You can also do selective backups with `SELECT * INTO OUTFILE
  18744. 'file_name' FROM tbl_name' and restore with `LOAD DATA INFILE
  18745. 'file_name' REPLACE ...' To avoid duplicate records, you need a
  18746. `PRIMARY KEY' or a `UNIQUE' key in the table. The `REPLACE' keyword
  18747. causes old records to be replaced with new ones when a new record
  18748. duplicates an old record on a unique key value.
  18749.  
  18750. If you get performance problems in making backups on your system, you
  18751. can solve this by setting up replication and do the backups on the slave
  18752. instead of on the master. *Note Replication Intro::.
  18753.  
  18754. If you are using a Veritas filesystem, you can do:
  18755.  
  18756.   1. From a client (or Perl), execute: `FLUSH TABLES WITH READ LOCK'.
  18757.  
  18758.   2. From another shell, execute: `mount vxfs snapshot'.
  18759.  
  18760.   3. From the first client, execute: `UNLOCK TABLES'.
  18761.  
  18762.   4. Copy files from snapshot.
  18763.  
  18764.   5. Unmount snapshot.
  18765.  
  18766. Using `myisamchk' for Table Maintenance and Crash Recovery
  18767. ----------------------------------------------------------
  18768.  
  18769. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  18770. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  18771. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18772.  
  18773. To check/repair MyISAM tables (`.MYI' and `.MYD') you should use the
  18774. `myisamchk' utility. To check/repair ISAM tables (`.ISM' and `.ISD')
  18775. you should use the `isamchk' utility. *Note Table types::.
  18776.  
  18777. In the following text we will talk about `myisamchk', but everything
  18778. also applies to the old `isamchk'.
  18779.  
  18780. You can use the `myisamchk' utility to get information about your
  18781. database tables, check and repair them, or optimize them.  The following
  18782. sections describe how to invoke `myisamchk' (including a description of
  18783. its options), how to set up a table maintenance schedule, and how to
  18784. use `myisamchk' to perform its various functions.
  18785.  
  18786. You can, in most cases, also use the command `OPTIMIZE TABLES' to
  18787. optimize and repair tables, but this is not as fast or reliable (in case
  18788. of real fatal errors) as `myisamchk'.  On the other hand, `OPTIMIZE
  18789. TABLE' is easier to use and you don't have to worry about flushing
  18790. tables.  *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  18791.  
  18792. Even though the repair in `myisamchk' is quite secure, it's always a
  18793. good idea to make a backup _before_ doing a repair (or anything that
  18794. could make a lot of changes to a table)
  18795.  
  18796. `myisamchk' Invocation Syntax
  18797. .............................
  18798.  
  18799. `myisamchk' is invoked like this:
  18800.  
  18801.      shell> myisamchk [options] tbl_name
  18802.  
  18803. The `options' specify what you want `myisamchk' to do.  They are
  18804. described here.  (You can also get a list of options by invoking
  18805. `myisamchk --help'.)  With no options, `myisamchk' simply checks your
  18806. table.  To get more information or to tell `myisamchk' to take
  18807. corrective action, specify options as described here and in the
  18808. following sections.
  18809.  
  18810. `tbl_name' is the database table you want to check/repair.  If you run
  18811. `myisamchk' somewhere other than in the database directory, you must
  18812. specify the path to the file, because `myisamchk' has no idea where your
  18813. database is located.  Actually, `myisamchk' doesn't care whether the
  18814. files you are working on are located in a database directory; you can
  18815. copy the files that correspond to a database table into another
  18816. location and perform recovery operations on them there.
  18817.  
  18818. You can name several tables on the `myisamchk' command-line if you
  18819. wish.  You can also specify a name as an index file name (with the
  18820. `.MYI' suffix), which allows you to specify all tables in a directory
  18821. by using the pattern `*.MYI'.  For example, if you are in a database
  18822. directory, you can check all the tables in the directory like this:
  18823.  
  18824.      shell> myisamchk *.MYI
  18825.  
  18826. If you are not in the database directory, you can check all the tables
  18827. there by specifying the path to the directory:
  18828.  
  18829.      shell> myisamchk /path/to/database_dir/*.MYI
  18830.  
  18831. You can even check all tables in all databases by specifying a wildcard
  18832. with the path to the MySQL data directory:
  18833.  
  18834.      shell> myisamchk /path/to/datadir/*/*.MYI
  18835.  
  18836. The recommended way to quickly check all tables is:
  18837.  
  18838.      myisamchk --silent --fast /path/to/datadir/*/*.MYI
  18839.      isamchk --silent /path/to/datadir/*/*.ISM
  18840.  
  18841. If you want to check all tables and repair all tables that are
  18842. corrupted, you can use the following line:
  18843.  
  18844.      myisamchk --silent --force --fast --update-state -O key_buffer=64M \
  18845.                -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
  18846.                /path/to/datadir/*/*.MYI
  18847.      isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M \
  18848.              -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.ISM
  18849.  
  18850. The above assumes that you have more than 64 M free.
  18851.  
  18852. Note that if you get an error like:
  18853.  
  18854.      myisamchk: warning: 1 clients is using or hasn't closed the table properly
  18855.  
  18856. This means that you are trying to check a table that has been updated by
  18857. another program (like the `mysqld' server) that hasn't yet closed the
  18858. file or that has died without closing the file properly.
  18859.  
  18860. If `mysqld' is running, you must force a sync/close of all tables with
  18861. `FLUSH TABLES' and ensure that no one is using the tables while you are
  18862. running `myisamchk'.  In MySQL Version 3.23 the easiest way to avoid
  18863. this problem is to use `CHECK TABLE' instead of `myisamchk' to check
  18864. tables.
  18865.  
  18866. General Options for `myisamchk'
  18867. ...............................
  18868.  
  18869. `myisamchk' supports the following options.
  18870.  
  18871. `-# or --debug=debug_options'
  18872.      Output debug log. The `debug_options' string often is
  18873.      `'d:t:o,filename''.
  18874.  
  18875. `-? or --help'
  18876.      Display a help message and exit.
  18877.  
  18878. `-O name=value, --set-variable=name=value'
  18879.      Set the value of a variable.  Please note that
  18880.      `--set-variable=name=value' and `-O name=value' syntax is
  18881.      deprecated as of MySQL 4.0.  Use `--name=value' instead.  The
  18882.      possible variables and their default values for myisamchk can be
  18883.      examined with `myisamchk --help':
  18884.      *Variable*    *Value*
  18885.      key_buffer_size523264
  18886.      read_buffer_size262136
  18887.      write_buffer_size262136
  18888.      sort_buffer_size2097144
  18889.      sort_key_blocks16
  18890.      decode_bits   9
  18891.  
  18892.      `sort_buffer_size' is used when the keys are repaired by sorting
  18893.      keys, which is the normal case when you use `--recover'.
  18894.  
  18895.      `key_buffer_size' is used when you are checking the table with
  18896.      `--extended-check' or when the keys are repaired by inserting key
  18897.      row by row in to the table (like when doing normal inserts).
  18898.      Repairing through the key buffer is used in the following cases:
  18899.  
  18900.         * If you use `--safe-recover'.
  18901.  
  18902.         * If the temporary files needed to sort the keys would be more
  18903.           than twice as big as when creating the key file directly.
  18904.           This is often the case when you have big `CHAR', `VARCHAR' or
  18905.           `TEXT' keys as the sort needs to store the whole keys during
  18906.           sorting. If you have lots of temporary space and you can
  18907.           force `myisamchk' to repair by sorting you can use the
  18908.           `--sort-recover' option.
  18909.  
  18910.      Reparing through the key buffer takes much less disk space than
  18911.      using sorting, but is also much slower.
  18912.  
  18913.      If you want a faster repair, set the above variables to about 1/4
  18914.      of your available memory.  You can set both variables to big
  18915.      values, as only one of the above buffers will be used at a time.
  18916.  
  18917. `-s or --silent'
  18918.      Silent mode.  Write output only when errors occur. You can use `-s'
  18919.      twice (`-ss') to make `myisamchk' very silent.
  18920.  
  18921. `-v or --verbose'
  18922.      Verbose mode.  Print more information. This can be used with `-d'
  18923.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for more
  18924.      verbosity!
  18925.  
  18926. `-V or --version'
  18927.      Print the `myisamchk' version and exit.
  18928.  
  18929. `-w or, --wait'
  18930.      Instead of giving an error if the table is locked, wait until the
  18931.      table is unlocked before continuing.  Note that if you are running
  18932.      `mysqld' on the table with `--skip-external-locking', the table
  18933.      can only be locked by another `myisamchk' command.
  18934.  
  18935. Check Options for `myisamchk'
  18936. .............................
  18937.  
  18938. `-c or --check'
  18939.      Check table for errors. This is the default operation if you are
  18940.      not giving `myisamchk' any options that override this.
  18941.  
  18942. `-e or --extend-check'
  18943.      Check the table very thoroughly (which is quite slow if you have
  18944.      many indexes).  This option should only be used in extreme cases.
  18945.      Normally, `myisamchk' or `myisamchk --medium-check' should, in most
  18946.      cases, be able to find out if there are any errors in the table.
  18947.  
  18948.      If you are using `--extended-check' and have much memory, you
  18949.      should increase the value of `key_buffer_size' a lot!
  18950.  
  18951. `-F or --fast'
  18952.      Check only tables that haven't been closed properly.
  18953.  
  18954. `-C or --check-only-changed'
  18955.      Check only tables that have changed since the last check.
  18956.  
  18957. `-f or --force'
  18958.      Restart `myisamchk' with `-r' (repair) on the table, if
  18959.      `myisamchk' finds any errors in the table.
  18960.  
  18961. `-i or --information'
  18962.      Print informational statistics about the table that is checked.
  18963.  
  18964. `-m or --medium-check'
  18965.      Faster than extended-check, but only finds 99.99% of all errors.
  18966.      Should, however, be good enough for most cases.
  18967.  
  18968. `-U or --update-state'
  18969.      Store in the `.MYI' file when the table was checked and if the
  18970.      table crashed.  This should be used to get full benefit of the
  18971.      `--check-only-changed' option, but you shouldn't use this option
  18972.      if the `mysqld' server is using the table and you are running
  18973.      `mysqld' with `--skip-external-locking'.
  18974.  
  18975. `-T or --read-only'
  18976.      Don't mark table as checked. This is useful if you use `myisamchk'
  18977.      to check a table that is in use by some other application that
  18978.      doesn't use locking (like `mysqld --skip-external-locking').
  18979.  
  18980. Repair Options for myisamchk
  18981. ............................
  18982.  
  18983. The following options are used if you start `myisamchk' with `-r' or
  18984. `-o':
  18985.  
  18986. `-B or --backup'
  18987.      Make a backup of the `.MYD' file as `filename-time.BAK'
  18988.  
  18989. `--correct-checksum'
  18990.      Correct checksum information for table.
  18991.  
  18992. `-D # or --data-file-length=#'
  18993.      Max length of datafile (when re-creating datafile when it's
  18994.      'full').
  18995.  
  18996. `-e or --extend-check'
  18997.      Try to recover every possible row from the datafile.  Normally
  18998.      this will also find a lot of garbage rows. Don't use this option
  18999.      if you are not totally desperate.
  19000.  
  19001. `-f or --force'
  19002.      Overwrite old temporary files (`table_name.TMD') instead of
  19003.      aborting.
  19004.  
  19005. `-k # or --keys-used=#'
  19006.      If you are using `ISAM', tells the `ISAM' storage engine to update
  19007.      only the first `#' indexes.  If you are using `MyISAM', tells
  19008.      which keys to use, where each binary bit stands for one key (first
  19009.      key is bit 0).  This can be used to get faster inserts!
  19010.      Deactivated indexes can be reactivated by using `myisamchk -r'.
  19011.  
  19012. `-l or --no-symlinks'
  19013.      Do not follow symbolic links. Normally `myisamchk' repairs the
  19014.      table a symlink points at.  This option doesn't exist in MySQL 4.0,
  19015.      as MySQL 4.0 will not remove symlinks during repair.
  19016.  
  19017. `-p or --parallel-recover'
  19018.      Uses the same technique as `-r' and `-n', but creates all the keys
  19019.      in parallel, in different threads.  This option was added in MySQL
  19020.      4.0.2.  *This is alpha code. Use at your own risk!*
  19021.  
  19022. `-r or --recover'
  19023.      Can fix almost anything except unique keys that aren't unique
  19024.      (which is an extremely unlikely error with `ISAM'/`MyISAM' tables).
  19025.      If you want to recover a table, this is the option to try first.
  19026.      Only if `myisamchk' reports that the table can't be recovered by
  19027.      `-r', you should then try `-o'.  (Note that in the unlikely case
  19028.      that `-r' fails, the datafile is still intact.)  If you have lots
  19029.      of memory, you should increase the size of `sort_buffer_size'!
  19030.  
  19031. `-o or --safe-recover'
  19032.      Uses an old recovery method (reads through all rows in order and
  19033.      updates all index trees based on the found rows); this is an order
  19034.      of magnitude slower than `-r', but can handle a couple of very
  19035.      unlikely cases that `-r' cannot handle.  This recovery method also
  19036.      uses much less disk space than `-r'. Normally one should always
  19037.      first repair with `-r', and only if this fails use `-o'.
  19038.  
  19039.      If you have lots of memory, you should increase the size of
  19040.      `key_buffer_size'!
  19041.  
  19042. `-n or --sort-recover'
  19043.      Force `myisamchk' to use sorting to resolve the keys even if the
  19044.      temporary files should be very big.
  19045.  
  19046. `--character-sets-dir=...'
  19047.      Directory where character sets are stored.
  19048.  
  19049. `--set-character-set=name'
  19050.      Change the character set used by the index
  19051.  
  19052. `-t or --tmpdir=path'
  19053.      Path for storing temporary files. If this is not set, `myisamchk'
  19054.      will use the environment variable `TMPDIR' for this.  Starting
  19055.      from MySQL 4.1, `tmpdir' can be set to a list of paths separated
  19056.      by colon `:' (semicolon `;' on Windows). They will be used in
  19057.      round-robin fashion.
  19058.  
  19059. `-q or --quick'
  19060.      Faster repair by not modifying the datafile. One can give a second
  19061.      `-q' to force `myisamchk' to modify the original datafile in case
  19062.      of duplicate keys
  19063.  
  19064. `-u or --unpack'
  19065.      Unpack file packed with myisampack.
  19066.  
  19067. Other Options for `myisamchk'
  19068. .............................
  19069.  
  19070. Other actions that `myisamchk' can do, besides repair and check tables:
  19071.  
  19072. `-a or --analyze'
  19073.      Analyze the distribution of keys. This improves join performance by
  19074.      enabling the join optimizer to better choose in which order it
  19075.      should join the tables and which keys it should use: `myisamchk
  19076.      --describe --verbose table_name'' or using `SHOW KEYS' in MySQL.
  19077.  
  19078. `-d or --description'
  19079.      Prints some information about table.
  19080.  
  19081. `-A or --set-auto-increment[=value]'
  19082.      Force `AUTO_INCREMENT' to start at this or higher value. If no
  19083.      value is given, then sets the next `AUTO_INCREMENT' value to the
  19084.      highest used value for the auto key + 1.
  19085.  
  19086. `-S or --sort-index'
  19087.      Sort the index tree blocks in high-low order.  This will optimize
  19088.      seeks and will make table scanning by key faster.
  19089.  
  19090. `-R or --sort-records=#'
  19091.      Sorts records according to an index.  This makes your data much
  19092.      more localized and may speed up ranged `SELECT' and `ORDER BY'
  19093.      operations on this index. (It may be very slow to do a sort the
  19094.      first time!)  To find out a table's index numbers, use `SHOW
  19095.      INDEX', which shows a table's indexes in the same order that
  19096.      `myisamchk' sees them.  Indexes are numbered beginning with 1.
  19097.  
  19098. `myisamchk' Memory Usage
  19099. ........................
  19100.  
  19101. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  19102. uses no more memory than you specify with the `-O' options.  If you are
  19103. going to use `myisamchk' on very large files, you should first decide
  19104. how much memory you want it to use.  The default is to use only about
  19105. 3M to perform repairs.  By using larger values, you can get `myisamchk'
  19106. to operate faster.  For example, if you have more than 32M RAM, you
  19107. could use options such as these (in addition to any other options you
  19108. might specify):
  19109.  
  19110.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  19111.  
  19112. Using `-O sort=16M' should probably be enough for most cases.
  19113.  
  19114. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  19115. points to a memory filesystem, you may easily get out of memory errors.
  19116. If this happens, set `TMPDIR' to point at some directory with more
  19117. space and restart `myisamchk'.
  19118.  
  19119. When repairing, `myisamchk' will also need a lot of disk space:
  19120.  
  19121.    * Double the size of the record file (the original one and a copy).
  19122.      This space is not needed if one does a repair with `--quick', as
  19123.      in this case only the index file will be re-created.  This space
  19124.      is needed on the same disk as the original record file!
  19125.  
  19126.    * Space for the new index file that replaces the old one. The old
  19127.      index file is truncated at start, so one usually ignore this space.
  19128.      This space is needed on the same disk as the original index file!
  19129.  
  19130.    * When using `--recover' or `--sort-recover' (but not when using
  19131.      `--safe-recover'), you will need space for a sort buffer for:
  19132.      `(largest_key + row_pointer_length)*number_of_rows * 2'.  You can
  19133.      check the length of the keys and the row_pointer_length with
  19134.      `myisamchk -dv table'.  This space is allocated on the temporary
  19135.      disk (specified by `TMPDIR' or `--tmpdir=#').
  19136.  
  19137. If you have a problem with disk space during repair, you can try to use
  19138. `--safe-recover' instead of `--recover'.
  19139.  
  19140. Using `myisamchk' for Crash Recovery
  19141. ....................................
  19142.  
  19143. If you run `mysqld' with `--skip-external-locking' (which is the
  19144. default on some systems, like Linux), you can't reliably use `myisamchk'
  19145. to check a table when `mysqld' is using the same table.  If you can be
  19146. sure that no one is accessing the tables through `mysqld' while you run
  19147. `myisamchk', you only have to do `mysqladmin flush-tables' before you
  19148. start checking the tables.  If you can't guarantee the above, then you
  19149. must take down `mysqld' while you check the tables.  If you run
  19150. `myisamchk' while `mysqld' is updating the tables, you may get a
  19151. warning that a table is corrupt even if it isn't.
  19152.  
  19153. If you are not using `--skip-external-locking', you can use `myisamchk'
  19154. to check tables at any time.  While you do this, all clients that try
  19155. to update the table will wait until `myisamchk' is ready before
  19156. continuing.
  19157.  
  19158. If you use `myisamchk' to repair or optimize tables, you *must* always
  19159. ensure that the `mysqld' server is not using the table (this also
  19160. applies if you are using `--skip-external-locking').  If you don't take
  19161. down `mysqld' you should at least do a `mysqladmin flush-tables' before
  19162. you run `myisamchk'.  Your tables *may be corrupted* if the server and
  19163. `myisamchk' access the tables simultaneously.
  19164.  
  19165. This section describes how to check for and deal with data corruption
  19166. in MySQL databases.  If your tables get corrupted frequently you should
  19167. try to find the reason for this! *Note Crashing::.
  19168.  
  19169. The `MyISAM' table section contains reason for why a table could be
  19170. corrupted. *Note MyISAM table problems::.
  19171.  
  19172. When performing crash recovery, it is important to understand that each
  19173. table `tbl_name' in a database corresponds to three files in the
  19174. database directory:
  19175.  
  19176. *File*         *Purpose*
  19177. `tbl_name.frm' Table definition
  19178.                (form) file
  19179. `tbl_name.MYD' Datafile
  19180. `tbl_name.MYI' Index file
  19181.  
  19182. Each of these three file types is subject to corruption in various
  19183. ways, but problems occur most often in datafiles and index files.
  19184.  
  19185. `myisamchk' works by creating a copy of the `.MYD' (data) file row by
  19186. row. It ends the repair stage by removing the old `.MYD' file and
  19187. renaming the new file to the original file name.  If you use `--quick',
  19188. `myisamchk' does not create a temporary `.MYD' file, but instead
  19189. assumes that the `.MYD' file is correct and only generates a new index
  19190. file without touching the `.MYD' file. This is safe, because
  19191. `myisamchk' automatically detects if the `.MYD' file is corrupt and
  19192. aborts the repair in this case.  You can also give two `--quick'
  19193. options to `myisamchk'.  In this case, `myisamchk' does not abort on
  19194. some errors (like duplicate key) but instead tries to resolve them by
  19195. modifying the `.MYD' file. Normally the use of two `--quick' options is
  19196. useful only if you have too little free disk space to perform a normal
  19197. repair.  In this case you should at least make a backup before running
  19198. `myisamchk'.
  19199.  
  19200. How to Check Tables for Errors
  19201. ..............................
  19202.  
  19203. To check a MyISAM table, use the following commands:
  19204.  
  19205. `myisamchk tbl_name'
  19206.      This finds 99.99% of all errors. What it can't find is corruption
  19207.      that involves *only* the datafile (which is very unusual). If you
  19208.      want to check a table, you should normally run `myisamchk' without
  19209.      options or with either the `-s' or `--silent' option.
  19210.  
  19211. `myisamchk -m tbl_name'
  19212.      This finds 99.999% of all errors. It checks first all index
  19213.      entries for errors and then it reads through all rows. It
  19214.      calculates a checksum for all keys in the rows and verifies that
  19215.      they checksum matches the checksum for the keys in the index tree.
  19216.  
  19217. `myisamchk -e tbl_name'
  19218.      This does a complete and thorough check of all data (`-e' means
  19219.      "extended check"). It does a check-read of every key for each row
  19220.      to verify that they indeed point to the correct row.  This may
  19221.      take a long time on a big table with many keys.  `myisamchk' will
  19222.      normally stop after the first error it finds. If you want to
  19223.      obtain more information, you can add the `--verbose' (`-v')
  19224.      option.  This causes `myisamchk' to keep going, up through a
  19225.      maximum of 20 errors.  In normal usage, a simple `myisamchk' (with
  19226.      no arguments other than the table name) is sufficient.
  19227.  
  19228. `myisamchk -e -i tbl_name'
  19229.      Like the previous command, but the `-i' option tells `myisamchk' to
  19230.      print some informational statistics, too.
  19231.  
  19232. How to Repair Tables
  19233. ....................
  19234.  
  19235. In the following section we only talk about using `myisamchk' on
  19236. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  19237. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  19238. instead.
  19239.  
  19240. Starting with MySQL Version 3.23.14, you can repair MyISAM tables with
  19241. the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  19242.  
  19243. The symptoms of a corrupted table include queries that abort
  19244. unexpectedly and observable errors such as these:
  19245.  
  19246.    * `tbl_name.frm' is locked against change
  19247.  
  19248.    * Can't find file `tbl_name.MYI' (Errcode: ###)
  19249.  
  19250.    * Unexpected end of file
  19251.  
  19252.    * Record file is crashed
  19253.  
  19254.    * Got error ### from table handler
  19255.  
  19256.      To get more information about the error you can run `perror ###'.
  19257.      Here is the most common errors that indicates a problem with the
  19258.      table:
  19259.  
  19260.           shell> perror 126 127 132 134 135 136 141 144 145
  19261.           126 = Index file is crashed / Wrong file format
  19262.           127 = Record-file is crashed
  19263.           132 = Old database file
  19264.           134 = Record was already deleted (or record file crashed)
  19265.           135 = No more room in record file
  19266.           136 = No more room in index file
  19267.           141 = Duplicate unique key or constraint on write or update
  19268.           144 = Table is crashed and last repair failed
  19269.           145 = Table was marked as crashed and should be repaired
  19270.  
  19271.      Note that error 135 (no more room in record file), is not an error
  19272.      that can be fixed by a simple repair. In this case you have to do:
  19273.  
  19274.           ALTER TABLE table MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;
  19275.  
  19276.      You can also use this technique for error 136 (no more room in
  19277.      index file).
  19278.  
  19279.  
  19280. In the other cases, you must repair your tables. `myisamchk' can
  19281. usually detect and fix most problems that occur.
  19282.  
  19283. The repair process involves up to four stages, described here. Before
  19284. you begin, you should `cd' to the database directory and check the
  19285. permissions of the table files. Make sure they are readable by the Unix
  19286. user that `mysqld' runs as (and to you, because you need to access the
  19287. files you are checking).  If it turns out you need to modify files,
  19288. they must also be writable by you.
  19289.  
  19290. If you are using MySQL Version 3.23.16 and above, you can (and should)
  19291. use the `CHECK' and `REPAIR' commands to check and repair `MyISAM'
  19292. tables.  *Note CHECK TABLE::.  *Note REPAIR TABLE::.
  19293.  
  19294. The manual section about table maintenance includes the options to
  19295. `isamchk'/`myisamchk'.  *Note Table maintenance::.
  19296.  
  19297. The following section is for the cases where the above command fails or
  19298. if you want to use the extended features that `isamchk'/`myisamchk'
  19299. provides.
  19300.  
  19301. If you are going to repair a table from the command-line, you must first
  19302. take down the `mysqld' server. Note that when you do `mysqladmin
  19303. shutdown' on a remote server, the `mysqld' server will still be alive
  19304. for a while after `mysqladmin' returns, until all queries are stopped
  19305. and all keys have been flushed to disk.
  19306.  
  19307. *Stage 1: Checking your tables*
  19308.  
  19309. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  19310. Use the `-s' (silent) option to suppress unnecessary information.
  19311.  
  19312. If the `mysqld' server is done you should use the -update option to tell
  19313. `myisamchk' to mark the table as 'checked'.
  19314.  
  19315. You have to repair only those tables for which `myisamchk' announces an
  19316. error.  For such tables, proceed to Stage 2.
  19317.  
  19318. If you get weird errors when checking (such as `out of memory' errors),
  19319. or if `myisamchk' crashes, go to Stage 3.
  19320.  
  19321. *Stage 2: Easy safe repair*
  19322.  
  19323. Note: If you want repairing to go much faster, you should add: `-O
  19324. sort_buffer=# -O key_buffer=#' (where # is about 1/4 of the available
  19325. memory) to all `isamchk/myisamchk' commands.
  19326.  
  19327. First, try `myisamchk -r -q tbl_name' (`-r -q' means "quick recovery
  19328. mode"). This will attempt to repair the index file without touching the
  19329. datafile.  If the datafile contains everything that it should and the
  19330. delete links point at the correct locations within the datafile, this
  19331. should work, and the table is fixed. Start repairing the next table.
  19332. Otherwise, use the following procedure:
  19333.  
  19334.   1. Make a backup of the datafile before continuing.
  19335.  
  19336.   2. Use `myisamchk -r tbl_name' (`-r' means "recovery mode"). This will
  19337.      remove incorrect records and deleted records from the datafile and
  19338.      reconstruct the index file.
  19339.  
  19340.   3. If the preceding step fails, use `myisamchk --safe-recover
  19341.      tbl_name'.  Safe recovery mode uses an old recovery method that
  19342.      handles a few cases that regular recovery mode doesn't (but is
  19343.      slower).
  19344.  
  19345. If you get weird errors when repairing (such as `out of memory'
  19346. errors), or if `myisamchk' crashes, go to Stage 3.
  19347.  
  19348. *Stage 3: Difficult repair*
  19349.  
  19350. You should only reach this stage if the first 16K block in the index
  19351. file is destroyed or contains incorrect information, or if the index
  19352. file is missing.  In this case, it's necessary to create a new index
  19353. file. Do so as follows:
  19354.  
  19355.   1. Move the datafile to some safe place.
  19356.  
  19357.   2. Use the table description file to create new (empty) data and
  19358.      index files:
  19359.  
  19360.           shell> mysql db_name
  19361.           mysql> SET AUTOCOMMIT=1;
  19362.           mysql> TRUNCATE TABLE table_name;
  19363.           mysql> quit
  19364.  
  19365.      If your SQL version doesn't have `TRUNCATE TABLE', use `DELETE FROM
  19366.      table_name' instead.
  19367.  
  19368.   3. Copy the old datafile back onto the newly created datafile.
  19369.      (Don't just move the old file back onto the new file; you want to
  19370.      retain a copy in case something goes wrong.)
  19371.  
  19372. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  19373. be an endless loop.)
  19374.  
  19375. As of `MySQL' 4.0.2 you can also use `REPAIR ... USE_FRM' which
  19376. performs the whole procedure automatically.
  19377.  
  19378. *Stage 4: Very difficult repair*
  19379.  
  19380. You should reach this stage only if the description file has also
  19381. crashed. That should never happen, because the description file isn't
  19382. changed after the table is created:
  19383.  
  19384.   1. Restore the description file from a backup and go back to Stage 3.
  19385.      You can also restore the index file and go back to Stage 2.  In
  19386.      the latter case, you should start with `myisamchk -r'.
  19387.  
  19388.   2. If you don't have a backup but know exactly how the table was
  19389.      created, create a copy of the table in another database.  Remove
  19390.      the new datafile, then move the description and index files from
  19391.      the other database to your crashed database.  This gives you new
  19392.      description and index files, but leaves the datafile alone.  Go
  19393.      back to Stage 2 and attempt to reconstruct the index file.
  19394.  
  19395. Table Optimization
  19396. ..................
  19397.  
  19398. To coalesce fragmented records and eliminate wasted space resulting from
  19399. deleting or updating records, run `myisamchk' in recovery mode:
  19400.  
  19401.      shell> myisamchk -r tbl_name
  19402.  
  19403. You can optimize a table in the same way using the SQL `OPTIMIZE TABLE'
  19404. statement.  `OPTIMIZE TABLE' does a repair of the table and a key
  19405. analysis, and also sorts the index tree to give faster key lookups.
  19406. There is also no possibility of unwanted interaction between a utility
  19407. and the server, because the server does all the work when you use
  19408. `OPTIMIZE TABLE'. *Note OPTIMIZE TABLE::.
  19409.  
  19410. `myisamchk' also has a number of other options you can use to improve
  19411. the performance of a table:
  19412.  
  19413.    * `-S', `--sort-index'
  19414.  
  19415.    * `-R index_num', `--sort-records=index_num'
  19416.  
  19417.    * `-a', `--analyze'
  19418.  
  19419. For a full description of the option. *Note myisamchk syntax::.
  19420.  
  19421. Setting Up a Table Maintenance Regimen
  19422. --------------------------------------
  19423.  
  19424. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  19425. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  19426. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  19427.  
  19428. It is a good idea to perform table checks on a regular basis rather than
  19429. waiting for problems to occur.  For maintenance purposes, you can use
  19430. `myisamchk -s' to check tables.  The `-s' option (short for `--silent')
  19431. causes `myisamchk' to run in silent mode, printing messages only when
  19432. errors occur.
  19433.  
  19434. It's also a good idea to check tables when the server starts.  For
  19435. example, whenever the machine has done a reboot in the middle of an
  19436. update, you usually need to check all the tables that could have been
  19437. affected. (This is an "expected crashed table".) You could add a test to
  19438. `mysqld_safe' that runs `myisamchk' to check all tables that have been
  19439. modified during the last 24 hours if there is an old `.pid' (process
  19440. ID) file left after a reboot.  (The `.pid' file is created by `mysqld'
  19441. when it starts and removed when it terminates normally.  The presence
  19442. of a `.pid' file at system startup time indicates that `mysqld'
  19443. terminated abnormally.)
  19444.  
  19445. An even better test would be to check any table whose last-modified time
  19446. is more recent than that of the `.pid' file.
  19447.  
  19448. You should also check your tables regularly during normal system
  19449. operation.  At MySQL AB, we run a `cron' job to check all our important
  19450. tables once a week, using a line like this in a `crontab' file:
  19451.  
  19452.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  19453.  
  19454. This prints out information about crashed tables so we can examine and
  19455. repair them when needed.
  19456.  
  19457. As we haven't had any unexpectedly crashed tables (tables that become
  19458. corrupted for reasons other than hardware trouble) for a couple of
  19459. years now (this is really true), once a week is more than enough for us.
  19460.  
  19461. We recommend that to start with, you execute `myisamchk -s' each night
  19462. on all tables that have been updated during the last 24 hours, until
  19463. you come to trust MySQL as much as we do.
  19464.  
  19465. Normally you don't need to maintain MySQL tables that much.  If you are
  19466. changing tables with dynamic size rows (tables with `VARCHAR', `BLOB'
  19467. or `TEXT' columns) or have tables with many deleted rows you may want
  19468. to from time to time (once a month?) defragment/reclaim space from the
  19469. tables.
  19470.  
  19471. You can do this by using `OPTIMIZE TABLE' on the tables in question or
  19472. if you can take down the `mysqld' server for a while do:
  19473.  
  19474.      isamchk -r --silent --sort-index -O sort_buffer_size=16M */*.ISM
  19475.      myisamchk -r --silent --sort-index  -O sort_buffer_size=16M */*.MYI
  19476.  
  19477. Getting Information About a Table
  19478. ---------------------------------
  19479.  
  19480. To get a description of a table or statistics about it, use the
  19481. commands shown here. We explain some of the information in more detail
  19482. later:
  19483.  
  19484.    * myisamchk -d tbl_name Runs `myisamchk' in "describe mode" to
  19485.      produce a description of your table. If you start the MySQL server
  19486.      using the `--skip-external-locking' option, `myisamchk' may report
  19487.      an error for a table that is updated while it runs.  However,
  19488.      because `myisamchk' doesn't change the table in describe mode,
  19489.      there isn't any risk of destroying data.
  19490.  
  19491.    * myisamchk -d -v tbl_name To produce more information about what
  19492.      `myisamchk' is doing, add `-v' to tell it to run in verbose mode.
  19493.  
  19494.    * myisamchk -eis tbl_name Shows only the most important information
  19495.      from a table. It is slow because it must read the whole table.
  19496.  
  19497.    * myisamchk -eiv tbl_name This is like `-eis', but tells you what is
  19498.      being done.
  19499.  
  19500. Example of `myisamchk -d' output:
  19501.      MyISAM file:     company.MYI
  19502.      Record format:   Fixed length
  19503.      Data records:    1403698  Deleted blocks:         0
  19504.      Recordlength:    226
  19505.      
  19506.      table description:
  19507.      Key Start Len Index   Type
  19508.      1   2     8   unique  double
  19509.      2   15    10  multip. text packed stripped
  19510.      3   219   8   multip. double
  19511.      4   63    10  multip. text packed stripped
  19512.      5   167   2   multip. unsigned short
  19513.      6   177   4   multip. unsigned long
  19514.      7   155   4   multip. text
  19515.      8   138   4   multip. unsigned long
  19516.      9   177   4   multip. unsigned long
  19517.          193   1           text
  19518.  
  19519. Example of `myisamchk -d -v' output:
  19520.      MyISAM file:         company
  19521.      Record format:       Fixed length
  19522.      File-version:        1
  19523.      Creation time:       1999-10-30 12:12:51
  19524.      Recover time:        1999-10-31 19:13:01
  19525.      Status:              checked
  19526.      Data records:           1403698  Deleted blocks:              0
  19527.      Datafile parts:         1403698  Deleted data:                0
  19528.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     3
  19529.      Max datafile length: 3791650815  Max keyfile length: 4294967294
  19530.      Recordlength:               226
  19531.      
  19532.      table description:
  19533.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  19534.      1   2     8   unique  double                      1 15845376      1024
  19535.      2   15    10  multip. text packed stripped        2 25062400      1024
  19536.      3   219   8   multip. double                     73 40907776      1024
  19537.      4   63    10  multip. text packed stripped        5 48097280      1024
  19538.      5   167   2   multip. unsigned short           4840 55200768      1024
  19539.      6   177   4   multip. unsigned long            1346 65145856      1024
  19540.      7   155   4   multip. text                     4995 75090944      1024
  19541.      8   138   4   multip. unsigned long              87 85036032      1024
  19542.      9   177   4   multip. unsigned long             178 96481280      1024
  19543.          193   1           text
  19544.  
  19545. Example of `myisamchk -eis' output:
  19546.      Checking MyISAM file: company
  19547.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19548.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  19549.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19550.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  19551.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19552.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19553.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19554.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19555.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  19556.      Total:    Keyblocks used:  98%  Packed:   17%
  19557.      
  19558.      Records:          1403698    M.recordlength:     226
  19559.      Packed:             0%
  19560.      Recordspace used:     100%   Empty space:          0%
  19561.      Blocks/Record:   1.00
  19562.      Record blocks:    1403698    Delete blocks:        0
  19563.      Recorddata:     317235748    Deleted data:         0
  19564.      Lost space:             0    Linkdata:             0
  19565.      
  19566.      User time 1626.51, System time 232.36
  19567.      Maximum resident set size 0, Integral resident set size 0
  19568.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  19569.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  19570.      Voluntary context switches 639, Involuntary context switches 28966
  19571.  
  19572. Example of `myisamchk -eiv' output:
  19573.      Checking MyISAM file: company
  19574.      Data records: 1403698   Deleted blocks:       0
  19575.      - check file-size
  19576.      - check delete-chain
  19577.      block_size 1024:
  19578.      index  1:
  19579.      index  2:
  19580.      index  3:
  19581.      index  4:
  19582.      index  5:
  19583.      index  6:
  19584.      index  7:
  19585.      index  8:
  19586.      index  9:
  19587.      No recordlinks
  19588.      - check index reference
  19589.      - check data record references index: 1
  19590.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19591.      - check data record references index: 2
  19592.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  19593.      - check data record references index: 3
  19594.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19595.      - check data record references index: 4
  19596.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  19597.      - check data record references index: 5
  19598.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19599.      - check data record references index: 6
  19600.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19601.      - check data record references index: 7
  19602.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19603.      - check data record references index: 8
  19604.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19605.      - check data record references index: 9
  19606.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  19607.      Total:    Keyblocks used:   9%  Packed:   17%
  19608.      
  19609.      - check records and index references
  19610.      [LOTS OF ROW NUMBERS DELETED]
  19611.      
  19612.      Records:          1403698    M.recordlength:     226   Packed:             0%
  19613.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  19614.      Record blocks:    1403698    Delete blocks:        0
  19615.      Recorddata:     317235748    Deleted data:         0
  19616.      Lost space:             0    Linkdata:             0
  19617.      
  19618.      User time 1639.63, System time 251.61
  19619.      Maximum resident set size 0, Integral resident set size 0
  19620.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  19621.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  19622.      Voluntary context switches 10604, Involuntary context switches 122798
  19623.  
  19624. Here are the sizes of the data and index files for the table used in the
  19625. preceding examples:
  19626.  
  19627.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  19628.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  19629.  
  19630. Explanations for the types of information `myisamchk' produces are
  19631. given here.  The "keyfile" is the index file.  "Record" and "row" are
  19632. synonymous:
  19633.  
  19634.    * ISAM file Name of the ISAM (index) file.
  19635.  
  19636.    * Isam-version Version of ISAM format. Currently always 2.
  19637.  
  19638.    * Creation time When the datafile was created.
  19639.  
  19640.    * Recover time When the index/datafile was last reconstructed.
  19641.  
  19642.    * Data records How many records are in the table.
  19643.  
  19644.    * Deleted blocks How many deleted blocks still have reserved space.
  19645.      You can optimize your table to minimise this space.  *Note
  19646.      Optimisation::.
  19647.  
  19648.    * Data file: Parts For dynamic record format, this indicates how
  19649.      many data blocks there are. For an optimized table without
  19650.      fragmented records, this is the same as `Data records'.
  19651.  
  19652.    * Deleted data How many bytes of non-reclaimed deleted data there
  19653.      are.  You can optimize your table to minimise this space.  *Note
  19654.      Optimisation::.
  19655.  
  19656.    * Data file pointer The size of the datafile pointer, in bytes. It
  19657.      is usually 2, 3, 4, or 5 bytes. Most tables manage with 2 bytes,
  19658.      but this cannot be controlled from MySQL yet. For fixed tables,
  19659.      this is a record address. For dynamic tables, this is a byte
  19660.      address.
  19661.  
  19662.    * Keyfile pointer The size of the index file pointer, in bytes. It
  19663.      is usually 1, 2, or 3 bytes. Most tables manage with 2 bytes, but
  19664.      this is calculated automatically by MySQL. It is always a block
  19665.      address.
  19666.  
  19667.    * Max datafile length How long the table's datafile (`.MYD' file)
  19668.      can become, in bytes.
  19669.  
  19670.    * Max keyfile length How long the table's key file (`.MYI' file) can
  19671.      become, in bytes.
  19672.  
  19673.    * Recordlength How much space each record takes, in bytes.
  19674.  
  19675.    * Record format The format used to store table rows.  The preceding
  19676.      examples use `Fixed length'.  Other possible values are
  19677.      `Compressed' and `Packed'.
  19678.  
  19679.    * table description A list of all keys in the table. For each key,
  19680.      some low-level information is presented:
  19681.  
  19682.         - Key This key's number.
  19683.  
  19684.         - Start Where in the record this index part starts.
  19685.  
  19686.         - Len How long this index part is. For packed numbers, this
  19687.           should always be the full length of the column. For strings,
  19688.           it may be shorter than the full length of the indexed column,
  19689.           because you can index a prefix of a string column.
  19690.  
  19691.         - Index `unique' or `multip.' (multiple). Indicates whether one
  19692.           value can exist multiple times in this index.
  19693.  
  19694.         - Type What data-type this index part has. This is an ISAM
  19695.           data-type with the options `packed', `stripped' or `empty'.
  19696.  
  19697.         - Root Address of the root index block.
  19698.  
  19699.         - Blocksize The size of each index block. By default this is
  19700.           1024, but the value may be changed at compile time.
  19701.  
  19702.         - Rec/key This is a statistical value used by the optimizer. It
  19703.           tells how many records there are per value for this key. A
  19704.           unique key always has a value of 1. This may be updated after
  19705.           a table is loaded (or greatly changed) with `myisamchk -a'.
  19706.           If this is not updated at all, a default value of 30 is given.
  19707.  
  19708.    * In the first example above, the 9th key is a multi-part key with
  19709.      two parts.
  19710.  
  19711.    * Keyblocks used What percentage of the keyblocks are used. Because
  19712.      the table used in the examples had just been reorganized with
  19713.      `myisamchk', the values are very high (very near the theoretical
  19714.      maximum).
  19715.  
  19716.    * Packed MySQL tries to pack keys with a common suffix. This can
  19717.      only be used for `CHAR'/`VARCHAR'/`DECIMAL' keys. For long strings
  19718.      like names, this can significantly reduce the space used. In the
  19719.      third example above, the 4th key is 10 characters long and a 60%
  19720.      reduction in space is achieved.
  19721.  
  19722.    * Max levels How deep the B-tree for this key is. Large tables with
  19723.      long keys get high values.
  19724.  
  19725.    * Records How many rows are in the table.
  19726.  
  19727.    * M.recordlength The average record length. For tables with
  19728.      fixed-length records, this is the exact record length.
  19729.  
  19730.    * Packed MySQL strips spaces from the end of strings. The `Packed'
  19731.      value indicates the percentage of savings achieved by doing this.
  19732.  
  19733.    * Recordspace used What percentage of the datafile is used.
  19734.  
  19735.    * Empty space What percentage of the datafile is unused.
  19736.  
  19737.    * Blocks/Record Average number of blocks per record (that is, how
  19738.      many links a fragmented record is composed of). This is always 1.0
  19739.      for fixed-format tables. This value should stay as close to 1.0 as
  19740.      possible. If it gets too big, you can reorganize the table with
  19741.      `myisamchk'.  *Note Optimisation::.
  19742.  
  19743.    * Recordblocks How many blocks (links) are used. For fixed format,
  19744.      this is the same as the number of records.
  19745.  
  19746.    * Deleteblocks How many blocks (links) are deleted.
  19747.  
  19748.    * Recorddata How many bytes in the datafile are used.
  19749.  
  19750.    * Deleted data How many bytes in the datafile are deleted (unused).
  19751.  
  19752.    * Lost space If a record is updated to a shorter length, some space
  19753.      is lost. This is the sum of all such losses, in bytes.
  19754.  
  19755.    * Linkdata When the dynamic table format is used, record fragments
  19756.      are linked with pointers (4 to 7 bytes each). `Linkdata' is the
  19757.      sum of the amount of storage used by all such pointers.
  19758.  
  19759. If a table has been compressed with `myisampack', `myisamchk -d' prints
  19760. additional information about each table column.  See *Note
  19761. `myisampack': myisampack, for an example of this information and a
  19762. description of what it means.
  19763.  
  19764. MySQL Localization and International Usage
  19765. ==========================================
  19766.  
  19767. The Character Set Used for Data and Sorting
  19768. -------------------------------------------
  19769.  
  19770. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  19771. sorting according to Swedish/Finnish rules. These defaults are suitable
  19772. for the USA and most of western Europe.
  19773.  
  19774. All standard MySQL binaries are compiled with
  19775. `--with-extra-charsets=complex'.  This will add code to all standard
  19776. programs to be able to handle `latin1' and all multi-byte character
  19777. sets within the binary. Other character sets will be loaded from a
  19778. character-set definition file when needed.
  19779.  
  19780. The character set determines what characters are allowed in names and
  19781. how strings are sorted by the `ORDER BY' and `GROUP BY' clauses of the
  19782. `SELECT' statement.
  19783.  
  19784. You can change the character set with the `--default-character-set'
  19785. option when you start the server.  The character sets available depend
  19786. on the `--with-charset=charset' and `--with-extra-charsets=
  19787. list-of-charset | complex | all | none' options to `configure', and the
  19788. character set configuration files listed in `SHAREDIR/charsets/Index'.
  19789. *Note configure options::.
  19790.  
  19791. If you change the character set when running MySQL (which may also
  19792. change the sort order), you must run `myisamchk -r -q
  19793. --set-character-set=charset' on all tables. Otherwise, your indexes may
  19794. not be ordered correctly.
  19795.  
  19796. When a client connects to a MySQL server, the server sends the default
  19797. character set in use to the client.  The client will switch to use this
  19798. character set for this connection.
  19799.  
  19800. One should use `mysql_real_escape_string()' when escaping strings for
  19801. an SQL query.  `mysql_real_escape_string()' is identical to the old
  19802. `mysql_escape_string()' function, except that it takes the `MYSQL'
  19803. connection handle as the first parameter.
  19804.  
  19805. If the client is compiled with different paths than where the server is
  19806. installed and the user who configured MySQL didn't include all
  19807. character sets in the MySQL binary, one must specify for the client
  19808. where it can find the additional character sets it will need if the
  19809. server runs with a different character set than the client.
  19810.  
  19811. One can specify this by putting in a MySQL option file:
  19812.  
  19813.      [client]
  19814.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  19815.  
  19816. where the path points to the directory in which the dynamic MySQL
  19817. character sets are stored.
  19818.  
  19819. One can force the client to use specific character set by specifying:
  19820.  
  19821.      [client]
  19822.      default-character-set=character-set-name
  19823.  
  19824. but normally this is never needed.
  19825.  
  19826. German character set
  19827. ....................
  19828.  
  19829. To get German sorting order, you should start `mysqld' with
  19830. `--default-character-set=latin1_de'.  This will give you the following
  19831. characteristics.
  19832.  
  19833. When sorting and comparing strings, the following mapping is done on the
  19834. strings before doing the comparison:
  19835.  
  19836.      a"  ->  ae
  19837.      o"  ->  oe
  19838.      u"  ->  ue
  19839.      ss  ->  ss
  19840.  
  19841. All accented characters, are converted to their un-accented uppercase
  19842. counterpart.  All letters are converted to uppercase.
  19843.  
  19844. When comparing strings with `LIKE' the one -> two character mapping is
  19845. not done. All letters are converted to uppercase. Accent are removed
  19846. from all letters except: `U"', `u"', `O"', `o"', `A"' and `a"'.
  19847.  
  19848. Non-English Error Messages
  19849. --------------------------
  19850.  
  19851. `mysqld' can issue error messages in the following languages: Czech,
  19852. Danish, Dutch, English (the default), Estonian, French, German, Greek,
  19853. Hungarian, Italian, Japanese, Korean, Norwegian, Norwegian-ny, Polish,
  19854. Portuguese, Romanian, Russian, Slovak, Spanish, and Swedish.
  19855.  
  19856. To start `mysqld' with a particular language, use either the
  19857. `--language=lang' or `-L lang' options. For example:
  19858.  
  19859.      shell> mysqld --language=swedish
  19860.  
  19861. or:
  19862.  
  19863.      shell> mysqld --language=/usr/local/share/swedish
  19864.  
  19865. Note that all language names are specified in lowercase.
  19866.  
  19867. The language files are located (by default) in
  19868. `MYSQL_BASE_DIR/share/LANGUAGE/'.
  19869.  
  19870. To update the error message file, you should edit the `errmsg.txt' file
  19871. and execute the following command to generate the `errmsg.sys' file:
  19872.  
  19873.      shell> comp_err errmsg.txt errmsg.sys
  19874.  
  19875. If you upgrade to a newer version of MySQL, remember to repeat your
  19876. changes with the new `errmsg.txt' file.
  19877.  
  19878. Adding a New Character Set
  19879. --------------------------
  19880.  
  19881. To add another character set to MySQL, use the following procedure.
  19882.  
  19883. Decide if the set is simple or complex.  If the character set does not
  19884. need to use special string collating routines for sorting and does not
  19885. need multi-byte character support, it is simple.  If it needs either of
  19886. those features, it is complex.
  19887.  
  19888. For example, `latin1' and `danish' are simple charactersets while
  19889. `big5' or `czech' are complex character sets.
  19890.  
  19891. In the following section, we have assumed that you name your character
  19892. set `MYSET'.
  19893.  
  19894. For a simple character set do the following:
  19895.  
  19896.   1. Add MYSET to the end of the `sql/share/charsets/Index' file Assign
  19897.      a unique number to it.
  19898.  
  19899.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use
  19900.      `sql/share/charsets/latin1.conf' as a base for this.)
  19901.  
  19902.      The syntax for the file is very simple:
  19903.  
  19904.         * Comments start with a '#' character and proceed to the end of
  19905.           the line.
  19906.  
  19907.         * Words are separated by arbitrary amounts of whitespace.
  19908.  
  19909.         * When defining the character set, every word must be a number
  19910.           in hexadecimal format
  19911.  
  19912.         * The `ctype' array takes up the first 257 words. The
  19913.           `to_lower[]', `to_upper[]' and `sort_order[]' arrays take up
  19914.           256 words each after that.
  19915.  
  19916.      *Note Character arrays::.
  19917.  
  19918.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  19919.      `COMPILED_CHARSETS' lists in `configure.in'.
  19920.  
  19921.   4. Reconfigure, recompile, and test.
  19922.  
  19923.  
  19924. For a complex character set do the following:
  19925.  
  19926.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  19927.      distribution.
  19928.  
  19929.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  19930.      Assign a unique number to it.
  19931.  
  19932.   3. Look at one of the existing `ctype-*.c' files to see what needs to
  19933.      be defined, for example `strings/ctype-big5.c'. Note that the
  19934.      arrays in your file must have names like `ctype_MYSET',
  19935.      `to_lower_MYSET', and so on.  This corresponds to the arrays in
  19936.      the simple character set. *Note Character arrays::.
  19937.  
  19938.   4. Near the top of the file, place a special comment like this:
  19939.  
  19940.           /*
  19941.            * This comment is parsed by configure to create ctype.c,
  19942.            * so don't change it unless you know what you are doing.
  19943.            *
  19944.            * .configure. number_MYSET=MYNUMBER
  19945.            * .configure. strxfrm_multiply_MYSET=N
  19946.            * .configure. mbmaxlen_MYSET=N
  19947.            */
  19948.  
  19949.      The `configure' program uses this comment to include the character
  19950.      set into the MySQL library automatically.
  19951.  
  19952.      The strxfrm_multiply and mbmaxlen lines will be explained in the
  19953.      following sections.  Only include these if you need the string
  19954.      collating functions or the multi-byte character set functions,
  19955.      respectively.
  19956.  
  19957.   5. You should then create some of the following functions:
  19958.  
  19959.         * `my_strncoll_MYSET()'
  19960.  
  19961.         * `my_strcoll_MYSET()'
  19962.  
  19963.         * `my_strxfrm_MYSET()'
  19964.  
  19965.         * `my_like_range_MYSET()'
  19966.  
  19967.      *Note String collating::.
  19968.  
  19969.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  19970.      `COMPILED_CHARSETS' lists in `configure.in'.
  19971.  
  19972.   7. Reconfigure, recompile, and test.
  19973.  
  19974. The file `sql/share/charsets/README' includes some more instructions.
  19975.  
  19976. If you want to have the character set included in the MySQL
  19977. distribution, mail a patch to the MySQL internals mailing list.  *Note
  19978. Mailing-list::.
  19979.  
  19980. The Character Definition Arrays
  19981. -------------------------------
  19982.  
  19983. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  19984. and uppercase characters corresponding to each member of the character
  19985. set.  For example:
  19986.  
  19987.      to_lower['A'] should contain 'a'
  19988.      to_upper['a'] should contain 'A'
  19989.  
  19990. `sort_order[]' is a map indicating how characters should be ordered for
  19991. comparison and sorting purposes. Quite often (but not for all character
  19992. sets) this is the same as `to_upper[]' (which means sorting will be
  19993. case-insensitive). MySQL will sort characters based on the value of
  19994. `sort_order[character]'.  For more complicated sorting rules, see the
  19995. discussion of string collating below. *Note String collating::.
  19996.  
  19997. `ctype[]' is an array of bit values, with one element for one character.
  19998. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  19999. by character value, but `ctype[]' is indexed by character value + 1.
  20000. This is an old legacy to be able to handle `EOF'.)
  20001.  
  20002. You can find the following bitmask definitions in `m_ctype.h':
  20003.  
  20004.      #define _U      01      /* Uppercase */
  20005.      #define _L      02      /* Lowercase */
  20006.      #define _N      04      /* Numeral (digit) */
  20007.      #define _S      010     /* Spacing character */
  20008.      #define _P      020     /* Punctuation */
  20009.      #define _C      040     /* Control character */
  20010.      #define _B      0100    /* Blank */
  20011.      #define _X      0200    /* heXadecimal digit */
  20012.  
  20013. The `ctype[]' entry for each character should be the union of the
  20014. applicable bitmask values that describe the character.  For example,
  20015. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  20016. (`_X'), so `ctype['A'+1]' should contain the value:
  20017.  
  20018.      _U + _X = 01 + 0200 = 0201
  20019.  
  20020. String Collating Support
  20021. ------------------------
  20022.  
  20023. If the sorting rules for your language are too complex to be handled
  20024. with the simple `sort_order[]' table, you need to use the string
  20025. collating functions.
  20026.  
  20027. Right now the best documentation on this is the character sets that are
  20028. already implemented.  Look at the `big5', `czech', `gbk', `sjis', and
  20029. `tis160' character sets for examples.
  20030.  
  20031. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  20032. comment at the top of the file.  `N' should be set to the maximum ratio
  20033. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  20034. integer).
  20035.  
  20036. Multi-byte Character Support
  20037. ----------------------------
  20038.  
  20039. If your want to add support for a new character set that includes
  20040. multi-byte characters, you need to use the multi-byte character
  20041. functions.
  20042.  
  20043. Right now the best documentation on this is the character sets that are
  20044. already implemented.  Look at the `euc_kr', `gb2312', `gbk', `sjis',
  20045. and `ujis' character sets for examples. These are implemented in the
  20046. `ctype-'charset'.c' files in the `strings' directory.
  20047.  
  20048. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  20049. the top of the source file.  `N' should be set to the size in bytes of
  20050. the largest character in the set.
  20051.  
  20052. Problems With Character Sets
  20053. ----------------------------
  20054.  
  20055. If you try to use a character set that is not compiled into your binary,
  20056. you can run into a couple of different problems:
  20057.  
  20058.    * Your program has a wrong path to where the character sets are
  20059.      stored.  (Default `/usr/local/mysql/share/mysql/charsets').  This
  20060.      can be fixed by using the `--character-sets-dir' option to the
  20061.      program in question.
  20062.  
  20063.    * The character set is a multi-byte character set that can't be
  20064.      loaded dynamically.  In this case you have to recompile the
  20065.      program with the support for the character set.
  20066.  
  20067.    * The character set is a dynamic character set, but you don't have a
  20068.      configure file for it.  In this case you should install the
  20069.      configure file for the character set from a new MySQL distribution.
  20070.  
  20071.    * Your `Index' file doesn't contain the name for the character set.
  20072.  
  20073.           ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf' not found
  20074.           (Errcode: 2)
  20075.  
  20076.      In this case you should either get a new `Index' file or add by
  20077.      hand the name of any missing character sets.
  20078.  
  20079. For `MyISAM' tables, you can check the character set name and number
  20080. for a table with `myisamchk -dvv table_name'.
  20081.  
  20082. The MySQL Log Files
  20083. ===================
  20084.  
  20085. MySQL has several different log files that can help you find out what's
  20086. going on inside `mysqld':
  20087.  
  20088. *Log file*     *Description*
  20089. The error log  Problems encountering starting, running or stopping
  20090.                `mysqld'.
  20091. The isam log   Logs all changes to the ISAM tables. Used only for
  20092.                debugging the isam code.
  20093. The query log  Established connections and executed queries.
  20094. The update     Deprecated: Stores all statements that changes data
  20095. log            
  20096. The binary     Stores all statements that changes something. Used also
  20097. log            for replication
  20098. The slow log   Stores all queries that took more than `long_query_time'
  20099.                seconds to execute or didn't use indexes.
  20100.  
  20101. All logs can be found in the `mysqld' data directory.  You can force
  20102. `mysqld' to reopen the log files (or in some cases switch to a new log)
  20103. by executing `FLUSH LOGS'. *Note FLUSH::.
  20104.  
  20105. The Error Log
  20106. -------------
  20107.  
  20108. The error log file contains information indicating when `mysqld' was
  20109. started and stopped and also any critical errors found when running.
  20110.  
  20111. If `mysqld' dies unexpectedly and `mysqld_safe' needs to restart
  20112. `mysqld', `mysqld_safe' will write a `restarted mysqld' row in this
  20113. file.  This log also holds a warning if `mysqld' notices a table that
  20114. needs to be automatically checked or repaired.
  20115.  
  20116. On some operating systems, the error log will contain a stack trace for
  20117. where `mysqld' died. This can be used to find out where `mysqld' died.
  20118. *Note Using stack trace::.
  20119.  
  20120. Beginning with MySQL 4.0.10 you can specify where `mysqld' stores the
  20121. error log file with the option `--log-error[=filename]'. If no file
  20122. name is given `mysqld' will use `mysql-data-dir/'hostname'.err' on Unix
  20123. and `\mysql\data\mysql.err' on Windows.  If you execute `flush logs'
  20124. the old file will be prefixed with `--old' and `mysqld' will create a
  20125. new empty log file.
  20126.  
  20127. In older MySQL versions the error log handling was done by
  20128. `mysqld_safe' which redirected the error file to `'hostname'.err'.  One
  20129. could change this file name with the option `--err-log=filename'.
  20130.  
  20131. If you don't specify `--log-error' or if you use the `--console' option
  20132. the errors will be written to stderr (the terminal).
  20133.  
  20134. On Windows, the output is always written to the `.err' file if
  20135. `--console' is not given.
  20136.  
  20137. The General Query Log
  20138. ---------------------
  20139.  
  20140. If you want to know what happens within `mysqld', you should start it
  20141. with `--log[=file]'.  This will log all connections and queries to the
  20142. log file (by default named `'hostname'.log').  This log can be very
  20143. useful when you suspect an error in a client and want to know exactly
  20144. what `mysqld' thought the client sent to it.
  20145.  
  20146. Older versions of the `mysql.server' script (from MySQL 3.23.4 to
  20147. 3.23.8) pass `safe_mysqld' a `--log' option (enable general query log).
  20148. If you need better performance when you start using MySQL in a
  20149. production environment, you can remove the `--log' option from
  20150. `mysql.server' or change it to `--log-bin'. *Note Binary log::.
  20151.  
  20152. The entries in this log are written as `mysqld' receives the questions.
  20153. This may be different from the order in which the statements are
  20154. executed.  This is in contrast to the update log and the binary log
  20155. which are written after the query is executed, but before any locks are
  20156. released.
  20157.  
  20158. The Update Log
  20159. --------------
  20160.  
  20161. *Note:* The update log has been deprecated and replaced by the binary
  20162. log. *Note Binary log::.  The binary log can do anything the old update
  20163. log could do, and more. *The update log is removed starting from MySQL
  20164. 5.0.0*.
  20165.  
  20166. When started with the `--log-update[=file_name]' option, `mysqld'
  20167. writes a log file containing all SQL commands that update data. If no
  20168. filename is given, it defaults to the name of the host machine. If a
  20169. filename is given, but it doesn't contain a path, the file is written
  20170. in the data directory. If `file_name' doesn't have an extension,
  20171. `mysqld' will create log file names like so: `file_name.###', where
  20172. `###' is a number that is incremented each time you execute `mysqladmin
  20173. refresh', execute `mysqladmin flush-logs', execute the `FLUSH LOGS'
  20174. statement, or restart the server.
  20175.  
  20176. *Note:* For the above scheme to work, you must not create your own
  20177. files with the same filename as the update log + some extensions that
  20178. may be regarded as a number, in the directory used by the update log!
  20179.  
  20180. If you use the `--log' or `-l' options, `mysqld' writes a general log
  20181. with a filename of `hostname.log', and restarts and refreshes do not
  20182. cause a new log file to be generated (although it is closed and
  20183. reopened). In this case you can copy it (on Unix) by doing:
  20184.  
  20185.      mv hostname.log hostname-old.log
  20186.      mysqladmin flush-logs
  20187.      cp hostname-old.log to-backup-directory
  20188.      rm hostname-old.log
  20189.  
  20190. Update logging is smart because it logs only statements that really
  20191. update data. So an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  20192. rows is not written to the log. It even skips `UPDATE' statements that
  20193. set a column to the value it already has.
  20194.  
  20195. The update logging is done immediately after a query completes but
  20196. before any locks are released or any commit is done. This ensures that
  20197. the log will be logged in the execution order.
  20198.  
  20199. If you want to update a database from update log files, you could do the
  20200. following (assuming your update logs have names of the form
  20201. `file_name.###'):
  20202.  
  20203.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  20204.  
  20205. `ls' is used to get all the log files in the right order.
  20206.  
  20207. This can be useful if you have to revert to backup files after a crash
  20208. and you want to redo the updates that occurred between the time of the
  20209. backup and the crash.
  20210.  
  20211. The Binary Log
  20212. --------------
  20213.  
  20214. The binary log has replaced the old update log. The update log is
  20215. removed starting from MySQL 5.0. The binary log contains all
  20216. information that is available in the update log in a more efficient
  20217. format and in a manner that is transactionally safe.
  20218.  
  20219. The binary log, like the old update log, only logs statements that
  20220. really update data. So an `UPDATE' or a `DELETE' with a `WHERE' that
  20221. finds no rows is not written to the log. It even skips `UPDATE'
  20222. statements that set a column to the value it already has.
  20223.  
  20224. The primary purpose of the binary log is to be able to update the
  20225. database during a restore operation as fully as possible, as the binary
  20226. log would contain all updates done after a backup was made.
  20227.  
  20228. The binary log is also used when you are replicating a slave from a
  20229. master.  *Note Replication::.
  20230.  
  20231. The binary log also contains information about how long each query took
  20232. that updated the database.  It doesn't contain queries that don't modify
  20233. any data.  If you want to log all queries (for example to find a problem
  20234. query) you should use the general query log. *Note Query log::.
  20235.  
  20236. When started with the `--log-bin[=file_name]' option, `mysqld' writes a
  20237. log file containing all SQL commands that update data. If no file name
  20238. is given, it defaults to the name of the host machine followed by
  20239. `-bin'. If file name is given, but it doesn't contain a path, the file
  20240. is written in the data directory.
  20241.  
  20242. If you supply an extension to `--log-bin=filename.extension', the
  20243. extension will be silenty removed.
  20244.  
  20245. To the binary log filename `mysqld' will append an extension that is a
  20246. number that is incremented each time you execute `mysqladmin refresh',
  20247. execute `mysqladmin flush-logs', execute the `FLUSH LOGS' statement or
  20248. restart the server. A new binary log will also automatically be created
  20249. when the current one's size reaches `max_binlog_size'. Note if you are
  20250. using transactions: a transaction is written in one chunk to the binary
  20251. log, hence it is never split between several binary logs. Therefore, if
  20252. you have big transactions, you may see binlogs bigger than
  20253. `max_binlog_size'.
  20254.  
  20255. You can delete all binary log files with the `RESET MASTER' command
  20256. (*note `RESET': RESET.), or only some of them with `PURGE MASTER LOGS'
  20257. (*note Replication Master SQL::).
  20258.  
  20259. You can use the following options to `mysqld' to affect what is logged
  20260. to the binary log (please make sure to read the notes which follow this
  20261. table):
  20262.  
  20263. *Option*                    *Description*
  20264. `binlog-do-db=database_name' Tells the master that it should log updates
  20265.                             to the binary log if the current database
  20266.                             (that is, the one selected by `USE')
  20267.                             database is 'database_name'. All others
  20268.                             databases which are not explicitly mentioned
  20269.                             are ignored.  Note that if you use this you
  20270.                             should ensure that you only do updates in
  20271.                             the current database.  (Example:
  20272.                             `binlog-do-db=some_database')
  20273.                             
  20274.                             Example of what does not work as you could
  20275.                             expect it: if the server is started with
  20276.                             `binlog-do-db=sales', and you do `USE
  20277.                             prices; UPDATE sales.january SET
  20278.                             amount=amount+1000;', this query will not be
  20279.                             written into the binary log.
  20280. `binlog-ignore-db=database_name' Tells the master that updates where the
  20281.                             current database (that is, the one selected
  20282.                             by `USE') is 'database_name' should not be
  20283.                             stored in the binary log.  Note that if you
  20284.                             use this you should ensure that you only do
  20285.                             updates in the current database.  (Example:
  20286.                             `binlog-ignore-db=some_database')
  20287.                             
  20288.                             Example of what does not work as you could
  20289.                             expect it: if the server is started with
  20290.                             `binlog-ignore-db=sales', and you do `USE
  20291.                             prices; UPDATE sales.january SET
  20292.                             amount=amount+1000;', this query will be
  20293.                             written into the binary log.
  20294.  
  20295. The rules are evaluated in the following order, to decide if the query
  20296. should be written to the binary log or not:
  20297.   1. Are there `binlog-do-db' or `binlog-ignore-db' rules?
  20298.         * No: write the query to the binlog and exit.
  20299.  
  20300.         * Yes: go to step below.
  20301.  
  20302.   2. So there are some rules (`binlog-do-db' or `binlog-ignore-db' or
  20303.      both). Is there a current database (has any database been selected
  20304.      by `USE'?)?
  20305.         * No: do *NOT* write the query, and exit.
  20306.  
  20307.         * Yes: go to step below.
  20308.  
  20309.   3. There is a current database. Are there some `binlog-do-db' rules?
  20310.         * Yes: Does the current database match any of the `binlog-do-db'
  20311.           rules?
  20312.              * Yes: write the query and exit.
  20313.  
  20314.              * No: do *NOT* write the query, and exit.
  20315.  
  20316.         * No: go to step below.
  20317.  
  20318.   4. There are some `binlog-ignore-db' rules.  Does the current
  20319.      database match any of the `binlog-ignore-db' rules?
  20320.         * Yes: do not write the query, and exit.
  20321.  
  20322.         * No: write the query and exit.
  20323.  
  20324. So for example, a slave running with only `binlog-do-db=sales' will not
  20325. write to the binlog any query whose current database is different from
  20326. `sales' (in other words, `binlog-do-db' can sometimes mean "ignore
  20327. other databases").
  20328.  
  20329. To be able to know which different binary log files have been used,
  20330. `mysqld' will also create a binary log index file that contains the
  20331. name of all used binary log files. By default this has the same name as
  20332. the binary log file, with the extension `'.index''.  You can change the
  20333. name of the binary log index file with the `--log-bin-index=[filename]'
  20334. option.  You should not manually edit this file while `mysqld' is
  20335. running; doing this would confuse `mysqld'.
  20336.  
  20337. If you are using replication, you should not delete old binary log
  20338. files until you are sure that no slave will ever need to use them.  One
  20339. way to do this is to do `mysqladmin flush-logs' once a day and then
  20340. remove any logs that are more than 3 days old. You can remove them
  20341. manually, or preferably using `PURGE MASTER LOGS' (*note Replication
  20342. Master SQL::) which will also safely update the binary log index file
  20343. for you  (and which can take a date argument since MySQL 4.1)
  20344.  
  20345. A connection with the `SUPER' privilege can disable the binary logging
  20346. of its queries using `SET SQL_LOG_BIN=0'. *Note Replication Master
  20347. SQL::.
  20348.  
  20349. You can examine the binary log file with the `mysqlbinlog' utility.
  20350. For example, you can update a MySQL server from the binary log as
  20351. follows:
  20352.  
  20353.      shell> mysqlbinlog log-file | mysql -h server_name
  20354.  
  20355. See *Note mysqlbinlog:: for more information on the `mysqlbinlog'
  20356. utility and how to use it.
  20357.  
  20358. If you are using `BEGIN [WORK]' or `SET AUTOCOMMIT=0', you must use the
  20359. MySQL binary log for backups instead of the old update log, which will
  20360. is removed in MySQL 5.0.0.
  20361.  
  20362. The binary logging is done immediately after a query completes but
  20363. before any locks are released or any commit is done. This ensures that
  20364. the log will be logged in the execution order.
  20365.  
  20366. Updates to non-transactional tables are stored in the binary log
  20367. immediately after execution.  For transactional tables such as `BDB' or
  20368. `InnoDB' tables, all updates (`UPDATE', `DELETE' or `INSERT') that
  20369. change tables are cached until a `COMMIT' command is sent to the
  20370. server. At this point `mysqld' writes the whole transaction to the
  20371. binary log before the `COMMIT' is executed.  Every thread will, on
  20372. start, allocate a buffer of `binlog_cache_size' to buffer queries.  If
  20373. a query is bigger than this, the thread will open a temporary file to
  20374. store the transaction.  The temporary file will be deleted when the
  20375. thread ends.
  20376.  
  20377. The `max_binlog_cache_size' (default 4G) can be used to restrict the
  20378. total size used to cache a multi-query transaction.  If a transaction is
  20379. bigger than this it will fail and roll back.
  20380.  
  20381. If you are using the update or binary log, concurrent inserts will be
  20382. converted to normal inserts when using `CREATE ... SELECT' or `INSERT
  20383. ... SELECT'.  This is to ensure that you can re-create an exact copy of
  20384. your tables by applying the log on a backup.
  20385.  
  20386. The binary log format is different in versions 3.23, 4.0, and 5.0.0.
  20387. Those format changes were required to enhance replication.  MySQL 4.1
  20388. has the same binary log format as 4.0.
  20389.  
  20390. The Slow Query Log
  20391. ------------------
  20392.  
  20393. When started with the `--log-slow-queries[=file_name]' option, `mysqld'
  20394. writes a log file containing all SQL commands that took more than
  20395. `long_query_time' seconds to execute. The time to get the initial table
  20396. locks are not counted as execution time.
  20397.  
  20398. The slow query log is logged after the query is executed and after all
  20399. locks has been released. This may be different from the order in which
  20400. the statements are executed.
  20401.  
  20402. If no file name is given, it defaults to the name of the host machine
  20403. suffixed with `-slow.log'. If a filename is given, but doesn't contain
  20404. a path, the file is written in the data directory.
  20405.  
  20406. The slow query log can be used to find queries that take a long time to
  20407. execute and are thus candidates for optimization. With a large log, that
  20408. can become a difficult task. You can pipe the slow query log through the
  20409. `mysqldumpslow' command to get a summary of the queries which appear in
  20410. the log.
  20411.  
  20412. You are using `--log-long-format' then also queries that are not using
  20413. indexes are printed. *Note Server options::.
  20414.  
  20415. Log File Maintenance
  20416. --------------------
  20417.  
  20418. The MySQL Server can create a number of different log files, which make
  20419. it easy to see what is going on. *Note Log Files::. However, you must
  20420. clean up these files regularly, to ensure that the logs don't take up
  20421. too much disk space.
  20422.  
  20423. When using MySQL with log files, you will want to remove/backup old log
  20424. files from time to time and tell MySQL to start logging to new files.
  20425. *Note Backup::.
  20426.  
  20427. On a Linux (`Red Hat') installation, you can use the `mysql-log-rotate'
  20428. script for this. If you installed MySQL from an RPM distribution, the
  20429. script should have been installed automatically.  Note that you should
  20430. be careful with this script if you are using the binary log for
  20431. replication!
  20432.  
  20433. On other systems you must install a short script yourself that you
  20434. start from `cron' to handle log files.
  20435.  
  20436. You can force MySQL to start using new log files by using `mysqladmin
  20437. flush-logs' or by using the SQL command `FLUSH LOGS'.  If you are using
  20438. MySQL Version 3.21, you must use `mysqladmin refresh'.
  20439.  
  20440. The above command does the following:
  20441.  
  20442.    * If standard logging (`--log') or slow query logging
  20443.      (`--log-slow-queries') is used, closes and reopens the log file
  20444.      (`mysql.log' and ``hostname`-slow.log' as default).
  20445.  
  20446.    * If update logging (`--log-update') is used, closes the update log
  20447.      and opens a new log file with a higher sequence number.
  20448.  
  20449. If you are using only an update log, you only have to flush the logs
  20450. and then move away the old update log files to a backup.  If you are
  20451. using the normal logging, you can do something like:
  20452.  
  20453.      shell> cd mysql-data-directory
  20454.      shell> mv mysql.log mysql.old
  20455.      shell> mysqladmin flush-logs
  20456.  
  20457. and then take a backup and remove `mysql.old'.
  20458.  
  20459. Running Multiple MySQL Servers on the Same Machine
  20460. ==================================================
  20461.  
  20462. In some cases you might want to run multiple `mysqld' servers on the
  20463. same machine.  You might want to test a new MySQL release while leaving
  20464. your existing production setup undisturbed.  Or you may want to give
  20465. different users access to different `mysqld' servers that they manage
  20466. themselves.  (For example, you might be an Internet service provider
  20467. that wants to provide independent MySQL installations for different
  20468. customers.)
  20469.  
  20470. To run multiple servers on a single machine, each server must have
  20471. unique values for several operating parameters. These can be set on the
  20472. command line or in option files.  *Note Program Options::.
  20473.  
  20474. At least the following options must be different for each server:
  20475.  
  20476.    * `--port=port_num'
  20477.  
  20478.    * `--socket=path'
  20479.  
  20480.    * `--shared-memory-base-name=name' (Windows only; new in MySQL 4.1)
  20481.  
  20482.    * `--pid-file=path' (Unix only)
  20483.  
  20484. `--port' controls the port number for TCP/IP connections.  `--socket'
  20485. controls the socket file path on Unix and the name of the named pipe on
  20486. Windows. (It's necessary to specify distinct pipe names on Windows only
  20487. for those servers that support named pipe connections.)
  20488. `--shared-memory-base-name' designates the shared memory name used by a
  20489. Windows server to allow clients to connect via shared memory.
  20490. `--pid-file' indicates the name of the file in which a Unix server
  20491. writes its process ID.
  20492.  
  20493. If you use the following options, they must be different for each
  20494. server:
  20495.  
  20496.    * `--log=path'
  20497.  
  20498.    * `--log-bin=path'
  20499.  
  20500.    * `--log-update=path'
  20501.  
  20502.    * `--log-error=path'
  20503.  
  20504.    * `--log-isam=path'
  20505.  
  20506.    * `--bdb-logdir=path'
  20507.  
  20508. If you want more performance, you can also specify the following options
  20509. differently for each server, to spread load between several physical
  20510. disks:
  20511.  
  20512.    * `--tmpdir=path'
  20513.  
  20514.    * `--bdb-tmpdir=path'
  20515.  
  20516. Having different temporary directories like above is also recommended
  20517. because it will be easier for you in case you want to know to which
  20518. MySQL server a certain temporary file belongs.
  20519.  
  20520. Generally, each server should also use a different data directory,
  20521. which is specified using the `--datadir=path' option.
  20522.  
  20523. *Warning:* Normally you should never have two servers that update data
  20524. in the same databases!  This may lead to unpleasant surprises if your
  20525. operating system doesn't support fault-free system locking!  If
  20526. (despite this warning) you run multiple servers using the same data
  20527. directory and they have logging enabled, you must use the appropriate
  20528. options to specify log file names that are unique to each server.
  20529. Otherwise, the servers will try to log to the same files.
  20530.  
  20531. This warning against sharing a data directory among servers also applies
  20532. in an NFS environment.  Allowing multiple MySQL servers to access a
  20533. common data directory over NFS is a *bad idea*!
  20534.  
  20535.    * The primary problem is that NFS will become the speed bottleneck.
  20536.      It is not meant for such use.
  20537.  
  20538.    * Another risk with NFS is that you will have to come up with a way
  20539.      to make sure that two or more servers do not interfere with each
  20540.      other.  Usually NFS file locking is handled by the `lockd' daemon,
  20541.      but at the moment there is no platform that will perform locking
  20542.      100% reliably in every situation.
  20543.  
  20544.  
  20545. Make it easy for yourself: Forget about sharing a data directory among
  20546. servers over NFS. A better solution is to have one computer that
  20547. contains several CPUs and use an operating system that handles threads
  20548. efficiently.
  20549.  
  20550. If you have multiple MySQL installations in different locations,
  20551. normally you can specify the base installation directory for each
  20552. server with the `--basedir=path' option to cause each server to use a
  20553. different data directory, log files, and PID file. (The defaults for
  20554. all these values are determined relative to the base directory.) In
  20555. that case, the only other options you need to specify are the
  20556. `--socket' and `--port' options.  For example, suppose you install
  20557. different versions of MySQL using `.tar' file binary distributions.
  20558. These will install in different locations, so you can start the server
  20559. for each installation using the command `./bin/mysqld_safe' under its
  20560. corresponding base directory.  `mysqld_safe' will determine the proper
  20561. `--basedir' option to pass to `mysqld', and you need specify only the
  20562. `--socket' and `--port' options to `mysqld_safe'.
  20563.  
  20564. As discussed in the following sections, it is possible to start
  20565. additional servers by setting environment variables or by specifying
  20566. appropriate command-line options.  However, if you need to run multiple
  20567. servers on a more permanent basis, it will be more convenient to use
  20568. option files to specify for each server those option values that must
  20569. be unique to it.
  20570.  
  20571. Running Multiple Servers on Windows
  20572. -----------------------------------
  20573.  
  20574. You can run multiple servers on Windows by starting them manually from
  20575. the command line, each with appropriate operating parameters. On
  20576. Windows NT-based systems, you also have the option of installing
  20577. several servers as Windows services and running them that way. General
  20578. instructions for running MySQL servers from the command line or as
  20579. services are given in *Note Windows installation::. This section
  20580. describes how to make sure you start each server with different values
  20581. for those startup options that must be unique per server, such as the
  20582. data directory.  (These options are described in *Note Multiple
  20583. servers::.)
  20584.  
  20585. Starting Multiple Windows Servers at the Command Line
  20586. .....................................................
  20587.  
  20588. To start multiple servers manually from the command line, you can
  20589. specify the appropriate options on the command line or in an option
  20590. file. It's more convenient to place the options in an option file, but
  20591. it's necessary to make sure that each server gets its own set of
  20592. options. To do this, create an option file for each server and tell the
  20593. server the filename with a `--defaults-file' option when you run it.
  20594.  
  20595. Suppose you want to run `mysqld' on port 3307 with a data directory of
  20596. `C:\mydata1', and `mysqld-max' on port 3308 with a data directory of
  20597. `C:\mydata2'. To accomplish this, create two option files. For example,
  20598. create one file named `C:\my-opts1.cnf' that looks like this:
  20599.  
  20600.      [mysqld]
  20601.      datadir = C:/mydata1
  20602.      port = 3307
  20603.  
  20604. Create a second file named `C:\my-opts2.cnf' that looks like this:
  20605.  
  20606.      [mysqld]
  20607.      datadir = C:/mydata2
  20608.      port = 3308
  20609.  
  20610. Then start each server with its own option file:
  20611.  
  20612.      shell> mysqld --defaults-file=C:\my-opts1.cnf
  20613.      shell> mysqld-max --defaults-file=C:\my-opts2.cnf
  20614.  
  20615. (On NT, the servers will start in the foreground, so you'll need to
  20616. issue those two commands in separate console windows.)
  20617.  
  20618. To shut down the servers, you must connect to the appropriate port
  20619. number:
  20620.  
  20621.      shell> mysqladmin --port=3307 shutdown
  20622.      shell> mysqladmin --port=3308 shutdown
  20623.  
  20624. Servers configured as just described will allow clients to connect over
  20625. TCP/IP.  If you also want to allow named pipe connections, use the
  20626. `mysqld-nt' or `mysqld-max-nt' servers and specify options that enable
  20627. the named pipe and specify its name. (Each server that supports named
  20628. pipe connections must use a unique pipe name.)  For example, the
  20629. `C:\my-opts1.cnf' file might be written like this:
  20630.  
  20631.      [mysqld]
  20632.      datadir = C:/mydata1
  20633.      port = 3307
  20634.      enable-named-pipe
  20635.      socket = mypipe1
  20636.  
  20637. Then start the server this way:
  20638.  
  20639.      shell> mysqld-nt --defaults-file=C:\my-opts1.cnf
  20640.  
  20641. `C:\my-opts2.cnf' would be modified similarly for use by the second
  20642. server.
  20643.  
  20644. Starting Multiple Windows Servers as Services
  20645. .............................................
  20646.  
  20647. On NT-based systems, a MySQL server can be run as a Windows service. The
  20648. procedures for installing, controlling, and removing a single MySQL
  20649. service are described in *Note NT start::.
  20650.  
  20651. As of MySQL 4.0.2, you can install multiple servers as services.  In
  20652. this case, you must make sure that each server uses a different service
  20653. name in addition to all the other parameters that must be unique per
  20654. server.
  20655.  
  20656. For the following instructions, assume that you want to run the
  20657. `mysqld-nt' server from two different versions of MySQL that are
  20658. installed at `C:\mysql-4.0.8' and `C:\mysql-4.0.17', respectively.
  20659. (This might be the case if you're running 4.0.8 as your production
  20660. server, but want to test 4.0.17 before upgrading to it.)
  20661.  
  20662. The following principles are relevant when installing a MySQL service
  20663. with the `--install' option:
  20664.  
  20665.    * If you specify no service name, the server uses the default
  20666.      service name of `MySQL' and the server reads options from the
  20667.      `[mysqld]' group in the standard option files.
  20668.  
  20669.    * If you specify a service name after the `--install' option, the
  20670.      server ignores the `[mysqld]' option group and instead reads
  20671.      options from the group that has the same name as the service. The
  20672.      server reads options from the standard option files.
  20673.  
  20674.    * If you specify a `--defaults-file' option after the service name,
  20675.      the server ignores the standard option files and reads options
  20676.      only from the `[mysqld]' group of the named file.
  20677.  
  20678.  
  20679. These principles also apply if you install a server using the
  20680. `--install-manual' option.
  20681.  
  20682. Based on the preceding information, you have several ways to set up
  20683. multiple services.  The following instructions describe some examples.
  20684. Before trying any of them, be sure you shut down and remove any
  20685. existing MySQL services first.
  20686.  
  20687.    * Specify the options for all services in one of the standard option
  20688.      files.  To do this, use a different service name for each server.
  20689.      Suppose you want to run the 4.0.8 `mysqld-nt' using the service
  20690.      name of `mysqld1' and the 4.0.17 `mysqld-nt' using the service
  20691.      name `mysqld2'.  In this case, you can use the `[mysqld1]' group
  20692.      for 4.0.8 and the `[mysqld2]' group for 4.0.17.  For example, you
  20693.      can set up `C:\my.cnf' like this:
  20694.  
  20695.           # options for mysqld1 service
  20696.           [mysqld1]
  20697.           basedir = C:/mysql-4.0.8
  20698.           port = 3307
  20699.           enable-named-pipe
  20700.           socket = mypipe1
  20701.           
  20702.           # options for mysqld2 service
  20703.           [mysqld2]
  20704.           basedir = C:/mysql-4.0.17
  20705.           port = 3308
  20706.           enable-named-pipe
  20707.           socket = mypipe2
  20708.  
  20709.      Install the services as follows, using the full server pathnames
  20710.      to ensure that Windows registers the correct executable program
  20711.      for each service:
  20712.  
  20713.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install mysqld1
  20714.           shell> C:\mysql-4.0.17\bin\mysqld-nt --install mysqld2
  20715.  
  20716.      To start the services, use the services manager, or use `NET START'
  20717.      with the appropriate service names:
  20718.  
  20719.           shell> NET START mysqld1
  20720.           shell> NET START mysqld2
  20721.  
  20722.      To stop the services, use the services manager, or use `NET STOP'
  20723.      with the appropriate service names:
  20724.  
  20725.           shell> NET STOP mysqld1
  20726.           shell> NET STOP mysqld2
  20727.  
  20728.      Note: Before MySQL 4.0.17, only a server installed using the
  20729.      default service name (`MySQL') or one installed explicitly with a
  20730.      service name of `mysqld' will read the `[mysqld]' group in the
  20731.      standard option files. As of 4.0.17, all servers read the
  20732.      `[mysqld' group if they read the standard option files, even if
  20733.      they are installed using another service name. This allows you to
  20734.      use the `[mysqld]' group for options that should be used by all
  20735.      MySQL services, and an option group named after each service for
  20736.      use by the server installed with that service name.
  20737.  
  20738.    * Specify options for each server in separate files and use
  20739.      `--defaults-file' when you install the services to tell each server
  20740.      what file to use.  In this case, each file should list options
  20741.      using a `[mysqld]' group.
  20742.  
  20743.      With this approach, to specify options for the 4.0.8 `mysqld-nt',
  20744.      create a file `C:\my-opts1.cnf' that looks like this:
  20745.  
  20746.           [mysqld]
  20747.           basedir = C:/mysql-4.0.8
  20748.           port = 3307
  20749.           enable-named-pipe
  20750.           socket = mypipe1
  20751.  
  20752.      For the 4.0.17 `mysqld-nt', create a file `C:\my-opts2.cnf' that
  20753.      looks like this:
  20754.  
  20755.           [mysqld]
  20756.           basedir = C:/mysql-4.0.17
  20757.           port = 3308
  20758.           enable-named-pipe
  20759.           socket = mypipe2
  20760.  
  20761.      Install the services as follows (enter each command on a single
  20762.      line):
  20763.  
  20764.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install mysqld1
  20765.                      --defaults-file=C:\my-opts1.cnf
  20766.           shell> C:\mysql-4.0.17\bin\mysqld-nt --install mysqld2
  20767.                      --defaults-file=C:\my-opts2.cnf
  20768.  
  20769.      To use a `--defaults-file' option when you install a MySQL server
  20770.      as a service, you must precede the option with the service name.
  20771.  
  20772.      After installing the services, start and stop them the same way as
  20773.      in the preceding example.
  20774.  
  20775.  
  20776. To remove multiple services, use `mysqld --remove' for each one,
  20777. specifying a service name following the `--remove' option if the
  20778. service to remove has a name different than the default.
  20779.  
  20780. Running Multiple Servers on Unix
  20781. --------------------------------
  20782.  
  20783. The easiest way is to run multiple servers on Unix is to compile them
  20784. with different TCP/IP ports and socket files so that each one is
  20785. listening on different network interfaces. Also, by compiling in
  20786. different base directories for each installation, that automatically
  20787. results in different compiled-in data directory, log file, and PID file
  20788. locations for each of your servers.
  20789.  
  20790. Assume an existing server is configured for the default port number and
  20791. socket file.  To configure a new server to have different operating
  20792. parameters, use a `configure' command something like this:
  20793.  
  20794.      shell> ./configure --with-tcp-port=port_number \
  20795.                   --with-unix-socket-path=file_name \
  20796.                   --prefix=/usr/local/mysql-4.0.17
  20797.  
  20798. Here `port_number' and `file_name' should be different from the default
  20799. port number and socket file pathname, and the `--prefix' value should
  20800. specify an installation directory different than the one under which
  20801. the existing MySQL installation is located.
  20802.  
  20803. If you have a MySQL server listening on a given port number, you can
  20804. use the following command to find out what operating parameters it is
  20805. using for several important configurable variables, including the base
  20806. directory and socket name:
  20807.  
  20808.      shell> mysqladmin --host=host_name --port=port_number variables
  20809.  
  20810. With the information displayed by that command, you can tell what option
  20811. values *not* to use when configuring an additional server.
  20812.  
  20813. Note that if you specify "`localhost'" as a hostname, `mysqladmin' will
  20814. default to using a Unix socket connection rather than TCP/IP.  In MySQL
  20815. 4.1, you can explicitly specify the connection protocol to use by using
  20816. the `--protocol={TCP | SOCKET | PIPE | MEMORY}' option.
  20817.  
  20818. You don't have to compile a new MySQL server just to start with a
  20819. different socket file and TCP/IP port number.  It is also possible to
  20820. specify those values at runtime. One way to do so is by using
  20821. command-line options:
  20822.  
  20823.      shell> /path/to/mysqld_safe --socket=file_name --port=port_number
  20824.  
  20825. To use another database directory for the second server, pass a
  20826. `--datadir=path' option to `mysqld_safe'.
  20827.  
  20828. Another way to achieve a similar effect is to use environment variables
  20829. to set the socket name and port number:
  20830.  
  20831.      shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
  20832.      shell> MYSQL_TCP_PORT=3307
  20833.      shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
  20834.      shell> scripts/mysql_install_db
  20835.      shell> bin/mysqld_safe &
  20836.  
  20837. This is a quick way of starting a second server to use for testing.
  20838. The nice thing about this method is that the environment variable
  20839. settings will apply to any client programs that you invoke from the
  20840. above shell. Thus, connections for those clients automatically will be
  20841. directed to the second server!
  20842.  
  20843. *Note Environment variables:: includes a list of other environment
  20844. variables you can use to affect `mysqld'.
  20845.  
  20846. For automatic server execution, your startup script that is executed at
  20847. boot time should execute the following command once for each server
  20848. with an appropriate option file path for each command:
  20849.  
  20850.      mysqld_safe --defaults-file=path-to-option-file
  20851.  
  20852. Each option file should contain option values specific to a given
  20853. server.
  20854.  
  20855. On Unix, the `mysqld_multi' script is another way to start multiple
  20856. servers.  *Note `mysqld_multi': mysqld_multi.
  20857.  
  20858. Using Client Programs in a Multiple-Server Environment
  20859. ------------------------------------------------------
  20860.  
  20861. When you want to connect with a client program to a MySQL server that is
  20862. listening to different network interfaces than those compiled into your
  20863. client, you can use one of the following methods:
  20864.  
  20865.    * Start the client with `--host=host_name --port=port_number' to
  20866.      connect via TCP/IP to a remote host, or with `--host=localhost
  20867.      --socket=file_name' to connect to a local host via a Unix socket
  20868.      or a Windows named pipe.
  20869.  
  20870.    * As of MySQL 4.1, start the client with `--protocol=tcp' to connect
  20871.      via TCP/IP, `--protocol=socket' to connect via a Unix socket,
  20872.      `--protocol=pipe' to connect via a named pipe, or
  20873.      `--protocol=memory' to connect via shared memory.  For TCP/IP
  20874.      connections, you may also need to specify `--host' and `--port'
  20875.      options.  For the other types of connections, you may need to
  20876.      specify a `--socket' option to specify a socket or named pipe
  20877.      name, or a `--shared-memory-base-name' option to specify the
  20878.      shared memory name.
  20879.  
  20880.    * On Unix, set the `MYSQL_UNIX_PORT' and `MYSQL_TCP_PORT'
  20881.      environment variables to point to the Unix socket and TCP/IP port
  20882.      before you start your clients.  If you normally use a specific
  20883.      socket or port, you can place commands to set these environment
  20884.      variables in your `.login' file so that they apply each time you
  20885.      log in.  *Note Environment variables::.
  20886.  
  20887.    * Specify the default socket and TCP/IP port in the `[client]' group
  20888.      of an option file. For example, you can use `C:\my.cnf' on
  20889.      Windows, or the `.my.cnf' file in your home directory on Unix.
  20890.      *Note Option files::.
  20891.  
  20892.    * In a C program, you can specify the port or socket arguments in the
  20893.      `mysql_real_connect()' call.  You can also have the program read
  20894.      option files by calling `mysql_options()'.  *Note C API
  20895.      functions::.
  20896.  
  20897.    * If you are using the Perl `DBD::mysql' module, you can read the
  20898.      options from the MySQL option files. For example:
  20899.  
  20900.           $dsn = "DBI:mysql:test;mysql_read_default_group=client;"
  20901.                   . "mysql_read_default_file=/usr/local/mysql/data/my.cnf";
  20902.           $dbh = DBI->connect($dsn, $user, $password);
  20903.  
  20904.      *Note Perl::.
  20905.  
  20906.  
  20907. Replication in MySQL
  20908. ********************
  20909.  
  20910. Replication capabilities allowing the databases on one MySQL server to
  20911. be duplicated on another were introduced in MySQL version 3.23.15.
  20912. This section describes the various replication features in MySQL.  It
  20913. serves as a reference to the options available with replication.  You
  20914. will be introduced to replication and learn how to implement it.
  20915. Toward that end, there are some frequently asked questions, descriptions
  20916. of problems, and how to solve them.
  20917.  
  20918. For a description of the syntax of replication SQL statements, see
  20919. *Note Replication SQL::.
  20920.  
  20921. We suggest that you visit our website at `http://www.mysql.com/' often
  20922. and read updates to this section. Replication is constantly being
  20923. improved, and we update the manual frequently with the most current
  20924. information.
  20925.  
  20926. Introduction to Replication
  20927. ===========================
  20928.  
  20929. Starting in Version 3.23.15, MySQL supports one-way replication
  20930. internally. One server acts as the master, while one or more other
  20931. servers act as slaves.  The master server keeps a binary log of updates
  20932. (*note Binary log::).  It also maintains an index file of the binary
  20933. logs to keep track of log rotation.  Each slave, upon connecting,
  20934. informs the master where it left off since the last successfully
  20935. propagated update, catches up any updates that have occurred since
  20936. then, and then blocks and waits for the master to notify it of new
  20937. updates.
  20938.  
  20939. A slave can also serve as a master if you set up chained replication
  20940. servers.
  20941.  
  20942. Note that when you are using replication, all updates to the tables
  20943. that are replicated should be performed on the master server.
  20944. Otherwise, you must always be careful to avoid conflicts between
  20945. updates that users make to tables on the master and updates that they
  20946. make to tables on the slave.
  20947.  
  20948. One-way replication has benefits for robustness, speed, and system
  20949. administration:
  20950.  
  20951.    * Robustness is increased with a master/slave setup.  In the event
  20952.      of problems with the master, you can switch to the slave as a
  20953.      backup.
  20954.  
  20955.    * The extra speed is achieved by splitting the load for processing
  20956.      client queries between the master and slave servers, resulting in
  20957.      better client response time.  `SELECT' queries may be sent to the
  20958.      slave to reduce query processing load of the master. Queries that
  20959.      modify data should still be sent to the master so that the master
  20960.      and slave to not get out of sync.  This load-balancing strategy is
  20961.      effective if non-updating queries dominate, but that is the normal
  20962.      case.
  20963.  
  20964.    * Another benefit of using replication is that one can get
  20965.      non-disturbing backups of the system by doing a backup on a slave
  20966.      instead of doing it on the master. *Note Backup::.
  20967.  
  20968.  
  20969. Replication Implementation Overview
  20970. ===================================
  20971.  
  20972. MySQL replication is based on the master server keeping track of all
  20973. changes to your database (updates, deletes, etc) in the binary log
  20974. (*note Binary log::).  Each slave server receives from the master the
  20975. saved queries that the master has recorded in its binary log, so that
  20976. the slave can execute the same queries on its copy of the data.
  20977.  
  20978. It is *very important* to realize that the binary log is simply a
  20979. record starting from a fixed point in time (the moment you enable binary
  20980. logging). Any slaves that you set up will need copies of the databases
  20981. on your master as they existed at the moment you enabled binary logging
  20982. on the master. If you start your slaves with data that is not the same
  20983. as what was on the master *when the binary log was started*, your
  20984. slaves may fail.
  20985.  
  20986. Starting from 4.0.0, you can use `LOAD DATA FROM MASTER' to set up a
  20987. slave. Be aware that `LOAD DATA FROM MASTER' currently works only if
  20988. all the tables on the master are `MyISAM' type. Also, this statement
  20989. acquires a global read lock, so no writes are possible while the tables
  20990. are being transferred from the master. When we implement lock-free hot
  20991. table backup (in MySQL 5.0), this global read lock will no longer be
  20992. necessary.
  20993.  
  20994. Due to these limitations, we recommend that at this point  you use
  20995. `LOAD DATA FROM MASTER' only if the dataset on the master is relatively
  20996. small, or if a prolonged read lock on the master is acceptable. While
  20997. the actual speed of `LOAD DATA FROM MASTER' may vary from system to
  20998. system, a good rule of thumb for how long it is going to take is 1
  20999. second per 1 MB of the datafile. You will get close to the estimate if
  21000. both master and slave are equivalent to 700 MHz Pentium and are
  21001. connected through a 100 MBit/s network.  Note that this is only a rough
  21002. estimate.
  21003.  
  21004. Once a slave is properly configured and running, it will simply connect
  21005. to the master and wait for updates to process. If the master goes away
  21006. or the slave loses connectivity with your master, it will keep trying to
  21007. connect periodically until it is able to reconnect and resume listening
  21008. for updates. The retry interval is controlled by the
  21009. `--master-connect-retry' option. The default is 60 seconds.
  21010.  
  21011. Each slave keeps track of where it left off. The master server has no
  21012. knowledge of how many slaves there are or which ones are up-to-date at
  21013. any given time.
  21014.  
  21015. Replication Implementation Details
  21016. ==================================
  21017.  
  21018. Three threads are involved in replication: one on the master and two on
  21019. the slave.  When `START SLAVE' is issued, the I/O thread is created on
  21020. the slave. It connects to the master and asks it to send the queries
  21021. recorded in its binlogs. Then one thread is created on the master to
  21022. send these binlogs.  This thread is identified by `Binlog Dump' in
  21023. `SHOW PROCESSLIST' output on the master.  The I/O thread reads what the
  21024. master `Binlog Dump' thread sends and simply copies it to some local
  21025. files in the slave's data directory called relay logs.  The last
  21026. thread, the SQL thread, is created on the slave; it reads the relay
  21027. logs and executes the queries it contains.
  21028.  
  21029. Note that the master has one thread for each currently connected slave
  21030. server.
  21031.  
  21032. With `SHOW PROCESSLIST' you can know what is happening on the master
  21033. and on the slave as regards replication.
  21034.  
  21035. The following example illustrates how the three threads show up in
  21036. `SHOW PROCESSLIST'.  The output format is that used by `SHOW
  21037. PROCESSLIST' as of MySQL version 4.0.15, when the content of the
  21038. `State' column was changed to be more meaningful compared to earlier
  21039. versions.
  21040.  
  21041. On the master server, the output looks like this:
  21042.  
  21043.      mysql> SHOW PROCESSLIST\G
  21044.      *************************** 1. row ***************************
  21045.           Id: 2
  21046.         User: root
  21047.         Host: localhost:32931
  21048.           db: NULL
  21049.      Command: Binlog Dump
  21050.         Time: 94
  21051.        State: Has sent all binlog to slave; waiting for binlog to be updated
  21052.         Info: NULL
  21053.  
  21054. On the slave server, the output looks like this:
  21055.  
  21056.      mysql> SHOW PROCESSLIST\G
  21057.      *************************** 1. row ***************************
  21058.           Id: 10
  21059.         User: system user
  21060.         Host:
  21061.           db: NULL
  21062.      Command: Connect
  21063.         Time: 11
  21064.        State: Waiting for master to send event
  21065.         Info: NULL
  21066.      *************************** 2. row ***************************
  21067.           Id: 11
  21068.         User: system user
  21069.         Host:
  21070.           db: NULL
  21071.      Command: Connect
  21072.         Time: 11
  21073.        State: Has read all relay log; waiting for the slave I/O thread to update it
  21074.         Info: NULL
  21075.  
  21076. Here thread 2 is on the master. Thread 10 is the I/O thread on the
  21077. slave.  Thread 11 is the SQL thread on the slave; note that the value
  21078. in the `Time' column can tell how late the slave is compared to the
  21079. master (*note Replication FAQ::).
  21080.  
  21081. The following list shows the most common states you will see in the
  21082. `State' column for the master's `Binlog Dump' thread. If you don't see
  21083. this thread on a master server, replication is not running.
  21084.  
  21085. `Sending binlog event to slave'
  21086.      Binlogs consist of events, where an event is usually a query plus
  21087.      some other information. The thread has read an event from the
  21088.      binlog and is sending it to the slave.
  21089.  
  21090. `Finished reading one binlog; switching to next binlog'
  21091.      The thread has finished reading a binlog file and is opening the
  21092.      next one to send to the slave.
  21093.  
  21094. `Has sent all binlog to slave; waiting for binlog to be updated'
  21095.      The thread has read all binary log files and is idle. It is
  21096.      waiting for new events to appear in the binary log as a result of
  21097.      new update queries being executed on the master.
  21098.  
  21099. `Waiting to finalize termination'
  21100.      A very brief state that happens as the thread is stopping.
  21101.  
  21102. Here are the most common states you will see in the `State' column for
  21103. the I/O thread of a slave server. Beginning with MySQL 4.1.1, this
  21104. state also appears in the `Slave_IO_State' column of `SHOW SLAVE
  21105. STATUS' output. This means that you can get a good view of what is
  21106. happening by using only `SHOW SLAVE STATUS'.
  21107.  
  21108. `Connecting to master'
  21109.      The thread is attempting to connect to the master.
  21110.  
  21111. `Checking master version'
  21112.      A very brief state that happens just after the connection to the
  21113.      master is established.
  21114.  
  21115. `Registering slave on master'
  21116.      A very brief state that happens just after the connection to the
  21117.      master is established.
  21118.  
  21119. `Requesting binlog dump'
  21120.      A very brief state that happens just after the connection to the
  21121.      master is established.  The thread sends to the master a request
  21122.      for the contents of its binlogs, starting from the requested
  21123.      binlog filename and position.
  21124.  
  21125. `Waiting to reconnect after a failed binlog dump request'
  21126.      If the binlog dump request failed (due to disconnection), the
  21127.      thread goes into this state while it sleeps. The thread sleeps for
  21128.      `master-connect-retry' seconds before retrying.
  21129.  
  21130. `Reconnecting after a failed binlog dump request'
  21131.      Then the thread tries to reconnect to the master.
  21132.  
  21133. `Waiting for master to send event'
  21134.      The thread has connected and is waiting for binlog events to
  21135.      arrive. This can last for a long time if the master is idle. If the
  21136.      wait lasts for `slave_read_timeout' seconds, a timeout will occur.
  21137.      At that point, the thread will consider the connection to be
  21138.      broken and make an attempt to reconnect.
  21139.  
  21140. `Queueing master event to the relay log'
  21141.      The thread has read an event and is copying it to the relay log so
  21142.      the SQL thread can process it.
  21143.  
  21144. `Waiting to reconnect after a failed master event read'
  21145.      An error occurred while reading (due to disconnection). The thread
  21146.      is sleeping for `master-connect-retry' seconds before attempting
  21147.      to reconnect.
  21148.  
  21149. `Reconnecting after a failed master event read'
  21150.      Then the thread tries to reconnect. When connection is established
  21151.      again, the state will become `Waiting for master to send event'.
  21152.  
  21153. `Waiting for the slave SQL thread to free enough relay log space'
  21154.      You are using a non-zero `relay_log_space_limit' value, and the
  21155.      relay logs have grown so much that their combined size exceeds
  21156.      this value.  The I/O thread is waiting until the SQL thread frees
  21157.      enough space by processing relay log contents so that it can
  21158.      delete some relay log files.
  21159.  
  21160. `Waiting for slave mutex on exit'
  21161.      A very brief state that happens as the thread is stopping.
  21162.  
  21163. Here are the most common states you will see in the `State' column for
  21164. the SQL thread of a slave server:
  21165.  
  21166. `Reading event from the relay log'
  21167.      The thread has read an event from the relay log so that it can
  21168.      process it.
  21169.  
  21170. `Has read all relay log; waiting for the slave I/O thread to update it'
  21171.      The thread has processed all events in the relay log files and is
  21172.      waiting for the I/O thread to write new events to the relay log.
  21173.  
  21174. `Waiting for slave mutex on exit'
  21175.      A very brief state that happens as the thread is stopping.
  21176.  
  21177. The `State' column for the I/O thread may also show a query string.
  21178. This indicates that the thread has read an event from the relay log,
  21179. extracted the query from it and is executing the query.
  21180.  
  21181. Before MySQL 4.0.2, the slave I/O and SQL threads were combined as a
  21182. single thread, and no relay log files were used.  The advantage of
  21183. using two threads is that it separates query reading and query
  21184. execution into two independent tasks, so the task of reading queries is
  21185. not slowed down if query execution is slow.  For example, if the slave
  21186. server has not been running for a while, its I/O thread can quickly
  21187. fetch all the binlog contents from the master when the slave starts,
  21188. even if the SQL thread lags far behind and may take hours to catch up.
  21189. If the slave stops before the SQL thread has executed all the fetched
  21190. queries, the I/O thread has at least fetched everything so that a safe
  21191. copy of the queries is locally stored in the slave's relay logs for
  21192. execution when next the slave starts. This allows the binlogs to be
  21193. purged on the master, because it no longer need wait for the slave to
  21194. fetch their contents.
  21195.  
  21196. By default, relay logs are named using filenames of the form
  21197. `host_name-relay-bin.nnn', where `host_name' is the name of the slave
  21198. server host, and `nnn' is a sequence number.  Successive relay log
  21199. files are created using successive sequence numbers, beginning with
  21200. `001'.  The slave keeps track of relay logs currently in use in an
  21201. index file.  The default relay log index filename is
  21202. `host_name-relay-bin.index'.  By default these files are created in the
  21203. slave's data directory.  The default filenames may be overridden with
  21204. the `--relay-log' and `--relay-log-index' server options.
  21205.  
  21206. Relay logs have the same format as binary logs, so they can be read
  21207. with `mysqlbinlog'.  A relay log is automatically deleted by the SQL
  21208. thread as soon as it no longer needs it (that is, as soon as it has
  21209. executed all its events). There is no command to delete relay logs,
  21210. because the SQL thread takes care of doing so. However, from MySQL
  21211. 4.0.14, `FLUSH LOGS' rotates relay logs, which will influence when the
  21212. SQL thread deletes them.
  21213.  
  21214. A new relay log is created under the following conditions:
  21215.  
  21216.    * The first time the I/O thread starts after the slave server starts.
  21217.      (In MySQL 5.0, a new relay log will be created each time the I/O
  21218.      thread starts, not just the first time.)
  21219.  
  21220.    * A `FLUSH LOGS' statement is issued (4.0.14 and up only).
  21221.  
  21222.    * The size of the current relay log file becomes too big. The
  21223.      meaning of "too big" is determined as follows:
  21224.         - `max_relay_log_size', if `max_relay_log_size' > 0
  21225.  
  21226.         - `max_binlog_size', if `max_relay_log_size' = 0 or MySQL is
  21227.           older than 4.0.14
  21228.  
  21229.  
  21230. A slave replication server creates additional two small files in the
  21231. data directory.  These files are named `master.info' and
  21232. `relay-log.info' by default.  They contain information like that shown
  21233. in the output of the `SHOW SLAVE STATUS' statement (*note Replication
  21234. Slave SQL:: for a description of this command).  As disk files they
  21235. survive slave's shutdown. The next time the slave starts up, it can
  21236. read these files to know how far it has proceeded in reading binlogs
  21237. from the master and in processing its own relay logs.
  21238.  
  21239. The `master.info' file is updated by the I/O thread.  The
  21240. correspondance between the lines in the file and the columns displayed
  21241. by `SHOW SLAVE STATUS' is as follows:
  21242.  
  21243. *Line**Description*
  21244. 1    `Master_Log_File'
  21245. 2    `Read_Master_Log_Pos'
  21246. 3    `Master_Host'
  21247. 4    `Master_User'
  21248. 5    Password (not shown by `SHOW SLAVE STATUS')
  21249. 6    `Master_Port'
  21250. 7    `Connect_Retry'
  21251.  
  21252. The `relay-log.info' file is updated by the SQL thread.  The
  21253. correspondance between the lines in the file and the columns displayed
  21254. by `SHOW SLAVE STATUS' is as follows:
  21255.  
  21256. *Line**Description*
  21257. 1    `Relay_Log_File'
  21258. 2    `Relay_Log_Pos'
  21259. 3    `Relay_Master_Log_File'
  21260. 4    `Exec_Master_Log_Pos'
  21261.  
  21262. When you back up your slave's data, you should back up these 2 small
  21263. files as well, along with the relay log files. because they are needed
  21264. to resume replication after you restore the slave's data.  If you lose
  21265. the relay logs but still have the `relay-log.info' file, you can check
  21266. it to determine how far the SQL thread has executed in the master
  21267. binlogs. Then you can use `CHANGE MASTER TO' with the
  21268. `MASTER_RELAY_LOG' and `MASTER_RELAY_POS' options to tell the slave to
  21269. re-read the binlogs from that point.  This requires that the binlogs
  21270. still exist on the master server.
  21271.  
  21272. If your slave is subject to replicating `LOAD DATA INFILE' statements,
  21273. you should also backup the `SQL_LOAD-*' files that may exist in the
  21274. directory that the slave uses for this purpose.  The slave needs these
  21275. files to resume replication of any interrupted `LOAD DATA INFILE'
  21276. statements.  The directory location is specified using the
  21277. `--slave-load-tmpdir' option.  Its default value if not specified is
  21278. the value of the `tmpdir' variable.
  21279.  
  21280. How to Set Up Replication
  21281. =========================
  21282.  
  21283. Here is a quick description of how to set up complete replication on
  21284. your current MySQL server. It assumes you want to replicate all your
  21285. databases and have not configured replication before. You will need to
  21286. shut down your master server briefly to complete the steps outlined
  21287. here.
  21288.  
  21289. The procedure is written in terms of setting up a single slave, but you
  21290. can use it to set up multiple slaves.
  21291.  
  21292. While this method is the most straightforward way to set up a slave, it
  21293. is not the only one. For example, if you already have a snapshot of the
  21294. master's data, and the master already has its server ID set and binary
  21295. logging enabled, you can set up a slave without shutting down the
  21296. master or even blocking updates to it.  For more details, please see
  21297. *Note Replication FAQ::.
  21298.  
  21299. If you want to administer a MySQL replication setup, we suggest that you
  21300. read this entire chapter through and try all commands mentioned in
  21301. *Note Replication Master SQL:: ans *Note Replication Slave SQL::.  You
  21302. should also familiarise yourself with replication startup options in
  21303. `my.cnf' in *Note Replication Options::.
  21304.  
  21305. Note that this procedure and some of the replication SQL statements in
  21306. later sections refer to the `SUPER' privilege. Prior to MySQL 4.0.2,
  21307. use the `PROCESS' privilege instead.
  21308.  
  21309.   1. Make sure you have a recent version of MySQL installed on the
  21310.      master and and slaves, and that these versions are compatible
  21311.      according to the table shown in *Note Replication Upgrade::.
  21312.  
  21313.      Please do not report bugs until you have verified that the problem
  21314.      is present in the latest release.
  21315.  
  21316.   2. Set up an account on the master server that the slave server can
  21317.      use to connnect. This account must be given the `REPLICATION
  21318.      SLAVE' privilege.  (If MySQL versions older than 4.0.2, give the
  21319.      account the `FILE' privilege instead.)  If the account is only for
  21320.      replication (which is recommended), you don't need to grant any
  21321.      additional privileges.
  21322.  
  21323.      The hostname in the account name should be such that each of the
  21324.      slave servers can use the account to connect to the master.  For
  21325.      example, to create a user named `repl' which can access your
  21326.      master from any host, you might use this command:
  21327.  
  21328.           mysql> GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY '<password>';
  21329.  
  21330.      For MySQL versions older than 4.0.2, use this command instead:
  21331.  
  21332.           mysql> GRANT FILE ON *.* TO repl@'%' IDENTIFIED BY '<password>';
  21333.  
  21334.      If you plan to use the `LOAD TABLE FROM MASTER' or `LOAD DATA FROM
  21335.      MASTER' statements from the slave host, you will need to grant this
  21336.      account additional privileges:
  21337.  
  21338.         * Grant to the account the `SUPER' and `RELOAD' global
  21339.           privileges.
  21340.  
  21341.         * Grant the `SELECT' privilege for all tables that you want to
  21342.           load. Any master tables from which the account cannot
  21343.           `SELECT' will be ignored by `LOAD DATA FROM MASTER'.
  21344.  
  21345.   3. If you are using MyISAM tables, flush all the tables and block
  21346.      write queries by executing `FLUSH TABLES WITH READ LOCK' command.
  21347.  
  21348.           mysql> FLUSH TABLES WITH READ LOCK;
  21349.  
  21350.      and then take a snapshot of the data on your master server.
  21351.  
  21352.      The easiest way to create a snapshot is to simply use an archiving
  21353.      program (`tar' on Unix, `PowerArchiver', `WinRAR', `WinZip' or any
  21354.      similar software on Windows) to produce an archive of the
  21355.      databases in your master's data directory.  For example, to use
  21356.      `tar' to create an archive that includes all databases, change
  21357.      location into the master server's data directory, then execute
  21358.      this command:
  21359.  
  21360.           shell> tar -cvf /tmp/mysql-snapshot.tar .
  21361.  
  21362.      If you want the archive to include only a database called
  21363.      `this_db', use this command instead:
  21364.  
  21365.           shell> tar -cvf /tmp/mysql-snapshot.tar ./this_db
  21366.  
  21367.      Then copy the archive file to the `/tmp' directory on the slave
  21368.      server host. On that machine, change location into the slave's
  21369.      data directory, and unpack the archive file using this command:
  21370.  
  21371.           shell> tar -xvf /tmp/mysql-snapshot.tar
  21372.  
  21373.      You may not want to replicate the `mysql' database. If not, you can
  21374.      exclude it from the archive. You also need not include any log
  21375.      files in the archive, or the `master.info' or `relay-log.info'
  21376.      files.
  21377.  
  21378.      While the read lock placed by `FLUSH TABLES WITH READ LOCK' is in
  21379.      effect, read the value of the current binary log name and offset
  21380.      on the master:
  21381.  
  21382.           mysql > SHOW MASTER STATUS;
  21383.           +---------------+----------+--------------+------------------+
  21384.           | File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  21385.           +---------------+----------+--------------+------------------+
  21386.           | mysql-bin.003 | 73       | test,bar     | foo,manual,mysql |
  21387.           +---------------+----------+--------------+------------------+
  21388.           1 row in set (0.06 sec)
  21389.  
  21390.      The `File' column shows the name of the log,  while `Position'
  21391.      shows the offset. In the above example, the binary log value is
  21392.      `mysql-bin.003' and the offset is 73. Record the values. You will
  21393.      need to use them later when you are setting up the slave.
  21394.  
  21395.      Once you have taken the snapshot and recorded the log name and
  21396.      offset, you can re-enable write activity on the master:
  21397.  
  21398.           mysql> UNLOCK TABLES;
  21399.  
  21400.      If you are using InnoDB tables, ideally you should use the InnoDB
  21401.      Hot Backup tool that is available to those who purchase MySQL
  21402.      commercial licenses, support, or the backup tool itself. It takes
  21403.      a consistent snapshot without acquiring any locks on the master
  21404.      server, and records the log name and offset corresponding to the
  21405.      snapshot to be later used on the slave. More information about the
  21406.      tool is available at `http://www.innodb.com/order.php'.
  21407.  
  21408.      Without the Hot Backup tool, the quickest way to take a snapshot
  21409.      of  InnoDB tables is to shut down the master server and copy the
  21410.      InnoDB datafiles and logs, and the table definition files
  21411.      (`.frm'). To record the current log file name and offset, you
  21412.      should do the following before you shut down the server:
  21413.  
  21414.           mysql> FLUSH TABLES WITH READ LOCK;
  21415.           mysql> SHOW MASTER STATUS;
  21416.  
  21417.      And then record the log name and the offset from the output of
  21418.      `SHOW MASTER STATUS' as was shown earlier. Once you have recorded
  21419.      the log name and the offset, shut down the server without
  21420.      unlocking the tables to make sure it goes down with the snapshot
  21421.      corresponding to the current log file and offset:
  21422.  
  21423.           shell> mysqladmin -uroot shutdown
  21424.  
  21425.      An alternative for both MyISAM and InnoDB tables is to take an SQL
  21426.      dump of the master instead of a binary copy like above; for this
  21427.      you can use `mysqldump --master-data' on your master and later run
  21428.      this SQL dump into your slave. However, this is slower than doing
  21429.      a binary copy.
  21430.  
  21431.      If the master has been previously running without `--log-bin'
  21432.      enabled, the log name and position values displayed by `SHOW MASTER
  21433.      STATUS' or `mysqldump' will be empty. In that case, record empty
  21434.      string (") for the log name, and 4 for the offset.
  21435.  
  21436.   4. Make sure the `[mysqld]' section of the `my.cnf' file on the
  21437.      master host includes a `log-bin' option. The section should also
  21438.      have a `server-id=master_id' option, where `master_id' must be an
  21439.      integer value from 1 to 2^32 - 1. For example:
  21440.  
  21441.           [mysqld]
  21442.           log-bin
  21443.           server-id=1
  21444.  
  21445.      If those options are not present, add them and restart the server.
  21446.  
  21447.   5. Stop the server that is to be used as a slave server and add the
  21448.      following to its `my.cnf' file:
  21449.  
  21450.           [mysqld]
  21451.           server-id=slave_id
  21452.  
  21453.      The `slave_id' value, like the `master_id' value, must be an
  21454.      integer value from 1 to 2^32 - 1. In addition, it is very
  21455.      important that the ID of the slave be different than the ID of the
  21456.      master. For example:
  21457.  
  21458.           [mysqld]
  21459.           server-id=2
  21460.  
  21461.      If you are setting up multiple slaves, each one must have a
  21462.      `server-id' value that differs from that of the master and from
  21463.      each of the other slaves.  Think of `server-id' values as
  21464.      something similar to IP addresses: These IDs uniquely identify
  21465.      each server instance in the community of replication partners.
  21466.  
  21467.      If you don't specify a `server-id' value, it will be set to 1 if
  21468.      you have not defined `master-host', else it will be set to 2. Note
  21469.      that in the case of `server-id' omission, a master will refuse
  21470.      connections from all slaves, and a slave will refuse to connect to
  21471.      a master. Thus, omitting `server-id' is only good for backup with a
  21472.      binary log.
  21473.  
  21474.   6. If you made a binary backup of the master server's data, copy it
  21475.      to the slave server's data directory before starting the slave.
  21476.      Make sure that the privileges on the files and directories are
  21477.      correct. The user which MySQL runs as needs to be able to read
  21478.      from and write to them, just as on the master.
  21479.  
  21480.      If you made a backup using `mysqldump', start the slave first (see
  21481.      next step).
  21482.  
  21483.   7. Start the slave server. If it has been replicating previously,
  21484.      start the slave server with the `--skip-slave-start' option.  You
  21485.      also may want to start the slave server with the `--log-warnings'
  21486.      option. That way, you will get more messages about problems (for
  21487.      example, network or connection problems).
  21488.  
  21489.   8. If you made a backup of the master server's data using
  21490.      `mysqldump', load the dump file into the slave server:
  21491.  
  21492.           shell> mysql -u root -p < dump_file.sql
  21493.  
  21494.   9. Execute the following command on the slave, replacing the values
  21495.      within `<>' with the actual values relevant to your system:
  21496.  
  21497.           mysql> CHANGE MASTER TO
  21498.               ->     MASTER_HOST='<master hostname>',
  21499.               ->     MASTER_USER='<replication username>',
  21500.               ->     MASTER_PASSWORD='<replication password>',
  21501.               ->     MASTER_LOG_FILE='<recorded log file name>',
  21502.               ->     MASTER_LOG_POS=<recorded log offset>;
  21503.  
  21504.      The following table lists the maximum string length for these
  21505.      variables:
  21506.  
  21507.      `MASTER_HOST'               60
  21508.      `MASTER_USER'               16
  21509.      `MASTER_PASSWORD'           32
  21510.      `MASTER_LOG_FILE'           255
  21511.  
  21512.  10. Start the slave threads:
  21513.  
  21514.           mysql> START SLAVE;
  21515.  
  21516.  
  21517. After you have performed this procedure, the slave should connect to
  21518. the master and catch up on any updates that have occurred since the
  21519. snapshot was taken.
  21520.  
  21521. If you have forgotten to set `server-id' for the master, slaves will
  21522. not be able to connect to it.
  21523.  
  21524. If you have forgotten to set `server-id' for the slave, you will get
  21525. the following error in its error log:
  21526.  
  21527.      Warning: one should set server_id to a non-0 value if master_host is set.
  21528.      The server will not act as a slave.
  21529.  
  21530. You will also find error messages in the slave's error log if it is not
  21531. able to replicate for any other reason.
  21532.  
  21533. Once a slave is replicating, you will find in its data directory one
  21534. file called `master.info' and another called `relay-log.info'.  The
  21535. slave uses these two files to keep track of how much of the master's
  21536. binary log it has processed. *Do not* remove or edit these files,
  21537. unless you really know what you are doing and understand the
  21538. implications. Even in that case, it is preferred that you use `CHANGE
  21539. MASTER TO' command.
  21540.  
  21541. *NOTE*: The content of `master.info' overrides some options specified
  21542. on the command-line or in `my.cnf' See *Note Replication Options:: for
  21543. more details.
  21544.  
  21545. Once you have a snapshot, you can use it to set up other slaves by
  21546. following the slave portion of the procedure just described. You do not
  21547. need to take another snapshot of the master.
  21548.  
  21549. Upgrading a Replication Setup - Mixing Different MySQL Versions
  21550. ===============================================================
  21551.  
  21552. Any MySQL 4.1.x version is identical to MySQL 4.0.3 (and newer 4.0) as
  21553. far as replication is concerned (same binary log format).  So
  21554. replication between 4.0.3 (and newer 4.0) and any 4.1.x (whatever of
  21555. the two is the master or slave) is working seamlessly.
  21556.  
  21557. Binary log format was changed between MySQL 3.23 and MySQL 4.0, and
  21558. between MySQL 4.0 (or 4.1, as it's the same binary log format) and
  21559. MySQL 5.0. This has consequences on how to upgrade a replication setup,
  21560. which is explained below.
  21561.  
  21562. The following table indicates master/slave replication compatibility
  21563. between different versions of MySQL.
  21564.  
  21565.                     *Master*    *Master*    *Master*
  21566.                     *3.23.33    *4.0.3 and  *5.0.0*
  21567.                     and up*     up or any   
  21568.                                 4.1.x*      
  21569. *Slave* *3.23.33    yes         no          no
  21570.         and up*                             
  21571. *Slave* *4.0.3 and  yes         yes         no
  21572.         up*                                 
  21573. *Slave* *5.0.0*     yes         yes         yes
  21574.  
  21575. Versions 4.0.0, 4.0.1 and 4.0.2 were very early development versions
  21576. which should not be used anymore (their compatibility is still
  21577. documented in the manual included in these versions' distributions).
  21578.  
  21579. As a general rule, it's always recommended to use recent MySQL versions,
  21580. because replication capabilities are continually being improved.  We
  21581. recommend using same version for both the master and the slave.
  21582.  
  21583. *Upgrading from 3.23 to 4.0 (4.0.3 or newer) or any 4.1.x*
  21584.      When you upgrade a master from MySQL 3.23 to MySQL 4.0 (or 4.1),
  21585.      you should first ensure that all the slaves of this master are
  21586.      already 4.0 or 4.1 (if that's not the case, you should first
  21587.      upgrade your slaves as explained a few lines below).  Once the
  21588.      master is upgraded, you should not restart replication using old
  21589.      3.23 binary logs, because this will unfortunately confuse the 4.0
  21590.      or 4.1 slave. The upgrade can safely be done this way, assuming
  21591.      you have a 3.23 master to upgrade and you have 4.0 or 4.1 slaves:
  21592.  
  21593.        1. Block all updates on the master (`FLUSH TABLES WITH READ
  21594.           LOCK').
  21595.  
  21596.        2. Wait until all the slaves have caught up all changes from the
  21597.           master (use `SHOW MASTER STATUS' on the master, and `SELECT
  21598.           MASTER_POS_WAIT()' on the slaves). Then run `STOP SLAVE' on
  21599.           the slaves.
  21600.  
  21601.        3. Shut down MySQL on the master and upgrade the master to MySQL
  21602.           4.0 or 4.1.
  21603.  
  21604.        4. Restart MySQL on the master. Record the name `<name>' of the
  21605.           master's newly created binary log. You can obtain the name of
  21606.           the file by issuing `SHOW MASTER STATUS' on the master. Then
  21607.           issue these commands on each slave:
  21608.                mysql> CHANGE MASTER TO MASTER_LOG_FILE='<name>', MASTER_LOG_POS=4;
  21609.                mysql> START SLAVE;
  21610.  
  21611.  
  21612.      If you also must upgrade your slaves from 3.23 to 4.0 or 4.1, you
  21613.      should first upgrade your slaves: shut down each one, upgrade it,
  21614.      and restart it. Then upgrade the master as just described.
  21615.  
  21616. *Upgrading from 3.23 or 4.0 (4.0.3 or newer) or any 4.1.x to 5.0.0*
  21617.      First, note that MySQL 5.0.0 is alpha; even if it is supposed to
  21618.      work better than older versions (easier upgrade, replication of
  21619.      some important session variables like `sql_mode'; see *Note
  21620.      News-5.0.0::), it has not been tested a lot yet so, as with any
  21621.      alpha release, we recommend you do not use in critical production
  21622.      environment yet.
  21623.  
  21624.      When you upgrade a master from MySQL 3.23 or 4.0 or 4.1 to 5.0.0,
  21625.      you should first ensure that all the slaves of this master are
  21626.      already 5.0.0 (if that's not the case, you should first upgrade
  21627.      your slaves as explained a few lines below).  Then just shut down
  21628.      your master, upgrade it to 5.0.0 and restart it.  The 5.0.0 master
  21629.      will be able to read the old binary logs (of before the master
  21630.      upgrade) and to send them to the 5.0.0 slaves which will recognize
  21631.      this old format and handle it. Binary logs created after the
  21632.      master upgrade will be in 5.0.0 format and be recognized by 5.0.0
  21633.      slaves too.  To upgrade the slaves, just shut them down, upgrade
  21634.      them to 5.0.0, and restart them (and restart replication). The
  21635.      5.0.0 slaves will be able to read the old relay logs (of before
  21636.      the slave upgrade) and execute the statements they contain. Relay
  21637.      logs created after the slave upgrade will be in 5.0.0 format.  In
  21638.      other words, there are no measures to take when upgrading to 5.0.0,
  21639.      except that slaves must be 5.0.0 to be able to upgrade the master
  21640.      to 5.0.0. Note that downgrading from 5.0.0 to older versions does
  21641.      not work as automatically; you will have to remove any 5.0.0
  21642.      binary logs or relay logs before proceeding.
  21643.  
  21644. Replication Features and Known Problems
  21645. =======================================
  21646.  
  21647. Here is an explanation of what is supported and what is not:
  21648.  
  21649.    * Replication will be done correctly with `AUTO_INCREMENT',
  21650.      `LAST_INSERT_ID()', and `TIMESTAMP' values.
  21651.  
  21652.    * The `USER()' and `LOAD_FILE()' functions are replicated without
  21653.      changes and will thus not work reliably on the slave. This is also
  21654.      true for `CONNECTION_ID()' in slave versions older than 4.1.1.
  21655.      The *new* `PASSWORD()' function in MySQL 4.1, is well replicated
  21656.      since 4.1.1 masters; your slaves must be 4.1.0 or above to
  21657.      replicate it. If you have older slaves and need to replicate
  21658.      `PASSWORD()' from your 4.1.x master, you must start your master
  21659.      with option `--old-password'.
  21660.  
  21661.    * The `SQL_MODE', `UNIQUE_CHECKS', `SQL_AUTO_IS_NULL' variables are
  21662.      replicated only starting from 5.0.0.  `SQL_SELECT_LIMIT' and
  21663.      `TABLE_TYPE' variables are not replicated yet.
  21664.      `FOREIGN_KEY_CHECKS' is replicated since version 4.0.14.
  21665.  
  21666.    * You must use the same character set (`--default-character-set') on
  21667.      the master and the slave. Otherwise, you may get duplicate key
  21668.      errors on the slave, because a key that is regarded as unique in
  21669.      the master character set may not be unique in the slave character
  21670.      set. Character sets will be replicated in 5.0.x.
  21671.  
  21672.    * If you are using transactional tables on the master and
  21673.      non-transactional tables (for the same tables) on the slave, you
  21674.      will get problems if the slave is stopped in the middle of a
  21675.      `BEGIN/COMMIT' block, as the slave will later start at the
  21676.      beginning of the `BEGIN' block.  This issue is on our TODO and
  21677.      will be fixed in the near future.
  21678.  
  21679.    * Update queries that use user variables are badly replicated in
  21680.      3.23 and 4.0. This is fixed in 4.1. Note that user variable names
  21681.      are case insensitive starting from version 5.0, so you should take
  21682.      this into account when setting up replication between 5.0 and a
  21683.      previous version.
  21684.  
  21685.    * The slave can connect to the master using SSL, if the master and
  21686.      slave are both 4.1.1 or newer.
  21687.  
  21688.    * If a `DATA DIRECTORY' or `INDEX DIRECTORY' clause was used in a
  21689.      `CREATE TABLE' on master, then these clauses will be used too on
  21690.      slave. Starting from MySQL 4.0.15 there is a `SQL_MODE' mode called
  21691.      `NO_DIR_IN_CREATE'; if the slave server is run in this mode, it
  21692.      will simply cut off the clauses before replicating the `CREATE
  21693.      TABLE' (so the MyISAM data and index files will be created in the
  21694.      slave's `datadir' directory).
  21695.  
  21696.    * Though we have never heard of it actually occurring, it is
  21697.      theoretically possible for the data on the master and slave to
  21698.      become different if a query is designed in such a way that the
  21699.      data modification is non-deterministic, that is, left to the will
  21700.      of the query optimizer (which generally is not a good practice,
  21701.      even outside of replication!).  For a detailed explanation, see
  21702.      *Note Open bugs::.
  21703.  
  21704.    * Before MySQL 4.1.1, `FLUSH', `ANALYZE', `OPTIMIZE', `REPAIR'
  21705.      commands are not stored in the binary log and thus are not
  21706.      replicated to the slaves. This is not normally a problem as these
  21707.      commands don't change anything. However, it does mean that if you
  21708.      update the MySQL privilege tables directly without using the
  21709.      `GRANT' statement and you replicate the `mysql' privilege
  21710.      database, you must do a `FLUSH PRIVILEGES' on your slaves to put
  21711.      the new privileges into effect. Also if you use `FLUSH TABLES'
  21712.      when renaming a `MyISAM' table involved in a `MERGE' table, you
  21713.      will have to issue `FLUSH TABLES' manually on the slave.  Since
  21714.      MySQL 4.1.1, these commands are written to the binary log (except
  21715.      `FLUSH LOGS', `FLUSH MASTER', `FLUSH SLAVE', `FLUSH TABLES WITH
  21716.      READ LOCK') unless you specify `NO_WRITE_TO_BINLOG' (or its alias
  21717.      `LOCAL').  For a syntax example, see *Note `FLUSH': FLUSH.
  21718.  
  21719.    * MySQL only supports one master and many slaves. Later we will add
  21720.      a voting algorithm to automatically change master if something goes
  21721.      wrong with the current master. We will also introduce "agent"
  21722.      processes to help do load balancing by sending `SELECT' queries to
  21723.      different slaves.
  21724.  
  21725.    * Starting from MySQL 4.0.18, the master notifies the slave of a
  21726.      `HEAP' table having been emptied by master's shutdown/restart by
  21727.      writing a `DELETE FROM' to its binary log the first time it uses
  21728.      the table since startup. See *Note HEAP:: for more details.
  21729.  
  21730.    * Temporary tables are replicated with the exception of the case
  21731.      that you shut down slave server (not just slave thread) and you
  21732.      have some replicated temporary tables that are used in update
  21733.      statements that have not yet been executed on the slave.  (If you
  21734.      shut down the slave, the temporary tables needed by those updates
  21735.      no longer are available when the slave starts again.)  To avoid
  21736.      this problem, do not shut down the slave while it has temporary
  21737.      tables open. Instead, use this procedure:
  21738.  
  21739.        1. Issue a `STOP SLAVE' statement.
  21740.  
  21741.        2. Use `SHOW STATUS' to check the value of the
  21742.           `Slave_open_temp_tables' variable.
  21743.  
  21744.        3. If the value is 0, issue a `mysqladmin shutdown' command to
  21745.           shut down the slave.
  21746.  
  21747.        4. If the value is not 0, restart the slave threads with `START
  21748.           SLAVE'.
  21749.  
  21750.        5. Repeat the procedure later to see if you have better luck
  21751.           next time.
  21752.  
  21753.  
  21754.      We have plans to fix this problem in the near future.
  21755.  
  21756.    * It is safe to connect servers in a circular master/slave
  21757.      relationship with `log-slave-updates' enabled.  Note, however,
  21758.      that many queries will not work correctly in this kind of setup
  21759.      unless your client code is written to take care of the potential
  21760.      problems that can happen from updates that occur in different
  21761.      sequence on different servers.
  21762.  
  21763.      This means that you can do a setup like the following:
  21764.  
  21765.           A -> B -> C -> A
  21766.  
  21767.      Server IDs are encoded in the binary log events.  A will know when
  21768.      an event it reads had originally been created by A, so A will not
  21769.      execute it and there will be no infinite loop.  But this circular
  21770.      setup will work only if you only if you perform no conflicting
  21771.      updates between the tables.  In other words, if you insert data in
  21772.      A and C, you should never insert a row in A that may have a
  21773.      conflicting key with a row insert in C.  You should also not update
  21774.      the same rows on two servers if the order in which the updates are
  21775.      applied matters.
  21776.  
  21777.    * If a query on the slave gets an error, the slave SQL thread will
  21778.      terminate, and a message will appear in the slave error log. You
  21779.      should then connect to the slave manually, fix the cause of the
  21780.      error (for example, non-existent table), and then run `START
  21781.      SLAVE'.
  21782.  
  21783.    * If the connection to the master is lost, the slave will try to
  21784.      reconnect immediately. If that fails, the slave will retry every
  21785.      `master-connect-retry' seconds (default 60). Because of this, it
  21786.      is safe to shut down the master, and then restart it after a
  21787.      while. The slave will also be able to deal with network
  21788.      connectivity outages. However, the slave will notice the network
  21789.      outage only after receiving no data from the master for
  21790.      `slave_net_timeout' seconds. So if your outages are short, you may
  21791.      want to decrease `slave_net_timeout'.  *Note `SHOW VARIABLES':
  21792.      SHOW VARIABLES.
  21793.  
  21794.    * Shutting down the slave (cleanly) is also safe, as it keeps track
  21795.      of where it left off.  Unclean shutdowns might produce problems,
  21796.      especially if disk cache was not synced before the system died.
  21797.      Your system fault tolerance will be greatly increased if you have
  21798.      a good UPS.
  21799.  
  21800.    * Due to the non-transactional nature of MyISAM tables, it is
  21801.      possible to have a query that will only partially update a table
  21802.      and return an error code. This can happen, for example, on a
  21803.      multi-row insert that has one row violating a key constraint, or
  21804.      if a long update query is killed after updating some of the rows.
  21805.      If that happens on the master, the slave thread will exit and wait
  21806.      for the DBA to decide what to do about it unless the error code is
  21807.      legitimate and the query execution results in the same error code.
  21808.      If this error code validation behavior is not desirable, some (or
  21809.      all) errors can be masked out (ignored) with the
  21810.      `--slave-skip-errors' option.  This option is available starting
  21811.      with MySQL Version 3.23.47.
  21812.  
  21813.    * If you update transactional tables from non-transactional tables
  21814.      inside a `BEGIN/COMMIT' segment, updates to the binary log may be
  21815.      out of sync if some thread changes the non-transactional table
  21816.      before the transaction commits.  This is because the transaction
  21817.      is written to the binary log only when it's commited.
  21818.  
  21819.    * Before version 4.0.15, any update to a non-transactional table is
  21820.      written to the binary log at once when the update is made while
  21821.      transactional updates are written on `COMMIT' or not written at
  21822.      all if you use `ROLLBACK'; you have to take this into account when
  21823.      updating both transactional tables and non-transactional tables in
  21824.      the same transaction if you are using binary logging for backups or
  21825.      replication. In version 4.0.15, we changed the logging behavior
  21826.      for transactions that mix updates to transactional and
  21827.      non-transactional tables, which solves the problems (order of
  21828.      queries is good in binlog, and all needed queries are written to
  21829.      the binlog even in case of `ROLLBACK'). The problem which remains
  21830.      is when a second connection updates the non-transactional table
  21831.      while the first connection's transaction is not finished yet
  21832.      (wrong order can still occur, because the second connection's
  21833.      update will be written immediately after it is done).
  21834.  
  21835. The following table lists problems in MySQL 3.23 that are fixed in
  21836. MySQL 4.0:
  21837.  
  21838.    * `LOAD DATA INFILE' is handled properly, as long as the data file
  21839.      still resides on the master server at the time of update
  21840.      propagation.
  21841.  
  21842.    * `LOAD LOCAL DATA INFILE' will be skipped.
  21843.  
  21844.    * In 3.23 `RAND()' in updates does not replicate properly.  Use
  21845.      `RAND(some_non_rand_expr)' if you are replicating updates with
  21846.      `RAND()'. You can, for example, use `UNIX_TIMESTAMP()' for the
  21847.      argument to `RAND()'. This is fixed in 4.0.
  21848.  
  21849. Replication Startup Options
  21850. ===========================
  21851.  
  21852. On both the master and the slave you need to use the `server-id' option
  21853. to establish a unique replication ID for each server. You should pick a
  21854. unique integer in the range from 1 to 2^32 - 1 for each master and
  21855. slave.  Example: `server-id=3'
  21856.  
  21857. The options that you can use on the master server for controlling binary
  21858. logging are all described in *Note Binary log::.
  21859.  
  21860. The following table describes the options you can use on slave servers.
  21861. You can specify them on the command line or in an option file.
  21862.  
  21863. *NOTE*: Replication handles the following options in a special way:
  21864.  
  21865.    * `--master-host'
  21866.  
  21867.    * `--master-user'
  21868.  
  21869.    * `--master-password'
  21870.  
  21871.    * `--master-port'
  21872.  
  21873.    * `--master-connect-retry'
  21874.  
  21875. If no `master.info' file exists when the slave server starts, it uses
  21876. values for those options that are specified in option files or on the
  21877. command line.  This will occur when you start the server as a
  21878. replication slave for the very first time, or you have run `RESET
  21879. SLAVE' and shut down and restarted the slave server.
  21880.  
  21881. However, if the `master.info' file exists when the slave server starts,
  21882. it uses the values in the file and *IGNORES* any values specified for
  21883. those options in option files or on the command line.
  21884.  
  21885. Suppose you specify this option in your `my.cnf' file:
  21886.  
  21887.      [mysqld]
  21888.      master-host=this_host
  21889.  
  21890. The first time you start the server as a replication slave, it will
  21891. read and use that option from the `my.cnf' file.  The server will then
  21892. record that value in the `master.info' file.  The next time you start
  21893. the server, it will read the master host value from the `master.info'
  21894. file only.  If you modify the `my.cnf' file to specify a different
  21895. master host, it will have no effect.  You must use `CHANGE MASTER TO'
  21896. instead.
  21897.  
  21898. As of MySQL 4.1.1, the following options also are handled specially:
  21899.  
  21900.    * `--master-ssl'
  21901.  
  21902.    * `--master-ssl-ca'
  21903.  
  21904.    * `--master-ssl-capath'
  21905.  
  21906.    * `--master-ssl-cert'
  21907.  
  21908.    * `--master-ssl-cipher'
  21909.  
  21910.    * `--master-ssl-key'
  21911.  
  21912. The `master.info' file includes the values corresponding to those
  21913. options. In addition, the 4.1.1 file format includes as its first line
  21914. the number of lines in the file. If you upgrade an older server to
  21915. 4.1.1, the `master.info' will be upgraded to the new format
  21916. automatically when the new server starts. (If you downgrade a 4.1.1 or
  21917. newer server to a version older than 4.1.1, you should manually remove
  21918. the first line before starting the older server for the first time.)
  21919.  
  21920. Because the server gives an existing `master.info' file precedence over
  21921. the startup options just described, you might prefer not to use startup
  21922. options for these values at all, and instead specify them by using the
  21923. `CHANGE MASTER TO' statement.  See *Note `CHANGE MASTER TO': CHANGE
  21924. MASTER TO.
  21925.  
  21926. This example shows a more extensive use of startup options to configure
  21927. a slave server:
  21928.  
  21929.      [mysqld]
  21930.      server-id=2
  21931.      master-host=db-master.mycompany.com
  21932.      master-port=3306
  21933.      master-user=pertinax
  21934.      master-password=freitag
  21935.      master-connect-retry=60
  21936.      report-host=db-slave.mycompany.com
  21937.  
  21938. The following list describes startup options for controlling
  21939. replication:
  21940.  
  21941. `--log-slave-updates'
  21942.      Tells the slave to log the updates performed by its SQL thread to
  21943.      the slave's own binary log. Off by default.  For this option to
  21944.      have any effect, the slave must be started with binary logging
  21945.      enabled (`--log-bin' option).  `--log-slave-updates' is used when
  21946.      you want to chain replication servers.  For example, you might
  21947.      want a setup like this:
  21948.  
  21949.           A -> B -> C
  21950.  
  21951.      That is, A serves as the master for the slave B, and B serves as
  21952.      the master for the slave C. For this to work, where B is both a
  21953.      master and a slave, you must start B with the
  21954.      `--log-slave-updates' option.  A and B must both be started with
  21955.      binary logging enabled.
  21956.  
  21957. `--log-warnings'
  21958.      Makes the slave print more messages about what it is doing. For
  21959.      example, it will warn you that it succeeded in reconnecting after a
  21960.      network/connection failure, and warn you about how each slave
  21961.      thread started.
  21962.  
  21963.      This option is not limited to replication use only. It produces
  21964.      warnings across a spectrum of server activities.
  21965.  
  21966. `--master-host=host'
  21967.      Specify the hostname or IP address of the master replication
  21968.      server.  If this option is not given, the slave thread will not be
  21969.      started.  The value in `master.info' takes precedence if it can be
  21970.      read.  Probably a better name for this options would have been
  21971.      something like `--bootstrap-master-host', but it is too late to
  21972.      change now.
  21973.  
  21974. `--master-user=username'
  21975.      The username of the account that the slave thread uses for
  21976.      authentication when connecting to the master. The account must
  21977.      have the `REPLICATION SLAVE' privilege (prior to MySQL 4.0.2, it
  21978.      must have the `FILE' privilege instead). If the master user is not
  21979.      set, user `test' is assumed. The value in `master.info' takes
  21980.      precedence if it can be read.
  21981.  
  21982. `--master-password=password'
  21983.      The password of the account that the slave thread uses for
  21984.      authentication when connecting to the master.  If not set, an
  21985.      empty password is assumed. The value in `master.info' takes
  21986.      precedence if it can be read.
  21987.  
  21988. `--master-port=port_number'
  21989.      The port the master is listening on. If not set, the compiled
  21990.      setting of `MYSQL_PORT' is assumed. If you have not tinkered with
  21991.      `configure' options, this should be 3306. The value in
  21992.      `master.info' takes precedence if it can be read.
  21993.  
  21994. `--master-connect-retry=seconds'
  21995.      The number of seconds the slave thread sleeps before retrying to
  21996.      connect to the master in case the master goes down or the
  21997.      connection is lost.  Default is 60. The value in `master.info'
  21998.      takes precedence if it can be read.
  21999.  
  22000. `--master-info-file=filename'
  22001.      Specifies the name to use for the file in which the slave records
  22002.      information about the master.  The default name is `mysql.info' in
  22003.      the data directory.
  22004.  
  22005. `--master-ssl'
  22006. `--master-ssl-ca=file_name'
  22007. `--master-ssl-capath=directory_name'
  22008. `--master-ssl-cert=file_name'
  22009. `--master-ssl-cipher=cipher_list'
  22010. `--master-ssl-key=file_name'
  22011.      These options are used for setting up a secure replication
  22012.      connection to the master server using SSL.  Their meanings are the
  22013.      same as the corresponding `--ssl', `--ssl-ca', `--ssl-capath',
  22014.      `--ssl-cert', `--ssl-cipher', `--ssl-key' options described in
  22015.      *Note SSL options::.
  22016.  
  22017.      These options are operational as of MySQL 4.1.1.
  22018.  
  22019. `--max-relay-log-size=#'
  22020.      To rotate the relay log automatically.  *Note `SHOW VARIABLES':
  22021.      SHOW VARIABLES.
  22022.  
  22023. `--relay-log=filename'
  22024.      To specify the location and name that should be used for relay
  22025.      logs.  You can use this to have hostname-independant relay log
  22026.      names, or if your relay logs tend to be big (and you don't want to
  22027.      decrease `max_relay_log_size') and you need to put them on some
  22028.      area different from the data directory, or if you want to increase
  22029.      speed by balancing load between disks.
  22030.  
  22031. `--relay-log-index=filename'
  22032.      To specify the location and name that should be used for the relay
  22033.      logs index file.
  22034.  
  22035. `--relay-log-info-file=filename'
  22036.      To give `relay-log.info' another name and/or to put it in another
  22037.      directory than the data directory.
  22038.  
  22039. `--relay-log-purge=0|1'
  22040.      Disables/enables automatic purging of relay logs as soon as they
  22041.      are not needed any more. This is a global variable that can be
  22042.      dynamically changed with `SET GLOBAL RELAY_LOG_PURGE=0|1'. The
  22043.      default value is 1.
  22044.  
  22045.      This option is available as of MySQL 4.1.1.
  22046.  
  22047. `--relay-log-space-limit=#'
  22048.      To put an upper limit on the total size of all relay logs on the
  22049.      slave (a value of 0 means "unlimited"). This is useful if you have
  22050.      a small hard disk on your slave machine. When the limit is
  22051.      reached, the I/O thread pauses (does not read the master's binlog)
  22052.      until the SQL thread has caught up and deleted some now unused
  22053.      relay logs. Note that this limit is not absolute: there are cases
  22054.      where the SQL thread needs more events to be able to delete; in
  22055.      that case the I/O thread will overgo the limit until deletion
  22056.      becomes possible. Not doing so would cause a deadlock (which
  22057.      happens before MySQL 4.0.13).  Users should not set
  22058.      `--relay-log-space-limit' to less than twice the value of
  22059.      `--max-relay-log-size' (or `--max-binlog-size' if
  22060.      `--max-relay-log-size' is 0) because in that case there are
  22061.      chances that when the I/O thread waits for free space because
  22062.      `--relay-log-space-limit' is exceeded, the SQL thread has no relay
  22063.      log to purge and so cannot satisfy the I/O thread, forcing the I/O
  22064.      thread to temporarily ignore `--relay-log-space-limit'.
  22065.  
  22066. `--replicate-do-table=db_name.table_name'
  22067.      Tells the slave thread to restrict replication to the specified
  22068.      table.  To specify more than one table, use the directive multiple
  22069.      times, once for each table.  This will work for cross-database
  22070.      updates, in contrast to `--replicate-do-db'.  Please read the
  22071.      notes that follow this option list.
  22072.  
  22073. `--replicate-ignore-table=db_name.table_name'
  22074.      Tells the slave thread to not replicate any command that updates
  22075.      the specified table (even if any other tables may be update by the
  22076.      same command). To specify more than one table to ignore, use the
  22077.      directive multiple times, once for each table. This will work for
  22078.      cross-database updates, in contrast to `--replicate-ignore-db'.
  22079.      Please read the notes that follow this option list.
  22080.  
  22081. `--replicate-wild-do-table=db_name.table_name'
  22082.      Tells the slave thread to restrict replication to queries where
  22083.      any of the updated tables match the specified wildcard pattern.
  22084.      To specify more than one table, use the directive multiple times,
  22085.      once for each table.  This will work for cross-database updates.
  22086.      Please read the notes that follow this option list.
  22087.  
  22088.      Example: `--replicate-wild-do-table=foo%.bar%' will replicate only
  22089.      updates that uses a table in any databases that start with `foo'
  22090.      and whose table names start with `bar'.
  22091.  
  22092.      Note that if you do `--replicate-wild-do-table=foo%.%' then the
  22093.      rule will be propagated to `CREATE DATABASE' and `DROP DATABASE',
  22094.      that is, these two statements will be replicated if the database
  22095.      name matches the database pattern (`foo%' here) (this magic is
  22096.      triggered by `%' being the table pattern).
  22097.  
  22098.      Escaping wildcard characters `_' and `%': if you want to
  22099.      replicate, for example, all tables of the `my_own%db' database
  22100.      (this is the exact name of the database), but not replicate tables
  22101.      from the `my1ownAABCdb' database, you should escape the `_' and
  22102.      `%': you should use something like this:
  22103.      `replicate-wild-do-table=my\_own\%db'. And if you are specifying
  22104.      this option from the command-line, depending on your system you
  22105.      may need to escape the `\' (for example, with a `bash' shell, you
  22106.      would need to type `--replicate-wild-do-table=my\\_own\\%db').
  22107.  
  22108. `--replicate-wild-ignore-table=db_name.table_name'
  22109.      Tells the slave thread to not replicate a query where any table
  22110.      matches the given wildcard pattern. To specify more than one table
  22111.      to ignore, use the directive multiple times, once for each table.
  22112.      This will work for cross-database updates.  Please read the notes
  22113.      that follow this option list.
  22114.  
  22115.      Example: `--replicate-wild-ignore-table=foo%.bar%' will not do
  22116.      updates to tables in databases that start with `foo' and whose
  22117.      table names start with `bar'.
  22118.  
  22119.      Note that if you do `--replicate-wild-ignore-table=foo%.%' then the
  22120.      rule will be propagated to `CREATE DATABASE' and `DROP DATABASE',
  22121.      that is, these two statements will not be replicated if the
  22122.      database name matches the database pattern (`foo%' here) (this
  22123.      magic is triggered by `%' being the table pattern).
  22124.  
  22125.      Escaping wildcard characters `_' and `%': see notes in the
  22126.      description of `replicate-wild-do-table' just above.
  22127.  
  22128. `--replicate-do-db=database_name'
  22129.      Tells the slave to restrict replication to commands where the
  22130.      current database (that is, the one selected by `USE') is
  22131.      `database_name'.  To specify more than one database, use the
  22132.      directive multiple times, once for each database. Note that this
  22133.      will not replicate cross-database queries such as `UPDATE
  22134.      some_db.some_table SET foo='bar'' while having selected a
  22135.      different or no database. If you need cross database updates to
  22136.      work, make sure you have 3.23.28 or later, and use
  22137.      `--replicate-wild-do-table=db_name.%'.  Please read the notes that
  22138.      follow this option list.
  22139.  
  22140.      Example of what does not work as you could expect it: if the slave
  22141.      is started with `--replicate-do-db=sales', and you do `USE prices;
  22142.      UPDATE sales.january SET amount=amount+1000;', this query will not
  22143.      be replicated.
  22144.  
  22145.      If you need cross database updates to work, use
  22146.      `--replicate-wild-do-table=db_name.%' instead.
  22147.  
  22148.      The main reason for this "just-check-the-current-database"
  22149.      behavior is that it's hard from the command alone to know if a
  22150.      query should be replicated or not; for example if you are using
  22151.      multiple-table-delete or multiple-table-update commands that go
  22152.      across multiple databases.  It's also very fast to just check the
  22153.      current database.
  22154.  
  22155. `--replicate-ignore-db=database_name'
  22156.      Tells the slave to not replicate any command where the current
  22157.      database (that is, the one selected by `USE') is `database_name'.
  22158.      To specify more than one database to ignore, use the directive
  22159.      multiple times, once for each database.  You should not use this
  22160.      directive if you are using cross table updates and you don't want
  22161.      these update to be replicated.  Please read the notes that follow
  22162.      this option list.
  22163.  
  22164.      Example of what does not work as you could expect it: if the slave
  22165.      is started with `--replicate-ignore-db=sales', and you do `USE
  22166.      prices; UPDATE sales.january SET amount=amount+1000;', this query
  22167.      will be replicated.
  22168.  
  22169.      If you need cross database updates to work, use
  22170.      `--replicate-wild-ignore-table=db_name.%' instead.
  22171.  
  22172. `--replicate-rewrite-db=from_name->to_name'
  22173.      Tells the slave to translate the current database (that is, the
  22174.      one selected by `USE') to `to_name' if it was `from_name' on the
  22175.      master.  Only statements involving tables may be affected (`CREATE
  22176.      DATABASE', `DROP DATABASE' won't), and only if `from_name' was the
  22177.      current database on the master.  This will not work for
  22178.      cross-database updates.  Note that the translation is done before
  22179.      `--replicate-*' rules are tested.
  22180.  
  22181.      Example: `replicate-rewrite-db=master_db_name->slave_db_name'
  22182.  
  22183. `--report-host=host'
  22184.      The hostname or IP number of the slave to be reported to the
  22185.      master during slave registration. Will appear in the output of
  22186.      `SHOW SLAVE HOSTS'. Leave unset if you do not want the slave to
  22187.      register itself with the master. Note that it is not sufficient
  22188.      for the master to simply read the IP number of the slave from the
  22189.      TCP/IP socket once the slave connects. Due to `NAT' and other
  22190.      routing issues, that IP may not be valid for connecting to the
  22191.      slave from the master or other hosts.
  22192.  
  22193.      This option is available as of MySQL 4.0.0.
  22194.  
  22195. `--report-port=port_number'
  22196.      Port for connecting to slave reported to the master during slave
  22197.      registration.  Set it only if the slave is listening on a
  22198.      non-default port or if you have a special tunnel from the master or
  22199.      other clients to the slave. If not sure, leave this option unset.
  22200.  
  22201.      This option is available as of MySQL 4.0.0.
  22202.  
  22203. `--skip-slave-start'
  22204.      Tells the slave server not to start the slave threads on server
  22205.      startup. The user can start them later with `START SLAVE'.
  22206.  
  22207. `--slave_compressed_protocol=#'
  22208.      If 1, then use compression on the slave/client protocol if both
  22209.      slave and master support this.
  22210.  
  22211. `--slave-load-tmpdir=filename'
  22212.      This option is by default equal to the value of the `tmpdir'
  22213.      variable.  When the slave SQL thread replicates a `LOAD DATA
  22214.      INFILE' command, it extracts the to-be-loaded file from the relay
  22215.      log into temporary files, then loads these into the table. If the
  22216.      file loaded on the master was huge, the temporary files on the
  22217.      slave will be huge, too; therefore you may wish/have to tell the
  22218.      slave to put the temporary files on some large disk different from
  22219.      `tmpdir', using this option. In that case, you may also use the
  22220.      `--relay-log' option, as relay logs will be huge, too.
  22221.      `--slave-load-tmpdir' should point to a disk-based filesystem; not
  22222.      a memory-based one. Because the slave needs the temporary files
  22223.      used to replicate `LOAD DATA INFILE') to survive a machine's
  22224.      reboot.
  22225.  
  22226. `--slave-net-timeout=#'
  22227.      Number of seconds to wait for more data from the master before
  22228.      aborting the read, considering the connection broken and retrying
  22229.      to connect. The first retry occurs immediately after timeout. The
  22230.      interval between retries is controlled by the
  22231.      `--master-connect-retry' option.
  22232.  
  22233. `--slave-skip-errors= [err_code1,err_code2,... | all]'
  22234.      Tells the slave SQL thread to continue replication when a query
  22235.      returns an error from the provided list. Normally, replication
  22236.      will discontinue when an error is encountered, giving the user a
  22237.      chance to resolve the inconsistency in the data manually. Do not
  22238.      use this option unless you fully understand why you are getting
  22239.      the errors.  If there are no bugs in your replication setup and
  22240.      client programs, and no bugs in MySQL itself, you should never get
  22241.      an abort with error. Indiscriminate use of this option will result
  22242.      in slaves being hopelessly out of sync with the master and you
  22243.      having no idea how the problem happened.
  22244.  
  22245.      For error codes, you should use the numbers provided by the error
  22246.      message in your slave error log and in the output of `SHOW SLAVE
  22247.      STATUS'. A full list of error messages can be found in the source
  22248.      distribution in `Docs/mysqld_error.txt'.  The server error codes
  22249.      also are listed at *Note Error-returns::.
  22250.  
  22251.      You can (but should not) also use a very non-recommended value of
  22252.      `all' which will ignore all error messages and keep barging along
  22253.      regardless.  Needless to say, if you use it, we make no promises
  22254.      regarding your data integrity. Please do not complain if your data
  22255.      on the slave is not anywhere close to what it is on the master in
  22256.      this case -- you have been warned.
  22257.  
  22258.      Examples:
  22259.  
  22260.           --slave-skip-errors=1062,1053
  22261.           --slave-skip-errors=all
  22262.  
  22263. Some of these options, like all `--replicate-*' options, can only be
  22264. set at the slave server's startup, not on-the-fly. We plan to fix this.
  22265.  
  22266. Here is the order of evaluation of the `r--eplicate-*' rules, to decide
  22267. if the query is going to be executed by the slave or ignored by it:
  22268.   1. Are there some `--replicate-do-db' or `--replicate-ignore-db'
  22269.      rules?
  22270.         * Yes: test them like for `--binlog-do-db' and
  22271.           `--binlog-ignore-db' (*note Binary log::). What is the result
  22272.           of the test?
  22273.              - ignore the query: ignore it and exit.
  22274.  
  22275.              - execute the query: don't execute it immediately, defer
  22276.                the decision, go to step below.
  22277.  
  22278.         * No: go to step below.
  22279.  
  22280.   2. Are there some `--replicate-*-table' rules?
  22281.         * No: execute the query and exit.
  22282.  
  22283.         * Yes: go to step below. Only tables which are to be updated
  22284.           will be compared to rules (`INSERT INTO sales SELECT * from
  22285.           prices': only `sales' will be compared to rules). If several
  22286.           tables are to be updated (multiple-table statement), the
  22287.           first matching table (matching "do" or "ignore") wins (that
  22288.           is, the first table is compared to rules, then if no decision
  22289.           could be taken the second table is compared to rules, etc).
  22290.  
  22291.   3. Are there some `--replicate-do-table' rules?
  22292.         * Yes: does the table match any of them?
  22293.              - Yes: execute the query and exit.
  22294.  
  22295.              - No: go to step below.
  22296.  
  22297.         * No: go to step below.
  22298.  
  22299.   4. Are there some `--replicate-ignore-table' rules?
  22300.         * Yes: does the table match any of them?
  22301.              - Yes: ignore the query and exit.
  22302.  
  22303.              - No: go to step below.
  22304.  
  22305.         * No: go to step below.
  22306.  
  22307.   5. Are there some `--replicate-wild-do-table' rules?
  22308.         * Yes: does the table match any of them?
  22309.              - Yes: execute the query and exit.
  22310.  
  22311.              - No: go to step below.
  22312.  
  22313.         * No: go to step below.
  22314.  
  22315.   6. Are there some `--replicate-wild-ignore-table' rules?
  22316.         * Yes: does the table match any of them?
  22317.              - Yes: ignore the query and exit.
  22318.  
  22319.              - No: go to step below.
  22320.  
  22321.         * No: go to step below.
  22322.  
  22323.   7. No `--replicate-*-table' rule was matched.  Is there another table
  22324.      to test against these rules?
  22325.         * Yes: loop.
  22326.  
  22327.         * No: we have tested all tables to be updated, could not match
  22328.           any rule.  Are there `--replicate-do-table' or
  22329.           `--replicate-wild-do-table' rules ?
  22330.              - Yes: ignore the query and exit.
  22331.  
  22332.              - No: execute the query and exit.
  22333.  
  22334. Replication FAQ
  22335. ===============
  22336.  
  22337. *Q*: How do I configure a slave if the master is already running and I
  22338. do not want to stop it?
  22339.  
  22340. *A*: There are several options. If you have taken a backup of the
  22341. master at some point and recorded the binlog name and offset ( from the
  22342. output of `SHOW MASTER STATUS' ) corresponding to the snapshot, do the
  22343. following:
  22344.  
  22345.   1. Make sure the slave is assigned a unique server ID.
  22346.  
  22347.   2. Execute the following statement on the slave, filling in
  22348.      appropriate values for each parameter:
  22349.  
  22350.           mysql> CHANGE MASTER TO
  22351.               ->     MASTER_HOST='master_host-name',
  22352.               ->     MASTER_USER='master_user_name',
  22353.               ->     MASTER_PASSWORD='master_pass',
  22354.               ->     MASTER_LOG_FILE='recorded_log_name',
  22355.               ->     MASTER_LOG_POS=recorded_log_pos;
  22356.  
  22357.   3. Execute `START SLAVE' on the slave.
  22358.  
  22359. If you do not have a backup of the master already, here is a quick way
  22360. to do it consistently:
  22361.  
  22362.   1. `FLUSH TABLES WITH READ LOCK'
  22363.  
  22364.   2. `gtar zcf /tmp/backup.tar.gz /var/lib/mysql' (or a variation of
  22365.      this)
  22366.  
  22367.   3. `SHOW MASTER STATUS' - make sure to record the output - you will
  22368.      need it later
  22369.  
  22370.   4. `UNLOCK TABLES'
  22371.  
  22372. An alternative is taking an SQL dump of the master instead of a binary
  22373. copy like above; for this you can use `mysqldump --master-data' on your
  22374. master and later run this SQL dump into your slave. However, this is
  22375. slower than makeing a binary copy.
  22376.  
  22377. No matter which of the two methods you use, afterwards follow the
  22378. instructions for the case when you have a snapshot and have recorded
  22379. the log name and offset. You can use the same snapshot to set up
  22380. several slaves. As long as the binary logs of the master are left
  22381. intact, you can wait as long as several days or in some cases maybe a
  22382. month to set up a slave once you have the snapshot of the master. In
  22383. theory the waiting gap can be infinite. The two practical limitations
  22384. is the diskspace of the master getting filled with old logs, and the
  22385. amount of time it will take the slave to catch up.
  22386.  
  22387. You can also use `LOAD DATA FROM MASTER'.  This is a convenient command
  22388. that takes a snapshot, restores it to the slave, and adjusts the log
  22389. name and offset on the slave all at once. In the future, `LOAD DATA
  22390. FROM MASTER' will be the recommended way to set up a slave.  Be warned,
  22391. howerver, that the read lock may be held for a long time if you use
  22392. this command. It is not yet implemented as efficiently as we would like
  22393. to have it. If you have large tables, the preferred method at this time
  22394. is still with a local `tar' snapshot after executing `FLUSH TABLES WITH
  22395. READ LOCK'.
  22396.  
  22397. *Q*: Does the slave need to be connected to the master all the time?
  22398.  
  22399. *A*: No, it does not. The slave can go down or stay disconnected for
  22400. hours or even days, then reconnect and catch up on the updates.  For
  22401. example, you can set up a master/slave relationship over a dial-up link
  22402. where the link is up only sporadically and for short periods of time.
  22403. The implication of this is that at any given time the slave is not
  22404. guaranteed to be in sync with the master unless you take some special
  22405. measures. In the future, we will have the option to block the master
  22406. until at least one slave is in sync.
  22407.  
  22408. *Q*: How do I know how late a slave is compared to the master? In other
  22409. words, how do I know the date of the last query replicated by the slave?
  22410.  
  22411. *A*: If the slave is 4.1.1 or newer, read the `Seconds_Behind_Master'
  22412. column in `SHOW SLAVE STATUS'. For older versions, the following
  22413. applies.  This is possible only if the slave SQL thread exists (that
  22414. is, if it shows up in `SHOW PROCESSLIST', *note Replication
  22415. Implementation Details::) (in MySQL 3.23: if the slave thread exists,
  22416. that is, shows up in `SHOW PROCESSLIST'), and if it has executed at
  22417. least one event from the master. Indeed, when the slave SQL thread
  22418. executes an event read from the master, this thread modifies its own
  22419. time to the event's timestamp (this is why `TIMESTAMP' is well
  22420. replicated). So in the `Time' column in the output of `SHOW
  22421. PROCESSLIST', the number of seconds displayed for the slave SQL thread
  22422. is the number of seconds between the timestamp of the last replicated
  22423. event and the real time of the slave machine. You can use this to
  22424. determine the date of the last replicated event. Note that if your
  22425. slave has been disconnected from the master for one hour, then
  22426. reconnects, you may immediately see `Time' values like 3600 for the
  22427. slave SQL thread in `SHOW PROCESSLIST'... This would be because the
  22428. slave is executing queries that are one hour old.
  22429.  
  22430. *Q*: How do I force the master to block updates until the slave catches
  22431. up?
  22432.  
  22433. *A*: Use the following procedure:
  22434.  
  22435.   1. On the master, execute these commands:
  22436.  
  22437.           mysql> FLUSH TABLES WITH READ LOCK;
  22438.           mysql> SHOW MASTER STATUS;
  22439.  
  22440.      Record the log name and the offset from the output of the `SHOW'
  22441.      statement.
  22442.  
  22443.   2. On the slave, issue this command, where the replication
  22444.      coordinates that are the arguments to the `MASTER_POS_WAIT()'
  22445.      function are the values recorded in the previous step:
  22446.  
  22447.           mysql> SELECT MASTER_POS_WAIT('log_name', log_offset);
  22448.  
  22449.      The `SELECT' statement will block until the slave reaches the
  22450.      specified log file and offset. At that point, the slave will be in
  22451.      sync with the master and the statement will return.
  22452.  
  22453.   3. On the master, issue the following statement to allow the master
  22454.      to begin processing updates again:
  22455.  
  22456.           mysql> UNLOCK TABLES;
  22457.  
  22458.  
  22459. *Q*: What issues should I be aware of when setting up two-way
  22460. replication?
  22461.  
  22462. *A*: MySQL replication currently does not support any locking protocol
  22463. between master and slave to guarantee the atomicity of a distributed
  22464. (cross-server) update. In other words, it is possible for client A to
  22465. make an update to  co-master 1, and in the meantime, before it
  22466. propagates to co-master 2, client B could make an update to co-master 2
  22467. that will make the update of client A work differently than it did on
  22468. co-master 1. Thus, when the update of client A will make it to
  22469. co-master 2, it will produce  tables that are different than what you
  22470. have on co-master 1, even after all the updates from co-master 2 have
  22471. also propagated. So you should not co-chain two servers in a two-way
  22472. replication relationship, unless you are sure that your updates can
  22473. safely happen in any order, or unless you take care of mis-ordered
  22474. updates somehow in the client code.
  22475.  
  22476. You must also realize that two-way replication actually does not improve
  22477. performance very much (if at all), as far as updates are concerned. Both
  22478. servers need to do the same amount of updates each, as you would have
  22479. one server do. The only difference is that there will be a little less
  22480. lock contention, because the updates originating on another server will
  22481. be serialized in one slave thread. Even so, this benefit might be
  22482. offset by network delays.
  22483.  
  22484. *Q*: How can I use replication to improve performance of my system?
  22485.  
  22486. *A*: You should set up one server as the master and direct all writes
  22487. to it. Then configure as many slaves as you have the money and
  22488. rackspace for, and distribute the reads among the master and the slaves.
  22489. You can also start the slaves with `--skip-bdb',
  22490. `--low-priority-updates' and `--delay-key-write=ALL' to get speed
  22491. improvements for the slave.  In this case the slave will use
  22492. non-transactional `MyISAM' tables instead of `BDB' tables to get more
  22493. speed.
  22494.  
  22495. *Q*: What should I do to prepare client code in my own applications to
  22496. use performance-enhancing replication?
  22497.  
  22498. *A*: If the part of your code that is responsible for database access
  22499. has been properly abstracted/modularised, converting it to run with a
  22500. replicated setup should be very smooth and easy. Just change the
  22501. implementation of your database access to send all writes the the
  22502. master, and to send reads to either the master or a slave.  If your
  22503. code does not have this level of abstraction, setting up a replicated
  22504. system will give you the opportunity and motivation to it clean up.
  22505. You should start by creating a wrapper library or module with the
  22506. following functions:
  22507.  
  22508.    * `safe_writer_connect()'
  22509.  
  22510.    * `safe_reader_connect()'
  22511.  
  22512.    * `safe_reader_query()'
  22513.  
  22514.    * `safe_writer_query()'
  22515.  
  22516. `safe_' in each function name means that the function will take care of
  22517. handling all the error conditions.  You can use different names for the
  22518. functions. The important thing is to have a unified interface for
  22519. connecting for reads, connecting for writes, doing a read, and doing a
  22520. write.
  22521.  
  22522. You should then convert your client code to use the wrapper library.
  22523. This may be a painful and scary process at first, but it will pay off in
  22524. the long run. All applications that use the approach just described
  22525. will be able to take advantage of a master/slave configuration, even
  22526. one involving multiple slaves.  The code will be a lot easier to
  22527. maintain, and adding troubleshooting options will be trivial. You will
  22528. just need to modify one or two functions, for example, to log how long
  22529. each query took, or which query, among your many thousands, gave you an
  22530. error.
  22531.  
  22532. If you have written a lot of code already, you may want to automate the
  22533. conversion task by using the `replace' utility that comes with the
  22534. standard distribution of MySQL, or just write your own Perl script.
  22535. Hopefully, your code follows some recognizable pattern. If not, then
  22536. you are probably better off rewriting it anyway, or at least going
  22537. through and manually beating it into a pattern.
  22538.  
  22539. *Q*: When and how much can MySQL replication improve the performance of
  22540. my system?
  22541.  
  22542. *A*: MySQL replication is most beneficial for a system with frequent
  22543. reads and infrequent writes. In theory, by using a
  22544. single-master/multiple-slave setup, you can scale the system by adding
  22545. more slaves until you either run out of network bandwidth, or your
  22546. update load grows to the point that the master cannot handle it.
  22547.  
  22548. In order to determine how many slaves you can get before the added
  22549. benefits begin to level out, and how much you can improve performance
  22550. of your site, you need to know your query patterns, and empirically
  22551. (by benchmarking) determine the relationship between the throughput on
  22552. reads (reads per second, or `max_reads') and on writes (`max_writes')
  22553. on a typical master and a typical slave. The example here will show you
  22554. a rather simplified calculation of what you can get with replication
  22555. for a hypothetical system.
  22556.  
  22557. Let's say that system load consists of 10% writes and 90% reads, and we
  22558. have determined `max_reads' to be 1200 - 2 * `max_writes'.  In other
  22559. words, the system can do 1200 reads per second with no writes, the
  22560. average write is twice as slow as average read, and the relationship is
  22561. linear. Let us suppose that the master and each slave have the same
  22562. capacity, and that we have 1 master and N slaves. Then we have for each
  22563. server (master or slave):
  22564.  
  22565. `reads = 1200 - 2 * writes' (from benchmarks)
  22566.  
  22567. `reads = 9* writes / (N + 1) ' (reads split, but writes go to all
  22568. servers)
  22569.  
  22570. `9*writes/(N+1) + 2 * writes = 1200'
  22571.  
  22572. `writes = 1200/(2 + 9/(N+1)'
  22573.  
  22574. This analysis yields the following conclusions:
  22575.  
  22576.    * If N = 0 (which means we have no replication), our system can
  22577.      handle 1200/11, about 109 writes per second (which means we will
  22578.      have 9 times as many reads due to the nature of our application).
  22579.  
  22580.    * If N = 1, we can get up to 184 writes per second.
  22581.  
  22582.    * If N = 8, we get up to 400.
  22583.  
  22584.    * If N = 17, 480 writes.
  22585.  
  22586.    * Eventually, as N approaches infinity (and our budget negative
  22587.      infinity), we can get very close to 600 writes per second,
  22588.      increasing system throughput about 5.5 times. However, with only 8
  22589.      servers, we increased it almost 4 times already.
  22590.  
  22591.  
  22592. Note that these computations assume infinite network bandwidth and
  22593. neglect several other factors that could turn out to be significant on
  22594. your system. In many cases, you may not be able to perform a computation
  22595. similar to the one above that will accurately predict what will happen
  22596. on your system if you add N replication slaves. However, answering the
  22597. following questions should help you decide whether and how much
  22598. replication will improve the performance of your system:
  22599.  
  22600.    * What is the read/write ratio on your system?
  22601.  
  22602.    * How much more write load can one server handle if you reduce the
  22603.      reads?
  22604.  
  22605.    * How many slaves do you have bandwidth available for on your
  22606.      network?
  22607.  
  22608. *Q*: How can I use replication to provide redundancy/high availability?
  22609.  
  22610. *A*: With the currently available features, you would have to set up a
  22611. master and a slave (or several slaves), and write a script that will
  22612. monitor the master to see whether it is up, and instruct your
  22613. applications and the slaves of the master change in case of failure.
  22614. Some suggestions:
  22615.  
  22616.    * To tell a slave to change the master, use the `CHANGE MASTER TO'
  22617.      command.
  22618.  
  22619.    * A good way to keep your applications informed as to the location
  22620.      of the master is by having a dynamic DNS entry for the master.
  22621.      With `bind' you can use `nsupdate' to dynamically update your DNS.
  22622.  
  22623.    * You should run your slaves with the `--log-bin' option and without
  22624.      `--log-slave-updates'. This way the slave will be ready to become a
  22625.      master as soon as you issue `STOP SLAVE'; `RESET MASTER', and
  22626.      `CHANGE MASTER TO' on the other slaves.  For example, consider you
  22627.      have the following setup ("M" means the master, "S" the slaves,
  22628.      "WC" the clients that issue database writes and reads; clients
  22629.      that issue only database reads are not represented, because they
  22630.      need not switch):
  22631.  
  22632.                  WC
  22633.                   \
  22634.                    v
  22635.            WC----> M
  22636.                  / | \
  22637.                 /  |  \
  22638.                v   v   v
  22639.               S1   S2  S3
  22640.  
  22641.      S1 (like S2 and S3) is a slave running with `--log-bin' and
  22642.      without `--log-slave-updates'. As the only writes executed on S1
  22643.      are those replicated from M, the binary log on S1 is *empty*
  22644.      (remember, S1 runs without `--log-slave-updates').  Then, for some
  22645.      reason, M becomes unavailable, and you want S1 to become the new
  22646.      master (that is, direct all WC to S1, and make S2 and S3 replicate
  22647.      S1).
  22648.  
  22649.      Make sure that all slaves have processed any queries in their
  22650.      relay log.  On each slave, issue `STOP SLAVE IO_THREAD', then
  22651.      check the output of `SHOW PROCESSLIST' until you see `Has read all
  22652.      relay log'.  When this is true for all slaves, they can be
  22653.      reconfigured to the new setup.  Issue `STOP SLAVE' on all slaves,
  22654.      `RESET MASTER' on the slave being promoted to master, and `CHANGE
  22655.      MASTER' on the other slaves.
  22656.  
  22657.      No WC accesses M. Instruct all WC to direct their queries to S1.
  22658.      From now on, all queries sent by WC to S1 are written to the
  22659.      binary log of S1. The binary log of S1 contains exactly every
  22660.      writing query sent to S1 since M died.  On S2 (and S3) do `STOP
  22661.      SLAVE', `CHANGE MASTER TO MASTER_HOST='S1'' (where `'S1'' is
  22662.      replaced by the real hostname of S1). To `CHANGE MASTER', add all
  22663.      information about how to connect to S1 from S2 or S3 (user,
  22664.      password, port). In `CHANGE MASTER', no need to specify the name
  22665.      of S1's binary log or binary log position to read from: we know it
  22666.      is the first binary log, from position 4, and these are the
  22667.      defaults of `CHANGE MASTER'. Finally do `START SLAVE' on S2 and
  22668.      S3, and now you have this:
  22669.  
  22670.                  WC
  22671.                 /
  22672.                 |
  22673.            WC   |  M(unavailable)
  22674.             \   |
  22675.              \  |
  22676.               v v
  22677.                S1<--S2  S3
  22678.                 ^       |
  22679.                 +-------+
  22680.  
  22681.      When M is up again, you just have to issue on it the same `CHANGE
  22682.      MASTER' as the one issued on S2 and S3, so that M becomes a slave
  22683.      of S1 and picks all the WC writes it has missed while it was down.
  22684.      Now to make M a master again (because it is the most powerful
  22685.      machine, for example), follow the preceding procedure as if S1 was
  22686.      unavailable and M was to be the new master; then during the
  22687.      procedure don't forget to run `RESET MASTER' on M before making
  22688.      S1, S2, S3 slaves of M, or they may pick old WC writes from before
  22689.      M's unavailibility.
  22690.  
  22691.  
  22692. We are currently working on integrating an automatic master election
  22693. system into MySQL, but until it is ready, you will have to create your
  22694. own monitoring tools.
  22695.  
  22696. Troubleshooting Replication
  22697. ===========================
  22698.  
  22699. If you have followed the instructions, and your replication setup is not
  22700. working, first check the following:
  22701.  
  22702.    * *Check the error log for messages*. Many users have lost time by
  22703.      not doing this early enough.
  22704.  
  22705.    * Is the master logging to the binary log? Check with `SHOW MASTER
  22706.      STATUS'.  If it is, `Position' will be non-zero. If not, verify
  22707.      that you have given the master `log-bin' option and have set
  22708.      `server-id'.
  22709.  
  22710.    * Is the slave running? Do `SHOW SLAVE STATUS' and check that the
  22711.      `Slave_IO_Running' and `Slave_SQL_Running' values are both `Yes'.
  22712.      If not, verify slave options
  22713.  
  22714.    * If the slave is running, did it establish a connection with the
  22715.      master? Do `SHOW PROCESSLIST', find the I/O and SQL threads (*note
  22716.      Replication Implementation Details:: to see how they display), and
  22717.      check their `State' column. If it says `Connecting to master',
  22718.      verify the privileges for the replication user on the master,
  22719.      master hostname, your DNS setup, whether the master is actually
  22720.      running, whether it is reachable from the slave.
  22721.  
  22722.    * If the slave was running before but now has stopped, the reason
  22723.      usually is that some query that succeeded on the master failed on
  22724.      the slave. This should never happen if you have taken a proper
  22725.      snapshot of the master, and never modify the data on the slave
  22726.      outside of the slave thread. If it does, it is a bug; read below
  22727.      on how to report it.
  22728.  
  22729.    * If a query on that succeeded on the master refuses to run on the
  22730.      slave, and it does not feasible to do a full database resync (that
  22731.      is, to delete the slave's database and copy a new snapshot from
  22732.      the master), try the following:
  22733.         - First see if the slave's table was different from the
  22734.           master's. Understand how it happened (it may be a bug: read
  22735.           the Changelogs in the online MySQL manual as
  22736.           `http://www.mysql.com/documentation' to check if this is a
  22737.           known bug and if it is fixed yet).  Then make the slave's
  22738.           table identical to the master's and run `START SLAVE'.
  22739.  
  22740.         - If the above does not work or does not apply, try to
  22741.           understand if it would be safe to make the update manually
  22742.           (if needed) and then ignore the next query from the master.
  22743.  
  22744.         - If you have decided you can skip the next query, issue the
  22745.           following statements:
  22746.  
  22747.                mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n;
  22748.                mysql> START SLAVE;
  22749.  
  22750.           The value of `n' should be 1 if the query does not use
  22751.           `AUTO_INCREMENT' or `LAST_INSERT_ID()'. Otherwise, the value
  22752.           should be 2.  The reason for using a value of 2 for queries
  22753.           that use `AUTO_INCREMENT' or `LAST_INSERT_ID()' is that they
  22754.           take two events in the binary log of the master.
  22755.  
  22756.         - Make sure you are not running into an old bug by upgrading to
  22757.           the most recent version.
  22758.  
  22759.         - If you are sure the slave started out perfectly in sync with
  22760.           the master, and no one has updated  the tables involved
  22761.           outside of slave thread, report the bug.
  22762.  
  22763. Reporting Replication Bugs
  22764. ==========================
  22765.  
  22766. When you have determined that there is no user error involved, and
  22767. replication still either does not work at all or is unstable, it is
  22768. time to send us a bug report. We need to get as much information as
  22769. possible from you to be able to track down the bug. Please do spend
  22770. some time and effort preparing a good bug report.
  22771.  
  22772. If you have a repeatable way to demonstrate the bug, please enter it
  22773. into our bugs database at `http://bugs.mysql.com/'. If you have a
  22774. phantom problem (one that you cannot duplicate "at will"), use the
  22775. following procedure:
  22776.  
  22777.   1. Verify that no user error is involved. For example, if you update
  22778.      the slave outside of the slave thread, the data will go out of
  22779.      sync, and you can have unique key violations on updates. In this
  22780.      case, the slave thread will stop and wait for you to clean up the
  22781.      tables manually to bring them in sync.  This is not a replication
  22782.      problem; it is a problem of outside interference that causes
  22783.      replication to fail.
  22784.  
  22785.   2. Run the slave with the `--log-slave-updates' and `--log-bin'
  22786.      options.  They will cause the slave to log the updates that it
  22787.      receives in its own binlogs.
  22788.  
  22789.   3. Save all evidence before resetting the replication state. If we
  22790.      have no information or only sketchy information, it will take us
  22791.      longer to track down the problem. The evidence you should collect
  22792.      is:
  22793.         * All binary logs from the master
  22794.  
  22795.         * All binary logs from the slave
  22796.  
  22797.         * The output of `SHOW MASTER STATUS' from the master at the time
  22798.           you have discovered the problem
  22799.  
  22800.         * The output of `SHOW SLAVE STATUS' from the master at the time
  22801.           you have discovered the problem
  22802.  
  22803.         * Error logs from the master and on the slave
  22804.  
  22805.   4. Use `mysqlbinlog' to examine the binary logs. The following should
  22806.      be helpful to find the trouble query, for example:
  22807.           mysqlbinlog -j pos_from_slave_status /path/to/log_from_slave_status | head
  22808.  
  22809. Once you have collected the evidence for the phantom problem, try hard
  22810. to isolate it into a separate test case first. Then enter the problem
  22811. into our bugs database at `http://bugs.mysql.com/' with as much
  22812. information as possible.
  22813.  
  22814. MySQL Optimization
  22815. ******************
  22816.  
  22817. Optimization is a complicated task because it ultimately requires
  22818. understanding of the whole system. While it may be possible to perform
  22819. some local optimizations with small knowledge of your system or
  22820. application, the more optimal you want your system to become the more
  22821. you will have to know about it.
  22822.  
  22823. This chapter tries to explain and give some examples of different ways
  22824. to optimize MySQL.  Remember, however, that there are always some
  22825. (increasingly harder) additional ways to make the system even faster.
  22826.  
  22827. Optimization Overview
  22828. =====================
  22829.  
  22830. The most important factor in making a system fast is the basic design.
  22831. You also need to know what kinds of things your system will be doing,
  22832. and what your bottlenecks are.
  22833.  
  22834. The most common bottlenecks are:
  22835.    * Disk seeks.  It takes time for the disk to find a piece of data.
  22836.      With modern disks in 1999, the mean time for this is usually lower
  22837.      than 10ms, so we can in theory do about 100 seeks a second. This
  22838.      time improves slowly with new disks and is very hard to optimize
  22839.      for a single table. The way to optimize this is to spread the data
  22840.      on more than one disk.
  22841.  
  22842.    * Disk reading/writing.  When the disk is at the correct position we
  22843.      need to read the data. With modern disks in 1999, one disk
  22844.      delivers something like 10-20 MB. This is easier to optimize than
  22845.      seeks because you can read in parallel from multiple disks.
  22846.  
  22847.    * CPU cycles.  When we have the data in main memory (or if it
  22848.      already were there) we need to process it to get to our result.
  22849.      Having small tables compared to the memory is the most common
  22850.      limiting factor. But then, with small tables speed is usually not
  22851.      the problem.
  22852.  
  22853.    * Memory bandwidth.  When the CPU needs more data than can fit in
  22854.      the CPU cache the main memory bandwidth becomes a bottleneck. This
  22855.      is an uncommon bottleneck for most systems, but one should be
  22856.      aware of it.
  22857.  
  22858. MySQL Design Limitations/Tradeoffs
  22859. ----------------------------------
  22860.  
  22861. When using the MyISAM storage engine, MySQL uses extremely fast table
  22862. locking (multiple readers / single writers). The biggest problem with
  22863. this table type occurs when you have a mix of a steady stream of
  22864. updates and slow selects on the same table.  If this is a problem with
  22865. some tables, you can use another table type for these. *Note Table
  22866. types::.
  22867.  
  22868. MySQL can work with both transactional and non-transactional tables.
  22869. To be able to work smoothly with non-transactional tables (which can't
  22870. roll back if something goes wrong), MySQL has the following rules:
  22871.  
  22872.    * All columns have default values.
  22873.  
  22874.    * If you insert a 'wrong' value in a column like a `NULL' in a `NOT
  22875.      NULL' column or a too big numerical value in a numerical column,
  22876.      MySQL will instead of giving an error instead set the column to
  22877.      the 'best possible value'.  For numerical values this is 0, the
  22878.      smallest possible values or the largest possible value. For
  22879.      strings this is either the empty string or the longest possible
  22880.      string that can be in the column.
  22881.  
  22882.    * All calculated expressions returns a value that can be used
  22883.      instead of signaling an error condition. For example 1/0 returns
  22884.      `NULL'
  22885.  
  22886. For more information about this, see *Note Constraints::.
  22887.  
  22888. The above means that one should not use MySQL to check fields content,
  22889. but one should do this in the application.
  22890.  
  22891. Portability
  22892. -----------
  22893.  
  22894. Because all SQL servers implement different parts of SQL, it takes work
  22895. to write portable SQL applications. For very simple selects/inserts it
  22896. is very easy, but the more you need the harder it gets. If you want an
  22897. application that is fast with many databases it becomes even harder!
  22898.  
  22899. To make a complex application portable you need to choose a number of
  22900. SQL servers that it should work with.
  22901.  
  22902. You can use the MySQL `crash-me' program/web-page
  22903. `http://www.mysql.com/information/crash-me.php' to find functions,
  22904. types, and limits you can use with a selection of database servers.
  22905. Crash-me now tests far from everything possible, but it is still
  22906. comprehensive with about 450 things tested.
  22907.  
  22908. For example, you shouldn't have column names longer than 18 characters
  22909. if you want to be able to use Informix or DB2.
  22910.  
  22911. Both the MySQL benchmarks and `crash-me' programs are very
  22912. database-independent.  By taking a look at how we have handled this, you
  22913. can get a feeling for what you have to do to write your application
  22914. database-independent.  The benchmarks themselves can be found in the
  22915. `sql-bench' directory in the MySQL source distribution. They are
  22916. written in Perl with DBI database interface (which solves the access
  22917. part of the problem).
  22918.  
  22919. See `http://www.mysql.com/information/benchmarks.html' for the results
  22920. from this benchmark.
  22921.  
  22922. As you can see in these results, all databases have some weak points.
  22923. That is, they have different design compromises that lead to different
  22924. behavior.
  22925.  
  22926. If you strive for database independence, you need to get a good feeling
  22927. for each SQL server's bottlenecks. MySQL is very fast in retrieving and
  22928. updating records, but will have a problem in mixing slow
  22929. readers/writers on the same table. Oracle, on the other hand, has a big
  22930. problem when you try to access rows that you have recently updated
  22931. (until they are flushed to disk). Transaction databases in general are
  22932. not very good at generating summary tables from log tables, as in this
  22933. case row locking is almost useless.
  22934.  
  22935. To get your application _really_ database-independent, you need to
  22936. define an easy extendable interface through which you manipulate your
  22937. data. As C++ is available on most systems, it makes sense to use a C++
  22938. classes interface to the databases.
  22939.  
  22940. If you use some specific feature for some database (like the `REPLACE'
  22941. command in MySQL), you should code a method for the other SQL servers
  22942. to implement the same feature (but slower).  With MySQL you can use the
  22943. `/*!  */' syntax to add MySQL-specific keywords to a query.  The code
  22944. inside `/**/' will be treated as a comment (ignored) by most other SQL
  22945. servers.
  22946.  
  22947. If high performance is more important than exactness, as in some web
  22948. applications, it is possibile to create an application layer that
  22949. caches all results to give you even higher performance. By letting old
  22950. results 'expire' after a while, you can keep the cache reasonably
  22951. fresh.  This provides a method to handle high load spikes, in which case
  22952. you can dynamically increase the cache and set the expire timeout higher
  22953. until things get back to normal.
  22954.  
  22955. In this case the table creation information should contain information
  22956. of the initial size of the cache and how often the table should normally
  22957. be refreshed.
  22958.  
  22959. What We Have Used MySQL For
  22960. ---------------------------
  22961.  
  22962. During MySQL initial development, the features of MySQL were made to
  22963. fit our largest customer. They handle data warehousing for a couple of
  22964. the biggest retailers in Sweden.
  22965.  
  22966. From all stores, we get weekly summaries of all bonus card transactions,
  22967. and we are expected to provide useful information for the store owners
  22968. to help them find how their advertisement campaigns are affecting their
  22969. customers.
  22970.  
  22971. The data is quite huge (about 7 million summary transactions per month),
  22972. and we have data for 4-10 years that we need to present to the users.
  22973. We got weekly requests from the customers that they want to get
  22974. 'instant' access to new reports from this data.
  22975.  
  22976. We solved this by storing all information per month in compressed
  22977. 'transaction' tables. We have a set of simple macros (script) that
  22978. generates summary tables grouped by different criteria (product group,
  22979. customer id, store ...) from the transactional tables.  The reports are
  22980. web pages that are dynamically generated by a small Perl script that
  22981. parses a web page, executes the SQL statements in it, and inserts the
  22982. results. We would have used PHP or mod_perl instead but they were not
  22983. available at that time.
  22984.  
  22985. For graphical data we wrote a simple tool in `C' that can produce GIFs
  22986. based on the result of an SQL query (with some processing of the
  22987. result). This is also dynamically executed from the Perl script that
  22988. parses the HTML files.
  22989.  
  22990. In most cases a new report can simply be done by copying an existing
  22991. script and modifying the SQL query in it.  In some cases, we will need
  22992. to add more fields to an existing summary table or generate a new one,
  22993. but this is also quite simple, as we keep all transactions tables on
  22994. disk.  (Currently we have at least 50G of transactions tables and 200G
  22995. of other customer data.)
  22996.  
  22997. We also let our customers access the summary tables directly with ODBC
  22998. so that the advanced users can themselves experiment with the data.
  22999.  
  23000. We haven't had any problems handling this with quite modest Sun Ultra
  23001. SPARCstation (2x200 Mhz). We recently upgraded one of our servers to a 2
  23002. CPU 400 Mhz UltraSPARC, and we are now planning to start handling
  23003. transactions on the product level, which would mean a ten-fold increase
  23004. of data. We think we can keep up with this by just adding more disk to
  23005. our systems.
  23006.  
  23007. We are also experimenting with Intel-Linux to be able to get more CPU
  23008. power cheaper. Now that we have the binary portable database format (new
  23009. in Version 3.23), we will start to use this for some parts of the
  23010. application.
  23011.  
  23012. Our initial feelings are that Linux will perform much better on
  23013. low-to-medium load and Solaris will perform better when you start to
  23014. get a high load because of extreme disk IO, but we don't yet have
  23015. anything conclusive about this. After some discussion with a Linux
  23016. kernel developer, this might be a side effect of Linux allocating so
  23017. many resources to the batch job that the interactive performance gets
  23018. very low. This makes the machine feel very slow and unresponsive while
  23019. big batches are going. Hopefully this will be better handled in future
  23020. Linux Kernels.
  23021.  
  23022. The MySQL Benchmark Suite
  23023. -------------------------
  23024.  
  23025. This section should contain a technical description of the MySQL
  23026. benchmark suite (and `crash-me'), but that description is not written
  23027. yet. Currently, you can get a good idea of the benchmark by looking at
  23028. the code and results in the `sql-bench' directory in any MySQL source
  23029. distribution.
  23030.  
  23031. This benchmark suite is meant to be a benchmark that will tell any user
  23032. what operations a given SQL implementation performs well or poorly.
  23033.  
  23034. Note that this benchmark is single-threaded, so it measures the minimum
  23035. time for the operations performed. We plan to add a lot of
  23036. multi-threaded tests to the benchmark suite in the future.
  23037.  
  23038. The following tables show some comparative benchmark results for several
  23039. database servers when accessed through ODBC on a Windows NT 4.0 machine.
  23040.  
  23041. *Reading 2000000 rows by  *Seconds**Seconds*
  23042. index*                            
  23043. mysql                     367     249
  23044. mysql_odbc                464     
  23045. db2_odbc                  1206    
  23046. informix_odbc             121126  
  23047. ms-sql_odbc               1634    
  23048. oracle_odbc               20800   
  23049. solid_odbc                877     
  23050. sybase_odbc               17614   
  23051.  
  23052. *Inserting 350768 rows*   *Seconds**Seconds*
  23053. mysql                     381     206
  23054. mysql_odbc                619     
  23055. db2_odbc                  3460    
  23056. informix_odbc             2692    
  23057. ms-sql_odbc               4012    
  23058. oracle_odbc               11291   
  23059. solid_odbc                1801    
  23060. sybase_odbc               4802    
  23061.  
  23062. For the preceding tests, MySQL was run with an index cache size of 8M.
  23063.  
  23064. We have gathered some more benchmark results at
  23065. `http://www.mysql.com/information/benchmarks.html'.
  23066.  
  23067. Note that Oracle is not included because they asked to be removed. All
  23068. Oracle benchmarks have to be passed by Oracle! We believe that makes
  23069. Oracle benchmarks *very* biased because the above benchmarks are
  23070. supposed to show what a standard installation can do for a single
  23071. client.
  23072.  
  23073. To use the benchmark suite, the following requirements must be
  23074. satisified:
  23075.  
  23076.    * The benchmark suite is provided with MySQL source distributions,
  23077.      so you must have a source distribution.  You can either download a
  23078.      released distribution from `http://www.mysql.com/downloads/', or
  23079.      use the current development source tree (*note Installing source
  23080.      tree::).
  23081.  
  23082.    * The benchmark scripts are written in Perl and use the Perl DBI
  23083.      module to access database servers, so DBI must be installed.  You
  23084.      will also need the server-specific DBD drivers for each of the
  23085.      servers you want to test.  For example, to test MySQL, PostgreSQL,
  23086.      and DB2, the DBD::mysql, DBD::Pg, and DBD::DB2 modules must be
  23087.      installed.
  23088.  
  23089.  
  23090. The benchmark suite is located in the `sql-bench' directory of MySQL
  23091. source distributions.  To run the benchmark tests, change location into
  23092. that directory and execute the `run-all-tests' script:
  23093.  
  23094.      shell> cd sql-bench
  23095.      shell> perl run-all-tests --server=server_name
  23096.  
  23097. `server_name' is one of supported servers. You can get a list of all
  23098. options and supported servers by invoking `run-all-tests --help'.
  23099.  
  23100. `crash-me' tries to determine what features a database supports and
  23101. what its capabilities and limitations are by actually running queries.
  23102. For example, it determines:
  23103.  
  23104.    * What column types are supported
  23105.  
  23106.    * How many indexes are supported
  23107.  
  23108.    * What functions are supported
  23109.  
  23110.    * How big a query can be
  23111.  
  23112.    * How big a `VARCHAR' column can be
  23113.  
  23114. We can find the result from `crash-me' on a lot of different databases
  23115. at `http://www.mysql.com/information/crash-me.php'.
  23116.  
  23117. Using Your Own Benchmarks
  23118. -------------------------
  23119.  
  23120. You should definitely benchmark your application and database to find
  23121. out where the bottlenecks are.  By fixing it (or by replacing the
  23122. bottleneck with a "dummy module") you can then easily identify the next
  23123. bottleneck (and so on).  Even if the overall performance for your
  23124. application currently is acceptable, you should at least make a plan
  23125. for each bottleneck, and decide how to solve it if someday you really
  23126. need the extra performance.
  23127.  
  23128. For an example of portable benchmark programs, look at the MySQL
  23129. benchmark suite. *Note MySQL Benchmarks: MySQL Benchmarks. You can take
  23130. any program from this suite and modify it for your needs. By doing
  23131. this, you can try different solutions to your problem and test which is
  23132. really fastest for you.
  23133.  
  23134. Another free benchmark suite is the `Open Source Database Benchmark',
  23135. available at `http://osdb.sourceforge.net/'.
  23136.  
  23137. It is very common for a problem to occur only when the system is very
  23138. heavily loaded. We have had many customers who contact us when they
  23139. have a (tested) system in production and have encountered load
  23140. problems. In most cases, performance problems turn out to be due to
  23141. issues of basic database design (table scans are *not good* at high
  23142. load) or problems with the operating system or libraries. Most of the
  23143. time, these problems would be a *lot* easier to fix if the systems were
  23144. not already in production.
  23145.  
  23146. To avoid problems like this, you should put some effort into
  23147. benchmarking your whole application under the worst possible load!  You
  23148. can use Super Smack for this. It is available at
  23149. `http://www.mysql.com/Downloads/super-smack/super-smack-1.0.tar.gz'.
  23150. As the name suggests, it can bring your system to its knees if you ask
  23151. it, so make sure to use it only on your development systems.
  23152.  
  23153. Optimizing `SELECT' Statements and Other Queries
  23154. ================================================
  23155.  
  23156. First, one thing that affects all queries: The more complex permission
  23157. system setup you have, the more overhead you get.
  23158.  
  23159. If you do not have any `GRANT' statements done, MySQL will optimize the
  23160. permission checking somewhat. So if you have a very high volume it may
  23161. be worth the time to avoid grants. Otherwise, more permission check
  23162. results in a larger overhead.
  23163.  
  23164. If your problem is with some explicit MySQL function, you can always
  23165. time this in the MySQL client:
  23166.  
  23167.      mysql> SELECT BENCHMARK(1000000,1+1);
  23168.      +------------------------+
  23169.      | BENCHMARK(1000000,1+1) |
  23170.      +------------------------+
  23171.      |                      0 |
  23172.      +------------------------+
  23173.      1 row in set (0.32 sec)
  23174.  
  23175. The above shows that MySQL can execute 1,000,000 `+' expressions in
  23176. 0.32 seconds on a `PentiumII 400MHz'.
  23177.  
  23178. All MySQL functions should be very optimized, but there may be some
  23179. exceptions, and the `BENCHMARK(loop_count,expression)' is a great tool
  23180. to find out if this is a problem with your query.
  23181.  
  23182. `EXPLAIN' Syntax (Get Information About a `SELECT')
  23183. ---------------------------------------------------
  23184.  
  23185.          EXPLAIN tbl_name
  23186.      or  EXPLAIN SELECT select_options
  23187.  
  23188. `EXPLAIN tbl_name' is a synonym for `DESCRIBE tbl_name' or `SHOW
  23189. COLUMNS FROM tbl_name'.
  23190.  
  23191. When you precede a `SELECT' statement with the keyword `EXPLAIN', MySQL
  23192. explains how it would process the `SELECT', providing information about
  23193. how tables are joined and in which order.
  23194.  
  23195. With the help of `EXPLAIN', you can see when you must add indexes to
  23196. tables to get a faster `SELECT' that uses indexes to find the records.
  23197.  
  23198. You should frequently run `ANALYZE TABLE' to update table statistics
  23199. such as cardinality of keys which can affect the choices the optimizer
  23200. makes. *Note ANALYZE TABLE::.
  23201.  
  23202. You can also see if the optimizer joins the tables in an optimal order.
  23203. To force the optimizer to use a specific join order for a `SELECT'
  23204. statement, add a `STRAIGHT_JOIN' clause.
  23205.  
  23206. For non-simple joins, `EXPLAIN' returns a row of information for each
  23207. table used in the `SELECT' statement. The tables are listed in the order
  23208. they would be read.  MySQL resolves all joins using a single-sweep
  23209. multi-join method. This means that MySQL reads a row from the first
  23210. table, then finds a matching row in the second table, then in the third
  23211. table and so on. When all tables are processed, it outputs the selected
  23212. columns and backtracks through the table list until a table is found
  23213. for which there are more matching rows. The next row is read from this
  23214. table and the process continues with the next table.
  23215.  
  23216. In MySQL version 4.1 the `EXPLAIN' output was changed to work better
  23217. with constructs like `UNION' statements, subqueries and derived tables.
  23218. Most notable is the addition of two new columns: `id' and `select_type'.
  23219.  
  23220. Output from `EXPLAIN' consists of the following columns:
  23221.  
  23222. `id'
  23223.      `SELECT' identifier, the sequential number of this `SELECT' within
  23224.      the query.
  23225.  
  23226. `select_type'
  23227.      Type of `SELECT' clause, which can be any of the following:
  23228.  
  23229.     `SIMPLE'
  23230.           Simple `SELECT' (not using `UNION' or subqueries).
  23231.  
  23232.     `PRIMARY'
  23233.           Outermost `SELECT'.
  23234.  
  23235.     `UNION'
  23236.           Second and further `SELECT' statements in a `UNION'.
  23237.  
  23238.     `DEPENDENT UNION'
  23239.           Second and further `SELECT' statements in a `UNION',
  23240.           dependent on outer subquery.
  23241.  
  23242.     `SUBQUERY'
  23243.           First `SELECT' in subquery.
  23244.  
  23245.     `DEPENDENT SUBQUERY'
  23246.           First `SELECT', dependent on outer subquery.
  23247.  
  23248.     `DERIVED'
  23249.           Derived table `SELECT' (subquery in `FROM' clause).
  23250.  
  23251. `table'
  23252.      The table to which the row of output refers.
  23253.  
  23254. `type'
  23255.      The join type. The different join types are listed here, ordered
  23256.      from best to worst type:
  23257.  
  23258.     `system'
  23259.           The table has only one row (= system table). This is a
  23260.           special case of the `const' join type.
  23261.  
  23262.     `const'
  23263.           The table has at most one matching row, which will be read at
  23264.           the start of the query. Because there is only one row, values
  23265.           from the column in this row can be regarded as constants by
  23266.           the rest of the optimizer. `const' tables are very fast as
  23267.           they are read only once!
  23268.  
  23269.           `const' is used when you compare all parts of a
  23270.           `PRIMARY'/`UNIQUE' key with constants:
  23271.  
  23272.                SELECT * FROM const_table WHERE primary_key=1;
  23273.                
  23274.                SELECT * FROM const_table
  23275.                WHERE primary_key_part1=1 AND primary_key_part2=2;
  23276.  
  23277.     `eq_ref'
  23278.           One row will be read from this table for each combination of
  23279.           rows from the previous tables.  This is the best possible
  23280.           join type, other than the `const' types.  It is used when all
  23281.           parts of an index are used by the join and the index is
  23282.           `UNIQUE' or a `PRIMARY KEY'.
  23283.  
  23284.           `eq_ref' can be used for indexed columns that is compared
  23285.           with the `=' operator.  The compared item may be a constant
  23286.           or an expression that uses columns from tables that are read
  23287.           before this table.
  23288.  
  23289.           In the following examples, `ref_table' will be able to use
  23290.           `eq_ref'
  23291.  
  23292.                SELECT * FROM ref_table,other_table
  23293.                WHERE ref_table.key_column=other_table.column;
  23294.                
  23295.                SELECT * FROM ref_table,other_table
  23296.                WHERE ref_table.key_column_part1=other_table.column
  23297.                AND ref_table.key_column_part2=1;
  23298.  
  23299.     `ref'
  23300.           All rows with matching index values will be read from this
  23301.           table for each combination of rows from the previous tables.
  23302.           `ref' is used if the join uses only a leftmost prefix of the
  23303.           key, or if the key is not `UNIQUE' or a `PRIMARY KEY' (in
  23304.           other words, if the join cannot select a single row based on
  23305.           the key value).  If the key that is used matches only a few
  23306.           rows, this join type is good.
  23307.  
  23308.           `ref' can be used for indexed columns that is compared with
  23309.           the `=' operator.
  23310.  
  23311.           In the following examples, `ref_table' will be able to use
  23312.           `ref'.
  23313.  
  23314.                SELECT * FROM ref_table WHERE key_column=expr;
  23315.                
  23316.                SELECT * FROM ref_table,other_table
  23317.                WHERE ref_table.key_column=other_table.column;
  23318.                
  23319.                SELECT * FROM ref_table,other_table
  23320.                WHERE ref_table.key_column_part1=other_table.column
  23321.                AND ref_table.key_column_part2=1;
  23322.  
  23323.     `ref_or_null'
  23324.           Like `ref', but with the addition that we will do an extra
  23325.           search for rows with `NULL'.  *Note `IS NULL' optimisation:
  23326.           IS NULL optimisation.
  23327.  
  23328.                SELECT * FROM ref_table WHERE key_column=expr OR key_column IS NULL;
  23329.  
  23330.           This join type optimization is new for MySQL 4.1.1 and is
  23331.           mostly used when resolving subqueries.
  23332.  
  23333.     `unique_subquery'
  23334.           This type replaces `ref' for some `IN' subqueries of the
  23335.           following form:
  23336.                value IN (SELECT primary_key FROM single_table WHERE some_exp)
  23337.           `unique_subquery' is just an index lookup function that
  23338.           replaces the subquery completely for better efficiency.
  23339.  
  23340.     `index_subquery'
  23341.           Like `unique_subquery', this type replaces `IN' subqueries,
  23342.           but it works for non-unique indexes:
  23343.                value IN (SELECT key_field FROM single_table WHERE some_exp)
  23344.  
  23345.     `range'
  23346.           Only rows that are in a given range will be retrieved, using
  23347.           an index to select the rows.  The `key' column indicates
  23348.           which index is used.  The `key_len' contains the longest key
  23349.           part that was used.  The `ref' column will be `NULL' for this
  23350.           type.
  23351.  
  23352.           `range' can be used for when an key column is compared to a
  23353.           constant with `=', `<>', `>', `>=', `<', `<=', `IS NULL',
  23354.           `<=>', `BETWEEN' and `IN'.
  23355.  
  23356.                SELECT * FROM range_table WHERE key_column = 10;
  23357.                
  23358.                SELECT * FROM range_table WHERE key_column BETWEEN 10 and 20;
  23359.                
  23360.                SELECT * FROM range_table WHERE key_column IN (10,20,30);
  23361.                
  23362.                SELECT * FROM range_table WHERE key_part1= 10 and key_part2 IN (10,20,30);
  23363.  
  23364.     `index'
  23365.           This is the same as `ALL', except that only the index tree is
  23366.           scanned.  This is usually faster than `ALL', as the index
  23367.           file is usually smaller than the datafile.
  23368.  
  23369.           This can be used when the query only uses columns that are
  23370.           part of one index.
  23371.  
  23372.     `ALL'
  23373.           A full table scan will be done for each combination of rows
  23374.           from the previous tables.  This is normally not good if the
  23375.           table is the first table not marked `const', and usually
  23376.           *very* bad in all other cases. You normally can avoid `ALL'
  23377.           by adding more indexes, so that the row can be retrieved
  23378.           based on constant values or column values from earlier tables.
  23379.  
  23380. `possible_keys'
  23381.      The `possible_keys' column indicates which indexes MySQL could use
  23382.      to find the rows in this table. Note that this column is totally
  23383.      independent of the order of the tables. That means that some of
  23384.      the keys in `possible_keys' may not be usable in practice with the
  23385.      generated table order.
  23386.  
  23387.      If this column is `NULL', there are no relevant indexes. In this
  23388.      case, you may be able to improve the performance of your query by
  23389.      examining the `WHERE' clause to see whether it refers to some
  23390.      column or columns that would be suitable for indexing.  If so,
  23391.      create an appropriate index and check the query with `EXPLAIN'
  23392.      again.  *Note `ALTER TABLE': ALTER TABLE.
  23393.  
  23394.      To see what indexes a table has, use `SHOW INDEX FROM tbl_name'.
  23395.  
  23396. `key'
  23397.      The `key' column indicates the key (index) that MySQL actually
  23398.      decided to use. The key is `NULL' if no index was chosen. To force
  23399.      MySQL to use an key listed in the `possible_keys' column, use `USE
  23400.      KEY/IGNORE KEY' in your query.  *Note `SELECT': SELECT.
  23401.  
  23402.      Also, running `myisamchk --analyze' (*note `myismchk' syntax:
  23403.      myisamchk syntax.) or `ANALYZE TABLE' (*note `ANALYZE TABLE':
  23404.      ANALYZE TABLE.) on the table will help the optimizer choose better
  23405.      indexes.
  23406.  
  23407. `key_len'
  23408.      The `key_len' column indicates the length of the key that MySQL
  23409.      decided to use.  The length is `NULL' if the `key' is `NULL'. Note
  23410.      that this tells us how many parts of a multi-part key MySQL will
  23411.      actually use.
  23412.  
  23413. `ref'
  23414.      The `ref' column shows which columns or constants are used with the
  23415.      `key' to select rows from the table.
  23416.  
  23417. `rows'
  23418.      The `rows' column indicates the number of rows MySQL believes it
  23419.      must examine to execute the query.
  23420.  
  23421. `Extra'
  23422.      This column contains additional information of how MySQL will
  23423.      resolve the query. Here is an explanation of the different text
  23424.      strings that can be found in this column:
  23425.  
  23426.     `Distinct'
  23427.           MySQL will not continue searching for more rows for the
  23428.           current row combination after it has found the first matching
  23429.           row.
  23430.  
  23431.     `Not exists'
  23432.           MySQL was able to do a `LEFT JOIN' optimization on the query
  23433.           and will not examine more rows in this table for the previous
  23434.           row combination after it finds one row that matches the `LEFT
  23435.           JOIN' criteria.
  23436.  
  23437.           Here is an example for this:
  23438.  
  23439.                SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id
  23440.                WHERE t2.id IS NULL;
  23441.  
  23442.           Assume that `t2.id' is defined with `NOT NULL'.  In this case
  23443.           MySQL will scan `t1' and look up the rows in `t2' through
  23444.           `t1.id'. If MySQL finds a matching row in `t2', it knows that
  23445.           `t2.id' can never be `NULL', and will not scan through the
  23446.           rest of the rows in `t2' that has the same `id'.  In other
  23447.           words, for each row in `t1', MySQL only needs to do a single
  23448.           lookup in `t2', independent of how many matching rows there
  23449.           are in `t2'.
  23450.  
  23451.     ``range checked for each record (index map: #)''
  23452.           MySQL didn't find a real good index to use. It will, instead,
  23453.           for each row combination in the preceding tables, do a check
  23454.           on which index to use (if any), and use this index to
  23455.           retrieve the rows from the table.  This isn't very fast but
  23456.           is faster than having to do a join without an index.
  23457.  
  23458.     `Using filesort'
  23459.           MySQL will need to do an extra pass to find out how to
  23460.           retrieve the rows in sorted order.  The sort is done by going
  23461.           through all rows according to the `join type' and storing the
  23462.           sort key + pointer to the row for all rows that match the
  23463.           `WHERE'. Then the keys are sorted. Finally the rows are
  23464.           retrieved in sorted order.
  23465.  
  23466.     `Using index'
  23467.           The column information is retrieved from the table using only
  23468.           information in the index tree without having to do an
  23469.           additional seek to read the actual row.  This can be done
  23470.           when all the used columns for the table are part of the same
  23471.           index.
  23472.  
  23473.     `Using temporary'
  23474.           To resolve the query MySQL will need to create a temporary
  23475.           table to hold the result.  This typically happens if you do an
  23476.           `ORDER BY' on a different column set than you did a `GROUP
  23477.           BY' on.
  23478.  
  23479.     `Using where'
  23480.           A `WHERE' clause will be used to restrict which rows will be
  23481.           matched against the next table or sent to the client.  If you
  23482.           don't have this information and the table is of type `ALL' or
  23483.           `index', you may have something wrong in your query (if you
  23484.           don't intend to fetch/examine all rows from the table).
  23485.  
  23486.      If you want to get your queries as fast as possible, you should
  23487.      look out for `Using filesort' and `Using temporary'.
  23488.  
  23489. You can get a good indication of how good a join is by multiplying all
  23490. values in the `rows' column of the `EXPLAIN' output. This should tell
  23491. you roughly how many rows MySQL must examine to execute the query. This
  23492. number is also used when you restrict queries with the `max_join_size'
  23493. variable.  *Note Server parameters::.
  23494.  
  23495. The following example shows how a `JOIN' can be optimized progressively
  23496. using the information provided by `EXPLAIN'.
  23497.  
  23498. Suppose you have the `SELECT' statement shown here, that you examine
  23499. using `EXPLAIN':
  23500.  
  23501.      EXPLAIN SELECT tt.TicketNumber, tt.TimeIn,
  23502.                  tt.ProjectReference, tt.EstimatedShipDate,
  23503.                  tt.ActualShipDate, tt.ClientID,
  23504.                  tt.ServiceCodes, tt.RepetitiveID,
  23505.                  tt.CurrentProcess, tt.CurrentDPPerson,
  23506.                  tt.RecordVolume, tt.DPPrinted, et.COUNTRY,
  23507.                  et_1.COUNTRY, do.CUSTNAME
  23508.              FROM tt, et, et AS et_1, do
  23509.              WHERE tt.SubmitTime IS NULL
  23510.                  AND tt.ActualPC = et.EMPLOYID
  23511.                  AND tt.AssignedPC = et_1.EMPLOYID
  23512.                  AND tt.ClientID = do.CUSTNMBR;
  23513.  
  23514. For this example, assume that:
  23515.  
  23516.    * The columns being compared have been declared as follows:
  23517.  
  23518.      *Table* *Column*   *Column
  23519.                         type*
  23520.      `tt'    `ActualPC' `CHAR(10)'
  23521.      `tt'    `AssignedPC'`CHAR(10)'
  23522.      `tt'    `ClientID' `CHAR(10)'
  23523.      `et'    `EMPLOYID' `CHAR(15)'
  23524.      `do'    `CUSTNMBR' `CHAR(15)'
  23525.  
  23526.    * The tables have the indexes shown here:
  23527.  
  23528.      *Table* *Index*
  23529.      `tt'    `ActualPC'
  23530.      `tt'    `AssignedPC'
  23531.      `tt'    `ClientID'
  23532.      `et'    `EMPLOYID' (primary
  23533.              key)
  23534.      `do'    `CUSTNMBR' (primary
  23535.              key)
  23536.  
  23537.    * The `tt.ActualPC' values aren't evenly distributed.
  23538.  
  23539. Initially, before any optimizations have been performed, the `EXPLAIN'
  23540. statement produces the following information:
  23541.  
  23542.      table type possible_keys                key  key_len ref  rows  Extra
  23543.      et    ALL  PRIMARY                      NULL NULL    NULL 74
  23544.      do    ALL  PRIMARY                      NULL NULL    NULL 2135
  23545.      et_1  ALL  PRIMARY                      NULL NULL    NULL 74
  23546.      tt    ALL  AssignedPC,ClientID,ActualPC NULL NULL    NULL 3872
  23547.            range checked for each record (key map: 35)
  23548.  
  23549. Because `type' is `ALL' for each table, this output indicates that
  23550. MySQL is generating a Cartesian product of all the tables!  This will
  23551. take quite a long time, as the product of the number of rows in each
  23552. table must be examined!  For the case at hand, this is `74 * 2135 * 74
  23553. * 3872 = 45,268,558,720' rows.  If the tables were bigger, you can only
  23554. imagine how long it would take.
  23555.  
  23556. One problem here is that MySQL can't (yet) use indexes on columns
  23557. efficiently if they are declared differently.  In this context,
  23558. `VARCHAR' and `CHAR' are the same unless they are declared as different
  23559. lengths. Because `tt.ActualPC' is declared as `CHAR(10)' and
  23560. `et.EMPLOYID' is declared as `CHAR(15)', there is a length mismatch.
  23561.  
  23562. To fix this disparity between column lengths, use `ALTER TABLE' to
  23563. lengthen `ActualPC' from 10 characters to 15 characters:
  23564.  
  23565.      mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15);
  23566.  
  23567. Now `tt.ActualPC' and `et.EMPLOYID' are both `VARCHAR(15)'.  Executing
  23568. the `EXPLAIN' statement again produces this result:
  23569.  
  23570.      table type   possible_keys   key     key_len ref         rows    Extra
  23571.      tt    ALL    AssignedPC,ClientID,ActualPC NULL NULL NULL 3872    Using where
  23572.      do    ALL    PRIMARY         NULL    NULL    NULL        2135
  23573.            range checked for each record (key map: 1)
  23574.      et_1  ALL    PRIMARY         NULL    NULL    NULL        74
  23575.            range checked for each record (key map: 1)
  23576.      et    eq_ref PRIMARY         PRIMARY 15      tt.ActualPC 1
  23577.  
  23578. This is not perfect, but is much better (the product of the `rows'
  23579. values is now less by a factor of 74). This version is executed in a
  23580. couple of seconds.
  23581.  
  23582. A second alteration can be made to eliminate the column length
  23583. mismatches for the `tt.AssignedPC = et_1.EMPLOYID' and `tt.ClientID =
  23584. do.CUSTNMBR' comparisons:
  23585.  
  23586.      mysql> ALTER TABLE tt MODIFY AssignedPC VARCHAR(15),
  23587.          ->                MODIFY ClientID   VARCHAR(15);
  23588.  
  23589. Now `EXPLAIN' produces the output shown here:
  23590.  
  23591.      table type   possible_keys   key      key_len ref           rows Extra
  23592.      et    ALL    PRIMARY         NULL     NULL    NULL          74
  23593.      tt    ref    AssignedPC,     ActualPC 15      et.EMPLOYID   52   Using where
  23594.                   ClientID,
  23595.                   ActualPC
  23596.      et_1  eq_ref PRIMARY         PRIMARY  15      tt.AssignedPC 1
  23597.      do    eq_ref PRIMARY         PRIMARY  15      tt.ClientID   1
  23598.  
  23599. This is almost as good as it can get.
  23600.  
  23601. The remaining problem is that, by default, MySQL assumes that values in
  23602. the `tt.ActualPC' column are evenly distributed, and that isn't the
  23603. case for the `tt' table.  Fortunately, it is easy to tell MySQL about
  23604. this:
  23605.  
  23606.      shell> myisamchk --analyze PATH_TO_MYSQL_DATABASE/tt
  23607.      shell> mysqladmin refresh
  23608.  
  23609. Now the join is perfect, and `EXPLAIN' produces this result:
  23610.  
  23611.      table type   possible_keys key     key_len ref           rows Extra
  23612.      tt    ALL    AssignedPC    NULL    NULL    NULL          3872 Using where
  23613.                   ClientID,
  23614.                   ActualPC
  23615.      et    eq_ref PRIMARY       PRIMARY 15      tt.ActualPC   1
  23616.      et_1  eq_ref PRIMARY       PRIMARY 15      tt.AssignedPC 1
  23617.      do    eq_ref PRIMARY       PRIMARY 15      tt.ClientID   1
  23618.  
  23619. Note that the `rows' column in the output from `EXPLAIN' is an educated
  23620. guess from the MySQL join optimizer. To optimize a query, you should
  23621. check if the numbers are even close to the truth.  If not, you may get
  23622. better performance by using `STRAIGHT_JOIN' in your `SELECT' statement
  23623. and trying to list the tables in a different order in the `FROM' clause.
  23624.  
  23625. Estimating Query Performance
  23626. ----------------------------
  23627.  
  23628. In most cases you can estimate the performance by counting disk seeks.
  23629. For small tables, you can usually find the row in 1 disk seek (as the
  23630. index is probably cached).  For bigger tables, you can estimate that
  23631. (using B++ tree indexes) you will need: `log(row_count) /
  23632. log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) +
  23633. 1' seeks to find a row.
  23634.  
  23635. In MySQL an index block is usually 1024 bytes and the data pointer is
  23636. usually 4 bytes. A 500,000 row table with an index length of 3 (medium
  23637. integer) gives you: `log(500,000)/log(1024/3*2/(3+4)) + 1' = 4 seeks.
  23638.  
  23639. As the above index would require about 500,000 * 7 * 3/2 = 5.2M,
  23640. (assuming that the index buffers are filled to 2/3, which is typical)
  23641. you will probably have much of the index in memory and you will probably
  23642. only need 1-2 calls to read data from the OS to find the row.
  23643.  
  23644. For writes, however, you will need 4 seek requests (as above) to find
  23645. where to place the new index and normally 2 seeks to update the index
  23646. and write the row.
  23647.  
  23648. Note that the above doesn't mean that your application will slowly
  23649. degenerate by log N!  As long as everything is cached by the OS or SQL
  23650. server, things will go only marginally slower while the table gets
  23651. bigger. After the data gets too big to be cached, things will start to
  23652. go much slower until your applications is only bound by disk-seeks
  23653. (which increase by log N). To avoid this, increase the index cache as
  23654. the data grows. *Note Server parameters::.
  23655.  
  23656. Speed of `SELECT' Queries
  23657. -------------------------
  23658.  
  23659. In general, when you want to make a slow `SELECT ... WHERE' faster, the
  23660. first thing to check is whether you can add an index. *Note MySQL
  23661. indexes: MySQL indexes. All references between different tables should
  23662. usually be done with indexes. You can use the `EXPLAIN' command to
  23663. determine which indexes are used for a `SELECT'.  *Note `EXPLAIN':
  23664. EXPLAIN.
  23665.  
  23666. Some general tips:
  23667.  
  23668.    * To help MySQL optimize queries better, run `myisamchk --analyze'
  23669.      on a table after it has been loaded with relevant data. This
  23670.      updates a value for each index part that indicates the average
  23671.      number of rows that have the same value.  (For unique indexes,
  23672.      this is always 1.)  MySQL will use this to decide which index to
  23673.      choose when you connect two tables with 'a non-constant
  23674.      expression'.  You can check the result from the `analyze' run by
  23675.      doing `SHOW INDEX FROM table_name' and examining the `Cardinality'
  23676.      column.
  23677.  
  23678.    * To sort an index and data according to an index, use `myisamchk
  23679.      --sort-index --sort-records=1' (if you want to sort on index 1).
  23680.      If you have a unique index from which you want to read all records
  23681.      in order according to that index, this is a good way to make that
  23682.      faster.  Note, however, that this sorting isn't written optimally
  23683.      and will take a long time for a large table!
  23684.  
  23685. How MySQL Optimizes `WHERE' Clauses
  23686. -----------------------------------
  23687.  
  23688. The `WHERE' optimizations are put in the `SELECT' part here because
  23689. they are mostly used with `SELECT', but the same optimizations apply for
  23690. `WHERE' in `DELETE' and `UPDATE' statements.
  23691.  
  23692. Also note that this section is incomplete. MySQL does many
  23693. optimizations, and we have not had time to document them all.
  23694.  
  23695. Some of the optimizations performed by MySQL are listed here:
  23696.  
  23697.    * Removal of unnecessary parentheses:
  23698.              ((a AND b) AND c OR (((a AND b) AND (c AND d))))
  23699.           -> (a AND b AND c) OR (a AND b AND c AND d)
  23700.  
  23701.    * Constant folding:
  23702.              (a<b AND b=c) AND a=5
  23703.           -> b>5 AND b=c AND a=5
  23704.  
  23705.    * Constant condition removal (needed because of constant folding):
  23706.              (B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
  23707.           -> B=5 OR B=6
  23708.  
  23709.    * Constant expressions used by indexes are evaluated only once.
  23710.  
  23711.    * `COUNT(*)' on a single table without a `WHERE' is retrieved
  23712.      directly from the table information for `MyISAM' and `HEAP' tables.
  23713.      This is also done for any `NOT NULL' expression when used with
  23714.      only one table.
  23715.  
  23716.    * Early detection of invalid constant expressions. MySQL quickly
  23717.      detects that some `SELECT' statements are impossible and returns
  23718.      no rows.
  23719.  
  23720.    * `HAVING' is merged with `WHERE' if you don't use `GROUP BY' or
  23721.      group functions (`COUNT()', `MIN()'...).
  23722.  
  23723.    * For each sub-join, a simpler `WHERE' is constructed to get a fast
  23724.      `WHERE' evaluation for each sub-join and also to skip records as
  23725.      soon as possible.
  23726.  
  23727.    * All constant tables are read first, before any other tables in the
  23728.      query.  A constant table is:
  23729.         - An empty table or a table with 1 row.
  23730.  
  23731.         - A table that is used with a `WHERE' clause on a `UNIQUE'
  23732.           index, or a `PRIMARY KEY', where all index parts are used
  23733.           with constant expressions and the index parts are defined as
  23734.           `NOT NULL'.
  23735.      All the following tables are used as constant tables:
  23736.           mysql> SELECT * FROM t WHERE primary_key=1;
  23737.           mysql> SELECT * FROM t1,t2
  23738.               ->          WHERE t1.primary_key=1 AND t2.primary_key=t1.id;
  23739.  
  23740.    * The best join combination to join the tables is found by trying all
  23741.      possibilities. If all columns in `ORDER BY' and in `GROUP BY' come
  23742.      from the same table, then this table is preferred first when
  23743.      joining.
  23744.  
  23745.    * If there is an `ORDER BY' clause and a different `GROUP BY'
  23746.      clause, or if the `ORDER BY' or `GROUP BY' contains columns from
  23747.      tables other than the first table in the join queue, a temporary
  23748.      table is created.
  23749.  
  23750.    * If you use `SQL_SMALL_RESULT', MySQL will use an in-memory
  23751.      temporary table.
  23752.  
  23753.    * Each table index is queried, and the best index that spans fewer
  23754.      than 30% of the rows is used. If no such index can be found, a
  23755.      quick table scan is used.
  23756.  
  23757.    * In some cases, MySQL can read rows from the index without even
  23758.      consulting the datafile.  If all columns used from the index are
  23759.      numeric, only the index tree is used to resolve the query.
  23760.  
  23761.    * Before each record is output, those that do not match the `HAVING'
  23762.      clause are skipped.
  23763.  
  23764. Some examples of queries that are very fast:
  23765.  
  23766.      mysql> SELECT COUNT(*) FROM tbl_name;
  23767.      mysql> SELECT MIN(key_part1),MAX(key_part1) FROM tbl_name;
  23768.      mysql> SELECT MAX(key_part2) FROM tbl_name
  23769.          ->        WHERE key_part_1=constant;
  23770.      mysql> SELECT ... FROM tbl_name
  23771.          ->        ORDER BY key_part1,key_part2,... LIMIT 10;
  23772.      mysql> SELECT ... FROM tbl_name
  23773.          ->        ORDER BY key_part1 DESC,key_part2 DESC,... LIMIT 10;
  23774.  
  23775. The following queries are resolved using only the index tree (assuming
  23776. the indexed columns are numeric):
  23777.  
  23778.      mysql> SELECT key_part1,key_part2 FROM tbl_name WHERE key_part1=val;
  23779.      mysql> SELECT COUNT(*) FROM tbl_name
  23780.          ->        WHERE key_part1=val1 AND key_part2=val2;
  23781.      mysql> SELECT key_part2 FROM tbl_name GROUP BY key_part1;
  23782.  
  23783. The following queries use indexing to retrieve the rows in sorted order
  23784. without a separate sorting pass:
  23785.  
  23786.      mysql> SELECT ... FROM tbl_name
  23787.          ->            ORDER BY key_part1,key_part2,... ;
  23788.      mysql> SELECT ... FROM tbl_name
  23789.          ->            ORDER BY key_part1 DESC,key_part2 DESC,... ;
  23790.  
  23791. How MySQL Optimizes `OR' Clauses
  23792. --------------------------------
  23793.  
  23794. The `Merge Index' method is used to retrieve rows with several `ref',
  23795. `ref_or_null' or `range' scans and merge the results into one.  This
  23796. method is employed when the table condition is a disjunction of
  23797. conditions for which `ref', `ref_or_null', or `range' could be used
  23798. with different keys.  The `key' column contains a list of used indexes.
  23799. `key_len' contains a list of the longest key parts of the used indexes.
  23800.  
  23801. Example:
  23802.  
  23803.      SELECT * FROM table WHERE key1column = 10 OR key2column = 20;
  23804.      
  23805.      SELECT * FROM table WHERE
  23806.        (key1column = 10 OR key2column = 20) AND nonkeycolumn=30;
  23807.      
  23808.      SELECT * FROM t1,t2 WHERE
  23809.        (t1.key1 IN (1,2) OR t1.key2 LIKE 'value%') AND t2.key1=t1.somefield
  23810.      
  23811.      SELECT * FROM t1,t2 WHERE
  23812.        t1.key1=1 AND (t2.key1=t1.somefield OR t2.key2=t1.somefield2)
  23813.  
  23814. This "join" type optimization is new in MySQL 5.0.0, and represents a
  23815. significant change in behaviour with regard to indexes since the _old_
  23816. rule was that the server is only ever able to use at most one index for
  23817. each referenced table.
  23818.  
  23819. How MySQL Optimizes `IS NULL'
  23820. -----------------------------
  23821.  
  23822. MySQL can do the same optimization on `column IS NULL' as it can do
  23823. with `column = constant_value'.  For example, MySQL can use indexes and
  23824. ranges to search for `NULL' with `IS NULL'.
  23825.  
  23826.      SELECT * FROM table_name WHERE key_col IS NULL;
  23827.      
  23828.      SELECT * FROM table_name WHERE key_col <=> NULL;
  23829.      
  23830.      SELECT * FROM table_name WHERE key_col=# OR key_col=# OR key_col IS NULL
  23831.  
  23832. If you use `column_name IS NULL' on a `NOT NULL' in a `WHERE' clause on
  23833. table that is not used `OUTER JOIN' that expression will be optimized
  23834. away.
  23835.  
  23836. MySQL 4.1.1 can additionally optimize the combination `column = expr
  23837. AND column IS NULL', an form that is common in resolved sub queries.
  23838. `EXPLAIN' will show `ref_or_null' when this optimization is used.
  23839.  
  23840. This optimization can handle one `IS NULL' for any key part.
  23841.  
  23842. Some examples of queries that are optimized (assuming key on t2 (a,b)):
  23843.  
  23844.      SELECT * FROM t1 WHERE t1.a=expr OR t1.a IS NULL;
  23845.      
  23846.      SELECT * FROM t1,t2 WHERE t1.a=t2.a OR t2.a IS NULL;
  23847.      
  23848.      SELECT * FROM t1,t2 WHERE (t1.a=t2.a OR t2.a IS NULL) AND t2.b=t1.b;
  23849.      
  23850.      SELECT * FROM t1,t2 WHERE t1.a=t2.a AND (t2.b=t1.b OR t2.b IS NULL);
  23851.      
  23852.      SELECT * FROM t1,t2 WHERE (t1.a=t2.a AND t2.a IS NULL AND ...) OR (t1.a=t2.a AND t2.a IS NULL AND ...);
  23853.  
  23854. `ref_or_null' works by first doing a read on the reference key and
  23855. after that a separate search after rows with NULL key.
  23856.  
  23857. Note that the optimization can only handle one `IS NULL' level.
  23858.  
  23859.      SELECT * FROM t1,t2 where (t1.a=t2.a AND t2.a IS NULL) OR (t1.b=t2.b AND t2.b IS NULL);
  23860.  
  23861. Int the above case MySQL will only use key lookups on the part
  23862. `(t1.a=t2.a AND t2.a IS NULL)' and not be able to use the key part on
  23863. `b'.
  23864.  
  23865. How MySQL Optimizes `DISTINCT'
  23866. ------------------------------
  23867.  
  23868. `DISTINCT' combined with `ORDER BY' will in many cases need a temporary
  23869. table.
  23870.  
  23871. Note that as `DISTINCT' may use `GROUP BY', you should be aware of how
  23872. MySQL works with in fields in `ORDER BY' or `HAVING' that are not part
  23873. of the selected fields. *Note GROUP-BY-hidden-fields::.
  23874.  
  23875. When combining `LIMIT row_count' with `DISTINCT', MySQL will stop as
  23876. soon as it finds `row_count' unique rows.
  23877.  
  23878. If you don't use columns from all used tables, MySQL will stop the
  23879. scanning of the not used tables as soon as it has found the first match.
  23880.  
  23881.      SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;
  23882.  
  23883. In this case, assuming `t1' is used before `t2' (check with `EXPLAIN'),
  23884. then MySQL will stop reading from `t2' (for that particular row in
  23885. `t1') when the first row in `t2' is found.
  23886.  
  23887. How MySQL Optimizes `LEFT JOIN' and `RIGHT JOIN'
  23888. ------------------------------------------------
  23889.  
  23890. `A LEFT JOIN B join_condition' in MySQL is implemented as follows:
  23891.  
  23892.    * The table `B' is set to be dependent on table `A' and all tables
  23893.      that `A' is dependent on.
  23894.  
  23895.    * The table `A' is set to be dependent on all tables (except `B')
  23896.      that are used in the `LEFT JOIN' condition.
  23897.  
  23898.    * The `LEFT JOIN' condition is used to decide how we should retrieve
  23899.      rows from table B. (In other words, any condition in the `WHERE'
  23900.      clause is not used).
  23901.  
  23902.    * All standard join optimizations are done, with the exception that
  23903.      a table is always read after all tables it is dependent on.  If
  23904.      there is a circular dependence then MySQL will issue an error.
  23905.  
  23906.    * All standard `WHERE' optimizations are done.
  23907.  
  23908.    * If there is a row in `A' that matches the `WHERE' clause, but there
  23909.      wasn't any row in `B' that matched the `ON' condition, then an
  23910.      extra `B' row is generated with all columns set to `NULL'.
  23911.  
  23912.    * If you use `LEFT JOIN' to find rows that don't exist in some table
  23913.      and you have the following test: `column_name IS NULL' in the
  23914.      `WHERE' part, where column_name is a column that is declared as
  23915.      `NOT NULL', then MySQL will stop searching after more rows (for a
  23916.      particular key combination) after it has found one row that
  23917.      matches the `LEFT JOIN' condition.
  23918.  
  23919. `RIGHT JOIN' is implemented analogously to `LEFT JOIN'.
  23920.  
  23921. The table read order forced by `LEFT JOIN' and `STRAIGHT JOIN' will
  23922. help the join optimizer (which calculates in which order tables should
  23923. be joined) to do its work much more quickly, as there are fewer table
  23924. permutations to check.
  23925.  
  23926. Note that the above means that if you do a query of type:
  23927.  
  23928.      SELECT * FROM a,b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key)
  23929.               WHERE b.key=d.key
  23930.  
  23931. MySQL will do a full scan on `b' as the `LEFT JOIN' will force it to be
  23932. read before `d'.
  23933.  
  23934. The fix in this case is to change the query to:
  23935.  
  23936.      SELECT * FROM b,a LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key)
  23937.               WHERE b.key=d.key
  23938.  
  23939. Starting from 4.0.14, MySQL does the following `LEFT JOIN' optimization:
  23940.  
  23941. If the `WHERE' condition is always be false for the generated `NULL'
  23942. row, the `LEFT JOIN' is changed to a normal join.
  23943.  
  23944. For example, in the following query the `WHERE' clause would be false
  23945. if t2.column would be `NULL' so it's safe to convert to a normal join.
  23946.  
  23947.      SELECT * FROM t1 LEFT t2 ON (column) WHERE t2.column2 =5;
  23948.      ->
  23949.      SELECT * FROM t1,t2 WHERE t2.column2=5 AND t1.column=t2.column;
  23950.  
  23951. This can be made faster as MySQL can now use table `t2' before table
  23952. `t1' if this would result in a better query plan.  To force a specific
  23953. table order, use `STRAIGHT JOIN'.
  23954.  
  23955. How MySQL Optimizes `ORDER BY'
  23956. ------------------------------
  23957.  
  23958. In some cases MySQL can uses index to satisfy an `ORDER BY' or `GROUP
  23959. BY' request without doing any extra sorting.
  23960.  
  23961. The index can also be used even if the `ORDER BY' doesn't match the
  23962. index exactly, as long as all the unused index parts and all the extra
  23963. are `ORDER BY' columns are constants in the `WHERE' clause. The
  23964. following queries will use the index to resolve the `ORDER BY' / `GROUP
  23965. BY' part:
  23966.  
  23967.      SELECT * FROM t1 ORDER BY key_part1,key_part2,...
  23968.      SELECT * FROM t1 WHERE key_part1=constant ORDER BY key_part2
  23969.      SELECT * FROM t1 WHERE key_part1=constant GROUP BY key_part2
  23970.      SELECT * FROM t1 ORDER BY key_part1 DESC,key_part2 DESC
  23971.      SELECT * FROM t1 WHERE key_part1=1 ORDER BY key_part1 DESC,key_part2 DESC
  23972.  
  23973. Some cases where MySQL can *not* use indexes to resolve the `ORDER BY':
  23974. (Note that MySQL will still use indexes to find the rows that matches
  23975. the `WHERE' clause):
  23976.  
  23977.    * You are doing an `ORDER BY' on different keys:
  23978.  
  23979.      `SELECT * FROM t1 ORDER BY key1,key2'
  23980.  
  23981.    * You are doing an `ORDER BY' using non-consecutive key parts.
  23982.  
  23983.      `SELECT * FROM t1 WHERE key2=constant ORDER BY key_part2'
  23984.  
  23985.    * You are mixing `ASC' and `DESC'.
  23986.  
  23987.      `SELECT * FROM t1 ORDER BY key_part1 DESC,key_part2 ASC'
  23988.  
  23989.    * The key used to fetch the rows are not the same one that is used to
  23990.      do the `ORDER BY':
  23991.  
  23992.      `SELECT * FROM t1 WHERE key2=constant ORDER BY key1'
  23993.  
  23994.    * You are joining many tables and the columns you are doing an `ORDER
  23995.      BY' on are not all from the first not-`const' table that is used to
  23996.      retrieve rows (This is the first table in the `EXPLAIN' output
  23997.      which doesn't use a `const' row fetch method).
  23998.  
  23999.    * You have different `ORDER BY' and `GROUP BY' expressions.
  24000.  
  24001.    * The used table index is an index type that doesn't store rows in
  24002.      order.  (Like the `HASH' index in `HEAP' tables).
  24003.  
  24004. In the cases where MySQL have to sort the result, it uses the following
  24005. algorithm:
  24006.  
  24007.    * Read all rows according to key or by table scanning.  Rows that
  24008.      don't match the `WHERE' clause are skipped.
  24009.  
  24010.    * Store the sort-key in a buffer (of size `sort_buffer').
  24011.  
  24012.    * When the buffer gets full, run a qsort on it and store the result
  24013.      in a temporary file.  Save a pointer to the sorted block.  (In the
  24014.      case where all rows fits into the sort buffer, no temporary file
  24015.      is created)
  24016.  
  24017.    * Repeat the above until all rows have been read.
  24018.  
  24019.    * Do a multi-merge of up to `MERGEBUFF' (7) regions to one block in
  24020.      another temporary file.  Repeat until all blocks from the first
  24021.      file are in the second file.
  24022.  
  24023.    * Repeat the following until there is less than `MERGEBUFF2' (15)
  24024.      blocks left.
  24025.  
  24026.    * On the last multi-merge, only the pointer to the row (last part of
  24027.      the sort-key) is written to a result file.
  24028.  
  24029.    * Now the code in `sql/records.cc' will be used to read through them
  24030.      in sorted order by using the row pointers in the result file.  To
  24031.      optimize this, we read in a big block of row pointers, sort these
  24032.      and then we read the rows in the sorted order into a row buffer
  24033.      (`read_rnd_buffer_size') .
  24034.  
  24035. You can with `EXPLAIN SELECT ... ORDER BY' check if MySQL can use
  24036. indexes to resolve the query.  If you get `Using filesort' in the
  24037. `extra' column, then MySQL can't use indexes to resolve the `ORDER BY'.
  24038. *Note `EXPLAIN': EXPLAIN.
  24039.  
  24040. If you want to have a higher `ORDER BY' speed, you should first see if
  24041. you can get MySQL to use indexes instead of having to do an extra
  24042. sorting phase. If this is not possible, then you can do:
  24043.  
  24044.    * Increase the size of the `sort_buffer_size' variable.
  24045.  
  24046.    * Increase the size of the `read_rnd_buffer_size' variable.
  24047.  
  24048.    * Change `tmpdir' to point to a dedicated disk with lots of empty
  24049.      space.  If you use MySQL 4.1 or later you can spread load between
  24050.      several physical disks by setting `tmpdir' to a list of paths
  24051.      separated by colon `:' (semicolon `;' on Windows). They will be
  24052.      used in round-robin fashion.  *Note:* These paths should end up on
  24053.      different *physical* disks, not different partitions of the same
  24054.      disk.
  24055.  
  24056. By default, MySQL sorts all `GROUP BY x,y[,...]' queries as if you
  24057. specified `ORDER BY x,y[,...]' in the query as well. If you include the
  24058. `ORDER BY' clause explicitly,  MySQL optimizes it away without any speed
  24059. penalty, though the sorting still occurs.  If a query includes `GROUP
  24060. BY' but you want to avoid the overhead of sorting the result, you can
  24061. supress sorting by specifying `ORDER BY NULL':
  24062.  
  24063.      INSERT INTO foo SELECT a,COUNT(*) FROM bar GROUP BY a ORDER BY NULL;
  24064.  
  24065. How MySQL Optimizes `LIMIT'
  24066. ---------------------------
  24067.  
  24068. In some cases MySQL will handle the query differently when you are
  24069. using `LIMIT row_count' and not using `HAVING':
  24070.  
  24071.    * If you are selecting only a few rows with `LIMIT', MySQL will use
  24072.      indexes in some cases when it normally would prefer to do a full
  24073.      table scan.
  24074.  
  24075.    * If you use `LIMIT row_count' with `ORDER BY', MySQL will end the
  24076.      sorting as soon as it has found the first `row_count' lines
  24077.      instead of sorting the whole table.
  24078.  
  24079.    * When combining `LIMIT row_count' with `DISTINCT', MySQL will stop
  24080.      as soon as it finds `row_count' unique rows.
  24081.  
  24082.    * In some cases a `GROUP BY' can be resolved by reading the key in
  24083.      order (or do a sort on the key) and then calculate summaries until
  24084.      the key value changes.  In this case `LIMIT row_count' will not
  24085.      calculate any unnecessary `GROUP BY' values.
  24086.  
  24087.    * As soon as MySQL has sent the first `#' rows to the client, it
  24088.      will abort the query (if you are not using `SQL_CALC_FOUND_ROWS').
  24089.  
  24090.    * `LIMIT 0' will always quickly return an empty set.  This is useful
  24091.      to check the query and to get the column types of the result
  24092.      columns.
  24093.  
  24094.    * When the server uses temporary tables to resolve the query, the
  24095.      `LIMIT row_count' is used to calculate how much space is required.
  24096.  
  24097. Speed of `INSERT' Queries
  24098. -------------------------
  24099.  
  24100. The time to insert a record consists approximately of:
  24101.  
  24102.    * Connect:                 (3)
  24103.  
  24104.    * Sending query to server: (2)
  24105.  
  24106.    * Parsing query:           (2)
  24107.  
  24108.    * Inserting record:        (1 x size of record)
  24109.  
  24110.    * Inserting indexes:       (1 x number of indexes)
  24111.  
  24112.    * Close:                   (1)
  24113.  
  24114. where the numbers are somewhat proportional to the overall time. This
  24115. does not take into consideration the initial overhead to open tables
  24116. (which is done once for each concurrently running query).
  24117.  
  24118. The size of the table slows down the insertion of indexes by log N
  24119. (B-trees).
  24120.  
  24121. Some ways to speed up inserts:
  24122.  
  24123.    * If you are inserting many rows from the same client at the same
  24124.      time, use multiple value lists `INSERT' statements. This is much
  24125.      faster (many times in some cases) than using separate `INSERT'
  24126.      statements.  If you are adding data to non-empty table, you may
  24127.      tune up the `bulk_insert_buffer_size' variable to make it even
  24128.      faster.  *Note `bulk_insert_buffer_size': SHOW VARIABLES.
  24129.  
  24130.    * If you are inserting a lot of rows from different clients, you can
  24131.      get higher speed by using the `INSERT DELAYED' statement. *Note
  24132.      `INSERT': INSERT.
  24133.  
  24134.    * Note that with `MyISAM' tables you can insert rows at the same time
  24135.      `SELECT' statements are running if there are no deleted rows in
  24136.      the tables.
  24137.  
  24138.    * When loading a table from a text file, use `LOAD DATA INFILE'. This
  24139.      is usually 20 times faster than using a lot of `INSERT' statements.
  24140.      *Note `LOAD DATA': LOAD DATA.
  24141.  
  24142.    * It is possible with some extra work to make `LOAD DATA INFILE' run
  24143.      even faster when the table has many indexes. Use the following
  24144.      procedure:
  24145.  
  24146.        1. Optionally create the table with `CREATE TABLE'. For example,
  24147.           using `mysql' or Perl-DBI.
  24148.  
  24149.        2. Execute a `FLUSH TABLES' statement or the shell command
  24150.           `mysqladmin flush-tables'.
  24151.  
  24152.        3. Use `myisamchk --keys-used=0 -rq /path/to/db/tbl_name'. This
  24153.           will remove all usage of all indexes from the table.
  24154.  
  24155.        4. Insert data into the table with `LOAD DATA INFILE'. This will
  24156.           not update any indexes and will therefore be very fast.
  24157.  
  24158.        5. If you are going to only read the table in the future, run
  24159.           `myisampack' on it to make it smaller. *Note Compressed
  24160.           format::.
  24161.  
  24162.        6. Re-create the indexes with `myisamchk -r -q
  24163.           /path/to/db/tbl_name'. This will create the index tree in
  24164.           memory before writing it to disk, which is much faster
  24165.           because it avoids lots of disk seeks. The resulting index
  24166.           tree is also perfectly balanced.
  24167.  
  24168.        7. Execute a `FLUSH TABLES' statement or the shell command
  24169.           `mysqladmin flush-tables'.
  24170.  
  24171.      Note that `LOAD DATA INFILE' also does the above optimization if
  24172.      you insert into an empty table; the main difference with the above
  24173.      procedure is that you can let `myisamchk' allocate much more
  24174.      temporary memory for the index creation that you may want MySQL to
  24175.      allocate for every index recreation.
  24176.  
  24177.      Since MySQL 4.0 you can also use `ALTER TABLE tbl_name DISABLE
  24178.      KEYS' instead of `myisamchk --keys-used=0 -rq
  24179.      /path/to/db/tbl_name' and `ALTER TABLE tbl_name ENABLE KEYS'
  24180.      instead of `myisamchk -r -q /path/to/db/tbl_name'. This way you
  24181.      can also skip `FLUSH TABLES' steps.
  24182.  
  24183.    * You can speed up insertions that are done using multiple
  24184.      statements by locking your tables:
  24185.  
  24186.           mysql> LOCK TABLES a WRITE;
  24187.           mysql> INSERT INTO a VALUES (1,23),(2,34),(4,33);
  24188.           mysql> INSERT INTO a VALUES (8,26),(6,29);
  24189.           mysql> UNLOCK TABLES;
  24190.  
  24191.      The main speed difference is that the index buffer is flushed to
  24192.      disk only once, after all `INSERT' statements have completed.
  24193.      Normally there would be as many index buffer flushes as there are
  24194.      different `INSERT' statements. Locking is not needed if you can
  24195.      insert all rows with a single statement.
  24196.  
  24197.      For transactional tables, you should use `BEGIN/COMMIT' instead of
  24198.      `LOCK TABLES' to get a speedup.
  24199.  
  24200.      Locking will also lower the total time of multi-connection tests,
  24201.      but the maximum wait time for some threads will go up (because
  24202.      they wait for locks).  For example:
  24203.  
  24204.           thread 1 does 1000 inserts
  24205.           thread 2, 3, and 4 does 1 insert
  24206.           thread 5 does 1000 inserts
  24207.  
  24208.      If you don't use locking, 2, 3, and 4 will finish before 1 and 5.
  24209.      If you use locking, 2, 3, and 4 probably will not finish before 1
  24210.      or 5, but the total time should be about 40% faster.
  24211.  
  24212.      As `INSERT', `UPDATE', and `DELETE' operations are very fast in
  24213.      MySQL, you will obtain better overall performance by adding locks
  24214.      around everything that does more than about 5 inserts or updates
  24215.      in a row.  If you do very many inserts in a row, you could do a
  24216.      `LOCK TABLES' followed by an `UNLOCK TABLES' once in a while
  24217.      (about each 1000 rows) to allow other threads access to the table.
  24218.      This would still result in a nice performance gain.
  24219.  
  24220.      `LOAD DATA INFILE' is much faster for loading data.
  24221.  
  24222. To get some more speed for both `LOAD DATA INFILE' and `INSERT',
  24223. enlarge the key buffer. *Note Server parameters::.
  24224.  
  24225. Speed of `UPDATE' Queries
  24226. -------------------------
  24227.  
  24228. Update queries are optimized as a `SELECT' query with the additional
  24229. overhead of a write. The speed of the write is dependent on the size of
  24230. the data that is being updated and the number of indexes that are
  24231. updated.  Indexes that are not changed will not be updated.
  24232.  
  24233. Also, another way to get fast updates is to delay updates and then do
  24234. many updates in a row later. Doing many updates in a row is much quicker
  24235. than doing one at a time if you lock the table.
  24236.  
  24237. Note that, with dynamic record format, updating a record to a longer
  24238. total length may split the record.  So if you do this often, it is very
  24239. important to `OPTIMIZE TABLE' sometimes.  *Note `OPTIMIZE TABLE':
  24240. OPTIMIZE TABLE.
  24241.  
  24242. Speed of `DELETE' Queries
  24243. -------------------------
  24244.  
  24245. If you want to delete all rows in the table, you should use `TRUNCATE
  24246. TABLE table_name'. *Note `TRUNCATE': TRUNCATE.
  24247.  
  24248. The time to delete a record is exactly proportional to the number of
  24249. indexes. To delete records more quickly, you can increase the size of
  24250. the index cache. *Note Server parameters::.
  24251.  
  24252. Other Optimization Tips
  24253. -----------------------
  24254.  
  24255. Unsorted tips for faster systems:
  24256.  
  24257.    * Use persistent connections to the database to avoid the connection
  24258.      overhead. If you can't use persistent connections and you are
  24259.      doing a lot of new connections to the database, you may want to
  24260.      change the value of the `thread_cache_size' variable. *Note Server
  24261.      parameters::.
  24262.  
  24263.    * Always check that all your queries really use the indexes you have
  24264.      created in the tables. In MySQL you can do this with the `EXPLAIN'
  24265.      command. *Note Explain: (manual)EXPLAIN.
  24266.  
  24267.    * Try to avoid complex `SELECT' queries on `MyISAM' tables that are
  24268.      updated a lot. This is to avoid problems with table locking.
  24269.  
  24270.    * With `MyISAM' tables that have no deleted rows, you can insert rows
  24271.      at the same time another query is reading from it.  If this is
  24272.      important for you, you should consider methods where you don't
  24273.      have to delete rows or run `OPTIMIZE TABLE' after you have deleted
  24274.      a lot of rows.
  24275.  
  24276.    * Use `ALTER TABLE ... ORDER BY expr1,expr2...' if you mostly
  24277.      retrieve rows in `expr1,expr2...' order.  By using this option
  24278.      after big changes to the table, you may be able to get higher
  24279.      performance.
  24280.  
  24281.    * In some cases it may make sense to introduce a column that is
  24282.      'hashed' based on information from other columns. If this column
  24283.      is short and reasonably unique it may be much faster than a big
  24284.      index on many columns. In MySQL it's very easy to use this extra
  24285.      column: `SELECT * FROM table_name WHERE hash=MD5(CONCAT(col1,col2))
  24286.      AND col_1='constant' AND col_2='constant''
  24287.  
  24288.    * For tables that change a lot you should try to avoid all `VARCHAR'
  24289.      or `BLOB' columns. You will get dynamic row length as soon as you
  24290.      are using a single `VARCHAR' or `BLOB' column. *Note Table types::.
  24291.  
  24292.    * It's not normally useful to split a table into different tables
  24293.      just because the rows gets 'big'. To access a row, the biggest
  24294.      performance hit is the disk seek to find the first byte of the
  24295.      row. After finding the data most new disks can read the whole row
  24296.      fast enough for most applications. The only cases where it really
  24297.      matters to split up a table is if it's a dynamic row size table
  24298.      (see above) that you can change to a fixed row size, or if you
  24299.      very often need to scan the table and don't need most of the
  24300.      columns. *Note Table types::.
  24301.  
  24302.    * If you very often need to calculate things based on information
  24303.      from a lot of rows (like counts of things), it's probably much
  24304.      better to introduce a new table and update the counter in real
  24305.      time. An update of type `UPDATE table SET count=count+1 WHERE
  24306.      index_column=constant' is very fast!
  24307.  
  24308.      This is really important when you use MySQL table types like
  24309.      MyISAM and ISAM that only have table locking (multiple readers /
  24310.      single writers). This will also give better performance with most
  24311.      databases, as the row locking manager in this case will have less
  24312.      to do.
  24313.  
  24314.    * If you need to collect statistics from big log tables, use summary
  24315.      tables instead of scanning the whole table. Maintaining the
  24316.      summaries should be much faster than trying to do statistics
  24317.      'live'. It's much faster to regenerate new summary tables from the
  24318.      logs when things change (depending on business decisions) than to
  24319.      have to change the running application!
  24320.  
  24321.    * If possible, one should classify reports as 'live' or
  24322.      'statistical', where data needed for statistical reports are only
  24323.      generated based on summary tables that are generated from the
  24324.      actual data.
  24325.  
  24326.    * Take advantage of the fact that columns have default values. Insert
  24327.      values explicitly only when the value to be inserted differs from
  24328.      the default. This reduces the parsing that MySQL need to do and
  24329.      improves the insert speed.
  24330.  
  24331.    * In some cases it's convenient to pack and store data into a blob.
  24332.      In this case you have to add some extra code in your application
  24333.      to pack/unpack things in the blob, but this may save a lot of
  24334.      accesses at some stage.  This is practical when you have data that
  24335.      doesn't conform to a static table structure.
  24336.  
  24337.    * Normally you should try to keep all data non-redundant (what is
  24338.      called 3rd normal form in database theory), but you should not be
  24339.      afraid of duplicating things or creating summary tables if you
  24340.      need these to gain more speed.
  24341.  
  24342.    * Stored procedures or UDF (user-defined functions) may be a good
  24343.      way to get more performance.  In this case you should, however,
  24344.      always have a way to do this some other (slower) way if you use
  24345.      some database that doesn't support this.
  24346.  
  24347.    * You can always gain something by caching queries/answers in your
  24348.      application and trying to do many inserts/updates at the same
  24349.      time.  If your database supports lock tables (like MySQL and
  24350.      Oracle), this should help to ensure that the index cache is only
  24351.      flushed once after all updates.
  24352.  
  24353.    * Use `INSERT /*! DELAYED */' when you do not need to know when your
  24354.      data is written. This speeds things up because many records can be
  24355.      written with a single disk write.
  24356.  
  24357.    * Use `INSERT /*! LOW_PRIORITY */' when you want your selects to be
  24358.      more important.
  24359.  
  24360.    * Use `SELECT /*! HIGH_PRIORITY */' to get selects that jump the
  24361.      queue. That is, the select is done even if there is somebody
  24362.      waiting to do a write.
  24363.  
  24364.    * Use the multi-line `INSERT' statement to store many rows with one
  24365.      SQL command (many SQL servers supports this).
  24366.  
  24367.    * Use `LOAD DATA INFILE' to load bigger amounts of data. This is
  24368.      faster than normal inserts and will be even faster when `myisamchk'
  24369.      is integrated in `mysqld'.
  24370.  
  24371.    * Use `AUTO_INCREMENT' columns to make unique values.
  24372.  
  24373.    * Use `OPTIMIZE TABLE' once in a while to avoid fragmentation when
  24374.      using a dynamic table format. *Note `OPTIMIZE TABLE': OPTIMIZE
  24375.      TABLE.
  24376.  
  24377.    * Use `HEAP' tables to get more speed when possible. *Note Table
  24378.      types::.
  24379.  
  24380.    * When using a normal web server setup, images should be stored as
  24381.      files. That is, store only a file reference in the database.  The
  24382.      main reason for this is that a normal web server is much better at
  24383.      caching files than database contents. So it it's much easier to
  24384.      get a fast system if you are using files.
  24385.  
  24386.    * Use in memory tables for non-critical data that are accessed often
  24387.      (like information about the last shown banner for users that don't
  24388.      have cookies).
  24389.  
  24390.    * Columns with identical information in different tables should be
  24391.      declared identical and have identical names. Before Version 3.23
  24392.      you got slow joins otherwise.
  24393.  
  24394.      Try to keep the names simple (use `name' instead of
  24395.      `customer_name' in the customer table). To make your names portable
  24396.      to other SQL servers you should keep them shorter than 18
  24397.      characters.
  24398.  
  24399.    * If you need really high speed, you should take a look at the
  24400.      low-level interfaces for data storage that the different SQL
  24401.      servers support!  For example, by accessing the MySQL `MyISAM'
  24402.      directly, you could get a speed increase of 2-5 times compared to
  24403.      using the SQL interface.  To be able to do this the data must be
  24404.      on the same server as the application, and usually it should only
  24405.      be accessed by one process (because external file locking is
  24406.      really slow).  One could eliminate the above problems by
  24407.      introducing low-level `MyISAM' commands in the MySQL server (this
  24408.      could be one easy way to get more performance if needed).  By
  24409.      carefully designing the database interface, it should be quite
  24410.      easy to support this types of optimization.
  24411.  
  24412.    * In many cases it's faster to access data from a database (using a
  24413.      live connection) than accessing a text file, just because the
  24414.      database is likely to be more compact than the text file (if you
  24415.      are using numerical data), and this will involve fewer disk
  24416.      accesses.  You will also save code because you don't have to parse
  24417.      your text files to find line and column boundaries.
  24418.  
  24419.    * You can also use replication to speed things up. *Note
  24420.      Replication::.
  24421.  
  24422.    * Declaring a table with `DELAY_KEY_WRITE=1' will make the updating
  24423.      of indexes faster, as these are not logged to disk until the file
  24424.      is closed.  The downside is that you should run `myisamchk' on
  24425.      these tables before you start `mysqld' to ensure that they are
  24426.      okay if something killed `mysqld' in the middle.  As the key
  24427.      information can always be generated from the data, you should not
  24428.      lose anything by using `DELAY_KEY_WRITE'.
  24429.  
  24430. Locking Issues
  24431. ==============
  24432.  
  24433. How MySQL Locks Tables
  24434. ----------------------
  24435.  
  24436. You can find a discussion about different locking methods in the
  24437. appendix.  *Note Locking methods::.
  24438.  
  24439. All locking in MySQL is deadlock-free, except for `InnoDB' and `BDB'
  24440. type tables.  This is managed by always requesting all needed locks at
  24441. once at the beginning of a query and always locking the tables in the
  24442. same order.
  24443.  
  24444. `InnoDB' type tables automatically acquire their row locks and `BDB'
  24445. type tables their page locks during the processing of SQL statements,
  24446. not at the start of the transaction.
  24447.  
  24448. The locking method MySQL uses for `WRITE' locks works as follows:
  24449.  
  24450.    * If there are no locks on the table, put a write lock on it.
  24451.  
  24452.    * Otherwise, put the lock request in the write lock queue.
  24453.  
  24454. The locking method MySQL uses for `READ' locks works as follows:
  24455.  
  24456.    * If there are no write locks on the table, put a read lock on it.
  24457.  
  24458.    * Otherwise, put the lock request in the read lock queue.
  24459.  
  24460. When a lock is released, the lock is made available to the threads in
  24461. the write lock queue, then to the threads in the read lock queue.
  24462.  
  24463. This means that if you have many updates on a table, `SELECT'
  24464. statements will wait until there are no more updates.
  24465.  
  24466. To work around this for the case where you want to do many `INSERT' and
  24467. `SELECT' operations on a table, you can insert rows in a temporary
  24468. table and update the real table with the records from the temporary
  24469. table once in a while.
  24470.  
  24471. This can be done with the following code:
  24472.      mysql> LOCK TABLES real_table WRITE, insert_table WRITE;
  24473.      mysql> INSERT INTO real_table SELECT * FROM insert_table;
  24474.      mysql> TRUNCATE TABLE insert_table;
  24475.      mysql> UNLOCK TABLES;
  24476.  
  24477. You can use the `LOW_PRIORITY' options with `INSERT', `UPDATE' or
  24478. `DELETE' or `HIGH_PRIORITY' with `SELECT' if you want to prioritize
  24479. retrieval in some specific cases.  You can also start `mysqld' with
  24480. `--low-priority-updates' to get the same behavior.
  24481.  
  24482. Using `SQL_BUFFER_RESULT' can also help making table locks shorter.
  24483. *Note `SELECT': SELECT.
  24484.  
  24485. You could also change the locking code in `mysys/thr_lock.c' to use a
  24486. single queue.  In this case, write locks and read locks would have the
  24487. same priority, which might help some applications.
  24488.  
  24489. Table Locking Issues
  24490. --------------------
  24491.  
  24492. The table locking code in MySQL is deadlock free.
  24493.  
  24494. MySQL uses table locking (instead of row locking or column locking) on
  24495. all table types, except `InnoDB' and `BDB' tables, to achieve a very
  24496. high lock speed.  For large tables, table locking is much better than
  24497. row locking for most applications, but there are some pitfalls.
  24498.  
  24499. For `InnoDB' and `BDB' tables, MySQL only uses table locking if you
  24500. explicitly lock the table with `LOCK TABLES'.  For these table types we
  24501. recommend you to not use `LOCK TABLES' at all, because `InnoDB' uses
  24502. automatic row level locking and `BDB' uses page level locking to ensure
  24503. transaction isolation.
  24504.  
  24505. As of MySQL Version 3.23.7 (3.23.25 for Windows), you can insert rows
  24506. into `MyISAM' tables at the same time other threads are reading from the
  24507. table.  Note that currently this works only if there are no holes
  24508. resulting from deleted rows in the table at the time the insert is
  24509. made. When all holes has been filled with new data, concurrent inserts
  24510. will automatically be enabled again.
  24511.  
  24512. Table locking enables many threads to read from a table at the same
  24513. time, but if a thread wants to write to a table, it must first get
  24514. exclusive access.  During the update, all other threads that want to
  24515. access this particular table will wait until the update is ready.
  24516.  
  24517. As updates on tables normally are considered to be more important than
  24518. `SELECT', all statements that update a table have higher priority than
  24519. statements that retrieve information from a table. This should ensure
  24520. that updates are not 'starved' because one issues a lot of heavy
  24521. queries against a specific table. (You can change this by using
  24522. `LOW_PRIORITY' with the statement that does the update or
  24523. `HIGH_PRIORITY' with the `SELECT' statement.)
  24524.  
  24525. Starting from MySQL Version 3.23.7 one can use the
  24526. `max_write_lock_count' variable to force MySQL to temporary give all
  24527. `SELECT' statements, that wait for a table, a higher priority after a
  24528. specific number of inserts on a table.
  24529.  
  24530. Table locking is, however, not very good under the following scenario:
  24531.  
  24532.    * A client issues a `SELECT' that takes a long time to run.
  24533.  
  24534.    * Another client then issues an `UPDATE' on a used table. This client
  24535.      will wait until the `SELECT' is finished.
  24536.  
  24537.    * Another client issues another `SELECT' statement on the same
  24538.      table. As `UPDATE' has higher priority than `SELECT', this `SELECT'
  24539.      will wait for the `UPDATE' to finish.  It will also wait for the
  24540.      first `SELECT' to finish!
  24541.  
  24542.    * A thread is waiting for something like `full disk', in which case
  24543.      all threads that wants to access the problem table will also be
  24544.      put in a waiting state until more disk space is made available.
  24545.  
  24546. Some possible solutions to this problem are:
  24547.  
  24548.    * Try to get the `SELECT' statements to run faster. You may have to
  24549.      create some summary tables to do this.
  24550.  
  24551.    * Start `mysqld' with `--low-priority-updates'.  This will give all
  24552.      statements that update (modify) a table lower priority than a
  24553.      `SELECT' statement. In this case the last `SELECT' statement in
  24554.      the previous scenario would execute before the `INSERT' statement.
  24555.  
  24556.    * You can give a specific `INSERT', `UPDATE', or `DELETE' statement
  24557.      lower priority with the `LOW_PRIORITY' attribute.
  24558.  
  24559.    * Start `mysqld' with a low value for `max_write_lock_count' to give
  24560.      `READ' locks after a certain number of `WRITE' locks.
  24561.  
  24562.    * You can specify that all updates from a specific thread should be
  24563.      done with low priority by using the SQL command: `SET
  24564.      LOW_PRIORITY_UPDATES=1'.  *Note `SET': SET OPTION.
  24565.  
  24566.    * You can specify that a specific `SELECT' is very important with the
  24567.      `HIGH_PRIORITY' attribute. *Note `SELECT': SELECT.
  24568.  
  24569.    * If you have problems with `INSERT' combined with `SELECT', switch
  24570.      to use the new `MyISAM' tables as these support concurrent
  24571.      `SELECT' and `INSERT' statements.
  24572.  
  24573.    * If you mainly mix `INSERT' and `SELECT' statements, the `DELAYED'
  24574.      attribute to `INSERT' will probably solve your problems.  *Note
  24575.      `INSERT': INSERT.
  24576.  
  24577.    * If you have problems with `SELECT' and `DELETE', the `LIMIT'
  24578.      option to `DELETE' may help. *Note `DELETE': DELETE.
  24579.  
  24580. Optimizing Database Structure
  24581. =============================
  24582.  
  24583. Design Choices
  24584. --------------
  24585.  
  24586. MySQL keeps row data and index data in separate files. Many (almost
  24587. all) other databases mix row and index data in the same file. We
  24588. believe that the MySQL choice is better for a very wide range of modern
  24589. systems.
  24590.  
  24591. Another way to store the row data is to keep the information for each
  24592. column in a separate area (examples are SDBM and Focus). This will
  24593. cause a performance hit for every query that accesses more than one
  24594. column. Because this degenerates so quickly when more than one column
  24595. is accessed, we believe that this model is not good for general purpose
  24596. databases.
  24597.  
  24598. The more common case is that the index and data are stored together (as
  24599. in Oracle/Sybase et al). In this case you will find the row information
  24600. at the leaf page of the index. The good thing with this layout is that
  24601. it, in many cases, depending on how well the index is cached, saves a
  24602. disk read.  The bad things with this layout are:
  24603.  
  24604.    * Table scanning is much slower because you have to read through the
  24605.      indexes to get at the data.
  24606.  
  24607.    * You can't use only the index table to retrieve data for a query.
  24608.  
  24609.    * You lose a lot of space, as you must duplicate indexes from the
  24610.      nodes (as you can't store the row in the nodes).
  24611.  
  24612.    * Deletes will degenerate the table over time (as indexes in nodes
  24613.      are usually not updated on delete).
  24614.  
  24615.    * It's harder to cache only the index data.
  24616.  
  24617. Get Your Data as Small as Possible
  24618. ----------------------------------
  24619.  
  24620. One of the most basic optimization is to get your data (and indexes) to
  24621. take as little space on the disk (and in memory) as possible. This can
  24622. give huge improvements because disk reads are faster and normally less
  24623. main memory will be used. Indexing also takes less resources if done on
  24624. smaller columns.
  24625.  
  24626. MySQL supports a lot of different table types and row formats.
  24627. Choosing the right table format may give you a big performance gain.
  24628. *Note Table types::.
  24629.  
  24630. You can get better performance on a table and minimise storage space
  24631. using the techniques listed here:
  24632.  
  24633.    * Use the most efficient (smallest) types possible. MySQL has many
  24634.      specialized types that save disk space and memory.
  24635.  
  24636.    * Use the smaller integer types if po