home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 Autumn / INTERNET109.ISO / pc / software / windows / building / mysql / data1.cab / Documentation / Docs / manual.txt < prev   
Encoding:
Text File  |  2003-08-03  |  2.6 MB  |  67,505 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.   What Is MySQL?
  13.     History of MySQL
  14.     The Main Features of MySQL
  15.     How Stable Is MySQL?
  16.     How Big Can MySQL Tables Be?
  17.     Year 2000 Compliance
  18.   What Is 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.       Advertising
  26.     Contact Information
  27.   MySQL Support and Licensing
  28.     Support Offered by MySQL AB
  29.     Copyrights and Licenses Used by MySQL
  30.     MySQL Licenses
  31.       Using the MySQL Software Under a Commercial License
  32.       Using the MySQL Software for Free Under GPL
  33.     MySQL AB Logos and Trademarks
  34.       The Original MySQL Logo
  35.       MySQL Logos that may be Used Without Written Permission
  36.       When do you need a Written Permission to use MySQL Logos?
  37.       MySQL AB Partnership Logos
  38.       Using the word `MySQL' in Printed Text or Presentations
  39.       Using the word `MySQL' in Company and Product Names
  40.   MySQL 4.0 In A Nutshell
  41.     Features Available From MySQL 4.0
  42.     Embedded MySQL Server
  43.   MySQL 4.1 In A Nutshell
  44.     Features Available From MySQL 4.1
  45.     Stepwise Rollout
  46.     Ready for Immediate Development Use
  47.     MySQL 5.0, The Next Development Release
  48.   MySQL Information Sources
  49.     MySQL Mailing Lists
  50.       The MySQL Mailing Lists
  51.       Asking Questions or Reporting Bugs
  52.       How to Report Bugs or Problems
  53.       Guidelines for Answering Questions on the Mailing List
  54.     MySQL Community Support on IRC (Internet Relay Chat)
  55.   How Standards-compatible Is MySQL?
  56.     What Standards Does MySQL Follow?
  57.     Running MySQL in ANSI Mode
  58.     MySQL Extensions To The SQL-92 Standard
  59.     MySQL Differences Compared To SQL-92
  60.       Sub`SELECT's
  61.       `SELECT INTO TABLE'
  62.       Transactions and Atomic Operations
  63.       Stored Procedures and Triggers
  64.       Foreign Keys
  65.       Views
  66.       `--' as the Start of a Comment
  67.     How MySQL deals with constraints
  68.       Constraint PRIMARY KEY / UNIQUE
  69.       Constraint `NOT NULL' and `DEFAULT' values
  70.       Constraint `ENUM' and `SET'
  71.     Known Errors and Design Deficiencies in MySQL
  72.       Errors in 3.23 Fixed in a Later MySQL Version
  73.       Open Bugs / Design Deficiencies in MySQL
  74.   MySQL and The Future (The TODO)
  75.     New Features Planned For 4.1
  76.     New Features Planned For 5.0
  77.     New Features Planned For 5.1
  78.     New Features Planned For The Near Future
  79.     New Features Planned For The Mid-Term Future
  80.     New Features We Don't Plan To Do
  81.   How MySQL Compares to Other Databases
  82.     How MySQL Compares to `mSQL'
  83.       How to Convert `mSQL' Tools for MySQL
  84.       How `mSQL' and MySQL Client/Server Communications Protocols Differ
  85.       How `mSQL' 2.0 SQL Syntax Differs from MySQL
  86.     How MySQL Compares to `PostgreSQL'
  87.       MySQL and PostgreSQL development strategies
  88.       Featurewise Comparison of MySQL and PostgreSQL
  89.       Benchmarking MySQL and PostgreSQL
  90.  
  91. MySQL Installation
  92.   Quick Standard Installation of MySQL
  93.     Installing MySQL on Linux
  94.     Installing MySQL on Windows
  95.       Installing the Binaries
  96.       Preparing the Windows MySQL Environment
  97.       Starting the Server for the First Time
  98.     Installing MySQL on Mac OS X
  99.     Installing MySQL on NetWare
  100.       Installing the MySQL for NetWare Binaries
  101.   General Installation Issues
  102.     How to Get MySQL
  103.     Verifying Package Integrity Using `MD5 Checksums' or `GnuPG'
  104.     Operating Systems Supported by MySQL
  105.     Which MySQL Version to Use
  106.     Installation Layouts
  107.     How and When Updates Are Released
  108.     Release Philosophy - No Known Bugs in Releases
  109.     MySQL Binaries Compiled by MySQL AB
  110.     Installing a MySQL Binary Distribution
  111.   Installing a MySQL Source Distribution
  112.     Quick Installation Overview
  113.     Applying Patches
  114.     Typical `configure' Options
  115.     Installing from the Development Source Tree
  116.     Problems Compiling MySQL?
  117.     MIT-pthreads Notes
  118.     Windows Source Distribution
  119.   Post-installation Setup and Testing
  120.     Problems Running `mysql_install_db'
  121.     Problems Starting the MySQL Server
  122.     Starting and Stopping MySQL Automatically
  123.   Upgrading/Downgrading MySQL
  124.     Upgrading From Version 4.0 to 4.1
  125.       Preparing to Upgrade From Version 4.0 to 4.1
  126.       What to do when upgrading from 4.0 to 4.1
  127.     Upgrading From Version 3.23 to 4.0
  128.     Upgrading From Version 3.22 to 3.23
  129.     Upgrading from Version 3.21 to 3.22
  130.     Upgrading from Version 3.20 to 3.21
  131.     Upgrading to Another Architecture
  132.     Upgrading MySQL under Windows
  133.   Operating System Specific Notes
  134.     Linux Notes (All Linux Versions)
  135.       Linux Notes for Binary Distributions
  136.       Linux x86 Notes
  137.       Linux SPARC Notes
  138.       Linux Alpha Notes
  139.       Linux PowerPC Notes
  140.       Linux MIPS Notes
  141.       Linux IA-64 Notes
  142.     Windows Notes
  143.       Starting MySQL on Windows 95, 98, or Me
  144.       Starting MySQL on Windows NT, 2000, or XP
  145.       Running MySQL on Windows
  146.       Connecting to MySQL Remotely from Windows with SSH
  147.       Distributing Data Across Different Disks on Windows
  148.       Compiling MySQL Clients on Windows
  149.       MySQL for Windows Compared to Unix MySQL
  150.     Solaris Notes
  151.       Solaris 2.7/2.8 Notes
  152.       Solaris x86 Notes
  153.     BSD Notes
  154.       FreeBSD Notes
  155.       NetBSD Notes
  156.       OpenBSD 2.5 Notes
  157.       OpenBSD 2.8 Notes
  158.       BSD/OS Version 2.x Notes
  159.       BSD/OS Version 3.x Notes
  160.       BSD/OS Version 4.x Notes
  161.     Mac OS X Notes
  162.       Mac OS X 10.x
  163.       Mac OS X Server 1.2 (Rhapsody)
  164.     Other Unix Notes
  165.       HP-UX Notes for Binary Distributions
  166.       HP-UX Version 10.20 Notes
  167.       HP-UX Version 11.x Notes
  168.       IBM-AIX notes
  169.       SunOS 4 Notes
  170.       Alpha-DEC-UNIX Notes (Tru64)
  171.       Alpha-DEC-OSF/1 Notes
  172.       SGI Irix Notes
  173.       SCO Notes
  174.       SCO UnixWare Version 7.1.x Notes
  175.     OS/2 Notes
  176.     Novell NetWare Notes
  177.     BeOS Notes
  178.   Perl Installation Comments
  179.     Installing Perl on Unix
  180.     Installing ActiveState Perl on Windows
  181.     Installing the MySQL Perl Distribution on Windows
  182.     Problems Using the Perl `DBI'/`DBD' Interface
  183.  
  184. Tutorial Introduction
  185.   Connecting to and Disconnecting from the Server
  186.   Entering Queries
  187.   Creating and Using a Database
  188.     Creating and Selecting a Database
  189.     Creating a Table
  190.     Loading Data into a Table
  191.     Retrieving Information from a Table
  192.       Selecting All Data
  193.       Selecting Particular Rows
  194.       Selecting Particular Columns
  195.       Sorting Rows
  196.       Date Calculations
  197.       Working with `NULL' Values
  198.       Pattern Matching
  199.       Counting Rows
  200.       Using More Than one Table
  201.   Getting Information About Databases and Tables
  202.   Examples of Common Queries
  203.     The Maximum Value for a Column
  204.     The Row Holding the Maximum of a Certain Column
  205.     Maximum of Column per Group
  206.     The Rows Holding the Group-wise Maximum of a Certain Field
  207.     Using user variables
  208.     Using Foreign Keys
  209.     Searching on Two Keys
  210.     Calculating Visits Per Day
  211.     Using `AUTO_INCREMENT'
  212.   Using `mysql' in Batch Mode
  213.   Queries from Twin Project
  214.     Find all Non-distributed Twins
  215.     Show a Table on Twin Pair Status
  216.   Using MySQL with Apache
  217.  
  218. Database Administration
  219.   Configuring MySQL
  220.     `mysqld' Command-line Options
  221.     `my.cnf' Option Files
  222.     Running Multiple MySQL Servers on the Same Machine
  223.       Running Multiple Servers on Windows
  224.       Running Multiple Servers on Unix
  225.       Using Client Programs in a Multiple-Server Environment
  226.   General Security Issues and the MySQL Access Privilege System
  227.     General Security Guidelines
  228.     How to Make MySQL Secure Against Crackers
  229.     Startup Options for `mysqld' Concerning Security
  230.     Security issues with `LOAD DATA LOCAL'
  231.     What the Privilege System Does
  232.     How the Privilege System Works
  233.     Privileges Provided by MySQL
  234.     Connecting to the MySQL Server
  235.     Access Control, Stage 1: Connection Verification
  236.     Access Control, Stage 2: Request Verification
  237.     Password Hashing in MySQL 4.1
  238.     Causes of `Access denied' Errors
  239.   MySQL User Account Management
  240.     `GRANT' and `REVOKE' Syntax
  241.     MySQL User Names and Passwords
  242.     When Privilege Changes Take Effect
  243.     Setting Up the Initial MySQL Privileges
  244.     Adding New Users to MySQL
  245.     Limiting user resources
  246.     Setting Up Passwords
  247.     Keeping Your Password Secure
  248.     Using Secure Connections
  249.       Basics
  250.       Requirements
  251.       Setting Up SSL Certificates for MySQL
  252.       `GRANT' Options
  253.   Disaster Prevention and Recovery
  254.     Database Backups
  255.     `BACKUP TABLE' Syntax
  256.     `RESTORE TABLE' Syntax
  257.     `CHECK TABLE' Syntax
  258.     `REPAIR TABLE' Syntax
  259.     Using `myisamchk' for Table Maintenance and Crash Recovery
  260.       `myisamchk' Invocation Syntax
  261.       General Options for `myisamchk'
  262.       Check Options for `myisamchk'
  263.       Repair Options for myisamchk
  264.       Other Options for `myisamchk'
  265.       `myisamchk' Memory Usage
  266.       Using `myisamchk' for Crash Recovery
  267.       How to Check Tables for Errors
  268.       How to Repair Tables
  269.       Table Optimisation
  270.     Setting Up a Table Maintenance Regimen
  271.     Getting Information About a Table
  272.   Database Administration Language Reference
  273.     `OPTIMIZE TABLE' Syntax
  274.     `ANALYZE TABLE' Syntax
  275.     `FLUSH' Syntax
  276.     `RESET' Syntax
  277.     `PURGE MASTER LOGS' Syntax
  278.     `KILL' Syntax
  279.     `SHOW' Syntax
  280.       Retrieving information about Database, Tables, Columns, and Indexes
  281.       `SHOW TABLE STATUS'
  282.       `SHOW STATUS'
  283.       `SHOW VARIABLES'
  284.       `SHOW [BDB] LOGS'
  285.       `SHOW PROCESSLIST'
  286.       `SHOW GRANTS'
  287.       `SHOW CREATE TABLE'
  288.       `SHOW WARNINGS | ERRORS'
  289.       `SHOW TABLE TYPES'
  290.       `SHOW PRIVILEGES'
  291.   MySQL Localisation and International Usage
  292.     The Character Set Used for Data and Sorting
  293.       German character set
  294.     Non-English Error Messages
  295.     Adding a New Character Set
  296.     The Character Definition Arrays
  297.     String Collating Support
  298.     Multi-byte Character Support
  299.     Problems With Character Sets
  300.   MySQL Server-Side Scripts and Utilities
  301.     Overview of the Server-Side Scripts and Utilities
  302.     `mysqld_safe', The Wrapper Around `mysqld'
  303.     `mysqld_multi', A Program for Managing Multiple MySQL Servers
  304.     `myisampack', The MySQL Compressed Read-only Table Generator
  305.     `mysqld-max', An Extended `mysqld' Server
  306.   MySQL Client-Side Scripts and Utilities
  307.     Overview of the Client-Side Scripts and Utilities
  308.     `mysql', The Command-line Tool
  309.     `mysqladmin', Administrating a MySQL Server
  310.     Using `mysqlcheck' for Table Maintenance and Crash Recovery
  311.     `mysqldump', Dumping Table Structure and Data
  312.     `mysqlhotcopy', Copying MySQL Databases and Tables
  313.     `mysqlimport', Importing Data from Text Files
  314.     `mysqlshow', Showing Databases, Tables, and Columns
  315.     `mysql_config', Get compile options for compiling clients
  316.     `perror', Explaining Error Codes
  317.     How to Run SQL Commands from a Text File
  318.   The MySQL Log Files
  319.     The Error Log
  320.     The General Query Log
  321.     The Update Log
  322.     The Binary Log
  323.     The Slow Query Log
  324.     Log File Maintenance
  325.   Replication in MySQL
  326.     Introduction
  327.     Replication Implementation Overview
  328.     Replication Implementation Details
  329.     How To Set Up Replication
  330.     Replication Features and Known Problems
  331.     Replication Options in `my.cnf'
  332.     SQL Commands Related to Replication
  333.       `START SLAVE' (slave)
  334.       `STOP SLAVE' (slave)
  335.       `SET SQL_LOG_BIN=0|1' (master)
  336.       `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n' (slave)
  337.       `RESET MASTER' (master)
  338.       `RESET SLAVE' (slave)
  339.       `LOAD TABLE tblname FROM MASTER' (slave)
  340.       `LOAD DATA FROM MASTER' (slave)
  341.       `CHANGE MASTER TO master_def_list' (slave)
  342.       `MASTER_POS_WAIT()' (slave)
  343.       `SHOW MASTER STATUS' (master)
  344.       `SHOW SLAVE HOSTS' (master)
  345.       `SHOW SLAVE STATUS' (slave)
  346.       `SHOW MASTER LOGS' (master)
  347.       `SHOW BINLOG EVENTS' (master)
  348.       `PURGE MASTER LOGS' (master)
  349.     Replication FAQ
  350.     Troubleshooting Replication
  351.  
  352. MySQL Optimisation
  353.   Optimisation Overview
  354.     MySQL Design Limitations/Tradeoffs
  355.     Portability
  356.     What Have We Used MySQL For?
  357.     The MySQL Benchmark Suite
  358.     Using Your Own Benchmarks
  359.   Optimising `SELECT's and Other Queries
  360.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  361.     Estimating Query Performance
  362.     Speed of `SELECT' Queries
  363.     How MySQL Optimises `WHERE' Clauses
  364.     How MySQL Optimises `IS NULL'
  365.     How MySQL Optimises `DISTINCT'
  366.     How MySQL Optimises `LEFT JOIN' and `RIGHT JOIN'
  367.     How MySQL Optimises `ORDER BY'
  368.     How MySQL Optimises `LIMIT'
  369.     Speed of `INSERT' Queries
  370.     Speed of `UPDATE' Queries
  371.     Speed of `DELETE' Queries
  372.     Other Optimisation Tips
  373.   Locking Issues
  374.     How MySQL Locks Tables
  375.     Table Locking Issues
  376.   Optimising Database Structure
  377.     Design Choices
  378.     Get Your Data as Small as Possible
  379.     How MySQL Uses Indexes
  380.     Column Indexes
  381.     Multiple-Column Indexes
  382.     Why So Many Open tables?
  383.     How MySQL Opens and Closes Tables
  384.     Drawbacks to Creating Large Numbers of Tables in the Same Database
  385.   Optimising the MySQL Server
  386.     System/Compile Time and Startup Parameter Tuning
  387.     Tuning Server Parameters
  388.     How Compiling and Linking Affects the Speed of MySQL
  389.     How MySQL Uses Memory
  390.     How MySQL uses DNS
  391.     `SET' Syntax
  392.   Disk Issues
  393.     Using Symbolic Links
  394.       Using Symbolic Links for Databases
  395.       Using Symbolic Links for Tables
  396.  
  397. MySQL Language Reference
  398.   Language Structure
  399.     Literals: How to Write Strings and Numbers
  400.       Strings
  401.       Numbers
  402.       Hexadecimal Values
  403.       `NULL' Values
  404.     Database, Table, Index, Column, and Alias Names
  405.     Case Sensitivity in Names
  406.     User Variables
  407.     System Variables
  408.     Comment Syntax
  409.     Is MySQL Picky About Reserved Words?
  410.   Column Types
  411.     Numeric Types
  412.     Date and Time Types
  413.       Y2K Issues and Date Types
  414.       The `DATETIME', `DATE', and `TIMESTAMP' Types
  415.       The `TIME' Type
  416.       The `YEAR' Type
  417.     String Types
  418.       The `CHAR' and `VARCHAR' Types
  419.       The `BLOB' and `TEXT' Types
  420.       The `ENUM' Type
  421.       The `SET' Type
  422.     Choosing the Right Type for a Column
  423.     Using Column Types from Other Database Engines
  424.     Column Type Storage Requirements
  425.   Functions for Use in `SELECT' and `WHERE' Clauses
  426.     Non-Type-Specific Operators and Functions
  427.       Parentheses
  428.       Comparison Operators
  429.       Logical Operators
  430.       Control Flow Functions
  431.     String Functions
  432.       String Comparison Functions
  433.       Case-Sensitivity
  434.     Numeric Functions
  435.       Arithmetic Operations
  436.       Mathematical Functions
  437.     Date and Time Functions
  438.     Cast Functions
  439.     Other Functions
  440.       Bit Functions
  441.       Miscellaneous Functions
  442.     Functions and Modifiers for Use with `GROUP BY' Clauses
  443.       `GROUP BY' Functions
  444.       `GROUP BY' Modifiers
  445.   Data Manipulation: `SELECT', `INSERT', `UPDATE', `DELETE'
  446.     `SELECT' Syntax
  447.       `JOIN' Syntax
  448.       `UNION' Syntax
  449.     `HANDLER' Syntax
  450.     `INSERT' Syntax
  451.       `INSERT ... SELECT' Syntax
  452.     `INSERT DELAYED' Syntax
  453.     `UPDATE' Syntax
  454.     `DELETE' Syntax
  455.     `TRUNCATE' Syntax
  456.     `REPLACE' Syntax
  457.     `LOAD DATA INFILE' Syntax
  458.     `DO' Syntax
  459.   Data Definition: `CREATE', `DROP', `ALTER'
  460.     `CREATE DATABASE' Syntax
  461.     `DROP DATABASE' Syntax
  462.     `CREATE TABLE' Syntax
  463.       Silent Column Specification Changes
  464.     `ALTER TABLE' Syntax
  465.     `RENAME TABLE' Syntax
  466.     `DROP TABLE' Syntax
  467.     `CREATE INDEX' Syntax
  468.     `DROP INDEX' Syntax
  469.   Basic MySQL User Utility Commands
  470.     `USE' Syntax
  471.     `DESCRIBE' Syntax (Get Information About Columns)
  472.   MySQL Transactional and Locking Commands
  473.     `BEGIN/COMMIT/ROLLBACK' Syntax
  474.     `LOCK TABLES/UNLOCK TABLES' Syntax
  475.     `SET TRANSACTION' Syntax
  476.   MySQL Full-text Search
  477.     Full-text Restrictions
  478.     Fine-tuning MySQL Full-text Search
  479.     Full-text Search TODO
  480.   MySQL Query Cache
  481.     How The Query Cache Operates
  482.     Query Cache Configuration
  483.     Query Cache Options in `SELECT'
  484.     Query Cache Status and Maintenance
  485.  
  486. MySQL Table Types
  487.   `MyISAM' Tables
  488.     Space Needed for Keys
  489.     `MyISAM' Table Formats
  490.       Static (Fixed-length) Table Characteristics
  491.       Dynamic Table Characteristics
  492.       Compressed Table Characteristics
  493.     `MyISAM' Table Problems
  494.       Corrupted `MyISAM' Tables
  495.       Clients is using or hasn't closed the table properly
  496.   `MERGE' Tables
  497.     `MERGE' Table Problems
  498.   `ISAM' Tables
  499.   `HEAP' Tables
  500.   `InnoDB' Tables
  501.     InnoDB Tables Overview
  502.     InnoDB in MySQL Version 3.23
  503.     InnoDB Startup Options
  504.     Creating InnoDB Tablespace
  505.       If Something Goes Wrong in Database Creation
  506.     Creating InnoDB Tables
  507.       Converting MyISAM Tables to InnoDB
  508.       Foreign Key Constraints
  509.     Adding and Removing InnoDB Data and Log Files
  510.     Backing up and Recovering an InnoDB Database
  511.       Checkpoints
  512.     Moving an InnoDB Database to Another Machine
  513.     InnoDB Transaction Model
  514.       Consistent Read
  515.       Locking Reads
  516.       Next-key Locking: Avoiding the Phantom Problem
  517.       Locks Set by Different SQL Statements in InnoDB
  518.       Deadlock Detection and Rollback
  519.       An Example of How the Consistent Read Works in InnoDB
  520.       How to cope with deadlocks?
  521.       Performance Tuning Tips
  522.       The InnoDB Monitor
  523.     Implementation of Multi-versioning
  524.     Table and Index Structures
  525.       Physical Structure of an Index
  526.       Insert Buffering
  527.       Adaptive Hash Indexes
  528.       Physical Record Structure
  529.       How an Auto-increment Column Works in InnoDB
  530.     File Space Management and Disk I/O
  531.       Disk I/O
  532.       File Space Management
  533.       Defragmenting a Table
  534.     Error Handling
  535.     Restrictions on InnoDB Tables
  536.     InnoDB Change History
  537.       MySQL/InnoDB-4.0.14, June x, 2003
  538.       MySQL/InnoDB-4.0.13, May 20, 2003
  539.       MySQL/InnoDB-4.1.0, April 3, 2003
  540.       MySQL/InnoDB-3.23.56, March 17, 2003
  541.       MySQL/InnoDB-4.0.12, March 18, 2003
  542.       MySQL/InnoDB-4.0.11, February 25, 2003
  543.       MySQL/InnoDB-4.0.10, February 4, 2003
  544.       MySQL/InnoDB-3.23.55, January 24, 2003
  545.       MySQL/InnoDB-4.0.9, January 14, 2003
  546.       MySQL/InnoDB-4.0.8, January 7, 2003
  547.       MySQL/InnoDB-4.0.7, December 26, 2002
  548.       MySQL/InnoDB-4.0.6, December 19, 2002
  549.       MySQL/InnoDB-3.23.54, December 12, 2002
  550.       MySQL/InnoDB-4.0.5, November 18, 2002
  551.       MySQL/InnoDB-3.23.53, October 9, 2002
  552.       MySQL/InnoDB-4.0.4, October 2, 2002
  553.       MySQL/InnoDB-4.0.3, August 28, 2002
  554.       MySQL/InnoDB-3.23.52, August 16, 2002
  555.       MySQL/InnoDB-4.0.2, July 10, 2002
  556.       MySQL/InnoDB-3.23.51, June 12, 2002
  557.       MySQL/InnoDB-3.23.50, April 23, 2002
  558.       MySQL/InnoDB-3.23.49, February 17, 2002
  559.       MySQL/InnoDB-3.23.48, February 9, 2002
  560.       MySQL/InnoDB-3.23.47, December 28, 2001
  561.       MySQL/InnoDB-4.0.1, December 23, 2001
  562.       MySQL/InnoDB-3.23.46, November 30, 2001
  563.       MySQL/InnoDB-3.23.45, November 23, 2001
  564.       MySQL/InnoDB-3.23.44, November 2, 2001
  565.       MySQL/InnoDB-3.23.43, October 4, 2001
  566.       MySQL/InnoDB-3.23.42, September 9, 2001
  567.       MySQL/InnoDB-3.23.41, August 13, 2001
  568.       MySQL/InnoDB-3.23.40, July 16, 2001
  569.       MySQL/InnoDB-3.23.39, June 13, 2001
  570.       MySQL/InnoDB-3.23.38, May 12, 2001
  571.     InnoDB Contact Information
  572.   `BDB' or `BerkeleyDB' Tables
  573.     Overview of `BDB' Tables
  574.     Installing `BDB'
  575.     `BDB' startup options
  576.     Characteristics of `BDB' tables:
  577.     Things we need to fix for `BDB' in the near future:
  578.     Operating systems supported by `BDB'
  579.     Restrictions on `BDB' Tables
  580.     Errors That May Occur When Using `BDB' Tables
  581.  
  582. National Character Sets and Unicode in MySQL 4.1
  583.   Character Sets and Collations in General
  584.   Character Sets and Collations in MySQL
  585.   Determining The Default Character Set And Collation
  586.     Server Character Set and Collation
  587.     Database Character Set and Collation
  588.     Table Character Set and Collation
  589.     Column Character Set and Collation
  590.     Examples of Character Set and Collation Assignment
  591.     Connection Character Sets and Collations
  592.     Character String Literal Character Set and Collation
  593.     `COLLATE' Clause in Various Parts of an SQL Query
  594.     `COLLATE' Clause Precedence
  595.     `BINARY' Operator
  596.     Some Special Cases Where the Collation Determination is Tricky
  597.     Collations Must Be for the Right Character Set
  598.     An example of the Effect of Collation
  599.   Operations Affected by Character Set Support
  600.     Result Strings
  601.     `CONVERT()'
  602.     `CAST()'
  603.     `SHOW CHARACTER SET'
  604.     `SHOW COLLATION'
  605.     `SHOW CREATE DATABASE'
  606.     `SHOW FULL FIELDS'
  607.   Unicode Support
  608.   UTF8 for Metadata
  609.   Compatibility with Other DBMSs
  610.   New Character Set Configuration File format
  611.   National Character Set
  612.   Upgrading from MySQL 4.0
  613.     4.0 Character Sets and Corresponding 4.1 Character Set/Collation Pairs
  614.   The Character Sets and Collations that MySQL Supports
  615.     The Unicode Character Sets
  616.     Platform Specific Character Sets
  617.     Character Sets for South Europe and Middle East
  618.     The Asian Character Sets
  619.     The Baltic Character Sets
  620.     The Cyrillic Character Sets
  621.     The Central European Character Sets
  622.     The West European Character Sets
  623.  
  624. MySQL APIs
  625.   MySQL C API
  626.     C API Datatypes
  627.     C API Function Overview
  628.     C API Function Descriptions
  629.       `mysql_affected_rows()'
  630.       `mysql_change_user()'
  631.       `mysql_character_set_name()'
  632.       `mysql_close()'
  633.       `mysql_connect()'
  634.       `mysql_create_db()'
  635.       `mysql_data_seek()'
  636.       `mysql_debug()'
  637.       `mysql_drop_db()'
  638.       `mysql_dump_debug_info()'
  639.       `mysql_eof()'
  640.       `mysql_errno()'
  641.       `mysql_error()'
  642.       `mysql_escape_string()'
  643.       `mysql_fetch_field()'
  644.       `mysql_fetch_fields()'
  645.       `mysql_fetch_field_direct()'
  646.       `mysql_fetch_lengths()'
  647.       `mysql_fetch_row()'
  648.       `mysql_field_count()'
  649.       `mysql_field_seek()'
  650.       `mysql_field_tell()'
  651.       `mysql_free_result()'
  652.       `mysql_get_client_info()'
  653.       `mysql_get_server_version()'
  654.       `mysql_get_host_info()'
  655.       `mysql_get_proto_info()'
  656.       `mysql_get_server_info()'
  657.       `mysql_info()'
  658.       `mysql_init()'
  659.       `mysql_insert_id()'
  660.       `mysql_kill()'
  661.       `mysql_list_dbs()'
  662.       `mysql_list_fields()'
  663.       `mysql_list_processes()'
  664.       `mysql_list_tables()'
  665.       `mysql_num_fields()'
  666.       `mysql_num_rows()'
  667.       `mysql_options()'
  668.       `mysql_ping()'
  669.       `mysql_query()'
  670.       `mysql_real_connect()'
  671.       `mysql_real_escape_string()'
  672.       `mysql_real_query()'
  673.       `mysql_reload()'
  674.       `mysql_row_seek()'
  675.       `mysql_row_tell()'
  676.       `mysql_select_db()'
  677.       `mysql_sqlstate()'
  678.       `mysql_shutdown()'
  679.       `mysql_stat()'
  680.       `mysql_store_result()'
  681.       `mysql_thread_id()'
  682.       `mysql_use_result()'
  683.       `mysql_commit()'
  684.       `mysql_rollback()'
  685.       `mysql_autocommit()'
  686.       `mysql_more_results()'
  687.       `mysql_next_result()'
  688.     C API Prepared Statements
  689.     C API Prepared Statements DataTypes
  690.     C API Prepared Statements Function Overview
  691.     C API Prepared Statement Function Descriptions
  692.       `mysql_prepare()'
  693.       `mysql_param_count()'
  694.       `mysql_prepare_result()'
  695.       `mysql_bind_param()'
  696.       `mysql_execute()'
  697.       `mysql_stmt_affected_rows()'
  698.       `mysql_bind_result()'
  699.       `mysql_stmt_store_result()'
  700.       `mysql_stmt_data_seek()'
  701.       `mysql_stmt_row_seek()'
  702.       `mysql_stmt_row_tell()'
  703.       `mysql_stmt_num_rows()'
  704.       `mysql_fetch()'
  705.       `mysql_send_long_data()'
  706.       `mysql_stmt_close()'
  707.       `mysql_stmt_errno()'
  708.       `mysql_stmt_error()'
  709.       `mysql_stmt_sqlstate()'
  710.     C API Handling multiple query executions
  711.     C API Handling DATE, TIME and TIMESTAMP
  712.     C API Threaded Function Descriptions
  713.       `my_init()'
  714.       `mysql_thread_init()'
  715.       `mysql_thread_end()'
  716.       `mysql_thread_safe()'
  717.     C API Embedded Server Function Descriptions
  718.       `mysql_server_init()'
  719.       `mysql_server_end()'
  720.     Common questions and problems when using the C API
  721.       Why Is It that After `mysql_query()' Returns Success, `mysql_store_result()' Sometimes Returns `NULL'?
  722.       What Results Can I Get From a Query?
  723.       How Can I Get the Unique ID for the Last Inserted Row?
  724.       Problems Linking with the C API
  725.     Building Client Programs
  726.     How to Make a Threaded Client
  727.     libmysqld, the Embedded MySQL Server Library
  728.       Overview of the Embedded MySQL Server Library
  729.       Compiling Programs with `libmysqld'
  730.       Restrictions when using the Embedded MySQL Server
  731.       Using Option Files with the Embedded Server
  732.       Things left to do in Embedded Server (TODO)
  733.       A Simple Embedded Server Example
  734.       Licensing the Embedded Server
  735.   MySQL ODBC Support
  736.     How To Install MyODBC
  737.     How to Fill in the Various Fields in the ODBC Administrator Program
  738.     Connect parameters for MyODBC
  739.     How to Report Problems with MyODBC
  740.     Programs Known to Work with MyODBC
  741.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  742.     Reporting Problems with MyODBC
  743.   MySQL Java Connectivity (JDBC)
  744.   MySQL PHP API
  745.     Common Problems with MySQL and PHP
  746.   MySQL Perl API
  747.     `DBI' with `DBD::mysql'
  748.     The `DBI' Interface
  749.     More `DBI'/`DBD' Information
  750.   MySQL C++ API
  751.     Borland C++
  752.   MySQL Python API
  753.   MySQL Tcl API
  754.   MySQL Eiffel Wrapper
  755.   Error Returns
  756.  
  757. Spatial Extensions in MySQL
  758.   Introduction
  759.   The OpenGIS Geometry Model
  760.     The Geometry Class Hierarchy
  761.     Class `Geometry'
  762.     Class `Point'
  763.     Class `Curve'
  764.     Class `LineString'
  765.     Class `Surface'
  766.     Class `Polygon'
  767.     Class `GeometryCollection'
  768.     Class `MultiPoint'
  769.     Class `MultiCurve'
  770.     Class `MultiLineString'
  771.     Class `MultiSurface'
  772.     Class `MultiPolygon'
  773.   Supported Spatial Data Formats
  774.     Well-Known Text (WKT) Representation
  775.     Well-Known Binary (WKB) Representation
  776.       WKB Basic Types
  777.       WKB Building Blocks
  778.       WKB Representation of Geometry Values
  779.       WKB Examples
  780.   Creating a Spatially Enabled MySQL Database
  781.     MySQL Spatial Data Types
  782.     Creating Spatial Values
  783.       Creating Geometry Values Using WKT Functions
  784.       Creating Geometry Values Using WKB Functions
  785.       Creating Geometry Values Using MySQL-Specific Functions
  786.     Creating Spatial Columns
  787.     Populating Spatial Columns
  788.       Examples Of Using WKT Functions
  789.     Fetching Spatial Data
  790.       Fetching Spatial Data Using WKT Representation
  791.       Fetching Spatial Data Using WKB Representation
  792.   Analysing Spatial Information
  793.     Functions To Convert Geometries Between Formats
  794.     Functions To Analyse `Geometry' Properties
  795.       Basic Functions To Analyse `Geometry' Properties
  796.       Functions To Analyse `Point' Properties
  797.       Functions To Analyse `LineString' Properties
  798.       Functions To Analyse `MultiLineString' Properties
  799.       Functions To Analyse `Polygon' Properties
  800.       Functions To Analyse `MultiPolygon' Properties
  801.       Functions To Analyse `GeometryCollection' Properties
  802.     Functions That Create New Geometries From Existing Ones
  803.       Geometry Functions That Produce New Geometries
  804.       Spatial Operators
  805.     Functions For Testing Spatial Relations Between Geometric Objects
  806.     Relations On Geometry Minimal Bounding Rectangles (MBRs)
  807.     Functions That Test Spatial Relationships Between Geometries
  808.   Optimising Spatial Analysis
  809.     Creating Spatial Indexes
  810.     Using a Spatial Index
  811.   MySQL Conformance And Compatibility
  812.     GIS Features That Are Not Yet Implemented
  813.  
  814. Extending MySQL
  815.   MySQL Internals
  816.     MySQL Threads
  817.     MySQL Test Suite
  818.       Running the MySQL Test Suite
  819.       Extending the MySQL Test Suite
  820.       Reporting Bugs in the MySQL Test Suite
  821.   Adding New Functions to MySQL
  822.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  823.     Adding a New User-definable Function
  824.       UDF Calling Sequences for simple functions
  825.       UDF Calling Sequences for aggregate functions
  826.       Argument Processing
  827.       Return Values and Error Handling
  828.       Compiling and Installing User-definable Functions
  829.     Adding a New Native Function
  830.   Adding New Procedures to MySQL
  831.     Procedure Analyse
  832.     Writing a Procedure
  833.  
  834. Problems and Common Errors
  835.   How to Determine What Is Causing Problems
  836.   Common Errors When Using MySQL
  837.     `Access denied' Error
  838.     `MySQL server has gone away' Error
  839.     `Can't connect to [local] MySQL server' Error
  840.     `Client does not support authentication protocol' error
  841.     `Host '...' is blocked' Error
  842.     `Too many connections' Error
  843.     `Some non-transactional changed tables couldn't be rolled back' Error
  844.     `Out of memory' Error
  845.     `Packet too large' Error
  846.     Communication Errors / Aborted Connection
  847.     `The table is full' Error
  848.     `Can't create/write to file' Error
  849.     `Commands out of sync' Error in Client
  850.     `Ignoring user' Error
  851.     `Table 'xxx' doesn't exist' Error
  852.     `Can't initialize character set xxx' error
  853.     File Not Found
  854.   Installation Related Issues
  855.     Problems When Linking with the MySQL Client Library
  856.     How to Run MySQL As a Normal User
  857.     Problems with File Permissions
  858.   Administration Related Issues
  859.     What To Do If MySQL Keeps Crashing
  860.     How to Reset a Forgotten Root Password
  861.     How MySQL Handles a Full Disk
  862.     Where MySQL Stores Temporary Files
  863.     How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'
  864.     Time Zone Problems
  865.   Query Related Issues
  866.     Case-Sensitivity in Searches
  867.     Problems Using `DATE' Columns
  868.     Problems with `NULL' Values
  869.     Problems with `alias'
  870.     Deleting Rows from Related Tables
  871.     Solving Problems with No Matching Rows
  872.     Problems with Floating-Point Comparison
  873.   Optimiser Related Issues
  874.     How to avoid table scan,,,
  875.   Table Definition Related Issues
  876.     Problems with `ALTER TABLE'.
  877.     How To Change the Order of Columns in a Table
  878.     TEMPORARY TABLE problems
  879.  
  880. Contributed Programs
  881.   APIs
  882.   Converters
  883.   Utilities
  884.  
  885. Credits
  886.   Developers at MySQL AB
  887.   Contributors to MySQL
  888.   Supporters to MySQL
  889.  
  890. MySQL Change History
  891.   Changes in release 5.0.0 (Development)
  892.   Changes in release 4.1.x (Alpha)
  893.     Changes in release 4.1.1 (not released yet)
  894.     Changes in release 4.1.0 (03 Apr 2003: Alpha)
  895.   Changes in release 4.0.x (Production)
  896.     Changes in release 4.0.15 (not released yet)
  897.     Changes in release 4.0.14 (to be released soon)
  898.     Changes in release 4.0.13 (16 May 2003)
  899.     Changes in release 4.0.12 (15 Mar 2003: Production)
  900.     Changes in release 4.0.11 (20 Feb 2003)
  901.     Changes in release 4.0.10 (29 Jan 2003)
  902.     Changes in release 4.0.9 (09 Jan 2003)
  903.     Changes in release 4.0.8 (07 Jan 2003)
  904.     Changes in release 4.0.7 (20 Dec 2002)
  905.     Changes in release 4.0.6 (14 Dec 2002: Gamma)
  906.     Changes in release 4.0.5 (13 Nov 2002)
  907.     Changes in release 4.0.4 (29 Sep 2002)
  908.     Changes in release 4.0.3 (26 Aug 2002: Beta)
  909.     Changes in release 4.0.2 (01 Jul 2002)
  910.     Changes in release 4.0.1 (23 Dec 2001)
  911.     Changes in release 4.0.0 (Oct 2001: Alpha)
  912.   Changes in release 3.23.x (Recent; still supported)
  913.     Changes in release 3.23.58 (not released yet)
  914.     Changes in release 3.23.57 (06 Jun 2003)
  915.     Changes in release 3.23.56 (13 Mar 2003)
  916.     Changes in release 3.23.55 (23 Jan 2003)
  917.     Changes in release 3.23.54 (05 Dec 2002)
  918.     Changes in release 3.23.53 (09 Oct 2002)
  919.     Changes in release 3.23.52 (14 Aug 2002)
  920.     Changes in release 3.23.51 (31 May 2002)
  921.     Changes in release 3.23.50 (21 Apr 2002)
  922.     Changes in release 3.23.49
  923.     Changes in release 3.23.48 (07 Feb 2002)
  924.     Changes in release 3.23.47 (27 Dec 2001)
  925.     Changes in release 3.23.46 (29 Nov 2001)
  926.     Changes in release 3.23.45 (22 Nov 2001)
  927.     Changes in release 3.23.44 (31 Oct 2001)
  928.     Changes in release 3.23.43 (04 Oct 2001)
  929.     Changes in release 3.23.42 (08 Sep 2001)
  930.     Changes in release 3.23.41 (11 Aug 2001)
  931.     Changes in release 3.23.40
  932.     Changes in release 3.23.39 (12 Jun 2001)
  933.     Changes in release 3.23.38 (09 May 2001)
  934.     Changes in release 3.23.37 (17 Apr 2001)
  935.     Changes in release 3.23.36 (27 Mar 2001)
  936.     Changes in release 3.23.35 (15 Mar 2001)
  937.     Changes in release 3.23.34a
  938.     Changes in release 3.23.34 (10 Mar 2001)
  939.     Changes in release 3.23.33 (09 Feb 2001)
  940.     Changes in release 3.23.32 (22 Jan 2001: Production)
  941.     Changes in release 3.23.31 (17 Jan 2001)
  942.     Changes in release 3.23.30 (04 Jan 2001)
  943.     Changes in release 3.23.29 (16 Dec 2000)
  944.     Changes in release 3.23.28 (22 Nov 2000: Gamma)
  945.     Changes in release 3.23.27 (24 Oct 2000)
  946.     Changes in release 3.23.26 (18 Oct 2000)
  947.     Changes in release 3.23.25 (29 Sep 2000)
  948.     Changes in release 3.23.24 (08 Sep 2000)
  949.     Changes in release 3.23.23 (01 Sep 2000)
  950.     Changes in release 3.23.22 (31 Jul 2000)
  951.     Changes in release 3.23.21
  952.     Changes in release 3.23.20
  953.     Changes in release 3.23.19
  954.     Changes in release 3.23.18
  955.     Changes in release 3.23.17
  956.     Changes in release 3.23.16
  957.     Changes in release 3.23.15 (May 2000: Beta)
  958.     Changes in release 3.23.14
  959.     Changes in release 3.23.13
  960.     Changes in release 3.23.12 (07 Mar 2000)
  961.     Changes in release 3.23.11
  962.     Changes in release 3.23.10
  963.     Changes in release 3.23.9
  964.     Changes in release 3.23.8 (02 Jan 2000)
  965.     Changes in release 3.23.7 (10 Dec 1999)
  966.     Changes in release 3.23.6
  967.     Changes in release 3.23.5 (20 Oct 1999)
  968.     Changes in release 3.23.4 (28 Sep 1999)
  969.     Changes in release 3.23.3
  970.     Changes in release 3.23.2 (09 Aug 1999)
  971.     Changes in release 3.23.1
  972.     Changes in release 3.23.0 (05 Aug 1999: Alpha)
  973.   Changes in release 3.22.x (Old; discontinued)
  974.     Changes in release 3.22.35
  975.     Changes in release 3.22.34
  976.     Changes in release 3.22.33
  977.     Changes in release 3.22.32 (14 Feb 2000)
  978.     Changes in release 3.22.31
  979.     Changes in release 3.22.30
  980.     Changes in release 3.22.29 (02 Jan 2000)
  981.     Changes in release 3.22.28 (20 Oct 1999)
  982.     Changes in release 3.22.27
  983.     Changes in release 3.22.26 (16 Sep 1999)
  984.     Changes in release 3.22.25
  985.     Changes in release 3.22.24 (05 Jul 1999)
  986.     Changes in release 3.22.23 (08 Jun 1999)
  987.     Changes in release 3.22.22 (30 Apr 1999)
  988.     Changes in release 3.22.21
  989.     Changes in release 3.22.20 (18 Mar 1999)
  990.     Changes in release 3.22.19 (Mar 1999: Production)
  991.     Changes in release 3.22.18
  992.     Changes in release 3.22.17
  993.     Changes in release 3.22.16 (Feb 1999: Gamma)
  994.     Changes in release 3.22.15
  995.     Changes in release 3.22.14
  996.     Changes in release 3.22.13
  997.     Changes in release 3.22.12
  998.     Changes in release 3.22.11
  999.     Changes in release 3.22.10
  1000.     Changes in release 3.22.9
  1001.     Changes in release 3.22.8
  1002.     Changes in release 3.22.7 (Sep 1998: Beta)
  1003.     Changes in release 3.22.6
  1004.     Changes in release 3.22.5
  1005.     Changes in release 3.22.4
  1006.     Changes in release 3.22.3
  1007.     Changes in release 3.22.2
  1008.     Changes in release 3.22.1 (Jun 1998: Alpha)
  1009.     Changes in release 3.22.0
  1010.   Changes in release 3.21.x
  1011.     Changes in release 3.21.33
  1012.     Changes in release 3.21.32
  1013.     Changes in release 3.21.31
  1014.     Changes in release 3.21.30
  1015.     Changes in release 3.21.29
  1016.     Changes in release 3.21.28
  1017.     Changes in release 3.21.27
  1018.     Changes in release 3.21.26
  1019.     Changes in release 3.21.25
  1020.     Changes in release 3.21.24
  1021.     Changes in release 3.21.23
  1022.     Changes in release 3.21.22
  1023.     Changes in release 3.21.21a
  1024.     Changes in release 3.21.21
  1025.     Changes in release 3.21.20
  1026.     Changes in release 3.21.19
  1027.     Changes in release 3.21.18
  1028.     Changes in release 3.21.17
  1029.     Changes in release 3.21.16
  1030.     Changes in release 3.21.15
  1031.     Changes in release 3.21.14b
  1032.     Changes in release 3.21.14a
  1033.     Changes in release 3.21.13
  1034.     Changes in release 3.21.12
  1035.     Changes in release 3.21.11
  1036.     Changes in release 3.21.10
  1037.     Changes in release 3.21.9
  1038.     Changes in release 3.21.8
  1039.     Changes in release 3.21.7
  1040.     Changes in release 3.21.6
  1041.     Changes in release 3.21.5
  1042.     Changes in release 3.21.4
  1043.     Changes in release 3.21.3
  1044.     Changes in release 3.21.2
  1045.     Changes in release 3.21.0
  1046.   Changes in release 3.20.x
  1047.     Changes in release 3.20.18
  1048.     Changes in release 3.20.17
  1049.     Changes in release 3.20.16
  1050.     Changes in release 3.20.15
  1051.     Changes in release 3.20.14
  1052.     Changes in release 3.20.13
  1053.     Changes in release 3.20.11
  1054.     Changes in release 3.20.10
  1055.     Changes in release 3.20.9
  1056.     Changes in release 3.20.8
  1057.     Changes in release 3.20.7
  1058.     Changes in release 3.20.6
  1059.     Changes in release 3.20.3
  1060.     Changes in release 3.20.0
  1061.   Changes in release 3.19.x
  1062.     Changes in release 3.19.5
  1063.     Changes in release 3.19.4
  1064.     Changes in release 3.19.3
  1065.  
  1066. Porting to Other Systems
  1067.   Debugging a MySQL server
  1068.     Compiling MYSQL for Debugging
  1069.     Creating Trace Files
  1070.     Debugging mysqld under gdb
  1071.     Using a Stack Trace
  1072.     Using Log Files to Find Cause of Errors in mysqld
  1073.     Making a Test Case If You Experience Table Corruption
  1074.   Debugging a MySQL client
  1075.   The DBUG Package
  1076.   Locking methods
  1077.   Comments about RTS threads
  1078.   Differences between different thread packages
  1079.  
  1080. Environment Variables
  1081.  
  1082. MySQL Regular Expressions
  1083.  
  1084. GNU General Public License
  1085.  
  1086. GNU Lesser General Public License
  1087.  
  1088. SQL command, type and function index
  1089.  
  1090. Concept Index
  1091.  
  1092.  
  1093. This is the Reference Manual for the `MySQL Database System'.  This
  1094. version refers to the {No value for `mysqlversion'} version of `MySQL
  1095. Server' but it is also applicable for any older version (such as 3.23
  1096. and 4.0-production) as changes are always indicated. There are also
  1097. references for version 5.0 (development).
  1098.  
  1099. General Information
  1100. *******************
  1101.  
  1102. The `MySQL' (R) software delivers a very fast, multi-threaded,
  1103. multi-user, and robust `SQL' (`Structured Query Language') database
  1104. server.  `MySQL Server' is intended for mission-critical, heavy-load
  1105. production systems as well as for embedding into mass-deployed software.
  1106. `MySQL' is a trademark of `MySQL AB'.
  1107.  
  1108. The `MySQL' software is `Dual Licensed'. Users can choose to use the
  1109. `MySQL' software as an `Open Source'/`Free Software' product under the
  1110. terms of the `GNU General Public License'
  1111. (`http://www.gnu.org/licenses/') or can purchase a standard commercial
  1112. license from `MySQL AB'.  *Note Licensing and Support::.
  1113.  
  1114. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1115. information about the `MySQL' software.
  1116.  
  1117. The following list describes some sections of particular interest in
  1118. this manual:
  1119.  
  1120.    * For information about the company behind the `MySQL Database
  1121.      Server', see *Note What is MySQL AB::.
  1122.  
  1123.    * For a discussion about the capabilities of the `MySQL Database
  1124.      Server', see *Note Features::.
  1125.  
  1126.    * For installation instructions, see *Note Installing::.
  1127.  
  1128.    * For tips on porting the `MySQL Database Software' to new
  1129.      architectures or operating systems, see *Note Porting::.
  1130.  
  1131.    * For information about upgrading from a Version 4.0 release, see
  1132.      *Note Upgrading-from-4.0::.
  1133.  
  1134.    * For information about upgrading from a Version 3.23 release, see
  1135.      *Note Upgrading-from-3.23::.
  1136.  
  1137.    * For information about upgrading from a Version 3.22 release, see
  1138.      *Note Upgrading-from-3.22::.
  1139.  
  1140.    * For a tutorial introduction to the `MySQL Database Server', see
  1141.      *Note Tutorial::.
  1142.  
  1143.    * For examples of `SQL' and benchmarking information, see the
  1144.      benchmarking directory (`sql-bench' in the distribution).
  1145.  
  1146.    * For a history of new features and bug fixes, see *Note News::.
  1147.  
  1148.    * For a list of currently known bugs and misfeatures, see *Note
  1149.      Bugs::.
  1150.  
  1151.    * For future plans, see *Note TODO::.
  1152.  
  1153.    * For a list of all the contributors to this project, see *Note
  1154.      Credits::.
  1155.  
  1156. *Important*:
  1157.  
  1158. Reports of errors (often called bugs), as well as questions and
  1159. comments, should be sent to the mailing list at <mysql@lists.mysql.com>.
  1160. *Note Bug reports::.
  1161.  
  1162. The `mysqlbug' script should be used to generate bug reports.
  1163.  
  1164. For source distributions, the `mysqlbug' script can be found in the
  1165. `scripts' directory. For binary distributions, `mysqlbug' can be found
  1166. in the `bin' directory (`/usr/bin' for the `MySQL-server' RPM package).
  1167.  
  1168. If you have found a sensitive security bug in `MySQL Server', you
  1169. should send an e-mail to <security@mysql.com>.
  1170.  
  1171. About This Manual
  1172. =================
  1173.  
  1174. This is the `MySQL' reference manual; it documents `MySQL' up to
  1175. Version {No value for `mysqlversion'}. Functional changes are always
  1176. indicated with reference to the version, so this manual is also suitable
  1177. if you are using an older version of the `MySQL' software (such as 3.23
  1178. or 4.0-production).  There are also references for version 5.0
  1179. (development).
  1180.  
  1181. Being a reference manual, it does not provide general instruction on
  1182. `SQL' or relational database concepts.
  1183.  
  1184. As the `MySQL Database Software' is under constant development, the
  1185. manual is also updated frequently.  The most recent version of this
  1186. manual is available at `http://www.mysql.com/documentation/' in many
  1187. different formats, including HTML, PDF, and Windows HLP versions.
  1188.  
  1189. The primary document is the Texinfo file.  The HTML version is produced
  1190. automatically using a modified version of `texi2html'.  The plain text
  1191. and Info versions are produced with `makeinfo'.  The PostScript version
  1192. is produced using `texi2dvi' and `dvips'.  The PDF version is produced
  1193. with `pdftex'.
  1194.  
  1195. If you have a hard time finding information in the manual, you can try
  1196. our searchable version at `http://www.mysql.com/doc/'.
  1197.  
  1198. If you have any suggestions concerning additions or corrections to this
  1199. manual, please send them to the documentation team at <docs@mysql.com>.
  1200.  
  1201. This manual was initially written by David Axmark and Michael (Monty)
  1202. Widenius. It is currently maintained by Michael (Monty) Widenius, Arjen
  1203. Lentz, and Paul DuBois. For other contributors, see *Note Credits::.
  1204.  
  1205. The copyright (2003) to this manual is owned by the Swedish company
  1206. `MySQL AB'. *Note Copyright::.
  1207.  
  1208. Conventions Used in This Manual
  1209. -------------------------------
  1210.  
  1211. This manual uses certain typographical conventions:
  1212.  
  1213. `constant'
  1214.      Constant-width font is used for command names and options; SQL
  1215.      statements; database, table, and column names; C and Perl code;
  1216.      and environment variables.  Example: "To see how `mysqladmin'
  1217.      works, invoke it with the `--help' option."
  1218.  
  1219. `filename'
  1220.      Constant-width font with surrounding quotes is used for filenames
  1221.      and pathnames.  Example: "The distribution is installed under the
  1222.      `/usr/local/' directory."
  1223.  
  1224. `c'
  1225.      Constant-width font with surrounding quotes is also used to
  1226.      indicate character sequences.  Example: "To specify a wildcard,
  1227.      use the `%' character."
  1228.  
  1229. _italic_
  1230.      Italic font is used for emphasis, _like this_.
  1231.  
  1232. *boldface*
  1233.      Boldface font is used in table headings and to convey *especially
  1234.      strong emphasis*.
  1235.  
  1236. When commands are shown that are meant to be executed by a particular
  1237. program, the program is indicated by a prompt shown before the command.
  1238. For example, `shell>' indicates a command that you execute from your
  1239. login shell, and `mysql>' indicates a command that you execute from the
  1240. `mysql' client program:
  1241.  
  1242.      shell> type a shell command here
  1243.      mysql> type a mysql command here
  1244.  
  1245. Shell commands are shown using Bourne shell syntax.  If you are using a
  1246. `csh'-style shell, you may need to issue commands slightly differently.
  1247. For example, the sequence to set an environment variable and run a
  1248. command looks like this in Bourne shell syntax:
  1249.  
  1250.      shell> VARNAME=value some_command
  1251.  
  1252. For `csh', you would execute the sequence like this:
  1253.  
  1254.      shell> setenv VARNAME value
  1255.      shell> some_command
  1256.  
  1257. Database, table, and column names must often be substituted into
  1258. commands.  To indicate that such substitution is necessary, this manual
  1259. uses `db_name', `tbl_name', and `col_name'.  For example, you might see
  1260. a statement like this:
  1261.  
  1262.      mysql> SELECT col_name FROM db_name.tbl_name;
  1263.  
  1264. This means that if you were to enter a similar statement, you would
  1265. supply your own database, table, and column names, perhaps like this:
  1266.  
  1267.      mysql> SELECT author_name FROM biblio_db.author_list;
  1268.  
  1269. SQL keywords are not case-sensitive and may be written in uppercase or
  1270. lowercase.  This manual uses uppercase.
  1271.  
  1272. In syntax descriptions, square brackets (`[' and `]') are used to
  1273. indicate optional words or clauses.  For example, in the following
  1274. statement, `IF EXISTS' is optional:
  1275.  
  1276.      DROP TABLE [IF EXISTS] tbl_name
  1277.  
  1278. When a syntax element consists of a number of alternatives, the
  1279. alternatives are separated by vertical bars (`|').  When one member
  1280. from a set of choices *may* be chosen, the alternatives are listed
  1281. within square brackets (`[' and `]'):
  1282.  
  1283.      TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  1284.  
  1285. When one member from a set of choices *must* be chosen, the
  1286. alternatives are listed within braces (`{' and `}'):
  1287.  
  1288.      {DESCRIBE | DESC} tbl_name {col_name | wild}
  1289.  
  1290. What Is MySQL?
  1291. ==============
  1292.  
  1293. `MySQL', the most popular `Open Source' SQL database, is developed,
  1294. distributed, and supported by `MySQL AB'.  `MySQL AB' is a commercial
  1295. company, founded by the MySQL developers, that builds its business
  1296. providing services around the `MySQL' database.  *Note What is MySQL
  1297. AB::.
  1298.  
  1299. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1300. information about `MySQL' software and `MySQL AB'.
  1301.  
  1302. `MySQL' is a database management system.
  1303.      A database is a structured collection of data.  It may be anything
  1304.      from a simple shopping list to a picture gallery or the vast
  1305.      amounts of information in a corporate network.  To add, access,
  1306.      and process data stored in a computer database, you need a
  1307.      database management system such as `MySQL' Server.  Since
  1308.      computers are very good at handling large amounts of data,
  1309.      database management systems play a central role in computing, as
  1310.      stand-alone utilities or as parts of other applications.
  1311.  
  1312. MySQL is a relational database management system.
  1313.      A relational database stores data in separate tables rather than
  1314.      putting all the data in one big storeroom.  This adds speed and
  1315.      flexibility.  The `SQL' part of "`MySQL'" stands for "`Structured
  1316.      Query Language'". SQL is the most common standardised language
  1317.      used to access databases and is defined by the ANSI/ISO SQL
  1318.      Standard.(The SQL standard has been evolving since 1986 and
  1319.      several versions exist. In this manual, "`SQL-92'" refers to the
  1320.      standard released in 1992, "`SQL-99'" refers to the standard
  1321.      released in 1999, and "`SQL:2003'" refers to the version of the
  1322.      standard that is expected to be released in mid-2003.We use the
  1323.      term "`the SQL standard'" to mean the current version of the SQL
  1324.      Standard at any time.)
  1325.  
  1326. MySQL software is `Open Source'.
  1327.      `Open Source' means that it is possible for anyone to use and
  1328.      modify the software.  Anybody can download the `MySQL' software
  1329.      from the Internet and use it without paying anything.  If you
  1330.      wish, you may study the source code and change it to suit your
  1331.      needs.  The `MySQL' software uses the `GPL' (`GNU General Public
  1332.      License'), `http://www.gnu.org/licenses/', to define what you may
  1333.      and may not do with the software in different situations.  If you
  1334.      feel uncomfortable with the `GPL' or need to embed `MySQL' code
  1335.      into a commercial application you can buy a commercially licensed
  1336.      version from us.  *Note MySQL licenses::.
  1337.  
  1338. Why use the MySQL Database Server?
  1339.      The `MySQL Database Server' is very fast, reliable, and easy to
  1340.      use.  If that is what you are looking for, you should give it a
  1341.      try.  `MySQL Server' also has a practical set of features
  1342.      developed in close cooperation with our users.  You can find a
  1343.      performance comparison of `MySQL Server' with other database
  1344.      managers on our benchmark page.  *Note MySQL Benchmarks::.
  1345.  
  1346.      `MySQL Server' was originally developed to handle large databases
  1347.      much faster than existing solutions and has been successfully used
  1348.      in highly demanding production environments for several years.
  1349.      Though under constant development, `MySQL Server' today offers a
  1350.      rich and useful set of functions.  Its connectivity, speed, and
  1351.      security make `MySQL Server' highly suited for accessing databases
  1352.      on the Internet.
  1353.  
  1354. The technical features of MySQL Server
  1355.      For advanced technical information, see *Note Reference::.  The
  1356.      `MySQL Database Software' is a client/server system that consists
  1357.      of a multi-threaded `SQL' server that supports different backends,
  1358.      several different client programs and libraries, administrative
  1359.      tools, and a wide range of programming interfaces (APIs).
  1360.  
  1361.      We also provide `MySQL Server' as a multi-threaded library which
  1362.      you can link into your application to get a smaller, faster,
  1363.      easier-to-manage product.
  1364.  
  1365. There is a large amount of contributed MySQL software available.
  1366.      It is very likely that you will find that your favorite
  1367.      application or language already supports the `MySQL Database
  1368.      Server'.
  1369.  
  1370. The official way to pronounce `MySQL' is "My Ess Que Ell" (not "my
  1371. sequel"), but we don't mind if you pronounce it as "my sequel" or in
  1372. some other localised way.
  1373.  
  1374. History of MySQL
  1375. ----------------
  1376.  
  1377. We started out with the intention of using `mSQL' to connect to our
  1378. tables using our own fast low-level (ISAM) routines. However, after some
  1379. testing we came to the conclusion that `mSQL' was not fast enough nor
  1380. flexible enough for our needs.  This resulted in a new SQL interface to
  1381. our database but with almost the same API interface as `mSQL'.  This
  1382. API was chosen to ease porting of third-party code.
  1383.  
  1384. The derivation of the name `MySQL' is not clear.  Our base directory
  1385. and a large number of our libraries and tools have had the prefix "my"
  1386. for well over 10 years.  However, co-founder Monty Widenius's daughter
  1387. (some years younger) is also named My.  Which of the two gave its name
  1388. to `MySQL' is still a mystery, even for us.
  1389.  
  1390. The name of the MySQL Dolphin (our logo) is `Sakila'. `Sakila' was
  1391. chosen by the founders of MySQL AB from a huge list of names suggested
  1392. by users in our "Name the Dolphin" contest. The winning name was
  1393. submitted by Ambrose Twebaze, an open source software developer from
  1394. Swaziland, Africa.  According to Ambrose, the name Sakila has its roots
  1395. in SiSwati, the local language of Swaziland. Sakila is also the name of
  1396. a town in Arusha, Tanzania, near Ambrose's country of origin, Uganda.
  1397.  
  1398. The Main Features of MySQL
  1399. --------------------------
  1400.  
  1401. The following list describes some of the important characteristics of
  1402. the `MySQL Database Software'. *Note MySQL 4.0 In A Nutshell::.
  1403.  
  1404. Internals and Portability
  1405.         * Written in C and C++.  Tested with a broad range of different
  1406.           compilers.
  1407.  
  1408.         * Works on many different platforms.  *Note Which OS::.
  1409.  
  1410.         * Uses GNU Automake, Autoconf, and Libtool for portability.
  1411.  
  1412.         * APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and
  1413.           Tcl.  *Note Clients::.
  1414.  
  1415.         * Fully multi-threaded using kernel threads.  This means it can
  1416.           easily use multiple CPUs if available.
  1417.  
  1418.         * Transactional and non-transactional storage engines.
  1419.  
  1420.         * Very fast B-tree disk tables (MyISAM) with index compression.
  1421.  
  1422.         * Relatively easy to add another storage engine. This is useful
  1423.           if you want to add an SQL interface to an in-house database.
  1424.  
  1425.         * A very fast thread-based memory allocation system.
  1426.  
  1427.         * Very fast joins using an optimised one-sweep multi-join.
  1428.  
  1429.         * In-memory hash tables which are used as temporary tables.
  1430.  
  1431.         * SQL functions are implemented through a highly optimised
  1432.           class library and should be as fast as possible.  Usually
  1433.           there isn't any memory allocation at all after query
  1434.           initialisation.
  1435.  
  1436.         * The `MySQL' code gets tested with Purify (a commercial memory
  1437.           leakage detector) as well as with Valgrind, a `GPL' tool
  1438.           (`http://developer.kde.org/~sewardj/').
  1439.  
  1440.         * Available as client/server or embedded (linked) version.
  1441.  
  1442. Column Types
  1443.         * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8
  1444.           bytes long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT',
  1445.           `BLOB', `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR',
  1446.           `SET', and `ENUM' types.  *Note Column types::.
  1447.  
  1448.         * Fixed-length and variable-length records.
  1449.  
  1450. Commands and Functions
  1451.         * Full operator and function support in the `SELECT' and `WHERE'
  1452.           clauses of queries.  For example:
  1453.  
  1454.                mysql> SELECT CONCAT(first_name, " ", last_name)
  1455.                    -> FROM tbl_name
  1456.                    -> WHERE income/dependents > 10000 AND age > 30;
  1457.  
  1458.         * Full support for SQL `GROUP BY' and `ORDER BY' clauses.
  1459.           Support for group functions (`COUNT()', `COUNT(DISTINCT ...)',
  1460.           `AVG()', `STD()', `SUM()', `MAX()', `MIN()', and
  1461.           `GROUP_CONCAT()').
  1462.  
  1463.         * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with
  1464.           both standard SQL and ODBC syntax.
  1465.  
  1466.         * Support for aliases on tables and columns as required by
  1467.           SQL-92.
  1468.  
  1469.         * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number
  1470.           of rows that were changed (affected).  It is possible to
  1471.           return the number of rows matched instead by setting a flag
  1472.           when connecting to the server.
  1473.  
  1474.         * The `MySQL'-specific `SHOW' command can be used to retrieve
  1475.           information about databases, tables, and indexes.  The
  1476.           `EXPLAIN' command can be used to determine how the optimiser
  1477.           resolves a query.
  1478.  
  1479.         * Function names do not clash with table or column names.  For
  1480.           example, `ABS' is a valid column name.  The only restriction
  1481.           is that for a function call, no spaces are allowed between
  1482.           the function name and the `(' that follows it.  *Note
  1483.           Reserved words::.
  1484.  
  1485.         * You can mix tables from different databases in the same query
  1486.           (as of Version 3.22).
  1487.  
  1488. Security
  1489.         * A privilege and password system that is very flexible and
  1490.           secure, and allows host-based verification.  Passwords are
  1491.           secure because all password traffic is encrypted when you
  1492.           connect to a server.
  1493.  
  1494. Scalability and Limits
  1495.         * Handles large databases.  We use `MySQL Server' with
  1496.           databases that contain 50 million records. We also know of
  1497.           users that use `MySQL Server' with 60,000 tables and about
  1498.           5,000,000,000 rows.
  1499.  
  1500.         * Up to 32 indexes per table are allowed.  Each index may
  1501.           consist of 1 to 16 columns or parts of columns.  The maximum
  1502.           index width is 500 bytes (this may be changed when compiling
  1503.           `MySQL Server').  An index may use a prefix of a `CHAR' or
  1504.           `VARCHAR' field.
  1505.  
  1506. Connectivity
  1507.         * Clients may connect to the `MySQL' server using TCP/IP
  1508.           Sockets, Unix Sockets (Unix), or Named Pipes (NT).
  1509.  
  1510.         * ODBC (Open-DataBase-Connectivity) support for Win32 (with
  1511.           source).  All ODBC 2.5 functions are supported, as are many
  1512.           others.  For example, you can use MS Access to connect to
  1513.           your `MySQL' server.  *Note ODBC::.
  1514.  
  1515. Localisation
  1516.         * The server can provide error messages to clients in many
  1517.           languages.  *Note Languages::.
  1518.  
  1519.         * Full support for several different character sets, including
  1520.           ISO-8859-1 (Latin1), german, big5, ujis, and more.  For
  1521.           example, the Scandinavian characters `a^', `a"' and `o"' are
  1522.           allowed in table and column names.
  1523.  
  1524.         * All data is saved in the chosen character set.  All
  1525.           comparisons for normal string columns are case-insensitive.
  1526.  
  1527.         * Sorting is done according to the chosen character set (the
  1528.           Swedish way by default).  It is possible to change this when
  1529.           the `MySQL' server is started.  To see an example of very
  1530.           advanced sorting, look at the Czech sorting code.  `MySQL
  1531.           Server' supports many different character sets that can be
  1532.           specified at compile and runtime.
  1533.  
  1534. Clients and Tools
  1535.         * Includes `myisamchk', a very fast utility for table checking,
  1536.           optimisation, and repair.  All of the functionality of
  1537.           `myisamchk' is also available through the SQL interface.
  1538.           *Note MySQL Database Administration::.
  1539.  
  1540.         * All `MySQL' programs can be invoked with the `--help' or `-?'
  1541.           options to obtain online assistance.
  1542.  
  1543. How Stable Is MySQL?
  1544. --------------------
  1545.  
  1546. This section addresses the questions "_How stable is MySQL Server?_"
  1547. and "_Can I depend on MySQL Server in this project?_" We will try to
  1548. clarify these issues and answer some important questions that concern
  1549. many potential users. The information in this section is based on data
  1550. gathered from the mailing list, which is very active in identifying
  1551. problems as well as reporting types of use.
  1552.  
  1553. Original code stems back from the early '80s, providing a stable code
  1554. base, and the ISAM table format remains backward-compatible.  At TcX,
  1555. the predecessor of `MySQL AB', `MySQL' code has worked in projects
  1556. since mid-1996, without any problems.  When the `MySQL Database
  1557. Software' was released to a wider public, our new users quickly found
  1558. some pieces of "untested code". Each new release since then has had
  1559. fewer portability problems (even though each new release has also had
  1560. many new features).
  1561.  
  1562. Each release of the `MySQL Server' has been usable. Problems have
  1563. occurred only when users try code from the "gray zones."  Naturally,
  1564. new users don't know what the gray zones are; this section therefore
  1565. attempts to document those areas that are currently known.  The
  1566. descriptions mostly deal with Version 3.23 and 4.0 of `MySQL Server'.
  1567. All known and reported bugs are fixed in the latest version, with the
  1568. exception of those listed in the bugs section, which are things that
  1569. are design-related.  *Note Bugs::.
  1570.  
  1571. The `MySQL Server' design is multi-layered with independent modules.
  1572. Some of the newer modules are listed here with an indication of how
  1573. well-tested each of them is:
  1574.  
  1575. *Replication - Gamma*
  1576.      Large server clusters using replication are in production use, with
  1577.      good results. Work on enhanced replication features is continuing
  1578.      in `MySQL' 4.x.
  1579.  
  1580. *`InnoDB' tables - Stable (in 3.23 from 3.23.49)*
  1581.      The `InnoDB' transactional storage engine has been declared stable
  1582.      in the `MySQL' 3.23 tree, starting from version 3.23.49.  `InnoDB'
  1583.      is being used in large, heavy-load production systems.
  1584.  
  1585. *`BDB' tables - Gamma*
  1586.      The `Berkeley DB' code is very stable, but we are still improving
  1587.      the `BDB' transactional storage engine interface in `MySQL
  1588.      Server', so it will take some time before this is as well tested
  1589.      as the other table types.
  1590.  
  1591. *`FULLTEXT' - Beta*
  1592.      Full-text search works but is not yet widely used.  Important
  1593.      enhancements have been implemented in `MySQL' 4.0.
  1594.  
  1595. *`MyODBC 3.51' (uses ODBC SDK 3.51) - Stable*
  1596.      In wide production use. Some issues brought up appear to be
  1597.      application-related and independent of the ODBC driver or
  1598.      underlying database server.
  1599.  
  1600. *Automatic recovery of `MyISAM' tables - Gamma*
  1601.      This status applies only to the new code in the `MyISAM' storage
  1602.      engine that checks if the table was closed properly on open and
  1603.      executes an automatic check/repair of the table if it wasn't.
  1604.  
  1605. *Bulk-insert - Alpha*
  1606.      New feature in `MyISAM' tables in `MySQL' 4.0 for faster insert of
  1607.      many rows.
  1608.  
  1609. *Locking - Gamma*
  1610.      This is very system-dependent.  On some systems there are big
  1611.      problems using standard OS locking (`fcntl()').  In these cases,
  1612.      you should run `mysqld' with the `--skip-external-locking' flag.
  1613.      Problems are known to occur on some Linux systems, and on SunOS
  1614.      when using NFS-mounted filesystems.
  1615.  
  1616. `MySQL AB' provides high-quality support for paying customers, and the
  1617. `MySQL' mailing list usually provides answers to common questions. Bugs
  1618. are usually fixed right away with a patch; for serious bugs, there is
  1619. almost always a new release.
  1620.  
  1621. How Big Can MySQL Tables Be?
  1622. ----------------------------
  1623.  
  1624. `MySQL' Version 3.22 had a 4 GB (4 gigabyte) limit on table size. With
  1625. the `MyISAM' table type in `MySQL' Version 3.23, the maximum table size
  1626. was pushed up to 8 million terabytes (2 ^ 63 bytes).
  1627.  
  1628. Note, however, that operating systems have their own file-size limits.
  1629. Here are some examples:
  1630.  
  1631. *Operating System*     *File-Size Limit*
  1632. Linux-Intel 32 bit     2 GB, 4GB or more, depends on Linux
  1633.                        version
  1634. Linux-Alpha            8 TB (?)
  1635. Solaris 2.5.1          2 GB (possible 4GB with patch)
  1636. Solaris 2.6            4 GB (can be changed with flag)
  1637. Solaris 2.7 Intel      4 GB
  1638. Solaris 2.7            512 GB
  1639. UltraSPARC             
  1640.  
  1641. On Linux 2.2 you can get tables larger than 2 GB in size by using the
  1642. LFS patch for the ext2 filesystem.  On Linux 2.4 patches also exist for
  1643. ReiserFS to get support for big files.
  1644.  
  1645. In effect, then, the table size for `MySQL' databases is normally
  1646. limited by the operating system.
  1647.  
  1648. By default, `MySQL' tables have a maximum size of about 4 GB.  You can
  1649. check the maximum table size for a table with the `SHOW TABLE STATUS'
  1650. command or with the `myisamchk -dv table_name'.  *Note SHOW::.
  1651.  
  1652. If you need a table that will be larger than 4 GB in size (and your
  1653. operating system supports this), set the `AVG_ROW_LENGTH' and `MAX_ROWS'
  1654. parameters accordingly when you create your table.  *Note CREATE
  1655. TABLE::.  You can also set these parameters later, with `ALTER TABLE'.
  1656. *Note ALTER TABLE::.
  1657.  
  1658. If your big table is a read-only table, you could use `myisampack' to
  1659. merge and compress many tables into one.  `myisampack' usually
  1660. compresses a table by at least 50%, so you can have, in effect, much
  1661. bigger tables.  *Note `myisampack': myisampack.
  1662.  
  1663. You can get around the operating system file limit for `MyISAM' data
  1664. files using the `RAID' option. *Note CREATE TABLE::.
  1665.  
  1666. Another solution can be the included `MERGE' library, which allows you
  1667. to handle a collection of identical tables as one.  *Note `MERGE'
  1668. tables: MERGE.
  1669.  
  1670. Year 2000 Compliance
  1671. --------------------
  1672.  
  1673. The `MySQL Server' itself has no problems with Year 2000 (Y2K)
  1674. compliance:
  1675.  
  1676.    * `MySQL Server' uses Unix time functions and has no problems with
  1677.      dates until `2069'. All 2-digit years are considered to be in the
  1678.      range `1970' to `2069', which means that if you store `01' in a
  1679.      `YEAR' column, `MySQL Server' treats it as `2001'.
  1680.  
  1681.    * All `MySQL' date functions are stored in one file, `sql/time.cc',
  1682.      and are coded very carefully to be year 2000-safe.
  1683.  
  1684.    * In `MySQL' Version 3.22 and later, the `YEAR' column type can
  1685.      store years `0' and `1901' to `2155' in one byte and display them
  1686.      using two or four digits.
  1687.  
  1688. You may run into problems with applications that use `MySQL Server' in
  1689. a way that is not Y2K-safe.  For example, many old applications store
  1690. or manipulate years using 2-digit values (which are ambiguous) rather
  1691. than 4-digit values.  This problem may be compounded by applications
  1692. that use values such as `00' or `99' as "missing" value indicators.
  1693.  
  1694. Unfortunately, these problems may be difficult to fix because different
  1695. applications may be written by different programmers, each of whom may
  1696. use a different set of conventions and date-handling functions.
  1697.  
  1698. Here is a simple demonstration illustrating that `MySQL Server' doesn't
  1699. have any problems with dates until the year 2030:
  1700.  
  1701.      mysql> DROP TABLE IF EXISTS y2k;
  1702.      Query OK, 0 rows affected (0.01 sec)
  1703.      
  1704.      mysql> CREATE TABLE y2k (date DATE,
  1705.          ->                   date_time DATETIME,
  1706.          ->                   time_stamp TIMESTAMP);
  1707.      Query OK, 0 rows affected (0.00 sec)
  1708.      
  1709.      mysql> INSERT INTO y2k VALUES
  1710.          -> ("1998-12-31","1998-12-31 23:59:59",19981231235959),
  1711.          -> ("1999-01-01","1999-01-01 00:00:00",19990101000000),
  1712.          -> ("1999-09-09","1999-09-09 23:59:59",19990909235959),
  1713.          -> ("2000-01-01","2000-01-01 00:00:00",20000101000000),
  1714.          -> ("2000-02-28","2000-02-28 00:00:00",20000228000000),
  1715.          -> ("2000-02-29","2000-02-29 00:00:00",20000229000000),
  1716.          -> ("2000-03-01","2000-03-01 00:00:00",20000301000000),
  1717.          -> ("2000-12-31","2000-12-31 23:59:59",20001231235959),
  1718.          -> ("2001-01-01","2001-01-01 00:00:00",20010101000000),
  1719.          -> ("2004-12-31","2004-12-31 23:59:59",20041231235959),
  1720.          -> ("2005-01-01","2005-01-01 00:00:00",20050101000000),
  1721.          -> ("2030-01-01","2030-01-01 00:00:00",20300101000000),
  1722.          -> ("2050-01-01","2050-01-01 00:00:00",20500101000000);
  1723.      Query OK, 13 rows affected (0.01 sec)
  1724.      Records: 13  Duplicates: 0  Warnings: 0
  1725.      
  1726.      mysql> SELECT * FROM y2k;
  1727.      +------------+---------------------+----------------+
  1728.      | date       | date_time           | time_stamp     |
  1729.      +------------+---------------------+----------------+
  1730.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1731.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1732.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1733.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1734.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1735.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1736.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1737.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1738.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1739.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1740.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  1741.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  1742.      | 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
  1743.      +------------+---------------------+----------------+
  1744.      13 rows in set (0.00 sec)
  1745.  
  1746. This example shows that the `DATE' and `DATETIME' data types will not
  1747. give any problems with future dates (they handle dates until the year
  1748. 9999).
  1749.  
  1750. The `TIMESTAMP' data type, which is used to store the current time,
  1751. supports values that range from `19700101000000' to `20300101000000' on
  1752. 32-bit machines (signed value).  On 64-bit machines, `TIMESTAMP'
  1753. handles values up to `2106' (unsigned value).
  1754.  
  1755. Even though `MySQL Server' is Y2K-compliant, it is your responsibility
  1756. to provide unambiguous input.  See *Note Y2K issues:: for `MySQL
  1757. Server''s rules for dealing with ambiguous date input data (data
  1758. containing 2-digit year values).
  1759.  
  1760. What Is MySQL AB?
  1761. =================
  1762.  
  1763. `MySQL AB' is the company of the `MySQL' founders and main developers.
  1764. `MySQL AB' was originally established in Sweden by David Axmark, Allan
  1765. Larsson, and Michael `Monty' Widenius.
  1766.  
  1767. The developers of the `MySQL' server are all employed by the company.
  1768. We are a virtual organisation with people in a dozen countries around
  1769. the world. We communicate extensively over the Net every day with one
  1770. another and with our users, supporters, and partners.
  1771.  
  1772. We are dedicated to developing the `MySQL' software and spreading our
  1773. database to new users. `MySQL AB' owns the copyright to the `MySQL'
  1774. source code, the `MySQL' logo and trademark, and this manual. *Note
  1775. What-is::.
  1776.  
  1777. The `MySQL' core values show our dedication to `MySQL' and `Open
  1778. Source'.
  1779.  
  1780. We want the `MySQL Database Software' to be:
  1781.    * The best and the most widely used database in the world.
  1782.  
  1783.    * Available to, and affordable by all.
  1784.  
  1785.    * Easy to use.
  1786.  
  1787.    * Continuously improving while remaining fast and safe.
  1788.  
  1789.    * Fun to use and improve.
  1790.  
  1791.    * Free from bugs.
  1792.  
  1793. `MySQL AB' and the people at `MySQL AB':
  1794.    * Promote `Open Source' philosophy and support the `Open Source'
  1795.      community.
  1796.  
  1797.    * Aim to be good citizens.
  1798.  
  1799.    * Prefer partners that share our values and mind-set.
  1800.  
  1801.    * Answer e-mail and provide support.
  1802.  
  1803.    * Are a virtual company, networking with others.
  1804.  
  1805.    * Work against software patents.
  1806.  
  1807. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1808. information about `MySQL' and `MySQL AB'.
  1809.  
  1810. The Business Model and Services of MySQL AB
  1811. -------------------------------------------
  1812.  
  1813. One of the most common questions we encounter is: "_How can you make a
  1814. living from something you give away for free?_" This is how.
  1815.  
  1816. `MySQL AB' makes money on support, services, commercial licenses, and
  1817. royalties. We use these revenues to fund product development and to
  1818. expand the `MySQL' business.
  1819.  
  1820. The company has been profitable since its inception. In October 2001,
  1821. we accepted venture financing from leading Scandinavian investors and a
  1822. handful of business angels. This investment is used to solidify our
  1823. business model and build a basis for sustainable growth.
  1824.  
  1825. Support
  1826. .......
  1827.  
  1828. `MySQL AB' is run and owned by the founders and main developers of the
  1829. `MySQL' database. The developers are committed to giving support to
  1830. customers and other users in order to stay in touch with their needs
  1831. and problems. All our support is given by qualified developers. Really
  1832. tricky questions are answered by Michael `Monty' Widenius, principal
  1833. author of the `MySQL Server'.  *Note Support::.
  1834.  
  1835. For more information and ordering support at various levels, see
  1836. `http://www.mysql.com/support/' or contact our sales staff at
  1837. <sales@mysql.com>.
  1838.  
  1839. Training and Certification
  1840. ..........................
  1841.  
  1842. `MySQL AB' delivers `MySQL' and related training worldwide.  We offer
  1843. both open courses and in-house courses tailored to the specific needs
  1844. of your company. `MySQL Training' is also available through our
  1845. partners, the `Authorised MySQL Training Centers'.
  1846.  
  1847. Our training material uses the same example databases used in our
  1848. documentation and our sample applications, and is always updated to
  1849. reflect the latest `MySQL' version. Our trainers are backed by the
  1850. development team to guarantee the quality of the training and the
  1851. continuous development of the course material. This also ensures that
  1852. no questions raised during the courses remain unanswered.
  1853.  
  1854. Attending our training courses will enable you to achieve your `MySQL'
  1855. application goals. You will also:
  1856.    * Save time.
  1857.  
  1858.    * Improve the performance of your application(s).
  1859.  
  1860.    * Reduce or eliminate the need for additional hardware, decreasing
  1861.      cost.
  1862.  
  1863.    * Enhance security.
  1864.  
  1865.    * Increase customers' and co-workers' satisfaction.
  1866.  
  1867.    * Prepare yourself for `MySQL Certification'.
  1868.  
  1869. If you are interested in our training as a potential participant or as
  1870. a training partner, please visit the training section at
  1871. `http://www.mysql.com/training/' or contact us at: <training@mysql.com>.
  1872.  
  1873. For details about the `MySQL Certification Program', please see
  1874. `http://www.mysql.com/certification/'.
  1875.  
  1876. Consulting
  1877. ..........
  1878.  
  1879. `MySQL AB' and its `Authorised Partners' offer consulting services to
  1880. users of `MySQL Server' and to those who embed `MySQL Server' in their
  1881. own software, all over the world.
  1882.  
  1883. Our consultants can help you design and tune your databases, construct
  1884. efficient queries, tune your platform for optimal performance, resolve
  1885. migration issues, set up replication, build robust transactional
  1886. applications, and more.  We also help customers embed `MySQL Server' in
  1887. their products and applications for large-scale deployment.
  1888.  
  1889. Our consultants work in close collaboration with our development team,
  1890. which ensures the technical quality of our professional services.
  1891. Consulting assignments range from 2-day power-start sessions to
  1892. projects that span weeks and months. Our expertise not only covers
  1893. `MySQL Server'--it also extends into programming and scripting
  1894. languages such as PHP, Perl, and more.
  1895.  
  1896. If you are interested in our consulting services or want to become a
  1897. consulting partner, please visit the consulting section of our web site
  1898. at `http://www.mysql.com/consulting/' or contact our consulting staff
  1899. at <consulting@mysql.com>.
  1900.  
  1901. Commercial Licenses
  1902. ...................
  1903.  
  1904. The `MySQL' database is released under the `GNU General Public License'
  1905. (`GPL').  This means that the `MySQL' software can be used free of
  1906. charge under the `GPL'. If you do not want to be bound by the `GPL'
  1907. terms (such as the requirement that your application must also be `GPL',
  1908. you may purchase a commercial license for the same product from `MySQL
  1909. AB'; see `http://www.mysql.com/products/pricing.html'.  Since `MySQL
  1910. AB' owns the copyright to the `MySQL' source code, we are able to
  1911. employ `Dual Licensing', which means that the same product is available
  1912. under `GPL' and under a commercial license. This does not in any way
  1913. affect the `Open Source' commitment of `MySQL AB'. For details about
  1914. when a commercial license is required, please see *Note MySQL
  1915. licenses::.
  1916.  
  1917. We also sell commercial licenses of third-party `Open Source GPL'
  1918. software that adds value to `MySQL Server'. A good example is the
  1919. `InnoDB' transactional storage engine that offers `ACID' support,
  1920. row-level locking, crash recovery, multi-versioning, foreign key
  1921. support, and more. *Note InnoDB::.
  1922.  
  1923. Partnering
  1924. ..........
  1925.  
  1926. `MySQL AB' has a worldwide partner programme that covers training
  1927. courses, consulting and support, publications, plus reselling and
  1928. distributing `MySQL' and related products. `MySQL AB Partners' get
  1929. visibility on the `http://www.mysql.com/' web site and the right to use
  1930. special versions of the `MySQL' trademarks to identify their products
  1931. and promote their business.
  1932.  
  1933. If you are interested in becoming a `MySQL AB Partner', please e-mail
  1934. <partner@mysql.com>.
  1935.  
  1936. The word `MySQL' and the `MySQL' dolphin logo are trademarks of `MySQL
  1937. AB'. *Note MySQL AB Logos and Trademarks::.  These trademarks represent
  1938. a significant value that the `MySQL' founders have built over the years.
  1939.  
  1940. Advertising
  1941. ...........
  1942.  
  1943. The `MySQL' web site (`http://www.mysql.com/') is popular among
  1944. developers and users. In October 2001, we served 10 million page views.
  1945. Our visitors represent a group that makes purchase decisions and
  1946. recommendations for both software and hardware. Twelve percent of our
  1947. visitors authorise purchase decisions, and only nine percent are not
  1948. involved in purchase decisions at all. More than 65% have made one or
  1949. more online business purchases within the last half-year, and 70% plan
  1950. to make one in the next few months.
  1951.  
  1952. Contact Information
  1953. -------------------
  1954.  
  1955. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1956. information about `MySQL' and `MySQL AB'.
  1957.  
  1958. For press services and inquiries not covered in our News releases
  1959. (`http://www.mysql.com/news/'), please send an e-mail to
  1960. <press@mysql.com>.
  1961.  
  1962. If you have a valid support contract with `MySQL AB', you will get
  1963. timely, precise answers to your technical questions about the `MySQL'
  1964. software. For more information, see *Note Support::.  On our web site,
  1965. see `http://www.mysql.com/support/', or send an e-mail to
  1966. <sales@mysql.com>.
  1967.  
  1968. For information about `MySQL' training, please visit the training
  1969. section at `http://www.mysql.com/training/'. If you have restricted
  1970. access to the Internet, please contact the `MySQL AB' training staff
  1971. via e-mail at <training@mysql.com>.  *Note Business Services Training::.
  1972.  
  1973. For information on the `MySQL Certification Program', please see
  1974. `http://www.mysql.com/certification/'.  *Note Business Services
  1975. Training::.
  1976.  
  1977. If you're interested in consulting, please visit the consulting section
  1978. of our web site at `http://www.mysql.com/consulting/'. If you have
  1979. restricted access to the Internet, please contact the `MySQL AB'
  1980. consulting staff via e-mail at <consulting@mysql.com>.  *Note Business
  1981. Services Consulting::.
  1982.  
  1983. Commercial licenses may be purchased online at
  1984. `https://order.mysql.com/'. There you will also find information on how
  1985. to fax your purchase order to `MySQL AB'. More information about
  1986. licensing can be found at `http://www.mysql.com/products/pricing.html'.
  1987. If you have questions regarding licensing or you want a quote for a
  1988. high-volume license deal, please fill in the contact form on our web
  1989. site (`http://www.mysql.com/') or send an e-mail message to
  1990. <licensing@mysql.com> (for licensing questions) or to <sales@mysql.com>
  1991. (for sales inquiries).  *Note MySQL licenses::.
  1992.  
  1993. If you represent a business that is interested in partnering with
  1994. `MySQL AB', please send an e-mail to <partner@mysql.com>.  *Note
  1995. Business Services Partnering::.
  1996.  
  1997. For more information on the `MySQL' trademark policy, refer to
  1998. `http://www.mysql.com/company/trademark.html' or send an e-mail to
  1999. <trademark@mysql.com>.  *Note MySQL AB Logos and Trademarks::.
  2000.  
  2001. If you are interested in any of the `MySQL AB' jobs listed in our jobs
  2002. section (`http://www.mysql.com/company/jobs/'), please send an e-mail
  2003. to <jobs@mysql.com>.  Please do not send your CV as an attachment, but
  2004. rather as plain text at the end of your e-mail message.
  2005.  
  2006. For general discussion among our many users, please direct your
  2007. attention to the appropriate mailing list.  *Note Questions::.
  2008.  
  2009. Reports of errors (often called bugs), as well as questions and
  2010. comments, should be sent to the mailing list at
  2011. <mysql@lists.mysql.com>. If you have found a sensitive security bug in
  2012. the `MySQL Server', please send an e-mail to <security@mysql.com>.
  2013. *Note Bug reports::.
  2014.  
  2015. If you have benchmark results that we can publish, please contact us
  2016. via e-mail at <benchmarks@mysql.com>.
  2017.  
  2018. If you have suggestions concerning additions or corrections to this
  2019. manual, please send them to the manual team via e-mail at
  2020. <docs@mysql.com>.
  2021.  
  2022. For questions or comments about the workings or content of the `MySQL'
  2023. web site (`http://www.mysql.com/'), please send an e-mail to
  2024. <webmaster@mysql.com>.
  2025.  
  2026. `MySQL AB' has a privacy policy, which can be read at
  2027. `http://www.mysql.com/company/privacy.html'.  For any queries regarding
  2028. this policy, please send an e-mail to <privacy@mysql.com>.
  2029.  
  2030. For all other inquires, please send an e-mail to <info@mysql.com>.
  2031.  
  2032. MySQL Support and Licensing
  2033. ===========================
  2034.  
  2035. This section describes `MySQL' support and licensing arrangements.
  2036.  
  2037. Support Offered by MySQL AB
  2038. ---------------------------
  2039.  
  2040. Technical support from `MySQL AB' means individualised answers to your
  2041. unique problems direct from the software engineers who code the `MySQL'
  2042. database engine.
  2043.  
  2044. We try to take a broad and inclusive view of technical support. Almost
  2045. any problem involving `MySQL' software is important to us if it's
  2046. important to you.  Typically customers seek help on how to get
  2047. different commands and utilities to work, remove performance
  2048. bottlenecks, restore crashed systems, understand operating system or
  2049. networking impacts on `MySQL', set up best practices for backup and
  2050. recovery, utilise APIs, and so on.  Our support covers only the `MySQL'
  2051. server and our own utilities, not third-party products that access the
  2052. `MySQL' server, though we try to help with these where we can.
  2053.  
  2054. Detailed information about our various support options is given at
  2055. `http://www.mysql.com/support/', where support contracts can also be
  2056. ordered online. If you have restricted access to the Internet, please
  2057. contact our sales staff via e-mail at <sales@mysql.com>.
  2058.  
  2059. Technical support is like life insurance. You can live happily without
  2060. it for years, but when your hour arrives it becomes critically
  2061. important, yet it's too late to buy it.  If you use `MySQL Server' for
  2062. important applications and encounter sudden difficulties, it may be too
  2063. time consuming to figure out all the answers yourself. You may need
  2064. immediate access to the most experienced `MySQL' troubleshooters
  2065. available, those employed by `MySQL AB'.
  2066.  
  2067. Copyrights and Licenses Used by MySQL
  2068. -------------------------------------
  2069.  
  2070. `MySQL AB' owns the copyright to the `MySQL' source code, the `MySQL'
  2071. logos and trademarks and this manual.  *Note What is MySQL AB::.
  2072. Several different licenses are relevant to the `MySQL' distribution:
  2073.  
  2074.   1. All the `MySQL'-specific source in the server, the `mysqlclient'
  2075.      library and the client, as well as the `GNU' `readline' library is
  2076.      covered by the `GNU General Public License'.  *Note GPL license::.
  2077.      The text of this license can be found as the file `COPYING' in the
  2078.      distribution.
  2079.  
  2080.   2. The `GNU' `getopt' library is covered by the `GNU Lesser General
  2081.      Public License'.  *Note LGPL license::.
  2082.  
  2083.   3. Some parts of the source (the `regexp' library) are covered by a
  2084.      Berkeley-style copyright.
  2085.  
  2086.   4. Older versions of `MySQL' (3.22 and earlier) are subject to a
  2087.      stricter license (`http://www.mysql.com/products/mypl.html').  See
  2088.      the documentation of the specific version for information.
  2089.  
  2090.   5. The `MySQL' reference manual is currently *not* distributed under
  2091.      a `GPL'-style license. Use of the manual is subject to the
  2092.      following terms:
  2093.         * Conversion to other formats is allowed, but the actual content
  2094.           may not be altered or edited in any way.
  2095.  
  2096.         * You may create a printed copy for your own personal use.
  2097.  
  2098.         * For all other uses, such as selling printed copies or using
  2099.           (parts of) the manual in another publication, prior written
  2100.           agreement from `MySQL AB' is required.
  2101.      Please send an e-mail to <docs@mysql.com> for more information or
  2102.      if you are interested in doing a translation.
  2103.  
  2104. For information about how the `MySQL' licenses work in practice, please
  2105. refer to *Note MySQL licenses::.  Also see *Note MySQL AB Logos and
  2106. Trademarks::.
  2107.  
  2108. MySQL Licenses
  2109. --------------
  2110.  
  2111. The `MySQL' software is released under the `GNU General Public License'
  2112. (`GPL'), which is probably the best known `Open Source' license.  The
  2113. formal terms of the `GPL' license can be found at
  2114. `http://www.gnu.org/licenses/'.  See also
  2115. `http://www.gnu.org/licenses/gpl-faq.html' and
  2116. `http://www.gnu.org/philosophy/enforcing-gpl.html'.
  2117.  
  2118. Since the `MySQL' software is released under the `GPL', it may often be
  2119. used for free, but for certain uses you may want or need to buy
  2120. commercial licenses from `MySQL AB' at `https://order.mysql.com/'.  See
  2121. `http://www.mysql.com/products/licensing.html' for more information.
  2122.  
  2123. Older versions of `MySQL' (3.22 and earlier) are subject to a stricter
  2124. license (`http://www.mysql.com/products/mypl.html').  See the
  2125. documentation of the specific version for information.
  2126.  
  2127. Please note that the use of the `MySQL' software under commercial
  2128. license, `GPL', or the old `MySQL' license does not automatically give
  2129. you the right to use `MySQL AB' trademarks.  *Note MySQL AB Logos and
  2130. Trademarks::.
  2131.  
  2132. Using the MySQL Software Under a Commercial License
  2133. ...................................................
  2134.  
  2135. The `GPL' license is contagious in the sense that when a program is
  2136. linked to a `GPL' program all the source code for all the parts of the
  2137. resulting product must also be released under the `GPL'.  If you do not
  2138. follow this `GPL' requirement, you break the license terms and forfeit
  2139. your right to use the `GPL' program altogether.  You also risk damages.
  2140.  
  2141. You need a commercial license:
  2142.  
  2143.    * When you link a program with any `GPL' code from the `MySQL'
  2144.      software and don't want the resulting product to be licensed under
  2145.      `GPL', perhaps because you want to build a commercial product or
  2146.      keep the added non-`GPL' code closed source for other reasons.
  2147.      When purchasing commercial licenses, you are not using the `MySQL'
  2148.      software under `GPL' even though it's the same code.
  2149.  
  2150.    * When you distribute a non-`GPL' application that *only* works with
  2151.      the `MySQL' software and ship it with the `MySQL' software. This
  2152.      type of solution is considered to be linking even if it's done
  2153.      over a network.
  2154.  
  2155.    * When you distribute copies of the `MySQL' software without
  2156.      providing the source code as required under the `GPL' license.
  2157.  
  2158.    * When you want to support the further development of the `MySQL'
  2159.      database even if you don't formally need a commercial license.
  2160.      Purchasing support directly from `MySQL AB' is another good way of
  2161.      contributing to the development of the `MySQL' software, with
  2162.      immediate advantages for you.  *Note Support::.
  2163.  
  2164. If you require a license, you will need one for each installation of the
  2165. `MySQL' software. This covers any number of CPUs on a machine, and there
  2166. is no artificial limit on the number of clients that connect to the
  2167. server in any way.
  2168.  
  2169. For commercial licenses, please visit our website at
  2170. `http://www.mysql.com/products/licensing.html'.  For support contracts,
  2171. see `http://www.mysql.com/support/'.  If you have special needs or you
  2172. have restricted access to the Internet, please contact our sales staff
  2173. via e-mail at <sales@mysql.com>.
  2174.  
  2175. Using the MySQL Software for Free Under GPL
  2176. ...........................................
  2177.  
  2178. You can use the `MySQL' software for free under the `GPL' if you adhere
  2179. to the conditions of the `GPL'.  For additional details, including
  2180. answers to common questions about the `GPL', see the generic FAQ from
  2181. the Free Software Foundation at
  2182. `http://www.gnu.org/licenses/gpl-faq.html'.  Common uses of the `GPL'
  2183. include:
  2184.  
  2185.    * When you distribute both your own application and the `MySQL'
  2186.      source code under the `GPL' with your product.
  2187.  
  2188.    * When you distribute the `MySQL' source code bundled with other
  2189.      programs that are not linked to or dependent on the `MySQL' system
  2190.      for their functionality even if you sell the distribution
  2191.      commercially.  This is called mere aggregation in the `GPL'
  2192.      license.
  2193.  
  2194.    * When you are not distributing *any* part of the `MySQL' system,
  2195.      you can use it for free.
  2196.  
  2197.    * When you are an Internet Service Provider (ISP), offering web
  2198.      hosting with `MySQL' servers for your customers.  We encourage
  2199.      people to use ISPs that have MySQL support, as this will give them
  2200.      the confidence that their ISP will, in fact, have the resources to
  2201.      solve any problems they may experience with the `MySQL'
  2202.      installation. Even if an ISP does not have a commercial license
  2203.      for `MySQL Server', their customers should at least be given read
  2204.      access to the source of the `MySQL' installation so that the
  2205.      customers can verify that it is correctly patched.
  2206.  
  2207.    * When you use the `MySQL' database software in conjunction with a
  2208.      web server, you do not need a commercial license (so long as it is
  2209.      not a product you distribute). This is true even if you run a
  2210.      commercial web server that uses `MySQL Server', because you are not
  2211.      distributing any part of the `MySQL' system. However, in this case
  2212.      we would like you to purchase `MySQL' support because the `MySQL'
  2213.      software is helping your enterprise.
  2214.  
  2215. If your use of `MySQL' database software does not require a commercial
  2216. license, we encourage you to purchase support from `MySQL AB' anyway.
  2217. This way you contribute toward `MySQL' development and also gain
  2218. immediate advantages for yourself. *Note Support::.
  2219.  
  2220. If you use the `MySQL' database software in a commercial context such
  2221. that you profit by its use, we ask that you further the development of
  2222. the `MySQL' software by purchasing some level of support.  We feel that
  2223. if the `MySQL' database helps your business, it is reasonable to ask
  2224. that you help `MySQL AB'.  (Otherwise, if you ask us support questions,
  2225. you are not only using for free something into which we've put a lot a
  2226. work, you're asking us to provide free support, too.)
  2227.  
  2228. MySQL AB Logos and Trademarks
  2229. -----------------------------
  2230.  
  2231. Many users of the `MySQL' database want to display the `MySQL AB'
  2232. dolphin logo on their web sites, books, or boxed products. We welcome
  2233. and encourage this, although it should be noted that the word `MySQL'
  2234. and the `MySQL' dolphin logo are trademarks of `MySQL AB' and may only
  2235. be used as stated in our trademark policy at
  2236. `http://www.mysql.com/company/trademark.html'.
  2237.  
  2238. The Original MySQL Logo
  2239. .......................
  2240.  
  2241. The `MySQL' dolphin logo was designed by the Finnish advertising agency
  2242. Priority in 2001.  The dolphin was chosen as a suitable symbol for the
  2243. `MySQL' database since it is a smart, fast, and lean animal,
  2244. effortlessly navigating oceans of data. We also happen to like dolphins.
  2245.  
  2246. The original `MySQL' logo may only be used by representatives of `MySQL
  2247. AB' and by those having a written agreement allowing them to do so.
  2248.  
  2249. MySQL Logos that may be Used Without Written Permission
  2250. .......................................................
  2251.  
  2252. We have designed a set of special _Conditional Use_ logos that may be
  2253. downloaded from our web site at `http://www.mysql.com/press/logos.html'
  2254. and used on third-party web sites without written permission from
  2255. `MySQL AB'.  The use of these logos is not entirely unrestricted but,
  2256. as the name implies, subject to our trademark policy that is also
  2257. available on our web site. You should read through the trademark policy
  2258. if you plan to use them. The requirements are basically as follows:
  2259.  
  2260.    * Use the logo you need as displayed on the `http://www.mysql.com/'
  2261.      site. You may scale it to fit your needs, but may not change
  2262.      colours or design, or alter the graphics in any way.
  2263.  
  2264.    * Make it evident that you, and not `MySQL AB', are the creator and
  2265.      owner of the site that displays the `MySQL' trademark.
  2266.  
  2267.    * Don't use the trademark in a way that is detrimental to `MySQL AB'
  2268.      or to the value of `MySQL AB' trademarks. We reserve the right to
  2269.      revoke the right to use the `MySQL AB' trademark.
  2270.  
  2271.    * If you use the trademark on a web site, make it clickable, leading
  2272.      directly to `http://www.mysql.com/'.
  2273.  
  2274.    * If you are use the `MySQL' database under `GPL' in an application,
  2275.      your application must be `Open Source' and must be able to connect
  2276.      to a `MySQL' server.
  2277.  
  2278. Contact us via e-mail at <trademark@mysql.com> to inquire about special
  2279. arrangements to fit your needs.
  2280.  
  2281. When do you need a Written Permission to use MySQL Logos?
  2282. .........................................................
  2283.  
  2284. You need written permission from `MySQL AB' before using `MySQL' logos
  2285. in the following cases:
  2286.  
  2287.    * When displaying any `MySQL AB' logo anywhere except on your web
  2288.      site.
  2289.  
  2290.    * When displaying any `MySQL AB' logo except the _Conditional Use_
  2291.      logos mentioned previously on web sites or elsewhere.
  2292.  
  2293. Due to legal and commercial reasons we monitor the use of MySQL
  2294. trademarks on products, books, and other items. We usually require a
  2295. fee for displaying `MySQL AB' logos on commercial products, since we
  2296. think it is reasonable that some of the revenue is returned to fund
  2297. further development of the `MySQL' database.
  2298.  
  2299. MySQL AB Partnership Logos
  2300. ..........................
  2301.  
  2302. `MySQL' partnership logos may be used only by companies and persons
  2303. having a written partnership agreement with `MySQL AB'. Partnerships
  2304. include certification as a `MySQL' trainer or consultant.  For more
  2305. information, please see *Note Partnering: Business Services Partnering.
  2306.  
  2307. Using the word `MySQL' in Printed Text or Presentations
  2308. .......................................................
  2309.  
  2310. `MySQL AB' welcomes references to the `MySQL' database, but it should
  2311. be noted that the word `MySQL' is a trademark of `MySQL AB'.  Because
  2312. of this, you must append the trademark symbol (`TM') to the first or
  2313. most prominent use of the word `MySQL' in a text and, where
  2314. appropriate, state that `MySQL' is a trademark of `MySQL AB'. For more
  2315. information, please refer to our trademark policy at
  2316. `http://www.mysql.com/company/trademark.html'.
  2317.  
  2318. Using the word `MySQL' in Company and Product Names
  2319. ...................................................
  2320.  
  2321. Use of the word `MySQL' in product or company names or in Internet
  2322. domain names is not allowed without written permission from `MySQL AB'.
  2323.  
  2324. MySQL 4.0 In A Nutshell
  2325. =======================
  2326.  
  2327. Long promised by `MySQL AB' and long awaited by our users, MySQL Server
  2328. 4.0 is now available in production version.
  2329.  
  2330. MySQL 4.0 is available for download from `http://www.mysql.com/' and
  2331. from our mirrors. MySQL 4.0 has been tested by a large number of users
  2332. and is in production use at many large sites.
  2333.  
  2334. The major new features of MySQL Server 4.0 are geared toward our
  2335. existing business and community users, enhancing the MySQL database
  2336. software as the solution for mission-critical, heavy-load database
  2337. systems.  Other new features target the users of embedded databases.
  2338.  
  2339. MySQL Version 4.0.12 was declared stable for production use in March
  2340. 2003. This means that, in future, only bug fixes will be done for the
  2341. 4.0 release series and only critical bug fixes will be done for the
  2342. older 3.23 series.  *Note Upgrading-from-3.23::.
  2343.  
  2344. New features to the `MySQL' software are being added to MySQL 4.1 which
  2345. is now also available (alpha version).  *Note MySQL 4.1 In A Nutshell::.
  2346.  
  2347. Features Available From MySQL 4.0
  2348. ---------------------------------
  2349.  
  2350. Speed enhancements
  2351.         * MySQL 4.0 has a query cache that can give a huge speed boost
  2352.           to applications with repetitive queries. *Note Query Cache::.
  2353.  
  2354.         * Version 4.0 further increases the speed of MySQL Server in a
  2355.           number of areas, such as bulk `INSERT's, searching on packed
  2356.           indexes, creation of `FULLTEXT' indexes, and
  2357.           `COUNT(DISTINCT)'.
  2358.  
  2359. Embedded MySQL Server introduced
  2360.         * The new Embedded Server library (instead of client/server)
  2361.           can easily be used in standalone and embedded applications.
  2362.           *Note Nutshell Embedded MySQL::.
  2363.  
  2364. InnoDB storage engine as standard
  2365.         * The `InnoDB' storage engine is now offered as a standard
  2366.           feature of the `MySQL' server. This means full support for
  2367.           ACID _transactions_, _foreign keys_ with cascading
  2368.           UPDATE/DELETE, and _row-level locking_ are now standard
  2369.           features.  *Note InnoDB::.
  2370.  
  2371. New functionality
  2372.         * The enhanced `FULLTEXT' search properties of MySQL Server 4.0
  2373.           enables `FULLTEXT' indexing of large text masses with both
  2374.           binary and natural-language searching logic. You can
  2375.           customise minimal word length and define your own stop word
  2376.           lists in any human language, enabling a new set of
  2377.           applications to be built on MySQL Server.  *Note Fulltext
  2378.           Search::.
  2379.  
  2380. Standards compliance, portability, and migration
  2381.         * Features to simplify migration from other database systems to
  2382.           MySQL Server include `TRUNCATE TABLE' (as in Oracle) and
  2383.           `IDENTITY' as a synonym for automatically incremented keys
  2384.           (as in Sybase).
  2385.  
  2386.         * Many users will also be happy to learn that MySQL Server now
  2387.           supports the `UNION' statement, a long-awaited standard SQL
  2388.           feature.
  2389.  
  2390.         * MySQL can now run natively on the Novell NetWare 6.0 platform.
  2391.           *Note Novell NetWare::.
  2392.  
  2393. Internationalisation
  2394.         * Our German, Austrian, and Swiss users will note that `MySQL'
  2395.           now supports a new character set, `latin1_de', which ensures
  2396.           that the _German sorting order_ sorts words with umlauts in
  2397.           the same order as do German telephone books.
  2398.  
  2399. Usability enhancements
  2400.      In the process of building features for new users, we have not
  2401.      forgotten requests from our community of loyal users.
  2402.  
  2403.         * Most `mysqld' parameters (startup options) can now be set
  2404.           without taking down the servers. This is a convenient feature
  2405.           for Database Administrators (DBAs).  *Note SET OPTION::.
  2406.  
  2407.         * Multi-table `DELETE' and `UPDATE' statements have been added..
  2408.  
  2409.         * Support has been added for `symbolic linking' to `MyISAM' at
  2410.           the table level (and not just the database level as before)
  2411.           and for enabling symlink handling by default on Windows.
  2412.  
  2413.         * `SQL_CALC_FOUND_ROWS' and `FOUND_ROWS()' are new functions
  2414.           that make it possible to find out the number of rows a
  2415.           `SELECT' query that includes a `LIMIT' clause would have
  2416.           returned without that clause.
  2417.  
  2418. The news section of this manual includes a more in-depth list of
  2419. features.  *Note News-4.0.x::.
  2420.  
  2421. Embedded MySQL Server
  2422. ---------------------
  2423.  
  2424. `libmysqld' makes MySQL Server suitable for a vastly expanded realm of
  2425. applications. Using the embedded MySQL server library, one can embed
  2426. MySQL Server into various applications and electronics devices, where
  2427. the end user has no knowledge of there actually being an underlying
  2428. database. Embedded MySQL Server is ideal for use behind the scenes in
  2429. Internet appliances, public kiosks, turnkey hardware/software
  2430. combination units, high performance Internet servers, self-contained
  2431. databases distributed on CD-ROM, and so on.
  2432.  
  2433. Many users of `libmysqld' will benefit from the MySQL _Dual Licensing_.
  2434. For those not wishing to be bound by the `GPL', the software is also
  2435. made available under a commercial license.  The embedded MySQL library
  2436. uses the same interface as the normal client library, so it is
  2437. convenient and easy to use. *Note libmysqld::.
  2438.  
  2439. MySQL 4.1 In A Nutshell
  2440. =======================
  2441.  
  2442. MySQL Server 4.0 laid the foundation for new features such as _nested
  2443. subqueries_ and _Unicode_ (implemented in version 4.1) and for the work
  2444. on SQL-99 _stored procedures_ being done for version 5.0. These
  2445. features come at the top of the wish list of many of our customers.
  2446.  
  2447. With these additions, critics of the MySQL Database Server have to be
  2448. more imaginative than ever in pointing out deficiencies in the MySQL
  2449. Database Management System. Already well-known for its stability,
  2450. speed, and ease of use, MySQL Server will be able to fulfill the
  2451. requirement checklists of very demanding buyers.
  2452.  
  2453. Features Available From MySQL 4.1
  2454. ---------------------------------
  2455.  
  2456. The features listed in this section are implemented in MySQL 4.1. Few
  2457. other features are still planned for MySQL 4.1. *Note TODO MySQL 4.1::.
  2458.  
  2459. Most new features being coded, such as _stored procedures_, will be
  2460. available in MySQL 5.0. *Note TODO MySQL 5.0::.
  2461.  
  2462. Support for subqueries and derived tables
  2463.         * Subqueries are now supported. Here is an example:
  2464.                SELECT * FROM t1 WHERE t1.a=(SELECT t2.b FROM t2);
  2465.                
  2466.                SELECT * FROM t1 WHERE (1,2,3) IN (SELECT a,b,c FROM t2);
  2467.  
  2468.         * Derived tables (unnamed views) are now supported. Basically,
  2469.           a derived table is a subquery in the `FROM' clause of a
  2470.           `SELECT' statement. Here is an example:
  2471.                SELECT t1.a FROM t1, (SELECT * FROM t2) t3 WHERE t1.a=t3.a;
  2472.  
  2473. Speed enhancements
  2474.         * Faster binary protocol with prepared statements and parameter
  2475.           binding.  *Note C API Prepared statements::.
  2476.  
  2477.         * `BTREE' indexing is now supported for `HEAP' tables,
  2478.           significantly improving response time for non-exact searches.
  2479.  
  2480. New functionality
  2481.         * `CREATE TABLE table LIKE table' allows you to create a new
  2482.           table with the exact structure of an existing table, using a
  2483.           single command.
  2484.  
  2485.         * Support for OpenGIS (Geographical data).  *Note GIS spatial
  2486.           extensions in MySQL::.
  2487.  
  2488. Standards compliance, portability, and migration
  2489.         * The new client-server protocol adds the ability to pass
  2490.           multiple warnings to the client, rather than only a single
  2491.           result. This makes jobs such as bulk loading of data much
  2492.           easier to track.  `SHOW WARNINGS' shows warnings for the last
  2493.           command.  *Note SHOW WARNINGS::.
  2494.  
  2495. Internationalisation
  2496.         * To support our ever expanding user base using local languages
  2497.           in applications, the MySQL software now offers extensive
  2498.           Unicode (UTF8) support.
  2499.  
  2500.         * Character sets can now be defined per column, table, and
  2501.           database.  This allows for a high degree of flexibility in
  2502.           application design, particularly for multi-language web sites.
  2503.  
  2504.         * The documentation for this improved character set support is
  2505.           being developed and will be added to the manual soon.
  2506.  
  2507. Usability enhancements
  2508.         * In response to popular demand, we have added a server-based
  2509.           `HELP command' that can be used in the `mysql' command line
  2510.           client (and other clients) to get help for SQL commands.  The
  2511.           advantage of having this information on the server side is
  2512.           that the information is always applicable for that particular
  2513.           server version.
  2514.  
  2515.         * In the new client-server protocol, multi-line queries can now
  2516.           be enabled.  This allows you to issue several queries in a
  2517.           single call and then read all the results in one go.  *Note C
  2518.           API multiple queries::.
  2519.  
  2520.         * A new `INSERT ... ON DUPLICATE KEY UPDATE ...' syntax has been
  2521.           implemented. This allows you to `UPDATE' an existing row if
  2522.           the `INSERT' would have caused a duplicate in a `PRIMARY' or
  2523.           `UNIQUE' key (index).  *Note INSERT::.
  2524.  
  2525.         * We have designed a new aggregate function `GROUP_CONCAT()',
  2526.           adding the extremely useful capability of concatenating
  2527.           columns from grouped rows into a single result string.  *Note
  2528.           Group by functions::.
  2529.  
  2530.         * The new client/server protocol supports multiple result sets.
  2531.  
  2532. The news section in this manual includes a more in-depth list of
  2533. features.  *Note News-4.1.x::.
  2534.  
  2535. Stepwise Rollout
  2536. ----------------
  2537.  
  2538. New features are being added to MySQL 4.1, which is already available
  2539. for download (alpha version). *Note Nutshell Ready for Immediate Use::.
  2540.  
  2541. The set of features that are being added to version 4.1 is mostly
  2542. fixed. Additional development is already ongoing for version 5.0.
  2543. MySQL 4.1 will go through the steps of _Alpha_ (during which time new
  2544. features might still be added/changed), _Beta_ (when we have feature
  2545. freeze and only bug corrections will be done), and _Gamma_ (indicating
  2546. that a production release is just weeks ahead).  At the end of this
  2547. process, MySQL 4.1 will become the new production release.
  2548.  
  2549. Ready for Immediate Development Use
  2550. -----------------------------------
  2551.  
  2552. MySQL 4.1 is currently in the alpha stage, and binaries are available
  2553. for download at `http://www.mysql.com/downloads/mysql-4.1.html'.  All
  2554. binary releases pass our extensive test suite without any errors on the
  2555. platforms on which we test.  *Note News-4.1.x::.
  2556.  
  2557. MySQL 5.0, The Next Development Release
  2558. ---------------------------------------
  2559.  
  2560. New development for MySQL is focused on the 5.0 release, featuring
  2561. Stored Procedures and other new features.  *Note TODO MySQL 5.0::.
  2562.  
  2563. For those wishing to take a look at the bleeding edge of MySQL
  2564. development, we have already made our BitKeeper repository for MySQL
  2565. version 5.0 publically available.  *Note Installing source tree::.
  2566.  
  2567. MySQL Information Sources
  2568. =========================
  2569.  
  2570. MySQL Mailing Lists
  2571. -------------------
  2572.  
  2573. This section introduces you to the MySQL mailing lists and gives some
  2574. guidelines as to how the lists should be used. When you subscribe to a
  2575. mailing list, you will receive, as e-mail messages, all postings to the
  2576. list. You will also be able to send your own questions and answers to
  2577. the list.
  2578.  
  2579. The MySQL Mailing Lists
  2580. .......................
  2581.  
  2582. To subscribe to the main MySQL mailing list, send a message to the
  2583. electronic mail address <mysql-subscribe@lists.mysql.com>.
  2584.  
  2585. To unsubscribe from the main MySQL mailing list, send a message to the
  2586. electronic mail address <mysql-unsubscribe@lists.mysql.com>.
  2587.  
  2588. When subscribing and unsubscribing, only the address to which you send
  2589. your message is significant. The subject line and the body of the
  2590. message are ignored.
  2591.  
  2592. If your reply address is not valid, you can specify your address
  2593. explicitly by adding a hyphen to the subscribe or unsubscribe command
  2594. word, followed by your address with the `@' character in your address
  2595. replaced by a `='.  For example, to subscribe `your_name@host.domain',
  2596. send a message to
  2597. `mysql-subscribe-your_name=host.domain@lists.mysql.com'.
  2598.  
  2599. Mail to <mysql-subscribe@lists.mysql.com> or
  2600. <mysql-unsubscribe@lists.mysql.com> is handled automatically by the
  2601. ezmlm mailing list processor.  Information about ezmlm is available at
  2602. the ezmlm web site (`http://www.ezmlm.org/').
  2603.  
  2604. To post a message to the list itself, send your message to
  2605. `mysql@lists.mysql.com'.  Please *do not* send mail about subscribing
  2606. or unsubscribing to <mysql@lists.mysql.com> because all mail sent to
  2607. that address is distributed automatically to thousands of other users.
  2608.  
  2609. Your local site may have many subscribers to <mysql@lists.mysql.com>.
  2610. If so, it may have a local mailing list, so that messages sent from
  2611. `lists.mysql.com' to your site are propagated to the local list.  In
  2612. such cases, please contact your system administrator to be added to or
  2613. dropped from the local MySQL list.
  2614.  
  2615. If you wish to have traffic for a mailing list go to a separate mailbox
  2616. in your mail program, set up a filter based on the message headers.
  2617. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  2618. list messages.
  2619.  
  2620. The MySQL mailing lists are as follows:
  2621.  
  2622. `<announce-subscribe@lists.mysql.com> announce'
  2623.      This list is for announcements of new versions of MySQL and related
  2624.      programs.  This is a low-volume list to which all MySQL users
  2625.      should subscribe.
  2626.  
  2627. `<mysql-subscribe@lists.mysql.com> mysql'
  2628.      This is the main list for general MySQL discussion.  Please note
  2629.      that some topics are better discussed on the more-specialised
  2630.      lists.  If you post to the wrong list, you may not get an answer.
  2631.  
  2632. `<mysql-digest-subscribe@lists.mysql.com> mysql-digest'
  2633.      This is the `mysql' list in digest form.  Subscribing to this list
  2634.      means you will get all list messages, sent as one large mail
  2635.      message once a day.
  2636.  
  2637. `<bugs-subscribe@lists.mysql.com> bugs'
  2638.      This list will be of interest to you if you want to stay informed
  2639.      about issues reported since the last release of `MySQL' or if you
  2640.      want to be actively involved in the process of bug hunting and
  2641.      fixing.  *Note Bug reports::.
  2642.  
  2643. `<bugs-digest-subscribe@lists.mysql.com> bugs-digest'
  2644.      This is the `bugs' list in digest form.
  2645.  
  2646. `<internals-subscribe@lists.mysql.com> internals'
  2647.      This list is for people who work on the MySQL code.  This is also
  2648.      the forum for discussions on MySQL development and post patches.
  2649.  
  2650. `<internals-digest-subscribe@lists.mysql.com> internals-digest'
  2651.      This is the `internals' list in digest form.
  2652.  
  2653. `<mysqldoc-subscribe@lists.mysql.com> mysqldoc'
  2654.      This list is for people who work on the MySQL documentation:
  2655.      people from MySQL AB, translators, and other community members.
  2656.  
  2657. `<mysqldoc-digest-subscribe@lists.mysql.com> mysqldoc-digest'
  2658.      This is the `mysqldoc' list in digest form.
  2659.  
  2660. `<benchmarks-subscribe@lists.mysql.com> benchmarks'
  2661.      This list is for anyone interested in performance issues.
  2662.      Discussions concentrate on database performance (not limited to
  2663.      MySQL) but also include broader categories such as performance of
  2664.      the kernel, file system, disk system, and so on.
  2665.  
  2666. `<benchmarks-digest-subscribe@lists.mysql.com> benchmarks-digest'
  2667.      This is the `benchmarks' list in digest form.
  2668.  
  2669. `<packagers-subscribe@lists.mysql.com> packagers'
  2670.      This list is for discussions on packaging and distributing MySQL.
  2671.      This is the forum used by distribution maintainers to exchange
  2672.      ideas on packaging MySQL and on ensuring that MySQL looks and
  2673.      feels as similar as possible on all supported platforms and
  2674.      operating systems.
  2675.  
  2676. `<packagers-digest-subscribe@lists.mysql.com> packagers-digest'
  2677.      This is the `packagers' list in digest form.
  2678.  
  2679. `<java-subscribe@lists.mysql.com> java'
  2680.      This list is for discussions about the MySQL server and Java.It is
  2681.      mostly used to discuss JDBC drivers, including MySQL Connector/J.
  2682.  
  2683. `<java-digest-subscribe@lists.mysql.com> java-digest'
  2684.      This is the `java' list in digest form.
  2685.  
  2686. `<win32-subscribe@lists.mysql.com> win32'
  2687.      This list is for all things concerning the MySQL software on
  2688.      Microsoft operating systems, such as Windows 9x/Me/NT/2000/XP.
  2689.  
  2690. `<win32-digest-subscribe@lists.mysql.com> win32-digest'
  2691.      This is the `win32' list in digest form.
  2692.  
  2693. `<myodbc-subscribe@lists.mysql.com> myodbc'
  2694.      This list is for all things concerning connecting to the MySQL
  2695.      server with ODBC.
  2696.  
  2697. `<myodbc-digest-subscribe@lists.mysql.com> myodbc-digest'
  2698.      This is the `myodbc' list in digest form.
  2699.  
  2700. `<mysqlcc-subscribe@lists.mysql.com> mysqlcc'
  2701.      This list is for all things concerning the `MySQL Control Center'
  2702.      graphical client.
  2703.  
  2704. `<mysqlcc-digest-subscribe@lists.mysql.com> mysqlcc-digest'
  2705.      This is the `mysqlcc' list in digest form.
  2706.  
  2707. `<plusplus-subscribe@lists.mysql.com> plusplus'
  2708.      This list is for all things concerning programming with the C++
  2709.      API to MySQL.
  2710.  
  2711. `<plusplus-digest-subscribe@lists.mysql.com> plusplus-digest'
  2712.      This is the `plusplus' list in digest form.
  2713.  
  2714. `<msql-mysql-modules-subscribe@lists.mysql.com> msql-mysql-modules'
  2715.      This list is for all things concerning the Perl support for MySQL
  2716.      with `msql-mysql-modules', which is now named `DBD-mysql'.
  2717.  
  2718. `<msql-mysql-modules-digest-subscribe@lists.mysql.com> msql-mysql-modules-digest'
  2719.      This is the `msql-mysql-modules' list in digest form.
  2720.  
  2721. You subscribe or unsubscribe to all lists using the same method
  2722. described at the beginning of this section.  For example, to subscribe
  2723. to or unsubscribe from the `myodbc' list, send a message to
  2724. <myodbc-subscribe@lists.mysql.com> or
  2725. <myodbc-unsubscribe@lists.mysql.com>.
  2726.  
  2727. If you're unable to get an answer to your question(s) from a `MySQL'
  2728. mailing list, one option is to pay for support from MySQL AB. This will
  2729. put you in direct contact with MySQL developers. *Note Support::.
  2730.  
  2731. The following table shows some MySQL mailing lists in languages other
  2732. than English.  These lists are not operated by MySQL AB, so we can't
  2733. guarantee their quality.
  2734.  
  2735. `<mysql-france-subscribe@yahoogroups.com> A French mailing list'
  2736.  
  2737. `<list@tinc.net> A Korean mailing list'
  2738.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2739.  
  2740. `<mysql-de-request@lists.4t2.com> A German mailing list'
  2741.      E-mail `subscribe mysql-de your@e-mail.address' to this list.  You
  2742.      can find information about this mailing list at
  2743.      `http://www.4t2.com/mysql/'.
  2744.  
  2745. `<mysql-br-request@listas.linkway.com.br> A Portuguese mailing list'
  2746.      E-mail `subscribe mysql-br your@e-mail.address' to this list.
  2747.  
  2748. `<mysql-alta@elistas.net> A Spanish mailing list'
  2749.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2750.  
  2751. Asking Questions or Reporting Bugs
  2752. ..................................
  2753.  
  2754. Before posting a bug report or question, please do the following:
  2755.  
  2756.    * Start by searching the MySQL online manual at:
  2757.      `http://www.mysql.com/doc/'
  2758.      We try to keep the manual up to date by updating it frequently with
  2759.      solutions to newly found problems. The change history appendix
  2760.      (`http://www.mysql.com/doc/en/News.html') can be particularly
  2761.      useful since it is quite possible that a newer version already
  2762.      contains a solution to your problem.
  2763.  
  2764.    * Search in the bugs database at `http://bugs.mysql.com/' to see
  2765.      whether the bug has already been reported/solved.
  2766.  
  2767.    * Search the MySQL mailing list archives:
  2768.      `http://lists.mysql.com/'
  2769.    * You can also use `http://www.mysql.com/search/' to search all the
  2770.      web pages (including the manual) that are located at
  2771.      `http://www.mysql.com/'.
  2772.  
  2773. If you can't find an answer in the manual or the archives, check with
  2774. your local MySQL expert.  If you still can't find an answer to your
  2775. question, please follow the guidelines on sending mail to
  2776. <mysql@lists.mysql.com>, outlined in the next section, before
  2777. contacting us.
  2778.  
  2779. How to Report Bugs or Problems
  2780. ..............................
  2781.  
  2782. Our bugs database is public, and can be browsed and searched by anyone
  2783. at `http://bugs.mysql.com/'.  If you log into the system, you will also
  2784. be able to enter new reports.
  2785.  
  2786. Writing a good bug report takes patience, but doing it right the first
  2787. time saves time both for us and for yourself.  A good bug report,
  2788. containing a full test case for the bug, makes it very likely that we
  2789. will fix the bug in the next release.  This section will help you write
  2790. your report correctly so that you don't waste your time doing things
  2791. that may not help us much or at all.
  2792.  
  2793. We encourage everyone to use the `mysqlbug' script to generate a bug
  2794. report (or a report about any problem).  `mysqlbug' can be found in the
  2795. `scripts' directory (source distribution) and in the `bin' directory
  2796. under your MySQL installation directory (binary distribution).  If you
  2797. are unable to use `mysqlbug' (for instance, if you are running on
  2798. Windows), it is still vital that you include all the necessary
  2799. information noted in this section (most importantly a description of
  2800. the operating system and the MySQL version).
  2801.  
  2802. The `mysqlbug' script helps you generate a report by determining much
  2803. of the following information automatically, but if something important
  2804. is missing, please include it with your message.  Please read this
  2805. section carefully and make sure that all the information described here
  2806. is included in your report.
  2807.  
  2808. Preferably, you should test the problem using the latest production or
  2809. development version of MySQL Server before posting.  Anyone should be
  2810. able to repeat the bug by just using '`mysql test < script'' on the
  2811. included test case or run the shell or Perl script that is included in
  2812. the bug report.
  2813.  
  2814. All bugs posted in the bugs database or on the <bugs@lists.mysql.com>
  2815. list will be corrected or documented in the next MySQL release. If only
  2816. minor code changes are needed to correct a problem, we will also post a
  2817. patch that fixes the problem.
  2818.  
  2819. The normal place to report bugs is `http://bugs.mysql.com/'.
  2820.  
  2821. If you have found a sensitive security bug in MySQL, please send an
  2822. e-mail to <security@mysql.com>.
  2823.  
  2824. If you have a repeatable bug report, please report this into the bugs
  2825. database at `http://bugs.mysql.com/'.  Note that even in this case it's
  2826. good to run the `mysqlbug' script first to find information about your
  2827. system.  Any bug that we are able to repeat has a high chance of being
  2828. fixed in the next MySQL release.
  2829.  
  2830. To report other problem, you can use <mysql@lists.mysql.com>.
  2831.  
  2832. Remember that it is possible for us to respond to a message containing
  2833. too much information, but not to one containing too little.  People
  2834. often omit facts because they think they know the cause of a problem
  2835. and assume that some details don't matter.  A good principle is: if you
  2836. are in doubt about stating something, state it.  It is a thousand times
  2837. faster and less troublesome to write a couple of lines more in your
  2838. report than to be forced to ask again and wait for the answer because
  2839. you didn't include enough information the first time.
  2840.  
  2841. The most common errors made in bug reports are (a) not including the
  2842. version number of the MySQL distribution used and (b) not fully
  2843. describing the platform on which the MySQL server is installed
  2844. (including the platform type and version number).  This is highly
  2845. relevant information, and in 99 cases out of 100 the bug report is
  2846. useless without it.  Very often we get questions like, "Why doesn't
  2847. this work for me?" Then we find that the feature requested wasn't
  2848. implemented in that MySQL version, or that a bug described in a report
  2849. has already been fixed in newer MySQL versions.  Sometimes the error is
  2850. platform-dependent; in such cases, it is next to impossible for us to
  2851. fix anything without knowing the operating system and the version
  2852. number of the platform.
  2853.  
  2854. Remember also to provide information about your compiler, if it is
  2855. related to the problem.  Often people find bugs in compilers and think
  2856. the problem is MySQL-related.  Most compilers are under development all
  2857. the time and become better version by version.  To determine whether
  2858. your problem depends on your compiler, we need to know what compiler
  2859. you use.  Note that every compiling problem should be regarded as a bug
  2860. and reported accordingly.
  2861.  
  2862. It is most helpful when a good description of the problem is included
  2863. in the bug report.  That is, give a good example of all the things you
  2864. did that led to the problem and describe, in exact detail, the problem
  2865. itself.  The best reports are those that include a full example showing
  2866. how to reproduce the bug or problem.  *Note Reproduceable test case::.
  2867.  
  2868. If a program produces an error message, it is very important to include
  2869. the message in your report.  If we try to search for something from the
  2870. archives using programs, it is better that the error message reported
  2871. exactly matches the one that the program produces.  (Even the case
  2872. should be observed.)  You should never try to remember what the error
  2873. message was; instead, copy and paste the entire message into your
  2874. report.
  2875.  
  2876. If you have a problem with MyODBC, please try to generate a MyODBC
  2877. trace file and send it with your report.  *Note MyODBC bug report::.
  2878.  
  2879. Please remember that many of the people who will read your report will
  2880. do so using an 80-column display.  When generating reports or examples
  2881. using the `mysql' command-line tool, you should therefore use the
  2882. `--vertical' option (or the `\G' statement terminator) for output that
  2883. would exceed the available width for such a display (for example, with
  2884. the `EXPLAIN SELECT' statement; see the example later in this section).
  2885.  
  2886. Please include the following information in your report:
  2887.  
  2888.    * The version number of the MySQL distribution you are using (for
  2889.      example, MySQL Version 4.0.12). You can find out which version you
  2890.      are running by executing `mysqladmin version'.  `mysqladmin' can be
  2891.      found in the `bin' directory under your MySQL installation
  2892.      directory.
  2893.  
  2894.    * The manufacturer and model of the machine on which you experience
  2895.      the problem.
  2896.  
  2897.    * The operating system name and version.  For most operating
  2898.      systems, you can get this information by executing the Unix
  2899.      command `uname -a'.  If you work with Windows, you can usually get
  2900.      the name and version number by double-clicking your "My Computer"
  2901.      icon and pulling down the "Help/About Windows" menu.
  2902.  
  2903.    * Sometimes the amount of memory (real and virtual) is relevant. If
  2904.      in doubt, include these values.
  2905.  
  2906.    * If you are using a source distribution of the MySQL software, the
  2907.      name and version number of the compiler used is needed.  If you
  2908.      have a binary distribution, the distribution name is needed.
  2909.  
  2910.    * If the problem occurs during compilation, include the exact error
  2911.      message(s) and also a few lines of context around the offending
  2912.      code in the file where the error occurrs.
  2913.  
  2914.    * If `mysqld' died, you should also report the query that crashed
  2915.      `mysqld'.  You can usually find this out by running `mysqld' with
  2916.      logging enabled.  *Note Using log files::.
  2917.  
  2918.    * If a database table is related to the problem, include the output
  2919.      from `mysqldump --no-data db_name tbl_name1 tbl_name2 ...'.  This
  2920.      is very easy to do and is a powerful way to get information about
  2921.      any table in a database.  The information will help us create a
  2922.      situation matching the one you have.
  2923.  
  2924.    * For speed-related bugs or problems with `SELECT' statements, you
  2925.      should always include the output of `EXPLAIN SELECT ...', and at
  2926.      least the number of rows that the `SELECT' statement produces.  You
  2927.      should also include the output from `SHOW CREATE TABLE tbl_name'
  2928.      for each involved table. The more information you give about your
  2929.      situation, the more likely it is that someone can help you.  The
  2930.      following is an example of a very good bug report (it should of
  2931.      course be posted with the `mysqlbug' script).
  2932.  
  2933.      Example run using the `mysql' command-line tool (note the use of
  2934.      the `\G' statement terminator for statements whose output width
  2935.      would otherwise exceed that of an 80-column display device):
  2936.  
  2937.           mysql> SHOW VARIABLES;
  2938.           mysql> SHOW COLUMNS FROM ...\G
  2939.                  <output from SHOW COLUMNS>
  2940.           mysql> EXPLAIN SELECT ...\G
  2941.                  <output from EXPLAIN>
  2942.           mysql> FLUSH STATUS;
  2943.           mysql> SELECT ...;
  2944.                  <A short version of the output from SELECT,
  2945.                  including the time taken to run the query>
  2946.           mysql> SHOW STATUS;
  2947.                  <output from SHOW STATUS>
  2948.  
  2949.    * If a bug or problem occurs while running `mysqld', try to provide
  2950.      an input script that will reproduce the anomaly.  This script
  2951.      should include any necessary source files.  The more closely the
  2952.      script can reproduce your situation, the better.  If you can make
  2953.      a reproducible test case, you should post it on
  2954.      `http://bugs.mysql.com/' for high-priority treatment.
  2955.  
  2956.      If you can't provide a script, you should at least include the
  2957.      output from `mysqladmin variables extended-status processlist' in
  2958.      your mail to provide some information on how your system is
  2959.      performing.
  2960.  
  2961.    * If you can't produce a test case with only a few rows, or if the
  2962.      test table is too big to be mailed to the mailing list (more than
  2963.      10 rows), you should dump your tables using `mysqldump' and create
  2964.      a `README' file that describes your problem.
  2965.  
  2966.      Create a compressed archive of your files using `tar' and `gzip'
  2967.      or `zip', and use `ftp' to transfer the archive to
  2968.      `ftp://support.mysql.com/pub/mysql/secret/'.  Then enter the
  2969.      problem into our bugs database at `http://bugs.mysql.com/'.
  2970.  
  2971.    * If you think that the MySQL server produces a strange result from
  2972.      a query, include not only the result, but also your opinion of
  2973.      what the result should be, and an account describing the basis for
  2974.      your opinion.
  2975.  
  2976.    * When giving an example of the problem, it's better to use the
  2977.      variable names, table names, etc., that exist in your actual
  2978.      situation than to come up with new names.  The problem could be
  2979.      related to the name of a variable or table.  These cases are rare,
  2980.      perhaps, but it is better to be safe than sorry.  After all, it
  2981.      should be easier for you to provide an example that uses your
  2982.      actual situation, and it is by all means better for us.  In case
  2983.      you have data you don't want to show to others, you can use `ftp'
  2984.      to transfer it to `ftp://support.mysql.com/pub/mysql/secret/'.  If
  2985.      the data is really top secret and you don't want to show it even
  2986.      to us, then go ahead and provide an example using other names, but
  2987.      please regard this as the last choice.
  2988.  
  2989.    * Include all the options given to the relevant programs, if
  2990.      possible.  For example, indicate the options that you use when you
  2991.      start the `mysqld' daemon as well as the options that you use to
  2992.      run any MySQL client programs.  The options to programs like
  2993.      `mysqld' and `mysql', and to the `configure' script, are often
  2994.      keys to answers and are very relevant.  It is never a bad idea to
  2995.      include them.  If you use any modules, such as Perl or PHP, please
  2996.      include the version number(s) of those as well.
  2997.  
  2998.    * If your question is related to the privilege system, please
  2999.      include the output of `mysqlaccess', the output of `mysqladmin
  3000.      reload', and all the error messages you get when trying to
  3001.      connect.  When you test your privileges, you should first run
  3002.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  3003.      and try to connect with the program that gives you trouble.
  3004.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  3005.      installation directory.
  3006.  
  3007.    * If you have a patch for a bug, do include it.  But don't assume
  3008.      the patch is all we need, or that we will use it, if you don't
  3009.      provide some necessary information such as test cases showing the
  3010.      bug that your patch fixes.  We might find problems with your patch
  3011.      or we might not understand it at all; if so, we can't use it.
  3012.  
  3013.      If we can't verify exactly what the patch is meant for, we won't
  3014.      use it.  Test cases will help us here.  Show that the patch will
  3015.      handle all the situations that may occur.  If we find a borderline
  3016.      case (even a rare one) where the patch won't work, it may be
  3017.      useless.
  3018.  
  3019.    * Guesses about what the bug is, why it occurs, or what it depends on
  3020.      are usually wrong.  Even the MySQL team can't guess such things
  3021.      without first using a debugger to determine the real cause of a
  3022.      bug.
  3023.  
  3024.    * Indicate in your bug report that you have checked the reference
  3025.      manual and mail archive so that others know you have tried to
  3026.      solve the problem yourself.
  3027.  
  3028.    * If you get a `parse error', please check your syntax closely.  If
  3029.      you can't find something wrong with it, it's extremely likely that
  3030.      your current version of MySQL Server doesn't support the syntax
  3031.      you are using.  If you are using the current version and the
  3032.      manual at `http://www.mysql.com/doc/' doesn't cover the syntax you
  3033.      are using, MySQL Server doesn't support your query.  In this case,
  3034.      your only options are to implement the syntax yourself or e-mail
  3035.      <licensing@mysql.com> and ask for an offer to implement it.
  3036.  
  3037.      If the manual covers the syntax you are using, but you have an
  3038.      older version of MySQL Server, you should check the MySQL change
  3039.      history to see when the syntax was implemented.  In this case, you
  3040.      have the option of upgrading to a newer version of MySQL Server.
  3041.      *Note News::.
  3042.  
  3043.    * If your problem is that your data appears corrupt or you get
  3044.      errors when you access a particular table, you should first check
  3045.      and then try repairing your tables with `myisamchk' or `CHECK
  3046.      TABLE' and `REPAIR TABLE'.  *Note MySQL Database Administration::.
  3047.  
  3048.    * If you often get corrupted tables you should try to find out when
  3049.      and why this happens.  In this case, the
  3050.      `mysql-data-directory/'hostname'.err' file may contain some
  3051.      information about what happened.  *Note Error log::.  Please
  3052.      include any relevant information from this file in your bug
  3053.      report.  Normally `mysqld' should *never* crash a table if nothing
  3054.      killed it in the middle of an update.  If you can find the cause
  3055.      of `mysqld' dying, it's much easier for us to provide you with a
  3056.      fix for the problem.  *Note What is crashing::.
  3057.  
  3058.    * If possible, download and install the most recent version of MySQL
  3059.      Server and check whether it solves your problem.  All versions of
  3060.      the MySQL software are thoroughly tested and should work without
  3061.      problems.  We believe in making everything as backward-compatible
  3062.      as possible, and you should be able to switch MySQL versions
  3063.      without difficulty.  *Note Which version::.
  3064.  
  3065. If you are a support customer, please cross-post the bug report to
  3066. <mysql-support@mysql.com> for higher-priority treatment, as well as to
  3067. the appropriate mailing list to see if someone else has experienced (and
  3068. perhaps solved) the problem.
  3069.  
  3070. For information on reporting bugs in `MyODBC', see *Note ODBC
  3071. Problems::.
  3072.  
  3073. For solutions to some common problems, see *Note Problems::.
  3074.  
  3075. When answers are sent to you individually and not to the mailing list,
  3076. it is considered good etiquette to summarise the answers and send the
  3077. summary to the mailing list so that others may have the benefit of
  3078. responses you received that helped you solve your problem.
  3079.  
  3080. Guidelines for Answering Questions on the Mailing List
  3081. ......................................................
  3082.  
  3083. If you consider your answer to have broad interest, you may want to
  3084. post it to the mailing list instead of replying directly to the
  3085. individual who asked.  Try to make your answer general enough that
  3086. people other than the original poster may benefit from it.  When you
  3087. post to the list, please make sure that your answer is not a
  3088. duplication of a previous answer.
  3089.  
  3090. Try to summarise the essential part of the question in your reply;
  3091. don't feel obliged to quote the entire original message.
  3092.  
  3093. Please don't post mail messages from your browser with HTML mode turned
  3094. on.  Many users don't read mail with a browser.
  3095.  
  3096. MySQL Community Support on IRC (Internet Relay Chat)
  3097. ----------------------------------------------------
  3098.  
  3099. In addition to the various MySQL mailing lists, you can find experienced
  3100. community people on `IRC' (`Internet Relay Chat').  These are the best
  3101. networks/channels currently known to us:
  3102.  
  3103.    * *freenode* (see `http://www.freenode.net/' for servers)
  3104.         * `#mysql' Primarily MySQL questions but other database and SQL
  3105.           questions welcome.
  3106.  
  3107.         * `#mysqlphp' Questions about MySQL+PHP, a popular combination.
  3108.  
  3109.         * `#mysqlperl' Questions about MySQL+Perl, another popular
  3110.           combination.
  3111.  
  3112.    * *EFnet* (see `http://www.efnet.org/' for servers)
  3113.         * `#mysql' MySQL questions.
  3114.  
  3115. If you are looking for IRC client software to connect to an IRC network,
  3116. take a look at `X-Chat' (`http://www.xchat.org/').  X-Chat (GPL
  3117. licensed) is available for Unix as well as for Windows platforms.
  3118.  
  3119. How Standards-compatible Is MySQL?
  3120. ==================================
  3121.  
  3122. This section describes how MySQL relates to the ANSI/ISO SQL standards.
  3123. MySQL Server has many extensions to the SQL standard, and here you will
  3124. find out what they are and how to use them.  You will also find
  3125. information about functionality missing from MySQL Server, and how to
  3126. work around some differences.
  3127.  
  3128. Our goal is to not, without a very good reason, restrict MySQL Server
  3129. usability for any usage.  Even if we don't have the resources to do
  3130. development for every possible use, we are always willing to help and
  3131. offer suggestions to people who are trying to use MySQL Server in new
  3132. territories.
  3133.  
  3134. One of our main goals with the product is to continue to work toward
  3135. compliance with the SQL-99 standard, but without sacrificing speed or
  3136. reliability.  We are not afraid to add extensions to SQL or support for
  3137. non-SQL features if this greatly increases the usability of MySQL
  3138. Server for a big part of our users.  (The new `HANDLER' interface in
  3139. MySQL Server 4.0 is an example of this strategy. *Note `HANDLER':
  3140. HANDLER.)
  3141.  
  3142. We will continue to support transactional and non-transactional
  3143. databases to satisfy both heavy web/logging usage and mission-critical
  3144. 24/7 usage.
  3145.  
  3146. MySQL Server was designed from the start to work with medium size
  3147. databases (10-100 million rows, or about 100 MB per table) on small
  3148. computer systems.  We will continue to extend MySQL Server to work even
  3149. better with terabyte-size databases, as well as to make it possible to
  3150. compile a reduced MySQL version that is more suitable for hand-held
  3151. devices and embedded usage.  The compact design of the MySQL server
  3152. makes both of these directions possible without any conflicts in the
  3153. source tree.
  3154.  
  3155. We are currently not targeting realtime support or clustered databases
  3156. (even if you can already do a lot of things with our replication
  3157. services).
  3158.  
  3159. We don't believe that one should have native XML support in the
  3160. database, but will instead add the XML support our users request from
  3161. us on the client side.  We think it's better to keep the main server
  3162. code as "lean and clean" as possible and instead develop libraries to
  3163. deal with the complexity on the client side.  This is part of the
  3164. strategy mentioned previously of not sacrificing speed or reliability
  3165. in the server.
  3166.  
  3167. What Standards Does MySQL Follow?
  3168. ---------------------------------
  3169.  
  3170. Entry-level SQL-92. ODBC levels 0-3.51.
  3171.  
  3172. We are aiming toward supporting the full SQL-99 standard, but without
  3173. concessions to speed and quality of the code.
  3174.  
  3175. Running MySQL in ANSI Mode
  3176. --------------------------
  3177.  
  3178. If you start `mysqld' with the `--ansi' or `--sql-mode=ANSI' option,
  3179. the following behaviours of MySQL Server change:
  3180.  
  3181.    * `||' is a string concatenation operator rather than a synonym for
  3182.      `OR'.
  3183.  
  3184.    * `"' is treated as an identifier quote character (like the MySQL
  3185.      Server ``' quote character) and not as a string quote character.
  3186.      You can still use ``' to quote identifers in ANSI mode.
  3187.  
  3188.    * You can have any number of spaces between a function name and the
  3189.      `(' character.  This forces all function names to be treated as
  3190.      reserved words. As a result, if you want to access any database,
  3191.      table, or column name that is a reserved word, you must quote it.
  3192.      For example, because there is a `USER()' function, the name of the
  3193.      `user' table in the `mysql' database and the `User' column in that
  3194.      table become reserved, so you must quote them:
  3195.  
  3196.           SELECT "User" FROM mysql."user";
  3197.  
  3198.    * `REAL' is a synonym for `FLOAT' instead of a synonym for `DOUBLE'.
  3199.  
  3200.    * The default transaction isolation level is `SERIALIZABLE'.  *Note
  3201.      `SET TRANSACTION': SET TRANSACTION.
  3202.  
  3203.    * You can use a field/expression in `GROUP BY' that is not in the
  3204.      field list.
  3205.  
  3206. Running the server in ANSI mode is the same as starting it with these
  3207. options:
  3208.  
  3209.      --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  3210.      --transaction-isolation=SERIALIZABLE
  3211.  
  3212. In MySQL 4.1, you can achieve the same effect with these two statements:
  3213.  
  3214.      SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3215.      SET GLOBAL sql_mode =
  3216.        "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY";
  3217.  
  3218. In MySQL 4.1.1, the `sql_mode' options shown can be also be set with:
  3219.  
  3220.      SET GLOBAL sql_mode="ansi";
  3221.  
  3222. In this case, the value of the `sql_mode' variable will be set to all
  3223. options that are relevant for ANSI mode. You can check the result by
  3224. doing:
  3225.  
  3226.      mysql> SET GLOBAL sql_mode="ansi";
  3227.      mysql> SELECT @@GLOBAL.sql_mode;
  3228.               -> "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI"
  3229.  
  3230. MySQL Extensions To The SQL-92 Standard
  3231. ---------------------------------------
  3232.  
  3233. MySQL Server includes some extensions that you probably will not find in
  3234. other SQL databases.  Be warned that if you use them, your code will
  3235. not be portable to other SQL servers.  In some cases, you can write
  3236. code that includes MySQL extensions, but is still portable, by using
  3237. comments of the form `/*! ... */'.  In this case, MySQL Server will
  3238. parse and execute the code within the comment as it would any other
  3239. MySQL statement, but other SQL servers will ignore the extensions.  For
  3240. example:
  3241.  
  3242.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  3243.  
  3244. If you add a version number after the `'!'', the syntax will be
  3245. executed only if the MySQL version is equal to or newer than the used
  3246. version number:
  3247.  
  3248.      CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
  3249.  
  3250. This means that if you have Version 3.23.02 or newer, MySQL Server will
  3251. use the `TEMPORARY' keyword.
  3252.  
  3253. The following is a list of MySQL extensions:
  3254.  
  3255.    * The field types `MEDIUMINT', `SET', `ENUM', and the different
  3256.      `BLOB' and `TEXT' types.
  3257.  
  3258.    * The field attributes `AUTO_INCREMENT', `BINARY', `NULL',
  3259.      `UNSIGNED', and `ZEROFILL'.
  3260.  
  3261.    * All string comparisons are case-insensitive by default, with sort
  3262.      ordering determined by the current character set (ISO-8859-1
  3263.      Latin1 by default).  If you don't like this, you should declare
  3264.      your columns with the `BINARY' attribute or use the `BINARY' cast,
  3265.      which causes comparisons to be done according to the ASCII order
  3266.      used on the MySQL server host.
  3267.  
  3268.    * MySQL Server maps each database to a directory under the MySQL
  3269.      data directory, and tables within a database to filenames in the
  3270.      database directory.
  3271.  
  3272.      This has a few implications:
  3273.  
  3274.         - Database names and table names are case-sensitive in MySQL
  3275.           Server on operating systems that have case-sensitive
  3276.           filenames (like most Unix systems). *Note Name case
  3277.           sensitivity::.
  3278.  
  3279.         - Database, table, index, column, or alias names may begin with
  3280.           a digit (but may not consist solely of digits).
  3281.  
  3282.         - You can use standard system commands to back up, rename,
  3283.           move, delete, and copy tables.  For example, to rename a
  3284.           table, rename the `.MYD', `.MYI', and `.frm' files to which
  3285.           the table corresponds.
  3286.  
  3287.    * In SQL statements, you can access tables from different databases
  3288.      with the `db_name.tbl_name' syntax.  Some SQL servers provide the
  3289.      same functionality but call this `User space'.  MySQL Server
  3290.      doesn't support tablespaces as in: `create table
  3291.      ralph.my_table...IN my_tablespace'.
  3292.  
  3293.    * `LIKE' is allowed on numeric columns.
  3294.  
  3295.    * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT' statement.
  3296.      *Note `SELECT': SELECT.
  3297.  
  3298.    * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  3299.  
  3300.    * `EXPLAIN SELECT' to get a description of how tables are joined.
  3301.  
  3302.    * Use of index names, indexes on a prefix of a field, and use of
  3303.      `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  3304.      TABLE': CREATE TABLE.
  3305.  
  3306.    * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  3307.  
  3308.    * Use of `COUNT(DISTINCT list)' where `list' has more than one
  3309.      element.
  3310.  
  3311.    * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  3312.      `IGNORE' or `RENAME' in an `ALTER TABLE' statement. *Note `ALTER
  3313.      TABLE': ALTER TABLE.
  3314.  
  3315.    * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  3316.  
  3317.    * Use of multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  3318.      `ALTER TABLE' statement.
  3319.  
  3320.    * Use of `DROP TABLE' with the keywords `IF EXISTS'.
  3321.  
  3322.    * You can drop multiple tables with a single `DROP TABLE' statement.
  3323.  
  3324.    * The `ORDER BY' and `LIMIT' clauses of the `UPDATE' and `DELETE'
  3325.      statements.
  3326.  
  3327.    * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  3328.  
  3329.    * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE', `DELETE',
  3330.      and `UPDATE' statements.
  3331.  
  3332.    * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  3333.      compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD DATA':
  3334.      LOAD DATA.
  3335.  
  3336.    * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and `REPAIR
  3337.      TABLE' statements.
  3338.  
  3339.    * The `SHOW' statement.  *Note `SHOW': SHOW.
  3340.  
  3341.    * Strings may be enclosed by either `"' or `'', not just by `''.
  3342.  
  3343.    * Use of the escape `\' character.
  3344.  
  3345.    * The `SET' statement. *Note `SET': SET OPTION.
  3346.  
  3347.    * You don't need to name all selected columns in the `GROUP BY' part.
  3348.      This gives better performance for some very specific, but quite
  3349.      normal queries.  *Note Group by functions::.
  3350.  
  3351.    * One can specify `ASC' and `DESC' with `GROUP BY'.
  3352.  
  3353.    * To make it easier for users who come from other SQL environments,
  3354.      MySQL Server supports aliases for many functions. For example, all
  3355.      string functions support both standard SQL syntax and ODBC syntax.
  3356.  
  3357.    * MySQL Server understands the `||' and `&&' operators to mean
  3358.      logical OR and AND, as in the C programming language.  In MySQL
  3359.      Server, `||' and `OR' are synonyms, as are `&&' and `AND'.
  3360.      Because of this nice syntax, MySQL Server doesn't support the
  3361.      standard SQL-99 `||' operator for string concatenation; use
  3362.      `CONCAT()' instead. Because `CONCAT()' takes any number of
  3363.      arguments, it's easy to convert use of the `||' operator to MySQL
  3364.      Server.
  3365.  
  3366.    * `CREATE DATABASE' or `DROP DATABASE'.  *Note `CREATE DATABASE':
  3367.      CREATE DATABASE.
  3368.  
  3369.    * The `%' operator is a synonym for `MOD()'.  That is, `N % M' is
  3370.      equivalent to `MOD(N,M)'.  `%' is supported for C programmers and
  3371.      for compatibility with PostgreSQL.
  3372.  
  3373.    * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  3374.      `OR', or `LIKE' operators may be used in column comparisons to the
  3375.      left of the `FROM' in `SELECT' statements.  For example:
  3376.  
  3377.           mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  3378.  
  3379.    * The `LAST_INSERT_ID()' function.  *Note `mysql_insert_id()':
  3380.      mysql_insert_id.
  3381.  
  3382.    * The `REGEXP' and `NOT REGEXP' extended regular expression
  3383.      operators.
  3384.  
  3385.    * `CONCAT()' or `CHAR()' with one argument or more than two
  3386.      arguments.  (In MySQL Server, these functions can take any number
  3387.      of arguments.)
  3388.  
  3389.    * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()', `FORMAT()',
  3390.      `IF()', `PASSWORD()', `ENCRYPT()', `MD5()', `ENCODE()', `DECODE()',
  3391.      `PERIOD_ADD()', `PERIOD_DIFF()', `TO_DAYS()', or `WEEKDAY()'
  3392.      functions.
  3393.  
  3394.    * Use of `TRIM()' to trim substrings.  SQL-99 supports removal of
  3395.      single characters only.
  3396.  
  3397.    * The `GROUP BY' functions `STD()', `BIT_OR()', `BIT_AND()', and
  3398.      `GROUP_CONCAT()'.  *Note Group by functions::.
  3399.  
  3400.    * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note `REPLACE':
  3401.      REPLACE.
  3402.  
  3403.    * The `FLUSH', `RESET' and `DO' statements.
  3404.  
  3405.    * The ability to set variables in a statement with `:=':
  3406.           SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg FROM test_table;
  3407.           SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  3408.  
  3409.  
  3410. MySQL Differences Compared To SQL-92
  3411. ------------------------------------
  3412.  
  3413. We try to make MySQL Server follow the ANSI SQL standard
  3414. (SQL-92/SQL-99) and the ODBC SQL standard, but in some cases MySQL
  3415. Server does things differently:
  3416.  
  3417.    * For `VARCHAR' columns, trailing spaces are removed when the value
  3418.      is stored. *Note Bugs::.
  3419.  
  3420.    * In some cases, `CHAR' columns are silently changed to `VARCHAR'
  3421.      columns. *Note Silent column changes::.
  3422.  
  3423.    * Privileges for a table are not automatically revoked when you
  3424.      delete a table. You must explicitly issue a `REVOKE' to revoke
  3425.      privileges for a table. *Note `GRANT': GRANT.
  3426.  
  3427.    * `NULL AND FALSE' will evaluate to `NULL' and not to `FALSE'.  This
  3428.      is because we don't think it's good to have to evaluate a lot of
  3429.      extra conditions in this case.
  3430.  
  3431. For a prioritised list indicating when new extensions will be added to
  3432. MySQL Server, you should consult the online MySQL TODO list at
  3433. `http://www.mysql.com/doc/en/TODO.html'.  That is the latest version of
  3434. the TODO list in this manual. *Note TODO::.
  3435.  
  3436. Sub`SELECT's
  3437. ............
  3438.  
  3439. Subqueries are supported in MySQL version 4.1.  *Note Nutshell 4.1
  3440. features::.
  3441.  
  3442. Upto version 4.0, only nested queries of the form `INSERT ... SELECT
  3443. ...' and `REPLACE ... SELECT ...' are supported.  You can, however, use
  3444. the function `IN()' in other contexts.
  3445.  
  3446. You can often rewrite the query without a subquery:
  3447.  
  3448.      SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
  3449.  
  3450. This can be rewritten as:
  3451.  
  3452.      SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
  3453.  
  3454. The queries:
  3455.      SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
  3456.      SELECT * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2
  3457.                                             WHERE table1.id=table2.id);
  3458.  
  3459. Can be rewritten as:
  3460.  
  3461.      SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id
  3462.                                             WHERE table2.id IS NULL;
  3463.  
  3464. Using a `LEFT [OUTER] JOIN' is generally much faster than an equivalent
  3465. subquery because the server can optimise it better, a fact that is not
  3466. specific to MySQL Server alone.  Prior to SQL-92, outer joins did not
  3467. exist, so subqueries were the only way to do certain things in those
  3468. bygone days. But that is no longer the case, MySQL Server and many
  3469. other modern database systems offer a whole range of outer joins types.
  3470.  
  3471. For more complicated subqueries you can often create temporary tables
  3472. to hold the subquery.  In some cases, however, this option will not
  3473. work. The most frequently encountered of these cases arises with
  3474. `DELETE' statements, for which standard SQL does not support joins
  3475. (except in subqueries).  For this situation there are three options
  3476. available:
  3477.  
  3478.    * The first option is to upgrade to MySQL version 4.1.
  3479.  
  3480.    * The second option is to use a procedural programming language
  3481.      (such as Perl or PHP) to submit a `SELECT' query to obtain the
  3482.      primary keys for the records to be deleted, and then use these
  3483.      values to construct the `DELETE' statement (`DELETE FROM ... WHERE
  3484.      ... IN (key1, key2, ...)').
  3485.  
  3486.    * The third option is to use interactive SQL to construct a set of
  3487.      `DELETE' statements automatically, using the MySQL extension
  3488.      `CONCAT()' (in lieu of the standard `||' operator).  For example:
  3489.  
  3490.           SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', "'", tab1.pkid, "'", ';')
  3491.             FROM tab1, tab2
  3492.            WHERE tab1.col1 = tab2.col2;
  3493.  
  3494.      You can place this query in a script file and redirect input from
  3495.      it to the `mysql' command-line interpreter, piping its output back
  3496.      to a second instance of the interpreter:
  3497.  
  3498.           shell> mysql --skip-column-names mydb < myscript.sql | mysql mydb
  3499.  
  3500. MySQL Server 4.0 supports multi-table `DELETE's that can be used to
  3501. efficiently delete rows based on information from one table or even
  3502. from many tables at the same time.
  3503.  
  3504. `SELECT INTO TABLE'
  3505. ...................
  3506.  
  3507. MySQL Server doesn't yet support the Oracle SQL extension: `SELECT ...
  3508. INTO TABLE ...'.  Instead, MySQL Server supports the SQL-99 syntax
  3509. `INSERT INTO ... SELECT ...', which is basically the same thing. *Note
  3510. INSERT SELECT::.
  3511.  
  3512.      INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID
  3513.             FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;
  3514.  
  3515. Alternatively, you can use `SELECT INTO OUTFILE...' or `CREATE TABLE
  3516. ... SELECT'.
  3517.  
  3518. Transactions and Atomic Operations
  3519. ..................................
  3520.  
  3521. MySQL Server (version 3.23-max and all versions 4.0 and above) supports
  3522. transactions with the `InnoDB' and `BDB' `Transactional storage
  3523. engines'.  `InnoDB' provides _full_ `ACID' compliance.  *Note Table
  3524. types::.
  3525.  
  3526. The other non-transactional table types (such as `MyISAM') in MySQL
  3527. Server follow a different paradigm for data integrity called "`Atomic
  3528. Operations'." In transactional terms, `MyISAM' tables effectively
  3529. always operate in `AUTOCOMMIT=1' mode.  Atomic operations often offer
  3530. comparable integrity with higher performance.
  3531.  
  3532. With MySQL Server supporting both paradigms, the user is able to decide
  3533. if he needs the speed of atomic operations or if he needs to use
  3534. transactional features in his applications. This choice can be made on
  3535. a per-table basis.
  3536.  
  3537. As noted, the trade off for transactional vs. non-transactional table
  3538. types lies mostly in performance. Transactional tables have
  3539. significantly higher memory and diskspace requirements, and more CPU
  3540. overhead.  That said, transactional table types such as `InnoDB' do of
  3541. course offer many unique features. MySQL Server's modular design allows
  3542. the concurrent use of all these different storage engines to suit
  3543. different requirements and deliver optimum performance in all
  3544. situations.
  3545.  
  3546. But how does one use the features of MySQL Server to maintain rigorous
  3547. integrity even with the non-transactional `MyISAM' tables, and how do
  3548. these features compare with the transactional table types?
  3549.  
  3550.   1. In the transactional paradigm, if your applications are written in
  3551.      a way that is dependent on the calling of `ROLLBACK' instead of
  3552.      `COMMIT' in critical situations, transactions are more convenient.
  3553.      Transactions also ensure that unfinished updates or corrupting
  3554.      activities are not committed to the database; the server is given
  3555.      the opportunity to do an automatic rollback and your database is
  3556.      saved.
  3557.  
  3558.      MySQL Server, in almost all cases, allows you to resolve potential
  3559.      problems by including simple checks before updates and by running
  3560.      simple scripts that check the databases for inconsistencies and
  3561.      automatically repair or warn if such an inconsistency occurs. Note
  3562.      that just by using the MySQL log or even adding one extra log, one
  3563.      can normally fix tables perfectly with no data integrity loss.
  3564.  
  3565.   2. More often than not, critical transactional updates can be
  3566.      rewritten to be atomic. Generally speaking, all integrity problems
  3567.      that transactions solve can be done with `LOCK TABLES' or atomic
  3568.      updates, ensuring that you never will get an automatic abort from
  3569.      the server, which is a common problem with transactional database
  3570.      systems.
  3571.  
  3572.   3. Even a transactional system can lose data if the server goes down.
  3573.      The difference between different systems lies in just how small the
  3574.      time-lap is where they could lose data. No system is 100% secure,
  3575.      only "secure enough." Even Oracle, reputed to be the safest of
  3576.      transactional database systems, is reported to sometimes lose data
  3577.      in such situations.
  3578.  
  3579.      To be safe with MySQL Server, whether using transactional tables
  3580.      or not, you only need to have backups and have the binary logging
  3581.      turned on. With this you can recover from any situation that you
  3582.      could with any other transactional database system.  It is, of
  3583.      course, always good to have backups, independent of which database
  3584.      system you use.
  3585.  
  3586. The transactional paradigm has its benefits and its drawbacks. Many
  3587. users and application developers depend on the ease with which they can
  3588. code around problems where an abort appears to be, or is necessary.
  3589. However, even if you are new to the atomic operations paradigm, or more
  3590. familiar with transactions, do consider the speed benefit that
  3591. non-transactional tables can offer on the order of three to five times
  3592. the speed of the fastest and most optimally tuned transactional tables.
  3593.  
  3594. In situations where integrity is of highest importance, MySQL Server
  3595. offers transaction-level reliability and integrity even for
  3596. non-transactional tables.  If you lock tables with `LOCK TABLES', all
  3597. updates will stall until any integrity checks are made. If you only
  3598. obtain a read lock (as opposed to a write lock), reads and inserts are
  3599. still allowed to happen. The new inserted records will not be seen by
  3600. any of the clients that have a read lock until they release their read
  3601. locks. With `INSERT DELAYED' you can queue inserts into a local queue,
  3602. until the locks are released, without having the client wait for the
  3603. insert to complete. *Note INSERT DELAYED::.
  3604.  
  3605. "Atomic," in the sense that we mean it, is nothing magical. It only
  3606. means that you can be sure that while each specific update is running,
  3607. no other user can interfere with it, and there will never be an
  3608. automatic rollback (which can happen with transactional tables if you
  3609. are not very careful).  MySQL Server also guarantees that there will
  3610. not be any dirty reads.
  3611.  
  3612. Following are some techniques for working with non-transactional tables:
  3613.  
  3614.    * Loops that need transactions normally can be coded with the help of
  3615.      `LOCK TABLES', and you don't need cursors when you can update
  3616.      records on the fly.
  3617.  
  3618.    * To avoid using `ROLLBACK', you can use the following strategy:
  3619.  
  3620.        1. Use `LOCK TABLES ...' to lock all the tables you want to
  3621.           access.
  3622.  
  3623.        2. Test conditions.
  3624.  
  3625.        3. Update if everything is okay.
  3626.  
  3627.        4. Use `UNLOCK TABLES' to release your locks.
  3628.  
  3629.      This is usually a much faster method than using transactions with
  3630.      possible `ROLLBACK's, although not always. The only situation this
  3631.      solution doesn't handle is when someone kills the threads in the
  3632.      middle of an update. In this case, all locks will be released but
  3633.      some of the updates may not have been executed.
  3634.  
  3635.    * You can also use functions to update records in a single operation.
  3636.      You can get a very efficient application by using the following
  3637.      techniques:
  3638.  
  3639.         * Modify fields relative to their current value.
  3640.  
  3641.         * Update only those fields that actually have changed.
  3642.  
  3643.      For example, when we are doing updates to some customer
  3644.      information, we update only the customer data that has changed and
  3645.      test only that none of the changed data, or data that depends on
  3646.      the changed data, has changed compared to the original row. The
  3647.      test for changed data is done with the `WHERE' clause in the
  3648.      `UPDATE' statement. If the record wasn't updated, we give the
  3649.      client a message: "Some of the data you have changed has been
  3650.      changed by another user." Then we show the old row versus the new
  3651.      row in a window, so the user can decide which version of the
  3652.      customer record he should use.
  3653.  
  3654.      This gives us something that is similar to column locking but is
  3655.      actually even better because we only update some of the columns,
  3656.      using values that are relative to their current values.  This
  3657.      means that typical `UPDATE' statements look something like these:
  3658.  
  3659.           UPDATE tablename SET pay_back=pay_back+125;
  3660.           
  3661.           UPDATE customer
  3662.             SET
  3663.               customer_date='current_date',
  3664.               address='new address',
  3665.               phone='new phone',
  3666.               money_he_owes_us=money_he_owes_us-125
  3667.             WHERE
  3668.               customer_id=id AND address='old address' AND phone='old phone';
  3669.  
  3670.      As you can see, this is very efficient and works even if another
  3671.      client has changed the values in the `pay_back' or
  3672.      `money_he_owes_us' columns.
  3673.  
  3674.    * In many cases, users have wanted `ROLLBACK' and/or `LOCK TABLES'
  3675.      for the purpose of managing unique identifiers for some tables.
  3676.      This can be handled much more efficiently by using an
  3677.      `AUTO_INCREMENT' column and either the SQL function
  3678.      `LAST_INSERT_ID()' or the C API function `mysql_insert_id()'.
  3679.      *Note `mysql_insert_id()': mysql_insert_id.
  3680.  
  3681.      You can generally code around row-level locking. Some situations
  3682.      really need it, but they are very few. `InnoDB' tables support
  3683.      row-level locking. With MyISAM, you can use a flag column in the
  3684.      table and do something like the following:
  3685.  
  3686.           UPDATE tbl_name SET row_flag=1 WHERE id=ID;
  3687.  
  3688.      MySQL returns 1 for the number of affected rows if the row was
  3689.      found and `row_flag' wasn't already 1 in the original row.
  3690.  
  3691.      You can think of it as though MySQL Server changed the preceding
  3692.      query to:
  3693.  
  3694.           UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;
  3695.  
  3696. Stored Procedures and Triggers
  3697. ..............................
  3698.  
  3699. Stored procedures are being implemented in our version 5.0 development
  3700. tree.  *Note Installing source tree::.
  3701.  
  3702. This effort is based on SQL-99, which has a basic syntax similar (but
  3703. not identical) to Oracle PL/SQL. In addition to this, we are
  3704. implementing the SQL-99 framework to hook in external languages.
  3705.  
  3706. A stored procedure is a set of SQL commands that can be compiled and
  3707. stored in the server. Once this has been done, clients don't need to
  3708. keep re-issuing the entire query but can refer to the stored procedure.
  3709. This provides better overall performance because the query has to be
  3710. parsed only once, and less information needs to be sent between the
  3711. server and the client. You can also raise the conceptual level by
  3712. having libraries of functions in the server.  However, stored
  3713. procedures of course do increase the load on the database server
  3714. system, as more of the work is done on the server side and less on the
  3715. client (application) side.
  3716.  
  3717. Triggers will also be implemented. A trigger is effectively a type of
  3718. stored procedure, one that is invoked when a particular event occurs.
  3719. For example, you can install a stored procedure that is triggered each
  3720. time a record is deleted from a transaction table and that stored
  3721. procedure automatically deletes the corresponding customer from a
  3722. customer table when all his transactions are deleted.
  3723.  
  3724. Foreign Keys
  3725. ............
  3726.  
  3727. In MySQL Server 3.23.44 and up, `InnoDB' tables support checking of
  3728. foreign key constraints, including `CASCADE', `ON DELETE', and `ON
  3729. UPDATE'. *Note InnoDB foreign key constraints::.
  3730.  
  3731. For other table types, MySQL Server only parses the `FOREIGN KEY'
  3732. syntax in `CREATE TABLE' commands, but does not use/store this info.
  3733.  
  3734. Note that foreign keys in SQL are not used to join tables, but are used
  3735. mostly for checking referential integrity (foreign key constraints).  If
  3736. you want to get results from multiple tables from a `SELECT' statement,
  3737. you do this by joining tables:
  3738.  
  3739.      SELECT * FROM table1,table2 WHERE table1.id = table2.id;
  3740.  
  3741. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  3742.  
  3743. When used as a constraint, `FOREIGN KEY's don't need to be used if the
  3744. application inserts rows into `MyISAM' tables in the proper order.
  3745.  
  3746. For `MyISAM' tables, you can work around the lack of `ON DELETE' by
  3747. adding the appropriate `DELETE' statement to an application when you
  3748. delete records from a table that has a foreign key. In practice this is
  3749. as quick (in some cases quicker) and much more portable than using
  3750. foreign keys.
  3751.  
  3752. In MySQL Server 4.0 you can use multi-table delete to delete rows from
  3753. many tables with one command. *Note DELETE::.
  3754.  
  3755. The `FOREIGN KEY' syntax without `ON DELETE ...' is often used by ODBC
  3756. applications to produce automatic `WHERE' clauses.
  3757.  
  3758. In the near future we will extend the `FOREIGN KEY' implementation so
  3759. that the information is stored in the table specification file and may
  3760. be retrieved by `mysqldump' and ODBC. At a later stage we will
  3761. implement foreign key constraints for `MyISAM' tables as well.
  3762.  
  3763. Do keep in mind that foreign keys are often misused, which can cause
  3764. severe problems. Even when used properly, it is not a magic solution for
  3765. the referential integrity problem, although it can make things easier.
  3766.  
  3767. Some advantages of foreign key enforcement:
  3768.  
  3769.    * Assuming proper design of the relations, foreign key constraints
  3770.      will make it more difficult for a programmer to introduce an
  3771.      inconsistency into the database.
  3772.  
  3773.    * Using cascading updates and deletes can simplify the client code.
  3774.  
  3775.    * Properly designed foreign key rules aid in documenting relations
  3776.      between tables.
  3777.  
  3778. Disadvantages:
  3779.  
  3780.    * Mistakes, which are easy to make in designing key relations, can
  3781.      cause severe problems--for example, circular rules, or the wrong
  3782.      combination of cascading deletes.
  3783.  
  3784.    * A properly written application will make sure (internally) that it
  3785.      is not violating referential integrity constraints before
  3786.      proceding with a query. Thus, additional checks on the database
  3787.      level will only slow down performance for such an application.
  3788.  
  3789.    * It is not uncommon for a DBA to make such a complex topology of
  3790.      relations that it becomes very difficult, and in some cases
  3791.      impossible, to back up or restore individual tables.
  3792.  
  3793. Views
  3794. .....
  3795.  
  3796. We plan to implement views in MySQL Server in version 5.1
  3797.  
  3798. Historically, MySQL Server has been most used in applications and on web
  3799. systems where the application writer has full control over database
  3800. usage. Of course, usage has shifted over time, and so we find that an
  3801. increasing number of users now regard views as an important aspect.
  3802.  
  3803. Views are useful for allowing users to access a set of relations as if
  3804. it were a single table, and limiting their access to just that.  Many
  3805. DBMS don't allow updates to a view, instead you have to perform the
  3806. updates on the individual tables.
  3807.  
  3808. Views can also be used to restrict access to rows (a subset of a
  3809. particular table).  One does not need views to restrict access to
  3810. columns, as MySQL Server has a sophisticated privilege system.  *Note
  3811. Privilege system::.
  3812.  
  3813. In designing our implementation of views, we aim toward (as fully as
  3814. possible within the confines of SQL) compliance with "*Codd's Rule #6*"
  3815. for relational database systems: all views that are theoretically
  3816. updatable, should in practice also be updatable.  This is a complex
  3817. issue, and we are taking the time to make sure we get it right.
  3818.  
  3819. The implementation itself will be done in stages.  Unnamed views
  3820. (_derived tables_, a subquery in the `FROM' clause of a `SELECT') are
  3821. already implemented in version 4.1.
  3822.  
  3823. *Note*: If you are an enterprise level user with an urgent need for
  3824. views, please contact <sales@mysql.com> to discuss sponsoring options.
  3825. Targeted financing of this particular effort by one or more companies
  3826. would allow us to allocate additional resources to it.  One example of
  3827. a feature sponsored in the past is replication.
  3828.  
  3829. `--' as the Start of a Comment
  3830. ..............................
  3831.  
  3832. Some other SQL databases use `--' to start comments.  MySQL Server has
  3833. `#' as the start comment character. You can also use the C comment
  3834. style `/* this is a comment */' with MySQL Server.  *Note Comments::.
  3835.  
  3836. MySQL Server Version 3.23.3 and above support the `--' comment style,
  3837. provided the comment is followed by a space.  This is because this
  3838. comment style has caused many problems with automatically generated SQL
  3839. queries that have used something like the following code, where we
  3840. automatically insert the value of the payment for `!payment!':
  3841.  
  3842.      UPDATE tbl_name SET credit=credit-!payment!
  3843.  
  3844. Think about what happens if the value of `payment' is negative.
  3845. Because `1--1' is legal in SQL, the consequences of allowing comments
  3846. to start with `--' are terrible.
  3847.  
  3848. Using our implementation of this method of commenting in MySQL Server
  3849. Version 3.23.3 and up, `1-- This is a comment' is actually safe.
  3850.  
  3851. Another safe feature is that the `mysql' command-line client removes
  3852. all lines that start with `--'.
  3853.  
  3854. The following information is relevant only if you are running a MySQL
  3855. version earlier than 3.23.3:
  3856.  
  3857. If you have an SQL program in a text file that contains `--' comments
  3858. you should use:
  3859.  
  3860.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  3861.               | mysql database
  3862.  
  3863. instead of the usual:
  3864.  
  3865.      shell> mysql database < text-file-with-funny-comments.sql
  3866.  
  3867. You can also edit the command file "in place" to change the `--'
  3868. comments to `#' comments:
  3869.  
  3870.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  3871.  
  3872. Change them back with this command:
  3873.  
  3874.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  3875.  
  3876. How MySQL deals with constraints
  3877. --------------------------------
  3878.  
  3879. As MySQL allows you to work with both transactional and
  3880. non-transactional tables (which don't allow rollback), constraint
  3881. handling is a bit different in MySQL than in other databases.
  3882.  
  3883. We have to handle the case when you have updated a lot of rows with a
  3884. non-transactional table which can't rollback on errors.
  3885.  
  3886. The basic philosophy is to try to give an error for anything that we can
  3887. detect on compile time but try to recover from any errors we get run
  3888. time.  We do this in most cases, but not yet for all. *Note TODO
  3889. future::.
  3890.  
  3891. The basic options MySQL has is to stop the statement in the middle or do
  3892. it's best to recover from the problem and continue.
  3893.  
  3894. Here follows what happens with the different types of constraints.
  3895.  
  3896. Constraint PRIMARY KEY / UNIQUE
  3897. ...............................
  3898.  
  3899. Normally you will get an error when you try to `INSERT' / `UPDATE' a
  3900. row that causes a primary key, unique key or foreign key violation.  If
  3901. you are using a transactional storage engine, like InnoDB, MySQL will
  3902. automatically roll back the transaction.  If you are using a
  3903. non-transactional storage engine MySQL will stop at the wrong row and
  3904. leave the rest of the rows unprocessed.
  3905.  
  3906. To make life easier MySQL has added support for the `IGNORE' directive
  3907. to most commands that can cause a key violation (like `INSERT IGNORE
  3908. ...'). In this case MySQL will ignore any key violation and continue
  3909. with processing the next row.  You can get information of what MySQL
  3910. did with the `mysql_info()' API function and in later MySQL 4.1 version
  3911. with the `SHOW WARNINGS' command. *Note mysql_info::. *Note SHOW
  3912. WARNINGS::.
  3913.  
  3914. Note that for the moment only `InnoDB' tables support foreign keys.
  3915. *Note InnoDB foreign key constraints::.  Foreign key support in
  3916. `MyISAM' tables is scheduled for inclusion in the MySQL 5.0 source tree.
  3917.  
  3918. Constraint `NOT NULL' and `DEFAULT' values
  3919. ..........................................
  3920.  
  3921. To be able to support easy handling of non-transactional tables all
  3922. fields in MySQL have default values.
  3923.  
  3924. If you insert a 'wrong' value in a column like a `NULL' in a `NOT NULL'
  3925. column or a too big numerical value in a numerical column, MySQL will
  3926. instead of giving an error instead set the column to the 'best possible
  3927. value'.  For numerical values this is 0, the smallest possible values
  3928. or the largest possible value. For strings this is either the empty
  3929. string or the longest possible string that can be in the column.
  3930.  
  3931. This means that if you try to store `NULL' into a column that doesn't
  3932. take `NULL' values, MySQL Server will store 0 or `''' (empty string) in
  3933. it instead. This last behaviour can, for single row inserts, be changed
  3934. with the `-DDONT_USE_DEFAULT_FIELDS' compile option.) *Note configure
  3935. options::.  This causes `INSERT' statements to generate an error unless
  3936. you explicitly specify values for all columns that require a non-`NULL'
  3937. value.
  3938.  
  3939. The reason for the above rules is that we can't check these conditions
  3940. before the query starts to execute.  If we encounter a problem after
  3941. updating a few rows, we can't just rollback as the table type may not
  3942. support this.  The option to stop is not that good as in this case the
  3943. update would be 'half done' which is probably the worst possible
  3944. scenario.  In this case it's better to 'do the best you can' and then
  3945. continue as if nothing happened.  In MySQL 5.0 we plan to improve this
  3946. by providing warnings for automatic field conversions, plus an option
  3947. to let you roll back statements that only use transactional tables in
  3948. case one such statement does a field assignment that is not allowed.
  3949.  
  3950. The above means that one should generally not use MySQL to check field
  3951. content, but instead handle this in the application.
  3952.  
  3953. Constraint `ENUM' and `SET'
  3954. ...........................
  3955.  
  3956. In MySQL 4.x `ENUM' is not a real constrain but a more efficient way to
  3957. store fields that can only contain a given set of values.  This is
  3958. because of the same reasons `NOT NULL' is not honoured.  *Note
  3959. constraint NOT NULL::.
  3960.  
  3961. If you insert an wrong value in an `ENUM' field, it will be set to the
  3962. reserved enum number `0', which will be displayed as an empty string in
  3963. string context. *Note ENUM::.
  3964.  
  3965. If you insert an wrong option in a `SET' field, the wrong value will be
  3966. ignored. *Note SET::.
  3967.  
  3968. Known Errors and Design Deficiencies in MySQL
  3969. ---------------------------------------------
  3970.  
  3971. Errors in 3.23 Fixed in a Later MySQL Version
  3972. .............................................
  3973.  
  3974. The following known errors/bugs are not fixed in MySQL 3.23 because
  3975. fixing them would involves changing a lot of code which could introduce
  3976. other even worse bugs. The bugs are also classified as 'not fatal' or
  3977. 'bearable'.
  3978.  
  3979.    * One can get a deadlock when doing `LOCK TABLE' on multiple tables
  3980.      and then in the same connection doing a `DROP TABLE' on one of
  3981.      them while another thread is trying to lock the table.  One can
  3982.      however do a `KILL' on any of the involved threads to resolve this.
  3983.      Fixed in 4.0.12.
  3984.  
  3985.    * `SELECT MAX(key_column) FROM t1,t2,t3...' where one of the tables
  3986.      are empty doesn't return `NULL' but instead the maximum value for
  3987.      the column.  Fixed in 4.0.11.
  3988.  
  3989.    * `DELETE FROM heap_table' without a `WHERE' doesn't work on a locked
  3990.      HEAP table.
  3991.  
  3992. Open Bugs / Design Deficiencies in MySQL
  3993. ........................................
  3994.  
  3995. The following problems are known and fixing them is a high priority:
  3996.  
  3997.    * `ANALYZE TABLE' on a BDB table may in some cases make the table
  3998.      unusable until one has restarted `mysqld'.  When this happens you
  3999.      will see errors like the following in the MySQL error file:
  4000.  
  4001.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  4002.  
  4003.    * MySQL accepts parentheses in the `FROM' part, but silently ignores
  4004.      them.  The reason for not giving an error is that many clients
  4005.      that automatically generate queries add parentheses in the `FROM'
  4006.      part even where they are not needed.
  4007.  
  4008.    * Concatenating many `RIGHT JOINS' or combining `LEFT' and `RIGHT'
  4009.      join in the same query may not give a correct answer as MySQL only
  4010.      generates `NULL' rows for the table preceding a `LEFT' or before a
  4011.      `RIGHT' join.  This will be fixed in 5.0 at the same time we add
  4012.      support for parentheses in the `FROM' part.
  4013.  
  4014.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  4015.      running multi-statement transactions until all those transactions
  4016.      complete.  (The transaction will probably be ignored.)
  4017.  
  4018.    * `ANALYZE TABLE', `OPTIMIZE TABLE', and `REPAIR TABLE' may cause
  4019.      problems on tables for which you are using `INSERT DELAYED'.
  4020.  
  4021.    * Doing a `LOCK TABLE ...' and `FLUSH TABLES ...' doesn't guarantee
  4022.      that there isn't a half-finished transaction in progress on the
  4023.      table.
  4024.  
  4025.    * BDB tables are a bit slow to open. If you have many BDB tables in a
  4026.      database, it will take a long time to use the `mysql' client on the
  4027.      database if you are not using the `-A' option or if you are using
  4028.      `rehash'. This is especially notable when you have a big table
  4029.      cache.
  4030.  
  4031.    * Replication uses query-level logging: the master writes the
  4032.      executed queries to the binary log. This is a very fast, compact
  4033.      and efficient logging method which works perfectly in most cases.
  4034.      However, currently there is a theoretical chance (though we never
  4035.      heard about it coming true) that the data on the master and slave
  4036.      become different if a query is designed in such a way that the
  4037.      data modification is non-deterministic, that is, left to the will
  4038.      of the query optimiser (which generally is no good practice, even
  4039.      outside of replication!). For example:
  4040.  
  4041.         - `CREATE ... SELECT' or `INSERT ... SELECT' which feeds zeros
  4042.           or `NULL's into an `auto_increment' column.
  4043.  
  4044.         - `DELETE' if you are deleting rows from a table which has
  4045.           foreign keys with `ON DELETE CASCADE' properties.
  4046.  
  4047.         - `REPLACE ... SELECT', `INSERT IGNORE ... SELECT' if you have
  4048.           duplicate key values in the inserted data.
  4049.      *IF and only if all these queries have NO `ORDER BY' clause
  4050.      guaranteeing a deterministic order*.
  4051.  
  4052.      Indeed, for example for `INSERT ... SELECT' with no `ORDER BY',
  4053.      the `SELECT' may return rows in a different order (which will
  4054.      result in a row having different ranks, hence getting a different
  4055.      number in the `auto_increment' column), depending on the choices
  4056.      made by the optimisers on the master and slave. A query will be
  4057.      optimised differently on the master and slave only if :
  4058.  
  4059.         - The files used by the two queries are not exactly the same;
  4060.           for example `OPTIMIZE TABLE' was run on the master tables and
  4061.           not on the slave tables (to fix this, since MySQL 4.1.1,
  4062.           `OPTIMIZE', `ANALYZE' and `REPAIR' are written to the binary
  4063.           log).
  4064.  
  4065.         - The table is stored in a different storage engine on the
  4066.           master than on the slave (one can run with different storage
  4067.           engines on the slave and master: for example InnoDB on the
  4068.           master and MyISAM on the slave, if the slave has less
  4069.           available disk space).
  4070.  
  4071.         - The MySQL buffers' sizes (`key_buffer_size' etc) are
  4072.           different on the master and slave.
  4073.  
  4074.         - The master and slave run different MySQL versions, and the
  4075.           optimiser code is different between these versions.
  4076.  
  4077.      This problem may also affect database restoration using
  4078.      `mysqlbinlog|mysql'.
  4079.  
  4080.      The easiest way to avoid this problem in all cases is add an
  4081.      `ORDER BY' clause to such non-deterministic queries to ensure that
  4082.      the rows are always stored/modified in the same order.  In future
  4083.      MySQL versions we will automatically add an `ORDER BY' clause when
  4084.      needed.
  4085.  
  4086.  
  4087. The following problems are known and will be fixed in due time:
  4088.  
  4089.    * `LIKE' is not `multi-byte character' safe. Comparison is done
  4090.      character by character.
  4091.  
  4092.    *  When using `RPAD' function, or any other string function that ends
  4093.      up adding blanks to the right, in a query that has to use temporary
  4094.      table to be resolved, then all resulting strings will be RTRIM'ed.
  4095.      This is an example of the query:
  4096.  
  4097.      `SELECT    RPAD(t1.field1, 50, ' ') AS f2,    RPAD(t2.field2, 50, '
  4098.      ') AS f1  FROM    table1 as t1     LEFT JOIN table2 AS t2 ON
  4099.      t1.record=t2.joinID ORDER BY t2.record;'
  4100.  
  4101.      Final result of this bug is that use will not be able to get
  4102.      blanks on the right side of the resulting field.
  4103.  
  4104.      The above behaviour exists in all versions of MySQL.
  4105.  
  4106.      The reason for this is due to the fact that HEAP tables, which are
  4107.      used first for temporary tables, are not capable of handling
  4108.      VARCHAR columns.
  4109.  
  4110.      This behaviour will be fixed in one of the 4.1 series releases.
  4111.  
  4112.    * Because of how table definitions files are stored one can't use
  4113.      character 255 (`CHAR(255)') in table names, column names or enums.
  4114.      This is scheduled to be fixed in version 5.1 when we have new table
  4115.      definition format files.
  4116.  
  4117.    * When using `SET CHARACTER SET', one can't use translated
  4118.      characters in database, table, and column names.
  4119.  
  4120.    * One can't use `_' or `%' with `ESCAPE' in `LIKE ... ESCAPE'.
  4121.  
  4122.    * If you have a `DECIMAL' column with a  number stored in different
  4123.      formats (+01.00, 1.00, 01.00), `GROUP BY' may regard each value as
  4124.      a different value.
  4125.  
  4126.    * `DELETE FROM merge_table' used without a `WHERE' will only clear
  4127.      the mapping for the table, not delete everything in the mapped
  4128.      tables.
  4129.  
  4130.    * You cannot build the server in another directory when using
  4131.      MIT-pthreads. Because this requires changes to MIT-pthreads, we
  4132.      are not likely to fix this. *Note MIT-pthreads::.
  4133.  
  4134.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  4135.      or `DISTINCT'. Only the first `max_sort_length' bytes (default
  4136.      1024) are used when comparing `BLOB's in these cases.  This can be
  4137.      changed with the `-O max_sort_length' option to `mysqld'. A
  4138.      workaround for most cases is to use a substring: `SELECT DISTINCT
  4139.      LEFT(blob,2048) FROM tbl_name'.
  4140.  
  4141.    * Calculation is done with `BIGINT' or `DOUBLE' (both are normally
  4142.      64 bits long). It depends on the function which precision one
  4143.      gets. The general rule is that bit functions are done with `BIGINT'
  4144.      precision, `IF', and `ELT()' with `BIGINT' or `DOUBLE' precision
  4145.      and the rest with `DOUBLE' precision.  One should try to avoid
  4146.      using unsigned long long values if they resolve to be bigger than
  4147.      63 bits (9223372036854775807) for anything else than bit fields.
  4148.      MySQL Server 4.0 has better `BIGINT' handling than 3.23.
  4149.  
  4150.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  4151.      have all trailing spaces removed when retrieved. For `CHAR' types
  4152.      this is okay, and may be regarded as a feature according to
  4153.      SQL-92. The bug is that in MySQL Server, `VARCHAR' columns are
  4154.      treated the same way.
  4155.  
  4156.    * You can only have up to 255 `ENUM' and `SET' columns in one table.
  4157.  
  4158.    * In `MIN()', `MAX()' and other aggregate functions, MySQL currently
  4159.      compares `ENUM' and `SET' columns by their string value rather
  4160.      than by the string's relative position in the set.
  4161.  
  4162.    * `mysqld_safe' redirects all messages from `mysqld' to the `mysqld'
  4163.      log.  One problem with this is that if you execute `mysqladmin
  4164.      refresh' to close and reopen the log, `stdout' and `stderr' are
  4165.      still redirected to the old log.  If you use `--log' extensively,
  4166.      you should edit `mysqld_safe' to log to `'hostname'.err' instead
  4167.      of `'hostname'.log' so you can easily reclaim the space for the
  4168.      old log by deleting the old one and executing `mysqladmin refresh'.
  4169.  
  4170.    * In the `UPDATE' statement, columns are updated from left to right.
  4171.      If you refer to an updated column, you will get the updated value
  4172.      instead of the original value. For example:
  4173.  
  4174.           mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
  4175.  
  4176.      This will update `KEY' with `2' instead of with `1'.
  4177.  
  4178.    * You can't use temporary tables more than once in the same query.
  4179.      For example, the following doesn't work:
  4180.  
  4181.           mysql> SELECT * FROM temporary_table, temporary_table AS t2;
  4182.  
  4183.    * `RENAME' doesn't work with `TEMPORARY' tables or tables used in a
  4184.      `MERGE' table.
  4185.  
  4186.    * The optimiser may handle `DISTINCT' differently if you are using
  4187.      'hidden' columns in a join or not.  In a join, hidden columns are
  4188.      counted as part of the result (even if they are not shown) while in
  4189.      normal queries hidden columns don't participate in the `DISTINCT'
  4190.      comparison.  We will probably change this in the future to never
  4191.      compare the hidden columns when executing `DISTINCT'.
  4192.  
  4193.      An example of this is:
  4194.  
  4195.           SELECT DISTINCT mp3id FROM band_downloads
  4196.                  WHERE userid = 9 ORDER BY id DESC;
  4197.  
  4198.      and
  4199.  
  4200.           SELECT DISTINCT band_downloads.mp3id
  4201.                  FROM band_downloads,band_mp3
  4202.                  WHERE band_downloads.userid = 9
  4203.                  AND band_mp3.id = band_downloads.mp3id
  4204.                  ORDER BY band_downloads.id DESC;
  4205.  
  4206.      In the second case you may in MySQL Server 3.23.x get two
  4207.      identical rows in the result set (because the hidden `id' column
  4208.      may differ).
  4209.  
  4210.      Note that this happens only for queries where you don't have the
  4211.      ORDER BY columns in the result, something that you are not allowed
  4212.      to do in SQL-92.
  4213.  
  4214.    * Because MySQL Server allows you to work with table types that don't
  4215.      support transactions, and thus can't `rollback' data, some things
  4216.      behave a little differently in MySQL Server than in other SQL
  4217.      servers.  This is just to ensure that MySQL Server never needs to
  4218.      do a rollback for an SQL command.  This may be a little awkward at
  4219.      times as column values must be checked in the application, but
  4220.      this will actually give you a nice speed increase as it allows
  4221.      MySQL Server to do some optimisations that otherwise would be very
  4222.      hard to do.
  4223.  
  4224.      If you set a column to an incorrect value, MySQL Server will,
  4225.      instead of doing a rollback, store the `best possible value' in
  4226.      the column:
  4227.  
  4228.         - If you try to store a value outside the range in a numerical
  4229.           column, MySQL Server will instead store the smallest or
  4230.           biggest possible value in the column.
  4231.  
  4232.         - If you try to store a string that doesn't start with a number
  4233.           into a numerical column, MySQL Server will store 0 into it.
  4234.  
  4235.         - If you try to store `NULL' into a column that doesn't take
  4236.           `NULL' values, MySQL Server will store 0 or `''' (empty
  4237.           string) in it instead. (This behaviour can, however, be
  4238.           changed with the -DDONT_USE_DEFAULT_FIELDS compile option.)
  4239.  
  4240.         - MySQL allows you to store some wrong date values into `DATE'
  4241.           and `DATETIME' columns (like 2000-02-31 or 2000-02-00).  The
  4242.           idea is that it's not the SQL server job to validate date.
  4243.           If MySQL can store a date and retrieve exactly the same date,
  4244.           then MySQL will store the date. If the date is totally wrong
  4245.           (outside the server's ability to store it), then the special
  4246.           date value 0000-00-00 will be stored in the column.
  4247.  
  4248.         - If you set an `ENUM' column to an unsupported value, it will
  4249.           be set to the error value `empty string', with numeric value
  4250.           0.
  4251.  
  4252.         - If you set a `SET' column to an unsupported value, the value
  4253.           will be ignored.
  4254.  
  4255.  
  4256.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  4257.      in some cases the `PROCEDURE' will not transform the columns.
  4258.  
  4259.    * Creation of a table of type `MERGE' doesn't check if the underlying
  4260.      tables are of compatible types.
  4261.  
  4262.    * MySQL Server can't yet handle `NaN', `-Inf', and `Inf' values in
  4263.      double. Using these will cause problems when trying to export and
  4264.      import data. We should as an intermediate solution change `NaN' to
  4265.      `NULL' (if possible) and `-Inf' and `Inf' to the minimum
  4266.      respective maximum possible `double' value.
  4267.  
  4268.    * `LIMIT' on negative numbers are treated as big positive numbers.
  4269.  
  4270.    * If you use `ALTER TABLE' to first add a `UNIQUE' index to a table
  4271.      used in a `MERGE' table and then use `ALTER TABLE' to add a normal
  4272.      index on the `MERGE' table, the key order will be different for
  4273.      the tables if there was an old key that was not unique in the
  4274.      table. This is because `ALTER TABLE' puts `UNIQUE' keys before
  4275.      normal keys to be able to detect duplicate keys as early as
  4276.      possible.
  4277.  
  4278. The following are known bugs in earlier versions of MySQL:
  4279.  
  4280.    * You can get a hung thread if you do a `DROP TABLE' on a table that
  4281.      is one among many tables that is locked with `LOCK TABLES'.
  4282.  
  4283.    * In the following case you can get a core dump:
  4284.  
  4285.         - Delayed insert handler has pending inserts to a table.
  4286.  
  4287.         - `LOCK table' with `WRITE'.
  4288.  
  4289.         - `FLUSH TABLES'.
  4290.  
  4291.    * Before MySQL Server Version 3.23.2 an `UPDATE' that updated a key
  4292.      with a `WHERE' on the same key may have failed because the key was
  4293.      used to search for records and the same row may have been found
  4294.      multiple times:
  4295.  
  4296.           UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
  4297.  
  4298.      A workaround is to use:
  4299.  
  4300.           mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
  4301.  
  4302.      This will work because MySQL Server will not use an index on
  4303.      expressions in the `WHERE' clause.
  4304.  
  4305.    * Before MySQL Server Version 3.23, all numeric types were treated as
  4306.      fixed-point fields. That means you had to specify how many decimals
  4307.      a floating-point field shall have. All results were returned with
  4308.      the correct number of decimals.
  4309.  
  4310. For platform-specific bugs, see the sections about compiling and
  4311. porting.
  4312.  
  4313. MySQL and The Future (The TODO)
  4314. ===============================
  4315.  
  4316. This section summarises the features that we plan to implement in
  4317. `MySQL Server'. The lists are broken up per version, and the items are
  4318. approximately in the order they will be done.
  4319.  
  4320. *Note*: If you are an enterprise level user with an urgent need for a
  4321. particular feature, please contact <sales@mysql.com> to discuss
  4322. sponsoring options. Targeted financing by one or more companies allows
  4323. us to allocate additional resources for that specific purpose.  One
  4324. example of a feature sponsored in the past is replication.
  4325.  
  4326. New Features Planned For 4.1
  4327. ----------------------------
  4328.  
  4329. The features below are not yet implemented in MySQL 4.1, but are planned
  4330. for implementation before MySQL 4.1 moves into its beta phase.  For a
  4331. list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  4332. features::.
  4333.  
  4334.    * Stable OpenSSL support (MySQL 4.0 supports rudimentary, not 100%
  4335.      tested, support for OpenSSL).
  4336.  
  4337.    * Character set casts and syntax for handling multiple character
  4338.      sets.
  4339.  
  4340.    * More testing of prepared statements and multiple characters sets
  4341.      for one table.
  4342.  
  4343. Development of other things has already shifted to the 5.0 tree.
  4344.  
  4345. New Features Planned For 5.0
  4346. ----------------------------
  4347.  
  4348. The following features are planned for inclusion into MySQL 5.0.  Note
  4349. that because we have many developers that are working on different
  4350. projects, there will also be many additional features. There is also a
  4351. small chance that some of these features will be added to MySQL 4.1.
  4352. For a list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  4353. features::.
  4354.  
  4355. For those wishing to take a look at the bleeding edge of MySQL
  4356. development, we have already made our BitKeeper repository for MySQL
  4357. version 5.0 publically available.  *Note Installing source tree::.
  4358.  
  4359. Stored Procedures
  4360.         * Stored procedures are currently being implemented.  This
  4361.           effort is based on SQL-99, which has a basic syntax similar
  4362.           (but not identical) to Oracle PL/SQL. We will also implement
  4363.           the SQL-99 framework to hook in external languages, and
  4364.           (where possible) compatibility with, for example, PL/SQL and
  4365.           T-SQL.
  4366.  
  4367. New functionality
  4368.         * Elementary cursor support.
  4369.  
  4370.         * Visible `RTREE' index for MyISAM tables.  In 4.1 RTREE
  4371.           indexes are used internally for geometrical data, but not
  4372.           directly usable.
  4373.  
  4374.         * Dynamic length rows for HEAP tables.
  4375.  
  4376. Standards compliance, portability and migration
  4377.         * Add true `VARCHAR' support (there is already support for this
  4378.           in `MyISAM').
  4379.  
  4380. Speed enhancements
  4381.         * `SHOW COLUMNS FROM table_name' (used by `mysql' client to
  4382.           allow expansions of column names) should not open the table,
  4383.           only the definition file. This will require less memory and
  4384.           be much faster.
  4385.  
  4386.         * Allow `DELETE' on `MyISAM' tables to use the record cache.
  4387.           To do this, we need to update the threads record cache when
  4388.           we update the `.MYD' file.
  4389.  
  4390.         * Better in-memory (`HEAP') tables:
  4391.              * Dynamic size rows.
  4392.  
  4393.              * Faster row handling (less copying).
  4394.  
  4395. Internationalisation
  4396.         * When using `SET CHARACTER SET' we should translate the whole
  4397.           query at once and not only strings. This will enable users to
  4398.           use the translated characters in database, table, and column
  4399.           names.
  4400.  
  4401. Usability enhancements
  4402.         * Resolving the issue of `RENAME TABLE' on a table used in an
  4403.           active `MERGE' table possibly corrupting the table.
  4404.  
  4405. New Features Planned For 5.1
  4406. ----------------------------
  4407.  
  4408. New functionality
  4409.         * `FOREIGN KEY' support for all table types.
  4410.  
  4411.         * Column-level constraints.
  4412.  
  4413.         * Fail-safe replication.
  4414.  
  4415.         * Online backup with very low performance penalty.  The online
  4416.           backup will make it easy to add a new replication slave
  4417.           without taking down the master.
  4418.  
  4419. Speed enhancements
  4420.         * New text based table definition file format (`.frm' files)
  4421.           and a table cache for table definitions.  This will enable us
  4422.           to do faster queries of table structures and do more
  4423.           efficient foreign key support.
  4424.  
  4425.         * Optimise `BIT' type to take 1 bit (now `BIT' takes 1 char).
  4426.  
  4427. Usability enhancements
  4428.         * Add options to the client/server protocol to get progress
  4429.           notes for long running commands.
  4430.  
  4431.         * Implement `RENAME DATABASE'. To make this safe for all
  4432.           storage engines, it should work as follows:
  4433.              * Create the new database.
  4434.  
  4435.              * For every table do a rename of the table to another
  4436.                database, as we do with the `RENAME' command.
  4437.  
  4438.              * Drop the old database.
  4439.  
  4440.         * New internal file interface change.  This will make all file
  4441.           handling much more general and make it easier to add
  4442.           extensions like RAID.  (The current implementation is a hack.)
  4443.  
  4444. New Features Planned For The Near Future
  4445. ----------------------------------------
  4446.  
  4447. New functionality
  4448.         * Oracle-like `CONNECT BY PRIOR ...' to search tree-like
  4449.           (hierarchical) structures.
  4450.  
  4451.         * Add all missing SQL-92 and ODBC 3.0 types.
  4452.  
  4453.         * Add `SUM(DISTINCT)'.
  4454.  
  4455.         * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do
  4456.           a concurrent insert at the end of the file if the file is
  4457.           read-locked.
  4458.  
  4459.         * Allow update of variables in `UPDATE' statements. For example:
  4460.           `UPDATE TABLE foo SET @a=a+b,a=@a, b=@a+c'.
  4461.  
  4462.         * Change when user variables are updated so that one can use
  4463.           them with `GROUP BY', as in the following example: `SELECT
  4464.           id, @a:=COUNT(*), SUM(sum_col)/@a FROM table_name GROUP BY
  4465.           id'.
  4466.  
  4467.         * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  4468.           `TIMESTAMP' and `AUTO_INCREMENT' fields.
  4469.  
  4470.         * Added `LOAD DATA INFILE ... UPDATE' syntax.
  4471.              * For tables with primary keys, if the data contains the
  4472.                primary key, entries matching that primary key are
  4473.                updated from the remainder of the columns. However,
  4474.                columns *missing* from the incoming data feed are not
  4475.                touched.
  4476.  
  4477.              * For tables with primary keys that are missing some part
  4478.                of the key in the incoming data stream, or that have no
  4479.                primary key, the feed is treated as a `LOAD DATA INFILE
  4480.                ... REPLACE INTO' now.
  4481.  
  4482.         * Make `LOAD DATA INFILE' understand syntax like:
  4483.                LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
  4484.                     TEXT_FIELDS (text_field1, text_field2, text_field3)
  4485.                     SET table_field1=CONCAT(text_field1, text_field2),
  4486.                         table_field3=23
  4487.                     IGNORE text_field3
  4488.           This can be used to skip over extra columns in the text file,
  4489.           or update columns based on expressions of the read data.
  4490.  
  4491.         * New functions for working with `SET' type columns:
  4492.              * `ADD_TO_SET(value,set)'
  4493.  
  4494.              * `REMOVE_FROM_SET(value,set)'
  4495.  
  4496.         * If you abort `mysql' in the middle of a query, you should open
  4497.           another connection and kill the old running query.
  4498.           Alternatively, an attempt should be made to detect this in
  4499.           the server.
  4500.  
  4501.         * Add a storage engine interface for table information so that
  4502.           you can use it as a system table. This would be a bit slow if
  4503.           you requested information about all tables, but very
  4504.           flexible.  `SHOW INFO FROM tbl_name' for basic table
  4505.           information should be implemented.
  4506.  
  4507.         * Allow `SELECT a FROM crash_me LEFT JOIN crash_me2 USING (a)';
  4508.           in this case `a' is assumed to come from the `crash_me' table.
  4509.  
  4510.         * `DELETE' and `REPLACE' options to the `UPDATE' statement
  4511.           (this will delete rows when one gets a duplicate key error
  4512.           while updating).
  4513.  
  4514.         * Change the format of `DATETIME' to store fractions of seconds.
  4515.  
  4516.         * Make it possible to use the new GNU regexp library instead of
  4517.           the current one (the GNU library should be much faster than
  4518.           the old one).
  4519.  
  4520. Standards compliance, portability and migration
  4521.         * Don't add automatic `DEFAULT' values to columns.  Give an
  4522.           error when using an `INSERT' that doesn't contain a column
  4523.           that doesn't have a `DEFAULT'.
  4524.  
  4525.         * Add `ANY()', `EVERY()', and `SOME()' group functions. In
  4526.           standard SQL these work only on boolean columns, but we can
  4527.           extend these to work on any columns/expressions by applying:
  4528.           value == 0 -> FALSE and value <> 0 -> TRUE.
  4529.  
  4530.         * Fix that the type for `MAX(column)' is the same as the column
  4531.           type:
  4532.                mysql> CREATE TABLE t1 (a DATE);
  4533.                mysql> INSERT INTO t1 VALUES (NOW());
  4534.                mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
  4535.                mysql> SHOW COLUMNS FROM t2;
  4536.  
  4537. Speed enhancements
  4538.         * Don't allow more than a defined number of threads to run
  4539.           MyISAM recover at the same time.
  4540.  
  4541.         * Change `INSERT ... SELECT' to optionally use concurrent
  4542.           inserts.
  4543.  
  4544.         * Add an option to periodically flush key pages for tables with
  4545.           delayed keys if they haven't been used in a while.
  4546.  
  4547.         * Allow join on key parts (optimisation issue).
  4548.  
  4549.         * Add simulation of `pread()'/`pwrite()' on Windows to enable
  4550.           concurrent inserts.
  4551.  
  4552.         * A logfile analyser that could parse out information about
  4553.           which tables are hit most often, how often multi-table joins
  4554.           are executed, etc.  It should help users identify areas or
  4555.           table design that could be optimised to execute much more
  4556.           efficient queries.
  4557.  
  4558. Internationalisation
  4559.  
  4560. Usability enhancements
  4561.         * Return the original field types() when doing `SELECT
  4562.           MIN(column) ... GROUP BY'.
  4563.  
  4564.         * Make it possible to specify `long_query_time' with a
  4565.           granularity in microseconds.
  4566.  
  4567.         * Link the `myisampack' code into the server, enabling a PACK or
  4568.           COMPRESS command on the server.
  4569.  
  4570.         * Add a temporary key buffer cache during
  4571.           `INSERT/DELETE/UPDATE' so that we can gracefully recover if
  4572.           the index file gets full.
  4573.  
  4574.         * If you perform an `ALTER TABLE' on a table that is symlinked
  4575.           to another disk, create temporary tables on this disk.
  4576.  
  4577.         * Implement a `DATE/DATETIME' type that handles time zone
  4578.           information properly so that dealing with dates in different
  4579.           time zones is easier.
  4580.  
  4581.         * Fix configure so that one can compile all libraries (like
  4582.           `MyISAM') without threads.
  4583.  
  4584.         * Allow SQL variables in `LIMIT', like in `LIMIT @a,@b'.
  4585.  
  4586.         * Automatic output from `mysql' to a web browser.
  4587.  
  4588.         * `LOCK DATABASES' (with various options).
  4589.  
  4590.         * Many more variables for `SHOW STATUS'.  Records reads and
  4591.           updates.  Selects on 1 table and selects with joins.  Mean
  4592.           number of tables in select. Number of `ORDER BY' and `GROUP
  4593.           BY' queries.
  4594.  
  4595.         * `mysqladmin copy database new-database'; requires `COPY'
  4596.           command to be added to `mysqld'.
  4597.  
  4598.         * Processlist should show number of queries/threads.
  4599.  
  4600.         * `SHOW HOSTS' for printing information about the hostname
  4601.           cache.
  4602.  
  4603.         * Change table names from empty strings to `NULL' for
  4604.           calculated columns.
  4605.  
  4606.         * Don't use `Item_copy_string' on numerical values to avoid
  4607.           number->string->number conversion in case of: `SELECT
  4608.           COUNT(*)*(id+0) FROM table_name GROUP BY id'
  4609.  
  4610.         * Change so that `ALTER TABLE' doesn't abort clients that
  4611.           execute `INSERT DELAYED'.
  4612.  
  4613.         * Fix so that when columns are referenced in an `UPDATE' clause,
  4614.           they contain the old values from before the update started.
  4615.  
  4616. New operating systems
  4617.         * Port of the MySQL code to QNX.
  4618.  
  4619.         * Port of the MySQL code to BeOS.
  4620.  
  4621.         * Port of the MySQL clients to LynxOS.
  4622.  
  4623. New Features Planned For The Mid-Term Future
  4624. --------------------------------------------
  4625.  
  4626.    * Implement function:
  4627.      `get_changed_tables(timeout,table1,table2,...)'.
  4628.  
  4629.    * Change reading through tables to use memmap when possible. Now only
  4630.      compressed tables use memmap.
  4631.  
  4632.    * Make the automatic timestamp code nicer.  Add timestamps to the
  4633.      update log with `SET TIMESTAMP=#;'.
  4634.  
  4635.    * Use read/write mutex in some places to get more speed.
  4636.  
  4637.    * Simple views (stepwise implementation up to full functionality).
  4638.      *Note ANSI diff Views::.
  4639.  
  4640.    * Automatically close some tables if a table, temporary table, or
  4641.      temporary files gets error 23 (not enough open files).
  4642.  
  4643.    * When one finds a field=#, change all occurrences of field to #.
  4644.      Now this is only done for some simple cases.
  4645.  
  4646.    * Change all const expressions with calculated expressions if
  4647.      possible.
  4648.  
  4649.    * Optimise key = expression. At the moment only key = field or key =
  4650.      constant are optimised.
  4651.  
  4652.    * Join some of the copy functions for nicer code.
  4653.  
  4654.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  4655.      better error messages (5 days).
  4656.  
  4657.    * Change the parser to use only one rule per different number of
  4658.      arguments in function.
  4659.  
  4660.    * Use of full calculation names in the order part (for ACCESS97).
  4661.  
  4662.    * `MINUS', `INTERSECT', and `FULL OUTER JOIN'.  (Currently `UNION'
  4663.      [in 4.0] and `LEFT|RIGHT OUTER JOIN' are supported.)
  4664.  
  4665.    * `SQL_OPTION MAX_SELECT_TIME=#' to put a time limit on a query.
  4666.  
  4667.    * Make the update log write to a database.
  4668.  
  4669.    * Enhance `LIMIT' to allow retrieval of data from the end of a
  4670.      result set.
  4671.  
  4672.    * Alarm around client connect/read/write functions.
  4673.  
  4674.    * Please note the changes to `mysqld_safe': according to FSSTND
  4675.      (which Debian tries to follow) PID files should go into
  4676.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  4677.      be nice if you could put the "DATADIR" in the first declaration of
  4678.      "pidfile" and "log", so the placement of these files can be
  4679.      changed with a single statement.
  4680.  
  4681.    * Allow a client to request logging.
  4682.  
  4683.    * Add use of `zlib()' for `gzip'-ed files to `LOAD DATA INFILE'.
  4684.  
  4685.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  4686.  
  4687.    * Change to use semaphores when counting threads.  One should first
  4688.      implement a semaphore library to MIT-pthreads.
  4689.  
  4690.    * Don't assign a new `AUTO_INCREMENT' value when one sets a column
  4691.      to 0.  Use `NULL' instead.
  4692.  
  4693.    * Add full support for `JOIN' with parentheses.
  4694.  
  4695.    * As an alternative for one thread/connection manage a pool of
  4696.      threads to handle the queries.
  4697.  
  4698.    * Allow one to get more than one lock with `GET_LOCK'.  When doing
  4699.      this, one must also handle the possible deadlocks this change will
  4700.      introduce.
  4701.  
  4702. Time is given according to amount of work, not real time.
  4703.  
  4704. New Features We Don't Plan To Do
  4705. --------------------------------
  4706.  
  4707.    * Nothing; we aim toward full compliance with SQL-92/SQL-99.
  4708.  
  4709. How MySQL Compares to Other Databases
  4710. =====================================
  4711.  
  4712. Our users have successfully run their own benchmarks against a number
  4713. of `Open Source' and traditional database servers.  We are aware of
  4714. tests against `Oracle' server, `DB/2' server, `Microsoft SQL Server',
  4715. and other commercial products.  Due to legal reasons we are restricted
  4716. from publishing some of those benchmarks in our reference manual.
  4717.  
  4718. This section includes a comparison with `mSQL' for historical reasons
  4719. and with `PostgreSQL' as it is also an `Open Source' database. If you
  4720. have benchmark results that we can publish, please contact us at
  4721. <benchmarks@mysql.com>.
  4722.  
  4723. For comparative lists of all supported functions and types as well as
  4724. measured operational limits of many different database systems, see the
  4725. `crash-me' web page at `http://www.mysql.com/information/crash-me.php'.
  4726.  
  4727. How MySQL Compares to `mSQL'
  4728. ----------------------------
  4729.  
  4730. *Performance*
  4731.      For a true comparison of speed, consult the growing MySQL benchmark
  4732.      suite. *Note MySQL Benchmarks::.
  4733.  
  4734.      Because there is no thread creation overhead, a small parser, few
  4735.      features, and simple security, `mSQL' should be quicker at:
  4736.  
  4737.         * Tests that perform repeated connects and disconnects, running
  4738.           a very simple query during each connection.
  4739.  
  4740.         * `INSERT' operations into very simple tables with few columns
  4741.           and keys.
  4742.  
  4743.         * `CREATE TABLE' and `DROP TABLE'.
  4744.  
  4745.         * `SELECT' on something that isn't indexed. (A table scan is
  4746.           very easy.)
  4747.  
  4748.      Because these operations are so simple, it is hard to be better at
  4749.      them when you have a higher startup overhead. After the connection
  4750.      is established, MySQL Server should perform much better.
  4751.  
  4752.      On the other hand, MySQL Server is much faster than `mSQL' (and
  4753.      most other SQL implementations) on the following:
  4754.  
  4755.         * Complex `SELECT' operations.
  4756.  
  4757.         * Retrieving large results (MySQL Server has a better, faster,
  4758.           and safer protocol).
  4759.  
  4760.         * Tables with variable-length strings because MySQL Server has
  4761.           more efficient handling and can have indexes on `VARCHAR'
  4762.           columns.
  4763.  
  4764.         * Handling tables with many columns.
  4765.  
  4766.         * Handling tables with large record lengths.
  4767.  
  4768.         * `SELECT' with many expressions.
  4769.  
  4770.         * `SELECT' on large tables.
  4771.  
  4772.         * Handling many connections at the same time. MySQL Server is
  4773.           fully multi-threaded. Each connection has its own thread,
  4774.           which means that no thread has to wait for another (unless a
  4775.           thread is modifying a table another thread wants to access).
  4776.           In `mSQL', once one connection is established, all others
  4777.           must wait until the first has finished, regardless of whether
  4778.           the connection is running a query that is short or long. When
  4779.           the first connection terminates, the next can be served,
  4780.           while all the others wait again, etc.
  4781.  
  4782.         * Joins.  `mSQL' can become pathologically slow if you change
  4783.           the order of tables in a `SELECT'. In the benchmark suite, a
  4784.           time more than 15,000 times slower than MySQL Server was
  4785.           seen.  This is due to `mSQL''s lack of a join optimiser to
  4786.           order tables in the optimal order.  However, if you put the
  4787.           tables in exactly the right order in `mSQL'2 and the `WHERE'
  4788.           is simple and uses index columns, the join will be relatively
  4789.           fast.  *Note MySQL Benchmarks::.
  4790.  
  4791.         * `ORDER BY' and `GROUP BY'.
  4792.  
  4793.         * `DISTINCT'.
  4794.  
  4795.         * Using `TEXT' or `BLOB' columns.
  4796.  
  4797. *SQL Features*
  4798.         * `GROUP BY' and `HAVING'.  `mSQL' does not support `GROUP BY'
  4799.           at all.  MySQL Server supports a full `GROUP BY' with both
  4800.           `HAVING' and the following functions: `COUNT()', `AVG()',
  4801.           `MIN()', `MAX()', `SUM()', and `STD()'.  `COUNT(*)' is
  4802.           optimised to return very quickly if the `SELECT' retrieves
  4803.           from one table, no other columns are retrieved, and there is
  4804.           no `WHERE' clause.  `MIN()' and `MAX()' may take string
  4805.           arguments.
  4806.  
  4807.         * `INSERT' and `UPDATE' with calculations.  MySQL Server can do
  4808.           calculations in an `INSERT' or `UPDATE'.  For example:
  4809.  
  4810.                mysql> UPDATE SET x=x*10+y WHERE x<20;
  4811.  
  4812.         * Aliasing.  MySQL Server has column aliasing.
  4813.  
  4814.         * Qualifying column names.  In MySQL Server, if a column name
  4815.           is unique among the tables used in a query, you do not have
  4816.           to use the full qualifier.
  4817.  
  4818.         * `SELECT' with functions.  MySQL Server has many functions
  4819.           (too many to list here; see *Note Functions::).
  4820.  
  4821.  
  4822. *Disk Space Efficiency*
  4823.      That is, how small can you make your tables?
  4824.  
  4825.      MySQL Server has very precise types, so you can create tables that
  4826.      take very little space. An example of a useful MySQL data type is
  4827.      the `MEDIUMINT' that is 3 bytes long. If you have 100 million
  4828.      records, saving even 1 byte per record is very important.
  4829.  
  4830.      `mSQL2' has a more limited set of column types, so it is more
  4831.      difficult to get small tables.
  4832.  
  4833. *Stability*
  4834.      This is harder to judge objectively. For a discussion of MySQL
  4835.      Server stability, see *Note Stability::.
  4836.  
  4837.      We have no experience with `mSQL' stability, so we cannot say
  4838.      anything about that.
  4839.  
  4840. *Price*
  4841.      Another important issue is the license. MySQL Server has a more
  4842.      flexible license than `mSQL', and is also less expensive than
  4843.      `mSQL'.  Whichever product you choose to use, remember to at least
  4844.      consider paying for a license or e-mail support.
  4845.  
  4846. *Perl Interfaces*
  4847.      MySQL Server has basically the same interfaces to Perl as `mSQL'
  4848.      with some added features.
  4849.  
  4850. *JDBC (Java)*
  4851.      MySQL Server currently has a lot of different JDBC drivers:
  4852.  
  4853.         * MySQL Connector/J is a native Java driver.  Version 3.x is
  4854.           released under dual licensing (`GPL' and commercial).
  4855.  
  4856.         * The Resin driver: this is a commercial JDBC driver released
  4857.           under open source.
  4858.           `http://www.caucho.com/projects/jdbc-mysql/index.xtp'
  4859.  
  4860.         * The gwe driver: a Java interface by GWE technologies (no
  4861.           longer supported).
  4862.  
  4863.         * The jms driver: an improved gwe driver by Xiaokun Kelvin ZHU
  4864.           <X.Zhu@brad.ac.uk> (no longer supported).
  4865.  
  4866.         * The twz driver: a type 4 JDBC driver by Terrence W. Zellers
  4867.           <zellert@voicenet.com>.  This is commercial but is free for
  4868.           private and educational use (no longer supported).
  4869.  
  4870.      The recommended driver is MySQL Connector/J. The Resin driver may
  4871.      also be good (at least the benchmarks look good), but we haven't
  4872.      received that much information about this yet.
  4873.  
  4874.      We know that `mSQL' has a JDBC driver, but we have too little
  4875.      experience with it to compare.
  4876.  
  4877. *Rate of Development*
  4878.      MySQL Server has a small core team of developers, but we are quite
  4879.      used to coding C and C++ very rapidly. Because threads, functions,
  4880.      `GROUP BY', and so on are still not implemented in `mSQL', it has
  4881.      a lot of catching up to do. To get some perspective on this, you
  4882.      can view the `mSQL' `HISTORY' file for the last year and compare
  4883.      it with the News section of the MySQL Reference Manual (*note
  4884.      News::). It should be pretty obvious which one has developed most
  4885.      rapidly.
  4886.  
  4887. *Utility Programs*
  4888.      Both `mSQL' and MySQL Server have many interesting third-party
  4889.      tools. Because it is very easy to port upward (from `mSQL' to
  4890.      MySQL Server), almost all the interesting applications that are
  4891.      available for `mSQL' are also available for MySQL Server.
  4892.  
  4893.      MySQL Server comes with a simple `msql2mysql' program that fixes
  4894.      differences in spelling between `mSQL' and MySQL Server for the
  4895.      most-used C API functions.  For example, it changes instances of
  4896.      `msqlConnect()' to `mysql_connect()'. Converting a client program
  4897.      from `mSQL' to MySQL Server usually requires only minor effort.
  4898.  
  4899. How to Convert `mSQL' Tools for MySQL
  4900. .....................................
  4901.  
  4902. According to our experience, it doesn't take long to convert tools such
  4903. as `msql-tcl' and `msqljava' that use the `mSQL' C API so that they
  4904. work with the MySQL C API.
  4905.  
  4906. The conversion procedure is:
  4907.  
  4908.   1. Run the shell script `msql2mysql' on the source. This requires the
  4909.      `replace' program, which is distributed with MySQL Server.
  4910.  
  4911.   2. Compile.
  4912.  
  4913.   3. Fix all compiler errors.
  4914.  
  4915. Differences between the `mSQL' C API and the MySQL C API are:
  4916.  
  4917.    * MySQL Server uses a `MYSQL' structure as a connection type (`mSQL'
  4918.      uses an `int').
  4919.  
  4920.    * `mysql_connect()' takes a pointer to a `MYSQL' structure as a
  4921.      parameter.  It is easy to define one globally or to use `malloc()'
  4922.      to get one.  `mysql_connect()' also takes two parameters for
  4923.      specifying the user and password.  You may set these to `NULL,
  4924.      NULL' for default use.
  4925.  
  4926.    * `mysql_error()' takes the `MYSQL' structure as a parameter.  Just
  4927.      add the parameter to your old `msql_error()' code if you are
  4928.      porting old code.
  4929.  
  4930.    * MySQL Server returns an error number and a text error message for
  4931.      all errors. `mSQL' returns only a text error message.
  4932.  
  4933.    * Some incompatibilities exist as a result of MySQL Server supporting
  4934.      multiple connections to the server from the same process.
  4935.  
  4936. How `mSQL' and MySQL Client/Server Communications Protocols Differ
  4937. ..................................................................
  4938.  
  4939. There are enough differences that it is impossible (or at least not
  4940. easy) to support both.
  4941.  
  4942. The most significant ways in which the MySQL protocol differs from the
  4943. `mSQL' protocol are listed here:
  4944.  
  4945.    * A message buffer may contain many result rows.
  4946.  
  4947.    * The message buffers are dynamically enlarged if the query or the
  4948.      result is bigger than the current buffer, up to a configurable
  4949.      server and client limit.
  4950.  
  4951.    * All packets are numbered to catch duplicated or missing packets.
  4952.  
  4953.    * All column values are sent in ASCII. The lengths of columns and
  4954.      rows are sent in packed binary coding (1, 2, or 3 bytes).
  4955.  
  4956.    * MySQL can read in the result unbuffered (without having to store
  4957.      the full set in the client).
  4958.  
  4959.    * If a single read/write takes more than 30 seconds, the server
  4960.      closes the connection.
  4961.  
  4962.    * If a connection is idle for 8 hours, the server closes the
  4963.      connection.
  4964.  
  4965. How `mSQL' 2.0 SQL Syntax Differs from MySQL
  4966. ............................................
  4967.  
  4968. *Column types*
  4969.  
  4970. `MySQL Server'
  4971.      Has the following additional types (among others; *note `CREATE
  4972.      TABLE': CREATE TABLE.):
  4973.         * `ENUM' type for one of a set of strings.
  4974.  
  4975.         * `SET' type for many of a set of strings.
  4976.  
  4977.         * `BIGINT' type for 64-bit integers.
  4978.  
  4979. `'
  4980.      MySQL Server also supports the following additional type
  4981.      attributes:
  4982.         * `UNSIGNED' option for integer and floating-point columns.
  4983.  
  4984.         * `ZEROFILL' option for integer columns.
  4985.  
  4986.         * `AUTO_INCREMENT' option for integer columns that are a
  4987.           `PRIMARY KEY'.  *Note `mysql_insert_id()': mysql_insert_id.
  4988.  
  4989.         * `DEFAULT' value for all columns.
  4990.  
  4991. `mSQL2'
  4992.      `mSQL' column types correspond to the MySQL types shown in the
  4993.      following table:
  4994.      `mSQL'     *Corresponding MySQL type*
  4995.      *type*     
  4996.      `CHAR(len)'`CHAR(len)'
  4997.      `TEXT(len)'`TEXT(len)'. `len' is the maximal length.  And
  4998.                 `LIKE' works.
  4999.      `INT'      `INT'. With many more options.
  5000.      `REAL'     `REAL'. Or `FLOAT'. Both 4- and 8-byte
  5001.                 versions are available.
  5002.      `UINT'     `INT UNSIGNED'
  5003.      `DATE'     `DATE'. Uses SQL-99 format rather than
  5004.                 `mSQL''s own format.
  5005.      `TIME'     `TIME'
  5006.      `MONEY'    `DECIMAL(12,2)'. A fixed-point value with two
  5007.                 decimals.
  5008.  
  5009. *Index Creation*
  5010.  
  5011. `MySQL Server'
  5012.      Indexes may be specified at table creation time with the `CREATE
  5013.      TABLE' statement.
  5014.  
  5015. `mSQL'
  5016.      Indexes must be created after the table has been created, with
  5017.      separate `CREATE INDEX' statements.
  5018.  
  5019. *To Insert a Unique Identifier into a Table*
  5020.  
  5021. `MySQL Server'
  5022.      Use `AUTO_INCREMENT' as a column type specifier.  *Note
  5023.      `mysql_insert_id()': mysql_insert_id.
  5024.  
  5025. `mSQL'
  5026.      Create a `SEQUENCE' on a table and select the `_seq' column.
  5027.  
  5028. *To Obtain a Unique Identifier for a Row*
  5029.  
  5030. `MySQL Server'
  5031.      Add a `PRIMARY KEY' or `UNIQUE' key to the table and use this.
  5032.      New in Version 3.23.11: If the `PRIMARY' or `UNIQUE' key consists
  5033.      of only one column and this is of type integer, one can also refer
  5034.      to it as `_rowid'.
  5035.  
  5036. `mSQL'
  5037.      Use the `_rowid' column. Observe that `_rowid' may change over time
  5038.      depending on many factors.
  5039.  
  5040. *To Get the Time a Column Was Last Modified*
  5041.  
  5042. `MySQL Server'
  5043.      Add a `TIMESTAMP' column to the table. This column is
  5044.      automatically set to the current date and time for `INSERT' or
  5045.      `UPDATE' statements if you don't give the column a value or if you
  5046.      give it a `NULL' value.
  5047.  
  5048. `mSQL'
  5049.      Use the `_timestamp' column.
  5050.  
  5051. *`NULL' Value Comparisons*
  5052.  
  5053. `MySQL Server'
  5054.      MySQL Server complies with standard SQL, and a comparison with
  5055.      `NULL' is always `UNKNOWN'.
  5056.  
  5057. `mSQL'
  5058.      In `mSQL', `NULL = NULL' is TRUE.  You must change `=NULL' to `IS
  5059.      NULL' and `<>NULL' to `IS NOT NULL' when porting old code from
  5060.      `mSQL' to MySQL Server.
  5061.  
  5062. *String Comparisons*
  5063.  
  5064. `MySQL Server'
  5065.      Normally, string comparisons are performed in case-independent
  5066.      fashion with the sort order determined by the current character
  5067.      set (ISO-8859-1 Latin1 by default).  If you don't like this,
  5068.      declare your columns with the `BINARY' attribute, which causes
  5069.      comparisons to be done according to the ASCII order used on the
  5070.      MySQL server host.
  5071.  
  5072. `mSQL'
  5073.      All string comparisons are performed in case-sensitive fashion with
  5074.      sorting in ASCII order.
  5075.  
  5076. *Case-insensitive Searching*
  5077.  
  5078. `MySQL Server'
  5079.      `LIKE' is a case-insensitive or case-sensitive operator, depending
  5080.      on the columns involved. If possible, MySQL uses indexes if the
  5081.      `LIKE' argument doesn't start with a wildcard character.
  5082.  
  5083. `mSQL'
  5084.      Use `CLIKE'.
  5085.  
  5086. *Handling of Trailing Spaces*
  5087.  
  5088. `MySQL Server'
  5089.      Strips all spaces at the end of `CHAR' and `VARCHAR' columns. Use
  5090.      a `TEXT' column if this behaviour is not desired.
  5091.  
  5092. `mSQL'
  5093.      Retains trailing space.
  5094.  
  5095. *`WHERE' Clauses*
  5096.  
  5097. `MySQL Server'
  5098.      MySQL correctly prioritises everything (`AND' is evaluated before
  5099.      `OR'). To get `mSQL' behaviour in MySQL Server, use parentheses
  5100.      (as shown in an example later in this section).
  5101.  
  5102. `mSQL'
  5103.      Evaluates everything from left to right. This means that some
  5104.      logical calculations with more than three arguments cannot be
  5105.      expressed in any way. It also means you must change some queries
  5106.      when you upgrade to MySQL Server. You do this easily by adding
  5107.      parentheses.  Suppose you have the following `mSQL' query:
  5108.           mysql> SELECT * FROM table WHERE a=1 AND b=2 OR a=3 AND b=4;
  5109.      To make MySQL Server evaluate this the way that `mSQL' would, you
  5110.      must add parentheses:
  5111.           mysql> SELECT * FROM table WHERE (a=1 AND (b=2 OR (a=3 AND (b=4))));
  5112.  
  5113. *Access Control*
  5114.  
  5115. `MySQL Server'
  5116.      Has tables to store grant (permission) options per user, host, and
  5117.      database. *Note Privileges::.
  5118.  
  5119. `mSQL'
  5120.      Has a file `mSQL.acl' in which you can grant read/write privileges
  5121.      for users.
  5122.  
  5123. How MySQL Compares to `PostgreSQL'
  5124. ----------------------------------
  5125.  
  5126. When reading the following, please note that both products are
  5127. continually evolving.  MySQL AB's and PostgreSQL's developers are both
  5128. working on making our respective databases as good as possible.  Both
  5129. products are thus a serious alternative to any commercial database.
  5130.  
  5131. The following comparison is made by us at MySQL AB.  We have tried to be
  5132. as accurate and fair as possible, but although we know MySQL Server
  5133. thoroughly, we don't have a full knowledge of all PostgreSQL features,
  5134. so we may have got some things wrong.  We will, however, correct these
  5135. when they come to our attention.
  5136.  
  5137. We would first like to note that PostgreSQL and MySQL Server are both
  5138. widely used products, but with different design goals, even if we are
  5139. both striving toward SQL standard compliance.  This means that for some
  5140. applications MySQL Server is more suited, while for others PostgreSQL
  5141. is more suited.  When choosing which database to use, you should first
  5142. check if the database's feature set satisfies your application.  If you
  5143. need raw speed, MySQL Server is probably your best choice.  If you need
  5144. some of the extra features that only PostgreSQL can offer, you should
  5145. use `PostgreSQL'.
  5146.  
  5147. MySQL and PostgreSQL development strategies
  5148. ...........................................
  5149.  
  5150. When adding things to MySQL Server we take pride to do an optimal,
  5151. definite solution.  The code should be so good that we shouldn't have
  5152. any need to change it in the foreseeable future.  We also do not like
  5153. to sacrifice speed for features but instead will do our utmost to find
  5154. a solution that will give maximal throughput.  This means that
  5155. development will take a little longer, but the end result will be well
  5156. worth this.  This kind of development is only possible because all
  5157. server code is checked by one of a few (currently two) persons before
  5158. it's included in the MySQL server.
  5159.  
  5160. We at MySQL AB believe in frequent releases to be able to push out new
  5161. features quickly to our users.  Because of this we do a new small
  5162. release about every three weeks, and a major branch every year.  All
  5163. releases are thoroughly tested with our testing tools on a lot of
  5164. different platforms.
  5165.  
  5166. PostgreSQL is based on a kernel with lots of contributors. In this setup
  5167. it makes sense to prioritise adding a lot of new features, instead of
  5168. implementing them optimally, because one can always optimise things
  5169. later if there arises a need for this.
  5170.  
  5171. Another big difference between MySQL Server and PostgreSQL is that
  5172. nearly all of the code in the MySQL server is coded by developers that
  5173. are employed by MySQL AB and are still working on the server code. The
  5174. exceptions are the transaction engines and the regexp library.
  5175.  
  5176. This is in sharp contrast to the PostgreSQL code, the majority of which
  5177. is coded by a big group of people with different backgrounds.  It was
  5178. only recently that the PostgreSQL developers announced that their
  5179. current developer group had finally had time to take a look at all the
  5180. code in the current PostgreSQL release.
  5181.  
  5182. Both of the aforementioned development methods have their own merits
  5183. and drawbacks.  We here at MySQL AB think, of course, that our model is
  5184. better because our model gives better code consistency, more optimal
  5185. and reusable code, and in our opinion, fewer bugs.  Because we are the
  5186. authors of the MySQL server code, we are better able to coordinate new
  5187. features and releases.
  5188.  
  5189. Featurewise Comparison of MySQL and PostgreSQL
  5190. ..............................................
  5191.  
  5192. On the `crash-me' page (`http://www.mysql.com/information/crash-me.php')
  5193. you can find a list of those database constructs and limits that one
  5194. can detect automatically with a program.  Note, however, that a lot of
  5195. the numerical limits may be changed with startup options for their
  5196. respective databases.  This web page is, however, extremely useful when
  5197. you want to ensure that your applications work with many different
  5198. databases or when you want to convert your application from one
  5199. database to another.
  5200.  
  5201. MySQL Server offers the following advantages over PostgreSQL:
  5202.  
  5203.    * `MySQL' Server is generally much faster than PostgreSQL.  MySQL
  5204.      4.0.1 also has a query cache that can boost up the query speed for
  5205.      mostly-read-only sites many times.
  5206.  
  5207.    * MySQL has a much larger user base than PostgreSQL. Therefore, the
  5208.      code is tested more and has historically proven more stable than
  5209.      PostgreSQL.  MySQL Server is used more in production environments
  5210.      than PostgreSQL, mostly thanks to the fact that MySQL AB, formerly
  5211.      TCX DataKonsult AB, has provided top-quality commercial support
  5212.      for MySQL Server from the day it was released, whereas until
  5213.      recently PostgreSQL was unsupported.
  5214.  
  5215.    * MySQL Server works better on Windows than PostgreSQL does.  MySQL
  5216.      Server runs as a native Windows application (a service on
  5217.      NT/2000/XP), while PostgreSQL is run under the `Cygwin' emulation.
  5218.      We have heard that PostgreSQL is not yet that stable on Windows
  5219.      but we haven't been able to verify this ourselves.
  5220.  
  5221.    * MySQL has more APIs to other languages and is supported by more
  5222.      existing programs than PostgreSQL.  *Note Contrib::.
  5223.  
  5224.    * MySQL Server works on 24/7 heavy-duty systems.  In most
  5225.      circumstances you never have to run any cleanups on MySQL Server.
  5226.      PostgreSQL doesn't yet support 24/7 systems because you have to
  5227.      run `VACUUM' once in a while to reclaim space from `UPDATE' and
  5228.      `DELETE' commands and to perform statistics analyses that are
  5229.      critical to get good performance with PostgreSQL.  `VACUUM' is
  5230.      also needed after adding a lot of new rows to a table.  On a busy
  5231.      system with lots of changes, `VACUUM' must be run very frequently,
  5232.      in the worst cases even many times a day.  During the `VACUUM'
  5233.      run, which may take hours if the database is big, the database is,
  5234.      from a production standpoint, practically dead. Please note: in
  5235.      PostgreSQL version 7.2, basic vacuuming no longer locks tables,
  5236.      thus allowing normal user access during the vacuum.  A new `VACUUM
  5237.      FULL' command does old-style vacuum by locking the table and
  5238.      shrinking the on-disk copy of the table.
  5239.  
  5240.    * MySQL replication has been thoroughly tested, and is used by sites
  5241.      like:
  5242.         - Yahoo Finance (`http://finance.yahoo.com/')
  5243.  
  5244.         - Mobile.de (`http://www.mobile.de/')
  5245.  
  5246.         - Slashdot (`http://www.slashdot.org/')
  5247.  
  5248.    * Included in the MySQL distribution are two different testing
  5249.      suites, `mysql-test-run' and `crash-me'
  5250.      (`http://www.mysql.com/information/crash-me.php'), as well as a
  5251.      benchmark suite.  The test system is actively updated with code to
  5252.      test each new feature and almost all reproducible bugs that have
  5253.      come to our attention.  We test MySQL Server with these on a lot
  5254.      of platforms before every release.  These tests are more
  5255.      sophisticated than anything we have seen from PostgreSQL, and they
  5256.      ensure that the MySQL Server is kept to a high standard.
  5257.  
  5258.    * There are far more books in print about MySQL Server than about
  5259.      PostgreSQL.  O'Reilly, SAMS, Que, and New Riders are all major
  5260.      publishers with books about MySQL.  All MySQL features are also
  5261.      documented in the MySQL online manual because when a new feature
  5262.      is implemented, the MySQL developers are required to document it
  5263.      before it's included in the source.
  5264.  
  5265.    * MySQL Server supports more of the standard ODBC functions than
  5266.      `PostgreSQL'.
  5267.  
  5268.    * MySQL Server has a much more sophisticated `ALTER TABLE'.
  5269.  
  5270.    * MySQL Server has support for tables without transactions for
  5271.      applications that need all the speed they can get. The tables may
  5272.      be memory-based, `HEAP' tables or disk based `MyISAM'.  *Note
  5273.      Table types::.
  5274.  
  5275.    * MySQL Server has support for two different storage engines that
  5276.      support transactions, `InnoDB', and `BerkeleyDB'.  Because every
  5277.      transaction engine performs differently under different
  5278.      conditions, this gives the application writer more options to find
  5279.      an optimal solution for his or her setup, if need be per
  5280.      individual table.  *Note Table types::.
  5281.  
  5282.    * `MERGE' tables gives you a unique way to instantly make a view over
  5283.      a set of identical tables and use these as one.  This is perfect
  5284.      for systems where you have log files that you order, for example,
  5285.      by month.  *Note MERGE::.
  5286.  
  5287.    * The option to compress read-only tables, but still have direct
  5288.      access to the rows in the table, gives you better performance by
  5289.      minimising disk reads.  This is very useful when you are archiving
  5290.      things.  *Note `myisampack': myisampack.
  5291.  
  5292.    * MySQL Server has internal support for full-text search. *Note
  5293.      Fulltext Search::.
  5294.  
  5295.    * You can access many databases from the same connection (depending,
  5296.      of course, on your privileges).
  5297.  
  5298.    * MySQL Server is coded from the start to be multi-threaded, while
  5299.      PostgreSQL uses processes.  Context switching and access to common
  5300.      storage areas is much faster between threads than between separate
  5301.      processes. This gives MySQL Server a big speed advantage in
  5302.      multi-user applications and also makes it easier for MySQL Server
  5303.      to take full advantage of symmetric multiprocessor (SMP) systems.
  5304.  
  5305.    * MySQL Server has a much more sophisticated privilege system than
  5306.      PostgreSQL.  While PostgreSQL only supports `INSERT', `SELECT',
  5307.      and `UPDATE/DELETE' grants per user on a database or a table,
  5308.      MySQL Server allows you to define a full set of different
  5309.      privileges on the database, table, and column level.  MySQL Server
  5310.      also allows you to specify the privilege on host and user
  5311.      combinations.  *Note GRANT::.
  5312.  
  5313.    * MySQL Server supports a compressed client/server protocol which
  5314.      improves performance over slow links.
  5315.  
  5316.    * MySQL Server employs a "storage engine" concept, and is the only
  5317.      relational database we know of built around this concept.  This
  5318.      allows different low-level table types to be called from the SQL
  5319.      engine, and each table type can be optimised for different
  5320.      performance characteristics.
  5321.  
  5322.    * All MySQL table types (except `InnoDB') are implemented as files
  5323.      (one table per file), which makes it really easy to back up, move,
  5324.      delete, and even symlink databases and tables, even when the
  5325.      server is down.
  5326.  
  5327.    * Tools exist to repair and optimise `MyISAM' tables (the most common
  5328.      MySQL table type).  A repair tool is only needed when a physical
  5329.      corruption of a datafile happens, usually from a hardware failure.
  5330.      It allows a majority of the data to be recovered.
  5331.  
  5332.    * Upgrading MySQL Server is painless.  When you are upgrading MySQL
  5333.      Server, you don't need to dump/restore your data, as you have to
  5334.      do with most PostgreSQL upgrades.
  5335.  
  5336. Drawbacks with MySQL Server compared to PostgreSQL:
  5337.  
  5338.    * Because MySQL Server uses threads, which are not yet flawless on
  5339.      many OSs, one must either use binaries from
  5340.      `http://www.mysql.com/downloads/', or carefully follow our
  5341.      instructions in *Note Installing source:: to get an optimal binary
  5342.      that works in all cases.
  5343.  
  5344.    * Table locking, as used by the non-transactional `MyISAM' tables, is
  5345.      in many cases faster than page locks, row locks, or versioning.
  5346.      The drawback, however, is that if one doesn't take into account
  5347.      how table locks work, a single long-running query can block a
  5348.      table for updates for a long time. This can usually be avoided
  5349.      when designing the application.  If not, one can always switch the
  5350.      trouble table to use one of the transactional table types. *Note
  5351.      Table locking::.
  5352.  
  5353.    * With UDF (user-defined functions) one can extend MySQL Server with
  5354.      both normal SQL functions and aggregates, but this is not yet as
  5355.      easy or as flexible as in PostgreSQL.  *Note Adding functions::.
  5356.  
  5357.    * Updates that run over multiple tables used to be harder to do in
  5358.      MySQL Server. However, this has been fixed in MySQL Server 4.0.2
  5359.      with multi-table `UPDATE' and in MySQL Server 4.1 with subqueries.
  5360.      In MySQL Server 4.0 one can use multi-table deletes to delete from
  5361.      many tables at the same time. *Note DELETE::.
  5362.  
  5363. PostgreSQL currently offers the following advantages over MySQL Server:
  5364.  
  5365. Note that because we know the MySQL road map, we have included in the
  5366. following table the version when MySQL Server should support this
  5367. feature.  Unfortunately we couldn't do this for previous comparisons,
  5368. because we don't know the PostgreSQL roadmap.
  5369.  
  5370. *Feature*              *MySQL version*
  5371. Subqueries             4.1
  5372. Foreign keys           5.1 (3.23 with InnoDB)
  5373. Views                  5.1
  5374. Stored procedures      5.0
  5375. Triggers               5.1
  5376. Unions                 4.0
  5377. Full outer join        5.1
  5378. Constraints            5.1
  5379. Cursors                5.0
  5380. R-trees                4.1 (for MyISAM
  5381.                        tables)
  5382. Inherited tables       Not planned
  5383. Extensible type        Not planned
  5384. system                 
  5385.  
  5386. Other reasons someone may consider using PostgreSQL:
  5387.  
  5388.    * Standard usage in PostgreSQL is closer to standard SQL in some
  5389.      cases.
  5390.  
  5391.    * One can speed up PostgreSQL by coding things as stored procedures.
  5392.  
  5393.    * The PostgreSQL optimiser can do some optimisation that the current
  5394.      MySQL optimiser can't do.  Most notable is doing joins when you
  5395.      don't have the proper keys in place and doing a join where you are
  5396.      using different keys combined with OR.  The MySQL benchmark suite
  5397.      at `http://www.mysql.com/information/benchmarks.html' shows you
  5398.      what kind of constructs you should watch out for when using
  5399.      different databases.
  5400.  
  5401.    * PostgreSQL has a bigger team of developers that contribute to the
  5402.      server.
  5403.  
  5404. Drawbacks with PostgreSQL compared to MySQL Server:
  5405.  
  5406.    * `VACUUM' makes PostgreSQL hard to use in a 24/7 environment.
  5407.  
  5408.    * Only transactional tables.
  5409.  
  5410.    * Much slower `INSERT', `DELETE', and `UPDATE'.
  5411.  
  5412. For a complete list of drawbacks, you should also examine the first
  5413. table in this section.
  5414.  
  5415. Benchmarking MySQL and PostgreSQL
  5416. .................................
  5417.  
  5418. The only `Open Source' benchmark that we know of that can be used to
  5419. benchmark MySQL Server and PostgreSQL (and other databases) is our own.
  5420. It can be found at `http://www.mysql.com/information/benchmarks.html'.
  5421.  
  5422. We have many times asked the PostgreSQL developers and some PostgreSQL
  5423. users to help us extend this benchmark to make it the definitive
  5424. benchmark for databases, but unfortunately we haven't gotten any
  5425. feedback for this.
  5426.  
  5427. We, the MySQL developers, have, because of this, spent a lot of hours
  5428. to get maximum performance from PostgreSQL for the benchmarks, but
  5429. because we don't know PostgreSQL intimately, we are sure that there are
  5430. things that we have missed.  We have on the benchmark page documented
  5431. exactly how we did run the benchmark so that it should be easy for
  5432. anyone to repeat and verify our results.
  5433.  
  5434. The benchmarks are usually run with and without the `--fast' option.
  5435. When run with `--fast' we are trying to use every trick the server can
  5436. do to get the code to execute as fast as possible.  The idea is that the
  5437. normal run should show how the server would work in a default setup and
  5438. the `--fast' run shows how the server would do if the application
  5439. developer would use extensions in the server to make his application run
  5440. faster.
  5441.  
  5442. When running with PostgreSQL and `--fast' we do a `VACUUM' after every
  5443. major table `UPDATE' and `DROP TABLE' to make the database in perfect
  5444. shape for the following `SELECT's.  The time for `VACUUM' is measured
  5445. separately.
  5446.  
  5447. When running with PostgreSQL 7.1.1 we could, however, not run with
  5448. `--fast' because during the `INSERT' test, the postmaster (the
  5449. PostgreSQL daemon) died and the database was so corrupted that it was
  5450. impossible to restart postmaster.  After this happened twice, we decided
  5451. to postpone the `--fast' test until the next PostgreSQL release.  The
  5452. details about the machine we run the benchmark on can be found on the
  5453. benchmark page.
  5454.  
  5455. Before going to the other benchmarks we know of, we would like to give
  5456. some background on benchmarks.
  5457.  
  5458. It's very easy to write a test that shows *any* database to be the best
  5459. database in the world, by just restricting the test to something the
  5460. database is very good at and not testing anything that the database is
  5461. not good at.  If one, after doing this, summarises the result as a
  5462. single figure, things are even easier.
  5463.  
  5464. This would be like us measuring the speed of MySQL Server compared to
  5465. PostgreSQL by looking at the summary time of the MySQL benchmarks on
  5466. our web page.  Based on this MySQL Server would be more than 40 times
  5467. faster than PostgreSQL, something that is, of course, not true.  We
  5468. could make things even worse by just taking the test where PostgreSQL
  5469. performs worst and claim that MySQL Server is more than 2000 times
  5470. faster than PostgreSQL.
  5471.  
  5472. The case is that MySQL does a lot of optimisations that PostgreSQL
  5473. doesn't do. This is, of course, also true the other way around.  An SQL
  5474. optimiser is a very complex thing, and a company could spend years just
  5475. making the optimiser faster and faster.
  5476.  
  5477. When looking at the benchmark results you should look for things that
  5478. you do in your application and just use these results to decide which
  5479. database would be best suited for your application.  The benchmark
  5480. results also show things a particular database is not good at and should
  5481. give you a notion about things to avoid and what you may have to do in
  5482. other ways.
  5483.  
  5484. We know of two benchmark tests that claim that PostgreSQL performs
  5485. better than MySQL Server.  These are both multi-user tests, a test that
  5486. we here at MySQL AB haven't had time to write and include in the
  5487. benchmark suite, mainly because it's a big task to do this in a manner
  5488. that is fair to all databases.
  5489.  
  5490. One is the benchmark paid for by Great Bridge, the company that for 16
  5491. months attempted to build a business based on PostgreSQL but now has
  5492. ceased operations. This is probably the worst benchmark we have ever
  5493. seen anyone conduct.  This was not only tuned to only test what
  5494. PostgreSQL is absolutely best at, but it was also totally unfair to
  5495. every other database involved in the test.
  5496.  
  5497. *Note*:  We know that even some of the main PostgreSQL developers did
  5498. not like the way Great Bridge conducted the benchmark, so we don't
  5499. blame the PostgreSQL team for the way the benchmark was done.
  5500.  
  5501. This benchmark has been condemned in a lot of postings and newsgroups,
  5502. so here we will just briefly repeat some things that were wrong with it.
  5503.  
  5504.    * The tests were run with an expensive commercial tool that makes it
  5505.      impossible for an `Open Source' company like us to verify the
  5506.      benchmarks, or even check how the benchmarks were really done.
  5507.      The tool is not even a true benchmark tool, but an
  5508.      application/setup testing tool.  To refer to this as a "standard"
  5509.      benchmark tool is to stretch the truth a long way.
  5510.  
  5511.    * Great Bridge admitted that they had optimised the PostgreSQL
  5512.      database (with `VACUUM' before the test) and tuned the startup for
  5513.      the tests, something they hadn't done for any of the other
  5514.      databases involved.  They say "This process optimises indexes and
  5515.      frees up disk space a bit.  The optimised indexes boost
  5516.      performance by some margin."  Our benchmarks clearly indicate that
  5517.      the difference in running a lot of selects on a database with and
  5518.      without `VACUUM' can easily differ by a factor of 10.
  5519.  
  5520.    * The test results were also strange.  The AS3AP test documentation
  5521.      mentions that the test does "selections, simple joins, projections,
  5522.      aggregates, one-tuple updates, and bulk updates."
  5523.  
  5524.      PostgreSQL is good at doing `SELECT's and `JOIN's (especially
  5525.      after a `VACUUM'), but doesn't perform as well on `INSERT's or
  5526.      `UPDATE's.  The benchmarks seem to indicate that only `SELECT's
  5527.      were done (or very few updates).  This could easily explain the
  5528.      good results for PostgreSQL in this test.  The bad results for
  5529.      MySQL will be obvious a bit down in this document.
  5530.  
  5531.    * They did run the so-called benchmark from a Windows machine
  5532.      against a Linux machine over ODBC, a setup that no normal database
  5533.      user would ever do when running a heavy multi-user application.
  5534.      This tested more the ODBC driver and the Windows protocol used
  5535.      between the clients than the database itself.
  5536.  
  5537.    * When running the database against Oracle and MS-SQL (Great Bridge
  5538.      has indirectly indicated the databases they used in the test), they
  5539.      didn't use the native protocol but instead ODBC.  Anyone that has
  5540.      ever used Oracle knows that all real applications use the native
  5541.      interface instead of ODBC.  Doing a test through ODBC and claiming
  5542.      that the results had anything to do with using the database in a
  5543.      real-world situation can't be regarded as fair.  They should have
  5544.      done two tests with and without ODBC to provide the right facts
  5545.      (after having gotten experts to tune all involved databases, of
  5546.      course).
  5547.  
  5548.    * They refer to the TPC-C tests, but they don't mention anywhere
  5549.      that the test they did was not a true TPC-C test and they were not
  5550.      even allowed to call it a TPC-C test.  A TPC-C test can only be
  5551.      conducted by the rules approved by the TPC Council
  5552.      (`http://www.tpc.org/'). Great Bridge didn't do that.  By doing
  5553.      this they have both violated the TPC trademark and miscredited
  5554.      their own benchmarks.  The rules set by the TPC Council are very
  5555.      strict to ensure that no one can produce false results or make
  5556.      unprovable statements.  Apparently Great Bridge wasn't interested
  5557.      in doing this.
  5558.  
  5559.    * After the first test, we contacted Great Bridge and mentioned to
  5560.      them some of the obvious mistakes they had done with MySQL Server:
  5561.  
  5562.         - Running with a debug version of our ODBC driver
  5563.  
  5564.         - Running on a Linux system that wasn't optimised for threads
  5565.  
  5566.         - Using an old MySQL version when there was a recommended newer
  5567.           one available
  5568.  
  5569.         - Not starting MySQL Server with the right options for heavy
  5570.           multi-user use (the default installation of MySQL Server is
  5571.           tuned for minimal resource use)
  5572.  
  5573.      Great Bridge did run a new test, with our optimised ODBC driver
  5574.      and with better startup options for MySQL Server, but refused to
  5575.      either use our updated glibc library or our standard binary (used
  5576.      by 80% of our users), which was statically linked with a fixed
  5577.      glibc library.
  5578.  
  5579.      From what we are able to determine, Great Bridge did nothing to
  5580.      ensure that the other databases were set up correctly to run well
  5581.      in their test environment.  We are sure, however, that they didn't
  5582.      contact Oracle or Microsoft to ask for their advice in this matter.
  5583.  
  5584.    * The benchmark was paid for by Great Bridge, and they decided to
  5585.      publish only partial, chosen results (instead of publishing it
  5586.      all).
  5587.  
  5588. Tim Perdue, a long-time PostgreSQL fan and a reluctant MySQL user,
  5589. published a comparison on PHPbuilder
  5590. (`http://www.phpbuilder.com/columns/tim20001112.php3').
  5591.  
  5592. When we became aware of the comparison, we phoned Tim Perdue about this
  5593. because there were a lot of strange things in his results.  For example,
  5594. he claimed that MySQL Server had a problem with five users in his
  5595. tests, when we know that there are users with similar machines running
  5596. MySQL Server with 2000 simultaneous connections doing 400 queries per
  5597. second.  (In this case the limit was the web bandwidth, not the
  5598. database.)
  5599.  
  5600. It sounded like he was using a Linux kernel that had some problems with
  5601. many threads, such as kernels before 2.4, which had a problem with many
  5602. threads on multi-CPU machines. This manual describes the fix for this
  5603. and Tim should be aware of this problem.
  5604.  
  5605. The other possible problem could have been an old glibc library and
  5606. that Tim didn't use a MySQL binary from our site, which is linked with
  5607. a corrected glibc library, but had compiled a version of his own.  In
  5608. any of these cases, the symptom would have been exactly what Tim had
  5609. measured.
  5610.  
  5611. We asked Tim if we could get access to his data so that we could repeat
  5612. the benchmark and if he could check the MySQL version on the machine to
  5613. find out what was wrong and he promised to come back to us about this.
  5614. He has not done that yet.
  5615.  
  5616. Because of this we can't put any trust in this benchmark either.
  5617.  
  5618. Over time things also change and the preceding benchmarks are no longer
  5619. very relevant.  MySQL Server now has a couple of different storage
  5620. engines with different speed/concurrency tradeoffs.  *Note Table
  5621. types::. It would be interesting to see how the above tests would run
  5622. with the different transactional table types in MySQL Server.
  5623. PostgreSQL has, of course, also got new features since the test was
  5624. made.  As these tests are not publicly available there is no way for us
  5625. to know how the database would perform in the same tests today.
  5626.  
  5627. Conclusion:
  5628.  
  5629. The only benchmarks that exist today that anyone can download and run
  5630. against MySQL Server and PostgreSQL are the MySQL benchmarks.  We here
  5631. at MySQL AB believe that `Open Source' databases should be tested with
  5632. `Open Source' tools.  This is the only way to ensure that no one does
  5633. tests that nobody can reproduce and use this to claim that one database
  5634. is better than another.  Without knowing all the facts it's impossible
  5635. to answer the claims of the tester.
  5636.  
  5637. The thing we find strange is that every test we have seen about
  5638. PostgreSQL, that is impossible to reproduce, claims that PostgreSQL is
  5639. better in most cases while our tests, which anyone can reproduce,
  5640. clearly show otherwise.  With this we don't want to say that PostgreSQL
  5641. isn't good at many things (it is!) or that it isn't faster than MySQL
  5642. Server under certain conditions.  We would just like to see a fair test
  5643. where PostgreSQL performs very well, so that we could get some friendly
  5644. competition going.
  5645.  
  5646. For more information about our benchmark suite, see *Note MySQL
  5647. Benchmarks::.
  5648.  
  5649. We are working on an even better benchmark suite, including multi-user
  5650. tests, and a better documentation of what the individual tests really
  5651. do and how to add more tests to the suite.
  5652.  
  5653. MySQL Installation
  5654. ******************
  5655.  
  5656. This chapter describes how to obtain and install MySQL:
  5657.  
  5658.    * For a list of sites from which you can obtain MySQL, see *Note
  5659.      Getting MySQL: Getting MySQL.
  5660.  
  5661.    * To see which platforms are supported, see *Note Which OS::. Please
  5662.      note that not all supported systems are equally good for running
  5663.      MySQL on them.  On some it is much more robust and efficient than
  5664.      others--see *Note Which OS:: for details.
  5665.  
  5666.    * Several versions of MySQL are available in both binary and source
  5667.      distributions.  We also provide public access to our current
  5668.      source tree for those who want to see our most recent developments
  5669.      and help us test new code.  To determine which version and type of
  5670.      distribution you should use, see *Note Which version::. When in
  5671.      doubt, use a binary distribution.
  5672.  
  5673.    * Installation instructions for binary and source distributions are
  5674.      described in *Note Installing binary::, and *Note Installing
  5675.      source::.  Each set of instructions includes a section on
  5676.      system-specific problems you may run into.
  5677.  
  5678.    * For post-installation procedures, see *Note Post-installation::.
  5679.      These procedures apply whether you install MySQL using a binary or
  5680.      source distribution.
  5681.  
  5682. Quick Standard Installation of MySQL
  5683. ====================================
  5684.  
  5685. This chapter covers the installation of MySQL on platforms where we
  5686. offer packages using the native packaging format of the respective
  5687. platform. However, binary distributions of MySQL are available for many
  5688. other platforms as well, see *Note Installing binary:: for generic
  5689. installation instructions for these packages that apply to all
  5690. platforms.
  5691.  
  5692. See *Note General Installation Issues:: for more info on what other
  5693. binary distributions are available on how to obtain them.
  5694.  
  5695. Installing MySQL on Linux
  5696. -------------------------
  5697.  
  5698. The recommended way to install MySQL on Linux is by using the RPM
  5699. packages. The MySQL RPMs are currently built on a SuSE Linux 7.3 system
  5700. but should work on most versions of Linux that support `rpm' and use
  5701. `glibc'.
  5702.  
  5703. If you have problems with an RPM file (for example, if you receive the
  5704. error "`Sorry, the host 'xxxx' could not be looked up'"), see *Note
  5705. Binary notes-Linux::.
  5706.  
  5707. In most cases, you only need to install the `MySQL-server' and
  5708. `MySQL-client' packages to get a functional MySQL installation. The
  5709. other packages are not required for a standard installation.
  5710.  
  5711. If you get a dependency failure when trying to install the MySQL 4.0
  5712. packages (for example, "`error: removing these packages would break
  5713. dependencies: libmysqlclient.so.10 is needed by ...'"), you should also
  5714. install the package `MySQL-shared-compat', which includes both the
  5715. shared libraries for backwards compatibility (`libmysqlclient.so.12'
  5716. for MySQL 4.0 and `libmysqlclient.so.10' for MySQL 3.23).
  5717.  
  5718. Many Linux distributions still ship with MySQL 3.23 and they usually
  5719. link applications dynamically to save disk space. If these shared
  5720. libraries are in a separate package (for example, `MySQL-shared'), it is
  5721. sufficient to simply leave this package installed and just upgrade the
  5722. MySQL server and client packages (which are statically linked and do
  5723. not depend on the shared libraries). For distributions that include the
  5724. shared libraries in the same package as the MySQL server (for example,
  5725. Red Hat Linux), you could either install our 3.23 `MySQL-shared' RPM,
  5726. or use the `MySQL-shared-compat' package instead.
  5727.  
  5728. The following RPM packages are available:
  5729.  
  5730.    * `MySQL-server-VERSION.i386.rpm'
  5731.  
  5732.      The MySQL server.  You will need this unless you only want to
  5733.      connect to a MySQL server running on another machine. Please note
  5734.      that this package was called `MySQL-VERSION.i386.rpm' before MySQL
  5735.      4.0.10.
  5736.  
  5737.    * `MySQL-client-VERSION.i386.rpm'
  5738.  
  5739.      The standard MySQL client programs. You probably always want to
  5740.      install this package.
  5741.  
  5742.    * `MySQL-bench-VERSION.i386.rpm'
  5743.  
  5744.      Tests and benchmarks. Requires Perl and the `DBD-mysql' module.
  5745.  
  5746.    * `MySQL-devel-VERSION.i386.rpm'
  5747.  
  5748.      The libraries and include files that are needed if you want to
  5749.      compile other MySQL clients, such as the Perl modules.
  5750.  
  5751.    * `MySQL-shared-VERSION.i386.rpm'
  5752.  
  5753.      This package contains the shared libraries (`libmysqlclient.so*')
  5754.      that certain languages and applications need to dynamically load
  5755.      and use MySQL.
  5756.  
  5757.    * `MySQL-shared-compat-VERSION.i386.rpm'
  5758.  
  5759.      This package includes the shared libraries for both MySQL 3.23 and
  5760.      MySQL 4.0. Install this package instead of `MySQL-shared', if you
  5761.      have applications installed that are dynamically linked against
  5762.      MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking
  5763.      the library dependencies. This package is available since MySQL
  5764.      4.0.13.
  5765.  
  5766.    * `MySQL-embedded-VERSION.i386.rpm'
  5767.  
  5768.      The embedded MySQL server library (from MySQL 4.0).
  5769.  
  5770.    * `MySQL-VERSION.src.rpm'
  5771.  
  5772.      This contains the source code for all of the previous packages. It
  5773.      can also be used to rebuild the RPMs on other architectures (for
  5774.      example, Alpha or SPARC).
  5775.  
  5776. To see all files in an RPM package, run:
  5777.      shell> rpm -qpl MySQL-VERSION.i386.rpm
  5778.  
  5779. To perform a standard minimal installation, run:
  5780.  
  5781.      shell> rpm -i MySQL-server-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
  5782.  
  5783. To install just the client package, run:
  5784.  
  5785.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  5786.  
  5787. The server RPM places data under the `/var/lib/mysql' directory. The
  5788. RPM also creates the appropriate entries in `/etc/init.d/' to start the
  5789. server automatically at boot time. (This means that if you have
  5790. performed a previous installation and have made changes to its startup
  5791. script, you may want to make a copy of the script so you don't lose it
  5792. when you install a newer RPM.) See *Note Automatic start:: for more
  5793. info on how MySQL can be started up automatically on system startup.
  5794.  
  5795. If you want to install the MySQL RPM on older Linux distributions that
  5796. do not support initialisation scripts in `/etc/init.d' (directly or via
  5797. a symlink), you should create a symbolic link that points to the
  5798. location where your initialisation scripts actually are installed. For
  5799. example, if that location is `/etc/rc.d/init.d', use these commands
  5800. before installing the RPM to create `/etc/init.d' as a symbolic link
  5801. that points there:
  5802.  
  5803.      shell> cd /etc ; ln -s rc.d/init.d .
  5804.  
  5805. However, all current major Linux distributions should already support
  5806. the new directory layout that uses `/etc/init.d', because it is
  5807. required for LSB (Linux Standard Base) compliance.
  5808.  
  5809. After installing the RPM file(s), the `mysqld' daemon should be up and
  5810. running and you should now be able to start using MySQL.  *Note
  5811. Post-installation::.
  5812.  
  5813. If something goes wrong, you can find more information in the binary
  5814. installation chapter. *Note Installing binary::.
  5815.  
  5816. Installing MySQL on Windows
  5817. ---------------------------
  5818.  
  5819. The MySQL server for Windows is available in two distribution formats:
  5820.  
  5821.    * The binary distribution contains a setup program that installs
  5822.      everything you need so that you can start the server immediately.
  5823.  
  5824.    * The source distribution contains all the code and support files
  5825.      for building the executables using the VC++ 6.0 compiler.  *Note
  5826.      Windows source build::.
  5827.  
  5828.  
  5829. Generally speaking, you should use the binary distribution. It's
  5830. simpler, and you need no additional tools to get MySQL up and running.
  5831.  
  5832. You will need the following:
  5833.  
  5834.    * A 32-bit Windows Operating System such as 9x, Me, NT, 2000, or XP.
  5835.      The NT family (Windows NT, 2000, and XP) permits you to run the
  5836.      MySQL server as a service. *Note NT start::.
  5837.  
  5838.      If you need tables with a size larger than 4 GB, install MySQL on
  5839.      an NTFS or newer filesystem. Don't forget to use `MAX_ROWS' and
  5840.      `AVG_ROW_LENGTH' when you create tables.  *Note `CREATE TABLE':
  5841.      CREATE TABLE.
  5842.  
  5843.    * TCP/IP protocol support.
  5844.  
  5845.    * A copy of the MySQL binary distribution for Windows, which can be
  5846.      downloaded from `http://www.mysql.com/downloads/'.
  5847.  
  5848.      Note: The distribution files are supplied with a zipped format and
  5849.      we recommend the use of an adequate FTP client with resume feature
  5850.      to avoid corruption of files during the download process.
  5851.  
  5852.    * A `ZIP' program to unpack the distribution file.
  5853.  
  5854.    * Enough space on the hard drive to unpack, install, and create the
  5855.      databases in accordance with your requirements.
  5856.  
  5857.    * If you plan to connect to the MySQL server via ODBC, you will also
  5858.      need the `MyODBC' driver. *Note ODBC::.
  5859.  
  5860.  
  5861. Installing the Binaries
  5862. .......................
  5863.  
  5864.   1. If you are working on an NT/2000/XP server, log on as a user with
  5865.      administrator privileges.
  5866.  
  5867.   2. If you are doing an upgrade of an earlier MySQL installation, it
  5868.      is necessary to stop the current server. If you are running the
  5869.      server as a service, stop it using this command:
  5870.  
  5871.           C:\> NET STOP MySQL
  5872.  
  5873.      Otherwise, stop the server like this:
  5874.  
  5875.           C:\mysql\bin> mysqladmin -u root shutdown
  5876.  
  5877.   3. On NT/2000/XP machines, if you want to change the server executable
  5878.      (for example, `-max' or `-nt'), it is also necessary to remove the
  5879.      service:
  5880.  
  5881.           C:\mysql\bin> mysqld --remove
  5882.  
  5883.   4. Unzip the distribution file to a temporary directory.
  5884.  
  5885.   5. Run the `setup.exe' program to begin the installation process.  If
  5886.      you want to install into another directory than the default
  5887.      (`C:\mysql'), use the `Browse' button to specify your preferred
  5888.      directory.
  5889.  
  5890.   6. Finish the install process.
  5891.  
  5892.  
  5893. Preparing the Windows MySQL Environment
  5894. .......................................
  5895.  
  5896. Starting with MySQL 3.23.38, the Windows distribution includes both the
  5897. normal and the MySQL-Max server binaries.  Here is a list of the
  5898. different MySQL servers from which you can choose:
  5899.  
  5900. *Binary*       *Description*
  5901. `mysqld'       Compiled with full debugging and automatic memory
  5902.                allocation checking, symbolic links, `InnoDB', and `BDB'
  5903.                tables.
  5904. `mysqld-opt'   Optimised binary with no support for transactional tables
  5905.                in version 3.23. For version 4.0, `InnoDB' is enabled.
  5906. `mysqld-nt'    Optimised binary for NT/2000/XP with support for named
  5907.                pipes.  You can run this version on Windows 9x/Me, but in
  5908.                this case no named pipes are created and you must have
  5909.                TCP/IP installed.
  5910. `mysqld-max'   Optimised binary with support for symbolic links,
  5911.                `InnoDB' and `BDB' tables.
  5912. `mysqld-max-nt'Like `mysqld-max', but compiled with support for named
  5913.                pipes.
  5914.  
  5915. The `mysqld-nt' and `mysqld-max-nt' servers support connections over a
  5916. named pipe. However, starting from 3.23.50, named pipes are enabled only
  5917. if you start these servers with the `--enable-named-pipe' option.
  5918.  
  5919. All of the preceding binaries are optimised for the Pentium Pro
  5920. processor but should work on any Intel processor >= i386.
  5921.  
  5922. You will find it helpful to use an option file to specify your MySQL
  5923. configuration under the following circumstances:
  5924.  
  5925.    * The installation or data directories are different from the default
  5926.      locations (`C:\mysql' and `C:\mysql\data').
  5927.  
  5928.    * You need to tune the server settings.  For example, if you want to
  5929.      use the `InnoDB' transactional tables in MySQL version 3.23, you
  5930.      need to manually create two new directories to hold the `InnoDB'
  5931.      data and log files--such as, `C:\ibdata' and `C:\iblogs'.  You
  5932.      will also need to add some extra lines to the option file, as
  5933.      described in *Note `InnoDB' start: InnoDB start.  (As of MySQL
  5934.      4.0, InnoDB will create its data and log files in the data
  5935.      directory by default. This means you need not configure InnoDB
  5936.      explicitly, though you may still wish to do so.)
  5937.  
  5938.  
  5939. On Windows, the MySQL installer places the data directory directly under
  5940. the directory where you install MySQL.  If you would like to use a data
  5941. directory in a different location, you should copy the entire contents
  5942. of the `data' directory to the new location. For example, the default
  5943. installation places MySQL in `C:\mysql' and the data directory in
  5944. `C:\mysql\data'. If you want to use a data directory of `E:\mydata',
  5945. you must copy `C:\mysql\data' there. You will also need to use a
  5946. `--datadir' option to specify the location of the new data directory.
  5947.  
  5948. Normally you can use the `WinMySQLAdmin' tool to edit the option file
  5949. `my.ini'.  In this case you don't have to worry about the following
  5950. discussion.
  5951.  
  5952. There are two option files with the same function: `C:\my.cnf', and the
  5953. `my.ini' file in the Windows directory.  (This directory typically is
  5954. named something like `C:\WINDOWS' or `C:\WinNT'.  You can determine its
  5955. exact location from the value of the `WINDIR' environment variable.)
  5956. MySQL looks first for the `my.ini' file, then for the `my.cnf' file.
  5957. However, to avoid confusion, it's best if you use only one of these
  5958. files. Both files are plain text.
  5959.  
  5960. If your PC uses a boot loader where the `C:' drive isn't the boot drive,
  5961. your only option is to use the `my.ini' file.  Also note that if you
  5962. use the `WinMySQLAdmin' tool, it uses only the `my.ini' file.  The
  5963. `\mysql\bin' directory contains a help file with instructions for using
  5964. this tool.
  5965.  
  5966. Using the `notepad' program, create the option file and edit the
  5967. `[mysqld]' section to specify values for the `basedir' and `datadir'
  5968. parameters:
  5969.  
  5970.      [mysqld]
  5971.      # set basedir to your installation path, for example, C:/mysql
  5972.      basedir=the_install_path
  5973.      # set datadir to the location of your data directory,
  5974.      # for example, C:/mysql/data or D:/mydata/data
  5975.      datadir=the_data_path
  5976.  
  5977. Note that Windows pathnames should be specified in option files using
  5978. forward slashes rather than backslashes.  If you do use backslashes, you
  5979. must double them.
  5980.  
  5981. Now you are ready to test starting the server.
  5982.  
  5983. Starting the Server for the First Time
  5984. ......................................
  5985.  
  5986. Testing is best done from a command prompt in a console window (a "DOS
  5987. window"). This way you can have the server display status messages in
  5988. the window where they are easy to see.  If something is wrong with your
  5989. configuration, these messages will make it easier for you to identify
  5990. and fix any problems.
  5991.  
  5992. Make sure you are in the directory where the server is located, then
  5993. enter this command:
  5994.  
  5995.      shell> mysqld --console
  5996.  
  5997. For servers that include `InnoDB' support, you should see the following
  5998. messages as the server starts up:
  5999.  
  6000.      InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist:
  6001.      InnoDB: a new database to be created!
  6002.      InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200
  6003.      InnoDB: Database physically writes the file full: wait...
  6004.      InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created
  6005.      InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280
  6006.      InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created
  6007.      InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280
  6008.      InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created
  6009.      InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280
  6010.      InnoDB: Doublewrite buffer not found: creating new
  6011.      InnoDB: Doublewrite buffer created
  6012.      InnoDB: creating foreign key constraint system tables
  6013.      InnoDB: foreign key constraint system tables created
  6014.      011024 10:58:25  InnoDB: Started
  6015.  
  6016. For further information about running MySQL on Windows, see *Note
  6017. Windows::.
  6018.  
  6019. Installing MySQL on Mac OS X
  6020. ----------------------------
  6021.  
  6022. Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.2
  6023. ("Jaguar") using a Mac OS X `PKG' binary package instead of the binary
  6024. tarball distribution. Please note that older versions of Mac OS X (for
  6025. example, 10.1.x) are not supported by this package.
  6026.  
  6027. The package is located inside a disk image (`.dmg') file, that you
  6028. first need to mount by double-clicking its icon in the Finder. It should
  6029. then mount the image and display its contents.
  6030.  
  6031. *NOTE*: Before proceeding with the installation, be sure to shut down
  6032. all running MySQL server instances by either using the MySQL Manager
  6033. Application (on Mac OS X Server) or via `mysqladmin shutdown' on the
  6034. command line.
  6035.  
  6036. To actually install the MySQL PKG, double click on the package icon.
  6037. This launches the Mac OS Package Installer, which will guide you through
  6038. the installation of MySQL.
  6039.  
  6040. The Mac OS X PKG of MySQL will install itself into
  6041. `/usr/local/mysql-<version>' and will also install a symbolic link
  6042. `/usr/local/mysql', pointing to the new location. If a directory named
  6043. `/usr/local/mysql' already exists, it will be renamed to
  6044. `/usr/local/mysql.bak' first. Additionally, it will install the grant
  6045. tables in the `mysql' database by executing `mysql_install_db' after
  6046. the installation.
  6047.  
  6048. The installation layout is similar to the one of the binary
  6049. distribution; all MySQL binaries are located in the directory
  6050. `/usr/local/mysql/bin'.  The MySQL socket file is created as
  6051. `/tmp/mysql.sock' by default.  *Note Installation layouts::.
  6052.  
  6053. MySQL installation requires a Mac OS X user account named `mysql' (a
  6054. user account with this name should exist by default on Mac OS X 10.2
  6055. and up).
  6056.  
  6057. If you are running Mac OS X Server, you already have a version of MySQL
  6058. installed:
  6059.  
  6060.    * Mac OS X Server 10.2-10.2.2 come with MySQL 3.23.51 installed
  6061.  
  6062.    * Mac OS X Server 10.2.3-10.2.6 ship with MySQL 3.23.53
  6063.  
  6064. This manual section covers the installation of the official MySQL Mac
  6065. OS X PKG only.  Make sure to read Apple's help about installing MySQL
  6066. (Run the "Help View" application, select "Mac OS X Server" help, and do
  6067. a search for "MySQL" and read the item entitled "Installing MySQL").
  6068.  
  6069. Especially note that the pre-installed version of MySQL on Mac OS X
  6070. Server starts the MySQL user with the command `safe_mysqld' instead of
  6071. `mysqld_safe'.
  6072.  
  6073. If you previously used Marc Liyanage's MySQL packages for Mac OS X from
  6074. `http://www.entropy.ch', you can simply follow the update instructions
  6075. for packages using the binary installation layout as given on his pages.
  6076.  
  6077. If you are upgrading from Marc's version or from the Mac OS X Server
  6078. version of MySQL to the official MySQL PKG, you also need to convert
  6079. the existing MySQL privilege tables using the
  6080. `mysql_fix_privilege_tables' script, since some new security privileges
  6081. have been added.  *Note Upgrading-from-3.23::.
  6082.  
  6083. After the installation, you can start up MySQL by running the following
  6084. commands in a terminal window. Please note that you need to have
  6085. administrator privileges to perform this task.
  6086.  
  6087.      shell> cd /usr/local/mysql
  6088.      shell> sudo ./bin/mysqld_safe
  6089.      (Enter your password, if necessary)
  6090.      (Press Control-Z)
  6091.      shell> bg
  6092.      (Press Control-D to exit the shell)
  6093.  
  6094. You should now be able to connect to the MySQL server, for example, by
  6095. running `/usr/local/mysql/bin/mysql'.
  6096.  
  6097. If you installed MySQL for the first time, *please remember to set a
  6098. password for the MySQL `root' user!*
  6099.  
  6100. This is done with the following two commands:
  6101.  
  6102.      /usr/local/mysql/bin/mysqladmin -u root password <password>
  6103.      /usr/local/mysql/bin/mysqladmin -u root -h `hostname` password <password>
  6104.  
  6105. You might want to also add aliases to your shell's resource file to
  6106. access `mysql' and `mysqladmin' from the command line:
  6107.  
  6108.      alias mysql '/usr/local/mysql/bin/mysql'
  6109.      alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
  6110.  
  6111. Alternatively, you could simply add `/usr/local/mysql/bin' to your
  6112. `PATH' environment variable, for example, by adding the following to
  6113. `$HOME/.tcshrc':
  6114.  
  6115.      setenv PATH ${PATH}:/usr/local/mysql/bin
  6116.  
  6117. To enable the automatic startup of MySQL on bootup, you can download
  6118. Marc Liyanage's MySQL StartupItem from the following location:
  6119.  
  6120. `http://www2.entropy.ch/download/mysql-startupitem.pkg.tar.gz'
  6121.  
  6122. We plan to add a StartupItem to the official MySQL PKG in the near
  6123. future.
  6124.  
  6125. Please note that installing a new MySQL PKG does not remove the
  6126. directory of an older installation. Unfortunately, the Mac OS X
  6127. Installer does not yet offer the functionality required to properly
  6128. upgrade previously installed packages.
  6129.  
  6130. After you have copied over the MySQL database files from the previous
  6131. version and have successfully started the new version, you should
  6132. consider removing the old installation files to save disk space.
  6133. Additionally, you should also remove older versions of the Package
  6134. Receipt directories located in `/Library/Receipts/mysql-<version>.pkg'.
  6135.  
  6136. Installing MySQL on NetWare
  6137. ---------------------------
  6138.  
  6139. As of version 4.0.11, the MySQL server is available for Novell NetWare
  6140. in binary package form. In order to host MySQL, the NetWare server must
  6141. meet these requirements:
  6142.  
  6143.    * NetWare version 6.5, or NetWare 6.0 with Support Pack 3 installed
  6144.      (You can obtain this at
  6145.      `http://support.novell.com/filefinder/13659/index.html').  The
  6146.      system must meet Novell's minimum requirements to run the
  6147.      respective version of NetWare.
  6148.  
  6149.    * MySQL data, as well as the binaries themselves, must be installed
  6150.      on an NSS volume; traditional volumes are not supported.
  6151.  
  6152. The binary package for NetWare can be obtained at
  6153. `http://www.mysql.com/downloads/'.
  6154.  
  6155. If you are running MySQL on NetWare 6.0, we strongly suggest that you
  6156. use the `--skip-external-locking' option on the command line. It will
  6157. also be neccesary to use `CHECK TABLE' and `REPAIR TABLE' instead of
  6158. `myisamchk', because `myisamchk' makes use of external locking.
  6159. External locking is known to have problems on NetWare 6.0; the problem
  6160. has been eliminated in NetWare 6.5.
  6161.  
  6162. Installing the MySQL for NetWare Binaries
  6163. .........................................
  6164.  
  6165.   1. If you are upgrading from a prior installation, stop the MySQL
  6166.      server.  This is done from the server console, using:
  6167.  
  6168.           SERVER:  mysqladmin -u root shutdown
  6169.  
  6170.   2. Log on to the target server from a client machine with access to
  6171.      the location where you will install MySQL.
  6172.  
  6173.   3. Extract the binary package zip file onto the server. Be sure to
  6174.      allow the paths in the zip file to be used. It is safe to simply
  6175.      extract the file to `SYS:\'.
  6176.  
  6177.      If you are upgrading from a prior installation, you may need to
  6178.      copy the data directory (for example, `SYS:MYSQL\DATA') now, as
  6179.      well as `my.cnf' if you have customised it. You can then delete
  6180.      the old copy of MySQL.
  6181.  
  6182.   4. You may wish to rename the directory to something more consistent
  6183.      and easy to use. We recommend using `SYS:MYSQL'; examples in the
  6184.      manual will use this to refer to the installation directory in
  6185.      general.
  6186.  
  6187.   5. At the server console, add a search path for the directory
  6188.      containing the MySQL NLMs. For example:
  6189.  
  6190.           SERVER:  SEARCH ADD SYS:MYSQL\BIN
  6191.  
  6192.   6. Install the initial database, if needed, by executing
  6193.      `mysql_install_db' at the server console.
  6194.  
  6195.   7. Start the MySQL server using `mysqld_safe' at the server console.
  6196.  
  6197.   8. To finish the installation, you should also add the following
  6198.      commands to `autoexec.ncf'. For example, if your MySQL
  6199.      installation is in `SYS:MYSQL' and you want MySQL to start
  6200.      automatically, you could add these lines:
  6201.  
  6202.           #Starts the MySQL 4.0.x database server
  6203.           SEARCH ADD SYS:MYSQL\BIN
  6204.           MYSQLD_SAFE
  6205.  
  6206.      If you are using NetWare 6.0, you should add the
  6207.      `--skip-external-locking' flag:
  6208.  
  6209.           #Starts the MySQL 4.0.x database server
  6210.           SEARCH ADD SYS:MYSQL\BIN
  6211.           MYSQLD_SAFE --skip-external-locking
  6212.  
  6213.  
  6214. If there was an existing installation of MySQL on the server, be sure
  6215. to check for existing MySQL startup commands in `autoexec.ncf', and
  6216. edit or delete them as necessary.
  6217.  
  6218. General Installation Issues
  6219. ===========================
  6220.  
  6221. How to Get MySQL
  6222. ----------------
  6223.  
  6224. Check the MySQL homepage (`http://www.mysql.com/') for information
  6225. about the current version and for downloading instructions.
  6226.  
  6227. Our main mirror is located at `http://mirrors.sunsite.dk/mysql/'.
  6228.  
  6229. For a complete up-to-date list of MySQL web/download mirrors, see
  6230. `http://www.mysql.com/downloads/mirrors.html'.  There you will also
  6231. find information about becoming a MySQL mirror site and how to report a
  6232. bad or out-of-date mirror.
  6233.  
  6234. Verifying Package Integrity Using `MD5 Checksums' or `GnuPG'
  6235. ------------------------------------------------------------
  6236.  
  6237. After you have downloaded the MySQL package that suits your needs and
  6238. before you attempt to install it, you should make sure it is intact and
  6239. has not been tampered with.
  6240.  
  6241. MySQL AB offers two means of integrity checking: `MD5 checksums' and
  6242. cryptographic signatures using `GnuPG', the `GNU Privacy Guard'.
  6243.  
  6244. Verifying the `MD5 Checksum'
  6245. ----------------------------
  6246.  
  6247. After you have downloaded the package, you should check, if the MD5
  6248. checksum matches the one provided on the MySQL download pages. Each
  6249. package has an individual checksum, that you can verify with the
  6250. following command:
  6251.  
  6252.      shell> md5sum <package>
  6253.  
  6254. Note, that not all operating systems support the `md5sum' command - on
  6255. some it is simply called `md5', others do not ship it at all. On Linux,
  6256. it is part of the `GNU Text Utilities' package, which is available for
  6257. a wide range of platforms. You can download the source code from
  6258. `http://www.gnu.org/software/textutils/' as well. If you have `OpenSSL'
  6259. installed, you can also use the command `openssl md5 <package>'
  6260. instead. A DOS/Windows implementation of the `md5' command is available
  6261. from `http://www.fourmilab.ch/md5/'.
  6262.  
  6263. Example:
  6264.      shell> md5sum mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz
  6265.      155836a7ed8c93aee6728a827a6aa153
  6266.                      mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz
  6267.  
  6268. You should check, if the resulting checksum matches the one printed on
  6269. the download page right below the respective package.
  6270.  
  6271. Most mirror sites also offer a file named `MD5SUMS', which also includes
  6272. the MD5 checksums for all files included in the `Downloads' directory.
  6273. Please note however that it's very easy to modify this file and it's
  6274. not a very reliable method. If in doubt, you should consult different
  6275. mirror sites and compare the results.
  6276.  
  6277. Signature Checking Using `GnuPG'
  6278. --------------------------------
  6279.  
  6280. A more reliable method of verifying the integrity of a package is using
  6281. cryptographic signatures. MySQL AB uses the `GNU Privacy Guard'
  6282. (`GnuPG'), an `Open Source' alternative to the very well-known `Pretty
  6283. Good Privacy' (`PGP') by Phil Zimmermann.  See `http://www.gnupg.org/'
  6284. and `http://www.openpgp.org/' for more information about
  6285. `OpenPGP'/`GnuPG' and how to obtain and install `GnuPG' on your system.
  6286. Most Linux distributions already ship with `GnuPG' installed by default.
  6287.  
  6288. Beginning with MySQL 4.0.10 (February 2003), MySQL AB has started
  6289. signing their downloadable packages with `GnuPG'. Cryptographic
  6290. signatures are a much more reliable method of verifying the integrity
  6291. and authenticity of a file.
  6292.  
  6293. To verify the signature for a specific package, you first need to
  6294. obtain a copy of MySQL AB's public GPG build key <build@mysql.com>. You
  6295. can either cut and paste it directly from here, or obtain it from
  6296. `http://www.keyserver.net/'.
  6297.  
  6298.      Key ID:
  6299.      pub  1024D/5072E1F5 2003-02-03
  6300.           MySQL Package signing key (www.mysql.com) <build@mysql.com>
  6301.      Fingerprint: A4A9 4068 76FC BD3C 4567  70C8 8C71 8D3B 5072 E1F5
  6302.      
  6303.      Public Key (ASCII-armored):
  6304.      
  6305.      -----BEGIN PGP PUBLIC KEY BLOCK-----
  6306.      Version: GnuPG v1.0.6 (GNU/Linux)
  6307.      Comment: For info see http://www.gnupg.org
  6308.      
  6309.      mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3
  6310.      RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ
  6311.      fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3
  6312.      BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW
  6313.      hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV
  6314.      K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE
  6315.      kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI
  6316.      QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep
  6317.      rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFj
  6318.      a2FnZSBzaWduaW5nIGtleSAod3d3Lm15c3FsLmNvbSkgPGJ1aWxkQG15c3FsLmNv
  6319.      bT6IXQQTEQIAHQUCPj6jDAUJCWYBgAULBwoDBAMVAwIDFgIBAheAAAoJEIxxjTtQ
  6320.      cuH1cY4AnilUwTXn8MatQOiG0a/bPxrvK/gCAJ4oinSNZRYTnblChwFaazt7PF3q
  6321.      zIhMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAn1mxHijft00bKXvu
  6322.      cSo/pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJ
  6323.      YiKJAAoJELb1zU3GuiQ/lpEAoIhpp6BozKI8p6eaabzF5MlJH58pAKCu/ROofK8J
  6324.      Eg2aLos+5zEYrB/LsrkCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/l
  6325.      xaZoJYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRi
  6326.      Rjd1DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE
  6327.      7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fm
  6328.      Le11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p
  6329.      /1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqq
  6330.      a8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSaf
  6331.      anFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOW
  6332.      I39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42Lmu
  6333.      QT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt92
  6334.      6s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZ
  6335.      Whe70YGNPw1yjWJT1IhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4A
  6336.      n3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uUq/SlsQ==
  6337.      =YJkx
  6338.      -----END PGP PUBLIC KEY BLOCK-----
  6339.  
  6340. You can import this key into your public `GPG' keyring by using `gpg
  6341. --import'. See the `GPG' documentation for more info on how to work
  6342. with public keys.
  6343.  
  6344. After you have downloaded and imported the public build key, now
  6345. download your desired MySQL package and the corresponding signature,
  6346. which is also available from the download page.  The signature has the
  6347. file name extension `.asc'. For example, the signature for
  6348. `mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz' would be
  6349. `mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz.asc'.  Make sure that
  6350. both files are stored in the same directory and then run the following
  6351. command to verify the signature for this file:
  6352.  
  6353.      shell> gpg --verify <package>.asc
  6354.      
  6355.      Example:
  6356.      
  6357.      shell> gpg --verify mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz.asc
  6358.      gpg: Warning: using insecure memory!
  6359.      gpg: Signature made Mon 03 Feb 2003 08:50:39 PM MET using DSA key ID 5072E1F5
  6360.      gpg: Good signature from
  6361.           "MySQL Package signing key (www.mysql.com) <build@mysql.com>"
  6362.  
  6363. The "Good signature" message indicates that everything is all right.
  6364.  
  6365. For `RPM' packages, there is no separate signature - `RPM' packages
  6366. actually have a built-in `GPG' signature and `MD5 checksum'. You can
  6367. verify them by running the following command:
  6368.  
  6369.      shell> rpm --checksig <package>.rpm
  6370.      
  6371.      Example:
  6372.      
  6373.      shell> rpm --checksig MySQL-server-4.0.10-0.i386.rpm
  6374.      MySQL-server-4.0.10-0.i386.rpm: md5 gpg OK
  6375.  
  6376. *Note:* If you are using RPM 4.1 and it complains about `(GPG) NOT OK
  6377. (MISSING KEYS: GPG#5072e1f5)' (even though you have imported it into
  6378. your GPG public keyring), you need to import the key into the RPM
  6379. keyring first. RPM 4.1 no longer uses your GPG keyring (and GPG
  6380. itself), but rather maintains its own keyring (because it's a system
  6381. wide application and the GPG public keyring is user-specific file). To
  6382. import the MySQL public key into the RPM keyring, please use the
  6383. following command:
  6384.  
  6385.      shell> rpm --import <pubkey>
  6386.      
  6387.      Example:
  6388.      
  6389.      shell> rpm --import mysql_pubkey.asc
  6390.  
  6391. In case you notice that the `MD5 checksum' or `GPG' signatures do not
  6392. match, first try to download the respective package one more time,
  6393. maybe from another mirror site. If you repeatedly can not successfully
  6394. verify the integrity of the package, please notify us about such
  6395. incidents including the full package name and the download site you
  6396. have been using at <webmaster@mysql.com> or <build@mysql.com>.
  6397.  
  6398. Operating Systems Supported by MySQL
  6399. ------------------------------------
  6400.  
  6401. We use GNU Autoconf, so it is possible to port MySQL to all modern
  6402. systems with working Posix threads and a C++ compiler.  (To compile
  6403. only the client code, a C++ compiler is required but not threads.)  We
  6404. use and develop the software ourselves primarily on Linux (SuSE and Red
  6405. Hat), FreeBSD and Sun Solaris (Versions 8 and 9).
  6406.  
  6407. Note that for many operating systems, the native thread support works
  6408. only in the latest versions. MySQL has been reported to compile
  6409. successfully on the following operating system/thread package
  6410. combinations:
  6411.  
  6412.    * AIX 4.x, 5.x with native threads.  *Note IBM-AIX::.
  6413.  
  6414.    * Amiga.
  6415.  
  6416.    * BSDI 2.x with the MIT-pthreads package.  *Note BSDI::.
  6417.  
  6418.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  6419.  
  6420.    * SCO OpenServer with a recent port of the FSU Pthreads package.
  6421.      *Note SCO::.
  6422.  
  6423.    * SCO UnixWare 7.1.x.  *Note SCO UnixWare::.
  6424.  
  6425.    * DEC Unix 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  6426.  
  6427.    * FreeBSD 2.x with the MIT-pthreads package.  *Note FreeBSD::.
  6428.  
  6429.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  6430.  
  6431.    * FreeBSD 4.x with Linuxthreads.  *Note FreeBSD::.
  6432.  
  6433.    * HP-UX 10.20 with the DCE threads or the MIT-pthreads package.
  6434.      *Note HP-UX 10.20::.
  6435.  
  6436.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  6437.  
  6438.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  6439.      Linux::.
  6440.  
  6441.    * Mac OS X.  *Note Mac OS X::.
  6442.  
  6443.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make).
  6444.      *Note NetBSD::.
  6445.  
  6446.    * Novell NetWare 6.0.  *Note Novell NetWare::.
  6447.  
  6448.    * OpenBSD > 2.5 with native threads. OpenBSD < 2.5 with the
  6449.      MIT-pthreads package.  *Note OpenBSD::.
  6450.  
  6451.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  6452.  
  6453.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  6454.  
  6455.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  6456.      Solaris::.
  6457.  
  6458.    * SunOS 4.x with the MIT-pthreads package.  *Note Solaris::.
  6459.  
  6460.    * Tru64 Unix
  6461.  
  6462.    * Windows 9x, Me, NT, 2000 and XP.  *Note Windows::.
  6463.  
  6464. Note that not all platforms are suited equally well for running MySQL.
  6465. How well a certain platform is suited for a high-load mission-critical
  6466. MySQL server is determined by the following factors:
  6467.  
  6468.    * General stability of the thread library. A platform may have
  6469.      excellent reputation otherwise, but if the thread library is
  6470.      unstable in the code that is called by MySQL, even if everything
  6471.      else is perfect, MySQL will be only as stable as the thread
  6472.      library.
  6473.  
  6474.    * The ability of the kernel and/or thread library to take advantage
  6475.      of *SMP* on multi-processor systems. In other words, when a process
  6476.      creates a thread, it should be possible for that thread to run on
  6477.      a different CPU than the original process.
  6478.  
  6479.    * The ability of the kernel and/or the thread library to run many
  6480.      threads which acquire/release a mutex over a short critical region
  6481.      frequently without excessive context switches. In other words, if
  6482.      the implementation of `pthread_mutex_lock()' is too anxious to
  6483.      yield CPU time, this will hurt MySQL tremendously. If this issue
  6484.      is not taken care of, adding extra CPUs will actually make MySQL
  6485.      slower.
  6486.  
  6487.    * General filesystem stability/performance.
  6488.  
  6489.    * Ability of the filesystem to deal with large files at all and deal
  6490.      with them efficiently, if your tables are big.
  6491.  
  6492.    * Our level of expertise here at MySQL AB with the platform. If we
  6493.      know a platform well, we introduce platform-specific
  6494.      optimisations/fixes enabled at compile time. We can also provide
  6495.      advice on configuring your system optimally for MySQL.
  6496.  
  6497.    * The amount of testing of similar configurations we have done
  6498.      internally.
  6499.  
  6500.    * The number of users that have successfully run MySQL on that
  6501.      platform in similar configurations. If this number is high, the
  6502.      chances of hitting some platform-specific surprises are much
  6503.      smaller.
  6504.  
  6505. Based on the preceding criteria, the best platforms for running MySQL
  6506. at this point are x86 with SuSE Linux 8.2, 2.4 kernel, and ReiserFS (or
  6507. any similar Linux distribution) and SPARC with Solaris (2.7-9). FreeBSD
  6508. comes third, but we really hope it will join the top club once the
  6509. thread library is improved. We also hope that at some point we will be
  6510. able to include all other platforms on which MySQL compiles, runs okay,
  6511. but not quite with the same level of stability and performance, into
  6512. the top category. This will require some effort on our part in
  6513. cooperation with the developers of the OS/library components MySQL
  6514. depends upon. If you are interested in making one of those components
  6515. better, are in a position to influence their development, and need more
  6516. detailed instructions on what MySQL needs to run better, send an e-mail
  6517. to <internals@lists.mysql.com>.
  6518.  
  6519. Please note that the preceding comparison is not to say that one OS is
  6520. better or worse than the other in general. We are talking about
  6521. choosing a particular OS for a dedicated purpose--running MySQL, and
  6522. compare platforms in that regard only. With this in mind, the result of
  6523. this comparison would be different if we included more issues into it.
  6524. And in some cases, the reason one OS is better than the other could
  6525. simply be that we have put forth more effort into testing on and
  6526. optimising for that particular platform.  We are just stating our
  6527. observations to help you decide on which platform to use MySQL on in
  6528. your setup.
  6529.  
  6530. Which MySQL Version to Use
  6531. --------------------------
  6532.  
  6533. The first decision to make is whether you want to use the latest
  6534. development release or the last production (stable) release:
  6535.  
  6536.    * Normally, if you are beginning to use MySQL for the first time or
  6537.      trying to port it to some system for which there is no binary
  6538.      distribution, we recommend going with the production release
  6539.      (currently version 4.0).  Note that all MySQL releases are checked
  6540.      with the MySQL benchmarks and an extensive test suite before each
  6541.      release (even the development releases).
  6542.  
  6543.    * Otherwise, if you are running an old system and want to upgrade,
  6544.      but don't want to take chances with a non-seamless upgrade, you
  6545.      should upgrade to the latest in the same branch you are using
  6546.      (where only the last version number is newer than yours).  We have
  6547.      tried to fix only fatal bugs and make small, relatively safe
  6548.      changes to that version.
  6549.  
  6550. The second decision to make is whether you want to use a source
  6551. distribution or a binary distribution.  In most cases you should
  6552. probably use a binary distribution, if one exists for your platform, as
  6553. this generally will be easier to install than a source distribution.
  6554.  
  6555. In the following cases you probably will be better off with a source
  6556. installation:
  6557.  
  6558.    * If you want to install MySQL at some explicit location.  (The
  6559.      standard binary distributions are "ready to run" at any place, but
  6560.      you may want to get even more flexibility).
  6561.  
  6562.    * To be able to satisfy different user requirements, we are
  6563.      providing two different binary versions: one compiled with the
  6564.      non-transactional storage engines (a small, fast binary), and one
  6565.      configured with the most important extended options like
  6566.      transaction-safe tables.  Both versions are compiled from the same
  6567.      source distribution.  All native `MySQL' clients can connect to
  6568.      both MySQL versions.
  6569.  
  6570.      The extended MySQL binary distribution is marked with the `-max'
  6571.      suffix and is configured with the same options as `mysqld-max'.
  6572.      *Note `mysqld-max': mysqld-max.
  6573.  
  6574.      If you want to use the MySQL-Max RPM, you must first install the
  6575.      standard MySQL RPM.
  6576.  
  6577.    * If you want to configure `mysqld' with some extra features that are
  6578.      not in the standard binary distributions.  Here is a list of the
  6579.      most common extra options that you may want to use:
  6580.  
  6581.         * `--with-innodb' (default for MySQL 4.0 and onwards)
  6582.  
  6583.         * `--with-berkeley-db' (not available on all platforms)
  6584.  
  6585.         * `--with-raid'
  6586.  
  6587.         * `--with-libwrap'
  6588.  
  6589.         * `--with-named-z-libs' (This is done for some of the binaries)
  6590.  
  6591.         * `--with-debug[=full]'
  6592.  
  6593.    * The default binary distribution is normally compiled with support
  6594.      for all character sets and should work on a variety of processors
  6595.      from the same processor family.
  6596.  
  6597.      If you want a faster MySQL server you may want to recompile it
  6598.      with support for only the character sets you need, use a better
  6599.      compiler (like `pgcc'), or use compiler options that are better
  6600.      optimised for your processor.
  6601.  
  6602.    * If you have found a bug and reported it to the MySQL development
  6603.      team you will probably receive a patch that you need to apply to
  6604.      the source distribution to get the bug fixed.
  6605.  
  6606.    * If you want to read (and/or modify) the C and C++ code that makes
  6607.      up MySQL, you should get a source distribution.  The source code is
  6608.      always the ultimate manual.  Source distributions also contain more
  6609.      tests and examples than binary distributions.
  6610.  
  6611. The MySQL naming scheme uses release numbers that consist of three
  6612. numbers and a suffix.  For example, a release name like
  6613. `mysql-3.21.17-beta' is interpreted like this:
  6614.  
  6615.    * The first number (`3') describes the file format.  All Version 3
  6616.      releases have the same file format.
  6617.  
  6618.    * The second number (`21') is the release level.  Normally there are
  6619.      two to choose from. One is the production branch (currently
  6620.      `3.23') and the other is the development branch (currently `4.0').
  6621.      Normally both are stable, but the development version may have
  6622.      quirks, may be missing documentation on new features, or may fail
  6623.      to compile on some systems.
  6624.  
  6625.    * The third number (`17') is the version number within the release
  6626.      level.  This is incremented for each new distribution.  Usually you
  6627.      want the latest version for the release level you have chosen.
  6628.  
  6629.    * The suffix (`beta') indicates the stability level of the release.
  6630.      The possible suffixes are:
  6631.  
  6632.         - `alpha' indicates that the release contains some large
  6633.           section of new code that hasn't been 100% tested.  Known bugs
  6634.           (usually there are none) should be documented in the News
  6635.           section.  *Note News::.  There are also new commands and
  6636.           extensions in most alpha releases.  Active development that
  6637.           may involve major code changes can occur on an alpha release,
  6638.           but everything will be tested before doing a release.  There
  6639.           should be no known bugs in any MySQL release.
  6640.  
  6641.         - `beta' means that all new code has been tested.  No major new
  6642.           features that could cause corruption on old code are added.
  6643.           There should be no known bugs.  A version changes from alpha
  6644.           to beta when there haven't been any reported fatal bugs
  6645.           within an alpha version for at least a month and we don't
  6646.           plan to add any features that could make any old command more
  6647.           unreliable.
  6648.  
  6649.         - `gamma' is a beta that has been around a while and seems to
  6650.           work fine.  Only minor fixes are added.  This is what many
  6651.           other companies call a release.
  6652.  
  6653.         - If there is no suffix, it means that the version has been run
  6654.           for a while at many different sites with no reports of bugs
  6655.           other than platform-specific bugs.  Only critical bug fixes
  6656.           are applied to the release. This is what we call a production
  6657.           (stable) release.
  6658.  
  6659. All versions of MySQL are run through our standard tests and benchmarks
  6660. to ensure that they are relatively safe to use.  Because the standard
  6661. tests are extended over time to check for all previously found bugs,
  6662. the test suite keeps getting better.
  6663.  
  6664. Note that all releases have been tested at least with:
  6665.  
  6666. An internal test suite
  6667.      This is part of a production system for a customer.  It has many
  6668.      tables with hundreds of megabytes of data.
  6669.  
  6670. The MySQL benchmark suite
  6671.      This runs a range of common queries.  It is also a test to see
  6672.      whether the latest batch of optimisations actually made the code
  6673.      faster.  *Note MySQL Benchmarks::.
  6674.  
  6675. The `crash-me' test
  6676.      This tries to determine what features the database supports and
  6677.      what its capabilities and limitations are.  *Note MySQL
  6678.      Benchmarks::.
  6679.  
  6680. Another test is that we use the newest MySQL version in our internal
  6681. production environment, on at least one machine.  We have more than 100
  6682. gigabytes of data to work with.
  6683.  
  6684. Installation Layouts
  6685. --------------------
  6686.  
  6687. This section describes the default layout of the directories created by
  6688. installing binary and source distributions.
  6689.  
  6690. A binary distribution is installed by unpacking it at the installation
  6691. location you choose (typically `/usr/local/mysql') and creates the
  6692. following directories in that location:
  6693.  
  6694. *Directory* *Contents of directory*
  6695. `bin'       Client programs and the
  6696.             `mysqld' server
  6697. `data'      Log files, databases
  6698. `include'   Include (header) files
  6699. `lib'       Libraries
  6700. `scripts'   `mysql_install_db'
  6701. `share/mysql'Error message files
  6702. `sql-bench' Benchmarks
  6703.  
  6704. A source distribution is installed after you configure and compile it.
  6705. By default, the installation step installs files under `/usr/local', in
  6706. the following subdirectories:
  6707.  
  6708. *Directory* *Contents of directory*
  6709. `bin'       Client programs and scripts
  6710. `include/mysql'Include (header) files
  6711. `info'      Documentation in Info format
  6712. `lib/mysql' Libraries
  6713. `libexec'   The `mysqld' server
  6714. `share/mysql'Error message files
  6715. `sql-bench' Benchmarks and `crash-me' test
  6716. `var'       Databases and log files
  6717.  
  6718. Within an installation directory, the layout of a source installation
  6719. differs from that of a binary installation in the following ways:
  6720.  
  6721.    * The `mysqld' server is installed in the `libexec' directory rather
  6722.      than in the `bin' directory.
  6723.  
  6724.    * The data directory is `var' rather than `data'.
  6725.  
  6726.    * `mysql_install_db' is installed in the `/usr/local/bin' directory
  6727.      rather than in `/usr/local/mysql/scripts'.
  6728.  
  6729.    * The header file and library directories are `include/mysql' and
  6730.      `lib/mysql' rather than `include' and `lib'.
  6731.  
  6732. You can create your own binary installation from a compiled source
  6733. distribution by executing the script `scripts/make_binary_distribution'.
  6734.  
  6735. How and When Updates Are Released
  6736. ---------------------------------
  6737.  
  6738. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  6739. this with other MySQL users.  We try to make a release when we have
  6740. very useful features that others seem to have a need for.
  6741.  
  6742. We also try to help out users who request features that are easy to
  6743. implement.  We take note of what our licensed users want to have, and
  6744. we especially take note of what our extended e-mail supported customers
  6745. want and try to help them out.
  6746.  
  6747. No one has to download a new release.  The News section will tell you if
  6748. the new release has something you really want.  *Note News::.
  6749.  
  6750. We use the following policy when updating MySQL:
  6751.  
  6752.    * For each minor update, the last number in the version string is
  6753.      incremented.  When there are major new features or minor
  6754.      incompatibilities with previous versions, the second number in the
  6755.      version string is incremented.  When the file format changes, the
  6756.      first number is increased.
  6757.  
  6758.    * Production (stable-tested) releases are meant to appear about 1-2
  6759.      times a year, but if small bugs are found, a release with only bug
  6760.      fixes will be released.
  6761.  
  6762.    * Working releases/bug fixes to old releases are meant to appear
  6763.      about every 1-8 weeks.
  6764.  
  6765.    * Binary distributions for some platforms will be made by us for
  6766.      major releases.  Other people may make binary distributions for
  6767.      other systems but probably less frequently.
  6768.  
  6769.    * We usually make patches available as soon as we have located and
  6770.      fixed small bugs. They are usually posted to
  6771.      <bugs@lists.mysql.com> and are immediately available from our
  6772.      public BitKeeper repositories. They will also be included in the
  6773.      next release.
  6774.  
  6775.    * Non-critical but annoying bugs will be added to the MySQL source
  6776.      repository and they will be fixed in the next release.
  6777.  
  6778.    * If there is, by any chance, a fatal bug in a release we will make
  6779.      a new release as soon as possible.  We would like other companies
  6780.      to do this, too.
  6781.  
  6782. The current production release is Version 4.0; we have already moved
  6783. active development to Version 4.1 and 5.0.  Bugs will still be fixed in
  6784. the 4.0 version, and critical bugs also in the 3.23 series.  We don't
  6785. believe in a complete freeze, as this also leaves out bug fixes and
  6786. things that "must be done."  "Somewhat frozen" means that we may add
  6787. small things that "almost surely will not affect anything that's
  6788. already working."
  6789.  
  6790. MySQL uses a slightly different naming scheme from most other products.
  6791. In general it's relatively safe to use any version that has been out for
  6792. a couple of weeks without being replaced with a new version.  *Note
  6793. Which version::.
  6794.  
  6795. Release Philosophy - No Known Bugs in Releases
  6796. ----------------------------------------------
  6797.  
  6798. We put a lot of time and effort into making our releases bug free.  To
  6799. our knowledge, we have not released a single MySQL version with any
  6800. _known_ 'fatal' repeatable bugs.
  6801.  
  6802. A fatal bug is something that crashes MySQL under normal usage, gives
  6803. wrong answers for normal queries, or has a security problem.
  6804.  
  6805. We have documented all open problems, bugs and things that are
  6806. dependent on design decisions.  *Note Bugs::.
  6807.  
  6808. Our aim is to fix everything that is fixable, but without risking
  6809. making a stable MySQL version less stable. In certain cases, this means
  6810. we can fix an issue in the development version(s), but not in the
  6811. stable (production) version. Naturally, we document such issues so that
  6812. users are aware.
  6813.  
  6814. Here is a description of how our build process works:
  6815.    * We monitor bugs from our customer support list, the MySQL external
  6816.      mailing lists and the bugs database at `http://bugs.mysql.com/'.
  6817.  
  6818.    * All reported bugs for live versions are entered into the bugs
  6819.      database.
  6820.  
  6821.    * When we fix a bug, we always try to make a test case of it and
  6822.      include this into our test system to ensure that the bug will never
  6823.      come back. (About 90% of all fixed bugs have a test case.)
  6824.  
  6825.    * We also create test cases for all new features we add to MySQL.
  6826.  
  6827.    * Before we start to build a new MySQL release, we ensure that all
  6828.      reported repeatable bugs for the MySQL version (3.23.x, 4.0.x, etc)
  6829.      are fixed.  If something is impossible to fix (because some
  6830.      internal design decision in MySQL) we document this in the manual.
  6831.      *Note Bugs::.
  6832.  
  6833.    * We do a build on all platforms for which we support binaries (15+
  6834.      platforms) and run our test suite and benchmark suite on all of
  6835.      them.
  6836.  
  6837.    * We will not publish a binary for a platform for which the test or
  6838.      benchmark suite fails.  If it's a general error in the source, we
  6839.      fix this and do the build plus tests on all systems again, from
  6840.      scratch.
  6841.  
  6842.    * If we, during the build and test process (which takes 2-3 days),
  6843.      receive a report regarding a fatal bug (for example, one that
  6844.      causes a core dump), we fix this and restart the build process.
  6845.  
  6846.    * After publishing the binaries on `http://www.mysql.com/', we send
  6847.      out an announce email on the lists <mysql@lists.mysql.com> and
  6848.      <announce@lists.mysql.com>.  The announce message contains a list
  6849.      of all changes to the release and any known problems with the
  6850.      release.  (The 'known problems' section in the release notes has
  6851.      only been needed in a handful of releases.)
  6852.  
  6853.    * To quickly give our users access to the latest MySQL features, we
  6854.      do a new MySQL release every 4-5 weeks.
  6855.  
  6856.    * If we, after the release is done, get any bug reports that there
  6857.      was (after all) anything critically wrong with the build on a
  6858.      specific platform, we will fix this at once and build a new `'a''
  6859.      release for that platform. Thanks to our large user base, problems
  6860.      are found quickly.
  6861.  
  6862.    * Our track record for making good releases is quite good.  In the
  6863.      last 150 releases, we had to do a new build for less than 10
  6864.      releases (in 3 of these cases, the bug was a faulty glibc library
  6865.      on one of our build machines that took us a long time to track
  6866.      down).
  6867.  
  6868. MySQL Binaries Compiled by MySQL AB
  6869. -----------------------------------
  6870.  
  6871. As a service, we at MySQL AB provide a set of binary distributions of
  6872. MySQL that are compiled at our site or at sites where customers kindly
  6873. have given us access to their machines.
  6874.  
  6875. In addition to the binaries provided in platform-specific package
  6876. formats (see *Note Quick Standard Installation::), we do offer binary
  6877. distributions for a number of platforms by means of compressed tar
  6878. archives (`.tar.gz').
  6879.  
  6880. These distributions are generated using the script
  6881. `Build-tools/Do-compile' which compiles the source code and creates the
  6882. binary `tar.gz' archive using `scripts/make_binary_distribution' These
  6883. binaries are configured and built with the following compilers and
  6884. options.
  6885.  
  6886. Binaries built on MySQL AB development systems:
  6887.  
  6888. Linux 2.4.xx i386 with `gcc' 2.95.3
  6889.      `CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2
  6890.      -mcpu=pentiumpro -felide-constructors" ./configure
  6891.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6892.      --enable-thread-safe-client --enable-local-infile
  6893.      --enable-assembler --disable-shared
  6894.      --with-client-ldflags=-all-static
  6895.      --with-mysqld-ldflags=-all-static'
  6896.  
  6897. Linux 2.4.xx Intel Itanium 2 with `ecc' (Intel C++ Itanium Compiler 7.0)
  6898.      `CC=ecc CFLAGS="-O2 -tpp2 -ip -nolib_inline" CXX=ecc CXXFLAGS="-O2
  6899.      -tpp2 -ip -nolib_inline" ./configure --prefix=/usr/local/mysql
  6900.      --with-extra-charsets=complex --enable-thread-safe-client
  6901.      --enable-local-infile'
  6902.  
  6903. Linux 2.4.xx Intel Itanium with `ecc' (Intel C++ Itanium Compiler 7.0)
  6904.      `CC=ecc CFLAGS=-tpp1 CXX=ecc CXXFLAGS=-tpp1 ./configure
  6905.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6906.      --enable-thread-safe-client --enable-local-infile'
  6907.  
  6908. Linux 2.4.xx alpha with `ccc' (Compaq C V6.2-505 / Compaq C++ V6.3-006)
  6909.      `CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
  6910.      generic -noexceptions -nortti" ./configure
  6911.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6912.      --enable-thread-safe-client --enable-local-infile
  6913.      --with-mysqld-ldflags=-non_shared
  6914.      --with-client-ldflags=-non_shared --disable-shared'
  6915.  
  6916. Linux 2.2.xx sparc with `egcs' 1.1.2
  6917.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6918.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6919.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6920.      --with-extra-charsets=complex --enable-thread-safe-client
  6921.      --enable-local-infile --enable-assembler --disable-shared'
  6922.  
  6923. Linux 2.4.xx s390 with `gcc' 2.95.3
  6924.      `CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors"
  6925.      ./configure --prefix=/usr/local/mysql
  6926.      --with-extra-charsets=complex --enable-thread-safe-client
  6927.      --enable-local-infile --disable-shared
  6928.      --with-client-ldflags=-all-static
  6929.      --with-mysqld-ldflags=-all-static'
  6930.  
  6931. Linux 2.4.xx x86_64 (AMD64) with `gcc' 3.2.1
  6932.      `CXX=gcc ./configure --prefix=/usr/local/mysql
  6933.      --with-extra-charsets=complex --enable-thread-safe-client
  6934.      --enable-local-infile  --disable-shared'
  6935.  
  6936. Sun Solaris 2.8 sparc with `gcc' 3.2
  6937.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6938.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6939.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6940.      --with-extra-charsets=complex --enable-thread-safe-client
  6941.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6942.      --with-named-curses-libs=-lcurses --disable-shared'
  6943.  
  6944. Sun Solaris 2.8 sparc 64bit with `gcc' 3.2
  6945.      `CC=gcc CFLAGS="-O3 -m64 -fno-omit-frame-pointer" CXX=gcc
  6946.      CXXFLAGS="-O3 -m64 -fno-omit-frame-pointer -felide-constructors
  6947.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6948.      --with-extra-charsets=complex --enable-thread-safe-client
  6949.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6950.      --with-named-curses-libs=-lcurses --disable-shared'
  6951.  
  6952. Sun Solaris 2.9 sparc with `gcc' 2.95.3
  6953.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6954.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6955.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6956.      --with-extra-charsets=complex --enable-thread-safe-client
  6957.      --enable-local-infile --enable-assembler
  6958.      --with-named-curses-libs=-lcurses --disable-shared'
  6959.  
  6960. Sun Solaris 2.9 sparc with `cc-5.0' (Sun Forte 5.0)
  6961.      `CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
  6962.      -D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
  6963.      ./configure --prefix=/usr/local/mysql
  6964.      --with-extra-charsets=complex --enable-thread-safe-client
  6965.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6966.      --enable-thread-safe-client --disable-shared'
  6967.  
  6968. IBM AIX 4.3.2 ppc with `gcc' 3.2.1
  6969.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2
  6970.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  6971.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6972.      --with-extra-charsets=complex --enable-thread-safe-client
  6973.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  6974.  
  6975. IBM AIX 5.1.0 ppc with `gcc' 3.2.1
  6976.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-O2
  6977.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  6978.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6979.      --with-extra-charsets=complex --with-server-suffix="-pro"
  6980.      --enable-thread-safe-client --enable-local-infile
  6981.      --with-named-z-libs=no --disable-shared'
  6982.  
  6983. HP-UX 10.20 pa-risc1.1 with `gcc' 3.1
  6984.      `CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc
  6985.      CXXFLAGS="-DHPUX -I/opt/dce /include -felide-constructors
  6986.      -fno-exceptions -fno-rtti -O3 -fPIC" ./configure
  6987.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6988.      --enable-thread-safe-client --enable-local-infile  --with-pthread
  6989.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  6990.      --disable-shared'
  6991.  
  6992. HP-UX 11.11 pa-risc2.0 with `aCC' (HP ANSI C++ B3910B A.03.33)
  6993.      `CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
  6994.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6995.      --enable-thread-safe-client --enable-local-infile --disable-shared'
  6996.  
  6997. Apple Mac OS X 10.2 powerpc with `gcc' 3.1
  6998.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6999.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  7000.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  7001.      --with-extra-charsets=complex --enable-thread-safe-client
  7002.      --enable-local-infile  --disable-shared'
  7003.  
  7004. FreeBSD 4.7 i386 with `gcc' 2.95.4
  7005.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  7006.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  7007.      --enable-thread-safe-client --enable-local-infile
  7008.      --enable-assembler --with-named-z-libs=not-used --disable-shared'
  7009.  
  7010. QNX Neutrino 6.2.1 i386 with `gcc' 2.95.3qnx-nto 20010315
  7011.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  7012.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  7013.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  7014.      --with-extra-charsets=complex --enable-thread-safe-client
  7015.      --enable-local-infile  --disable-shared'
  7016.  
  7017. The following binaries are built on third-party systems kindly provided
  7018. to MySQL AB by other users. Please note that these are only provided as
  7019. a courtesy. Since MySQL AB does not have full control over these
  7020. systems, we can only provide limited support for the binaries built on
  7021. these systems.
  7022.  
  7023. SCO Unix 3.2v5.0.6 i386 with `gcc' 2.95.3
  7024.      `CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3
  7025.      -mpentium -felide-constructors" ./configure
  7026.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  7027.      --enable-thread-safe-client --enable-local-infile
  7028.      --with-named-z-libs=no --enable-thread-safe-client
  7029.      --disable-shared'
  7030.  
  7031. SCO OpenUnix 8.0.0 i386 with `CC' 3.2
  7032.      `CC=cc CFLAGS="-O" CXX=CC ./configure --prefix=/usr/local/mysql
  7033.      --with-extra-charsets=complex --enable-thread-safe-client
  7034.      --enable-local-infile --with-named-z-libs=no
  7035.      --enable-thread-safe-client --disable-shared'
  7036.  
  7037. Compaq Tru64 OSF/1 V5.1 732 alpha with `cc/cxx' (Compaq C V6.3-029i / DIGITAL C++ V6.1-027)
  7038.      `CC="cc -pthread" CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline
  7039.      speed -speculate all" CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias
  7040.      -fast -inline speed -speculate all -noexceptions -nortti"
  7041.      ./configure --prefix=/usr/local/mysql
  7042.      --with-extra-charsets=complex --enable-thread-safe-client
  7043.      --enable-local-infile --with-prefix=/usr/local/mysql
  7044.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  7045.      --disable-shared --with-mysqld-ldflags=-all-static'
  7046.  
  7047. SGI Irix 6.5 IP32 with `gcc' 3.0.1
  7048.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
  7049.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  7050.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  7051.      --with-extra-charsets=complex --enable-thread-safe-client
  7052.      --enable-local-infile  --disable-shared'
  7053.  
  7054. The following compile options have been used for binary packages MySQL
  7055. AB used to provide in the past. These binaries are no longer being
  7056. updated, but the compile options are kept here for reference purposes.
  7057.  
  7058. Linux 2.2.x with x686 with `gcc' 2.95.2
  7059.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  7060.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  7061.      --prefix=/usr/local/mysql --enable-assembler
  7062.      --with-mysqld-ldflags=-all-static --disable-shared
  7063.      --with-extra-charsets=complex'
  7064.  
  7065. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1
  7066.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  7067.      --prefix=/usr/local/mysql --disable-shared
  7068.      --with-extra-charsets=complex --enable-assembler'
  7069.  
  7070. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or gcc 2.95.2 and newer
  7071.      `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors
  7072.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  7073.      --with-low-memory --with-extra-charsets=complex --enable-assembler'
  7074.  
  7075. SunOS 5.6 i86pc with `gcc' 2.8.1
  7076.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  7077.      --with-low-memory --with-extra-charsets=complex'
  7078.  
  7079. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1
  7080.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  7081.      --with-extra-charsets=complex'
  7082.  
  7083. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2
  7084.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  7085.      --with-extra-charsets=complex'
  7086.  
  7087. AIX 2 4 with `gcc' 2.7.2.2
  7088.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  7089.      --with-extra-charsets=complex'
  7090.  
  7091. Anyone who has more optimal options for any of the preceding
  7092. configurations listed can always mail them to the developer's mailing
  7093. list at <internals@lists.mysql.com>.
  7094.  
  7095. RPM distributions prior to MySQL Version 3.22 are user-contributed.
  7096. Beginning with Version 3.22, the RPMs are generated by us at MySQL AB.
  7097.  
  7098. If you want to compile a debug version of MySQL, you should add
  7099. `--with-debug' or `--with-debug=full' to the preceding configure lines
  7100. and remove any `-fomit-frame-pointer' options.
  7101.  
  7102. For the Windows distribution, please see *Note Windows installation::.
  7103.  
  7104. Installing a MySQL Binary Distribution
  7105. --------------------------------------
  7106.  
  7107. This chapter covers the installation of MySQL binary distributions
  7108. (`.tar.gz' Archives) for various platforms (see *Note MySQL binaries::
  7109. for a detailed list).
  7110.  
  7111. In addition to these generic packages, we also offer binaries in
  7112. platform-specific package formats for selected platforms.  See *Note
  7113. Quick Standard Installation:: for more info on how to install these.
  7114.  
  7115. The generic MySQL binary distributions are packaged as gzip-compressed
  7116. GNU tar archives (`.tar.gz'). You need the following tools to install a
  7117. MySQL binary distribution:
  7118.  
  7119.    * GNU `gunzip' to uncompress the distribution.
  7120.  
  7121.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  7122.      to work. Some `tar' implementations that come pre-installed with
  7123.      the operating system (e.g. Sun `tar') are known to have problems
  7124.      (with long file names, for example). In that case, you should
  7125.      install GNU `tar' first.
  7126.  
  7127. If you run into problems, *please always use `mysqlbug'* when posting
  7128. questions to <mysql@lists.mysql.com>.  Even if the problem isn't a bug,
  7129. `mysqlbug' gathers system information that will help others solve your
  7130. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  7131. a solution to your problem.  You will find `mysqlbug' in the `bin'
  7132. directory after you unpack the distribution.  *Note Bug reports::.
  7133.  
  7134. The basic commands you must execute to install and use a MySQL binary
  7135. distribution are:
  7136.  
  7137.      shell> groupadd mysql
  7138.      shell> useradd -g mysql mysql
  7139.      shell> cd /usr/local
  7140.      shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  7141.      shell> ln -s full-path-to-mysql-VERSION-OS mysql
  7142.      shell> cd mysql
  7143.      shell> scripts/mysql_install_db
  7144.      shell> chown -R root  .
  7145.      shell> chown -R mysql data
  7146.      shell> chgrp -R mysql .
  7147.      shell> bin/mysqld_safe --user=mysql &
  7148.      or
  7149.      shell> bin/mysqld_safe --user=mysql &
  7150.      if you are running MySQL 4.x
  7151.  
  7152. You can add new users using the `bin/mysql_setpermission' script if you
  7153. install the `DBI' and `DBD-mysql' Perl modules.
  7154.  
  7155. A more detailed description follows.
  7156.  
  7157. To install a binary distribution, follow these steps, then proceed to
  7158. *Note Post-installation::, for post-installation setup and testing:
  7159.  
  7160.   1. Pick the directory under which you want to unpack the
  7161.      distribution, and move into it.  In the following example, we
  7162.      unpack the distribution under `/usr/local' and create a directory
  7163.      `/usr/local/mysql' into which MySQL is installed.  (The following
  7164.      instructions, therefore, assume you have permission to create
  7165.      files in `/usr/local'.  If that directory is protected, you will
  7166.      need to perform the installation as `root'.)
  7167.  
  7168.   2. Obtain a distribution file from one of the sites listed in *Note
  7169.      Getting MySQL: Getting MySQL.
  7170.  
  7171.      MySQL binary distributions are provided as compressed `tar'
  7172.      archives and have names like `mysql-VERSION-OS.tar.gz', where
  7173.      `VERSION' is a number (for example, `3.21.15'), and `OS' indicates
  7174.      the type of operating system for which the distribution is intended
  7175.      (for example, `pc-linux-gnu-i586').  Note that all binaries are
  7176.      built from the same MySQL source distribution.
  7177.  
  7178.   3. Add a user and group for `mysqld' to run as:
  7179.  
  7180.           shell> groupadd mysql
  7181.           shell> useradd -g mysql mysql
  7182.  
  7183.      These commands add the `mysql' group and the `mysql' user.  The
  7184.      syntax for `useradd' and `groupadd' may differ slightly on
  7185.      different versions of Unix.  They may also be called `adduser' and
  7186.      `addgroup'.  You may wish to call the user and group something
  7187.      else instead of `mysql'.
  7188.  
  7189.   4. Change into the intended installation directory:
  7190.  
  7191.           shell> cd /usr/local
  7192.  
  7193.   5. Unpack the distribution and create the installation directory:
  7194.  
  7195.           shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  7196.           shell> ln -s full-path-to-mysql-VERSION-OS mysql
  7197.  
  7198.      Using GNU tar, you can also replace the first line with the
  7199.      following alternative command to decompress and extract the
  7200.      distribution in one go:
  7201.  
  7202.           shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
  7203.  
  7204.      The first command creates a directory named `mysql-VERSION-OS'.
  7205.      The second command makes a symbolic link to that directory.  This
  7206.      lets you refer more easily to the installation directory as
  7207.      `/usr/local/mysql'.
  7208.  
  7209.   6. Change into the installation directory:
  7210.  
  7211.           shell> cd mysql
  7212.  
  7213.      You will find several files and subdirectories in the `mysql'
  7214.      directory.  The most important for installation purposes are the
  7215.      `bin' and `scripts' subdirectories.
  7216.  
  7217.     `bin'
  7218.           This directory contains client programs and the server You
  7219.           should add the full pathname of this directory to your `PATH'
  7220.           environment variable so that your shell finds the MySQL
  7221.           programs properly. *Note Environment variables::.
  7222.  
  7223.     `scripts'
  7224.           This directory contains the `mysql_install_db' script used to
  7225.           initialise the `mysql' database containing the grant tables
  7226.           that store the server access permissions.
  7227.  
  7228.   7. If you would like to use `mysqlaccess' and have the MySQL
  7229.      distribution in some non-standard place, you must change the
  7230.      location where `mysqlaccess' expects to find the `mysql' client.
  7231.      Edit the `bin/mysqlaccess' script at approximately line 18.
  7232.      Search for a line that looks like this:
  7233.  
  7234.           $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
  7235.  
  7236.      Change the path to reflect the location where `mysql' actually is
  7237.      stored on your system.  If you do not do this, you will get a
  7238.      `Broken pipe' error when you run `mysqlaccess'.
  7239.  
  7240.   8. Create the MySQL grant tables (necessary only if you haven't
  7241.      installed MySQL before):
  7242.           shell> scripts/mysql_install_db
  7243.  
  7244.      Note that MySQL versions older than Version 3.22.10 started the
  7245.      MySQL server when you run `mysql_install_db'.  This is no longer
  7246.      true.
  7247.  
  7248.   9. Change ownership of binaries to `root' and ownership of the data
  7249.      directory to the user that you will run `mysqld' as:
  7250.  
  7251.           shell> chown -R root  /usr/local/mysql/.
  7252.           shell> chown -R mysql /usr/local/mysql/data
  7253.           shell> chgrp -R mysql /usr/local/mysql/.
  7254.  
  7255.      The first command changes the `owner' attribute of the files to the
  7256.      `root' user, the second one changes the `owner' attribute of the
  7257.      data directory to the `mysql' user, and the third one changes the
  7258.      `group' attribute to the `mysql' group.
  7259.  
  7260.  10. If you want to install support for the Perl `DBI'/`DBD' interface,
  7261.      see *Note Perl support::.
  7262.  
  7263.  11. If you would like MySQL to start automatically when you boot your
  7264.      machine, you can copy `support-files/mysql.server' to the location
  7265.      where your system has its startup files.  More information can be
  7266.      found in the `support-files/mysql.server' script itself and in
  7267.      *Note Automatic start::.
  7268.  
  7269.  
  7270. After everything has been unpacked and installed, you should initialise
  7271. and test your distribution.
  7272.  
  7273. You can start the MySQL server with the following command:
  7274.  
  7275.      shell> bin/mysqld_safe --user=mysql &
  7276.  
  7277. Now proceed to *Note `mysqld_safe': mysqld_safe, and *Note
  7278. Post-installation::.
  7279.  
  7280. Installing a MySQL Source Distribution
  7281. ======================================
  7282.  
  7283. Before you proceed with the source installation, check first to see if
  7284. our binary is available for your platform and if it will work for you.
  7285. We put a lot of effort into making sure that our binaries are built
  7286. with the best possible options.
  7287.  
  7288. You need the following tools to build and install MySQL from source:
  7289.  
  7290.    * GNU `gunzip' to uncompress the distribution.
  7291.  
  7292.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  7293.      to work. Some `tar' implementations that come pre-installed with
  7294.      the operating system (e.g. Sun `tar') are known to have problems
  7295.      (with long file names, for example). In that case, you should
  7296.      install GNU `tar' first.
  7297.  
  7298.    * A working ANSI C++ compiler.  `gcc' >= 2.95.2, `egcs' >= 1.0.2 or
  7299.      `egcs 2.91.66', SGI C++, and SunPro C++ are some of the compilers
  7300.      that are known to work.  `libg++' is not needed when using `gcc'.
  7301.      `gcc' 2.7.x has a bug that makes it impossible to compile some
  7302.      perfectly legal C++ files, such as `sql/sql_base.cc'.  If you only
  7303.      have `gcc' 2.7.x, you must upgrade your `gcc' to be able to
  7304.      compile MySQL. `gcc' 2.8.1 is also known to have problems on some
  7305.      platforms, so it should be avoided if a new compiler exists for
  7306.      the platform.
  7307.  
  7308.      `gcc' >= 2.95.2 is recommended when compiling MySQL Version 3.23.x.
  7309.  
  7310.    * A good `make' program.  GNU `make' is always recommended and is
  7311.      sometimes required.  If you have problems, we recommend trying GNU
  7312.      `make' 3.75 or newer.
  7313.  
  7314. If you are using a recent version of `gcc', recent enough to understand
  7315. the `-fno-exceptions' option, it is *very important* that you use it.
  7316. Otherwise, you may compile a binary that crashes randomly. We also
  7317. recommend that you use `-felide-constructors' and `-fno-rtti' along
  7318. with `-fno-exceptions'. When in doubt, do the following:
  7319.  
  7320.  
  7321.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions \
  7322.             -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler \
  7323.             --with-mysqld-ldflags=-all-static
  7324.  
  7325. On most systems this will give you a fast and stable binary.
  7326.  
  7327. If you run into problems, *please always use `mysqlbug'* when posting
  7328. questions to <mysql@lists.mysql.com>.  Even if the problem isn't a bug,
  7329. `mysqlbug' gathers system information that will help others solve your
  7330. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  7331. a solution to your problem.  You will find `mysqlbug' in the `scripts'
  7332. directory after you unpack the distribution.  *Note Bug reports::.
  7333.  
  7334. Quick Installation Overview
  7335. ---------------------------
  7336.  
  7337. The basic commands you must execute to install a MySQL source
  7338. distribution are:
  7339.  
  7340.      shell> groupadd mysql
  7341.      shell> useradd -g mysql mysql
  7342.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  7343.      shell> cd mysql-VERSION
  7344.      shell> ./configure --prefix=/usr/local/mysql
  7345.      shell> make
  7346.      shell> make install
  7347.      shell> scripts/mysql_install_db
  7348.      shell> chown -R root  /usr/local/mysql
  7349.      shell> chown -R mysql /usr/local/mysql/var
  7350.      shell> chgrp -R mysql /usr/local/mysql
  7351.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  7352.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  7353.  
  7354. If your version of MySQL is older than 4.0, use `safe_mysqld' rather
  7355. than `mysqld_safe'.
  7356.  
  7357. If you want to have support for InnoDB tables, you should edit the
  7358. `/etc/my.cnf' file and remove the `#' character before the parameter
  7359. that starts with `innodb_...'.  *Note Option files::, and *Note InnoDB
  7360. start::.
  7361.  
  7362. If you start from a source RPM, do the following:
  7363.  
  7364.      shell> rpm --rebuild --clean MySQL-VERSION.src.rpm
  7365.  
  7366. This will make a binary RPM that you can install.
  7367.  
  7368. You can add new users using the `bin/mysql_setpermission' script if you
  7369. install the `DBI' and `DBD-mysql' Perl modules.
  7370.  
  7371. A more detailed description follows.
  7372.  
  7373. To install a source distribution, follow these steps, then proceed to
  7374. *Note Post-installation::, for post-installation initialisation and
  7375. testing:
  7376.  
  7377.   1. Pick the directory under which you want to unpack the
  7378.      distribution, and move into it.
  7379.  
  7380.   2. Obtain a distribution file from one of the sites listed in *Note
  7381.      Getting MySQL: Getting MySQL.
  7382.  
  7383.   3. If you are interested in using Berkeley DB tables with MySQL, you
  7384.      will need to obtain a patched version of the Berkeley DB source
  7385.      code.  Please read the chapter on Berkeley DB tables before
  7386.      proceeding.  *Note BDB::.
  7387.  
  7388.      MySQL source distributions are provided as compressed `tar'
  7389.      archives and have names like `mysql-VERSION.tar.gz', where
  7390.      `VERSION' is a number like {No value for `mysqlversion'}.
  7391.  
  7392.   4. Add a user and group for `mysqld' to run as:
  7393.  
  7394.           shell> groupadd mysql
  7395.           shell> useradd -g mysql mysql
  7396.  
  7397.      These commands add the `mysql' group and the `mysql' user.  The
  7398.      syntax for `useradd' and `groupadd' may differ slightly on
  7399.      different versions of Unix.  They may also be called `adduser' and
  7400.      `addgroup'.  You may wish to call the user and group something
  7401.      else instead of `mysql'.
  7402.  
  7403.   5. Unpack the distribution into the current directory:
  7404.           shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
  7405.  
  7406.      This command creates a directory named `mysql-VERSION'.
  7407.  
  7408.   6. Change into the top-level directory of the unpacked distribution:
  7409.  
  7410.           shell> cd mysql-VERSION
  7411.  
  7412.      Note that currently you must configure and build MySQL from this
  7413.      top-level directory.  You cannot build it in a different directory.
  7414.  
  7415.   7. Configure the release and compile everything:
  7416.  
  7417.           shell> ./configure --prefix=/usr/local/mysql
  7418.           shell> make
  7419.  
  7420.      When you run `configure', you might want to specify some options.
  7421.      Run `./configure --help' for a list of options.  *Note `configure'
  7422.      options: configure options, discusses some of the more useful
  7423.      options.
  7424.  
  7425.      If `configure' fails, and you are going to send mail to
  7426.      <mysql@lists.mysql.com> to ask for assistance, please include any
  7427.      lines from `config.log' that you think can help solve the problem.
  7428.      Also include the last couple of lines of output from `configure'
  7429.      if `configure' aborts.  Post the bug report using the `mysqlbug'
  7430.      script.  *Note Bug reports::.
  7431.  
  7432.      If the compile fails, see *Note Compilation problems::, for help
  7433.      with a number of common problems.
  7434.  
  7435.   8. Install everything:
  7436.  
  7437.           shell> make install
  7438.  
  7439.      You might need to run this command as `root'.
  7440.  
  7441.   9. Create the MySQL grant tables (necessary only if you haven't
  7442.      installed MySQL before):
  7443.  
  7444.           shell> scripts/mysql_install_db
  7445.  
  7446.      Note that MySQL versions older than Version 3.22.10 started the
  7447.      MySQL server when you run `mysql_install_db'.  This is no longer
  7448.      true.
  7449.  
  7450.  10. Change ownership of binaries to `root' and ownership of the data
  7451.      directory to the user that you will run `mysqld' as:
  7452.  
  7453.           shell> chown -R root  /usr/local/mysql
  7454.           shell> chown -R mysql /usr/local/mysql/var
  7455.           shell> chgrp -R mysql /usr/local/mysql
  7456.  
  7457.      The first command changes the `owner' attribute of the files to the
  7458.      `root' user, the second one changes the `owner' attribute of the
  7459.      data directory to the `mysql' user, and the third one changes the
  7460.      `group' attribute to the `mysql' group.
  7461.  
  7462.  11. If you want to install support for the Perl `DBI'/`DBD' interface,
  7463.      see *Note Perl support::.
  7464.  
  7465.  12. If you would like MySQL to start automatically when you boot your
  7466.      machine, you can copy `support-files/mysql.server' to the location
  7467.      where your system has its startup files.  More information can be
  7468.      found in the `support-files/mysql.server' script itself and in
  7469.      *Note Automatic start::.
  7470.  
  7471. After everything has been installed, you should initialise and test your
  7472. distribution:
  7473.  
  7474.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  7475.  
  7476. If that command fails immediately with `mysqld daemon ended', you can
  7477. find some information in the file `mysql-data-directory/'hostname'.err'.
  7478. The likely reason is that you already have another `mysqld' server
  7479. running.  *Note Multiple servers::.
  7480.  
  7481. Now proceed to *Note Post-installation::.
  7482.  
  7483. Applying Patches
  7484. ----------------
  7485.  
  7486. Sometimes patches appear on the mailing list or are placed in the
  7487. patches area of the MySQL web site
  7488. (`http://www.mysql.com/downloads/patches.html').
  7489.  
  7490. To apply a patch from the mailing list, save the message in which the
  7491. patch appears in a file, change into the top-level directory of your
  7492. MySQL source tree, and run these commands:
  7493.  
  7494.      shell> patch -p1 < patch-file-name
  7495.      shell> rm config.cache
  7496.      shell> make clean
  7497.  
  7498. Patches from the FTP site are distributed as plain text files or as
  7499. files compressed with `gzip'.  Apply a plain patch as shown previously
  7500. for mailing list patches.  To apply a compressed patch, change into the
  7501. top-level directory of your MySQL source tree and run these commands:
  7502.  
  7503.      shell> gunzip < patch-file-name.gz | patch -p1
  7504.      shell> rm config.cache
  7505.      shell> make clean
  7506.  
  7507. After applying a patch, follow the instructions for a normal source
  7508. install, beginning with the `./configure' step.  After running the `make
  7509. install' step, restart your MySQL server.
  7510.  
  7511. You may need to bring down any currently running server before you run
  7512. `make install'.  (Use `mysqladmin shutdown' to do this.)  Some systems
  7513. do not allow you to install a new version of a program if it replaces
  7514. the version that is currently executing.
  7515.  
  7516. Typical `configure' Options
  7517. ---------------------------
  7518.  
  7519. The `configure' script gives you a great deal of control over how you
  7520. configure your MySQL distribution.  Typically you do this using options
  7521. on the `configure' command-line.  You can also affect `configure' using
  7522. certain environment variables.  *Note Environment variables::.  For a
  7523. list of options supported by `configure', run this command:
  7524.  
  7525.      shell> ./configure --help
  7526.  
  7527. Some of the more commonly-used `configure' options are described here:
  7528.  
  7529.    * To compile just the MySQL client libraries and client programs and
  7530.      not the server, use the `--without-server' option:
  7531.  
  7532.           shell> ./configure --without-server
  7533.  
  7534.      If you don't have a C++ compiler, `mysql' will not compile (it is
  7535.      the one client program that requires C++).  In this case, you can
  7536.      remove the code in `configure' that tests for the C++ compiler and
  7537.      then run `./configure' with the `--without-server' option. The
  7538.      compile step will still try to build `mysql', but you can ignore
  7539.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  7540.      tell it to continue with the rest of the build even if errors
  7541.      occur.)
  7542.  
  7543.    * If you want to get an embedded MySQL library (`libmysqld.a') you
  7544.      should use the `--with-embedded-server' option.
  7545.  
  7546.    * If you don't want your log files and database directories located
  7547.      under `/usr/local/var', use a `configure' command, something like
  7548.      one of these:
  7549.  
  7550.           shell> ./configure --prefix=/usr/local/mysql
  7551.           shell> ./configure --prefix=/usr/local \
  7552.                      --localstatedir=/usr/local/mysql/data
  7553.  
  7554.      The first command changes the installation prefix so that
  7555.      everything is installed under `/usr/local/mysql' rather than the
  7556.      default of `/usr/local'.  The second command preserves the default
  7557.      installation prefix, but overrides the default location for
  7558.      database directories (normally `/usr/local/var') and changes it to
  7559.      `/usr/local/mysql/data'.  After you have compiled MySQL, you can
  7560.      change these options with option files. *Note Option files::.
  7561.  
  7562.    * If you are using Unix and you want the MySQL socket located
  7563.      somewhere other than the default location (normally in the
  7564.      directory `/tmp' or `/var/run') use a `configure' command like
  7565.      this:
  7566.  
  7567.           shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  7568.  
  7569.      Note that the given file must be an absolute pathname.  You can
  7570.      also later change the location `mysql.sock' by using the MySQL
  7571.      option files. *Note Problems with mysql.sock::.
  7572.  
  7573.    * If you want to compile statically linked programs (for example, to
  7574.      make a binary distribution, to get more speed, or to work around
  7575.      problems with some Red Hat Linux distributions), run `configure'
  7576.      like this:
  7577.  
  7578.           shell> ./configure --with-client-ldflags=-all-static \
  7579.                      --with-mysqld-ldflags=-all-static
  7580.  
  7581.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  7582.      installed, you can tell `configure' to use `gcc' as your C++
  7583.      compiler:
  7584.  
  7585.           shell> CC=gcc CXX=gcc ./configure
  7586.  
  7587.      When you use `gcc' as your C++ compiler, it will not attempt to
  7588.      link in `libg++' or `libstdc++'.  This may be a good idea to do
  7589.      even if you have the above libraries installed, as some versions
  7590.      of these libraries have caused strange problems for MySQL users in
  7591.      the past.
  7592.  
  7593.      Here are some common environment variables to set depending on the
  7594.      compiler you are using:
  7595.  
  7596.      *Compiler*    *Recommended options*
  7597.      gcc 2.7.2.1    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
  7598.      egcs 1.0.3a    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors
  7599.                    -fno-exceptions -fno-rtti"
  7600.      gcc 2.95.2     CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3
  7601.                    -mpentiumpro \ -felide-constructors -fno-exceptions
  7602.                    -fno-rtti"
  7603.      pgcc 2.90.29   CFLAGS="-O3 -mpentiumpro -mstack-align-double"
  7604.      or newer      CXX=gcc \ CXXFLAGS="-O3 -mpentiumpro
  7605.                    -mstack-align-double -felide-constructors \
  7606.                    -fno-exceptions -fno-rtti"
  7607.  
  7608.      In most cases you can get a reasonably optimal MySQL binary by
  7609.      using the options from the preceding table and adding the
  7610.      following options to the configure line:
  7611.  
  7612.           --prefix=/usr/local/mysql --enable-assembler \
  7613.           --with-mysqld-ldflags=-all-static
  7614.  
  7615.      The full configure line would, in other words, be something like
  7616.      the following for all recent gcc versions:
  7617.  
  7618.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  7619.           -felide-constructors -fno-exceptions -fno-rtti" ./configure \
  7620.           --prefix=/usr/local/mysql --enable-assembler \
  7621.           --with-mysqld-ldflags=-all-static
  7622.  
  7623.      The binaries we provide on the MySQL web site at
  7624.      `http://www.mysql.com/' are all compiled with full optimisation and
  7625.      should be perfect for most users.  *Note MySQL binaries::.  There
  7626.      are some things you can tweak to make an even faster binary, but
  7627.      this is only for advanced users.  *Note Compile and link options::.
  7628.  
  7629.      If the build fails and produces errors about your compiler or
  7630.      linker not being able to create the shared library
  7631.      `libmysqlclient.so.#' (`#' is a version number), you can work
  7632.      around this problem by giving the `--disable-shared' option to
  7633.      `configure'.  In this case, `configure' will not build a shared
  7634.      `libmysqlclient.so.#' library.
  7635.  
  7636.    * You can configure MySQL not to use `DEFAULT' column values for
  7637.      non-`NULL' columns (that is, columns that are not allowed to be
  7638.      `NULL'). *Note constraint NOT NULL::.
  7639.  
  7640.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  7641.  
  7642.    * By default, MySQL uses the ISO-8859-1 (Latin1) character set. To
  7643.      change the default set, use the `--with-charset' option:
  7644.           shell> ./configure --with-charset=CHARSET
  7645.      `CHARSET' may be one of `big5', `cp1251', `cp1257', `czech',
  7646.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  7647.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  7648.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  7649.      `win1251ukr'.  *Note Character sets::.
  7650.  
  7651.      If you want to convert characters between the server and the
  7652.      client, you should take a look at the `SET CHARACTER SET' command.
  7653.      *Note `SET': SET OPTION.
  7654.  
  7655.      *Warning*: If you change character sets after having created any
  7656.      tables, you will have to run `myisamchk -r -q
  7657.      --set-character-set=charset' on every table. Your indexes may be
  7658.      sorted incorrectly otherwise.  (This can happen if you install
  7659.      MySQL, create some tables, then reconfigure MySQL to use a
  7660.      different character set and reinstall it.)
  7661.  
  7662.      With the option `--with-extra-charsets=LIST' you can define which
  7663.      additional character sets should be compiled into the server.
  7664.  
  7665.      Here `LIST' is either a list of character sets separated with
  7666.      spaces, `complex' to include all characters that can't be
  7667.      dynamically loaded, or `all' to include all character sets into
  7668.      the binaries.
  7669.  
  7670.    * To configure MySQL with debugging code, use the `--with-debug'
  7671.      option:
  7672.           shell> ./configure --with-debug
  7673.      This causes a safe memory allocator to be included that can find
  7674.      some errors and that provides output about what is happening.
  7675.      *Note Debugging server::.
  7676.  
  7677.    * If your client programs are using threads, you need to also
  7678.      compile a thread-safe version of the MySQL client library with the
  7679.      `--enable-thread-safe-client' configure options. This will create a
  7680.      `libmysqlclient_r' library with which you should link your threaded
  7681.      applications.  *Note Threaded clients::.
  7682.  
  7683.    * Options that pertain to particular systems can be found in the
  7684.      system-specific section of this manual.  *Note Operating System
  7685.      Specific Notes::.
  7686.  
  7687. Installing from the Development Source Tree
  7688. -------------------------------------------
  7689.  
  7690. *Caution*: You should read this section only if you are interested in
  7691. helping us test our new code. If you just want to get MySQL up and
  7692. running on your system, you should use a standard release distribution
  7693. (either a source or binary distribution will do).
  7694.  
  7695. To obtain our most recent development source tree, use these
  7696. instructions:
  7697.  
  7698.   1. Download `BitKeeper' from
  7699.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  7700.      `Bitkeeper' 3.0 or newer to access our repository.
  7701.  
  7702.   2. Follow the instructions to install it.
  7703.  
  7704.   3. After `BitKeeper' is installed, first go to the directory you want
  7705.      to work from, and then use one of the following commands to clone
  7706.      the MySQL version branch of your choice:
  7707.  
  7708.      To clone the 3.23 (old) branch, use this command:
  7709.  
  7710.           shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
  7711.  
  7712.      To clone the 4.0 (stable/production) branch, use this command:
  7713.  
  7714.           shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
  7715.  
  7716.      To clone the 4.1 alpha branch, use this command:
  7717.  
  7718.           shell> bk clone bk://mysql.bkbits.net/mysql-4.1 mysql-4.1
  7719.  
  7720.      To clone the 5.0 development branch, use this command:
  7721.  
  7722.           shell> bk clone bk://mysql.bkbits.net/mysql-5.0 mysql-5.0
  7723.  
  7724.      In the preceding examples the source tree will be set up in the
  7725.      `mysql-3.23/', `mysql-4.0/', `mysql-4.1/', or `mysql-5.0/'
  7726.      subdirectory of your current directory.
  7727.  
  7728.      If you are behind a firewall and can only initiate HTTP
  7729.      connections, you can also use `BitKeeper' via HTTP.
  7730.  
  7731.      If you are required to use a proxy server, simply set the
  7732.      environment variable `http_proxy' to point to your proxy:
  7733.  
  7734.           shell> export http_proxy="http://your.proxy.server:8080/"
  7735.  
  7736.      Now, simply replace the `bk://' with `http://' when doing a clone.
  7737.      Example:
  7738.  
  7739.           shell> bk clone http://mysql.bkbits.net/mysql-4.1 mysql-4.1
  7740.  
  7741.      The initial download of the source tree may take a while,
  7742.      depending on the speed of your connection - please be patient.
  7743.  
  7744.   4. You will need *GNU* `make', `autoconf 2.53 (or newer)', `automake
  7745.      1.5', `libtool 1.4', and `m4' to run the next set of commands.
  7746.      Even though many operating system already come with their own
  7747.      implementation of `make', chances are high that the compilation
  7748.      fails with strange error messages. Therefore it is highly
  7749.      recommended to use GNU `make' (sometimes also named `gmake') by
  7750.      all means.
  7751.  
  7752.      Fortunately, a large number of operating systems already ship with
  7753.      the GNU toolchain preinstalled or supply installable packages of
  7754.      these. In any case, they can also be downloaded from the following
  7755.      locations:
  7756.  
  7757.         * <http://www.gnu.org/software/autoconf/>
  7758.  
  7759.         * <http://www.gnu.org/software/automake/>
  7760.  
  7761.         * <http://www.gnu.org/software/libtool/>
  7762.  
  7763.         * <http://www.gnu.org/software/make/>
  7764.  
  7765.      If you are trying to configure MySQL 4.1, you will also need GNU
  7766.      `bison 1.75'.  Older versions of `bison' may report this error:
  7767.      `sql_yacc.yy:#####: fatal error: maximum table size (32767)
  7768.      exceeded'. Note: the maximum table size is not actually exceeded,
  7769.      the error is caused by bugs in these earlier `bison' versions.
  7770.  
  7771.      Versions of MySQL before version 4.1 may also compile with other
  7772.      `yacc' implementations (e.g. BSD `yacc' 91.7.30). For later
  7773.      versions, GNU `bison' is a requirement.
  7774.  
  7775.      The typical command to do in a shell is:
  7776.  
  7777.           cd mysql-4.0
  7778.           bk -r edit
  7779.           aclocal; autoheader; autoconf; automake
  7780.           (cd innobase ; aclocal; autoheader; autoconf; automake) # for InnoDB
  7781.           (cd bdb/dist ; sh s_all ) # for Berkeley DB
  7782.           ./configure  # Add your favorite options here
  7783.           make
  7784.  
  7785.      If you get some strange error during this stage, check that you
  7786.      really have `libtool' installed.
  7787.  
  7788.      A collection of our standard configure scripts is located in the
  7789.      `BUILD/' subdirectory.  If you are lazy, you can use
  7790.      `BUILD/compile-pentium-debug'. To compile on a different
  7791.      architecture, modify the script by removing flags that are
  7792.      Pentium-specific.
  7793.  
  7794.   5. When the build is done, run `make install'.  Be careful with this
  7795.      on a production machine; the command may overwrite your live
  7796.      release installation.  If you have another installation of MySQL,
  7797.      we recommend that you run `./configure' with different values for
  7798.      the `prefix', `with-tcp-port', and `unix-socket-path' options than
  7799.      those used for your production server.
  7800.  
  7801.   6. Play hard with your new installation and try to make the new
  7802.      features crash.  Start by running `make test'.  *Note MySQL test
  7803.      suite::.
  7804.  
  7805.   7. If you have gotten to the `make' stage and the distribution does
  7806.      not compile, please report it in our bugs database at
  7807.      `http://bugs.mysql.com/'.  If you have installed the latest
  7808.      versions of the required GNU tools, and they crash trying to
  7809.      process our configuration files, please report that also.
  7810.      However, if you execute `aclocal' and get a `command not found'
  7811.      error or a similar problem, do not report it.  Instead, make sure
  7812.      all the necessary tools are installed and that your `PATH'
  7813.      variable is set correctly so that your shell can find them.
  7814.  
  7815.   8. After the initial `bk clone' operation to get the source tree, you
  7816.      should run `bk pull' periodically to get the updates.
  7817.  
  7818.   9. You can examine the change history for the tree with all the diffs
  7819.      by using `bk sccstool'.  If you see some funny diffs or code that
  7820.      you have a question about, do not hesitate to send e-mail to
  7821.      <internals@lists.mysql.com>. Also, if you think you have a better
  7822.      idea on how to do something, send an e-mail to the same address
  7823.      with a patch.  `bk diffs' will produce a patch for you after you
  7824.      have made changes to the source. If you do not have the time to
  7825.      code your idea, just send a description.
  7826.  
  7827.  10. `BitKeeper' has a nice help utility that you can access via `bk
  7828.      helptool'.
  7829.  
  7830.  11. Please note that any commits (`bk ci' or `bk citool') will trigger
  7831.      the posting of a message with the changeset to our internals
  7832.      mailing list, as well as the usual openlogging.org submission with
  7833.      just the changeset comments.  Generally, you wouldn't need to use
  7834.      commit (since the public tree will not allow `bk push'), but
  7835.      rather use the `bk diffs' method described previously.
  7836.  
  7837.  
  7838. You can also browse changesets, comments and sourcecode online by
  7839. browsing to for example, `http://mysql.bkbits.net:8080/mysql-4.1' For
  7840. MySQL 4.1.
  7841.  
  7842. The manual is in a separate tree which can be cloned with:
  7843.  
  7844.      shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
  7845.  
  7846. There are also public BitKeeper trees for MySQL Control Center and
  7847. Connector/ODBC. They can be cloned respectively as follows.
  7848.  
  7849. To clone MySQL Control center, use this command:
  7850.  
  7851.      shell> bk clone http://mysql.bkbits.net/mysqlcc mysqlcc
  7852.  
  7853. To clone Connector/ODBC, use this command:
  7854.  
  7855.      shell> bk clone http://mysql.bkbits.net/myodbc3 myodbc3
  7856.  
  7857. Problems Compiling MySQL?
  7858. -------------------------
  7859.  
  7860. All MySQL programs compile cleanly for us with no warnings on Solaris
  7861. or Linux using `gcc'.  On other systems, warnings may occur due to
  7862. differences in system include files.  See *Note MIT-pthreads:: for
  7863. warnings that may occur when using MIT-pthreads.  For other problems,
  7864. check the following list.
  7865.  
  7866. The solution to many problems involves reconfiguring.  If you do need to
  7867. reconfigure, take note of the following:
  7868.  
  7869.    * If `configure' is run after it already has been run, it may use
  7870.      information that was gathered during its previous invocation.  This
  7871.      information is stored in `config.cache'.  When `configure' starts
  7872.      up, it looks for that file and reads its contents if it exists, on
  7873.      the assumption that the information is still correct.  That
  7874.      assumption is invalid when you reconfigure.
  7875.  
  7876.    * Each time you run `configure', you must run `make' again to
  7877.      recompile.  However, you may want to remove old object files from
  7878.      previous builds first because they were compiled using different
  7879.      configuration options.
  7880.  
  7881. To prevent old configuration information or object files from being
  7882. used, run these commands before rerunning `configure':
  7883.  
  7884.      shell> rm config.cache
  7885.      shell> make clean
  7886.  
  7887. Alternatively, you can run `make distclean'.
  7888.  
  7889. The following list describes some of the problems when compiling MySQL
  7890. that have been found to occur most often:
  7891.  
  7892.    * If you get errors when compiling `sql_yacc.cc', such as the ones
  7893.      shown here, you have probably run out of memory or swap space:
  7894.  
  7895.           Internal compiler error: program cc1plus got fatal signal 11
  7896.             or
  7897.           Out of virtual memory
  7898.             or
  7899.           Virtual memory exhausted
  7900.  
  7901.      The problem is that `gcc' requires huge amounts of memory to
  7902.      compile `sql_yacc.cc' with inline functions.  Try running
  7903.      `configure' with the `--with-low-memory' option:
  7904.  
  7905.           shell> ./configure --with-low-memory
  7906.  
  7907.      This option causes `-fno-inline' to be added to the compile line
  7908.      if you are using `gcc' and `-O0' if you are using something else.
  7909.      You should try the `--with-low-memory' option even if you have so
  7910.      much memory and swap space that you think you can't possibly have
  7911.      run out.  This problem has been observed to occur even on systems
  7912.      with generous hardware configurations, and the `--with-low-memory'
  7913.      option usually fixes it.
  7914.  
  7915.    * By default, `configure' picks `c++' as the compiler name and GNU
  7916.      `c++' links with `-lg++'.  If you are using `gcc', that behaviour
  7917.      can cause problems during configuration such as this:
  7918.  
  7919.           configure: error: installation or configuration problem:
  7920.           C++ compiler cannot create executables.
  7921.  
  7922.      You might also observe problems during compilation related to
  7923.      `g++', `libg++', or `libstdc++'.
  7924.  
  7925.      One cause of these problems is that you may not have `g++', or you
  7926.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  7927.      the `config.log' file.  It should contain the exact reason why
  7928.      your C++ compiler didn't work.  To work around these problems, you
  7929.      can use `gcc' as your C++ compiler.  Try setting the environment
  7930.      variable `CXX' to `"gcc -O3"'.  For example:
  7931.  
  7932.           shell> CXX="gcc -O3" ./configure
  7933.  
  7934.      This works because `gcc' compiles C++ sources as well as `g++'
  7935.      does, but does not link in `libg++' or `libstdc++' by default.
  7936.  
  7937.      Another way to fix these problems, of course, is to install `g++',
  7938.      `libg++', and `libstdc++'.  We would however like to recommend you
  7939.      to not use `libg++' or `libstdc++' with MySQL as this will only
  7940.      increase the binary size of mysqld without giving you any benefits.
  7941.      Some versions of these libraries have also caused strange problems
  7942.      for MySQL users in the past.
  7943.  
  7944.      Using `gcc' as the C++ compiler is also required, if you want to
  7945.      compile MySQL with RAID functionality (see *Note CREATE TABLE::
  7946.      for more info on RAID table type) and you are using GNU `gcc'
  7947.      version 3 and above. If you get errors like the ones below during
  7948.      the linking stage when you configure MySQL to compile with the
  7949.      option `--with-raid', try to use `gcc' as your C++ compiler by
  7950.      defining the above mentioned environment variable `CXX':
  7951.  
  7952.           gcc -O3 -DDBUG_OFF -rdynamic -o isamchk isamchk.o sort.o  libnisam.a
  7953.           ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread
  7954.           -lz -lcrypt -lnsl -lm -lpthread
  7955.           ../mysys/libmysys.a(raid.o)(.text+0x79): In function `my_raid_create':
  7956.           : undefined reference to `operator new(unsigned)'
  7957.           ../mysys/libmysys.a(raid.o)(.text+0xdd): In function `my_raid_create':
  7958.           : undefined reference to `operator delete(void*)'
  7959.           ../mysys/libmysys.a(raid.o)(.text+0x129): In function `my_raid_open':
  7960.           : undefined reference to `operator new(unsigned)'
  7961.           ../mysys/libmysys.a(raid.o)(.text+0x189): In function `my_raid_open':
  7962.           : undefined reference to `operator delete(void*)'
  7963.           ../mysys/libmysys.a(raid.o)(.text+0x64b): In function `my_raid_close':
  7964.           : undefined reference to `operator delete(void*)'
  7965.           collect2: ld returned 1 exit status
  7966.  
  7967.    * If your compile fails with errors, such as any of the following,
  7968.      you must upgrade your version of `make' to GNU `make':
  7969.  
  7970.           making all in mit-pthreads
  7971.           make: Fatal error in reader: Makefile, line 18:
  7972.           Badly formed macro assignment
  7973.             or
  7974.           make: file `Makefile' line 18: Must be a separator (:
  7975.             or
  7976.           pthread.h: No such file or directory
  7977.  
  7978.      Solaris and FreeBSD are known to have troublesome `make' programs.
  7979.  
  7980.      GNU `make' Version 3.75 is known to work.
  7981.  
  7982.    * If you want to define flags to be used by your C or C++ compilers,
  7983.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  7984.      environment variables.  You can also specify the compiler names
  7985.      this way using `CC' and `CXX'.  For example:
  7986.  
  7987.           shell> CC=gcc
  7988.           shell> CFLAGS=-O3
  7989.           shell> CXX=gcc
  7990.           shell> CXXFLAGS=-O3
  7991.           shell> export CC CFLAGS CXX CXXFLAGS
  7992.  
  7993.      See *Note MySQL binaries::, for a list of flag definitions that
  7994.      have been found to be useful on various systems.
  7995.  
  7996.    * If you get an error message like this, you need to upgrade your
  7997.      `gcc' compiler:
  7998.  
  7999.           client/libmysql.c:273: parse error before `__attribute__'
  8000.  
  8001.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  8002.      or `egcs' 1.0.3a instead.
  8003.  
  8004.    * If you get errors such as those shown here when compiling `mysqld',
  8005.      `configure' didn't correctly detect the type of the last argument
  8006.      to `accept()', `getsockname()', or `getpeername()':
  8007.  
  8008.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  8009.                type of the pointer value ''length'' is ''unsigned long'', which
  8010.                is not compatible with ''int''.
  8011.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  8012.  
  8013.      To fix this, edit the `config.h' file (which is generated by
  8014.      `configure').  Look for these lines:
  8015.  
  8016.           /* Define as the base type of the last arg to accept */
  8017.           #define SOCKET_SIZE_TYPE XXX
  8018.  
  8019.      Change `XXX' to `size_t' or `int', depending on your operating
  8020.      system.  (Note that you will have to do this each time you run
  8021.      `configure' because `configure' regenerates `config.h'.)
  8022.  
  8023.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  8024.      the build process doesn't need to create `sql_yacc.cc', because
  8025.      MySQL comes with an already generated copy.  However, if you do
  8026.      need to re-create it, you might encounter this error:
  8027.  
  8028.           "sql_yacc.yy", line xxx fatal: default action causes potential...
  8029.  
  8030.      This is a sign that your version of `yacc' is deficient.  You
  8031.      probably need to install `bison' (the GNU version of `yacc') and
  8032.      use that instead.
  8033.  
  8034.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  8035.      with the `--with-debug' option, then recompile and link your
  8036.      clients with the new client library.  *Note Debugging client::.
  8037.  
  8038.    * If you get a compilation error on Linux (e.g. SuSE Linux 8.1 or
  8039.      Red Hat Linux 7.3) similar to the following one:
  8040.  
  8041.           libmysql.c:1329: warning: passing arg 5 of `gethostbyname_r' from incompatible pointer type
  8042.           libmysql.c:1329: too few arguments to function `gethostbyname_r'
  8043.           libmysql.c:1329: warning: assignment makes pointer from integer without a cast
  8044.           make[2]: *** [libmysql.lo] Error 1
  8045.  
  8046.      By default, the `configure' script attempts to determine the
  8047.      correct number of arguments by using `g++' the GNU C++ compiler.
  8048.      This test yields wrong results, if `g++' is not installed. There
  8049.      are two ways to work around this problem:
  8050.  
  8051.         * Make sure that the GNU C++ `g++' is installed. On some Linux
  8052.           distributions, the required package is called `gpp', on
  8053.           others it is named `gcc-c++'.
  8054.  
  8055.         * Use `gcc' as your C++ compiler by setting the `CXX'
  8056.           environment variable to `gcc':
  8057.                export CXX="gcc"
  8058.  
  8059.      Please note that you need to run `configure' again afterwards.
  8060.  
  8061.  
  8062. MIT-pthreads Notes
  8063. ------------------
  8064.  
  8065. This section describes some of the issues involved in using
  8066. MIT-pthreads.
  8067.  
  8068. Note that on Linux you should *not* use MIT-pthreads but use the
  8069. installed LinuxThreads implementation instead.  *Note Linux::.
  8070.  
  8071. If your system does not provide native thread support, you will need to
  8072. build MySQL using the MIT-pthreads package.  This includes older
  8073. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  8074. *Note Which OS::.
  8075.  
  8076. Note, that beginning with MySQL 4.0.2 MIT-pthreads are no longer part of
  8077. the source distribution. If you require this package, you need to
  8078. download it separately from
  8079. <http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz>
  8080.  
  8081. After downloading, extract this source archive into the top level of the
  8082. MySQL source directory. It will create a new subdirectory
  8083. `mit-pthreads'.
  8084.  
  8085.    * On most systems, you can force MIT-pthreads to be used by running
  8086.      `configure' with the `--with-mit-threads' option:
  8087.  
  8088.           shell> ./configure --with-mit-threads
  8089.  
  8090.      Building in a non-source directory is not supported when using
  8091.      MIT-pthreads because we want to minimise our changes to this code.
  8092.  
  8093.    * The checks that determine whether to use MIT-pthreads occur only
  8094.      during the part of the configuration process that deals with the
  8095.      server code.  If you have configured the distribution using
  8096.      `--without-server' to build only the client code, clients will not
  8097.      know whether MIT-pthreads is being used and will use Unix socket
  8098.      connections by default.  Because Unix sockets do not work under
  8099.      MIT-pthreads on some platforms, this means you will need to use
  8100.      `-h' or `--host' when you run client programs.
  8101.  
  8102.    * When MySQL is compiled using MIT-pthreads, system locking is
  8103.      disabled by default for performance reasons.  You can tell the
  8104.      server to use system locking with the `--external-locking' option.
  8105.      This is only needed if you want to be able to run two MySQL
  8106.      servers against the same data files (not recommended).
  8107.  
  8108.    * Sometimes the pthread `bind()' command fails to bind to a socket
  8109.      without any error message (at least on Solaris).  The result is
  8110.      that all connections to the server fail.  For example:
  8111.  
  8112.           shell> mysqladmin version
  8113.           mysqladmin: connect to server at '' failed;
  8114.           error: 'Can't connect to mysql server on localhost (146)'
  8115.  
  8116.      The solution to this is to kill the `mysqld' server and restart it.
  8117.      This has only happened to us when we have forced the server down
  8118.      and done a restart immediately.
  8119.  
  8120.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  8121.      with `SIGINT' (break).  This is only noticeable when you run
  8122.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  8123.      terminate before the interrupt is served and the process stops.
  8124.  
  8125.    * When linking, you may receive warning messages like these (at
  8126.      least on Solaris); they can be ignored:
  8127.  
  8128.           ld: warning: symbol `_iob' has differing sizes:
  8129.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  8130.           file /usr/lib/libc.so value=0x140);
  8131.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  8132.           ld: warning: symbol `__iob' has differing sizes:
  8133.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  8134.           file /usr/lib/libc.so value=0x140);
  8135.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  8136.  
  8137.    * Some other warnings also can be ignored:
  8138.  
  8139.           implicit declaration of function `int strtoll(...)'
  8140.           implicit declaration of function `int strtoul(...)'
  8141.  
  8142.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  8143.      isn't needed, but may be interesting for someone.)
  8144.  
  8145. Windows Source Distribution
  8146. ---------------------------
  8147.  
  8148. You will need the following:
  8149.  
  8150.    * VC++ 6.0 compiler (updated with 4 or 5 SP and Pre-processor
  8151.      package) The Pre-processor package is necessary for the macro
  8152.      assembler.  More details at:
  8153.      `http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/faq.aspx'.
  8154.  
  8155.    * The MySQL source distribution for Windows, which can be downloaded
  8156.      from `http://www.mysql.com/downloads/'.
  8157.  
  8158. Building MySQL:
  8159.  
  8160.   1. Create a work directory (for example, `workdir').
  8161.  
  8162.   2. Unpack the source distribution in the aforementioned directory.
  8163.  
  8164.   3. Start the VC++ 6.0 compiler.
  8165.  
  8166.   4. In the `File' menu, select `Open Workspace'.
  8167.  
  8168.   5. Open the `mysql.dsw' workspace you find on the work directory.
  8169.  
  8170.   6. From the `Build' menu, select the `Set Active Configuration' menu.
  8171.  
  8172.   7. Click over the screen selecting `mysqld - Win32 Debug' and click
  8173.      OK.
  8174.  
  8175.   8. Press `F7' to begin the build of the debug server, libraries, and
  8176.      some client applications.
  8177.  
  8178.   9. When the compilation finishes, copy the libraries and the
  8179.      executables to a separate directory.
  8180.  
  8181.  10. Compile the release versions that you want, in the same way.
  8182.  
  8183.  11. Create the directory into which to install the MySQL stuff (for
  8184.      example, `c:\mysql').
  8185.  
  8186.  12. From the `workdir' directory copy into the `c:\mysql' directory the
  8187.      following directories:
  8188.  
  8189.         * `Data'
  8190.  
  8191.         * `Docs'
  8192.  
  8193.         * `Share'
  8194.  
  8195.  13. Create the directory `c:\mysql\bin' and copy into it all the
  8196.      servers and clients that you just compiled.
  8197.  
  8198.  14. If you want, also create the `c:\mysql\lib' directory and copy the
  8199.      libraries that you just compiled.
  8200.  
  8201.  15. Do a clean using Visual Studio.
  8202.  
  8203. Set up and start the server in the same way as for the binary Windows
  8204. distribution. *Note Windows prepare environment::.
  8205.  
  8206. Post-installation Setup and Testing
  8207. ===================================
  8208.  
  8209. Once you've installed MySQL (from either a binary or source
  8210. distribution), you need to initialise the grant tables, start the
  8211. server, and make sure that the server works okay.  You may also wish to
  8212. arrange for the server to be started and stopped automatically when
  8213. your system starts up and shuts down.
  8214.  
  8215. Normally you install the grant tables and start the server like this
  8216. for installation from a source distribution:
  8217.  
  8218.      shell> ./scripts/mysql_install_db
  8219.      shell> cd mysql_installation_directory
  8220.      shell> ./bin/mysqld_safe --user=mysql &
  8221.  
  8222. For a binary distribution (not RPM or pkg packages), do this:
  8223.  
  8224.      shell> cd mysql_installation_directory
  8225.      shell> ./scripts/mysql_install_db
  8226.      shell> ./bin/mysqld_safe --user=mysql &
  8227.  
  8228. The `mysql_install_db' script creates the `mysql' database which will
  8229. hold all database privileges, the `test' database which you can use to
  8230. test MySQL, and also privilege entries for the user that runs
  8231. `mysql_install_db' and a `root' user.  The entries are created without
  8232. passwords.  The `mysqld_safe' script starts the `mysqld' server.  (If
  8233. your version of MySQL is older than 4.0, use `safe_mysqld' rather than
  8234. `mysqld_safe'.)
  8235.  
  8236. `mysql_install_db' will not overwrite any old privilege tables, so it
  8237. should be safe to run in any circumstances.  If you don't want to have
  8238. the `test' database you can remove it with `mysqladmin -u root drop
  8239. test' after starting the server.
  8240.  
  8241. Testing is most easily done from the top-level directory of the MySQL
  8242. distribution.  For a binary distribution, this is your installation
  8243. directory (typically something like `/usr/local/mysql').  For a source
  8244. distribution, this is the main directory of your MySQL source tree.
  8245.  
  8246. In the commands shown in this section and in the following subsections,
  8247. `BINDIR' is the path to the location in which programs like
  8248. `mysqladmin' and `mysqld_safe' are installed.  For a binary
  8249. distribution, this is the `bin' directory within the distribution.  For
  8250. a source distribution, `BINDIR' is probably `/usr/local/bin', unless
  8251. you specified an installation directory other than `/usr/local' when
  8252. you ran `configure'.  `EXECDIR' is the location in which the `mysqld'
  8253. server is installed.  For a binary distribution, this is the same as
  8254. `BINDIR'.  For a source distribution, `EXECDIR' is probably
  8255. `/usr/local/libexec'.
  8256.  
  8257. Testing is described in detail:
  8258.  
  8259.   1. If necessary, start the `mysqld' server and set up the initial
  8260.      MySQL grant tables containing the privileges that determine how
  8261.      users are allowed to connect to the server.  This is normally done
  8262.      with the `mysql_install_db' script:
  8263.  
  8264.           shell> scripts/mysql_install_db
  8265.  
  8266.      Typically, `mysql_install_db' needs to be run only the first time
  8267.      you install MySQL.  Therefore, if you are upgrading an existing
  8268.      installation, you can skip this step.  (However,
  8269.      `mysql_install_db' is quite safe to use and will not update any
  8270.      tables that already exist, so if you are unsure of what to do, you
  8271.      can always run `mysql_install_db'.)
  8272.  
  8273.      `mysql_install_db' creates six tables (`user', `db', `host',
  8274.      `tables_priv', `columns_priv', and `func') in the `mysql'
  8275.      database.  A description of the initial privileges is given in
  8276.      *Note Default privileges::.  Briefly, these privileges allow the
  8277.      MySQL `root' user to do anything, and allow anybody to create or
  8278.      use databases with a name of `test' or starting with `test_'.
  8279.  
  8280.      If you don't set up the grant tables, the following error will
  8281.      appear in the log file when you start the server:
  8282.  
  8283.           mysqld: Can't find file: 'host.frm'
  8284.  
  8285.      This may also happen with a binary MySQL distribution if you don't
  8286.      start MySQL by executing exactly `./bin/mysqld_safe'.  *Note
  8287.      `mysqld_safe': mysqld_safe.
  8288.  
  8289.      You might need to run `mysql_install_db' as `root'.  However, if
  8290.      you prefer, you can run the MySQL server as an unprivileged
  8291.      (non-`root') user, provided that the user can read and write files
  8292.      in the database directory.  Instructions for running MySQL as an
  8293.      unprivileged user are given in *Note Changing MySQL user: Changing
  8294.      MySQL user.
  8295.  
  8296.      If you have problems with `mysql_install_db', see *Note
  8297.      `mysql_install_db': mysql_install_db.
  8298.  
  8299.      There are some alternatives to running the `mysql_install_db'
  8300.      script as it is provided in the MySQL distribution:
  8301.  
  8302.         * You may want to edit `mysql_install_db' before running it, to
  8303.           change the initial privileges that are installed into the
  8304.           grant tables.  This is useful if you want to install MySQL on
  8305.           a lot of machines with the same privileges.  In this case you
  8306.           probably should need only to add a few extra `INSERT'
  8307.           statements to the `mysql.user' and `mysql.db' tables.
  8308.  
  8309.         * If you want to change things in the grant tables after
  8310.           installing them, you can run `mysql_install_db', then use
  8311.           `mysql -u root mysql' to connect to the grant tables as the
  8312.           MySQL `root' user and issue SQL statements to modify the
  8313.           grant tables directly.
  8314.  
  8315.         * It is possible to re-create the grant tables completely after
  8316.           they have already been created.  You might want to do this if
  8317.           you've already installed the tables but then want to
  8318.           re-create them after editing `mysql_install_db'.
  8319.  
  8320.      For more information about these alternatives, see *Note Default
  8321.      privileges::.
  8322.  
  8323.   2. Start the MySQL server like this:
  8324.  
  8325.           shell> cd mysql_installation_directory
  8326.           shell> bin/mysqld_safe &
  8327.  
  8328.      If you have problems starting the server, see *Note Starting
  8329.      server::.
  8330.  
  8331.   3. Use `mysqladmin' to verify that the server is running.  The
  8332.      following commands provide a simple test to check that the server
  8333.      is up and responding to connections:
  8334.  
  8335.           shell> BINDIR/mysqladmin version
  8336.           shell> BINDIR/mysqladmin variables
  8337.  
  8338.      The output from `mysqladmin version' varies slightly depending on
  8339.      your platform and version of MySQL, but should be similar to that
  8340.      shown here:
  8341.  
  8342.           shell> BINDIR/mysqladmin version
  8343.           mysqladmin  Ver 8.14 Distrib 3.23.32, for linux on i586
  8344.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  8345.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  8346.           and you are welcome to modify and redistribute it under the GPL license.
  8347.           
  8348.           Server version          3.23.32-debug
  8349.           Protocol version        10
  8350.           Connection              Localhost via Unix socket
  8351.           TCP port                3306
  8352.           UNIX socket             /tmp/mysql.sock
  8353.           Uptime:                 16 sec
  8354.           
  8355.           Threads: 1  Questions: 9  Slow queries: 0
  8356.           Opens: 7  Flush tables: 2  Open tables: 0
  8357.           Queries per second avg: 0.000
  8358.           Memory in use: 132K  Max memory used: 16773K
  8359.  
  8360.      To get a feeling for what else you can do with `BINDIR/mysqladmin',
  8361.      invoke it with the `--help' option.
  8362.  
  8363.   4. Verify that you can shut down the server:
  8364.  
  8365.           shell> BINDIR/mysqladmin -u root shutdown
  8366.  
  8367.   5. Verify that you can restart the server.  Do this using
  8368.      `mysqld_safe' or by invoking `mysqld' directly.  For example:
  8369.  
  8370.           shell> BINDIR/mysqld_safe --log &
  8371.  
  8372.      If `mysqld_safe' fails, try running it from the MySQL installation
  8373.      directory (if you are not already there).  If that doesn't work,
  8374.      see *Note Starting server::.
  8375.  
  8376.   6. Run some simple tests to verify that the server is working.  The
  8377.      output should be similar to what is shown here:
  8378.  
  8379.           shell> BINDIR/mysqlshow
  8380.           +-----------+
  8381.           | Databases |
  8382.           +-----------+
  8383.           | mysql     |
  8384.           +-----------+
  8385.           
  8386.           shell> BINDIR/mysqlshow mysql
  8387.           Database: mysql
  8388.           +--------------+
  8389.           |    Tables    |
  8390.           +--------------+
  8391.           | columns_priv |
  8392.           | db           |
  8393.           | func         |
  8394.           | host         |
  8395.           | tables_priv  |
  8396.           | user         |
  8397.           +--------------+
  8398.           
  8399.           shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql
  8400.           +------+--------+------+
  8401.           | host | db     | user |
  8402.           +------+--------+------+
  8403.           | %    | test   |      |
  8404.           | %    | test_% |      |
  8405.           +------+--------+------+
  8406.  
  8407.      There is also a benchmark suite in the `sql-bench' directory
  8408.      (under the MySQL installation directory) that you can use to
  8409.      compare how MySQL performs on different platforms. The benchmark
  8410.      suite is written in Perl, using the Perl DBI module to provide a
  8411.      database-independent interface to the various databases. The
  8412.      following additional Perl modules are required to run the
  8413.      benchmark suite:
  8414.  
  8415.           DBI
  8416.           DBD-mysql
  8417.           Data-Dumper
  8418.           Data-ShowTable
  8419.  
  8420.      These modules can be obtained from CPAN `http://www.cpan.org/'.
  8421.      *Note Perl installation::.
  8422.  
  8423.      The `sql-bench/Results' directory contains the results from many
  8424.      runs against different databases and platforms.  To run all tests,
  8425.      execute these commands:
  8426.  
  8427.           shell> cd sql-bench
  8428.           shell> run-all-tests
  8429.  
  8430.      If you don't have the `sql-bench' directory, you are probably
  8431.      using an RPM for a binary distribution.  (Source distribution RPMs
  8432.      include the benchmark directory.)  In this case, you must first
  8433.      install the benchmark suite before you can use it.  Beginning with
  8434.      MySQL Version 3.22, there are benchmark RPM files named
  8435.      `mysql-bench-VERSION-i386.rpm' that contain benchmark code and
  8436.      data.
  8437.  
  8438.      If you have a source distribution, you can also run the tests in
  8439.      the `tests' subdirectory. For example, to run
  8440.      `auto_increment.tst', do this:
  8441.  
  8442.           shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
  8443.  
  8444.      The expected results are shown in the `./tests/auto_increment.res'
  8445.      file.
  8446.  
  8447. Problems Running `mysql_install_db'
  8448. -----------------------------------
  8449.  
  8450. The purpose of the `mysql_install_db' script is to generate new MySQL
  8451. privilege tables.  It will not affect any other data.  It will also not
  8452. do anything if you already have MySQL privilege tables installed.
  8453.  
  8454. If you want to re-create your privilege tables, you should take down
  8455. the `mysqld' server, if it's running, and then do something like:
  8456.  
  8457.      mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  8458.      mysql_install_db
  8459.  
  8460. This section lists problems you might encounter when you run
  8461. `mysql_install_db':
  8462.  
  8463. *`mysql_install_db' doesn't install the grant tables*
  8464.      You may find that `mysql_install_db' fails to install the grant
  8465.      tables and terminates after displaying the following messages:
  8466.  
  8467.           starting mysqld daemon with databases from XXXXXX
  8468.           mysql daemon ended
  8469.  
  8470.      In this case, you should examine the log file very carefully.  The
  8471.      log should be located in the directory `XXXXXX' named by the error
  8472.      message, and should indicate why `mysqld' didn't start.  If you
  8473.      don't understand what happened, include the log when you post a
  8474.      bug report using `mysqlbug'.  *Note Bug reports::.
  8475.  
  8476. *There is already a `mysqld' daemon running*
  8477.      In this case, you probably don't have to run `mysql_install_db' at
  8478.      all.  You have to run `mysql_install_db' only once, when you
  8479.      install MySQL the first time.
  8480.  
  8481. *Installing a second `mysqld' daemon doesn't work when one daemon is running*
  8482.      This can happen when you already have an existing MySQL
  8483.      installation, but want to put a new installation in a different
  8484.      place (for example, for testing, or perhaps you simply want to run
  8485.      two installations at the same time).  Generally the problem that
  8486.      occurs when you try to run the second server is that it tries to
  8487.      use the same socket and port as the old one.  In this case you
  8488.      will get the error message: `Can't start server: Bind on TCP/IP
  8489.      port: Address already in use' or `Can't start server: Bind on unix
  8490.      socket...'. *Note Multiple servers::.
  8491.  
  8492. *You don't have write access to `/tmp'*
  8493.      If you don't have write access to create a socket file at the
  8494.      default place (in `/tmp') or permission to create temporary files
  8495.      in `/tmp,' you will get an error when running `mysql_install_db'
  8496.      or when starting or using `mysqld'.
  8497.  
  8498.      You can specify a different socket and temporary directory as
  8499.      follows:
  8500.  
  8501.           shell> TMPDIR=/some_tmp_dir/
  8502.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
  8503.           shell> export TMPDIR MYSQL_UNIX_PORT
  8504.  
  8505.      See *Note Problems with mysql.sock::.
  8506.  
  8507.      `some_tmp_dir' should be the path to some directory for which you
  8508.      have write permission. *Note Environment variables::.
  8509.  
  8510.      After this you should be able to run `mysql_install_db' and start
  8511.      the server with these commands:
  8512.  
  8513.           shell> scripts/mysql_install_db
  8514.           shell> BINDIR/mysqld_safe &
  8515.  
  8516. *`mysqld' crashes immediately*
  8517.      If you are running Red Hat Version 5.0 with a version of `glibc'
  8518.      older than 2.0.7-5, you should make sure you have installed all
  8519.      `glibc' patches.  There is a lot of information about this in the
  8520.      MySQL mail archives.  Links to the mail archives are available
  8521.      online at `http://lists.mysql.com/'.  Also, see *Note Linux::.
  8522.  
  8523.      You can also start `mysqld' manually using the
  8524.      `--skip-grant-tables' option and add the privilege information
  8525.      yourself using `mysql':
  8526.  
  8527.           shell> BINDIR/mysqld_safe --skip-grant-tables &
  8528.           shell> BINDIR/mysql -u root mysql
  8529.  
  8530.      From `mysql', manually execute the SQL commands in
  8531.      `mysql_install_db'.  Make sure you run `mysqladmin
  8532.      flush-privileges' or `mysqladmin reload' afterward to tell the
  8533.      server to reload the grant tables.
  8534.  
  8535. Problems Starting the MySQL Server
  8536. ----------------------------------
  8537.  
  8538. If you are going to use tables that support transactions (InnoDB, BDB),
  8539. you should first create a `my.cnf' file and set startup options for the
  8540. table types you plan to use. *Note Table types::.
  8541.  
  8542. Generally, you start the `mysqld' server in one of these ways:
  8543.  
  8544.    * By invoking `mysql.server'.  This script is used primarily at
  8545.      system startup and shutdown, and is described more fully in *Note
  8546.      Automatic start::.
  8547.  
  8548.    * By invoking `mysqld_safe', which tries to determine the proper
  8549.      options for `mysqld' and then runs it with those options. *Note
  8550.      `mysqld_safe': mysqld_safe.
  8551.  
  8552.    * For Windows NT/2000/XP, please see *Note NT start::.
  8553.  
  8554.    * By invoking `mysqld' directly.
  8555.  
  8556. When the `mysqld' daemon starts up, it changes the directory to the
  8557. data directory.  This is where it expects to write log files and the pid
  8558. (process ID) file, and where it expects to find databases.
  8559.  
  8560. The data directory location is hardwired in when the distribution is
  8561. compiled.  However, if `mysqld' expects to find the data directory
  8562. somewhere other than where it really is on your system, it will not work
  8563. properly.  If you have problems with incorrect paths, you can find out
  8564. what options `mysqld' allows and what the default path settings are by
  8565. invoking `mysqld' with the `--help' option.  You can override the
  8566. defaults by specifying the correct pathnames as command-line arguments
  8567. to `mysqld'.  (These options can be used with `mysqld_safe' as well.)
  8568.  
  8569. Normally you should need to tell `mysqld' only the base directory under
  8570. which MySQL is installed.  You can do this with the `--basedir' option.
  8571. You can also use `--help' to check the effect of changing path options
  8572. (note that `--help' *must* be the final option of the `mysqld'
  8573. command).  For example:
  8574.  
  8575.      shell> EXECDIR/mysqld --basedir=/usr/local --help
  8576.  
  8577. Once you determine the path settings you want, start the server without
  8578. the `--help' option.
  8579.  
  8580. Whichever method you use to start the server, if it fails to start up
  8581. correctly, check the log file to see if you can find out why.  Log files
  8582. are located in the data directory (typically `/usr/local/mysql/data'
  8583. for a binary distribution, `/usr/local/var' for a source distribution,
  8584. and `\mysql\data\mysql.err' on Windows).  Look in the data directory for
  8585. files with names of the form `host_name.err' and `host_name.log' where
  8586. `host_name' is the name of your server host.  Then check the last few
  8587. lines of these files:
  8588.  
  8589.      shell> tail host_name.err
  8590.      shell> tail host_name.log
  8591.  
  8592. Look for something like the following in the log file:
  8593.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  8594.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  8595.      000729 14:50:10  Can't init databases
  8596.  
  8597. This means that you didn't start `mysqld' with `--bdb-no-recover' and
  8598. Berkeley DB found something wrong with its log files when it tried to
  8599. recover your databases.  To be able to continue, you should move away
  8600. the old Berkeley DB log file from the database directory to some other
  8601. place, where you can later examine it.  The log files are named
  8602. `log.0000000001', where the number will increase over time.
  8603.  
  8604. If you are running `mysqld' with BDB table support and `mysqld' core
  8605. dumps at start this could be because of some problems with the BDB
  8606. recover log.  In this case you can try starting `mysqld' with
  8607. `--bdb-no-recover'.  If this helps, then you should remove all `log.*'
  8608. files from the data directory and try starting `mysqld' again.
  8609.  
  8610. If you get the following error, it means that some other program (or
  8611. another `mysqld' server) is already using the TCP/IP port or socket
  8612. `mysqld' is trying to use:
  8613.  
  8614.      Can't start server: Bind on TCP/IP port: Address already in use
  8615.        or
  8616.      Can't start server : Bind on unix socket...
  8617.  
  8618. Use `ps' to make sure that you don't have another `mysqld' server
  8619. running.  If you can't find another server running, you can try to
  8620. execute the command `telnet your-host-name tcp-ip-port-number' and press
  8621. Enter a couple of times.  If you don't get an error message like
  8622. `telnet: Unable to connect to remote host: Connection refused',
  8623. something is using the TCP/IP port `mysqld' is trying to use.  See
  8624. *Note mysql_install_db:: and *Note Multiple servers::.
  8625.  
  8626. If `mysqld' is currently running, you can find out what path settings
  8627. it is using by executing this command:
  8628.  
  8629.      shell> mysqladmin variables
  8630.  
  8631. or
  8632.  
  8633.      shell> mysqladmin -h 'your-host-name' variables
  8634.  
  8635. If you get `Errcode 13', which means `Permission denied', when starting
  8636. `mysqld' this means that you didn't have the right to read/create files
  8637. in the MySQL database or log directory. In this case you should either
  8638. start `mysqld' as the `root' user or change the permissions for the
  8639. involved files and directories so that you have the right to use them.
  8640.  
  8641. If `mysqld_safe' starts the server but you can't connect to it, you
  8642. should make sure you have an entry in `/etc/hosts' that looks like this:
  8643.  
  8644.      127.0.0.1       localhost
  8645.  
  8646. This problem occurs only on systems that don't have a working thread
  8647. library and for which MySQL must be configured to use MIT-pthreads.
  8648.  
  8649. If you can't get `mysqld' to start you can try to make a trace file to
  8650. find the problem. *Note Making trace files::.
  8651.  
  8652. If you are using InnoDB tables, refer to the InnoDB-specific startup
  8653. options.  *Note InnoDB start::.
  8654.  
  8655. If you are using BDB (Berkeley DB) tables, you should familiarise
  8656. yourself with the different BDB-specific startup options.  *Note BDB
  8657. start::.
  8658.  
  8659. Starting and Stopping MySQL Automatically
  8660. -----------------------------------------
  8661.  
  8662. The `mysql.server' and `mysqld_safe' scripts can be used to start the
  8663. server automatically at system startup time. `mysql.server' can also be
  8664. used to stop the server.
  8665.  
  8666. The `mysql.server' script can be used to start or stop the server by
  8667. invoking it with `start' or `stop' arguments:
  8668.  
  8669.      shell> mysql.server start
  8670.      shell> mysql.server stop
  8671.  
  8672. `mysql.server' can be found in the `share/mysql' directory under the
  8673. MySQL installation directory or in the `support-files' directory of the
  8674. MySQL source tree. Note that if you use the Linux RPM package
  8675. (`MySQL-server-VERSION.rpm'), the `mysql.server' script has already
  8676. been installed as `/etc/init.d/mysql' - you don't have to install it
  8677. manually. See *Note Linux-RPM:: for more info on the Linux RPM packages.
  8678.  
  8679. Before `mysql.server' starts the server, it changes the directory to
  8680. the MySQL installation directory, then invokes `mysqld_safe'.  You
  8681. might need to edit `mysql.server' if you have a binary distribution
  8682. that you've installed in a non-standard location.  Modify it to `cd'
  8683. into the proper directory before it runs `mysqld_safe'. If you want the
  8684. server to run as some specific user, add an appropriate `user' line to
  8685. the `/etc/my.cnf' file, as shown later in this section.
  8686.  
  8687. `mysql.server stop' brings down the server by sending a signal to it.
  8688. You can also take down the server manually by executing `mysqladmin
  8689. shutdown'.
  8690.  
  8691. You need to add these start and stop commands to the appropriate places
  8692. in your `/etc/rc*' files when you want to start up MySQL automatically
  8693. on your server.
  8694.  
  8695. On most current Linux distributions, it is sufficient to copy the file
  8696. `mysql.server' into the `/etc/init.d' directory (or `/etc/rc.d/init.d'
  8697. on older Red Hat systems). Afterwards, run the following command to
  8698. enable the startup of MySQL on system bootup:
  8699.  
  8700.      shell> chkconfig --add mysql.server
  8701.  
  8702. On FreeBSD startup scripts generally should go in
  8703. `/usr/local/etc/rc.d/'. The `rc(8)' manual page also states that
  8704. scripts in this directory are only executed, if their basename matches
  8705. the shell globbing pattern `*.sh'. Any other files or directories
  8706. present within the directory are silently ignored. In other words, on
  8707. FreeBSD you should install the file `mysql.server' as
  8708. `/usr/local/etc/rc.d/mysql.server.sh' to enable automatic startup.
  8709.  
  8710. As an alternative to the above, some operating systems also use
  8711. `/etc/rc.local' or `/etc/init.d/boot.local' to start additional
  8712. services on bootup. To start up MySQL using this method, you could
  8713. append something like the following to it:
  8714.  
  8715.      /bin/sh -c 'cd /usr/local/mysql ; ./bin/mysqld_safe --user=mysql &'
  8716.  
  8717. You can also add options for `mysql.server' in a global `/etc/my.cnf'
  8718. file.  A typical `/etc/my.cnf' file might look like this:
  8719.  
  8720.      [mysqld]
  8721.      datadir=/usr/local/mysql/var
  8722.      socket=/var/tmp/mysql.sock
  8723.      port=3306
  8724.      user=mysql
  8725.      
  8726.      [mysql.server]
  8727.      basedir=/usr/local/mysql
  8728.  
  8729. The `mysql.server' script understands the following options: `datadir',
  8730. `basedir', and `pid-file'.
  8731.  
  8732. The following table shows which option groups each startup script reads
  8733. from option files:
  8734.  
  8735. *Script*    *Option groups*
  8736. `mysqld'    `[mysqld]' and `[server]'
  8737. `mysql.server'`[mysql.server]', `[mysqld]', and `[server]'
  8738. `mysqld_safe'`[mysqld]', `[server]', and `[mysqld_safe]'
  8739.  
  8740. For backward compatibility, `mysql.server' also reads the
  8741. `[mysql_server]' group and `mysqld_safe' also reads the `[safe_mysqld]'
  8742. group. However, you should update your option files to use the
  8743. `[mysql.server]' and `[mysqld_safe]' groups instead.
  8744.  
  8745. *Note Option files::.
  8746.  
  8747. Upgrading/Downgrading MySQL
  8748. ===========================
  8749.  
  8750. Before you do an upgrade, you should back up your old databases.
  8751.  
  8752. You can always move the MySQL form files and datafiles between different
  8753. versions on the same architecture as long as you have the same base
  8754. version of MySQL. The current base version is 4. If you change the
  8755. character set when running MySQL, you must run `myisamchk -r -q
  8756. --set-character-set=charset' on all tables.  Otherwise, your indexes
  8757. may not be ordered correctly, because changing the character set may
  8758. also change the sort order.
  8759.  
  8760. If you are afraid of new versions, you can always rename your old
  8761. `mysqld' to something like `mysqld-old-version-number'.  If your new
  8762. `mysqld' then does something unexpected, you can simply shut it down
  8763. and restart with your old `mysqld'.
  8764.  
  8765. If, after an upgrade, you experience problems with recompiled client
  8766. programs, such as `Commands out of sync' or unexpected core dumps, you
  8767. probably have used an old header or library file when compiling your
  8768. programs.  In this case you should check the date for your `mysql.h'
  8769. file and `libmysqlclient.a' library to verify that they are from the new
  8770. MySQL distribution.  If not, please recompile your programs.
  8771.  
  8772. If problems occur, such as that the new `mysqld' server doesn't want to
  8773. start or that you can't connect without a password, check that you don't
  8774. have some old `my.cnf' file from your old installation.  You can check
  8775. this with: `program-name --print-defaults'.  If this outputs anything
  8776. other than the program name, you have an active `my.cnf' file that will
  8777. affect things.
  8778.  
  8779. It is a good idea to rebuild and reinstall the Perl `DBD-mysql' module
  8780. whenever you install a new release of MySQL. The same applies to other
  8781. MySQL interfaces as well, such as the Python `MySQLdb' module.
  8782.  
  8783. Upgrading From Version 4.0 to 4.1
  8784. ---------------------------------
  8785.  
  8786. Preparing to Upgrade From Version 4.0 to 4.1
  8787. ............................................
  8788.  
  8789. Some visible things have changed between MySQL 4.0 and MySQL 4.1 to fix
  8790. some critical bugs and make MySQL more compatible with the ANSI SQL
  8791. standard.
  8792.  
  8793. Instead of adding options (and a lot of code) to try to make 4.1 behave
  8794. like 4.0 we have taken another approach:
  8795.  
  8796. We have added to the later MySQL 4.0 releases (from 4.0.12 on) the
  8797. `--new' startup option for `mysqld', which gives you the 4.1 behaviour
  8798. for the most critical changes.  You can also set this behaviour for a
  8799. given client connection with the `SET @@new=1 command'.
  8800.  
  8801. If you believe that some of the following changes will affect you when
  8802. you upgrade to 4.1, we recommend that before upgrading to 4.1, you
  8803. download the latest MySQL 4.0 version and make sure that your
  8804. applications work in the `--new' mode.  This way you will have a smooth
  8805. painless upgrade to 4.1 later.
  8806.  
  8807. In MySQL 4.1 we have done some things that may affect applications.
  8808. The following is a list of things that you have to watch out for when
  8809. upgrading to version 4.1:
  8810.  
  8811.    * `TIMESTAMP' is now returned as a string with the format
  8812.      `'YYYY-MM-DD HH:MM:SS''. If you want to have this as a number (like
  8813.      Version 4.0 does) should add +0 to `TIMESTAMP' columns when you
  8814.      retrieve them.  Different `TIMESTAMP' display widths are no longer
  8815.      supported.
  8816.  
  8817.      This change was necessary for SQL standards compliance. In a future
  8818.      version, a further change will be made (backward compatible with
  8819.      this change), allowing the timestamp length to indicate the
  8820.      desired number of digits for fractions of a second.
  8821.  
  8822.    * For functions that produce a `DATE', `DATETIME', or `TIME' value,
  8823.      the result returned to the client now is fixed up to have a
  8824.      temporal type. For example, in MySQL 4.1, you get this result:
  8825.  
  8826.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  8827.               -> '2001-01-01 00:00:00'
  8828.  
  8829.      In MySQL 4.0, the result is different:
  8830.  
  8831.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  8832.               -> '2001-01-01'
  8833.  
  8834.    * Binary values such as `0xFFDF' now are assumed to be strings
  8835.      instead of numbers.  This fixes some problems with character sets
  8836.      where it's convenient to input the string as a binary values.
  8837.      With this change, you should use `CAST()' if you want to compare
  8838.      binary values numerically as integers:
  8839.  
  8840.           SELECT CAST(0xFEFF AS UNSIGNED INTEGER) < CAST(0xFF AS UNSIGNED INTEGER)
  8841.  
  8842.      Using binary items in a numeric context or comparing them using the
  8843.      `=' operator should work as before.  (The `--new' option can be
  8844.      used to make the server behave as 4.1 in this repect from 4.0.13
  8845.      on.)
  8846.  
  8847.    * `AUTO_INCREMENT' columns cannot take `DEFAULT' values. (In 4.0
  8848.      these were just silently ignored; in 4.1, an error occurs).
  8849.  
  8850.    * `SERIALIZE' is no longer a valid option value for the `sql_mode'
  8851.      variable.  You should use `SET TRANSACTION ISOLATION LEVEL
  8852.      SERIALIZABLE' instead. `SERIALIZE' is no longer valid for the
  8853.      `--sql-mode' option for `mysqld', either. Use
  8854.      `--transaction-isolation=SERIALIZABLE' instead.
  8855.  
  8856.    * All column and tables now have a character set, which shows up in
  8857.      `SHOW CREATE TABLE' and `mysqldump'.  (MySQL versions 4.0.6 and
  8858.      above can read the new dump files; older versions cannot.)
  8859.  
  8860.    * If you are running multiple servers on the same Windows machine,
  8861.      you should use a different `--shared_memory_base_name' option on
  8862.      all machines.
  8863.  
  8864.  
  8865. *Note:* The table definition format used in `.frm' files has changed
  8866. slightly in 4.1.  MySQL 4.0 versions from 4.0.11 on can read the new
  8867. `.frm' format directly, but older versions cannot.  If you need to move
  8868. tables from 4.1 to an earlier MySQL version, you should use `mysqldump'.
  8869. *Note `mysqldump': mysqldump.
  8870.  
  8871. If you are running MySQL Server on Windows, please also see *Note
  8872. Windows upgrading::.
  8873.  
  8874. What to do when upgrading from 4.0 to 4.1
  8875. .........................................
  8876.  
  8877. In general, upgrading to 4.1 from an earlier MySQL version involves the
  8878. following steps:
  8879.  
  8880.    * Check the changes section if there is some change that may affect
  8881.      your application. *Note Prepare-upgrade-4.0-4.1::.
  8882.  
  8883.    * Read the 4.1 news items to see what significant new features you
  8884.      can use in 4.1.  *Note News-4.1.x::.
  8885.  
  8886.    * Run the script `mysql_fix_privilege_tables' to generate the new
  8887.      longer `Password' column that is needed for secure handling of
  8888.      passwords.
  8889.  
  8890.  
  8891. The password hashing mechanism has changed in 4.1 to provide better
  8892. security, but this may cause compatibility problems if you still have
  8893. clients that use the client library from 4.0 or earlier.  (It is very
  8894. likely that you will have 4.0 clients in situations where clients
  8895. connect from remote hosts that have not yet upgraded to 4.1).  The
  8896. following list indicates some possible upgrade strategies.  They
  8897. represent various tradeoffs between the goal of compatibility with old
  8898. clients and the goal of security.
  8899.  
  8900.    * Don't upgrade to 4.1. No behaviour will change, but of course you
  8901.      cannot use any of the new features provided by the 4.1
  8902.      client/server protocol, either.  (MySQL 4.1 has an extended
  8903.      client/server protocol that offers such features as prepared
  8904.      statements and multiple result sets.)  *Note C API Prepared
  8905.      statements::.
  8906.  
  8907.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  8908.      widen the `Password' column in the `user' table so that it can
  8909.      hold long password hashes.  But run the server with the
  8910.      `--old-passwords' option to provide backward compatibility that
  8911.      allows pre-4.1 clients to continue to connect to their short-hash
  8912.      accounts.  Eventually, when all your clients are upgraded to 4.1,
  8913.      you can stop using the `--old-passwords' server option. You can
  8914.      also change the passwords for your MySQL accounts to use the new
  8915.      more secure format.
  8916.  
  8917.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  8918.      widen the `Password' column in the `user' table.  If you know that
  8919.      all clients also have been upgraded to 4.1, don't run the server
  8920.      with the `--old-passwords' option.  Instead, change the passwords
  8921.      on all existing accounts so that they have the new format.  A
  8922.      pure-4.1 installation is the most secure.
  8923.  
  8924.  
  8925. Further background on password hashing with respect to client
  8926. authentication and password-changing operations may be found in *Note
  8927. Password hashing::.
  8928.  
  8929. Upgrading From Version 3.23 to 4.0
  8930. ----------------------------------
  8931.  
  8932. In general, you should do the following when upgrading to 4.0 from an
  8933. earlier MySQL version:
  8934.  
  8935.    * Run the script `mysql_fix_privilege_tables' to add new privileges
  8936.      and features to the MySQL privilege tables.
  8937.  
  8938.    * Edit any MySQL startup scripts or configure files to not use any
  8939.      of the deprecated options described later in this section.
  8940.  
  8941.    * Convert your old `ISAM' files to `MyISAM' files with the
  8942.      `mysql_convert_table_format database' script. (This is a Perl
  8943.      script; it requires that DBI be installed.) To convert the tables
  8944.      in a given database, use this command:
  8945.  
  8946.           shell> mysql_convert_table_format database db_name
  8947.  
  8948.      Note that this should only be used if all tables in the given
  8949.      database are `ISAM' or `MyISAM' tables. To avoid converting tables
  8950.      of other types to `MyISAM', you can explicitly list the names of
  8951.      your `ISAM' tables after the database name on the command line.
  8952.      You can also issue a `ALTER TABLE table_name TYPE=MyISAM'
  8953.      statement for each `ISAM' table to convert it to `MyISAM'.
  8954.  
  8955.    * Ensure that you don't have any MySQL clients that use shared
  8956.      libraries (like the Perl `DBD-mysql' mode). If you do, you should
  8957.      recompile them, because the data structures used in
  8958.      `libmysqlclient.so' have changed.  The same applies to other MySQL
  8959.      interfaces as well, such as the Python `MySQLdb' module.
  8960.  
  8961.  
  8962. MySQL 4.0 will work even if you don't do the above, but you will not be
  8963. able to use the new security privileges that MySQL 4.0 and you may run
  8964. into problems when upgrading later to MySQL 4.1 or newer.  The `ISAM'
  8965. file format still works in MySQL 4.0 but it's deprecated and will be
  8966. disabled in MySQL 5.0.
  8967.  
  8968. Old clients should work with a Version 4.0 server without any problems.
  8969.  
  8970. Even if you do the above, you can still downgrade to MySQL 3.23.52 or
  8971. newer if you run into problems with the MySQL 4.0 series.  In this
  8972. case, you must use `mysqldump' to dump any tables that use full-text
  8973. indexes and reload the dump file into the 3.23 server.  This is
  8974. necessary because 4.0 uses a new format for full-text indexing.
  8975.  
  8976. The following is a more complete list that tells what you must watch out
  8977. for when upgrading to version 4.0:
  8978.  
  8979.    * MySQL 4.0 has a lot of new privileges in the `mysql.user' table.
  8980.      *Note `GRANT': GRANT.
  8981.  
  8982.      To get these new privileges to work, you must run the
  8983.      `mysql_fix_privilege_tables' script.  Until you do, all users have
  8984.      the `SHOW DATABASES', `CREATE TEMPORARY TABLES', and `LOCK TABLES'
  8985.      privileges. `SUPER' and `EXECUTE' privileges take their value from
  8986.      `PROCESS'.  `REPLICATION SLAVE' and `REPLICATION CLIENT' take their
  8987.      values from `FILE'.
  8988.  
  8989.      If you have any scripts that create new users, you may want to
  8990.      change them to use the new privileges.  If you are not using
  8991.      `GRANT' commands in the scripts, this is a good time to change
  8992.      your scripts to use `GRANT' instead of modifying the grant tables
  8993.      directly..
  8994.  
  8995.      From version 4.0.2 on, the option `--safe-show-database' is
  8996.      deprecated (and no longer does anything). *Note Privileges
  8997.      options::.
  8998.  
  8999.      If you get `Access denied' errors for new users in version 4.0.2
  9000.      and up, you should check if you need some of the new grants that
  9001.      you didn't need before.  In particular, you will need `REPLICATION
  9002.      SLAVE' (instead of `FILE') for new slaves.
  9003.  
  9004.    * `safe_mysqld' is renamed to `mysqld_safe'.  For backward
  9005.      compatibility, binary distributions will for some time include
  9006.      `safe_mysqld' as a symlink to `mysqld_safe'.
  9007.  
  9008.    * The startup parameters `myisam_max_extra_sort_file_size' and
  9009.      `myisam_max_extra_sort_file_size' are now given in bytes (they
  9010.      were given in megabytes before 4.0.3).
  9011.  
  9012.    * External system locking of `MyISAM'/`ISAM' files is now turned off
  9013.      by default.  Your can turn this on by doing `--external-locking'.
  9014.      (However, this is never needed for most users.)
  9015.  
  9016.    * The following startup variables/options have been renamed:
  9017.  
  9018.      *Old Name*                         *New Name*
  9019.      `myisam_bulk_insert_tree_size'     `bulk_insert_buffer_size'
  9020.      `query_cache_startup_type'         `query_cache_type'
  9021.      `record_buffer'                    `read_buffer_size'
  9022.      `record_rnd_buffer'                `read_rnd_buffer_size'
  9023.      `sort_buffer'                      `sort_buffer_size'
  9024.      `warnings'                         `log-warnings'
  9025.      `--err-log'                        `--log-error' (for `mysqld_safe')
  9026.  
  9027.      The startup options `record_buffer', `sort_buffer' and `warnings'
  9028.      will still work in MySQL 4.0 but are deprecated.
  9029.  
  9030.    * The following SQL variables have changed name.
  9031.  
  9032.      *Old Name*                         *New Name*
  9033.      `SQL_BIG_TABLES'                   `BIG_TABLES'
  9034.      `SQL_LOW_PRIORITY_UPDATES'         `LOW_PRIORITY_UPDATES'
  9035.      `SQL_MAX_JOIN_SIZE'                `MAX_JOIN_SIZE'
  9036.      `SQL_QUERY_CACHE_TYPE'             `QUERY_CACHE_TYPE'
  9037.      The old names still work in MySQL 4.0 but are deprecated.
  9038.  
  9039.    * You have to use `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=#' instead of
  9040.      `SET SQL_SLAVE_SKIP_COUNTER=#'.
  9041.  
  9042.    * The `mysqld' startup options `--skip-locking' and
  9043.      `--enable-locking' were renamed to `--skip-external-locking' and
  9044.      `--external-locking'.
  9045.  
  9046.    * `SHOW MASTER STATUS' now returns an empty set if binary logging is
  9047.      not enabled.
  9048.  
  9049.    * `SHOW SLAVE STATUS' now returns an empty set if slave is not
  9050.      initialised.
  9051.  
  9052.    * `mysqld' now has the option `--temp-pool' enabled by default as
  9053.      this gives better performance with some operating systems (most
  9054.      notably Linux).
  9055.  
  9056.    * `DOUBLE' and `FLOAT' columns now honour the `UNSIGNED' flag on
  9057.      storage (before, `UNSIGNED' was ignored for these columns).
  9058.  
  9059.    * `ORDER BY col_name DESC' sorts `NULL' values last, as of MySQL
  9060.      4.0.11. In 3.23 and in earlier 4.0 versions, this was not always
  9061.      consistent.
  9062.  
  9063.    * `SHOW INDEX' has two more columns (`Null' and `Index_type') than
  9064.      it had in 3.23.
  9065.  
  9066.    * `CHECK', `SIGNED', `LOCALTIME' and `LOCALTIMESTAMP' are now
  9067.      reserved words.
  9068.  
  9069.    * The result of all bitwise operators (`|', `&', `<<', `>>', and
  9070.      `~')) is now unsigned.  This may cause problems if you are using
  9071.      them in a context where you want a signed result.  *Note Cast
  9072.      Functions::.
  9073.  
  9074.    * *Note*: when you use subtraction between integer values where one
  9075.      is of type `UNSIGNED', the result will be unsigned.  In other
  9076.      words, before upgrading to MySQL 4.0, you should check your
  9077.      application for cases where you are subtracting a value from an
  9078.      unsigned entity and want a negative answer or subtracting an
  9079.      unsigned value from an integer column. You can disable this
  9080.      behaviour by using the `--sql-mode=NO_UNSIGNED_SUBTRACTION' option
  9081.      when starting `mysqld'.  *Note Cast Functions::.
  9082.  
  9083.    * To use `MATCH ... AGAINST (... IN BOOLEAN MODE)' with your tables,
  9084.      you need to rebuild them with `REPAIR TABLE table_name USE_FRM'.
  9085.  
  9086.    * `LOCATE()' and `INSTR()' are case-sensitive if one of the
  9087.      arguments is a binary string. Otherwise they are case-insensitive.
  9088.  
  9089.    * `STRCMP()' now uses the current character set when doing
  9090.      comparisons, which means that the default comparison behaviour now
  9091.      is case-insensitive.
  9092.  
  9093.    * `HEX(string)' now returns the characters in `string' converted to
  9094.      hexadecimal.  If you want to convert a number to hexadecimal, you
  9095.      should ensure that you call `HEX()' with a numeric argument.
  9096.  
  9097.    * In 3.23, `INSERT INTO ... SELECT' always had `IGNORE' enabled.  In
  9098.      4.0.1, MySQL will stop (and possibly roll back) by default in case
  9099.      of an error unless you specify `IGNORE'.
  9100.  
  9101.    * The old C API functions `mysql_drop_db()', `mysql_create_db()', and
  9102.      `mysql_connect()' are no longer supported unless you compile MySQL
  9103.      with `CFLAGS=-DUSE_OLD_FUNCTIONS'.  However, it is preferable to
  9104.      change client programs to use the new 4.0 API instead.
  9105.  
  9106.    * In the `MYSQL_FIELD' structure, `length' and `max_length' have
  9107.      changed from `unsigned int' to `unsigned long'. This should not
  9108.      cause any problems, except that they may generate warning messages
  9109.      when used as arguments in the `printf()' class of functions.
  9110.  
  9111.    * You should use `TRUNCATE TABLE' when you want to delete all rows
  9112.      from a table and you don't need to obtain a count of the number of
  9113.      rows that were deleted.  (`DELETE FROM table_name' returns a row
  9114.      count in 4.0, and `TRUNCATE TABLE' is faster.)
  9115.  
  9116.    * You will get an error if you have an active `LOCK TABLES' or
  9117.      transaction when trying to execute `TRUNCATE TABLE' or `DROP
  9118.      DATABASE'.
  9119.  
  9120.    * You should use integers to store values in `BIGINT' columns
  9121.      (instead of using strings, as you did in MySQL 3.23).  Using
  9122.      strings will still work, but using integers is more efficient.
  9123.  
  9124.    * The format of `SHOW OPEN TABLES' has changed.
  9125.  
  9126.    * Multi-threaded clients should use `mysql_thread_init()' and
  9127.      `mysql_thread_end()'. *Note Threaded clients::.
  9128.  
  9129.    * If you want to recompile the Perl `DBD::mysql' module, you must get
  9130.      `DBD-mysql' version 1.2218 or newer because older DBD modules used
  9131.      the deprecated `mysql_drop_db()' call.  Version 2.1022 or newer is
  9132.      recommended.
  9133.  
  9134.    * `RAND(seed)' returns a different random number series in 4.0 than
  9135.      in 3.23; this was done to further differentiate `RAND(seed)' and
  9136.      `RAND(seed+1)'.
  9137.  
  9138.    * The default type returned by `IFNULL(A,B)' is now set to be the
  9139.      more 'general' of the types of `A' and `B'. (The
  9140.      general-to-specific order is string, `REAL' or `INTEGER').
  9141.  
  9142.  
  9143. If you are running MySQL Server on Windows, please also see *Note
  9144. Windows upgrading::. If you are using replication, please also see
  9145. *Note Replication Implementation::.
  9146.  
  9147. Upgrading From Version 3.22 to 3.23
  9148. -----------------------------------
  9149.  
  9150. MySQL Version 3.23 supports tables of the new `MyISAM' type and the old
  9151. `ISAM' type.  You don't have to convert your old tables to use these
  9152. with Version 3.23.  By default, all new tables will be created with
  9153. type `MyISAM' (unless you start `mysqld' with the
  9154. `--default-table-type=isam' option). You can convert an `ISAM' table to
  9155. `MyISAM' format with `ALTER TABLE table_name TYPE=MyISAM' or the Perl
  9156. script `mysql_convert_table_format'.
  9157.  
  9158. Version 3.22 and 3.21 clients will work without any problems with a
  9159. Version 3.23 server.
  9160.  
  9161. The following list tells what you have to watch out for when upgrading
  9162. to Version 3.23:
  9163.  
  9164.    * All tables that use the `tis620' character set must be fixed with
  9165.      `myisamchk -r' or `REPAIR TABLE'.
  9166.  
  9167.    * If you do a `DROP DATABASE' on a symbolically-linked database,
  9168.      both the link and the original database are deleted.  (This didn't
  9169.      happen in 3.22 because `configure' didn't detect the availability
  9170.      of the `readlink()' system call.)
  9171.  
  9172.    * `OPTIMIZE TABLE' now works only for `MyISAM' tables.  For other
  9173.      table types, you can use `ALTER TABLE' to optimise the table.
  9174.      During `OPTIMIZE TABLE', the table is now locked to prevent it
  9175.      from being used by other threads.
  9176.  
  9177.    * The MySQL client `mysql' is now by default started with the option
  9178.      `--no-named-commands (-g)'. This option can be disabled with
  9179.      `--enable-named-commands (-G)'. This may cause incompatibility
  9180.      problems in some cases--for example, in SQL scripts that use named
  9181.      commands without a semicolon.  Long format commands still work
  9182.      from the first line.
  9183.  
  9184.    * Date functions that work on parts of dates (like `MONTH()') will
  9185.      now return 0 for `0000-00-00' dates. (In MySQL 3.22, these
  9186.      functions returned `NULL'.)
  9187.  
  9188.    * If you are using the `german' character sort order for `ISAM'
  9189.      tables, you must repair them with `isamchk -r', because we have
  9190.      made some changes in the sort order.
  9191.  
  9192.    * The default return type of `IF()' now depends on both arguments
  9193.      and not only the first argument.
  9194.  
  9195.    * `AUTO_INCREMENT' columns should not be used to store negative
  9196.      numbers. The reason for this is that negative numbers caused
  9197.      problems when wrapping from -1 to 0.  You should not store 0 in
  9198.      `AUTO_INCREMENT' columns, either; `CHECK TABLE' will complain
  9199.      about 0 values because they may change if you dump and restore the
  9200.      table.  `AUTO_INCREMENT' for `MyISAM' tables is now handled at a
  9201.      lower level and is much faster than before. In addition, for
  9202.      `MyISAM' tables, old numbers are no longer reused, even if you
  9203.      delete rows from the table.
  9204.  
  9205.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  9206.      `THEN', and `WHEN' are now reserved words.
  9207.  
  9208.    * `FLOAT(X)' is now a true floating-point type and not a value with a
  9209.      fixed number of decimals.
  9210.  
  9211.    * When declaring columns using a `DECIMAL(length,dec)' type, the
  9212.      `length' argument no longer includes a place for the sign or the
  9213.      decimal point.
  9214.  
  9215.    * A `TIME' string must now be of one of the following formats:
  9216.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  9217.      `[[[[[H]H]H]H]MM]SS[.fraction]'.
  9218.  
  9219.    * `LIKE' now compares strings using the same character comparison
  9220.      rules as for the `=' operator.  If you require the old behaviour,
  9221.      you can compile MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  9222.  
  9223.    * `REGEXP' is now case-insensitive if neither of the strings are
  9224.      binary strings.
  9225.  
  9226.    * When you check or repair `MyISAM' (`.MYI') tables, you should use
  9227.      the `CHECK TABLE' statement or the `myisamchk' command. For `ISAM'
  9228.      (`.ISM') tables, use the `isamchk' command.
  9229.  
  9230.    * If you want your `mysqldump' files to be compatible between MySQL
  9231.      Version 3.22 and Version 3.23, you should not use the `--opt' or
  9232.      `--all' option to `mysqldump'.
  9233.  
  9234.    * Check all your calls to `DATE_FORMAT()' to make sure there is a
  9235.      `%' before each format character.  (MySQL Version 3.22 and later
  9236.      already allowed this syntax.)
  9237.  
  9238.    * `mysql_fetch_fields_direct()' is now a function (it used to be a
  9239.      macro) and it returns a pointer to a `MYSQL_FIELD' instead of a
  9240.      `MYSQL_FIELD'.
  9241.  
  9242.    * `mysql_num_fields()' can no longer be used on a `MYSQL*' object
  9243.      (it's now a function that takes a `MYSQL_RES*' value as an
  9244.      argument). With a `MYSQL*' object, you should now use
  9245.      `mysql_field_count()' instead.
  9246.  
  9247.    * In MySQL Version 3.22, the output of `SELECT DISTINCT ...' was
  9248.      almost always sorted.  In Version 3.23, you must use `GROUP BY' or
  9249.      `ORDER BY' to obtain sorted output.
  9250.  
  9251.    * `SUM()' now returns `NULL' instead of 0 if there are no matching
  9252.      rows. This is required by SQL-99.
  9253.  
  9254.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  9255.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  9256.      expression as `NOT NULL' = `NULL'.
  9257.  
  9258.    * `LPAD()' and `RPAD()' now shorten the result string if it's longer
  9259.      than the length argument.
  9260.  
  9261. Upgrading from Version 3.21 to 3.22
  9262. -----------------------------------
  9263.  
  9264. Nothing that affects compatibility has changed between versions 3.21
  9265. and 3.22.  The only pitfall is that new tables that are created with
  9266. `DATE' type columns will use the new way to store the date. You can't
  9267. access these new columns from an old version of `mysqld'.
  9268.  
  9269. After installing MySQL Version 3.22, you should start the new server
  9270. and then run the `mysql_fix_privilege_tables' script. This will add the
  9271. new privileges that you need to use the `GRANT' command.  If you forget
  9272. this, you will get `Access denied' when you try to use `ALTER TABLE',
  9273. `CREATE INDEX', or `DROP INDEX'. If your MySQL `root' user requires a
  9274. password, you should give this as an argument to
  9275. `mysql_fix_privilege_tables'.
  9276.  
  9277. The C API interface to `mysql_real_connect()' has changed.  If you have
  9278. an old client program that calls this function, you must place a `0' for
  9279. the new `db' argument (or recode the client to send the `db' element
  9280. for faster connections).  You must also call `mysql_init()' before
  9281. calling `mysql_real_connect()'.  This change was done to allow the new
  9282. `mysql_options()' function to save options in the `MYSQL' handler
  9283. structure.
  9284.  
  9285. The `mysqld' variable `key_buffer' has been renamed to
  9286. `key_buffer_size', but you can still use the old name in your startup
  9287. files.
  9288.  
  9289. Upgrading from Version 3.20 to 3.21
  9290. -----------------------------------
  9291.  
  9292. If you are running a version older than Version 3.20.28 and want to
  9293. switch to Version 3.21, you need to do the following:
  9294.  
  9295. You can start the `mysqld' Version 3.21 server with the
  9296. `--old-protocol' option to use it with clients from a Version 3.20
  9297. distribution.  In this case, the new client function `mysql_errno()'
  9298. will not return any server error, only `CR_UNKNOWN_ERROR' (but it works
  9299. for client errors), and the server uses the old pre-3.21 `password()'
  9300. checking rather than the new method.
  9301.  
  9302. If you are *not* using the `--old-protocol' option to `mysqld', you
  9303. will need to make the following changes:
  9304.  
  9305.    * All client code must be recompiled. If you are using ODBC, you
  9306.      must get the new `MyODBC' 2.x driver.
  9307.  
  9308.    * The script `scripts/add_long_password' must be run to convert the
  9309.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  9310.  
  9311.    * All passwords must be reassigned in the `mysql.user' table (to get
  9312.      62-bit rather than 31-bit passwords).
  9313.  
  9314.    * The table format hasn't changed, so you don't have to convert any
  9315.      tables.
  9316.  
  9317.  
  9318. MySQL Version 3.20.28 and above can handle the new `user' table format
  9319. without affecting clients. If you have a MySQL version earlier than
  9320. Version 3.20.28, passwords will no longer work with it if you convert
  9321. the `user' table. So to be safe, you should first upgrade to at least
  9322. Version 3.20.28 and then upgrade to Version 3.21.
  9323.  
  9324. The new client code works with a 3.20.x `mysqld' server, so if you
  9325. experience problems with 3.21.x, you can use the old 3.20.x server
  9326. without having to recompile the clients again.
  9327.  
  9328. If you are not using the `--old-protocol' option to `mysqld', old
  9329. clients will be unable to connect and will issue the following error
  9330. message:
  9331.  
  9332.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  9333.  
  9334. The new Perl `DBI'/`DBD' interface also supports the old `mysqlperl'
  9335. interface.  The only change you have to make if you use `mysqlperl' is
  9336. to change the arguments to the `connect()' function.  The new arguments
  9337. are: `host', `database', `user', and `password' (note that the `user'
  9338. and `password' arguments have changed places).  *Note Perl `DBI' Class:
  9339. Perl DBI Class.
  9340.  
  9341. The following changes may affect queries in old applications:
  9342.  
  9343.    * `HAVING' must now be specified before any `ORDER BY' clause.
  9344.  
  9345.    * The parameters to `LOCATE()' have been swapped.
  9346.  
  9347.    * There are some new reserved words. The most notable are `DATE',
  9348.      `TIME', and `TIMESTAMP'.
  9349.  
  9350.  
  9351. Upgrading to Another Architecture
  9352. ---------------------------------
  9353.  
  9354. If you are using MySQL Version 3.23, you can copy the `.frm', `.MYI',
  9355. and `.MYD' files for `MyISAM' tables between different architectures
  9356. that support the same floating-point format.  (MySQL takes care of any
  9357. byte-swapping issues.)  *Note `MyISAM' Tables: MyISAM.
  9358.  
  9359. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  9360. respectively) are architecture-dependent and in some cases
  9361. OS-dependent.  If you want to move your applications to another machine
  9362. that has a different architecture or OS than your current machine, you
  9363. should not try to move a database by simply copying the files to the
  9364. other machine. Use `mysqldump' instead.
  9365.  
  9366. By default, `mysqldump' will create a file containing SQL statements.
  9367. You can then transfer the file to the other machine and feed it as input
  9368. to the `mysql' client.
  9369.  
  9370. Try `mysqldump --help' to see what options are available.  If you are
  9371. moving the data to a newer version of MySQL, you should use `mysqldump
  9372. --opt' with the newer version to get a fast, compact dump.
  9373.  
  9374. The easiest (although not the fastest) way to move a database between
  9375. two machines is to run the following commands on the machine on which
  9376. the database is located:
  9377.  
  9378.      shell> mysqladmin -h 'other hostname' create db_name
  9379.      shell> mysqldump --opt db_name \
  9380.              | mysql -h 'other hostname' db_name
  9381.  
  9382. If you want to copy a database from a remote machine over a slow
  9383. network, you can use:
  9384.  
  9385.      shell> mysqladmin create db_name
  9386.      shell> mysqldump -h 'other hostname' --opt --compress db_name \
  9387.              | mysql db_name
  9388.  
  9389. You can also store the result in a file, then transfer the file to the
  9390. target machine and load the file into the database there.  For example,
  9391. you can dump a database to a file on the source machine like this:
  9392.  
  9393.      shell> mysqldump --quick db_name | gzip > db_name.contents.gz
  9394.  
  9395. (The file created in this example is compressed.) Transfer the file
  9396. containing the database contents to the target machine and run these
  9397. commands there:
  9398.  
  9399.      shell> mysqladmin create db_name
  9400.      shell> gunzip < db_name.contents.gz | mysql db_name
  9401.  
  9402. You can also use `mysqldump' and `mysqlimport' to transfer the database.
  9403. For big tables, this is much faster than simply using `mysqldump'.  In
  9404. the following commands, `DUMPDIR' represents the full pathname of the
  9405. directory you use to store the output from `mysqldump'.
  9406.  
  9407. First, create the directory for the output files and dump the database:
  9408.  
  9409.      shell> mkdir DUMPDIR
  9410.      shell> mysqldump --tab=DUMPDIR db_name
  9411.  
  9412. Then transfer the files in the `DUMPDIR' directory to some corresponding
  9413. directory on the target machine and load the files into MySQL there:
  9414.  
  9415.      shell> mysqladmin create db_name           # create database
  9416.      shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
  9417.      shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables
  9418.  
  9419. Also, don't forget to copy the `mysql' database because that's where the
  9420. grant tables (`user', `db', `host') are stored.  You may have to run
  9421. commands as the MySQL `root' user on the new machine until you have the
  9422. `mysql' database in place.
  9423.  
  9424. After you import the `mysql' database on the new machine, execute
  9425. `mysqladmin flush-privileges' so that the server reloads the grant table
  9426. information.
  9427.  
  9428. Upgrading MySQL under Windows
  9429. -----------------------------
  9430.  
  9431. When upgrading MySQL under Windows, please follow these steps:
  9432.  
  9433.   1. Download the latest Windows distribution of MySQL.
  9434.  
  9435.   2. Choose a time of day with low usage, where a maintenance break is
  9436.      acceptable.
  9437.  
  9438.   3. Alert the users that still are active about the maintenance break.
  9439.  
  9440.   4. Stop the running MySQL Server (for example, with `NET STOP mysql'
  9441.      if you are running MySQL as a service, or with `mysqladmin
  9442.      shutdown' otherwise).
  9443.  
  9444.   5. Run the installation script of the Windows distribution, by
  9445.      clicking the "Install" button in WinZip and following the
  9446.      installation steps of the script.
  9447.  
  9448.   6. You may either overwrite your old MySQL installation (usually
  9449.      located at `C:\mysql'), or install it into a different directory,
  9450.      such as `C:\mysql4'. Overwriting the old installation is
  9451.      recommended.
  9452.  
  9453.   7. The version of MySQL that is started as a service is determined by
  9454.      the `basedir' parameter in the `my.ini' file of your Windows
  9455.      directory (for example, `C:\WINNT').
  9456.  
  9457.   8. Restart the server (for example, with `NET START mysql' if you run
  9458.      MYSQL as a service, or by invoking `mysqld' directly otherwise).
  9459.  
  9460.  
  9461. Possible error situations:
  9462.      A system error has occurred.
  9463.      System error 1067 has occurred.
  9464.      The process terminated unexpectedly.
  9465.  
  9466. This cryptic error means that your `my.cnf' file (by default
  9467. `C:\my.cnf') contains an option that cannot be recognised by MySQL. You
  9468. can verify that this is the case by trying to restart MySQL with the
  9469. `my.cnf' file renamed, for example, to `my.cnf.old' to prevent the
  9470. server from using it.  Once you have verified it, you need to identify
  9471. which option is the culprit. Create a new `my.cnf' file and move parts
  9472. of the old file to it (restarting the server after you move each part)
  9473. until you determine which part causes server startup to fail.
  9474.  
  9475. Operating System Specific Notes
  9476. ===============================
  9477.  
  9478. Linux Notes (All Linux Versions)
  9479. --------------------------------
  9480.  
  9481. The following notes regarding `glibc' apply only to the situation when
  9482. you build MySQL yourself. If you are running Linux on an x86 machine,
  9483. in most cases it is much better for you to just use our binary. We link
  9484. our binaries against the best patched version of `glibc' we can come up
  9485. with and with the best compiler options, in an attempt to make it
  9486. suitable for a high-load server. So if you read the following text, and
  9487. are in doubt about what you should do, try our binary first to see if
  9488. it meets your needs, and worry about your own build only after you have
  9489. discovered that our binary is not good enough. In that case, we would
  9490. appreciate a note about it, so we can build a better binary next time.
  9491. For a typical user, even for setups with a lot of concurrent
  9492. connections and/or tables exceeding the 2G limit, our binary in most
  9493. cases is the best choice.
  9494.  
  9495. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  9496. version that doesn't have `glibc2', you must install LinuxThreads
  9497. before trying to compile MySQL.   You can get LinuxThreads at
  9498. `http://www.mysql.com/downloads/os-linux.html'.
  9499.  
  9500. *Note*: we have seen some strange problems with Linux 2.2.14 and MySQL
  9501. on SMP systems. If you have a SMP system, we recommend you upgrade to
  9502. Linux 2.4 as soon as possible.  Your system will be faster and more
  9503. stable by doing this.
  9504.  
  9505. Note that `glibc' versions before and including Version 2.1.1 have a
  9506. fatal bug in `pthread_mutex_timedwait' handling, which is used when you
  9507. do `INSERT DELAYED'.  We recommend that you not use `INSERT DELAYED'
  9508. before upgrading glibc.
  9509.  
  9510. If you plan to have 1000+ concurrent connections, you will need to make
  9511. some changes to LinuxThreads, recompile it, and relink MySQL against
  9512. the new `libpthread.a'.  Increase `PTHREAD_THREADS_MAX' in
  9513. `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  9514. `STACK_SIZE' in `linuxthreads/internals.h' to 256 KB. The paths are
  9515. relative to the root of `glibc' Note that MySQL will not be stable with
  9516. around 600-1000 connections if `STACK_SIZE' is the default of 2 MB.
  9517.  
  9518. If MySQL can't open enough files, or connections, it may be that you
  9519. haven't configured Linux to handle enough files.
  9520.  
  9521. In Linux 2.2 and onward, you can check the number of allocated file
  9522. handles by doing:
  9523.  
  9524.      cat /proc/sys/fs/file-max
  9525.      cat /proc/sys/fs/dquot-max
  9526.      cat /proc/sys/fs/super-max
  9527.  
  9528. If you have more than 16 MB of memory, you should add something like the
  9529. following to your init scripts (for example, `/etc/init.d/boot.local'
  9530. on SuSE Linux):
  9531.  
  9532.      echo 65536 > /proc/sys/fs/file-max
  9533.      echo 8192 > /proc/sys/fs/dquot-max
  9534.      echo 1024 > /proc/sys/fs/super-max
  9535.  
  9536. You can also run the preceding commands from the command-line as root,
  9537. but these settings will be lost the next time your computer reboots.
  9538.  
  9539. Alternatively, you can set these parameters on bootup by using the
  9540. `sysctl' tool, which is used by many Linux distributions (SuSE has
  9541. added it as well, beginning with SuSE Linux 8.0). Just put the following
  9542. values into a file named `/etc/sysctl.conf':
  9543.  
  9544.      # Increase some values for MySQL
  9545.      fs.file-max = 65536
  9546.      fs.dquot-max = 8192
  9547.      fs.super-max = 1024
  9548.  
  9549. You should also add the following to `/etc/my.cnf':
  9550.  
  9551.      [mysqld_safe]
  9552.      open-files-limit=8192
  9553.  
  9554. This should allow MySQL to create up to 8192 connections + files.
  9555.  
  9556. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  9557. stacks in the address space.  It needs to be large enough so that there
  9558. will be plenty of room for the stack of each individual thread, but
  9559. small enough to keep the stack of some threads from running into the
  9560. global `mysqld' data.  Unfortunately, the Linux implementation of
  9561. `mmap()', as we have experimentally discovered, will successfully unmap
  9562. an already mapped region if you ask it to map out an address already in
  9563. use, zeroing out the data on the entire page, instead of returning an
  9564. error.  So, the safety of `mysqld' or any other threaded application
  9565. depends on the "gentleman" behaviour of the code that creates threads.
  9566. The user must take measures to make sure the number of running threads
  9567. at any time is sufficiently low for thread stacks to stay away from the
  9568. global heap.  With `mysqld', you should enforce this "gentleman"
  9569. behaviour by setting a reasonable value for the `max_connections'
  9570. variable.
  9571.  
  9572. If you build MySQL yourself and do not want to mess with patching
  9573. LinuxThreads, you should set `max_connections' to a value no higher
  9574. than 500.  It should be even less if you have a large key buffer,  large
  9575. heap tables, or some other things that make `mysqld' allocate a lot of
  9576. memory, or if you are running a 2.2 kernel with a 2G patch. If you are
  9577. using our binary or RPM version 3.23.25 or later, you can safely set
  9578. `max_connections' at 1500, assuming no large key buffer or heap tables
  9579. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  9580. the more threads you can safely create.  We recommend the values between
  9581. 128K and 256K.
  9582.  
  9583. If you use a lot of concurrent connections, you may suffer from a
  9584. "feature" in the 2.2 kernel that penalises a process for forking or
  9585. cloning a child in an attempt to prevent a fork bomb attack.  This will
  9586. cause MySQL not to scale well as you increase the number of concurrent
  9587. clients.  On single-CPU systems, we have seen this manifested in a very
  9588. slow thread creation, which means it may take a long time to connect to
  9589. MySQL (as long as 1 minute), and it may take just as long to shut it
  9590. down.  On multiple-CPU systems, we have observed a gradual drop in
  9591. query speed as the number of clients increases.  In the process of
  9592. trying to find a solution, we have received a kernel patch from one of
  9593. our users, who claimed it made a lot of difference for his site.  The
  9594. patch is available at
  9595. `http://www.mysql.com/Downloads/Patches/linux-fork.patch'. We have now
  9596. done rather extensive testing of this patch on both development and
  9597. production systems.  It has significantly improved `MySQL' performance
  9598. without causing any problems and we now recommend it to our users who
  9599. are still running high-load servers on 2.2 kernels.  This issue has
  9600. been fixed in the 2.4 kernel, so if you are not satisfied with the
  9601. current performance of your system, rather than patching your 2.2
  9602. kernel, it might be easier to just upgrade to 2.4, which will also give
  9603. you a nice SMP boost in addition to fixing this fairness bug.
  9604.  
  9605. We have tested MySQL on the 2.4 kernel on a 2-CPU machine and found
  9606. MySQL scales *much* better--there was virtually no slowdown on queries
  9607. throughput all the way up to 1000 clients, and the MySQL scaling factor
  9608. (computed as the ratio of maximum throughput to the throughput with one
  9609. client) was 180%.  We have observed similar results on a 4-CPU
  9610. system--virtually no slowdown as the number of clients was increased up
  9611. to 1000, and 300% scaling factor. So for a high-load SMP server we
  9612. would definitely recommend the 2.4 kernel at this point. We have
  9613. discovered that it is essential to run `mysqld' process with the
  9614. highest possible priority on the 2.4 kernel to achieve maximum
  9615. performance.  This can be done by adding `renice -20 $$' command to
  9616. `mysqld_safe'. In our testing on a 4-CPU machine, increasing the
  9617. priority gave 60% increase in throughput with 400 clients.
  9618.  
  9619. We are currently also trying to collect more info on how well `MySQL'
  9620. performs on 2.4 kernel on 4-way and 8-way systems. If you have access
  9621. such a system and have done some benchmarks, please send a mail to
  9622. <docs@mysql.com> with the results - we will include them in the manual.
  9623.  
  9624. There is another issue that greatly hurts MySQL performance, especially
  9625. on SMP systems.  The implementation of mutex in LinuxThreads in
  9626. `glibc-2.1' is very bad for programs with many threads that only hold
  9627. the mutex for a short time. On an SMP system, ironic as it is, if you
  9628. link MySQL against unmodified `LinuxThreads', removing processors from
  9629. the machine improves MySQL performance in many cases.  We have made a
  9630. patch available for `glibc 2.1.3' to correct this behaviour
  9631. (`http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch').
  9632.  
  9633. With `glibc-2.2.2' MySQL version 3.23.36 will use the adaptive mutex,
  9634. which is much better than even the patched one in `glibc-2.1.3'. Be
  9635. warned, however, that under some conditions, the current mutex code in
  9636. `glibc-2.2.2' overspins, which hurts MySQL performance. The chance of
  9637. this condition can be reduced by renicing `mysqld' process to the
  9638. highest priority. We have also been able to correct the overspin
  9639. behaviour with a patch, available at
  9640. `http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch'.  It
  9641. combines the correction of overspin, maximum number of threads, and
  9642. stack spacing all in one. You will need to apply it in the
  9643. `linuxthreads' directory with `patch -p0
  9644. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  9645. form in to the future releases of `glibc-2.2'. In any case, if you link
  9646. against `glibc-2.2.2' you still need to correct `STACK_SIZE' and
  9647. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  9648. some more acceptable values for high-load MySQL setup in the future, so
  9649. that your own build can be reduced to `./configure; make; make install'.
  9650.  
  9651. We recommend that you use the above patches to build a special static
  9652. version of `libpthread.a' and use it only for statically linking
  9653. against `MySQL'. We know that the patches are safe for `MySQL' and
  9654. significantly improve its performance, but we cannot say anything about
  9655. other applications. If you link other applications against the patched
  9656. version of the library, or build a patched shared version and install
  9657. it on your system, you are doing it at your own risk with regard to
  9658. other applications that depend on `LinuxThreads'.
  9659.  
  9660. If you experience any strange problems during the installation of
  9661. MySQL, or with some common utilities hanging, it is very likely that
  9662. they are either library or compiler related. If this is the case, using
  9663. our binary will resolve them.
  9664.  
  9665. One known problem with the binary distribution is that with older Linux
  9666. systems that use `libc' (like Red Hat 4.x or Slackware), you will get
  9667. some non-fatal problems with hostname resolution.  *Note Binary
  9668. notes-Linux::.
  9669.  
  9670. When using LinuxThreads you will see a minimum of three processes
  9671. running.  These are in fact threads.  There will be one thread for the
  9672. LinuxThreads manager, one thread to handle connections, and one thread
  9673. to handle alarms and signals.
  9674.  
  9675. Note that the Linux kernel and the LinuxThread library can by default
  9676. only have 1024 threads.  This means that you can only have up to 1021
  9677. connections to MySQL on an unpatched system.  The page
  9678. `http://www.volano.com/linuxnotes.html' contains information how to go
  9679. around this limit.
  9680.  
  9681. If you see a dead `mysqld' daemon process with `ps', this usually means
  9682. that you have found a bug in MySQL or you have a corrupted table. *Note
  9683. Crashing::.
  9684.  
  9685. To get a core dump on Linux if `mysqld' dies with a `SIGSEGV' signal,
  9686. you can start `mysqld' with the `--core-file' option.  Note that you
  9687. also probably need to raise the `core file size' by adding `ulimit -c
  9688. 1000000' to `mysqld_safe' or starting `mysqld_safe' with
  9689. `--core-file-size=1000000'.  *Note `mysqld_safe': mysqld_safe.
  9690.  
  9691. If you are linking your own MySQL client and get the error:
  9692.  
  9693.      ld.so.1: ./my: fatal: libmysqlclient.so.4:
  9694.      open failed: No such file or directory
  9695.  
  9696. When executing them, the problem can be avoided by one of the following
  9697. methods:
  9698.  
  9699.    * Link the client with the following flag (instead of `-Lpath'):
  9700.      `-Wl,r/path-libmysqlclient.so'.
  9701.  
  9702.    * Copy `libmysqclient.so' to `/usr/lib'.
  9703.  
  9704.    * Add the pathname of the directory where `libmysqlclient.so' is
  9705.      located to the `LD_RUN_PATH' environment variable before running
  9706.      your client.
  9707.  
  9708. If you are using the Fujitsu compiler `(fcc / FCC)' you will have some
  9709. problems compiling MySQL because the Linux header files are very `gcc'
  9710. oriented.
  9711.  
  9712. The following `configure' line should work with `fcc/FCC':
  9713.  
  9714.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE \
  9715.      -DCONST=const -DNO_STRTOLL_PROTO" CXX=FCC CXXFLAGS="-O -K fast -K lib \
  9716.      -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE -DCONST=const \
  9717.      -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO \
  9718.      '-D_EXTERN_INLINE=static __inline'" ./configure --prefix=/usr/local/mysql \
  9719.      --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared \
  9720.      --with-low-memory
  9721.  
  9722. Linux Notes for Binary Distributions
  9723. ....................................
  9724.  
  9725. MySQL needs at least Linux Version 2.0.
  9726.  
  9727. *Warning*: We have reports from some MySQL users that they have got
  9728. serious stability problems with MySQL with Linux kernel 2.2.14.  If you
  9729. are using this kernel you should upgrade to 2.2.19 (or newer) or to a
  9730. 2.4 kernel.  If you have a multi-cpu box, then you should seriously
  9731. consider using 2.4 as this will give you a significant speed boost.
  9732.  
  9733. The binary release is linked with `-static', which means you do not
  9734. normally need to worry about which version of the system libraries you
  9735. have. You need not install LinuxThreads, either.  A program linked with
  9736. `-static' is slightly bigger than a dynamically linked program but also
  9737. slightly faster (3-5%).  One problem, however, is that you can't use
  9738. user-definable functions (UDFs) with a statically linked program.  If
  9739. you are going to write or use UDFs (this is something for C or C++
  9740. programmers only), you must compile MySQL yourself, using dynamic
  9741. linking.
  9742.  
  9743. If you are using a `libc'-based system (instead of a `glibc2' system),
  9744. you will probably get some problems with hostname resolving and
  9745. `getpwnam()' with the binary release. (This is because `glibc'
  9746. unfortunately depends on some external libraries to resolve hostnames
  9747. and `getpwent()', even when compiled with `-static'). In this case you
  9748. probably get the following error message when you run
  9749. `mysql_install_db':
  9750.  
  9751.      Sorry, the host 'xxxx' could not be looked up
  9752.  
  9753. or the following error when you try to run `mysqld' with the `--user'
  9754. option:
  9755.  
  9756.      getpwnam: No such file or directory
  9757.  
  9758. You can solve this problem in one of the following ways:
  9759.  
  9760.    * Get a MySQL source distribution (an RPM or the `tar.gz'
  9761.      distribution) and install this instead.
  9762.  
  9763.    * Execute `mysql_install_db --force'; this will not execute the
  9764.      `resolveip' test in `mysql_install_db'.  The downside is that you
  9765.      can't use host names in the grant tables; you must use IP numbers
  9766.      instead (except for `localhost').  If you are using an old MySQL
  9767.      release that doesn't support `--force', you have to remove the
  9768.      `resolveip' test in `mysql_install' with an editor.
  9769.  
  9770.    * Start `mysqld' with `su' instead of using `--user'.
  9771.  
  9772. The Linux-Intel binary and RPM releases of MySQL are configured for the
  9773. highest possible speed.  We are always trying to use the fastest stable
  9774. compiler available.
  9775.  
  9776. MySQL Perl support requires Version Perl 5.004_03 or newer.
  9777.  
  9778. On some Linux 2.2 versions, you may get the error `Resource temporarily
  9779. unavailable' when you do a lot of new connections to a `mysqld' server
  9780. over TCP/IP.
  9781.  
  9782. The problem is that Linux has a delay between when you close a TCP/IP
  9783. socket and until this is actually freed by the system.  As there is only
  9784. room for a finite number of TCP/IP slots, you will get the above error
  9785. if you try to do too many new TCP/IP connections during a small time,
  9786. like when you run the MySQL `test-connect' benchmark over TCP/IP.
  9787.  
  9788. We have mailed about this problem a couple of times to different Linux
  9789. mailing lists but have never been able to resolve this properly.
  9790.  
  9791. The only known 'fix' to this problem is to use persistent connections in
  9792. your clients or use sockets, if you are running the database server and
  9793. clients on the same machine.  We hope that the `Linux 2.4' kernel will
  9794. fix this problem in the future.
  9795.  
  9796. Linux x86 Notes
  9797. ...............
  9798.  
  9799. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  9800. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  9801. have been some problems with the `glibc' RPMs from Red Hat, so if you
  9802. have problems, check whether there are any updates.  The `glibc'
  9803. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  9804.  
  9805. If you are using Red Hat 8.0 or a new glibc 2.2.x library you should
  9806. start mysqld with the option `--thread-stack=192K'.  If you don't do it
  9807. mysqld will die in `gethostbyaddr()' because the new glibc library
  9808. requires > 128K memory on stack for this call. This stack size is now
  9809. the default on MySQL 4.0.10 and above.
  9810.  
  9811. If you are using gcc 3.0 and above to compile MySQL, you must install
  9812. the `libstdc++v3' library before compiling MySQL; if you don't do this
  9813. you will get an error about a missing `__cxa_pure_virtual' symbol
  9814. during linking.
  9815.  
  9816. On some older Linux distributions, `configure' may produce an error
  9817. like this:
  9818.  
  9819.      Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file.
  9820.      See the Installation chapter in the Reference Manual.
  9821.  
  9822. Just do what the error message says and add an extra underscore to the
  9823. `_P' macro that has only one underscore, then try again.
  9824.  
  9825. You may get some warnings when compiling; those shown here can be
  9826. ignored:
  9827.  
  9828.      mysqld.cc -o objs-thread/mysqld.o
  9829.      mysqld.cc: In function `void init_signals()':
  9830.      mysqld.cc:315: warning: assignment of negative value `-1' to
  9831.      `long unsigned int'
  9832.      mysqld.cc: In function `void * signal_hand(void *)':
  9833.      mysqld.cc:346: warning: assignment of negative value `-1' to
  9834.      `long unsigned int'
  9835.  
  9836. `mysql.server' can be found in the `share/mysql' directory under the
  9837. MySQL installation directory or in the `support-files' directory of the
  9838. MySQL source tree.
  9839.  
  9840. If `mysqld' always core dumps when it starts up, the problem may be that
  9841. you have an old `/lib/libc.a'.  Try renaming it, then remove
  9842. `sql/mysqld' and do a new `make install' and try again.  This problem
  9843. has been reported on some Slackware installations.
  9844.  
  9845. If you get the following error when linking `mysqld', it means that
  9846. your `libg++.a' is not installed correctly:
  9847.  
  9848.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  9849.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  9850.  
  9851. You can avoid using `libg++.a' by running `configure' like this:
  9852.  
  9853.      shell> CXX=gcc ./configure
  9854.  
  9855. Linux SPARC Notes
  9856. .................
  9857.  
  9858. In some implementations, `readdir_r()' is broken.  The symptom is that
  9859. `SHOW DATABASES' always returns an empty set.  This can be fixed by
  9860. removing `HAVE_READDIR_R' from `config.h' after configuring and before
  9861. compiling.
  9862.  
  9863. Some problems will require patching your Linux installation.  The patch
  9864. can be found at
  9865. `http://www.mysql.com/Downloads/patches/Linux-sparc-2.0.30.diff'.  This
  9866. patch is against the Linux distribution `sparclinux-2.0.30.tar.gz' that
  9867. is available at `vger.rutgers.edu' (a version of Linux that was never
  9868. merged with the official 2.0.30).  You must also install LinuxThreads
  9869. Version 0.6 or newer.
  9870.  
  9871. Linux Alpha Notes
  9872. .................
  9873.  
  9874. MySQL Version 3.23.12 is the first MySQL version that is tested on
  9875. Linux-Alpha.  If you plan to use MySQL on Linux-Alpha, you should
  9876. ensure that you have this version or newer.
  9877.  
  9878. We have tested MySQL on Alpha with our benchmarks and test suite, and
  9879. it appears to work nicely.
  9880.  
  9881. We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP,
  9882. kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler
  9883. (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.
  9884.  
  9885. You can find the above compilers at
  9886. `http://www.support.compaq.com/alpha-tools/'.  By using these compilers,
  9887. instead of gcc, we get about 9-14% better performance with MySQL.
  9888.  
  9889. Note that until MySQL version 3.23.52 and 4.0.2 we optimised the binary
  9890. for the current CPU only (by using the `-fast' compile option); this
  9891. meant that you could only use our binaries if you had an Alpha EV6
  9892. processor.
  9893.  
  9894. Starting with all following releases we added the `-arch generic' flag
  9895. to our compile options, which makes sure the binary runs on all Alpha
  9896. processors. We also compile statically to avoid library problems.
  9897.  
  9898.      CC=ccc CFLAGS="-fast -arch generic" CXX=cxx \
  9899.      CXXFLAGS="-fast -arch generic -noexceptions -nortti" \
  9900.      ./configure --prefix=/usr/local/mysql --disable-shared \
  9901.      --with-extra-charsets=complex --enable-thread-safe-client \
  9902.      --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  9903.  
  9904. If you want to use egcs the following configure line worked for us:
  9905.  
  9906.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
  9907.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  9908.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  9909.      --disable-shared
  9910.  
  9911. Some known problems when running MySQL on Linux-Alpha:
  9912.  
  9913.    * Debugging threaded applications like MySQL will not work with `gdb
  9914.      4.18'.  You should download and use gdb 5.1 instead!
  9915.  
  9916.    * If you try linking `mysqld' statically when using `gcc', the
  9917.      resulting image will core dump at start.  In other words, *don't*
  9918.      use `--with-mysqld-ldflags=-all-static' with `gcc'.
  9919.  
  9920. Linux PowerPC Notes
  9921. ...................
  9922.  
  9923. MySQL should work on MkLinux with the newest `glibc' package (tested
  9924. with `glibc' 2.0.7).
  9925.  
  9926. Linux MIPS Notes
  9927. ................
  9928.  
  9929. To get MySQL to work on Qube2, (Linux Mips), you need the newest
  9930. `glibc' libraries (`glibc-2.0.7-29C2' is known to work).  You must also
  9931. use the `egcs' C++ compiler (`egcs-1.0.2-9', `gcc 2.95.2' or newer).
  9932.  
  9933. Linux IA-64 Notes
  9934. .................
  9935.  
  9936. To get MySQL to compile on Linux IA-64, we use the following compile
  9937. line: Using `gcc-2.96':
  9938.  
  9939.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  9940.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  9941.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  9942.      "--with-comment=Official MySQL binary" --with-extra-charsets=complex
  9943.  
  9944. On IA-64, the MySQL client binaries use shared libraries. This means
  9945. that if you install our binary distribution in some other place than
  9946. `/usr/local/mysql' you need to add the path of the directory where you
  9947. have `libmysqlclient.so' installed either to the `/etc/ld.so.conf' file
  9948. or to the value of your `LD_LIBRARY_PATH' environment variable.
  9949.  
  9950. *Note Link errors::.
  9951.  
  9952. Windows Notes
  9953. -------------
  9954.  
  9955. This section describes using MySQL on Windows. This information is also
  9956. provided in the `README' file that comes with the MySQL Windows
  9957. distribution. *Note Windows installation::.
  9958.  
  9959. On Windows 95, 98, or Me, MySQL clients always connect to the server
  9960. using TCP/IP. On NT-based systems such as Windows NT, 2000, or XP,
  9961. clients have two options. They can use TCP/IP, or they can use a named
  9962. pipe if the server supports named pipe connections.
  9963.  
  9964. For information about which server binary to run, see *Note Windows
  9965. prepare environment::.
  9966.  
  9967. The examples in this section assume that MySQL is installed under the
  9968. default location of `C:\mysql'. Adjust the pathnames shown in the
  9969. examples if you have MySQL installed in a different location.
  9970.  
  9971. Starting MySQL on Windows 95, 98, or Me
  9972. .......................................
  9973.  
  9974. On these versions of Windows, MySQL uses TCP/IP to connect a client to
  9975. a server. (This will allow any machine on your network to connect to
  9976. your MySQL server.)  Because of this, you must make sure that TCP/IP
  9977. support is installed on your machine before starting MySQL.  You can
  9978. find TCP/IP on your Windows CD-ROM.
  9979.  
  9980. Note that if you are using an old Windows 95 release (for example,
  9981. OSR2), it's likely that you have an old Winsock package; MySQL requires
  9982. Winsock 2! You can get the newest Winsock from
  9983. `http://www.microsoft.com/'.  Windows 98 has the new Winsock 2 library,
  9984. so it is unnecessary to update the library.
  9985.  
  9986. To start the `mysqld' server, you should start a console window (a
  9987. "DOS" window) and enter this command:
  9988.  
  9989.      shell> C:\mysql\bin\mysqld
  9990.  
  9991. This will start `mysqld' in the background. That is, after the server
  9992. starts up, you should see another command prompt. (Note that if you
  9993. start the server this way on Windows NT, 2000, or XP, the server will
  9994. run in the foreground and the next command prompt will not appear until
  9995. the server exits.  To run client programs while the server is running,
  9996. you should open another console window.)
  9997.  
  9998. You can stop the MySQL server by executing this command:
  9999.  
  10000.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  10001.  
  10002. This invokes the MySQL administrative utility `mysqladmin' to connect
  10003. to the server as `root', which is the default administrative account in
  10004. the MySQL grant system. Please note that users in the MySQL grant
  10005. system are wholly independent from any login users under Windows.
  10006.  
  10007. If `mysqld' doesn't start, please check the error log to see if the
  10008. server wrote any messages there to indicate the cause of the problem.
  10009. The error log is located in the `C:\mysql\data' directory. It is the
  10010. file with a suffix of `.err'. You can also try to start the server as
  10011. `mysqld --console'; in this case, you may get some useful information
  10012. on the screen that may help solve the problem.
  10013.  
  10014. The last option is to start `mysqld' with `--standalone --debug'.  In
  10015. this case `mysqld' will write a log file `C:\mysqld.trace' that should
  10016. contain the reason why `mysqld' doesn't start. *Note Making trace
  10017. files::.
  10018.  
  10019. Use `mysqld --help' to display all the options that `mysqld'
  10020. understands!
  10021.  
  10022. Starting MySQL on Windows NT, 2000, or XP
  10023. .........................................
  10024.  
  10025. To get MySQL to work with TCP/IP on Windows NT 4, you must install
  10026. service pack 3 (or newer)!
  10027.  
  10028. Normally you should install MySQL as a service on Windows NT/2000/XP.
  10029. In case the server was already running, first stop it using the
  10030. following command:
  10031.  
  10032.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  10033.  
  10034. This invokes the MySQL administrative utility `mysqladmin' to connect
  10035. to the server as `root', which is the default administrative account in
  10036. the MySQL grant system. Please note that users in the MySQL grant
  10037. system are wholly independent from any login users under Windows.
  10038.  
  10039. Now install the server as a service:
  10040.  
  10041.      shell> C:\mysql\bin\mysqld --install
  10042.  
  10043. The service is installed with the name `MySql'. Once installed, it can
  10044. be immediately started from the `Services' utility, or by using the
  10045. command `NET START MySql'.
  10046.  
  10047. Once running, `mysqld' can be stopped by using the Services utility,
  10048. the command `NET STOP MySql', or the command `mysqladmin shutdown'.
  10049.  
  10050. If any startup options are required, you can place them in the
  10051. `[mysqld]' group of any of the standard option files. As of MySQL
  10052. 4.0.3, you can place options in the `[mysqld]' group of any option file
  10053. and use a `--defaults-file' option to tell the server the name of the
  10054. file when you install the service. For example:
  10055.  
  10056.      shell> C:\mysql\bin\mysqld --install MySql --defaults-file=C:\my-opts.cnf
  10057.  
  10058. You can also specify options as "`Start parameters'" in the Windows
  10059. `Services' utility before you start the MySQL service.
  10060.  
  10061. The `Services' utility (`Windows Service Control Manager') can be found
  10062. in the `Windows Control Panel' (under `Administrative Tools' on Windows
  10063. 2000). It is advisable to close the Services utility while performing
  10064. the `--install' or `--remove' operations, this prevents some odd errors.
  10065.  
  10066. Please note that from MySQL version 3.23.44, you have the choice of
  10067. setting up the service as `Manual' instead (if you don't wish the
  10068. service to be started automatically during the boot process):
  10069.  
  10070.      shell> C:\mysql\bin\mysqld --install-manual
  10071.  
  10072. When MySQL is running as a service, the operating system will
  10073. automatically stop the server on computer shutdown. In MySQL versions
  10074. older than 3.23.47, Windows waited only for a few seconds for the
  10075. shutdown to complete, and killed the database server process if the
  10076. time limit was exceeded. This had the potential to cause problems.
  10077. (For example, at the next startup the `InnoDB' storage engine had to do
  10078. crash recovery.) Starting from MySQL version 3.23.48, Windows waits
  10079. longer for the MySQL server shutdown to complete. If you notice this
  10080. still is not enough for your installation, it is safest not to run the
  10081. MySQL server as a service. Instead, run it from the command-line
  10082. prompt, and shut it down with `mysqladmin shutdown'.
  10083.  
  10084. There is a problem that Windows NT (but not Windows 2000/XP) by default
  10085. only waits 20 seconds for a service to shut down, and after that kills
  10086. the service process. You can increase this default by opening the
  10087. Registry Editor `\winnt\system32\regedt32.exe' and editing the value of
  10088. `WaitToKillServiceTimeout' at
  10089. `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' in the Registry
  10090. tree. Specify the new larger value in milliseconds (for example, 120000
  10091. to have Windows NT wait up to 120 seconds).
  10092.  
  10093. Please note that when run as a service, `mysqld' has no access to a
  10094. console and so no messages can be seen.  Errors can be checked in the
  10095. error log, which is located in the `C:\mysql\data' directory. It is the
  10096. file with a suffix of `.err'.
  10097.  
  10098. If you have problems installing `mysqld' as a service using just the
  10099. server name, try installing it using its full pathname:
  10100.  
  10101.      shell> C:\mysql\bin\mysqld --install
  10102.  
  10103. If that doesn't work, you can get `mysqld' to start properly by fixing
  10104. the path in the registry!
  10105.  
  10106. If you don't want to start `mysqld' as a service, you can start it from
  10107. the command line the same way as for Windows 95, 98, or Me. For
  10108. instructions, see *Note Win95 start::.
  10109.  
  10110. Running MySQL on Windows
  10111. ........................
  10112.  
  10113. MySQL supports TCP/IP on all Windows platforms. The `mysqld-nt' and
  10114. `mysql-max-nt' servers support named pipes on NT, 2000, and XP.  The
  10115. default is to use TCP/IP regardless of the platform, because named
  10116. pipes are actually slower than TCP/IP, and because some users have
  10117. experienced problems shutting down the MySQL server when named pipes
  10118. are used. Starting from 3.23.50, named pipes are only enabled for
  10119. `mysqld-nt' and `mysql-max-nt' if they are started with the
  10120. `--enable-named-pipe' option.
  10121.  
  10122. You can force a MySQL client to use named pipes by specifying the
  10123. `--pipe' option or by specifying `.' as the host name.  Use the
  10124. `--socket' option to specify the name of the pipe.  In MySQL 4.1, you
  10125. should use the `--protocol=PIPE' option.
  10126.  
  10127. You can test whether the MySQL server is working by executing any of the
  10128. following commands:
  10129.  
  10130.      C:\> C:\mysql\bin\mysqlshow
  10131.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  10132.      C:\> C:\mysql\bin\mysqladmin version status proc
  10133.      C:\> C:\mysql\bin\mysql test
  10134.  
  10135. If `mysqld' is slow to answer to connections on Windows 9x/Me, there is
  10136. probably a problem with your DNS.  In this case, start `mysqld' with the
  10137. `--skip-name-resolve' option and use only `localhost' and IP numbers in
  10138. the `Host' column of the MySQL grant tables.
  10139.  
  10140. There are two versions of the MySQL command-line tool:
  10141. *Binary**Description*
  10142. `mysql' Compiled on native Windows, offering
  10143.         limited text editing capabilities.
  10144. `mysqlc'Compiled with the Cygnus GNU compiler and
  10145.         libraries, which offers `readline' editing.
  10146.  
  10147. If you want to use `mysqlc', you must have a copy of the
  10148. `cygwinb19.dll' library installed somewhere that `mysqlc' can find it.
  10149. If your distribution of MySQL doesn't have this library installed in the
  10150. same directory as `mysqlc' (the `bin' directory under the base
  10151. directory of your MySQL installation, look in the `lib' directory to
  10152. find it and copy it to your Windows system directory (`\windows\system'
  10153. or similar place).
  10154.  
  10155. The default privileges on Windows give all local users full privileges
  10156. to all databases without specifying a password.  To make MySQL more
  10157. secure, you should set a password for all users and remove the row in
  10158. the `mysql.user' table that has `Host='localhost'' and `User='''.
  10159.  
  10160. You should also add a password for the `root' user. The following
  10161. example starts by removing the anonymous user that has all privileges,
  10162. then sets a `root' user password:
  10163.  
  10164.      C:\> C:\mysql\bin\mysql mysql
  10165.      mysql> DELETE FROM user WHERE Host='localhost' AND User='';
  10166.      mysql> QUIT
  10167.      C:\> C:\mysql\bin\mysqladmin reload
  10168.      C:\> C:\mysql\bin\mysqladmin -u root password your_password
  10169.  
  10170. After you've set the password, if you want to shut down the `mysqld'
  10171. server, you can do so using this command:
  10172.  
  10173.      C:\> mysqladmin --user=root --password=your_password shutdown
  10174.  
  10175. If you are using the old shareware version of MySQL Version 3.21 under
  10176. Windows, the above command will fail with an error: `parse error near
  10177. 'SET password''.  The solution to this problem is to upgrade to a newer
  10178. version of MySQL.
  10179.  
  10180. With the current MySQL versions you can easily add new users and change
  10181. privileges with `GRANT' and `REVOKE' commands.  *Note `GRANT': GRANT.
  10182.  
  10183. Connecting to MySQL Remotely from Windows with SSH
  10184. ..................................................
  10185.  
  10186. Here is a note about how to connect to get a secure connection to remote
  10187. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  10188.  
  10189.   1. Install an SSH client on your Windows machine.  As a user, the
  10190.      best non-free one I've found is from `SecureCRT' from
  10191.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  10192.      `http://www.f-secure.com/'. You can also find some free ones on
  10193.      `Google' at
  10194.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  10195.  
  10196.   2. Start your Windows SSH client.  Set `Host_Name =
  10197.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  10198.      your server (probably not the same as your MySQL login/password.
  10199.  
  10200.   3. Set up port forwarding. Either do a remote forward (Set
  10201.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  10202.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  10203.      `host: localhost', `remote port: 3306').
  10204.  
  10205.   4. Save everything, otherwise you'll have to redo it the next time.
  10206.  
  10207.   5. Log in to your server with SSH session you just created.
  10208.  
  10209.   6. On your Windows machine, start some ODBC application (such as
  10210.      Access).
  10211.  
  10212.   7. Create a new file in Windows and link to MySQL using the ODBC
  10213.      driver the same way you normally do, except type in `localhost'
  10214.      for the MySQL host server--not `yourmysqlservername'.
  10215.  
  10216. You should now have an ODBC connection to MySQL, encrypted using SSH.
  10217.  
  10218. Distributing Data Across Different Disks on Windows
  10219. ...................................................
  10220.  
  10221. Beginning with MySQL Version 3.23.16, the `mysqld-max' and
  10222. `mysql-max-nt' servers in the MySQL distribution are compiled with the
  10223. `-DUSE_SYMDIR' option.  This allows you to put a database on a
  10224. different disk by setting up a symbolic link to it (in a manner similar
  10225. to the way that symbolic links work on Unix).
  10226.  
  10227. On Windows, you make a symbolic link to a database by creating a file
  10228. that contains the path to the destination directory and saving this in
  10229. the data directory using the filename `db_name.sym', where `db_name' is
  10230. the database name.  Note that the symbolic link will not be used if a
  10231. directory with the database name exists.
  10232.  
  10233. For example, if the MySQL data directory is `C:\mysql\data' and you
  10234. want to have database `foo' located at `D:\data\foo', you should create
  10235. the file `C:\mysql\data\foo.sym' that contains the text `D:\data\foo\'.
  10236. After that, all tables created in the database `foo' will be created
  10237. in `D:\data\foo'.
  10238.  
  10239. Note that because of the speed penalty you get when opening every table,
  10240. we have not enabled this by default even if you have compiled MySQL
  10241. with support for this. To enable symlinks you should put in your
  10242. `my.cnf' or `my.ini' file the following entry:
  10243.  
  10244.      [mysqld]
  10245.      symbolic-links
  10246.  
  10247. In MySQL 4.0, symbolic links are enabled by default. If you don't need
  10248. them, you can disable them with the `skip-symbolic-links' option.
  10249.  
  10250. Compiling MySQL Clients on Windows
  10251. ..................................
  10252.  
  10253. In your source files, you should include `my_global.h' before `mysql.h':
  10254.  
  10255.      #include <my_global.h>
  10256.      #include <mysql.h>
  10257.  
  10258. `my_global.h' includes any other files needed for Windows compatibility
  10259. (such as `windows.h') if you compile your program on Windows.
  10260.  
  10261. You can either link your code with the dynamic `libmysql.lib' library,
  10262. which is just a wrapper to load in `libmysql.dll' on demand, or link
  10263. with the static `mysqlclient.lib' library.
  10264.  
  10265. Note that because the MySQL client libraries are compiled as threaded
  10266. libraries, you should also compile your code to be multi-threaded!
  10267.  
  10268. MySQL for Windows Compared to Unix MySQL
  10269. ........................................
  10270.  
  10271. MySQL for Windows has by now proven itself to be very stable. The
  10272. Windows version of MySQL has the same features as the corresponding
  10273. Unix version, with the following exceptions:
  10274.  
  10275. *Windows 95 and threads*
  10276.      Windows 95 leaks about 200 bytes of main memory for each thread
  10277.      creation.  Each connection in MySQL creates a new thread, so you
  10278.      shouldn't run `mysqld' for an extended time on Windows 95 if your
  10279.      server handles many connections!  Other versions of Windows don't
  10280.      suffer from this bug.
  10281.  
  10282. *Concurrent reads*
  10283.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  10284.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  10285.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  10286.      level interface with a virtual interface so that we can use the
  10287.      `readfile()'/`writefile()' interface on NT/2000/XP to get more
  10288.      speed.  The current implementation limits the number of open files
  10289.      MySQL can use to 1024, which means that you will not be able to
  10290.      run as many concurrent threads on NT/2000/XP as on Unix.
  10291.  
  10292. *Blocking read*
  10293.      MySQL uses a blocking read for each connection, which has the
  10294.      following implications:
  10295.  
  10296.         * A connection will not be disconnected automatically after 8
  10297.           hours, as happens with the Unix version of MySQL.
  10298.  
  10299.         * If a connection hangs, it's impossible to break it without
  10300.           killing MySQL.
  10301.  
  10302.         * `mysqladmin kill' will not work on a sleeping connection.
  10303.  
  10304.         * `mysqladmin shutdown' can't abort as long as there are
  10305.           sleeping connections.
  10306.  
  10307.      We plan to fix this problem when our Windows developers have
  10308.      figured out a nice workaround.
  10309.  
  10310. *`DROP DATABASE'*
  10311.      You can't drop a database that is in use by some thread.
  10312.  
  10313. *Killing MySQL from the task manager*
  10314.      You can't kill MySQL from the task manager or with the shutdown
  10315.      utility in Windows 95.  You must take it down with `mysqladmin
  10316.      shutdown'.
  10317.  
  10318. *Case-insensitive names*
  10319.      Filenames are case-insensitive on Windows, so database and table
  10320.      names are also case-insensitive in MySQL for Windows.  The only
  10321.      restriction is that database and table names must be specified
  10322.      using the same case throughout a given statement.  *Note Name case
  10323.      sensitivity::.
  10324.  
  10325. *The `\' directory character*
  10326.      Pathname components in Windows 95 are separated by the `\'
  10327.      character, which is also the escape character in MySQL.  If you
  10328.      are using `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', you
  10329.      must double the `\' character:
  10330.  
  10331.           mysql> LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
  10332.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  10333.  
  10334.      Alternatively, use Unix style filenames with `/' characters:
  10335.  
  10336.           mysql> LOAD DATA INFILE "C:/tmp/skr.txt" INTO TABLE skr;
  10337.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  10338.  
  10339. *Problems with pipes.*
  10340.      Pipes doesn't work reliably in the Windows command-line prompt.
  10341.      If the pipe includes the character `^Z' / `CHAR(24)', Windows will
  10342.      think it has encountered end-of-file and abort the program.
  10343.  
  10344.      This is mainly a problem when you try to apply a binary log as
  10345.      follows:
  10346.  
  10347.           mysqlbinlog binary-log-name | mysql --user=root
  10348.  
  10349.      If you get a problem applying the log and suspect it's because of
  10350.      an `^Z' / `CHAR(24)' character you can use the following
  10351.      workaround:
  10352.  
  10353.           mysqlbinlog binary-log-file --result-file=/tmp/bin.sql
  10354.           mysql --user=root --execute "source /tmp/bin.sql"
  10355.  
  10356.      The latter command also can be used to reliably read in any SQL
  10357.      file that may contain binary data.
  10358.  
  10359. *`Can't open named pipe' error*
  10360.      If you use a MySQL 3.22 version on NT with the newest mysql-clients
  10361.      you will get the following error:
  10362.  
  10363.           error 2017: can't open named pipe to host: . pipe...
  10364.  
  10365.      This is because the release version of MySQL uses named pipes on NT
  10366.      by default.  You can avoid this error by using the
  10367.      `--host=localhost' option to the new MySQL clients or create an
  10368.      option file `C:\my.cnf' that contains the following information:
  10369.  
  10370.           [client]
  10371.           host = localhost
  10372.  
  10373.      Starting from 3.23.50, named pipes are enabled only if `mysqld-nt'
  10374.      or `mysqld-max-nt' is started with `--enable-named-pipe'.
  10375.  
  10376. *`Access denied for user' error*
  10377.      If you get the error `Access denied for user: 'some-user@unknown'
  10378.      to database 'mysql'' when accessing a MySQL server on the same
  10379.      machine, this means that MySQL can't resolve your host name
  10380.      properly.
  10381.  
  10382.      To fix this, you should create a file `\windows\hosts' with the
  10383.      following information:
  10384.  
  10385.           127.0.0.1       localhost
  10386.  
  10387. *`ALTER TABLE'*
  10388.      While you are executing an `ALTER TABLE' statement, the table is
  10389.      locked from usage by other threads.  This has to do with the fact
  10390.      that on Windows, you can't delete a file that is in use by another
  10391.      threads.  (In the future, we may find some way to work around this
  10392.      problem.)
  10393.  
  10394. *`DROP TABLE'*
  10395.      `DROP TABLE' on a table that is in use by a `MERGE' table will not
  10396.      work on Windows because the `MERGE' handler does the table mapping
  10397.      hidden from the upper layer of MySQL.  Because Windows doesn't
  10398.      allow you to drop files that are open, you first must flush all
  10399.      `MERGE' tables (with `FLUSH TABLES') or drop the `MERGE' table
  10400.      before dropping the table.  We will fix this at the same time we
  10401.      introduce `VIEW's.
  10402.  
  10403. *`DATA DIRECTORY' and `INDEX DIRECTORY'*
  10404.      The `DATA DIRECTORY' and `INDEX DIRECTORY' options for `CREATE
  10405.      TABLE' are ignored on Windows, because Windows doesn't support
  10406.      symbolic links.
  10407.  
  10408. Here are some open issues for anyone who might want to help us with the
  10409. Windows release:
  10410.  
  10411.    * Add some nice start and shutdown icons to the MySQL installation.
  10412.  
  10413.    * It would be really nice to be able to kill `mysqld' from the task
  10414.      manager.  For the moment, you must use `mysqladmin shutdown'.
  10415.  
  10416.    * Port `readline' to Windows for use in the `mysql' command-line
  10417.      tool.
  10418.  
  10419.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  10420.      `mysqladmin', and `mysqldump') would be nice.
  10421.  
  10422.    * It would be nice if the socket read and write functions in `net.c'
  10423.      were interruptible. This would make it possible to kill open
  10424.      threads with `mysqladmin kill' on Windows.
  10425.  
  10426.    * `mysqld' always starts in the "C" locale and not in the default
  10427.      locale.  We would like to have `mysqld' use the current locale for
  10428.      the sort order.
  10429.  
  10430.    * Add macros to use the faster thread-safe increment/decrement
  10431.      methods provided by Windows.
  10432.  
  10433. Other Windows-specific issues are described in the `README' file that
  10434. comes with the Windows distribution of MySQL.
  10435.  
  10436. Solaris Notes
  10437. -------------
  10438.  
  10439. On Solaris, you may run into trouble even before you get the MySQL
  10440. distribution unpacked!  Solaris `tar' can't handle long file names, so
  10441. you may see an error like this when you unpack MySQL:
  10442.  
  10443.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,\
  10444.      informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  10445.      tar: directory checksum error
  10446.  
  10447. In this case, you must use GNU `tar' (`gtar') to unpack the
  10448. distribution.  You can find a precompiled copy for Solaris at
  10449. `http://www.mysql.com/downloads/os-solaris.html'.
  10450.  
  10451. Sun native threads only work on Solaris 2.5 and higher.  For Version
  10452. 2.4 and earlier, MySQL will automatically use MIT-pthreads.  *Note
  10453. MIT-pthreads::.
  10454.  
  10455. If you get the following error from configure:
  10456.  
  10457.      checking for restartable system calls... configure: error can not run test
  10458.      programs while cross compiling
  10459.  
  10460. This means that you have something wrong with your compiler
  10461. installation!  In this case you should upgrade your compiler to a newer
  10462. version.  You may also be able to solve this problem by inserting the
  10463. following row into the `config.cache' file:
  10464.  
  10465.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  10466.  
  10467. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  10468. 2.95.2 or 3.2. You can find this at `http://gcc.gnu.org/'.  Note that
  10469. `egcs' 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  10470.  
  10471. The recommended `configure' line when using `gcc' 2.95.2 is:
  10472.  
  10473.      CC=gcc CFLAGS="-O3" \
  10474.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  10475.      ./configure --prefix=/usr/local/mysql --with-low-memory --enable-assembler
  10476.  
  10477. If you have an UltraSPARC, you can get 4% more performance by adding
  10478. "-mcpu=v8 -Wa,-xarch=v8plusa" to CFLAGS and CXXFLAGS.
  10479.  
  10480. If you have Sun's Forte 5.0 (or newer) compiler, you can run
  10481. `configure' like this:
  10482.  
  10483.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt" \
  10484.      CXX=CC CXXFLAGS="-noex -mt" \
  10485.      ./configure --prefix=/usr/local/mysql --enable-assembler
  10486.  
  10487. You can create a 64 bit binary using Sun's Forte compiler with the
  10488. following compile flags:
  10489.  
  10490.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
  10491.      CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS="-xarch=v9" \
  10492.      ./configure --prefix=/usr/local/mysql --enable-assembler
  10493.  
  10494. To create a 64bit Solaris binary using `gcc', add `-m64' to `CFLAGS'
  10495. and `CXXFLAGS'. Note that this only works with MySQL 4.0 and up - MySQL
  10496. 3.23 does not include the required modifications to support this.
  10497.  
  10498. In the MySQL benchmarks, we got a 4% speedup on an UltraSPARC when using
  10499. Forte 5.0 in 32 bit mode compared to using gcc 3.2 with -mcpu flags.
  10500.  
  10501. If you create a 64 bit binary, it's 4 % slower than the 32 bit binary,
  10502. but `mysqld' can instead handle more treads and memory.
  10503.  
  10504. If you get a problem with `fdatasync' or `sched_yield', you can fix
  10505. this by adding `LIBS=-lrt' to the configure line
  10506.  
  10507. The following paragraph is only relevant for older compilers than
  10508. WorkShop 5.3:
  10509.  
  10510. You may also have to edit the `configure' script to change this line:
  10511.  
  10512.      #if !defined(__STDC__) || __STDC__ != 1
  10513.  
  10514. to this:
  10515.  
  10516.      #if !defined(__STDC__)
  10517.  
  10518. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  10519. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  10520. (broken compiler or broken include file).
  10521.  
  10522. If `mysqld' issues the error message shown here when you run it, you
  10523. have tried to compile MySQL with the Sun compiler without enabling the
  10524. multi-thread option (`-mt'):
  10525.  
  10526.      libc internal error: _rmutex_unlock: rmutex not held
  10527.  
  10528. Add `-mt' to `CFLAGS' and `CXXFLAGS' and try again.
  10529.  
  10530. If you are using the SFW version of gcc (which comes with Solaris 8),
  10531. you must add `/opt/sfw/lib' to the environment variable
  10532. `LD_LIBRARY_PATH' before running configure.
  10533.  
  10534. If you are using the gcc available from `sunfreeware.com', you may have
  10535. many problems.  You should recompile gcc and GNU binutils on the
  10536. machine you will be running them from to avoid any problems.
  10537.  
  10538. If you get the following error when compiling MySQL with `gcc', it
  10539. means that your `gcc' is not configured for your version of Solaris:
  10540.  
  10541.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  10542.      ./thr_alarm.c: In function `signal_hand':
  10543.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  10544.  
  10545. The proper thing to do in this case is to get the newest version of
  10546. `gcc' and compile it with your current `gcc' compiler!  At least for
  10547. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  10548. include files that will break all programs that use threads (and
  10549. possibly other programs)!
  10550.  
  10551. Solaris doesn't provide static versions of all system libraries
  10552. (`libpthreads' and `libdl'), so you can't compile MySQL with
  10553. `--static'.  If you try to do so, you will get the error:
  10554.  
  10555.      ld: fatal: library -ldl: not found
  10556.      
  10557.      or
  10558.      
  10559.      undefined reference to `dlopen'
  10560.      
  10561.      or
  10562.      
  10563.      cannot find -lrt
  10564.  
  10565. If too many processes try to connect very rapidly to `mysqld', you will
  10566. see this error in the MySQL log:
  10567.  
  10568.      Error in accept: Protocol error
  10569.  
  10570. You might try starting the server with the `--set-variable back_log=50'
  10571. option as a workaround for this. Please note that `--set-variable' is
  10572. deprecated since MySQL 4.0, just use `--back_log=50' on its own.  *Note
  10573. Command-line options::.
  10574.  
  10575. If you are linking your own MySQL client, you might get the following
  10576. error when you try to execute it:
  10577.  
  10578.      ld.so.1: ./my: fatal: libmysqlclient.so.#:
  10579.      open failed: No such file or directory
  10580.  
  10581. The problem can be avoided by one of the following methods:
  10582.  
  10583.    * Link the client with the following flag (instead of `-Lpath'):
  10584.      `-Wl,r/full-path-to-libmysqlclient.so'.
  10585.  
  10586.    * Copy `libmysqclient.so' to `/usr/lib'.
  10587.  
  10588.    * Add the pathname of the directory where `libmysqlclient.so' is
  10589.      located to the `LD_RUN_PATH' environment variable before running
  10590.      your client.
  10591.  
  10592. If you have problems with configure trying to link with `-lz' and you
  10593. don't have `zlib' installed, you have two options:
  10594.  
  10595.    * If you want to be able to use the compressed communication
  10596.      protocol, you need to get and install zlib from ftp.gnu.org.
  10597.  
  10598.    * Configure with `--with-named-z-libs=no'.
  10599.  
  10600. If you are using gcc and have problems with loading user defined
  10601. functions (`UDF's) into MySQL, try adding `-lgcc' to the link line for
  10602. the `UDF'.
  10603.  
  10604. If you would like MySQL to start automatically, you can copy
  10605. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  10606. link to it named `/etc/rc3.d/S99mysql.server'.
  10607.  
  10608. As Solaris doesn't support core files for `setuid()' applications, you
  10609. can't get a core file from `mysqld' if you are using the `--user'
  10610. option.
  10611.  
  10612. Solaris 2.7/2.8 Notes
  10613. .....................
  10614.  
  10615. You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  10616. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  10617.  
  10618. Note that MySQL Version 3.23.4 and above should be able to autodetect
  10619. new versions of Solaris and enable workarounds for the following
  10620. problems!
  10621.  
  10622. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  10623. following error when you use `gcc':
  10624.  
  10625.      /usr/include/widec.h:42: warning: `getwc' redefined
  10626.      /usr/include/wchar.h:326: warning: this is the location of the previous
  10627.      definition
  10628.  
  10629. If this occurs, you can do the following to fix the problem:
  10630.  
  10631. Copy `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include'
  10632. and change line 41 from:
  10633.  
  10634.      #if     !defined(lint) && !defined(__lint)
  10635.      
  10636.      to
  10637.      
  10638.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  10639.  
  10640. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  10641. way, after you make the fix, you should remove `config.cache' and run
  10642. `configure' again!
  10643.  
  10644. If you get errors like this when you run `make', it's because
  10645. `configure' didn't detect the `curses.h' file (probably because of the
  10646. error in `/usr/include/widec.h'):
  10647.  
  10648.      In file included from mysql.cc:50:
  10649.      /usr/include/term.h:1060: syntax error before `,'
  10650.      /usr/include/term.h:1081: syntax error before `;'
  10651.  
  10652. The solution to this is to do one of the following:
  10653.  
  10654.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  10655.      ./configure'.
  10656.  
  10657.    * Edit `/usr/include/widec.h' as indicted above and rerun configure.
  10658.  
  10659.    * Remove the `#define HAVE_TERM' line from `config.h' file and run
  10660.      `make' again.
  10661.  
  10662. If you get a problem that your linker can't find `-lz' when linking
  10663. your client program, the problem is probably that your `libz.so' file is
  10664. installed in `/usr/local/lib'.  You can fix this by one of the
  10665. following methods:
  10666.  
  10667.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  10668.  
  10669.    * Add a link to `libz.so' from `/lib'.
  10670.  
  10671.    * If you are using Solaris 8, you can install the optional zlib from
  10672.      your Solaris 8 CD distribution.
  10673.  
  10674.    * Configure MySQL with the `--with-named-z-libs=no' option.
  10675.  
  10676. Solaris x86 Notes
  10677. .................
  10678.  
  10679. On Solaris 2.8 on x86, `mysqld' will dump core if you remove the debug
  10680. symbols using `strip'.
  10681.  
  10682. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  10683. problems with core dumps under load, you should use the following
  10684. `configure' command:
  10685.  
  10686.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  10687.      CXX=gcc \
  10688.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions \
  10689.      -fno-rtti -DHAVE_CURSES_H" \
  10690.      ./configure --prefix=/usr/local/mysql
  10691.  
  10692. This will avoid problems with the `libstdc++' library and with C++
  10693. exceptions.
  10694.  
  10695. If this doesn't help, you should compile a debug version and run it
  10696. with a trace file or under `gdb'.  *Note Using gdb on mysqld::.
  10697.  
  10698. BSD Notes
  10699. ---------
  10700.  
  10701. This section provides information for the various BSD flavours, as well
  10702. as specific versions within those.
  10703.  
  10704. FreeBSD Notes
  10705. .............
  10706.  
  10707. FreeBSD 4.x is recommended for running MySQL since the thread package
  10708. is much more integrated.
  10709.  
  10710. The easiest and therefore the preferred way to install is to use the
  10711. mysql-server and mysql-client ports available on
  10712. `http://www.freebsd.org/'.
  10713.  
  10714. Using these gives you:
  10715.    * A working MySQL with all optimisations known to work on your
  10716.      version of FreeBSD enabled.
  10717.  
  10718.    * Automatic configuration and build.
  10719.  
  10720.    * Startup scripts installed in /usr/local/etc/rc.d.
  10721.  
  10722.    * Ability to see which files that are installed with pkg_info -L.
  10723.      And to remove them all with pkg_delete if you no longer want MySQL
  10724.      on that machine.
  10725.  
  10726. It is recommended you use MIT-pthreads on FreeBSD 2.x and native
  10727. threads on Versions 3 and up. It is possible to run with native threads
  10728. on some late 2.2.x versions but you may encounter problems shutting
  10729. down `mysqld'.
  10730.  
  10731. Unfortunately, certain function calls on FreeBSD are not yet fully
  10732. thread-safe, most notably the `gethostbyname()' function, which is used
  10733. by MySQL to convert host names into IP addresses. Under certain
  10734. circumstances, the `mysqld' process will suddenly cause 100% CPU load
  10735. and will be unresponsive. If you encounter this, try to start up MySQL
  10736. using the `--skip-name-resolve' option.
  10737.  
  10738. Alternatively, you can link MySQL on FreeBSD 4.x against the
  10739. LinuxThreads library, which avoids a few of the problems that the
  10740. native FreeBSD thread implementation has. For a very good comparison of
  10741. LinuxThreads vs. native threads have a look at Jeremy Zawodny's article
  10742. "FreeBSD or Linux for your MySQL Server?" at
  10743. `http://jeremy.zawodny.com/blog/archives/000203.html'.
  10744.  
  10745. The MySQL `Makefile's require GNU make (`gmake') to work.  If you want
  10746. to compile MySQL you need to install GNU `make' first.
  10747.  
  10748. Be sure to have your name resolver setup correct.  Otherwise, you may
  10749. experience resolver delays or failures when connecting to `mysqld'.
  10750.  
  10751. Make sure that the `localhost' entry in the `/etc/hosts' file is
  10752. correct (otherwise, you will have problems connecting to the database).
  10753. The `/etc/hosts' file should start with a line:
  10754.  
  10755.      127.0.0.1       localhost localhost.your.domain
  10756.  
  10757. The recommended way to compile and install MySQL on FreeBSD with gcc
  10758. (2.95.2 and up) is:
  10759.  
  10760.      CC=gcc CFLAGS="-O2 -fno-strength-reduce" \
  10761.      CXX=gcc CXXFLAGS="-O2 -fno-rtti -fno-exceptions -felide-constructors \
  10762.      -fno-strength-reduce" \
  10763.      ./configure --prefix=/usr/local/mysql --enable-assembler
  10764.      gmake
  10765.      gmake install
  10766.      ./scripts/mysql_install_db
  10767.      cd /usr/local/mysql
  10768.      ./bin/mysqld_safe &
  10769.  
  10770. If you notice that `configure' will use MIT-pthreads, you should read
  10771. the MIT-pthreads notes.  *Note MIT-pthreads::.
  10772.  
  10773. If you get an error from `make install' that it can't find
  10774. `/usr/include/pthreads', `configure' didn't detect that you need
  10775. MIT-pthreads.  This is fixed by executing these commands:
  10776.  
  10777.      shell> rm config.cache
  10778.      shell> ./configure --with-mit-threads
  10779.  
  10780. FreeBSD is also known to have a very low default file handle limit.
  10781. *Note Not enough file handles::.  Uncomment the `ulimit -n' section in
  10782. `mysqld_safe' or raise the limits for the `mysqld' user in
  10783. /etc/login.conf (and rebuild it with cap_mkdb /etc/login.conf).  Also
  10784. be sure you set the appropriate class for this user in the password
  10785. file if you are not using the default (use: chpass mysqld-user-name).
  10786. *Note `mysqld_safe': mysqld_safe.
  10787.  
  10788. If you have a lot of memory you should consider rebuilding the kernel
  10789. to allow MySQL to take more than 512M of RAM.  Take a look at `option
  10790. MAXDSIZ' in the LINT config file for more info.
  10791.  
  10792. If you get problems with the current date in MySQL, setting the `TZ'
  10793. variable will probably help.  *Note Environment variables::.
  10794.  
  10795. To get a secure and stable system you should only use FreeBSD kernels
  10796. that are marked `-RELEASE'.
  10797.  
  10798. NetBSD Notes
  10799. ............
  10800.  
  10801. To compile on NetBSD you need GNU `make'. Otherwise, the compile will
  10802. crash when `make' tries to run `lint' on C++ files.
  10803.  
  10804. OpenBSD 2.5 Notes
  10805. .................
  10806.  
  10807. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  10808. the following options:
  10809.  
  10810.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  10811.  
  10812. OpenBSD 2.8 Notes
  10813. .................
  10814.  
  10815. Our users have reported that OpenBSD 2.8 has a threading bug which
  10816. causes problems with MySQL.  The OpenBSD Developers have fixed the
  10817. problem, but as of January 25th, 2001, it's only available in the
  10818. "-current" branch.  The symptoms of this threading bug are: slow
  10819. response, high load, high CPU usage, and crashes.
  10820.  
  10821. If you get an error like `Error in accept:: Bad file descriptor' or
  10822. error 9 when trying to open tables or directories, the problem is
  10823. probably that you haven't allocated enough file descriptors for MySQL.
  10824.  
  10825. In this case, try starting `mysqld_safe' as `root' with the following
  10826. options:
  10827.  
  10828.      shell> mysqld_safe --user=mysql --open-files-limit=2048 &
  10829.  
  10830. BSD/OS Version 2.x Notes
  10831. ........................
  10832.  
  10833. If you get the following error when compiling MySQL, your `ulimit'
  10834. value for virtual memory is too low:
  10835.  
  10836.      item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  10837.      item_func.h:28: virtual memory exhausted
  10838.      make[2]: *** [item_func.o] Error 1
  10839.  
  10840. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  10841. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  10842. users have reported problems with `bash' and `ulimit'.
  10843.  
  10844. If you are using `gcc', you may also use have to use the
  10845. `--with-low-memory' flag for `configure' to be able to compile
  10846. `sql_yacc.cc'.
  10847.  
  10848. If you get problems with the current date in MySQL, setting the `TZ'
  10849. variable will probably help.  *Note Environment variables::.
  10850.  
  10851. BSD/OS Version 3.x Notes
  10852. ........................
  10853.  
  10854. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  10855. BSDIpatch M300-038.
  10856.  
  10857. Use the following command when configuring MySQL:
  10858.  
  10859.      shell> env CXX=shlicc++ CC=shlicc2 \
  10860.             ./configure \
  10861.                 --prefix=/usr/local/mysql \
  10862.                 --localstatedir=/var/mysql \
  10863.                 --without-perl \
  10864.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10865.  
  10866. The following is also known to work:
  10867.  
  10868.      shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  10869.             ./configure \
  10870.                 --prefix=/usr/local/mysql \
  10871.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10872.  
  10873. You can change the directory locations if you wish, or just use the
  10874. defaults by not specifying any locations.
  10875.  
  10876. If you have problems with performance under heavy load, try using the
  10877. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  10878. with the same priority; on BSDI Version 3.1, this gives better
  10879. performance (at least until BSDI fixes their thread scheduler).
  10880.  
  10881. If you get the error `virtual memory exhausted' while compiling, you
  10882. should try using `ulimit -v 80000' and run `make' again.  If this
  10883. doesn't work and you are using `bash', try switching to `csh' or `sh';
  10884. some BSDI users have reported problems with `bash' and `ulimit'.
  10885.  
  10886. BSD/OS Version 4.x Notes
  10887. ........................
  10888.  
  10889. BSDI Version 4.x has some thread-related bugs.  If you want to use
  10890. MySQL on this, you should install all thread-related patches.  At least
  10891. M400-023 should be installed.
  10892.  
  10893. On some BSDI Version 4.x systems, you may get problems with shared
  10894. libraries.  The symptom is that you can't execute any client programs,
  10895. for example, `mysqladmin'.  In this case you need to reconfigure not to
  10896. use shared libraries with the `--disable-shared' option to configure.
  10897.  
  10898. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  10899. after a while can't open tables.  This is because some library/system
  10900. related bug causes `mysqld' to change current directory without asking
  10901. for this!
  10902.  
  10903. The fix is to either upgrade to 3.23.34 or after running `configure'
  10904. remove the line `#define HAVE_REALPATH' from `config.h' before running
  10905. make.
  10906.  
  10907. Note that the above means that you can't symbolic link a database
  10908. directories to another database directory or symbolic link a table to
  10909. another database on BSDI!  (Making a symbolic link to another disk is
  10910. okay).
  10911.  
  10912. Mac OS X Notes
  10913. --------------
  10914.  
  10915. Mac OS X 10.x
  10916. .............
  10917.  
  10918. MySQL should work without any problems on Mac OS X 10.x (Darwin). You
  10919. don't need the pthread patches for this OS!
  10920.  
  10921. This also applies to Mac OS X 10.x Server. Compiling for the Server
  10922. platform is the same as for the client version of Mac OS X. However
  10923. please note that MySQL comes preinstalled on the Server!
  10924.  
  10925. Our binary for Mac OS X is compiled on Darwin 6.3 with the following
  10926. configure line:
  10927.  
  10928.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  10929.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  10930.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  10931.      --with-extra-charsets=complex --enable-thread-safe-client \
  10932.      --enable-local-infile --disable-shared
  10933.  
  10934. *Note Mac OS X installation::.
  10935.  
  10936. Mac OS X Server 1.2 (Rhapsody)
  10937. ..............................
  10938.  
  10939. Before trying to configure MySQL on Mac OS X Server 1.2 (aka Rhapsody)
  10940. you must first install the pthread package from
  10941. `http://www.prnet.de/RegEx/mysql.html'.
  10942.  
  10943. *Note Mac OS X installation::.
  10944.  
  10945. Other Unix Notes
  10946. ----------------
  10947.  
  10948. HP-UX Notes for Binary Distributions
  10949. ....................................
  10950.  
  10951. Some of the binary distributions of MySQL for HP-UX are distributed as
  10952. an HP depot file and as a tar file.  To use the depot file you must be
  10953. running at least HP-UX 10.x to have access to HP's software depot tools.
  10954.  
  10955. The HP version of MySQL was compiled on an HP 9000/8xx server under
  10956. HP-UX 10.20, and uses MIT-pthreads.  It is known to work well under
  10957. this configuration.  MySQL Version 3.22.26 and newer can also be built
  10958. with HP's native thread package.
  10959.  
  10960. Other configurations that may work:
  10961.  
  10962.    * HP 9000/7xx running HP-UX 10.20+
  10963.  
  10964.    * HP 9000/8xx running HP-UX 10.30
  10965.  
  10966. The following configurations almost definitely won't work:
  10967.  
  10968.    * HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
  10969.  
  10970.    * HP 9000/7xx or 8xx running HP-UX 9.x
  10971.  
  10972. To install the distribution, use one of the commands here, where
  10973. `/path/to/depot' is the full pathname of the depot file:
  10974.  
  10975.    * To install everything, including the server, client and
  10976.      development tools:
  10977.  
  10978.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
  10979.  
  10980.    * To install only the server:
  10981.  
  10982.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
  10983.  
  10984.    * To install only the client package:
  10985.  
  10986.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
  10987.  
  10988.    * To install only the development tools:
  10989.  
  10990.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
  10991.  
  10992. The depot places binaries and libraries in `/opt/mysql' and data in
  10993. `/var/opt/mysql'. The depot also creates the appropriate entries in
  10994. `/etc/init.d' and `/etc/rc2.d' to start the server automatically at
  10995. boot time.  Obviously, this entails being `root' to install.
  10996.  
  10997. To install the HP-UX tar.gz distribution, you must have a copy of GNU
  10998. `tar'.
  10999.  
  11000. HP-UX Version 10.20 Notes
  11001. .........................
  11002.  
  11003. There are a couple of small problems when compiling MySQL on HP-UX.  We
  11004. recommend that you use `gcc' instead of the HP-UX native compiler,
  11005. because `gcc' produces better code!
  11006.  
  11007. We recommend using `gcc' 2.95 on HP-UX.  Don't use high optimisation
  11008. flags (like -O6) as this may not be safe on HP-UX.
  11009.  
  11010. The following `configure' line should work with `gcc' 2.95:
  11011.  
  11012.      CFLAGS="-I/opt/dce/include -fpic" \
  11013.      CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
  11014.      -fno-rtti" CXX=gcc ./configure --with-pthread \
  11015.      --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
  11016.  
  11017. The following `configure' line should work with `gcc' 3.1:
  11018.  
  11019.      CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc \
  11020.      CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions \
  11021.      -fno-rtti -O3 -fPIC" ./configure --prefix=/usr/local/mysql \
  11022.      --with-extra-charsets=complex --enable-thread-safe-client \
  11023.      --enable-local-infile  --with-pthread \
  11024.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  11025.      --disable-shared
  11026.  
  11027. HP-UX Version 11.x Notes
  11028. ........................
  11029.  
  11030. For HP-UX Version 11.x, we recommend MySQL Version 3.23.15 or later.
  11031.  
  11032. Because of some critical bugs in the standard HP-UX libraries, you
  11033. should install the following patches before trying to run MySQL on
  11034. HP-UX 11.0:
  11035.  
  11036.      PHKL_22840 Streams cumulative
  11037.      PHNE_22397 ARPA cumulative
  11038.  
  11039. This will solve the problem of getting `EWOULDBLOCK' from `recv()' and
  11040. `EBADF' from `accept()' in threaded applications.
  11041.  
  11042. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  11043. will get the error:
  11044.  
  11045.      In file included from /usr/include/unistd.h:11,
  11046.                       from ../include/global.h:125,
  11047.                       from mysql_priv.h:15,
  11048.                       from item.cc:19:
  11049.      /usr/include/sys/unistd.h:184: declaration of C function ...
  11050.      /usr/include/sys/pthread.h:440: previous declaration ...
  11051.      In file included from item.h:306,
  11052.                       from mysql_priv.h:158,
  11053.                       from item.cc:19:
  11054.  
  11055. The problem is that HP-UX doesn't define `pthreads_atfork()'
  11056. consistently.  It has conflicting prototypes in
  11057. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440
  11058. (details below).
  11059.  
  11060. One solution is to copy `/usr/include/sys/unistd.h' into
  11061. `mysql/include' and edit `unistd.h' and change it to match the
  11062. definition in `pthread.h'.  Here's the diff:
  11063.  
  11064.      183,184c183,184
  11065.      <      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  11066.      <                                                void (*child)());
  11067.      ---
  11068.      >      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  11069.      >                                                void (*child)(void));
  11070.  
  11071. After this, the following configure line should work:
  11072.  
  11073.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc \
  11074.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" \
  11075.      ./configure --prefix=/usr/local/mysql --disable-shared
  11076.  
  11077. If you are using MySQL 4.0.5 with the HP-UX compiler you can use:
  11078. (tested with cc B.11.11.04):
  11079.  
  11080.      CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure --with-extra-character-set=complex
  11081.  
  11082. You can ignore any errors of the following type:
  11083.  
  11084.      aCC: warning 901: unknown option: `-3': use +help for online documentation
  11085.  
  11086. If you get the following error from `configure'
  11087.  
  11088.      checking for cc option to accept ANSI C... no
  11089.      configure: error: MySQL requires a ANSI C compiler (and a C++ compiler).
  11090.      Try gcc. See the Installation chapter in the Reference Manual.
  11091.  
  11092. Check that you don't have the path to the K&R compiler before the path
  11093. to the HP-UX C and C++ compiler.
  11094.  
  11095. Another reason for not beeing able to compile is that you didn't define
  11096. the `+DD64' flags above.
  11097.  
  11098. Another possibility for HP-UX 11 is to use MySQL binaries for HP-UX
  11099. 10.20.  We have received reports from some users that these binaries
  11100. work fine on HP-UX 11.00. If you encounter problems, be sure to check
  11101. your HP-UX patch level.
  11102.  
  11103. IBM-AIX notes
  11104. .............
  11105.  
  11106. Automatic detection of `xlC' is missing from Autoconf, so a `configure'
  11107. command something like this is needed when compiling MySQL (This
  11108. example uses the IBM compiler):
  11109.  
  11110.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  11111.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  11112.      export CFLAGS="-I /usr/local/include"
  11113.      export LDFLAGS="-L /usr/local/lib"
  11114.      export CPPFLAGS=$CFLAGS
  11115.      export CXXFLAGS=$CFLAGS
  11116.      
  11117.      ./configure --prefix=/usr/local \
  11118.                      --localstatedir=/var/mysql \
  11119.                      --sysconfdir=/etc/mysql \
  11120.                      --sbindir='/usr/local/bin' \
  11121.                      --libexecdir='/usr/local/bin' \
  11122.                      --enable-thread-safe-client \
  11123.                      --enable-large-files
  11124.  
  11125. Above are the options used to compile the MySQL distribution that can
  11126. be found at `http://www-frec.bull.com/'.
  11127.  
  11128. If you change the `-O3' to `-O2' in the above configure line, you must
  11129. also remove the `-qstrict' option (this is a limitation in the IBM C
  11130. compiler).
  11131.  
  11132. If you are using `gcc' or `egcs' to compile MySQL, you *must* use the
  11133. `-fno-exceptions' flag, as the exception handling in `gcc'/`egcs' is
  11134. not thread-safe!  (This is tested with `egcs' 1.1.)  There are also
  11135. some known problems with IBM's assembler, which may cause it to
  11136. generate bad code when used with gcc.
  11137.  
  11138. We recommend the following `configure' line with `egcs' and `gcc 2.95'
  11139. on AIX:
  11140.  
  11141.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  11142.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  11143.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  11144.      ./configure --prefix=/usr/local/mysql --with-low-memory
  11145.  
  11146. The `-Wa,-many' is necessary for the compile to be successful.  IBM is
  11147. aware of this problem but is in to hurry to fix it because of the
  11148. workaround available.  We don't know if the `-fno-exceptions' is
  11149. required with `gcc 2.95', but as MySQL doesn't use exceptions and the
  11150. above option generates faster code, we recommend that you should always
  11151. use this option with `egcs / gcc'.
  11152.  
  11153. If you get a problem with assembler code try changing the -mcpu=xxx to
  11154. match your CPU. Typically power2, power, or powerpc may need to be used,
  11155. alternatively you might need to use 604 or 604e. I'm not positive but I
  11156. would think using "power" would likely be safe most of the time, even on
  11157. a power2 machine.
  11158.  
  11159. If you don't know what your CPU is then do a "uname -m", this will give
  11160. you back a string that looks like "000514676700", with a format of
  11161. xxyyyyyymmss where xx and ss are always 0's, yyyyyy is a unique system
  11162. id and mm is the id of the CPU Planar. A chart of these values can be
  11163. found at
  11164. `http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  11165. This will give you a machine type and a machine model you can use to
  11166. determine what type of CPU you have.
  11167.  
  11168. If you have problems with signals (MySQL dies unexpectedly under high
  11169. load) you may have found an OS bug with threads and signals.  In this
  11170. case you can tell MySQL not to use signals by configuring with:
  11171.  
  11172.      shell> CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  11173.             CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
  11174.             -DDONT_USE_THR_ALARM" \
  11175.             ./configure --prefix=/usr/local/mysql --with-debug --with-low-memory
  11176.  
  11177. This doesn't affect the performance of MySQL, but has the side effect
  11178. that you can't kill clients that are "sleeping" on a connection with
  11179. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  11180. die when it issues its next command.
  11181.  
  11182. On some versions of AIX, linking with `libbind.a' makes `getservbyname'
  11183. core dump.  This is an AIX bug and should be reported to IBM.
  11184.  
  11185. For AIX 4.2.1 and gcc you have to do the following changes.
  11186.  
  11187. After configuring, edit `config.h' and `include/my_config.h' and change
  11188. the line that says
  11189.  
  11190.      #define HAVE_SNPRINTF 1
  11191.  
  11192. to
  11193.  
  11194.      #undef HAVE_SNPRINTF
  11195.  
  11196. And finally, in `mysqld.cc' you need to add a prototype for initgoups.
  11197.  
  11198.      #ifdef _AIX41
  11199.      extern "C" int initgroups(const char *,int);
  11200.      #endif
  11201.  
  11202. If you need to allocate a lot of memory to the mysqld process, it's not
  11203. enough to just set 'ulimit -d unlimited'. You may also have to set in
  11204. `mysqld_safe' something like:
  11205.  
  11206.      export LDR_CNTRL='MAXDATA=0x80000000'
  11207.  
  11208. You can find more about using a lot of memory at:
  11209. `http://publib16.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/lrg_prg_support.htm'.
  11210.  
  11211. SunOS 4 Notes
  11212. .............
  11213.  
  11214. On SunOS 4, MIT-pthreads is needed to compile MySQL, which in turn
  11215. means you will need GNU `make'.
  11216.  
  11217. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  11218. You can use the following `configure' line to avoid this problem:
  11219.  
  11220.      shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
  11221.  
  11222. When compiling `readline', you may get warnings about duplicate defines.
  11223. These may be ignored.
  11224.  
  11225. When compiling `mysqld', there will be some `implicit declaration of
  11226. function' warnings. These may be ignored.
  11227.  
  11228. Alpha-DEC-UNIX Notes (Tru64)
  11229. ............................
  11230.  
  11231. If you are using egcs 1.1.2 on Digital Unix, you should upgrade to gcc
  11232. 2.95.2, as egcs on DEC has some serious bugs!
  11233.  
  11234. When compiling threaded programs under Digital Unix, the documentation
  11235. recommends using the `-pthread' option for `cc' and `cxx' and the
  11236. libraries `-lmach -lexc' (in addition to `-lpthread').  You should run
  11237. `configure' something like this:
  11238.  
  11239.      CC="cc -pthread" CXX="cxx -pthread -O" \
  11240.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  11241.  
  11242. When compiling `mysqld', you may see a couple of warnings like this:
  11243.  
  11244.      mysqld.cc: In function void handle_connections()':
  11245.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  11246.      accept(int,sockadddr *, int *)'
  11247.  
  11248. You can safely ignore these warnings.  They occur because `configure'
  11249. can detect only errors, not warnings.
  11250.  
  11251. If you start the server directly from the command-line, you may have
  11252. problems with it dying when you log out.  (When you log out, your
  11253. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  11254. the server like this:
  11255.  
  11256.      shell> nohup mysqld [options] &
  11257.  
  11258. `nohup' causes the command following it to ignore any `SIGHUP' signal
  11259. sent from the terminal.  Alternatively, start the server by running
  11260. `mysqld_safe', which invokes `mysqld' using `nohup' for you.  *Note
  11261. `mysqld_safe': mysqld_safe.
  11262.  
  11263. If you get a problem when compiling mysys/get_opt.c, just remove the
  11264. line #define _NO_PROTO from the start of that file!
  11265.  
  11266. If you are using Compaq's CC compiler, the following configure line
  11267. should work:
  11268.  
  11269.      CC="cc -pthread"
  11270.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  11271.      CXX="cxx -pthread"
  11272.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host \
  11273.      -noexceptions -nortti"
  11274.      export CC CFLAGS CXX CXXFLAGS
  11275.      ./configure \
  11276.      --prefix=/usr/local/mysql \
  11277.      --with-low-memory \
  11278.      --enable-large-files \
  11279.      --enable-shared=yes \
  11280.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  11281.      gnumake
  11282.  
  11283. If you get a problem with libtool, when compiling with shared libraries
  11284. as above, when linking `mysql', you should be able to get around this
  11285. by issuing:
  11286.  
  11287.      cd mysql
  11288.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  11289.      -O4 -ansi_alias -ansi_args -fast -inline speed \
  11290.      -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  11291.      -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  11292.      ../readline/libreadline.a -lcurses \
  11293.      ../libmysql/.libs/libmysqlclient.so  -lm
  11294.      cd ..
  11295.      gnumake
  11296.      gnumake install
  11297.      scripts/mysql_install_db
  11298.  
  11299. Alpha-DEC-OSF/1 Notes
  11300. .....................
  11301.  
  11302. If you have problems compiling and have DEC `CC' and `gcc' installed,
  11303. try running `configure' like this:
  11304.  
  11305.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  11306.      ./configure --prefix=/usr/local/mysql
  11307.  
  11308. If you get problems with the `c_asm.h' file, you can create and use a
  11309. 'dummy' `c_asm.h' file with:
  11310.  
  11311.      touch include/c_asm.h
  11312.      CC=gcc CFLAGS=-I./include \
  11313.      CXX=gcc CXXFLAGS=-O3 \
  11314.      ./configure --prefix=/usr/local/mysql
  11315.  
  11316. Note that the following problems with the `ld' program can be fixed by
  11317. downloading the latest DEC (Compaq) patch kit from:
  11318. `http://ftp.support.compaq.com/public/unix/'.
  11319.  
  11320. On OSF/1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  11321. 878)" the compiler had some strange behaviour (undefined `asm' symbols).
  11322. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  11323. errors occurring while linking `mysqld').  On this system, we have
  11324. managed to compile MySQL with the following `configure' line, after
  11325. replacing `/bin/ld' with the version from OSF 4.0C:
  11326.  
  11327.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  11328.  
  11329. With the Digital compiler "C++ V6.1-029", the following should work:
  11330.  
  11331.      CC=cc -pthread
  11332.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  11333.             -arch host
  11334.      CXX=cxx -pthread
  11335.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  11336.                -arch host -noexceptions -nortti
  11337.      export CC CFLAGS CXX CXXFLAGS
  11338.      ./configure --prefix=/usr/mysql/mysql --with-mysqld-ldflags=-all-static \
  11339.                  --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
  11340.  
  11341. In some versions of OSF/1, the `alloca()' function is broken. Fix this
  11342. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  11343.  
  11344. The `alloca()' function also may have an incorrect prototype in
  11345. `/usr/include/alloca.h'.  This warning resulting from this can be
  11346. ignored.
  11347.  
  11348. `configure' will use the following thread libraries automatically:
  11349. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  11350.  
  11351. When using `gcc', you can also try running `configure' like this:
  11352.  
  11353.      shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ...
  11354.  
  11355. If you have problems with signals (MySQL dies unexpectedly under high
  11356. load), you may have found an OS bug with threads and signals. In this
  11357. case you can tell MySQL not to use signals by configuring with:
  11358.  
  11359.      shell> CFLAGS=-DDONT_USE_THR_ALARM \
  11360.             CXXFLAGS=-DDONT_USE_THR_ALARM \
  11361.             ./configure ...
  11362.  
  11363. This doesn't affect the performance of MySQL, but has the side effect
  11364. that you can't kill clients that are "sleeping" on a connection with
  11365. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  11366. die when it issues its next command.
  11367.  
  11368. With `gcc' 2.95.2, you will probably run into the following compile
  11369. error:
  11370.  
  11371.      sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
  11372.      Please submit a full bug report.
  11373.  
  11374. To fix this you should change to the `sql' directory and do a "cut and
  11375. paste" of the last `gcc' line, but change `-O3' to `-O0' (or add `-O0'
  11376. immediately after `gcc' if you don't have any `-O' option on your
  11377. compile line).  After this is done you can just change back to the
  11378. top-level directly and run `make' again.
  11379.  
  11380. SGI Irix Notes
  11381. ..............
  11382.  
  11383. If you are using Irix Version 6.5.3 or newer `mysqld' will only be able
  11384. to create threads if you run it as a user with `CAP_SCHED_MGT'
  11385. privileges (like `root') or give the `mysqld' server this privilege
  11386. with the following shell command:
  11387.  
  11388.      shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  11389.  
  11390. You may have to undefine some things in `config.h' after running
  11391. `configure' and before compiling.
  11392.  
  11393. In some Irix implementations, the `alloca()' function is broken.  If the
  11394. `mysqld' server dies on some `SELECT' statements, remove the lines from
  11395. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  11396. `mysqladmin create' doesn't work, remove the line from `config.h' that
  11397. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  11398. line as well.
  11399.  
  11400. SGI recommends that you install all of the patches on this page as a
  11401. set:
  11402. `http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html'
  11403.  
  11404. At the very minimum, you should install the latest kernel rollup, the
  11405. latest `rld' rollup, and the latest `libc' rollup.
  11406.  
  11407. You definitely need all the POSIX patches on this page, for pthreads
  11408. support:
  11409.  
  11410. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  11411.  
  11412. If you get the something like the following error when compiling
  11413. `mysql.cc':
  11414.  
  11415.      "/usr/include/curses.h", line 82: error(1084): invalid combination of type
  11416.  
  11417. Type the following in the top-level directory of your MySQL source tree:
  11418.  
  11419.      shell> extra/replace bool curses_bool < /usr/include/curses.h \
  11420.      > include/curses.h
  11421.      shell> make
  11422.  
  11423. There have also been reports of scheduling problems.  If only one
  11424. thread is running, things go slow.  Avoid this by starting another
  11425. client.  This may lead to a 2-to-10-fold increase in execution speed
  11426. thereafter for the other thread.  This is a poorly understood problem
  11427. with Irix threads; you may have to improvise to find solutions until
  11428. this can be fixed.
  11429.  
  11430. If you are compiling with `gcc', you can use the following `configure'
  11431. command:
  11432.  
  11433.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  11434.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
  11435.      --with-named-thread-libs=-lpthread
  11436.  
  11437. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  11438. following is reported to work
  11439.  
  11440.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  11441.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  11442.      -I/usr/local/include -L/usr/local/lib' ./configure \
  11443.      --prefix=/usr/local/mysql --with-innodb --with-berkeley-db \
  11444.      --with-libwrap=/usr/local \
  11445.      --with-named-curses-libs=/usr/local/lib/libncurses.a
  11446.  
  11447. SCO Notes
  11448. .........
  11449.  
  11450. The current port is tested only on "sco3.2v5.0.5", "sco3.2v5.0.6" and
  11451. "sco3.2v5.0.7" systems.  There has also been a lot of progress on a
  11452. port to "sco 3.2v4.2".
  11453.  
  11454. For the moment the recommended compiler on OpenServer is gcc 2.95.2.
  11455. With this you should be able to compile MySQL with just:
  11456.  
  11457.      CC=gcc CXX=gcc ./configure ... (options)
  11458.  
  11459.   1. For OpenServer 5.0.x you need to use gcc-2.95.2p1 or newer from the
  11460.      Skunkware.  `http://www.sco.com/skunkware/' and choose browser
  11461.      OpenServer packages or by ftp to ftp2.caldera.com in the
  11462.      pub/skunkware/osr5/devtools/gcc directory.
  11463.  
  11464.   2. You need the port of GCC 2.5.x for this product and the Development
  11465.      system.  They are required on this version of SCO Unix.  You cannot
  11466.      just use the GCC Dev system.
  11467.  
  11468.   3. You should get the FSU Pthreads package and install it first.
  11469.      This can be found at
  11470.      `http://moss.csc.ncsu.edu/~mueller/ftp/pub/PART/pthreads.tar.gz'.
  11471.      You can also get a precompiled package from
  11472.      `http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz'.
  11473.  
  11474.   4. FSU Pthreads can be compiled with SCO Unix 4.2 with tcpip.  Or
  11475.      OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0), with the SCO
  11476.      Development System installed using a good port of GCC 2.5.x ODT or
  11477.      OS 3.0 you will need a good port of GCC 2.5.x There are a lot of
  11478.      problems without a good port.  The port for this product requires
  11479.      the SCO Unix Development system.  Without it, you are missing the
  11480.      libraries and the linker that is needed.
  11481.  
  11482.   5. To build FSU Pthreads on your system, do the following:
  11483.  
  11484.        1. Run `./configure' in the `threads/src' directory and select
  11485.           the SCO OpenServer option. This command copies
  11486.           `Makefile.SCO5' to `Makefile'.
  11487.  
  11488.        2. Run `make'.
  11489.  
  11490.        3. To install in the default `/usr/include' directory, login as
  11491.           root, then `cd' to the `thread/src' directory, and run `make
  11492.           install'.
  11493.  
  11494.   6. Remember to use GNU `make' when making MySQL.
  11495.  
  11496.   7. If you don't start `mysqld_safe' as `root', you probably will get
  11497.      only the default 110 open files per process.  `mysqld' will write
  11498.      a note about this in the log file.
  11499.  
  11500.   8. With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or
  11501.      newer.  You should also use gcc 2.95.2 or newer!
  11502.  
  11503.      The following `configure' command should work:
  11504.  
  11505.           shell> ./configure --prefix=/usr/local/mysql --disable-shared
  11506.  
  11507.   9. With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or
  11508.      newer.  The following `configure' command should work:
  11509.  
  11510.           shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  11511.                  ./configure \
  11512.                      --prefix=/usr/local/mysql \
  11513.                      --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  11514.                      --with-named-curses-libs="-lcurses"
  11515.  
  11516.      You may get some problems with some include files. In this case,
  11517.      you can find new SCO-specific include files at
  11518.      `http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz'.
  11519.      You should unpack this file in the `include' directory of your
  11520.      MySQL source tree.
  11521.  
  11522. SCO development notes:
  11523.  
  11524.    * MySQL should automatically detect FSU Pthreads and link `mysqld'
  11525.      with `-lgthreads -lsocket -lgthreads'.
  11526.  
  11527.    * The SCO development libraries are re-entrant in FSU Pthreads.  SCO
  11528.      claim's that its libraries' functions are re-entrant, so they must
  11529.      be reentrant with FSU Pthreads.  FSU Pthreads on OpenServer tries
  11530.      to use the SCO scheme to make re-entrant libraries.
  11531.  
  11532.    * FSU Pthreads (at least the version at `http://www.mysql.com/')
  11533.      comes linked with GNU `malloc'.  If you encounter problems with
  11534.      memory usage, make sure that `gmalloc.o' is included in
  11535.      `libgthreads.a' and `libgthreads.so'.
  11536.  
  11537.    * In FSU Pthreads, the following system calls are pthreads-aware:
  11538.      `read()', `write()', `getmsg()', `connect()', `accept()',
  11539.      `select()', and `wait()'.
  11540.  
  11541.    * The CSSA-2001-SCO.35.2 (the patch is listed in custom as
  11542.      erg711905-dscr_remap security patch (version 2.0.0) breaks FSU
  11543.      threads and makes mysqld unstable.  You have to remove this one if
  11544.      you want to run mysqld on an OpenServer 5.0.6 machine.
  11545.  
  11546.    * SCO provides Operating Systems Patches at
  11547.      `ftp://ftp.sco.com/pub/openserver5' for OpenServer 5.0.x
  11548.  
  11549.    * SCO provides secruity fixes and libsocket.so.2 at
  11550.      `ftp://ftp.sco.com/pub/security/OpenServer' and
  11551.      `ftp://ftp.sco.com/pub/security/sse' for OpenServer 5.0.x
  11552.  
  11553.    * pre-OSR506 security fixes. Also, the telnetd fix at
  11554.      `ftp://stage.caldera.com/pub/security/openserver/' or
  11555.      `ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/'
  11556.      as both libsocket.so.2 and libresolv.so.1 with instructions for
  11557.      installing on pre-OSR506 systems.
  11558.  
  11559.      It's probably a good idea to install the above patches before
  11560.      trying to compile/use MySQL.
  11561.  
  11562. If you want to install DBI on SCO, you have to edit the `Makefile' in
  11563. DBI-xxx and each subdirectory.
  11564.  
  11565. Note that the following assumes gcc 2.95.2 or newer:
  11566.  
  11567.      OLD:                                  NEW:
  11568.      CC = cc                               CC = gcc
  11569.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  11570.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  11571.      
  11572.      LD = ld                               LD = gcc -G -fpic
  11573.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  11574.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  11575.      
  11576.      LD = ld                               LD = gcc -G -fpic
  11577.      OPTIMISE = -Od                        OPTIMISE = -O1
  11578.      
  11579.      OLD:
  11580.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  11581.      
  11582.      NEW:
  11583.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  11584.  
  11585. This is because the Perl dynaloader will not load the `DBI' modules if
  11586. they were compiled with `icc' or `cc'.
  11587.  
  11588. Perl works best when compiled with `cc'.
  11589.  
  11590. SCO UnixWare Version 7.1.x Notes
  11591. ................................
  11592.  
  11593. You must use a version of MySQL at least as recent as Version 3.22.13
  11594. and of UnixWare 7.1.0 because these version fixes some portability and
  11595. OS problems under UnixWare.
  11596.  
  11597. We have been able to compile MySQL with the following `configure'
  11598. command on UnixWare Version 7.1.x:
  11599.  
  11600.      CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
  11601.  
  11602. If you want to use `gcc', you must use `gcc' 2.95.2 or newer.
  11603.  
  11604.      CC=gcc CXX=g++ ./configure --prefix=/usr/local/mysql
  11605.  
  11606.   1. SCO provides Operating Systems Patches at
  11607.      `ftp://ftp.sco.com/pub/unixware7' for UnixWare 7.1.1 and 7.1.3
  11608.      `ftp://ftp.sco.com/pub/openunix8' for OpenUNIX 8.0.0
  11609.  
  11610.   2. SCO provides information about Security Fixes at
  11611.      `ftp://ftp.sco.com/pub/security/OpenUNIX' for OpenUNIX
  11612.      `ftp://ftp.sco.com/pub/security/UnixWare' for UnixWare
  11613.  
  11614. OS/2 Notes
  11615. ----------
  11616.  
  11617. MySQL uses quite a few open files. Because of this, you should add
  11618. something like the following to your `CONFIG.SYS' file:
  11619.  
  11620.      SET EMXOPT=-c -n -h1024
  11621.  
  11622. If you don't do this, you will probably run into the following error:
  11623.  
  11624.      File 'xxxx' not found (Errcode: 24)
  11625.  
  11626. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  11627. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  11628. of the Pthreads library.  MySQL must be installed in a partition that
  11629. supports long filenames such as HPFS, FAT32, etc.
  11630.  
  11631. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  11632. not work with replacement shells such as `4OS2.EXE'.
  11633.  
  11634. The `scripts/mysql-install-db' script has been renamed.  It is now
  11635. called `install.cmd' and is a REXX script, which will set up the default
  11636. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  11637.  
  11638. Dynamic module support is compiled in but not fully tested. Dynamic
  11639. modules should be compiled using the Pthreads run-time library.
  11640.  
  11641.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  11642.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  11643.      mv example.dll example.udf
  11644.  
  11645. *Note*: Due to limitations in OS/2, UDF module name stems must not
  11646. exceed 8 characters. Modules are stored in the `/mysql2/udf' directory;
  11647. the `safe-mysqld.cmd' script will put this directory in the
  11648. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  11649. extensions are ignored--it is assumed to be `.udf'.  For example, in
  11650. Unix, the shared module might be named `example.so' and you would load
  11651. a function from it like this:
  11652.  
  11653.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
  11654.  
  11655. In OS/2, the module would be named `example.udf', but you would not
  11656. specify the module extension:
  11657.  
  11658.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
  11659.  
  11660. Novell NetWare Notes
  11661. --------------------
  11662.  
  11663. Porting `MySQL' to `NetWare' was an effort spearheaded by `Novell'.
  11664. Novell customers will be pleased to note that NetWare 6.5 will ship
  11665. with bundled MySQL binaries, complete with an automatic commercial use
  11666. license for all servers running that version of NetWare.
  11667.  
  11668. *Note NetWare installation::.
  11669.  
  11670. MySQL for NetWare is compiled using a combination of `Metrowerks
  11671. Codewarrior for NetWare' and special cross-compilation versions of the
  11672. GNU autotools. Check back here in the future for more information on
  11673. building and optimising MySQL for NetWare.
  11674.  
  11675. BeOS Notes
  11676. ----------
  11677.  
  11678. We are really interested in getting MySQL to work on BeOS, but
  11679. unfortunately we don't have any person who knows BeOS or has time to do
  11680. a port.
  11681.  
  11682. We are interested in finding someone to do a port, and we will help them
  11683. with any technical questions they may have while doing the port.
  11684.  
  11685. We have previously talked with some BeOS developers that have said that
  11686. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  11687.  
  11688. Perl Installation Comments
  11689. ==========================
  11690.  
  11691. Installing Perl on Unix
  11692. -----------------------
  11693.  
  11694. Perl support for MySQL is provided by means of the `DBI'/`DBD' client
  11695. interface.  *Note Perl::.  The Perl `DBD'/`DBI' client code requires
  11696. Perl Version 5.004 or later.  The interface *will not work* if you have
  11697. an older version of Perl.
  11698.  
  11699. MySQL Perl support also requires that you've installed MySQL client
  11700. programming support.  If you installed MySQL from RPM files, client
  11701. programs are in the client RPM, but client programming support is in
  11702. the developer RPM.  Make sure you've installed the latter RPM.
  11703.  
  11704. As of Version 3.22.8, Perl support is distributed separately from the
  11705. main MySQL distribution.  If you want to install Perl support, the files
  11706. you will need can be obtained from
  11707. `http://www.mysql.com/downloads/api-dbi.html'.
  11708.  
  11709. The Perl distributions are provided as compressed `tar' archives and
  11710. have names like `MODULE-VERSION.tar.gz', where `MODULE' is the module
  11711. name and `VERSION' is the version number.  You should get the
  11712. `Data-Dumper', `DBI', and `DBD-mysql' distributions and install them in
  11713. that order.  The installation procedure is shown here.  The example
  11714. shown is for the `Data-Dumper' module, but the procedure is the same
  11715. for all three distributions:
  11716.  
  11717.   1. Unpack the distribution into the current directory:
  11718.           shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf -
  11719.      This command creates a directory named `Data-Dumper-VERSION'.
  11720.  
  11721.   2. Change into the top-level directory of the unpacked distribution:
  11722.           shell> cd Data-Dumper-VERSION
  11723.  
  11724.   3. Build the distribution and compile everything:
  11725.           shell> perl Makefile.PL
  11726.           shell> make
  11727.           shell> make test
  11728.           shell> make install
  11729.  
  11730. The `make test' command is important because it verifies that the
  11731. module is working.  Note that when you run that command during the
  11732. `DBD-mysql' installation to exercise the interface code, the MySQL
  11733. server must be running or the test will fail.
  11734.  
  11735. It is a good idea to rebuild and reinstall the `DBD-mysql' distribution
  11736. whenever you install a new release of MySQL, particularly if you notice
  11737. symptoms such as all your `DBI' scripts dumping core after you upgrade
  11738. MySQL.
  11739.  
  11740. If you don't have the right to install Perl modules in the system
  11741. directory or if you to install local Perl modules, the following
  11742. reference may help you:
  11743.  
  11744.      `http://www.iserver.com/support/contrib/perl5/modules.html'
  11745.  
  11746. Look under the heading `Installing New Modules that Require Locally
  11747. Installed Modules'.
  11748.  
  11749. Installing ActiveState Perl on Windows
  11750. --------------------------------------
  11751.  
  11752. To install the MySQL `DBD' module with ActiveState Perl on Windows, you
  11753. should do the following:
  11754.  
  11755.    * Get ActiveState Perl from
  11756.      `http://www.activestate.com/Products/ActivePerl/' and install it.
  11757.  
  11758.    * Open a DOS shell.
  11759.  
  11760.    * If required, set the HTTP_proxy variable. For example, you might
  11761.      try:
  11762.  
  11763.           set HTTP_proxy=my.proxy.com:3128
  11764.  
  11765.    * Start the PPM program:
  11766.  
  11767.           C:\> c:\perl\bin\ppm.pl
  11768.  
  11769.    * If you have not already done so, install `DBI':
  11770.  
  11771.           ppm> install DBI
  11772.  
  11773.    * If this succeeds, run the following command:
  11774.  
  11775.           install \
  11776.           ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
  11777.  
  11778. The above should work at least with ActiveState Perl Version 5.6.
  11779.  
  11780. If you can't get the above to work, you should instead install the
  11781. `MyODBC' driver and connect to MySQL server through ODBC:
  11782.  
  11783.      use DBI;
  11784.      $dbh= DBI->connect("DBI:ODBC:$dsn","$user","$password") ||
  11785.        die "Got error $DBI::errstr when connecting to $dsn\n";
  11786.  
  11787. Installing the MySQL Perl Distribution on Windows
  11788. -------------------------------------------------
  11789.  
  11790. The MySQL Perl distribution contains `DBI', `DBD:MySQL' and `DBD:ODBC'.
  11791.  
  11792.    * Get the Perl distribution for Windows from
  11793.      `http://www.mysql.com/downloads/os-win32.html'.
  11794.  
  11795.    * Unzip the distribution in `C:' so that you get a `C:\PERL'
  11796.      directory.
  11797.  
  11798.    * Add the directory `C:\PERL\BIN' to your path.
  11799.  
  11800.    * Add the directory `C:\PERL\BIN\MSWIN32-x86-thread' or
  11801.      `C:\PERL\BIN\MSWIN32-x86' to your path.
  11802.  
  11803.    * Test that `perl' works by executing `perl -v' in a DOS shell.
  11804.  
  11805. Problems Using the Perl `DBI'/`DBD' Interface
  11806. ---------------------------------------------
  11807.  
  11808. If Perl reports that it can't find the `../mysql/mysql.so' module, then
  11809. the problem is probably that Perl can't locate the shared library
  11810. `libmysqlclient.so'.
  11811.  
  11812. You can fix this by any of the following methods:
  11813.  
  11814.    * Compile the `DBD-mysql' distribution with `perl Makefile.PL
  11815.      -static -config' rather than `perl Makefile.PL'.
  11816.  
  11817.    * Copy `libmysqlclient.so' to the directory where your other shared
  11818.      libraries are located (probably `/usr/lib' or `/lib').
  11819.  
  11820.    * On Linux you can add the pathname of the directory where
  11821.      `libmysqlclient.so' is located to the `/etc/ld.so.conf' file.
  11822.  
  11823.    * Add the pathname of the directory where `libmysqlclient.so' is
  11824.      located to the `LD_RUN_PATH' environment variable.
  11825.  
  11826. If you get the following errors from `DBD-mysql', you are probably
  11827. using `gcc' (or using an old binary compiled with `gcc'):
  11828.  
  11829.      /usr/bin/perl: can't resolve symbol '__moddi3'
  11830.      /usr/bin/perl: can't resolve symbol '__divdi3'
  11831.  
  11832. Add `-L/usr/lib/gcc-lib/... -lgcc' to the link command when the
  11833. `mysql.so' library gets built (check the output from `make' for
  11834. `mysql.so' when you compile the Perl client).  The `-L' option should
  11835. specify the pathname of the directory where `libgcc.a' is located on
  11836. your system.
  11837.  
  11838. Another cause of this problem may be that Perl and MySQL aren't both
  11839. compiled with `gcc'.  In this case, you can solve the mismatch by
  11840. compiling both with `gcc'.
  11841.  
  11842. If you get the following error from `DBD-mysql' when you run the tests:
  11843.  
  11844.      t/00base............install_driver(mysql) failed:
  11845.      Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
  11846.      ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
  11847.      uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
  11848.  
  11849. it means that you need to include the compression library, -lz, to the
  11850. link line. This can be doing the following change in the file
  11851. `lib/DBD/mysql/Install.pm':
  11852.  
  11853.      $sysliblist .= " -lm";
  11854.      
  11855.      to
  11856.      
  11857.      $sysliblist .= " -lm -lz";
  11858.  
  11859. After this, you *must* run 'make realclean' and then proceed with the
  11860. installation from the beginning.
  11861.  
  11862. If you want to use the Perl module on a system that doesn't support
  11863. dynamic linking (like SCO) you can generate a static version of Perl
  11864. that includes `DBI' and `DBD-mysql'.  The way this works is that you
  11865. generate a version of Perl with the `DBI' code linked in and install it
  11866. on top of your current Perl.  Then you use that to build a version of
  11867. Perl that additionally has the `DBD' code linked in, and install that.
  11868.  
  11869. On SCO, you must have the following environment variables set:
  11870.  
  11871.      shell> LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
  11872.      or
  11873.      shell> LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11874.      /usr/progressive/lib:/usr/skunk/lib
  11875.      shell> LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11876.      /usr/progressive/lib:/usr/skunk/lib
  11877.      shell> MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
  11878.      /usr/skunk/man:
  11879.  
  11880. First, create a Perl that includes a statically linked `DBI' by running
  11881. these commands in the directory where your `DBI' distribution is
  11882. located:
  11883.  
  11884.      shell> perl Makefile.PL -static -config
  11885.      shell> make
  11886.      shell> make install
  11887.      shell> make perl
  11888.  
  11889. Then you must install the new Perl. The output of `make perl' will
  11890. indicate the exact `make' command you will need to execute to perform
  11891. the installation.  On SCO, this is `make -f Makefile.aperl inst_perl
  11892. MAP_TARGET=perl'.
  11893.  
  11894. Next, use the just-created Perl to create another Perl that also
  11895. includes a statically-linked `DBD::mysql' by running these commands in
  11896. the directory where your `DBD-mysql' distribution is located:
  11897.  
  11898.      shell> perl Makefile.PL -static -config
  11899.      shell> make
  11900.      shell> make install
  11901.      shell> make perl
  11902.  
  11903. Finally, you should install this new Perl.  Again, the output of `make
  11904. perl' indicates the command to use.
  11905.  
  11906. Tutorial Introduction
  11907. *********************
  11908.  
  11909. This chapter provides a tutorial introduction to MySQL by showing how
  11910. to use the `mysql' client program to create and use a simple database.
  11911. `mysql' (sometimes referred to as the "terminal monitor" or just
  11912. "monitor") is an interactive program that allows you to connect to a
  11913. MySQL server, run queries, and view the results.  `mysql' may also be
  11914. used in batch mode: you place your queries in a file beforehand, then
  11915. tell `mysql' to execute the contents of the file.  Both ways of using
  11916. `mysql' are covered here.
  11917.  
  11918. To see a list of options provided by `mysql', invoke it with the
  11919. `--help' option:
  11920.  
  11921.      shell> mysql --help
  11922.  
  11923. This chapter assumes that `mysql' is installed on your machine and that
  11924. a MySQL server is available to which you can connect.  If this is not
  11925. true, contact your MySQL administrator.  (If *you* are the
  11926. administrator, you will need to consult other sections of this manual.)
  11927.  
  11928. This chapter describes the entire process of setting up and using a
  11929. database.  If you are interested only in accessing an already-existing
  11930. database, you may want to skip over the sections that describe how to
  11931. create the database and the tables it contains.
  11932.  
  11933. Because this chapter is tutorial in nature, many details are
  11934. necessarily left out.  Consult the relevant sections of the manual for
  11935. more information on the topics covered here.
  11936.  
  11937. Connecting to and Disconnecting from the Server
  11938. ===============================================
  11939.  
  11940. To connect to the server, you'll usually need to provide a MySQL user
  11941. name when you invoke `mysql' and, most likely, a password.  If the
  11942. server runs on a machine other than the one where you log in, you'll
  11943. also need to specify a hostname.  Contact your administrator to find
  11944. out what connection parameters you should use to connect (that is, what
  11945. host, user name, and password to use).  Once you know the proper
  11946. parameters, you should be able to connect like this:
  11947.  
  11948.      shell> mysql -h host -u user -p
  11949.      Enter password: ********
  11950.  
  11951. The `********' represents your password; enter it when `mysql' displays
  11952. the `Enter password:' prompt.
  11953.  
  11954. If that works, you should see some introductory information followed by
  11955. a `mysql>' prompt:
  11956.  
  11957.      shell> mysql -h host -u user -p
  11958.      Enter password: ********
  11959.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  11960.      Your MySQL connection id is 459 to server version: 3.22.20a-log
  11961.      
  11962.      Type 'help' for help.
  11963.      
  11964.      mysql>
  11965.  
  11966. The prompt tells you that `mysql' is ready for you to enter commands.
  11967.  
  11968. Some MySQL installations allow users to connect as the anonymous
  11969. (unnamed) user to the server running on the local host.  If this is the
  11970. case on your machine, you should be able to connect to that server by
  11971. invoking `mysql' without any options:
  11972.  
  11973.      shell> mysql
  11974.  
  11975. After you have connected successfully, you can disconnect any time by
  11976. typing `QUIT' at the `mysql>' prompt:
  11977.  
  11978.      mysql> QUIT
  11979.      Bye
  11980.  
  11981. You can also disconnect by pressing Control-D.
  11982.  
  11983. Most examples in the following sections assume you are connected to the
  11984. server.  They indicate this by the `mysql>' prompt.
  11985.  
  11986. Entering Queries
  11987. ================
  11988.  
  11989. Make sure you are connected to the server, as discussed in the previous
  11990. section.  Doing so will not in itself select any database to work with,
  11991. but that's okay.  At this point, it's more important to find out a
  11992. little about how to issue queries than to jump right in creating
  11993. tables, loading data into them, and retrieving data from them.  This
  11994. section describes the basic principles of entering commands, using
  11995. several queries you can try out to familiarise yourself with how
  11996. `mysql' works.
  11997.  
  11998. Here's a simple command that asks the server to tell you its version
  11999. number and the current date.  Type it in as shown here following the
  12000. `mysql>' prompt and press Enter:
  12001.  
  12002.      mysql> SELECT VERSION(), CURRENT_DATE;
  12003.      +--------------+--------------+
  12004.      | VERSION()    | CURRENT_DATE |
  12005.      +--------------+--------------+
  12006.      | 3.22.20a-log | 1999-03-19   |
  12007.      +--------------+--------------+
  12008.      1 row in set (0.01 sec)
  12009.      mysql>
  12010.  
  12011. This query illustrates several things about `mysql':
  12012.  
  12013.    * A command normally consists of an SQL statement followed by a
  12014.      semicolon.  (There are some exceptions where a semicolon is not
  12015.      needed.  `QUIT', mentioned earlier, is one of them.  We'll get to
  12016.      others later.)
  12017.  
  12018.    * When you issue a command, `mysql' sends it to the server for
  12019.      execution and displays the results, then prints another `mysql>'
  12020.      to indicate that it is ready for another command.
  12021.  
  12022.    * `mysql' displays query output as a table (rows and columns).  The
  12023.      first row contains labels for the columns.  The rows following are
  12024.      the query results.  Normally, column labels are the names of the
  12025.      columns you fetch from database tables.  If you're retrieving the
  12026.      value of an expression rather than a table column (as in the
  12027.      example just shown), `mysql' labels the column using the
  12028.      expression itself.
  12029.  
  12030.    * `mysql' shows how many rows were returned and how long the query
  12031.      took to execute, which gives you a rough idea of server
  12032.      performance.  These values are imprecise because they represent
  12033.      wall clock time (not CPU or machine time), and because they are
  12034.      affected by factors such as server load and network latency.  (For
  12035.      brevity, the "rows in set" line is not shown in the remaining
  12036.      examples in this chapter.)
  12037.  
  12038. Keywords may be entered in any lettercase.  The following queries are
  12039. equivalent:
  12040.  
  12041.      mysql> SELECT VERSION(), CURRENT_DATE;
  12042.      mysql> select version(), current_date;
  12043.      mysql> SeLeCt vErSiOn(), current_DATE;
  12044.  
  12045. Here's another query.  It demonstrates that you can use `mysql' as a
  12046. simple calculator:
  12047.  
  12048.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  12049.      +-------------+---------+
  12050.      | SIN(PI()/4) | (4+1)*5 |
  12051.      +-------------+---------+
  12052.      |    0.707107 |      25 |
  12053.      +-------------+---------+
  12054.  
  12055. The commands shown thus far have been relatively short, single-line
  12056. statements.  You can even enter multiple statements on a single line.
  12057. Just end each one with a semicolon:
  12058.  
  12059.      mysql> SELECT VERSION(); SELECT NOW();
  12060.      +--------------+
  12061.      | VERSION()    |
  12062.      +--------------+
  12063.      | 3.22.20a-log |
  12064.      +--------------+
  12065.      
  12066.      +---------------------+
  12067.      | NOW()               |
  12068.      +---------------------+
  12069.      | 1999-03-19 00:15:33 |
  12070.      +---------------------+
  12071.  
  12072. A command need not be given all on a single line, so lengthy commands
  12073. that require several lines are not a problem.  `mysql' determines where
  12074. your statement ends by looking for the terminating semicolon, not by
  12075. looking for the end of the input line.  (In other words, `mysql'
  12076. accepts free-format input:  it collects input lines but does not
  12077. execute them until it sees the semicolon.)
  12078.  
  12079. Here's a simple multiple-line statement:
  12080.  
  12081.      mysql> SELECT
  12082.          -> USER()
  12083.          -> ,
  12084.          -> CURRENT_DATE;
  12085.      +--------------------+--------------+
  12086.      | USER()             | CURRENT_DATE |
  12087.      +--------------------+--------------+
  12088.      | joesmith@localhost | 1999-03-18   |
  12089.      +--------------------+--------------+
  12090.  
  12091. In this example, notice how the prompt changes from `mysql>' to `->'
  12092. after you enter the first line of a multiple-line query.  This is how
  12093. `mysql' indicates that it hasn't seen a complete statement and is
  12094. waiting for the rest.  The prompt is your friend, because it provides
  12095. valuable feedback.  If you use that feedback, you will always be aware
  12096. of what `mysql' is waiting for.
  12097.  
  12098. If you decide you don't want to execute a command that you are in the
  12099. process of entering, cancel it by typing `\c':
  12100.  
  12101.      mysql> SELECT
  12102.          -> USER()
  12103.          -> \c
  12104.      mysql>
  12105.  
  12106. Here, too, notice the prompt.  It switches back to `mysql>' after you
  12107. type `\c', providing feedback to indicate that `mysql' is ready for a
  12108. new command.
  12109.  
  12110. The following table shows each of the prompts you may see and
  12111. summarises what they mean about the state that `mysql' is in:
  12112.  
  12113. *Prompt**Meaning*
  12114. `mysql>'Ready for new command.
  12115. `       Waiting for next line of multiple-line command.
  12116. ->'     
  12117. `       Waiting for next line, collecting a string that begins
  12118. '>'     with a single quote (`'').
  12119. `       Waiting for next line, collecting a string that begins
  12120. ">'     with a double quote (`"').
  12121.  
  12122. Multiple-line statements commonly occur by accident when you intend to
  12123. issue a command on a single line, but forget the terminating semicolon.
  12124. In this case, `mysql' waits for more input:
  12125.  
  12126.      mysql> SELECT USER()
  12127.          ->
  12128.  
  12129. If this happens to you (you think you've entered a statement but the
  12130. only response is a `->' prompt), most likely `mysql' is waiting for the
  12131. semicolon.  If you don't notice what the prompt is telling you, you
  12132. might sit there for a while before realising what you need to do.
  12133. Enter a semicolon to complete the statement, and `mysql' will execute
  12134. it:
  12135.  
  12136.      mysql> SELECT USER()
  12137.          -> ;
  12138.      +--------------------+
  12139.      | USER()             |
  12140.      +--------------------+
  12141.      | joesmith@localhost |
  12142.      +--------------------+
  12143.  
  12144. The `'>' and `">' prompts occur during string collection.  In MySQL,
  12145. you can write strings surrounded by either `'' or `"' characters (for
  12146. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  12147. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  12148. that you've entered a line containing a string that begins with a `''
  12149. or `"' quote character, but have not yet entered the matching quote
  12150. that terminates the string.  That's fine if you really are entering a
  12151. multiple-line string, but how likely is that?  Not very.  More often,
  12152. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  12153. quote character.  For example:
  12154.  
  12155.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  12156.          ">
  12157.  
  12158. If you enter this `SELECT' statement, then press Enter and wait for the
  12159. result, nothing will happen.  Instead of wondering why this query takes
  12160. so long, notice the clue provided by the `">' prompt.  It tells you
  12161. that `mysql' expects to see the rest of an unterminated string.  (Do
  12162. you see the error in the statement?  The string `"Smith' is missing the
  12163. second quote.)
  12164.  
  12165. At this point, what do you do?  The simplest thing is to cancel the
  12166. command.  However, you cannot just type `\c' in this case, because
  12167. `mysql' interprets it as part of the string that it is collecting!
  12168. Instead, enter the closing quote character (so `mysql' knows you've
  12169. finished the string), then type `\c':
  12170.  
  12171.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  12172.          "> "\c
  12173.      mysql>
  12174.  
  12175. The prompt changes back to `mysql>', indicating that `mysql' is ready
  12176. for a new command.
  12177.  
  12178. It's important to know what the `'>' and `">' prompts signify, because
  12179. if you mistakenly enter an unterminated string, any further lines you
  12180. type will appear to be ignored by `mysql'--including a line containing
  12181. `QUIT'!  This can be quite confusing, especially if you don't know that
  12182. you need to supply the terminating quote before you can cancel the
  12183. current command.
  12184.  
  12185. Creating and Using a Database
  12186. =============================
  12187.  
  12188. Now that you know how to enter commands, it's time to access a database.
  12189.  
  12190. Suppose you have several pets in your home (your menagerie) and you'd
  12191. like to keep track of various types of information about them.  You can
  12192. do so by creating tables to hold your data and loading them with the
  12193. desired information.  Then you can answer different sorts of questions
  12194. about your animals by retrieving data from the tables.  This section
  12195. shows you how to:
  12196.  
  12197.    * Create a database
  12198.  
  12199.    * Create a table
  12200.  
  12201.    * Load data into the table
  12202.  
  12203.    * Retrieve data from the table in various ways
  12204.  
  12205.    * Use multiple tables
  12206.  
  12207. The menagerie database will be simple (deliberately), but it is not
  12208. difficult to think of real-world situations in which a similar type of
  12209. database might be used.  For example, a database like this could be
  12210. used by a farmer to keep track of livestock, or by a veterinarian to
  12211. keep track of patient records.  A menagerie distribution containing
  12212. some of the queries and sample data used in the following sections can
  12213. be obtained from the MySQL web site.  It's available in either
  12214. compressed `tar' format
  12215. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz') or
  12216. Zip format
  12217. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip').
  12218.  
  12219. Use the `SHOW' statement to find out what databases currently exist on
  12220. the server:
  12221.  
  12222.      mysql> SHOW DATABASES;
  12223.      +----------+
  12224.      | Database |
  12225.      +----------+
  12226.      | mysql    |
  12227.      | test     |
  12228.      | tmp      |
  12229.      +----------+
  12230.  
  12231. The list of databases is probably different on your machine, but the
  12232. `mysql' and `test' databases are likely to be among them.  The `mysql'
  12233. database is required because it describes user access privileges.  The
  12234. `test' database is often provided as a workspace for users to try
  12235. things out.
  12236.  
  12237. Note that you may not see all databases if you don't have the `SHOW
  12238. DATABASES' privilege. *Note GRANT::.
  12239.  
  12240. If the `test' database exists, try to access it:
  12241.  
  12242.      mysql> USE test
  12243.      Database changed
  12244.  
  12245. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  12246. terminate such statements with a semicolon if you like; it does no
  12247. harm.)  The `USE' statement is special in another way, too:  it must be
  12248. given on a single line.
  12249.  
  12250. You can use the `test' database (if you have access to it) for the
  12251. examples that follow, but anything you create in that database can be
  12252. removed by anyone else with access to it.  For this reason, you should
  12253. probably ask your MySQL administrator for permission to use a database
  12254. of your own.  Suppose you want to call yours `menagerie'.  The
  12255. administrator needs to execute a command like this:
  12256.  
  12257.      mysql> GRANT ALL ON menagerie.* TO your_mysql_name;
  12258.  
  12259. where `your_mysql_name' is the MySQL user name assigned to you.
  12260.  
  12261. Creating and Selecting a Database
  12262. ---------------------------------
  12263.  
  12264. If the administrator creates your database for you when setting up your
  12265. permissions, you can begin using it.  Otherwise, you need to create it
  12266. yourself:
  12267.  
  12268.      mysql> CREATE DATABASE menagerie;
  12269.  
  12270. Under Unix, database names are case-sensitive (unlike SQL keywords), so
  12271. you must always refer to your database as `menagerie', not as
  12272. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  12273. table names.  (Under Windows, this restriction does not apply, although
  12274. you must refer to databases and tables using the same lettercase
  12275. throughout a given query.)
  12276.  
  12277. Creating a database does not select it for use; you must do that
  12278. explicitly.  To make `menagerie' the current database, use this command:
  12279.  
  12280.      mysql> USE menagerie
  12281.      Database changed
  12282.  
  12283. Your database needs to be created only once, but you must select it for
  12284. use each time you begin a `mysql' session.  You can do this by issuing a
  12285. `USE' statement as shown above.  Alternatively, you can select the
  12286. database on the command-line when you invoke `mysql'.  Just specify its
  12287. name after any connection parameters that you might need to provide.
  12288. For example:
  12289.  
  12290.      shell> mysql -h host -u user -p menagerie
  12291.      Enter password: ********
  12292.  
  12293. Note that `menagerie' is not your password on the command just shown.
  12294. If you want to supply your password on the command-line after the `-p'
  12295. option, you must do so with no intervening space (for example, as
  12296. `-pmypassword', not as `-p mypassword').  However, putting your
  12297. password on the command-line is not recommended, because doing so
  12298. exposes it to snooping by other users logged in on your machine.
  12299.  
  12300. Creating a Table
  12301. ----------------
  12302.  
  12303. Creating the database is the easy part, but at this point it's empty, as
  12304. `SHOW TABLES' will tell you:
  12305.  
  12306.      mysql> SHOW TABLES;
  12307.      Empty set (0.00 sec)
  12308.  
  12309. The harder part is deciding what the structure of your database should
  12310. be: what tables you will need and what columns will be in each of them.
  12311.  
  12312. You'll want a table that contains a record for each of your pets.  This
  12313. can be called the `pet' table, and it should contain, as a bare minimum,
  12314. each animal's name.  Because the name by itself is not very
  12315. interesting, the table should contain other information.  For example,
  12316. if more than one person in your family keeps pets, you might want to
  12317. list each animal's owner.  You might also want to record some basic
  12318. descriptive information such as species and sex.
  12319.  
  12320. How about age?  That might be of interest, but it's not a good thing to
  12321. store in a database.  Age changes as time passes, which means you'd
  12322. have to update your records often.  Instead, it's better to store a
  12323. fixed value such as date of birth.  Then, whenever you need age, you
  12324. can calculate it as the difference between the current date and the
  12325. birth date.  MySQL provides functions for doing date arithmetic, so
  12326. this is not difficult.  Storing birth date rather than age has other
  12327. advantages, too:
  12328.  
  12329.    * You can use the database for tasks such as generating reminders
  12330.      for upcoming pet birthdays.  (If you think this type of query is
  12331.      somewhat silly, note that it is the same question you might ask in
  12332.      the context of a business database to identify clients to whom
  12333.      you'll soon need to send out birthday greetings, for that
  12334.      computer-assisted personal touch.)
  12335.  
  12336.    * You can calculate age in relation to dates other than the current
  12337.      date.  For example, if you store death date in the database, you
  12338.      can easily calculate how old a pet was when it died.
  12339.  
  12340. You can probably think of other types of information that would be
  12341. useful in the `pet' table, but the ones identified so far are
  12342. sufficient for now: name, owner, species, sex, birth, and death.
  12343.  
  12344. Use a `CREATE TABLE' statement to specify the layout of your table:
  12345.  
  12346.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  12347.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  12348.  
  12349. `VARCHAR' is a good choice for the `name', `owner', and `species'
  12350. columns because the column values will vary in length.  The lengths of
  12351. those columns need not all be the same, and need not be `20'.  You can
  12352. pick any length from `1' to `255', whatever seems most reasonable to
  12353. you.  (If you make a poor choice and it turns out later that you need a
  12354. longer field, MySQL provides an `ALTER TABLE' statement.)
  12355.  
  12356. Several types of values can be chosen to represent sex in animal
  12357. records, such as `"m"' and `"f"', or perhaps `"male"' and `"female"'.
  12358. It's simplest to use the single characters `"m"' and `"f"'.
  12359.  
  12360. The use of the `DATE' data type for the `birth' and `death' columns is
  12361. a fairly obvious choice.
  12362.  
  12363. Now that you have created a table, `SHOW TABLES' should produce some
  12364. output:
  12365.  
  12366.      mysql> SHOW TABLES;
  12367.      +---------------------+
  12368.      | Tables in menagerie |
  12369.      +---------------------+
  12370.      | pet                 |
  12371.      +---------------------+
  12372.  
  12373. To verify that your table was created the way you expected, use a
  12374. `DESCRIBE' statement:
  12375.  
  12376.      mysql> DESCRIBE pet;
  12377.      +---------+-------------+------+-----+---------+-------+
  12378.      | Field   | Type        | Null | Key | Default | Extra |
  12379.      +---------+-------------+------+-----+---------+-------+
  12380.      | name    | varchar(20) | YES  |     | NULL    |       |
  12381.      | owner   | varchar(20) | YES  |     | NULL    |       |
  12382.      | species | varchar(20) | YES  |     | NULL    |       |
  12383.      | sex     | char(1)     | YES  |     | NULL    |       |
  12384.      | birth   | date        | YES  |     | NULL    |       |
  12385.      | death   | date        | YES  |     | NULL    |       |
  12386.      +---------+-------------+------+-----+---------+-------+
  12387.  
  12388. You can use `DESCRIBE' any time, for example, if you forget the names of
  12389. the columns in your table or what types they are.
  12390.  
  12391. Loading Data into a Table
  12392. -------------------------
  12393.  
  12394. After creating your table, you need to populate it.  The `LOAD DATA' and
  12395. `INSERT' statements are useful for this.
  12396.  
  12397. Suppose your pet records can be described as shown here.  (Observe that
  12398. MySQL expects dates in `'YYYY-MM-DD'' format; this may be different
  12399. from what you are used to.)
  12400.  
  12401. *name*  *owner* *species**sex**birth*     *death*
  12402. Fluffy  Harold  cat     f    1993-02-04  
  12403. Claws   Gwen    cat     m    1994-03-17  
  12404. Buffy   Harold  dog     f    1989-05-13  
  12405. Fang    Benny   dog     m    1990-08-27  
  12406. Bowser  Diane   dog     m    1998-08-31  1995-07-29
  12407. Chirpy  Gwen    bird    f    1998-09-11  
  12408. WhistlerGwen    bird         1997-12-09  
  12409. Slim    Benny   snake   m    1996-04-29  
  12410.  
  12411. Because you are beginning with an empty table, an easy way to populate
  12412. it is to create a text file containing a row for each of your animals,
  12413. then load the contents of the file into the table with a single
  12414. statement.
  12415.  
  12416. You could create a text file `pet.txt' containing one record per line,
  12417. with values separated by tabs, and given in the order in which the
  12418. columns were listed in the `CREATE TABLE' statement.  For missing
  12419. values (such as unknown sexes or death dates for animals that are still
  12420. living), you can use `NULL' values.  To represent these in your text
  12421. file, use `\N'.  For example, the record for Whistler the bird would
  12422. look like this (where the whitespace between values is a single tab
  12423. character):
  12424.  
  12425. *name*  *owner* *species**sex**birth*     *death*
  12426. `Whistler'`Gwen'  `bird'  `\N' `1997-12-09'`\N'
  12427.  
  12428. To load the text file `pet.txt' into the `pet' table, use this command:
  12429.  
  12430.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  12431.  
  12432. You can specify the column value separator and end of line marker
  12433. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  12434. are tab and linefeed.  These are sufficient for the statement to read
  12435. the file `pet.txt' properly.
  12436.  
  12437. When you want to add new records one at a time, the `INSERT' statement
  12438. is useful.  In its simplest form, you supply values for each column, in
  12439. the order in which the columns were listed in the `CREATE TABLE'
  12440. statement.  Suppose Diane gets a new hamster named Puffball.  You could
  12441. add a new record using an `INSERT' statement like this:
  12442.  
  12443.      mysql> INSERT INTO pet
  12444.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  12445.  
  12446. Note that string and date values are specified as quoted strings here.
  12447. Also, with `INSERT', you can insert `NULL' directly to represent a
  12448. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  12449.  
  12450. From this example, you should be able to see that there would be a lot
  12451. more typing involved to load your records initially using several
  12452. `INSERT' statements rather than a single `LOAD DATA' statement.
  12453.  
  12454. Retrieving Information from a Table
  12455. -----------------------------------
  12456.  
  12457. The `SELECT' statement is used to pull information from a table.  The
  12458. general form of the statement is:
  12459.  
  12460.      SELECT what_to_select
  12461.      FROM which_table
  12462.      WHERE conditions_to_satisfy
  12463.  
  12464. `what_to_select' indicates what you want to see.  This can be a list of
  12465. columns, or `*' to indicate "all columns." `which_table' indicates the
  12466. table from which you want to retrieve data.  The `WHERE' clause is
  12467. optional.  If it's present, `conditions_to_satisfy' specifies
  12468. conditions that rows must satisfy to qualify for retrieval.
  12469.  
  12470. Selecting All Data
  12471. ..................
  12472.  
  12473. The simplest form of `SELECT' retrieves everything from a table:
  12474.  
  12475.      mysql> SELECT * FROM pet;
  12476.      +----------+--------+---------+------+------------+------------+
  12477.      | name     | owner  | species | sex  | birth      | death      |
  12478.      +----------+--------+---------+------+------------+------------+
  12479.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  12480.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  12481.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  12482.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  12483.      | Bowser   | Diane  | dog     | m    | 1998-08-31 | 1995-07-29 |
  12484.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  12485.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  12486.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  12487.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  12488.      +----------+--------+---------+------+------------+------------+
  12489.  
  12490. This form of `SELECT' is useful if you want to review your entire table,
  12491. for instance, after you've just loaded it with your initial dataset.
  12492. As it happens, the output just shown reveals an error in your datafile:
  12493. Bowser appears to have been born after he died!  Consulting your
  12494. original pedigree papers, you find that the correct birth year is 1989,
  12495. not 1998.
  12496.  
  12497. There are least a couple of ways to fix this:
  12498.  
  12499.    * Edit the file `pet.txt' to correct the error, then empty the table
  12500.      and reload it using `DELETE' and `LOAD DATA':
  12501.  
  12502.           mysql> SET AUTOCOMMIT=1;  # Used for quick re-create of the table
  12503.           mysql> DELETE FROM pet;
  12504.           mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  12505.  
  12506.      However, if you do this, you must also re-enter the record for
  12507.      Puffball.
  12508.  
  12509.    * Fix only the erroneous record with an `UPDATE' statement:
  12510.  
  12511.           mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
  12512.  
  12513. As shown above, it is easy to retrieve an entire table.  But typically
  12514. you don't want to do that, particularly when the table becomes large.
  12515. Instead, you're usually more interested in answering a particular
  12516. question, in which case you specify some constraints on the information
  12517. you want.  Let's look at some selection queries in terms of questions
  12518. about your pets that they answer.
  12519.  
  12520. Selecting Particular Rows
  12521. .........................
  12522.  
  12523. You can select only particular rows from your table.  For example, if
  12524. you want to verify the change that you made to Bowser's birth date,
  12525. select Bowser's record like this:
  12526.  
  12527.      mysql> SELECT * FROM pet WHERE name = "Bowser";
  12528.      +--------+-------+---------+------+------------+------------+
  12529.      | name   | owner | species | sex  | birth      | death      |
  12530.      +--------+-------+---------+------+------------+------------+
  12531.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12532.      +--------+-------+---------+------+------------+------------+
  12533.  
  12534. The output confirms that the year is correctly recorded now as 1989,
  12535. not 1998.
  12536.  
  12537. String comparisons are normally case-insensitive, so you can specify the
  12538. name as `"bowser"', `"BOWSER"', etc.  The query result will be the same.
  12539.  
  12540. You can specify conditions on any column, not just `name'.  For example,
  12541. if you want to know which animals were born after 1998, test the `birth'
  12542. column:
  12543.  
  12544.      mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
  12545.      +----------+-------+---------+------+------------+-------+
  12546.      | name     | owner | species | sex  | birth      | death |
  12547.      +----------+-------+---------+------+------------+-------+
  12548.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  12549.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  12550.      +----------+-------+---------+------+------------+-------+
  12551.  
  12552. You can combine conditions, for example, to locate female dogs:
  12553.  
  12554.      mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
  12555.      +-------+--------+---------+------+------------+-------+
  12556.      | name  | owner  | species | sex  | birth      | death |
  12557.      +-------+--------+---------+------+------------+-------+
  12558.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12559.      +-------+--------+---------+------+------------+-------+
  12560.  
  12561. The preceding query uses the `AND' logical operator.  There is also an
  12562. `OR' operator:
  12563.  
  12564.      mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
  12565.      +----------+-------+---------+------+------------+-------+
  12566.      | name     | owner | species | sex  | birth      | death |
  12567.      +----------+-------+---------+------+------------+-------+
  12568.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  12569.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  12570.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  12571.      +----------+-------+---------+------+------------+-------+
  12572.  
  12573. `AND' and `OR' may be intermixed.  If you do that, it's a good idea to
  12574. use parentheses to indicate how conditions should be grouped:
  12575.  
  12576.      mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
  12577.          -> OR (species = "dog" AND sex = "f");
  12578.      +-------+--------+---------+------+------------+-------+
  12579.      | name  | owner  | species | sex  | birth      | death |
  12580.      +-------+--------+---------+------+------------+-------+
  12581.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12582.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12583.      +-------+--------+---------+------+------------+-------+
  12584.  
  12585. Selecting Particular Columns
  12586. ............................
  12587.  
  12588. If you don't want to see entire rows from your table, just name the
  12589. columns in which you're interested, separated by commas.  For example,
  12590. if you want to know when your animals were born, select the `name' and
  12591. `birth' columns:
  12592.  
  12593.      mysql> SELECT name, birth FROM pet;
  12594.      +----------+------------+
  12595.      | name     | birth      |
  12596.      +----------+------------+
  12597.      | Fluffy   | 1993-02-04 |
  12598.      | Claws    | 1994-03-17 |
  12599.      | Buffy    | 1989-05-13 |
  12600.      | Fang     | 1990-08-27 |
  12601.      | Bowser   | 1989-08-31 |
  12602.      | Chirpy   | 1998-09-11 |
  12603.      | Whistler | 1997-12-09 |
  12604.      | Slim     | 1996-04-29 |
  12605.      | Puffball | 1999-03-30 |
  12606.      +----------+------------+
  12607.  
  12608. To find out who owns pets, use this query:
  12609.  
  12610.      mysql> SELECT owner FROM pet;
  12611.      +--------+
  12612.      | owner  |
  12613.      +--------+
  12614.      | Harold |
  12615.      | Gwen   |
  12616.      | Harold |
  12617.      | Benny  |
  12618.      | Diane  |
  12619.      | Gwen   |
  12620.      | Gwen   |
  12621.      | Benny  |
  12622.      | Diane  |
  12623.      +--------+
  12624.  
  12625. However, notice that the query simply retrieves the `owner' field from
  12626. each record, and some of them appear more than once.  To minimise the
  12627. output, retrieve each unique output record just once by adding the
  12628. keyword `DISTINCT':
  12629.  
  12630.      mysql> SELECT DISTINCT owner FROM pet;
  12631.      +--------+
  12632.      | owner  |
  12633.      +--------+
  12634.      | Benny  |
  12635.      | Diane  |
  12636.      | Gwen   |
  12637.      | Harold |
  12638.      +--------+
  12639.  
  12640. You can use a `WHERE' clause to combine row selection with column
  12641. selection.  For example, to get birth dates for dogs and cats only, use
  12642. this query:
  12643.  
  12644.      mysql> SELECT name, species, birth FROM pet
  12645.          -> WHERE species = "dog" OR species = "cat";
  12646.      +--------+---------+------------+
  12647.      | name   | species | birth      |
  12648.      +--------+---------+------------+
  12649.      | Fluffy | cat     | 1993-02-04 |
  12650.      | Claws  | cat     | 1994-03-17 |
  12651.      | Buffy  | dog     | 1989-05-13 |
  12652.      | Fang   | dog     | 1990-08-27 |
  12653.      | Bowser | dog     | 1989-08-31 |
  12654.      +--------+---------+------------+
  12655.  
  12656. Sorting Rows
  12657. ............
  12658.  
  12659. You may have noticed in the preceding examples that the result rows are
  12660. displayed in no particular order.  However, it's often easier to examine
  12661. query output when the rows are sorted in some meaningful way.  To sort a
  12662. result, use an `ORDER BY' clause.
  12663.  
  12664. Here are animal birthdays, sorted by date:
  12665.  
  12666.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  12667.      +----------+------------+
  12668.      | name     | birth      |
  12669.      +----------+------------+
  12670.      | Buffy    | 1989-05-13 |
  12671.      | Bowser   | 1989-08-31 |
  12672.      | Fang     | 1990-08-27 |
  12673.      | Fluffy   | 1993-02-04 |
  12674.      | Claws    | 1994-03-17 |
  12675.      | Slim     | 1996-04-29 |
  12676.      | Whistler | 1997-12-09 |
  12677.      | Chirpy   | 1998-09-11 |
  12678.      | Puffball | 1999-03-30 |
  12679.      +----------+------------+
  12680.  
  12681. On character type columns, sorting--like all other comparison
  12682. operations--is normally performed in a case-insensitive fashion.  This
  12683. means that the order will be undefined for columns that are identical
  12684. except for their case. You can force a case-sensitive sort by using the
  12685. BINARY cast: `ORDER BY BINARY(field)'.
  12686.  
  12687. To sort in reverse order, add the `DESC' (descending) keyword to the
  12688. name of the column you are sorting by:
  12689.  
  12690.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  12691.      +----------+------------+
  12692.      | name     | birth      |
  12693.      +----------+------------+
  12694.      | Puffball | 1999-03-30 |
  12695.      | Chirpy   | 1998-09-11 |
  12696.      | Whistler | 1997-12-09 |
  12697.      | Slim     | 1996-04-29 |
  12698.      | Claws    | 1994-03-17 |
  12699.      | Fluffy   | 1993-02-04 |
  12700.      | Fang     | 1990-08-27 |
  12701.      | Bowser   | 1989-08-31 |
  12702.      | Buffy    | 1989-05-13 |
  12703.      +----------+------------+
  12704.  
  12705. You can sort on multiple columns.  For example, to sort by type of
  12706. animal, then by birth date within animal type with youngest animals
  12707. first, use the following query:
  12708.  
  12709.      mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
  12710.      +----------+---------+------------+
  12711.      | name     | species | birth      |
  12712.      +----------+---------+------------+
  12713.      | Chirpy   | bird    | 1998-09-11 |
  12714.      | Whistler | bird    | 1997-12-09 |
  12715.      | Claws    | cat     | 1994-03-17 |
  12716.      | Fluffy   | cat     | 1993-02-04 |
  12717.      | Fang     | dog     | 1990-08-27 |
  12718.      | Bowser   | dog     | 1989-08-31 |
  12719.      | Buffy    | dog     | 1989-05-13 |
  12720.      | Puffball | hamster | 1999-03-30 |
  12721.      | Slim     | snake   | 1996-04-29 |
  12722.      +----------+---------+------------+
  12723.  
  12724. Note that the `DESC' keyword applies only to the column name immediately
  12725. preceding it (`birth'); `species' values are still sorted in ascending
  12726. order.
  12727.  
  12728. Date Calculations
  12729. .................
  12730.  
  12731. MySQL provides several functions that you can use to perform
  12732. calculations on dates, for example, to calculate ages or extract parts
  12733. of dates.
  12734.  
  12735. To determine how many years old each of your pets is, compute the
  12736. difference in the year part of the current date and the birth date, then
  12737. subtract one if the current date occurs earlier in the calendar year
  12738. than the birth date.  The following query shows, for each pet, the
  12739. birth date, the current date, and the age in years.
  12740.  
  12741.      mysql> SELECT name, birth, CURRENT_DATE,
  12742.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  12743.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  12744.          -> AS age
  12745.          -> FROM pet;
  12746.      +----------+------------+--------------+------+
  12747.      | name     | birth      | CURRENT_DATE | age  |
  12748.      +----------+------------+--------------+------+
  12749.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  12750.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  12751.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  12752.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  12753.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  12754.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  12755.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  12756.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  12757.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  12758.      +----------+------------+--------------+------+
  12759.  
  12760. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  12761. off the rightmost five characters that represent the `MM-DD' (calendar
  12762. year) part of the date.  The part of the expression that compares the
  12763. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  12764. down a year if `CURRENT_DATE' occurs earlier in the year than `birth'.
  12765. The full expression is somewhat ungainly, so an alias (`age') is used
  12766. to make the output column label more meaningful.
  12767.  
  12768. The query works, but the result could be scanned more easily if the rows
  12769. were presented in some order.  This can be done by adding an `ORDER BY
  12770. name' clause to sort the output by name:
  12771.  
  12772.      mysql> SELECT name, birth, CURRENT_DATE,
  12773.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  12774.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  12775.          -> AS age
  12776.          -> FROM pet ORDER BY name;
  12777.      +----------+------------+--------------+------+
  12778.      | name     | birth      | CURRENT_DATE | age  |
  12779.      +----------+------------+--------------+------+
  12780.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  12781.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  12782.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  12783.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  12784.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  12785.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  12786.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  12787.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  12788.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  12789.      +----------+------------+--------------+------+
  12790.  
  12791. To sort the output by `age' rather than `name', just use a different
  12792. `ORDER BY' clause:
  12793.  
  12794.      mysql> SELECT name, birth, CURRENT_DATE,
  12795.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  12796.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  12797.          -> AS age
  12798.          -> FROM pet ORDER BY age;
  12799.      +----------+------------+--------------+------+
  12800.      | name     | birth      | CURRENT_DATE | age  |
  12801.      +----------+------------+--------------+------+
  12802.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  12803.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  12804.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  12805.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  12806.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  12807.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  12808.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  12809.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  12810.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  12811.      +----------+------------+--------------+------+
  12812.  
  12813. A similar query can be used to determine age at death for animals that
  12814. have died.  You determine which animals these are by checking whether
  12815. the `death' value is `NULL'.  Then, for those with non-`NULL' values,
  12816. compute the difference between the `death' and `birth' values:
  12817.  
  12818.      mysql> SELECT name, birth, death,
  12819.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  12820.          -> AS age
  12821.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  12822.      +--------+------------+------------+------+
  12823.      | name   | birth      | death      | age  |
  12824.      +--------+------------+------------+------+
  12825.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  12826.      +--------+------------+------------+------+
  12827.  
  12828. The query uses `death IS NOT NULL' rather than `death <> NULL' because
  12829. `NULL' is a special value.  This is explained later.  *Note Working
  12830. with `NULL': Working with NULL.
  12831.  
  12832. What if you want to know which animals have birthdays next month?  For
  12833. this type of calculation, year and day are irrelevant; you simply want
  12834. to extract the month part of the `birth' column.  MySQL provides several
  12835. date-part extraction functions, such as `YEAR()', `MONTH()', and
  12836. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  12837. how it works, run a simple query that displays the value of both
  12838. `birth' and `MONTH(birth)':
  12839.  
  12840.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  12841.      +----------+------------+--------------+
  12842.      | name     | birth      | MONTH(birth) |
  12843.      +----------+------------+--------------+
  12844.      | Fluffy   | 1993-02-04 |            2 |
  12845.      | Claws    | 1994-03-17 |            3 |
  12846.      | Buffy    | 1989-05-13 |            5 |
  12847.      | Fang     | 1990-08-27 |            8 |
  12848.      | Bowser   | 1989-08-31 |            8 |
  12849.      | Chirpy   | 1998-09-11 |            9 |
  12850.      | Whistler | 1997-12-09 |           12 |
  12851.      | Slim     | 1996-04-29 |            4 |
  12852.      | Puffball | 1999-03-30 |            3 |
  12853.      +----------+------------+--------------+
  12854.  
  12855. Finding animals with birthdays in the upcoming month is easy, too.
  12856. Suppose the current month is April.  Then the month value is `4' and
  12857. you look for animals born in May (month 5) like this:
  12858.  
  12859.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  12860.      +-------+------------+
  12861.      | name  | birth      |
  12862.      +-------+------------+
  12863.      | Buffy | 1989-05-13 |
  12864.      +-------+------------+
  12865.  
  12866. There is a small complication if the current month is December, of
  12867. course.  You don't just add one to the month number (`12') and look for
  12868. animals born in month 13, because there is no such month.  Instead, you
  12869. look for animals born in January (month 1).
  12870.  
  12871. You can even write the query so that it works no matter what the current
  12872. month is.  That way you don't have to use a particular month number in
  12873. the query.  `DATE_ADD()' allows you to add a time interval to a given
  12874. date.  If you add a month to the value of `NOW()', then extract the
  12875. month part with `MONTH()', the result produces the month in which to
  12876. look for birthdays:
  12877.  
  12878.      mysql> SELECT name, birth FROM pet
  12879.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(NOW(), INTERVAL 1 MONTH));
  12880.  
  12881. A different way to accomplish the same task is to add `1' to get the
  12882. next month after the current one (after using the modulo function
  12883. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  12884.  
  12885.      mysql> SELECT name, birth FROM pet
  12886.          -> WHERE MONTH(birth) = MOD(MONTH(NOW()), 12) + 1;
  12887.  
  12888. Note that `MONTH' returns a number between 1 and 12. And
  12889. `MOD(something,12)' returns a number between 0 and 11. So the addition
  12890. has to be after the `MOD()', otherwise we would go from November (11)
  12891. to January (1).
  12892.  
  12893. Working with `NULL' Values
  12894. ..........................
  12895.  
  12896. The `NULL' value can be surprising until you get used to it.
  12897. Conceptually, `NULL' means missing value or unknown value and it is
  12898. treated somewhat differently than other values.  To test for `NULL',
  12899. you cannot use the arithmetic comparison operators such as `=', `<', or
  12900. `<>'.  To demonstrate this for yourself, try the following query:
  12901.  
  12902.      mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
  12903.      +----------+-----------+----------+----------+
  12904.      | 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |
  12905.      +----------+-----------+----------+----------+
  12906.      |     NULL |      NULL |     NULL |     NULL |
  12907.      +----------+-----------+----------+----------+
  12908.  
  12909. Clearly you get no meaningful results from these comparisons.  Use the
  12910. `IS NULL' and `IS NOT NULL' operators instead:
  12911.  
  12912.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  12913.      +-----------+---------------+
  12914.      | 1 IS NULL | 1 IS NOT NULL |
  12915.      +-----------+---------------+
  12916.      |         0 |             1 |
  12917.      +-----------+---------------+
  12918.  
  12919. Note that in MySQL, 0 or `NULL' means false and anything else means
  12920. true. The default truth value from a boolean operation is 1.
  12921.  
  12922. This special treatment of `NULL' is why, in the previous section, it
  12923. was necessary to determine which animals are no longer alive using
  12924. `death IS NOT NULL' instead of `death <> NULL'.
  12925.  
  12926. Two `NULL' values are regarded as equal in a `GROUP BY'.
  12927.  
  12928. When doing an `ORDER BY', `NULL' values are presented first if you do
  12929. `ORDER BY ... ASC' and last if you do `ORDER BY ... DESC'.
  12930.  
  12931. Note that between MySQL 4.0.2 - 4.0.10, `NULL' values incorrectly were
  12932. always sorted first regardless of the sort direction.
  12933.  
  12934. Pattern Matching
  12935. ................
  12936.  
  12937. MySQL provides standard SQL pattern matching as well as a form of
  12938. pattern matching based on extended regular expressions similar to those
  12939. used by Unix utilities such as `vi', `grep', and `sed'.
  12940.  
  12941. SQL pattern matching allows you to use `_' to match any single
  12942. character and `%' to match an arbitrary number of characters (including
  12943. zero characters).  In MySQL, SQL patterns are case-insensitive by
  12944. default.  Some examples are shown here.  Note that you do not use `='
  12945. or `<>' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  12946. comparison operators instead.
  12947.  
  12948. To find names beginning with `b':
  12949.  
  12950.      mysql> SELECT * FROM pet WHERE name LIKE "b%";
  12951.      +--------+--------+---------+------+------------+------------+
  12952.      | name   | owner  | species | sex  | birth      | death      |
  12953.      +--------+--------+---------+------+------------+------------+
  12954.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  12955.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  12956.      +--------+--------+---------+------+------------+------------+
  12957.  
  12958. To find names ending with `fy':
  12959.  
  12960.      mysql> SELECT * FROM pet WHERE name LIKE "%fy";
  12961.      +--------+--------+---------+------+------------+-------+
  12962.      | name   | owner  | species | sex  | birth      | death |
  12963.      +--------+--------+---------+------+------------+-------+
  12964.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  12965.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  12966.      +--------+--------+---------+------+------------+-------+
  12967.  
  12968. To find names containing a `w':
  12969.  
  12970.      mysql> SELECT * FROM pet WHERE name LIKE "%w%";
  12971.      +----------+-------+---------+------+------------+------------+
  12972.      | name     | owner | species | sex  | birth      | death      |
  12973.      +----------+-------+---------+------+------------+------------+
  12974.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  12975.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12976.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  12977.      +----------+-------+---------+------+------------+------------+
  12978.  
  12979. To find names containing exactly five characters, use the `_' pattern
  12980. character:
  12981.  
  12982.      mysql> SELECT * FROM pet WHERE name LIKE "_____";
  12983.      +-------+--------+---------+------+------------+-------+
  12984.      | name  | owner  | species | sex  | birth      | death |
  12985.      +-------+--------+---------+------+------------+-------+
  12986.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12987.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12988.      +-------+--------+---------+------+------------+-------+
  12989.  
  12990. The other type of pattern matching provided by MySQL uses extended
  12991. regular expressions.  When you test for a match for this type of
  12992. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  12993. `NOT RLIKE', which are synonyms).
  12994.  
  12995. Some characteristics of extended regular expressions are:
  12996.  
  12997.    * `.' matches any single character.
  12998.  
  12999.    * A character class `[...]' matches any character within the
  13000.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  13001.      a range of characters, use a dash.  `[a-z]' matches any lowercase
  13002.      letter, whereas `[0-9]' matches any digit.
  13003.  
  13004.    * `*' matches zero or more instances of the thing preceding it.  For
  13005.      example, `x*' matches any number of `x' characters, `[0-9]*'
  13006.      matches any number of digits, and `.*' matches any number of
  13007.      anything.
  13008.  
  13009.    * The pattern matches if it occurs anywhere in the value being
  13010.      tested.  (SQL patterns match only if they match the entire value.)
  13011.  
  13012.    * To anchor a pattern so that it must match the beginning or end of
  13013.      the value being tested, use `^' at the beginning or `$' at the end
  13014.      of the pattern.
  13015.  
  13016. To demonstrate how extended regular expressions work, the `LIKE' queries
  13017. shown previously are rewritten here to use `REGEXP'.
  13018.  
  13019. To find names beginning with `b', use `^' to match the beginning of the
  13020. name:
  13021.  
  13022.      mysql> SELECT * FROM pet WHERE name REGEXP "^b";
  13023.      +--------+--------+---------+------+------------+------------+
  13024.      | name   | owner  | species | sex  | birth      | death      |
  13025.      +--------+--------+---------+------+------------+------------+
  13026.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  13027.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  13028.      +--------+--------+---------+------+------------+------------+
  13029.  
  13030. Prior to MySQL Version 3.23.4, `REGEXP' is case-sensitive, and the
  13031. previous query will return no rows. To match either lowercase or
  13032. uppercase `b', use this query instead:
  13033.  
  13034.      mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
  13035.  
  13036. From MySQL 3.23.4 on, to force a `REGEXP' comparison to be
  13037. case-sensitive, use the `BINARY' keyword to make one of the strings a
  13038. binary string. This query will match only lowercase `b' at the
  13039. beginning of a name:
  13040.  
  13041.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY "^b";
  13042.  
  13043. To find names ending with `fy', use `$' to match the end of the name:
  13044.  
  13045.      mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
  13046.      +--------+--------+---------+------+------------+-------+
  13047.      | name   | owner  | species | sex  | birth      | death |
  13048.      +--------+--------+---------+------+------------+-------+
  13049.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  13050.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  13051.      +--------+--------+---------+------+------------+-------+
  13052.  
  13053. To find names containing a lowercase or uppercase `w', use this query:
  13054.  
  13055.      mysql> SELECT * FROM pet WHERE name REGEXP "w";
  13056.      +----------+-------+---------+------+------------+------------+
  13057.      | name     | owner | species | sex  | birth      | death      |
  13058.      +----------+-------+---------+------+------------+------------+
  13059.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  13060.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  13061.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  13062.      +----------+-------+---------+------+------------+------------+
  13063.  
  13064. Because a regular expression pattern matches if it occurs anywhere in
  13065. the value, it is not necessary in the previous query to put a wildcard
  13066. on either side of the pattern to get it to match the entire value like
  13067. it would be if you used an SQL pattern.
  13068.  
  13069. To find names containing exactly five characters, use `^' and `$' to
  13070. match the beginning and end of the name, and five instances of `.' in
  13071. between:
  13072.  
  13073.      mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
  13074.      +-------+--------+---------+------+------------+-------+
  13075.      | name  | owner  | species | sex  | birth      | death |
  13076.      +-------+--------+---------+------+------------+-------+
  13077.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  13078.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  13079.      +-------+--------+---------+------+------------+-------+
  13080.  
  13081. You could also write the previous query using the `{n}'
  13082. "repeat-`n'-times" operator:
  13083.  
  13084.      mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
  13085.      +-------+--------+---------+------+------------+-------+
  13086.      | name  | owner  | species | sex  | birth      | death |
  13087.      +-------+--------+---------+------+------------+-------+
  13088.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  13089.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  13090.      +-------+--------+---------+------+------------+-------+
  13091.  
  13092. Counting Rows
  13093. .............
  13094.  
  13095. Databases are often used to answer the question, "How often does a
  13096. certain type of data occur in a table?"  For example, you might want to
  13097. know how many pets you have, or how many pets each owner has, or you
  13098. might want to perform various kinds of censuses on your animals.
  13099.  
  13100. Counting the total number of animals you have is the same question as
  13101. "How many rows are in the `pet' table?" because there is one record per
  13102. pet.  The `COUNT()' function counts the number of non-`NULL' results, so
  13103. the query to count your animals looks like this:
  13104.  
  13105.      mysql> SELECT COUNT(*) FROM pet;
  13106.      +----------+
  13107.      | COUNT(*) |
  13108.      +----------+
  13109.      |        9 |
  13110.      +----------+
  13111.  
  13112. Earlier, you retrieved the names of the people who owned pets.  You can
  13113. use `COUNT()' if you want to find out how many pets each owner has:
  13114.  
  13115.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  13116.      +--------+----------+
  13117.      | owner  | COUNT(*) |
  13118.      +--------+----------+
  13119.      | Benny  |        2 |
  13120.      | Diane  |        2 |
  13121.      | Gwen   |        3 |
  13122.      | Harold |        2 |
  13123.      +--------+----------+
  13124.  
  13125. Note the use of `GROUP BY' to group together all records for each
  13126. `owner'.  Without it, all you get is an error message:
  13127.  
  13128.      mysql> SELECT owner, COUNT(owner) FROM pet;
  13129.      ERROR 1140 at line 1: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  13130.      with no GROUP columns is illegal if there is no GROUP BY clause
  13131.  
  13132. `COUNT()' and `GROUP BY' are useful for characterising your data in
  13133. various ways.  The following examples show different ways to perform
  13134. animal census operations.
  13135.  
  13136. Number of animals per species:
  13137.  
  13138.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  13139.      +---------+----------+
  13140.      | species | COUNT(*) |
  13141.      +---------+----------+
  13142.      | bird    |        2 |
  13143.      | cat     |        2 |
  13144.      | dog     |        3 |
  13145.      | hamster |        1 |
  13146.      | snake   |        1 |
  13147.      +---------+----------+
  13148.  
  13149. Number of animals per sex:
  13150.  
  13151.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  13152.      +------+----------+
  13153.      | sex  | COUNT(*) |
  13154.      +------+----------+
  13155.      | NULL |        1 |
  13156.      | f    |        4 |
  13157.      | m    |        4 |
  13158.      +------+----------+
  13159.  
  13160. (In this output, `NULL' indicates sex unknown.)
  13161.  
  13162. Number of animals per combination of species and sex:
  13163.  
  13164.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  13165.      +---------+------+----------+
  13166.      | species | sex  | COUNT(*) |
  13167.      +---------+------+----------+
  13168.      | bird    | NULL |        1 |
  13169.      | bird    | f    |        1 |
  13170.      | cat     | f    |        1 |
  13171.      | cat     | m    |        1 |
  13172.      | dog     | f    |        1 |
  13173.      | dog     | m    |        2 |
  13174.      | hamster | f    |        1 |
  13175.      | snake   | m    |        1 |
  13176.      +---------+------+----------+
  13177.  
  13178. You need not retrieve an entire table when you use `COUNT()'.  For
  13179. example, the previous query, when performed just on dogs and cats,
  13180. looks like this:
  13181.  
  13182.      mysql> SELECT species, sex, COUNT(*) FROM pet
  13183.          -> WHERE species = "dog" OR species = "cat"
  13184.          -> GROUP BY species, sex;
  13185.      +---------+------+----------+
  13186.      | species | sex  | COUNT(*) |
  13187.      +---------+------+----------+
  13188.      | cat     | f    |        1 |
  13189.      | cat     | m    |        1 |
  13190.      | dog     | f    |        1 |
  13191.      | dog     | m    |        2 |
  13192.      +---------+------+----------+
  13193.  
  13194. Or, if you wanted the number of animals per sex only for known-sex
  13195. animals:
  13196.  
  13197.      mysql> SELECT species, sex, COUNT(*) FROM pet
  13198.          -> WHERE sex IS NOT NULL
  13199.          -> GROUP BY species, sex;
  13200.      +---------+------+----------+
  13201.      | species | sex  | COUNT(*) |
  13202.      +---------+------+----------+
  13203.      | bird    | f    |        1 |
  13204.      | cat     | f    |        1 |
  13205.      | cat     | m    |        1 |
  13206.      | dog     | f    |        1 |
  13207.      | dog     | m    |        2 |
  13208.      | hamster | f    |        1 |
  13209.      | snake   | m    |        1 |
  13210.      +---------+------+----------+
  13211.  
  13212. Using More Than one Table
  13213. .........................
  13214.  
  13215. The `pet' table keeps track of which pets you have.  If you want to
  13216. record other information about them, such as events in their lives like
  13217. visits to the vet or when litters are born, you need another table.
  13218. What should this table look like? It needs:
  13219.  
  13220.    * To contain the pet name so you know which animal each event
  13221.      pertains to.
  13222.  
  13223.    * A date so you know when the event occurred.
  13224.  
  13225.    * A field to describe the event.
  13226.  
  13227.    * An event type field, if you want to be able to categorise events.
  13228.  
  13229. Given these considerations, the `CREATE TABLE' statement for the
  13230. `event' table might look like this:
  13231.  
  13232.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  13233.          -> type VARCHAR(15), remark VARCHAR(255));
  13234.  
  13235. As with the `pet' table, it's easiest to load the initial records by
  13236. creating a tab-delimited text file containing the information:
  13237.  
  13238. *name*  *date*      *type*  *remark*
  13239. Fluffy  1995-05-15  litter  4 kittens, 3 female, 1
  13240.                             male
  13241. Buffy   1993-06-23  litter  5 puppies, 2 female, 3
  13242.                             male
  13243. Buffy   1994-06-19  litter  3 puppies, 3 female
  13244. Chirpy  1999-03-21  vet     needed beak straightened
  13245. Slim    1997-08-03  vet     broken rib
  13246. Bowser  1991-10-12  kennel  
  13247. Fang    1991-10-12  kennel  
  13248. Fang    1998-08-28  birthdayGave him a new chew toy
  13249. Claws   1998-03-17  birthdayGave him a new flea
  13250.                             collar
  13251. Whistler1998-12-09  birthdayFirst birthday
  13252.  
  13253. Load the records like this:
  13254.  
  13255.      mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
  13256.  
  13257. Based on what you've learned from the queries you've run on the `pet'
  13258. table, you should be able to perform retrievals on the records in the
  13259. `event' table; the principles are the same.  But when is the `event'
  13260. table by itself insufficient to answer questions you might ask?
  13261.  
  13262. Suppose you want to find out the ages of each pet when they had their
  13263. litters.  The `event' table indicates when this occurred, but to
  13264. calculate the age of the mother, you need her birth date.  Because that
  13265. is stored in the `pet' table, you need both tables for the query:
  13266.  
  13267.      mysql> SELECT pet.name,
  13268.          -> (TO_DAYS(date) - TO_DAYS(birth))/365 AS age,
  13269.          -> remark
  13270.          -> FROM pet, event
  13271.          -> WHERE pet.name = event.name AND type = "litter";
  13272.      +--------+------+-----------------------------+
  13273.      | name   | age  | remark                      |
  13274.      +--------+------+-----------------------------+
  13275.      | Fluffy | 2.27 | 4 kittens, 3 female, 1 male |
  13276.      | Buffy  | 4.12 | 5 puppies, 2 female, 3 male |
  13277.      | Buffy  | 5.10 | 3 puppies, 3 female         |
  13278.      +--------+------+-----------------------------+
  13279.  
  13280. There are several things to note about this query:
  13281.  
  13282.    * The `FROM' clause lists two tables because the query needs to pull
  13283.      information from both of them.
  13284.  
  13285.    * When combining (joining) information from multiple tables, you
  13286.      need to specify how records in one table can be matched to records
  13287.      in the other.  This is easy because they both have a `name'
  13288.      column.  The query uses `WHERE' clause to match up records in the
  13289.      two tables based on the `name' values.
  13290.  
  13291.    * Because the `name' column occurs in both tables, you must be
  13292.      specific about which table you mean when referring to the column.
  13293.      This is done by prepending the table name to the column name.
  13294.  
  13295. You need not have two different tables to perform a join.  Sometimes it
  13296. is useful to join a table to itself, if you want to compare records in
  13297. a table to other records in that same table.  For example, to find
  13298. breeding pairs among your pets, you can join the `pet' table with
  13299. itself to pair up males and females of like species:
  13300.  
  13301.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  13302.          -> FROM pet AS p1, pet AS p2
  13303.          -> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
  13304.      +--------+------+--------+------+---------+
  13305.      | name   | sex  | name   | sex  | species |
  13306.      +--------+------+--------+------+---------+
  13307.      | Fluffy | f    | Claws  | m    | cat     |
  13308.      | Buffy  | f    | Fang   | m    | dog     |
  13309.      | Buffy  | f    | Bowser | m    | dog     |
  13310.      +--------+------+--------+------+---------+
  13311.  
  13312. In this query, we specify aliases for the table name in order to refer
  13313. to the columns and keep straight which instance of the table each
  13314. column reference is associated with.
  13315.  
  13316. Getting Information About Databases and Tables
  13317. ==============================================
  13318.  
  13319. What if you forget the name of a database or table, or what the
  13320. structure of a given table is (for example, what its columns are
  13321. called)?  MySQL addresses this problem through several statements that
  13322. provide information about the databases and tables it supports.
  13323.  
  13324. You have already seen `SHOW DATABASES', which lists the databases
  13325. managed by the server.  To find out which database is currently
  13326. selected, use the `DATABASE()' function:
  13327.  
  13328.      mysql> SELECT DATABASE();
  13329.      +------------+
  13330.      | DATABASE() |
  13331.      +------------+
  13332.      | menagerie  |
  13333.      +------------+
  13334.  
  13335. If you haven't selected any database yet, the result is blank.
  13336.  
  13337. To find out what tables the current database contains (for example, when
  13338. you're not sure about the name of a table), use this command:
  13339.  
  13340.      mysql> SHOW TABLES;
  13341.      +---------------------+
  13342.      | Tables in menagerie |
  13343.      +---------------------+
  13344.      | event               |
  13345.      | pet                 |
  13346.      +---------------------+
  13347.  
  13348. If you want to find out about the structure of a table, the `DESCRIBE'
  13349. command is useful; it displays information about each of a table's
  13350. columns:
  13351.  
  13352.      mysql> DESCRIBE pet;
  13353.      +---------+-------------+------+-----+---------+-------+
  13354.      | Field   | Type        | Null | Key | Default | Extra |
  13355.      +---------+-------------+------+-----+---------+-------+
  13356.      | name    | varchar(20) | YES  |     | NULL    |       |
  13357.      | owner   | varchar(20) | YES  |     | NULL    |       |
  13358.      | species | varchar(20) | YES  |     | NULL    |       |
  13359.      | sex     | char(1)     | YES  |     | NULL    |       |
  13360.      | birth   | date        | YES  |     | NULL    |       |
  13361.      | death   | date        | YES  |     | NULL    |       |
  13362.      +---------+-------------+------+-----+---------+-------+
  13363.  
  13364. `Field' indicates the column name, `Type' is the data type for the
  13365. column, `NULL' indicates whether the column can contain `NULL' values,
  13366. `Key' indicates whether the column is indexed, and `Default' specifies
  13367. the column's default value.
  13368.  
  13369. If you have indexes on a table, `SHOW INDEX FROM tbl_name' produces
  13370. information about them.
  13371.  
  13372. Examples of Common Queries
  13373. ==========================
  13374.  
  13375. Here are examples of how to solve some common problems with MySQL.
  13376.  
  13377. Some of the examples use the table `shop' to hold the price of each
  13378. article (item number) for certain traders (dealers).  Supposing that
  13379. each trader has a single fixed price per article, then (`article',
  13380. `dealer') is a primary key for the records.
  13381.  
  13382. Start the command-line tool `mysql' and select a database:
  13383.  
  13384.      mysql your-database-name
  13385.  
  13386. (In most MySQL installations, you can use the database-name 'test').
  13387.  
  13388. You can create the example table as:
  13389.  
  13390.      CREATE TABLE shop (
  13391.       article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  13392.       dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  13393.       price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  13394.       PRIMARY KEY(article, dealer));
  13395.      
  13396.      INSERT INTO shop VALUES
  13397.      (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
  13398.      (3,'D',1.25),(4,'D',19.95);
  13399.  
  13400. Okay, so the example data is:
  13401.  
  13402.      mysql> SELECT * FROM shop;
  13403.      
  13404.      +---------+--------+-------+
  13405.      | article | dealer | price |
  13406.      +---------+--------+-------+
  13407.      |    0001 | A      |  3.45 |
  13408.      |    0001 | B      |  3.99 |
  13409.      |    0002 | A      | 10.99 |
  13410.      |    0003 | B      |  1.45 |
  13411.      |    0003 | C      |  1.69 |
  13412.      |    0003 | D      |  1.25 |
  13413.      |    0004 | D      | 19.95 |
  13414.      +---------+--------+-------+
  13415.  
  13416. The Maximum Value for a Column
  13417. ------------------------------
  13418.  
  13419. "What's the highest item number?"
  13420.  
  13421.      SELECT MAX(article) AS article FROM shop
  13422.      
  13423.      +---------+
  13424.      | article |
  13425.      +---------+
  13426.      |       4 |
  13427.      +---------+
  13428.  
  13429. The Row Holding the Maximum of a Certain Column
  13430. -----------------------------------------------
  13431.  
  13432. "Find number, dealer, and price of the most expensive article."
  13433.  
  13434. In SQL-99 (and MySQL Version 4.1) this is easily done with a subquery:
  13435.  
  13436.      SELECT article, dealer, price
  13437.      FROM   shop
  13438.      WHERE  price=(SELECT MAX(price) FROM shop)
  13439.  
  13440. In MySQL versions prior to 4.1, just do it in two steps:
  13441.  
  13442.   1. Get the maximum price value from the table with a `SELECT'
  13443.      statement.
  13444.  
  13445.   2. Using this value compile the actual query:
  13446.           SELECT article, dealer, price
  13447.           FROM   shop
  13448.           WHERE  price=19.95
  13449.  
  13450. Another solution is to sort all rows descending by price and only get
  13451. the first row using the MySQL-specific `LIMIT' clause:
  13452.  
  13453.      SELECT article, dealer, price
  13454.      FROM   shop
  13455.      ORDER BY price DESC
  13456.      LIMIT 1
  13457.  
  13458. *NOTE*:  If there are several most expensive articles (for example,
  13459. each 19.95) the `LIMIT' solution shows only one of them!
  13460.  
  13461. Maximum of Column per Group
  13462. ---------------------------
  13463.  
  13464. "What's the highest price per article?"
  13465.  
  13466.      SELECT article, MAX(price) AS price
  13467.      FROM   shop
  13468.      GROUP BY article
  13469.      
  13470.      +---------+-------+
  13471.      | article | price |
  13472.      +---------+-------+
  13473.      |    0001 |  3.99 |
  13474.      |    0002 | 10.99 |
  13475.      |    0003 |  1.69 |
  13476.      |    0004 | 19.95 |
  13477.      +---------+-------+
  13478.  
  13479. The Rows Holding the Group-wise Maximum of a Certain Field
  13480. ----------------------------------------------------------
  13481.  
  13482. "For each article, find the dealer(s) with the most expensive price."
  13483.  
  13484. In SQL-99 (and MySQL Version 4.1 or greater), I'd do it with a subquery
  13485. like this:
  13486.  
  13487.      SELECT article, dealer, price
  13488.      FROM   shop s1
  13489.      WHERE  price=(SELECT MAX(s2.price)
  13490.                    FROM shop s2
  13491.                    WHERE s1.article = s2.article);
  13492.  
  13493. In MySQL versions prior to 4.1 it's best do it in several steps:
  13494.  
  13495.   1. Get the list of (article,maxprice).
  13496.  
  13497.   2. For each article get the corresponding rows that have the stored
  13498.      maximum price.
  13499.  
  13500. This can easily be done with a temporary table:
  13501.  
  13502.      CREATE TEMPORARY TABLE tmp (
  13503.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  13504.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  13505.      
  13506.      LOCK TABLES shop read;
  13507.      
  13508.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  13509.      
  13510.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  13511.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  13512.      
  13513.      UNLOCK TABLES;
  13514.      
  13515.      DROP TABLE tmp;
  13516.  
  13517. If you don't use a `TEMPORARY' table, you must also lock the 'tmp'
  13518. table.
  13519.  
  13520. "Can it be done with a single query?"
  13521.  
  13522. Yes, but only by using a quite inefficient trick that I call the
  13523. "MAX-CONCAT trick":
  13524.  
  13525.      SELECT article,
  13526.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  13527.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  13528.      FROM   shop
  13529.      GROUP BY article;
  13530.      
  13531.      +---------+--------+-------+
  13532.      | article | dealer | price |
  13533.      +---------+--------+-------+
  13534.      |    0001 | B      |  3.99 |
  13535.      |    0002 | A      | 10.99 |
  13536.      |    0003 | C      |  1.69 |
  13537.      |    0004 | D      | 19.95 |
  13538.      +---------+--------+-------+
  13539.  
  13540. The last example can, of course, be made a bit more efficient by doing
  13541. the splitting of the concatenated column in the client.
  13542.  
  13543. Using user variables
  13544. --------------------
  13545.  
  13546. You can use MySQL user variables to remember results without having to
  13547. store them in temporary variables in the client.  *Note Variables::.
  13548.  
  13549. For example, to find the articles with the highest and lowest price you
  13550. can do:
  13551.  
  13552.      mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
  13553.      mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
  13554.      +---------+--------+-------+
  13555.      | article | dealer | price |
  13556.      +---------+--------+-------+
  13557.      |    0003 | D      |  1.25 |
  13558.      |    0004 | D      | 19.95 |
  13559.      +---------+--------+-------+
  13560.  
  13561. Using Foreign Keys
  13562. ------------------
  13563.  
  13564. In MySQL 3.23.44 and up, `InnoDB' tables supports checking of foreign
  13565. key constraints. *Note InnoDB::.  See also *Note ANSI diff Foreign
  13566. Keys::.
  13567.  
  13568. You don't actually need foreign keys to join 2 tables.  The only thing
  13569. MySQL currently doesn't do (in table types other than `InnoDB'), is
  13570. `CHECK' to make sure that the keys you use really exist in the table(s)
  13571. you're referencing and it doesn't automatically delete rows from a
  13572. table with a foreign key definition. If you use your keys like normal,
  13573. it'll work just fine:
  13574.  
  13575.      CREATE TABLE person (
  13576.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  13577.          name CHAR(60) NOT NULL,
  13578.          PRIMARY KEY (id)
  13579.      );
  13580.      
  13581.      CREATE TABLE shirt (
  13582.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  13583.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  13584.          colour ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  13585.          owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),
  13586.          PRIMARY KEY (id)
  13587.      );
  13588.      
  13589.      
  13590.      INSERT INTO person VALUES (NULL, 'Antonio Paz');
  13591.      
  13592.      INSERT INTO shirt VALUES
  13593.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  13594.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  13595.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  13596.      
  13597.      
  13598.      INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
  13599.      
  13600.      INSERT INTO shirt VALUES
  13601.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  13602.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  13603.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  13604.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  13605.      
  13606.      
  13607.      SELECT * FROM person;
  13608.      +----+---------------------+
  13609.      | id | name                |
  13610.      +----+---------------------+
  13611.      |  1 | Antonio Paz         |
  13612.      |  2 | Lilliana Angelovska |
  13613.      +----+---------------------+
  13614.      
  13615.      SELECT * FROM shirt;
  13616.      +----+---------+--------+-------+
  13617.      | id | style   | colour | owner |
  13618.      +----+---------+--------+-------+
  13619.      |  1 | polo    | blue   |     1 |
  13620.      |  2 | dress   | white  |     1 |
  13621.      |  3 | t-shirt | blue   |     1 |
  13622.      |  4 | dress   | orange |     2 |
  13623.      |  5 | polo    | red    |     2 |
  13624.      |  6 | dress   | blue   |     2 |
  13625.      |  7 | t-shirt | white  |     2 |
  13626.      +----+---------+--------+-------+
  13627.      
  13628.      
  13629.      SELECT s.* FROM person p, shirt s
  13630.       WHERE p.name LIKE 'Lilliana%'
  13631.         AND s.owner = p.id
  13632.         AND s.colour <> 'white';
  13633.      
  13634.      +----+-------+--------+-------+
  13635.      | id | style | colour | owner |
  13636.      +----+-------+--------+-------+
  13637.      |  4 | dress | orange |     2 |
  13638.      |  5 | polo  | red    |     2 |
  13639.      |  6 | dress | blue   |     2 |
  13640.      +----+-------+--------+-------+
  13641.  
  13642. Searching on Two Keys
  13643. ---------------------
  13644.  
  13645. MySQL doesn't yet optimise when you search on two different keys
  13646. combined with `OR' (searching on one key with different `OR' parts is
  13647. optimised quite well):
  13648.  
  13649.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
  13650.      OR  field2_index = '1'
  13651.  
  13652. The reason is that we haven't yet had time to come up with an efficient
  13653. way to handle this in the general case. (The `AND' handling is, in
  13654. comparison, now completely general and works very well.)
  13655.  
  13656. For the moment you can solve this very efficiently by using a
  13657. `TEMPORARY' table. This type of optimisation is also very good if you
  13658. are using very complicated queries where the SQL server does the
  13659. optimisations in the wrong order.
  13660.  
  13661.      CREATE TEMPORARY TABLE tmp
  13662.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
  13663.      INSERT INTO tmp
  13664.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  13665.      SELECT * from tmp;
  13666.      DROP TABLE tmp;
  13667.  
  13668. The above way to solve this query is in effect a `UNION' of two queries.
  13669. *Note UNION::.
  13670.  
  13671. Calculating Visits Per Day
  13672. --------------------------
  13673.  
  13674. The following shows an idea of how you can use the bit group functions
  13675. to calculate the number of days per month a user has visited a web page.
  13676.  
  13677.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL,
  13678.                   day INT(2) UNSIGNED ZEROFILL);
  13679.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),
  13680.                  (2000,2,23),(2000,2,23);
  13681.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
  13682.             GROUP BY year,month;
  13683.      
  13684.      Which returns:
  13685.      
  13686.      +------+-------+------+
  13687.      | year | month | days |
  13688.      +------+-------+------+
  13689.      | 2000 |    01 |    3 |
  13690.      | 2000 |    02 |    2 |
  13691.      +------+-------+------+
  13692.  
  13693. The above calculates how many different days was used for a given
  13694. year/month combination, with automatic removal of duplicate entries.
  13695.  
  13696. Using `AUTO_INCREMENT'
  13697. ----------------------
  13698.  
  13699. The `AUTO_INCREMENT' attribute can be used to generate a unique
  13700. identity for new rows:
  13701.  
  13702.      CREATE TABLE animals (
  13703.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13704.                   name CHAR(30) NOT NULL,
  13705.                   PRIMARY KEY (id)
  13706.                   );
  13707.      INSERT INTO animals (name) VALUES ("dog"),("cat"),("penguin"),
  13708.                                        ("lax"),("whale");
  13709.      SELECT * FROM animals;
  13710.      
  13711.      Which returns:
  13712.      
  13713.      +----+---------+
  13714.      | id | name    |
  13715.      +----+---------+
  13716.      |  1 | dog     |
  13717.      |  2 | cat     |
  13718.      |  3 | penguin |
  13719.      |  4 | lax     |
  13720.      |  5 | whale   |
  13721.      +----+---------+
  13722.  
  13723. You can retrieve the used `AUTO_INCREMENT' key with the
  13724. `LAST_INSERT_ID()' SQL function or the `mysql_insert_id()' API function.
  13725. Note: for a multi-row insert, `LAST_INSERT_ID()'/`mysql_insert_id()'
  13726. will actually return the `AUTO_INCREMENT' key from the *first* inserted
  13727. row. This allows multi-row inserts to be reproduced on other servers.
  13728.  
  13729. For MyISAM and BDB tables you can specify `AUTO_INCREMENT' on secondary
  13730. column in a multi-column key.  In this case the generated value for the
  13731. autoincrement column is calculated as `MAX(auto_increment_column)+1)
  13732. WHERE prefix=given-prefix'.  This is useful when you want to put data
  13733. into ordered groups.
  13734.  
  13735.      CREATE TABLE animals (
  13736.                   grp ENUM('fish','mammal','bird') NOT NULL,
  13737.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13738.                   name CHAR(30) NOT NULL,
  13739.                   PRIMARY KEY (grp,id)
  13740.                   );
  13741.      INSERT INTO animals (grp,name) VALUES("mammal","dog"),("mammal","cat"),
  13742.                        ("bird","penguin"),("fish","lax"),("mammal","whale");
  13743.      SELECT * FROM animals ORDER BY grp,id;
  13744.      
  13745.      Which returns:
  13746.      
  13747.      +--------+----+---------+
  13748.      | grp    | id | name    |
  13749.      +--------+----+---------+
  13750.      | fish   |  1 | lax     |
  13751.      | mammal |  1 | dog     |
  13752.      | mammal |  2 | cat     |
  13753.      | mammal |  3 | whale   |
  13754.      | bird   |  1 | penguin |
  13755.      +--------+----+---------+
  13756.  
  13757. Note that in this case, the `AUTO_INCREMENT' value will be reused if you
  13758. delete the row with the biggest `AUTO_INCREMENT' value in any group.
  13759.  
  13760. Using `mysql' in Batch Mode
  13761. ===========================
  13762.  
  13763. In the previous sections, you used `mysql' interactively to enter
  13764. queries and view the results.  You can also run `mysql' in batch mode.
  13765. To do this, put the commands you want to run in a file, then tell
  13766. `mysql' to read its input from the file:
  13767.  
  13768.      shell> mysql < batch-file
  13769.  
  13770. If you are running `mysql' under Windows and have some special
  13771. characters in the file that causes problems, you can do:
  13772.  
  13773.      dos> mysql -e "source batch-file"
  13774.  
  13775. If you need to specify connection parameters on the command-line, the
  13776. command might look like this:
  13777.  
  13778.      shell> mysql -h host -u user -p < batch-file
  13779.      Enter password: ********
  13780.  
  13781. When you use `mysql' this way, you are creating a script file, then
  13782. executing the script.
  13783.  
  13784. If you want the script to continue even if you have errors, you should
  13785. use the `--force' command-line option.
  13786.  
  13787. Why use a script?  Here are a few reasons:
  13788.  
  13789.    * If you run a query repeatedly (say, every day or every week),
  13790.      making it a script allows you to avoid retyping it each time you
  13791.      execute it.
  13792.  
  13793.    * You can generate new queries from existing ones that are similar
  13794.      by copying and editing script files.
  13795.  
  13796.    * Batch mode can also be useful while you're developing a query,
  13797.      particularly for multiple-line commands or multiple-statement
  13798.      sequences of commands.  If you make a mistake, you don't have to
  13799.      retype everything.  Just edit your script to correct the error,
  13800.      then tell `mysql' to execute it again.
  13801.  
  13802.    * If you have a query that produces a lot of output, you can run the
  13803.      output through a pager rather than watching it scroll off the top
  13804.      of your screen:
  13805.  
  13806.           shell> mysql < batch-file | more
  13807.  
  13808.    * You can catch the output in a file for further processing:
  13809.  
  13810.           shell> mysql < batch-file > mysql.out
  13811.  
  13812.    * You can distribute your script to other people so they can run the
  13813.      commands, too.
  13814.  
  13815.    * Some situations do not allow for interactive use, for example,
  13816.      when you run a query from a `cron' job.  In this case, you must
  13817.      use batch mode.
  13818.  
  13819. The default output format is different (more concise) when you run
  13820. `mysql' in batch mode than when you use it interactively.  For example,
  13821. the output of `SELECT DISTINCT species FROM pet' looks like this when
  13822. run interactively:
  13823.  
  13824.      +---------+
  13825.      | species |
  13826.      +---------+
  13827.      | bird    |
  13828.      | cat     |
  13829.      | dog     |
  13830.      | hamster |
  13831.      | snake   |
  13832.      +---------+
  13833.  
  13834. But like this when run in batch mode:
  13835.  
  13836.      species
  13837.      bird
  13838.      cat
  13839.      dog
  13840.      hamster
  13841.      snake
  13842.  
  13843. If you want to get the interactive output format in batch mode, use
  13844. `mysql -t'.  To echo to the output the commands that are executed, use
  13845. `mysql -vvv'.
  13846.  
  13847. You can also use scripts in the `mysql' command-line prompt by using
  13848. the `source' command:
  13849.  
  13850.      mysql> source filename;
  13851.  
  13852. Queries from Twin Project
  13853. =========================
  13854.  
  13855. At Analytikerna and Lentus, we have been doing the systems and field
  13856. work for a big research project. This project is a collaboration
  13857. between the Institute of Environmental Medicine at Karolinska
  13858. Institutet Stockholm and the Section on Clinical Research in Aging and
  13859. Psychology at the University of Southern California.
  13860.  
  13861. The project involves a screening part where all twins in Sweden older
  13862. than 65 years are interviewed by telephone. Twins who meet certain
  13863. criteria are passed on to the next stage. In this latter stage, twins
  13864. who want to participate are visited by a doctor/nurse team. Some of the
  13865. examinations include physical and neuropsychological examination,
  13866. laboratory testing, neuroimaging, psychological status assessment, and
  13867. family history collection. In addition, data are collected on medical
  13868. and environmental risk factors.
  13869.  
  13870. More information about Twin studies can be found at:
  13871. `http://www.imm.ki.se/TWIN/TWINUKW.HTM'
  13872.  
  13873. The latter part of the project is administered with a web interface
  13874. written using Perl and MySQL.
  13875.  
  13876. Each night all data from the interviews is moved into a MySQL database.
  13877.  
  13878. Find all Non-distributed Twins
  13879. ------------------------------
  13880.  
  13881. The following query is used to determine who goes into the second part
  13882. of the project:
  13883.  
  13884.      SELECT
  13885.              CONCAT(p1.id, p1.tvab) + 0 AS tvid,
  13886.              CONCAT(p1.christian_name, " ", p1.surname) AS Name,
  13887.              p1.postal_code AS Code,
  13888.              p1.city AS City,
  13889.              pg.abrev AS Area,
  13890.              IF(td.participation = "Aborted", "A", " ") AS A,
  13891.              p1.dead AS dead1,
  13892.              l.event AS event1,
  13893.              td.suspect AS tsuspect1,
  13894.              id.suspect AS isuspect1,
  13895.              td.severe AS tsevere1,
  13896.              id.severe AS isevere1,
  13897.              p2.dead AS dead2,
  13898.              l2.event AS event2,
  13899.              h2.nurse AS nurse2,
  13900.              h2.doctor AS doctor2,
  13901.              td2.suspect AS tsuspect2,
  13902.              id2.suspect AS isuspect2,
  13903.              td2.severe AS tsevere2,
  13904.              id2.severe AS isevere2,
  13905.              l.finish_date
  13906.      FROM
  13907.              twin_project AS tp
  13908.              /* For Twin 1 */
  13909.              LEFT JOIN twin_data AS td ON tp.id = td.id
  13910.                        AND tp.tvab = td.tvab
  13911.              LEFT JOIN informant_data AS id ON tp.id = id.id
  13912.                        AND tp.tvab = id.tvab
  13913.              LEFT JOIN harmony AS h ON tp.id = h.id
  13914.                        AND tp.tvab = h.tvab
  13915.              LEFT JOIN lentus AS l ON tp.id = l.id
  13916.                        AND tp.tvab = l.tvab
  13917.              /* For Twin 2 */
  13918.              LEFT JOIN twin_data AS td2 ON p2.id = td2.id
  13919.                        AND p2.tvab = td2.tvab
  13920.              LEFT JOIN informant_data AS id2 ON p2.id = id2.id
  13921.                        AND p2.tvab = id2.tvab
  13922.              LEFT JOIN harmony AS h2 ON p2.id = h2.id
  13923.                        AND p2.tvab = h2.tvab
  13924.              LEFT JOIN lentus AS l2 ON p2.id = l2.id
  13925.                        AND p2.tvab = l2.tvab,
  13926.              person_data AS p1,
  13927.              person_data AS p2,
  13928.              postal_groups AS pg
  13929.      WHERE
  13930.              /* p1 gets main twin and p2 gets his/her twin. */
  13931.              /* ptvab is a field inverted from tvab */
  13932.              p1.id = tp.id AND p1.tvab = tp.tvab AND
  13933.              p2.id = p1.id AND p2.ptvab = p1.tvab AND
  13934.              /* Just the sceening survey */
  13935.              tp.survey_no = 5 AND
  13936.              /* Skip if partner died before 65 but allow emigration (dead=9) */
  13937.              (p2.dead = 0 OR p2.dead = 9 OR
  13938.               (p2.dead = 1 AND
  13939.                (p2.death_date = 0 OR
  13940.                 (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
  13941.                  >= 65))))
  13942.              AND
  13943.              (
  13944.              /* Twin is suspect */
  13945.              (td.future_contact = 'Yes' AND td.suspect = 2) OR
  13946.              /* Twin is suspect - Informant is Blessed */
  13947.              (td.future_contact = 'Yes' AND td.suspect = 1
  13948.                                         AND id.suspect = 1) OR
  13949.              /* No twin - Informant is Blessed */
  13950.              (ISNULL(td.suspect) AND id.suspect = 1
  13951.                                  AND id.future_contact = 'Yes') OR
  13952.              /* Twin broken off - Informant is Blessed */
  13953.              (td.participation = 'Aborted'
  13954.               AND id.suspect = 1 AND id.future_contact = 'Yes') OR
  13955.              /* Twin broken off - No inform - Have partner */
  13956.              (td.participation = 'Aborted' AND ISNULL(id.suspect)
  13957.                                            AND p2.dead = 0))
  13958.              AND
  13959.              l.event = 'Finished'
  13960.              /* Get at area code */
  13961.              AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
  13962.              /* Not already distributed */
  13963.              AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
  13964.              /* Has not refused or been aborted */
  13965.              AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
  13966.              OR h.status = 'Died' OR h.status = 'Other')
  13967.      ORDER BY
  13968.              tvid;
  13969.  
  13970. Some explanations:
  13971. `CONCAT(p1.id, p1.tvab) + 0 AS tvid'
  13972.      We want to sort on the concatenated `id' and `tvab' in numerical
  13973.      order. Adding `0' to the result causes MySQL to treat the result
  13974.      as a number.
  13975.  
  13976. column `id'
  13977.      This identifies a pair of twins. It is a key in all tables.
  13978.  
  13979. column `tvab'
  13980.      This identifies a twin in a pair. It has a value of `1' or `2'.
  13981.  
  13982. column `ptvab'
  13983.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  13984.      vice versa. It exists to save typing and to make it easier for
  13985.      MySQL to optimise the query.
  13986.  
  13987. This query demonstrates, among other things, how to do lookups on a
  13988. table from the same table with a join (`p1' and `p2'). In the example,
  13989. this is used to check whether a twin's partner died before the age of
  13990. 65. If so, the row is not returned.
  13991.  
  13992. All of the above exist in all tables with twin-related information. We
  13993. have a key on both `id,tvab' (all tables), and `id,ptvab'
  13994. (`person_data') to make queries faster.
  13995.  
  13996. On our production machine (A 200MHz UltraSPARC), this query returns
  13997. about 150-200 rows and takes less than one second.
  13998.  
  13999. The current number of records in the tables used above:
  14000. *Table*            *Rows*
  14001. `person_data'      71074
  14002. `lentus'           5291
  14003. `twin_project'     5286
  14004. `twin_data'        2012
  14005. `informant_data'   663
  14006. `harmony'          381
  14007. `postal_groups'    100
  14008.  
  14009. Show a Table on Twin Pair Status
  14010. --------------------------------
  14011.  
  14012. Each interview ends with a status code called `event'. The query shown
  14013. here is used to display a table over all twin pairs combined by event.
  14014. This indicates in how many pairs both twins are finished, in how many
  14015. pairs one twin is finished and the other refused, and so on.
  14016.  
  14017.      SELECT
  14018.              t1.event,
  14019.              t2.event,
  14020.              COUNT(*)
  14021.      FROM
  14022.              lentus AS t1,
  14023.              lentus AS t2,
  14024.              twin_project AS tp
  14025.      WHERE
  14026.              /* We are looking at one pair at a time */
  14027.              t1.id = tp.id
  14028.              AND t1.tvab=tp.tvab
  14029.              AND t1.id = t2.id
  14030.              /* Just the sceening survey */
  14031.              AND tp.survey_no = 5
  14032.              /* This makes each pair only appear once */
  14033.              AND t1.tvab='1' AND t2.tvab='2'
  14034.      GROUP BY
  14035.              t1.event, t2.event;
  14036.  
  14037. Using MySQL with Apache
  14038. =======================
  14039.  
  14040. There are programs that let you authenticate your users from a MySQL
  14041. database and also let you log your log files into a MySQL table.
  14042.  
  14043. You can change the Apache logging format to be easily readable by MySQL
  14044. by putting the following into the Apache configuration file:
  14045.  
  14046.      LogFormat \
  14047.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  14048.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  14049.  
  14050. In MySQL you can do a variation of:
  14051.  
  14052.      LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
  14053.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  14054.  
  14055. Database Administration
  14056. ***********************
  14057.  
  14058. Configuring MySQL
  14059. =================
  14060.  
  14061. `mysqld' Command-line Options
  14062. -----------------------------
  14063.  
  14064. In most cases you should manage `mysqld' options through option files.
  14065. *Note Option files::.
  14066.  
  14067. `mysqld' and `mysqld.server' read options from the `mysqld' and
  14068. `server' groups. `mysqld_safe' read options from the `mysqld',
  14069. `server', `mysqld_safe' and `safe_mysqld' groups.  An embedded MySQL
  14070. server usually reads options from the `server', `embedded' and
  14071. `xxxxx_SERVER', where `xxxxx' is the name of the application.
  14072.  
  14073. `mysqld' accepts a lot of command-line options. Here follows some of
  14074. the most common ones. For a full list execute `mysqld --help'.  Options
  14075. used for replication are listed in a separate section, see *Note
  14076. Replication Options::.
  14077.  
  14078. `--ansi'
  14079.      Use SQL-99 syntax instead of MySQL syntax.  *Note ANSI mode::.
  14080.  
  14081. `-b, --basedir=path'
  14082.      Path to installation directory. All paths are usually resolved
  14083.      relative to this.
  14084.  
  14085. `--big-tables'
  14086.      Allow big result sets by saving all temporary sets on file.  It
  14087.      solves most 'table full' errors, but also slows down the queries
  14088.      where in-memory tables would suffice.  Since Version 3.23.2, MySQL
  14089.      is able to solve it automatically by using memory for small
  14090.      temporary tables and switching to disk tables where necessary.
  14091.  
  14092. `--bind-address=IP'
  14093.      IP address to bind to.
  14094.  
  14095. `--console'
  14096.      Write the error log messages to stderr/stdout even if `--log-error'
  14097.      is specified.  On Windows, `mysqld' will not close the console
  14098.      screen if this option is used.
  14099.  
  14100. `--character-sets-dir=path'
  14101.      Directory where character sets are.  *Note Character sets::.
  14102.  
  14103. `--chroot=path'
  14104.      Put `mysqld' daemon in chroot environment at startup. Recommended
  14105.      security measure since MySQL 4.0 (MySQL 3.23 is not able to provide
  14106.      100% closed chroot jail).  It somewhat limits `LOAD DATA INFILE'
  14107.      and `SELECT ... INTO OUTFILE' though.
  14108.  
  14109. `--core-file'
  14110.      Write a core file if `mysqld' dies.  For some systems you must also
  14111.      specify `--core-file-size' to `mysqld_safe'.  *Note `mysqld_safe':
  14112.      mysqld_safe.  Note that on some systems, like Solaris, you will
  14113.      not get a core file if you are also using the `--user' option.
  14114.  
  14115. `-h, --datadir=path'
  14116.      Path to the database root.
  14117.  
  14118. `--debug[...]='
  14119.      If MySQL is configured with `--with-debug', you can use this
  14120.      option to get a trace file of what `mysqld' is doing.  *Note
  14121.      Making trace files::.
  14122.  
  14123. `--default-character-set=charset'
  14124.      Set the default character set.  *Note Character sets::.
  14125.  
  14126. `--default-table-type=type'
  14127.      Set the default table type for tables.  *Note Table types::.
  14128.  
  14129. `--delay-key-write[= OFF | ON | ALL]'
  14130.      How MyISAM `DELAYED KEYS' should be used. *Note Server
  14131.      parameters::.
  14132.  
  14133. `--delay-key-write-for-all-tables;  In MySQL 4.0.3 you should use --delay-key-write=ALL instead.'
  14134.      Don't flush key buffers between writes for any `MyISAM' table.
  14135.      *Note Server parameters::.
  14136.  
  14137. `--des-key-file=filename'
  14138.      Read the default keys used by `DES_ENCRYPT()' and `DES_DECRYPT()'
  14139.      from this file.
  14140.  
  14141. `--enable-external-locking (was --enable-locking)'
  14142.      Enable system locking.  Note that if you use this option on a
  14143.      system on which `lockd' does not fully work (as on Linux), you
  14144.      will easily get mysqld to deadlock.
  14145.  
  14146. `--enable-named-pipe'
  14147.      Enable support for named pipes (only on NT/Win2000/XP).
  14148.  
  14149. `-T, --exit-info'
  14150.      This is a bit mask of different flags one can use for debugging the
  14151.      mysqld server; one should not use this option if one doesn't know
  14152.      exactly what it does!
  14153.  
  14154. `--flush'
  14155.      Flush all changes to disk after each SQL command.  Normally MySQL
  14156.      only does a write of all changes to disk after each SQL command
  14157.      and lets the operating system handle the syncing to disk.  *Note
  14158.      Crashing::.
  14159.  
  14160. `-?, --help'
  14161.      Display short help and exit.
  14162.  
  14163. `--init-file=file'
  14164.      Read SQL commands from this file at startup.
  14165.  
  14166. `-L, --language=...'
  14167.      Client error messages in given language.  May be given as a full
  14168.      path.  *Note Languages::.
  14169.  
  14170. `-l, --log[=file]'
  14171.      Log connections and queries to file. *Note Query log::.
  14172.  
  14173. `--log-bin=[file]'
  14174.      Log all queries that change data to the file. Used for backup and
  14175.      replication.  *Note Binary log::.
  14176.  
  14177. `--log-bin-index[=file]'
  14178.      Index file for binary log file names. *Note Binary log::.
  14179.  
  14180. `--log-error[=file]'
  14181.      Log errors and startup messages to this file. *Note Error log::.
  14182.  
  14183. `--log-isam[=file]'
  14184.      Log all ISAM/MyISAM changes to file (only used when debugging
  14185.      ISAM/MyISAM).
  14186.  
  14187. `--log-slow-queries[=file]'
  14188.      Log all queries that have taken more than `long_query_time'
  14189.      seconds to execute to file.  *Note Slow query log::.
  14190.  
  14191. `--log-update[=file]'
  14192.      Log updates to `file.#' where `#' is a unique number if not given.
  14193.      *Note Update log::. The update log is deprecated and will be
  14194.      removed in MySQL 5.0; you should use the binary log instead
  14195.      (`--log-bin'). *Note Binary log::. Starting from version 5.0,
  14196.      using `--log-update' will just turn on the binlog instead.
  14197.  
  14198. `--log-long-format'
  14199.      Log some extra information to the update log.  If you are using
  14200.      `--log-slow-queries' then queries that are not using indexes are
  14201.      logged to the slow query log.
  14202.  
  14203. `--low-priority-updates'
  14204.      Table-modifying operations (`INSERT'/`DELETE'/`UPDATE') will have
  14205.      lower priority than selects.  It can also be done via `{INSERT |
  14206.      REPLACE | UPDATE | DELETE} LOW_PRIORITY ...' to lower the priority
  14207.      of only one query, or by `SET LOW_PRIORITY_UPDATES=1' to change
  14208.      the priority in one thread.  *Note Table locking::.
  14209.  
  14210. `--memlock'
  14211.      Lock the `mysqld' process in memory.  This works only if your
  14212.      system supports the `mlockall()' system call (like Solaris).  This
  14213.      may help if you have a problem where the operating system is
  14214.      causing `mysqld' to swap on disk.  Note that use of this option
  14215.      requires that you run the server as `root', which is normally not
  14216.      a good idea for security reasons.
  14217.  
  14218. `--myisam-recover [=option[,option...]]]'
  14219.      Option is any combination of `DEFAULT', `BACKUP', `FORCE' or
  14220.      `QUICK'.  You can also set this explicitly to `""' if you want to
  14221.      disable this option. If this option is used, `mysqld' will on open
  14222.      check if the table is marked as crashed or if the table wasn't
  14223.      closed properly.  (The last option only works if you are running
  14224.      with `--skip-external-locking'.)  If this is the case `mysqld'
  14225.      will run check on the table. If the table was corrupted, `mysqld'
  14226.      will attempt to repair it.
  14227.  
  14228.      The following options affects how the repair works.
  14229.  
  14230.      *Option*   *Description*
  14231.      DEFAULT    The same as not giving any option to
  14232.                          `--myisam-recover'.
  14233.      BACKUP     If the data table was changed during recover,
  14234.                 save a                     backup of the
  14235.                 `table_name.MYD' datafile as
  14236.                  `table_name-datetime.BAK'.
  14237.      FORCE      Run recover even if we will lose more than one
  14238.                 row                     from the .MYD file.
  14239.      QUICK      Don't check the rows in the table if there
  14240.                 aren't any                     delete blocks.
  14241.  
  14242.      Before a table is automatically repaired, MySQL will add a note
  14243.      about this in the error log.  If you want to be able to recover
  14244.      from most things without user intervention, you should use the
  14245.      options `BACKUP,FORCE'.  This will force a repair of a table even
  14246.      if some rows would be deleted, but it will keep the old datafile
  14247.      as a backup so that you can later examine what happened.
  14248.  
  14249. `--new'
  14250.      From version 4.0.12, the `--new' option can be used to make the
  14251.      server behave as 4.1 in certain aspects, easing a 4.0 to 4.1
  14252.      upgrade:
  14253.         * `TIMESTAMP' is returned as a string with the format
  14254.           `'YYYY-MM-DD HH:MM:SS''.  *Note Column types::.
  14255.  
  14256. `--pid-file=path'
  14257.      Path to pid file used by `mysqld_safe'.
  14258.  
  14259. `-P, --port=...'
  14260.      Port number to listen for TCP/IP connections.
  14261.  
  14262. `-o, --old-protocol'
  14263.      Use the 3.20 protocol for compatibility with some very old clients.
  14264.      *Note Upgrading-from-3.20::.
  14265.  
  14266. `--one-thread'
  14267.      Only use one thread (for debugging under Linux).  *Note Debugging
  14268.      server::.
  14269.  
  14270. `-O, --set-variable var=option'
  14271.      Give a variable a value. `--help' lists variables.  You can find a
  14272.      full description for all variables in the `SHOW VARIABLES' section
  14273.      in this manual.  *Note SHOW VARIABLES::.  The tuning server
  14274.      parameters section includes information of how to optimise these.
  14275.      Please note that `--set-variable' is deprecated since MySQL 4.0,
  14276.      just use `--var=option' on its own.  *Note Server parameters::.
  14277.  
  14278.      In MySQL 4.0.2 one can set a variable directly with
  14279.      `--variable-name=option' and `set-variable' is no longer needed in
  14280.      option files.
  14281.  
  14282.      If you want to restrict the maximum value a startup option can be
  14283.      set to with `SET', you can define this by using the
  14284.      `--maximum-variable-name' command line option. *Note SET OPTION::.
  14285.  
  14286.      Note that when setting a variable to a value, MySQL may
  14287.      automatically correct it to stay within a given range and also
  14288.      adjusts the value a little to fix for the used algorithm.
  14289.  
  14290. `--safe-mode'
  14291.      Skip some optimise stages.
  14292.  
  14293. `--safe-show-database'
  14294.      With this option, the `SHOW DATABASES' command returns only those
  14295.      databases for which the user has some kind of privilege.  From
  14296.      version 4.0.2 this option is deprecated and doesn't do anything
  14297.      (the option is enabled by default) as we now have the `SHOW
  14298.      DATABASES' privilege. *Note GRANT::.
  14299.  
  14300. `--safe-user-create'
  14301.      If this is enabled, a user can't create new users with the GRANT
  14302.      command, if the user doesn't have `INSERT' privilege to the
  14303.      `mysql.user' table or any column in this table.
  14304.  
  14305. `--skip-bdb'
  14306.      Disable usage of BDB tables. This will save memory and may speed
  14307.      up some things.
  14308.  
  14309. `--skip-concurrent-insert'
  14310.      Turn off the ability to select and insert at the same time on
  14311.      `MyISAM' tables. (This is only to be used if you think you have
  14312.      found a bug in this feature.)
  14313.  
  14314. `--skip-delay-key-write'
  14315.      In MySQL 4.0.3 you should use -delay-key-write=OFF instead.
  14316.      Ignore the `DELAY_KEY_WRITE' option for all tables.  *Note Server
  14317.      parameters::.
  14318.  
  14319. `--skip-grant-tables'
  14320.      This option causes the server not to use the privilege system at
  14321.      all.  This gives everyone *full access* to all databases!  (You
  14322.      can tell a running server to start using the grant tables again by
  14323.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  14324.  
  14325. `--skip-host-cache'
  14326.      Never use host name cache for faster name-ip resolution, but query
  14327.      DNS server on every connect instead.  *Note DNS::.
  14328.  
  14329. `--skip-innodb'
  14330.      Disable usage of Innodb tables.  This will save memory and disk
  14331.      space and speed up some things.
  14332.  
  14333. `--skip-external-locking (was --skip-locking)'
  14334.      Don't use system locking.  To use `isamchk' or `myisamchk' you must
  14335.      shut down the server.  *Note Stability::.  Note that in MySQL
  14336.      Version 3.23 you can use `REPAIR' and `CHECK' to repair/check
  14337.      `MyISAM' tables.
  14338.  
  14339. `--skip-name-resolve'
  14340.      Hostnames are not resolved.  All `Host' column values in the grant
  14341.      tables must be IP numbers or `localhost'.  *Note DNS::.
  14342.  
  14343. `--skip-networking'
  14344.      Don't listen for TCP/IP connections at all.  All interaction with
  14345.      `mysqld' must be made via named pipes or Unix sockets.  This
  14346.      option is highly recommended for systems where only local requests
  14347.      are allowed.  *Note DNS::.
  14348.  
  14349. `--skip-new'
  14350.      Don't use new, possibly wrong routines.
  14351.  
  14352. `--skip-symlink'
  14353.      Deprecated option in 4.0.13;  use `--skip-symbolic-links' instead.
  14354.  
  14355. `--symbolic-links, --skip-symbolic-links'
  14356.      Enable or disable symbolic link support. This option has different
  14357.      effects on Windows and Unix.
  14358.  
  14359.      On Windows, enabling symbolic links allows you to establish a
  14360.      symbolic link to a database directory by creating a
  14361.      `directory.sym' file that contains the path to the real directory.
  14362.      *Note Windows symbolic links::.
  14363.  
  14364.      On Unix, enabling symbolic links means that you can link a
  14365.      `MyISAM' index file or datafile to another directory with with the
  14366.      `INDEX DIRECTORY' or `DATA DIRECTORY' options of the `CREATE
  14367.      TABLE' statement.  If you delete or rename the table, the files
  14368.      that its symbolic links point to also will be deleted or renamed.
  14369.  
  14370. `--skip-safemalloc'
  14371.      If MySQL is configured with `--with-debug=full', all programs
  14372.      check memory for overruns for every memory allocation and memory
  14373.      freeing operations.  This checking is very slow, so for the server
  14374.      you can avoid it when you don't need it by using the
  14375.      `--skip-safemalloc' option.
  14376.  
  14377. `--skip-show-database'
  14378.      Don't allow the `SHOW DATABASES' command, unless the user has the
  14379.      `SHOW DATABASES' privilege. From version 4.0.2 on, you should no
  14380.      longer need this option, because access can now be granted
  14381.      specifically with the `SHOW DATABASES' privilege that was added in
  14382.      that version.
  14383.  
  14384. `--skip-stack-trace'
  14385.      Don't write stack traces.  This option is useful when you are
  14386.      running `mysqld' under a debugger. On some systems, you also must
  14387.      use this option to get a core file. *Note Debugging server::.
  14388.  
  14389. `--skip-thread-priority'
  14390.      Disable using thread priorities for faster response time.
  14391.  
  14392. `--socket=path'
  14393.      On Unix, the socket file to use for local connections (default
  14394.      `/tmp/mysql.sock').  On Windows, the pipe name to use for local
  14395.      connections that use a named pipe (default `MySql').
  14396.  
  14397. `--sql-mode=value[,value[,value...]]'
  14398.      The option values can be any combination of: `REAL_AS_FLOAT',
  14399.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  14400.      `ONLY_FULL_GROUP_BY', `NO_UNSIGNED_SUBTRACTION',
  14401.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', `NO_KEY_OPTIONS',
  14402.      `MYSQL323', `MYSQL40', `DB2', `MSSQL', `ORACLE', `POSTGRESQL',
  14403.      `SAPDB', or `ANSI'.  The value also can be empty (`--sql-mode=""')
  14404.      if you want to reset it.
  14405.  
  14406.      Several of the option values are used for compatibility with other
  14407.      servers.  If specified, they cause the server to omit from the
  14408.      output of `SHOW CREATE TABLE' those parts of the statement that
  14409.      are not understood by earlier versions of MySQL or other database
  14410.      servers.  Using these option values results in `CREATE TABLE'
  14411.      statements that are more portable for use with other servers:
  14412.  
  14413.         * The `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', and
  14414.           `NO_KEY_OPTIONS' values cause omission of table options, or
  14415.           options pertaining to column or index definitions.
  14416.  
  14417.         * The values `MYSQL323' and `MYSQL40' are for compatibility with
  14418.           MySQL 3.23 and MySQL 4.0.
  14419.  
  14420.         * The values used for compatibility with other servers are
  14421.           `DB2', `MSSQL', `ORACLE', `POSTGRESQL', and `SAPDB'.
  14422.  
  14423.  
  14424.      These options also affect the output of `mysqldump', because that
  14425.      program uses `SHOW CREATE TABLE' to obtain the table-creation
  14426.      statments that it includes in its own output.
  14427.  
  14428.      Several of the option values have a complex effect because they
  14429.      are shorthand for a group or set of values.  For example, you can
  14430.      tell the server to run in ANSI mode by using the `--sql-mode=ANSI'
  14431.      (or `--ansi') option, which is equivalent to specifying both of
  14432.      the following command-line options:
  14433.  
  14434.           --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  14435.           --transaction-isolation=SERIALIZABLE
  14436.  
  14437.      Note that specifying ANSI mode in this way also has the effect of
  14438.      setting the transaction isolation level.  For more information
  14439.      about running the server in ANSI mode, see *Note ANSI mode::.
  14440.  
  14441.      Other "group" values are `DB2', `MSSQL', `ORACLE', `POSTGRESQL',
  14442.      and `SAPDB'.  Specifying any of them turns on the
  14443.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  14444.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', and `NO_KEY_OPTIONS'
  14445.      values.
  14446.  
  14447.      The `--sql-mode' option was added in MySQL 3.23.41. The
  14448.      `NO_UNSIGNED_SUBTRACTION' value was added in 4.0.0. The
  14449.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', `NO_KEY_OPTIONS',
  14450.      `MYSQL323', `MYSQL40', `DB2', `MSSQL', `ORACLE', `POSTGRESQL',
  14451.      `SAPDB', and values were added in 4.1.1.  `ANSI' was added in
  14452.      4.1.1.
  14453.  
  14454. `--temp-pool'
  14455.      Using this option will cause most temporary files created by the
  14456.      server to use a small set of names, rather than a unique name for
  14457.      each new file. This is to work around a problem in the Linux kernel
  14458.      dealing with creating many new files with different names. With
  14459.      the old behaviour, Linux seems to "leak" memory, as it's being
  14460.      allocated to the directory entry cache rather than to the disk
  14461.      cache.
  14462.  
  14463. `--transaction-isolation={ READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE }'
  14464.      Sets the default transaction isolation level.  *Note `SET
  14465.      TRANSACTION': SET TRANSACTION.
  14466.  
  14467. `-t, --tmpdir=path'
  14468.      Path of the directory to use for creating temporary files. It may
  14469.      be useful if your default `/tmp' directory resides on a partition
  14470.      that is too small to hold temporary tables.  Starting from MySQL
  14471.      4.1, this option accepts several paths that are used in
  14472.      round-robin fashion. Paths should be separated by colon characters
  14473.      (`:') on Unix and semicolon characters (`;') on Windows.
  14474.  
  14475. `-u, --user={user_name | user_id}'
  14476.      Run the `mysqld' server as the user having the name `user_name' or
  14477.      numeric user ID `user_id'.  ("User" in this context refers to a
  14478.      system login account, not a MySQL user listed in the grant tables.)
  14479.  
  14480.      This option is *mandatory* when starting `mysqld' as `root'.  The
  14481.      server will change its user ID during its startup sequence,
  14482.      causing it to run as that particular user rather than as `root'.
  14483.      *Note Security::.
  14484.  
  14485.      Starting from MySQL 3.23.56 and 4.0.12: To avoid a possible
  14486.      security hole where a user adds a `--user=root' option to some
  14487.      `my.cnf' file (thus causing the server to run as `root'), `mysqld'
  14488.      uses only the first `--user' option specified and produces a
  14489.      warning if there are multiple `--user' options. Options in
  14490.      `/etc/my.cnf' and `datadir/my.cnf' are processed before
  14491.      command-line options, so it is recommended that you put a `--user'
  14492.      option in `/etc/my.cnf' and specify a value other than `root'. The
  14493.      option in `/etc/my.cnf' will be found before any other `--user'
  14494.      options, which ensures that the server runs as a user other than
  14495.      `root', and that a warning results if any other `--user' option is
  14496.      found.
  14497.  
  14498. `-V, --version'
  14499.      Display version information and exit.
  14500.  
  14501. `-W, --log-warnings'
  14502.      Print out warnings like `Aborted connection...' to the `.err'
  14503.      file. Enabling this option is recommended, for example, if you use
  14504.      replication (you will get more information about what is happening,
  14505.      such as messages about network failures and reconnections). *Note
  14506.      Communication errors::.
  14507.  
  14508.      This option used to be called `--warnings'.
  14509.  
  14510. You can change most values for a running server with the `SET' command.
  14511. *Note `SET OPTION': SET OPTION.
  14512.  
  14513. `my.cnf' Option Files
  14514. ---------------------
  14515.  
  14516. MySQL can, since Version 3.22, read default startup options for the
  14517. server and for clients from option files.
  14518.  
  14519. On Windows, MySQL reads default options from the following files:
  14520.  
  14521. *Filename*                *Purpose*
  14522. `windows-directory\my.ini'Global options
  14523. `C:\my.cnf'               Global options
  14524.  
  14525. `windows-directory' is the location of your Windows directory.
  14526.  
  14527. On Unix, MySQL reads default options from the following files:
  14528.  
  14529. *Filename*                *Purpose*
  14530. `/etc/my.cnf'             Global options
  14531. `DATADIR/my.cnf'          Server-specific options
  14532. `defaults-extra-file'     The file specified with
  14533.                           `--defaults-extra-file=path'
  14534. `~/.my.cnf'               User-specific options
  14535.  
  14536. `DATADIR' is the MySQL data directory (typically
  14537. `/usr/local/mysql/data' for a binary installation or `/usr/local/var'
  14538. for a source installation).  Note that this is the directory that was
  14539. specified at configuration time, not the one specified with `--datadir'
  14540. when `mysqld' starts up!  (`--datadir' has no effect on where the
  14541. server looks for option files, because the server looks for files
  14542. before it processes any command-line arguments.)
  14543.  
  14544. Note that on Windows you should specify all paths in option files with
  14545. `/' instead of `\'. If you use `\', you need to specify it twice,
  14546. because `\' is the escape character in MySQL.
  14547.  
  14548. MySQL tries to read option files in the order listed above.  If
  14549. multiple option files exist, an option specified in a file read later
  14550. takes precedence over the same option specified in a file read earlier.
  14551. Options specified on the command-line take precedence over options
  14552. specified in any option file.  Some options can be specified using
  14553. environment variables.  Options specified on the command-line or in
  14554. option files take precedence over environment variable values. *Note
  14555. Environment variables::.
  14556.  
  14557. The following programs support option files:  `mysql', `mysqladmin',
  14558. `mysqld', `mysqld_safe', `mysql.server', `mysqldump', `mysqlimport',
  14559. `mysqlshow', `mysqlcheck', `myisamchk', and `myisampack'.
  14560.  
  14561. Any long option that may be given on the command-line when running a
  14562. MySQL program can be given in an option file as well (without the
  14563. leading double dash).  Run the program with the `--help' option to get
  14564. a list of available options.
  14565.  
  14566. An option file can contain lines of the following forms:
  14567.  
  14568. `#comment'
  14569.      Comment lines start with `#' or `;'. Empty lines are ignored.
  14570.  
  14571. `[group]'
  14572.      `group' is the name of the program or group for which you want to
  14573.      set options.  After a group line, any `option' or `set-variable'
  14574.      lines apply to the named group until the end of the option file or
  14575.      another group line is given.
  14576.  
  14577. `option'
  14578.      This is equivalent to `--option' on the command-line.
  14579.  
  14580. `option=value'
  14581.      This is equivalent to `--option=value' on the command-line.
  14582.  
  14583. `set-variable = variable=value'
  14584.      This is equivalent to `--set-variable variable=value' on the
  14585.      command-line.  Please note that `--set-variable' is deprecated
  14586.      since MySQL 4.0; as of that version, program variable names can be
  14587.      used as option names.  On the command line, just use
  14588.      `--variable=value'. In an option file, use `variable=value'.
  14589.  
  14590. The `[client]' group allows you to specify options that apply to all
  14591. MySQL clients (not `mysqld'). This is the perfect group to use to
  14592. specify the password that you use to connect to the server.  (But make
  14593. sure the option file is readable and writable only by yourself.)
  14594.  
  14595. Note that for options and values, all leading and trailing blanks are
  14596. automatically deleted.  You may use the escape sequences `\b', `\t',
  14597. `\n', `\r', `\\', and `\s' in your value string (`\s' == blank).
  14598.  
  14599. Here is a typical global option file:
  14600.  
  14601.      [client]
  14602.      port=3306
  14603.      socket=/tmp/mysql.sock
  14604.      
  14605.      [mysqld]
  14606.      port=3306
  14607.      socket=/tmp/mysql.sock
  14608.      set-variable = key_buffer_size=16M
  14609.      set-variable = max_allowed_packet=1M
  14610.      
  14611.      [mysqldump]
  14612.      quick
  14613.  
  14614. Here is typical user option file:
  14615.  
  14616.      [client]
  14617.      # The following password will be sent to all standard MySQL clients
  14618.      password=my_password
  14619.      
  14620.      [mysql]
  14621.      no-auto-rehash
  14622.      set-variable = connect_timeout=2
  14623.      
  14624.      [mysqlhotcopy]
  14625.      interactive-timeout
  14626.  
  14627. If you have a source distribution, you will find sample configuration
  14628. files named `my-xxxx.cnf' in the `support-files' directory.  If you
  14629. have a binary distribution, look in the `DIR/support-files' directory,
  14630. where `DIR' is the pathname to the MySQL installation directory
  14631. (typically `C:\mysql' or `/usr/local/mysql').  Currently there are
  14632. sample configuration files for small, medium, large, and very large
  14633. systems.  You can copy `my-xxxx.cnf' to your home directory (rename the
  14634. copy to `.my.cnf') to experiment with this.
  14635.  
  14636. All MySQL programs that support option files support the following
  14637. options:
  14638.  
  14639. *Option*                         *Description*
  14640. `--no-defaults'                  Don't read any option files.
  14641. `--print-defaults'               Print the program name and all options
  14642.                                  that it will get.
  14643. `--defaults-file=full-path-to-default-file'Only use the given configuration file.
  14644. `--defaults-extra-file=full-path-to-default-file'Read this configuration file after the
  14645.                                  global configuration file but before
  14646.                                  the user configuration file.
  14647.  
  14648. Note that the options just shown must be first on the command line to
  14649. work, with the exception that `--print-defaults' may be used
  14650. immediately after `--defaults-file' or `--defaults-extra-file'.
  14651.  
  14652. Note for developers:  Option file handling is implemented simply by
  14653. processing all matching options (that is, options in the appropriate
  14654. group) before any command-line arguments. This works nicely for
  14655. programs that use the last instance of an option that is specified
  14656. multiple times. If you have an old program that handles multiply
  14657. specified options this way but doesn't read option files, you need add
  14658. only two lines to give it that capability.  Check the source code of
  14659. any of the standard MySQL clients to see how to do this.
  14660.  
  14661. In shell scripts, you can use the `my_print_defaults' command to parse
  14662. the option files. The following example shows the output that
  14663. `my_print_defaults' might produce when asked to show the options found
  14664. in the `[client]' and `[mysql]' groups:
  14665.  
  14666.  
  14667.      shell> my_print_defaults client mysql
  14668.      --port=3306
  14669.      --socket=/tmp/mysql.sock
  14670.      --no-auto-rehash
  14671.  
  14672. Running Multiple MySQL Servers on the Same Machine
  14673. --------------------------------------------------
  14674.  
  14675. In some cases you might want to run multiple `mysqld' servers on the
  14676. same machine.  For example, you might want to test a new MySQL release
  14677. while leaving your existing production setup undisturbed.  Or you may
  14678. want to give different users access to different `mysqld' servers that
  14679. they manage themselves.  (For example, you might be an Internet service
  14680. provider that wants to provide independent MySQL installations for
  14681. different customers.)
  14682.  
  14683. When you run multiple servers on a single machine, each server must have
  14684. unique values for several operating parameters. At least the following
  14685. options must be different for each server:
  14686.  
  14687.    * `--port=port_num'
  14688.  
  14689.    * `--socket=path'
  14690.  
  14691.    * `--shared-memory-base-name=name' (Windows only; new in MySQL 4.1)
  14692.  
  14693.    * `--pid-file=path' (Unix only)
  14694.  
  14695. `--port' controls the port number for TCP/IP connections.  `--socket'
  14696. controls the socket file path on Unix and the name of the named pipe on
  14697. Windows. (It's necessary to specify distinct pipe names on Windows only
  14698. for those servers that support named pipe connections.)
  14699. `--shared-memory-base-name' designates the shared memory name used by a
  14700. Windows server to allow clients to connect via shared memory.
  14701. `--pid-file' indicates the name of the file in which a Unix server
  14702. writes its process ID.
  14703.  
  14704. If you use the following options, they must be different for each
  14705. server:
  14706.  
  14707.    * `--log=path'
  14708.  
  14709.    * `--log-bin=path'
  14710.  
  14711.    * `--log-update=path'
  14712.  
  14713.    * `--log-error=path'
  14714.  
  14715.    * `--log-isam=path'
  14716.  
  14717.    * `--bdb-logdir=path'
  14718.  
  14719. If you want more performance, you can also specify the following options
  14720. differently for each server, to spread load between several physical
  14721. disks:
  14722.  
  14723.    * `--tmpdir=path'
  14724.  
  14725.    * `--bdb-tmpdir=path'
  14726.  
  14727. *Note Command-line options::.
  14728.  
  14729. Generally, each server should also use a different data directory,
  14730. which is specified using the `--datadir=path' option.
  14731.  
  14732. If you have multiple MySQL installations in different locations,
  14733. normally you can specify the base installation directory for each
  14734. server with the `--basedir=path' option to cause each server to use a
  14735. different data directory, log files, and PID file. (The defaults for
  14736. all these values are determined relative to the base directory.) In
  14737. that case, the only other options you need to specify are the
  14738. `--socket' and `--port' options.  For example, suppose you install
  14739. binary MySQL versions (`.tar' files) in different locations and start
  14740. them using the command `./bin/mysqld_safe' under the corresponding base
  14741. directory of each installation.  `mysqld_safe' will determine the proper
  14742. `--basedir' option to pass to `mysqld', and you need specify only the
  14743. `--socket' and `--port' options to `mysqld_safe'.
  14744.  
  14745. As discussed in the following sections, it is possible to start
  14746. additional servers by setting environment variables or by specifying
  14747. appropriate command-line options.  However, if you need to run multiple
  14748. servers on a more permanent basis, it will be more convenient to use
  14749. option files to specify for each server those option values that must
  14750. be unique to it.  *Note Option files::.
  14751.  
  14752. *Warning*: Normally you should never have two servers that update data
  14753. in the same databases!  If your OS doesn't support fault-free system
  14754. locking, this may lead to unpleasant surprises!  If (despite this
  14755. warning) you run multiple servers using the same data directory and
  14756. they have logging enabled, you must specify the names of the log files
  14757. using the appropriate options.  Otherwise, the servers may try to log
  14758. to the same files.
  14759.  
  14760. This warning against sharing a data directory among servers also applies
  14761. in an NFS environment.  Allowing several MySQL servers to access a
  14762. common data directory over NFS is a *bad idea*!
  14763.  
  14764.    * The primary problem is that NFS will become the speed bottleneck.
  14765.      It is not meant for such use.
  14766.  
  14767.    * You also will have to come up with a solution how to make sure
  14768.      that two or more servers do not interfere with each other. At the
  14769.      moment there is no platform that will 100% reliably do the file
  14770.      locking in every situation (usually this is handled by the `lockd'
  14771.      daemon).  Yet there would be one more possible risk with NFS; it
  14772.      would make the work even more complicated for `lockd' daemon to
  14773.      handle.
  14774.  
  14775.  
  14776. Make it easy for yourself: Forget about sharing a data directory among
  14777. servers over NFS. A better solution is to have one computer with an
  14778. operating system that efficiently handles threads and have several CPUs
  14779. in it.
  14780.  
  14781. Running Multiple Servers on Windows
  14782. ...................................
  14783.  
  14784. You can run multiple servers on Windows by starting them manually from
  14785. the command line, each with appropriate operating parameters. On
  14786. Windows NT-based systems, you also have the option of installing
  14787. several servers as services and running them that way. General
  14788. instructions for running MySQL servers from the command line or as
  14789. services are given in *Note Windows::. This section describes how to
  14790. make sure you start each server with different values for those startup
  14791. options that must be unique per server.
  14792.  
  14793. Starting Multiple Windows Servers at the Command Line
  14794. .....................................................
  14795.  
  14796. To start multiple servers manually from the command line, you can
  14797. specify the appropriate options on the command line or in an option
  14798. file. It's more convenient to place the options in an option file, but
  14799. it's necessary to make sure that each server gets its own set of
  14800. options. To do this, create an option file for each server and tell the
  14801. server the filename with a `--defaults-file' option when you run it.
  14802.  
  14803. Suppose you want to run `mysqld' on port 3307 with a data directory of
  14804. `C:\mydata1', and `mysqld-max' on port 3308 with a data directory of
  14805. `C:\mydata2'. To accomplish this, create two option files. For example,
  14806. create one file `C:\my-opts1.cnf' that looks like this:
  14807.  
  14808.      [mysqld]
  14809.      datadir = C:/mydata1
  14810.      port = 3307
  14811.  
  14812. Create a second file `C:\my-opts2.cnf' that looks like this:
  14813.  
  14814.      [mysqld]
  14815.      datadir = C:/mydata2
  14816.      port = 3308
  14817.  
  14818. Then start each server with its own option file:
  14819.  
  14820.      shell> mysqld --defaults-file=C:\my-opts1.cnf
  14821.      shell> mysqld-max --defaults-file=C:\my-opts2.cnf
  14822.  
  14823. (On NT, the servers will start in the foreground, so you'll need to
  14824. issue those two commands in separate console windows.)
  14825.  
  14826. To shut down the servers, you must connect to the appropriate port
  14827. number:
  14828.  
  14829.      shell> mysqladmin --port=3307 shutdown
  14830.      shell> mysqladmin --port=3308 shutdown
  14831.  
  14832. If you want to allow named pipe connections in addition to TCP/IP
  14833. connections, use the `mysqld-nt' or `mysqld-max-nt' servers and specify
  14834. options that enable the named pipe and specify its name. (Each server
  14835. must have a unique pipe name.)  For example, the `C:\my-opts1.cnf' file
  14836. might be written like this:
  14837.  
  14838.      [mysqld]
  14839.      datadir = C:/mydata1
  14840.      port = 3307
  14841.      enable-named-pipe
  14842.      socket = mypipe1
  14843.  
  14844. Then start the server this way:
  14845.  
  14846.      shell> mysqld-nt --defaults-file=C:\my-opts1.cnf
  14847.  
  14848. `C:\my-opts2.cnf' would be modified similarly.
  14849.  
  14850. Starting Multiple Windows Servers as Services
  14851. .............................................
  14852.  
  14853. On NT-based systems, you can install multiple servers as services.
  14854. (This is possible as of MySQL 4.0.2.) In this case, you must make sure
  14855. that each server uses a different service name in addition to all the
  14856. other parameters that must be unique per server.
  14857.  
  14858. For the following instructions, assume that you want to run `mysqld-nt'
  14859. servers from two different versions of MySQL that are installed at
  14860. `C:\mysql-4.0.8' and `C:\mysql-4.0.14', respectively. (This might be
  14861. the case if you're running 4.0.8 as your production server, but want to
  14862. test 4.0.14 before upgrading to it.)
  14863.  
  14864. The following principles are relevant when installing a MySQL service
  14865. with the `--install' (or `--install-manual') option:
  14866.  
  14867.    * If you specify no service name, the server uses the default
  14868.      service name of `MySql' and the server reads options from the
  14869.      `[mysqld]' group in the standard option files.
  14870.  
  14871.    * If you specify a service name after the `--install' option, the
  14872.      server ignores the `[mysqld]' option group and instead reads
  14873.      options from the group that has the same name as the service.
  14874.  
  14875.    * If you specify a `--defaults-file' option after the service name,
  14876.      the server ignores the standard option files and reads options
  14877.      only from the `[mysqld]' group of the named file.
  14878.  
  14879. These principles give you several ways to set up multiple services.
  14880. The following instructions describe some examples. Before trying any of
  14881. them, be sure you shut down and remove any existing MySQL services
  14882. first.
  14883.  
  14884.    * Specify the options for all services in one of the standard option
  14885.      files.  To do this, use the `[mysqld]' group for the server that
  14886.      is installed under the default service name (`MySql'). For other
  14887.      servers, use a group name that is the same as the service name.
  14888.      Suppose you want to run the 4.0.8 `mysqld-nt' using the default
  14889.      service name and the 4.0.14 `mysqld-nt' using the service name
  14890.      `mysqld2'.  In this case, you can use the `[mysqld]' group for
  14891.      4.0.8 and the `[mysqld2]' group for 4.0.14.  For example, you can
  14892.      set up `C:\my.cnf' like this:
  14893.  
  14894.           # options for default service (MySql)
  14895.           [mysqld]
  14896.           basedir = C:/mysql-4.0.8
  14897.           port = 3307
  14898.           enable-named-pipe
  14899.           socket = mypipe1
  14900.           
  14901.           # options for mysqld2 service
  14902.           [mysqld2]
  14903.           basedir = C:/mysql-4.0.14
  14904.           port = 3308
  14905.           enable-named-pipe
  14906.           socket = mypipe2
  14907.  
  14908.      Install the services like this:
  14909.  
  14910.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install
  14911.           shell> C:\mysql-4.0.14\bin\mysqld-nt --install mysqld2
  14912.  
  14913.      To start the services, use the services manager, or use `NET START'
  14914.      with the appropriate service names:
  14915.  
  14916.           shell> NET START MySql
  14917.           shell> NET START mysqld2
  14918.  
  14919.      To stop the services, use the services manager, or use `NET STOP'
  14920.      with the same service names.
  14921.  
  14922.    * Specify options for each server in separate files and use
  14923.      `--defaults-file' when you install the services to tell each server
  14924.      what file to use.  In this case, each file should list options
  14925.      using a `[mysqld]' group.
  14926.  
  14927.      With this approach, to specify options for the 4.0.8 `mysqld-nt',
  14928.      create a file `C:\my-opts1.cnf' that looks like this:
  14929.  
  14930.           [mysqld]
  14931.           basedir = C:/mysql-4.0.8
  14932.           port = 3307
  14933.           enable-named-pipe
  14934.           socket = mypipe1
  14935.  
  14936.      For the 4.0.14 `mysqld-nt', create a file `C:\my-opts2.cnf' that
  14937.      looks like this:
  14938.  
  14939.           [mysqld]
  14940.           basedir = C:/mysql-4.0.14
  14941.           port = 3308
  14942.           enable-named-pipe
  14943.           socket = mypipe2
  14944.  
  14945.      Install the services as follows (enter each command on a single
  14946.      line):
  14947.  
  14948.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install MySql
  14949.                      --defaults-file=C:\my-opts1.cnf
  14950.           shell> C:\mysql-4.0.14\bin\mysqld-nt --install mysqld2
  14951.                      --defaults-file=C:\my-opts2.cnf
  14952.  
  14953.      To use a `--defaults-file' option when you install a MySQL server
  14954.      as a service, you must precede the option with the service name.
  14955.      That is why the first command names the `MySql' service
  14956.      explicitly, even though that is the default service name.
  14957.  
  14958.      Start and stop the services the same way as in the preceding
  14959.      example.
  14960.  
  14961.  
  14962. To remove multiple services, use `mysqld --remove' for each one,
  14963. specifying a service name following the `--remove' option if the
  14964. service to remove has a name different than the default.
  14965.  
  14966. Running Multiple Servers on Unix
  14967. ................................
  14968.  
  14969. The easiest way is to run multiple servers on Unix is to compile them
  14970. with different TCP/IP ports and socket files so that each one is
  14971. listening on different network interfaces. Also, by compiling in
  14972. different base directories for each installation, that automatically
  14973. results in different compiled-in data directory, log file, and PID file
  14974. locations for each of your servers.
  14975.  
  14976. Assume an existing server is configured for the default port number and
  14977. socket file.  To configure a new server to have different operating
  14978. parameters, use a `configure' command something like this:
  14979.  
  14980.      shell> ./configure --with-tcp-port=port_number \
  14981.                   --with-unix-socket-path=file_name \
  14982.                   --prefix=/usr/local/mysql-4.0.14
  14983.  
  14984. Here `port_number' and `file_name' should be different from the default
  14985. port number and socket file pathname, and the `--prefix' value should
  14986. specify an installation directory different than the one under which
  14987. the existing MySQL installation is located.
  14988.  
  14989. If you have a MySQL server listening on a given port number, you can
  14990. use the following command to find out what operating parameters it is
  14991. using for several important configurable variables, including the base
  14992. directory and socket name:
  14993.  
  14994.      shell> mysqladmin --host=host_name --port=port_number variables
  14995.  
  14996. With the information displayed by that command, you can tell what option
  14997. values *not* to use when configuring an additional server.
  14998.  
  14999. Note that if you specify "`localhost'" as a hostname, `mysqladmin' will
  15000. default to using a Unix socket connection rather than TCP/IP.  In MySQL
  15001. 4.1, you can explicitly specify the connection protocol to use by using
  15002. the `--protocol={TCP | SOCKET | PIPE | MEMORY}' option.
  15003.  
  15004. You don't have to compile a new MySQL server just to start with a
  15005. different socket file and TCP/IP port number.  It is also possible to
  15006. specify those values at runtime. One way to do so is by using
  15007. command-line options:
  15008.  
  15009.      shell> /path/to/mysqld_safe --socket=file_name --port=port_number
  15010.  
  15011. To use another database directory for the second server, pass a
  15012. `--datadir=path' option to `mysqld_safe'.
  15013.  
  15014. Another way to achieve a similar effect is to use environment variables
  15015. to set the socket name and port number:
  15016.  
  15017.      shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
  15018.      shell> MYSQL_TCP_PORT=3307
  15019.      shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
  15020.      shell> scripts/mysql_install_db
  15021.      shell> bin/mysqld_safe &
  15022.  
  15023. This is a quick and dirty method for starting a second server to use
  15024. for testing.  The nice thing about this method is that the environment
  15025. variable settings will apply to any client programs that you invoke from
  15026. the above shell. Thus, connections for those clients automatically will
  15027. be directed to the second server!
  15028.  
  15029. *Note Environment variables:: includes a list of other environment
  15030. variables you can use to affect `mysqld'.
  15031.  
  15032. For automatic server execution, your startup script that is executed at
  15033. boot time should execute the following command once for each server
  15034. with an appropriate option file path for each command:
  15035.  
  15036.      mysqld_safe --defaults-file=path-to-option-file
  15037.  
  15038. Each option file should contain option values specific to a given
  15039. server.
  15040.  
  15041. On Unix, the `mysqld_multi' script is another way to start multiple
  15042. servers.  *Note `mysqld_multi': mysqld_multi.
  15043.  
  15044. Using Client Programs in a Multiple-Server Environment
  15045. ......................................................
  15046.  
  15047. When you want to connect with a client program to a MySQL server that is
  15048. listening to different network interfaces than those compiled into your
  15049. client, you can use one of the following methods:
  15050.  
  15051.    * Start the client with `--host=host_name --port=port_number' to
  15052.      connect via TCP/IP to a remote host, or with `--host=localhost
  15053.      --socket=file_name' to connect to a local host via a Unix socket
  15054.      or a Windows named pipe.
  15055.  
  15056.    * As of MySQL 4.1, start the client with `--protocol=tcp' to connect
  15057.      via TCP/IP, `--protocol=socket' to connect via a Unix socket,
  15058.      `--protocol=pipe' to connect via a named pipe, or
  15059.      `--protocol=memory' to connect via shared memory.  For TCP/IP
  15060.      connections, you may also need to specify `--host' and `--port'
  15061.      options.  For the other types of connections, you may need to
  15062.      specify a `--socket' option to specify a socket or named pipe
  15063.      name, or a `--shared-memory-base-name' option to specify the
  15064.      shared memory name.
  15065.  
  15066.    * On Unix, set the `MYSQL_UNIX_PORT' and `MYSQL_TCP_PORT'
  15067.      environment variables to point to the Unix socket and TCP/IP port
  15068.      before you start your clients.  If you normally use a specific
  15069.      socket or port, you can place commands to set these environment
  15070.      variables in your `.login' file so that they apply each time you
  15071.      log in.  *Note Environment variables::.
  15072.  
  15073.    * Specify the default socket and TCP/IP port in the `[client]' group
  15074.      of an option file. Foe example, you can use `C:\my.cnf' on
  15075.      Windows, or the `.my.cnf' file in your home directory on Unix.
  15076.      *Note Option files::.
  15077.  
  15078.    * In a C program, you can specify the port or socket arguments in the
  15079.      `mysql_real_connect()' call.  You can also have the program read
  15080.      option files by calling `mysql_options()'.  *Note C API
  15081.      functions::.
  15082.  
  15083.    * If you are using the Perl `DBD::mysql' module, you can read the
  15084.      options from the MySQL option files. For example:
  15085.  
  15086.           $dsn = "DBI:mysql:test;mysql_read_default_group=client;"
  15087.                   . "mysql_read_default_file=/usr/local/mysql/data/my.cnf";
  15088.           $dbh = DBI->connect($dsn, $user, $password);
  15089.  
  15090.      *Note Perl DBI Class::.
  15091.  
  15092.  
  15093. General Security Issues and the MySQL Access Privilege System
  15094. =============================================================
  15095.  
  15096. MySQL has an advanced but non-standard security/privilege system.  This
  15097. section describes how it works.
  15098.  
  15099. General Security Guidelines
  15100. ---------------------------
  15101.  
  15102. Anyone using MySQL on a computer connected to the Internet should read
  15103. this section to avoid the most common security mistakes.
  15104.  
  15105. In discussing security, we emphasise the necessity of fully protecting
  15106. the entire server host (not simply the MySQL server) against all types
  15107. of applicable attacks: eavesdropping, altering, playback, and denial of
  15108. service. We do not cover all aspects of availability and fault tolerance
  15109. here.
  15110.  
  15111. MySQL uses security based on Access Control Lists (ACLs) for all
  15112. connections, queries, and other operations that a user may attempt to
  15113. perform. There is also some support for SSL-encrypted connections
  15114. between MySQL clients and servers. Many of the concepts discussed here
  15115. are not specific to MySQL at all; the same general ideas apply to
  15116. almost all applications.
  15117.  
  15118. When running MySQL, follow these guidelines whenever possible:
  15119.  
  15120.    * *Do not ever give anyone (except the mysql `root' user) access to
  15121.      the `user' table in the `mysql' database!*  This is critical.
  15122.      *The encrypted password is the real password in MySQL.* Anyone who
  15123.      knows the password which is listed in the `user' table and has
  15124.      access to the host listed for the account *can easily log in as
  15125.      that user*.
  15126.  
  15127.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  15128.      commands are used for controlling access to MySQL. Do not grant
  15129.      any more privileges than necessary. Never grant privileges to all
  15130.      hosts.
  15131.  
  15132.      Checklist:
  15133.         - Try `mysql -u root'. If you are able to connect successfully
  15134.           to the server without being asked for a password, you have
  15135.           problems. Anyone can connect to your MySQL server as the MySQL
  15136.           `root' user with full privileges!  Review the MySQL
  15137.           installation instructions, paying particular attention to the
  15138.           item about setting a `root' password.
  15139.  
  15140.         - Use the command `SHOW GRANTS' and check to see who has access
  15141.           to what. Remove those privileges that are not necessary using
  15142.           the `REVOKE' command.
  15143.  
  15144.    * Do not keep any plain-text passwords in your database. When your
  15145.      computer becomes compromised, the intruder can take the full list
  15146.      of passwords and use them. Instead use `MD5()', `SHA1()' or
  15147.      another one-way hashing function.
  15148.  
  15149.    * Do not choose passwords from dictionaries. There are special
  15150.      programs to break them. Even passwords like "xfish98" are very
  15151.      bad.  Much better is "duag98" which contains the same word "fish"
  15152.      but typed one key to the left on a standard QWERTY keyboard.
  15153.      Another method is to use "Mhall" which is taken from the first
  15154.      characters of each word in the sentence "Mary had a little lamb."
  15155.      This is easy to remember and type, but difficult to guess for
  15156.      someone who does not know it.
  15157.  
  15158.    * Invest in a firewall. This protects you from at least 50% of all
  15159.      types of exploits in any software. Put MySQL behind the firewall
  15160.      or in a demilitarised zone (DMZ).
  15161.  
  15162.      Checklist:
  15163.         - Try to scan your ports from the Internet using a tool such as
  15164.           `nmap'. MySQL uses port 3306 by default. This port should be
  15165.           inaccessible from untrusted hosts. Another simple way to
  15166.           check whether or not your MySQL port is open is to try the
  15167.           following command from some remote machine, where
  15168.           `server_host' is the hostname of your MySQL server:
  15169.  
  15170.                shell> telnet server_host 3306
  15171.  
  15172.           If you get a connection and some garbage characters, the port
  15173.           is open, and should be closed on your firewall or router,
  15174.           unless you really have a good reason to keep it open. If
  15175.           `telnet' just hangs or the connection is refused, everything
  15176.           is OK; the port is blocked.
  15177.  
  15178.    * Do not trust any data entered by your users. They can try to trick
  15179.      your code by entering special or escaped character sequences in
  15180.      web forms, URLs, or whatever application you have built. Be sure
  15181.      that your application remains secure if a user enters something
  15182.      like "`; DROP DATABASE mysql;'". This is an extreme example, but
  15183.      large security leaks and data loss may occur as a result of
  15184.      hackers using similar techniques, if you do not prepare for them.
  15185.  
  15186.      Also remember to check numeric data. A common mistake is to
  15187.      protect only strings. Sometimes people think that if a database
  15188.      contains only publicly available data that it need not be
  15189.      protected. This is incorrect. At least denial-of-service type
  15190.      attacks can be performed on such databases. The simplest way to
  15191.      protect from this type of attack is to use apostrophes around the
  15192.      numeric constants: `SELECT * FROM table WHERE ID='234'' rather
  15193.      than `SELECT * FROM table WHERE ID=234'.  MySQL automatically
  15194.      converts this string to a number and strips all non-numeric
  15195.      symbols from it.
  15196.  
  15197.      Checklist:
  15198.         - All web applications:
  15199.              * Try to enter `'' and `"' in all your web forms. If you
  15200.                get any kind of MySQL error, investigate the problem
  15201.                right away.
  15202.  
  15203.              * Try to modify any dynamic URLs by adding `%22' (`"'),
  15204.                `%23' (`#'), and `%27' (`'') in the URL.
  15205.  
  15206.              * Try to modify datatypes in dynamic URLs from numeric
  15207.                ones to character ones containing characters from
  15208.                previous examples. Your application should be safe
  15209.                against this and similar attacks.
  15210.  
  15211.              * Try to enter characters, spaces, and special symbols
  15212.                instead of numbers in numeric fields. Your application
  15213.                should remove them before passing them to MySQL or your
  15214.                application should generate an error. Passing unchecked
  15215.                values to MySQL is very dangerous!
  15216.  
  15217.              * Check data sizes before passing them to MySQL.
  15218.  
  15219.              * Consider having your application connect to the database
  15220.                using a different user name than the one you use for
  15221.                administrative purposes. Do not give your applications
  15222.                any more access privileges than they need.
  15223.  
  15224.         - Users of PHP:
  15225.              * Check out the `addslashes()' function.  As of PHP 4.0.3,
  15226.                a `mysql_escape_string()' function is available that is
  15227.                based on the function of the same name in the MySQL C
  15228.                API.
  15229.  
  15230.         - Users of MySQL C API:
  15231.              * Check out the `mysql_real_escape_string()' API call.
  15232.  
  15233.         - Users of MySQL++:
  15234.              * Check out the `escape' and `quote' modifiers for query
  15235.                streams.
  15236.  
  15237.         - Users of Perl DBI:
  15238.              * Check out the `quote()' method or use placeholders.
  15239.  
  15240.         - Users of Java JDBC:
  15241.              * Use a `PreparedStatement' object and placeholders.
  15242.  
  15243.    * Do not transmit plain (unencrypted) data over the Internet. These
  15244.      data are accessible to everyone who has the time and ability to
  15245.      intercept it and use it for their own purposes. Instead, use an
  15246.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  15247.      connections as of Version 4.0.0.  SSH port-forwarding can be used
  15248.      to create an encrypted (and compressed) tunnel for the
  15249.      communication.
  15250.  
  15251.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  15252.      you can check whether MySQL data streams are unencrypted by
  15253.      issuing a command like the following:
  15254.  
  15255.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  15256.  
  15257.      (This works under Linux and should work with small modifications
  15258.      under other systems.)  Warning: If you do not see data this
  15259.      doesn't always actually mean that it is encrypted. If you need
  15260.      high security, you should consult with a security expert.
  15261.  
  15262. How to Make MySQL Secure Against Crackers
  15263. -----------------------------------------
  15264.  
  15265. When you connect to a MySQL server, you normally should use a password.
  15266. The password is not transmitted in clear text over the connection,
  15267. however the encryption algorithm is not very strong, and with some
  15268. effort a clever attacker can crack the password if he is able to sniff
  15269. the traffic between the client and the server. If the connection
  15270. between the client and the server goes through an untrusted network,
  15271. you should use an SSH tunnel to encrypt the communication.
  15272.  
  15273. All other information is transferred as text that can be read by anyone
  15274. who is able to watch the connection.  If you are concerned about this,
  15275. you can use the compressed protocol (in MySQL Version 3.22 and above)
  15276. to make things much harder.  To make things even more secure you should
  15277. use `ssh'.  You can find an `Open Source' `ssh' client at
  15278. `http://www.openssh.org/', and a commercial `ssh' client at
  15279. `http://www.ssh.com/'.  With this, you can get an encrypted TCP/IP
  15280. connection between a MySQL server and a MySQL client.
  15281.  
  15282. If you are using MySQL 4.0, you can also use internal OpenSSL support.
  15283. *Note Secure connections::.
  15284.  
  15285. To make a MySQL system secure, you should strongly consider the
  15286. following suggestions:
  15287.  
  15288.    * Use passwords for all MySQL users. Remember that anyone can log in
  15289.      as any other person as simply as `mysql -u other_user db_name' if
  15290.      `other_user' has no password.  It is common behaviour with
  15291.      client/server applications that the client may specify any user
  15292.      name.  You can change the password of all users by editing the
  15293.      `mysql_install_db' script before you run it, or only the password
  15294.      for the MySQL `root' user like this:
  15295.  
  15296.           shell> mysql -u root mysql
  15297.           mysql> UPDATE user SET Password=PASSWORD('new_password')
  15298.               ->             WHERE user='root';
  15299.           mysql> FLUSH PRIVILEGES;
  15300.  
  15301.    * Don't run the MySQL daemon as the Unix `root' user.  This is very
  15302.      dangerous, because any user with the `FILE' privilege will be able
  15303.      to create files as `root' (for example, `~root/.bashrc'). To
  15304.      prevent this, `mysqld' will refuse to run as `root' unless it is
  15305.      specified directly using a `--user=root' option.
  15306.  
  15307.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  15308.      can also create a new Unix user `mysql' to make everything even
  15309.      more secure.  If you run `mysqld' as another Unix user, you don't
  15310.      need to change the `root' user name in the `user' table, because
  15311.      MySQL user names have nothing to do with Unix user names.  To
  15312.      start `mysqld' as another Unix user, add a `user' line that
  15313.      specifies the user name to the `[mysqld]' group of the
  15314.      `/etc/my.cnf' option file or the `my.cnf' option file in the
  15315.      server's data directory. For example:
  15316.  
  15317.           [mysqld]
  15318.           user=mysql
  15319.  
  15320.      This will cause the server to start as the designated user whether
  15321.      you start it manually or by using `mysqld_safe' or `mysql.server'.
  15322.      For more details, see *Note Changing MySQL user::.
  15323.  
  15324.    * Don't support symlinks to tables (this can be disabled with the
  15325.      `--skip-symlink' option). This is especially important if you run
  15326.      `mysqld' as root as anyone that has write access to the mysqld data
  15327.      directories could then delete any file in the system!  *Note
  15328.      Symbolic links to tables::.
  15329.  
  15330.    * Check that the Unix user that `mysqld' runs as is the only user
  15331.      with read/write privileges in the database directories.
  15332.  
  15333.    * Don't give the `PROCESS' privilege to all users.  The output of
  15334.      `mysqladmin processlist' shows the text of the currently executing
  15335.      queries, so any user who is allowed to execute that command might
  15336.      be able to see if another user issues an `UPDATE user SET
  15337.      password=PASSWORD('not_secure')' query.
  15338.  
  15339.      `mysqld' reserves an extra connection for users who have the
  15340.      `PROCESS' privilege, so that a MySQL `root' user can log in and
  15341.      check things even if all normal connections are in use.
  15342.  
  15343.    * Don't give the `FILE' privilege to all users.  Any user that has
  15344.      this privilege can write a file anywhere in the filesystem with
  15345.      the privileges of the `mysqld' daemon!  To make this a bit safer,
  15346.      all files generated with `SELECT ... INTO OUTFILE' are writeable
  15347.      by everyone, and you cannot overwrite existing files.
  15348.  
  15349.      The `FILE' privilege may also be used to read any world readable
  15350.      file that is accessible to the Unix user that the server runs as.
  15351.      One can also read any file to the current database (which the user
  15352.      need some privilege for).  This could be abused, for example, by
  15353.      using `LOAD DATA' to load `/etc/passwd' into a table, which can
  15354.      then be read with `SELECT'.
  15355.  
  15356.    * If you don't trust your DNS, you should use IP numbers instead of
  15357.      hostnames in the grant tables. In any case, you should be very
  15358.      careful about creating grant table entries using hostname values
  15359.      that contain wildcards!
  15360.  
  15361.    * If you want to restrict the number of connections for a single
  15362.      user, you can do this by setting the `max_user_connections'
  15363.      variable in `mysqld'.
  15364.  
  15365. Startup Options for `mysqld' Concerning Security
  15366. ------------------------------------------------
  15367.  
  15368. The following `mysqld' options affect security:
  15369.  
  15370. `--local-infile[=(0|1)]'
  15371.      If one uses `--local-infile=0' then one can't use `LOAD DATA LOCAL
  15372.      INFILE'.
  15373.  
  15374. `--safe-show-database'
  15375.      With this option, the `SHOW DATABASES' command returns only those
  15376.      databases for which the user has some kind of privilege.  From
  15377.      version 4.0.2 this option is deprecated and doesn't do anything
  15378.      (the option is enabled by default) as we now have the `SHOW
  15379.      DATABASES' privilege. *Note GRANT::.
  15380.  
  15381. `--safe-user-create'
  15382.      If this is enabled, an user can't create new users with the `GRANT'
  15383.      command, if the user doesn't have the `INSERT' privilege for the
  15384.      `mysql.user' table.  If you want to give a user access to just
  15385.      create new users with those privileges that the user has right to
  15386.      grant, you should give the user the following privilege:
  15387.  
  15388.           mysql> GRANT INSERT(user) ON mysql.user TO 'user'@'hostname';
  15389.  
  15390.      This will ensure that the user can't change any privilege columns
  15391.      directly, but has to use the `GRANT' command to give privileges to
  15392.      other users.
  15393.  
  15394. `--skip-grant-tables'
  15395.      This option causes the server not to use the privilege system at
  15396.      all. This gives everyone *full access* to all databases!  (You can
  15397.      tell a running server to start using the grant tables again by
  15398.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  15399.  
  15400. `--skip-name-resolve'
  15401.      Hostnames are not resolved.  All `Host' column values in the grant
  15402.      tables must be IP numbers or `localhost'.
  15403.  
  15404. `--skip-networking'
  15405.      Don't allow TCP/IP connections over the network.  All connections
  15406.      to `mysqld' must be made via Unix sockets.  This option is
  15407.      unsuitable when using a MySQL version prior to 3.23.27 with the
  15408.      MIT-pthreads package, because Unix sockets were not supported by
  15409.      MIT-pthreads at that time.
  15410.  
  15411. `--skip-show-database'
  15412.      Don't allow `SHOW DATABASES' command, unless the user has the
  15413.      `SHOW DATABASES' privilege. From version 4.0.2 you should no longer
  15414.      need this option, since access can now be granted specifically
  15415.      with the `SHOW DATABASES' privilege.
  15416.  
  15417. Security issues with `LOAD DATA LOCAL'
  15418. --------------------------------------
  15419.  
  15420. In MySQL 3.23.49 and MySQL 4.0.2, we added some new options to deal with
  15421. possible security issues when it comes to `LOAD DATA LOCAL'.
  15422.  
  15423. There are two possible problems with supporting this command:
  15424.  
  15425. As the reading of the file is initiated from the server, one could
  15426. theoretically create a patched MySQL server that could read any file on
  15427. the client machine that the current user has read access to, when the
  15428. client issues a query against the table.
  15429.  
  15430. In a web environment where the clients are connecting from a web
  15431. server, a user could use `LOAD DATA LOCAL' to read any files that the
  15432. web server process has read access to (assuming a user could run any
  15433. command against the SQL server).
  15434.  
  15435. There are two separate fixes for this:
  15436.  
  15437. If you don't configure MySQL with `--enable-local-infile', then `LOAD
  15438. DATA LOCAL' will be disabled by all clients, unless one calls
  15439. `mysql_options(... MYSQL_OPT_LOCAL_INFILE, 0)' in the client.  *Note
  15440. `mysql_options()': mysql_options.
  15441.  
  15442. For the `mysql' command-line client, `LOAD DATA LOCAL' can be enabled
  15443. by specifying the option `--local-infile[=1]', or disabled with
  15444. `--local-infile=0'.
  15445.  
  15446. By default, all MySQL clients and libraries are compiled with
  15447. `--enable-local-infile', to be compatible with MySQL 3.23.48 and before.
  15448.  
  15449. One can disable all `LOAD DATA LOCAL' commands in the MySQL server by
  15450. starting `mysqld' with `--local-infile=0'.
  15451.  
  15452. In the case that `LOAD DATA LOCAL INFILE' is disabled in the server or
  15453. the client, you will get the error message (1148):
  15454.  
  15455.      The used command is not allowed with this MySQL version
  15456.  
  15457. What the Privilege System Does
  15458. ------------------------------
  15459.  
  15460. The primary function of the MySQL privilege system is to authenticate a
  15461. user connecting from a given host, and to associate that user with
  15462. privileges on a database such as `SELECT', `INSERT', `UPDATE' and
  15463. `DELETE'.
  15464.  
  15465. Additional functionality includes the ability to have an anonymous user
  15466. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  15467. INFILE' and administrative operations.
  15468.  
  15469. How the Privilege System Works
  15470. ------------------------------
  15471.  
  15472. The MySQL privilege system ensures that all users may do exactly the
  15473. things that they are supposed to be allowed to do.  When you connect to
  15474. a MySQL server, your identity is determined by *the host from which you
  15475. connect* and *the user name you specify*.  The system grants privileges
  15476. according to your identity and *what you want to do*.
  15477.  
  15478. MySQL considers both your hostname and user name in identifying you
  15479. because there is little reason to assume that a given user name belongs
  15480. to the same person everywhere on the Internet.  For example, the user
  15481. `joe' who connects from `office.com' need not be the same person as the
  15482. user `joe' who connects from `elsewhere.com'.  MySQL handles this by
  15483. allowing you to distinguish users on different hosts that happen to
  15484. have the same name:  you can grant `joe' one set of privileges for
  15485. connections from `office.com', and a different set of privileges for
  15486. connections from `elsewhere.com'.
  15487.  
  15488. MySQL access control involves two stages:
  15489.  
  15490.    * Stage 1: The server checks whether you are even allowed to connect.
  15491.  
  15492.    * Stage 2: Assuming you can connect, the server checks each request
  15493.      you issue to see whether you have sufficient privileges to perform
  15494.      it.  For example, if you try to select rows from a table in a
  15495.      database or drop a table from the database, the server makes sure
  15496.      you have the `SELECT' privilege for the table or the `DROP'
  15497.      privilege for the database.
  15498.  
  15499. Note that if your privileges are changed (either by yourself or someone
  15500. else) while you are connected, those changes will not necessarily take
  15501. effect with your next query or queries. See *Note Privilege changes::
  15502. for details.
  15503.  
  15504. The server uses the `user', `db', and `host' tables in the `mysql'
  15505. database at both stages of access control.  The fields in these grant
  15506. tables are shown here:
  15507.  
  15508. *Table name*   *user*         *db*           *host*
  15509. *Scope fields* `Host'         `Host'         `Host'
  15510.                `User'         `Db'           `Db'
  15511.                `Password'     `User'         
  15512. *Privilege     `Select_priv'  `Select_priv'  `Select_priv'
  15513. fields*                                      
  15514.                `Insert_priv'  `Insert_priv'  `Insert_priv'
  15515.                `Update_priv'  `Update_priv'  `Update_priv'
  15516.                `Delete_priv'  `Delete_priv'  `Delete_priv'
  15517.                `Index_priv'   `Index_priv'   `Index_priv'
  15518.                `Alter_priv'   `Alter_priv'   `Alter_priv'
  15519.                `Create_priv'  `Create_priv'  `Create_priv'
  15520.                `Drop_priv'    `Drop_priv'    `Drop_priv'
  15521.                `Grant_priv'   `Grant_priv'   `Grant_priv'
  15522.                `References_priv'               
  15523.                `Reload_priv'                 
  15524.                `Shutdown_priv'               
  15525.                `Process_priv'                
  15526.                `File_priv'                   
  15527.                `Show_db_priv'                
  15528.                `Super_priv'                  
  15529.                `Create_tmp_table_priv'`Create_tmp_table_priv'`Create_tmp_table_priv'
  15530.                `Lock_tables_priv'`Lock_tables_priv'`Lock_tables_priv'
  15531.                `Execute_priv'                
  15532.                `Repl_slave_priv'               
  15533.                `Repl_client_priv'               
  15534.                `ssl_type'                    
  15535.                `ssl_cypher'                  
  15536.                `x509_issuer'                 
  15537.                `x509_cubject'                
  15538.                `max_questions'               
  15539.                `max_updates'                 
  15540.                `max_connections'               
  15541.  
  15542. For the second stage of access control (request verification), the
  15543. server may, if the request involves tables, additionally consult the
  15544. `tables_priv' and `columns_priv' tables.  The fields in these tables
  15545. are shown here:
  15546.  
  15547. *Table name*   *tables_priv*  *columns_priv*
  15548. *Scope         `Host'         `Host'
  15549. fields*                       
  15550.                `Db'           `Db'
  15551.                `User'         `User'
  15552.                `Table_name'   `Table_name'
  15553.                               `Column_name'
  15554. *Privilege     `Table_priv'   `Column_priv'
  15555. fields*                       
  15556.                `Column_priv'  
  15557. *Other         `Timestamp'    `Timestamp'
  15558. fields*                       
  15559.                `Grantor'      
  15560.  
  15561. Each grant table contains scope fields and privilege fields.
  15562.  
  15563. Scope fields determine the scope of each entry in the tables, that is,
  15564. the context in which the entry applies.  For example, a `user' table
  15565. entry with `Host' and `User' values of `'thomas.loc.gov'' and `'bob''
  15566. would be used for authenticating connections made to the server by
  15567. `bob' from the host `thomas.loc.gov'.  Similarly, a `db' table entry
  15568. with `Host', `User', and `Db' fields of `'thomas.loc.gov'', `'bob'' and
  15569. `'reports'' would be used when `bob' connects from the host
  15570. `thomas.loc.gov' to access the `reports' database.  The `tables_priv'
  15571. and `columns_priv' tables contain scope fields indicating tables or
  15572. table/column combinations to which each entry applies.
  15573.  
  15574. For access-checking purposes, comparisons of `Host' values are
  15575. case-insensitive.  `User', `Password', `Db', and `Table_name' values
  15576. are case-sensitive.  `Column_name' values are case-insensitive in MySQL
  15577. Version 3.22.12 or later.
  15578.  
  15579. Privilege fields indicate the privileges granted by a table entry, that
  15580. is, what operations can be performed.  The server combines the
  15581. information in the various grant tables to form a complete description
  15582. of a user's privileges.  The rules used to do this are described in
  15583. *Note Request access::.
  15584.  
  15585. Scope fields are strings, declared as shown here; the default value for
  15586. each is the empty string:
  15587.  
  15588. *Field name*   *Type*      *Notes*
  15589. `Host'         `CHAR(60)'  
  15590. `User'         `CHAR(16)'  
  15591. `Password'     `CHAR(16)'  
  15592. `Db'           `CHAR(64)'  (`CHAR(60)' for the `tables_priv' and
  15593.                            `columns_priv' tables)
  15594. `Table_name'   `CHAR(60)'  
  15595. `Column_name'  `CHAR(60)'  
  15596.  
  15597. In the `user', `db' and `host' tables, all privilege fields are
  15598. declared as `ENUM('N','Y')'--each can have a value of `'N'' or `'Y'',
  15599. and the default value is `'N''.
  15600.  
  15601. In the `tables_priv' and `columns_priv' tables, the privilege fields
  15602. are declared as `SET' fields:
  15603.  
  15604. *Table      *Field      *Possible set elements*
  15605. name*       name*       
  15606. `tables_priv'`Table_priv'`'Select', 'Insert', 'Update',
  15607.                         'Delete', 'Create', 'Drop', 'Grant',
  15608.                         'References', 'Index', 'Alter''
  15609. `tables_priv'`Column_priv'`'Select', 'Insert', 'Update',
  15610.                         'References''
  15611. `columns_priv'`Column_priv'`'Select', 'Insert', 'Update',
  15612.                         'References''
  15613.  
  15614. Briefly, the server uses the grant tables like this:
  15615.  
  15616.    * The `user' table scope fields determine whether to allow or reject
  15617.      incoming connections.  For allowed connections, any privileges
  15618.      granted in the `user' table indicate the user's global (superuser)
  15619.      privileges.  These privileges apply to *all* databases on the
  15620.      server.
  15621.  
  15622.    * The `db' and `host' tables are used together:
  15623.  
  15624.         - The `db' table scope fields determine which users can access
  15625.           which databases from which hosts.  The privilege fields
  15626.           determine which operations are allowed.
  15627.  
  15628.         - The `host' table is used as an extension of the `db' table
  15629.           when you want a given `db' table entry to apply to several
  15630.           hosts.  For example, if you want a user to be able to use a
  15631.           database from several hosts in your network, leave the `Host'
  15632.           value empty in the user's `db' table entry, then populate the
  15633.           `host' table with an entry for each of those hosts.  This
  15634.           mechanism is described more detail in *Note Request access::.
  15635.  
  15636.    * The `tables_priv' and `columns_priv' tables are similar to the
  15637.      `db' table, but are more fine-grained: they apply at the table and
  15638.      column levels rather than at the database level.
  15639.  
  15640. Note that administrative privileges (`RELOAD', `SHUTDOWN', etc.) are
  15641. specified only in the `user' table.  This is because administrative
  15642. operations are operations on the server itself and are not
  15643. database-specific, so there is no reason to list such privileges in the
  15644. other grant tables.  In fact, only the `user' table need be consulted
  15645. to determine whether you can perform an administrative operation.
  15646.  
  15647. The `FILE' privilege is specified only in the `user' table, too.  It is
  15648. not an administrative privilege as such, but your ability to read or
  15649. write files on the server host is independent of the database you are
  15650. accessing.
  15651.  
  15652. The `mysqld' server reads the contents of the grant tables once, when it
  15653. starts up.  Changes to the grant tables take effect as indicated in
  15654. *Note Privilege changes::.
  15655.  
  15656. When you modify the contents of the grant tables, it is a good idea to
  15657. make sure that your changes set up privileges the way you want.  For
  15658. help in diagnosing problems, see *Note Access denied::.  For advice on
  15659. security issues, see *Note Security::.
  15660.  
  15661. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  15662. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  15663. with the `--help' option to find out how it works.  Note that
  15664. `mysqlaccess' checks access using only the `user', `db' and `host'
  15665. tables.  It does not check table- or column-level privileges.
  15666.  
  15667. Privileges Provided by MySQL
  15668. ----------------------------
  15669.  
  15670. Information about user privileges is stored in the `user', `db',
  15671. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  15672. database (that is, in the database named `mysql').  The MySQL server
  15673. reads the contents of these tables when it starts up and under the
  15674. circumstances indicated in *Note Privilege changes::.
  15675.  
  15676. The names used in this manual to refer to the privileges provided by
  15677. MySQL version 4.0.2 are shown here, along with the table column name
  15678. associated with each privilege in the grant tables and the context in
  15679. which the privilege applies:
  15680.  
  15681. *Privilege* *Column*       *Context*
  15682. `ALTER'     `Alter_priv'   tables
  15683. `DELETE'    `Delete_priv'  tables
  15684. `INDEX'     `Index_priv'   tables
  15685. `INSERT'    `Insert_priv'  tables
  15686. `SELECT'    `Select_priv'  tables
  15687. `UPDATE'    `Update_priv'  tables
  15688. `CREATE'    `Create_priv'  databases, tables, or
  15689.                            indexes
  15690. `DROP'      `Drop_priv'    databases or tables
  15691. `GRANT'     `Grant_priv'   databases or tables
  15692. `REFERENCES'`References_priv'databases or tables
  15693. `CREATE     `Create_tmp_table_priv'server administration
  15694. TEMPORARY                  
  15695. TABLES'                    
  15696. `EXECUTE'   `Execute_priv' server administration
  15697. `FILE'      `File_priv'    file access on server
  15698. `LOCK       `Lock_tables_priv'server administration
  15699. TABLES'                    
  15700. `PROCESS'   `Process_priv' server administration
  15701. `RELOAD'    `Reload_priv'  server administration
  15702. `REPLICATION`Repl_client_priv'server administration
  15703. CLIENT'                    
  15704. `REPLICATION`Repl_slave_priv'server administration
  15705. SLAVE'                     
  15706. `SHOW       `Show_db_priv' server administration
  15707. DATABASES'                 
  15708. `SHUTDOWN'  `Shutdown_priv'server administration
  15709. `SUPER'     `Super_priv'   server administration
  15710.  
  15711. The `SELECT', `INSERT', `UPDATE', and `DELETE' privileges allow you to
  15712. perform operations on rows in existing tables in a database.
  15713.  
  15714. `SELECT' statements require the `SELECT' privilege only if they
  15715. actually retrieve rows from a table.  You can execute certain `SELECT'
  15716. statements even without permission to access any of the databases on the
  15717. server.  For example, you could use the `mysql' client as a simple
  15718. calculator:
  15719.  
  15720.      mysql> SELECT 1+1;
  15721.      mysql> SELECT PI()*2;
  15722.  
  15723. The `INDEX' privilege allows you to create or drop (remove) indexes.
  15724.  
  15725. The `ALTER' privilege allows you to use `ALTER TABLE'.
  15726.  
  15727. The `CREATE' and `DROP' privileges allow you to create new databases
  15728. and tables, or to drop (remove) existing databases and tables.
  15729.  
  15730. Note that if you grant the `DROP' privilege for the `mysql' database to
  15731. a user, that user can drop the database in which the MySQL access
  15732. privileges are stored!
  15733.  
  15734. The `GRANT' privilege allows you to give to other users those
  15735. privileges you yourself possess.
  15736.  
  15737. The `FILE' privilege gives you permission to read and write files on
  15738. the server using the `LOAD DATA INFILE' and `SELECT ... INTO OUTFILE'
  15739. statements.  Any user to whom this privilege is granted can read any
  15740. world readable file accessable by the MySQL server and create a new
  15741. world readable file in any directory where the MySQL server can write.
  15742. The user can also read any file in the current database directory.  The
  15743. user can however not change any existing file.
  15744.  
  15745. The remaining privileges are used for administrative operations, which
  15746. are performed using the `mysqladmin' program.  The table here shows
  15747. which `mysqladmin' commands each administrative privilege allows you to
  15748. execute:
  15749.  
  15750. *Privilege* *Commands permitted to privilege holders*
  15751. `RELOAD'    `reload', `refresh', `flush-privileges',
  15752.             `flush-hosts', `flush-logs', and `flush-tables'
  15753. `SHUTDOWN'  `shutdown'
  15754. `PROCESS'   `processlist'
  15755. `SUPER'     `kill'
  15756.  
  15757. The `reload' command tells the server to re-read the grant tables.  The
  15758. `refresh' command flushes all tables and opens and closes the log
  15759. files.  `flush-privileges' is a synonym for `reload'.  The other
  15760. `flush-*' commands perform functions similar to `refresh' but are more
  15761. limited in scope, and may be preferable in some instances.  For example,
  15762. if you want to flush just the log files, `flush-logs' is a better choice
  15763. than `refresh'.
  15764.  
  15765. The `shutdown' command shuts down the server.
  15766.  
  15767. The `processlist' command displays information about the threads
  15768. executing within the server.  The `kill' command kills server threads.
  15769. You can always display or kill your own threads, but you need the
  15770. `PROCESS' privilege to display and `SUPER' privilege to kill threads
  15771. initiated by other users. *Note KILL::.
  15772.  
  15773. It is a good idea in general to grant privileges only to those users
  15774. who need them, but you should exercise particular caution in granting
  15775. certain privileges:
  15776.  
  15777.    * The `GRANT' privilege allows users to give away their privileges to
  15778.      other users.  Two users with different privileges and with the
  15779.      `GRANT' privilege are able to combine privileges.
  15780.  
  15781.    * The `ALTER' privilege may be used to subvert the privilege system
  15782.      by renaming tables.
  15783.  
  15784.    * The `FILE' privilege can be abused to read any world-readable file
  15785.      on the server or any file in the current database directory on the
  15786.      server into a database table, the contents of which can then be
  15787.      accessed using `SELECT'.
  15788.  
  15789.    * The `SHUTDOWN' privilege can be abused to deny service to other
  15790.      users entirely, by terminating the server.
  15791.  
  15792.    * The `PROCESS' privilege can be used to view the plain text of
  15793.      currently executing queries, including queries that set or change
  15794.      passwords.
  15795.  
  15796.    * Privileges on the `mysql' database can be used to change passwords
  15797.      and other access privilege information.  (Passwords are stored
  15798.      encrypted, so a malicious user cannot simply read them to know the
  15799.      plain text password.)  If they can access the `mysql.user' password
  15800.      column, they can use it to log into the MySQL server for the given
  15801.      user.  (With sufficient privileges, the same user can replace a
  15802.      password with a different one.)
  15803.  
  15804. There are some things that you cannot do with the MySQL privilege
  15805. system:
  15806.  
  15807.    * You cannot explicitly specify that a given user should be denied
  15808.      access.  That is, you cannot explicitly match a user and then
  15809.      refuse the connection.
  15810.  
  15811.    * You cannot specify that a user has privileges to create or drop
  15812.      tables in a database but not to create or drop the database itself.
  15813.  
  15814. Connecting to the MySQL Server
  15815. ------------------------------
  15816.  
  15817. MySQL client programs generally require that you specify connection
  15818. parameters when you want to access a MySQL server: the host you want to
  15819. connect to, your user name, and your password.  For example, the
  15820. `mysql' client can be started like this (optional arguments are enclosed
  15821. between `[' and `]'):
  15822.  
  15823.      shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
  15824.  
  15825. Alternate forms of the `-h', `-u', and `-p' options are
  15826. `--host=host_name', `--user=user_name', and `--password=your_pass'.
  15827. Note that there is _no space_ between `-p' or `--password=' and the
  15828. password following it.
  15829.  
  15830. *Note*: Specifying a password on the command-line is not secure!  Any
  15831. user on your system may then find out your password by typing a command
  15832. like: `ps auxww'.  *Note Option files::.
  15833.  
  15834. `mysql' uses default values for connection parameters that are missing
  15835. from the command-line:
  15836.  
  15837.    * The default hostname is `localhost'.
  15838.  
  15839.    * The default user name is your Unix login name.
  15840.  
  15841.    * No password is supplied if `-p' is missing.
  15842.  
  15843. Thus, for a Unix user `joe', the following commands are equivalent:
  15844.  
  15845.      shell> mysql -h localhost -u joe
  15846.      shell> mysql -h localhost
  15847.      shell> mysql -u joe
  15848.      shell> mysql
  15849.  
  15850. Other MySQL clients behave similarly.
  15851.  
  15852. On Unix systems, you can specify different default values to be used
  15853. when you make a connection, so that you need not enter them on the
  15854. command-line each time you invoke a client program.  This can be done
  15855. in a couple of ways:
  15856.  
  15857.    * You can specify connection parameters in the `[client]' section of
  15858.      the `.my.cnf' configuration file in your home directory.  The
  15859.      relevant section of the file might look like this:
  15860.  
  15861.           [client]
  15862.           host=host_name
  15863.           user=user_name
  15864.           password=your_pass
  15865.  
  15866.      *Note Option files::.
  15867.  
  15868.    * You can specify connection parameters using environment variables.
  15869.      The host can be specified for `mysql' using `MYSQL_HOST'.  The
  15870.      MySQL user name can be specified using `USER' (this is for Windows
  15871.      only).  The password can be specified using `MYSQL_PWD' (but this
  15872.      is insecure; see the next section).  *Note Environment variables::.
  15873.  
  15874. Access Control, Stage 1: Connection Verification
  15875. ------------------------------------------------
  15876.  
  15877. When you attempt to connect to a MySQL server, the server accepts or
  15878. rejects the connection based on your identity and whether you can
  15879. verify your identity by supplying the correct password.  If not, the
  15880. server denies access to you completely.  Otherwise, the server accepts
  15881. the connection, then enters Stage 2 and waits for requests.
  15882.  
  15883. Your identity is based on two pieces of information:
  15884.  
  15885.    * The host from which you connect
  15886.  
  15887.    * Your MySQL user name
  15888.  
  15889. Identity checking is performed using the three `user' table scope fields
  15890. (`Host', `User', and `Password').  The server accepts the connection
  15891. only if a `user' table entry matches your hostname and user name, and
  15892. you supply the correct password.
  15893.  
  15894. Values in the `user' table scope fields may be specified as follows:
  15895.  
  15896.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  15897.      to indicate the local host.
  15898.  
  15899.    * You can use the wildcard characters `%' and `_' in the `Host'
  15900.      field.
  15901.  
  15902.    * A `Host' value of `'%'' matches any hostname.
  15903.  
  15904.    * A blank `Host' value means that the privilege should be anded with
  15905.      the entry in the `host' table that matches the given host name.
  15906.      You can find more information about this in the next chapter.
  15907.  
  15908.    * As of MySQL Version 3.23, for `Host' values specified as IP
  15909.      numbers, you can specify a netmask indicating how many address
  15910.      bits to use for the network number. For example:
  15911.  
  15912.           mysql> GRANT ALL PRIVILEGES ON db.*
  15913.               -> TO david@'192.58.197.0/255.255.255.0';
  15914.  
  15915.      This will allow everyone to connect from an IP where the following
  15916.      is true:
  15917.  
  15918.           user_ip & netmask = host_ip.
  15919.  
  15920.      In the above example all IP:s in the interval 192.58.197.0 -
  15921.      192.58.197.255 can connect to the MySQL server.
  15922.  
  15923.    * Wildcard characters are not allowed in the `User' field, but you
  15924.      can specify a blank value, which matches any name.  If the `user'
  15925.      table entry that matches an incoming connection has a blank user
  15926.      name, the user is considered to be the anonymous user (the user
  15927.      with no name), rather than the name that the client actually
  15928.      specified.  This means that a blank user name is used for all
  15929.      further access checking for the duration of the connection (that
  15930.      is, during Stage 2).
  15931.  
  15932.    * The `Password' field can be blank.  This does not mean that any
  15933.      password matches, it means the user must connect without
  15934.      specifying a password.
  15935.  
  15936. Non-blank `Password' values represent encrypted passwords.  MySQL does
  15937. not store passwords in plaintext form for anyone to see.  Rather, the
  15938. password supplied by a user who is attempting to connect is encrypted
  15939. (using the `PASSWORD()' function). The encrypted password is then used
  15940. when the client/server is checking if the password is correct. (This is
  15941. done without the encrypted password ever traveling over the
  15942. connection.)  Note that from MySQL's point of view the encrypted
  15943. password is the REAL password, so you should not give anyone access to
  15944. it!  In particular, don't give normal users read access to the tables
  15945. in the `mysql' database!  From version 4.1, MySQL employs a different
  15946. password and login mechanism that is secure even if TCP/IP packets are
  15947. sniffed and/or the mysql database is captured.
  15948.  
  15949. The examples here show how various combinations of `Host' and `User'
  15950. values in `user' table entries apply to incoming connections:
  15951.  
  15952. `Host' *value*            `User'      *Connections matched by entry*
  15953.                           *value*     
  15954. `'thomas.loc.gov''        `'fred''    `fred', connecting from
  15955.                                       `thomas.loc.gov'
  15956. `'thomas.loc.gov''        `'''        Any user, connecting from
  15957.                                       `thomas.loc.gov'
  15958. `'%''                     `'fred''    `fred', connecting from any host
  15959. `'%''                     `'''        Any user, connecting from any host
  15960. `'%.loc.gov''             `'fred''    `fred', connecting from any host in
  15961.                                       the `loc.gov' domain
  15962. `'x.y.%''                 `'fred''    `fred', connecting from `x.y.net',
  15963.                                       `x.y.com',`x.y.edu', etc. (this is
  15964.                                       probably not useful)
  15965. `'144.155.166.177''       `'fred''    `fred', connecting from the host
  15966.                                       with IP address `144.155.166.177'
  15967. `'144.155.166.%''         `'fred''    `fred', connecting from any host in
  15968.                                       the `144.155.166' class C subnet
  15969. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  15970.  
  15971. Because you can use IP wildcard values in the `Host' field (for example,
  15972. `'144.155.166.%'' to match every host on a subnet), there is the
  15973. possibility that someone might try to exploit this capability by naming
  15974. a host `144.155.166.somewhere.com'.  To foil such attempts, MySQL
  15975. disallows matching on hostnames that start with digits and a dot. Thus,
  15976. if you have a host named something like `1.2.foo.com', its name will
  15977. never match the `Host' column of the grant tables.  Only an IP number
  15978. can match an IP wildcard value.
  15979.  
  15980. An incoming connection may be matched by more than one entry in the
  15981. `user' table.  For example, a connection from `thomas.loc.gov' by
  15982. `fred' would be matched by several of the entries just shown above.  How
  15983. does the server choose which entry to use if more than one matches?  The
  15984. server resolves this question by sorting the `user' table after reading
  15985. it at startup time, then looking through the entries in sorted order
  15986. when a user attempts to connect.  The first matching entry is the one
  15987. that is used.
  15988.  
  15989. `user' table sorting works as follows.  Suppose the `user' table looks
  15990. like this:
  15991.  
  15992.      +-----------+----------+-
  15993.      | Host      | User     | ...
  15994.      +-----------+----------+-
  15995.      | %         | root     | ...
  15996.      | %         | jeffrey  | ...
  15997.      | localhost | root     | ...
  15998.      | localhost |          | ...
  15999.      +-----------+----------+-
  16000.  
  16001. When the server reads in the table, it orders the entries with the
  16002. most-specific `Host' values first (`'%'' in the `Host' column means
  16003. "any host" and is least specific).  Entries with the same `Host' value
  16004. are ordered with the most-specific `User' values first (a blank `User'
  16005. value means "any user" and is least specific).  The resulting sorted
  16006. `user' table looks like this:
  16007.  
  16008.      +-----------+----------+-
  16009.      | Host      | User     | ...
  16010.      +-----------+----------+-
  16011.      | localhost | root     | ...
  16012.      | localhost |          | ...
  16013.      | %         | jeffrey  | ...
  16014.      | %         | root     | ...
  16015.      +-----------+----------+-
  16016.  
  16017. When a connection is attempted, the server looks through the sorted
  16018. entries and uses the first match found.  For a connection from
  16019. `localhost' by `jeffrey', the entries with `'localhost'' in the `Host'
  16020. column match first.  Of those, the entry with the blank user name
  16021. matches both the connecting hostname and user name.  (The
  16022. `'%'/'jeffrey'' entry would have matched, too, but it is not the first
  16023. match in the table.)
  16024.  
  16025. Here is another example.  Suppose the `user' table looks like this:
  16026.  
  16027.      +----------------+----------+-
  16028.      | Host           | User     | ...
  16029.      +----------------+----------+-
  16030.      | %              | jeffrey  | ...
  16031.      | thomas.loc.gov |          | ...
  16032.      +----------------+----------+-
  16033.  
  16034. The sorted table looks like this:
  16035.  
  16036.      +----------------+----------+-
  16037.      | Host           | User     | ...
  16038.      +----------------+----------+-
  16039.      | thomas.loc.gov |          | ...
  16040.      | %              | jeffrey  | ...
  16041.      +----------------+----------+-
  16042.  
  16043. A connection from `thomas.loc.gov' by `jeffrey' is matched by the first
  16044. entry, whereas a connection from `whitehouse.gov' by `jeffrey' is
  16045. matched by the second.
  16046.  
  16047. A common misconception is to think that for a given user name, all
  16048. entries that explicitly name that user will be used first when the
  16049. server attempts to find a match for the connection.  This is simply not
  16050. true.  The previous example illustrates this, where a connection from
  16051. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  16052. containing `'jeffrey'' as the `User' field value, but by the entry with
  16053. no user name!
  16054.  
  16055. If you have problems connecting to the server, print out the `user'
  16056. table and sort it by hand to see where the first match is being made.
  16057. If connection was successful, but your privileges are not what you
  16058. expected you may use `CURRENT_USER()' function (new in version 4.0.6)
  16059. to see what user/host combination your connection actually matched.
  16060. *Note `CURRENT_USER()': Miscellaneous functions.
  16061.  
  16062. Access Control, Stage 2: Request Verification
  16063. ---------------------------------------------
  16064.  
  16065. Once you establish a connection, the server enters Stage 2.  For each
  16066. request that comes in on the connection, the server checks whether you
  16067. have sufficient privileges to perform it, based on the type of
  16068. operation you wish to perform.  This is where the privilege fields in
  16069. the grant tables come into play.  These privileges can come from any of
  16070. the `user', `db', `host', `tables_priv', or `columns_priv' tables.  The
  16071. grant tables are manipulated with `GRANT' and `REVOKE' commands.  *Note
  16072. `GRANT': GRANT.  (You may find it helpful to refer to *Note
  16073. Privileges::, which lists the fields present in each of the grant
  16074. tables.)
  16075.  
  16076. The `user' table grants privileges that are assigned to you on a global
  16077. basis and that apply no matter what the current database is.  For
  16078. example, if the `user' table grants you the `DELETE' privilege, you can
  16079. delete rows from any database on the server host!  In other words,
  16080. `user' table privileges are superuser privileges.  It is wise to grant
  16081. privileges in the `user' table only to superusers such as server or
  16082. database administrators.  For other users, you should leave the
  16083. privileges in the `user' table set to `'N'' and grant privileges on a
  16084. database-specific basis only, using the `db' and `host' tables.
  16085.  
  16086. The `db' and `host' tables grant database-specific privileges.  Values
  16087. in the scope fields may be specified as follows:
  16088.  
  16089.    * The wildcard characters `%' and `_' can be used in the `Host' and
  16090.      `Db' fields of either table. If you wish to use for instance a `_'
  16091.      character as part of a database name, specify it as `\_' in the
  16092.      `GRANT' command.
  16093.  
  16094.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  16095.      `Host' value in the `db' table means "consult the `host' table for
  16096.      further information."
  16097.  
  16098.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  16099.  
  16100.    * A `'%'' or blank `Db' value in either table means "any database."
  16101.  
  16102.    * A blank `User' value in either table matches the anonymous user.
  16103.  
  16104. The `db' and `host' tables are read in and sorted when the server
  16105. starts up (at the same time that it reads the `user' table).  The `db'
  16106. table is sorted on the `Host', `Db', and `User' scope fields, and the
  16107. `host' table is sorted on the `Host' and `Db' scope fields.  As with
  16108. the `user' table, sorting puts the most-specific values first and
  16109. least-specific values last, and when the server looks for matching
  16110. entries, it uses the first match that it finds.
  16111.  
  16112. The `tables_priv' and `columns_priv' tables grant table- and
  16113. column-specific privileges.  Values in the scope fields may be
  16114. specified as follows:
  16115.  
  16116.    * The wildcard characters `%' and `_' can be used in the `Host'
  16117.      field of either table.
  16118.  
  16119.    * A `'%'' or blank `Host' value in either table means "any host."
  16120.  
  16121.    * The `Db', `Table_name' and `Column_name' fields cannot contain
  16122.      wildcards or be blank in either table.
  16123.  
  16124. The `tables_priv' and `columns_priv' tables are sorted on the `Host',
  16125. `Db', and `User' fields.  This is similar to `db' table sorting,
  16126. although the sorting is simpler because only the `Host' field may
  16127. contain wildcards.
  16128.  
  16129. The request verification process is described here.  (If you are
  16130. familiar with the access-checking source code, you will notice that the
  16131. description here differs slightly from the algorithm used in the code.
  16132. The description is equivalent to what the code actually does; it
  16133. differs only to make the explanation simpler.)
  16134.  
  16135. For administrative requests (`SHUTDOWN', `RELOAD', etc.), the server
  16136. checks only the `user' table entry, because that is the only table that
  16137. specifies administrative privileges.  Access is granted if the entry
  16138. allows the requested operation and denied otherwise.  For example, if
  16139. you want to execute `mysqladmin shutdown' but your `user' table entry
  16140. doesn't grant the `SHUTDOWN' privilege to you, access is denied without
  16141. even checking the `db' or `host' tables.  (They contain no
  16142. `Shutdown_priv' column, so there is no need to do so.)
  16143.  
  16144. For database-related requests (`INSERT', `UPDATE', etc.), the server
  16145. first checks the user's global (superuser) privileges by looking in the
  16146. `user' table entry.  If the entry allows the requested operation,
  16147. access is granted.  If the global privileges in the `user' table are
  16148. insufficient, the server determines the user's database-specific
  16149. privileges by checking the `db' and `host' tables:
  16150.  
  16151.   1. The server looks in the `db' table for a match on the `Host',
  16152.      `Db', and `User' fields.  The `Host' and `User' fields are matched
  16153.      to the connecting user's hostname and MySQL user name.  The `Db'
  16154.      field is matched to the database the user wants to access.  If
  16155.      there is no entry for the `Host' and `User', access is denied.
  16156.  
  16157.   2. If there is a matching `db' table entry and its `Host' field is
  16158.      not blank, that entry defines the user's database-specific
  16159.      privileges.
  16160.  
  16161.   3. If the matching `db' table entry's `Host' field is blank, it
  16162.      signifies that the `host' table enumerates which hosts should be
  16163.      allowed access to the database.  In this case, a further lookup is
  16164.      done in the `host' table to find a match on the `Host' and `Db'
  16165.      fields.  If no `host' table entry matches, access is denied.  If
  16166.      there is a match, the user's database-specific privileges are
  16167.      computed as the intersection (*not* the union!) of the privileges
  16168.      in the `db' and `host' table entries, that is, the privileges that
  16169.      are `'Y'' in both entries.  (This way you can grant general
  16170.      privileges in the `db' table entry and then selectively restrict
  16171.      them on a host-by-host basis using the `host' table entries.)
  16172.  
  16173. After determining the database-specific privileges granted by the `db'
  16174. and `host' table entries, the server adds them to the global privileges
  16175. granted by the `user' table.  If the result allows the requested
  16176. operation, access is granted.  Otherwise, the server checks the user's
  16177. table and column privileges in the `tables_priv' and `columns_priv'
  16178. tables and adds those to the user's privileges.  Access is allowed or
  16179. denied based on the result.
  16180.  
  16181. Expressed in boolean terms, the preceding description of how a user's
  16182. privileges are calculated may be summarised like this:
  16183.  
  16184.      global privileges
  16185.      OR (database privileges AND host privileges)
  16186.      OR table privileges
  16187.      OR column privileges
  16188.  
  16189. It may not be apparent why, if the global `user' entry privileges are
  16190. initially found to be insufficient for the requested operation, the
  16191. server adds those privileges to the database-, table-, and
  16192. column-specific privileges later. The reason is that a request might
  16193. require more than one type of privilege.  For example, if you execute
  16194. an `INSERT ...  SELECT' statement, you need both `INSERT' and `SELECT'
  16195. privileges.  Your privileges might be such that the `user' table entry
  16196. grants one privilege and the `db' table entry grants the other.  In
  16197. this case, you have the necessary privileges to perform the request,
  16198. but the server cannot tell that from either table by itself; the
  16199. privileges granted by the entries in both tables must be combined.
  16200.  
  16201. The `host' table can be used to maintain a list of secure servers.
  16202.  
  16203. At TcX, the `host' table contains a list of all machines on the local
  16204. network. These are granted all privileges.
  16205.  
  16206. You can also use the `host' table to indicate hosts that are *not*
  16207. secure.  Suppose you have a machine `public.your.domain' that is located
  16208. in a public area that you do not consider secure.  You can allow access
  16209. to all hosts on your network except that machine by using `host' table
  16210. entries like this:
  16211.  
  16212.      +--------------------+----+-
  16213.      | Host               | Db | ...
  16214.      +--------------------+----+-
  16215.      | public.your.domain | %  | ... (all privileges set to 'N')
  16216.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  16217.      +--------------------+----+-
  16218.  
  16219. Naturally, you should always test your entries in the grant tables (for
  16220. example, using `mysqlaccess') to make sure your access privileges are
  16221. actually set up the way you think they are.
  16222.  
  16223. Password Hashing in MySQL 4.1
  16224. -----------------------------
  16225.  
  16226. MySQL user accounts are listed in the `user' table of the `mysql'
  16227. database. Each MySQL account is assigned a password, although what is
  16228. stored in the `Password' column of the `user' table is not the
  16229. plaintext version of the password, but a hash value computed from it.
  16230. Password hash values are computed by the `PASSWORD()' function.
  16231.  
  16232. MySQL uses passwords in two phases of client/server communication:
  16233.  
  16234.    * First, when a client attempts to connect to the server, there is an
  16235.      initial authentication step in which the client must present a
  16236.      password that matches the hash value stored in the user table for
  16237.      the account that the client wants to use.
  16238.  
  16239.    * Second, after the client connects, it may set or change the
  16240.      password hashes for accounts listed in the user table (if it has
  16241.      sufficient privileges). The client may do this by using the
  16242.      PASSWORD() function to generate a password hash, or by using the
  16243.      GRANT or SET PASSWORD statements.
  16244.  
  16245.  
  16246. In other words, the server _uses_ hash values during authentication when
  16247. a client first attempts to connect. The server _generates_ hash values
  16248. if a connected client invokes the `PASSWORD()' function or uses a
  16249. `GRANT' or `SET PASSWORD' statement to set or change a password.
  16250.  
  16251. The password hashing mechanism was updated in MySQL 4.1 to provide
  16252. better security and to reduce the risk of passwords being stolen.
  16253. However, this new mechanism is understood only by the 4.1 server and
  16254. 4.1 clients, which can result in some compatibility problems.  A 4.1
  16255. client can connect to a pre-4.1 server, because the client understands
  16256. both the old and new password hashing mechanisms. However, a pre-4.1
  16257. client that attempts to connect to a 4.1 server may run into
  16258. difficulties.  For example, a 4.0 `mysql' client that attempts to
  16259. connect to a 4.1 server may fail with the following error message:
  16260.  
  16261.      shell> mysql
  16262.      Client does not support authentication protocol requested
  16263.      by server; consider upgrading MySQL client
  16264.  
  16265. The following discussion describes the differences between the old and
  16266. new password mechanisms, and what you should do if you upgrade your
  16267. server to 4.1 but need to maintain backward compatibility with pre-4.1
  16268. clients.
  16269.  
  16270. *Note:* This discussion contrasts 4.1 behaviour with pre-4.1 behaviour,
  16271. but the 4.1 behaviour described here actually begins with 4.1.1. MySQL
  16272. 4.1.0 is an "odd" release because it has a slightly different mechanism
  16273. than that implemented in 4.1.1 and up.  Differences between 4.1.0 and
  16274. more recent versions are described later.
  16275.  
  16276. Prior to MySQL 4.1, password hashes computed by the `PASSWORD()'
  16277. function are 16 bytes long.  Such hashes look like this:
  16278.  
  16279.      mysql> SELECT PASSWORD('mypass');
  16280.      +--------------------+
  16281.      | PASSWORD('mypass') |
  16282.      +--------------------+
  16283.      | 6f8c114b58f2ce9e   |
  16284.      +--------------------+
  16285.  
  16286. The `Password' column of the `user' table (in which these hashes are
  16287. stored) also is 16 bytes long before MySQL 4.1.
  16288.  
  16289. As of MySQL 4.1, the `PASSWORD()' function has been modified to produce
  16290. a longer 41-byte hash value:
  16291.  
  16292.      mysql> SELECT PASSWORD('mypass');
  16293.      +-----------------------------------------------+
  16294.      | PASSWORD('mypass')                            |
  16295.      +-----------------------------------------------+
  16296.      | *43c8aa34cdc98eddd3de1fe9a9c2c2a9f92bb2098d75 |
  16297.      +-----------------------------------------------+
  16298.  
  16299. Accordingly, the `Password' column in the `user' table also must be 41
  16300. bytes long to store these values:
  16301.  
  16302.    * If you perform a new installation of MySQL 4.1, the `Password'
  16303.      column will be made 41 bytes long automatically.
  16304.  
  16305.    * If you upgrade an older installation to 4.1, you should run the
  16306.      `mysql_fix_privilege_tables' script to update the length of the
  16307.      `Password' column from 16 to 41 bytes. (The script does not change
  16308.      existing password values, which remain 16 bytes long.)
  16309.  
  16310.  
  16311. A widened `Password' column can store password hashes in both the old
  16312. and new formats. The format of any given password hash value can be
  16313. determined two ways:
  16314.  
  16315.    * The obvious difference is the length (16 bytes versus 41 bytes)
  16316.  
  16317.    * A second difference is that password hashes in the new format
  16318.      always begin with a `*' character, whereas passwords in the old
  16319.      format never do
  16320.  
  16321.  
  16322. The longer password hash format has better cryptographic properties, and
  16323. client authentication based on long hashes is more secure than that
  16324. based on the older short hashes.
  16325.  
  16326. The differences between short and long password hashes are relevant
  16327. both for how the server uses passwords during authentication and for
  16328. how it generates password hashes for connected clients that perform
  16329. password-changing operations.
  16330.  
  16331. The way in which the server uses password hashes during authentication
  16332. is affected by the width of the Password column:
  16333.  
  16334.    * If the column is narrow, only short-hash authentication is used.
  16335.  
  16336.    * If the column is wide, it can hold either short or long hashes, and
  16337.      the server can use either format:
  16338.  
  16339.         * Pre-4.1 clients can connect, though because they know only
  16340.           about the old hashing mechanism, they can authenticate only
  16341.           for accounts that have short hashes.
  16342.  
  16343.         * 4.1 clients can authenticate for accounts that have short or
  16344.           long hashes.
  16345.  
  16346.  
  16347.  
  16348. For short-hash accounts, the authentication process is actually a bit
  16349. more secure for 4.1 clients than for older clients.  In terms of
  16350. security, the gradient from least to most secure is:
  16351.  
  16352.    * Pre-4.1 client authenticating for account with short password hash
  16353.  
  16354.    * 4.1 client authenticating for account with short password hash
  16355.  
  16356.    * 4.1 client authenticating for account with long password hash
  16357.  
  16358.  
  16359. The way in which the server generates password hashes for connected
  16360. clients is affected by the width of the `Password' column and by the
  16361. `--old-passwords' option.  A 4.1 server generates long hashes only if
  16362. certain conditions are met: The `Password' column must be wide enough
  16363. to hold long values and the `--old-passwords' option must not be given.
  16364. These conditions apply as follows:
  16365.  
  16366.    * The `Password' column must be wide enough to hold long hashes (41
  16367.      bytes).  If the column has not been updated and still has the
  16368.      pre-4.1 width (16 bytes), the server notices that long hashes
  16369.      cannot fit into it and generates only short hashes when a client
  16370.      performs password-changing operations using `PASSWORD()', `GRANT',
  16371.      or `SET PASSWORD'.  (This behaviour occurs if you have upgraded to
  16372.      4.1 but have not run the `mysql_fix_privilege_tables' script to
  16373.      widen the `Password' column.)
  16374.  
  16375.    * If the `Password' column is wide, it can store either short or long
  16376.      password hashes. In this case, `PASSWORD()', `GRANT', and `SET
  16377.      PASSWORD' will generate long hashes unless the server was started
  16378.      with the `--old-passwords' option. This option forces the server
  16379.      to generate short passsword hashes instead.
  16380.  
  16381.  
  16382. The purpose of the `--old-passwords' option is to allow you to maintain
  16383. backward compatibility with pre-4.1 clients under circumstances where
  16384. the server would otherwise generate long password hashes. It doesn't
  16385. affect authentication (4.1 clients can still use accounts that have
  16386. long password hashes), but it does prevent creation of a long password
  16387. hash in the `user' table as the result of a password-changing
  16388. operation. Were that to occur, the account no longer could be used by
  16389. pre-4.1 clients. Without the `--old-passwords' option, the following
  16390. scenario is possible:
  16391.  
  16392.    * An old client connects to an account that has a short password
  16393.      hash.
  16394.  
  16395.    * The client changes the account's password. Without
  16396.      `--old-passwords', this results in the account having a long
  16397.      password hash.
  16398.  
  16399.    * The next time the old client attempts to connect to the account, it
  16400.      cannot, because the account now requires the new hashing mechanism
  16401.      during authentication. (Once an account has a long password hash in
  16402.      the user table, only 4.1 clients can authenticate for it, because
  16403.      pre-4.1 clients do not understand long hashes.)
  16404.  
  16405.  
  16406. This scenario illustrates that it is dangerous to run a 4.1 server
  16407. without using the `--old-passwords' option if you must support older
  16408. pre-4.1 clients. By running the server with `--old-passwords',
  16409. password-changing operations will not generate long password hashes and
  16410. thus do not cause accounts to become inaccessible to older clients.
  16411. (Those clients cannot inadvertently lock themselves out by changing
  16412. their password and ending up with a long password hash.)
  16413.  
  16414. The downside of the `--old-passwords' option is that any passwords you
  16415. create or change will use short hashes, even for 4.1 clients. Thus, you
  16416. lose the additional security provided by long password hashes. If you
  16417. want to create an account that has a long hash (for example, for use by
  16418. 4.1 clients), you must do so while running the server without
  16419. `--old-passwords'.
  16420.  
  16421. The following scenarios are possible for running a 4.1 server:
  16422.  
  16423. Scenario 1) Narrow `Password' column in user table
  16424.  
  16425.    * Only short hashes can be stored in the `Password' column.
  16426.  
  16427.    * The server uses only short hashes during client authentication.
  16428.  
  16429.    * For connected clients, password hash-generating operations
  16430.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  16431.      exclusively.  Any change to an account's password results in that
  16432.      account having a short password hash.
  16433.  
  16434.    * The `--old-passwords' option can be used but is superfluous because
  16435.      with a narrow `Password' column, the server will be generating
  16436.      short password hashes anyway.
  16437.  
  16438.  
  16439. Scenario 2) Long `Password' column; server not started with
  16440. `--old-passwords' option
  16441.  
  16442.    * Short or long hashes can be stored in the `Password' column.
  16443.  
  16444.    * 4.1 clients can authenticate for accounts that have short or long
  16445.      hashes.
  16446.  
  16447.    * Pre-4.1 clients can authenticate only for accounts that have short
  16448.      hashes.
  16449.  
  16450.    * For connected clients, password hash-generating operations
  16451.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use long hashes
  16452.      exclusively.  Any change to an account's password results in that
  16453.      account having a long password hash.
  16454.  
  16455.    * `OLD_PASSWORD()' may be used to explicitly generate a short hash.
  16456.      For example, to assign an account a short password, use `UPDATE'
  16457.      as follows:
  16458.  
  16459.           mysql> UPDATE user SET Password = OLD_PASSWORD('mypass')
  16460.               -> WHERE Host = 'some_host' AND User = 'some_user';
  16461.           mysql> FLUSH PRIVILEGES;
  16462.  
  16463.  
  16464. As indicated earlier, a danger in this scenario is that it is possible
  16465. for accounts that have a short password hash to become inaccessible to
  16466. pre-4.1 clients. Any change to such an account's password made via
  16467. `GRANT', `SET PASSWORD', or `PASSWORD()' results in the account being
  16468. given a long password hash, and from that point on, no pre-4.1 client
  16469. can authenticate to that account until the client upgrades to 4.1.
  16470.  
  16471. Scenario 3) Long `Password' column; server started with
  16472. `--old-passwords' option
  16473.  
  16474.    * Short or long hashes can be stored in the `Password' column.
  16475.  
  16476.    * 4.1 clients can authenticate for accounts that have short or long
  16477.      hashes (but note that it is possible to create long hashes only
  16478.      when the server is started without `--old-passwords').
  16479.  
  16480.    * Pre-4.1 clients can authenticate only for accounts that have short
  16481.      hashes.
  16482.  
  16483.    * For connected clients, password hash-generating operations
  16484.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  16485.      exclusively.  Any change to an account's password results in that
  16486.      account having a short password hash.
  16487.  
  16488.  
  16489. In this scenario, you cannot create accounts that have long password
  16490. hashes, because `--old-passwords' prevents generation of long hashes.
  16491. Also, if you create an account with a long hash before using the
  16492. `--old-passwords' option, changing the account's password while
  16493. `--old-passwords' is in effect results in the account being given a
  16494. short password, causing it to lose the security benefits of a longer
  16495. hash.
  16496.  
  16497. The disadvantages for these scenarios may be summarized as follows:
  16498.  
  16499. Scenario 1) You cannot take advantage of longer hashes that provide more
  16500. secure authentication.
  16501.  
  16502. Scenario 2) Accounts with short hashes become inaccessible to pre-4.1
  16503. clients if you change their passwords without explicitly using
  16504. `OLD_PASSWORD()'.
  16505.  
  16506. Scenario 3) `--old-passwords' prevents accounts with short hashes from
  16507. becoming inaccessible, but password-changing operations cause accounts
  16508. with long hashes to revert to short hashes, and you cannot change them
  16509. back to long hashes while `--old-passwords' is in effect.
  16510.  
  16511. Implications of Password Hashing Changes for Application Programs
  16512. -----------------------------------------------------------------
  16513.  
  16514. An upgrade to MySQL 4.1 can cause a compatibility issue for
  16515. applications that use `PASSWORD()' to generate passwords for their own
  16516. purposes. (Applications really should not do this, because `PASSWORD()'
  16517. should be used only to manage passwords for MySQL accounts. But some
  16518. applications use `PASSWORD()' for their own purposes anyway.)  If you
  16519. upgrade to 4.1 and run the server under conditions where it generates
  16520. long password hashes, an application that uses `PASSWORD()' for its own
  16521. passwords will break.  The recommended course of action is to modify
  16522. the application to use another function such as `SHA1()' or `MD5()' to
  16523. produce hashed values.  If that is not possible, you can use the
  16524. `OLD_PASSWORD()' function, which is provided to generate short hashes
  16525. in the old format. (But note that `OLD_PASSWORD()' may one day no
  16526. longer be supported.)
  16527.  
  16528. If the server is running under circumstances where it generates short
  16529. hashes, `OLD_PASSWORD()' is available but is equivalent to `PASSWORD()'.
  16530.  
  16531. Password hashing in MySQL 4.1.0 differs from hashing in 4.1.1 and up.
  16532. The 4.1.0 differences are:
  16533.  
  16534.    * Password hashes are 45 bytes long rather than 41 bytes.
  16535.  
  16536.    * The `PASSWORD()' function is non-repeatable.  That is, with a given
  16537.      argument `X', successive calls to `PASSWORD(X)' generate different
  16538.      results.
  16539.  
  16540.  
  16541. Causes of `Access denied' Errors
  16542. --------------------------------
  16543.  
  16544. If you encounter `Access denied' errors when you try to connect to the
  16545. MySQL server, the following list indicates some courses of action you
  16546. can take to correct the problem:
  16547.  
  16548.    * After installing MySQL, did you run the `mysql_install_db' script
  16549.      to set up the initial grant table contents?  If not, do so.  *Note
  16550.      Default privileges::.  Test the initial privileges by executing
  16551.      this command:
  16552.  
  16553.           shell> mysql -u root test
  16554.  
  16555.      The server should let you connect without error.  You should also
  16556.      make sure you have a file `user.MYD' in the MySQL database
  16557.      directory.  Ordinarily, this is `PATH/var/mysql/user.MYD', where
  16558.      `PATH' is the pathname to the MySQL installation root.
  16559.  
  16560.    * After a fresh installation, you should connect to the server and
  16561.      set up your users and their access permissions:
  16562.  
  16563.           shell> mysql -u root mysql
  16564.  
  16565.      The server should let you connect because the MySQL `root' user
  16566.      has no password initially.  That is also a security risk, so
  16567.      setting the `root' password is something you should do while
  16568.      you're setting up your other MySQL users.
  16569.  
  16570.      If you try to connect as `root' and get this error:
  16571.  
  16572.           Access denied for user: '@unknown' to database mysql
  16573.  
  16574.      this means that you don't have an entry in the `user' table with a
  16575.      `User' column value of `'root'' and that `mysqld' cannot resolve
  16576.      the hostname for your client.  In this case, you must restart the
  16577.      server with the `--skip-grant-tables' option and edit your
  16578.      `/etc/hosts' or `\windows\hosts' file to add an entry for your
  16579.      host.
  16580.  
  16581.    * If you get an error like the following:
  16582.  
  16583.           shell> mysqladmin -u root -pxxxx ver
  16584.           Access denied for user: 'root@localhost' (Using password: YES)
  16585.  
  16586.      It means that you are using an incorrect password. *Note
  16587.      Passwords::.
  16588.  
  16589.      If you have forgot the root password, you can restart `mysqld' with
  16590.      `--skip-grant-tables' to change the password.  *Note Resetting
  16591.      permissions::.
  16592.  
  16593.      If you get the above error even if you haven't specified a
  16594.      password, this means that you have an incorrect password in some
  16595.      `my.ini' file. *Note Option files::.  You can avoid using option
  16596.      files with the `--no-defaults' option, as follows:
  16597.  
  16598.           shell> mysqladmin --no-defaults -u root ver
  16599.  
  16600.    * If you updated an existing MySQL installation from a version
  16601.      earlier than Version 3.22.11 to Version 3.22.11 or later, did you
  16602.      run the `mysql_fix_privilege_tables' script?  If not, do so.  The
  16603.      structure of the grant tables changed with MySQL Version 3.22.11
  16604.      when the `GRANT' statement became functional.
  16605.  
  16606.    * If your privileges seem to have changed in the middle of a
  16607.      session, it may be that a superuser has changed them.  Reloading
  16608.      the grant tables affects new client connections, but it also
  16609.      affects existing connections as indicated in *Note Privilege
  16610.      changes::.
  16611.  
  16612.    * If you can't get your password to work, remember that you must use
  16613.      the `PASSWORD()' function if you set the password with the
  16614.      `INSERT', `UPDATE', or `SET PASSWORD' statements.  The
  16615.      `PASSWORD()' function is unnecessary if you specify the password
  16616.      using the `GRANT ... IDENTIFIED BY' statement or the `mysqladmin
  16617.      password' command.  *Note Passwords::.
  16618.  
  16619.    * `localhost' is a synonym for your local hostname, and is also the
  16620.      default host to which clients try to connect if you specify no host
  16621.      explicitly.  However, connections to `localhost' do not work if
  16622.      you are using a MySQL version prior to 3.23.27 that uses
  16623.      MIT-pthreads (`localhost' connections are made using Unix sockets,
  16624.      which were not supported by MIT-pthreads at that time).  To avoid
  16625.      this problem on such systems, you should use the `--host' option
  16626.      to name the server host explicitly.  This will make a TCP/IP
  16627.      connection to the `mysqld' server.  In this case, you must have
  16628.      your real hostname in `user' table entries on the server host.
  16629.      (This is true even if you are running a client program on the same
  16630.      host as the server.)
  16631.  
  16632.    * If you get an `Access denied' error when trying to connect to the
  16633.      database with `mysql -u user_name db_name', you may have a problem
  16634.      with the `user' table. Check this by executing `mysql -u root
  16635.      mysql' and issuing this SQL statement:
  16636.  
  16637.           mysql> SELECT * FROM user;
  16638.  
  16639.      The result should include an entry with the `Host' and `User'
  16640.      columns matching your computer's hostname and your MySQL user name.
  16641.  
  16642.    * The `Access denied' error message will tell you who you are trying
  16643.      to log in as, the host from which you are trying to connect, and
  16644.      whether or not you were using a password. Normally, you should
  16645.      have one entry in the `user' table that exactly matches the
  16646.      hostname and user name that were given in the error message. For
  16647.      example if you get an error message that contains `Using password:
  16648.      NO', this means that you tried to login without an password.
  16649.  
  16650.    * If you get the following error when you try to connect from a
  16651.      different host than the one on which the MySQL server is running,
  16652.      then there is no row in the `user' table that matches that host:
  16653.  
  16654.           Host ... is not allowed to connect to this MySQL server
  16655.  
  16656.      You can fix this by using the command-line tool `mysql' (on the
  16657.      server host!) to add a row to the `user', `db', or `host' table
  16658.      for the user/hostname combination from which you are trying to
  16659.      connect and then execute `mysqladmin flush-privileges'.  If you are
  16660.      not running MySQL Version 3.22 and you don't know the IP number or
  16661.      hostname of the machine from which you are connecting, you should
  16662.      put an entry with `'%'' as the `Host' column value in the `user'
  16663.      table and restart `mysqld' with the `--log' option on the server
  16664.      machine.  After trying to connect from the client machine, the
  16665.      information in the MySQL log will indicate how you really did
  16666.      connect.  (Then replace the `'%'' in the `user' table entry with
  16667.      the actual hostname that shows up in the log.  Otherwise, you'll
  16668.      have a system that is insecure.)
  16669.  
  16670.      Another reason for this error on Linux is that you are using a
  16671.      binary MySQL version that is compiled with a different glibc
  16672.      version than the one you are using.  In this case you should
  16673.      either upgrade your OS/glibc or download the source MySQL version
  16674.      and compile this yourself.  A source RPM is normally trivial to
  16675.      compile and install, so this isn't a big problem.
  16676.  
  16677.    * If you get an error message where the hostname is not shown or
  16678.      where the hostname is an IP, even if you try to connect with a
  16679.      hostname:
  16680.  
  16681.           shell> mysqladmin -u root -pxxxx -h some-hostname ver
  16682.           Access denied for user: 'root@' (Using password: YES)
  16683.  
  16684.      This means that MySQL got some error when trying to resolve the IP
  16685.      to a hostname.  In this case you can execute `mysqladmin
  16686.      flush-hosts' to reset the internal DNS cache. *Note DNS::.
  16687.  
  16688.      Some permanent solutions are:
  16689.  
  16690.         - Try to find out what is wrong with your DNS server and fix
  16691.           this.
  16692.  
  16693.         - Specify IPs instead of hostnames in the MySQL privilege
  16694.           tables.
  16695.  
  16696.         - Start `mysqld' with `--skip-name-resolve'.
  16697.  
  16698.         - Start `mysqld' with `--skip-host-cache'.
  16699.  
  16700.         - Connect to `localhost' if you are running the server and the
  16701.           client on the same machine.
  16702.  
  16703.         - Put the client machine names in `/etc/hosts'.
  16704.  
  16705.    * If `mysql -u root test' works but `mysql -h your_hostname -u root
  16706.      test' results in `Access denied', then you may not have the
  16707.      correct name for your host in the `user' table.  A common problem
  16708.      here is that the `Host' value in the user table entry specifies an
  16709.      unqualified hostname, but your system's name resolution routines
  16710.      return a fully qualified domain name (or vice-versa).  For
  16711.      example, if you have an entry with host `'tcx'' in the `user'
  16712.      table, but your DNS tells MySQL that your hostname is
  16713.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  16714.      the `user' table that contains the IP number of your host as the
  16715.      `Host' column value.  (Alternatively, you could add an entry to the
  16716.      `user' table with a `Host' value that contains a wildcard--for
  16717.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  16718.      *insecure* and is *not* recommended!)
  16719.  
  16720.    * If `mysql -u user_name test' works but `mysql -u user_name
  16721.      other_db_name' doesn't work, you don't have an entry for
  16722.      `other_db_name' listed in the `db' table.
  16723.  
  16724.    * If `mysql -u user_name db_name' works when executed on the server
  16725.      machine, but `mysql -h host_name -u user_name db_name' doesn't
  16726.      work when executed on another client machine, you don't have the
  16727.      client machine listed in the `user' table or the `db' table.
  16728.  
  16729.    * If you can't figure out why you get `Access denied', remove from
  16730.      the `user' table all entries that have `Host' values containing
  16731.      wildcards (entries that contain `%' or `_').  A very common error
  16732.      is to insert a new entry with `Host'=`'%'' and `User'=`'some
  16733.      user'', thinking that this will allow you to specify `localhost'
  16734.      to connect from the same machine.  The reason that this doesn't
  16735.      work is that the default privileges include an entry with
  16736.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  16737.      `Host' value `'localhost'' that is more specific than `'%'', it is
  16738.      used in preference to the new entry when connecting from
  16739.      `localhost'!  The correct procedure is to insert a second entry
  16740.      with `Host'=`'localhost'' and `User'=`'some_user'', or to remove
  16741.      the entry with `Host'=`'localhost'' and `User'=`'''.
  16742.  
  16743.    * If you get the following error, you may have a problem with the
  16744.      `db' or `host' table:
  16745.  
  16746.           Access to database denied
  16747.  
  16748.      If the entry selected from the `db' table has an empty value in the
  16749.      `Host' column, make sure there are one or more corresponding
  16750.      entries in the `host' table specifying which hosts the `db' table
  16751.      entry applies to.
  16752.  
  16753.      If you get the error when using the SQL commands `SELECT ...  INTO
  16754.      OUTFILE' or `LOAD DATA INFILE', your entry in the `user' table
  16755.      probably doesn't have the `FILE' privilege enabled.
  16756.  
  16757.    * Remember that client programs will use connection parameters
  16758.      specified in configuration files or environment variables.  *Note
  16759.      Environment variables::.  If a client seems to be sending the
  16760.      wrong default connection parameters when you don't specify them on
  16761.      the command-line, check your environment and the `.my.cnf' file in
  16762.      your home directory.  You might also check the system-wide MySQL
  16763.      configuration files, though it is far less likely that client
  16764.      connection parameters will be specified there. *Note Option
  16765.      files::.  If you get `Access denied' when you run a client without
  16766.      any options, make sure you haven't specified an old password in
  16767.      any of your option files!  *Note Option files::.
  16768.  
  16769.    * If you make changes to the grant tables directly (using an
  16770.      `INSERT' or `UPDATE' statement) and your changes seem to be
  16771.      ignored, remember that you must issue a `FLUSH PRIVILEGES'
  16772.      statement or execute a `mysqladmin flush-privileges' command to
  16773.      cause the server to re-read the privilege tables. Otherwise, your
  16774.      changes have no effect until the next time the server is
  16775.      restarted.  Remember that after you set the `root' password with
  16776.      an `UPDATE' command, you won't need to specify it until after you
  16777.      flush the privileges, because the server won't know you've changed
  16778.      the password yet!
  16779.  
  16780.    * If you have access problems with a Perl, PHP, Python, or ODBC
  16781.      program, try to connect to the server with `mysql -u user_name
  16782.      db_name' or `mysql -u user_name -pyour_pass db_name'.  If you are
  16783.      able to connect using the `mysql' client, there is a problem with
  16784.      your program and not with the access privileges.  (Note that there
  16785.      is no space between `-p' and the password; you can also use the
  16786.      `--password=your_pass' syntax to specify the password. If you use
  16787.      the `-p' option alone, MySQL will prompt you for the password.)
  16788.  
  16789.    * For testing, start the `mysqld' daemon with the
  16790.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  16791.      tables and use the `mysqlaccess' script to check whether your
  16792.      modifications have the desired effect.  When you are satisfied
  16793.      with your changes, execute `mysqladmin flush-privileges' to tell
  16794.      the `mysqld' server to start using the new grant tables.  *Note*:
  16795.      reloading the grant tables overrides the `--skip-grant-tables'
  16796.      option.  This allows you to tell the server to begin using the
  16797.      grant tables again without bringing it down and restarting it.
  16798.  
  16799.    * If everything else fails, start the `mysqld' daemon with a
  16800.      debugging option (for example, `--debug=d,general,query'). This
  16801.      will print host and user information about attempted connections,
  16802.      as well as information about each command issued. *Note Making
  16803.      trace files::.
  16804.  
  16805.    * If you have any other problems with the MySQL grant tables and
  16806.      feel you must post the problem to the mailing list, always provide
  16807.      a dump of the MySQL grant tables. You can dump the tables with the
  16808.      `mysqldump mysql' command. As always, post your problem using the
  16809.      `mysqlbug' script.  *Note Bug reports::.  In some cases you may
  16810.      need to restart `mysqld' with `--skip-grant-tables' to run
  16811.      `mysqldump'.
  16812.  
  16813. MySQL User Account Management
  16814. =============================
  16815.  
  16816. `GRANT' and `REVOKE' Syntax
  16817. ---------------------------
  16818.  
  16819.      GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
  16820.          ON {tbl_name | * | *.* | db_name.*}
  16821.          TO user_name [IDENTIFIED BY [PASSWORD] 'password']
  16822.              [, user_name [IDENTIFIED BY [PASSWORD] 'password'] ...]
  16823.          [REQUIRE
  16824.              NONE |
  16825.              [{SSL| X509}]
  16826.              [CIPHER cipher [AND]]
  16827.              [ISSUER issuer [AND]]
  16828.              [SUBJECT subject]]
  16829.          [WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR # |
  16830.                                MAX_UPDATES_PER_HOUR # |
  16831.                                MAX_CONNECTIONS_PER_HOUR #]]
  16832.      
  16833.      REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
  16834.          ON {tbl_name | * | *.* | db_name.*}
  16835.          FROM user_name [, user_name ...]
  16836.  
  16837. `GRANT' is implemented in MySQL Version 3.22.11 or later. For earlier
  16838. MySQL versions, the `GRANT' statement does nothing.
  16839.  
  16840. The `GRANT' and `REVOKE' commands allow system administrators to create
  16841. users and grant and revoke rights to MySQL users at four privilege
  16842. levels:
  16843.  
  16844. *Global level*
  16845.      Global privileges apply to all databases on a given server. These
  16846.      privileges are stored in the `mysql.user' table.  `REVOKE ALL ON
  16847.      *.*' will revoke only global privileges.
  16848.  
  16849. *Database level*
  16850.      Database privileges apply to all tables in a given database. These
  16851.      privileges are stored in the `mysql.db' and `mysql.host' tables.
  16852.      `REVOKE ALL ON db.*' will revoke only database privileges.
  16853.  
  16854. *Table level*
  16855.      Table privileges apply to all columns in a given table. These
  16856.      privileges are stored in the `mysql.tables_priv' table.  `REVOKE
  16857.      ALL ON db.table' will revoke only table privileges.
  16858.  
  16859. *Column level*
  16860.      Column privileges apply to single columns in a given table. These
  16861.      privileges are stored in the `mysql.columns_priv' table.  When
  16862.      using `REVOKE' you must specify the same columns that were granted.
  16863.  
  16864. For the `GRANT' and `REVOKE' statements, `priv_type' may be specified
  16865. as any of the following:
  16866.  
  16867. `ALL [PRIVILEGES]'     Sets all simple privileges except `WITH GRANT
  16868.                        OPTION'
  16869. `ALTER'                Allows usage of `ALTER TABLE'
  16870. `CREATE'               Allows usage of `CREATE TABLE'
  16871. `CREATE TEMPORARY      Allows usage of `CREATE TEMPORARY TABLE'
  16872. TABLES'                
  16873. `DELETE'               Allows usage of `DELETE'
  16874. `DROP'                 Allows usage of `DROP TABLE'.
  16875. `EXECUTE'              Allows the user to run stored procedures (MySQL
  16876.                        5.0)
  16877. `FILE'                 Allows usage of `SELECT ... INTO OUTFILE' and
  16878.                        `LOAD DATA INFILE'.
  16879. `INDEX'                Allows usage of `CREATE INDEX' and `DROP INDEX'
  16880. `INSERT'               Allows usage of `INSERT'
  16881. `LOCK TABLES'          Allows usage of `LOCK TABLES' on tables for which
  16882.                        one has the `SELECT' privilege.
  16883. `PROCESS'              Allows usage of `SHOW FULL PROCESSLIST'
  16884. `REFERENCES'           For the future
  16885. `RELOAD'               Allows usage of `FLUSH'
  16886. `REPLICATION CLIENT'   Gives the right to the user to ask where the
  16887.                        slaves/masters are.
  16888. `REPLICATION SLAVE'    Needed for the replication slaves (to read
  16889.                        binlogs from master).
  16890. `SELECT'               Allows usage of `SELECT'
  16891. `SHOW DATABASES'       `SHOW DATABASES' shows all databases.
  16892. `SHUTDOWN'             Allows usage of `mysqladmin shutdown'
  16893. `SUPER'                Allows one connect (once) even if max_connections
  16894.                        is reached and execute commands `CHANGE MASTER',
  16895.                        `KILL thread', `mysqladmin debug', `PURGE MASTER
  16896.                        LOGS' and `SET GLOBAL'
  16897. `UPDATE'               Allows usage of `UPDATE'
  16898. `USAGE'                Synonym for "no privileges."
  16899. `GRANT OPTION'         Synonym for `WITH GRANT OPTION'
  16900.  
  16901. `USAGE' can be used when you want to create a user that has no
  16902. privileges.
  16903.  
  16904. The privileges `CREATE TEMPORARY TABLES', `EXECUTE', `LOCK TABLES',
  16905. `REPLICATION ...', `SHOW DATABASES' and `SUPER' are new for in version
  16906. 4.0.2.  To use these new privileges after upgrading to 4.0.2, you have
  16907. to run the `mysql_fix_privilege_tables' script.
  16908.  
  16909. In older MySQL versions, the `PROCESS' privilege gives the same rights
  16910. as the new `SUPER' privilege.
  16911.  
  16912. To revoke the `GRANT' privilege from a user, use a `priv_type' value of
  16913. `GRANT OPTION':
  16914.  
  16915.      mysql> REVOKE GRANT OPTION ON ... FROM ...;
  16916.  
  16917. The only `priv_type' values you can specify for a table are `SELECT',
  16918. `INSERT', `UPDATE', `DELETE', `CREATE', `DROP', `GRANT OPTION',
  16919. `INDEX', and `ALTER'.
  16920.  
  16921. The only `priv_type' values you can specify for a column (that is, when
  16922. you use a `column_list' clause) are `SELECT', `INSERT', and `UPDATE'.
  16923.  
  16924. MySQL allows you to create database level privileges even if the
  16925. database doesn't exist, to make it easy to prepare for database usage.
  16926. Currently MySQL does however not allow one to create table level grants
  16927. if the table doesn't exist. MySQL will not automatically revoke any
  16928. privileges even if you drop a table or drop a database.
  16929.  
  16930. You can set global privileges by using `ON *.*' syntax.  You can set
  16931. database privileges by using `ON db_name.*' syntax. If you specify `ON
  16932. *' and you have a current database, you will set the privileges for
  16933. that database.  (*Warning*: if you specify `ON *' and you *don't* have
  16934. a current database, you will affect the global privileges!)
  16935.  
  16936. *Please note*: the `_' and `%' wildcards are allowed when specifying
  16937. database names in `GRANT' commands. This means that if you wish to use
  16938. for instance a `_' character as part of a database name, you should
  16939. specify it as `\_' in the `GRANT' command, to prevent the user from
  16940. being able to access additional databases matching the wildcard
  16941. pattern, for example, `GRANT ... ON `foo\_bar`.* TO ...'.
  16942.  
  16943. In order to accommodate granting rights to users from arbitrary hosts,
  16944. MySQL supports specifying the `user_name' value in the form
  16945. `user@host'.  If you want to specify a `user' string containing special
  16946. characters (such as `-'), or a `host' string containing special
  16947. characters or wildcard characters (such as `%'), you can quote the user
  16948. or host name (for example, `'test-user'@'test-hostname'').
  16949.  
  16950. You can specify wildcards in the hostname.  For example,
  16951. `user@'%.loc.gov'' applies to `user' for any host in the `loc.gov'
  16952. domain, and `user@'144.155.166.%'' applies to `user' for any host in
  16953. the `144.155.166' class C subnet.
  16954.  
  16955. The simple form `user' is a synonym for `user@"%"'.
  16956.  
  16957. MySQL doesn't support wildcards in user names.  Anonymous users are
  16958. defined by inserting entries with `User=''' into the `mysql.user' table
  16959. or creating an user with an empty name with the `GRANT' command.
  16960.  
  16961. *Note*: if you allow anonymous users to connect to the MySQL server,
  16962. you should also grant privileges to all local users as `user@localhost'
  16963. because otherwise the anonymous user entry for the local host in the
  16964. `mysql.user' table will be used when the user tries to log into the
  16965. MySQL server from the local machine!
  16966.  
  16967. You can verify if this applies to you by executing this query:
  16968.  
  16969.      mysql> SELECT Host,User FROM mysql.user WHERE User='';
  16970.  
  16971. For the moment, `GRANT' only supports host, table, database, and column
  16972. names up to 60 characters long. A user name can be up to 16 characters.
  16973.  
  16974. The privileges for a table or column are formed from the logical OR of
  16975. the privileges at each of the four privilege levels.  For example, if
  16976. the `mysql.user' table specifies that a user has a global `SELECT'
  16977. privilege, this can't be denied by an entry at the database, table, or
  16978. column level.
  16979.  
  16980. The privileges for a column can be calculated as follows:
  16981.  
  16982.      global privileges
  16983.      OR (database privileges AND host privileges)
  16984.      OR table privileges
  16985.      OR column privileges
  16986.  
  16987. In most cases, you grant rights to a user at only one of the privilege
  16988. levels, so life isn't normally as complicated as above. The details of
  16989. the privilege-checking procedure are presented in *Note Privilege
  16990. system::.
  16991.  
  16992. If you grant privileges for a user/hostname combination that does not
  16993. exist in the `mysql.user' table, an entry is added and remains there
  16994. until deleted with a `DELETE' command.  In other words, `GRANT' may
  16995. create `user' table entries, but `REVOKE' will not remove them; you
  16996. must do that explicitly using `DELETE'.
  16997.  
  16998. In MySQL Version 3.22.12 or later, if a new user is created or if you
  16999. have global grant privileges, the user's password will be set to the
  17000. password specified by the `IDENTIFIED BY' clause, if one is given.  If
  17001. the user already had a password, it is replaced by the new one.
  17002.  
  17003. If you don't want to send the password in clear text you can use the
  17004. `PASSWORD' option followed by a scrambled password from SQL function
  17005. `PASSWORD()' or the C API function `make_scrambled_password(char *to,
  17006. const char *password)'.
  17007.  
  17008. *Warning*: if you create a new user but do not specify an `IDENTIFIED
  17009. BY' clause, the user has no password.  This is insecure.
  17010.  
  17011. Passwords can also be set with the `SET PASSWORD' command.  *Note
  17012. `SET': SET OPTION.
  17013.  
  17014. If you grant privileges for a database, an entry in the `mysql.db'
  17015. table is created if needed. When all privileges for the database have
  17016. been removed with `REVOKE', this entry is deleted.
  17017.  
  17018. If a user doesn't have any privileges on a table, the table is not
  17019. displayed when the user requests a list of tables (for example, with a
  17020. `SHOW TABLES' statement). The same is true for `SHOW DATABASES'.
  17021.  
  17022. The `WITH GRANT OPTION' clause gives the user the ability to give to
  17023. other users any privileges the user has at the specified privilege
  17024. level.  You should be careful to whom you give the `GRANT' privilege,
  17025. as two users with different privileges may be able to join privileges!
  17026.  
  17027. `MAX_QUERIES_PER_HOUR #', `MAX_UPDATES_PER_HOUR #' and
  17028. `MAX_CONNECTIONS_PER_HOUR #' are new in MySQL version 4.0.2.  These
  17029. options limit the number of queries/updates and logins the user can do
  17030. during one hour. If `#' is 0 (default), then this means that there are
  17031. no limitations for that user. *Note User resources::.  Note: to specify
  17032. any of these options for an existing user without adding other
  17033. additional privileges, use `GRANT USAGE ON *.* ... WITH MAX_...'.
  17034.  
  17035. You cannot grant another user a privilege you don't have yourself; the
  17036. `GRANT' privilege allows you to give away only those privileges you
  17037. possess.
  17038.  
  17039. Be aware that when you grant a user the `GRANT' privilege at a
  17040. particular privilege level, any privileges the user already possesses
  17041. (or is given in the future!) at that level are also grantable by that
  17042. user.  Suppose you grant a user the `INSERT' privilege on a database.
  17043. If you then grant the `SELECT' privilege on the database and specify
  17044. `WITH GRANT OPTION', the user can give away not only the `SELECT'
  17045. privilege, but also `INSERT'.  If you then grant the `UPDATE' privilege
  17046. to the user on the database, the user can give away the `INSERT',
  17047. `SELECT' and `UPDATE'.
  17048.  
  17049. You should not grant `ALTER' privileges to a normal user.  If you do
  17050. that, the user can try to subvert the privilege system by renaming
  17051. tables!
  17052.  
  17053. Note that if you are using table or column privileges for even one
  17054. user, the server examines table and column privileges for all users and
  17055. this will slow down MySQL a bit.
  17056.  
  17057. When `mysqld' starts, all privileges are read into memory.  Database,
  17058. table, and column privileges take effect at once, and user-level
  17059. privileges take effect the next time the user connects.  Modifications
  17060. to the grant tables that you perform using `GRANT' or `REVOKE' are
  17061. noticed by the server immediately.  If you modify the grant tables
  17062. manually (using `INSERT', `UPDATE', etc.), you should execute a `FLUSH
  17063. PRIVILEGES' statement or run `mysqladmin flush-privileges' to tell the
  17064. server to reload the grant tables.  *Note Privilege changes::.
  17065.  
  17066. The biggest differences between the SQL standard and MySQL versions of
  17067. `GRANT' are:
  17068.  
  17069.    * In MySQL privileges are given for an username + hostname
  17070.      combination and not only for an username.
  17071.  
  17072.    * SQL-99 doesn't have global or database-level privileges, nor does
  17073.      it support all the privilege types that MySQL supports.  MySQL
  17074.      doesn't support the SQL-99 `TRIGGER' or `UNDER' privileges.
  17075.  
  17076.    * SQL-99 privileges are structured in a hierarchal manner. If you
  17077.      remove an user, all privileges the user has granted are revoked. In
  17078.      MySQL the granted privileges are not automatically revoked, but
  17079.      you have to revoke these yourself if needed.
  17080.  
  17081.    * In MySQL, if you have the `INSERT' privilege on only some of the
  17082.      columns in a table, you can execute `INSERT' statements on the
  17083.      table; the columns for which you don't have the `INSERT' privilege
  17084.      will be set to their default values. SQL-99 requires you to have
  17085.      the `INSERT' privilege on all columns.
  17086.  
  17087.    * With SQL99, when you drop a table, all privileges for the table
  17088.      are revoked.  With SQL-99, when you revoke a privilege, all
  17089.      privileges that were granted based on the privilege are also
  17090.      revoked. In MySQL, privileges can be dropped only with explicit
  17091.      `REVOKE' commands or by manipulating the MySQL grant tables.
  17092.  
  17093. For a description of using `REQUIRE', see *Note Secure connections::.
  17094.  
  17095. MySQL User Names and Passwords
  17096. ------------------------------
  17097.  
  17098. There are several distinctions between the way user names and passwords
  17099. are used by MySQL and the way they are used by Unix or Windows:
  17100.  
  17101.    * User names, as used by MySQL for authentication purposes, have
  17102.      nothing to do with Unix user names (login names) or Windows user
  17103.      names.  Most MySQL clients by default try to log in using the
  17104.      current Unix user name as the MySQL user name, but that is for
  17105.      convenience only.  Client programs allow a different name to be
  17106.      specified with the `-u' or `--user' options. This means that you
  17107.      can't make a database secure in any way unless all MySQL user
  17108.      names have passwords.  Anyone may attempt to connect to the server
  17109.      using any name, and they will succeed if they specify any name
  17110.      that doesn't have a password.
  17111.  
  17112.    * MySQL user names can be up to 16 characters long; Unix user names
  17113.      typically are limited to 8 characters.
  17114.  
  17115.    * MySQL passwords have nothing to do with Unix passwords.  There is
  17116.      no necessary connection between the password you use to log in to
  17117.      a Unix machine and the password you use to access a database on
  17118.      that machine.
  17119.  
  17120.    * MySQL encrypts passwords using a different algorithm than the one
  17121.      used during the Unix login process.  See the descriptions of the
  17122.      `PASSWORD()' and `ENCRYPT()' functions in *Note Miscellaneous
  17123.      functions::.  Note that even if the password is stored
  17124.      'scrambled', and knowing your 'scrambled' password is enough to be
  17125.      able to connect to the MySQL server!  From version 4.1, MySQL
  17126.      employs a different password and login mechanism that is secure
  17127.      even if TCP/IP packets are sniffed and/or the mysql database is
  17128.      captured.
  17129.  
  17130. MySQL users and their privileges are normally created with the `GRANT'
  17131. command. *Note GRANT::.
  17132.  
  17133. When you login to a MySQL server with a command-line client you should
  17134. specify the password with `--password=your-password'.  *Note
  17135. Connecting::.
  17136.  
  17137.      mysql --user=monty --password=guess database_name
  17138.  
  17139. If you want the client to prompt for a password, you should use
  17140. `--password' without any argument
  17141.  
  17142.      mysql --user=monty --password database_name
  17143.  
  17144. or the short form:
  17145.  
  17146.      mysql -u monty -p database_name
  17147.  
  17148. Note that in the last example the password is *not* 'database_name'.
  17149.  
  17150. If you want to use the `-p' option to supply a password you should do so
  17151. like this:
  17152.  
  17153.      mysql -u monty -pguess database_name
  17154.  
  17155. On some systems, the library call that MySQL uses to prompt for a
  17156. password will automatically cut the password to 8 characters. Internally
  17157. MySQL doesn't have any limit for the length of the password.
  17158.  
  17159. When Privilege Changes Take Effect
  17160. ----------------------------------
  17161.  
  17162. When `mysqld' starts, all grant table contents are read into memory and
  17163. become effective at that point.
  17164.  
  17165. Modifications to the grant tables that you perform using `GRANT',
  17166. `REVOKE', or `SET PASSWORD' are noticed by the server immediately.
  17167.  
  17168. If you modify the grant tables manually (using `INSERT', `UPDATE',
  17169. etc.), you should execute a `FLUSH PRIVILEGES' statement or run
  17170. `mysqladmin flush-privileges' or `mysqladmin reload' to tell the server
  17171. to reload the grant tables. Otherwise, your changes will have _no
  17172. effect_ until you restart the server. If you change the grant tables
  17173. manually but forget to reload the privileges, you will be wondering why
  17174. your changes don't seem to make any difference!
  17175.  
  17176. When the server notices that the grant tables have been changed,
  17177. existing client connections are affected as follows:
  17178.  
  17179.    * Table and column privilege changes take effect with the client's
  17180.      next request.
  17181.  
  17182.    * Database privilege changes take effect at the next `USE db_name'
  17183.      command.
  17184.  
  17185.    * Global privilege changes and password changes take effect the next
  17186.      time the client connects.
  17187.  
  17188. Setting Up the Initial MySQL Privileges
  17189. ---------------------------------------
  17190.  
  17191. After installing MySQL, you set up the initial access privileges by
  17192. running `scripts/mysql_install_db'.  *Note Quick install::.  The
  17193. `mysql_install_db' script starts up the `mysqld' server, then
  17194. initialises the grant tables to contain the following set of privileges:
  17195.  
  17196.    * The MySQL `root' user is created as a superuser who can do
  17197.      anything.  Connections must be made from the local host.
  17198.  
  17199.      *Note*: The initial `root' password is empty, so anyone can
  17200.      connect as `root' _without a password_ and be granted all
  17201.      privileges.
  17202.  
  17203.    * An anonymous user is created that can do anything with databases
  17204.      that have a name of `'test'' or starting with `'test_''.
  17205.      Connections must be made from the local host.  This means any
  17206.      local user can connect without a password and be treated as the
  17207.      anonymous user.
  17208.  
  17209.    * Other privileges are denied.  For example, normal users can't use
  17210.      `mysqladmin shutdown' or `mysqladmin processlist'.
  17211.  
  17212. *Note*: the default privileges are different for Windows.  *Note
  17213. Windows running::.
  17214.  
  17215. Because your installation is initially wide open, one of the first
  17216. things you should do is specify a password for the MySQL `root' user.
  17217. You can do this as follows (note that you specify the password using
  17218. the `PASSWORD()' function):
  17219.  
  17220.      shell> mysql -u root mysql
  17221.      mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
  17222.  
  17223. If you know what you are doing, you can also directly manipulate the
  17224. privilege tables:
  17225.  
  17226.      shell> mysql -u root mysql
  17227.      mysql> UPDATE user SET Password=PASSWORD('new_password')
  17228.          ->     WHERE user='root';
  17229.      mysql> FLUSH PRIVILEGES;
  17230.  
  17231. Another way to set the password is by using the `mysqladmin' command:
  17232.  
  17233.      shell> mysqladmin -u root password new_password
  17234.  
  17235. Only users with write/update access to the `mysql' database can change
  17236. the password for others users.  All normal users (not anonymous ones)
  17237. can only change their own password with either of the above commands or
  17238. with `SET PASSWORD=PASSWORD('new password')'.
  17239.  
  17240. Note that if you update the password in the `user' table directly using
  17241. the first method, you must tell the server to re-read the grant tables
  17242. (with `FLUSH PRIVILEGES'), because the change will go unnoticed
  17243. otherwise.
  17244.  
  17245. Once the `root' password has been set, thereafter you must supply that
  17246. password when you connect to the server as `root'.
  17247.  
  17248. You may wish to leave the `root' password blank so that you don't need
  17249. to specify it while you perform additional setup or testing. However,
  17250. be sure to set it before using your installation for any real
  17251. production work.
  17252.  
  17253. See the `scripts/mysql_install_db' script to see how it sets up the
  17254. default privileges.  You can use this as a basis to see how to add
  17255. other users.
  17256.  
  17257. If you want the initial privileges to be different from those just
  17258. described above, you can modify `mysql_install_db' before you run it.
  17259.  
  17260. To re-create the grant tables completely, remove all the `.frm',
  17261. `.MYI', and `.MYD' files in the directory containing the `mysql'
  17262. database.  (This is the directory named `mysql' under the database
  17263. directory, which is listed when you run `mysqld --help'.) Then run the
  17264. `mysql_install_db' script, possibly after editing it first to have the
  17265. privileges you want.
  17266.  
  17267. *Note*: for MySQL versions older than Version 3.22.10, you should not
  17268. delete the `.frm' files.  If you accidentally do this, you should copy
  17269. them back from your MySQL distribution before running
  17270. `mysql_install_db'.
  17271.  
  17272. Adding New Users to MySQL
  17273. -------------------------
  17274.  
  17275. You can add users two different ways: by using `GRANT' statements or by
  17276. manipulating the MySQL grant tables directly.  The preferred method is
  17277. to use `GRANT' statements, because they are more concise and less
  17278. error-prone. *Note GRANT::.
  17279.  
  17280. There are also a lot of contributed programs like `phpmyadmin' that can
  17281. be used to create and administrate users.
  17282.  
  17283. The following examples show how to use the `mysql' client to set up new
  17284. users.  These examples assume that privileges are set up according to
  17285. the defaults described in the previous section.  This means that to
  17286. make changes, you must be on the same machine where `mysqld' is
  17287. running, you must connect as the MySQL `root' user, and the `root' user
  17288. must have the `INSERT' privilege for the `mysql' database and the
  17289. `RELOAD' administrative privilege.  Also, if you have changed the
  17290. `root' user password, you must specify it for the `mysql' commands here.
  17291.  
  17292. You can add new users by issuing `GRANT' statements:
  17293.  
  17294.      shell> mysql --user=root mysql
  17295.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
  17296.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  17297.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%"
  17298.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  17299.      mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
  17300.      mysql> GRANT USAGE ON *.* TO dummy@localhost;
  17301.  
  17302. These `GRANT' statements set up three new users:
  17303.  
  17304. `monty'
  17305.      A full superuser who can connect to the server from anywhere, but
  17306.      who must use a password `'some_pass'' to do so.  Note that we must
  17307.      issue `GRANT' statements for both `monty@localhost' and
  17308.      `monty@"%"'.  If we don't add the entry with `localhost', the
  17309.      anonymous user entry for `localhost' that is created by
  17310.      `mysql_install_db' will take precedence when we connect from the
  17311.      local host, because it has a more specific `Host' field value and
  17312.      thus comes earlier in the `user' table sort order.
  17313.  
  17314. `admin'
  17315.      A user who can connect from `localhost' without a password and who
  17316.      is granted the `RELOAD' and `PROCESS' administrative privileges.
  17317.      This allows the user to execute the `mysqladmin reload',
  17318.      `mysqladmin refresh', and `mysqladmin flush-*' commands, as well as
  17319.      `mysqladmin processlist' .  No database-related privileges are
  17320.      granted.  (They can be granted later by issuing additional `GRANT'
  17321.      statements.)
  17322.  
  17323. `dummy'
  17324.      A user who can connect without a password, but only from the local
  17325.      host.  The global privileges are all set to `'N''--the `USAGE'
  17326.      privilege type allows you to create a user with no privileges.  It
  17327.      is assumed that you will grant database-specific privileges later.
  17328.  
  17329. You can also add the same user access information directly by issuing
  17330. `INSERT' statements and then telling the server to reload the grant
  17331. tables:
  17332.  
  17333.      shell> mysql --user=root mysql
  17334.      mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
  17335.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  17336.      mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
  17337.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  17338.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  17339.          ->           Reload_priv='Y', Process_priv='Y';
  17340.      mysql> INSERT INTO user (Host,User,Password)
  17341.          ->                  VALUES('localhost','dummy','');
  17342.      mysql> FLUSH PRIVILEGES;
  17343.  
  17344. Depending on your MySQL version, you may have to use a different number
  17345. of `'Y'' values above (versions prior to Version 3.22.11 had fewer
  17346. privilege columns).  For the `admin' user, the more readable extended
  17347. `INSERT' syntax that is available starting with Version 3.22.11 is used.
  17348.  
  17349. Note that to set up a superuser, you need only create a `user' table
  17350. entry with the privilege fields set to `'Y''.  No `db' or `host' table
  17351. entries are necessary.
  17352.  
  17353. The privilege columns in the `user' table were not set explicitly in the
  17354. last `INSERT' statement (for the `dummy' user), so those columns are
  17355. assigned the default value of `'N''.  This is the same thing that
  17356. `GRANT USAGE' does.
  17357.  
  17358. The following example adds a user `custom' who can connect from hosts
  17359. `localhost', `server.domain', and `whitehouse.gov'.  He wants to access
  17360. the `bankaccount' database only from `localhost', the `expenses'
  17361. database only from `whitehouse.gov', and the `customer' database from
  17362. all three hosts.  He wants to use the password `stupid' from all three
  17363. hosts.
  17364.  
  17365. To set up this user's privileges using `GRANT' statements, run these
  17366. commands:
  17367.  
  17368.      shell> mysql --user=root mysql
  17369.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  17370.          ->     ON bankaccount.*
  17371.          ->     TO custom@localhost
  17372.          ->     IDENTIFIED BY 'stupid';
  17373.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  17374.          ->     ON expenses.*
  17375.          ->     TO custom@whitehouse.gov
  17376.          ->     IDENTIFIED BY 'stupid';
  17377.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  17378.          ->     ON customer.*
  17379.          ->     TO custom@'%'
  17380.          ->     IDENTIFIED BY 'stupid';
  17381.  
  17382. The reason that we issue two grant statements for the user 'custom' is
  17383. that we want the give the user access to MySQL both from the local
  17384. machine with Unix sockets and from the remote machine 'whitehouse.gov'
  17385. over TCP/IP.
  17386.  
  17387. To set up the user's privileges by modifying the grant tables directly,
  17388. run these commands (note the `FLUSH PRIVILEGES' at the end):
  17389.  
  17390.      shell> mysql --user=root mysql
  17391.      mysql> INSERT INTO user (Host,User,Password)
  17392.          -> VALUES('localhost','custom',PASSWORD('stupid'));
  17393.      mysql> INSERT INTO user (Host,User,Password)
  17394.          -> VALUES('server.domain','custom',PASSWORD('stupid'));
  17395.      mysql> INSERT INTO user (Host,User,Password)
  17396.          -> VALUES('whitehouse.gov','custom',PASSWORD('stupid'));
  17397.      mysql> INSERT INTO db
  17398.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  17399.          ->  Create_priv,Drop_priv)
  17400.          -> VALUES
  17401.          -> ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
  17402.      mysql> INSERT INTO db
  17403.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  17404.          ->  Create_priv,Drop_priv)
  17405.          -> VALUES
  17406.          -> ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
  17407.      mysql> INSERT INTO db
  17408.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  17409.          ->  Create_priv,Drop_priv)
  17410.          -> VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y');
  17411.      mysql> FLUSH PRIVILEGES;
  17412.  
  17413. The first three `INSERT' statements add `user' table entries that allow
  17414. user `custom' to connect from the various hosts with the given
  17415. password, but grant no permissions to him (all privileges are set to the
  17416. default value of `'N'').  The next three `INSERT' statements add `db'
  17417. table entries that grant privileges to `custom' for the `bankaccount',
  17418. `expenses', and `customer' databases, but only when accessed from the
  17419. proper hosts.  As usual, when the grant tables are modified directly,
  17420. the server must be told to reload them (with `FLUSH PRIVILEGES') so
  17421. that the privilege changes take effect.
  17422.  
  17423. If you want to give a specific user access from any machine in a given
  17424. domain, you can issue a `GRANT' statement like the following:
  17425.  
  17426.      mysql> GRANT ...
  17427.          ->     ON *.*
  17428.          ->     TO myusername@"%.mydomainname.com"
  17429.          ->     IDENTIFIED BY 'mypassword';
  17430.  
  17431. To do the same thing by modifying the grant tables directly, do this:
  17432.  
  17433.      mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername',
  17434.          ->             PASSWORD('mypassword'),...);
  17435.      mysql> FLUSH PRIVILEGES;
  17436.  
  17437. Limiting user resources
  17438. -----------------------
  17439.  
  17440. Starting from MySQL 4.0.2 one can limit certain resources per user.
  17441.  
  17442. So far, the only available method of limiting usage of MySQL server
  17443. resources has been setting the `max_user_connections' startup variable
  17444. to a non-zero value. But this method is strictly global and does not
  17445. allow for management of individual users, which could be of particular
  17446. interest to Internet Service Providers.
  17447.  
  17448. Therefore, management of three resources is introduced on the
  17449. individual user level:
  17450.  
  17451.    * Number of all queries per hour: All commands that could be run by
  17452.      a user.
  17453.  
  17454.    * Number of all updates per hour: Any command that changes any table
  17455.      or database.
  17456.  
  17457.    * Number of connections made per hour: New connections opened per
  17458.      hour.
  17459.  
  17460. A user in the aforementioned context is a single entry in the `user'
  17461. table, which is uniquely identified by its `user' and `host' columns.
  17462.  
  17463. All users are by default not limited in using the above resources,
  17464. unless the limits are granted to them. These limits can be granted
  17465. *only* via global `GRANT (*.*)', using this syntax:
  17466.  
  17467.      GRANT ... WITH MAX_QUERIES_PER_HOUR N1
  17468.                     MAX_UPDATES_PER_HOUR N2
  17469.                     MAX_CONNECTIONS_PER_HOUR N3;
  17470.  
  17471. One can specify any combination of the above resources.  `N1', `N2',
  17472. and `N3' are integers and represent counts per hour.
  17473.  
  17474. If a user reaches the limit on number of connections within one hour, no
  17475. further connections will be accepted until that hour is up. Similarly,
  17476. if the user reaches the limit on number of queries or updates, further
  17477. queries or updates will be rejected until the hour is up. In all cases,
  17478. an appropriate error message shall be issued.
  17479.  
  17480. Current usage values for a particular user can be flushed (set to zero)
  17481. by issuing a `GRANT' statement with any of the above clauses, including
  17482. a `GRANT' statement with the current values.
  17483.  
  17484. Also, current values for all users will be flushed if privileges are
  17485. reloaded (in the server or using `mysqladmin reload') or if the `FLUSH
  17486. USER_RESOURCES' command is issued.
  17487.  
  17488. The feature is enabled as soon as a single user is granted with any of
  17489. the limiting `GRANT' clauses.
  17490.  
  17491. As a prerequisite for enabling this feature, the `user' table in the
  17492. `mysql' database must contain the additional columns, as defined in the
  17493. table creation scripts `mysql_install_db' and `mysql_install_db.sh' in
  17494. `scripts' subdirectory.
  17495.  
  17496. Setting Up Passwords
  17497. --------------------
  17498.  
  17499. In most cases you should use `GRANT' to set up your users/passwords, so
  17500. the following only applies for advanced users. *Note `GRANT': GRANT.
  17501.  
  17502. The examples in the preceding sections illustrate an important
  17503. principle: when you store a non-empty password using `INSERT' or
  17504. `UPDATE' statements, you must use the `PASSWORD()' function to encrypt
  17505. it.  This is because the `user' table stores passwords in encrypted
  17506. form, not as plaintext.  If you forget that fact, you are likely to
  17507. attempt to set passwords like this:
  17508.  
  17509.      shell> mysql -u root mysql
  17510.      mysql> INSERT INTO user (Host,User,Password)
  17511.          -> VALUES('%','jeffrey','biscuit');
  17512.      mysql> FLUSH PRIVILEGES;
  17513.  
  17514. The result is that the plaintext value `'biscuit'' is stored as the
  17515. password in the `user' table.  When the user `jeffrey' attempts to
  17516. connect to the server using this password, the `mysql' client encrypts
  17517. it with `PASSWORD()', generates an authentification vector based on
  17518. *encrypted* password and a random number, obtained from server, and
  17519. sends the result to the server.  The server uses the `password' value
  17520. in the `user' table (that is *not encrypted* value `'biscuit'') to
  17521. perform the same calculations, and compares results.  The comparison
  17522. fails and the server rejects the connection:
  17523.  
  17524.      shell> mysql -u jeffrey -pbiscuit test
  17525.      Access denied
  17526.  
  17527. Passwords must be encrypted when they are inserted in the `user' table,
  17528. so the `INSERT' statement should have been specified like this instead:
  17529.  
  17530.      mysql> INSERT INTO user (Host,User,Password)
  17531.          -> VALUES('%','jeffrey',PASSWORD('biscuit'));
  17532.  
  17533. You must also use the `PASSWORD()' function when you use `SET PASSWORD'
  17534. statements:
  17535.  
  17536.      mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
  17537.  
  17538. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  17539. the `mysqladmin password' command, the `PASSWORD()' function is
  17540. unnecessary.  They both take care of encrypting the password for you,
  17541. so you would specify a password of `'biscuit'' like this:
  17542.  
  17543.      mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
  17544.  
  17545. or
  17546.  
  17547.      shell> mysqladmin -u jeffrey password biscuit
  17548.  
  17549. *Note*: `PASSWORD()' is different from Unix password encryption.  *Note
  17550. User names::.
  17551.  
  17552. Keeping Your Password Secure
  17553. ----------------------------
  17554.  
  17555. It is inadvisable to specify your password in a way that exposes it to
  17556. discovery by other users.  The methods you can use to specify your
  17557. password when you run client programs are listed here, along with an
  17558. assessment of the risks of each method:
  17559.  
  17560.    * Never give a normal user access to the `mysql.user' table. Knowing
  17561.      the encrypted password for a user makes it possible to login as
  17562.      this user.  The passwords are only scrambled so that one shouldn't
  17563.      be able to see the real password you used (if you happen to use a
  17564.      similar password with your other applications).
  17565.  
  17566.    * Use a `-pyour_pass' or `--password=your_pass' option on the command
  17567.      line.  This is convenient but insecure, because your password
  17568.      becomes visible to system status programs (such as `ps') that may
  17569.      be invoked by other users to display command-lines.  (MySQL
  17570.      clients typically overwrite the command-line argument with zeroes
  17571.      during their initialisation sequence, but there is still a brief
  17572.      interval during which the value is visible.)
  17573.  
  17574.    * Use a `-p' or `--password' option (with no `your_pass' value
  17575.      specified).  In this case, the client program solicits the
  17576.      password from the terminal:
  17577.  
  17578.           shell> mysql -u user_name -p
  17579.           Enter password: ********
  17580.  
  17581.      The `*' characters represent your password.
  17582.  
  17583.      It is more secure to enter your password this way than to specify
  17584.      it on the command-line because it is not visible to other users.
  17585.      However, this method of entering a password is suitable only for
  17586.      programs that you run interactively.  If you want to invoke a
  17587.      client from a script that runs non-interactively, there is no
  17588.      opportunity to enter the password from the terminal. On some
  17589.      systems, you may even find that the first line of your script is
  17590.      read and interpreted (incorrectly) as your password!
  17591.  
  17592.    * Store your password in a configuration file.  For example, you can
  17593.      list your password in the `[client]' section of the `.my.cnf' file
  17594.      in your home directory:
  17595.  
  17596.           [client]
  17597.           password=your_pass
  17598.  
  17599.      If you store your password in `.my.cnf', the file should not be
  17600.      group or world readable or writable.  Make sure the file's access
  17601.      mode is `400' or `600'.
  17602.  
  17603.      *Note Option files::.
  17604.  
  17605.    * You can store your password in the `MYSQL_PWD' environment
  17606.      variable, but this method must be considered extremely insecure
  17607.      and should not be used.  Some versions of `ps' include an option
  17608.      to display the environment of running processes; your password
  17609.      will be in plain sight for all to see if you set `MYSQL_PWD'.
  17610.      Even on systems without such a version of `ps', it is unwise to
  17611.      assume there is no other method to observe process environments.
  17612.      *Note Environment variables::.
  17613.  
  17614. All in all, the safest methods are to have the client program prompt
  17615. for the password or to specify the password in a properly protected
  17616. `.my.cnf' file.
  17617.  
  17618. Using Secure Connections
  17619. ------------------------
  17620.  
  17621. Basics
  17622. ......
  17623.  
  17624. Beginning with version 4.0.0, MySQL has support for SSL encrypted
  17625. connections. To understand how MySQL uses SSL, it's necessary to
  17626. explain some basic SSL and X509 concepts. People who are already
  17627. familiar with them can skip this part.
  17628.  
  17629. By default, MySQL uses unencrypted connections between the client and
  17630. the server. This means that someone could watch all your traffic and
  17631. look at the data being sent or received.  They could even change the
  17632. data while it is in transit between client and server. Sometimes you
  17633. need to move information over public networks in a secure fashion; in
  17634. such cases, using an unencrypted connection is unacceptable.
  17635.  
  17636. SSL is a protocol that uses different encryption algorithms to ensure
  17637. that data received over a public network can be trusted. It has
  17638. mechanisms to detect any change, loss or replay of data. SSL also
  17639. incorporates algorithms to recognise and provide identity verification
  17640. using the X509 standard.
  17641.  
  17642. Encryption is the way to make any kind of data unreadable. In fact,
  17643. today's practice requires many additional security elements from
  17644. encryption algorithms.  They should resist many kind of known attacks
  17645. like just messing with the order of encrypted messages or replaying data
  17646. twice.
  17647.  
  17648. X509 is a standard that makes it possible to identify someone on the
  17649. Internet.  It is most commonly used in e-commerce applications. In basic
  17650. terms, there should be some company (called a "Certificate Authority")
  17651. that assigns electronic certificates to anyone who needs them.
  17652. Certificates rely on asymmetric encryption algorithms that have two
  17653. encryption keys (a public key and a secret key). A certificate owner
  17654. can prove his identity by showing his certificate to other party. A
  17655. certificate consists of its owner's public key. Any data encrypted with
  17656. this public key can be decrypted only using the corresponding secret
  17657. key, which is held by the owner of the certificate.
  17658.  
  17659. MySQL doesn't use encrypted connections by default, because doing so
  17660. would make the client/server protocol much slower. Any kind of
  17661. additional functionality requires the computer to do additional work and
  17662. encrypting data is a CPU-intensive operation that requires time and can
  17663. delay MySQL main tasks. By default MySQL is tuned to be fast as
  17664. possible.
  17665.  
  17666. If you need more information about SSL, X509, or encryption, you should
  17667. use your favourite Internet search engine and search for keywords in
  17668. which you are interested.
  17669.  
  17670. Requirements
  17671. ............
  17672.  
  17673. To get secure connections to work with MySQL you must do the following:
  17674.  
  17675.   1. Install the OpenSSL library. We have tested MySQL with OpenSSL
  17676.      0.9.6.  `http://www.openssl.org/'.
  17677.  
  17678.   2. Configure MySQL with `--with-vio --with-openssl'.
  17679.  
  17680.   3. If you are using an old MySQL installation, you have to update your
  17681.      `mysql.user' table with some new SSL-related columns. You can do
  17682.      this by running the `mysql_fix_privilege_tables.sh' script.  This
  17683.      is necessary if your grant tables date from a version prior to
  17684.      MySQL 4.0.0.
  17685.  
  17686.   4. You can check if a running `mysqld' server supports OpenSSL by
  17687.      examining if `SHOW VARIABLES LIKE 'have_openssl'' returns `YES'.
  17688.  
  17689. Setting Up SSL Certificates for MySQL
  17690. .....................................
  17691.  
  17692. Here is an example for setting up SSL certificates for MySQL:
  17693.  
  17694.      DIR=`pwd`/openssl
  17695.      PRIV=$DIR/private
  17696.      
  17697.      mkdir $DIR $PRIV $DIR/newcerts
  17698.      cp /usr/share/ssl/openssl.cnf $DIR
  17699.      replace ./demoCA $DIR -- $DIR/openssl.cnf
  17700.      
  17701.      # Create necessary files: $database, $serial and $new_certs_dir
  17702.      # directory (optional)
  17703.      
  17704.      touch $DIR/index.txt
  17705.      echo "01" > $DIR/serial
  17706.      
  17707.      #
  17708.      # Generation of Certificate Authority(CA)
  17709.      #
  17710.      
  17711.      openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem \
  17712.          -config $DIR/openssl.cnf
  17713.      
  17714.      # Sample output:
  17715.      # Using configuration from /home/monty/openssl/openssl.cnf
  17716.      # Generating a 1024 bit RSA private key
  17717.      # ................++++++
  17718.      # .........++++++
  17719.      # writing new private key to '/home/monty/openssl/private/cakey.pem'
  17720.      # Enter PEM pass phrase:
  17721.      # Verifying password - Enter PEM pass phrase:
  17722.      # -----
  17723.      # You are about to be asked to enter information that will be incorporated
  17724.      # into your certificate request.
  17725.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17726.      # There are quite a few fields but you can leave some blank
  17727.      # For some fields there will be a default value,
  17728.      # If you enter '.', the field will be left blank.
  17729.      # -----
  17730.      # Country Name (2 letter code) [AU]:FI
  17731.      # State or Province Name (full name) [Some-State]:.
  17732.      # Locality Name (eg, city) []:
  17733.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17734.      # Organizational Unit Name (eg, section) []:
  17735.      # Common Name (eg, YOUR name) []:MySQL admin
  17736.      # Email Address []:
  17737.      
  17738.      #
  17739.      # Create server request and key
  17740.      #
  17741.      openssl req -new -keyout $DIR/server-key.pem -out \
  17742.          $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
  17743.      
  17744.      # Sample output:
  17745.      # Using configuration from /home/monty/openssl/openssl.cnf
  17746.      # Generating a 1024 bit RSA private key
  17747.      # ..++++++
  17748.      # ..........++++++
  17749.      # writing new private key to '/home/monty/openssl/server-key.pem'
  17750.      # Enter PEM pass phrase:
  17751.      # Verifying password - Enter PEM pass phrase:
  17752.      # -----
  17753.      # You are about to be asked to enter information that will be incorporated
  17754.      # into your certificate request.
  17755.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17756.      # There are quite a few fields but you can leave some blank
  17757.      # For some fields there will be a default value,
  17758.      # If you enter '.', the field will be left blank.
  17759.      # -----
  17760.      # Country Name (2 letter code) [AU]:FI
  17761.      # State or Province Name (full name) [Some-State]:.
  17762.      # Locality Name (eg, city) []:
  17763.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17764.      # Organizational Unit Name (eg, section) []:
  17765.      # Common Name (eg, YOUR name) []:MySQL server
  17766.      # Email Address []:
  17767.      #
  17768.      # Please enter the following 'extra' attributes
  17769.      # to be sent with your certificate request
  17770.      # A challenge password []:
  17771.      # An optional company name []:
  17772.      
  17773.      #
  17774.      # Remove the passphrase from the key (optional)
  17775.      #
  17776.      
  17777.      openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
  17778.      
  17779.      #
  17780.      # Sign server cert
  17781.      #
  17782.      openssl ca  -policy policy_anything -out $DIR/server-cert.pem \
  17783.          -config $DIR/openssl.cnf -infiles $DIR/server-req.pem
  17784.      
  17785.      # Sample output:
  17786.      # Using configuration from /home/monty/openssl/openssl.cnf
  17787.      # Enter PEM pass phrase:
  17788.      # Check that the request matches the signature
  17789.      # Signature ok
  17790.      # The Subjects Distinguished Name is as follows
  17791.      # countryName           :PRINTABLE:'FI'
  17792.      # organizationName      :PRINTABLE:'MySQL AB'
  17793.      # commonName            :PRINTABLE:'MySQL admin'
  17794.      # Certificate is to be certified until Sep 13 14:22:46 2003 GMT (365 days)
  17795.      # Sign the certificate? [y/n]:y
  17796.      #
  17797.      #
  17798.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  17799.      # Write out database with 1 new entries
  17800.      # Data Base Updated
  17801.      
  17802.      #
  17803.      # Create client request and key
  17804.      #
  17805.      openssl req -new -keyout $DIR/client-key.pem -out \
  17806.          $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
  17807.      
  17808.      # Sample output:
  17809.      # Using configuration from /home/monty/openssl/openssl.cnf
  17810.      # Generating a 1024 bit RSA private key
  17811.      # .....................................++++++
  17812.      # .............................................++++++
  17813.      # writing new private key to '/home/monty/openssl/client-key.pem'
  17814.      # Enter PEM pass phrase:
  17815.      # Verifying password - Enter PEM pass phrase:
  17816.      # -----
  17817.      # You are about to be asked to enter information that will be incorporated
  17818.      # into your certificate request.
  17819.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17820.      # There are quite a few fields but you can leave some blank
  17821.      # For some fields there will be a default value,
  17822.      # If you enter '.', the field will be left blank.
  17823.      # -----
  17824.      # Country Name (2 letter code) [AU]:FI
  17825.      # State or Province Name (full name) [Some-State]:.
  17826.      # Locality Name (eg, city) []:
  17827.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17828.      # Organizational Unit Name (eg, section) []:
  17829.      # Common Name (eg, YOUR name) []:MySQL user
  17830.      # Email Address []:
  17831.      #
  17832.      # Please enter the following 'extra' attributes
  17833.      # to be sent with your certificate request
  17834.      # A challenge password []:
  17835.      # An optional company name []:
  17836.      
  17837.      #
  17838.      # Remove a passphrase from the key (optional)
  17839.      #
  17840.      openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
  17841.      
  17842.      #
  17843.      # Sign client cert
  17844.      #
  17845.      
  17846.      openssl ca  -policy policy_anything -out $DIR/client-cert.pem \
  17847.          -config $DIR/openssl.cnf -infiles $DIR/client-req.pem
  17848.      
  17849.      # Sample output:
  17850.      # Using configuration from /home/monty/openssl/openssl.cnf
  17851.      # Enter PEM pass phrase:
  17852.      # Check that the request matches the signature
  17853.      # Signature ok
  17854.      # The Subjects Distinguished Name is as follows
  17855.      # countryName           :PRINTABLE:'FI'
  17856.      # organizationName      :PRINTABLE:'MySQL AB'
  17857.      # commonName            :PRINTABLE:'MySQL user'
  17858.      # Certificate is to be certified until Sep 13 16:45:17 2003 GMT (365 days)
  17859.      # Sign the certificate? [y/n]:y
  17860.      #
  17861.      #
  17862.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  17863.      # Write out database with 1 new entries
  17864.      # Data Base Updated
  17865.      
  17866.      #
  17867.      # Create a my.cnf file that you can use to test the certificates
  17868.      #
  17869.      
  17870.      cnf=""
  17871.      cnf="$cnf [client]"
  17872.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  17873.      cnf="$cnf ssl-cert=$DIR/client-cert.pem"
  17874.      cnf="$cnf ssl-key=$DIR/client-key.pem"
  17875.      cnf="$cnf [mysqld]"
  17876.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  17877.      cnf="$cnf ssl-cert=$DIR/server-cert.pem"
  17878.      cnf="$cnf ssl-key=$DIR/server-key.pem"
  17879.      echo $cnf | replace " " '
  17880.      ' > $DIR/my.cnf
  17881.      
  17882.      #
  17883.      # To test MySQL
  17884.      
  17885.      mysqld --defaults-file=$DIR/my.cnf &
  17886.      
  17887.      mysql --defaults-file=$DIR/my.cnf
  17888.  
  17889. You can also test your setup by modifying the above `my.cnf' file to
  17890. refer to the demo certificates in the mysql-source-dist/SSL direcory.
  17891.  
  17892. `GRANT' Options
  17893. ...............
  17894.  
  17895. MySQL can check X509 certificate attributes in addition to the normal
  17896. username/password scheme. All the usual options are still required
  17897. (username, password, IP address mask, database/table name).
  17898.  
  17899. There are different possibilities to limit connections:
  17900.  
  17901.    * Without any SSL or X509 options, all kind of encrypted/unencrypted
  17902.      connections are allowed if the username and password are valid.
  17903.  
  17904.    * `REQUIRE SSL' option limits the server to allow only SSL encrypted
  17905.      connections. Note that this option can be omitted if there are any
  17906.      ACL records which allow non-SSL connections.
  17907.  
  17908.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17909.               -> IDENTIFIED BY "goodsecret" REQUIRE SSL;
  17910.  
  17911.    * `REQUIRE X509' means that the client should have a valid
  17912.      certificate but we do not care about the exact certificate, issuer
  17913.      or subject.  The only restriction is that it should be possible to
  17914.      verify its signature with one of the CA certificates.
  17915.  
  17916.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17917.               -> IDENTIFIED BY "goodsecret" REQUIRE X509;
  17918.  
  17919.    * `REQUIRE ISSUER "issuer"' places a restriction on connection
  17920.      attempts: The client must present a valid X509 certificate issued
  17921.      by CA `"issuer"'.  Using X509 certificates always implies
  17922.      encryption, so the `SSL' option is unneccessary.
  17923.  
  17924.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17925.               -> IDENTIFIED BY "goodsecret"
  17926.               -> REQUIRE ISSUER "C=FI, ST=Some-State, L=Helsinki,
  17927.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com";
  17928.  
  17929.    * `REQUIRE SUBJECT "subject"' requires clients to have valid X509
  17930.      certificate with subject `"subject"' on it. If the client presents
  17931.      a certificate that is valid but has a different `"subject"', the
  17932.      connection is disallowed.
  17933.  
  17934.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17935.               -> IDENTIFIED BY "goodsecret"
  17936.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  17937.               "> O=MySQL demo client certificate,
  17938.               "> CN=Tonu Samuel/Email=tonu@mysql.com";
  17939.  
  17940.    * `REQUIRE CIPHER "cipher"' is needed to assure enough strong ciphers
  17941.      and keylengths will be used. SSL itself can be weak if old
  17942.      algorithms with short encryption keys are used. Using this option,
  17943.      we can ask for some exact cipher method to allow a connection.
  17944.  
  17945.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17946.               -> IDENTIFIED BY "goodsecret"
  17947.               -> REQUIRE CIPHER "EDH-RSA-DES-CBC3-SHA";
  17948.  
  17949.      The `SUBJECT', `ISSUER', and `CIPHER' options can be combined in
  17950.      the `REQUIRE' clause like this:
  17951.  
  17952.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17953.               -> IDENTIFIED BY "goodsecret"
  17954.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  17955.               "> O=MySQL demo client certificate,
  17956.               "> CN=Tonu Samuel/Email=tonu@mysql.com"
  17957.               -> AND ISSUER "C=FI, ST=Some-State, L=Helsinki,
  17958.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com"
  17959.               -> AND CIPHER "EDH-RSA-DES-CBC3-SHA";
  17960.  
  17961.      Starting from MySQL 4.0.4 the `AND' keyword is optional between
  17962.      `REQUIRE' options.
  17963.  
  17964.      The order of the options does not matter, but no option can be
  17965.      specified twice.
  17966.  
  17967. Disaster Prevention and Recovery
  17968. ================================
  17969.  
  17970. Database Backups
  17971. ----------------
  17972.  
  17973. Because MySQL tables are stored as files, it is easy to do a backup. To
  17974. get a consistent backup, do a `LOCK TABLES' on the relevant tables
  17975. followed by `FLUSH TABLES' for the tables.  *Note `LOCK TABLES': LOCK
  17976. TABLES.  *Note `FLUSH': FLUSH.  You only need a read lock; this allows
  17977. other threads to continue to query the tables while you are making a
  17978. copy of the files in the database directory.  The `FLUSH TABLE' is
  17979. needed to ensure that the all active index pages is written to disk
  17980. before you start the backup.
  17981.  
  17982. Starting from 3.23.56 and 4.0.12 `BACKUP TABLE' will not allow you to
  17983. overwrite existing files as this would be a security risk.
  17984.  
  17985. If you want to make an SQL level backup of a table, you can use `SELECT
  17986. INTO OUTFILE' or `BACKUP TABLE'. *Note SELECT::.  *Note BACKUP TABLE::.
  17987.  
  17988. Another way to back up a database is to use the `mysqldump' program or
  17989. the `mysqlhotcopy script'. *Note `mysqldump': mysqldump.  *Note
  17990. `mysqlhotcopy': mysqlhotcopy.
  17991.  
  17992.   1. Do a full backup of your databases:
  17993.  
  17994.           shell> mysqldump --tab=/path/to/some/dir --opt --all
  17995.           
  17996.           or
  17997.           
  17998.           shell> mysqlhotcopy database /path/to/some/dir
  17999.  
  18000.      You can also simply copy all table files (`*.frm', `*.MYD', and
  18001.      `*.MYI' files) as long as the server isn't updating anything.  The
  18002.      script `mysqlhotcopy' does use this method.
  18003.  
  18004.   2. Stop `mysqld' if it's running, then start it with the
  18005.      `--log-bin[=file_name]' option.  *Note Binary log::. The binary
  18006.      log file(s) provide you with the information you need to replicate
  18007.      changes to the database that are made subsequent to the point at
  18008.      which you executed `mysqldump'.
  18009.  
  18010. If you have to restore something, try to recover your tables using
  18011. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  18012. all cases.  If `myisamchk' fails, try the following procedure (this
  18013. will only work if you have started MySQL with `--log-bin', see *Note
  18014. Binary log::):
  18015.  
  18016.   1. Restore the original `mysqldump' backup.
  18017.  
  18018.   2. Execute the following command to re-run the updates in the binary
  18019.      log:
  18020.  
  18021.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  18022.  
  18023.      If you are using the update log (which will be removed in MySQL
  18024.      5.0) you can use:
  18025.  
  18026.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  18027.  
  18028. `ls' is used to get all the update log files in the right order.
  18029.  
  18030. You can also do selective backups with `SELECT * INTO OUTFILE
  18031. 'file_name' FROM tbl_name' and restore with `LOAD DATA INFILE
  18032. 'file_name' REPLACE ...' To avoid duplicate records, you need a
  18033. `PRIMARY KEY' or a `UNIQUE' key in the table. The `REPLACE' keyword
  18034. causes old records to be replaced with new ones when a new record
  18035. duplicates an old record on a unique key value.
  18036.  
  18037. If you get performance problems in making backups on your system, you
  18038. can solve this by setting up replication and do the backups on the slave
  18039. instead of on the master. *Note Replication Intro::.
  18040.  
  18041. If you are using a Veritas filesystem, you can do:
  18042.  
  18043.   1. From a client (or Perl), execute: `FLUSH TABLES WITH READ LOCK'.
  18044.  
  18045.   2. From another shell, execute: `mount vxfs snapshot'.
  18046.  
  18047.   3. From the first client, execute: `UNLOCK TABLES'.
  18048.  
  18049.   4. Copy files from snapshot.
  18050.  
  18051.   5. Unmount snapshot.
  18052.  
  18053. `BACKUP TABLE' Syntax
  18054. ---------------------
  18055.  
  18056.      BACKUP TABLE tbl_name[,tbl_name...] TO '/path/to/backup/directory'
  18057.  
  18058. Copies to the backup directory the minimum number of table files needed
  18059. to restore the table, after flushing any buffered changes to disk.
  18060. Currently works only for `MyISAM' tables.  For `MyISAM' tables, copies
  18061. `.frm' (definition)  and `.MYD' (data) files. The index file can be
  18062. rebuilt from those two.
  18063.  
  18064. Before using this command, please see *Note Backup::.
  18065.  
  18066. During the backup, a read lock will be held for each table, one at time,
  18067. as they are being backed up. If you want to back up several tables as a
  18068. snapshot, you must first issue `LOCK TABLES' obtaining a read lock for
  18069. each table in the group.
  18070.  
  18071. The command returns a table with the following columns:
  18072.  
  18073. *Column*    *Value*
  18074. Table       Table name
  18075. Op          Always `backup'
  18076. Msg_type    One of `status', `error',
  18077.             `info', or `warning'
  18078. Msg_text    The message
  18079.  
  18080. Note that `BACKUP TABLE' is only available in MySQL version 3.23.25 and
  18081. later.
  18082.  
  18083. `RESTORE TABLE' Syntax
  18084. ----------------------
  18085.  
  18086.      RESTORE TABLE tbl_name[,tbl_name...] FROM '/path/to/backup/directory'
  18087.  
  18088. Restores the table(s) from the backup that was made with `BACKUP
  18089. TABLE'. Existing tables will not be overwritten; if you try to restore
  18090. over an existing table, you will get an error. Restoring will take
  18091. longer than backing up due to the need to rebuild the index. The more
  18092. keys you have, the longer it will take. Just as `BACKUP TABLE',
  18093. `RESTORE TABLE' currently works only for `MyISAM' tables.
  18094.  
  18095. The command returns a table with the following columns:
  18096.  
  18097. *Column*    *Value*
  18098. Table       Table name
  18099. Op          Always `restore'
  18100. Msg_type    One of `status', `error',
  18101.             `info', or `warning'
  18102. Msg_text    The message
  18103.  
  18104. `CHECK TABLE' Syntax
  18105. --------------------
  18106.  
  18107.      CHECK TABLE tbl_name[,tbl_name...] [option [option...]]
  18108.      
  18109.      option = QUICK | FAST | MEDIUM | EXTENDED | CHANGED
  18110.  
  18111. `CHECK TABLE' works only on `MyISAM' and `InnoDB' tables. On `MyISAM'
  18112. tables, it's the same thing as running `myisamchk --medium-check
  18113. table_name' on the table.
  18114.  
  18115. If you don't specify any option, `MEDIUM' is used.
  18116.  
  18117. Checks the table or tables for errors. For `MyISAM' tables, the key
  18118. statistics are updated. The command returns a table with the following
  18119. columns:
  18120.  
  18121. *Column*    *Value*
  18122. Table       Table name
  18123. Op          Always `check'
  18124. Msg_type    One of `status', `error',
  18125.             `info', or `warning'
  18126. Msg_text    The message
  18127.  
  18128. Note that the statement may produce many rows of information for each
  18129. checked table.  The last row will be of `Msg_type status' and should
  18130. normally be `OK'.  If you don't get `OK', or `Table is already up to
  18131. date' you should normally run a repair of the table. *Note Table
  18132. maintenance::. `Table is already up to date' means that the storage
  18133. manager for the table indicated that there was no need to check the
  18134. table.
  18135.  
  18136. The different check types are as follows:
  18137.  
  18138. *Type*      *Meaning*
  18139. `QUICK'     Don't scan the rows to check for incorrect links.
  18140. `FAST'      Only check tables that haven't been closed properly.
  18141. `CHANGED'   Only check tables that have been changed since the last
  18142.             check or haven't been closed properly.
  18143. `MEDIUM'    Scan rows to verify that deleted links are okay. This also
  18144.             calculates a key checksum for the rows and verifies this
  18145.             with a calculated checksum for the keys.
  18146. `EXTENDED'  Do a full key lookup for all keys for each row.  This
  18147.             ensures that the table is 100% consistent, but will take a
  18148.             long time!
  18149.  
  18150. For dynamically sized `MyISAM' tables, a started check will always do a
  18151. `MEDIUM' check. For statically sized rows, we skip the row scan for
  18152. `QUICK' and `FAST' as the rows are very seldom corrupted.
  18153.  
  18154. You can combine check options, as in the following example that does a
  18155. quick check on the table to see whether it was closed properly:
  18156.  
  18157.      CHECK TABLE test_table FAST QUICK;
  18158.  
  18159. *Note*: that in some cases `CHECK TABLE' will change the table!  This
  18160. happens if the table is marked as 'corrupted' or 'not closed properly'
  18161. but `CHECK TABLE' didn't find any problems in the table.  In this case,
  18162. `CHECK TABLE' will mark the table as okay.
  18163.  
  18164. If a table is corrupted, then it's most likely that the problem is in
  18165. the indexes and not in the data part.  All of the above check types
  18166. checks the indexes thoroughly and should thus find most errors.
  18167.  
  18168. If you just want to check a table that you assume is okay, you should
  18169. use no check options or the `QUICK' option. The latter should be used
  18170. when you are in a hurry and can take the very small risk that `QUICK'
  18171. didn't find an error in the datafile. (In most cases MySQL should find,
  18172. under normal usage, any error in the data file. If this happens then
  18173. the table will be marked as 'corrupted', in which case the table can't
  18174. be used until it's repaired.)
  18175.  
  18176. `FAST' and `CHANGED' are mostly intended to be used from a script (for
  18177. example to be executed from `cron') if you want to check your table
  18178. from time to time. In most cases you `FAST' is to be prefered over
  18179. `CHANGED'.  (The only case when it isn't is when you suspect a bug you
  18180. have found a bug in the `MyISAM' code.)
  18181.  
  18182. `EXTENDED' is only to be used after you have run a normal check but
  18183. still get strange errors from a table when MySQL tries to update a row
  18184. or find a row by key (this is very unlikely if a normal check has
  18185. succeeded!).
  18186.  
  18187. Some things reported by `CHECK TABLE' can't be corrected automatically:
  18188.  
  18189.    * `Found row where the auto_increment column has the value 0'.
  18190.  
  18191.      This means that you have a row in the table where the
  18192.      `AUTO_INCREMENT' index column contains the value 0.  (It's
  18193.      possible to create a row where the `AUTO_INCREMENT' column is 0 by
  18194.      explicitly setting the column to 0 with an `UPDATE' statement.)
  18195.  
  18196.      This isn't an error in itself, but could cause trouble if you
  18197.      decide to dump the table and restore it or do an `ALTER TABLE' on
  18198.      the table. In this case, the `AUTO_INCREMENT' column will change
  18199.      value, according to the rules of `AUTO_INCREMENT' columns, which
  18200.      could cause problems such as a duplicate key error.
  18201.  
  18202.      To get rid of the warning, just execute an `UPDATE' statement to
  18203.      set the column to some other value than 0.
  18204.  
  18205. `REPAIR TABLE' Syntax
  18206. ---------------------
  18207.  
  18208.      REPAIR [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED] [USE_FRM]
  18209.  
  18210. `REPAIR TABLE' works only on `MyISAM' tables and is the same as running
  18211. `myisamchk -r table_name' on the table.
  18212.  
  18213. Normally you should never have to run this command, but if disaster
  18214. strikes you are very likely to get back all your data from a MyISAM
  18215. table with `REPAIR TABLE'. If your tables get corrupted a lot, you
  18216. should try to find the reason for it, to eliminate the need to use
  18217. `REPAIR TABLE'.  *Note Crashing::. *Note MyISAM table problems::.
  18218.  
  18219. `REPAIR TABLE' repairs a possibly corrupted table. The command returns a
  18220. table with the following columns:
  18221.  
  18222. *Column*    *Value*
  18223. Table       Table name
  18224. Op          Always `repair'
  18225. Msg_type    One of `status', `error',
  18226.             `info', or `warning'
  18227. Msg_text    The message
  18228.  
  18229. Note that the statement may produce many rows of information for each
  18230. repaired table.  The last one row will be of `Msg_type status' and
  18231. should normally be `OK'.  If you don't get `OK', you should try
  18232. repairing the table with `myisamchk --safe-recover', as `REPAIR TABLE'
  18233. does not yet implement all the options of `myisamchk'. In the near
  18234. future, we will make it more flexible.
  18235.  
  18236. If `QUICK' is given, `REPAIR TABLE' tries to repair only the index tree.
  18237.  
  18238. If you use `EXTENDED', MySQL will create the index row by row instead
  18239. of creating one index at a time with sorting; this may be better than
  18240. sorting on fixed-length keys if you have long `CHAR' keys that compress
  18241. very well.  This type of repair is like that done by `myisamchk
  18242. --safe-recover'.
  18243.  
  18244. As of `MySQL' 4.0.2, there is a `USE_FRM' mode for `REPAIR'.  Use it if
  18245. the `.MYI' file is missing or if its header is corrupted.  In this mode
  18246. MySQL will recreate the table, using information from the `.frm' file.
  18247. This kind of repair cannot be done with `myisamchk'.
  18248.  
  18249. *Warning:* If `mysqld' dies during a `REPAIR TABLE', it's essential
  18250. that you do at once another `REPAIR' on the table before executing any
  18251. other commands on it. (It's of course always good to start with a
  18252. backup).  In the worst case you can have a new clean index file without
  18253. information about the data file and when the next command you do may
  18254. overwrite the data file.  This is not a likely, but possible scenario.
  18255.  
  18256. Strictly before MySQL 4.1.1, `REPAIR' commands are not written to the
  18257. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  18258. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  18259. used.
  18260.  
  18261. Using `myisamchk' for Table Maintenance and Crash Recovery
  18262. ----------------------------------------------------------
  18263.  
  18264. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  18265. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  18266. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18267.  
  18268. To check/repair MyISAM tables (`.MYI' and `.MYD') you should use the
  18269. `myisamchk' utility. To check/repair ISAM tables (`.ISM' and `.ISD')
  18270. you should use the `isamchk' utility. *Note Table types::.
  18271.  
  18272. In the following text we will talk about `myisamchk', but everything
  18273. also applies to the old `isamchk'.
  18274.  
  18275. You can use the `myisamchk' utility to get information about your
  18276. database tables, check and repair them, or optimise them.  The following
  18277. sections describe how to invoke `myisamchk' (including a description of
  18278. its options), how to set up a table maintenance schedule, and how to
  18279. use `myisamchk' to perform its various functions.
  18280.  
  18281. You can, in most cases, also use the command `OPTIMIZE TABLES' to
  18282. optimise and repair tables, but this is not as fast or reliable (in case
  18283. of real fatal errors) as `myisamchk'.  On the other hand, `OPTIMIZE
  18284. TABLE' is easier to use and you don't have to worry about flushing
  18285. tables.  *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  18286.  
  18287. Even that the repair in `myisamchk' is quite secure, it's always a good
  18288. idea to make a backup _before_ doing a repair (or anything that could
  18289. make a lot of changes to a table)
  18290.  
  18291. `myisamchk' Invocation Syntax
  18292. .............................
  18293.  
  18294. `myisamchk' is invoked like this:
  18295.  
  18296.      shell> myisamchk [options] tbl_name
  18297.  
  18298. The `options' specify what you want `myisamchk' to do.  They are
  18299. described here.  (You can also get a list of options by invoking
  18300. `myisamchk --help'.)  With no options, `myisamchk' simply checks your
  18301. table.  To get more information or to tell `myisamchk' to take
  18302. corrective action, specify options as described here and in the
  18303. following sections.
  18304.  
  18305. `tbl_name' is the database table you want to check/repair.  If you run
  18306. `myisamchk' somewhere other than in the database directory, you must
  18307. specify the path to the file, because `myisamchk' has no idea where your
  18308. database is located.  Actually, `myisamchk' doesn't care whether the
  18309. files you are working on are located in a database directory; you can
  18310. copy the files that correspond to a database table into another
  18311. location and perform recovery operations on them there.
  18312.  
  18313. You can name several tables on the `myisamchk' command-line if you
  18314. wish.  You can also specify a name as an index file name (with the
  18315. `.MYI' suffix), which allows you to specify all tables in a directory
  18316. by using the pattern `*.MYI'.  For example, if you are in a database
  18317. directory, you can check all the tables in the directory like this:
  18318.  
  18319.      shell> myisamchk *.MYI
  18320.  
  18321. If you are not in the database directory, you can check all the tables
  18322. there by specifying the path to the directory:
  18323.  
  18324.      shell> myisamchk /path/to/database_dir/*.MYI
  18325.  
  18326. You can even check all tables in all databases by specifying a wildcard
  18327. with the path to the MySQL data directory:
  18328.  
  18329.      shell> myisamchk /path/to/datadir/*/*.MYI
  18330.  
  18331. The recommended way to quickly check all tables is:
  18332.  
  18333.      myisamchk --silent --fast /path/to/datadir/*/*.MYI
  18334.      isamchk --silent /path/to/datadir/*/*.ISM
  18335.  
  18336. If you want to check all tables and repair all tables that are
  18337. corrupted, you can use the following line:
  18338.  
  18339.      myisamchk --silent --force --fast --update-state -O key_buffer=64M \
  18340.                -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
  18341.                /path/to/datadir/*/*.MYI
  18342.      isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M \
  18343.              -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.ISM
  18344.  
  18345. The above assumes that you have more than 64 M free.
  18346.  
  18347. Note that if you get an error like:
  18348.  
  18349.      myisamchk: warning: 1 clients is using or hasn't closed the table properly
  18350.  
  18351. This means that you are trying to check a table that has been updated by
  18352. the another program (like the `mysqld' server) that hasn't yet closed
  18353. the file or that has died without closing the file properly.
  18354.  
  18355. If you `mysqld' is running, you must force a sync/close of all tables
  18356. with `FLUSH TABLES' and ensure that no one is using the tables while
  18357. you are running `myisamchk'.  In MySQL Version 3.23 the easiest way to
  18358. avoid this problem is to use `CHECK TABLE' instead of `myisamchk' to
  18359. check tables.
  18360.  
  18361. General Options for `myisamchk'
  18362. ...............................
  18363.  
  18364. `myisamchk' supports the following options.
  18365.  
  18366. `-# or --debug=debug_options'
  18367.      Output debug log. The `debug_options' string often is
  18368.      `'d:t:o,filename''.
  18369.  
  18370. `-? or --help'
  18371.      Display a help message and exit.
  18372.  
  18373. `-O var=option, --set-variable var=option'
  18374.      Set the value of a variable.  Please note that `--set-variable' is
  18375.      deprecated since MySQL 4.0, just use `--var=option' on its own.
  18376.      The possible variables and their default values for myisamchk can
  18377.      be examined with `myisamchk --help':
  18378.      *Variable*    *Value*
  18379.      key_buffer_size523264
  18380.      read_buffer_size262136
  18381.      write_buffer_size262136
  18382.      sort_buffer_size2097144
  18383.      sort_key_blocks16
  18384.      decode_bits   9
  18385.  
  18386.      `sort_buffer_size' is used when the keys are repaired by sorting
  18387.      keys, which is the normal case when you use `--recover'.
  18388.  
  18389.      `key_buffer_size' is used when you are checking the table with
  18390.      `--extended-check' or when the keys are repaired by inserting key
  18391.      row by row in to the table (like when doing normal inserts).
  18392.      Repairing through the key buffer is used in the following cases:
  18393.  
  18394.         * If you use `--safe-recover'.
  18395.  
  18396.         * If the temporary files needed to sort the keys would be more
  18397.           than twice as big as when creating the key file directly.
  18398.           This is often the case when you have big `CHAR', `VARCHAR' or
  18399.           `TEXT' keys as the sort needs to store the whole keys during
  18400.           sorting. If you have lots of temporary space and you can
  18401.           force `myisamchk' to repair by sorting you can use the
  18402.           `--sort-recover' option.
  18403.  
  18404.      Reparing through the key buffer takes much less disk space than
  18405.      using sorting, but is also much slower.
  18406.  
  18407.      If you want a faster repair, set the above variables to about 1/4
  18408.      of your available memory.  You can set both variables to big
  18409.      values, as only one of the above buffers will be used at a time.
  18410.  
  18411. `-s or --silent'
  18412.      Silent mode.  Write output only when errors occur. You can use `-s'
  18413.      twice (`-ss') to make `myisamchk' very silent.
  18414.  
  18415. `-v or --verbose'
  18416.      Verbose mode.  Print more information. This can be used with `-d'
  18417.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for more
  18418.      verbosity!
  18419.  
  18420. `-V or --version'
  18421.      Print the `myisamchk' version and exit.
  18422.  
  18423. `-w or, --wait'
  18424.      Instead of giving an error if the table is locked, wait until the
  18425.      table is unlocked before continuing.  Note that if you are running
  18426.      `mysqld' on the table with `--skip-external-locking', the table
  18427.      can only be locked by another `myisamchk' command.
  18428.  
  18429. Check Options for `myisamchk'
  18430. .............................
  18431.  
  18432. `-c or --check'
  18433.      Check table for errors. This is the default operation if you are
  18434.      not giving `myisamchk' any options that override this.
  18435.  
  18436. `-e or --extend-check'
  18437.      Check the table very thoroughly (which is quite slow if you have
  18438.      many indexes).  This option should only be used in extreme cases.
  18439.      Normally, `myisamchk' or `myisamchk --medium-check' should, in most
  18440.      cases, be able to find out if there are any errors in the table.
  18441.  
  18442.      If you are using `--extended-check' and have much memory, you
  18443.      should increase the value of `key_buffer_size' a lot!
  18444.  
  18445. `-F or --fast'
  18446.      Check only tables that haven't been closed properly.
  18447.  
  18448. `-C or --check-only-changed'
  18449.      Check only tables that have changed since the last check.
  18450.  
  18451. `-f or --force'
  18452.      Restart `myisamchk' with `-r' (repair) on the table, if
  18453.      `myisamchk' finds any errors in the table.
  18454.  
  18455. `-i or --information'
  18456.      Print informational statistics about the table that is checked.
  18457.  
  18458. `-m or --medium-check'
  18459.      Faster than extended-check, but only finds 99.99% of all errors.
  18460.      Should, however, be good enough for most cases.
  18461.  
  18462. `-U or --update-state'
  18463.      Store in the `.MYI' file when the table was checked and if the
  18464.      table crashed.  This should be used to get full benefit of the
  18465.      `--check-only-changed' option, but you shouldn't use this option
  18466.      if the `mysqld' server is using the table and you are running
  18467.      `mysqld' with `--skip-external-locking'.
  18468.  
  18469. `-T or --read-only'
  18470.      Don't mark table as checked. This is useful if you use `myisamchk'
  18471.      to check a table that is in use by some other application that
  18472.      doesn't use locking (like `mysqld --skip-external-locking').
  18473.  
  18474. Repair Options for myisamchk
  18475. ............................
  18476.  
  18477. The following options are used if you start `myisamchk' with `-r' or
  18478. `-o':
  18479.  
  18480. `-D # or --data-file-length=#'
  18481.      Max length of datafile (when re-creating datafile when it's
  18482.      'full').
  18483.  
  18484. `-e or --extend-check'
  18485.      Try to recover every possible row from the datafile.  Normally
  18486.      this will also find a lot of garbage rows. Don't use this option
  18487.      if you are not totally desperate.
  18488.  
  18489. `-f or --force'
  18490.      Overwrite old temporary files (`table_name.TMD') instead of
  18491.      aborting.
  18492.  
  18493. `-k # or keys-used=#'
  18494.      If you are using ISAM, tells the ISAM storage engine to update
  18495.      only the first `#' indexes.  If you are using `MyISAM', tells
  18496.      which keys to use, where each binary bit stands for one key (first
  18497.      key is bit 0).  This can be used to get faster inserts!
  18498.      Deactivated indexes can be reactivated by using `myisamchk -r'.
  18499.      keys.
  18500.  
  18501. `-l or --no-symlinks'
  18502.      Do not follow symbolic links. Normally `myisamchk' repairs the
  18503.      table a symlink points at.  This option doesn't exist in MySQL 4.0,
  18504.      as MySQL 4.0 will not remove symlinks during repair.
  18505.  
  18506. `-r or --recover'
  18507.      Can fix almost anything except unique keys that aren't unique
  18508.      (which is an extremely unlikely error with ISAM/MyISAM tables).
  18509.      If you want to recover a table, this is the option to try first.
  18510.      Only if myisamchk reports that the table can't be recovered by
  18511.      `-r', you should then try `-o'.  (Note that in the unlikely case
  18512.      that `-r' fails, the datafile is still intact.)  If you have lots
  18513.      of memory, you should increase the size of `sort_buffer_size'!
  18514.  
  18515. `-o or --safe-recover'
  18516.      Uses an old recovery method (reads through all rows in order and
  18517.      updates all index trees based on the found rows); this is an order
  18518.      of magnitude slower than `-r', but can handle a couple of very
  18519.      unlikely cases that `-r' cannot handle.  This recovery method also
  18520.      uses much less disk space than `-r'. Normally one should always
  18521.      first repair with `-r', and only if this fails use `-o'.
  18522.  
  18523.      If you have lots of memory, you should increase the size of
  18524.      `key_buffer_size'!
  18525.  
  18526. `-n or --sort-recover'
  18527.      Force `myisamchk' to use sorting to resolve the keys even if the
  18528.      temporary files should be very big.
  18529.  
  18530. `--character-sets-dir=...'
  18531.      Directory where character sets are stored.
  18532.  
  18533. `--set-character-set=name'
  18534.      Change the character set used by the index
  18535.  
  18536. `-t or --tmpdir=path'
  18537.      Path for storing temporary files. If this is not set, `myisamchk'
  18538.      will use the environment variable `TMPDIR' for this.  Starting
  18539.      from MySQL 4.1, `tmpdir' can be set to a list of paths separated
  18540.      by colon `:' (semicolon `;' on Windows). They will be used in
  18541.      round-robin fashion.
  18542.  
  18543. `-q or --quick'
  18544.      Faster repair by not modifying the datafile. One can give a second
  18545.      `-q' to force `myisamchk' to modify the original datafile in case
  18546.      of duplicate keys
  18547.  
  18548. `-u or --unpack'
  18549.      Unpack file packed with myisampack.
  18550.  
  18551. Other Options for `myisamchk'
  18552. .............................
  18553.  
  18554. Other actions that `myisamchk' can do, besides repair and check tables:
  18555.  
  18556. `-a or --analyze'
  18557.      Analyse the distribution of keys. This improves join performance by
  18558.      enabling the join optimiser to better choose in which order it
  18559.      should join the tables and which keys it should use: `myisamchk
  18560.      --describe --verbose table_name'' or using `SHOW KEYS' in MySQL.
  18561.  
  18562. `-d or --description'
  18563.      Prints some information about table.
  18564.  
  18565. `-A or --set-auto-increment[=value]'
  18566.      Force `AUTO_INCREMENT' to start at this or higher value. If no
  18567.      value is given, then sets the next `AUTO_INCREMENT' value to the
  18568.      highest used value for the auto key + 1.
  18569.  
  18570. `-S or --sort-index'
  18571.      Sort the index tree blocks in high-low order.  This will optimise
  18572.      seeks and will make table scanning by key faster.
  18573.  
  18574. `-R or --sort-records=#'
  18575.      Sorts records according to an index.  This makes your data much
  18576.      more localised and may speed up ranged `SELECT' and `ORDER BY'
  18577.      operations on this index. (It may be very slow to do a sort the
  18578.      first time!)  To find out a table's index numbers, use `SHOW
  18579.      INDEX', which shows a table's indexes in the same order that
  18580.      `myisamchk' sees them.  Indexes are numbered beginning with 1.
  18581.  
  18582. `myisamchk' Memory Usage
  18583. ........................
  18584.  
  18585. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  18586. uses no more memory than you specify with the `-O' options.  If you are
  18587. going to use `myisamchk' on very large files, you should first decide
  18588. how much memory you want it to use.  The default is to use only about
  18589. 3M to fix things.  By using larger values, you can get `myisamchk' to
  18590. operate faster.  For example, if you have more than 32M RAM, you could
  18591. use options such as these (in addition to any other options you might
  18592. specify):
  18593.  
  18594.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  18595.  
  18596. Using `-O sort=16M' should probably be enough for most cases.
  18597.  
  18598. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  18599. points to a memory filesystem, you may easily get out of memory errors.
  18600. If this happens, set `TMPDIR' to point at some directory with more
  18601. space and restart `myisamchk'.
  18602.  
  18603. When repairing, `myisamchk' will also need a lot of disk space:
  18604.  
  18605.    * Double the size of the record file (the original one and a copy).
  18606.      This space is not needed if one does a repair with `--quick', as
  18607.      in this case only the index file will be re-created.  This space
  18608.      is needed on the same disk as the original record file!
  18609.  
  18610.    * Space for the new index file that replaces the old one. The old
  18611.      index file is truncated at start, so one usually ignore this space.
  18612.      This space is needed on the same disk as the original index file!
  18613.  
  18614.    * When using `--recover' or `--sort-recover' (but not when using
  18615.      `--safe-recover'), you will need space for a sort buffer for:
  18616.      `(largest_key + row_pointer_length)*number_of_rows * 2'.  You can
  18617.      check the length of the keys and the row_pointer_length with
  18618.      `myisamchk -dv table'.  This space is allocated on the temporary
  18619.      disk (specified by `TMPDIR' or `--tmpdir=#').
  18620.  
  18621. If you have a problem with disk space during repair, you can try to use
  18622. `--safe-recover' instead of `--recover'.
  18623.  
  18624. Using `myisamchk' for Crash Recovery
  18625. ....................................
  18626.  
  18627. If you run `mysqld' with `--skip-external-locking' (which is the
  18628. default on some systems, like Linux), you can't reliably use `myisamchk'
  18629. to check a table when `mysqld' is using the same table.  If you can be
  18630. sure that no one is accessing the tables through `mysqld' while you run
  18631. `myisamchk', you only have to do `mysqladmin flush-tables' before you
  18632. start checking the tables.  If you can't guarantee the above, then you
  18633. must take down `mysqld' while you check the tables.  If you run
  18634. `myisamchk' while `mysqld' is updating the tables, you may get a
  18635. warning that a table is corrupt even if it isn't.
  18636.  
  18637. If you are not using `--skip-external-locking', you can use `myisamchk'
  18638. to check tables at any time.  While you do this, all clients that try
  18639. to update the table will wait until `myisamchk' is ready before
  18640. continuing.
  18641.  
  18642. If you use `myisamchk' to repair or optimise tables, you *must* always
  18643. ensure that the `mysqld' server is not using the table (this also
  18644. applies if you are using `--skip-external-locking').  If you don't take
  18645. down `mysqld' you should at least do a `mysqladmin flush-tables' before
  18646. you run `myisamchk'.  Your tables *may be corrupted* if the server and
  18647. `myisamchk' access the tables simultaneously.
  18648.  
  18649. This chapter describes how to check for and deal with data corruption
  18650. in MySQL databases.  If your tables get corrupted frequently you should
  18651. try to find the reason for this! *Note Crashing::.
  18652.  
  18653. The `MyISAM' table section contains reason for why a table could be
  18654. corrupted. *Note MyISAM table problems::.
  18655.  
  18656. When performing crash recovery, it is important to understand that each
  18657. table `tbl_name' in a database corresponds to three files in the
  18658. database directory:
  18659.  
  18660. *File*         *Purpose*
  18661. `tbl_name.frm' Table definition
  18662.                (form) file
  18663. `tbl_name.MYD' Datafile
  18664. `tbl_name.MYI' Index file
  18665.  
  18666. Each of these three file types is subject to corruption in various
  18667. ways, but problems occur most often in datafiles and index files.
  18668.  
  18669. `myisamchk' works by creating a copy of the `.MYD' (data) file row by
  18670. row. It ends the repair stage by removing the old `.MYD' file and
  18671. renaming the new file to the original file name.  If you use `--quick',
  18672. `myisamchk' does not create a temporary `.MYD' file, but instead
  18673. assumes that the `.MYD' file is correct and only generates a new index
  18674. file without touching the `.MYD' file. This is safe, because
  18675. `myisamchk' automatically detects if the `.MYD' file is corrupt and
  18676. aborts the repair in this case.  You can also give two `--quick'
  18677. options to `myisamchk'.  In this case, `myisamchk' does not abort on
  18678. some errors (like duplicate key) but instead tries to resolve them by
  18679. modifying the `.MYD' file. Normally the use of two `--quick' options is
  18680. useful only if you have too little free disk space to perform a normal
  18681. repair.  In this case you should at least make a backup before running
  18682. `myisamchk'.
  18683.  
  18684. How to Check Tables for Errors
  18685. ..............................
  18686.  
  18687. To check a MyISAM table, use the following commands:
  18688.  
  18689. `myisamchk tbl_name'
  18690.      This finds 99.99% of all errors. What it can't find is corruption
  18691.      that involves *only* the datafile (which is very unusual). If you
  18692.      want to check a table, you should normally run `myisamchk' without
  18693.      options or with either the `-s' or `--silent' option.
  18694.  
  18695. `myisamchk -m tbl_name'
  18696.      This finds 99.999% of all errors. It checks first all index
  18697.      entries for errors and then it reads through all rows. It
  18698.      calculates a checksum for all keys in the rows and verifies that
  18699.      they checksum matches the checksum for the keys in the index tree.
  18700.  
  18701. `myisamchk -e tbl_name'
  18702.      This does a complete and thorough check of all data (`-e' means
  18703.      "extended check"). It does a check-read of every key for each row
  18704.      to verify that they indeed point to the correct row.  This may
  18705.      take a long time on a big table with many keys.  `myisamchk' will
  18706.      normally stop after the first error it finds. If you want to
  18707.      obtain more information, you can add the `--verbose' (`-v')
  18708.      option.  This causes `myisamchk' to keep going, up through a
  18709.      maximum of 20 errors.  In normal usage, a simple `myisamchk' (with
  18710.      no arguments other than the table name) is sufficient.
  18711.  
  18712. `myisamchk -e -i tbl_name'
  18713.      Like the previous command, but the `-i' option tells `myisamchk' to
  18714.      print some informational statistics, too.
  18715.  
  18716. How to Repair Tables
  18717. ....................
  18718.  
  18719. In the following section we only talk about using `myisamchk' on
  18720. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  18721. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  18722. instead.
  18723.  
  18724. Starting with MySQL Version 3.23.14, you can repair MyISAM tables with
  18725. the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18726.  
  18727. The symptoms of a corrupted table include queries that abort
  18728. unexpectedly and observable errors such as these:
  18729.  
  18730.    * `tbl_name.frm' is locked against change
  18731.  
  18732.    * Can't find file `tbl_name.MYI' (Errcode: ###)
  18733.  
  18734.    * Unexpected end of file
  18735.  
  18736.    * Record file is crashed
  18737.  
  18738.    * Got error ### from table handler
  18739.  
  18740.      To get more information about the error you can run `perror ###'.
  18741.      Here is the most common errors that indicates a problem with the
  18742.      table:
  18743.  
  18744.           shell> perror 126 127 132 134 135 136 141 144 145
  18745.           126 = Index file is crashed / Wrong file format
  18746.           127 = Record-file is crashed
  18747.           132 = Old database file
  18748.           134 = Record was already deleted (or record file crashed)
  18749.           135 = No more room in record file
  18750.           136 = No more room in index file
  18751.           141 = Duplicate unique key or constraint on write or update
  18752.           144 = Table is crashed and last repair failed
  18753.           145 = Table was marked as crashed and should be repaired
  18754.  
  18755.      Note that error 135, no more room in record file, is not an error
  18756.      that can be fixed by a simple repair. In this case you have to do:
  18757.  
  18758.           ALTER TABLE table MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;
  18759.  
  18760.  
  18761. In the other cases, you must repair your tables. `myisamchk' can
  18762. usually detect and fix most things that go wrong.
  18763.  
  18764. The repair process involves up to four stages, described here. Before
  18765. you begin, you should `cd' to the database directory and check the
  18766. permissions of the table files. Make sure they are readable by the Unix
  18767. user that `mysqld' runs as (and to you, because you need to access the
  18768. files you are checking).  If it turns out you need to modify files,
  18769. they must also be writable by you.
  18770.  
  18771. If you are using MySQL Version 3.23.16 and above, you can (and should)
  18772. use the `CHECK' and `REPAIR' commands to check and repair `MyISAM'
  18773. tables.  *Note CHECK TABLE::.  *Note REPAIR TABLE::.
  18774.  
  18775. The manual section about table maintenance includes the options to
  18776. `isamchk'/`myisamchk'.  *Note Table maintenance::.
  18777.  
  18778. The following section is for the cases where the above command fails or
  18779. if you want to use the extended features that `isamchk'/`myisamchk'
  18780. provides.
  18781.  
  18782. If you are going to repair a table from the command-line, you must first
  18783. take down the `mysqld' server. Note that when you do `mysqladmin
  18784. shutdown' on a remote server, the `mysqld' server will still be alive
  18785. for a while after `mysqladmin' returns, until all queries are stopped
  18786. and all keys have been flushed to disk.
  18787.  
  18788. *Stage 1: Checking your tables*
  18789.  
  18790. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  18791. Use the `-s' (silent) option to suppress unnecessary information.
  18792.  
  18793. If the `mysqld' server is done you should use the -update option to tell
  18794. `myisamchk' to mark the table as 'checked'.
  18795.  
  18796. You have to repair only those tables for which `myisamchk' announces an
  18797. error.  For such tables, proceed to Stage 2.
  18798.  
  18799. If you get weird errors when checking (such as `out of memory' errors),
  18800. or if `myisamchk' crashes, go to Stage 3.
  18801.  
  18802. *Stage 2: Easy safe repair*
  18803.  
  18804. Note: If you want repairing to go much faster, you should add: `-O
  18805. sort_buffer=# -O key_buffer=#' (where # is about 1/4 of the available
  18806. memory) to all `isamchk/myisamchk' commands.
  18807.  
  18808. First, try `myisamchk -r -q tbl_name' (`-r -q' means "quick recovery
  18809. mode"). This will attempt to repair the index file without touching the
  18810. datafile.  If the datafile contains everything that it should and the
  18811. delete links point at the correct locations within the datafile, this
  18812. should work, and the table is fixed. Start repairing the next table.
  18813. Otherwise, use the following procedure:
  18814.  
  18815.   1. Make a backup of the datafile before continuing.
  18816.  
  18817.   2. Use `myisamchk -r tbl_name' (`-r' means "recovery mode"). This will
  18818.      remove incorrect records and deleted records from the datafile and
  18819.      reconstruct the index file.
  18820.  
  18821.   3. If the preceding step fails, use `myisamchk --safe-recover
  18822.      tbl_name'.  Safe recovery mode uses an old recovery method that
  18823.      handles a few cases that regular recovery mode doesn't (but is
  18824.      slower).
  18825.  
  18826. If you get weird errors when repairing (such as `out of memory'
  18827. errors), or if `myisamchk' crashes, go to Stage 3.
  18828.  
  18829. *Stage 3: Difficult repair*
  18830.  
  18831. You should only reach this stage if the first 16K block in the index
  18832. file is destroyed or contains incorrect information, or if the index
  18833. file is missing.  In this case, it's necessary to create a new index
  18834. file. Do so as follows:
  18835.  
  18836.   1. Move the datafile to some safe place.
  18837.  
  18838.   2. Use the table description file to create new (empty) data and
  18839.      index files:
  18840.  
  18841.           shell> mysql db_name
  18842.           mysql> SET AUTOCOMMIT=1;
  18843.           mysql> TRUNCATE TABLE table_name;
  18844.           mysql> quit
  18845.  
  18846.      If your SQL version doesn't have `TRUNCATE TABLE', use `DELETE FROM
  18847.      table_name' instead.
  18848.  
  18849.   3. Copy the old datafile back onto the newly created datafile.
  18850.      (Don't just move the old file back onto the new file; you want to
  18851.      retain a copy in case something goes wrong.)
  18852.  
  18853. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  18854. be an endless loop.)
  18855.  
  18856. As of `MySQL' 4.0.2 you can also use `REPAIR ... USE_FRM' which
  18857. performs the whole procedure automatically.
  18858.  
  18859. *Stage 4: Very difficult repair*
  18860.  
  18861. You should reach this stage only if the description file has also
  18862. crashed. That should never happen, because the description file isn't
  18863. changed after the table is created:
  18864.  
  18865.   1. Restore the description file from a backup and go back to Stage 3.
  18866.      You can also restore the index file and go back to Stage 2.  In
  18867.      the latter case, you should start with `myisamchk -r'.
  18868.  
  18869.   2. If you don't have a backup but know exactly how the table was
  18870.      created, create a copy of the table in another database.  Remove
  18871.      the new datafile, then move the description and index files from
  18872.      the other database to your crashed database.  This gives you new
  18873.      description and index files, but leaves the datafile alone.  Go
  18874.      back to Stage 2 and attempt to reconstruct the index file.
  18875.  
  18876. Table Optimisation
  18877. ..................
  18878.  
  18879. To coalesce fragmented records and eliminate wasted space resulting from
  18880. deleting or updating records, run `myisamchk' in recovery mode:
  18881.  
  18882.      shell> myisamchk -r tbl_name
  18883.  
  18884. You can optimise a table in the same way using the SQL `OPTIMIZE TABLE'
  18885. statement.  `OPTIMIZE TABLE' does a repair of the table and a key
  18886. analysis, and also sorts the index tree to give faster key lookups.
  18887. There is also no possibility of unwanted interaction between a utility
  18888. and the server, because the server does all the work when you use
  18889. `OPTIMIZE TABLE'. *Note OPTIMIZE TABLE::.
  18890.  
  18891. `myisamchk' also has a number of other options you can use to improve
  18892. the performance of a table:
  18893.  
  18894.    * `-S', `--sort-index'
  18895.  
  18896.    * `-R index_num', `--sort-records=index_num'
  18897.  
  18898.    * `-a', `--analyze'
  18899.  
  18900. For a full description of the option. *Note myisamchk syntax::.
  18901.  
  18902. Setting Up a Table Maintenance Regimen
  18903. --------------------------------------
  18904.  
  18905. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  18906. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  18907. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18908.  
  18909. It is a good idea to perform table checks on a regular basis rather than
  18910. waiting for problems to occur.  For maintenance purposes, you can use
  18911. `myisamchk -s' to check tables.  The `-s' option (short for `--silent')
  18912. causes `myisamchk' to run in silent mode, printing messages only when
  18913. errors occur.
  18914.  
  18915. It's also a good idea to check tables when the server starts up.  For
  18916. example, whenever the machine has done a reboot in the middle of an
  18917. update, you usually need to check all the tables that could have been
  18918. affected. (This is an "expected crashed table".) You could add a test to
  18919. `mysqld_safe' that runs `myisamchk' to check all tables that have been
  18920. modified during the last 24 hours if there is an old `.pid' (process
  18921. ID) file left after a reboot.  (The `.pid' file is created by `mysqld'
  18922. when it starts up and removed when it terminates normally.  The
  18923. presence of a `.pid' file at system startup time indicates that
  18924. `mysqld' terminated abnormally.)
  18925.  
  18926. An even better test would be to check any table whose last-modified time
  18927. is more recent than that of the `.pid' file.
  18928.  
  18929. You should also check your tables regularly during normal system
  18930. operation.  At MySQL AB, we run a `cron' job to check all our important
  18931. tables once a week, using a line like this in a `crontab' file:
  18932.  
  18933.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  18934.  
  18935. This prints out information about crashed tables so we can examine and
  18936. repair them when needed.
  18937.  
  18938. As we haven't had any unexpectedly crashed tables (tables that become
  18939. corrupted for reasons other than hardware trouble) for a couple of
  18940. years now (this is really true), once a week is more than enough for us.
  18941.  
  18942. We recommend that to start with, you execute `myisamchk -s' each night
  18943. on all tables that have been updated during the last 24 hours, until
  18944. you come to trust MySQL as much as we do.
  18945.  
  18946. Normally you don't need to maintain MySQL tables that much.  If you are
  18947. changing tables with dynamic size rows (tables with `VARCHAR', `BLOB'
  18948. or `TEXT' columns) or have tables with many deleted rows you may want
  18949. to from time to time (once a month?) defragment/reclaim space from the
  18950. tables.
  18951.  
  18952. You can do this by using `OPTIMIZE TABLE' on the tables in question or
  18953. if you can take the `mysqld' server down for a while do:
  18954.  
  18955.      isamchk -r --silent --sort-index -O sort_buffer_size=16M */*.ISM
  18956.      myisamchk -r --silent --sort-index  -O sort_buffer_size=16M */*.MYI
  18957.  
  18958. Getting Information About a Table
  18959. ---------------------------------
  18960.  
  18961. To get a description of a table or statistics about it, use the
  18962. commands shown here. We explain some of the information in more detail
  18963. later:
  18964.  
  18965.    * myisamchk -d tbl_name Runs `myisamchk' in "describe mode" to
  18966.      produce a description of your table. If you start the MySQL server
  18967.      using the `--skip-external-locking' option, `myisamchk' may report
  18968.      an error for a table that is updated while it runs.  However,
  18969.      because `myisamchk' doesn't change the table in describe mode,
  18970.      there isn't any risk of destroying data.
  18971.  
  18972.    * myisamchk -d -v tbl_name To produce more information about what
  18973.      `myisamchk' is doing, add `-v' to tell it to run in verbose mode.
  18974.  
  18975.    * myisamchk -eis tbl_name Shows only the most important information
  18976.      from a table. It is slow because it must read the whole table.
  18977.  
  18978.    * myisamchk -eiv tbl_name This is like `-eis', but tells you what is
  18979.      being done.
  18980.  
  18981. Example of `myisamchk -d' output:
  18982.      MyISAM file:     company.MYI
  18983.      Record format:   Fixed length
  18984.      Data records:    1403698  Deleted blocks:         0
  18985.      Recordlength:    226
  18986.      
  18987.      table description:
  18988.      Key Start Len Index   Type
  18989.      1   2     8   unique  double
  18990.      2   15    10  multip. text packed stripped
  18991.      3   219   8   multip. double
  18992.      4   63    10  multip. text packed stripped
  18993.      5   167   2   multip. unsigned short
  18994.      6   177   4   multip. unsigned long
  18995.      7   155   4   multip. text
  18996.      8   138   4   multip. unsigned long
  18997.      9   177   4   multip. unsigned long
  18998.          193   1           text
  18999.  
  19000. Example of `myisamchk -d -v' output:
  19001.      MyISAM file:         company
  19002.      Record format:       Fixed length
  19003.      File-version:        1
  19004.      Creation time:       1999-10-30 12:12:51
  19005.      Recover time:        1999-10-31 19:13:01
  19006.      Status:              checked
  19007.      Data records:           1403698  Deleted blocks:              0
  19008.      Datafile parts:         1403698  Deleted data:                0
  19009.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     3
  19010.      Max datafile length: 3791650815  Max keyfile length: 4294967294
  19011.      Recordlength:               226
  19012.      
  19013.      table description:
  19014.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  19015.      1   2     8   unique  double                      1 15845376      1024
  19016.      2   15    10  multip. text packed stripped        2 25062400      1024
  19017.      3   219   8   multip. double                     73 40907776      1024
  19018.      4   63    10  multip. text packed stripped        5 48097280      1024
  19019.      5   167   2   multip. unsigned short           4840 55200768      1024
  19020.      6   177   4   multip. unsigned long            1346 65145856      1024
  19021.      7   155   4   multip. text                     4995 75090944      1024
  19022.      8   138   4   multip. unsigned long              87 85036032      1024
  19023.      9   177   4   multip. unsigned long             178 96481280      1024
  19024.          193   1           text
  19025.  
  19026. Example of `myisamchk -eis' output:
  19027.      Checking MyISAM file: company
  19028.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19029.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  19030.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19031.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  19032.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19033.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19034.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19035.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19036.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  19037.      Total:    Keyblocks used:  98%  Packed:   17%
  19038.      
  19039.      Records:          1403698    M.recordlength:     226
  19040.      Packed:             0%
  19041.      Recordspace used:     100%   Empty space:          0%
  19042.      Blocks/Record:   1.00
  19043.      Record blocks:    1403698    Delete blocks:        0
  19044.      Recorddata:     317235748    Deleted data:         0
  19045.      Lost space:             0    Linkdata:             0
  19046.      
  19047.      User time 1626.51, System time 232.36
  19048.      Maximum resident set size 0, Integral resident set size 0
  19049.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  19050.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  19051.      Voluntary context switches 639, Involuntary context switches 28966
  19052.  
  19053. Example of `myisamchk -eiv' output:
  19054.      Checking MyISAM file: company
  19055.      Data records: 1403698   Deleted blocks:       0
  19056.      - check file-size
  19057.      - check delete-chain
  19058.      block_size 1024:
  19059.      index  1:
  19060.      index  2:
  19061.      index  3:
  19062.      index  4:
  19063.      index  5:
  19064.      index  6:
  19065.      index  7:
  19066.      index  8:
  19067.      index  9:
  19068.      No recordlinks
  19069.      - check index reference
  19070.      - check data record references index: 1
  19071.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19072.      - check data record references index: 2
  19073.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  19074.      - check data record references index: 3
  19075.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  19076.      - check data record references index: 4
  19077.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  19078.      - check data record references index: 5
  19079.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19080.      - check data record references index: 6
  19081.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19082.      - check data record references index: 7
  19083.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19084.      - check data record references index: 8
  19085.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  19086.      - check data record references index: 9
  19087.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  19088.      Total:    Keyblocks used:   9%  Packed:   17%
  19089.      
  19090.      - check records and index references
  19091.      [LOTS OF ROW NUMBERS DELETED]
  19092.      
  19093.      Records:          1403698    M.recordlength:     226   Packed:             0%
  19094.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  19095.      Record blocks:    1403698    Delete blocks:        0
  19096.      Recorddata:     317235748    Deleted data:         0
  19097.      Lost space:             0    Linkdata:             0
  19098.      
  19099.      User time 1639.63, System time 251.61
  19100.      Maximum resident set size 0, Integral resident set size 0
  19101.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  19102.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  19103.      Voluntary context switches 10604, Involuntary context switches 122798
  19104.  
  19105. Here are the sizes of the data and index files for the table used in the
  19106. preceding examples:
  19107.  
  19108.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  19109.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  19110.  
  19111. Explanations for the types of information `myisamchk' produces are
  19112. given here.  The "keyfile" is the index file.  "Record" and "row" are
  19113. synonymous:
  19114.  
  19115.    * ISAM file Name of the ISAM (index) file.
  19116.  
  19117.    * Isam-version Version of ISAM format. Currently always 2.
  19118.  
  19119.    * Creation time When the datafile was created.
  19120.  
  19121.    * Recover time When the index/datafile was last reconstructed.
  19122.  
  19123.    * Data records How many records are in the table.
  19124.  
  19125.    * Deleted blocks How many deleted blocks still have reserved space.
  19126.      You can optimise your table to minimise this space.  *Note
  19127.      Optimisation::.
  19128.  
  19129.    * Data file: Parts For dynamic record format, this indicates how
  19130.      many data blocks there are. For an optimised table without
  19131.      fragmented records, this is the same as `Data records'.
  19132.  
  19133.    * Deleted data How many bytes of non-reclaimed deleted data there
  19134.      are.  You can optimise your table to minimise this space.  *Note
  19135.      Optimisation::.
  19136.  
  19137.    * Data file pointer The size of the datafile pointer, in bytes. It
  19138.      is usually 2, 3, 4, or 5 bytes. Most tables manage with 2 bytes,
  19139.      but this cannot be controlled from MySQL yet. For fixed tables,
  19140.      this is a record address. For dynamic tables, this is a byte
  19141.      address.
  19142.  
  19143.    * Keyfile pointer The size of the index file pointer, in bytes. It
  19144.      is usually 1, 2, or 3 bytes. Most tables manage with 2 bytes, but
  19145.      this is calculated automatically by MySQL. It is always a block
  19146.      address.
  19147.  
  19148.    * Max datafile length How long the table's datafile (`.MYD' file)
  19149.      can become, in bytes.
  19150.  
  19151.    * Max keyfile length How long the table's key file (`.MYI' file) can
  19152.      become, in bytes.
  19153.  
  19154.    * Recordlength How much space each record takes, in bytes.
  19155.  
  19156.    * Record format The format used to store table rows.  The examples
  19157.      shown above use `Fixed length'.  Other possible values are
  19158.      `Compressed' and `Packed'.
  19159.  
  19160.    * table description A list of all keys in the table. For each key,
  19161.      some low-level information is presented:
  19162.  
  19163.         - Key This key's number.
  19164.  
  19165.         - Start Where in the record this index part starts.
  19166.  
  19167.         - Len How long this index part is. For packed numbers, this
  19168.           should always be the full length of the column. For strings,
  19169.           it may be shorter than the full length of the indexed column,
  19170.           because you can index a prefix of a string column.
  19171.  
  19172.         - Index `unique' or `multip.' (multiple). Indicates whether one
  19173.           value can exist multiple times in this index.
  19174.  
  19175.         - Type What data-type this index part has. This is an ISAM
  19176.           data-type with the options `packed', `stripped' or `empty'.
  19177.  
  19178.         - Root Address of the root index block.
  19179.  
  19180.         - Blocksize The size of each index block. By default this is
  19181.           1024, but the value may be changed at compile time.
  19182.  
  19183.         - Rec/key This is a statistical value used by the optimiser. It
  19184.           tells how many records there are per value for this key. A
  19185.           unique key always has a value of 1. This may be updated after
  19186.           a table is loaded (or greatly changed) with `myisamchk -a'.
  19187.           If this is not updated at all, a default value of 30 is given.
  19188.  
  19189.    * In the first example above, the 9th key is a multi-part key with
  19190.      two parts.
  19191.  
  19192.    * Keyblocks used What percentage of the keyblocks are used. Because
  19193.      the table used in the examples had just been reorganised with
  19194.      `myisamchk', the values are very high (very near the theoretical
  19195.      maximum).
  19196.  
  19197.    * Packed MySQL tries to pack keys with a common suffix. This can
  19198.      only be used for `CHAR'/`VARCHAR'/`DECIMAL' keys. For long strings
  19199.      like names, this can significantly reduce the space used. In the
  19200.      third example above, the 4th key is 10 characters long and a 60%
  19201.      reduction in space is achieved.
  19202.  
  19203.    * Max levels How deep the B-tree for this key is. Large tables with
  19204.      long keys get high values.
  19205.  
  19206.    * Records How many rows are in the table.
  19207.  
  19208.    * M.recordlength The average record length. For tables with
  19209.      fixed-length records, this is the exact record length.
  19210.  
  19211.    * Packed MySQL strips spaces from the end of strings. The `Packed'
  19212.      value indicates the percentage of savings achieved by doing this.
  19213.  
  19214.    * Recordspace used What percentage of the datafile is used.
  19215.  
  19216.    * Empty space What percentage of the datafile is unused.
  19217.  
  19218.    * Blocks/Record Average number of blocks per record (that is, how
  19219.      many links a fragmented record is composed of). This is always 1.0
  19220.      for fixed-format tables. This value should stay as close to 1.0 as
  19221.      possible. If it gets too big, you can reorganise the table with
  19222.      `myisamchk'.  *Note Optimisation::.
  19223.  
  19224.    * Recordblocks How many blocks (links) are used. For fixed format,
  19225.      this is the same as the number of records.
  19226.  
  19227.    * Deleteblocks How many blocks (links) are deleted.
  19228.  
  19229.    * Recorddata How many bytes in the datafile are used.
  19230.  
  19231.    * Deleted data How many bytes in the datafile are deleted (unused).
  19232.  
  19233.    * Lost space If a record is updated to a shorter length, some space
  19234.      is lost. This is the sum of all such losses, in bytes.
  19235.  
  19236.    * Linkdata When the dynamic table format is used, record fragments
  19237.      are linked with pointers (4 to 7 bytes each). `Linkdata' is the
  19238.      sum of the amount of storage used by all such pointers.
  19239.  
  19240. If a table has been compressed with `myisampack', `myisamchk -d' prints
  19241. additional information about each table column.  See *Note
  19242. `myisampack': myisampack, for an example of this information and a
  19243. description of what it means.
  19244.  
  19245. Database Administration Language Reference
  19246. ==========================================
  19247.  
  19248. `OPTIMIZE TABLE' Syntax
  19249. -----------------------
  19250.  
  19251.      OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name]...
  19252.  
  19253. `OPTIMIZE TABLE' should be used if you have deleted a large part of a
  19254. table or if you have made many changes to a table with variable-length
  19255. rows (tables that have `VARCHAR', `BLOB', or `TEXT' columns).  Deleted
  19256. records are maintained in a linked list and subsequent `INSERT'
  19257. operations reuse old record positions. You can use `OPTIMIZE TABLE' to
  19258. reclaim the unused space and to defragment the datafile.
  19259.  
  19260. In most setups you don't have to run `OPTIMIZE TABLE' at all.  Even if
  19261. you do a lot of updates to variable length rows it's not likely that
  19262. you need to do this more than once a month/week and only on certain
  19263. tables.
  19264.  
  19265. For the moment, `OPTIMIZE TABLE' works only on `MyISAM' and `BDB'
  19266. tables. For `BDB' tables, `OPTIMIZE TABLE' is currently mapped to
  19267. `ANALYZE TABLE'.  *Note `ANALYZE TABLE': ANALYZE TABLE.
  19268.  
  19269. You can get `OPTIMIZE TABLE' to work on other table types by starting
  19270. `mysqld' with `--skip-new' or `--safe-mode', but in this case `OPTIMIZE
  19271. TABLE' is just mapped to `ALTER TABLE'.
  19272.  
  19273. `OPTIMIZE TABLE' works the following way:
  19274.    * If the table has deleted or split rows, repair the table.
  19275.  
  19276.    * If the index pages are not sorted, sort them.
  19277.  
  19278.    * If the statistics are not up to date (and the repair couldn't be
  19279.      done by sorting the index), update them.
  19280.  
  19281. Note that the table is locked during the time `OPTIMIZE TABLE' is
  19282. running!
  19283.  
  19284. Strictly before MySQL 4.1.1, `OPTIMIZE' commands are not written to the
  19285. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  19286. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  19287. used.
  19288.  
  19289. `ANALYZE TABLE' Syntax
  19290. ----------------------
  19291.  
  19292.      ANALYZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name...]
  19293.  
  19294. Analyse and store the key distribution for the table.  During the
  19295. analysis, the table is locked with a read lock.  This works on `MyISAM'
  19296. and `BDB' tables.
  19297.  
  19298. This is equivalent to running `myisamchk -a' on the table.
  19299.  
  19300. MySQL uses the stored key distribution to decide in which order tables
  19301. should be joined when one does a join on something else than a constant.
  19302.  
  19303. The command returns a table with the following columns:
  19304.  
  19305. *Column*    *Value*
  19306. Table       Table name
  19307. Op          Always `analyze'
  19308. Msg_type    One of `status', `error',
  19309.             `info', or `warning'
  19310. Msg_text    The message
  19311.  
  19312. You can check the stored key distribution with the `SHOW INDEX' command.
  19313. *Note SHOW DATABASE INFO::.
  19314.  
  19315. If the table hasn't changed since the last `ANALYZE TABLE' command, the
  19316. table will not be analysed again.
  19317.  
  19318. Strictly before MySQL 4.1.1, `ANALYZE' commands are not written to the
  19319. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  19320. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  19321. used.
  19322.  
  19323. `FLUSH' Syntax
  19324. --------------
  19325.  
  19326.      FLUSH [LOCAL | NO_WRITE_TO_BINLOG] flush_option [,flush_option] ...
  19327.  
  19328. You should use the `FLUSH' command if you want to clear some of the
  19329. internal caches MySQL uses.  To execute `FLUSH', you must have the
  19330. `RELOAD' privilege.
  19331.  
  19332. `flush_option' can be any of the following:
  19333.  
  19334. *Option*           *Description*
  19335. `HOSTS'            Empties the host cache tables.  You should flush the
  19336.                    host tables if some of your hosts change IP number or
  19337.                    if you get the error message `Host ... is blocked'.
  19338.                    When more than `max_connect_errors' errors occur in a
  19339.                    row for a given host while connection to the MySQL
  19340.                    server, MySQL assumes something is wrong and blocks
  19341.                    the host from further connection requests.  Flushing
  19342.                    the host tables allows the host to attempt to connect
  19343.                    again. *Note Blocked host::. You can start `mysqld'
  19344.                    with `-O max_connect_errors=999999999' to avoid this
  19345.                    error message.
  19346. `DES_KEY_FILE'     Reloads the DES keys from the file that was specified
  19347.                    with the `--des-key-file' option at server startup
  19348.                    time.
  19349. `LOGS'             Closes and reopens all log files.  If you have
  19350.                    specified an update log file or a binary log file
  19351.                    without an extension, the extension number of the log
  19352.                    file will be incremented by one relative to the
  19353.                    previous file. If you have used an extension in the
  19354.                    file name, MySQL will close and reopen the update log
  19355.                    file.  *Note Update log::. This is the same thing as
  19356.                    sending the `SIGHUP' signal to the `mysqld' server.
  19357. `PRIVILEGES'       Reloads the privileges from the grant tables in the
  19358.                    `mysql' database.
  19359. `QUERY CACHE'      Defragment the query cache to better utilise its
  19360.                    memory.  This command will not remove any queries
  19361.                    from the cache, unlike `RESET QUERY CACHE'.
  19362. `TABLES'           Closes all open tables and force all tables in use to
  19363.                    be closed. This also flushes the query cache.
  19364. `[TABLE | TABLES]  Flushes only the given tables.
  19365. tbl_name           
  19366. [,tbl_name...]'    
  19367. `TABLES WITH READ  Closes all open tables and locks all tables for all
  19368. LOCK'              databases with a read lock until you execute `UNLOCK
  19369.                    TABLES'. This is very convenient way to get backups
  19370.                    if you have a filesystem, like Veritas, that can take
  19371.                    snapshots in time.
  19372. `STATUS'           Resets most status variables to zero. This is
  19373.                    something one should only use when debugging a query.
  19374. `USER_RESOURCES'   Resets all user resources to zero. This will enable
  19375.                    blocked users to login again. *Note User resources::.
  19376.  
  19377. Strictly before MySQL 4.1.1, `FLUSH' commands are not written to the
  19378. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  19379. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  19380. used, or unless the command contained one of these arguments: `LOGS',
  19381. `MASTER', `SLAVE', `TABLES WITH READ LOCK', because any of these
  19382. arguments may cause problems if replicated to a slave.
  19383.  
  19384. You can also access some of the commands shown above with the
  19385. `mysqladmin' utility, using the `flush-hosts', `flush-logs',
  19386. `flush-privileges', `flush-status' or `flush-tables' commands.
  19387.  
  19388. Take also a look at the `RESET' command used with replication.  *Note
  19389. `RESET': RESET.
  19390.  
  19391. `RESET' Syntax
  19392. --------------
  19393.  
  19394.      RESET reset_option [,reset_option] ...
  19395.  
  19396. The `RESET' command is used to clear things. It also acts as an stronger
  19397. version of the `FLUSH' command.  *Note `FLUSH': FLUSH.
  19398.  
  19399. To execute `RESET', you must have the `RELOAD' privilege.
  19400.  
  19401. *Option*           *Description*
  19402. `MASTER'           Deletes all binary logs listed in the index file,
  19403.                    resetting the binlog index file to be empty.
  19404.                    Previously named `FLUSH MASTER'. *Note Replication
  19405.                    SQL::.
  19406. `SLAVE'            Makes the slave forget its replication position in
  19407.                    the master logs.  Previously named `FLUSH SLAVE'.
  19408.                    *Note Replication SQL::.
  19409. `QUERY CACHE'      Removes all query results from the query cache.
  19410.  
  19411. `PURGE MASTER LOGS' Syntax
  19412. --------------------------
  19413.  
  19414.      PURGE MASTER|BINARY LOGS TO binlog_name
  19415.      PURGE MASTER|BINARY LOGS BEFORE date
  19416.  
  19417. `MASTER' and `BINARY' are here synonyms.  This command is used to
  19418. delete all binary logs strictly prior to the specified binlog or date,
  19419. see *Note Replication SQL::.
  19420.  
  19421. `KILL' Syntax
  19422. -------------
  19423.  
  19424.      KILL thread_id
  19425.  
  19426. Each connection to `mysqld' runs in a separate thread.  You can see
  19427. which threads are running with the `SHOW PROCESSLIST' command and kill
  19428. a thread with the `KILL thread_id' command.
  19429.  
  19430. If you have the `PROCESS' privilege, you can see all threads.  If you
  19431. have the `SUPER' privilege, you can kill all threads.  Otherwise, you
  19432. can only see and kill your own threads.
  19433.  
  19434. You can also use the `mysqladmin processlist' and `mysqladmin kill'
  19435. commands to examine and kill threads.
  19436.  
  19437. _Note_: You currently cannot use `KILL' with the Embedded MySQL Server
  19438. library, because the embedded server merely runs inside the threads of
  19439. the host application, it does not create connection threads of its own.
  19440.  
  19441. When you do a `KILL', a thread-specific `kill flag' is set for the
  19442. thread.
  19443.  
  19444. In most cases it may take some time for the thread to die as the kill
  19445. flag is only checked at specific intervals.
  19446.  
  19447.    * In `SELECT', `ORDER BY' and `GROUP BY' loops, the flag is checked
  19448.      after reading a block of rows. If the kill flag is set, the
  19449.      statement is aborted.
  19450.  
  19451.    * When doing an `ALTER TABLE' the kill flag is checked before each
  19452.      block of rows are read from the original table. If the kill flag
  19453.      was set the command is aborted and the temporary table is deleted.
  19454.  
  19455.    * When doing an `UPDATE' or `DELETE', the kill flag is checked after
  19456.      each block read and after each updated or deleted row. If the kill
  19457.      flag is set, the statement is aborted.  Note that if you are not
  19458.      using transactions, the changes will not be rolled back!
  19459.  
  19460.    * `GET_LOCK()' will abort with `NULL'.
  19461.  
  19462.    * An `INSERT DELAYED' thread will quickly flush all rows it has in
  19463.      memory and die.
  19464.  
  19465.    * If the thread is in the table lock handler (state: `Locked'), the
  19466.      table lock will be quickly aborted.
  19467.  
  19468.    * If the thread is waiting for free disk space in a `write' call, the
  19469.      write is aborted with an disk full error message.
  19470.  
  19471. `SHOW' Syntax
  19472. -------------
  19473.  
  19474.         SHOW DATABASES [LIKE wild]
  19475.      or SHOW [OPEN] TABLES [FROM db_name] [LIKE wild]
  19476.      or SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
  19477.      or SHOW INDEX FROM tbl_name [FROM db_name]
  19478.      or SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  19479.      or SHOW STATUS [LIKE wild]
  19480.      or SHOW VARIABLES [LIKE wild]
  19481.      or SHOW [BDB] LOGS
  19482.      or SHOW [FULL] PROCESSLIST
  19483.      or SHOW GRANTS FOR user
  19484.      or SHOW CREATE TABLE table_name
  19485.      or SHOW MASTER STATUS
  19486.      or SHOW MASTER LOGS
  19487.      or SHOW SLAVE STATUS
  19488.      or SHOW WARNINGS [LIMIT row_count]
  19489.      or SHOW ERRORS [LIMIT row_count]
  19490.      or SHOW TABLE TYPES
  19491.  
  19492. `SHOW' provides information about databases, tables, columns, or status
  19493. information about the server. If the `LIKE wild' part is used, the
  19494. `wild' string can be a string that uses the SQL `%' and `_' wildcard
  19495. characters.
  19496.  
  19497. Retrieving information about Database, Tables, Columns, and Indexes
  19498. ...................................................................
  19499.  
  19500. You can use `db_name.tbl_name' as an alternative to the `tbl_name FROM
  19501. db_name' syntax.  These two statements are equivalent:
  19502.  
  19503.      mysql> SHOW INDEX FROM mytable FROM mydb;
  19504.      mysql> SHOW INDEX FROM mydb.mytable;
  19505.  
  19506. `SHOW DATABASES' lists the databases on the MySQL server host.  You can
  19507. also get this list using the `mysqlshow' command line tool.  In version
  19508. 4.0.2 you will only see those databases for which you have some kind of
  19509. privilege, if you don't have the global `SHOW DATABASES' privilege.
  19510.  
  19511. `SHOW TABLES' lists the tables in a given database.  You can also get
  19512. this list using the `mysqlshow db_name' command.
  19513.  
  19514. *Note*: if a user doesn't have any privileges for a table, the table
  19515. will not show up in the output from `SHOW TABLES' or `mysqlshow
  19516. db_name'.
  19517.  
  19518. `SHOW OPEN TABLES' lists the tables that are currently open in the
  19519. table cache. *Note Table cache::.  The `Comment' field tells how many
  19520. times the table is `cached' and `in_use'.
  19521.  
  19522. `SHOW COLUMNS' lists the columns in a given table.  If you specify the
  19523. `FULL' option, you will also get the privileges you have for each
  19524. column.  If the column types are different from what you expect them to
  19525. be based on a `CREATE TABLE' statement, note that MySQL sometimes
  19526. changes column types.  *Note Silent column changes::.
  19527.  
  19528. The `DESCRIBE' statement provides information similar to `SHOW COLUMNS'.
  19529. *Note `DESCRIBE': DESCRIBE.
  19530.  
  19531. `SHOW FIELDS' is a synonym for `SHOW COLUMNS', and `SHOW KEYS' is a
  19532. synonym for `SHOW INDEX'.  You can also list a table's columns or
  19533. indexes with `mysqlshow db_name tbl_name' or `mysqlshow -k db_name
  19534. tbl_name'.
  19535.  
  19536. `SHOW INDEX' returns the index information in a format that closely
  19537. resembles the `SQLStatistics' call in ODBC. The following columns are
  19538. returned:
  19539.  
  19540. *Column*    *Meaning*
  19541. `Table'     Name of the table.
  19542. `Non_unique'0 if the index can't contain
  19543.             duplicates, 1 if it can.
  19544. `Key_name'  Name of the index.
  19545. `Seq_in_index'Column sequence number in index,
  19546.                                           starting
  19547.             with 1.
  19548. `Column_name'Column name.
  19549. `Collation' How the column is sorted in the index.
  19550.             In MySQL, this can have values
  19551.                                         `A'
  19552.             (Ascending) or `NULL' (Not
  19553.                                     sorted).
  19554. `Cardinality'Number of unique values in the index.
  19555.             This is updated by running
  19556.                                     `isamchk -a'.
  19557. `Sub_part'  Number of indexed characters if the
  19558.             column is only partly indexed.
  19559.                                          `NULL' if
  19560.             the entire key is indexed.
  19561. `Null'      Contains 'YES' if the column may
  19562.             contain `NULL'.
  19563. `Index_type'Index method used.
  19564. `Comment'   Various remarks.  For now, it tells in
  19565.             MySQL < 4.0.2 whether index is
  19566.             `FULLTEXT' or not.
  19567.  
  19568. Note that as the `Cardinality' is counted based on statistics stored as
  19569. integers, it's not necessarily accurate for small tables.
  19570.  
  19571. The `Null' and `Index_type' columns were added in MySQL 4.0.2.
  19572.  
  19573. `SHOW TABLE STATUS'
  19574. ...................
  19575.  
  19576.      SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  19577.  
  19578. `SHOW TABLE STATUS' (new in Version 3.23) works likes `SHOW STATUS',
  19579. but provides a lot of information about each table. You can also get
  19580. this list using the `mysqlshow --status db_name' command.  The
  19581. following columns are returned:
  19582.  
  19583. *Column*       *Meaning*
  19584. `Name'         Name of the table.
  19585. `Type'         Type of table. *Note Table types::.
  19586. `Row_format'   The row storage format (Fixed, Dynamic, or
  19587.                Compressed).
  19588. `Rows'         Number of rows.
  19589. `Avg_row_length'Average row length.
  19590. `Data_length'  Length of the datafile.
  19591. `Max_data_length'Max length of the datafile.  For fixed row
  19592.                formats, this is the max number of rows in the
  19593.                table.  For dynamic row formats, this is the
  19594.                total number of data bytes that can be stored in
  19595.                the table, given the data pointer size used.
  19596. `Index_length' Length of the index file.
  19597. `Data_free'    Number of allocated but not used bytes.
  19598. `Auto_increment'Next autoincrement value.
  19599. `Create_time'  When the table was created.
  19600. `Update_time'  When the datafile was last updated.
  19601. `Check_time'   When the table was last checked.
  19602. `Create_options'Extra options used with `CREATE TABLE'.
  19603. `Comment'      The comment used when creating the table (or some
  19604.                information why MySQL couldn't access the table
  19605.                information).
  19606.  
  19607. `InnoDB' tables will report the free space in the tablespace in the
  19608. table comment.
  19609.  
  19610. `SHOW STATUS'
  19611. .............
  19612.  
  19613. `SHOW STATUS' provides server status information (like `mysqladmin
  19614. extended-status'). The output resembles that shown here, though the
  19615. format and numbers probably differ:
  19616.  
  19617.      +--------------------------+------------+
  19618.      | Variable_name            | Value      |
  19619.      +--------------------------+------------+
  19620.      | Aborted_clients          | 0          |
  19621.      | Aborted_connects         | 0          |
  19622.      | Bytes_received           | 155372598  |
  19623.      | Bytes_sent               | 1176560426 |
  19624.      | Connections              | 30023      |
  19625.      | Created_tmp_disk_tables  | 0          |
  19626.      | Created_tmp_tables       | 8340       |
  19627.      | Created_tmp_files        | 60         |
  19628.      | Delayed_insert_threads   | 0          |
  19629.      | Delayed_writes           | 0          |
  19630.      | Delayed_errors           | 0          |
  19631.      | Flush_commands           | 1          |
  19632.      | Handler_delete           | 462604     |
  19633.      | Handler_read_first       | 105881     |
  19634.      | Handler_read_key         | 27820558   |
  19635.      | Handler_read_next        | 390681754  |
  19636.      | Handler_read_prev        | 6022500    |
  19637.      | Handler_read_rnd         | 30546748   |
  19638.      | Handler_read_rnd_next    | 246216530  |
  19639.      | Handler_update           | 16945404   |
  19640.      | Handler_write            | 60356676   |
  19641.      | Key_blocks_used          | 14955      |
  19642.      | Key_read_requests        | 96854827   |
  19643.      | Key_reads                | 162040     |
  19644.      | Key_write_requests       | 7589728    |
  19645.      | Key_writes               | 3813196    |
  19646.      | Max_used_connections     | 0          |
  19647.      | Not_flushed_key_blocks   | 0          |
  19648.      | Not_flushed_delayed_rows | 0          |
  19649.      | Open_tables              | 1          |
  19650.      | Open_files               | 2          |
  19651.      | Open_streams             | 0          |
  19652.      | Opened_tables            | 44600      |
  19653.      | Questions                | 2026873    |
  19654.      | Select_full_join         | 0          |
  19655.      | Select_full_range_join   | 0          |
  19656.      | Select_range             | 99646      |
  19657.      | Select_range_check       | 0          |
  19658.      | Select_scan              | 30802      |
  19659.      | Slave_running            | OFF        |
  19660.      | Slave_open_temp_tables   | 0          |
  19661.      | Slow_launch_threads      | 0          |
  19662.      | Slow_queries             | 0          |
  19663.      | Sort_merge_passes        | 30         |
  19664.      | Sort_range               | 500        |
  19665.      | Sort_rows                | 30296250   |
  19666.      | Sort_scan                | 4650       |
  19667.      | Table_locks_immediate    | 1920382    |
  19668.      | Table_locks_waited       | 0          |
  19669.      | Threads_cached           | 0          |
  19670.      | Threads_created          | 30022      |
  19671.      | Threads_connected        | 1          |
  19672.      | Threads_running          | 1          |
  19673.      | Uptime                   | 80380      |
  19674.      +--------------------------+------------+
  19675.  
  19676. The status variables listed above have the following meaning:
  19677.  
  19678. *Variable*             *Meaning*
  19679. `Aborted_clients'      Number of connections aborted because the client
  19680.                        died without closing the connection properly.
  19681.                        *Note Communication errors::.
  19682. `Aborted_connects'     Number of tries to connect to the MySQL server
  19683.                        that failed. *Note Communication errors::.
  19684. `Bytes_received'       Number of bytes received from all clients.
  19685. `Bytes_sent'           Number of bytes sent to all clients.
  19686. `Com_xxx'              Number of times each xxx command has been
  19687.                        executed.
  19688. `Connections'          Number of connection attempts to the MySQL server.
  19689. `Created_tmp_disk_tables'Number of implicit temporary tables on disk
  19690.                        created while executing statements.
  19691. `Created_tmp_tables'   Number of implicit temporary tables in memory
  19692.                        created while executing statements.
  19693. `Created_tmp_files'    How many temporary files `mysqld' has created.
  19694. `Delayed_insert_threads'Number of delayed insert handler threads in use.
  19695. `Delayed_writes'       Number of rows written with `INSERT DELAYED'.
  19696. `Delayed_errors'       Number of rows written with `INSERT DELAYED' for
  19697.                        which some error occurred (probably `duplicate
  19698.                        key').
  19699. `Flush_commands'       Number of executed `FLUSH' commands.
  19700. `Handler_commit'       Number of internal `COMMIT' commands.
  19701. `Handler_delete'       Number of times a row was deleted from a table.
  19702. `Handler_read_first'   Number of times the first entry was read from an
  19703.                        index.  If this is high, it suggests that the
  19704.                        server is doing a lot of full index scans, for
  19705.                        example, `SELECT col1 FROM foo', assuming that
  19706.                        col1 is indexed.
  19707. `Handler_read_key'     Number of requests to read a row based on a key.
  19708.                        If this is high, it is a good indication that
  19709.                        your queries and tables are properly indexed.
  19710. `Handler_read_next'    Number of requests to read next row in key order.
  19711.                        This will be incremented if you are querying an
  19712.                        index column with a range constraint. This also
  19713.                        will be incremented if you are doing an index
  19714.                        scan.
  19715. `Handler_read_prev'    Number of requests to read previous row in key
  19716.                        order.  This is mainly used to optimise `ORDER BY
  19717.                        ... DESC'.
  19718. `Handler_read_rnd'     Number of requests to read a row based on a fixed
  19719.                        position.  This will be high if you are doing a
  19720.                        lot of queries that require sorting of the result.
  19721. `Handler_read_rnd_next'Number of requests to read the next row in the
  19722.                        datafile.  This will be high if you are doing a
  19723.                        lot of table scans. Generally this suggests that
  19724.                        your tables are not properly indexed or that your
  19725.                        queries are not written to take advantage of the
  19726.                        indexes you have.
  19727. `Handler_rollback'     Number of internal `ROLLBACK' commands.
  19728. `Handler_update'       Number of requests to update a row in a table.
  19729. `Handler_write'        Number of requests to insert a row in a table.
  19730. `Key_blocks_used'      The number of used blocks in the key cache.
  19731. `Key_read_requests'    The number of requests to read a key block from
  19732.                        the cache.
  19733. `Key_reads'            The number of physical reads of a key block from
  19734.                        disk.
  19735. `Key_write_requests'   The number of requests to write a key block to
  19736.                        the cache.
  19737. `Key_writes'           The number of physical writes of a key block to
  19738.                        disk.
  19739. `Max_used_connections' The maximum number of connections in use
  19740.                        simultaneously.
  19741. `Not_flushed_key_blocks'Keys blocks in the key cache that has changed but
  19742.                        hasn't yet been flushed to disk.
  19743. `Not_flushed_delayed_rows'Number of rows waiting to be written in `INSERT
  19744.                        DELAY' queues.
  19745. `Open_tables'          Number of tables that are open.
  19746. `Open_files'           Number of files that are open.
  19747. `Open_streams'         Number of streams that are open (used mainly for
  19748.                        logging).
  19749. `Opened_tables'        Number of tables that have been opened.
  19750. `Rpl_status'           Status of failsafe replication. (Not yet in use).
  19751. `Select_full_join'     Number of joins without keys (If this is not 0,
  19752.                        you should carefully check the indexes of your
  19753.                        tables).
  19754. `Select_full_range_join'Number of joins where we used a range search on
  19755.                        reference table.
  19756. `Select_range'         Number of joins where we used ranges on the first
  19757.                        table. (It's normally not critical even if this
  19758.                        is big.)
  19759. `Select_scan'          Number of joins where we did a full scan of the
  19760.                        first table.
  19761. `Select_range_check'   Number of joins without keys where we check for
  19762.                        key usage after each row (If this is not 0, you
  19763.                        should carefully check the indexes of your
  19764.                        tables).
  19765. `Questions'            Number of queries sent to the server.
  19766. `Slave_open_temp_tables'Number of temporary tables currently open by the
  19767.                        slave thread
  19768. `Slave_running'        Is `ON' if this is a slave that is connected to a
  19769.                        master.
  19770. `Slow_launch_threads'  Number of threads that have taken more than
  19771.                        `slow_launch_time' to create.
  19772. `Slow_queries'         Number of queries that have taken more than
  19773.                        `long_query_time'. *Note Slow query log::.
  19774. `Sort_merge_passes'    Number of merges passes the sort algoritm have
  19775.                        had to do. If this value is large you should
  19776.                        consider increasing `sort_buffer'.
  19777. `Sort_range'           Number of sorts that were done with ranges.
  19778. `Sort_rows'            Number of sorted rows.
  19779. `Sort_scan'            Number of sorts that were done by scanning the
  19780.                        table.
  19781. `ssl_xxx'              Variables used by SSL; Not yet implemented.
  19782. `Table_locks_immediate'Number of times a table lock was acquired
  19783.                        immediately. Available after 3.23.33.
  19784. `Table_locks_waited'   Number of times a table lock could not be
  19785.                        acquired immediately and a wait was needed. If
  19786.                        this is high, and you have performance problems,
  19787.                        you should first optimise your queries, and then
  19788.                        either split your table(s) or use replication.
  19789.                        Available after 3.23.33.
  19790. `Threads_cached'       Number of threads in the thread cache.
  19791. `Threads_connected'    Number of currently open connections.
  19792. `Threads_created'      Number of threads created to handle connections.
  19793. `Threads_running'      Number of threads that are not sleeping.
  19794. `Uptime'               How many seconds the server has been up.
  19795.  
  19796. Some comments about the above:
  19797.  
  19798.    * If `Opened_tables' is big, then your `table_cache' variable is
  19799.      probably too small.
  19800.  
  19801.    * If `Key_reads' is big, then your `key_buffer_size' variable is
  19802.      probably too small.  The *cache miss rate* can be calculated with
  19803.      `Key_reads'/`Key_read_requests'.
  19804.  
  19805.    * If `Handler_read_rnd' is big, then you probably have a lot of
  19806.      queries that require MySQL to scan whole tables or you have joins
  19807.      that don't use keys properly.
  19808.  
  19809.    * If `Threads_created' is big, you may want to increase the
  19810.      `thread_cache_size' variable.  The cache hit rate can be calculated
  19811.      with `Threads_created'/`Connections'.
  19812.  
  19813.    * If `Created_tmp_disk_tables' is big, you may want to increase the
  19814.      `tmp_table_size' variable to get the temporary tables memory-based
  19815.      instead of disk based.
  19816.  
  19817. `SHOW VARIABLES'
  19818. ................
  19819.  
  19820.      SHOW [GLOBAL | SESSION] VARIABLES [LIKE wild]
  19821.  
  19822. `SHOW VARIABLES' shows the values of some MySQL system variables.  The
  19823. options `GLOBAL' and `SESSION' are new in MySQL 4.0.3.  With `GLOBAL'
  19824. you will get the variables that will be used for new connections to
  19825. MySQL. With `SESSION' you will get the values that are in effect for
  19826. the current connection. If you are not using either option, `SESSION'
  19827. is used.
  19828.  
  19829. If the default values are unsuitable, you can set most of these
  19830. variables using command-line options when `mysqld' starts up.  *Note
  19831. Command-line options::. It is also possible to change most variables
  19832. with the `SET' statement.  *Note `SET': SET OPTION.
  19833.  
  19834. The output from `SHOW VARIABLES' resembles that shown in the following
  19835. list, though the format and numbers may differ somewhat.  You can also
  19836. get this information using the `mysqladmin variables' command.
  19837.  
  19838.      +---------------------------------+------------------------------+
  19839.      | Variable_name                   | Value                        |
  19840.      +---------------------------------+------------------------------|
  19841.      | back_log                        | 50                           |
  19842.      | basedir                         | /usr/local/mysql             |
  19843.      | bdb_cache_size                  | 8388572                      |
  19844.      | bdb_log_buffer_size             | 32768                        |
  19845.      | bdb_home                        | /usr/local/mysql             |
  19846.      | bdb_max_lock                    | 10000                        |
  19847.      | bdb_logdir                      |                              |
  19848.      | bdb_shared_data                 | OFF                          |
  19849.      | bdb_tmpdir                      | /tmp/                        |
  19850.      | bdb_version                     | Sleepycat Software: ...      |
  19851.      | binlog_cache_size               | 32768                        |
  19852.      | bulk_insert_buffer_size         | 8388608                      |
  19853.      | character_set                   | latin1                       |
  19854.      | character_sets                  | latin1 big5 czech euc_kr     |
  19855.      | concurrent_insert               | ON                           |
  19856.      | connect_timeout                 | 5                            |
  19857.      | convert_character_set           |                              |
  19858.      | datadir                         | /usr/local/mysql/data/       |
  19859.      | delay_key_write                 | ON                           |
  19860.      | delayed_insert_limit            | 100                          |
  19861.      | delayed_insert_timeout          | 300                          |
  19862.      | delayed_queue_size              | 1000                         |
  19863.      | flush                           | OFF                          |
  19864.      | flush_time                      | 0                            |
  19865.      | ft_boolean_syntax               | + -><()~*:""&|               |
  19866.      | ft_min_word_len                 | 4                            |
  19867.      | ft_max_word_len                 | 254                          |
  19868.      | ft_max_word_len_for_sort        | 20                           |
  19869.      | ft_stopword_file                | (built-in)                   |
  19870.      | have_bdb                        | YES                          |
  19871.      | have_innodb                     | YES                          |
  19872.      | have_isam                       | YES                          |
  19873.      | have_raid                       | NO                           |
  19874.      | have_symlink                    | DISABLED                     |
  19875.      | have_openssl                    | YES                          |
  19876.      | have_query_cache                | YES                          |
  19877.      | init_file                       |                              |
  19878.      | innodb_additional_mem_pool_size | 1048576                      |
  19879.      | innodb_buffer_pool_size         | 8388608                      |
  19880.      | innodb_data_file_path           | ibdata1:10M:autoextend       |
  19881.      | innodb_data_home_dir            |                              |
  19882.      | innodb_file_io_threads          | 4                            |
  19883.      | innodb_force_recovery           | 0                            |
  19884.      | innodb_thread_concurrency       | 8                            |
  19885.      | innodb_flush_log_at_trx_commit  | 1                            |
  19886.      | innodb_fast_shutdown            | ON                           |
  19887.      | innodb_flush_method             |                              |
  19888.      | innodb_lock_wait_timeout        | 50                           |
  19889.      | innodb_log_arch_dir             |                              |
  19890.      | innodb_log_archive              | OFF                          |
  19891.      | innodb_log_buffer_size          | 1048576                      |
  19892.      | innodb_log_file_size            | 5242880                      |
  19893.      | innodb_log_files_in_group       | 2                            |
  19894.      | innodb_log_group_home_dir       | ./                           |
  19895.      | innodb_mirrored_log_groups      | 1                            |
  19896.      | interactive_timeout             | 28800                        |
  19897.      | join_buffer_size                | 131072                       |
  19898.      | key_buffer_size                 | 16773120                     |
  19899.      | language                        | /usr/local/mysql/share/...   |
  19900.      | large_files_support             | ON                           |
  19901.      | local_infile                    | ON                           |
  19902.      | locked_in_memory                | OFF                          |
  19903.      | log                             | OFF                          |
  19904.      | log_update                      | OFF                          |
  19905.      | log_bin                         | OFF                          |
  19906.      | log_slave_updates               | OFF                          |
  19907.      | log_slow_queries                | OFF                          |
  19908.      | log_warnings                    | OFF                          |
  19909.      | long_query_time                 | 10                           |
  19910.      | low_priority_updates            | OFF                          |
  19911.      | lower_case_table_names          | OFF                          |
  19912.      | max_allowed_packet              | 1047552                      |
  19913.      | max_binlog_cache_size           | 4294967295                   |
  19914.      | max_binlog_size                 | 1073741824                   |
  19915.      | max_connections                 | 100                          |
  19916.      | max_connect_errors              | 10                           |
  19917.      | max_delayed_threads             | 20                           |
  19918.      | max_heap_table_size             | 16777216                     |
  19919.      | max_join_size                   | 4294967295                   |
  19920.      | max_relay_log_size              | 0                            |
  19921.      | max_sort_length                 | 1024                         |
  19922.      | max_user_connections            | 0                            |
  19923.      | max_tmp_tables                  | 32                           |
  19924.      | max_write_lock_count            | 4294967295                   |
  19925.      | myisam_max_extra_sort_file_size | 268435456                    |
  19926.      | myisam_repair_threads           | 1                            |
  19927.      | myisam_max_sort_file_size       | 2147483647                   |
  19928.      | myisam_recover_options          | force                        |
  19929.      | myisam_sort_buffer_size         | 8388608                      |
  19930.      | net_buffer_length               | 16384                        |
  19931.      | net_read_timeout                | 30                           |
  19932.      | net_retry_count                 | 10                           |
  19933.      | net_write_timeout               | 60                           |
  19934.      | open_files_limit                | 0                            |
  19935.      | pid_file                        | /usr/local/mysql/name.pid    |
  19936.      | port                            | 3306                         |
  19937.      | protocol_version                | 10                           |
  19938.      | read_buffer_size                | 131072                       |
  19939.      | read_rnd_buffer_size            | 262144                       |
  19940.      | rpl_recovery_rank               | 0                            |
  19941.      | query_cache_limit               | 1048576                      |
  19942.      | query_cache_size                | 0                            |
  19943.      | query_cache_type                | ON                           |
  19944.      | safe_show_database              | OFF                          |
  19945.      | server_id                       | 0                            |
  19946.      | slave_net_timeout               | 3600                         |
  19947.      | skip_external_locking           | ON                           |
  19948.      | skip_networking                 | OFF                          |
  19949.      | skip_show_database              | OFF                          |
  19950.      | slow_launch_time                | 2                            |
  19951.      | socket                          | /tmp/mysql.sock              |
  19952.      | sort_buffer_size                | 2097116                      |
  19953.      | sql_mode                        |                              |
  19954.      | table_cache                     | 64                           |
  19955.      | table_type                      | MYISAM                       |
  19956.      | thread_cache_size               | 3                            |
  19957.      | thread_stack                    | 131072                       |
  19958.      | tx_isolation                    | READ-COMMITTED               |
  19959.      | timezone                        | EEST                         |
  19960.      | tmp_table_size                  | 33554432                     |
  19961.      | tmpdir                          | /tmp/:/mnt/hd2/tmp/          |
  19962.      | version                         | 4.0.4-beta                   |
  19963.      | wait_timeout                    | 28800                        |
  19964.      +---------------------------------+------------------------------+
  19965.  
  19966. Each option is described here. Values for buffer sizes, lengths, and
  19967. stack sizes are given in bytes.  You can specify values with a suffix
  19968. of `K' or `M' to indicate kilobytes or megabytes. For example, `16M'
  19969. indicates 16 megabytes.  The case of suffix letters does not matter;
  19970. `16M' and `16m' are equivalent:
  19971.  
  19972.    * `ansi_mode'.  Is `ON' if `mysqld' was started with `--ansi'.
  19973.      *Note ANSI mode::.
  19974.  
  19975.    * `back_log' The number of outstanding connection requests MySQL can
  19976.      have. This comes into play when the main MySQL thread gets *very*
  19977.      many connection requests in a very short time. It then takes some
  19978.      time (although very little) for the main thread to check the
  19979.      connection and start a new thread. The `back_log' value indicates
  19980.      how many requests can be stacked during this short time before
  19981.      MySQL momentarily stops answering new requests. You need to
  19982.      increase this only if you expect a large number of connections in
  19983.      a short period of time.
  19984.  
  19985.      In other words, this value is the size of the listen queue for
  19986.      incoming TCP/IP connections.  Your operating system has its own
  19987.      limit on the size of this queue.  The manual page for the Unix
  19988.      `listen(2)' system call should have more details.  Check your OS
  19989.      documentation for the maximum value for this variable.  Attempting
  19990.      to set `back_log' higher than your operating system limit will be
  19991.      ineffective.
  19992.  
  19993.    * `basedir' The value of the `--basedir' option.
  19994.  
  19995.    * `bdb_cache_size' The buffer that is allocated to cache index and
  19996.      rows for `BDB' tables.  If you don't use `BDB' tables, you should
  19997.      start `mysqld' with `--skip-bdb' to not waste memory for this
  19998.      cache.
  19999.  
  20000.    * `bdb_log_buffer_size' The buffer that is allocated to cache index
  20001.      and rows for `BDB' tables.  If you don't use `BDB' tables, you
  20002.      should set this to 0 or start `mysqld' with `--skip-bdb' to not
  20003.      waste memory for this cache.
  20004.  
  20005.    * `bdb_home' The value of the `--bdb-home' option.
  20006.  
  20007.    * `bdb_max_lock' The maximum number of locks (10,000 by default) you
  20008.      can have active on a BDB table. You should increase this if you
  20009.      get errors of type `bdb: Lock table is out of available locks' or
  20010.      `Got error 12 from ...' when you have do long transactions or when
  20011.      `mysqld' has to examine a lot of rows to calculate the query.
  20012.  
  20013.    * `bdb_logdir' The value of the `--bdb-logdir' option.
  20014.  
  20015.    * `bdb_shared_data' Is `ON' if you are using `--bdb-shared-data'.
  20016.  
  20017.    * `bdb_tmpdir' The value of the `--bdb-tmpdir' option.
  20018.  
  20019.    * `binlog_cache_size'.  The size of the cache to hold the SQL
  20020.      statements for the binary log during a transaction.  If you often
  20021.      use big, multi-statement transactions you can increase this to get
  20022.      more performance. *Note COMMIT::.
  20023.  
  20024.    * `bulk_insert_buffer_size' (was `myisam_bulk_insert_tree_size')
  20025.      MyISAM uses special tree-like cache to make bulk inserts (that is,
  20026.      `INSERT ... SELECT', `INSERT ... VALUES (...), (...), ...', and
  20027.      `LOAD DATA INFILE') faster. This variable limits the size of the
  20028.      cache tree in bytes per thread. Setting it to 0 will disable this
  20029.      optimisation.  *Note*: this cache is only used when adding data to
  20030.      non-empty table.  Default value is 8 MB.
  20031.  
  20032.    * `character_set' The default character set.
  20033.  
  20034.    * `character_sets' The supported character sets.
  20035.  
  20036.    * `concurrent_inserts' If `ON' (the default), MySQL will allow you
  20037.      to use `INSERT' on `MyISAM' tables at the same time as you run
  20038.      `SELECT' queries on them.  You can turn this option off by
  20039.      starting `mysqld' with `--safe' or `--skip-new'.
  20040.  
  20041.    * `connect_timeout' The number of seconds the `mysqld' server is
  20042.      waiting for a connect packet before responding with `Bad
  20043.      handshake'.
  20044.  
  20045.    * `datadir' The value of the `--datadir' option.
  20046.  
  20047.    * `delay_key_write' Option for MyISAM tables. Can have one of the
  20048.      following values:
  20049.  
  20050.      OFF                  All CREATE TABLE ... DELAYED_KEY_WRITES are
  20051.                           ignored.
  20052.      ON                   (default)  MySQL will honor the
  20053.                           `DELAY_KEY_WRITE' option for `CREATE TABLE'.
  20054.      ALL                  All new opened tables are treated as if they
  20055.                           were created with the `DELAY_KEY_WRITE' option.
  20056.  
  20057.      If `DELAY_KEY_WRITE' is enabled this means that the key buffer for
  20058.      tables with this option will not get flushed on every index
  20059.      update, but only when a table is closed.  This will speed up
  20060.      writes on keys a lot, but you should add automatic checking of all
  20061.      tables with `myisamchk --fast --force' if you use this.
  20062.  
  20063.    * `delayed_insert_limit' After inserting `delayed_insert_limit'
  20064.      rows, the `INSERT DELAYED' handler will check if there are any
  20065.      `SELECT' statements pending. If so, it allows these to execute
  20066.      before continuing.
  20067.  
  20068.    * `delayed_insert_timeout' How long a `INSERT DELAYED' thread should
  20069.      wait for `INSERT' statements before terminating.
  20070.  
  20071.    * `delayed_queue_size' What size queue (in rows) should be allocated
  20072.      for handling `INSERT DELAYED'.  If the queue becomes full, any
  20073.      client that does `INSERT DELAYED' will wait until there is room in
  20074.      the queue again.
  20075.  
  20076.    * `flush' This is `ON' if you have started MySQL with the `--flush'
  20077.      option.
  20078.  
  20079.    * `flush_time' If this is set to a non-zero value, then every
  20080.      `flush_time' seconds all tables will be closed (to free up
  20081.      resources and sync things to disk). We only recommend this option
  20082.      on Windows 9x/Me, or on systems where you have very little
  20083.      resources.
  20084.  
  20085.    * `ft_boolean_syntax' List of operators supported by `MATCH ...
  20086.      AGAINST(... IN BOOLEAN MODE)'.  *Note Fulltext Search::.
  20087.  
  20088.    * `ft_min_word_len' The minimum length of the word to be included in
  20089.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  20090.      after changing this variable.* (This option is new for MySQL 4.0.)
  20091.  
  20092.    * `ft_max_word_len' The maximum length of the word to be included in
  20093.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  20094.      after changing this variable.* (This option is new for MySQL 4.0.)
  20095.  
  20096.    * `ft_max_word_len_for_sort' The maximum length of the word in a
  20097.      `FULLTEXT' index to be used in fast index recreation method in
  20098.      `REPAIR', `CREATE INDEX',  or `ALTER TABLE'.  Longer words are
  20099.      inserted the slow way.  The rule of the thumb is as follows: with
  20100.      `ft_max_word_len_for_sort' increasing, *MySQL* will create bigger
  20101.      temporary files (thus slowing the process down, due to disk I/O),
  20102.      and will put fewer keys in one sort block (again, decreasing the
  20103.      efficiency).  When `ft_max_word_len_for_sort' is too small,
  20104.      instead, *MySQL* will insert a lot of words into index the slow
  20105.      way, but short words will be inserted very quickly.
  20106.  
  20107.    * `ft_stopword_file' The file to read the list of stopwords for
  20108.      fulltext search from.  All the words from the file will be used,
  20109.      comments are *not* honored.  By default, built-in list of
  20110.      stopwords is used (as defined in `myisam/ft_static.c').  Setting
  20111.      this parameter to an empty string (`""') will disable stopword
  20112.      filtering.  *Note: `FULLTEXT' indexes must be rebuilt after
  20113.      changing this variable.* (This option is new for MySQL 4.0.10)
  20114.  
  20115.    * `have_innodb' `YES' if `mysqld' supports InnoDB tables. `DISABLED'
  20116.      if `--skip-innodb' is used.
  20117.  
  20118.    * `have_bdb' `YES' if `mysqld' supports Berkeley DB tables.
  20119.      `DISABLED' if `--skip-bdb' is used.
  20120.  
  20121.    * `have_raid' `YES' if `mysqld' supports the `RAID' option.
  20122.  
  20123.    * `have_openssl' `YES' if `mysqld' supports SSL (encryption) on the
  20124.      client/server protocol.
  20125.  
  20126.    * `init_file' The name of the file specified with the `--init-file'
  20127.      option when you start the server.  This is a file of SQL
  20128.      statements you want the server to execute when it starts.
  20129.  
  20130.    * `interactive_timeout' The number of seconds the server waits for
  20131.      activity on an interactive connection before closing it.  An
  20132.      interactive client is defined as a client that uses the
  20133.      `CLIENT_INTERACTIVE' option to `mysql_real_connect()'.  See also
  20134.      `wait_timeout'.
  20135.  
  20136.    * `join_buffer_size' The size of the buffer that is used for full
  20137.      joins (joins that do not use indexes).  The buffer is allocated
  20138.      one time for each full join between two tables. Increase this
  20139.      value to get a faster full join when adding indexes is not
  20140.      possible. (Normally the best way to get fast joins is to add
  20141.      indexes.)
  20142.  
  20143.    * `key_buffer_size' Index blocks are buffered and are shared by all
  20144.      threads.  `key_buffer_size' is the size of the buffer used for
  20145.      index blocks.
  20146.  
  20147.      Increase this to get better index handling (for all reads and
  20148.      multiple writes) to as much as you can afford; 64M on a 256M
  20149.      machine that mainly runs MySQL is quite common.  If you, however,
  20150.      make this too big (for instance more than 50% of your total
  20151.      memory) your system may start to page and become extremely slow.
  20152.      Remember that because MySQL does not cache data reads, you will
  20153.      have to leave some room for the OS filesystem cache.
  20154.  
  20155.      You can check the performance of the key buffer by doing `SHOW
  20156.      STATUS' and examine the variables `Key_read_requests',
  20157.      `Key_reads', `Key_write_requests', and `Key_writes'.  The
  20158.      `Key_reads/Key_read_request' ratio should normally be < 0.01.  The
  20159.      `Key_write/Key_write_requests' is usually near 1 if you are using
  20160.      mostly updates/deletes but may be much smaller if you tend to do
  20161.      updates that affect many at the same time or if you are using
  20162.      `DELAY_KEY_WRITE'. *Note `SHOW': SHOW.
  20163.  
  20164.      To get even more speed when writing many rows at the same time, use
  20165.      `LOCK TABLES'.  *Note `LOCK TABLES': LOCK TABLES.
  20166.  
  20167.    * `language' The language used for error messages.
  20168.  
  20169.    * `large_file_support' If `mysqld' was compiled with options for big
  20170.      file support.
  20171.  
  20172.    * `locked_in_memory' If `mysqld' was locked in memory with
  20173.      `--memlock'
  20174.  
  20175.    * `log' If logging of all queries is enabled.
  20176.  
  20177.    * `log_update' If the update log is enabled.
  20178.  
  20179.    * `log_bin' If the binary log is enabled.
  20180.  
  20181.    * `log_slave_updates' If the updates from the slave should be logged.
  20182.  
  20183.    * `long_query_time' If a query takes longer than this (in seconds),
  20184.      the `Slow_queries' counter will be incremented. If you are using
  20185.      `--log-slow-queries', the query will be logged to the slow query
  20186.      logfile. This value is measured in real time, not CPU time, so a
  20187.      query that may be under the threshold on a lightly loaded system
  20188.      may be above the threshold on a heavily loaded one.  *Note Slow
  20189.      query log::.
  20190.  
  20191.    * `lower_case_table_names' If set to 1 table names are stored in
  20192.      lowercase on disk and table name comparisons will be
  20193.      case-insensitive.  From version 4.0.2, this option also applies to
  20194.      database names.  From 4.1.1 this option also applies to table
  20195.      alias.  *Note Name case sensitivity::.
  20196.  
  20197.    * `max_allowed_packet' The maximum size of one packet. The message
  20198.      buffer is initialised to `net_buffer_length' bytes, but can grow
  20199.      up to `max_allowed_packet' bytes when needed.  This value by
  20200.      default is small, to catch big (possibly wrong) packets.  You must
  20201.      increase this value if you are using big `BLOB' columns. It should
  20202.      be as big as the biggest `BLOB' you want to use.  The protocol
  20203.      limits for `max_allowed_packet' is 16M in MySQL 3.23 and 1G in
  20204.      MySQL 4.0.
  20205.  
  20206.    * `max_binlog_cache_size' If a multi-statement transaction requires
  20207.      more than this amount of memory, one will get the error
  20208.      "Multi-statement transaction required more than
  20209.      'max_binlog_cache_size' bytes of storage".
  20210.  
  20211.    * `max_binlog_size' Available after 3.23.33. If a write to the
  20212.      binary (replication) log exceeds the given value, rotate the logs.
  20213.      You cannot set it to less than 4096 bytes (1024 in MySQL versions
  20214.      older than 4.0.14), or more than 1 GB. Default is 1 GB. Note if
  20215.      you are using transactions: a transaction is written in one chunk
  20216.      to the binary log, hence it is never split between several binary
  20217.      logs. Therefore, if you have big transactions, you may see binlogs
  20218.      bigger than `max_binlog_size'. If `max_relay_log_size' (available
  20219.      starting from MySQL 4.0.14) is 0, then `max_binlog_size' will
  20220.      apply to relay logs as well.
  20221.  
  20222.    * `max_connections' The number of simultaneous clients allowed.
  20223.      Increasing this value increases the number of file descriptors
  20224.      that `mysqld' requires.  See below for comments on file descriptor
  20225.      limits. *Note Too many connections::.
  20226.  
  20227.    * `max_connect_errors' If there is more than this number of
  20228.      interrupted connections from a host this host will be blocked from
  20229.      further connections.  You can unblock a host with the command
  20230.      `FLUSH HOSTS'.
  20231.  
  20232.    * `max_delayed_threads' Don't start more than this number of threads
  20233.      to handle `INSERT DELAYED' statements.  If you try to insert data
  20234.      into a new table after all `INSERT DELAYED' threads are in use,
  20235.      the row will be inserted as if the `DELAYED' attribute wasn't
  20236.      specified. If you set this to 0, MySQL will never create a
  20237.      max_delayed thread.
  20238.  
  20239.    * `max_heap_table_size' Don't allow creation of heap tables bigger
  20240.      than this.
  20241.  
  20242.    * `max_join_size' Joins that are probably going to read more than
  20243.      `max_join_size' records return an error. Set this value if your
  20244.      users tend to perform joins that lack a `WHERE' clause, that take
  20245.      a long time, and that return millions of rows.
  20246.  
  20247.    * `max_relay_log_size' Available starting from 4.0.14. If a write to
  20248.      the relay log (a kind of log used by replication slaves, *note
  20249.      Replication Implementation Details::) exceeds the given value,
  20250.      rotate the relay log.  This variable enables you to put different
  20251.      size constraints on relay logs and binary logs.  However, setting
  20252.      the variable to 0 will make MySQL use `max_binlog_size' for both
  20253.      binary logs and relay logs.  You have to set `max_relay_log_size'
  20254.      to 0 or more than 4096, and less than 1 GB. Default is 0.
  20255.  
  20256.    * `max_seeks_for_key' Limit assumed max number of seeks when looking
  20257.      up rows based on a key.  The MySQL optimiser will assume that when
  20258.      searching after matching rows in a table through scanning a key,
  20259.      we will not cause more than this number of key seeks independent
  20260.      of the cardinality of the key.  By setting this to a low value
  20261.      (100 ?) you can force MySQL to prefer keys instead of table scans.
  20262.  
  20263.    * `max_sort_length' The number of bytes to use when sorting `BLOB'
  20264.      or `TEXT' values (only the first `max_sort_length' bytes of each
  20265.      value are used; the rest are ignored).
  20266.  
  20267.    * `max_user_connections' The maximum number of active connections
  20268.      for a single user (0 = no limit).
  20269.  
  20270.    * `max_tmp_tables' (This option doesn't yet do anything.)  Maximum
  20271.      number of temporary tables a client can keep open at the same time.
  20272.  
  20273.    * `max_write_lock_count' After this many write locks, allow some
  20274.      read locks to run in between.
  20275.  
  20276.    * `myisam_recover_options' The value of the `--myisam-recover'
  20277.      option.
  20278.  
  20279.    * `myisam_sort_buffer_size' The buffer that is allocated when
  20280.      sorting the index when doing a `REPAIR' or when creating indexes
  20281.      with `CREATE INDEX' or `ALTER TABLE'.
  20282.  
  20283.    * `myisam_max_extra_sort_file_size'.  If the temporary file used for
  20284.      fast index creation would be bigger than using the key cache by
  20285.      the amount specified here, then prefer the key cache method.  This
  20286.      is mainly used to force long character keys in large tables to use
  20287.      the slower key cache method to create the index.  *Note* that this
  20288.      parameter is given in megabytes before 4.0.3 and in bytes
  20289.      beginning with this version.
  20290.  
  20291.    * `myisam_repair_threads'.  If this value is greater than one,
  20292.      MyISAM table indexes during `Repair by sorting' process will be
  20293.      created in parallel - each index in its own thread. *Note:*
  20294.      multi-threaded repair is still *alpha* quality code.
  20295.  
  20296.    * `myisam_max_sort_file_size' The maximum size of the temporary file
  20297.      MySQL is allowed to use while recreating the index (during
  20298.      `REPAIR', `ALTER TABLE' or `LOAD DATA INFILE'.  If the file-size
  20299.      would be bigger than this, the index will be created through the
  20300.      key cache (which is slower).  *Note* that this parameter is given
  20301.      in megabytes before 4.0.3 and in bytes beginning with this version.
  20302.  
  20303.    * `net_buffer_length' The communication buffer is reset to this size
  20304.      between queries. This should not normally be changed, but if you
  20305.      have very little memory, you can set it to the expected size of a
  20306.      query.  (That is, the expected length of SQL statements sent by
  20307.      clients.  If statements exceed this length, the buffer is
  20308.      automatically enlarged, up to `max_allowed_packet' bytes.)
  20309.  
  20310.    * `net_read_timeout' Number of seconds to wait for more data from a
  20311.      connection before aborting the read.  Note that when we don't
  20312.      expect data from a connection, the timeout is defined by
  20313.      `write_timeout'. See also `slave_net_timeout'.
  20314.  
  20315.    * `net_retry_count' If a read on a communication port is
  20316.      interrupted, retry this many times before giving up.  This value
  20317.      should be quite high on `FreeBSD' as internal interrupts are sent
  20318.      to all threads.
  20319.  
  20320.    * `net_write_timeout' Number of seconds to wait for a block to be
  20321.      written to a connection before aborting the write.
  20322.  
  20323.    * `open_files_limit' If this is not 0, then `mysqld' will use this
  20324.      value to reserve file descriptors to use with `setrlimit()'.  If
  20325.      this value is 0 then `mysqld' will reserve `max_connections*5' or
  20326.      `max_connections + table_cache*2' (whichever is larger) number of
  20327.      files.  You should try increasing this if `mysqld' gives you the
  20328.      error 'Too many open files'.
  20329.  
  20330.    * `pid_file' The value of the `--pid-file' option.
  20331.  
  20332.    * `port' The value of the `--port' option.
  20333.  
  20334.    * `protocol_version' The protocol version used by the MySQL server.
  20335.  
  20336.    * `read_buffer_size' (was `record_buffer') Each thread that does a
  20337.      sequential scan allocates a buffer of this size for each table it
  20338.      scans. If you do many sequential scans, you may want to increase
  20339.      this value.
  20340.  
  20341.    * `record_rnd_buffer_size' When reading rows in sorted order after a
  20342.      sort, the rows are read through this buffer to avoid a disk seeks.
  20343.      Can improve `ORDER BY' by a lot if set to a high value.  As this
  20344.      is a thread-specific variable, one should not set this big
  20345.      globally, but just change this when running some specific big
  20346.      queries.
  20347.  
  20348.    * `query_cache_limit' Don't cache results that are bigger than this.
  20349.      (Default 1M).
  20350.  
  20351.    * `query_cache_size' The memory allocated to store results from old
  20352.      queries.  If this is 0, the query cache is disabled (default).
  20353.  
  20354.    * `query_cache_type' This may be set (only numeric) to
  20355.      *Value**Alias*   *Comment*
  20356.      0      OFF       Don't cache or retrieve results.
  20357.      1      ON        Cache all results except `SELECT SQL_NO_CACHE
  20358.                       ...' queries.
  20359.      2      DEMAND    Cache only `SELECT SQL_CACHE ...' queries.
  20360.  
  20361.    * `safe_show_database' Don't show databases for which the user
  20362.      doesn't have any database or table privileges. This can improve
  20363.      security if you're concerned about people being able to see what
  20364.      databases other users have. See also `skip_show_database'.
  20365.  
  20366.    * `server_id' The value of the `--server-id' option.
  20367.  
  20368.    * `skip_locking' Is OFF if `mysqld' uses external locking.
  20369.  
  20370.    * `skip_networking' Is ON if we only allow local (socket)
  20371.      connections.
  20372.  
  20373.    * `skip_show_database' This prevents people from doing `SHOW
  20374.      DATABASES' if they don't have the `PROCESS' privilege. This can
  20375.      improve security if you're concerned about people being able to
  20376.      see what databases other users have. See also `safe_show_database'.
  20377.  
  20378.    * `slave_net_timeout' Number of seconds to wait for more data from a
  20379.      master/slave connection before aborting the read.
  20380.  
  20381.    * `slow_launch_time' If creating the thread takes longer than this
  20382.      value (in seconds), the `Slow_launch_threads' counter will be
  20383.      incremented.
  20384.  
  20385.    * `socket' The Unix socket used by the server.
  20386.  
  20387.    * `sort_buffer_size' Each thread that needs to do a sort allocates a
  20388.      buffer of this size. Increase this value for faster `ORDER BY' or
  20389.      `GROUP BY' operations.  *Note Temporary files::.
  20390.  
  20391.    * `table_cache' The number of open tables for all threads.
  20392.      Increasing this value increases the number of file descriptors
  20393.      that `mysqld' requires.  You can check if you need to increase the
  20394.      table cache by checking the `Opened_tables' variable.  *Note
  20395.      `Opened_tables': SHOW STATUS.  If this variable is big and you
  20396.      don't do `FLUSH TABLES' a lot (which just forces all tables to be
  20397.      closed and reopenend), then you should increase the value of this
  20398.      variable.
  20399.  
  20400.      For more information about the table cache, see *Note Table
  20401.      cache::.
  20402.  
  20403.    * `table_type' The default table type.
  20404.  
  20405.    * `thread_cache_size' How many threads we should keep in a cache for
  20406.      reuse.  When a client disconnects, the client's threads are put in
  20407.      the cache if there aren't more than `thread_cache_size' threads
  20408.      from before.  All new threads are first taken from the cache, and
  20409.      only when the cache is empty is a new thread created.  This
  20410.      variable can be increased to improve performance if you have a lot
  20411.      of new connections. (Normally this doesn't give a notable
  20412.      performance improvement if you have a good thread implementation.)
  20413.      By examing the difference between the `Connections' and
  20414.      `Threads_created' status variables (*note `SHOW STATUS': SHOW
  20415.      STATUS. for details) you can see how efficient thread cache is.
  20416.  
  20417.    * `thread_concurrency' On Solaris, `mysqld' will call
  20418.      `thr_setconcurrency()' with this value.  `thr_setconcurrency()'
  20419.      permits the application to give the threads system a hint for the
  20420.      desired number of threads that should be run at the same time.
  20421.  
  20422.    * `thread_stack' The stack size for each thread.  Many of the limits
  20423.      detected by the `crash-me' test are dependent on this value. The
  20424.      default is large enough for normal operation.  *Note MySQL
  20425.      Benchmarks::.
  20426.  
  20427.    * `timezone' The timezone for the server.
  20428.  
  20429.    * `tmp_table_size' If an in-memory temporary table exceeds this
  20430.      size, MySQL will automatically convert it to an on-disk `MyISAM'
  20431.      table.  Increase the value of `tmp_table_size' if you do many
  20432.      advanced `GROUP BY' queries and you have lots of memory.
  20433.  
  20434.    * `tmpdir' The directory used for temporary files and temporary
  20435.      tables.  Starting from MySQL 4.1, it can be set to a list of paths
  20436.      separated by colon `:' (semicolon `;' on Windows). They will be
  20437.      used in round-robin fashion. This feature can be used to spread
  20438.      load between several physical disks.
  20439.  
  20440.    * `version' The version number for the server.
  20441.  
  20442.    * `wait_timeout' The number of seconds the server waits for activity
  20443.      on a not interactive connection before closing it.
  20444.  
  20445.      On thread startup `SESSION.WAIT_TIMEOUT' is initialised from
  20446.      `GLOBAL.WAIT_TIMEOUT' or `GLOBAL.INTERACTIVE_TIMEOUT' depending on
  20447.      the type of client (as defined by the `CLIENT_INTERACTIVE' connect
  20448.      option). See also `interactive_timeout'.
  20449.  
  20450. The manual section that describes tuning MySQL contains some
  20451. information of how to tune the above variables. *Note Server
  20452. parameters::.
  20453.  
  20454. `SHOW [BDB] LOGS'
  20455. .................
  20456.  
  20457. `SHOW LOGS' shows you status information about existing log files.  It
  20458. currently only displays information about Berkeley DB log files, so an
  20459. alias for it is `SHOW BDB LOGS'.
  20460.  
  20461.    * `File' shows the full path to the log file
  20462.  
  20463.    * `Type' shows the type of the log file (`BDB' for Berkeley DB log
  20464.      files)
  20465.  
  20466.    * `Status' shows the status of the log file (`FREE' if the file can
  20467.      be removed, or `IN USE' if the file is needed by the transaction
  20468.      subsystem)
  20469.  
  20470. `SHOW PROCESSLIST'
  20471. ..................
  20472.  
  20473. `SHOW [FULL] PROCESSLIST' shows you which threads are running.  You can
  20474. also get this information using the `mysqladmin processlist' command.
  20475. If you have the `SUPER' privilege, you can see all threads.  Otherwise,
  20476. you can see only your own threads.  *Note `KILL': KILL.  If you don't
  20477. use the `FULL' option, then only the first 100 characters of each query
  20478. will be shown.
  20479.  
  20480. Starting from 4.0.12, MySQL reports the hostname for TCP/IP connections
  20481. as `hostname:client_port' to make it easier to find out which client is
  20482. doing what.
  20483.  
  20484. This command is very useful if you get the 'too many connections' error
  20485. message and want to find out what's going on. MySQL reserves one extra
  20486. connection for a client with the `SUPER' privilege to ensure that you
  20487. should always be able to login and check the system (assuming you are
  20488. not giving this privilege to all your users).
  20489.  
  20490. Some states commonly seen in `mysqladmin processlist'
  20491.  
  20492.    * `Checking table' The thread is performing [automatic] checking of
  20493.      the table.
  20494.  
  20495.    * `Closing tables' Means that the thread is flushing the changed
  20496.      table data to disk and closing the used tables. This should be a
  20497.      fast operation.  If not, then you should check that you don't have
  20498.      a full disk or that the disk is not in very heavy use.
  20499.  
  20500.    * `Connect Out' Slave connecting to master.
  20501.  
  20502.    * `Copying to tmp table on disk' The temporary result set was larger
  20503.      than `tmp_table_size' and the thread is now changing the in
  20504.      memory-based temporary table to a disk based one to save memory.
  20505.  
  20506.    * `Creating tmp table' The thread is creating a temporary table to
  20507.      hold a part of the result for the query.
  20508.  
  20509.    * `deleting from main table' When executing the first part of a
  20510.      multi-table delete and we are only deleting from the first table.
  20511.  
  20512.    * `deleting from reference tables' When executing the second part of
  20513.      a multi-table delete and we are deleting the matched rows from the
  20514.      other tables.
  20515.  
  20516.    * `Flushing tables' The thread is executing `FLUSH TABLES' and is
  20517.      waiting for all threads to close their tables.
  20518.  
  20519.    * `Killed' Someone has sent a kill to the thread and it should abort
  20520.      next time it checks the kill flag.  The flag is checked in each
  20521.      major loop in MySQL, but in some cases it may still take a short
  20522.      time for the thread to die.  If the thread is locked by some other
  20523.      thread, the kill will take affect as soon as the other thread
  20524.      releases it's lock.
  20525.  
  20526.    * `Sending data' The thread is processing rows for a `SELECT'
  20527.      statement and is also sending data to the client.
  20528.  
  20529.    * `Sorting for group' The thread is doing a sort to satsify a `GROUP
  20530.      BY'.
  20531.  
  20532.    * `Sorting for order' The thread is doing a sort to satsify a `ORDER
  20533.      BY'.
  20534.  
  20535.    * `Opening tables' This simply means that the thread is trying to
  20536.      open a table. This is should be very fast procedure, unless
  20537.      something prevents opening. For example an `ALTER TABLE' or a
  20538.      `LOCK TABLE' can prevent opening a table until the command is
  20539.      finished.
  20540.  
  20541.    * `Removing duplicates' The query was using `SELECT DISTINCT' in
  20542.      such a way that MySQL couldn't optimise that distinct away at an
  20543.      early stage. Because of this MySQL has to do an extra stage to
  20544.      remove all duplicated rows before sending the result to the client.
  20545.  
  20546.    * `Reopen table' The thread got a lock for the table, but noticed
  20547.      after getting the lock that the underlying table structure
  20548.      changed. It has freed the lock, closed the table and is now trying
  20549.      to reopen it.
  20550.  
  20551.    * `Repair by sorting' The repair code is using sorting to create
  20552.      indexes.
  20553.  
  20554.    * `Repair with keycache' The repair code is using creating keys one
  20555.      by one through the key cache.  This is much slower than `Repair by
  20556.      sorting'.
  20557.  
  20558.    * `Searching rows for update' The thread is doing a first phase to
  20559.      find all matching rows before updating them.  This has to be done
  20560.      if the `UPDATE' is changing the index that is used to find the
  20561.      involved rows.
  20562.  
  20563.    * `Sleeping' The thread is wating for the client to send a new
  20564.      command to it.
  20565.  
  20566.    * `System lock' The thread is waiting for getting to get a external
  20567.      system lock for the table. If you are not using multiple mysqld
  20568.      servers that are accessing the same tables, you can disable system
  20569.      locks with the `--skip-external-locking' option.
  20570.  
  20571.    * `Upgrading lock' The `INSERT DELAYED' handler is trying to get a
  20572.      lock for the table to insert rows.
  20573.  
  20574.    * `Updating' The thread is searching for rows to update and updating
  20575.      them.
  20576.  
  20577.    * `User Lock' The thread is waiting on a `GET_LOCK()'.
  20578.  
  20579.    * `Waiting for tables' The thread got a notification that the
  20580.      underlying structure for a table has changed and it needs to
  20581.      reopen the table to get the new structure.  To be able to reopen
  20582.      the table it must however wait until all other threads have closed
  20583.      the table in question.
  20584.  
  20585.      This notification happens if another thread has used `FLUSH TABLES'
  20586.      or one of the following commands on the table in question: `FLUSH
  20587.      TABLES table_name', `ALTER TABLE', `RENAME TABLE', `REPAIR TABLE',
  20588.      `ANALYZE TABLE' or `OPTIMIZE TABLE'.
  20589.  
  20590.    * `waiting for handler insert' The `INSERT DELAYED' handler has
  20591.      processed all inserts and are waiting to get new ones.
  20592.  
  20593. Most states are very quick operations. If threads last in any of these
  20594. states for many seconds, there may be a problem around that needs to be
  20595. investigated.
  20596.  
  20597. There are some other states that are not mentioned previously, but most
  20598. of these are only useful to find bugs in `mysqld'.
  20599.  
  20600. `SHOW GRANTS'
  20601. .............
  20602.  
  20603. `SHOW GRANTS FOR user' lists the grant commands that must be issued to
  20604. duplicate the grants for a user.
  20605.  
  20606.      mysql> SHOW GRANTS FOR root@localhost;
  20607.      +---------------------------------------------------------------------+
  20608.      | Grants for root@localhost                                           |
  20609.      +---------------------------------------------------------------------+
  20610.      | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  20611.      +---------------------------------------------------------------------+
  20612.  
  20613. To list grants for the current session one may use `CURRENT_USER()'
  20614. function (new in version 4.0.6) to find out what user the session was
  20615. authenticated as.  *Note `CURRENT_USER()': Miscellaneous functions.
  20616.  
  20617. `SHOW CREATE TABLE'
  20618. ...................
  20619.  
  20620. Shows a `CREATE TABLE' statement that will create the given table:
  20621.  
  20622.      mysql> SHOW CREATE TABLE t\G
  20623.      *************************** 1. row ***************************
  20624.             Table: t
  20625.      Create Table: CREATE TABLE t (
  20626.        id INT(11) default NULL auto_increment,
  20627.        s char(60) default NULL,
  20628.        PRIMARY KEY (id)
  20629.      ) TYPE=MyISAM
  20630.  
  20631. `SHOW CREATE TABLE' will quote table and column names according to
  20632. `SQL_QUOTE_SHOW_CREATE' option.  *Note `SET SQL_QUOTE_SHOW_CREATE': SET
  20633. OPTION.
  20634.  
  20635. `SHOW WARNINGS | ERRORS'
  20636. ........................
  20637.  
  20638.      SHOW WARNINGS [LIMIT row_count]
  20639.      SHOW ERRORS [LIMIT row_count]
  20640.  
  20641. This command is implemented in MySQL 4.1.0.
  20642.  
  20643. It shows the errors, warnings and notes that one got for the last
  20644. command.  The errors/warnings are reset for each new command that uses
  20645. a table.
  20646.  
  20647. The MySQL server sends back the total number of warnings and errors you
  20648. got for the last commend; This can be retrieved by calling
  20649. `mysql_warning_count()'.
  20650.  
  20651. Up to `max_error_count' messages are stored (Global and thread specific
  20652. variable).
  20653.  
  20654. You can retrieve the number of errors from `@error_count' and warnings
  20655. from `@warning_count'.
  20656.  
  20657. `SHOW WARNINGS' shows all errors, warnings and notes you got for the
  20658. last command while `SHOW ERRORS' only shows you the errors.
  20659.  
  20660.      mysql> DROP TABLE IF EXISTS no_such_table;
  20661.      mysql> SHOW WARNINGS;
  20662.      
  20663.      +-------+------+-------------------------------+
  20664.      | Level | Code | Message                       |
  20665.      +-------+------+-------------------------------+
  20666.      | Note  | 1051 | Unknown table 'no_such_table' |
  20667.      +-------+------+-------------------------------+
  20668.  
  20669. Note that in MySQL 4.1.0 we have just added the frame work for warnings
  20670. and not many MySQL command do yet generate warnings.  4.1.1 supports all
  20671. kind of warnings for `LOAD DATA INFILE' and DML statements such as
  20672. `INSERT', `UPDATE' and `ALTER' commands.
  20673.  
  20674. For example, here is a simple case which produces conversion warnings
  20675. for a insert statement.
  20676.  
  20677.      mysql> create table t1(a tinyint NOT NULL, b char(4));
  20678.      Query OK, 0 rows affected (0.00 sec)
  20679.      
  20680.      mysql> insert into t1 values(10,'mysql'),(NULL,'test'),(300,'open source');
  20681.      Query OK, 3 rows affected, 4 warnings (0.15 sec)
  20682.      Records: 3  Duplicates: 0  Warnings: 4
  20683.      
  20684.      mysql> show warnings;
  20685.      +---------+------+---------------------------------------------------------------+
  20686.      | Level   | Code | Message                                                       |
  20687.      +---------+------+---------------------------------------------------------------+
  20688.      | Warning | 1263 | Data truncated for column 'b' at row 1                        |
  20689.      | Warning | 1261 | Data truncated, NULL supplied to NOT NULL column 'a' at row 2 |
  20690.      | Warning | 1262 | Data truncated, out of range for column 'a' at row 3          |
  20691.      | Warning | 1263 | Data truncated for column 'b' at row 3                        |
  20692.      +---------+------+---------------------------------------------------------------+
  20693.      4 rows in set (0.00 sec)
  20694.  
  20695. Maximum number of warnings can be specified using the server variable
  20696. `'max_error_count'', `SET max_error_count=[count]'; By default it is
  20697. 64. In case to disable warnings, simply reset this variable to '0'. In
  20698. case if `max_error_count' is 0, then still the warning count represents
  20699. how many warnings have occurred, but none of the messages are stored.
  20700.  
  20701. For example, consider the following `ALTER' table statement for the
  20702. above example, which returns only one warning message even though total
  20703. warnings occurred is 3 when you set max_error_count=1.
  20704.  
  20705.      mysql> show variables like 'max_error_count';
  20706.      +-----------------+-------+
  20707.      | Variable_name   | Value |
  20708.      +-----------------+-------+
  20709.      | max_error_count | 64    |
  20710.      +-----------------+-------+
  20711.      1 row in set (0.00 sec)
  20712.      
  20713.      mysql> set max_error_count=1;
  20714.      Query OK, 0 rows affected (0.00 sec)
  20715.      
  20716.      mysql> alter table t1 modify b char;
  20717.      Query OK, 3 rows affected, 3 warnings (0.00 sec)
  20718.      Records: 3  Duplicates: 0  Warnings: 3
  20719.      
  20720.      mysql> show warnings;
  20721.      +---------+------+----------------------------------------+
  20722.      | Level   | Code | Message                                |
  20723.      +---------+------+----------------------------------------+
  20724.      | Warning | 1263 | Data truncated for column 'b' at row 1 |
  20725.      +---------+------+----------------------------------------+
  20726.      1 row in set (0.00 sec)
  20727.      
  20728.      mysql>
  20729.  
  20730. `SHOW TABLE TYPES'
  20731. ..................
  20732.  
  20733.      SHOW TABLE TYPES
  20734.  
  20735. This command is implemented in MySQL 4.1.0.
  20736.  
  20737. `SHOW TABLE TYPES' shows you status information about the table types.
  20738. This is particulary useful for checking if a table type is supported;
  20739. or to see what is the default table type is.
  20740.  
  20741.      mysql> SHOW TABLE TYPES;
  20742.      
  20743.      +--------+---------+-----------------------------------------------------------+
  20744.      | Type   | Support | Comment                                                   |
  20745.      +--------+---------+-----------------------------------------------------------+
  20746.      | MyISAM | DEFAULT | Default type from 3.23 with great performance             |
  20747.      | HEAP   | YES     | Hash based, stored in memory, useful for temporary tables |
  20748.      | MERGE  | YES     | Collection of identical MyISAM tables                     |
  20749.      | ISAM   | YES     | Obsolete table type; Is replaced by MyISAM                |
  20750.      | InnoDB | YES     | Supports transactions, row-level locking and foreign keys |
  20751.      | BDB    | NO      | Supports transactions and page-level locking              |
  20752.      +--------+---------+-----------------------------------------------------------+
  20753.      6 rows in set (0.00 sec)
  20754.  
  20755. The 'Support' option `DEFAULT' indicates whether the perticular table
  20756. type is supported, and which is the default type. If the server is
  20757. started with `--default-table-type=InnoDB', then the InnoDB 'Support'
  20758. field will have the value `DEFAULT'.
  20759.  
  20760. `SHOW PRIVILEGES'
  20761. .................
  20762.  
  20763.      SHOW PRIVILEGES
  20764.  
  20765. This command is implemented in MySQL 4.1.0.
  20766.  
  20767. `SHOW PRIVILEGES' shows the list of system privileges that the
  20768. underlying MySQL server supports.
  20769.  
  20770.      mysql> show privileges;
  20771.      +------------+--------------------------+-------------------------------------------------------+
  20772.      | Privilege  | Context                  | Comment                                               |
  20773.      +------------+--------------------------+-------------------------------------------------------+
  20774.      | Select     | Tables                   | To retrieve rows from table                           |
  20775.      | Insert     | Tables                   | To insert data into tables                            |
  20776.      | Update     | Tables                   | To update existing rows                               |
  20777.      | Delete     | Tables                   | To delete existing rows                               |
  20778.      | Index      | Tables                   | To create or drop indexes                             |
  20779.      | Alter      | Tables                   | To alter the table                                    |
  20780.      | Create     | Databases,Tables,Indexes | To create new databases and tables                    |
  20781.      | Drop       | Databases,Tables         | To drop databases and tables                          |
  20782.      | Grant      | Databases,Tables         | To give to other users those privileges you possess   |
  20783.      | References | Databases,Tables         | To have references on tables                          |
  20784.      | Reload     | Server Admin             | To reload or refresh tables, logs and privileges      |
  20785.      | Shutdown   | Server Admin             | To shutdown the server                                |
  20786.      | Process    | Server Admin             | To view the plain text of currently executing queries |
  20787.      | File       | File access on server    | To read and write files on the server                 |
  20788.      +------------+--------------------------+-------------------------------------------------------+
  20789.      14 rows in set (0.00 sec)
  20790.  
  20791. MySQL Localisation and International Usage
  20792. ==========================================
  20793.  
  20794. The Character Set Used for Data and Sorting
  20795. -------------------------------------------
  20796.  
  20797. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  20798. sorting according to Swedish/Finnish. This is the character set suitable
  20799. in the USA and western Europe.
  20800.  
  20801. All standard MySQL binaries are compiled with
  20802. `--with-extra-charsets=complex'.  This will add code to all standard
  20803. programs to be able to handle `latin1' and all multi-byte character
  20804. sets within the binary. Other character sets will be loaded from a
  20805. character-set definition file when needed.
  20806.  
  20807. The character set determines what characters are allowed in names and
  20808. how things are sorted by the `ORDER BY' and `GROUP BY' clauses of the
  20809. `SELECT' statement.
  20810.  
  20811. You can change the character set with the `--default-character-set'
  20812. option when you start the server.  The character sets available depend
  20813. on the `--with-charset=charset' and `--with-extra-charsets=
  20814. list-of-charset | complex | all' options to `configure', and the
  20815. character set configuration files listed in `SHAREDIR/charsets/Index'.
  20816. *Note configure options::.
  20817.  
  20818. If you change the character set when running MySQL (which may also
  20819. change the sort order), you must run `myisamchk -r -q
  20820. --set-character-set=charset' on all tables. Otherwise, your indexes may
  20821. not be ordered correctly.
  20822.  
  20823. When a client connects to a MySQL server, the server sends the default
  20824. character set in use to the client.  The client will switch to use this
  20825. character set for this connection.
  20826.  
  20827. One should use `mysql_real_escape_string()' when escaping strings for
  20828. an SQL query.  `mysql_real_escape_string()' is identical to the old
  20829. `mysql_escape_string()' function, except that it takes the `MYSQL'
  20830. connection handle as the first parameter.
  20831.  
  20832. If the client is compiled with different paths than where the server is
  20833. installed and the user who configured MySQL didn't include all
  20834. character sets in the MySQL binary, one must specify for the client
  20835. where it can find the additional character sets it will need if the
  20836. server runs with a different character set than the client.
  20837.  
  20838. One can specify this by putting in a MySQL option file:
  20839.  
  20840.      [client]
  20841.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  20842.  
  20843. where the path points to the directory in which the dynamic MySQL
  20844. character sets are stored.
  20845.  
  20846. One can force the client to use specific character set by specifying:
  20847.  
  20848.      [client]
  20849.      default-character-set=character-set-name
  20850.  
  20851. but normally this is never needed.
  20852.  
  20853. German character set
  20854. ....................
  20855.  
  20856. To get German sorting order, you should start `mysqld' with
  20857. `--default-character-set=latin1_de'.  This will give you the following
  20858. characteristics.
  20859.  
  20860. When sorting and comparing strings, the following mapping is done on the
  20861. strings before doing the comparison:
  20862.  
  20863.      a"  ->  ae
  20864.      o"  ->  oe
  20865.      u"  ->  ue
  20866.      ss  ->  ss
  20867.  
  20868. All accented characters, are converted to their un-accented uppercase
  20869. counterpart.  All letters are converted to uppercase.
  20870.  
  20871. When comparing strings with `LIKE' the one -> two character mapping is
  20872. not done. All letters are converted to uppercase. Accent are removed
  20873. from all letters except: `U"', `u"', `O"', `o"', `A"' and `a"'.
  20874.  
  20875. Non-English Error Messages
  20876. --------------------------
  20877.  
  20878. `mysqld' can issue error messages in the following languages: Czech,
  20879. Danish, Dutch, English (the default), Estonian, French, German, Greek,
  20880. Hungarian, Italian, Japanese, Korean, Norwegian, Norwegian-ny, Polish,
  20881. Portuguese, Romanian, Russian, Slovak, Spanish, and Swedish.
  20882.  
  20883. To start `mysqld' with a particular language, use either the
  20884. `--language=lang' or `-L lang' options. For example:
  20885.  
  20886.      shell> mysqld --language=swedish
  20887.  
  20888. or:
  20889.  
  20890.      shell> mysqld --language=/usr/local/share/swedish
  20891.  
  20892. Note that all language names are specified in lowercase.
  20893.  
  20894. The language files are located (by default) in
  20895. `MYSQL_BASE_DIR/share/LANGUAGE/'.
  20896.  
  20897. To update the error message file, you should edit the `errmsg.txt' file
  20898. and execute the following command to generate the `errmsg.sys' file:
  20899.  
  20900.      shell> comp_err errmsg.txt errmsg.sys
  20901.  
  20902. If you upgrade to a newer version of MySQL, remember to repeat your
  20903. changes with the new `errmsg.txt' file.
  20904.  
  20905. Adding a New Character Set
  20906. --------------------------
  20907.  
  20908. To add another character set to MySQL, use the following procedure.
  20909.  
  20910. Decide if the set is simple or complex.  If the character set does not
  20911. need to use special string collating routines for sorting and does not
  20912. need multi-byte character support, it is simple.  If it needs either of
  20913. those features, it is complex.
  20914.  
  20915. For example, `latin1' and `danish' are simple charactersets while
  20916. `big5' or `czech' are complex character sets.
  20917.  
  20918. In the following section, we have assumed that you name your character
  20919. set `MYSET'.
  20920.  
  20921. For a simple character set do the following:
  20922.  
  20923.   1. Add MYSET to the end of the `sql/share/charsets/Index' file Assign
  20924.      a unique number to it.
  20925.  
  20926.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use
  20927.      `sql/share/charsets/latin1.conf' as a base for this.)
  20928.  
  20929.      The syntax for the file very simple:
  20930.  
  20931.         * Comments start with a '#' character and proceed to the end of
  20932.           the line.
  20933.  
  20934.         * Words are separated by arbitrary amounts of whitespace.
  20935.  
  20936.         * When defining the character set, every word must be a number
  20937.           in hexadecimal format
  20938.  
  20939.         * The `ctype' array takes up the first 257 words. The
  20940.           `to_lower[]', `to_upper[]' and `sort_order[]' arrays take up
  20941.           256 words each after that.
  20942.  
  20943.      *Note Character arrays::.
  20944.  
  20945.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  20946.      `COMPILED_CHARSETS' lists in `configure.in'.
  20947.  
  20948.   4. Reconfigure, recompile, and test.
  20949.  
  20950.  
  20951. For a complex character set do the following:
  20952.  
  20953.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  20954.      distribution.
  20955.  
  20956.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  20957.      Assign a unique number to it.
  20958.  
  20959.   3. Look at one of the existing `ctype-*.c' files to see what needs to
  20960.      be defined, for example `strings/ctype-big5.c'. Note that the
  20961.      arrays in your file must have names like `ctype_MYSET',
  20962.      `to_lower_MYSET', and so on.  This corresponds to the arrays in
  20963.      the simple character set. *Note Character arrays::.
  20964.  
  20965.   4. Near the top of the file, place a special comment like this:
  20966.  
  20967.           /*
  20968.            * This comment is parsed by configure to create ctype.c,
  20969.            * so don't change it unless you know what you are doing.
  20970.            *
  20971.            * .configure. number_MYSET=MYNUMBER
  20972.            * .configure. strxfrm_multiply_MYSET=N
  20973.            * .configure. mbmaxlen_MYSET=N
  20974.            */
  20975.  
  20976.      The `configure' program uses this comment to include the character
  20977.      set into the MySQL library automatically.
  20978.  
  20979.      The strxfrm_multiply and mbmaxlen lines will be explained in the
  20980.      following sections.  Only include these if you need the string
  20981.      collating functions or the multi-byte character set functions,
  20982.      respectively.
  20983.  
  20984.   5. You should then create some of the following functions:
  20985.  
  20986.         * `my_strncoll_MYSET()'
  20987.  
  20988.         * `my_strcoll_MYSET()'
  20989.  
  20990.         * `my_strxfrm_MYSET()'
  20991.  
  20992.         * `my_like_range_MYSET()'
  20993.  
  20994.      *Note String collating::.
  20995.  
  20996.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  20997.      `COMPILED_CHARSETS' lists in `configure.in'.
  20998.  
  20999.   7. Reconfigure, recompile, and test.
  21000.  
  21001. The file `sql/share/charsets/README' includes some more instructions.
  21002.  
  21003. If you want to have the character set included in the MySQL
  21004. distribution, mail a patch to <internals@lists.mysql.com>.
  21005.  
  21006. The Character Definition Arrays
  21007. -------------------------------
  21008.  
  21009. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  21010. and uppercase characters corresponding to each member of the character
  21011. set.  For example:
  21012.  
  21013.      to_lower['A'] should contain 'a'
  21014.      to_upper['a'] should contain 'A'
  21015.  
  21016. `sort_order[]' is a map indicating how characters should be ordered for
  21017. comparison and sorting purposes. Quite often (but not for all character
  21018. sets) this is the same as `to_upper[]' (which means sorting will be
  21019. case-insensitive). MySQL will sort characters based on the value of
  21020. `sort_order[character]'.  For more complicated sorting rules, see the
  21021. discussion of string collating below. *Note String collating::.
  21022.  
  21023. `ctype[]' is an array of bit values, with one element for one character.
  21024. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  21025. by character value, but `ctype[]' is indexed by character value + 1.
  21026. This is an old legacy to be able to handle `EOF'.)
  21027.  
  21028. You can find the following bitmask definitions in `m_ctype.h':
  21029.  
  21030.      #define _U      01      /* Uppercase */
  21031.      #define _L      02      /* Lowercase */
  21032.      #define _N      04      /* Numeral (digit) */
  21033.      #define _S      010     /* Spacing character */
  21034.      #define _P      020     /* Punctuation */
  21035.      #define _C      040     /* Control character */
  21036.      #define _B      0100    /* Blank */
  21037.      #define _X      0200    /* heXadecimal digit */
  21038.  
  21039. The `ctype[]' entry for each character should be the union of the
  21040. applicable bitmask values that describe the character.  For example,
  21041. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  21042. (`_X'), so `ctype['A'+1]' should contain the value:
  21043.  
  21044.      _U + _X = 01 + 0200 = 0201
  21045.  
  21046. String Collating Support
  21047. ------------------------
  21048.  
  21049. If the sorting rules for your language are too complex to be handled
  21050. with the simple `sort_order[]' table, you need to use the string
  21051. collating functions.
  21052.  
  21053. Right now the best documentation on this is the character sets that are
  21054. already implemented.  Look at the `big5', `czech', `gbk', `sjis', and
  21055. `tis160' character sets for examples.
  21056.  
  21057. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  21058. comment at the top of the file.  `N' should be set to the maximum ratio
  21059. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  21060. integer).
  21061.  
  21062. Multi-byte Character Support
  21063. ----------------------------
  21064.  
  21065. If your want to add support for a new character set that includes
  21066. multi-byte characters, you need to use the multi-byte character
  21067. functions.
  21068.  
  21069. Right now the best documentation on this is the character sets that are
  21070. already implemented.  Look at the `euc_kr', `gb2312', `gbk', `sjis',
  21071. and `ujis' character sets for examples. These are implemented in the
  21072. `ctype-'charset'.c' files in the `strings' directory.
  21073.  
  21074. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  21075. the top of the source file.  `N' should be set to the size in bytes of
  21076. the largest character in the set.
  21077.  
  21078. Problems With Character Sets
  21079. ----------------------------
  21080.  
  21081. If you try to use a character set that is not compiled into your binary,
  21082. you can run into a couple of different problems:
  21083.  
  21084.    * Your program has a wrong path to where the character sets are
  21085.      stored.  (Default `/usr/local/mysql/share/mysql/charsets').  This
  21086.      can be fixed by using the `--character-sets-dir' option to the
  21087.      program in question.
  21088.  
  21089.    * The character set is a multi-byte character set that can't be
  21090.      loaded dynamically.  In this case you have to recompile the
  21091.      program with the support for the character set.
  21092.  
  21093.    * The character set is a dynamic character set, but you don't have a
  21094.      configure file for it.  In this case you should install the
  21095.      configure file for the character set from a new MySQL distribution.
  21096.  
  21097.    * Your `Index' file doesn't contain the name for the character set.
  21098.  
  21099.           ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf' not found
  21100.           (Errcode: 2)
  21101.  
  21102.      In this case you should either get a new `Index' file or add by
  21103.      hand the name of any missing character sets.
  21104.  
  21105. For `MyISAM' tables, you can check the character set name and number
  21106. for a table with `myisamchk -dvv table_name'.
  21107.  
  21108. MySQL Server-Side Scripts and Utilities
  21109. =======================================
  21110.  
  21111. Overview of the Server-Side Scripts and Utilities
  21112. -------------------------------------------------
  21113.  
  21114. All MySQL programs take many different options. However, every MySQL
  21115. program provides a `--help' option that you can use to get a full
  21116. description of the program's different options. For example, try `mysql
  21117. --help'.
  21118.  
  21119. You can override default options for all standard programs with an
  21120. option file. *Note Option files::.
  21121.  
  21122. The following list briefly describes the server-side MySQL programs:
  21123.  
  21124. `myisamchk'
  21125.      Utility to describe, check, optimise, and repair MySQL tables.
  21126.      Because `myisamchk' has many functions, it is described in its own
  21127.      chapter. *Note MySQL Database Administration::.
  21128.  
  21129. `make_binary_distribution'
  21130.      Makes a binary release of a compiled MySQL. This could be sent by
  21131.      FTP to `/pub/mysql/Incoming' on `support.mysql.com' for the
  21132.      convenience of other MySQL users.
  21133.  
  21134. `mysqlbug'
  21135.      The MySQL bug report script.  This script should always be used
  21136.      when filing a bug report to the MySQL list.
  21137.  
  21138. `mysqld'
  21139.      The SQL daemon. This should always be running.
  21140.  
  21141. `mysql_install_db'
  21142.      Creates the MySQL grant tables with default privileges. This is
  21143.      usually executed only once, when first installing MySQL on a
  21144.      system.
  21145.  
  21146. `mysqld_safe', The Wrapper Around `mysqld'
  21147. ------------------------------------------
  21148.  
  21149. `mysqld_safe' is the recommended way to start a `mysqld' daemon on
  21150. Unix.  `mysqld_safe' adds some safety features such as restarting the
  21151. server when an error occurs and logging run-time information to a log
  21152. file.
  21153.  
  21154. *Note:* Before MySQL 4.0, `mysqld_safe' is named `safe_mysqld'.  To
  21155. preserve backward compatibility, MySQL binary distributions for some
  21156. time will include `safe_mysqld' as a symbolic link to `mysqld_safe'.
  21157.  
  21158. If you don't use `--mysqld=#' or `--mysqld-version=#' `mysqld_safe'
  21159. will use an executable named `mysqld-max' if it exists. If not,
  21160. `mysqld_safe' will start `mysqld'.  This makes it very easy to test to
  21161. use `mysqld-max' instead of `mysqld'; just copy `mysqld-max' to where
  21162. you have `mysqld' and it will be used.
  21163.  
  21164. Normally one should never edit the `mysqld_safe' script, but instead
  21165. put the options to `mysqld_safe' in the `[mysqld_safe]' section in the
  21166. `my.cnf' file. `mysqld_safe' reads all options from the `[mysqld]',
  21167. `[server]' and `[mysqld_safe]' sections from the option files.  (For
  21168. backward compatibility, it also reads the `[safe_mysqld]' sections.)
  21169. *Note Option files::.
  21170.  
  21171. Note that all options on the command-line to `mysqld_safe' are passed
  21172. to `mysqld'.  If you wants to use any options in `mysqld_safe' that
  21173. `mysqld' doesn't support, you must specify these in the option file.
  21174.  
  21175. Most of the options to `mysqld_safe' are the same as the options to
  21176. `mysqld'. *Note Command-line options::.
  21177.  
  21178. `mysqld_safe' supports the following options:
  21179.  
  21180. `--basedir=path'
  21181.  
  21182. `--core-file-size=#'
  21183.      Size of the core file `mysqld' should be able to create. Passed to
  21184.      `ulimit -c'.
  21185.  
  21186. `--datadir=path'
  21187.  
  21188. `--defaults-extra-file=path'
  21189.  
  21190. `--defaults-file=path'
  21191.  
  21192. `--err-log=path (this is marked obsolete in 4.0; Use --log-error instead)'
  21193.  
  21194. `--log-error=path'
  21195.      Write the error log to the above file. *Note Error log::.
  21196.  
  21197. `--ledir=path'
  21198.      Path to `mysqld'
  21199.  
  21200. `--log=path'
  21201.  
  21202. `--mysqld=mysqld-version'
  21203.      Name of the `mysqld' version in the `ledir' directory you want to
  21204.      start.
  21205.  
  21206. `--mysqld-version=version'
  21207.      Similar to `--mysqld=' but here you only give the suffix for
  21208.      `mysqld'.  For example if you use `--mysqld-version=max',
  21209.      `mysqld_safe' will start the `ledir/mysqld-max' version.  If the
  21210.      argument to `--mysqld-version' is empty, `ledir/mysqld' will be
  21211.      used.
  21212.  
  21213. `--nice=# (added in MySQL 4.0.14)'
  21214.  
  21215. `--no-defaults'
  21216.  
  21217. `--open-files-limit=#'
  21218.      Number of files `mysqld' should be able to open. Passed to `ulimit
  21219.      -n'. Note that you need to start `mysqld_safe' as `root' for this
  21220.      to work properly!
  21221.  
  21222. `--pid-file=path'
  21223.  
  21224. `--port=#'
  21225.  
  21226. `--socket=path'
  21227.  
  21228. `--timezone=#'
  21229.      Set the timezone (the `TZ') variable to the value of this
  21230.      parameter.
  21231.  
  21232. `--user=#'
  21233. The `mysqld_safe' script is written so that it normally is able to start
  21234. a server that was installed from either a source or a binary version of
  21235. MySQL, even if these install the server in slightly different
  21236. locations.  `mysqld_safe' expects one of these conditions to be true:
  21237.  
  21238.    * The server and databases can be found relative to the directory
  21239.      from which `mysqld_safe' is invoked.  `mysqld_safe' looks under
  21240.      its working directory for `bin' and `data' directories (for binary
  21241.      distributions) or for `libexec' and `var' directories (for source
  21242.      distributions).  This condition should be met if you execute
  21243.      `mysqld_safe' from your MySQL installation directory (for example,
  21244.      `/usr/local/mysql' for a binary distribution).
  21245.  
  21246.    * If the server and databases cannot be found relative to the
  21247.      working directory, `mysqld_safe' attempts to locate them by
  21248.      absolute pathnames.  Typical locations are `/usr/local/libexec'
  21249.      and `/usr/local/var'.  The actual locations are determined when
  21250.      the distribution was built from which `mysqld_safe' comes.  They
  21251.      should be correct if MySQL was installed in a standard location.
  21252.  
  21253. Because `mysqld_safe' will try to find the server and databases relative
  21254. to its own working directory, you can install a binary distribution of
  21255. MySQL anywhere, as long as you start `mysqld_safe' from the MySQL
  21256. installation directory:
  21257.  
  21258.      shell> cd mysql_installation_directory
  21259.      shell> bin/mysqld_safe &
  21260.  
  21261. If `mysqld_safe' fails, even when invoked from the MySQL installation
  21262. directory, you can modify it to use the path to `mysqld' and the
  21263. pathname options that are correct for your system.  Note that if you
  21264. upgrade MySQL in the future, your modified version of `mysqld_safe'
  21265. will be overwritten, so you should make a copy of your edited version
  21266. that you can reinstall.
  21267.  
  21268. `mysqld_multi', A Program for Managing Multiple MySQL Servers
  21269. -------------------------------------------------------------
  21270.  
  21271. `mysqld_multi' is meant for managing several `mysqld' processes that
  21272. listen for connections on different Unix sockets and TCP/IP ports.
  21273.  
  21274. The program will search for group(s) named `[mysqld#]' from `my.cnf'
  21275. (or the file named by the `--config-file=...' option), where `#' can be
  21276. any positive number starting from 1.  This number is referred to in the
  21277. following discussion as the option group number, or GNR.  Group numbers
  21278. distinquish option groups from one another and are used as arguments to
  21279. `mysqld_multi' to specify which servers you want to start, stop, or
  21280. obtain status for.  Options listed in these groups should be the same
  21281. as you would use in the usual `[mysqld]' group used for starting
  21282. `mysqld'.  (See, for example, *Note Automatic start::.)  However, for
  21283. `mysqld_multi', be sure that each group includes options for values
  21284. such as the port, socket, etc., to be used for each individual `mysqld'
  21285. process.
  21286.  
  21287. `mysqld_multi' is invoked using the following syntax:
  21288.  
  21289.      Usage: mysqld_multi [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  21290.      or     mysqld_multi [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  21291.  
  21292. Each GNR represents an option group number. You can start, stop or
  21293. report any GNR, or several of them at the same time. For an example of
  21294. how you might set up an option file, use this command:
  21295.  
  21296.      shell> mysqld_multi --example
  21297.  
  21298. The GNR values in the list can be comma-separated or combined with a
  21299. dash; in the latter case, all the GNRs between GNR1-GNR2 will be
  21300. affected. With no GNR argument, all groups listed in the option file
  21301. will be either started, stopped, or reported. Note that you must not
  21302. have any white spaces in the GNR list. Anything after a white space is
  21303. ignored.
  21304.  
  21305. `mysqld_multi' supports the following options:
  21306.  
  21307. `--config-file=...'
  21308.      Alternative config file. Note: This will not affect this program's
  21309.      own options (group `[mysqld_multi]'), but only groups `[mysqld#]'.
  21310.      Without this option, everything will be searched from the ordinary
  21311.      `my.cnf' file.
  21312.  
  21313. `--example'
  21314.      Display an example option file.
  21315.  
  21316. `--help'
  21317.      Print this help and exit.
  21318.  
  21319. `--log=...'
  21320.      Log file. Full path to and the name for the log file. Note: If the
  21321.      file exists, everything will be appended.
  21322.  
  21323. `--mysqladmin=...'
  21324.      `mysqladmin' binary to be used for a server shutdown.
  21325.  
  21326. `--mysqld=...'
  21327.      `mysqld' binary to be used. Note that you can give `mysqld_safe'
  21328.      to this option also. The options are passed to `mysqld'. Just make
  21329.      sure you have `mysqld' in your environment variable `PATH' or fix
  21330.      `mysqld_safe'.
  21331.  
  21332. `--no-log'
  21333.      Print to stdout instead of the log file. By default the log file is
  21334.      turned on.
  21335.  
  21336. `--password=...'
  21337.      Password for user for `mysqladmin'.
  21338.  
  21339. `--tcp-ip'
  21340.      Connect to the MySQL server(s) via the TCP/IP port instead of the
  21341.      Unix socket. This affects stopping and reporting.  If a socket file
  21342.      is missing, the server may still be running, but can be accessed
  21343.      only via the TCP/IP port.  By default, connections are made using
  21344.      the Unix socket.
  21345.  
  21346. `--user=...'
  21347.      MySQL user for `mysqladmin'.
  21348.  
  21349. `--version'
  21350.      Print the version number and exit.
  21351.  
  21352. Some notes about `mysqld_multi':
  21353.  
  21354.    * Make sure that the MySQL user, who is stopping the `mysqld'
  21355.      services (e.g using the `mysqladmin' program) have the same
  21356.      password and username for all the data directories accessed (to the
  21357.      `mysql' database) And make sure that the user has the `SHUTDOWN'
  21358.      privilege! If you have many data directories and many different
  21359.      `mysql' databases with different passwords for the MySQL `root'
  21360.      user, you may want to create a common `multi_admin' user for each
  21361.      using the same password (see below). Example how to do it:
  21362.           shell> mysql -u root -S /tmp/mysql.sock -proot_password -e
  21363.           "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'multipass'"
  21364.      *Note Privileges::.  You will have to do the above for each
  21365.      `mysqld' running in each data directory, that you have (just
  21366.      change the socket, `-S=...').
  21367.  
  21368.    * `pid-file' is very important, if you are using `mysqld_safe' to
  21369.      start `mysqld' (for example, `--mysqld=mysqld_safe') Every
  21370.      `mysqld' should have its own `pid-file'. The advantage using
  21371.      `mysqld_safe' instead of `mysqld' directly here is, that
  21372.      `mysqld_safe' "guards" every `mysqld' process and will restart it,
  21373.      if a `mysqld' process terminates due to a signal sent using `kill
  21374.      -9', or for other reasons such as a segmentation fault (which
  21375.      MySQL should never do, of course ;). Please note that the
  21376.      `mysqld_safe' script may require that you start it from a certain
  21377.      place. This means that you may have to `cd' to a certain directory,
  21378.      before you start the `mysqld_multi'. If you have problems starting,
  21379.      please see the `mysqld_safe' script. Check especially the lines:
  21380.  
  21381.           --------------------------------------------------------------------------
  21382.           MY_PWD=`pwd` Check if we are starting this relative (for the binary
  21383.           release) if test -d /data/mysql -a -f ./share/mysql/english/errmsg.sys
  21384.           -a -x ./bin/mysqld
  21385.           --------------------------------------------------------------------------
  21386.  
  21387.      *Note `mysqld_safe': mysqld_safe.  The above test should be
  21388.      successful, or you may encounter problems.
  21389.  
  21390.    * Beware of the dangers starting multiple `mysqld's in the same data
  21391.      directory.  Use separate data directories, unless you *know* what
  21392.      you are doing!
  21393.  
  21394.    * The socket file and the TCP/IP port must be different for every
  21395.      `mysqld'.
  21396.  
  21397.    * The first and fifth `mysqld' group were intentionally left out from
  21398.      the example.  You may have 'gaps' in the config file. This gives
  21399.      you more flexibility.  The order in which the `mysqlds' are
  21400.      started or stopped depends on the order in which they appear in
  21401.      the config file.
  21402.  
  21403.    * When you want to refer to a certain group using GNR with this
  21404.      program, just use the number in the end of the group name.  For
  21405.      example, the GNR for a group named `[mysqld17]' is 17.
  21406.  
  21407.    * You may want to use option `--user' for `mysqld', but in order to
  21408.      do this you need to run the `mysqld_multi' script as the Unix
  21409.      `root' user. Having the option in the config file doesn't matter;
  21410.      you will just get a warning, if you are not the superuser and the
  21411.      `mysqlds' are started under *your* Unix account. *Important*: Make
  21412.      sure that the `pid-file' and the data directory are
  21413.      read+write(+execute for the latter one) accessible for *that* Unix
  21414.      user, who the specific `mysqld' process is started as. *Do not*
  21415.      use the Unix root account for this, unless you *know* what you are
  21416.      doing!
  21417.  
  21418.    * *Most important*: Make sure that you understand the meanings of
  21419.      the options that are passed to the `mysqld's and *why one would
  21420.      want* to have separate `mysqld' processes. Starting multiple
  21421.      `mysqld's in one data directory *will not* give you extra
  21422.      performance in a threaded system!
  21423.  
  21424. *Note Multiple servers::.
  21425.  
  21426. This is an example of the config file on behalf of `mysqld_multi'.
  21427.  
  21428.      # This file should probably be in your home dir (~/.my.cnf) or /etc/my.cnf
  21429.      # Version 2.1 by Jani Tolonen
  21430.      
  21431.      [mysqld_multi]
  21432.      mysqld     = /usr/local/bin/mysqld_safe
  21433.      mysqladmin = /usr/local/bin/mysqladmin
  21434.      user       = multi_admin
  21435.      password   = multipass
  21436.      
  21437.      [mysqld2]
  21438.      socket     = /tmp/mysql.sock2
  21439.      port       = 3307
  21440.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  21441.      datadir    = /usr/local/mysql/var2
  21442.      language   = /usr/local/share/mysql/english
  21443.      user       = john
  21444.      
  21445.      [mysqld3]
  21446.      socket     = /tmp/mysql.sock3
  21447.      port       = 3308
  21448.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  21449.      datadir    = /usr/local/mysql/var3
  21450.      language   = /usr/local/share/mysql/swedish
  21451.      user       = monty
  21452.      
  21453.      [mysqld4]
  21454.      socket     = /tmp/mysql.sock4
  21455.      port       = 3309
  21456.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  21457.      datadir    = /usr/local/mysql/var4
  21458.      language   = /usr/local/share/mysql/estonia
  21459.      user       = tonu
  21460.      
  21461.      [mysqld6]
  21462.      socket     = /tmp/mysql.sock6
  21463.      port       = 3311
  21464.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  21465.      datadir    = /usr/local/mysql/var6
  21466.      language   = /usr/local/share/mysql/japanese
  21467.      user       = jani
  21468.  
  21469. *Note Option files::.
  21470.  
  21471. `myisampack', The MySQL Compressed Read-only Table Generator
  21472. ------------------------------------------------------------
  21473.  
  21474. `myisampack' is used to compress MyISAM tables, and `pack_isam' is used
  21475. to compress ISAM tables. Because ISAM tables are deprecated, we will
  21476. only discuss `myisampack' here, but everything said about `myisampack'
  21477. should also be true for `pack_isam'.
  21478.  
  21479. `myisampack' works by compressing each column in the table separately.
  21480. The information needed to decompress columns is read into memory when
  21481. the table is opened. This results in much better performance when
  21482. accessing individual records, because you only have to uncompress
  21483. exactly one record, not a much larger disk block as when using Stacker
  21484. on MS-DOS.  Usually, `myisampack' packs the datafile 40%-70%.
  21485.  
  21486. MySQL uses memory mapping (`mmap()') on compressed tables and falls
  21487. back to normal read/write file usage if `mmap()' doesn't work.
  21488.  
  21489. Please note the following:
  21490.    * After packing, the table is read-only. This is generally intended
  21491.      (such as when accessing packed tables on a CD). Also allowing
  21492.      writes to a packed table is on our TODO list but with low priority.
  21493.  
  21494.    * `myisampack' can also pack `BLOB' or `TEXT' columns.  The older
  21495.      `pack_isam' (for `ISAM' tables) can not do this.
  21496.  
  21497. `myisampack' is invoked like this:
  21498.  
  21499.      shell> myisampack [options] filename ...
  21500.  
  21501. Each filename should be the name of an index (`.MYI') file.  If you are
  21502. not in the database directory, you should specify the pathname to the
  21503. file.  It is permissible to omit the `.MYI' extension.
  21504.  
  21505. `myisampack' supports the following options:
  21506.  
  21507. `-b, --backup'
  21508.      Make a backup of the table as `tbl_name.OLD'.
  21509.  
  21510. `-#, --debug=debug_options'
  21511.      Output debug log. The `debug_options' string often is
  21512.      `'d:t:o,filename''.
  21513.  
  21514. `-f, --force'
  21515.      Force packing of the table even if it becomes bigger or if the
  21516.      temporary file exists.  `myisampack' creates a temporary file
  21517.      named `tbl_name.TMD' while it compresses the table.  If you kill
  21518.      `myisampack', the `.TMD' file may not be deleted.  Normally,
  21519.      `myisampack' exits with an error if it finds that `tbl_name.TMD'
  21520.      exists.  With `--force', `myisampack' packs the table anyway.
  21521.  
  21522. `-?, --help'
  21523.      Display a help message and exit.
  21524.  
  21525. `-j big_tbl_name, --join=big_tbl_name'
  21526.      Join all tables named on the command-line into a single table
  21527.      `big_tbl_name'.  All tables that are to be combined *must* be
  21528.      identical (same column names and types, same indexes, etc.).
  21529.  
  21530. `-p #, --packlength=#'
  21531.      Specify the record length storage size, in bytes.  The value
  21532.      should be 1, 2, or 3.  (`myisampack' stores all rows with length
  21533.      pointers of 1, 2, or 3 bytes.  In most normal cases, `myisampack'
  21534.      can determine the right length value before it begins packing the
  21535.      file, but it may notice during the packing process that it could
  21536.      have used a shorter length. In this case, `myisampack' will print
  21537.      a note that the next time you pack the same file, you could use a
  21538.      shorter record length.)
  21539.  
  21540. `-s, --silent'
  21541.      Silent mode.  Write output only when errors occur.
  21542.  
  21543. `-t, --test'
  21544.      Don't actually pack table, just test packing it.
  21545.  
  21546. `-T dir_name, --tmp_dir=dir_name'
  21547.      Use the named directory as the location in which to write the
  21548.      temporary table.
  21549.  
  21550. `-v, --verbose'
  21551.      Verbose mode.  Write information about progress and packing result.
  21552.  
  21553. `-V, --version'
  21554.      Display version information and exit.
  21555.  
  21556. `-w, --wait'
  21557.      Wait and retry if table is in use.  If the `mysqld' server was
  21558.      invoked with the `--skip-external-locking' option, it is not a
  21559.      good idea to invoke `myisampack' if the table might be updated
  21560.      during the packing process.
  21561.  
  21562. The sequence of commands shown here illustrates a typical table
  21563. compression session:
  21564.  
  21565.      shell> ls -l station.*
  21566.      -rw-rw-r--   1 monty    my         994128 Apr 17 19:00 station.MYD
  21567.      -rw-rw-r--   1 monty    my          53248 Apr 17 19:00 station.MYI
  21568.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  21569.      
  21570.      shell> myisamchk -dvv station
  21571.      
  21572.      MyISAM file:     station
  21573.      Isam-version:  2
  21574.      Creation time: 1996-03-13 10:08:58
  21575.      Recover time:  1997-02-02  3:06:43
  21576.      Data records:              1192  Deleted blocks:              0
  21577.      Datafile: Parts:           1192  Deleted data:                0
  21578.      Datafile pointer (bytes):     2  Keyfile pointer (bytes):     2
  21579.      Max datafile length:   54657023  Max keyfile length:   33554431
  21580.      Recordlength:               834
  21581.      Record format: Fixed length
  21582.      
  21583.      table description:
  21584.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  21585.      1   2     4   unique  unsigned long              1024       1024          1
  21586.      2   32    30  multip. text                      10240       1024          1
  21587.      
  21588.      Field Start Length Type
  21589.      1     1     1
  21590.      2     2     4
  21591.      3     6     4
  21592.      4     10    1
  21593.      5     11    20
  21594.      6     31    1
  21595.      7     32    30
  21596.      8     62    35
  21597.      9     97    35
  21598.      10    132   35
  21599.      11    167   4
  21600.      12    171   16
  21601.      13    187   35
  21602.      14    222   4
  21603.      15    226   16
  21604.      16    242   20
  21605.      17    262   20
  21606.      18    282   20
  21607.      19    302   30
  21608.      20    332   4
  21609.      21    336   4
  21610.      22    340   1
  21611.      23    341   8
  21612.      24    349   8
  21613.      25    357   8
  21614.      26    365   2
  21615.      27    367   2
  21616.      28    369   4
  21617.      29    373   4
  21618.      30    377   1
  21619.      31    378   2
  21620.      32    380   8
  21621.      33    388   4
  21622.      34    392   4
  21623.      35    396   4
  21624.      36    400   4
  21625.      37    404   1
  21626.      38    405   4
  21627.      39    409   4
  21628.      40    413   4
  21629.      41    417   4
  21630.      42    421   4
  21631.      43    425   4
  21632.      44    429   20
  21633.      45    449   30
  21634.      46    479   1
  21635.      47    480   1
  21636.      48    481   79
  21637.      49    560   79
  21638.      50    639   79
  21639.      51    718   79
  21640.      52    797   8
  21641.      53    805   1
  21642.      54    806   1
  21643.      55    807   20
  21644.      56    827   4
  21645.      57    831   4
  21646.      
  21647.      shell> myisampack station.MYI
  21648.      Compressing station.MYI: (1192 records)
  21649.      - Calculating statistics
  21650.      
  21651.      normal:     20  empty-space:      16  empty-zero:        12  empty-fill:  11
  21652.      pre-space:   0  end-space:        12  table-lookups:      5  zero:         7
  21653.      Original trees:  57  After join: 17
  21654.      - Compressing file
  21655.      87.14%
  21656.      
  21657.      shell> ls -l station.*
  21658.      -rw-rw-r--   1 monty    my         127874 Apr 17 19:00 station.MYD
  21659.      -rw-rw-r--   1 monty    my          55296 Apr 17 19:04 station.MYI
  21660.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  21661.      
  21662.      shell> myisamchk -dvv station
  21663.      
  21664.      MyISAM file:     station
  21665.      Isam-version:  2
  21666.      Creation time: 1996-03-13 10:08:58
  21667.      Recover time:  1997-04-17 19:04:26
  21668.      Data records:              1192  Deleted blocks:              0
  21669.      Datafile: Parts:           1192  Deleted data:                0
  21670.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     1
  21671.      Max datafile length:   16777215  Max keyfile length:     131071
  21672.      Recordlength:               834
  21673.      Record format: Compressed
  21674.      
  21675.      table description:
  21676.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  21677.      1   2     4   unique  unsigned long             10240       1024          1
  21678.      2   32    30  multip. text                      54272       1024          1
  21679.      
  21680.      Field Start Length Type                         Huff tree  Bits
  21681.      1     1     1      constant                             1     0
  21682.      2     2     4      zerofill(1)                          2     9
  21683.      3     6     4      no zeros, zerofill(1)                2     9
  21684.      4     10    1                                           3     9
  21685.      5     11    20     table-lookup                         4     0
  21686.      6     31    1                                           3     9
  21687.      7     32    30     no endspace, not_always              5     9
  21688.      8     62    35     no endspace, not_always, no empty    6     9
  21689.      9     97    35     no empty                             7     9
  21690.      10    132   35     no endspace, not_always, no empty    6     9
  21691.      11    167   4      zerofill(1)                          2     9
  21692.      12    171   16     no endspace, not_always, no empty    5     9
  21693.      13    187   35     no endspace, not_always, no empty    6     9
  21694.      14    222   4      zerofill(1)                          2     9
  21695.      15    226   16     no endspace, not_always, no empty    5     9
  21696.      16    242   20     no endspace, not_always              8     9
  21697.      17    262   20     no endspace, no empty                8     9
  21698.      18    282   20     no endspace, no empty                5     9
  21699.      19    302   30     no endspace, no empty                6     9
  21700.      20    332   4      always zero                          2     9
  21701.      21    336   4      always zero                          2     9
  21702.      22    340   1                                           3     9
  21703.      23    341   8      table-lookup                         9     0
  21704.      24    349   8      table-lookup                        10     0
  21705.      25    357   8      always zero                          2     9
  21706.      26    365   2                                           2     9
  21707.      27    367   2      no zeros, zerofill(1)                2     9
  21708.      28    369   4      no zeros, zerofill(1)                2     9
  21709.      29    373   4      table-lookup                        11     0
  21710.      30    377   1                                           3     9
  21711.      31    378   2      no zeros, zerofill(1)                2     9
  21712.      32    380   8      no zeros                             2     9
  21713.      33    388   4      always zero                          2     9
  21714.      34    392   4      table-lookup                        12     0
  21715.      35    396   4      no zeros, zerofill(1)               13     9
  21716.      36    400   4      no zeros, zerofill(1)                2     9
  21717.      37    404   1                                           2     9
  21718.      38    405   4      no zeros                             2     9
  21719.      39    409   4      always zero                          2     9
  21720.      40    413   4      no zeros                             2     9
  21721.      41    417   4      always zero                          2     9
  21722.      42    421   4      no zeros                             2     9
  21723.      43    425   4      always zero                          2     9
  21724.      44    429   20     no empty                             3     9
  21725.      45    449   30     no empty                             3     9
  21726.      46    479   1                                          14     4
  21727.      47    480   1                                          14     4
  21728.      48    481   79     no endspace, no empty               15     9
  21729.      49    560   79     no empty                             2     9
  21730.      50    639   79     no empty                             2     9
  21731.      51    718   79     no endspace                         16     9
  21732.      52    797   8      no empty                             2     9
  21733.      53    805   1                                          17     1
  21734.      54    806   1                                           3     9
  21735.      55    807   20     no empty                             3     9
  21736.      56    827   4      no zeros, zerofill(2)                2     9
  21737.      57    831   4      no zeros, zerofill(1)                2     9
  21738.  
  21739. The information printed by `myisampack' is described here:
  21740.  
  21741. `normal'
  21742.      The number of columns for which no extra packing is used.
  21743.  
  21744. `empty-space'
  21745.      The number of columns containing values that are only spaces;
  21746.      these will occupy 1 bit.
  21747.  
  21748. `empty-zero'
  21749.      The number of columns containing values that are only binary 0's;
  21750.      these will occupy 1 bit.
  21751.  
  21752. `empty-fill'
  21753.      The number of integer columns that don't occupy the full byte
  21754.      range of their type; these are changed to a smaller type (for
  21755.      example, an `INTEGER' column may be changed to `MEDIUMINT').
  21756.  
  21757. `pre-space'
  21758.      The number of decimal columns that are stored with leading spaces.
  21759.      In this case, each value will contain a count for the number of
  21760.      leading spaces.
  21761.  
  21762. `end-space'
  21763.      The number of columns that have a lot of trailing spaces.  In this
  21764.      case, each value will contain a count for the number of trailing
  21765.      spaces.
  21766.  
  21767. `table-lookup'
  21768.      The column had only a small number of different values, which were
  21769.      converted to an `ENUM' before Huffman compression.
  21770.  
  21771. `zero'
  21772.      The number of columns for which all values are zero.
  21773.  
  21774. `Original trees'
  21775.      The initial number of Huffman trees.
  21776.  
  21777. `After join'
  21778.      The number of distinct Huffman trees left after joining trees to
  21779.      save some header space.
  21780.  
  21781. After a table has been compressed, `myisamchk -dvv' prints additional
  21782. information about each field:
  21783.  
  21784. `Type'
  21785.      The field type may contain the following descriptors:
  21786.  
  21787.     `constant'
  21788.           All rows have the same value.
  21789.  
  21790.     `no endspace'
  21791.           Don't store endspace.
  21792.  
  21793.     `no endspace, not_always'
  21794.           Don't store endspace and don't do end space compression for
  21795.           all values.
  21796.  
  21797.     `no endspace, no empty'
  21798.           Don't store endspace. Don't store empty values.
  21799.  
  21800.     `table-lookup'
  21801.           The column was converted to an `ENUM'.
  21802.  
  21803.     `zerofill(n)'
  21804.           The most significant `n' bytes in the value are always 0 and
  21805.           are not stored.
  21806.  
  21807.     `no zeros'
  21808.           Don't store zeros.
  21809.  
  21810.     `always zero'
  21811.           0 values are stored in 1 bit.
  21812.  
  21813. `Huff tree'
  21814.      The Huffman tree associated with the field.
  21815.  
  21816. `Bits'
  21817.      The number of bits used in the Huffman tree.
  21818.  
  21819. After you have run `pack_isam'/`myisampack' you must run
  21820. `isamchk'/`myisamchk' to re-create the index.  At this time you can
  21821. also sort the index blocks and create statistics needed for the MySQL
  21822. optimiser to work more efficiently:
  21823.  
  21824.      myisamchk -rq --analyze --sort-index table_name.MYI
  21825.      isamchk   -rq --analyze --sort-index table_name.ISM
  21826.  
  21827. After you have installed the packed table into the MySQL database
  21828. directory you should do `mysqladmin flush-tables' to force `mysqld' to
  21829. start using the new table.
  21830.  
  21831. If you want to unpack a packed table, you can do this with the
  21832. `--unpack' option to `isamchk' or `myisamchk'.
  21833.  
  21834. `mysqld-max', An Extended `mysqld' Server
  21835. -----------------------------------------
  21836.  
  21837. `mysqld-max' is the MySQL server (`mysqld') configured with the
  21838. following configure options:
  21839.  
  21840. *Option*               *Comment*
  21841. -with-server-suffix=-maxAdd a suffix to the `mysqld'
  21842.                        version string.
  21843. -with-innodb           Support for InnoDB tables in
  21844.                        version 3.23.
  21845. -with-bdb              Support for Berkeley DB (BDB)
  21846.                        tables
  21847. CFLAGS=-DUSE_SYMDIR    Symbolic links support for
  21848.                        Windows.
  21849.  
  21850. You can find the MySQL-Max binaries at
  21851. `http://www.mysql.com/downloads/mysql-max-3.23.html'.
  21852.  
  21853. The Windows MySQL binary distributions includes both the standard
  21854. `mysqld.exe' binary and the `mysqld-max.exe' binary.
  21855. `http://www.mysql.com/downloads/mysql-3.23.html'.  *Note Windows
  21856. installation::.
  21857.  
  21858. Note that as BerkeleyDB (BDB) is not available for all platforms, so
  21859. some of the `Max' binaries may not have support for it.  You can check
  21860. which table types are supported by doing the following query:
  21861.  
  21862.      mysql> SHOW VARIABLES LIKE "have_%";
  21863.      +------------------+----------+
  21864.      | Variable_name    | Value    |
  21865.      +------------------+----------+
  21866.      | have_bdb         | NO       |
  21867.      | have_crypt       | YES      |
  21868.      | have_innodb      | YES      |
  21869.      | have_isam        | YES      |
  21870.      | have_raid        | NO       |
  21871.      | have_symlink     | DISABLED |
  21872.      | have_openssl     | NO       |
  21873.      | have_query_cache | YES      |
  21874.      +------------------+----------+
  21875.  
  21876. The meaning of the values are:
  21877.  
  21878. *Value*     *Meaning*
  21879. `YES'       The option is activated and usable.
  21880. `NO'        MySQL is not compiled with support for this option.
  21881. `DISABLED'  The xxxx option is disabled because one started `mysqld'
  21882.             with `--skip-xxxx' or because one didn't start `mysqld' with
  21883.             all needed options to enable the option.  In this case the
  21884.             `hostname.err' file should contain a reason for why the
  21885.             option is disabled.
  21886.  
  21887. *Note*:  To be able to create InnoDB tables in MySQL version 3.23 you
  21888. *must* edit your startup options to include at least the
  21889. `innodb_data_file_path' option. *Note InnoDB in MySQL 3.23::.
  21890.  
  21891. To get better performance for BDB tables, you should add some
  21892. configuration options for these too. *Note BDB start::.
  21893.  
  21894. `mysqld_safe' will automatically try to start any `mysqld' binary with
  21895. the `-max' suffix. This makes it very easy to test out a another
  21896. `mysqld' binary in an existing installation.  Just run `configure' with
  21897. the options you want and then install the new `mysqld' binary as
  21898. `mysqld-max' in the same directory where your old `mysqld' binary is.
  21899. *Note `mysqld_safe': mysqld_safe.
  21900.  
  21901. The `mysqld-max' RPM uses the above mentioned `mysqld_safe' feature. It
  21902. just installs the `mysqld-max' executable and `mysqld_safe' will
  21903. automatically use this executable when `mysqld_safe' is restarted.
  21904.  
  21905. The following table shows which table types our standard MySQL-Max
  21906. binaries includes:
  21907.  
  21908. *System*    `BDB'   `InnoDB'
  21909. AIX 4.3     N       Y
  21910. HP-UX 11.0  N       Y
  21911. Linux-Alpha N       Y
  21912. Linux-Intel Y       Y
  21913. Linux-IA-64 N       Y
  21914. Solaris-IntelN       Y
  21915. Solaris-SPARCY       Y
  21916. SCO OSR5    Y       Y
  21917. UnixWare    Y       Y
  21918. Windows/NT  Y       Y
  21919.  
  21920. MySQL Client-Side Scripts and Utilities
  21921. =======================================
  21922.  
  21923. Overview of the Client-Side Scripts and Utilities
  21924. -------------------------------------------------
  21925.  
  21926. All MySQL clients that communicate with the server using the
  21927. `mysqlclient' library use the following environment variables:
  21928.  
  21929. *Name*             *Description*
  21930. `MYSQL_UNIX_PORT'  The default socket; used for connections
  21931.                    to `localhost'
  21932. `MYSQL_TCP_PORT'   The default TCP/IP port
  21933. `MYSQL_PWD'        The default password
  21934. `MYSQL_DEBUG'      Debug-trace options when debugging
  21935. `TMPDIR'           The directory where temporary tables/files
  21936.                    are created
  21937.  
  21938. Use of `MYSQL_PWD' is insecure.  *Note Connecting::.
  21939.  
  21940. The `mysql' client uses the file named in the `MYSQL_HISTFILE'
  21941. environment variable to save the command-line history. The default
  21942. value for the history file is `$HOME/.mysql_history', where `$HOME' is
  21943. the value of the `HOME' environment variable. *Note Environment
  21944. variables::.
  21945.  
  21946. All MySQL programs take many different options. However, every MySQL
  21947. program provides a `--help' option that you can use to get a full
  21948. description of the program's different options. For example, try `mysql
  21949. --help'.
  21950.  
  21951. You can override default options for all standard client programs with
  21952. an option file. *Note Option files::.
  21953.  
  21954. The following list briefly describes the client-side MySQL programs:
  21955.  
  21956. `msql2mysql'
  21957.      A shell script that converts `mSQL' programs to MySQL. It doesn't
  21958.      handle all cases, but it gives a good start when converting.
  21959.  
  21960. `mysqlaccess'
  21961.      A script that checks the access privileges for a host, user, and
  21962.      database combination.
  21963.  
  21964. `mysqladmin'
  21965.      Utility for performing administrative operations, such as creating
  21966.      or dropping databases, reloading the grant tables, flushing tables
  21967.      to disk, and reopening log files.  `mysqladmin' can also be used
  21968.      to retrieve version, process, and status information from the
  21969.      server.  *Note `mysqladmin': mysqladmin.
  21970.  
  21971. `mysqldump'
  21972.      Dumps a MySQL database into a file as SQL statements or as
  21973.      tab-separated text files. Enhanced freeware originally by Igor
  21974.      Romanenko.  *Note `mysqldump': mysqldump.
  21975.  
  21976. `mysqlimport'
  21977.      Imports text files into their respective tables using `LOAD DATA
  21978.      INFILE'. *Note `mysqlimport': mysqlimport.
  21979.  
  21980. `mysqlshow'
  21981.      Displays information about databases, tables, columns, and indexes.
  21982.  
  21983. `replace'
  21984.      A utility program that is used by `msql2mysql', but that has more
  21985.      general applicability as well.  `replace' changes strings in place
  21986.      in files or on the standard input. Uses a finite state machine to
  21987.      match longer strings first. Can be used to swap strings. For
  21988.      example, this command swaps `a' and `b' in the given files:
  21989.  
  21990.           shell> replace a b b a -- file1 file2 ...
  21991.  
  21992. `mysql', The Command-line Tool
  21993. ------------------------------
  21994.  
  21995. `mysql' is a simple SQL shell (with GNU `readline' capabilities).  It
  21996. supports interactive and non-interactive use. When used interactively,
  21997. query results are presented in an ASCII-table format. When used
  21998. non-interactively (for example, as a filter), the result is presented in
  21999. tab-separated format.  (The output format can be changed using
  22000. command-line options.)  You can run scripts simply like this:
  22001.  
  22002.      shell> mysql database < script.sql > output.tab
  22003.  
  22004. If you have problems due to insufficient memory in the client, use the
  22005. `--quick' option!  This forces `mysql' to use `mysql_use_result()'
  22006. rather than `mysql_store_result()' to retrieve the result set.
  22007.  
  22008. Using `mysql' is very easy. Just start it as follows: `mysql database'
  22009. or `mysql --user=user_name --password=your_password database'. Type an
  22010. SQL statement, end it with `;', `\g', or `\G' and press Enter.
  22011.  
  22012. `mysql' supports the following options:
  22013.  
  22014. `-?, --help'
  22015.      Display this help and exit.
  22016.  
  22017. `-A, --no-auto-rehash'
  22018.      No automatic rehashing. One has to use 'rehash' to get table and
  22019.      field completion. This gives a quicker start of mysql.
  22020.  
  22021. `--prompt=...'
  22022.      Set the mysql prompt to specified format.
  22023.  
  22024. `-b, --no-beep'
  22025.      Turn off beep-on-error.
  22026.  
  22027. `-B, --batch'
  22028.      Print results with a tab as separator, each row on a new line.
  22029.      Doesn't use history file.
  22030.  
  22031. `--character-sets-dir=...'
  22032.      Directory where character sets are located.
  22033.  
  22034. `-C, --compress'
  22035.      Use compression in server/client protocol.
  22036.  
  22037. `-#, --debug[=...]'
  22038.      Debug log. Default is 'd:t:o,/tmp/mysql.trace'.
  22039.  
  22040. `-D, --database=...'
  22041.      Database to use. This is mainly useful in the `my.cnf' file.
  22042.  
  22043. `--default-character-set=...'
  22044.      Set the default character set.
  22045.  
  22046. `-e, --execute=...'
  22047.      Execute command and quit. (Output like with -batch)
  22048.  
  22049. `-E, --vertical'
  22050.      Print the output of a query (rows) vertically. Without this option
  22051.      you can also force this output by ending your statements with `\G'.
  22052.  
  22053. `-f, --force'
  22054.      Continue even if we get an SQL error.
  22055.  
  22056. `-g, --no-named-commands'
  22057.      Named commands are disabled. Use \* form only, or use named
  22058.      commands only in the beginning of a line ending with a semicolon
  22059.      (`;'). Since Version 10.9, the client now starts with this option
  22060.      *enabled* by default!  With the -g option, long format commands
  22061.      will still work from the first line, however.
  22062.  
  22063. `-G, --enable-named-commands'
  22064.      Named commands are *enabled*.  Long format commands are allowed as
  22065.      well as shortened \* commands.
  22066.  
  22067. `-i, --ignore-space'
  22068.      Ignore space after function names.
  22069.  
  22070. `-h, --host=...'
  22071.      Connect to the given host.
  22072.  
  22073. `-H, --html'
  22074.      Produce HTML output.
  22075.  
  22076. `-X, --xml'
  22077.      Produce XML output.
  22078.  
  22079. `-L, --skip-line-numbers'
  22080.      Don't write line number for errors. Useful when one wants to
  22081.      compare result files that includes error messages
  22082.  
  22083. `--no-pager'
  22084.      Disable pager and print to stdout. See interactive help (\h) also.
  22085.  
  22086. `--no-tee'
  22087.      Disable outfile. See interactive help (\h) also.
  22088.  
  22089. `-n, --unbuffered'
  22090.      Flush buffer after each query.
  22091.  
  22092. `-N, --skip-column-names'
  22093.      Don't write column names in results.
  22094.  
  22095. `-O, --set-variable var=option'
  22096.      Give a variable a value. `--help' lists variables.  Please note
  22097.      that `--set-variable' is deprecated since MySQL 4.0, just use
  22098.      `--var=option' on its own.
  22099.  
  22100. `-o, --one-database'
  22101.      Only update the default database. This is useful for skipping
  22102.      updates to other database in the binary log.
  22103.  
  22104. ``--pager[=...]''
  22105.      Output type. Default is your `ENV' variable `PAGER'. Valid pagers
  22106.      are less, more, cat [> filename], etc.  See interactive help (\h)
  22107.      also. This option does not work in batch mode. Pager works only in
  22108.      Unix.
  22109.  
  22110. `-p[password], --password[=...]'
  22111.      Password to use when connecting to server. If a password is not
  22112.      given on the command-line, you will be prompted for it.  Note that
  22113.      if you use the short form `-p' you can't have a space between the
  22114.      option and the password.
  22115.  
  22116. `-P port_num, --port=port_num'
  22117.      TCP/IP port number to use for connection.
  22118.  
  22119. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22120.      To specify the connect protocol to use.  New in MySQL 4.1.
  22121.  
  22122. `-q, --quick'
  22123.      Don't cache result, print it row-by-row. This may slow down the
  22124.      server if the output is suspended. Doesn't use history file.
  22125.  
  22126. `-r, --raw'
  22127.      Write column values without escape conversion. Used with `--batch'
  22128.  
  22129. `--reconnect'
  22130.      If the connection is lost, automatically try to reconnect to the
  22131.      server (but only once).
  22132.  
  22133. `-s, --silent'
  22134.      Be more silent.
  22135.  
  22136. `-S  --socket=...'
  22137.      Socket file to use for connection.
  22138.  
  22139. `-t  --table'
  22140.      Output in table format. This is default in non-batch mode.
  22141.  
  22142. `-T, --debug-info'
  22143.      Print some debug information at exit.
  22144.  
  22145. `--tee=...'
  22146.      Append everything into outfile. See interactive help (\h) also.
  22147.      Does not work in batch mode.
  22148.  
  22149. `-u, --user=#'
  22150.      User for login if not current user.
  22151.  
  22152. `-U, --safe-updates[=#], --i-am-a-dummy[=#]'
  22153.      Only allow `UPDATE' and `DELETE' that uses keys. See below for
  22154.      more information about this option.  You can reset this option if
  22155.      you have it in your `my.cnf' file by using `--safe-updates=0'.
  22156.  
  22157. `-v, --verbose'
  22158.      More verbose output (-v -v -v gives the table output format).
  22159.  
  22160. `-V, --version'
  22161.      Output version information and exit.
  22162.  
  22163. `-w, --wait'
  22164.      Wait and retry if connection is down instead of aborting.
  22165.  
  22166. You can also set the following variables with `-O' or `--set-variable';
  22167. please note that `--set-variable' is deprecated since MySQL 4.0, just
  22168. use `--var=option' on its own:
  22169.  
  22170. *Variable Name*    *Default**Description*
  22171. connect_timeout    0       Number of seconds before timeout connection.
  22172. max_allowed_packet 16777216Max packetlength to send/receive from to server
  22173. net_buffer_length  16384   Buffer for TCP/IP and socket communication
  22174. select_limit       1000    Automatic limit for SELECT when using
  22175.                            -i-am-a-dummy
  22176. max_join_size      1000000 Automatic limit for rows in a join when using
  22177.                            -i-am-a-dummy.
  22178.  
  22179. If the `mysql' client loses connection to the server while sending it a
  22180. query, it will immediately and automatically try to reconnect once to
  22181. the server and send the query again.  Note that even if it succeeds in
  22182. reconnecting, as your first connection has ended, all your previous
  22183. session objects are lost : temporary tables, user and session
  22184. variables. Therefore, the above behaviour may be dangerous for you,
  22185. like in this example where the server was shut down and restarted
  22186. without you knowing it :
  22187.  
  22188.      mysql> set @a=1;
  22189.      Query OK, 0 rows affected (0.05 sec)
  22190.      
  22191.      mysql> insert into t values(@a);
  22192.      ERROR 2006: MySQL server has gone away
  22193.      No connection. Trying to reconnect...
  22194.      Connection id:    1
  22195.      Current database: test
  22196.      
  22197.      Query OK, 1 row affected (1.30 sec)
  22198.      
  22199.      mysql> select * from t;
  22200.      +------+
  22201.      | a    |
  22202.      +------+
  22203.      | NULL |
  22204.      +------+
  22205.      1 row in set (0.05 sec)
  22206.  
  22207. The `@a' user variable has been lost with the connection, and after the
  22208. reconnection it is undefined.  To protect from this risk, you can start
  22209. the `mysql' client with the `--disable-reconnect' option.
  22210.  
  22211. If you type 'help' on the command-line, `mysql' will print out the
  22212. commands that it supports:
  22213.  
  22214.      mysql> help
  22215.      
  22216.      MySQL commands:
  22217.      help    (\h)    Display this text.
  22218.      ?       (\h)    Synonym for `help'.
  22219.      clear   (\c)    Clear command.
  22220.      connect (\r)    Reconnect to the server.
  22221.                      Optional arguments are db and host.
  22222.      edit    (\e)    Edit command with $EDITOR.
  22223.      ego     (\G)    Send command to mysql server,
  22224.                      display result vertically.
  22225.      exit    (\q)    Exit mysql. Same as quit.
  22226.      go      (\g)    Send command to mysql server.
  22227.      nopager (\n)    Disable pager, print to stdout.
  22228.      notee   (\t)    Don't write into outfile.
  22229.      pager   (\P)    Set PAGER [to_pager].
  22230.                      Print the query results via PAGER.
  22231.      print   (\p)    Print current command.
  22232.      prompt  (\R)    Change your mysql prompt.
  22233.      quit    (\q)    Quit mysql.
  22234.      rehash  (\#)    Rebuild completion hash.
  22235.      source  (\.)    Execute an SQL script file.
  22236.                      Takes a file name as an argument.
  22237.      status  (\s)    Get status information from the server.
  22238.      system  (\!)    Execute a system shell command.
  22239.      tee     (\T)    Set outfile [to_outfile].
  22240.                      Append everything into given outfile.
  22241.      use     (\u)    Use another database.
  22242.                      Takes database name as argument.
  22243.  
  22244. The `edit', `nopager', `pager', and `system' commands work only in Unix.
  22245.  
  22246. The `status' command gives you some information about the connection
  22247. and the server you are using. If you are running in the
  22248. `--safe-updates' mode, `status' will also print the values for the
  22249. `mysql' variables that affect your queries.
  22250.  
  22251. A useful startup option for beginners (introduced in MySQL Version
  22252. 3.23.11) is `--safe-updates' (or `--i-am-a-dummy' for users that once
  22253. may have done a `DELETE FROM table_name' but forgot the `WHERE'
  22254. clause).  When using this option, `mysql' sends the following command
  22255. to the MySQL server when opening the connection:
  22256.  
  22257.      SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#,
  22258.          SQL_MAX_JOIN_SIZE=#max_join_size#"
  22259.  
  22260. where `#select_limit#' and `#max_join_size#' are variables that can be
  22261. set from the `mysql' command-line. *Note `SET': SET OPTION.
  22262.  
  22263. The effect of the above is:
  22264.  
  22265.    * You are not allowed to do an `UPDATE' or `DELETE' statement if you
  22266.      don't have a key constraint in the `WHERE' part. One can, however,
  22267.      force an `UPDATE/DELETE' by using `LIMIT':
  22268.           UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1;
  22269.  
  22270.    * All big results are automatically limited to `#select_limit#' rows.
  22271.  
  22272.    * `SELECT's that will probably need to examine more than
  22273.      `#max_join_size' row combinations will be aborted.
  22274.  
  22275. Some useful hints about the `mysql' client:
  22276.  
  22277. Some data is much more readable when displayed vertically, instead of
  22278. the usual horizontal box type output. For example longer text, which
  22279. includes new lines, is often much easier to be read with vertical
  22280. output.
  22281.  
  22282.      mysql> SELECT * FROM mails WHERE LENGTH(txt) < 300 lIMIT 300,1\G
  22283.      *************************** 1. row ***************************
  22284.        msg_nro: 3068
  22285.           date: 2000-03-01 23:29:50
  22286.      time_zone: +0200
  22287.      mail_from: Monty
  22288.          reply: monty@no.spam.com
  22289.        mail_to: "Thimble Smith" <tim@no.spam.com>
  22290.            sbj: UTF-8
  22291.            txt: >>>>> "Thimble" == Thimble Smith writes:
  22292.      
  22293.      Thimble> Hi.  I think this is a good idea.  Is anyone familiar with UTF-8
  22294.      Thimble> or Unicode? Otherwise, I'll put this on my TODO list and see what
  22295.      Thimble> happens.
  22296.      
  22297.      Yes, please do that.
  22298.      
  22299.      Regards,
  22300.      Monty
  22301.           file: inbox-jani-1
  22302.           hash: 190402944
  22303.      1 row in set (0.09 sec)
  22304.  
  22305. For logging, you can use the `tee' option. The `tee' can be started
  22306. with option `--tee=...', or from the command-line interactively with
  22307. command `tee'. All the data displayed on the screen will also be
  22308. appended into a given file. This can be very useful for debugging
  22309. purposes also. The `tee' can be disabled from the command-line with
  22310. command `notee'. Executing `tee' again starts logging again. Without a
  22311. parameter the previous file will be used. Note that `tee' will flush
  22312. the results into the file after each command, just before the
  22313. command-line appears again waiting for the next command.
  22314.  
  22315. Browsing, or searching the results in the interactive mode in Unix less,
  22316. more, or any other similar program, is now possible with option
  22317. `--pager[=...]'. Without argument, `mysql' client will look for
  22318. environment variable PAGER and set `pager' to that.  `pager' can be
  22319. started from the interactive command-line with command `pager' and
  22320. disabled with command `nopager'.  The command takes an argument
  22321. optionally and the `pager' will be set to that. Command `pager' can be
  22322. called without an argument, but this requires that the option `--pager'
  22323. was used, or the `pager' will default to stdout. `pager' works only in
  22324. Unix, since it uses the popen() function, which doesn't exist in
  22325. Windows. In Windows, the `tee' option can be used instead, although it
  22326. may not be as handy as `pager' can be in some situations.
  22327.  
  22328. A few tips about `pager':
  22329.    * You can use it to write to a file:
  22330.           mysql> pager cat > /tmp/log.txt
  22331.      and the results will only go to a file. You can also pass any
  22332.      options for the programs that you want to use with the `pager':
  22333.           mysql> pager less -n -i -S
  22334.  
  22335.    * From the above do note the option '-S'. You may find it very
  22336.      useful when browsing the results; try the option with horizontal
  22337.      output (end commands with '\g', or ';') and with vertical output
  22338.      (end commands with '\G'). Sometimes a very wide result set is hard
  22339.      to be read from the screen, with option -S to less you can browse
  22340.      the results within the interactive less from left to right,
  22341.      preventing lines longer than your screen from being continued to
  22342.      the next line. This can make the result set much more readable.
  22343.      You can swith the mode between on and off within the interactive
  22344.      less with '-S'. See the 'h' for more help about less.
  22345.  
  22346.    * You can combine very complex ways to handle the results, for
  22347.      example the following would send the results to two files in two
  22348.      different directories, on two different hard-disks mounted on /dr1
  22349.      and /dr2, yet let the results still be seen on the screen via less:
  22350.           mysql> pager cat | tee /dr1/tmp/res.txt | \
  22351.           tee /dr2/tmp/res2.txt | less -n -i -S
  22352.  
  22353.  
  22354. You can also combine the two functions above; have the `tee' enabled,
  22355. `pager' set to 'less' and you will be able to browse the results in
  22356. unix 'less' and still have everything appended into a file the same
  22357. time. The difference between Unix `tee' used with the `pager' and the
  22358. `mysql' client in-built `tee', is that the in-built `tee' works even if
  22359. you don't have the Unix `tee' available. The in-built `tee' also logs
  22360. everything that is printed on the screen, where the Unix `tee' used
  22361. with `pager' doesn't log quite that much. Last, but not least, the
  22362. interactive `tee' is more handy to switch on and off, when you want to
  22363. log something into a file, but want to be able to turn the feature off
  22364. sometimes.
  22365.  
  22366. From MySQL version 4.0.2 it is possible to change the prompt in the
  22367. `mysql' command-line client.
  22368.  
  22369. You can use the following prompt options:
  22370. *Option**Description*
  22371. \v      mysqld version
  22372. \d      database in use
  22373. \h      host connected to
  22374. \p      port connected on
  22375. \u      username
  22376. \U      full username@host
  22377. \\      `\'
  22378. \n      new line break
  22379. \t      tab
  22380. \       space
  22381. \_      space
  22382. \R      military hour time (0-23)
  22383. \r      standard hour time (1-12)
  22384. \m      minutes
  22385. \y      two digit year
  22386. \Y      four digit year
  22387. \D      full date format
  22388. \s      seconds
  22389. \w      day of the week in three letter
  22390.         format (Mon, Tue, ...)
  22391. \P      am/pm
  22392. \o      month in number format
  22393. \O      month in three letter format (Jan,
  22394.         Feb, ...)
  22395. \c      counter that counts up for each
  22396.         command you do
  22397.  
  22398. `\' followed by any other letter just becomes that letter.
  22399.  
  22400. You may set the prompt in the following places:
  22401.  
  22402. *Environment Variable*
  22403.      You may set the `MYSQL_PS1' environment variable to a prompt
  22404.      string.  For example:
  22405.  
  22406.           shell> export MYSQL_PS1="(\u@\h) [\d]> "
  22407.  
  22408. *`my.cnf'*
  22409.  
  22410. *`.my.cnf'*
  22411.      You may set the `prompt' option in any MySQL configuration file,
  22412.      in the `mysql' group.  For example:
  22413.  
  22414.           [mysql]
  22415.           prompt=(\u@\h) [\d]>\_
  22416.  
  22417. *Command Line*
  22418.      You may set the `--prompt' option on the command line to `mysql'.
  22419.      For example:
  22420.  
  22421.           shell> mysql --prompt="(\u@\h) [\d]> "
  22422.           
  22423.           (user@host) [database]>
  22424.  
  22425. *Interactively*
  22426.      You may also use the `prompt' (or `\R') command to change your
  22427.      prompt interactively.  For example:
  22428.  
  22429.           mysql> prompt (\u@\h) [\d]>\_
  22430.           PROMPT set to '(\u@\h) [\d]>\_'
  22431.           (user@host) [database]>
  22432.           (user@host) [database]> prompt
  22433.           Returning to default PROMPT of mysql>
  22434.           mysql>
  22435.  
  22436. `mysqladmin', Administrating a MySQL Server
  22437. -------------------------------------------
  22438.  
  22439. A utility for performing administrative operations. The syntax is:
  22440.  
  22441.      shell> mysqladmin [OPTIONS] command [command-option] command ...
  22442.  
  22443. You can get a list of the options your version of `mysqladmin' supports
  22444. by executing `mysqladmin --help'.
  22445.  
  22446. The current `mysqladmin' supports the following commands:
  22447.  
  22448. `create databasename'
  22449.      Create a new database.
  22450.  
  22451. `drop databasename'
  22452.      Delete a database and all its tables.
  22453.  
  22454. `extended-status'
  22455.      Gives an extended status message from the server.
  22456.  
  22457. `flush-hosts'
  22458.      Flush all cached hosts.
  22459.  
  22460. `flush-logs'
  22461.      Flush all logs.
  22462.  
  22463. `flush-tables'
  22464.      Flush all tables.
  22465.  
  22466. `flush-privileges'
  22467.      Reload grant tables (same as reload).
  22468.  
  22469. `kill id,id,...'
  22470.      Kill mysql threads.
  22471.  
  22472. `password'
  22473.      Set a new password. Change old password to new-password.
  22474.  
  22475. `ping'
  22476.      Check if mysqld is alive.
  22477.  
  22478. `processlist'
  22479.      Show list of active threads in server.
  22480.  
  22481. `reload'
  22482.      Reload grant tables.
  22483.  
  22484. `refresh'
  22485.      Flush all tables and close and open logfiles.
  22486.  
  22487. `shutdown'
  22488.      Take server down.
  22489.  
  22490. `slave-start'
  22491.      Start slave replication thread.
  22492.  
  22493. `slave-stop'
  22494.      Stop slave replication thread.
  22495.  
  22496. `status'
  22497.      Gives a short status message from the server.
  22498.  
  22499. `variables'
  22500.      Prints variables available.
  22501.  
  22502. `version'
  22503.      Get version info from server.
  22504.  
  22505. All commands can be shortened to their unique prefix.  For example:
  22506.  
  22507.      shell> mysqladmin proc stat
  22508.      +----+-------+-----------+----+-------------+------+-------+------+
  22509.      | Id | User  | Host      | db | Command     | Time | State | Info |
  22510.      +----+-------+-----------+----+-------------+------+-------+------+
  22511.      | 6  | monty | localhost |    | Processlist | 0    |       |      |
  22512.      +----+-------+-----------+----+-------------+------+-------+------+
  22513.      Uptime: 10077  Threads: 1  Questions: 9  Slow queries: 0
  22514.      Opens: 6 Flush tables: 1  Open tables: 2
  22515.      Memory in use: 1092K  Max memory used: 1116K
  22516.  
  22517. The `mysqladmin status' command result has the following columns:
  22518.  
  22519. *Column*       *Description*
  22520. Uptime         Number of seconds the MySQL server has been up.
  22521. Threads        Number of active threads (clients).
  22522. Questions      Number of questions from clients since
  22523.                `mysqld' was started.
  22524. Slow queries   Queries that have taken more than
  22525.                `long_query_time' seconds. *Note Slow query
  22526.                log::.
  22527. Opens          How many tables `mysqld' has opened.
  22528. Flush tables   Number of `flush ...', `refresh', and `reload'
  22529.                commands.
  22530. Open tables    Number of tables that are open now.
  22531. Memory in use  Memory allocated directly by the `mysqld' code
  22532.                (only available when MySQL is compiled with
  22533.                -with-debug=full).
  22534. Max memory     Maximum memory allocated directly by the
  22535. used           `mysqld' code (only available when MySQL is
  22536.                compiled with -with-debug=full).
  22537.  
  22538. If you do `mysqladmin shutdown' on a socket (in other words, on a the
  22539. computer where `mysqld' is running), `mysqladmin' will wait until the
  22540. MySQL `pid-file' is removed to ensure that the `mysqld' server has
  22541. stopped properly.
  22542.  
  22543. Using `mysqlcheck' for Table Maintenance and Crash Recovery
  22544. -----------------------------------------------------------
  22545.  
  22546. Since MySQL version 3.23.38 you will be able to use a new checking and
  22547. repairing tool for `MyISAM' tables. The difference to `myisamchk' is
  22548. that `mysqlcheck' should be used when the `mysqld' server is running,
  22549. where as `myisamchk' should be used when it is not. The benefit is that
  22550. you no longer have to take the server down for checking or repairing
  22551. your tables.
  22552.  
  22553. `mysqlcheck' uses MySQL server commands `CHECK', `REPAIR', `ANALYZE'
  22554. and `OPTIMIZE' in a convenient way for the user.
  22555.  
  22556. There are three alternative ways to invoke `mysqlcheck':
  22557.  
  22558.      shell> mysqlcheck [OPTIONS] database [tables]
  22559.      shell> mysqlcheck [OPTIONS] --databases DB1 [DB2 DB3...]
  22560.      shell> mysqlcheck [OPTIONS] --all-databases
  22561.  
  22562. So it can be used in a similar way as `mysqldump' when it comes to what
  22563. databases and tables you want to choose.
  22564.  
  22565. `mysqlcheck' does have a special feature compared to the other clients;
  22566. the default behaviour, checking tables (-c), can be changed by renaming
  22567. the binary. So if you want to have a tool that repairs tables by
  22568. default, you should just copy `mysqlcheck' to your harddrive with a new
  22569. name, `mysqlrepair', or alternatively make a symbolic link to
  22570. `mysqlrepair' and name the symbolic link as `mysqlrepair'. If you
  22571. invoke `mysqlrepair' now, it will repair tables by default.
  22572.  
  22573. The names that you can use to change `mysqlcheck' default behaviour are
  22574. here:
  22575.  
  22576.      mysqlrepair:   The default option will be -r
  22577.      mysqlanalyze:  The default option will be -a
  22578.      mysqloptimize: The default option will be -o
  22579.  
  22580. The options available for `mysqlcheck' are listed here, please check
  22581. what your version supports with `mysqlcheck --help'.
  22582.  
  22583. `-A, --all-databases'
  22584.      Check all the databases. This will be same as -databases with all
  22585.      databases selected
  22586.  
  22587. `-1, --all-in-1'
  22588.      Instead of making one query for each table, execute all queries in
  22589.      1 query separately for each database. Table names will be in a
  22590.      comma separated list.
  22591.  
  22592. `-a, --analyze'
  22593.      Analyse given tables.
  22594.  
  22595. `--auto-repair'
  22596.      If a checked table is corrupted, automatically fix it. Repairing
  22597.      will be done after all tables have been checked, if corrupted ones
  22598.      were found.
  22599.  
  22600. `-#, --debug=...'
  22601.      Output debug log. Often this is 'd:t:o,filename'
  22602.  
  22603. `--character-sets-dir=...'
  22604.      Directory where character sets are
  22605.  
  22606. `-c, --check'
  22607.      Check table for errors
  22608.  
  22609. `-C, --check-only-changed'
  22610.      Check only tables that have changed since last check or haven't
  22611.      been closed properly.
  22612.  
  22613. `--compress'
  22614.      Use compression in server/client protocol.
  22615.  
  22616. `-?, --help'
  22617.      Display this help message and exit.
  22618.  
  22619. `-B, --databases'
  22620.      To check several databases. Note the difference in usage; in this
  22621.      case no tables are given. All name arguments are regarded as
  22622.      database names.
  22623.  
  22624. `--default-character-set=...'
  22625.      Set the default character set
  22626.  
  22627. `-F, --fast'
  22628.      Check only tables that hasn't been closed properly
  22629.  
  22630. `-f, --force'
  22631.      Continue even if we get an sql-error.
  22632.  
  22633. `-e, --extended'
  22634.      If you are using this option with CHECK TABLE, it will ensure that
  22635.      the table is 100 percent consistent, but will take a long time.
  22636.  
  22637.      If you are using this option with REPAIR TABLE, it will run an
  22638.      extended repair on the table, which may not only take a long time
  22639.      to execute, but may produce a lot of garbage rows also!
  22640.  
  22641. `-h, --host=...'
  22642.      Connect to host.
  22643.  
  22644. `-m, --medium-check'
  22645.      Faster than extended-check, but only finds 99.99 percent of all
  22646.      errors. Should be good enough for most cases.
  22647.  
  22648. `-o, --optimize'
  22649.      Optimise table
  22650.  
  22651. `-p, --password[=...]'
  22652.      Password to use when connecting to server. If password is not given
  22653.      it's solicited on the tty.
  22654.  
  22655. `-P, --port=...'
  22656.      Port number to use for TCP/IP connections.
  22657.  
  22658. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22659.      To specify the connect protocol to use.  New in MySQL 4.1.
  22660.  
  22661. `-q, --quick'
  22662.      If you are using this option with CHECK TABLE, it prevents the
  22663.      check from scanning the rows to check for wrong links. This is the
  22664.      fastest check.
  22665.  
  22666.      If you are using this option with REPAIR TABLE, it will try to
  22667.      repair only the index tree. This is the fastest repair method for
  22668.      a table.
  22669.  
  22670. `-r, --repair'
  22671.      Can fix almost anything except unique keys that aren't unique.
  22672.  
  22673. `-s, --silent'
  22674.      Print only error messages.
  22675.  
  22676. `-S, --socket=...'
  22677.      Socket file to use for connection.
  22678.  
  22679. `--tables'
  22680.      Overrides option -databases (-B).
  22681.  
  22682. `-u, --user=#'
  22683.      User for login if not current user.
  22684.  
  22685. `-v, --verbose'
  22686.      Print info about the various stages.
  22687.  
  22688. `-V, --version'
  22689.      Output version information and exit.
  22690.  
  22691. `mysqldump', Dumping Table Structure and Data
  22692. ---------------------------------------------
  22693.  
  22694. Utility to dump a database or a collection of database for backup or for
  22695. transferring the data to another SQL server (not necessarily a MySQL
  22696. server).  The dump will contain SQL statements to create the table
  22697. and/or populate the table.
  22698.  
  22699. If you are doing a backup on the server, you should consider using the
  22700. `mysqlhotcopy' instead. *Note `mysqlhotcopy': mysqlhotcopy.
  22701.  
  22702.      shell> mysqldump [OPTIONS] database [tables]
  22703.      OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
  22704.      OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
  22705.  
  22706. If you don't give any tables or use the `--databases' or
  22707. `--all-databases', the whole database(s) will be dumped.
  22708.  
  22709. You can get a list of the options your version of `mysqldump' supports
  22710. by executing `mysqldump --help'.
  22711.  
  22712. Note that if you run `mysqldump' without `--quick' or `--opt',
  22713. `mysqldump' will load the whole result set into memory before dumping
  22714. the result.  This will probably be a problem if you are dumping a big
  22715. database.
  22716.  
  22717. Note that if you are using a new copy of the `mysqldump' program and
  22718. you are going to do a dump that will be read into a very old MySQL
  22719. server, you should not use the `--opt' or `-e' options.
  22720.  
  22721. `mysqldump' supports the following options:
  22722.  
  22723. `--add-locks'
  22724.      Add `LOCK TABLES' before and `UNLOCK TABLE' after each table dump.
  22725.      (To get faster inserts into MySQL.)
  22726.  
  22727. `--add-drop-table'
  22728.      Add a `drop table' before each create statement.
  22729.  
  22730. `-A, --all-databases'
  22731.      Dump all the databases. This will be same as `--databases' with all
  22732.      databases selected.
  22733.  
  22734. `-a, --all'
  22735.      Include all MySQL-specific create options.
  22736.  
  22737. `--allow-keywords'
  22738.      Allow creation of column names that are keywords.  This works by
  22739.      prefixing each column name with the table name.
  22740.  
  22741. `-c, --complete-insert'
  22742.      Use complete insert statements (with column names).
  22743.  
  22744. `-C, --compress'
  22745.      Compress all information between the client and the server if both
  22746.      support compression.
  22747.  
  22748. `-B, --databases'
  22749.      To dump several databases. Note the difference in usage. In this
  22750.      case no tables are given. All name arguments are regarded as
  22751.      database names.  `USE db_name;' will be included in the output
  22752.      before each new database.
  22753.  
  22754. `--delayed'
  22755.      Insert rows with the `INSERT DELAYED' command.
  22756.  
  22757. `-e, --extended-insert'
  22758.      Use the new multiline `INSERT' syntax. (Gives more compact and
  22759.      faster inserts statements.)
  22760.  
  22761. `-#, --debug[=option_string]'
  22762.      Trace usage of the program (for debugging).
  22763.  
  22764. `--help'
  22765.      Display a help message and exit.
  22766.  
  22767. `--fields-terminated-by=...'
  22768. `--fields-enclosed-by=...'
  22769. `--fields-optionally-enclosed-by=...'
  22770. `--fields-escaped-by=...'
  22771. `--lines-terminated-by=...'
  22772.      These options are used with the `-T' option and have the same
  22773.      meaning as the corresponding clauses for `LOAD DATA INFILE'.
  22774.      *Note `LOAD DATA': LOAD DATA.
  22775.  
  22776. `-F, --flush-logs'
  22777.      Flush log file in the MySQL server before starting the dump.
  22778.  
  22779. `-f, --force,'
  22780.      Continue even if we get an SQL error during a table dump.
  22781.  
  22782. `-h, --host=..'
  22783.      Dump data from the MySQL server on the named host. The default host
  22784.      is `localhost'.
  22785.  
  22786. `-l, --lock-tables.'
  22787.      Lock all tables before starting the dump.  The tables are locked
  22788.      with `READ LOCAL' to allow concurrent inserts in the case of
  22789.      `MyISAM' tables.
  22790.  
  22791.      Please note that when dumping multiple databases, `--lock-tables'
  22792.      will lock tables for each database separately. So using this
  22793.      option will not guarantee your tables will be logically consistent
  22794.      between databases.  Tables in different databases may be dumped in
  22795.      completely different states.
  22796.  
  22797. `-K, --disable-keys'
  22798.      `/*!40000 ALTER TABLE tb_name DISABLE KEYS */;' and `/*!40000
  22799.      ALTER TABLE tb_name ENABLE KEYS */;' will be put in the output.
  22800.      This will make loading the data into a MySQL 4.0 server faster as
  22801.      the indexes are created after all data are inserted.
  22802.  
  22803. `-n, --no-create-db'
  22804.      `CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be
  22805.      put in the output. The above line will be added otherwise, if a
  22806.      `--databases' or `--all-databases' option was given.
  22807.  
  22808. `-t, --no-create-info'
  22809.      Don't write table creation information (the `CREATE TABLE'
  22810.      statement).
  22811.  
  22812. `-d, --no-data'
  22813.      Don't write any row information for the table.  This is very
  22814.      useful if you just want to get a dump of the structure for a table!
  22815.  
  22816. `--opt'
  22817.      Same as `--quick --add-drop-table --add-locks --extended-insert
  22818.      --lock-tables'.  Should give you the fastest possible dump for
  22819.      reading into a MySQL server.
  22820.  
  22821. `-pyour_pass, --password[=your_pass]'
  22822.      The password to use when connecting to the server. If you specify
  22823.      no `=your_pass' part, `mysqldump' you will be prompted for a
  22824.      password.
  22825.  
  22826. `-P, --port=...'
  22827.      Port number to use for TCP/IP connections.
  22828.  
  22829. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22830.      To specify the connect protocol to use.  New in MySQL 4.1.
  22831.  
  22832. `-q, --quick'
  22833.      Don't buffer query, dump directly to stdout. Uses
  22834.      `mysql_use_result()' to do this.
  22835.  
  22836. `-Q, --quote-names'
  22837.      Quote table and column names within ``' characters.
  22838.  
  22839. `-r, --result-file=...'
  22840.      Direct output to a given file. This option should be used in MSDOS,
  22841.      because it prevents new line `\n' from being converted to `\n\r'
  22842.      (new line + carriage return).
  22843.  
  22844. `--single-transaction'
  22845.      This option issues a `BEGIN' SQL command before dumping data from
  22846.      server. It is mostly useful with `InnoDB' tables and
  22847.      `READ_COMMITTED' transaction isolation level, as in this mode it
  22848.      will dump the consistent state of the database at the time then
  22849.      `BEGIN' was issued without blocking any applications.
  22850.  
  22851.      When using this option you should keep in mind that only
  22852.      transactional tables will be dumped in a consistent state, for
  22853.      example, any `MyISAM' or `HEAP' tables dumped while using this
  22854.      option may still change state.
  22855.  
  22856.      The `--single-transaction' option was added in version 4.0.2.
  22857.      This option is mutually exclusive with the `--lock-tables' option
  22858.      as `LOCK TABLES' already commits a previous transaction internally.
  22859.  
  22860. `-S /path/to/socket, --socket=/path/to/socket'
  22861.      The socket file to use when connecting to `localhost' (which is the
  22862.      default host).
  22863.  
  22864. `--tables'
  22865.      Overrides option -databases (-B).
  22866.  
  22867. `-T, --tab=path-to-some-directory'
  22868.      Creates a `table_name.sql' file, that contains the SQL CREATE
  22869.      commands, and a `table_name.txt' file, that contains the data, for
  22870.      each give table.  The format of the `.txt' file is made according
  22871.      to the `--fields-xxx' and `--lines--xxx' options.  *Note*: This
  22872.      option only works if `mysqldump' is run on the same machine as the
  22873.      `mysqld' daemon, and the user/group that `mysqld' is running as
  22874.      (normally user `mysql', group `mysql') needs to have permission to
  22875.      create/write a file at the location you specify.
  22876.  
  22877. `-u user_name, --user=user_name'
  22878.      The MySQL user name to use when connecting to the server. The
  22879.      default value is your Unix login name.
  22880.  
  22881. `-O var=option, --set-variable var=option'
  22882.      Set the value of a variable.  The possible variables are listed
  22883.      below.  Please note that `--set-variable' is deprecated since
  22884.      MySQL 4.0, just use `--var=option' on its own.
  22885.  
  22886. `-v, --verbose'
  22887.      Verbose mode.  Print out more information on what the program does.
  22888.  
  22889. `-V, --version'
  22890.      Print version information and exit.
  22891.  
  22892. `-w, --where='where-condition''
  22893.      Dump only selected records. Note that quotes are mandatory:
  22894.           "--where=user='jimf'" "-wuserid>1" "-wuserid<1"
  22895.  
  22896. `-X, --xml'
  22897.      Dumps a database as well formed XML
  22898.  
  22899. `-x, --first-slave'
  22900.      Locks all tables across all databases.
  22901.  
  22902. `--master-data'
  22903.      Like `--first-slave', but also prints some `CHANGE MASTER TO'
  22904.      commands which will later make your slave start from the right
  22905.      position in the master's binlogs, if you have set up your slave
  22906.      using this SQL dump of the master.
  22907.  
  22908. `-O net_buffer_length=#, where # < 16M'
  22909.      When creating multi-row-insert statements (as with option
  22910.      `--extended-insert' or `--opt'), `mysqldump' will create rows up
  22911.      to `net_buffer_length' length. If you increase this variable, you
  22912.      should also ensure that the `max_allowed_packet' variable in the
  22913.      MySQL server is bigger than the `net_buffer_length'.
  22914.  
  22915. The most normal use of `mysqldump' is probably for making a backup of
  22916. whole databases. *Note Backup::.
  22917.  
  22918.      mysqldump --opt database > backup-file.sql
  22919.  
  22920. You can read this back into MySQL with:
  22921.  
  22922.      mysql database < backup-file.sql
  22923.  
  22924. or
  22925.  
  22926.      mysql -e "source /patch-to-backup/backup-file.sql" database
  22927.  
  22928. However, it's also very useful to populate another MySQL server with
  22929. information from a database:
  22930.  
  22931.      mysqldump --opt database | mysql ---host=remote-host -C database
  22932.  
  22933. It is possible to dump several databases with one command:
  22934.  
  22935.      mysqldump --databases database1 [database2 ...] > my_databases.sql
  22936.  
  22937. If all the databases are wanted, one can use:
  22938.  
  22939.      mysqldump --all-databases > all_databases.sql
  22940.  
  22941. `mysqlhotcopy', Copying MySQL Databases and Tables
  22942. --------------------------------------------------
  22943.  
  22944. `mysqlhotcopy' is a Perl script that uses `LOCK TABLES', `FLUSH TABLES'
  22945. and `cp' or `scp' to quickly make a backup of a database.  It's the
  22946. fastest way to make a backup of the database or single tables, but it
  22947. can only be run on the same machine where the database directories are.
  22948. `mysqlhotcopy' works only on Unix, and it works only for `MyISAM' and
  22949. `ISAM' tables.
  22950.  
  22951.      mysqlhotcopy db_name [/path/to/new_directory]
  22952.      
  22953.      mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
  22954.      
  22955.      mysqlhotcopy db_name./regex/
  22956.  
  22957. `mysqlhotcopy' supports the following options:
  22958.  
  22959. `-?, --help'
  22960.      Display a help screen and exit
  22961.  
  22962. `-u, --user=#'
  22963.      User for database login
  22964.  
  22965. `-p, --password=#'
  22966.      Password to use when connecting to server
  22967.  
  22968. `-P, --port=#'
  22969.      Port to use when connecting to local server
  22970.  
  22971. `-S, --socket=#'
  22972.      Socket to use when connecting to local server
  22973.  
  22974. `--allowold'
  22975.      Don't abort if target already exists (rename it _old)
  22976.  
  22977. `--keepold'
  22978.      Don't delete previous (now renamed) target when done
  22979.  
  22980. `--noindices'
  22981.      Don't include full index files in copy to make the backup smaller
  22982.      and faster The indexes can later be reconstructed with `myisamchk
  22983.      -rq.'.
  22984.  
  22985. `--method=#'
  22986.      Method for copy (`cp' or `scp').
  22987.  
  22988. `-q, --quiet'
  22989.      Be silent except for errors
  22990.  
  22991. `--debug'
  22992.      Enable debug
  22993.  
  22994. `-n, --dryrun'
  22995.      Report actions without doing them
  22996.  
  22997. `--regexp=#'
  22998.      Copy all databases with names matching regexp
  22999.  
  23000. `--suffix=#'
  23001.      Suffix for names of copied databases
  23002.  
  23003. `--checkpoint=#'
  23004.      Insert checkpoint entry into specified db.table
  23005.  
  23006. `--flushlog'
  23007.      Flush logs once all tables are locked.
  23008.  
  23009. `--tmpdir=#'
  23010.      Temporary directory (instead of /tmp).
  23011.  
  23012. You can use `perldoc mysqlhotcopy' to get more complete documentation
  23013. for `mysqlhotcopy'.
  23014.  
  23015. `mysqlhotcopy' reads the groups `[client]' and  `[mysqlhotcopy]' from
  23016. the option files.
  23017.  
  23018. To be able to execute `mysqlhotcopy' you need write access to the
  23019. backup directory, the `SELECT' privilege for the tables you are about to
  23020. copy and the MySQL `RELOAD' privilege (to be able to execute `FLUSH
  23021. TABLES').
  23022.  
  23023. `mysqlimport', Importing Data from Text Files
  23024. ---------------------------------------------
  23025.  
  23026. `mysqlimport' provides a command-line interface to the `LOAD DATA
  23027. INFILE' SQL statement.  Most options to `mysqlimport' correspond
  23028. directly to the same options to `LOAD DATA INFILE'.  *Note `LOAD DATA':
  23029. LOAD DATA.
  23030.  
  23031. `mysqlimport' is invoked like this:
  23032.  
  23033.      shell> mysqlimport [options] database textfile1 [textfile2 ...]
  23034.  
  23035. For each text file named on the command-line, `mysqlimport' strips any
  23036. extension from the filename and uses the result to determine which
  23037. table to import the file's contents into.  For example, files named
  23038. `patient.txt', `patient.text', and `patient' would all be imported into
  23039. a table named `patient'.
  23040.  
  23041. `mysqlimport' supports the following options:
  23042.  
  23043. `-c, --columns=...'
  23044.      This option takes a comma-separated list of field names as an
  23045.      argument.  The field list is used to create a proper `LOAD DATA
  23046.      INFILE' command, which is then passed to MySQL. *Note `LOAD DATA':
  23047.      LOAD DATA.
  23048.  
  23049. `-C, --compress'
  23050.      Compress all information between the client and the server if both
  23051.      support compression.
  23052.  
  23053. `-#, --debug[=option_string]'
  23054.      Trace usage of the program (for debugging).
  23055.  
  23056. `-d, --delete'
  23057.      Empty the table before importing the text file.
  23058.  
  23059. `--fields-terminated-by=...'
  23060. `--fields-enclosed-by=...'
  23061. `--fields-optionally-enclosed-by=...'
  23062. `--fields-escaped-by=...'
  23063. `--lines-terminated-by=...'
  23064.      These options have the same meaning as the corresponding clauses
  23065.      for `LOAD DATA INFILE'. *Note `LOAD DATA': LOAD DATA.
  23066.  
  23067. `-f, --force'
  23068.      Ignore errors.  For example, if a table for a text file doesn't
  23069.      exist, continue processing any remaining files.  Without `--force',
  23070.      `mysqlimport' exits if a table doesn't exist.
  23071.  
  23072. `--help'
  23073.      Display a help message and exit.
  23074.  
  23075. `-h host_name, --host=host_name'
  23076.      Import data to the MySQL server on the named host. The default host
  23077.      is `localhost'.
  23078.  
  23079. `-i, --ignore'
  23080.      See the description for the `--replace' option.
  23081.  
  23082. `-l, --lock-tables'
  23083.      Lock *all* tables for writing before processing any text files.
  23084.      This ensures that all tables are synchronised on the server.
  23085.  
  23086. `-L, --local'
  23087.      Read input files from the client.  By default, text files are
  23088.      assumed to be on the server if you connect to `localhost' (which
  23089.      is the default host).
  23090.  
  23091. `-pyour_pass, --password[=your_pass]'
  23092.      The password to use when connecting to the server. If you specify
  23093.      no `=your_pass' part, `mysqlimport' you will be prompted for a
  23094.      password.
  23095.  
  23096. `-P port_num, --port=port_num'
  23097.      TCP/IP port number to use for connection.
  23098.  
  23099. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  23100.      To specify the connect protocol to use.  New in MySQL 4.1.
  23101.  
  23102. `-r, --replace'
  23103.      The `--replace' and `--ignore' options control handling of input
  23104.      records that duplicate existing records on unique key values.  If
  23105.      you specify `--replace', new rows replace existing rows that have
  23106.      the same unique key value. If you specify `--ignore', input rows
  23107.      that duplicate an existing row on a unique key value are skipped.
  23108.      If you don't specify either option, an error occurs when a
  23109.      duplicate key value is found, and the rest of the text file is
  23110.      ignored.
  23111.  
  23112. `-s, --silent'
  23113.      Silent mode.  Write output only when errors occur.
  23114.  
  23115. `-S /path/to/socket, --socket=/path/to/socket'
  23116.      The socket file to use when connecting to `localhost' (which is the
  23117.      default host).
  23118.  
  23119. `-u user_name, --user=user_name'
  23120.      The MySQL user name to use when connecting to the server. The
  23121.      default value is your Unix login name.
  23122.  
  23123. `-v, --verbose'
  23124.      Verbose mode.  Print out more information what the program does.
  23125.  
  23126. `-V, --version'
  23127.      Print version information and exit.
  23128.  
  23129. Here is a sample run using `mysqlimport':
  23130.  
  23131.      $ mysql --version
  23132.      mysql  Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686)
  23133.      $ uname -a
  23134.      Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown
  23135.      $ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
  23136.      $ ed
  23137.      a
  23138.      100     Max Sydow
  23139.      101     Count Dracula
  23140.      .
  23141.      w imptest.txt
  23142.      32
  23143.      q
  23144.      $ od -c imptest.txt
  23145.      0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
  23146.      0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
  23147.      0000040
  23148.      $ mysqlimport --local test imptest.txt
  23149.      test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
  23150.      $ mysql -e 'SELECT * FROM imptest' test
  23151.      +------+---------------+
  23152.      | id   | n             |
  23153.      +------+---------------+
  23154.      |  100 | Max Sydow     |
  23155.      |  101 | Count Dracula |
  23156.      +------+---------------+
  23157.  
  23158. `mysqlshow', Showing Databases, Tables, and Columns
  23159. ---------------------------------------------------
  23160.  
  23161. `mysqlshow' can be used to quickly look at which databases exist, their
  23162. tables, and the table's columns.
  23163.  
  23164. With the `mysql' program you can get the same information with the
  23165. `SHOW' commands.  *Note SHOW::.
  23166.  
  23167. `mysqlshow' is invoked like this:
  23168.  
  23169.      shell> mysqlshow [OPTIONS] [database [table [column]]]
  23170.  
  23171.    * If no database is given, all matching databases are shown.
  23172.  
  23173.    * If no table is given, all matching tables in the database are
  23174.      shown.
  23175.  
  23176.    * If no column is given, all matching columns and column types in
  23177.      the table are shown.
  23178.  
  23179. Note that in newer MySQL versions, you only see those
  23180. database/tables/columns for which you have some privileges.
  23181.  
  23182. If the last argument contains a shell or SQL wildcard (`*', `?', `%' or
  23183. `_') then only what's matched by the wildcard is shown.  If a database
  23184. contains underscore(s), those should be escaped with backslash (some
  23185. Unix shells will require two), in order to get tables / columns
  23186. properly. '*' are converted into SQL '%' wildcard and '?' into SQL '_'
  23187. wildcard.  This may cause some confusion when you try to display the
  23188. columns for a table with a `_' as in this case `mysqlshow' only shows
  23189. you the table names that match the pattern.  This is easily fixed by
  23190. adding an extra `%' last on the command-line (as a separate argument).
  23191.  
  23192. `mysql_config', Get compile options for compiling clients
  23193. ---------------------------------------------------------
  23194.  
  23195. `mysql_config' provides you with useful information how to compile your
  23196. MySQL client and connect it to MySQL.
  23197.  
  23198. `mysql_config' supports the following options:
  23199.  
  23200. `--cflags'
  23201.      Compiler flags to find include files
  23202.  
  23203. `--libs'
  23204.      Libs and options required to link with the MySQL client library.
  23205.  
  23206. `--socket'
  23207.      The default socket name, defined when configuring MySQL.
  23208.  
  23209. `--port'
  23210.      The default port number, defined when configuring MySQL.
  23211.  
  23212. `--version'
  23213.      Version number and version for the MySQL distribution
  23214.  
  23215. `--libmysqld-libs'
  23216.      Libs and options required to link with the MySQL embedded server.
  23217.  
  23218. If you execute `mysql_config' without any options it will print all
  23219. options it supports plus the value of all options:
  23220.  
  23221.      shell> mysql_config
  23222.      sage: /usr/local/mysql/bin/mysql_config [OPTIONS]
  23223.      Options:
  23224.              --cflags         [-I'/usr/local/mysql/include/mysql']
  23225.              --libs           [-L'/usr/local/mysql/lib/mysql' -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto]
  23226.              --socket         [/tmp/mysql.sock]
  23227.              --port           [3306]
  23228.              --version        [4.0.8-gamma]
  23229.              --libmysqld-libs [ -L'/usr/local/mysql/lib/mysql' -lmysqld -lpthread -lz -lcrypt -lnsl -lm  -lpthread  -lrt]
  23230.  
  23231. You can use this to compile a MySQL client by as follows:
  23232.  
  23233.      CFG=/usr/local/mysql/bin/mysql_config
  23234.      sh -c "gcc -o progname `$CFG --cflags` progname.c `$CFG --libs`"
  23235.  
  23236. `perror', Explaining Error Codes
  23237. --------------------------------
  23238.  
  23239. For most system errors MySQL will, in addition to a internal text
  23240. message, also print the system error code in one of the following
  23241. styles: `message ... (errno: #)' or `message ... (Errcode: #)'.
  23242.  
  23243. You can find out what the error code means by either examining the
  23244. documentation for your system or use the `perror' utility.
  23245.  
  23246. `perror' prints a description for a system error code, or an MyISAM/ISAM
  23247. storage engine (table handler) error code.
  23248.  
  23249. `perror' is invoked like this:
  23250.  
  23251.      shell> perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  23252.      
  23253.      Example:
  23254.      
  23255.      shell> perror 13 64
  23256.      Error code  13:  Permission denied
  23257.      Error code  64:  Machine is not on the network
  23258.  
  23259. Note that the error messages are mostly system dependent!
  23260.  
  23261. How to Run SQL Commands from a Text File
  23262. ----------------------------------------
  23263.  
  23264. The `mysql' client typically is used interactively, like this:
  23265.  
  23266.      shell> mysql database
  23267.  
  23268. However, it's also possible to put your SQL commands in a file and tell
  23269. `mysql' to read its input from that file.  To do so, create a text file
  23270. `text_file' that contains the commands you wish to execute.  Then
  23271. invoke `mysql' as shown here:
  23272.  
  23273.      shell> mysql database < text_file
  23274.  
  23275. You can also start your text file with a `USE db_name' statement.  In
  23276. this case, it is unnecessary to specify the database name on the command
  23277. line:
  23278.  
  23279.      shell> mysql < text_file
  23280.  
  23281. If you are already running `mysql', you can execute an SQL script file
  23282. using the `source' command:
  23283.  
  23284.      mysql> source filename;
  23285.  
  23286. For more information about batch mode, *Note Batch mode::.
  23287.  
  23288. The MySQL Log Files
  23289. ===================
  23290.  
  23291. MySQL has several different log files that can help you find out what's
  23292. going on inside `mysqld':
  23293.  
  23294. *Log file*     *Description*
  23295. The error log  Problems encountering starting, running or stopping
  23296.                `mysqld'.
  23297. The isam log   Logs all changes to the ISAM tables. Used only for
  23298.                debugging the isam code.
  23299. The query log  Established connections and executed queries.
  23300. The update     Deprecated: Stores all statements that changes data
  23301. log            
  23302. The binary     Stores all statements that changes something. Used also
  23303. log            for replication
  23304. The slow log   Stores all queries that took more than `long_query_time'
  23305.                to execute or didn't use indexes.
  23306.  
  23307. All logs can be found in the `mysqld' data directory.  You can force
  23308. `mysqld' to reopen the log files (or in some cases switch to a new log)
  23309. by executing `FLUSH LOGS'. *Note FLUSH::.
  23310.  
  23311. The Error Log
  23312. -------------
  23313.  
  23314. The error log file contains information indicating when `mysqld' was
  23315. started and stopped and also any critical errors found when running.
  23316.  
  23317. If `mysqld' dies unexpectedly and `mysqld_safe' needs to restart
  23318. `mysqld', `mysqld_safe' will write a `restarted mysqld' row in this
  23319. file.  This log also holds a warning if `mysqld' notices a table that
  23320. needs to be automatically checked or repaired.
  23321.  
  23322. On some operating systems, the error log will contain a stack trace for
  23323. where `mysqld' died. This can be used to find out where `mysqld' died.
  23324. *Note Using stack trace::.
  23325.  
  23326. Beginning with MySQL 4.0.10 you can specify where `mysqld' stores the
  23327. error log file with the option `--log-error[=filename]'. If no file
  23328. name is given `mysqld' will use `mysql-data-dir/'hostname'.err' on Unix
  23329. and `\mysql\data\mysql.err' on Windows.  If you execute `flush logs'
  23330. the old file will be prefixed with `--old' and `mysqld' will create a
  23331. new empty log file.
  23332.  
  23333. In older MySQL versions the error log handling was done by
  23334. `mysqld_safe' which redirected the error file to `'hostname'.err'.  One
  23335. could change this file name with the option `--err-log=filename'.
  23336.  
  23337. If you don't specify `--log-error' or if you use the `--console' option
  23338. the errors will be written to stderr (the terminal).
  23339.  
  23340. On Windows, the output is always written to the `.err' file if
  23341. `--console' is not given.
  23342.  
  23343. The General Query Log
  23344. ---------------------
  23345.  
  23346. If you want to know what happens within `mysqld', you should start it
  23347. with `--log[=file]'.  This will log all connections and queries to the
  23348. log file (by default named `'hostname'.log').  This log can be very
  23349. useful when you suspect an error in a client and want to know exactly
  23350. what `mysqld' thought the client sent to it.
  23351.  
  23352. Older versions of the `mysql.server' script (from MySQL 3.23.4 to
  23353. 3.23.8) pass `safe_mysqld' a `--log' option (enable general query log).
  23354. If you need better performance when you start using MySQL in a
  23355. production environment, you can remove the `--log' option from
  23356. `mysql.server' or change it to `--log-bin'. *Note Binary log::.
  23357.  
  23358. The entries in this log are written as `mysqld' receives the questions.
  23359. This may be different from the order in which the statements are
  23360. executed.  This is in contrast to the update log and the binary log
  23361. which are written after the query is executed, but before any locks are
  23362. released.
  23363.  
  23364. The Update Log
  23365. --------------
  23366.  
  23367. *Note*: the update log is replaced by the binary log. *Note Binary
  23368. log::.  With this you can do anything that you can do with the update
  23369. log. *The update log will be removed in MySQL 5.0*.
  23370.  
  23371. When started with the `--log-update[=file_name]' option, `mysqld'
  23372. writes a log file containing all SQL commands that update data. If no
  23373. filename is given, it defaults to the name of the host machine. If a
  23374. filename is given, but it doesn't contain a path, the file is written
  23375. in the data directory. If `file_name' doesn't have an extension,
  23376. `mysqld' will create log file names like so: `file_name.###', where
  23377. `###' is a number that is incremented each time you execute `mysqladmin
  23378. refresh', execute `mysqladmin flush-logs', execute the `FLUSH LOGS'
  23379. statement, or restart the server.
  23380.  
  23381. *Note*: for the above scheme to work, you must not create your own
  23382. files with the same filename as the update log + some extensions that
  23383. may be regarded as a number, in the directory used by the update log!
  23384.  
  23385. If you use the `--log' or `-l' options, `mysqld' writes a general log
  23386. with a filename of `hostname.log', and restarts and refreshes do not
  23387. cause a new log file to be generated (although it is closed and
  23388. reopened). In this case you can copy it (on Unix) by doing:
  23389.  
  23390.      mv hostname.log hostname-old.log
  23391.      mysqladmin flush-logs
  23392.      cp hostname-old.log to-backup-directory
  23393.      rm hostname-old.log
  23394.  
  23395. Update logging is smart because it logs only statements that really
  23396. update data. So an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  23397. rows is not written to the log. It even skips `UPDATE' statements that
  23398. set a column to the value it already has.
  23399.  
  23400. The update logging is done immediately after a query completes but
  23401. before any locks are released or any commit is done. This ensures that
  23402. the log will be logged in the execution order.
  23403.  
  23404. If you want to update a database from update log files, you could do the
  23405. following (assuming your update logs have names of the form
  23406. `file_name.###'):
  23407.  
  23408.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  23409.  
  23410. `ls' is used to get all the log files in the right order.
  23411.  
  23412. This can be useful if you have to revert to backup files after a crash
  23413. and you want to redo the updates that occurred between the time of the
  23414. backup and the crash.
  23415.  
  23416. The Binary Log
  23417. --------------
  23418.  
  23419. The intention is that the binary log should replace the update log, so
  23420. we recommend you to switch to this log format as soon as possible! The
  23421. update log will be removed in MySQL 5.0.
  23422.  
  23423. The binary log contains all information that is available in the update
  23424. log in a more efficient format. It also contains information about how
  23425. long each query took that updated the database.  It doesn't contain
  23426. queries that don't modify any data.  If you want to log all queries
  23427. (for example to find a problem query) you should use the general query
  23428. log. *Note Query log::.
  23429.  
  23430. The binary log is also used when you are replicating a slave from a
  23431. master.  *Note Replication::.
  23432.  
  23433. When started with the `--log-bin[=file_name]' option, `mysqld' writes a
  23434. log file containing all SQL commands that update data. If no file name
  23435. is given, it defaults to the name of the host machine followed by
  23436. `-bin'. If file name is given, but it doesn't contain a path, the file
  23437. is written in the data directory.
  23438.  
  23439. If you supply an extension to `--log-bin=filename.extension', the
  23440. extension will be silenty removed.
  23441.  
  23442. To the binary log filename `mysqld' will append an extension that is a
  23443. number that is incremented each time you execute `mysqladmin refresh',
  23444. execute `mysqladmin flush-logs', execute the `FLUSH LOGS' statement or
  23445. restart the server. A new binary log will also automatically be created
  23446. when the current one's size reaches `max_binlog_size'. Note if you are
  23447. using transactions: a transaction is written in one chunk to the binary
  23448. log, hence it is never split between several binary logs. Therefore, if
  23449. you have big transactions, you may see binlogs bigger than
  23450. `max_binlog_size'.
  23451.  
  23452. You can delete all binary log files with the `RESET MASTER' command
  23453. (*note `RESET': RESET.), or only some of them with `PURGE MASTER LOGS'
  23454. (*note Replication SQL::).
  23455.  
  23456. You can use the following options to `mysqld' to affect what is logged
  23457. to the binary log:
  23458.  
  23459. *Option*                    *Description*
  23460. `binlog-do-db=database_name' Tells the master that it should log updates
  23461.                             to the binary log if the current database
  23462.                             (that is, the one selected by `USE')
  23463.                             database is 'database_name'. All others
  23464.                             databases which are not explicitly mentioned
  23465.                             are ignored.  Note that if you use this you
  23466.                             should ensure that you only do updates in
  23467.                             the current database.  (Example:
  23468.                             `binlog-do-db=some_database')
  23469.                             
  23470.                             Example of what does not work as you could
  23471.                             expect it: if the server is started with
  23472.                             `binlog-do-db=sales', and you do `USE
  23473.                             prices; UPDATE sales.january SET
  23474.                             amount=amount+1000;', this query will not be
  23475.                             written into the binary log.
  23476. `binlog-ignore-db=database_name' Tells the master that updates where the
  23477.                             current database (that is, the one selected
  23478.                             by `USE') is 'database_name' should not be
  23479.                             stored in the binary log.  Note that if you
  23480.                             use this you should ensure that you only do
  23481.                             updates in the current database.  (Example:
  23482.                             `binlog-ignore-db=some_database')
  23483.                             
  23484.                             Example of what does not work as you could
  23485.                             expect it: if the server is started with
  23486.                             `binlog-ignore-db=sales', and you do `USE
  23487.                             prices; UPDATE sales.january SET
  23488.                             amount=amount+1000;', this query will be
  23489.                             written into the binary log.
  23490.  
  23491. To be able to know which different binary log files have been used,
  23492. `mysqld' will also create a binary log index file that contains the
  23493. name of all used binary log files. By default this has the same name as
  23494. the binary log file, with the extension `'.index''.  You can change the
  23495. name of the binary log index file with the `--log-bin-index=[filename]'
  23496. option.  You should not manually edit this file while `mysqld' is
  23497. running; doing this would confuse `mysqld'.
  23498.  
  23499. If you are using replication, you should not delete old binary log
  23500. files until you are sure that no slave will ever need to use them.  One
  23501. way to do this is to do `mysqladmin flush-logs' once a day and then
  23502. remove any logs that are more than 3 days old. You can remove them
  23503. manually, or preferably using `PURGE MASTER LOGS' (*note Replication
  23504. SQL::) which will also safely update the binary log index file for you
  23505. (and which can take a date argument since MySQL 4.1)
  23506.  
  23507. A connexion with the `SUPER' privilege can disable the binary logging
  23508. of its queries using `SET SQL_LOG_BIN=0'. *Note Replication SQL::.
  23509.  
  23510. You can examine the binary log file with the `mysqlbinlog' command.
  23511. For example, you can update a MySQL server from the binary log as
  23512. follows:
  23513.  
  23514.      shell> mysqlbinlog log-file | mysql -h server_name
  23515.  
  23516. You can also use the `mysqlbinlog' program to read the binary log
  23517. directly from a remote MySQL server!
  23518.  
  23519. `mysqlbinlog --help' will give you more information of how to use this
  23520. program!
  23521.  
  23522. If you are using `BEGIN [WORK]' or `SET AUTOCOMMIT=0', you must use the
  23523. MySQL binary log for backups instead of the old update log, which will
  23524. be removed in MySQL 5.0.
  23525.  
  23526. The binary logging is done immediately after a query completes but
  23527. before any locks are released or any commit is done. This ensures that
  23528. the log will be logged in the execution order.
  23529.  
  23530. Updates to non-transactional tables are stored in the binary log
  23531. immediately after execution.  For transactional tables such as `BDB' or
  23532. `InnoDB' tables, all updates (`UPDATE', `DELETE' or `INSERT') that
  23533. change tables are cached until a `COMMIT' command is sent to the
  23534. server. At this point `mysqld' writes the whole transaction to the
  23535. binary log before the `COMMIT' is executed.  Every thread will, on
  23536. start, allocate a buffer of `binlog_cache_size' to buffer queries.  If
  23537. a query is bigger than this, the thread will open a temporary file to
  23538. store the transaction.  The temporary file will be deleted when the
  23539. thread ends.
  23540.  
  23541. The `max_binlog_cache_size' (default 4G) can be used to restrict the
  23542. total size used to cache a multi-query transaction.  If a transaction is
  23543. bigger than this it will fail and roll back.
  23544.  
  23545. If you are using the update or binary log, concurrent inserts will be
  23546. converted to normal inserts when using `CREATE ... SELECT' or `INSERT
  23547. ... SELECT'.  This is to ensure that you can recreate an exact copy of
  23548. your tables by applying the log on a backup.
  23549.  
  23550. The Slow Query Log
  23551. ------------------
  23552.  
  23553. When started with the `--log-slow-queries[=file_name]' option, `mysqld'
  23554. writes a log file containing all SQL commands that took more than
  23555. `long_query_time' to execute. The time to get the initial table locks
  23556. are not counted as execution time.
  23557.  
  23558. The slow query log is logged after the query is executed and after all
  23559. locks has been released. This may be different from the order in which
  23560. the statements are executed.
  23561.  
  23562. If no file name is given, it defaults to the name of the host machine
  23563. suffixed with `-slow.log'. If a filename is given, but doesn't contain
  23564. a path, the file is written in the data directory.
  23565.  
  23566. The slow query log can be used to find queries that take a long time to
  23567. execute and are thus candidates for optimisation. With a large log, that
  23568. can become a difficult task. You can pipe the slow query log through the
  23569. `mysqldumpslow' command to get a summary of the queries which appear in
  23570. the log.
  23571.  
  23572. You are using `--log-long-format' then also queries that are not using
  23573. indexes are printed. *Note Command-line options::.
  23574.  
  23575. Log File Maintenance
  23576. --------------------
  23577.  
  23578. The MySQL Server can create a number of different log files, which make
  23579. it easy to see what is going on. *Note Log Files::. One must however
  23580. regularly clean up these files, to ensure that the logs don't take up
  23581. too much disk space.
  23582.  
  23583. When using MySQL with log files, you will, from time to time, want to
  23584. remove/backup old log files and tell MySQL to start logging on new
  23585. files.  *Note Backup::.
  23586.  
  23587. On a Linux (`Red Hat') installation, you can use the `mysql-log-rotate'
  23588. script for this. If you installed MySQL from an RPM distribution, the
  23589. script should have been installed automatically.  Note that you should
  23590. be careful with this if you are using the log for replication!
  23591.  
  23592. On other systems you must install a short script yourself that you
  23593. start from `cron' to handle log files.
  23594.  
  23595. You can force MySQL to start using new log files by using `mysqladmin
  23596. flush-logs' or by using the SQL command `FLUSH LOGS'.  If you are using
  23597. MySQL Version 3.21 you must use `mysqladmin refresh'.
  23598.  
  23599. The above command does the following:
  23600.  
  23601.    * If standard logging (`--log') or slow query logging
  23602.      (`--log-slow-queries') is used, closes and reopens the log file
  23603.      (`mysql.log' and ``hostname`-slow.log' as default).
  23604.  
  23605.    * If update logging (`--log-update') is used, closes the update log
  23606.      and opens a new log file with a higher sequence number.
  23607.  
  23608. If you are using only an update log, you only have to flush the logs
  23609. and then move away the old update log files to a backup.  If you are
  23610. using the normal logging, you can do something like:
  23611.  
  23612.      shell> cd mysql-data-directory
  23613.      shell> mv mysql.log mysql.old
  23614.      shell> mysqladmin flush-logs
  23615.  
  23616. and then take a backup and remove `mysql.old'.
  23617.  
  23618. Replication in MySQL
  23619. ====================
  23620.  
  23621. This section describes the various replication features in MySQL.  It
  23622. serves as a reference to the options available with replication.  You
  23623. will be introduced to replication and learn how to implement it.
  23624. Toward the end, there are some frequently asked questions and
  23625. descriptions of problems and how to solve them.
  23626.  
  23627. We suggest that you visit our website at `http://www.mysql.com/' often
  23628. and read updates to this section. Replication is constantly being
  23629. improved, and we update the manual frequently with the most current
  23630. information.
  23631.  
  23632. Introduction
  23633. ------------
  23634.  
  23635. One-way replication can be used is to increase both robustness and
  23636. speed. For robustness you can have two systems and can switch to the
  23637. backup if you have problems with the master. The extra speed is
  23638. achieved by sending a part of the non-updating queries to the replica
  23639. server. Of course this only works if non-updating queries dominate, but
  23640. that is the normal case.
  23641.  
  23642. Starting in Version 3.23.15, MySQL supports one-way replication
  23643. internally. One server acts as the master, while the other acts as the
  23644. slave. Note that one server could play the roles of master in one pair
  23645. and slave in the other. The master server keeps a binary log of updates
  23646. (*note Binary log::) and an index file to binary logs to keep track of
  23647. log rotation.  The slave, upon connecting, informs the master where it
  23648. left off since the last successfully propagated update, catches up on
  23649. the updates, and then blocks and waits for the master to notify it of
  23650. the new updates.
  23651.  
  23652. Note that if you are using replicating  all updates to the tables you
  23653. replicate should be done through the master, unless you are always
  23654. careful of avoiding conflicts between updates which users issue on the
  23655. master and those which users issue on the slave.
  23656.  
  23657. Another benefit of using replication is that one can get non-disturbing
  23658. backups of the system by doing a backup on a slave instead of doing it
  23659. on the master. *Note Backup::.
  23660.  
  23661. Replication Implementation Overview
  23662. -----------------------------------
  23663.  
  23664. MySQL replication is based on the server keeping track of all changes
  23665. to your database (updates, deletes, etc) in the binary log (*note
  23666. Binary log::) and the slave server(s) reading the saved queries from
  23667. the master server's binary log so that the slave can execute the same
  23668. queries on its copy of the data.
  23669.  
  23670. It is *very important* to realise that the binary log is simply a
  23671. record starting from a fixed point in time (the moment you enable binary
  23672. logging). Any slaves which you set up will need copies of the data from
  23673. your master as it existed the moment that you enabled binary logging on
  23674. the master. If you start your slaves with data that doesn't agree with
  23675. what was on the master *when the binary log was started*, your slaves
  23676. may fail.
  23677.  
  23678. Please see the following table for an indication of master-slave
  23679. compatibility between different versions. With regard to version 4.0,
  23680. we recommend using same version on both sides.
  23681.  
  23682.                     *Master*    *Master**Master**Master*
  23683.                     *3.23.33    *4.0.0* *4.0.1* *4.0.3 and
  23684.                     and up*                     up*
  23685. *Slave* *3.23.33    yes         no      no      no
  23686.         and up*                                 
  23687. *Slave* *4.0.0*     no          yes     no      no
  23688. *Slave* *4.0.1*     yes         no      yes     no
  23689. *Slave* *4.0.3 and  yes         no      no      yes
  23690.         up*                                     
  23691.  
  23692. *Note*: MySQL Version 4.0.2 is not recommended for replication. As a
  23693. general rule, it's always recommended to use recent MySQL versions for
  23694. replication.
  23695.  
  23696. Note that when you upgrade a master from MySQL 3.23 to MySQL 4.0 (or
  23697. 4.1) you should not restart replication using old 3.23 binary logs,
  23698. because this will unfortunately confuse the 4.0 slave. The upgrade can
  23699. be safely done this way:
  23700.    * Block all updates on the master (`FLUSH TABLES WITH READ LOCK').
  23701.  
  23702.    * Wait until all the slaves have caught up all changes from the
  23703.      master (use `SHOW MASTER STATUS' on the master, and `SELECT
  23704.      MASTER_POS_WAIT()' on the slaves). Then run `SLAVE STOP' and
  23705.      `RESET SLAVE' on the slaves.
  23706.  
  23707.    * Shutdown MySQL on the master and slaves, upgrade the master and
  23708.      slaves to MySQL 4.0. Restart the master and slaves, and issue
  23709.      `CHANGE MASTER TO' commands on the slaves, unless the slaves
  23710.      already have the identification of the master in their `my.cnf'
  23711.      files.
  23712.  
  23713. Starting from 4.0.0, one can use `LOAD DATA FROM MASTER' to set up a
  23714. slave. Be aware that `LOAD DATA FROM MASTER' currently works only if
  23715. all the tables on the master are `MyISAM' type, and will acquire a
  23716. global read lock, so no writes are possible while the tables are being
  23717. transferred from the master. When we implement hot lock-free table
  23718. backup (in MySQL 5.0), this global read lock will no longer be
  23719. necessary.
  23720.  
  23721. Due to the above limitation, we recommend that at this point  you use
  23722. `LOAD DATA FROM MASTER' only if the dataset on the master is relatively
  23723. small, or if a prolonged read lock on the master is acceptable. While
  23724. the actual speed of `LOAD DATA FROM MASTER' may vary from system to
  23725. system, a good rule for a rough estimate of how long it is going to
  23726. take is 1 second per 1 MB of the datafile. You will get close to the
  23727. estimate if both master and slave are equivalent to 700 MHz Pentium,
  23728. are connected through 100 MBit/s network, and your index file is about
  23729. half the size of your data file. Of course, this is only a rough order
  23730. of magnitude estimate.
  23731.  
  23732. Once a slave is properly configured and running, it will simply connect
  23733. to the master and wait for updates to process. If the master goes away
  23734. or the slave loses connectivity with your master, it will keep trying to
  23735. connect every `master-connect-retry' seconds until it is able to
  23736. reconnect and resume listening for updates.
  23737.  
  23738. Each slave keeps track of where it left off. The master server has no
  23739. knowledge of how many slaves there are or which ones are up-to-date at
  23740. any given time.
  23741.  
  23742. Replication Implementation Details
  23743. ----------------------------------
  23744.  
  23745. Three threads are involved in replication : one on the master and two
  23746. on the slave.  When `START SLAVE' is issued, the I/O thread is created
  23747. on the slave. It connects to the master and asks it to send its
  23748. binlogs. Then one thread (named `Binlog_dump' in `SHOW PROCESSLIST' on
  23749. the master) is created on the master to send these binlogs. The I/O
  23750. thread reads what `Binlog_dump' sends and simply copies it to some local
  23751. files in the slave's data directory called relay logs.  The last
  23752. thread, the SQL thread, is created on the slave; it reads the relay
  23753. logs and executes the queries it contains.
  23754.  
  23755. Here is how the three threads show up in `SHOW PROCESSLIST':
  23756.  
  23757.      | 76 | root | localhost | NULL | Binlog Dump |   42 | Slave: waiting for binlog update | NULL             |
  23758.  
  23759.      |  7 | system user |           | NULL | Connect |    3 | Reading master update            | NULL             |
  23760.      |  8 | system user |           | NULL | Connect |    3 | Slave: waiting for binlog update | NULL             |
  23761.  
  23762. Here thread 76 is on the master. Thread 7 is the I/O thread on the
  23763. slave.  Thread 8 the SQL thread on the slave; note that the value in the
  23764. `Time' column can tell how late the slave is compared to the master
  23765. (*note Replication FAQ::).
  23766.  
  23767. Before MySQL 4.0.2, the I/O and SQL threads were one. The advantage
  23768. brought by the two separate threads is that it makes the reading job
  23769. and the execution job independant, thus the reading job is not slowed
  23770. down by the execution job. As soon as the slave starts, even if it has
  23771. not been running for a while, the I/O thread can quickly fetch all the
  23772. binlogs, while the SQL thread lags far behind and may take hours to
  23773. catch. If the slave stops, though it has not executed everything yet,
  23774. at least it has fetched everything, so binlogs can be purged on the
  23775. master, as a safe copy is locally stored on the slave for future use.
  23776.  
  23777. Relay logs are by default named as the hostname followed by
  23778. `-relay-bin' plus a numeric extension. A `-relay-bin.index' file
  23779. contains the list of all relay logs currently in use.  By default these
  23780. files are in the slave's data directory.  Relay logs have the same
  23781. format than binary logs, so they can be read with `mysqlbinlog'.  A
  23782. relay log is automatically deleted by the SQL thread as soon as it no
  23783. longer needs it (that is, as soon as it has executed all its events).
  23784. The user has no command to delete relay logs as the SQL thread does the
  23785. job. However, from MySQL 4.0.14, `FLUSH LOGS' rotates relay logs, which
  23786. will influence deletion by the SQL thread.  A new relay log is created
  23787. when the I/O thread starts, or when the size of the current relay log
  23788. exceeds `max_relay_log_size' (or if this variable is 0 or the slave is
  23789. older than MySQL 4.0.14, when the size exceeds `max_binlog_size'), or
  23790. when `FLUSH LOGS' is issued (from version 4.0.14).
  23791.  
  23792. Replication also creates two small files in the data directory: these
  23793. files are the disk images of the output of `SHOW SLAVE STATUS' (*note
  23794. Replication SQL:: for a description of this command); but as disk
  23795. images they survive slave's shutdown; this way at restart time the slave
  23796. still knows his master and where the slave is in the master's binlogs,
  23797. and where it is in its own relay logs.
  23798.  
  23799.    * `master.info' is updated by the I/O thread.  Here is a
  23800.      correspondance between the file's rows and the columns displayed
  23801.      by `SHOW SLAVE STATUS':
  23802.  
  23803.      *Line#**Description*
  23804.      1   `Master_Log_File'
  23805.      2   `Read_Master_Log_Pos'
  23806.      3   `Master_Host'
  23807.      4   `Master_User'
  23808.      5   Password (not in `SHOW SLAVE STATUS')
  23809.      6   `Master_Port'
  23810.      7   `Connect_Retry'
  23811.  
  23812.    * `relay-log.info' is updated by the SQL thread.  Here is a
  23813.      correspondance between the file's rows and the columns displayed
  23814.      by `SHOW SLAVE STATUS':
  23815.  
  23816.      *Line#**Description*
  23817.      1   `Relay_Log_File'
  23818.      2   `Relay_Log_Pos'
  23819.      3   `Relay_Master_Log_File'
  23820.      4   `Exec_master_log_pos'
  23821.  
  23822.  
  23823. How To Set Up Replication
  23824. -------------------------
  23825.  
  23826. Here is a quick description of how to set up complete replication on
  23827. your current MySQL server. It assumes you want to replicate all your
  23828. databases and have not configured replication before. You will need to
  23829. shutdown your master server briefly to complete the steps outlined here.
  23830.  
  23831. While this method is the most straightforward way to set up a slave, it
  23832. is not the only one. For example, if you already have a snapshot of the
  23833. master, and the master already has server id set and binary logging
  23834. enabled, you can set up a slave without shutting the master down or
  23835. even blocking the updates.  For more details, please see *Note
  23836. Replication FAQ::.
  23837.  
  23838. If you want to be able to administrate a MySQL replication setup, we
  23839. suggest that you read this entire chapter through and try all commands
  23840. mentioned in *Note Replication SQL::. You should also familiarise
  23841. yourself with replication startup options in `my.cnf' in *Note
  23842. Replication Options::.
  23843.  
  23844.   1. Make sure you have a recent version of MySQL installed on the
  23845.      master and slave(s), and that these versions match with the above
  23846.      yes/no array.
  23847.  
  23848.      Please, do not report bugs until you have verified that the
  23849.      problem is present in the latest release.
  23850.  
  23851.   2. Set up a replication user on the master with the `FILE' (in MySQL
  23852.      versions older than 4.0.2) or `REPLICATION SLAVE' privilege in
  23853.      newer MySQL versions.  You must also have given this user
  23854.      permission to connect from all the slaves. If the user is only
  23855.      doing replication (which is recommended), you don't need to grant
  23856.      any additional privileges.
  23857.  
  23858.      For example, to create a user named `repl' which can access your
  23859.      master from any host, you might use this command:
  23860.  
  23861.           mysql> GRANT FILE ON *.* TO repl@"%" IDENTIFIED BY '<password>'; # master < 4.0.2
  23862.  
  23863.           mysql> GRANT REPLICATION SLAVE ON *.* TO repl@"%" IDENTIFIED BY '<password>'; # master >= 4.0.2
  23864.  
  23865.      If you plan to use the `LOAD TABLE FROM MASTER' or `LOAD DATA FROM
  23866.      MASTER' commands, you will also need to grant the `REPLICATION
  23867.      CLIENT' (or `SUPER' if the master is older than 4.0.13) and
  23868.      `RELOAD' privileges on the master to the above user.
  23869.  
  23870.   3. If you are using MyISAM tables, flush all the tables and block
  23871.      write queries by executing `FLUSH TABLES WITH READ LOCK' command.
  23872.  
  23873.           mysql> FLUSH TABLES WITH READ LOCK;
  23874.  
  23875.      and then take a snapshot of the data on your master server.
  23876.  
  23877.      The easiest way to do this is to simply use an archiving program
  23878.      (`tar' on Unix, `PowerArchiver', `WinRAR', `WinZIP' or any similar
  23879.      software on Windows) to produce an archive of the databases in
  23880.      your master's data directory.  Include all the databases you want
  23881.      to replicate.
  23882.  
  23883.           tar -cvf /tmp/mysql-snapshot.tar /path/to/data-dir
  23884.  
  23885.      If you want to replicate only a database called `this_db', you can
  23886.      do just this:
  23887.  
  23888.           tar -cvf /tmp/mysql-snapshot.tar /path/to/data-dir/this_db
  23889.  
  23890.      You may not want to replicate the `mysql' database, then you can
  23891.      exclude it from the archive too. Into the archive you needn't copy
  23892.      the master's binary logs, error log, `master.info' /
  23893.      `relay-log.info' / relay logs (if the master is itself a slave of
  23894.      another machine). You can exclude all this from the archive.
  23895.  
  23896.      After or during the process of taking a snapshot, read the value
  23897.      of the current binary log name and the offset on the master:
  23898.  
  23899.           mysql > SHOW MASTER STATUS;
  23900.           +---------------+----------+--------------+-------------------------------+
  23901.           | File          | Position | Binlog_do_db | Binlog_ignore_db              |
  23902.           +---------------+----------+--------------+-------------------------------+
  23903.           | mysql-bin.003 | 73       | test,bar     | foo,manual,sasha_likes_to_run |
  23904.           +---------------+----------+--------------+-------------------------------+
  23905.           1 row in set (0.06 sec)
  23906.  
  23907.      The `File' column shows the name of the log,  while `Position'
  23908.      shows the offset. In the above example, the binary log value is
  23909.      `mysql-bin.003' and the offset is 73. Record the values - you will
  23910.      need to use them later when you are setting up the slave.
  23911.  
  23912.      Once you have taken the snapshot and recorded the log name and
  23913.      offset, you can re-enable write activity on the master:
  23914.  
  23915.           mysql> UNLOCK TABLES;
  23916.  
  23917.      If you are using InnoDB tables, ideally you should use the InnoDB
  23918.      Hot Backup tool that is available to those who purchase MySQL
  23919.      commercial licenses, support, or the backup tool itself. It will
  23920.      take a consistent snapshot without acquiring any locks on the
  23921.      master server, and record the log name and offset corresponding to
  23922.      the snapshot to be later used on the slave. More information about
  23923.      the tool is avalaible at `http://www.innodb.com/hotbackup.html'.
  23924.  
  23925.      Without the hot backup tool, the quickest way to take a snapshot
  23926.      of  InnoDB tables is to shut the master server down and copy the
  23927.      InnoDB data files and logs, and the table definition files
  23928.      (`.frm'). To record the current log file name and offset, you
  23929.      should do the following before you shut down the server:
  23930.  
  23931.           mysql> FLUSH TABLES WITH READ LOCK;
  23932.           mysql> SHOW MASTER STATUS;
  23933.  
  23934.      And then record the log name and the offset from the output of
  23935.      `SHOW MASTER STATUS' as was shown earlier. Once you have recorded
  23936.      the log name and the offset, shut the server down without
  23937.      unlocking the tables to make sure it goes down with the snapshot
  23938.      corresponding to the current log file and offset:
  23939.  
  23940.           shell> mysqladmin -uroot shutdown
  23941.  
  23942.      An alternative for both MyISAM and InnoDB tables is taking an SQL
  23943.      dump of the master instead of a binary copy like above; for this
  23944.      you can use `mysqldump --master-data' on your master and later run
  23945.      this SQL dump into your slave. This is however slower than doing a
  23946.      binary copy.
  23947.  
  23948.      If the master has been previously running without `log-bin'
  23949.      enabled, the values of log name and position displayed by `SHOW
  23950.      MASTER STATUS' or `mysqldump' will be empty. In that case, record
  23951.      empty string (") for the log name, and 4 for the offset.
  23952.  
  23953.   4. Make sure that `my.cnf' on the master has  `log-bin' if it is not
  23954.      there already and `server-id=unique number' in the `[mysqld]'
  23955.      section. If those options are not present, add them and restart
  23956.      the server.  It is very important that the id of the slave is
  23957.      different from the id of the master. Think of `server-id' as
  23958.      something similar to the IP address - it uniquely identifies the
  23959.      server instance in the community of replication partners.
  23960.  
  23961.           [mysqld]
  23962.           log-bin
  23963.           server-id=1
  23964.  
  23965.   5. Stop the slave server(s). Add the following to `my.cnf' on the
  23966.      slave(s):
  23967.  
  23968.           server-id=<some unique number between 1 and 2^32-1 that is different from
  23969.            that of the master>
  23970.  
  23971.      replacing the values in <> with what is relevant to your system.
  23972.  
  23973.      `server-id' must be different for each server participating in
  23974.      replication.  If you don't specify a server-id, it will be set to
  23975.      1 if you have not defined `master-host', else it will be set to 2.
  23976.      Note that in the case of `server-id' omission the master will
  23977.      refuse connections from all slaves, and the slave will refuse to
  23978.      connect to a master. Thus, omitting `server-id' is only good for
  23979.      backup with a binary log.
  23980.  
  23981.   6. Start the slave server(s). If it has been replicating previously,
  23982.      start the slave server with option `skip-slave-start'.  You may
  23983.      want to start the slave server with option `log-warnings', this
  23984.      way you will get more messages about network/connection problems
  23985.      for example.
  23986.  
  23987.   7. Copy the snapshot data into your data directory on your slave(s)
  23988.      (or execute the output of the above `mysqldump' into the `mysql').
  23989.      Make sure that the privileges on the files and directories are
  23990.      correct. The user which MySQL runs as needs to be able to read and
  23991.      write to them, just as on the master.
  23992.  
  23993.   8. Execute the following command on the slave(s):
  23994.  
  23995.           mysql> CHANGE MASTER TO MASTER_HOST='<master host name>',
  23996.            MASTER_USER='<replication user name>',
  23997.            MASTER_PASSWORD='<replication password>',
  23998.            MASTER_LOG_FILE='<recorded log file name>',
  23999.            MASTER_LOG_POS=<recorded log offset>;
  24000.  
  24001.      replacing the values in <> with the actual values relevant to your
  24002.      system.
  24003.  
  24004.      The maximum string length for the above variables are:
  24005.  
  24006.      MASTER_HOST                                            60
  24007.      MASTER_USER                                            16
  24008.      MASTER_PASSWORD                                        32
  24009.      MASTER_LOG_FILE                                        255
  24010.  
  24011.   9. Start the slave threads:
  24012.  
  24013.           mysql> START SLAVE;
  24014.  
  24015.  
  24016. After you have done the above, the slave(s) should connect to the master
  24017. and catch up on any updates which happened since the snapshot was taken.
  24018.  
  24019. If you have forgotten to set `server-id' for the slave you will get the
  24020. following error in the error log file:
  24021.  
  24022.      Warning: one should set server_id to a non-0 value if master_host is set.
  24023.      The server will not act as a slave.
  24024.  
  24025. If you have forgotten to do this for the master, the slaves will not be
  24026. able to connect to the master.
  24027.  
  24028. If a slave is not able to replicate for any reason, you will find error
  24029. messages in the error log on the slave.
  24030.  
  24031. Once a slave is replicating, you will find a file called `master.info'
  24032. and one called `relay-log.info' in the data directory. These two files
  24033. are used by the slave to keep track of how much of the master's binary
  24034. log it has processed. *Do not* remove or edit these files, unless you
  24035. really know what you are doing. Even in that case, it is preferred that
  24036. you use `CHANGE MASTER TO' command.  *NOTE*: the content of
  24037. `master.info' overrides some options specified on the command-line or
  24038. in `my.cnf' (*note Replication Options:: for more details).
  24039.  
  24040. Now that you have a snapshot, you can use it to set up other slaves. To
  24041. do so, follow the slave portion of the procedure described above. You
  24042. do not need to take another snapshot of the master.
  24043.  
  24044. Replication Features and Known Problems
  24045. ---------------------------------------
  24046.  
  24047. Here is an explanation of what is supported and what is not:
  24048.  
  24049.    * Replication will be done correctly with `AUTO_INCREMENT',
  24050.      `LAST_INSERT_ID()', and `TIMESTAMP' values.
  24051.  
  24052.    * `USER()' and `LOAD_FILE()' functions are replicated without
  24053.      changes and will thus not work reliably on the slave. This is also
  24054.      true for `CONNECTION_ID()' in slave versions strictly older than
  24055.      4.1.1.  The *new* `PASSWORD()' function in MySQL 4.1, is well
  24056.      replicated since 4.1.1 masters ; your slaves must be 4.1.0 or above
  24057.      to replicate it. If you have older slaves and need to replicate
  24058.      `PASSWORD()' from your 4.1.x master, you should start your master
  24059.      with option `--old-password'.
  24060.  
  24061.    * `sql_mode', `FOREIGN_KEY_CHECKS' and `table_type' variables are
  24062.      not replicated.
  24063.  
  24064.    * You have to use the same character set (`--default-character-set')
  24065.      on the master and the slave. If not, you may get duplicate key
  24066.      errors on the slave, because a key that is regarded as unique in
  24067.      the master character set may not be unique in the slave character
  24068.      set.
  24069.  
  24070.    * If you are using transaction tables on the master and not
  24071.      transactional tables (for the same tables) on the slave, you will
  24072.      get problems if the slave is stopped in the middle of a
  24073.      `BEGIN/COMMIT' block, as the slave will later start at the
  24074.      beginning of the `BEGIN' block.  This issue is on our TODO and
  24075.      will be fixed in the near future.
  24076.  
  24077.    * Update queries that use user variables are badly replicated in
  24078.      3.23 and 4.0. This is fixed in 4.1. Note that user variables' names
  24079.      are case insensitive starting from version 5.0, so you should take
  24080.      this into account when setting up replication between 5.0 and a
  24081.      previous version.
  24082.  
  24083.    * The slave cannot connect to the master using SSL yet.
  24084.  
  24085.    * There is a theoretical chance (though we have never heard of it
  24086.      actually occurring) that the data on the master and slave become
  24087.      different if a query is designed in such a way that the data
  24088.      modification is non-deterministic, that is, left to the will of
  24089.      the query optimiser (which generally is not good practice!). For a
  24090.      detailed explanation, see *Note Open bugs::.
  24091.  
  24092.    * Strictly before MySQL 4.1.1, `FLUSH', `ANALYZE', `OPTIMIZE',
  24093.      `REPAIR' commands are not stored in the binary log and are because
  24094.      of this not replicated to the slaves. This is not normally a
  24095.      problem as these commands don't change anything. This does however
  24096.      mean that if you update the MySQL privilege tables directly
  24097.      without using the `GRANT' statement and you replicate the `mysql'
  24098.      privilege database, you must do a `FLUSH PRIVILEGES' on your
  24099.      slaves to put the new privileges into effect. Also if you use
  24100.      `FLUSH TABLES' when renaming a `MyISAM' table involved in a
  24101.      `MERGE' table, you will have to issue `FLUSH TABLES' manually on
  24102.      the slave.  Since MySQL 4.1.1, these commands are written to the
  24103.      binary log (except `FLUSH LOGS', `FLUSH MASTER', `FLUSH SLAVE',
  24104.      `FLUSH TABLES WITH READ LOCK') unless you specify
  24105.      `NO_WRITE_TO_BINLOG' (or its alias `LOCAL') (for a syntax example,
  24106.      *note `FLUSH': FLUSH.).
  24107.  
  24108.    * MySQL only supports one master and many slaves. Later we will add
  24109.      a voting algorithm to automatically change master if something goes
  24110.      wrong with the current master. We will also introduce 'agent'
  24111.      processes to help do load balancing by sending select queries to
  24112.      different slaves.
  24113.  
  24114.    * Temporary tables are replicated with the exception of the case
  24115.      when you shut down slave server (not just slave thread) when you
  24116.      have some replicated temporary tables and they are used in
  24117.      subsequent updates by the master. To deal with this problem
  24118.      shutting down the slave, do `STOP SLAVE', check
  24119.      `Slave_open_temp_tables' variable to see if it is 0, if so issue
  24120.      `mysqladmin shutdown'. If the number is not 0, restart the slave
  24121.      threads with `START SLAVE' and see if you have better luck next
  24122.      time. We have plans to fix this in the near future.
  24123.  
  24124.    * It is safe to connect servers in a circular master-slave
  24125.      relationship with `log-slave-updates' enabled.  Note, however,
  24126.      that many queries will not work right in this kind of setup unless
  24127.      your client code is written to take care of the potential problems
  24128.      that can happen from updates that occur in different sequence on
  24129.      different servers.
  24130.  
  24131.      This means that you can do a setup like the following:
  24132.  
  24133.           A -> B -> C -> A
  24134.  
  24135.      Thanks to server ids, which are encoded in the binary log events, A
  24136.      will know when the event it reads had originally been created by
  24137.      A, so A will not execute it and there will be no infinite loop.
  24138.      But this circular setup will only work if you only do non
  24139.      conflicting updates between the tables.  In other words, if you
  24140.      insert data in A and C, you should never insert a row in A that
  24141.      may have a conflicting key with a row insert in C.  You should
  24142.      also not update the same rows on two servers if the order in which
  24143.      the updates are applied matters.
  24144.  
  24145.    * If the query on the slave gets an error, the slave SQL thread will
  24146.      terminate, and a message will appear in the `.err' file. You should
  24147.      then connect to the slave manually, fix the cause of the error (for
  24148.      example, non-existent table), and then run `START SLAVE'.
  24149.  
  24150.    * If connection to the master is lost, the slave will retry
  24151.      immediately, and then in case of failure every
  24152.      `master-connect-retry' (default 60) seconds. Because of this, it
  24153.      is safe to shut down the master, and then restart it after a
  24154.      while. The slave will also be able to deal with network
  24155.      connectivity outages. However, the slave will notice the network
  24156.      outage only after receiving no data from the master for
  24157.      `slave_net_timeout' seconds. So if your outages are short, you may
  24158.      want to decrease `slave_net_timeout' ; see *Note SHOW VARIABLES::.
  24159.  
  24160.    * Shutting down the slave (cleanly) is also safe, as it keeps track
  24161.      of where it left off.  Unclean shutdowns might produce problems,
  24162.      especially if disk cache was not synced before the system died.
  24163.      Your system fault tolerance will be greatly increased if you have
  24164.      a good UPS.
  24165.  
  24166.    * Due to the non-transactional nature of MyISAM tables, it is
  24167.      possible to have a query that will only partially update a table
  24168.      and return an error code. This can happen, for example, on a
  24169.      multi-row insert that has one row violating a key constraint, or
  24170.      if a long update query is killed after updating some of the rows.
  24171.      If that happens on the master, the slave thread will exit and wait
  24172.      for the DBA to decide what to do about it unless the error code is
  24173.      legitimate and the query execution results in the same error code.
  24174.      If this error code validation behaviour is not desirable, some (
  24175.      or all) errors could be masked out with `slave-skip-errors' option
  24176.      starting in Version 3.23.47.
  24177.  
  24178.    * If you update transactional tables from non-transaction tables
  24179.      inside a `BEGIN/COMMIT' segment updates to the binary log may be
  24180.      out of sync if some thread changes the non-transactional table
  24181.      before the transaction commits.  This is because the transaction
  24182.      is written to the binary log only when it's commited.
  24183.  
  24184.    * Any updates to a non-transactional table is written to the binary
  24185.      log at once when the update is made while transactional updates
  24186.      are written on `COMMIT' or not written at all if you use
  24187.      `ROLLBACK'.  You have to take this into account when updating both
  24188.      transactional tables and non-transactional tables in the same
  24189.      transaction and you are using binary logging for backups or
  24190.      replication.
  24191.  
  24192. The following table is about problems in 3.23 that are fixed in 4.0:
  24193.  
  24194.    * `LOAD DATA INFILE' will be handled properly as long as the file
  24195.      still resides on the master server at the time of update
  24196.      propagation.
  24197.  
  24198.    * `LOAD LOCAL DATA INFILE' will be skipped.
  24199.  
  24200.    * In 3.23 `RAND()' in updates does not replicate properly.  Use
  24201.      `RAND(some_non_rand_expr)' if you are replicating updates with
  24202.      `RAND()'. You can, for example, use `UNIX_TIMESTAMP()' for the
  24203.      argument to `RAND()'. This is fixed in 4.0.
  24204.  
  24205. Replication Options in `my.cnf'
  24206. -------------------------------
  24207.  
  24208. On both master and slave you need to use the `server-id' option.  This
  24209. sets a unique replication id. You should pick a unique value in the
  24210. range between 1 to 2^32-1 for each master and slave.  Example:
  24211. `server-id=3'
  24212.  
  24213. The options you can use on the MASTER are all described there: see
  24214. *Note Binary log::.
  24215.  
  24216. The following table describes the options you can use on the SLAVE.  It
  24217. is recommended to read the following paragraph; these options can help
  24218. you customize replication to suit your needs.
  24219.  
  24220. *NOTE*: replication handles the following options :
  24221.    * master-host
  24222.  
  24223.    * master-user
  24224.  
  24225.    * master-password
  24226.  
  24227.    * master-port
  24228.  
  24229.    * master-connect-retry
  24230. in a special way. If no `master.info' file exists (replication is used
  24231. for the very first time or you have run `RESET SLAVE' and
  24232. shutdown/restarted the slave server), the slave uses values specified
  24233. on the command-line or in `my.cnf'.  But if `master.info' exists, the
  24234. slave *IGNORES* any values specified on the command-line or in `my.cnf',
  24235. and uses instead the values it reads from `master.info'.  For example,
  24236. if you have
  24237.  
  24238. `master-host=this_host'
  24239.  
  24240. in your `my.cnf', are using replication, then want to replicate from
  24241. another host, modifying the above line in `my.cnf' will have no effect.
  24242. You must use `CHANGE MASTER TO' instead. This holds true for
  24243. `master-host', `master-user', `master-password', `master-port',
  24244. `master-connect-retry'.  Therefore, you may decide to put no `master-*'
  24245. options in `my.cnf' and instead use only `CHANGE MASTER TO' (*note
  24246. Replication SQL::).
  24247.  
  24248. *Option*                    *Description*
  24249. `log-slave-updates'          Tells the slave to log the updates done by
  24250.                             the slave SQL thread to the slave's binary
  24251.                             log. Off by default.  Of course, it requires
  24252.                             that the slave be started with binary
  24253.                             logging enabled (`log-bin' option).  You
  24254.                             have to use `log-slave-updates' to chain
  24255.                             several slaves ; for example for the
  24256.                             following setup to work
  24257.                             
  24258.                                  A -> B ->C
  24259.                             (C is a slave of B which is a slave of A)
  24260.                             you need to start B with the
  24261.                             `log-slave-updates' option.
  24262. `log-warnings'               Makes the slave print more messages about
  24263.                             what it is doing. For example, it will warn
  24264.                             you that it succeeded in reconnecting after a
  24265.                             network/connection failure, and warn you
  24266.                             about how each slave thread started.
  24267. `master-host=host'           Master hostname or IP address for
  24268.                             replication. If not set, the slave thread
  24269.                             will not be started. Note that the setting
  24270.                             of `master-host' will be ignored if there
  24271.                             exists a valid `master.info' file. Probably a
  24272.                             better name for this options would have been
  24273.                             something like `bootstrap-master-host', but
  24274.                             it is too late to change now.
  24275.                             
  24276.                             Example:
  24277.                             `master-host=db-master.mycompany.com'
  24278. `master-user=username'       The username the slave thread will use for
  24279.                             authentication when connecting to the
  24280.                             master. The user must have the `FILE'
  24281.                             privilege. If the master user is not set,
  24282.                             user `test' is assumed. The value in
  24283.                             `master.info' will take precedence if it can
  24284.                             be read.
  24285.                             
  24286.                             Example: `master-user=scott'
  24287. `master-password=password'   The password the slave thread will
  24288.                             authenticate with when connecting to the
  24289.                             master. If not set, an empty password is
  24290.                             assumed.The value in `master.info' will take
  24291.                             precedence if it can be read.
  24292.                             
  24293.                             Example: `master-password=tiger'
  24294. `master-port=portnumber'     The port the master is listening on. If not
  24295.                             set, the compiled setting of `MYSQL_PORT' is
  24296.                             assumed. If you have not tinkered with
  24297.                             `configure' options, this should be 3306.
  24298.                             The value in `master.info' will take
  24299.                             precedence if it can be read.
  24300.                             
  24301.                             Example: `master-port=3306'
  24302. `master-connect-retry=seconds' The number of seconds the slave thread will
  24303.                             sleep before retrying to connect to the
  24304.                             master in case the master goes down or the
  24305.                             connection is lost.  Default is 60. The
  24306.                             value in `master.info' will take precedence
  24307.                             if it can be read.
  24308.                             
  24309.                             Example: `master-connect-retry=60'
  24310. `master-ssl'                 Planned to enable the slave to connect to
  24311.                             the master using SSL.  Does nothing yet!
  24312.                             
  24313.                             Example: `master-ssl'
  24314. `master-ssl-key=filename'    Master SSL keyfile name. Only applies if
  24315.                             you have enabled `master-ssl'. Does nothing
  24316.                             yet.
  24317.                             
  24318.                             Example: `master-ssl-key=SSL/master-key.pem'
  24319. `master-ssl-cert=filename'   Master SSL certificate file name. Only
  24320.                             applies if you have enabled `master-ssl'.
  24321.                             Does nothing yet.
  24322.                             
  24323.                             Example:
  24324.                             `master-ssl-cert=SSL/master-cert.pem'
  24325. `master-ssl-capath'          Master SSL CA path. Only applies if you
  24326.                             have enabled `master-ssl'. Does nothing yet.
  24327. `master-ssl-cipher'          Master SSL cipher. Only applies if you have
  24328.                             enabled `master-ssl'. Does nothing yet.
  24329. `master-info-file=filename'  To give `master.info' another name and/or
  24330.                             to put it in another directory than the data
  24331.                             directory.
  24332. `relay-log=filename'         To specify the location and name that
  24333.                             should be used for relay logs.  You can use
  24334.                             this to have hostname-independant relay log
  24335.                             names, or if your relay logs tend to be big
  24336.                             (and you don't want to decrease
  24337.                             `max_relay_log_size') and you need to put
  24338.                             them on some area different from the data
  24339.                             directory, or if you want to increase speed
  24340.                             by balancing load between disks.
  24341. `relay-log-index=filename'   To specify the location and name that
  24342.                             should be used for the relay logs index file.
  24343. `relay-log-info-file=filename' To give `relay-log.info' another name
  24344.                             and/or to put it in another directory than
  24345.                             the data directory.
  24346. `relay-log-purge=0|1'        Available since MySQL 4.1.1.
  24347.                             Disables/enables automatic purging of relay
  24348.                             logs as soon as they are not needed anymore.
  24349.                             This is a global variable which can be
  24350.                             dynamically changed with `SET GLOBAL
  24351.                             RELAY_LOG_PURGE=0|1'. The default value is 1.
  24352. `relay-log-space-limit=#'    To put an upper limit on the total size of
  24353.                             all relay logs on the slave (a value of 0
  24354.                             means "unlimited"). This is useful if you
  24355.                             have a small hard disk on your slave
  24356.                             machine. When the limit is reached, the I/O
  24357.                             thread pauses (does not read the master's
  24358.                             binlog) until the SQL thread has catched up
  24359.                             and deleted some now unused relay logs. Note
  24360.                             that this limit is not absolute: there are
  24361.                             cases where the SQL thread needs more events
  24362.                             to be able to delete; in that case the I/O
  24363.                             thread will overgo the limit until deletion
  24364.                             becomes possible. Not doing so would cause a
  24365.                             deadlock (which happens before MySQL 4.0.13).
  24366.                             Users should not set `relay-log-space-limit'
  24367.                             to less than twice the value of
  24368.                             `max-binlog-size' because in that case there
  24369.                             are chances that when the I/O thread waits
  24370.                             for free space because
  24371.                             `relay-log-space-limit' is exceeded, the SQL
  24372.                             thread has no relay log to purge and so
  24373.                             cannot satisfy the I/O thread, forcing the
  24374.                             I/O thread to temporarily ignore
  24375.                             `relay-log-space-limit'.
  24376. `replicate-do-table=db_name.table_name' Tells the slave thread to restrict
  24377.                             replication to the specified table.  To
  24378.                             specify more than one table, use the
  24379.                             directive multiple times, once for each
  24380.                             table.  This will work for cross-database
  24381.                             updates, in contrast to `replicate-do-db'.
  24382.                             
  24383.                             Example:
  24384.                             `replicate-do-table=some_db.some_table'
  24385. `replicate-ignore-table=db_name.table_name' Tells the slave thread to not replicate any
  24386.                             command that updates the specified table
  24387.                             (even if any other tables may be update by
  24388.                             the same command). To specify more than one
  24389.                             table to ignore, use the directive multiple
  24390.                             times, once for each table. This will work
  24391.                             for cross-database updates, in contrast to
  24392.                             `replicate-ignore-db'.
  24393.                             
  24394.                             Example:
  24395.                             `replicate-ignore-table=db_name.some_table'
  24396. `replicate-wild-do-table=db_name.table_name' Tells the slave thread to restrict
  24397.                             replication to queries where any of the
  24398.                             updated tables match the specified wildcard
  24399.                             pattern.  To specify more than one table,
  24400.                             use the directive multiple times, once for
  24401.                             each table.  This will work for
  24402.                             cross-database updates.
  24403.                             
  24404.                             Example: `replicate-wild-do-table=foo%.bar%'
  24405.                             will replicate only updates that uses a
  24406.                             table in any databases that start with `foo'
  24407.                             and whose table names start with `bar'.
  24408.                             
  24409.                             Note that if you do
  24410.                             `replicate-wild-do-table=foo%.%' then the
  24411.                             rule will be propagated to `CREATE DATABASE'
  24412.                             and `DROP DATABASE', that is, these two
  24413.                             statements will be replicated if the
  24414.                             database name matches the database pattern
  24415.                             ('foo%' here) (this magic is triggered by
  24416.                             '%' being the table pattern).
  24417. `replicate-wild-ignore-table=db_name.table_name' Tells the slave thread to not replicate a
  24418.                             query where any table matches the given
  24419.                             wildcard pattern. To specify more than one
  24420.                             table to ignore, use the directive multiple
  24421.                             times, once for each table. This will work
  24422.                             for cross-database updates.
  24423.                             
  24424.                             Example:
  24425.                             `replicate-wild-ignore-table=foo%.bar%' will
  24426.                             not do updates to tables in databases that
  24427.                             start with `foo' and whose table names start
  24428.                             with `bar'.
  24429.                             
  24430.                             Note that if you do
  24431.                             `replicate-wild-ignore-table=foo%.%' then the
  24432.                             rule will be propagated to `CREATE DATABASE'
  24433.                             and `DROP DATABASE', that is, these two
  24434.                             statements will not be replicated if the
  24435.                             database name matches the database pattern
  24436.                             ('foo%' here) (this magic is triggered by
  24437.                             '%' being the table pattern).
  24438. `replicate-do-db=database_name' Tells the slave to restrict replication to
  24439.                             commands where the current database (that
  24440.                             is, the one selected by `USE') is
  24441.                             `database_name'.  To specify more than one
  24442.                             database, use the directive multiple times,
  24443.                             once for each database. Note that this will
  24444.                             not replicate cross-database queries such as
  24445.                             `UPDATE some_db.some_table SET foo='bar''
  24446.                             while having selected a different or no
  24447.                             database. If you need cross database updates
  24448.                             to work, make sure you have 3.23.28 or
  24449.                             later, and use
  24450.                             `replicate-wild-do-table=db_name.%'.
  24451.                             
  24452.                             Example: `replicate-do-db=some_db'
  24453.                             
  24454.                             Example of what does not work as you could
  24455.                             expect it: if the slave is started with
  24456.                             `replicate-do-db=sales', and you do `USE
  24457.                             prices; UPDATE sales.january SET
  24458.                             amount=amount+1000;', this query will not be
  24459.                             replicated.
  24460.                             
  24461.                             If you need cross database updates to work,
  24462.                             use `replicate-wild-do-table=db_name.%'
  24463.                             instead.
  24464.                             
  24465.                             The main reason for this
  24466.                             "just-check-the-current-database" behaviour
  24467.                             is that it's hard from the command alone to
  24468.                             know if a query should be replicated or not
  24469.                             ; for example if you are using
  24470.                             multi-table-delete or multi-table-update
  24471.                             commands that go across multiple databases.
  24472.                             It's also very fast to just check the
  24473.                             current database.
  24474. `replicate-ignore-db=database_name' Tells the slave to not replicate any
  24475.                             command where the current database (that is,
  24476.                             the one selected by `USE') is
  24477.                             `database_name'. To specify more than one
  24478.                             database to ignore, use the directive
  24479.                             multiple times, once for each database.  You
  24480.                             should not use this directive if you are
  24481.                             using cross table updates and you don't want
  24482.                             these update to be replicated.
  24483.                             
  24484.                             Example: `replicate-ignore-db=some_db'
  24485.                             
  24486.                             Example of what does not work as you could
  24487.                             expect it: if the slave is started with
  24488.                             `replicate-ignore-db=sales', and you do `USE
  24489.                             prices; UPDATE sales.january SET
  24490.                             amount=amount+1000;', this query will be
  24491.                             replicated.
  24492.                             
  24493.                             If you need cross database updates to work,
  24494.                             use `replicate-wild-ignore-table=db_name.%'
  24495.                             instead.
  24496. `replicate-rewrite-db=from_name->to_name' Tells the slave to translate the current
  24497.                             database (that is, the one selected by `USE')
  24498.                             to `to_name' if it was `from_name' on the
  24499.                             master.  Only statements involving tables
  24500.                             may be affected (`CREATE DATABASE', `DROP
  24501.                             DATABASE' won't), and only if `from_name'
  24502.                             was the current database on the master.
  24503.                             This will not work for cross-database
  24504.                             updates.
  24505.                             
  24506.                             Example:
  24507.                             `replicate-rewrite-db=master_db_name->slave_db_name'
  24508. `report-host=host'           Available after 4.0.0. Hostname or IP of
  24509.                             the slave to be reported to the master
  24510.                             during slave registration. Will appear in
  24511.                             the output of `SHOW SLAVE HOSTS'. Leave
  24512.                             unset if you do not want the slave to
  24513.                             register itself with the master. Note that
  24514.                             it is not sufficient for the master to
  24515.                             simply read the IP of the slave off the
  24516.                             socket once the slave connects. Due to `NAT'
  24517.                             and other routing issues, that IP may not be
  24518.                             valid for connecting to the slave from the
  24519.                             master or other hosts. For the moment this
  24520.                             option has no real interest ; it is meant
  24521.                             for failover replication which is not
  24522.                             implemented yet.
  24523.                             
  24524.                             Example: `report-host=slave1.mycompany.com'
  24525. `report-port=portnumber'     Available after 4.0.0. Port for connecting
  24526.                             to slave reported to the master during slave
  24527.                             registration.  Set it only if the slave is
  24528.                             listening on a non-default port or if you
  24529.                             have a special tunnel from the master or
  24530.                             other clients to the slave. If not sure,
  24531.                             leave this option unset.  For the moment
  24532.                             this option has no real interest ; it is
  24533.                             meant for failover replication which is not
  24534.                             implemented yet.
  24535. `skip-slave-start'           Tells the slave server not to start the
  24536.                             slave threads on server startup. The user
  24537.                             can start them later with `START SLAVE'.
  24538. `slave_compressed_protocol=#' If 1, then use compression on the
  24539.                             slave/client protocol if both slave and
  24540.                             master support this.
  24541. `slave-load-tmpdir=filename' This option is by default equal to `tmpdir'.
  24542.                             When the SQL slave replicates a `LOAD DATA
  24543.                             INFILE' command, it extracts the
  24544.                             to-be-loaded file from the relay log into
  24545.                             temporary files, then loads these into the
  24546.                             table. If the file loaded on the master was
  24547.                             huge, the temporary files on the slave will
  24548.                             be huge too; therefore you may wish/have to
  24549.                             tell the slave to put the temporary files on
  24550.                             some large disk different from `tmpdir',
  24551.                             using this option. In that case, you may
  24552.                             also use the `relay-log' option, as relay
  24553.                             logs will be huge too.
  24554. `slave-net-timeout=#'        Number of seconds to wait for more data
  24555.                             from the master before aborting the read,
  24556.                             considering the connection broken and
  24557.                             retrying to connect, first time immediately,
  24558.                             then every `master-connect-retry' seconds.
  24559. `slave-skip-errors=          Tells the slave SQL thread to continue
  24560. [err_code1,err_code2,... |  replication when a query returns an error
  24561. all]'                       from the provided list. Normally,
  24562.                             replication will discontinue when an error is
  24563.                             encountered, giving the user a chance to
  24564.                             resolve the inconsistency in the data
  24565.                             manually. Do not use this option unless you
  24566.                             fully understand why you are getting the
  24567.                             errors.  If there are no bugs in your
  24568.                             replication setup and client programs, and
  24569.                             no bugs in MySQL itself, you should never
  24570.                             get an abort with error. Indiscriminate use
  24571.                             of this option will result in slaves being
  24572.                             hopelessly out of sync with the master and
  24573.                             you having no idea how the problem happened.
  24574.                             
  24575.                             For error codes, you should use the numbers
  24576.                             provided by the error message in your slave
  24577.                             error log and in the output of `SHOW SLAVE
  24578.                             STATUS'. A full list of error messages can
  24579.                             be found in the source distribution in
  24580.                             `Docs/mysqld_error.txt'.
  24581.                             
  24582.                             You can (but should not) also use a very
  24583.                             non-recommended value of `all' which will
  24584.                             ignore all error messages and keep barging
  24585.                             along regardless.  Needless to say, if you
  24586.                             use it, we make no promises regarding your
  24587.                             data integrity. Please do not complain if
  24588.                             your data on the slave is not anywhere close
  24589.                             to what it is on the master in this case -
  24590.                             you have been warned.
  24591.                             
  24592.                             Example:
  24593.                             
  24594.                             `slave-skip-errors=1062,1053' or
  24595.                             `slave-skip-errors=all'
  24596.  
  24597. Some of these options, like all `replicate-*' options, can only be set
  24598. at the slave server's startup, not on-the-fly. We plan to fix this.
  24599.  
  24600. SQL Commands Related to Replication
  24601. -----------------------------------
  24602.  
  24603. Replication can be controlled through the SQL interface. Here is the
  24604. summary of commands. Near each command you will find "(Slave)", meaning
  24605. this command is issued on the slave, or "Master", meaning it is issued
  24606. on the master.
  24607.  
  24608. `START SLAVE' (slave)
  24609. .....................
  24610.  
  24611. Starts the slave threads. Was called `SLAVE START' in MySQL 3.23.  As
  24612. of MySQL 4.0.2, you can add `IO_THREAD' or `SQL_THREAD' options to the
  24613. statement to start only the I/O thread or the SQL thread.  The I/O
  24614. thread reads queries from the master server and stores them in the
  24615. relay log.  The SQL thread reads the relay log and executes the queries.
  24616. Note that if `START SLAVE' succeeds in starting the slave threads it
  24617. will return without any error. But even in that case it might be that
  24618. slave threads start and then later stop (because they don't manage to
  24619. connect to the master or read his binlogs or any other problem). `START
  24620. SLAVE' will not warn you about this, you have to check your slave's
  24621. `.err' file for error messages generated by the slave threads, or check
  24622. that these are running fine with `SHOW SLAVE STATUS'.
  24623.  
  24624. `STOP SLAVE' (slave)
  24625. ....................
  24626.  
  24627. Stops the slave threads. Was called `SLAVE STOP' in MySQL 3.23.  Like
  24628. `SLAVE START', this statement may be used with `IO_THREAD' and
  24629. `SQL_THREAD' options.
  24630.  
  24631. `SET SQL_LOG_BIN=0|1' (master)
  24632. ..............................
  24633.  
  24634. Disables/enables binary logging for the user's connection
  24635. (`SQL_LOG_BIN' is a session variable) if the user has the `SUPER'
  24636. privilege.  Ignored otherwise.
  24637.  
  24638. `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n' (slave)
  24639. .............................................
  24640.  
  24641. Skip the next `n' events from the master. Only valid when the slave
  24642. thread is not running, otherwise, gives an error. Useful for recovering
  24643. from replication stops caused by a statement.
  24644.  
  24645. `RESET MASTER' (master)
  24646. .......................
  24647.  
  24648. Deletes all binary logs listed in the index file, resetting the binlog
  24649. index file to be empty.  Previously named `FLUSH MASTER'.
  24650.  
  24651. `RESET SLAVE' (slave)
  24652. .....................
  24653.  
  24654. Makes the slave forget its replication position in the master's binlogs,
  24655. deletes the `master.info' and `relay-log.info' files, all relay logs,
  24656. starts a new relay log.  Connection information (`master-host' et al.)
  24657. is not cleared in memory and will be reused if you `START SLAVE' later.
  24658. But if you shutdown the slave server between `RESET SLAVE' and `START
  24659. SLAVE', then the connection information in memory will be lost and
  24660. reread from the command-line or `my.cnf'.  Previously named `FLUSH
  24661. SLAVE'.
  24662.  
  24663. `LOAD TABLE tblname FROM MASTER' (slave)
  24664. ........................................
  24665.  
  24666. Downloads a copy of the table from master to the slave. Implemented
  24667. mainly for debugging of `LOAD DATA FROM MASTER'.   Requires that the
  24668. replication user which is used to connect to the master has  `RELOAD'
  24669. and `SUPER' privileges on the master.   Please read the timeout notes
  24670. in the description of `LOAD DATA  FROM MASTER' below, they apply here
  24671. too.
  24672.  
  24673. `LOAD DATA FROM MASTER' (slave)
  24674. ...............................
  24675.  
  24676. Takes a snapshot of the master and copies  it to the slave.   Requires
  24677. that the replication user which is used to connect to the master has
  24678. `RELOAD' and `SUPER' privileges on the master.   Updates the values of
  24679. `MASTER_LOG_FILE' and  `MASTER_LOG_POS' so that the slave will start
  24680. replicating from the  correct position. Will honor table and database
  24681. exclusion rules  specified with `replicate-*' options. So far works
  24682. only with  `MyISAM' tables and acquires a global read lock on the
  24683. master while  taking the snapshot. In the future it is planned to make
  24684. it work with  `InnoDB' tables and to remove the need for global read
  24685. lock using  the non-blocking online backup feature.
  24686.  
  24687. If you are loading big tables, you may have to increase the values  of
  24688. `net_read_timeout' and `net_write_timeout'  on both your master