home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / mysql / data1.cab / Documentation / Docs / manual.txt < prev   
Encoding:
Text File  |  2003-01-22  |  2.2 MB  |  56,388 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.x In A Nutshell
  41.     Stepwise Rollout
  42.     Ready for Immediate Use
  43.     Embedded MySQL
  44.     Other Features Available From MySQL 4.0
  45.     Future MySQL 4.x Features
  46.     MySQL 4.1, The Following Development Release
  47.   MySQL Information Sources
  48.     MySQL Mailing Lists
  49.       The MySQL Mailing Lists
  50.       Asking Questions or Reporting Bugs
  51.       How to Report Bugs or Problems
  52.       Guidelines for Answering Questions on the Mailing List
  53.     MySQL Community Support on IRC (Internet Relay Chat)
  54.   How Standards-compatible Is MySQL?
  55.     What Standards Does MySQL Follow?
  56.     Running MySQL in ANSI Mode
  57.     MySQL Extensions to ANSI SQL92
  58.     MySQL Differences Compared to ANSI SQL92
  59.       Sub`SELECT's
  60.       `SELECT INTO TABLE'
  61.       Transactions and Atomic Operations
  62.       Stored Procedures and Triggers
  63.       Foreign Keys
  64.       Views
  65.       `--' as the Start of a Comment
  66.     Known Errors and Design Deficiencies in MySQL
  67.   MySQL and The Future (The TODO)
  68.     Things That Should be in 4.0
  69.     Things That Should be in 4.1
  70.     Things That Must be Done in the Near Future
  71.     Things That Have to be Done Sometime
  72.     Things We Don't Plan To Do
  73.   How MySQL Compares to Other Databases
  74.     How MySQL Compares to `mSQL'
  75.       How to Convert `mSQL' Tools for MySQL
  76.       How `mSQL' and MySQL Client/Server Communications Protocols Differ
  77.       How `mSQL' 2.0 SQL Syntax Differs from MySQL
  78.     How MySQL Compares to `PostgreSQL'
  79.       MySQL and PostgreSQL development strategies
  80.       Featurewise Comparison of MySQL and PostgreSQL
  81.       Benchmarking MySQL and PostgreSQL
  82.  
  83. MySQL Installation
  84.   Quick Standard Installation of MySQL
  85.     Installing MySQL on Linux
  86.     Installing MySQL on Windows
  87.       Installing the Binaries
  88.       Preparing the Windows MySQL Environment
  89.       Starting the Server for the First Time
  90.   General Installation Issues
  91.     How to Get MySQL
  92.     Operating Systems Supported by MySQL
  93.     Which MySQL Version to Use
  94.     Installation Layouts
  95.     How and When Updates Are Released
  96.     MySQL Binaries Compiled by MySQL AB
  97.     Installing a MySQL Binary Distribution
  98.   Installing a MySQL Source Distribution
  99.     Quick Installation Overview
  100.     Applying Patches
  101.     Typical `configure' Options
  102.     Installing from the Development Source Tree
  103.     Problems Compiling?
  104.     MIT-pthreads Notes
  105.     Windows Source Distribution
  106.   Post-installation Setup and Testing
  107.     Problems Running `mysql_install_db'
  108.     Problems Starting the MySQL Server
  109.     Starting and Stopping MySQL Automatically
  110.   Upgrading/Downgrading MySQL
  111.     Upgrading From Version 4.0 to Version 4.1
  112.     Upgrading From Version 3.23 to Version 4.0
  113.     Upgrading From Version 3.22 to Version 3.23
  114.     Upgrading from Version 3.21 to Version 3.22
  115.     Upgrading from Version 3.20 to Version 3.21
  116.     Upgrading to Another Architecture
  117.   Operating System Specific Notes
  118.     Linux Notes (All Linux Versions)
  119.       Linux Notes for Binary Distributions
  120.       Linux x86 Notes
  121.       Linux SPARC Notes
  122.       Linux Alpha Notes
  123.       Linux PowerPC Notes
  124.       Linux MIPS Notes
  125.       Linux IA64 Notes
  126.     Windows Notes
  127.       Starting MySQL on Windows 95, 98 or Me
  128.       Starting MySQL on Windows NT, 2000 or XP
  129.       Running MySQL on Windows
  130.       Connecting to a Remote MySQL from Windows with SSH
  131.       Splitting Data Across Different Disks on Windows
  132.       Compiling MySQL Clients on Windows
  133.       MySQL-Windows Compared to Unix MySQL
  134.     Solaris Notes
  135.       Solaris 2.7/2.8 Notes
  136.       Solaris x86 Notes
  137.     BSD Notes
  138.       FreeBSD Notes
  139.       NetBSD notes
  140.       OpenBSD 2.5 Notes
  141.       OpenBSD 2.8 Notes
  142.       BSD/OS Version 2.x Notes
  143.       BSD/OS Version 3.x Notes
  144.       BSD/OS Version 4.x Notes
  145.     Mac OS X Notes
  146.       Mac OS X Public Beta
  147.       Mac OS X Server
  148.     Other Unix Notes
  149.       HP-UX Notes for Binary Distributions
  150.       HP-UX Version 10.20 Notes
  151.       HP-UX Version 11.x Notes
  152.       IBM-AIX notes
  153.       SunOS 4 Notes
  154.       Alpha-DEC-UNIX Notes (Tru64)
  155.       Alpha-DEC-OSF/1 Notes
  156.       SGI Irix Notes
  157.       Caldera (SCO) Notes
  158.       Caldera (SCO) Unixware Version 7.0 Notes
  159.     OS/2 Notes
  160.     BeOS Notes
  161.     Novell NetWare Notes
  162.   Perl Installation Comments
  163.     Installing Perl on Unix
  164.     Installing ActiveState Perl on Windows
  165.     Installing the MySQL Perl Distribution on Windows
  166.     Problems Using the Perl `DBI'/`DBD' Interface
  167.  
  168. Tutorial Introduction
  169.   Connecting to and Disconnecting from the Server
  170.   Entering Queries
  171.   Creating and Using a Database
  172.     Creating and Selecting a Database
  173.     Creating a Table
  174.     Loading Data into a Table
  175.     Retrieving Information from a Table
  176.       Selecting All Data
  177.       Selecting Particular Rows
  178.       Selecting Particular Columns
  179.       Sorting Rows
  180.       Date Calculations
  181.       Working with `NULL' Values
  182.       Pattern Matching
  183.       Counting Rows
  184.       Using More Than one Table
  185.   Getting Information About Databases and Tables
  186.   Examples of Common Queries
  187.     The Maximum Value for a Column
  188.     The Row Holding the Maximum of a Certain Column
  189.     Maximum of Column per Group
  190.     The Rows Holding the Group-wise Maximum of a Certain Field
  191.     Using user variables
  192.     Using Foreign Keys
  193.     Searching on Two Keys
  194.     Calculating Visits Per Day
  195.     Using `AUTO_INCREMENT'
  196.   Using `mysql' in Batch Mode
  197.   Queries from Twin Project
  198.     Find all Non-distributed Twins
  199.     Show a Table on Twin Pair Status
  200.   Using MySQL with Apache
  201.  
  202. Database Administration
  203.   Configuring MySQL
  204.     `mysqld' Command-line Options
  205.     `my.cnf' Option Files
  206.     Installing Many Servers on the Same Machine
  207.     Running Multiple MySQL Servers on the Same Machine
  208.   General Security Issues and the MySQL Access Privilege System
  209.     General Security Guidelines
  210.     How to Make MySQL Secure Against Crackers
  211.     Startup Options for `mysqld' Concerning Security
  212.     Security issues with LOAD DATA LOCAL
  213.     What the Privilege System Does
  214.     How the Privilege System Works
  215.     Privileges Provided by MySQL
  216.     Connecting to the MySQL Server
  217.     Access Control, Stage 1: Connection Verification
  218.     Access Control, Stage 2: Request Verification
  219.     Causes of `Access denied' Errors
  220.   MySQL User Account Management
  221.     `GRANT' and `REVOKE' Syntax
  222.     MySQL User Names and Passwords
  223.     When Privilege Changes Take Effect
  224.     Setting Up the Initial MySQL Privileges
  225.     Adding New Users to MySQL
  226.     Limiting user resources
  227.     Setting Up Passwords
  228.     Keeping Your Password Secure
  229.     Using Secure Connections
  230.       Basics
  231.       Requirements
  232.       `GRANT' Options
  233.   Disaster Prevention and Recovery
  234.     Database Backups
  235.     `BACKUP TABLE' Syntax
  236.     `RESTORE TABLE' Syntax
  237.     `CHECK TABLE' Syntax
  238.     `REPAIR TABLE' Syntax
  239.     Using `myisamchk' for Table Maintenance and Crash Recovery
  240.       `myisamchk' Invocation Syntax
  241.       General Options for `myisamchk'
  242.       Check Options for `myisamchk'
  243.       Repair Options for myisamchk
  244.       Other Options for `myisamchk'
  245.       `myisamchk' Memory Usage
  246.       Using `myisamchk' for Crash Recovery
  247.       How to Check Tables for Errors
  248.       How to Repair Tables
  249.       Table Optimisation
  250.     Setting Up a Table Maintenance Regimen
  251.     Getting Information About a Table
  252.   Database Administration Language Reference
  253.     `OPTIMIZE TABLE' Syntax
  254.     `ANALYZE TABLE' Syntax
  255.     `FLUSH' Syntax
  256.     `RESET' Syntax
  257.     `KILL' Syntax
  258.     `SHOW' Syntax
  259.       Retrieving information about Database, Tables, Columns, and Indexes
  260.       `SHOW TABLE STATUS'
  261.       `SHOW STATUS'
  262.       `SHOW VARIABLES'
  263.       `SHOW LOGS'
  264.       `SHOW PROCESSLIST'
  265.       `SHOW GRANTS'
  266.       `SHOW CREATE TABLE'
  267.       `SHOW WARNINGS | ERRORS'
  268.   MySQL Localisation and International Usage
  269.     The Character Set Used for Data and Sorting
  270.       German character set
  271.     Non-English Error Messages
  272.     Adding a New Character Set
  273.     The Character Definition Arrays
  274.     String Collating Support
  275.     Multi-byte Character Support
  276.     Problems With Character Sets
  277.   MySQL Server-Side Scripts and Utilities
  278.     Overview of the Server-Side Scripts and Utilities
  279.     `safe_mysqld', The Wrapper Around `mysqld'
  280.     `mysqld_multi', A Program for Managing Multiple MySQL Servers
  281.     `myisampack', The MySQL Compressed Read-only Table Generator
  282.     `mysqld-max', An Extended `mysqld' Server
  283.   MySQL Client-Side Scripts and Utilities
  284.     Overview of the Client-Side Scripts and Utilities
  285.     `mysql', The Command-line Tool
  286.     `mysqladmin', Administrating a MySQL Server
  287.     Using `mysqlcheck' for Table Maintenance and Crash Recovery
  288.     `mysqldump', Dumping Table Structure and Data
  289.     `mysqlhotcopy', Copying MySQL Databases and Tables
  290.     `mysqlimport', Importing Data from Text Files
  291.     Showing Databases, Tables, and Columns
  292.     perror, Explaining Error Codes
  293.     How to Run SQL Commands from a Text File
  294.   The MySQL Log Files
  295.     The Error Log
  296.     The General Query Log
  297.     The Update Log
  298.     The Binary Update Log
  299.     The Slow Query Log
  300.     Log File Maintenance
  301.   Replication in MySQL
  302.     Introduction
  303.     Replication Implementation Overview
  304.     How To Set Up Replication
  305.     Replication Features and Known Problems
  306.     Replication Options in `my.cnf'
  307.     SQL Commands Related to Replication
  308.     Replication FAQ
  309.     Troubleshooting Replication
  310.  
  311. MySQL Optimisation
  312.   Optimisation Overview
  313.     MySQL Design Limitations/Tradeoffs
  314.     Portability
  315.     What Have We Used MySQL For?
  316.     The MySQL Benchmark Suite
  317.     Using Your Own Benchmarks
  318.   Optimising `SELECT's and Other Queries
  319.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  320.     Estimating Query Performance
  321.     Speed of `SELECT' Queries
  322.     How MySQL Optimises `WHERE' Clauses
  323.     How MySQL Optimises `DISTINCT'
  324.     How MySQL Optimises `LEFT JOIN' and `RIGHT JOIN'
  325.     How MySQL Optimises `ORDER BY'
  326.     How MySQL Optimises `LIMIT'
  327.     Speed of `INSERT' Queries
  328.     Speed of `UPDATE' Queries
  329.     Speed of `DELETE' Queries
  330.     Other Optimisation Tips
  331.   Locking Issues
  332.     How MySQL Locks Tables
  333.     Table Locking Issues
  334.   Optimising Database Structure
  335.     Design Choices
  336.     Get Your Data as Small as Possible
  337.     How MySQL Uses Indexes
  338.     Column Indexes
  339.     Multiple-Column Indexes
  340.     Why So Many Open tables?
  341.     How MySQL Opens and Closes Tables
  342.     Drawbacks to Creating Large Numbers of Tables in the Same Database
  343.   Optimising the MySQL Server
  344.     System/Compile Time and Startup Parameter Tuning
  345.     Tuning Server Parameters
  346.     How Compiling and Linking Affects the Speed of MySQL
  347.     How MySQL Uses Memory
  348.     How MySQL uses DNS
  349.     `SET' Syntax
  350.   Disk Issues
  351.     Using Symbolic Links
  352.       Using Symbolic Links for Databases
  353.       Using Symbolic Links for Tables
  354.  
  355. MySQL Language Reference
  356.   Language Structure
  357.     Literals: How to Write Strings and Numbers
  358.       Strings
  359.       Numbers
  360.       Hexadecimal Values
  361.       `NULL' Values
  362.     Database, Table, Index, Column, and Alias Names
  363.     Case Sensitivity in Names
  364.     User Variables
  365.     System Variables
  366.     Comment Syntax
  367.     Is MySQL Picky About Reserved Words?
  368.   Column Types
  369.     Numeric Types
  370.     Date and Time Types
  371.       Y2K Issues and Date Types
  372.       The `DATETIME', `DATE', and `TIMESTAMP' Types
  373.       The `TIME' Type
  374.       The `YEAR' Type
  375.     String Types
  376.       The `CHAR' and `VARCHAR' Types
  377.       The `BLOB' and `TEXT' Types
  378.       The `ENUM' Type
  379.       The `SET' Type
  380.     Choosing the Right Type for a Column
  381.     Using Column Types from Other Database Engines
  382.     Column Type Storage Requirements
  383.   Functions for Use in `SELECT' and `WHERE' Clauses
  384.     Non-Type-Specific Operators and Functions
  385.       Parentheses
  386.       Comparison Operators
  387.       Logical Operators
  388.       Control Flow Functions
  389.     String Functions
  390.       String Comparison Functions
  391.       Case-Sensitivity
  392.     Numeric Functions
  393.       Arithmetic Operations
  394.       Mathematical Functions
  395.     Date and Time Functions
  396.     Cast Functions
  397.     Other Functions
  398.       Bit Functions
  399.       Miscellaneous Functions
  400.     Functions for Use with `GROUP BY' Clauses
  401.   Data Manipulation: `SELECT', `INSERT', `UPDATE', `DELETE'
  402.     `SELECT' Syntax
  403.       `JOIN' Syntax
  404.       `UNION' Syntax
  405.     `HANDLER' Syntax
  406.     `INSERT' Syntax
  407.       `INSERT ... SELECT' Syntax
  408.     `INSERT DELAYED' Syntax
  409.     `UPDATE' Syntax
  410.     `DELETE' Syntax
  411.     `TRUNCATE' Syntax
  412.     `REPLACE' Syntax
  413.     `LOAD DATA INFILE' Syntax
  414.     `DO' Syntax
  415.   Data Definition: `CREATE', `DROP', `ALTER'
  416.     `CREATE DATABASE' Syntax
  417.     `DROP DATABASE' Syntax
  418.     `CREATE TABLE' Syntax
  419.       Silent Column Specification Changes
  420.     `ALTER TABLE' Syntax
  421.     `RENAME TABLE' Syntax
  422.     `DROP TABLE' Syntax
  423.     `CREATE INDEX' Syntax
  424.     `DROP INDEX' Syntax
  425.   Basic MySQL User Utility Commands
  426.     `USE' Syntax
  427.     `DESCRIBE' Syntax (Get Information About Columns)
  428.   MySQL Transactional and Locking Commands
  429.     `BEGIN/COMMIT/ROLLBACK' Syntax
  430.     `LOCK TABLES/UNLOCK TABLES' Syntax
  431.     `SET TRANSACTION' Syntax
  432.   MySQL Full-text Search
  433.     Full-text Restrictions
  434.     Fine-tuning MySQL Full-text Search
  435.     Full-text Search TODO
  436.   MySQL Query Cache
  437.     How The Query Cache Operates
  438.     Query Cache Configuration
  439.     Query Cache Options in `SELECT'
  440.     Query Cache Status and Maintenance
  441.  
  442. MySQL Table Types
  443.   `MyISAM' Tables
  444.     Space Needed for Keys
  445.     `MyISAM' Table Formats
  446.       Static (Fixed-length) Table Characteristics
  447.       Dynamic Table Characteristics
  448.       Compressed Table Characteristics
  449.     `MyISAM' Table Problems
  450.       Corrupted `MyISAM' Tables
  451.       Clients is using or hasn't closed the table properly
  452.   `MERGE' Tables
  453.     `MERGE' Table Problems
  454.   `ISAM' Tables
  455.   `HEAP' Tables
  456.   `InnoDB' Tables
  457.     InnoDB Tables Overview
  458.     InnoDB Startup Options
  459.     Creating InnoDB Tablespace
  460.       If Something Goes Wrong in Database Creation
  461.     Creating InnoDB Tables
  462.       Converting MyISAM Tables to InnoDB
  463.       Foreign Key Constraints
  464.     Adding and Removing InnoDB Data and Log Files
  465.     Backing up and Recovering an InnoDB Database
  466.       Checkpoints
  467.     Moving an InnoDB Database to Another Machine
  468.     InnoDB Transaction Model
  469.       Consistent Read
  470.       Locking Reads
  471.       Next-key Locking: Avoiding the Phantom Problem
  472.       Locks Set by Different SQL Statements in InnoDB
  473.       Deadlock Detection and Rollback
  474.       An Example of How the Consistent Read Works in InnoDB
  475.       How to cope with deadlocks?
  476.       Performance Tuning Tips
  477.       The InnoDB Monitor
  478.     Implementation of Multi-versioning
  479.     Table and Index Structures
  480.       Physical Structure of an Index
  481.       Insert Buffering
  482.       Adaptive Hash Indexes
  483.       Physical Record Structure
  484.       How an Auto-increment Column Works in InnoDB
  485.     File Space Management and Disk I/O
  486.       Disk I/O
  487.       File Space Management
  488.       Defragmenting a Table
  489.     Error Handling
  490.     Restrictions on InnoDB Tables
  491.     InnoDB Change History
  492.       MySQL/InnoDB-4.1, January xx, 2003
  493.       MySQL/InnoDB-4.0.8, January 7, 2003
  494.       MySQL/InnoDB-4.0.7, December 26, 2002
  495.       MySQL/InnoDB-4.0.6, December 19, 2002
  496.       MySQL/InnoDB-3.23.54, December 12, 2002
  497.       MySQL/InnoDB-4.0.5, November 18, 2002
  498.       MySQL/InnoDB-3.23.53, October 9, 2002
  499.       MySQL/InnoDB-4.0.4, October 2, 2002
  500.       MySQL/InnoDB-4.0.3, August 28, 2002
  501.       MySQL/InnoDB-3.23.52, August 16, 2002
  502.       MySQL/InnoDB-4.0.2, July 10, 2002
  503.       MySQL/InnoDB-3.23.51, June 12, 2002
  504.       MySQL/InnoDB-3.23.50, April 23, 2002
  505.       MySQL/InnoDB-3.23.49, February 17, 2002
  506.       MySQL/InnoDB-3.23.48, February 9, 2002
  507.       MySQL/InnoDB-3.23.47, December 28, 2001
  508.       MySQL/InnoDB-4.0.1, December 23, 2001
  509.       MySQL/InnoDB-3.23.46, November 30, 2001
  510.       MySQL/InnoDB-3.23.45, November 23, 2001
  511.       MySQL/InnoDB-3.23.44, November 2, 2001
  512.       MySQL/InnoDB-3.23.43, October 4, 2001
  513.       MySQL/InnoDB-3.23.42, September 9, 2001
  514.       MySQL/InnoDB-3.23.41, August 13, 2001
  515.       MySQL/InnoDB-3.23.40, July 16, 2001
  516.       MySQL/InnoDB-3.23.39, June 13, 2001
  517.       MySQL/InnoDB-3.23.38, May 12, 2001
  518.     InnoDB Contact Information
  519.   `BDB' or `BerkeleyDB' Tables
  520.     Overview of `BDB' Tables
  521.     Installing `BDB'
  522.     `BDB' startup options
  523.     Characteristics of `BDB' tables:
  524.     Things we need to fix for `BDB' in the near future:
  525.     Operating systems supported by `BDB'
  526.     Restrictions on `BDB' Tables
  527.     Errors That May Occur When Using `BDB' Tables
  528.  
  529. MySQL APIs
  530.   MySQL PHP API
  531.     Common Problems with MySQL and PHP
  532.   MySQL Perl API
  533.     `DBI' with `DBD::mysql'
  534.     The `DBI' Interface
  535.     More `DBI'/`DBD' Information
  536.   MySQL ODBC Support
  537.     How To Install MyODBC
  538.     How to Fill in the Various Fields in the ODBC Administrator Program
  539.     Connect parameters for MyODBC
  540.     How to Report Problems with MyODBC
  541.     Programs Known to Work with MyODBC
  542.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  543.     Reporting Problems with MyODBC
  544.   MySQL C API
  545.     C API Datatypes
  546.     C API Function Overview
  547.     C API Function Descriptions
  548.       `mysql_affected_rows()'
  549.       `mysql_change_user()'
  550.       `mysql_character_set_name()'
  551.       `mysql_close()'
  552.       `mysql_connect()'
  553.       `mysql_create_db()'
  554.       `mysql_data_seek()'
  555.       `mysql_debug()'
  556.       `mysql_drop_db()'
  557.       `mysql_dump_debug_info()'
  558.       `mysql_eof()'
  559.       `mysql_errno()'
  560.       `mysql_error()'
  561.       `mysql_escape_string()'
  562.       `mysql_fetch_field()'
  563.       `mysql_fetch_fields()'
  564.       `mysql_fetch_field_direct()'
  565.       `mysql_fetch_lengths()'
  566.       `mysql_fetch_row()'
  567.       `mysql_field_count()'
  568.       `mysql_field_seek()'
  569.       `mysql_field_tell()'
  570.       `mysql_free_result()'
  571.       `mysql_get_client_info()'
  572.       `mysql_get_host_info()'
  573.       `mysql_get_proto_info()'
  574.       `mysql_get_server_info()'
  575.       `mysql_info()'
  576.       `mysql_init()'
  577.       `mysql_insert_id()'
  578.       `mysql_kill()'
  579.       `mysql_list_dbs()'
  580.       `mysql_list_fields()'
  581.       `mysql_list_processes()'
  582.       `mysql_list_tables()'
  583.       `mysql_num_fields()'
  584.       `mysql_num_rows()'
  585.       `mysql_options()'
  586.       `mysql_ping()'
  587.       `mysql_query()'
  588.       `mysql_real_connect()'
  589.       `mysql_real_escape_string()'
  590.       `mysql_real_query()'
  591.       `mysql_reload()'
  592.       `mysql_row_seek()'
  593.       `mysql_row_tell()'
  594.       `mysql_select_db()'
  595.       `mysql_shutdown()'
  596.       `mysql_stat()'
  597.       `mysql_store_result()'
  598.       `mysql_thread_id()'
  599.       `mysql_use_result()'
  600.     C Threaded Function Descriptions
  601.       `my_init()'
  602.       `mysql_thread_init()'
  603.       `mysql_thread_end()'
  604.       `mysql_thread_safe()'
  605.     C Embedded Server Function Descriptions
  606.       `mysql_server_init()'
  607.       `mysql_server_end()'
  608.     Common questions and problems when using the C API
  609.       Why Is It that After `mysql_query()' Returns Success, `mysql_store_result()' Sometimes Returns `NULL'?
  610.       What Results Can I Get From a Query?
  611.       How Can I Get the Unique ID for the Last Inserted Row?
  612.       Problems Linking with the C API
  613.     Building Client Programs
  614.     How to Make a Threaded Client
  615.     libmysqld, the Embedded MySQL Server Library
  616.       Overview of the Embedded MySQL Server Library
  617.       Compiling Programs with `libmysqld'
  618.       Restrictions when using the Embedded MySQL Server
  619.       Using Option Files with the Embedded Server
  620.       Things left to do in Embedded Server (TODO)
  621.       A Simple Embedded Server Example
  622.       Licensing the Embedded Server
  623.   MySQL C++ APIs
  624.     Borland C++
  625.   MySQL Java Connectivity (JDBC)
  626.   MySQL Python APIs
  627.   MySQL Tcl APIs
  628.   MySQL Eiffel wrapper
  629.  
  630. Extending MySQL
  631.   MySQL Internals
  632.     MySQL Threads
  633.     MySQL Test Suite
  634.       Running the MySQL Test Suite
  635.       Extending the MySQL Test Suite
  636.       Reporting Bugs in the MySQL Test Suite
  637.   Adding New Functions to MySQL
  638.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  639.     Adding a New User-definable Function
  640.       UDF Calling Sequences for simple functions
  641.       UDF Calling Sequences for aggregate functions
  642.       Argument Processing
  643.       Return Values and Error Handling
  644.       Compiling and Installing User-definable Functions
  645.     Adding a New Native Function
  646.   Adding New Procedures to MySQL
  647.     Procedure Analyse
  648.     Writing a Procedure
  649.  
  650. Problems and Common Errors
  651.   How to Determine What Is Causing Problems
  652.   Common Errors When Using MySQL
  653.     `Access denied' Error
  654.     `MySQL server has gone away' Error
  655.     `Can't connect to [local] MySQL server' Error
  656.     `Host '...' is blocked' Error
  657.     `Too many connections' Error
  658.     `Some non-transactional changed tables couldn't be rolled back' Error
  659.     `Out of memory' Error
  660.     `Packet too large' Error
  661.     Communication Errors / Aborted Connection
  662.     `The table is full' Error
  663.     `Can't create/write to file' Error
  664.     `Commands out of sync' Error in Client
  665.     `Ignoring user' Error
  666.     `Table 'xxx' doesn't exist' Error
  667.     `Can't initialize character set xxx' error
  668.     File Not Found
  669.   Installation Related Issues
  670.     Problems When Linking with the MySQL Client Library
  671.     How to Run MySQL As a Normal User
  672.     Problems with File Permissions
  673.   Administration Related Issues
  674.     What To Do If MySQL Keeps Crashing
  675.     How to Reset a Forgotten Root Password
  676.     How MySQL Handles a Full Disk
  677.     Where MySQL Stores Temporary Files
  678.     How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'
  679.     Time Zone Problems
  680.   Query Related Issues
  681.     Case-Sensitivity in Searches
  682.     Problems Using `DATE' Columns
  683.     Problems with `NULL' Values
  684.     Problems with `alias'
  685.     Deleting Rows from Related Tables
  686.     Solving Problems with No Matching Rows
  687.     Problems with Floating-Point Comparison
  688.   Table Definition Related Issues
  689.     Problems with `ALTER TABLE'.
  690.     How To Change the Order of Columns in a Table
  691.     TEMPORARY TABLE problems
  692.  
  693. Contributed Programs
  694.   APIs
  695.   Converters
  696.   Utilities
  697.  
  698. Credits
  699.   Developers at MySQL AB
  700.   Contributors to MySQL
  701.   Supporters to MySQL
  702.  
  703. MySQL Change History
  704.   Changes in release 4.1.x (Alpha)
  705.     Changes in release 4.1.0
  706.   Changes in release 4.0.x (Gamma)
  707.     Changes in release 4.0.10 (not released yet)
  708.     Changes in release 4.0.9 (10 Jan 2003)
  709.     Changes in release 4.0.8 (07 Jan 2003)
  710.     Changes in release 4.0.7 (20 Dec 2002)
  711.     Changes in release 4.0.6 (14 Dec 2002: Gamma)
  712.     Changes in release 4.0.5 (13 Nov 2002)
  713.     Changes in release 4.0.4 (29 Sep 2002)
  714.     Changes in release 4.0.3 (26 Aug 2002: Beta)
  715.     Changes in release 4.0.2 (01 Jul 2002)
  716.     Changes in release 4.0.1 (23 Dec 2001)
  717.     Changes in release 4.0.0 (Oct 2001: Alpha)
  718.   Changes in release 3.23.x (Stable)
  719.     Changes in release 3.23.56 (not released yet)
  720.     Changes in release 3.23.55 (to be released shortly)
  721.     Changes in release 3.23.54 (05 Dec 2002)
  722.     Changes in release 3.23.53 (09 Oct 2002)
  723.     Changes in release 3.23.52 (14 Aug 2002)
  724.     Changes in release 3.23.51 (31 May 2002)
  725.     Changes in release 3.23.50 (21 Apr 2002)
  726.     Changes in release 3.23.49
  727.     Changes in release 3.23.48 (07 Feb 2002)
  728.     Changes in release 3.23.47 (27 Dec 2001)
  729.     Changes in release 3.23.46 (29 Nov 2001)
  730.     Changes in release 3.23.45 (22 Nov 2001)
  731.     Changes in release 3.23.44 (31 Oct 2001)
  732.     Changes in release 3.23.43 (04 Oct 2001)
  733.     Changes in release 3.23.42 (08 Sep 2001)
  734.     Changes in release 3.23.41 (11 Aug 2001)
  735.     Changes in release 3.23.40
  736.     Changes in release 3.23.39 (12 Jun 2001)
  737.     Changes in release 3.23.38 (09 May 2001)
  738.     Changes in release 3.23.37 (17 Apr 2001)
  739.     Changes in release 3.23.36 (27 Mar 2001)
  740.     Changes in release 3.23.35 (15 Mar 2001)
  741.     Changes in release 3.23.34a
  742.     Changes in release 3.23.34 (10 Mar 2001)
  743.     Changes in release 3.23.33 (09 Feb 2001)
  744.     Changes in release 3.23.32 (22 Jan 2001: Stable)
  745.     Changes in release 3.23.31 (17 Jan 2001)
  746.     Changes in release 3.23.30 (04 Jan 2001)
  747.     Changes in release 3.23.29 (16 Dec 2000)
  748.     Changes in release 3.23.28 (22 Nov 2000: Gamma)
  749.     Changes in release 3.23.27 (24 Oct 2000)
  750.     Changes in release 3.23.26 (18 Oct 2000)
  751.     Changes in release 3.23.25 (29 Sep 2000)
  752.     Changes in release 3.23.24 (08 Sep 2000)
  753.     Changes in release 3.23.23 (01 Sep 2000)
  754.     Changes in release 3.23.22 (31 Jul 2000)
  755.     Changes in release 3.23.21
  756.     Changes in release 3.23.20
  757.     Changes in release 3.23.19
  758.     Changes in release 3.23.18
  759.     Changes in release 3.23.17
  760.     Changes in release 3.23.16
  761.     Changes in release 3.23.15 (May 2000: Beta)
  762.     Changes in release 3.23.14
  763.     Changes in release 3.23.13
  764.     Changes in release 3.23.12 (07 Mar 2000)
  765.     Changes in release 3.23.11
  766.     Changes in release 3.23.10
  767.     Changes in release 3.23.9
  768.     Changes in release 3.23.8 (02 Jan 2000)
  769.     Changes in release 3.23.7 (10 Dec 1999)
  770.     Changes in release 3.23.6
  771.     Changes in release 3.23.5 (20 Oct 1999)
  772.     Changes in release 3.23.4 (28 Sep 1999)
  773.     Changes in release 3.23.3
  774.     Changes in release 3.23.2 (09 Aug 1999)
  775.     Changes in release 3.23.1
  776.     Changes in release 3.23.0 (05 Aug 1999: Alpha)
  777.   Changes in release 3.22.x (Older; still supported)
  778.     Changes in release 3.22.35
  779.     Changes in release 3.22.34
  780.     Changes in release 3.22.33
  781.     Changes in release 3.22.32 (14 Feb 2000)
  782.     Changes in release 3.22.31
  783.     Changes in release 3.22.30
  784.     Changes in release 3.22.29 (02 Jan 2000)
  785.     Changes in release 3.22.28 (20 Oct 1999)
  786.     Changes in release 3.22.27
  787.     Changes in release 3.22.26 (16 Sep 1999)
  788.     Changes in release 3.22.25
  789.     Changes in release 3.22.24 (05 Jul 1999)
  790.     Changes in release 3.22.23 (08 Jun 1999)
  791.     Changes in release 3.22.22 (30 Apr 1999)
  792.     Changes in release 3.22.21
  793.     Changes in release 3.22.20 (18 Mar 1999)
  794.     Changes in release 3.22.19 (Mar 1999: Stable)
  795.     Changes in release 3.22.18
  796.     Changes in release 3.22.17
  797.     Changes in release 3.22.16 (Feb 1999: Gamma)
  798.     Changes in release 3.22.15
  799.     Changes in release 3.22.14
  800.     Changes in release 3.22.13
  801.     Changes in release 3.22.12
  802.     Changes in release 3.22.11
  803.     Changes in release 3.22.10
  804.     Changes in release 3.22.9
  805.     Changes in release 3.22.8
  806.     Changes in release 3.22.7 (Sep 1998: Beta)
  807.     Changes in release 3.22.6
  808.     Changes in release 3.22.5
  809.     Changes in release 3.22.4
  810.     Changes in release 3.22.3
  811.     Changes in release 3.22.2
  812.     Changes in release 3.22.1 (Jun 1998: Alpha)
  813.     Changes in release 3.22.0
  814.   Changes in release 3.21.x
  815.     Changes in release 3.21.33
  816.     Changes in release 3.21.32
  817.     Changes in release 3.21.31
  818.     Changes in release 3.21.30
  819.     Changes in release 3.21.29
  820.     Changes in release 3.21.28
  821.     Changes in release 3.21.27
  822.     Changes in release 3.21.26
  823.     Changes in release 3.21.25
  824.     Changes in release 3.21.24
  825.     Changes in release 3.21.23
  826.     Changes in release 3.21.22
  827.     Changes in release 3.21.21a
  828.     Changes in release 3.21.21
  829.     Changes in release 3.21.20
  830.     Changes in release 3.21.19
  831.     Changes in release 3.21.18
  832.     Changes in release 3.21.17
  833.     Changes in release 3.21.16
  834.     Changes in release 3.21.15
  835.     Changes in release 3.21.14b
  836.     Changes in release 3.21.14a
  837.     Changes in release 3.21.13
  838.     Changes in release 3.21.12
  839.     Changes in release 3.21.11
  840.     Changes in release 3.21.10
  841.     Changes in release 3.21.9
  842.     Changes in release 3.21.8
  843.     Changes in release 3.21.7
  844.     Changes in release 3.21.6
  845.     Changes in release 3.21.5
  846.     Changes in release 3.21.4
  847.     Changes in release 3.21.3
  848.     Changes in release 3.21.2
  849.     Changes in release 3.21.0
  850.   Changes in release 3.20.x
  851.     Changes in release 3.20.18
  852.     Changes in release 3.20.17
  853.     Changes in release 3.20.16
  854.     Changes in release 3.20.15
  855.     Changes in release 3.20.14
  856.     Changes in release 3.20.13
  857.     Changes in release 3.20.11
  858.     Changes in release 3.20.10
  859.     Changes in release 3.20.9
  860.     Changes in release 3.20.8
  861.     Changes in release 3.20.7
  862.     Changes in release 3.20.6
  863.     Changes in release 3.20.3
  864.     Changes in release 3.20.0
  865.   Changes in release 3.19.x
  866.     Changes in release 3.19.5
  867.     Changes in release 3.19.4
  868.     Changes in release 3.19.3
  869.  
  870. Porting to Other Systems
  871.   Debugging a MySQL server
  872.     Compiling MYSQL for Debugging
  873.     Creating Trace Files
  874.     Debugging mysqld under gdb
  875.     Using a Stack Trace
  876.     Using Log Files to Find Cause of Errors in mysqld
  877.     Making a Test Case When You Experience Table Corruption
  878.   Debugging a MySQL client
  879.   The DBUG Package
  880.   Locking methods
  881.   Comments about RTS threads
  882.   Differences between different thread packages
  883.  
  884. Environment Variables
  885.  
  886. MySQL Regular Expressions
  887.  
  888. GNU General Public License
  889.   Preamble
  890.   How to Apply These Terms to Your New Programs
  891.  
  892. GNU Lesser General Public License
  893.   Preamble
  894.   How to Apply These Terms to Your New Libraries
  895.  
  896. SQL command, type and function index
  897.  
  898. Concept Index
  899.  
  900.  
  901. This is the Reference Manual for the `MySQL Database System'.  This
  902. version refers to the 3.23.55 version of `MySQL Server' but it is also
  903. applicable for any older version as changes are always indicated.
  904.  
  905. General Information
  906. *******************
  907.  
  908. The `MySQL (TM)' software delivers a very fast, multi-threaded,
  909. multi-user, and robust `SQL' (`Structured Query Language') database
  910. server.  `MySQL Server' is intended for mission-critical, heavy-load
  911. production systems as well as for embedding into mass-deployed software.
  912. `MySQL' is a trademark of `MySQL AB'.
  913.  
  914. The `MySQL' software is `Dual Licensed'. Users can choose to use the
  915. `MySQL' software as an `Open Source'/`Free Software' product under the
  916. terms of the `GNU General Public License'
  917. (`http://www.gnu.org/licenses/') or can purchase a standard commercial
  918. license from `MySQL AB'.  *Note Licensing and Support::.
  919.  
  920. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  921. information about the `MySQL' software.
  922.  
  923. The following list describes some sections of particular interest in
  924. this manual:
  925.  
  926.    * For information about the company behind the `MySQL Database
  927.      Server', see *Note What is MySQL AB::.
  928.  
  929.    * For a discussion about the capabilities of the `MySQL Database
  930.      Server', see *Note Features::.
  931.  
  932.    * For installation instructions, see *Note Installing::.
  933.  
  934.    * For tips on porting the `MySQL Database Software' to new
  935.      architectures or operating systems, see *Note Porting::.
  936.  
  937.    * For information about upgrading from a Version 3.23 release, see
  938.      *Note Upgrading-from-3.23::.
  939.  
  940.    * For information about upgrading from a Version 3.22 release, see
  941.      *Note Upgrading-from-3.22::.
  942.  
  943.    * For a tutorial introduction to the `MySQL Database Server', see
  944.      *Note Tutorial::.
  945.  
  946.    * For examples of `SQL' and benchmarking information, see the
  947.      benchmarking directory (`sql-bench' in the distribution).
  948.  
  949.    * For a history of new features and bug fixes, see *Note News::.
  950.  
  951.    * For a list of currently known bugs and misfeatures, see *Note
  952.      Bugs::.
  953.  
  954.    * For future plans, see *Note TODO::.
  955.  
  956.    * For a list of all the contributors to this project, see *Note
  957.      Credits::.
  958.  
  959. *Important*:
  960.  
  961. Reports of errors (often called bugs), as well as questions and
  962. comments, should be sent to the mailing list at <mysql@lists.mysql.com>.
  963. *Note Bug reports::.
  964.  
  965. The `mysqlbug' script should be used to generate bug reports.  For
  966. source distributions, the `mysqlbug' script can be found in the
  967. `scripts' directory.  For binary distributions, `mysqlbug' can be found
  968. in the `bin' directory. If you have found a sensitive security bug in
  969. `MySQL Server', you should send an e-mail to <security@mysql.com>.
  970.  
  971. About This Manual
  972. =================
  973.  
  974. This is the `MySQL' reference manual; it documents `MySQL' upto Version
  975. 3.23.55. Functional changes are always indicated with reference to the
  976. version, so this manual is also suitable if you are using an older
  977. version of the `MySQL' software.  Being a reference manual, it does not
  978. provide general instruction on `SQL' or relational database concepts.
  979.  
  980. As the `MySQL Database Software' is under constant development, the
  981. manual is also updated frequently.  The most recent version of this
  982. manual is available at `http://www.mysql.com/documentation/' in many
  983. different formats, including HTML, PDF, and Windows HLP versions.
  984.  
  985. The primary document is the Texinfo file.  The HTML version is produced
  986. automatically using a modified version of `texi2html'.  The plain text
  987. and Info versions are produced with `makeinfo'.  The PostScript version
  988. is produced using `texi2dvi' and `dvips'.  The PDF version is produced
  989. with `pdftex'.
  990.  
  991. If you have a hard time finding information in the manual, you can try
  992. our searchable version at `http://www.mysql.com/doc/'.
  993.  
  994. If you have any suggestions concerning additions or corrections to this
  995. manual, please send them to the documentation team at <docs@mysql.com>.
  996.  
  997. This manual was initially written by David Axmark and Michael (Monty)
  998. Widenius. It is currently maintained by Michael (Monty) Widenius, Arjen
  999. Lentz, and Paul DuBois. For other contributors, see *Note Credits::.
  1000.  
  1001. The copyright (2002) to this manual is owned by the Swedish company
  1002. `MySQL AB'. *Note Copyright::.
  1003.  
  1004. Conventions Used in This Manual
  1005. -------------------------------
  1006.  
  1007. This manual uses certain typographical conventions:
  1008.  
  1009. `constant'
  1010.      Constant-width font is used for command names and options; SQL
  1011.      statements; database, table, and column names; C and Perl code;
  1012.      and environment variables.  Example: "To see how `mysqladmin'
  1013.      works, invoke it with the `--help' option."
  1014.  
  1015. `filename'
  1016.      Constant-width font with surrounding quotes is used for filenames
  1017.      and pathnames.  Example: "The distribution is installed under the
  1018.      `/usr/local/' directory."
  1019.  
  1020. `c'
  1021.      Constant-width font with surrounding quotes is also used to
  1022.      indicate character sequences.  Example: "To specify a wildcard,
  1023.      use the `%' character."
  1024.  
  1025. _italic_
  1026.      Italic font is used for emphasis, _like this_.
  1027.  
  1028. *boldface*
  1029.      Boldface font is used in table headings and to convey *especially
  1030.      strong emphasis*.
  1031.  
  1032. When commands are shown that are meant to be executed by a particular
  1033. program, the program is indicated by a prompt shown before the command.
  1034. For example, `shell>' indicates a command that you execute from your
  1035. login shell, and `mysql>' indicates a command that you execute from the
  1036. `mysql' client program:
  1037.  
  1038.      shell> type a shell command here
  1039.      mysql> type a mysql command here
  1040.  
  1041. Shell commands are shown using Bourne shell syntax.  If you are using a
  1042. `csh'-style shell, you may need to issue commands slightly differently.
  1043. For example, the sequence to set an environment variable and run a
  1044. command looks like this in Bourne shell syntax:
  1045.  
  1046.      shell> VARNAME=value some_command
  1047.  
  1048. For `csh', you would execute the sequence like this:
  1049.  
  1050.      shell> setenv VARNAME value
  1051.      shell> some_command
  1052.  
  1053. Often database, table, and column names must be substituted into
  1054. commands.  To indicate that such substitution is necessary, this manual
  1055. uses `db_name', `tbl_name' and `col_name'.  For example, you might see
  1056. a statement like this:
  1057.  
  1058.      mysql> SELECT col_name FROM db_name.tbl_name;
  1059.  
  1060. This means that if you were to enter a similar statement, you would
  1061. supply your own database, table, and column names, perhaps like this:
  1062.  
  1063.      mysql> SELECT author_name FROM biblio_db.author_list;
  1064.  
  1065. SQL keywords are not case-sensitive and may be written in uppercase or
  1066. lowercase.  This manual uses uppercase.
  1067.  
  1068. In syntax descriptions, square brackets (`[' and `]') are used to
  1069. indicate optional words or clauses.  For example, in the following
  1070. statement, `IF EXISTS' is optional:
  1071.  
  1072.      DROP TABLE [IF EXISTS] tbl_name
  1073.  
  1074. When a syntax element consists of a number of alternatives, the
  1075. alternatives are separated by vertical bars (`|').  When one member
  1076. from a set of choices *may* be chosen, the alternatives are listed
  1077. within square brackets (`[' and `]'):
  1078.  
  1079.      TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  1080.  
  1081. When one member from a set of choices *must* be chosen, the
  1082. alternatives are listed within braces (`{' and `}'):
  1083.  
  1084.      {DESCRIBE | DESC} tbl_name {col_name | wild}
  1085.  
  1086. What Is MySQL?
  1087. ==============
  1088.  
  1089. `MySQL', the most popular `Open Source' SQL database, is developed,
  1090. distributed and supported by `MySQL AB'.  `MySQL AB' is a commercial
  1091. company founded by the MySQL developers that builds its business
  1092. providing services around the `MySQL' database.  *Note What is MySQL
  1093. AB::.
  1094.  
  1095. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1096. information about `MySQL' software and `MySQL AB'.
  1097.  
  1098. `MySQL' is a database management system.
  1099.      A database is a structured collection of data.  It may be anything
  1100.      from a simple shopping list to a picture gallery or the vast
  1101.      amounts of information in a corporate network.  To add, access,
  1102.      and process data stored in a computer database, you need a
  1103.      database management system such as `MySQL' Server.  Since
  1104.      computers are very good at handling large amounts of data,
  1105.      database management plays a central role in computing, as
  1106.      stand-alone utilities, or as parts of other applications.
  1107.  
  1108. MySQL is a relational database management system.
  1109.      A relational database stores data in separate tables rather than
  1110.      putting all the data in one big storeroom.  This adds speed and
  1111.      flexibility.  The tables are linked by defined relations making it
  1112.      possible to combine data from several tables on request. The `SQL'
  1113.      part of "`MySQL'" stands for "`Structured Query Language'"the most
  1114.      common standardised language used to access databases.
  1115.  
  1116. MySQL software is `Open Source'.
  1117.      `Open Source' means that it is possible for anyone to use and
  1118.      modify.  Anybody can download the `MySQL' software from the
  1119.      Internet and use it without paying anything.  Anybody so inclined
  1120.      can study the source code and change it to fit their needs.  The
  1121.      `MySQL' software uses the `GPL' (`GNU General Public License'),
  1122.      `http://www.gnu.org/licenses/', to define what you may and may not
  1123.      do with the software in different situations.  If you feel
  1124.      uncomfortable with the `GPL' or need to embed `MySQL' code into a
  1125.      commercial application you can buy a commercially licensed version
  1126.      from us.  *Note MySQL licenses::.
  1127.  
  1128. Why use the MySQL Database Server?
  1129.      The `MySQL Database Server' is very fast, reliable, and easy to
  1130.      use.  If that is what you are looking for, you should give it a
  1131.      try.  `MySQL Server' also has a practical set of features
  1132.      developed in close cooperation with our users.  You can find a
  1133.      performance comparison of `MySQL Server' to some other database
  1134.      managers on our benchmark page.  *Note MySQL Benchmarks::.
  1135.  
  1136.      `MySQL Server' was originally developed to handle large databases
  1137.      much faster than existing solutions and has been successfully used
  1138.      in highly demanding production environments for several years.
  1139.      Though under constant development, `MySQL Server' today offers a
  1140.      rich and useful set of functions.  Its connectivity, speed, and
  1141.      security make `MySQL Server' highly suited for accessing databases
  1142.      on the Internet.
  1143.  
  1144. The technical features of MySQL Server
  1145.      For advanced technical information, see *Note Reference::.  The
  1146.      `MySQL Database Software' is a client/server system that consists
  1147.      of a multi-threaded `SQL' server that supports different backends,
  1148.      several different client programs and libraries, administrative
  1149.      tools, and a wide range of programming interfaces (`API's).
  1150.  
  1151.      We also provide `MySQL Server' as a multi-threaded library which
  1152.      you can link into your application to get a smaller, faster,
  1153.      easier-to-manage product.
  1154.  
  1155. There is a large amount of contributed MySQL software available.
  1156.      It is very likely that you will find that your favorite
  1157.      application or language already supports the `MySQL Database
  1158.      Server'.
  1159.  
  1160. The official way to pronounce `MySQL' is "My Ess Que Ell" (not "my
  1161. sequel"), but we don't mind if you pronounce it as "my sequel" or in
  1162. some other localised way.
  1163.  
  1164. History of MySQL
  1165. ----------------
  1166.  
  1167. We once started out with the intention of using `mSQL' to connect to our
  1168. tables using our own fast low-level (ISAM) routines. However, after some
  1169. testing we came to the conclusion that `mSQL' was not fast enough nor
  1170. flexible enough for our needs.  This resulted in a new SQL interface to
  1171. our database but with almost the same API interface as `mSQL'.  This
  1172. API was chosen to ease porting of third-party code.
  1173.  
  1174. The derivation of the name `MySQL' is not perfectly clear.  Our base
  1175. directory and a large number of our libraries and tools have had the
  1176. prefix "my" for well over 10 years.  However, Monty's daughter (some
  1177. years younger) is also named My.  Which of the two gave its name to
  1178. `MySQL' is still a mystery, even for us.
  1179.  
  1180. The Main Features of MySQL
  1181. --------------------------
  1182.  
  1183. The following list describes some of the important characteristics of
  1184. the `MySQL Database Software'. *Note MySQL 4.0 In A Nutshell::.
  1185.  
  1186. Internals and Portability
  1187.         * Written in C and C++.  Tested with a broad range of different
  1188.           compilers.
  1189.  
  1190.         * Works on many different platforms.  *Note Which OS::.
  1191.  
  1192.         * Uses GNU Automake, Autoconf, and Libtool for portability.
  1193.  
  1194.         * APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and
  1195.           Tcl.  *Note Clients::.
  1196.  
  1197.         * Fully multi-threaded using kernel threads.  This means it can
  1198.           easily use multiple CPUs if available.
  1199.  
  1200.         * Very fast B-tree disk tables with index compression.
  1201.  
  1202.         * A very fast thread-based memory allocation system.
  1203.  
  1204.         * Very fast joins using an optimised one-sweep multi-join.
  1205.  
  1206.         * In-memory hash tables which are used as temporary tables.
  1207.  
  1208.         * SQL functions are implemented through a highly optimised
  1209.           class library and should be as fast as possible!  Usually
  1210.           there isn't any memory allocation at all after query
  1211.           initialisation.
  1212.  
  1213.         * The `MySQL' code gets tested with Purify (a commercial memory
  1214.           leakage detector) as well as with Valgrind, a GPL tool
  1215.           (`http://developer.kde.org/~sewardj/').
  1216.  
  1217. Column Types
  1218.         * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8
  1219.           bytes long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT',
  1220.           `BLOB', `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR',
  1221.           `SET', and `ENUM' types.  *Note Column types::.
  1222.  
  1223.         * Fixed-length and variable-length records.
  1224.  
  1225.         * All columns have default values.  You can use `INSERT' to
  1226.           insert a subset of a table's columns; those columns that are
  1227.           not explicitly given values are set to their default values.
  1228.  
  1229. Commands and Functions
  1230.         * Full operator and function support in the `SELECT' and `WHERE'
  1231.           parts of queries.  For example:
  1232.  
  1233.                mysql> SELECT CONCAT(first_name, " ", last_name)
  1234.                    -> FROM tbl_name
  1235.                    -> WHERE income/dependents > 10000 AND age > 30;
  1236.  
  1237.         * Full support for SQL `GROUP BY' and `ORDER BY' clauses.
  1238.           Support for group functions (`COUNT()', `COUNT(DISTINCT ...)',
  1239.           `AVG()', `STD()', `SUM()', `MAX()', and `MIN()').
  1240.  
  1241.         * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with ANSI
  1242.           SQL and ODBC syntax.
  1243.  
  1244.         * Aliases on tables and columns are allowed as in the SQL92
  1245.           standard.
  1246.  
  1247.         * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number
  1248.           of rows that were changed (affected).  It is possible to
  1249.           return the number of rows matched instead by setting a flag
  1250.           when connecting to the server.
  1251.  
  1252.         * The `MySQL'-specific `SHOW' command can be used to retrieve
  1253.           information about databases, tables, and indexes.  The
  1254.           `EXPLAIN' command can be used to determine how the optimiser
  1255.           resolves a query.
  1256.  
  1257.         * Function names do not clash with table or column names.  For
  1258.           example, `ABS' is a valid column name.  The only restriction
  1259.           is that for a function call, no spaces are allowed between
  1260.           the function name and the `(' that follows it.  *Note
  1261.           Reserved words::.
  1262.  
  1263.         * You can mix tables from different databases in the same query
  1264.           (as of Version 3.22).
  1265.  
  1266. Security
  1267.         * A privilege and password system that is very flexible and
  1268.           secure, and allows host-based verification.  Passwords are
  1269.           secure because all password traffic is encrypted when you
  1270.           connect to a server.
  1271.  
  1272. Scalability and Limits
  1273.         * Handles large databases.  We are using `MySQL Server' with
  1274.           some databases that contain 50 million records and we know of
  1275.           users that use `MySQL Server' with 60,000 tables and about
  1276.           5,000,000,000 rows.
  1277.  
  1278.         * Up to 32 indexes per table are allowed.  Each index may
  1279.           consist of 1 to 16 columns or parts of columns.  The maximum
  1280.           index width is 500 bytes (this may be changed when compiling
  1281.           `MySQL Server').  An index may use a prefix of a `CHAR' or
  1282.           `VARCHAR' field.
  1283.  
  1284. Connectivity
  1285.         * Clients may connect to the `MySQL' server using TCP/IP
  1286.           Sockets, Unix Sockets (Unix), or Named Pipes (NT).
  1287.  
  1288.         * `ODBC' (Open-DataBase-Connectivity) support for Win32 (with
  1289.           source).  All ODBC 2.5 functions and many others.  For
  1290.           example, you can use MS Access to connect to your `MySQL'
  1291.           server.  *Note ODBC::.
  1292.  
  1293. Localisation
  1294.         * The server can provide error messages to clients in many
  1295.           languages.  *Note Languages::.
  1296.  
  1297.         * Full support for several different character sets, including
  1298.           ISO-8859-1 (Latin1), german, big5, ujis, and more.  For
  1299.           example, the Scandinavian characters 'σ', 'Σ' and '÷' are
  1300.           allowed in table and column names.
  1301.  
  1302.         * All data is saved in the chosen character set.  All
  1303.           comparisons for normal string columns are case-insensitive.
  1304.  
  1305.         * Sorting is done according to the chosen character set (the
  1306.           Swedish way by default).  It is possible to change this when
  1307.           the `MySQL' server is started.  To see an example of very
  1308.           advanced sorting, look at the Czech sorting code.  `MySQL
  1309.           Server' supports many different character sets that can be
  1310.           specified at compile and runtime.
  1311.  
  1312. Clients and Tools
  1313.         * Includes `myisamchk', a very fast utility for table checking,
  1314.           optimisation, and repair.  All of the functionality of
  1315.           `myisamchk' is also available through the SQL interface as
  1316.           well.  *Note MySQL Database Administration::.
  1317.  
  1318.         * All `MySQL' programs can be invoked with the `--help' or `-?'
  1319.           options to obtain online assistance.
  1320.  
  1321. How Stable Is MySQL?
  1322. --------------------
  1323.  
  1324. This section addresses the questions "_How stable is MySQL Server?_"
  1325. and "_Can I depend on MySQL Server in this project?_" We will try to
  1326. clarify these issues and answer some important questions that concern
  1327. many potential users. The information in this section is based on data
  1328. gathered from the mailing list, which is very active in identifying
  1329. problems as well as reporting types of use.
  1330.  
  1331. Original code stems back from the early '80s, providing a stable code
  1332. base, and the ISAM table format remains backward-compatible.  At TcX,
  1333. the predecessor of `MySQL AB', `MySQL' code has worked in projects
  1334. since mid-1996, without any problems.  When the `MySQL Database
  1335. Software' was released to a wider public, we noticed that there were
  1336. some pieces of "untested code" that were quickly found by the new users
  1337. who made different types of queries from us. Each new release has had
  1338. fewer portability problems (even though each new release has had many
  1339. new features).
  1340.  
  1341. Each release of the `MySQL Server' has been usable. There have only
  1342. been problems when users try code from the "gray zones."  Naturally,
  1343. new users don't know what the gray zones are; this section attempts to
  1344. indicate those that are currently known.  The descriptions mostly deal
  1345. with Version 3.23 of `MySQL Server'.  All known and reported bugs are
  1346. fixed in the latest version, with the exception of those listed in the
  1347. bugs section, which are things that are design-related.  *Note Bugs::.
  1348.  
  1349. The `MySQL Server' design is multi-layered with independent modules.
  1350. Some of the newer modules are listed here with an indication of how
  1351. well-tested each of them is:
  1352.  
  1353. *Replication - Gamma*
  1354.      Large server clusters using replication are in production use, with
  1355.      good results. Work on enhanced replication features is continuing
  1356.      in `MySQL' 4.x.
  1357.  
  1358. *`InnoDB' tables - Stable (in 3.23 from 3.23.49)*
  1359.      The `InnoDB' transactional storage engine has now been declared
  1360.      stable in the `MySQL' 3.23 tree, starting from version 3.23.49.
  1361.      `InnoDB' is being used in large, heavy-load production systems.
  1362.  
  1363. *`BDB' tables - Gamma*
  1364.      The `Berkeley DB' code is very stable, but we are still improving
  1365.      the `BDB' transactional storage engine interface in `MySQL
  1366.      Server', so it will take some time before this is as well tested
  1367.      as the other table types.
  1368.  
  1369. *`FULLTEXT' - Beta*
  1370.      Full-text search works but is not yet widely used.  Important
  1371.      enhancements are being implemented for `MySQL' 4.0.
  1372.  
  1373. *`MyODBC 2.50' (uses ODBC SDK 2.5) - Gamma*
  1374.      Increasingly in wide use. Some issues brought up appear to be
  1375.      application-related and independent of the ODBC driver or
  1376.      underlying database server.
  1377.  
  1378. *Automatic recovery of `MyISAM' tables - Gamma*
  1379.      This status only regards the new code in the `MyISAM' storage
  1380.      engine that checks if the table was closed properly on open and
  1381.      executes an automatic check/repair of the table if it wasn't.
  1382.  
  1383. *Bulk-insert - Alpha*
  1384.      New feature in `MyISAM' tables in `MySQL' 4.0 for faster insert of
  1385.      many rows.
  1386.  
  1387. *Locking - Gamma*
  1388.      This is very system-dependent.  On some systems there are big
  1389.      problems using standard OS locking (`fcntl()').  In these cases,
  1390.      you should run `mysqld' with the `--skip-external-locking' flag.
  1391.      Problems are known to occur on some Linux systems, and on SunOS
  1392.      when using NFS-mounted filesystems.
  1393.  
  1394. `MySQL AB' provides high-quality support for paying customers, but the
  1395. `MySQL' mailing list usually provides answers to common questions. Bugs
  1396. are usually fixed right away with a patch; for serious bugs, there is
  1397. almost always a new release.
  1398.  
  1399. How Big Can MySQL Tables Be?
  1400. ----------------------------
  1401.  
  1402. `MySQL' Version 3.22 has a 4G limit on table size. With the new
  1403. `MyISAM' table type in `MySQL' Version 3.23, the maximum table size is
  1404. pushed up to 8 million terabytes (2 ^ 63 bytes).
  1405.  
  1406. Note, however, that operating systems have their own file-size limits.
  1407. Here are some examples:
  1408.  
  1409. *Operating System*     *File-Size Limit*
  1410. Linux-Intel 32 bit     2G, 4G or more, depends on Linux
  1411.                        version
  1412. Linux-Alpha            8T (?)
  1413. Solaris 2.5.1          2G (possible 4G with patch)
  1414. Solaris 2.6            4G (can be changed with flag)
  1415. Solaris 2.7 Intel      4G
  1416. Solaris 2.7            512G
  1417. UltraSPARC             
  1418.  
  1419. On Linux 2.2 you can get bigger tables than 2G by using the LFS patch
  1420. for the ext2 filesystem.  On Linux 2.4 patches also exist for ReiserFS
  1421. to get support for big files.
  1422.  
  1423. This means that the table size for `MySQL' databases is normally
  1424. limited by the operating system.
  1425.  
  1426. By default, `MySQL' tables have a maximum size of about 4G.  You can
  1427. check the maximum table size for a table with the `SHOW TABLE STATUS'
  1428. command or with the `myisamchk -dv table_name'.  *Note SHOW::.
  1429.  
  1430. If you need bigger tables than 4G (and your operating system supports
  1431. this), you should set the `AVG_ROW_LENGTH' and `MAX_ROWS' parameter
  1432. when you create your table.  *Note CREATE TABLE::.  You can also set
  1433. these later with `ALTER TABLE'. *Note ALTER TABLE::.
  1434.  
  1435. If your big table is going to be read-only, you could use `myisampack'
  1436. to merge and compress many tables to one.  `myisampack' usually
  1437. compresses a table by at least 50%, so you can have, in effect, much
  1438. bigger tables.  *Note `myisampack': myisampack.
  1439.  
  1440. You can go around the operating system file limit for `MyISAM' data
  1441. files by using the `RAID' option. *Note CREATE TABLE::.
  1442.  
  1443. Another solution can be the included `MERGE' library, which allows you
  1444. to handle a collection of identical tables as one.  *Note `MERGE'
  1445. tables: MERGE.
  1446.  
  1447. Year 2000 Compliance
  1448. --------------------
  1449.  
  1450. The `MySQL Server' itself has no problems with Year 2000 (Y2K)
  1451. compliance:
  1452.  
  1453.    * `MySQL Server' uses Unix time functions and has no problems with
  1454.      dates until `2069'; all 2-digit years are regarded to be in the
  1455.      range `1970' to `2069', which means that if you store `01' in a
  1456.      `year' column, `MySQL Server' treats it as `2001'.
  1457.  
  1458.    * All `MySQL' date functions are stored in one file, `sql/time.cc',
  1459.      and are coded very carefully to be year 2000-safe.
  1460.  
  1461.    * In `MySQL' Version 3.22 and later, the new `YEAR' column type can
  1462.      store years `0' and `1901' to `2155' in 1 byte and display them
  1463.      using 2 or 4 digits.
  1464.  
  1465. You may run into problems with applications that use `MySQL Server' in
  1466. a way that is not Y2K-safe.  For example, many old applications store
  1467. or manipulate years using 2-digit values (which are ambiguous) rather
  1468. than 4-digit values.  This problem may be compounded by applications
  1469. that use values such as `00' or `99' as "missing" value indicators.
  1470.  
  1471. Unfortunately, these problems may be difficult to fix because different
  1472. applications may be written by different programmers, each of whom may
  1473. use a different set of conventions and date-handling functions.
  1474.  
  1475. Here is a simple demonstration illustrating that `MySQL Server' doesn't
  1476. have any problems with dates until the year 2030:
  1477.  
  1478.      mysql> DROP TABLE IF EXISTS y2k;
  1479.      Query OK, 0 rows affected (0.01 sec)
  1480.      
  1481.      mysql> CREATE TABLE y2k (date DATE,
  1482.          ->                   date_time DATETIME,
  1483.          ->                   time_stamp TIMESTAMP);
  1484.      Query OK, 0 rows affected (0.00 sec)
  1485.      
  1486.      mysql> INSERT INTO y2k VALUES
  1487.          -> ("1998-12-31","1998-12-31 23:59:59",19981231235959),
  1488.          -> ("1999-01-01","1999-01-01 00:00:00",19990101000000),
  1489.          -> ("1999-09-09","1999-09-09 23:59:59",19990909235959),
  1490.          -> ("2000-01-01","2000-01-01 00:00:00",20000101000000),
  1491.          -> ("2000-02-28","2000-02-28 00:00:00",20000228000000),
  1492.          -> ("2000-02-29","2000-02-29 00:00:00",20000229000000),
  1493.          -> ("2000-03-01","2000-03-01 00:00:00",20000301000000),
  1494.          -> ("2000-12-31","2000-12-31 23:59:59",20001231235959),
  1495.          -> ("2001-01-01","2001-01-01 00:00:00",20010101000000),
  1496.          -> ("2004-12-31","2004-12-31 23:59:59",20041231235959),
  1497.          -> ("2005-01-01","2005-01-01 00:00:00",20050101000000),
  1498.          -> ("2030-01-01","2030-01-01 00:00:00",20300101000000),
  1499.          -> ("2050-01-01","2050-01-01 00:00:00",20500101000000);
  1500.      Query OK, 13 rows affected (0.01 sec)
  1501.      Records: 13  Duplicates: 0  Warnings: 0
  1502.      
  1503.      mysql> SELECT * FROM y2k;
  1504.      +------------+---------------------+----------------+
  1505.      | date       | date_time           | time_stamp     |
  1506.      +------------+---------------------+----------------+
  1507.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1508.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1509.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1510.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1511.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1512.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1513.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1514.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1515.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1516.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1517.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  1518.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  1519.      | 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
  1520.      +------------+---------------------+----------------+
  1521.      13 rows in set (0.00 sec)
  1522.  
  1523. This shows that the `DATE' and `DATETIME' types will not give any
  1524. problems with future dates (they handle dates until the year 9999).
  1525.  
  1526. The `TIMESTAMP' type, which is used to store the current time, has a
  1527. range up to only `2030-01-01'.  `TIMESTAMP' has a range of `1970' to
  1528. `2030' on 32-bit machines (signed value).  On 64-bit machines it
  1529. handles times up to `2106' (unsigned value).
  1530.  
  1531. Even though `MySQL Server' is Y2K-compliant, it is your responsibility
  1532. to provide unambiguous input.  See *Note Y2K issues:: for `MySQL
  1533. Server''s rules for dealing with ambiguous date input data (data
  1534. containing 2-digit year values).
  1535.  
  1536. What Is MySQL AB?
  1537. =================
  1538.  
  1539. `MySQL AB' is the company of the `MySQL' founders and main developers.
  1540. `MySQL AB' was originally established in Sweden by David Axmark, Allan
  1541. Larsson, and Michael `Monty' Widenius.
  1542.  
  1543. All the developers of the `MySQL' server are employed by the company.
  1544. We are a virtual organisation with people in a dozen countries around
  1545. the world. We communicate extensively over the Net every day with each
  1546. other and with our users, supporters and partners.
  1547.  
  1548. We are dedicated to developing the `MySQL' software and spreading our
  1549. database to new users. `MySQL AB' owns the copyright to the `MySQL'
  1550. source code, the `MySQL' logo and trademark, and this manual. *Note
  1551. What-is::.
  1552.  
  1553. The `MySQL' core values show our dedication to `MySQL' and `Open
  1554. Source'.
  1555.  
  1556. We want the `MySQL Database Software' to be:
  1557.    * The best and the most widely used database in the world.
  1558.  
  1559.    * Available and affordable for all.
  1560.  
  1561.    * Easy to use.
  1562.  
  1563.    * Continuously improving while remaining fast and safe.
  1564.  
  1565.    * Fun to use and improve.
  1566.  
  1567.    * Free from bugs.
  1568.  
  1569. `MySQL AB' and the people at `MySQL AB':
  1570.    * Promote `Open Source' philosophy and support the `Open Source'
  1571.      community.
  1572.  
  1573.    * Aim to be good citizens.
  1574.  
  1575.    * Prefer partners that share our values and mind-set.
  1576.  
  1577.    * Answer e-mail and provide support.
  1578.  
  1579.    * Are a virtual company, networking with others.
  1580.  
  1581.    * Work against software patents.
  1582.  
  1583. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1584. information about `MySQL' and `MySQL AB'.
  1585.  
  1586. The Business Model and Services of MySQL AB
  1587. -------------------------------------------
  1588.  
  1589. One of the most common questions we encounter is: "_How can you make a
  1590. living from something you give away for free?_" This is how.
  1591.  
  1592. `MySQL AB' makes money on support, services, commercial licenses, and
  1593. royalties, and we use these revenues to fund product development and to
  1594. expand the `MySQL' business.
  1595.  
  1596. The company has been profitable since its inception. In October 2001,
  1597. we accepted venture financing from leading Scandinavian investors and a
  1598. handful of business angels. This investment is used to solidify our
  1599. business model and build a basis for sustainable growth.
  1600.  
  1601. Support
  1602. .......
  1603.  
  1604. `MySQL AB' is run and owned by the founders and main developers of the
  1605. `MySQL' database. The developers are committed to giving support to
  1606. customers and other users in order to stay in touch with their needs
  1607. and problems. All our support is given by qualified developers. Really
  1608. tricky questions are answered by Michael `Monty' Widenius, principal
  1609. author of the `MySQL Server'.  *Note Support::.
  1610.  
  1611. For more information and ordering support at various levels, see
  1612. `http://www.mysql.com/support/' or contact our sales staff at
  1613. <sales@mysql.com>.
  1614.  
  1615. Training and Certification
  1616. ..........................
  1617.  
  1618. `MySQL AB' delivers `MySQL' and related training worldwide.  We offer
  1619. both open courses and in-house courses tailored to the specific needs
  1620. of your company. `MySQL Training' is also available through our
  1621. partners, the `Authorised MySQL Training Centers'.
  1622.  
  1623. Our training material uses the same example databases as our
  1624. documentation and our sample applications, and it is always updated to
  1625. reflect the latest `MySQL' version. Our trainers are backed by the
  1626. development team to guarantee the quality of the training and the
  1627. continuous development of the course material. This also ensures that
  1628. no questions raised during the courses remain unanswered.
  1629.  
  1630. Attending our training courses will enable you to achieve your goals
  1631. related to your `MySQL' applications. You will also:
  1632.    * Save time.
  1633.  
  1634.    * Improve the performance of your application(s).
  1635.  
  1636.    * Reduce or eliminate the need for additional hardware, decreasing
  1637.      cost.
  1638.  
  1639.    * Enhance security.
  1640.  
  1641.    * Increase customers' and co-workers' satisfaction.
  1642.  
  1643.    * Prepare yourself for `MySQL Certification'.
  1644.  
  1645. If you are interested in our training as a potential participant or as
  1646. a training partner, please visit the training section at
  1647. `http://www.mysql.com/training/' or contact us at: <training@mysql.com>.
  1648.  
  1649. The `MySQL Certification Program' is being released in the second half
  1650. of 2002. For details please see `http://www.mysql.com/certification/'.
  1651.  
  1652. Consulting
  1653. ..........
  1654.  
  1655. `MySQL AB' and its `Authorised Partners' offer consulting services to
  1656. users of `MySQL Server' and to those who embed `MySQL Server' in their
  1657. own software, all over the world.
  1658.  
  1659. Our consultants can help you design and tune your databases, construct
  1660. efficient queries, tune your platform for optimal performance, resolve
  1661. migration issues, set up replication, build robust transactional
  1662. applications, and more.  We also help customers embed `MySQL Server' in
  1663. their products and applications for large-scale deployment.
  1664.  
  1665. Our consultants work in close collaboration with our development team,
  1666. which ensures the technical quality of our professional services.
  1667. Consulting assignments range from 2-day power-start sessions to
  1668. projects that span weeks and months. Our expertise not only covers
  1669. `MySQL Server', but also extends into programming and scripting
  1670. languages such as PHP, Perl, and more.
  1671.  
  1672. If you are interested in our consulting services or want to become a
  1673. consulting partner, please visit the consulting section of our web site
  1674. at `http://www.mysql.com/consulting/' or contact our consulting staff
  1675. at <consulting@mysql.com>.
  1676.  
  1677. Commercial Licenses
  1678. ...................
  1679.  
  1680. The `MySQL' database is released under the `GNU General Public License'
  1681. (`GPL').  This means that the `MySQL' software can be used free of
  1682. charge under the `GPL'. If you do not want to be bound by the `GPL'
  1683. terms (like the requirement that your own application becomes `GPL' as
  1684. well), you may purchase a commercial license for the same product from
  1685. `MySQL AB'.  See `http://www.mysql.com/products/pricing.html'.  Since
  1686. `MySQL AB' owns the copyright to the `MySQL' source code, we are able
  1687. to employ `Dual Licensing' which means that the same product is
  1688. available under `GPL' and under a commercial license. This does not in
  1689. any way affect the `Open Source' commitment of `MySQL AB'. For details
  1690. about when a commercial license is required, please see *Note MySQL
  1691. licenses::.
  1692.  
  1693. We also sell commercial licenses of third-party `Open Source GPL'
  1694. software that adds value to `MySQL Server'. A good example is the
  1695. `InnoDB' transactional storage engine that offers `ACID' support,
  1696. row-level locking, crash recovery, multi-versioning, foreign key
  1697. support, and more. *Note InnoDB::.
  1698.  
  1699. Partnering
  1700. ..........
  1701.  
  1702. `MySQL AB' has a worldwide partner programme that covers training
  1703. courses, consulting & support, publications plus reselling and
  1704. distributing `MySQL' and related products. `MySQL AB Partners' get
  1705. visibility on the `http://www.mysql.com/' web site and the right to use
  1706. special versions of the `MySQL' trademarks to identify their products
  1707. and promote their business.
  1708.  
  1709. If you are interested in becoming a `MySQL AB Partner', please e-mail
  1710. <partner@mysql.com>.
  1711.  
  1712. The word `MySQL' and the `MySQL' dolphin logo are trademarks of `MySQL
  1713. AB'. *Note MySQL AB Logos and Trademarks::.  These trademarks represent
  1714. a significant value that the `MySQL' founders have built over the years.
  1715.  
  1716. Advertising
  1717. ...........
  1718.  
  1719. The `MySQL' web site (`http://www.mysql.com/') is popular among
  1720. developers and users. In October 2001, we served 10 million page views.
  1721. Our visitors represent a group that makes purchase decisions and
  1722. recommendations for both software and hardware. Twelve percent of our
  1723. visitors authorise purchase decisions, and only nine percent are not
  1724. involved in purchase decisions at all. More than 65% have made one or
  1725. more online business purchase within the last half-year, and 70% plan
  1726. to make one in the next months.
  1727.  
  1728. Contact Information
  1729. -------------------
  1730.  
  1731. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1732. information about `MySQL' and `MySQL AB'.
  1733.  
  1734. For press service and inquiries not covered in our News releases
  1735. (`http://www.mysql.com/news/'), please send e-mail to <press@mysql.com>.
  1736.  
  1737. If you have a valid support contract with `MySQL AB', you will get
  1738. timely, precise answers to your technical questions about the `MySQL'
  1739. software. For more information, see *Note Support::.  On our website,
  1740. see `http://www.mysql.com/support/', or send an e-mail message to
  1741. <sales@mysql.com>.
  1742.  
  1743. For information about `MySQL' training, please visit the training
  1744. section at `http://www.mysql.com/training/'. If you have restricted
  1745. access to the Internet, please contact the `MySQL AB' training staff at
  1746. <training@mysql.com>.  *Note Business Services Training::.
  1747.  
  1748. For information on the `MySQL Certification Program', please see
  1749. `http://www.mysql.com/certification/'.  *Note Business Services
  1750. Training::.
  1751.  
  1752. If you're interested in consulting, please visit the consulting section
  1753. at `http://www.mysql.com/consulting/'. If you have restricted access to
  1754. the Internet, please contact the `MySQL AB' consulting staff at
  1755. <consulting@mysql.com>.  *Note Business Services Consulting::.
  1756.  
  1757. Commercial licenses may be purchased online at
  1758. `https://order.mysql.com/'. There you will also find information on how
  1759. to fax your purchase order to `MySQL AB'. More information about
  1760. licensing can be found at `http://www.mysql.com/products/pricing.html'.
  1761. If you have questions regarding licensing or you want a quote for a
  1762. high-volume license deal, please fill in the contact form on our web
  1763. site (`http://www.mysql.com/') or send an e-mail message to
  1764. <licensing@mysql.com> (for licensing questions) or to <sales@mysql.com>
  1765. (for sales inquiries).  *Note MySQL licenses::.
  1766.  
  1767. If you represent a business that is interested in partnering with
  1768. `MySQL AB', please send e-mail to <partner@mysql.com>.  *Note Business
  1769. Services Partnering::.
  1770.  
  1771. For more information on the `MySQL' trademark policy, refer to
  1772. `http://www.mysql.com/company/trademark.html' or send e-mail to
  1773. <trademark@mysql.com>.  *Note MySQL AB Logos and Trademarks::.
  1774.  
  1775. If you are interested in any of the `MySQL AB' jobs listed in our jobs
  1776. section (`http://www.mysql.com/company/jobs/'), please send an e-mail
  1777. message to <jobs@mysql.com>.  Please do not send your CV as an
  1778. attachment, but rather as plain text at the end of your e-mail message.
  1779.  
  1780. For general discussion among our many users, please direct your
  1781. attention to the appropriate mailing list.  *Note Questions::.
  1782.  
  1783. Reports of errors (often called bugs), as well as questions and
  1784. comments, should be sent to the mailing list at
  1785. <mysql@lists.mysql.com>. If you have found a sensitive security bug in
  1786. the `MySQL Server', please send an e-mail to <security@mysql.com>.
  1787. *Note Bug reports::.
  1788.  
  1789. If you have benchmark results that we can publish, please contact us at
  1790. <benchmarks@mysql.com>.
  1791.  
  1792. If you have any suggestions concerning additions or corrections to this
  1793. manual, please send them to the manual team at <docs@mysql.com>.
  1794.  
  1795. For questions or comments about the workings or content of the `MySQL'
  1796. web site (`http://www.mysql.com/'), please send e-mail to
  1797. <webmaster@mysql.com>.
  1798.  
  1799. `MySQL AB' has a privacy policy, which can be read at
  1800. `http://www.mysql.com/company/privacy.html'.  For any queries regarding
  1801. this policy, please e-mail <privacy@mysql.com>.
  1802.  
  1803. For all other inquires, please send e-mail to <info@mysql.com>.
  1804.  
  1805. MySQL Support and Licensing
  1806. ===========================
  1807.  
  1808. This section describes `MySQL' support and licensing arrangements.
  1809.  
  1810. Support Offered by MySQL AB
  1811. ---------------------------
  1812.  
  1813. Technical support from `MySQL AB' means individualised answers to your
  1814. unique problems direct from the software engineers who code the `MySQL'
  1815. database engine.
  1816.  
  1817. We try to take a broad and inclusive view of technical support. Almost
  1818. any problem involving `MySQL' software is important to us if it's
  1819. important to you.  Typically customers seek help on how to get
  1820. different commands and utilities to work, remove performance
  1821. bottlenecks, restore crashed systems, understand operating system or
  1822. networking impacts on `MySQL', set up best practices for backup and
  1823. recovery, utilise `API's, etc.  Our support covers only the `MySQL'
  1824. server and our own utilities, not third-party products that access the
  1825. `MySQL' server, though we try to help with these where we can.
  1826.  
  1827. Detailed information about our various support options is given at
  1828. `http://www.mysql.com/support/', where support contracts can also be
  1829. ordered online. If you have restricted access to the Internet, contact
  1830. our sales staff at <sales@mysql.com>.
  1831.  
  1832. Technical support is like life insurance. You can live happily without
  1833. it for years, but when your hour arrives it becomes critically
  1834. important, yet it's too late to buy it!  If you use `MySQL' Server for
  1835. important applications and encounter sudden troubles,  it might take
  1836. too long to figure out all the answers yourself. You may need immediate
  1837. access to the most experienced `MySQL' troubleshooters available, those
  1838. employed by `MySQL AB'.
  1839.  
  1840. Copyrights and Licenses Used by MySQL
  1841. -------------------------------------
  1842.  
  1843. `MySQL AB' owns the copyright to the `MySQL' source code, the `MySQL'
  1844. logos and trademarks and this manual.  *Note What is MySQL AB::.
  1845. Several different licenses are relevant to the `MySQL' distribution:
  1846.  
  1847.   1. All the `MySQL'-specific source in the server, the `mysqlclient'
  1848.      library and the client, as well as the `GNU' `readline' library is
  1849.      covered by the `GNU General Public License'.  *Note GPL license::.
  1850.      The text of this license can also be found as the file `COPYING'
  1851.      in the distributions.
  1852.  
  1853.   2. The `GNU' `getopt' library is covered by the `GNU Lesser General
  1854.      Public License'.  *Note LGPL license::.
  1855.  
  1856.   3. Some parts of the source (the `regexp' library) are covered by a
  1857.      Berkeley-style copyright.
  1858.  
  1859.   4. Older versions of `MySQL' (3.22 and earlier) are subject to a more
  1860.      strict license (`http://www.mysql.com/products/mypl.html').  See
  1861.      the documentation of the specific version for information.
  1862.  
  1863.   5. The manual is currently *not* distributed under a `GPL'-style
  1864.      license.  Use of the manual is subject to the following terms:
  1865.         * Conversion to other formats is allowed, but the actual content
  1866.           may not be altered or edited in any way.
  1867.  
  1868.         * You may create a printed copy for your own personal use.
  1869.  
  1870.         * For all other uses, such as selling printed copies or using
  1871.           (parts of) the manual in another publication, prior written
  1872.           agreement from `MySQL AB' is required.
  1873.      Please e-mail <docs@mysql.com> for more information or if you are
  1874.      interested in doing a translation.
  1875.  
  1876. For information about how the `MySQL' licenses work in practice, please
  1877. refer to *Note MySQL licenses::.  Also see *Note MySQL AB Logos and
  1878. Trademarks::.
  1879.  
  1880. MySQL Licenses
  1881. --------------
  1882.  
  1883. The `MySQL' software is released under the `GNU General Public License'
  1884. (`GPL'), which probably is the best known `Open Source' license.  The
  1885. formal terms of the `GPL' license can be found at
  1886. `http://www.gnu.org/licenses/'.  See also
  1887. `http://www.gnu.org/licenses/gpl-faq.html' and
  1888. `http://www.gnu.org/philosophy/enforcing-gpl.html'.
  1889.  
  1890. Since the `MySQL' software is released under the `GPL', it may often be
  1891. used for free, but for certain uses you may want or need to buy
  1892. commercial licenses from `MySQL AB' at `https://order.mysql.com/'.  See
  1893. `http://www.mysql.com/products/licensing.html' for more information.
  1894.  
  1895. Older versions of `MySQL' (3.22 and earlier) are subject to a more
  1896. strict license (`http://www.mysql.com/products/mypl.html').  See the
  1897. documentation of the specific version for information.
  1898.  
  1899. Please note that the use of the `MySQL' software under commercial
  1900. license, `GPL', or the old `MySQL' license does not automatically give
  1901. you the right to use `MySQL AB' trademarks.  *Note MySQL AB Logos and
  1902. Trademarks::.
  1903.  
  1904. Using the MySQL Software Under a Commercial License
  1905. ...................................................
  1906.  
  1907. The `GPL' license is contagious in the sense that when a program is
  1908. linked to a `GPL' program all the source code for all the parts of the
  1909. resulting product must also be released under the `GPL'.  Otherwise you
  1910. break the license terms and forfeit your right to use the `GPL' program
  1911. altogether and also risk damages.
  1912.  
  1913. You need a commercial license:
  1914.  
  1915.    * When you link a program with any `GPL' code from the `MySQL'
  1916.      software and don't want the resulting product to be `GPL', maybe
  1917.      because you want to build a commercial product or keep the added
  1918.      non-`GPL' code closed source for other reasons. When purchasing
  1919.      commercial licenses, you are not using the `MySQL' software under
  1920.      `GPL' even though it's the same code.
  1921.  
  1922.    * When you distribute a non-`GPL' application that *only* works with
  1923.      the `MySQL' software and ship it with the `MySQL' software. This
  1924.      type of solution is actually considered to be linking even if it's
  1925.      done over a network.
  1926.  
  1927.    * When you distribute copies of the `MySQL' software without
  1928.      providing the source code as required under the `GPL' license.
  1929.  
  1930.    * When you want to support the further development of the `MySQL'
  1931.      database even if you don't formally need a commercial license.
  1932.      Purchasing support directly from `MySQL AB' is another good way of
  1933.      contributing to the development of the `MySQL' software, with
  1934.      immediate advantages for you.  *Note Support::.
  1935.  
  1936. If you require a license, you will need one for each installation of the
  1937. `MySQL' software. This covers any number of CPUs on a machine, and there
  1938. is no artificial limit on the number of clients that connect to the
  1939. server in any way.
  1940.  
  1941. For commercial licenses, please visit our website at
  1942. `http://www.mysql.com/products/licensing.html'.  For support contracts,
  1943. see `http://www.mysql.com/support/'.  If you have special needs or you
  1944. have restricted access to the Internet, please contact our sales staff
  1945. at <sales@mysql.com>.
  1946.  
  1947. Using the MySQL Software for Free Under GPL
  1948. ...........................................
  1949.  
  1950. You can use the `MySQL' software for free under the `GPL' if you adhere
  1951. to the conditions of the `GPL'.  For more complete coverage of the
  1952. common questions about the `GPL' see the generic FAQ from the Free
  1953. Software Foundation at `http://www.gnu.org/licenses/gpl-faq.html'.
  1954. Some common cases:
  1955.  
  1956.    * When you distribute both your own application as well as the
  1957.      `MySQL' source code under the `GPL' with your product.
  1958.  
  1959.    * When you distribute the `MySQL' source code bundled with other
  1960.      programs that are not linked to or dependent on the `MySQL' system
  1961.      for their functionality even if you sell the distribution
  1962.      commercially.  This is called mere aggregation in the `GPL'
  1963.      license.
  1964.  
  1965.    * If you are not distributing *any* part of the `MySQL' system, you
  1966.      can use it for free.
  1967.  
  1968.    * When you are an Internet Service Provider (ISP), offering web
  1969.      hosting with `MySQL' servers for your customers.  However, we do
  1970.      encourage people to use ISPs that have MySQL support, as this will
  1971.      give them the confidence that if they have some problem with the
  1972.      `MySQL' installation, their ISP will in fact have the resources to
  1973.      solve the problem for them.  Note that even if an ISP does not
  1974.      have a commercial license for `MySQL Server', they should at least
  1975.      give their customers read access to the source of the `MySQL'
  1976.      installation so that the customers can verify that it is patched
  1977.      correctly.
  1978.  
  1979.    * When you use the `MySQL' Database Software in conjunction with a
  1980.      web server, you do not need a commercial license (so long as it is
  1981.      not a product you distribute). This is true even if you run a
  1982.      commercial web server that uses `MySQL Server', because you are not
  1983.      distributing any part of the `MySQL' system. However, in this case
  1984.      we would like you to purchase `MySQL' support because the `MySQL'
  1985.      software is helping your enterprise.
  1986.  
  1987. If your use of `MySQL' database software does not require a commercial
  1988. license, we encourage you to purchase support from `MySQL AB' anyway.
  1989. This way you contribute toward `MySQL' development and also gain
  1990. immediate advantages for yourself. *Note Support::.
  1991.  
  1992. If you use the `MySQL' database software in a commercial context such
  1993. that you profit by its use, we ask that you further the development of
  1994. the `MySQL' software by purchasing some level of support.  We feel that
  1995. if the `MySQL' database helps your business, it is reasonable to ask
  1996. that you help `MySQL AB'.  (Otherwise, if you ask us support questions,
  1997. you are not only using for free something into which we've put a lot a
  1998. work, you're asking us to provide free support, too.)
  1999.  
  2000. MySQL AB Logos and Trademarks
  2001. -----------------------------
  2002.  
  2003. Many users of the `MySQL' database want to display the `MySQL AB'
  2004. dolphin logo on their web sites, books, or boxed products. We welcome
  2005. and encourage this, although it should be noted that the word `MySQL'
  2006. and the `MySQL' dolphin logo are trademarks of `MySQL AB' and may only
  2007. be used as stated in our trademark policy at
  2008. `http://www.mysql.com/company/trademark.html'.
  2009.  
  2010. The Original MySQL Logo
  2011. .......................
  2012.  
  2013. The `MySQL' dolphin logo was designed by the Finnish advertising agency
  2014. Priority in 2001.  The dolphin was chosen as a suitable symbol for the
  2015. `MySQL' database since it is a smart, fast, and lean animal,
  2016. effortlessly navigating oceans of data. We also happen to like dolphins.
  2017.  
  2018. The original `MySQL' logo may only be used by representatives of `MySQL
  2019. AB' and by those having a written agreement allowing them to do so.
  2020.  
  2021. MySQL Logos that may be Used Without Written Permission
  2022. .......................................................
  2023.  
  2024. We have designed a set of special _Conditional Use_ logos that may be
  2025. downloaded from our web site at `http://www.mysql.com/press/logos.html'
  2026. and used on third-party web sites without written permission from
  2027. `MySQL AB'.  The use of these logos is not entirely unrestricted but,
  2028. as the name implies, subject to our trademark policy that is also
  2029. available on our web site. You should read through the trademark policy
  2030. if you plan to use them. The requirements are basically:
  2031.  
  2032.    * Use the logo you need as displayed on the `http://www.mysql.com/'
  2033.      site. You may scale it to fit your needs, but not change colours
  2034.      or design, or alter the graphics in any way.
  2035.  
  2036.    * Make it evident that you, and not `MySQL AB', are the creator and
  2037.      owner of the site that displays the `MySQL' trademark.
  2038.  
  2039.    * Don't use the trademark in a way that is detrimental to `MySQL AB'
  2040.      or to the value of `MySQL AB' trademarks. We reserve the right to
  2041.      revoke the right to use the `MySQL AB' trademark.
  2042.  
  2043.    * If you use the trademark on a web site, make it clickable, leading
  2044.      directly to `http://www.mysql.com/'.
  2045.  
  2046.    * If you are using the `MySQL' database under `GPL' in an
  2047.      application, your application must be `Open Source' and be able to
  2048.      connect to a `MySQL' server.
  2049.  
  2050. Contact us at <trademark@mysql.com> to inquire about special
  2051. arrangements to fit your needs.
  2052.  
  2053. When do you need a Written Permission to use MySQL Logos?
  2054. .........................................................
  2055.  
  2056. In the following cases you need a written permission from `MySQL AB'
  2057. before using `MySQL' logos:
  2058.  
  2059.    * When displaying any `MySQL AB' logo anywhere except on your web
  2060.      site.
  2061.  
  2062.    * When displaying any `MySQL AB' logo except the _Conditional Use_
  2063.      logos mentioned previously on web sites or elsewhere.
  2064.  
  2065. Out of legal and commercial reasons we have to monitor the use of MySQL
  2066. trademarks on products, books, etc. We will usually require a fee for
  2067. displaying `MySQL AB' logos on commercial products, since we think it
  2068. is reasonable that some of the revenue is returned to fund further
  2069. development of the `MySQL' database.
  2070.  
  2071. MySQL AB Partnership Logos
  2072. ..........................
  2073.  
  2074. `MySQL' partnership logos may only be used by companies and persons
  2075. having a written partnership agreement with `MySQL AB'. Partnerships
  2076. include certification as a `MySQL' trainer or consultant.  Please see
  2077. *Note Partnering: Business Services Partnering.
  2078.  
  2079. Using the word `MySQL' in Printed Text or Presentations
  2080. .......................................................
  2081.  
  2082. `MySQL AB' welcomes references to the `MySQL' database, but note that
  2083. the word `MySQL' is a trademark of `MySQL AB'.  Because of this, you
  2084. should append the trademark symbol (`TM') to the first or most
  2085. prominent use of the word `MySQL' in a text and where appropriate,
  2086. state that `MySQL' is a trademark of `MySQL AB'. Please refer to our
  2087. trademark policy at `http://www.mysql.com/company/trademark.html' for
  2088. details.
  2089.  
  2090. Using the word `MySQL' in Company and Product Names
  2091. ...................................................
  2092.  
  2093. Use of the word `MySQL' in product or company names or in Internet
  2094. domain names is not allowed without written permission from `MySQL AB'.
  2095.  
  2096. MySQL 4.x In A Nutshell
  2097. =======================
  2098.  
  2099. Long promised by `MySQL AB' and long awaited by our users, MySQL Server
  2100. 4.0 is now available in beta version for download from
  2101. `http://www.mysql.com/' and our mirrors.
  2102.  
  2103. Main new features of MySQL Server 4.0 are geared toward our existing
  2104. business and community users, enhancing the MySQL database software as
  2105. the solution for mission-critical, heavy-load database systems.  Other
  2106. new features target the users of embedded databases.
  2107.  
  2108. Stepwise Rollout
  2109. ----------------
  2110.  
  2111. MySQL is starting from 4.0.6 been labelled gamma, which means that 4.0.x
  2112. has been available more than 2 months (first in alpha and then in beta)
  2113. without any found serious hard to fix bugs and should now be ready for
  2114. production use.
  2115.  
  2116. We will drop the gamma prefix when MySQL 4.0 has been out for more than
  2117. a month without any serious bugs.
  2118.  
  2119. Further new features are being added in MySQL 4.1, which is now
  2120. available from our bk source tree, and is targeted for alpha release in
  2121. first quarter of 2003. *Note Installing source tree::.
  2122.  
  2123. Ready for Immediate Use
  2124. -----------------------
  2125.  
  2126. All binary releases pass our extensive test suite without any errors on
  2127. any of the platforms we test on.  MySQL 4.0 has been tested on by a
  2128. large number of users and is in production used by several big sites.
  2129.  
  2130. Embedded MySQL
  2131. --------------
  2132.  
  2133. `libmysqld' makes MySQL Server suitable for a vastly expanded realm of
  2134. applications. Using the embedded MySQL server library, one can embed
  2135. MySQL Server into various applications and electronics devices, where
  2136. the end user has no knowledge of there actually being an underlying
  2137. database. Embedded MySQL Server is ideal for use behind the scenes in
  2138. Internet appliances, public kiosks, turnkey hardware/software
  2139. combination units, high performance Internet servers, self-contained
  2140. databases distributed on CD-ROM, etc.
  2141.  
  2142. Many users of `libmysqld' will benefit from the MySQL _Dual Licensing_.
  2143. For those not wishing to be bound by the GPL, the software is also made
  2144. available under a commercial license.  The embedded MySQL library uses
  2145. the same interface as the normal client library, so it is convenient
  2146. and easy to use. *Note libmysqld::.
  2147.  
  2148. Other Features Available From MySQL 4.0
  2149. ---------------------------------------
  2150.  
  2151.    * Version 4.0 further increases _the speed of MySQL Server_ in a
  2152.      number of areas, such as bulk `INSERT's, searching on packed
  2153.      indexes, creation of `FULLTEXT' indexes, as well as
  2154.      `COUNT(DISTINCT)'.
  2155.  
  2156.    * The `InnoDB' storage engine is now offered as a feature of the
  2157.      standard MySQL server, including full support for `transactions'
  2158.      and `row-level locking'.
  2159.  
  2160.    * Our German, Austrian, and Swiss users will note that we have a new
  2161.      character set, `latin1_de', which corrects the _German sorting
  2162.      order_, placing German umlauts in the same order as German
  2163.      telephone books.
  2164.  
  2165.    * Features to simplify migration from other database systems to MySQL
  2166.      Server include `TRUNCATE TABLE' (like in Oracle) and `IDENTITY' as
  2167.      a synonym for automatically incremented keys (like in Sybase).
  2168.      Many users will also be happy to learn that MySQL Server now
  2169.      supports the `UNION' statement, a long-awaited standard SQL
  2170.      feature.
  2171.  
  2172.    * In the process of building features for new users, we have not
  2173.      forgotten requests by the community of loyal users.  We have
  2174.      multi-table `DELETE' and `UPDATE' statements.  By adding support
  2175.      for `symbolic linking' to `MyISAM' on the table level (and not
  2176.      just the database level as before), as well as by enabling symlink
  2177.      handling by default on Windows, we hope to show that we take
  2178.      enhancement requests seriously.  Functions like
  2179.      `SQL_CALC_FOUND_ROWS' and `FOUND_ROWS()' make it possible to know
  2180.      how many rows a query would have returned without a `LIMIT' clause.
  2181.  
  2182. Future MySQL 4.x Features
  2183. -------------------------
  2184.  
  2185. For the upcoming MySQL Server 4.x releases, expect the following
  2186. features now still under development:
  2187.  
  2188.    * Mission-critical, heavy-load users of MySQL Server will appreciate
  2189.      the additions to our replication system and our online hot backup.
  2190.      Later versions of 4.x will include `fail-safe replication';
  2191.      already existing in 4.0, the `LOAD DATA FROM MASTER' command will
  2192.      soon automate slave setup. The `online backup' will make it easy
  2193.      to add a new replication slave without taking down the master, and
  2194.      have a very low performance penalty on update-heavy systems.
  2195.  
  2196.    * A convenience feature for Database Administrators is that `mysqld'
  2197.      parameters (startup options) can soon be set without taking down
  2198.      the servers.
  2199.  
  2200.    * The new `FULLTEXT' search properties of MySQL Server 4.0 enable the
  2201.      use of `FULLTEXT' indexing of large text masses with both binary
  2202.      and natural-language searching logic. Users can customise minimal
  2203.      word length and define their own stop word lists in any human
  2204.      language, enabling a new set of applications to be built on MySQL
  2205.      Server.
  2206.  
  2207.    * Many read-heavy applications will benefit from further increased
  2208.      speed through the rewritten `key cache'.
  2209.  
  2210.    * Many developers will also be happy to see the `MySQL command help'
  2211.      in the client.
  2212.  
  2213. MySQL 4.1, The Following Development Release
  2214. --------------------------------------------
  2215.  
  2216. MySQL Server 4.0 lays the foundation for the new features of MySQL
  2217. Server 4.1 and onward, such as `nested subqueries' (4.1), `stored
  2218. procedures' (5.0), and `foreign key integrity rules' for `MyISAM'
  2219. tables (5.0), which form the top of the wish list for many of our
  2220. customers.
  2221.  
  2222. After those additions, critics of the MySQL Database Server have to be
  2223. more imaginative than ever in pointing out deficiencies in the MySQL
  2224. Database Management System. For long already known for its stability,
  2225. speed, and ease of use, MySQL Server will then match the requirement
  2226. checklist of very demanding buyers.
  2227.  
  2228. MySQL Information Sources
  2229. =========================
  2230.  
  2231. MySQL Mailing Lists
  2232. -------------------
  2233.  
  2234. This section introduces you to the MySQL mailing lists, and gives some
  2235. guidelines as to how to use them. By subscribing to a mailing list, you
  2236. will receive as e-mail messages all other postings on the list, and you
  2237. will be able to send in your own questions and answers.
  2238.  
  2239. The MySQL Mailing Lists
  2240. .......................
  2241.  
  2242. To subscribe to the main MySQL mailing list, send a message to the
  2243. electronic mail address <mysql-subscribe@lists.mysql.com>.
  2244.  
  2245. To unsubscribe from the main MySQL mailing list, send a message to the
  2246. electronic mail address <mysql-unsubscribe@lists.mysql.com>.
  2247.  
  2248. Only the address to which you send your messages is significant.  The
  2249. subject line and the body of the message are ignored.
  2250.  
  2251. If your reply address is not valid, you can specify your address
  2252. explicitly, by adding a hyphen to the subscribe or unsubscribe command
  2253. word, followed by your address with the `@' character in your address
  2254. replaced by a `='.  For example, to subscribe `your_name@host.domain',
  2255. send a message to
  2256. `mysql-subscribe-your_name=host.domain@lists.mysql.com'.
  2257.  
  2258. Mail to <mysql-subscribe@lists.mysql.com> or
  2259. <mysql-unsubscribe@lists.mysql.com> is handled automatically by the
  2260. ezmlm mailing list processor.  Information about ezmlm is available at
  2261. the ezmlm web site (`http://www.ezmlm.org/').
  2262.  
  2263. To post a message to the list itself, send your message to
  2264. `mysql@lists.mysql.com'.  However, please *do not* send mail about
  2265. subscribing or unsubscribing to <mysql@lists.mysql.com> because any
  2266. mail sent to that address is distributed automatically to thousands of
  2267. other users.
  2268.  
  2269. Your local site may have many subscribers to <mysql@lists.mysql.com>.
  2270. If so, it may have a local mailing list, so messages sent from
  2271. `lists.mysql.com' to your site are propagated to the local list.  In
  2272. such cases, please contact your system administrator to be added to or
  2273. dropped from the local MySQL list.
  2274.  
  2275. If you wish to have traffic for a mailing list go to a separate mailbox
  2276. in your mail program, set up a filter based on the message headers.
  2277. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  2278. list messages.
  2279.  
  2280. The following MySQL mailing lists exist:
  2281.  
  2282. `<announce-subscribe@lists.mysql.com> announce'
  2283.      This is for announcement of new versions of MySQL and related
  2284.      programs.  This is a low-volume list all MySQL users should
  2285.      subscribe to.
  2286.  
  2287. `<mysql-subscribe@lists.mysql.com> mysql'
  2288.      The main list for general MySQL discussion.  Please note that some
  2289.      topics are better discussed on the more-specialised lists.  If you
  2290.      post to the wrong list, you may not get an answer!
  2291.  
  2292. `<mysql-digest-subscribe@lists.mysql.com> mysql-digest'
  2293.      The `mysql' list in digest form.  That means you get all individual
  2294.      messages, sent as one large mail message once a day.
  2295.  
  2296. `<bugs-subscribe@lists.mysql.com> bugs'
  2297.      On this list you should only post a full, repeatable bug report
  2298.      using the `mysqlbug' script (if you are running on Windows, you
  2299.      should include a description of the operating system and the MySQL
  2300.      version).  Preferably, you should test the problem using the
  2301.      latest stable or development version of MySQL Server before
  2302.      posting!  Anyone should be able to repeat the bug by just using
  2303.      `mysql test < script' on the included test case.  All bugs posted
  2304.      on this list will be corrected or documented in the next MySQL
  2305.      release!  If only small code changes are needed, we will also post
  2306.      a patch that fixes the problem.
  2307.  
  2308. `<bugs-digest-subscribe@lists.mysql.com> bugs-digest'
  2309.      The `bugs' list in digest form.
  2310.  
  2311. `<internals-subscribe@lists.mysql.com> internals'
  2312.      A list for people who work on the MySQL code.  On this list one
  2313.      can also discuss MySQL development and post patches.
  2314.  
  2315. `<internals-digest-subscribe@lists.mysql.com> internals-digest'
  2316.      A digest version of the `internals' list.
  2317.  
  2318. `<java-subscribe@lists.mysql.com> java'
  2319.      Discussion about the MySQL server and Java.  Mostly about the JDBC
  2320.      drivers including MySQL Connector/J.
  2321.  
  2322. `<java-digest-subscribe@lists.mysql.com> java-digest'
  2323.      A digest version of the `java' list.
  2324.  
  2325. `<win32-subscribe@lists.mysql.com> win32'
  2326.      All things concerning the MySQL software on Microsoft operating
  2327.      systems such as Windows 9x/Me/NT/2000/XP.
  2328.  
  2329. `<win32-digest-subscribe@lists.mysql.com> win32-digest'
  2330.      A digest version of the `win32' list.
  2331.  
  2332. `<myodbc-subscribe@lists.mysql.com> myodbc'
  2333.      All things about connecting to the MySQL server with ODBC.
  2334.  
  2335. `<myodbc-digest-subscribe@lists.mysql.com> myodbc-digest'
  2336.      A digest version of the `myodbc' list.
  2337.  
  2338. `<mysqlcc-subscribe@lists.mysql.com> mysqlcc'
  2339.      All things about the `MySQL Control Center' graphical client.
  2340.  
  2341. `<mysqlcc-digest-subscribe@lists.mysql.com> mysqlcc-digest'
  2342.      A digest version of the `mysqlcc' list.
  2343.  
  2344. `<plusplus-subscribe@lists.mysql.com> plusplus'
  2345.      All things concerning programming with the C++ API to MySQL.
  2346.  
  2347. `<plusplus-digest-subscribe@lists.mysql.com> plusplus-digest'
  2348.      A digest version of the `plusplus' list.
  2349.  
  2350. `<msql-mysql-modules-subscribe@lists.mysql.com> msql-mysql-modules'
  2351.      A list about the Perl support for MySQL with msql-mysql-modules.
  2352.  
  2353. `<msql-mysql-modules-digest-subscribe@lists.mysql.com> msql-mysql-modules-digest'
  2354.      A digest version of the `msql-mysql-modules' list.
  2355.  
  2356. You subscribe or unsubscribe to all lists in the same way as described
  2357. previously.  In your subscribe or unsubscribe message, just put the
  2358. appropriate mailing list name rather than `mysql'.  For example, to
  2359. subscribe to or unsubscribe from the `myodbc' list, send a message to
  2360. <myodbc-subscribe@lists.mysql.com> or
  2361. <myodbc-unsubscribe@lists.mysql.com>.
  2362.  
  2363. If you can't get an answer for your questions from the mailing list, one
  2364. option is to pay for support from MySQL AB, which will put you in
  2365. direct contact with MySQL developers. *Note Support::.
  2366.  
  2367. The following table shows some MySQL mailing in languages other than
  2368. English.  Note that these are not operated by MySQL AB, so we can't
  2369. guarantee the quality on these.
  2370.  
  2371. `<mysql-france-subscribe@yahoogroups.com> A French mailing list'
  2372.  
  2373. `<list@tinc.net> A Korean mailing list'
  2374.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2375.  
  2376. `<mysql-de-request@lists.4t2.com> A German mailing list'
  2377.      E-mail `subscribe mysql-de your@e-mail.address' to this list.  You
  2378.      can find information about this mailing list at
  2379.      `http://www.4t2.com/mysql/'.
  2380.  
  2381. `<mysql-br-request@listas.linkway.com.br> A Portugese mailing list'
  2382.      E-mail `subscribe mysql-br your@e-mail.address' to this list.
  2383.  
  2384. `<mysql-alta@elistas.net> A Spanish mailing list'
  2385.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2386.  
  2387. Asking Questions or Reporting Bugs
  2388. ..................................
  2389.  
  2390. Before posting a bug report or question, please do the following:
  2391.  
  2392.    * Start by searching the MySQL online manual at:
  2393.      `http://www.mysql.com/doc/'
  2394.      We try to keep the manual up to date by updating it frequently with
  2395.      solutions to newly found problems! The change history appendix
  2396.      (`http://www.mysql.com/doc/en/News.html') can be particularly
  2397.      useful since it is quite possible that a newer version already
  2398.      contains a solution to your problem.
  2399.  
  2400.    * Search the MySQL mailing list archives:
  2401.      `http://lists.mysql.com/'
  2402.    * You can also use `http://www.mysql.com/search/' to search all the
  2403.      web pages (including the manual) that are located at
  2404.      `http://www.mysql.com/'.
  2405.  
  2406. If you can't find an answer in the manual or the archives, check with
  2407. your local MySQL expert.  If you still can't find an answer to your
  2408. question, go ahead and read the next section about how to send mail to
  2409. <mysql@lists.mysql.com>.
  2410.  
  2411. How to Report Bugs or Problems
  2412. ..............................
  2413.  
  2414. Writing a good bug report takes patience, but doing it right the first
  2415. time saves time for us and for you.  A good bug report containing a full
  2416. test case for the bug will make it very likely that we will fix it in
  2417. the next release.  This section will help you write your report
  2418. correctly so that you don't waste your time doing things that may not
  2419. help us much or at all.
  2420.  
  2421. We encourage everyone to use the `mysqlbug' script to generate a bug
  2422. report (or a report about any problem), if possible.  `mysqlbug' can be
  2423. found in the `scripts' directory in the source distribution, or for a
  2424. binary distribution, in the `bin' directory under your MySQL
  2425. installation directory.  If you are unable to use `mysqlbug', you should
  2426. still include all the necessary information listed in this section.
  2427.  
  2428. The `mysqlbug' script helps you generate a report by determining much
  2429. of the following information automatically, but if something important
  2430. is missing, please include it with your message!  Please read this
  2431. section carefully and make sure that all the information described here
  2432. is included in your report.
  2433.  
  2434. The normal place to report bugs and problems is
  2435. <mysql@lists.mysql.com>.  If you can make a test case that clearly
  2436. demonstrates the bug, you should post it to the <bugs@lists.mysql.com>
  2437. list.  Note that on this list you should only post a full, repeatable
  2438. bug report using the `mysqlbug' script.  If you are running on Windows,
  2439. you should include a description of the operating system and the MySQL
  2440. version.  Preferably, you should test the problem using the latest
  2441. stable or development version of MySQL Server before posting!  Anyone
  2442. should be able to repeat the bug by just using "`mysql test < script'"
  2443. on the included test case or run the shell or Perl script that is
  2444. included in the bug report.  All bugs posted on the `bugs' list will be
  2445. corrected or documented in the next MySQL release!  If only small code
  2446. changes are needed to correct this problem, we will also post a patch
  2447. that fixes the problem.
  2448.  
  2449. If you have found a sensitive security bug in MySQL, you should send an
  2450. e-mail to <security@mysql.com>.
  2451.  
  2452. Remember that it is possible to respond to a message containing too much
  2453. information, but not to one containing too little.  Often people omit
  2454. facts because they think they know the cause of a problem and assume
  2455. that some details don't matter.  A good principle is: if you are in
  2456. doubt about stating something, state it!  It is a thousand times faster
  2457. and less troublesome to write a couple of lines more in your report
  2458. than to be forced to ask again and wait for the answer because you
  2459. didn't include enough information the first time.
  2460.  
  2461. The most common errors are that people don't indicate the version
  2462. number of the MySQL distribution they are using, or don't indicate what
  2463. platform they have the MySQL server installed on (including the platform
  2464. version number).  This is highly relevant information, and in 99 cases
  2465. out of 100 the bug report is useless without it!  Very often we get
  2466. questions like, "Why doesn't this work for me?" Then we find that the
  2467. feature requested wasn't implemented in that MySQL version, or that a
  2468. bug described in a report has been fixed already in newer MySQL
  2469. versions.  Sometimes the error is platform-dependent; in such cases, it
  2470. is next to impossible to fix anything without knowing the operating
  2471. system and the version number of the platform.
  2472.  
  2473. Remember also to provide information about your compiler, if it is
  2474. related to the problem.  Often people find bugs in compilers and think
  2475. the problem is MySQL-related.  Most compilers are under development all
  2476. the time and become better version by version.  To determine whether
  2477. your problem depends on your compiler, we need to know what compiler is
  2478. used.  Note that every compiling problem should be regarded as a bug
  2479. report and reported accordingly.
  2480.  
  2481. It is most helpful when a good description of the problem is included
  2482. in the bug report.  That is, a good example of all the things you did
  2483. that led to the problem and the problem itself exactly described.  The
  2484. best reports are those that include a full example showing how to
  2485. reproduce the bug or problem.  *Note Reproduceable test case::.
  2486.  
  2487. If a program produces an error message, it is very important to include
  2488. the message in your report!  If we try to search for something from the
  2489. archives using programs, it is better that the error message reported
  2490. exactly matches the one that the program produces.  (Even the case
  2491. should be observed!)  You should never try to remember what the error
  2492. message was; instead, copy and paste the entire message into your
  2493. report!
  2494.  
  2495. If you have a problem with MyODBC, you should try to generate a MyODBC
  2496. trace file.  *Note MyODBC bug report::.
  2497.  
  2498. Please remember that many of the people who will read your report will
  2499. do so using an 80-column display.  When generating reports or examples
  2500. using the `mysql' command-line tool, you should therefore use the
  2501. `--vertical' option (or the `\G' statement terminator) for output that
  2502. would exceed the available width for such a display (for example, with
  2503. the `EXPLAIN SELECT' statement; see the example later in this section).
  2504.  
  2505. Please include the following information in your report:
  2506.  
  2507.    * The version number of the MySQL distribution you are using (for
  2508.      example, MySQL Version 3.22.22). You can find out which version you
  2509.      are running by executing `mysqladmin version'.  `mysqladmin' can be
  2510.      found in the `bin' directory under your MySQL installation
  2511.      directory.
  2512.  
  2513.    * The manufacturer and model of the machine you are working on.
  2514.  
  2515.    * The operating system name and version.  For most operating
  2516.      systems, you can get this information by executing the Unix
  2517.      command `uname -a'.
  2518.  
  2519.    * Sometimes the amount of memory (real and virtual) is relevant. If
  2520.      in doubt, include these values.
  2521.  
  2522.    * If you are using a source distribution of the MySQL software, the
  2523.      name and version number of the compiler used is needed.  If you
  2524.      have a binary distribution, the distribution name is needed.
  2525.  
  2526.    * If the problem occurs during compilation, include the exact error
  2527.      message(s) and also a few lines of context around the offending
  2528.      code in the file where the error occurred.
  2529.  
  2530.    * If `mysqld' died, you should also report the query that crashed
  2531.      `mysqld'.  You can usually find this out by running `mysqld' with
  2532.      logging enabled.  *Note Using log files::.
  2533.  
  2534.    * If any database table is related to the problem, include the
  2535.      output from `mysqldump --no-data db_name tbl_name1 tbl_name2 ...'.
  2536.      This is very easy to do and is a powerful way to get information
  2537.      about any table in a database that will help us create a situation
  2538.      matching the one you have.
  2539.  
  2540.    * For speed-related bugs or problems with `SELECT' statements, you
  2541.      should always include the output of `EXPLAIN SELECT ...', and at
  2542.      least the number of rows that the `SELECT' statement produces.  You
  2543.      should also include the output from `SHOW CREATE TABLE table_name'
  2544.      for each involved table. The more information you give about your
  2545.      situation, the more likely it is that someone can help you!  For
  2546.      example, the following is an example of a very good bug report (it
  2547.      should of course be posted with the `mysqlbug' script):
  2548.  
  2549.      Example run using the `mysql' command-line tool (note the use of
  2550.      the `\G' statement terminator for statements whose output width
  2551.      would otherwise exceed that of an 80-column display device):
  2552.  
  2553.           mysql> SHOW VARIABLES;
  2554.           mysql> SHOW COLUMNS FROM ...\G
  2555.                  <output from SHOW COLUMNS>
  2556.           mysql> EXPLAIN SELECT ...\G
  2557.                  <output from EXPLAIN>
  2558.           mysql> FLUSH STATUS;
  2559.           mysql> SELECT ...;
  2560.                  <A short version of the output from SELECT,
  2561.                  including the time taken to run the query>
  2562.           mysql> SHOW STATUS;
  2563.                  <output from SHOW STATUS>
  2564.  
  2565.    * If a bug or problem occurs while running `mysqld', try to provide
  2566.      an input script that will reproduce the anomaly.  This script
  2567.      should include any necessary source files.  The more closely the
  2568.      script can reproduce your situation, the better.  If you can make
  2569.      a reproduceable test case, you should post this to
  2570.      <bugs@lists.mysql.com> for a high-priority treatment!
  2571.  
  2572.      If you can't provide a script, you should at least include the
  2573.      output from `mysqladmin variables extended-status processlist' in
  2574.      your mail to provide some information of how your system is
  2575.      performing!
  2576.  
  2577.    * If you can't produce a test case in a few rows, or if the test
  2578.      table is too big to be mailed to the mailing list (more than 10
  2579.      rows), you should dump your tables using `mysqldump' and create a
  2580.      `README' file that describes your problem.
  2581.  
  2582.      Create a compressed archive of your files using `tar' and `gzip'
  2583.      or `zip', and use `ftp' to transfer the archive to
  2584.      `ftp://support.mysql.com/pub/mysql/secret/'.  Then send a short
  2585.      description of the problem to <bugs@lists.mysql.com>.
  2586.  
  2587.    * If you think that the MySQL server produces a strange result from
  2588.      a query, include not only the result, but also your opinion of
  2589.      what the result should be, and an account describing the basis for
  2590.      your opinion.
  2591.  
  2592.    * When giving an example of the problem, it's better to use the
  2593.      variable names, table names, etc., that exist in your actual
  2594.      situation than to come up with new names.  The problem could be
  2595.      related to the name of a variable or table!  These cases are rare,
  2596.      perhaps, but it is better to be safe than sorry.  After all, it
  2597.      should be easier for you to provide an example that uses your
  2598.      actual situation, and it is by all means better for us.  In case
  2599.      you have data you don't want to show to others, you can use `ftp'
  2600.      to transfer it to `ftp://support.mysql.com/pub/mysql/secret/'.  If
  2601.      the data is really top secret and you don't want to show it even
  2602.      to us, then go ahead and provide an example using other names, but
  2603.      please regard this as the last choice.
  2604.  
  2605.    * Include all the options given to the relevant programs, if
  2606.      possible.  For example, indicate the options that you use when you
  2607.      start the `mysqld' daemon and that you use to run any MySQL client
  2608.      programs.  The options to programs like `mysqld' and `mysql', and
  2609.      to the `configure' script, are often keys to answers and are very
  2610.      relevant!  It is never a bad idea to include them anyway!  If you
  2611.      use any modules, such as Perl or PHP, please include the version
  2612.      number(s) of those as well.
  2613.  
  2614.    * If your question is related to the privilege system, please
  2615.      include the output of `mysqlaccess', the output of `mysqladmin
  2616.      reload', and all the error messages you get when trying to
  2617.      connect!  When you test your privileges, you should first run
  2618.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  2619.      and try to connect with the program that gives you trouble.
  2620.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  2621.      installation directory.
  2622.  
  2623.    * If you have a patch for a bug, that is good. But don't assume the
  2624.      patch is all we need, or that we will use it, if you don't provide
  2625.      some necessary information such as test cases showing the bug that
  2626.      your patch fixes.  We might find problems with your patch or we
  2627.      might not understand it at all; if so, we can't use it.
  2628.  
  2629.      If we can't verify exactly what the patch is meant for, we won't
  2630.      use it.  Test cases will help us here.  Show that the patch will
  2631.      handle all the situations that may occur.  If we find a borderline
  2632.      case (even a rare one) where the patch won't work, it may be
  2633.      useless.
  2634.  
  2635.    * Guesses about what the bug is, why it occurs, or what it depends on
  2636.      are usually wrong.  Even the MySQL team can't guess such things
  2637.      without first using a debugger to determine the real cause of a
  2638.      bug.
  2639.  
  2640.    * Indicate in your mail message that you have checked the reference
  2641.      manual and mail archive so that others know you have tried to
  2642.      solve the problem yourself.
  2643.  
  2644.    * If you get a `parse error', please check your syntax closely!  If
  2645.      you can't find something wrong with it, it's extremely likely that
  2646.      your current version of MySQL Server doesn't support the query you
  2647.      are using.  If you are using the current version and the manual at
  2648.      `http://www.mysql.com/doc/' doesn't cover the syntax you are
  2649.      using, MySQL Server doesn't support your query.  In this case,
  2650.      your only options are to implement the syntax yourself or e-mail
  2651.      <licensing@mysql.com> and ask for an offer to implement it!
  2652.  
  2653.      If the manual covers the syntax you are using, but you have an
  2654.      older version of MySQL Server, you should check the MySQL change
  2655.      history to see when the syntax was implemented.  In this case, you
  2656.      have the option of upgrading to a newer version of MySQL Server.
  2657.      *Note News::.
  2658.  
  2659.    * If you have a problem such that your data appears corrupt or you
  2660.      get errors when you access some particular table, you should first
  2661.      check and then try repairing your tables with `myisamchk' or
  2662.      `CHECK TABLE' and `REPAIR TABLE'.  *Note MySQL Database
  2663.      Administration::.
  2664.  
  2665.    * If you often get corrupted tables you should try to find out when
  2666.      and why this happens.  In this case, the
  2667.      `mysql-data-directory/'hostname'.err' file may contain some
  2668.      information about what happened.  *Note Error log::.  Please
  2669.      include any relevant information from this file in your bug
  2670.      report.  Normally `mysqld' should *never* crash a table if nothing
  2671.      killed it in the middle of an update!  If you can find the cause
  2672.      of `mysqld' dying, it's much easier for us to provide you with a
  2673.      fix for the problem.  *Note What is crashing::.
  2674.  
  2675.    * If possible, download and install the most recent version of MySQL
  2676.      Server and check whether it solves your problem.  All versions of
  2677.      the MySQL software are thoroughly tested and should work without
  2678.      problems.  We believe in making everything as backward-compatible
  2679.      as possible, and you  should be able to switch MySQL versions
  2680.      without any hassle.  *Note Which version::.
  2681.  
  2682. If you are a support customer, please cross-post the bug report to
  2683. <mysql-support@mysql.com> for higher-priority treatment, as well as to
  2684. the appropriate mailing list to see if someone else has experienced (and
  2685. perhaps solved) the problem.
  2686.  
  2687. For information on reporting bugs in `MyODBC', see *Note ODBC
  2688. Problems::.
  2689.  
  2690. For solutions to some common problems, see *Note Problems::.
  2691.  
  2692. When answers are sent to you individually and not to the mailing list,
  2693. it is considered good etiquette to summarise the answers and send the
  2694. summary to the mailing list so that others may have the benefit of
  2695. responses you received that helped you solve your problem!
  2696.  
  2697. Guidelines for Answering Questions on the Mailing List
  2698. ......................................................
  2699.  
  2700. If you consider your answer to have broad interest, you may want to
  2701. post it to the mailing list instead of replying directly to the
  2702. individual who asked.  Try to make your answer general enough that
  2703. people other than the original poster may benefit from it.  When you
  2704. post to the list, please make sure that your answer is not a
  2705. duplication of a previous answer.
  2706.  
  2707. Try to summarise the essential part of the question in your reply;
  2708. don't feel obliged to quote the entire original message.
  2709.  
  2710. Please don't post mail messages from your browser with HTML mode turned
  2711. on!  Many users don't read mail with a browser!
  2712.  
  2713. MySQL Community Support on IRC (Internet Relay Chat)
  2714. ----------------------------------------------------
  2715.  
  2716. In addition to the various MySQL mailing lists, you can find experienced
  2717. community people on `IRC' (`Internet Relay Chat').  These are the best
  2718. networks/channels currently known to us:
  2719.  
  2720.    * *freenode* (see `http://www.freenode.net/' for servers)
  2721.         * `#mysql' Primarily MySQL questions but other database and SQL
  2722.           questions welcome.
  2723.  
  2724.         * `#mysqlphp' Questions about MySQL+PHP, a popular combo.
  2725.  
  2726.    * *EFnet* (see `http://www.efnet.org/' for servers)
  2727.         * `#mysql' MySQL questions.
  2728.  
  2729. If you are looking for IRC client software to connect to an IRC network,
  2730. take a peek at `X-Chat' (`http://www.xchat.org/').  X-Chat is available
  2731. for Unix as well as for Windows platforms.
  2732.  
  2733. How Standards-compatible Is MySQL?
  2734. ==================================
  2735.  
  2736. This section describes how MySQL relates to the ANSI SQL standards.
  2737. MySQL Server has many extensions to the ANSI SQL standards, and here you
  2738. will find out what they are and how to use them.  You will also find
  2739. information about functionality missing from MySQL Server, and how to
  2740. work around some differences.
  2741.  
  2742. Our goal is to not, without a very good reason, restrict MySQL Server
  2743. usability for any usage.  Even if we don't have the resources to do
  2744. development for every possible use, we are always willing to help and
  2745. offer suggestions to people who are trying to use MySQL Server in new
  2746. territories.
  2747.  
  2748. One of our main goals with the product is to continue to work toward
  2749. ANSI 99 compliancy, but without sacrificing speed or reliability.  We
  2750. are not afraid to add extensions to SQL or support for non-SQL features
  2751. if this greatly increases the usability of MySQL Server for a big part
  2752. of our users.  (The new `HANDLER' interface in MySQL Server 4.0 is an
  2753. example of this strategy. *Note `HANDLER': HANDLER.)
  2754.  
  2755. We will continue to support transactional and non-transactional
  2756. databases to satisfy both heavy web/logging usage and mission-critical
  2757. 24/7 usage.
  2758.  
  2759. MySQL Server was designed from the start to work with medium size
  2760. databases (10-100 million rows, or about 100 MB per table) on small
  2761. computer systems.  We will continue to extend MySQL Server to work even
  2762. better with terabyte-size databases, as well as to make it possible to
  2763. compile a reduced MySQL version that is more suitable for hand-held
  2764. devices and embedded usage.  The compact design of the MySQL server
  2765. makes both of these directions possible without any conflicts in the
  2766. source tree.
  2767.  
  2768. We are currently not targeting realtime support or clustered databases
  2769. (even if you can already do a lot of things with our replication
  2770. services).
  2771.  
  2772. We don't believe that one should have native XML support in the
  2773. database, but will instead add the XML support our users request from
  2774. us on the client side.  We think it's better to keep the main server
  2775. code as "lean and clean" as possible and instead develop libraries to
  2776. deal with the complexity on the client side.  This is part of the
  2777. strategy mentioned previously of not sacrificing speed or reliability
  2778. in the server.
  2779.  
  2780. What Standards Does MySQL Follow?
  2781. ---------------------------------
  2782.  
  2783. Entry-level SQL92. ODBC levels 0-3.51.
  2784.  
  2785. We are aiming toward supporting the full ANSI SQL99 standard, but
  2786. without concessions to speed and quality of the code.
  2787.  
  2788. Running MySQL in ANSI Mode
  2789. --------------------------
  2790.  
  2791. If you start `mysqld' with the `--ansi' option, the following behaviour
  2792. of MySQL Server changes:
  2793.  
  2794.    * `||' is string concatenation instead of `OR'.
  2795.  
  2796.    * You can have any number of spaces between a function name and the
  2797.      `('.  This forces all function names to be treated as reserved
  2798.      words.
  2799.  
  2800.    * `"' will be an identifier quote character (like the MySQL Server
  2801.      ``' quote character) and not a string quote character.
  2802.  
  2803.    * `REAL' will be a synonym for `FLOAT' instead of a synonym for
  2804.      `DOUBLE'.
  2805.  
  2806.    * The default transaction isolation level is `SERIALIZABLE'.  *Note
  2807.      SET TRANSACTION::.
  2808.  
  2809. This is the same as using
  2810. `--sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,
  2811. IGNORE_SPACE,SERIALIZE,ONLY_FULL_GROUP_BY'.
  2812.  
  2813. MySQL Extensions to ANSI SQL92
  2814. ------------------------------
  2815.  
  2816. MySQL Server includes some extensions that you probably will not find in
  2817. other SQL databases.  Be warned that if you use them, your code will
  2818. not be portable to other SQL servers.  In some cases, you can write
  2819. code that includes MySQL extensions, but is still portable, by using
  2820. comments of the form `/*! ... */'.  In this case, MySQL Server will
  2821. parse and execute the code within the comment as it would any other
  2822. MySQL statement, but other SQL servers will ignore the extensions.  For
  2823. example:
  2824.  
  2825.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  2826.  
  2827. If you add a version number after the `'!'', the syntax will be
  2828. executed only if the MySQL version is equal to or newer than the used
  2829. version number:
  2830.  
  2831.      CREATE /*!32302 TEMPORARY */ TABLE t (a int);
  2832.  
  2833. This means that if you have Version 3.23.02 or newer, MySQL Server will
  2834. use the `TEMPORARY' keyword.
  2835.  
  2836. The following is a list of MySQL extensions:
  2837.  
  2838.    * The field types `MEDIUMINT', `SET', `ENUM', and the different
  2839.      `BLOB' and `TEXT' types.
  2840.  
  2841.    * The field attributes `AUTO_INCREMENT', `BINARY', `NULL',
  2842.      `UNSIGNED', and `ZEROFILL'.
  2843.  
  2844.    * All string comparisons are case-insensitive by default, with sort
  2845.      ordering determined by the current character set (ISO-8859-1
  2846.      Latin1 by default).  If you don't like this, you should declare
  2847.      your columns with the `BINARY' attribute or use the `BINARY' cast,
  2848.      which causes comparisons to be done according to the ASCII order
  2849.      used on the MySQL server host.
  2850.  
  2851.    * MySQL Server maps each database to a directory under the MySQL
  2852.      data directory, and tables within a database to filenames in the
  2853.      database directory.
  2854.  
  2855.      This has a few implications:
  2856.  
  2857.         - Database names and table names are case-sensitive in MySQL
  2858.           Server on operating systems that have case-sensitive
  2859.           filenames (like most Unix systems). *Note Name case
  2860.           sensitivity::.
  2861.  
  2862.         - Database, table, index, column, or alias names may begin with
  2863.           a digit (but may not consist solely of digits).
  2864.  
  2865.         - You can use standard system commands to back up, rename,
  2866.           move, delete, and copy tables.  For example, to rename a
  2867.           table, rename the `.MYD', `.MYI', and `.frm' files to which
  2868.           the table corresponds.
  2869.  
  2870.    * In SQL statements, you can access tables from different databases
  2871.      with the `db_name.tbl_name' syntax.  Some SQL servers provide the
  2872.      same functionality but call this `User space'.  MySQL Server
  2873.      doesn't support tablespaces as in: `create table
  2874.      ralph.my_table...IN my_tablespace'.
  2875.  
  2876.    * `LIKE' is allowed on numeric columns.
  2877.  
  2878.    * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT' statement.
  2879.      *Note `SELECT': SELECT.
  2880.  
  2881.    * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  2882.  
  2883.    * `EXPLAIN SELECT' to get a description on how tables are joined.
  2884.  
  2885.    * Use of index names, indexes on a prefix of a field, and use of
  2886.      `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  2887.      TABLE': CREATE TABLE.
  2888.  
  2889.    * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  2890.  
  2891.    * Use of `COUNT(DISTINCT list)' where `list' is more than one
  2892.      element.
  2893.  
  2894.    * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  2895.      `IGNORE' or `RENAME' in an `ALTER TABLE' statement. *Note `ALTER
  2896.      TABLE': ALTER TABLE.
  2897.  
  2898.    * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  2899.  
  2900.    * Use of multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  2901.      `ALTER TABLE' statement.
  2902.  
  2903.    * Use of `DROP TABLE' with the keywords `IF EXISTS'.
  2904.  
  2905.    * You can drop multiple tables with a single `DROP TABLE' statement.
  2906.  
  2907.    * The `LIMIT' clause of the `DELETE' statement.
  2908.  
  2909.    * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  2910.  
  2911.    * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE', `DELETE',
  2912.      and `UPDATE' statements.
  2913.  
  2914.    * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  2915.      compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD DATA':
  2916.      LOAD DATA.
  2917.  
  2918.    * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and `REPAIR
  2919.      TABLE' statements.
  2920.  
  2921.    * The `SHOW' statement.  *Note `SHOW': SHOW.
  2922.  
  2923.    * Strings may be enclosed by either `"' or `'', not just by `''.
  2924.  
  2925.    * Use of the escape `\' character.
  2926.  
  2927.    * The `SET' statement. *Note `SET': SET OPTION.
  2928.  
  2929.    * You don't need to name all selected columns in the `GROUP BY' part.
  2930.      This gives better performance for some very specific, but quite
  2931.      normal queries.  *Note Group by functions::.
  2932.  
  2933.    * One can specify `ASC' and `DESC' with `GROUP BY'.
  2934.  
  2935.    * To make it easier for users who come from other SQL environments,
  2936.      MySQL Server supports aliases for many functions. For example, all
  2937.      string functions support both ANSI SQL syntax and ODBC syntax.
  2938.  
  2939.    * MySQL Server understands the `||' and `&&' operators to mean
  2940.      logical OR and AND, as in the C programming language.  In MySQL
  2941.      Server, `||' and `OR' are synonyms, as are `&&' and `AND'.
  2942.      Because of this nice syntax, MySQL Server doesn't support the ANSI
  2943.      SQL `||' operator for string concatenation; use `CONCAT()'
  2944.      instead. Because `CONCAT()' takes any number of arguments, it's
  2945.      easy to convert use of the `||' operator to MySQL Server.
  2946.  
  2947.    * `CREATE DATABASE' or `DROP DATABASE'.  *Note `CREATE DATABASE':
  2948.      CREATE DATABASE.
  2949.  
  2950.    * The `%' operator is a synonym for `MOD()'.  That is, `N % M' is
  2951.      equivalent to `MOD(N,M)'.  `%' is supported for C programmers and
  2952.      for compatibility with PostgreSQL.
  2953.  
  2954.    * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  2955.      `OR', or `LIKE' operators may be used in column comparisons to the
  2956.      left of the `FROM' in `SELECT' statements.  For example:
  2957.  
  2958.           mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  2959.  
  2960.    * The `LAST_INSERT_ID()' function.  *Note `mysql_insert_id()':
  2961.      mysql_insert_id.
  2962.  
  2963.    * The `REGEXP' and `NOT REGEXP' extended regular expression
  2964.      operators.
  2965.  
  2966.    * `CONCAT()' or `CHAR()' with one argument or more than two
  2967.      arguments.  (In MySQL Server, these functions can take any number
  2968.      of arguments.)
  2969.  
  2970.    * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()', `FORMAT()',
  2971.      `IF()', `PASSWORD()', `ENCRYPT()', `MD5()', `ENCODE()', `DECODE()',
  2972.      `PERIOD_ADD()', `PERIOD_DIFF()', `TO_DAYS()', or `WEEKDAY()'
  2973.      functions.
  2974.  
  2975.    * Use of `TRIM()' to trim substrings. ANSI SQL only supports removal
  2976.      of single characters.
  2977.  
  2978.    * The `GROUP BY' functions `STD()', `BIT_OR()', and `BIT_AND()'.
  2979.  
  2980.    * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note `REPLACE':
  2981.      REPLACE.
  2982.  
  2983.    * The `FLUSH', `RESET' and `DO' statements.
  2984.  
  2985.    * The ability to set variables in a statement with `:=':
  2986.           SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg FROM test_table;
  2987.           SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  2988.  
  2989.  
  2990. MySQL Differences Compared to ANSI SQL92
  2991. ----------------------------------------
  2992.  
  2993. We try to make MySQL Server follow the ANSI SQL standard and the ODBC
  2994. SQL standard, but in some cases MySQL Server does things differently:
  2995.  
  2996.    * For `VARCHAR' columns, trailing spaces are removed when the value
  2997.      is stored. *Note Bugs::.
  2998.  
  2999.    * In some cases, `CHAR' columns are silently changed to `VARCHAR'
  3000.      columns. *Note Silent column changes::.
  3001.  
  3002.    * Privileges for a table are not automatically revoked when you
  3003.      delete a table. You must explicitly issue a `REVOKE' to revoke
  3004.      privileges for a table. *Note `GRANT': GRANT.
  3005.  
  3006.    * `NULL AND FALSE' will evaluate to `NULL' and not to `FALSE'.  This
  3007.      is because we don't think it's good to have to evaluate a lot of
  3008.      extra conditions in this case.
  3009.  
  3010. For a prioritised list indicating when new extensions will be added to
  3011. MySQL Server, you should consult the online MySQL TODO list at
  3012. `http://www.mysql.com/doc/en/TODO.html'.  That is the latest version of
  3013. the TODO list in this manual. *Note TODO::.
  3014.  
  3015. Sub`SELECT's
  3016. ............
  3017.  
  3018. MySQL Server until version 4.0 only supports nested queries of the form
  3019. `INSERT ... SELECT ...' and `REPLACE ... SELECT ...'.  You can,
  3020. however, use the function `IN()' in other contexts.  Subselects are
  3021. being implemented in the 4.1 development tree.
  3022.  
  3023. Meanwhile, you can often rewrite the query without a subselect:
  3024.  
  3025.      SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
  3026.  
  3027. This can be rewritten as:
  3028.  
  3029.      SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
  3030.  
  3031. The queries:
  3032.      SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
  3033.      SELECT * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2
  3034.                                             WHERE table1.id=table2.id);
  3035.  
  3036. Can be rewritten as:
  3037.  
  3038.      SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id
  3039.                                             WHERE table2.id IS NULL;
  3040.  
  3041. For more complicated subqueries you can often create temporary tables
  3042. to hold the subquery.  In some cases, however, this option will not
  3043. work. The most frequently encountered of these cases arises with
  3044. `DELETE' statements, for which standard SQL does not support joins
  3045. (except in subselects).  For this situation there are two options
  3046. available until subqueries are supported by MySQL Server.
  3047.  
  3048. The first option is to use a procedural programming language (such as
  3049. Perl or PHP) to submit a `SELECT' query to obtain the primary keys for
  3050. the records to be deleted, and then use these values to construct the
  3051. `DELETE' statement (`DELETE FROM ... WHERE ... IN (key1, key2, ...)').
  3052.  
  3053. The second option is to use interactive SQL to construct a set of
  3054. `DELETE' statements automatically, using the MySQL extension `CONCAT()'
  3055. (in lieu of the standard `||' operator).  For example:
  3056.  
  3057.      SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', "'", tab1.pkid, "'", ';')
  3058.        FROM tab1, tab2
  3059.       WHERE tab1.col1 = tab2.col2;
  3060.  
  3061. You can place this query in a script file and redirect input from it to
  3062. the `mysql' command-line interpreter, piping its output back to a
  3063. second instance of the interpreter:
  3064.  
  3065.      shell> mysql --skip-column-names mydb < myscript.sql | mysql mydb
  3066.  
  3067. MySQL Server 4.0 supports multi-table deletes that can be used to
  3068. efficiently delete rows based on information from one table or even
  3069. from many tables at the same time.
  3070.  
  3071. `SELECT INTO TABLE'
  3072. ...................
  3073.  
  3074. MySQL Server doesn't yet support the Oracle SQL extension: `SELECT ...
  3075. INTO TABLE ...'.  MySQL Server supports instead the ANSI SQL syntax
  3076. `INSERT INTO ... SELECT ...', which is basically the same thing. *Note
  3077. INSERT SELECT::.
  3078.  
  3079.      INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID
  3080.             FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;
  3081.  
  3082. Alternatively, you can use `SELECT INTO OUTFILE...' or `CREATE TABLE
  3083. ... SELECT'.
  3084.  
  3085. Transactions and Atomic Operations
  3086. ..................................
  3087.  
  3088. MySQL Server supports transactions with the `InnoDB' and `BDB'
  3089. `Transactional table handlers'. *Note Table types::.  `InnoDB' provides
  3090. `ACID' compliancy.
  3091.  
  3092. However, the non-transactional table types in MySQL Server such as
  3093. `MyISAM' follow another paradigm for data integrity called "`Atomic
  3094. Operations'." Atomic operations often offer equal or even better
  3095. integrity with much better performance.  With MySQL Server supporting
  3096. both paradigms, the user is able to decide if he needs the speed of
  3097. atomic operations or if he need to use transactional features in his
  3098. applications. This choice can be made on a per-table basis.
  3099.  
  3100. How does one use the features of MySQL Server to maintain rigorous
  3101. integrity and how do these features compare with the transactional
  3102. paradigm?
  3103.  
  3104.   1. In the transactional paradigm, if your applications are written in
  3105.      a way that is dependent on the calling of `ROLLBACK' instead of
  3106.      `COMMIT' in critical situations, transactions are more convenient.
  3107.      Transactions also ensure that unfinished updates or corrupting
  3108.      activities are not committed to the database; the server is given
  3109.      the opportunity to do an automatic rollback and your database is
  3110.      saved.
  3111.  
  3112.      MySQL Server, in almost all cases, allows you to resolve potential
  3113.      problems by including simple checks before updates and by running
  3114.      simple scripts that check the databases for inconsistencies and
  3115.      automatically repair or warn if such an inconsistency occurs. Note
  3116.      that just by using the MySQL log or even adding one extra log, one
  3117.      can normally fix tables perfectly with no data integrity loss.
  3118.  
  3119.   2. More often than not, fatal transactional updates can be rewritten
  3120.      to be atomic. Generally speaking, all integrity problems that
  3121.      transactions solve can be done with `LOCK TABLES' or atomic
  3122.      updates, ensuring that you never will get an automatic abort from
  3123.      the database, which is a common problem with transactional
  3124.      databases.
  3125.  
  3126.   3. Even a transactional system can lose data if the server goes down.
  3127.      The difference between different systems lies in just how small the
  3128.      time-lap is where they could lose data. No system is 100% secure,
  3129.      only "secure enough." Even Oracle, reputed to be the safest of
  3130.      transactional databases, is reported to sometimes lose data in such
  3131.      situations.
  3132.  
  3133.      To be safe with MySQL Server, whether using transactional tables
  3134.      or not, you only need to have backups and have the update logging
  3135.      turned on. With this you can recover from any situation that you
  3136.      could with any other transactional database.  It is, of course,
  3137.      always good to have backups, independent of which database you use.
  3138.  
  3139. The transactional paradigm has its benefits and its drawbacks. Many
  3140. users and application developers depend on the ease with which they can
  3141. code around problems where an abort appears to be, or is necessary.
  3142. However, even if you are new to the atomic operations paradigm, or more
  3143. familiar with transactions, do consider the speed benefit that
  3144. non-transactional tables can offer on the order of three to five times
  3145. the speed of the fastest and most optimally tuned transactional tables.
  3146.  
  3147. In situations where integrity is of highest importance, MySQL Server
  3148. offers transaction-level or better reliability and integrity even for
  3149. non-transactional tables.  If you lock tables with `LOCK TABLES', all
  3150. updates will stall until any integrity checks are made. If you only
  3151. obtain a read lock (as opposed to a write lock), reads and inserts are
  3152. still allowed to happen. The new inserted records will not be seen by
  3153. any of the clients that have a read lock until they release their read
  3154. locks. With `INSERT DELAYED' you can queue inserts into a local queue,
  3155. until the locks are released, without having the client wait for the
  3156. insert to complete. *Note INSERT DELAYED::.
  3157.  
  3158. "Atomic," in the sense that we mean it, is nothing magical. It only
  3159. means that you can be sure that while each specific update is running,
  3160. no other user can interfere with it, and there will never be an
  3161. automatic rollback (which can happen with transactional tables if you
  3162. are not very careful).  MySQL Server also guarantees that there will
  3163. not be any dirty reads.
  3164.  
  3165. Following are some techniques for working with non-transactional tables:
  3166.  
  3167.    * Loops that need transactions normally can be coded with the help of
  3168.      `LOCK TABLES', and you don't need cursors when you can update
  3169.      records on the fly.
  3170.  
  3171.    * To avoid using `ROLLBACK', you can use the following strategy:
  3172.  
  3173.        1. Use `LOCK TABLES ...' to lock all the tables you want to
  3174.           access.
  3175.  
  3176.        2. Test conditions.
  3177.  
  3178.        3. Update if everything is okay.
  3179.  
  3180.        4. Use `UNLOCK TABLES' to release your locks.
  3181.  
  3182.      This is usually a much faster method than using transactions with
  3183.      possible `ROLLBACK's, although not always. The only situation this
  3184.      solution doesn't handle is when someone kills the threads in the
  3185.      middle of an update. In this case, all locks will be released but
  3186.      some of the updates may not have been executed.
  3187.  
  3188.    * You can also use functions to update records in a single operation.
  3189.      You can get a very efficient application by using the following
  3190.      techniques:
  3191.  
  3192.         * Modify fields relative to their current value.
  3193.  
  3194.         * Update only those fields that actually have changed.
  3195.  
  3196.      For example, when we are doing updates to some customer
  3197.      information, we update only the customer data that has changed and
  3198.      test only that none of the changed data, or data that depends on
  3199.      the changed data, has changed compared to the original row. The
  3200.      test for changed data is done with the `WHERE' clause in the
  3201.      `UPDATE' statement. If the record wasn't updated, we give the
  3202.      client a message: "Some of the data you have changed has been
  3203.      changed by another user." Then we show the old row versus the new
  3204.      row in a window, so the user can decide which version of the
  3205.      customer record he should use.
  3206.  
  3207.      This gives us something that is similar to column locking but is
  3208.      actually even better because we only update some of the columns,
  3209.      using values that are relative to their current values.  This
  3210.      means that typical `UPDATE' statements look something like these:
  3211.  
  3212.           UPDATE tablename SET pay_back=pay_back+'relative change';
  3213.           
  3214.           UPDATE customer
  3215.             SET
  3216.               customer_date='current_date',
  3217.               address='new address',
  3218.               phone='new phone',
  3219.               money_he_owes_us=money_he_owes_us+'new_money'
  3220.             WHERE
  3221.               customer_id=id AND address='old address' AND phone='old phone';
  3222.  
  3223.      As you can see, this is very efficient and works even if another
  3224.      client has changed the values in the `pay_back' or
  3225.      `money_he_owes_us' columns.
  3226.  
  3227.    * In many cases, users have wanted `ROLLBACK' and/or `LOCK TABLES'
  3228.      for the purpose of managing unique identifiers for some tables.
  3229.      This can be handled much more efficiently by using an
  3230.      `AUTO_INCREMENT' column and either the SQL function
  3231.      `LAST_INSERT_ID()' or the C API function `mysql_insert_id()'.
  3232.      *Note `mysql_insert_id()': mysql_insert_id.
  3233.  
  3234.      You can generally code around row-level locking. Some situations
  3235.      really need it, but they are very few. `InnoDB' tables support
  3236.      row-level locking. With MyISAM, you can use a flag column in the
  3237.      table and do something like the following:
  3238.  
  3239.           UPDATE tbl_name SET row_flag=1 WHERE id=ID;
  3240.  
  3241.      MySQL returns 1 for the number of affected rows if the row was
  3242.      found and `row_flag' wasn't already 1 in the original row.
  3243.  
  3244.      You can think of it as though MySQL Server changed the preceding
  3245.      query to:
  3246.  
  3247.           UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;
  3248.  
  3249. Stored Procedures and Triggers
  3250. ..............................
  3251.  
  3252. A stored procedure is a set of SQL commands that can be compiled and
  3253. stored in the server. Once this has been done, clients don't need to
  3254. keep re-issuing the entire query but can refer to the stored procedure.
  3255. This provides better performance because the query has to be parsed
  3256. only once, and less information needs to be sent between the server and
  3257. the client. You can also raise the conceptual level by having libraries
  3258. of functions in the server.
  3259.  
  3260. A trigger is a stored procedure that is invoked when a particular event
  3261. occurs.  For example, you can install a stored procedure that is
  3262. triggered each time a record is deleted from a transaction table and
  3263. that automatically deletes the corresponding customer from a customer
  3264. table when all his transactions are deleted.
  3265.  
  3266. The planned update language will be able to handle stored procedures.
  3267. Our aim is to have stored procedures implemented in MySQL Server around
  3268. version 5.0. We are also looking at triggers.
  3269.  
  3270. Foreign Keys
  3271. ............
  3272.  
  3273. Note that foreign keys in SQL are not used to join tables, but are used
  3274. mostly for checking referential integrity (foreign key constraints).  If
  3275. you want to get results from multiple tables from a `SELECT' statement,
  3276. you do this by joining tables:
  3277.  
  3278.      SELECT * FROM table1,table2 WHERE table1.id = table2.id;
  3279.  
  3280. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  3281.  
  3282. In MySQL Server 3.23.44 and up, `InnoDB' tables support checking of
  3283. foreign key constraints. *Note InnoDB::. For other table types, MySQL
  3284. Server does parse the `FOREIGN KEY' syntax in `CREATE TABLE' commands,
  3285. but without further action being taken.
  3286.  
  3287. The `FOREIGN KEY' syntax without `ON DELETE ...' is mostly used for
  3288. documentation purposes. Some ODBC applications may use this to produce
  3289. automatic `WHERE' clauses, but this is usually easy to override.
  3290. `FOREIGN KEY' is sometimes used as a constraint check, but this check
  3291. is unnecessary in practice if rows are inserted into the tables in the
  3292. right order.
  3293.  
  3294. In MySQL Server, you can work around the problem of `ON DELETE ...' not
  3295. being implemented by adding the appropriate `DELETE' statement to an
  3296. application when you delete records from a table that has a foreign
  3297. key. In practice this is as quick (in some cases quicker) and much more
  3298. portable than using foreign keys.
  3299.  
  3300. In MySQL Server 4.0 you can use multi-table delete to delete rows from
  3301. many tables with one command. *Note DELETE::.
  3302.  
  3303. In the near future we will extend the `FOREIGN KEY' implementation so
  3304. that the information will be saved in the table specification file and
  3305. may be retrieved by `mysqldump' and ODBC. At a later stage we will
  3306. implement the foreign key constraints for applications that can't
  3307. easily be coded to avoid them.
  3308.  
  3309. Do keep in mind that foreign keys are often misused, which can cause
  3310. severe problems. Even when used properly, it is not a magic solution for
  3311. the referential integrity problem, although it does make things easier
  3312. in some cases.
  3313.  
  3314. Some advantages of foreign key enforcement:
  3315.  
  3316.    * Assuming proper design of the relations, foreign key constraints
  3317.      will make it more difficult for a programmer to introduce an
  3318.      inconsistency into the database.
  3319.  
  3320.    * Using cascading updates and deletes can simplify the client code.
  3321.  
  3322.    * Properly designed foreign key rules aid in documenting relations
  3323.      between tables.
  3324.  
  3325. Disadvantages:
  3326.  
  3327.    * Mistakes, which are easy to make in designing key relations, can
  3328.      cause severe problemsfor example, circular rules, or the wrong
  3329.      combination of cascading deletes.
  3330.  
  3331.    * A properly written application will make sure internally that it is
  3332.      not violating referential integrity constraints before proceding
  3333.      with a query. Thus, additional checks on the database level will
  3334.      only slow down performance for such an application.
  3335.  
  3336.    * It is not uncommon for a DBA to make such a complex topology of
  3337.      relations that it becomes very difficult, and in some cases
  3338.      impossible, to back up or restore individual tables.
  3339.  
  3340. Views
  3341. .....
  3342.  
  3343. It is planned to implement views in MySQL Server around version 5.0.
  3344.  
  3345. Views are mostly useful for letting users access a set of relations as
  3346. one table (in read-only mode).  Many SQL databases don't allow one to
  3347. update any rows in a view, but you have to do the updates in the
  3348. separate tables.
  3349.  
  3350. As MySQL Server is mostly used in applications and on web systems where
  3351. the application writer has full control on the database usage, most of
  3352. our users haven't regarded views to be very important.  (At least no
  3353. one has been interested enough in this to be prepared to finance the
  3354. implementation of views.)
  3355.  
  3356. One doesn't need views in MySQL Server to restrict access to columns,
  3357. as MySQL Server has a very sophisticated privilege system.  *Note
  3358. Privilege system::.
  3359.  
  3360. `--' as the Start of a Comment
  3361. ..............................
  3362.  
  3363. Some other SQL databases use `--' to start comments.  MySQL Server has
  3364. `#' as the start comment character. You can also use the C comment
  3365. style `/* this is a comment */' with MySQL Server.  *Note Comments::.
  3366.  
  3367. MySQL Server Version 3.23.3 and above support the `--' comment style,
  3368. provided the comment is followed by a space.  This is because this
  3369. comment style has caused many problems with automatically generated SQL
  3370. queries that have used something like the following code, where we
  3371. automatically insert the value of the payment for `!payment!':
  3372.  
  3373.      UPDATE tbl_name SET credit=credit-!payment!
  3374.  
  3375. Think about what happens if the value of `payment' is negative.
  3376. Because `1--1' is legal in SQL, the consequences of allowing comments
  3377. to start with `--' are terrible.
  3378.  
  3379. Using our implementation of this method of commenting in MySQL Server
  3380. Version 3.23.3 and up, `1-- This is a comment' is actually safe.
  3381.  
  3382. Another safe feature is that the `mysql' command-line client removes
  3383. all lines that start with `--'.
  3384.  
  3385. The following information is relevant only if you are running a MySQL
  3386. version earlier than 3.23.3:
  3387.  
  3388. If you have a SQL program in a text file that contains `--' comments
  3389. you should use:
  3390.  
  3391.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  3392.               | mysql database
  3393.  
  3394. instead of the usual:
  3395.  
  3396.      shell> mysql database < text-file-with-funny-comments.sql
  3397.  
  3398. You can also edit the command file "in place" to change the `--'
  3399. comments to `#' comments:
  3400.  
  3401.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  3402.  
  3403. Change them back with this command:
  3404.  
  3405.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  3406.  
  3407. Known Errors and Design Deficiencies in MySQL
  3408. ---------------------------------------------
  3409.  
  3410. The following problems are known and have a very high priority to get
  3411. fixed:
  3412.  
  3413.    * `ANALYZE TABLE' on a BDB table may in some case make the table
  3414.      unusable until one has restarted `mysqld'.  When this happens you
  3415.      will see errors like the following in the MySQL error file:
  3416.  
  3417.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  3418.  
  3419.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  3420.      running multi-statement transactions until all those transactions
  3421.      complete.  (The transaction will probably be ignored.)
  3422.  
  3423.    * `ANALYZE TABLE', `OPTIMIZE TABLE', and `REPAIR TABLE' may cause
  3424.      problems on tables for which you are using `INSERT DELAYED'.
  3425.  
  3426.    * Doing a `LOCK TABLE ...' and `FLUSH TABLES ...' doesn't guarantee
  3427.      that there isn't a half-finished transaction in progress on the
  3428.      table.
  3429.  
  3430.    * BDB tables are a bit slow to open. If you have many BDB tables in a
  3431.      database, it will take a long time to use the `mysql' client on the
  3432.      database if you are not using the `-A' option or if you are using
  3433.      `rehash'. This is especially notable when you have a big table
  3434.      cache.
  3435.  
  3436.  
  3437. The following problems are known and will be fixed in due time:
  3438.  
  3439.    * When using `RPAD' function, or any other string function that ends
  3440.      up adding blanks to the right, in a query that has to use temporary
  3441.      table to be resolved, then all resulting strings will be RTRIM'ed.
  3442.      This is an example of the query:
  3443.  
  3444.      `SELECT    RPAD(t1.field1, 50, ' ') AS f2,    RPAD(t2.field2, 50, '
  3445.      ') AS f1  FROM    table1 as t1     LEFT JOIN table2 AS t2 ON
  3446.      t1.record=t2.joinID ORDER BY t2.record;'
  3447.  
  3448.      Final result of this bug is that use will not be able to get
  3449.      blanks on the right side of the resulting field.
  3450.  
  3451.      The above behaviour exists in all versions of MySQL.
  3452.  
  3453.      The reason for this is due to the fact that HEAP tables, which are
  3454.      used first for temporary tables, are not capable of handling
  3455.      VARCHAR columns.
  3456.  
  3457.      This behaviour will be fixed in one of 4.1 releases.
  3458.  
  3459.    * When using `SET CHARACTER SET', one can't use translated
  3460.      characters in database, table, and column names.
  3461.  
  3462.    * One can't use `_' or `%' with `ESCAPE' in `LIKE ... ESCAPE'.
  3463.  
  3464.    * If you have a `DECIMAL' column with a  number stored in different
  3465.      formats (+01.00, 1.00, 01.00), `GROUP BY' may regard each value as
  3466.      a different value.
  3467.  
  3468.    * `DELETE FROM merge_table' used without a `WHERE' will only clear
  3469.      the mapping for the table, not delete everything in the mapped
  3470.      tables.
  3471.  
  3472.    * You cannot build the server in another directory when using
  3473.      MIT-pthreads. Because this requires changes to MIT-pthreads, we
  3474.      are not likely to fix this. *Note MIT-pthreads::.
  3475.  
  3476.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  3477.      or `DISTINCT'. Only the first `max_sort_length' bytes (default
  3478.      1024) are used when comparing `BLOB's in these cases.  This can be
  3479.      changed with the `-O max_sort_length' option to `mysqld'. A
  3480.      workaround for most cases is to use a substring: `SELECT DISTINCT
  3481.      LEFT(blob,2048) FROM tbl_name'.
  3482.  
  3483.    * Calculation is done with `BIGINT' or `DOUBLE' (both are normally
  3484.      64 bits long). It depends on the function which precision one
  3485.      gets. The general rule is that bit functions are done with `BIGINT'
  3486.      precision, `IF', and `ELT()' with `BIGINT' or `DOUBLE' precision
  3487.      and the rest with `DOUBLE' precision.  One should try to avoid
  3488.      using unsigned long long values if they resolve to be bigger than
  3489.      63 bits (9223372036854775807) for anything else than bit fields!
  3490.      MySQL Server 4.0 has better `BIGINT' handling than 3.23.
  3491.  
  3492.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  3493.      have all trailing spaces removed when retrieved. For `CHAR' types
  3494.      this is okay, and may be regarded as a feature according to ANSI
  3495.      SQL92. The bug is that in MySQL Server, `VARCHAR' columns are
  3496.      treated the same way.
  3497.  
  3498.    * You can only have up to 255 `ENUM' and `SET' columns in one table.
  3499.  
  3500.    * In `MIN()', `MAX()' and other aggregate functions, MySQL currently
  3501.      compares `ENUM' and `SET' columns by their string value rather
  3502.      than by the string's relative position in the set.
  3503.  
  3504.    * `safe_mysqld' redirects all messages from `mysqld' to the `mysqld'
  3505.      log.  One problem with this is that if you execute `mysqladmin
  3506.      refresh' to close and reopen the log, `stdout' and `stderr' are
  3507.      still redirected to the old log.  If you use `--log' extensively,
  3508.      you should edit `safe_mysqld' to log to `'hostname'.err' instead
  3509.      of `'hostname'.log' so you can easily reclaim the space for the
  3510.      old log by deleting the old one and executing `mysqladmin refresh'.
  3511.  
  3512.    * In the `UPDATE' statement, columns are updated from left to right.
  3513.      If you refer to an updated column, you will get the updated value
  3514.      instead of the original value. For example:
  3515.  
  3516.           mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
  3517.  
  3518.      This will update `KEY' with `2' instead of with `1'.
  3519.  
  3520.    * You can't use temporary tables more than once in the same query.
  3521.      For example, the following doesn't work:
  3522.  
  3523.           mysql> SELECT * FROM temporary_table, temporary_table AS t2;
  3524.  
  3525.    * `RENAME' doesn't work with `TEMPORARY' tables or tables used in a
  3526.      `MERGE' table.
  3527.  
  3528.    * The optimiser may handle `DISTINCT' differently if you are using
  3529.      'hidden' columns in a join or not.  In a join, hidden columns are
  3530.      counted as part of the result (even if they are not shown) while in
  3531.      normal queries hidden columns don't participate in the `DISTINCT'
  3532.      comparison.  We will probably change this in the future to never
  3533.      compare the hidden columns when executing `DISTINCT'.
  3534.  
  3535.      An example of this is:
  3536.  
  3537.           SELECT DISTINCT mp3id FROM band_downloads
  3538.                  WHERE userid = 9 ORDER BY id DESC;
  3539.  
  3540.      and
  3541.  
  3542.           SELECT DISTINCT band_downloads.mp3id
  3543.                  FROM band_downloads,band_mp3
  3544.                  WHERE band_downloads.userid = 9
  3545.                  AND band_mp3.id = band_downloads.mp3id
  3546.                  ORDER BY band_downloads.id DESC;
  3547.  
  3548.      In the second case you may in MySQL Server 3.23.x get two
  3549.      identical rows in the result set (because the hidden `id' column
  3550.      may differ).
  3551.  
  3552.      Note that this happens only for queries where you don't have the
  3553.      ORDER BY columns in the result, something that you are not allowed
  3554.      to do in ANSI SQL.
  3555.  
  3556.    * Because MySQL Server allows you to work with table types that don't
  3557.      support transactions, and thus can't `rollback' data, some things
  3558.      behave a little differently in MySQL Server than in other SQL
  3559.      servers.  This is just to ensure that MySQL Server never needs to
  3560.      do a rollback for a SQL command.  This may be a little awkward at
  3561.      times as column values must be checked in the application, but
  3562.      this will actually give you a nice speed increase as it allows
  3563.      MySQL Server to do some optimisations that otherwise would be very
  3564.      hard to do.
  3565.  
  3566.      If you set a column to an incorrect value, MySQL Server will,
  3567.      instead of doing a rollback, store the `best possible value' in
  3568.      the column:
  3569.  
  3570.         - If you try to store a value outside the range in a numerical
  3571.           column, MySQL Server will instead store the smallest or
  3572.           biggest possible value in the column.
  3573.  
  3574.         - If you try to store a string that doesn't start with a number
  3575.           into a numerical column, MySQL Server will store 0 into it.
  3576.  
  3577.         - If you try to store `NULL' into a column that doesn't take
  3578.           `NULL' values, MySQL Server will store 0 or `''' (empty
  3579.           string) in it instead. (This behaviour can, however, be
  3580.           changed with the -DDONT_USE_DEFAULT_FIELDS compile option.)
  3581.  
  3582.         - MySQL allows you to store some wrong date values into `DATE'
  3583.           and `DATETIME' columns (like 2000-02-31 or 2000-02-00).  The
  3584.           idea is that it's not the SQL server job to validate date.
  3585.           If MySQL can store a date and retrieve exactly the same date,
  3586.           then MySQL will store the date. If the date is totally wrong
  3587.           (outside the server's ability to store it), then the special
  3588.           date value 0000-00-00 will be stored in the column.
  3589.  
  3590.         - If you set an `ENUM' column to an unsupported value, it will
  3591.           be set to the error value `empty string', with numeric value
  3592.           0.
  3593.  
  3594.         - If you set a `SET' column to an unsupported value, the value
  3595.           will be ignored.
  3596.  
  3597.  
  3598.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  3599.      in some cases the `PROCEDURE' will not transform the columns.
  3600.  
  3601.    * Creation of a table of type `MERGE' doesn't check if the underlying
  3602.      tables are of compatible types.
  3603.  
  3604.    * MySQL Server can't yet handle `NaN', `-Inf', and `Inf' values in
  3605.      double. Using these will cause problems when trying to export and
  3606.      import data. We should as an intermediate solution change `NaN' to
  3607.      `NULL' (if possible) and `-Inf' and `Inf' to the minimum
  3608.      respective maximum possible `double' value.
  3609.  
  3610.    * `LIMIT' on negative numbers are treated as big positive numbers.
  3611.  
  3612.    * If you use `ALTER TABLE' to first add a `UNIQUE' index to a table
  3613.      used in a `MERGE' table and then use `ALTER TABLE' to add a normal
  3614.      index on the `MERGE' table, the key order will be different for
  3615.      the tables if there was an old key that was not unique in the
  3616.      table. This is because `ALTER TABLE' puts `UNIQUE' keys before
  3617.      normal keys to be able to detect duplicate keys as early as
  3618.      possible.
  3619.  
  3620. The following are known bugs in earlier versions of MySQL:
  3621.  
  3622.    * You can get a hung thread if you do a `DROP TABLE' on a table that
  3623.      is one among many tables that is locked with `LOCK TABLES'.
  3624.  
  3625.    * In the following case you can get a core dump:
  3626.  
  3627.         - Delayed insert handler has pending inserts to a table.
  3628.  
  3629.         - `LOCK table' with `WRITE'.
  3630.  
  3631.         - `FLUSH TABLES'.
  3632.  
  3633.    * Before MySQL Server Version 3.23.2 an `UPDATE' that updated a key
  3634.      with a `WHERE' on the same key may have failed because the key was
  3635.      used to search for records and the same row may have been found
  3636.      multiple times:
  3637.  
  3638.           UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
  3639.  
  3640.      A workaround is to use:
  3641.  
  3642.           mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
  3643.  
  3644.      This will work because MySQL Server will not use an index on
  3645.      expressions in the `WHERE' clause.
  3646.  
  3647.    * Before MySQL Server Version 3.23, all numeric types where treated
  3648.      as fixed-point fields. That means you had to specify how many
  3649.      decimals a floating-point field shall have. All results were
  3650.      returned with the correct number of decimals.
  3651.  
  3652. For platform-specific bugs, see the sections about compiling and
  3653. porting.
  3654.  
  3655. MySQL and The Future (The TODO)
  3656. ===============================
  3657.  
  3658. This section lists the features that we plan to implement in MySQL
  3659. Server.
  3660.  
  3661. Everything in this list is approximately in the order it will be done.
  3662. If you want to affect the priority order, please register a license or
  3663. support us and tell us what you want to have done more quickly. *Note
  3664. Licensing and Support::.
  3665.  
  3666. The plan is that we in the future will support the full ANSI SQL99
  3667. standard, but with a lot of useful extensions. The challenge is to do
  3668. this without sacrificing the speed or compromising the code.
  3669.  
  3670. Things That Should be in 4.0
  3671. ----------------------------
  3672.  
  3673. All done. We now only do bug fixes for MySQL 4.0. *Note News-4.0.x::.
  3674. Development has shifted to 4.1
  3675.  
  3676. Things That Should be in 4.1
  3677. ----------------------------
  3678.  
  3679. The following features are planned for inclusion into MySQL 4.1.  Note
  3680. that because we have many developers that are working on different
  3681. projects, there will also be many additional features. There is also a
  3682. small chance that some of these features will be added to MySQL 4.0.
  3683. Some of the work on MySQL 4.1 is already in progress.
  3684.  
  3685.    * Subqueries.
  3686.           SELECT id FROM t WHERE grp IN (SELECT grp FROM g WHERE u > 100);
  3687.  
  3688.    * New table definition file format (`.frm' files). This will enable
  3689.      us to not run out of bits when adding more table options.  One
  3690.      will still be able to use the old `.frm' file format with 4.0.
  3691.      All newly created tables will, however, use the new format.
  3692.  
  3693.      The new file format will enable us to add new column types, more
  3694.      options for keys, and possibly to store and retrieve `FOREIGN KEY'
  3695.      definitions.
  3696.  
  3697.    * `SHOW COLUMNS FROM table_name' (used by `mysql' client to allow
  3698.      expansions of column names) should not open the table, only the
  3699.      definition file. This will require less memory and be much faster.
  3700.  
  3701.    * Foreign keys for `MyISAM' tables, including cascading delete.
  3702.  
  3703.    * Fail-safe replication.
  3704.  
  3705.    * Replication should work with `RAND()' and user variables `@var'.
  3706.  
  3707.    * Online backup with very low performance penalty.  The online
  3708.      backup will make it easy to add a new replication slave without
  3709.      taking down the master.
  3710.  
  3711.    * Derived tables:
  3712.           SELECT a.col1, b.col2
  3713.                  FROM (SELECT MAX(col1) AS col1 FROM root_table) a,
  3714.                  other_table b
  3715.                  WHERE a.col1=b.col1;
  3716.  
  3717.      This could be done by automatically creating temporary tables for
  3718.      the derived tables for the duration of the query.
  3719.  
  3720.      Please, do note, that as per SQL-99, all derived tables have to be
  3721.      aliased. This is enforced in MySQL too ...
  3722.  
  3723.    * `ROLLUP' and `CUBE' OLAP (Online Analytical Processing) grouping
  3724.      options for data warehousing applications.
  3725.  
  3726.    * Allow `DELETE' on `MyISAM' tables to use the record cache.  To do
  3727.      this, we need to update the threads record cache when we update
  3728.      the `.MYD' file.
  3729.  
  3730.    * When using `SET CHARACTER SET' we should translate the whole query
  3731.      at once and not only strings. This will enable users to use the
  3732.      translated characters in database, table, and column names.
  3733.  
  3734.    * Add `record_in_range()' method to `MERGE' tables to be able to
  3735.      choose the right index when there are many to choose from. We
  3736.      should also extend the info interface to get the key distribution
  3737.      for each index, if `analyze' is run on all subtables.
  3738.  
  3739.    * Resolving the issue of `RENAME TABLE' on a table used in an active
  3740.      `MERGE' table possibly corrupting the table.
  3741.  
  3742.    * A faster, smaller embedded MySQL library (compatible with the old
  3743.      one).
  3744.  
  3745.    * Stable OpenSSL support (MySQL 4.0 supports rudimentary, not 100%
  3746.      tested, support for OpenSSL).
  3747.  
  3748.    * Add support for sorting on `UNICODE'.
  3749.  
  3750.    * Character set casts and syntax for handling multiple character
  3751.      sets.
  3752.  
  3753.    * Help for all commands from the client.
  3754.  
  3755.    * New faster client/server protocol which will support prepared
  3756.      statements, bound parameters, and bound result columns, binary
  3757.      transfer of data, warnings...
  3758.  
  3759.    * Add database and real table name (in case of alias) to the
  3760.      MYSQL_FIELD structure.
  3761.  
  3762.    * Add options to the client/server protocol to get progress notes
  3763.      for long running commands.
  3764.  
  3765.    * Implement `RENAME DATABASE'. To make this safe for all storage
  3766.      engines, it should work as follows:
  3767.         * Create the new database.
  3768.  
  3769.         * For every table do a rename of the table to another database,
  3770.           as we do with the `RENAME' command.
  3771.  
  3772.         * Drop the old database.
  3773.  
  3774.    * Add true `VARCHAR' support (there is already support for this in
  3775.      `MyISAM').
  3776.  
  3777.    * Optimise `BIT' type to take 1 bit (now `BIT' takes 1 char).
  3778.  
  3779.    * New internal file interface change.  This will make all file
  3780.      handling much more general and make it easier to add extensions
  3781.      like RAID.  (the current implementation is a hack.)
  3782.  
  3783.    * Better in-memory (`HEAP') tables:
  3784.         * Support for B-tree indexes
  3785.  
  3786.         * Dynamic size rows
  3787.  
  3788.         * Faster row handling (less copying)
  3789.  
  3790. Things That Must be Done in the Near Future
  3791. -------------------------------------------
  3792.  
  3793.    * Don't allow more than a defined number of threads to run MyISAM
  3794.      recover at the same time.
  3795.  
  3796.    * Change `INSERT ... SELECT' to optionally use concurrent inserts.
  3797.  
  3798.    * Return the original field types() when doing `SELECT MIN(column)
  3799.      ... GROUP BY'.
  3800.  
  3801.    * Multiple result sets.
  3802.  
  3803.    * Make it possible to specify `long_query_time' with a granularity
  3804.      in microseconds.
  3805.  
  3806.    * Link the `myisampack' code into the server.
  3807.  
  3808.    * Port of the MySQL code to QNX.
  3809.  
  3810.    * Port of the MySQL code to BeOS.
  3811.  
  3812.    * Port of the MySQL clients to LynxOS.
  3813.  
  3814.    * Add a temporary key buffer cache during `INSERT/DELETE/UPDATE' so
  3815.      that we can gracefully recover if the index file gets full.
  3816.  
  3817.    * If you perform an `ALTER TABLE' on a table that is symlinked to
  3818.      another disk, create temporary tables on this disk.
  3819.  
  3820.    * Implement a `DATE/DATETIME' type that handles time zone information
  3821.      properly so that dealing with dates in different time zones is
  3822.      easier.
  3823.  
  3824.    * FreeBSD and MIT-pthreads; do sleeping threads take CPU time?
  3825.  
  3826.    * Check if locked threads take any CPU time.
  3827.  
  3828.    * Fix configure so that one can compile all libraries (like `MyISAM')
  3829.      without threads.
  3830.  
  3831.    * Add an option to periodically flush key pages for tables with
  3832.      delayed keys if they haven't been used in a while.
  3833.  
  3834.    * Allow join on key parts (optimisation issue).
  3835.  
  3836.    * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do a
  3837.      concurrent insert at the end of the file if the file is
  3838.      read-locked.
  3839.  
  3840.    * Server-side cursors.
  3841.  
  3842.    * Check if `lockd' works with modern Linux kernels; if not, we have
  3843.      to fix `lockd'!  To test this, start `mysqld' with
  3844.      `--enable-locking' and run the different fork* test suits. They
  3845.      shouldn't give any errors if `lockd' works.
  3846.  
  3847.    * Allow SQL variables in `LIMIT', like in `LIMIT @a,@b'.
  3848.  
  3849.    * Allow update of variables in `UPDATE' statements. For example:
  3850.      `UPDATE TABLE foo SET @a=a+b,a=@a, b=@a+c'.
  3851.  
  3852.    * Change when user variables are updated so that one can use them
  3853.      with `GROUP BY', as in the following example: `SELECT id,
  3854.      @a:=COUNT(*), SUM(sum_col)/@a FROM table_name GROUP BY id'.
  3855.  
  3856.    * Don't add automatic `DEFAULT' values to columns.  Give an error
  3857.      when using an `INSERT' that doesn't contain a column that doesn't
  3858.      have a `DEFAULT'.
  3859.  
  3860.    * Fix `libmysql.c' to allow two `mysql_query()' commands in a row
  3861.      without reading results or give a nice error message when one does
  3862.      this.
  3863.  
  3864.    * Check why MIT-pthreads `ctime()' doesn't work on some FreeBSD
  3865.      systems.
  3866.  
  3867.    * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  3868.      `TIMESTAMP' and `AUTO_INCREMENT' fields.
  3869.  
  3870.    * Added `LOAD DATE INFILE ... UPDATE' syntax.
  3871.         * For tables with primary keys, if the data contains the
  3872.           primary key, entries matching that primary key are updated
  3873.           from the remainder of the columns. However, columns *missing*
  3874.           from the incoming data feed are not touched.
  3875.  
  3876.         * For tables with primary keys that are missing some part of
  3877.           the key in the incoming data stream, or that have no primary
  3878.           key, the feed is treated as a `LOAD DATA INFILE ... REPLACE
  3879.           INTO' now.
  3880.  
  3881.    * Make `LOAD DATA INFILE' understand syntax like:
  3882.           LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
  3883.                TEXT_FIELDS (text_field1, text_field2, text_field3)
  3884.                SET table_field1=CONCAT(text_field1, text_field2),
  3885.                    table_field3=23
  3886.                IGNORE text_field3
  3887.      This can be used to skip over extra columns in the text file, or
  3888.      update columns based on expressions of the read data.
  3889.  
  3890.    * `LOAD DATA INFILE 'file_name' INTO TABLE 'table_name' ERRORS TO
  3891.      err_table_name'.  This would cause any errors and warnings to be
  3892.      logged into the `err_table_name' table. That table would have a
  3893.      structure like:
  3894.  
  3895.           line_number    - line number in datafile
  3896.           error_message  - the error/warning message
  3897.           and maybe
  3898.           data_line      - the line from the datafile
  3899.  
  3900.    * Automatic output from `mysql' to Netscape.
  3901.  
  3902.    * `LOCK DATABASES' (with various options.)
  3903.  
  3904.    * Functions: ADD_TO_SET(value,set) and REMOVE_FROM_SET(value,set).
  3905.  
  3906.    * Add use of `t1 JOIN t2 ON ...' and `t1 JOIN t2 USING ...'
  3907.      Currently, you can only use this syntax with `LEFT JOIN'.
  3908.  
  3909.    * Many more variables for `show status'.  Records reads and updates.
  3910.      Selects on 1 table and selects with joins.  Mean number of tables
  3911.      in select. Number of `ORDER BY' and `GROUP BY' queries.
  3912.  
  3913.    * If you abort `mysql' in the middle of a query, you should open
  3914.      another connection and kill the old running query.  Alternatively,
  3915.      an attempt should be made to detect this in the server.
  3916.  
  3917.    * Add a storage engine interface for table information so that you
  3918.      can use it as a system table. This would be a bit slow if you
  3919.      requested information about all tables, but very flexible.  `SHOW
  3920.      INFO FROM tbl_name' for basic table information should be
  3921.      implemented.
  3922.  
  3923.    * `NATURAL JOIN'.
  3924.  
  3925.    * Allow `SELECT a FROM crash_me LEFT JOIN crash_me2 USING (a)'; in
  3926.      this case `a' is assumed to come from the `crash_me' table.
  3927.  
  3928.    * Fix so that `ON' and `USING' works with the `JOIN' join type.
  3929.  
  3930.    * Oracle-like `CONNECT BY PRIOR ...' to search hierarchy structures.
  3931.  
  3932.    * `mysqladmin copy database new-database'; requires `COPY' command
  3933.      to be added to `mysqld'.
  3934.  
  3935.    * Processlist should show number of queries/threads.
  3936.  
  3937.    * `SHOW HOSTS' for printing information about the hostname cache.
  3938.  
  3939.    * `DELETE' and `REPLACE' options to the `UPDATE' statement (this
  3940.      will delete rows when one gets a duplicate key error while
  3941.      updating).
  3942.  
  3943.    * Change the format of `DATETIME' to store fractions of seconds.
  3944.  
  3945.    * Add all missing ANSI92 and ODBC 3.0 types.
  3946.  
  3947.    * Change table names from empty strings to `NULL' for calculated
  3948.      columns.
  3949.  
  3950.    * Don't use `Item_copy_string' on numerical values to avoid
  3951.      number->string->number conversion in case of: `SELECT
  3952.      COUNT(*)*(id+0) FROM table_name GROUP BY id'
  3953.  
  3954.    * Make it possible to use the new GNU regexp library instead of the
  3955.      current one (the GNU library should be much faster than the old
  3956.      one).
  3957.  
  3958.    * Change so that `ALTER TABLE' doesn't abort clients that execute
  3959.      `INSERT DELAYED'.
  3960.  
  3961.    * Fix so that when columns are referenced in an `UPDATE' clause,
  3962.      they contain the old values from before the update started.
  3963.  
  3964.    * Add simulation of `pread()'/`pwrite()' on Windows to enable
  3965.      concurrent inserts.
  3966.  
  3967.    * A logfile analyser that could parse out information about which
  3968.      tables are hit most often, how often multi-table joins are
  3969.      executed, etc.  It should help users identify areas or table
  3970.      design that could be optimised to execute much more efficient
  3971.      queries.
  3972.  
  3973.    * Add `SUM(DISTINCT)'.
  3974.  
  3975.    * Add `ANY()', `EVERY()', and `SOME()' group functions. In ANSI SQL
  3976.      these work only on boolean columns, but we can extend these to
  3977.      work on any columns/expressions by applying: value == 0 -> FALSE
  3978.      and value <> 0 -> TRUE.
  3979.  
  3980.    * Fix that the type for `MAX(column)' is the same as the column type:
  3981.           mysql> CREATE TABLE t1 (a DATE);
  3982.           mysql> INSERT INTO t1 VALUES (NOW());
  3983.           mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
  3984.           mysql> SHOW COLUMNS FROM t2;
  3985.  
  3986.    * Come up with a nice syntax for a statement that will `UPDATE' the
  3987.      row if it exists and `INSERT' a new row if the row didn't exist
  3988.      (like `REPLACE' works with `INSERT' / `DELETE').
  3989.  
  3990. Things That Have to be Done Sometime
  3991. ------------------------------------
  3992.  
  3993.    * Implement function:
  3994.      `get_changed_tables(timeout,table1,table2,...)'.
  3995.  
  3996.    * Change reading through tables to use memmap when possible. Now only
  3997.      compressed tables use memmap.
  3998.  
  3999.    * Make the automatic timestamp code nicer.  Add timestamps to the
  4000.      update log with `SET TIMESTAMP=#;'.
  4001.  
  4002.    * Use read/write mutex in some places to get more speed.
  4003.  
  4004.    * Full foreign key support in for `MyISAM' tables, probably after
  4005.      the implementation of stored procedures with triggers.
  4006.  
  4007.    * Simple views (first on one table, later on any expression).
  4008.  
  4009.    * Automatically close some tables if a table, temporary table, or
  4010.      temporary files gets error 23 (not enough open files).
  4011.  
  4012.    * When one finds a field=#, change all occurrences of field to #.
  4013.      Now this is only done for some simple cases.
  4014.  
  4015.    * Change all const expressions with calculated expressions if
  4016.      possible.
  4017.  
  4018.    * Optimise key = expression. At the moment only key = field or key =
  4019.      constant are optimised.
  4020.  
  4021.    * Join some of the copy functions for nicer code.
  4022.  
  4023.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  4024.      better error messages (5 days).
  4025.  
  4026.    * Change the parser to use only one rule per different number of
  4027.      arguments in function.
  4028.  
  4029.    * Use of full calculation names in the order part (for ACCESS97).
  4030.  
  4031.    * `MINUS', `INTERSECT', and `FULL OUTER JOIN'.  (Currently `UNION'
  4032.      [in 4.0] and `LEFT OUTER JOIN' are supported.)
  4033.  
  4034.    * `SQL_OPTION MAX_SELECT_TIME=#' to put a time limit on a query.
  4035.  
  4036.    * Make the update log write to a database.
  4037.  
  4038.    * Add to `LIMIT' to allow retrieval of data from the end of a result
  4039.      set.
  4040.  
  4041.    * Alarm around client connect/read/write functions.
  4042.  
  4043.    * Please note the changes to `safe_mysqld': according to FSSTND
  4044.      (which Debian tries to follow) PID files should go into
  4045.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  4046.      be nice if you could put the "DATADIR" in the first declaration of
  4047.      "pidfile" and "log", so the placement of these files can be
  4048.      changed with a single statement.
  4049.  
  4050.    * Allow a client to request logging.
  4051.  
  4052.    * Add use of `zlib()' for `gzip'-ed files to `LOAD DATA INFILE'.
  4053.  
  4054.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  4055.  
  4056.    * Stored procedures. Triggers are also being looked at.
  4057.  
  4058.    * A simple (atomic) update language that can be used to write loops
  4059.      and such in the MySQL server.
  4060.  
  4061.    * Change to use semaphores when counting threads.  One should first
  4062.      implement a semaphore library to MIT-pthreads.
  4063.  
  4064.    * Don't assign a new `AUTO_INCREMENT' value when one sets a column
  4065.      to 0.  Use `NULL' instead.
  4066.  
  4067.    * Add full support for `JOIN' with parentheses.
  4068.  
  4069.    * As an alternative for one thread/connection manage a pool of
  4070.      threads to handle the queries.
  4071.  
  4072.    * Allow one to get more than one lock with `GET_LOCK'.  When doing
  4073.      this, one must also handle the possible deadlocks this change will
  4074.      introduce.
  4075.  
  4076. Time is given according to amount of work, not real time.
  4077.  
  4078. Things We Don't Plan To Do
  4079. --------------------------
  4080.  
  4081.    * Nothing; we aim toward full ANSI 92/ANSI 99 compliancy.
  4082.  
  4083. How MySQL Compares to Other Databases
  4084. =====================================
  4085.  
  4086. Our users have successfully run their own benchmarks against a number
  4087. of `Open Source' and traditional database servers.  We are aware of
  4088. tests against `Oracle' server, `DB/2' server, `Microsoft SQL Server',
  4089. and other commercial products.  Due to legal reasons we are restricted
  4090. from publishing some of those benchmarks in our reference manual.
  4091.  
  4092. This section includes a comparison with `mSQL' for historical reasons
  4093. and with `PostgreSQL' as it is also an `Open Source' database. If you
  4094. have benchmark results that we can publish, please contact us at
  4095. <benchmarks@mysql.com>.
  4096.  
  4097. For comparative lists of all supported functions and types as well as
  4098. measured operational limits of many different database systems, see the
  4099. `crash-me' web page at `http://www.mysql.com/information/crash-me.php'.
  4100.  
  4101. How MySQL Compares to `mSQL'
  4102. ----------------------------
  4103.  
  4104. *Performance*
  4105.      For a true comparison of speed, consult the growing MySQL benchmark
  4106.      suite. *Note MySQL Benchmarks::.
  4107.  
  4108.      Because there is no thread creation overhead, a small parser, few
  4109.      features, and simple security, `mSQL' should be quicker at:
  4110.  
  4111.         * Tests that perform repeated connects and disconnects, running
  4112.           a very simple query during each connection.
  4113.  
  4114.         * `INSERT' operations into very simple tables with few columns
  4115.           and keys.
  4116.  
  4117.         * `CREATE TABLE' and `DROP TABLE'.
  4118.  
  4119.         * `SELECT' on something that isn't an index. (A table scan is
  4120.           very easy.)
  4121.  
  4122.      Because these operations are so simple, it is hard to be better at
  4123.      them when you have a higher startup overhead. After the connection
  4124.      is established, MySQL Server should perform much better.
  4125.  
  4126.      On the other hand, MySQL Server is much faster than `mSQL' (and
  4127.      most other SQL implementations) on the following:
  4128.  
  4129.         * Complex `SELECT' operations.
  4130.  
  4131.         * Retrieving large results (MySQL Server has a better, faster,
  4132.           and safer protocol).
  4133.  
  4134.         * Tables with variable-length strings because MySQL Server has
  4135.           more efficient handling and can have indexes on `VARCHAR'
  4136.           columns.
  4137.  
  4138.         * Handling tables with many columns.
  4139.  
  4140.         * Handling tables with large record lengths.
  4141.  
  4142.         * `SELECT' with many expressions.
  4143.  
  4144.         * `SELECT' on large tables.
  4145.  
  4146.         * Handling many connections at the same time. MySQL Server is
  4147.           fully multi-threaded. Each connection has its own thread,
  4148.           which means that no thread has to wait for another (unless a
  4149.           thread is modifying a table another thread wants to access).
  4150.           In `mSQL', once one connection is established, all others
  4151.           must wait until the first has finished, regardless of whether
  4152.           the connection is running a query that is short or long. When
  4153.           the first connection terminates, the next can be served,
  4154.           while all the others wait again, etc.
  4155.  
  4156.         * Joins.  `mSQL' can become pathologically slow if you change
  4157.           the order of tables in a `SELECT'. In the benchmark suite, a
  4158.           time more than 15,000 times slower than MySQL Server was
  4159.           seen.  This is due to `mSQL''s lack of a join optimiser to
  4160.           order tables in the optimal order.  However, if you put the
  4161.           tables in exactly the right order in `mSQL'2 and the `WHERE'
  4162.           is simple and uses index columns, the join will be relatively
  4163.           fast!  *Note MySQL Benchmarks::.
  4164.  
  4165.         * `ORDER BY' and `GROUP BY'.
  4166.  
  4167.         * `DISTINCT'.
  4168.  
  4169.         * Using `TEXT' or `BLOB' columns.
  4170.  
  4171. *SQL Features*
  4172.         * `GROUP BY' and `HAVING'.  `mSQL' does not support `GROUP BY'
  4173.           at all.  MySQL Server supports a full `GROUP BY' with both
  4174.           `HAVING' and the following functions: `COUNT()', `AVG()',
  4175.           `MIN()', `MAX()', `SUM()', and `STD()'.  `COUNT(*)' is
  4176.           optimised to return very quickly if the `SELECT' retrieves
  4177.           from one table, no other columns are retrieved, and there is
  4178.           no `WHERE' clause.  `MIN()' and `MAX()' may take string
  4179.           arguments.
  4180.  
  4181.         * `INSERT' and `UPDATE' with calculations.  MySQL Server can do
  4182.           calculations in an `INSERT' or `UPDATE'.  For example:
  4183.  
  4184.                mysql> UPDATE SET x=x*10+y WHERE x<20;
  4185.  
  4186.         * Aliasing.  MySQL Server has column aliasing.
  4187.  
  4188.         * Qualifying column names.  In MySQL Server, if a column name
  4189.           is unique among the tables used in a query, you do not have
  4190.           to use the full qualifier.
  4191.  
  4192.         * `SELECT' with functions.  MySQL Server has many functions
  4193.           (too many to list here; see *Note Functions::).
  4194.  
  4195.  
  4196. *Disk Space Efficiency*
  4197.      That is, how small can you make your tables?
  4198.  
  4199.      MySQL Server has very precise types, so you can create tables that
  4200.      take very little space. An example of a useful MySQL datatype is
  4201.      the `MEDIUMINT' that is 3 bytes long. If you have 100 million
  4202.      records, saving even 1 byte per record is very important.
  4203.  
  4204.      `mSQL2' has a more limited set of column types, so it is more
  4205.      difficult to get small tables.
  4206.  
  4207. *Stability*
  4208.      This is harder to judge objectively. For a discussion of MySQL
  4209.      Server stability, see *Note Stability::.
  4210.  
  4211.      We have no experience with `mSQL' stability, so we cannot say
  4212.      anything about that.
  4213.  
  4214. *Price*
  4215.      Another important issue is the license. MySQL Server has a more
  4216.      flexible license than `mSQL', and is also less expensive than
  4217.      `mSQL'.  Whichever product you choose to use, remember to at least
  4218.      consider paying for a license or e-mail support.
  4219.  
  4220. *Perl Interfaces*
  4221.      MySQL Server has basically the same interfaces to Perl as `mSQL'
  4222.      with some added features.
  4223.  
  4224. *JDBC (Java)*
  4225.      MySQL Server currently has a lot of different JDBC drivers:
  4226.  
  4227.         * MySQL Connector/J is a native Java driver.  Version 3.x is
  4228.           released under dual licensing (GPL and commercial).
  4229.  
  4230.         * The Resin driver: this is a commercial JDBC driver released
  4231.           under open source.
  4232.           `http://www.caucho.com/projects/jdbc-mysql/index.xtp'
  4233.  
  4234.         * The gwe driver: a Java interface by GWE technologies (not
  4235.           supported anymore).
  4236.  
  4237.         * The jms driver: an improved gwe driver by Xiaokun Kelvin ZHU
  4238.           <X.Zhu@brad.ac.uk> (not supported anymore).
  4239.  
  4240.         * The twz driver: a type 4 JDBC driver by Terrence W. Zellers
  4241.           <zellert@voicenet.com>.  This is commercial but is free for
  4242.           private and educational use (not supported anymore).
  4243.  
  4244.      The recommended driver is the mm driver. The Resin driver may also
  4245.      be good (at least the benchmarks look good), but we haven't
  4246.      received that much information about this yet.
  4247.  
  4248.      We know that `mSQL' has a JDBC driver, but we have too little
  4249.      experience with it to compare.
  4250.  
  4251. *Rate of Development*
  4252.      MySQL Server has a small core team of developers, but we are quite
  4253.      used to coding C and C++ very rapidly. Because threads, functions,
  4254.      `GROUP BY', and so on are still not implemented in `mSQL', it has
  4255.      a lot of catching up to do. To get some perspective on this, you
  4256.      can view the `mSQL' `HISTORY' file for the last year and compare
  4257.      it with the News section of the MySQL Reference Manual (*note
  4258.      News::). It should be pretty obvious which one has developed most
  4259.      rapidly.
  4260.  
  4261. *Utility Programs*
  4262.      Both `mSQL' and MySQL Server have many interesting third-party
  4263.      tools. Because it is very easy to port upward (from `mSQL' to
  4264.      MySQL Server), almost all the interesting applications that are
  4265.      available for `mSQL' are also available for MySQL Server.
  4266.  
  4267.      MySQL Server comes with a simple `msql2mysql' program that fixes
  4268.      differences in spelling between `mSQL' and MySQL Server for the
  4269.      most-used C API functions.  For example, it changes instances of
  4270.      `msqlConnect()' to `mysql_connect()'. Converting a client program
  4271.      from `mSQL' to MySQL Server usually requires only minor effort.
  4272.  
  4273. How to Convert `mSQL' Tools for MySQL
  4274. .....................................
  4275.  
  4276. According to our experience, it doesn't take long to convert tools such
  4277. as `msql-tcl' and `msqljava' that use the `mSQL' C API so that they
  4278. work with the MySQL C API.
  4279.  
  4280. The conversion procedure is:
  4281.  
  4282.   1. Run the shell script `msql2mysql' on the source. This requires the
  4283.      `replace' program, which is distributed with MySQL Server.
  4284.  
  4285.   2. Compile.
  4286.  
  4287.   3. Fix all compiler errors.
  4288.  
  4289. Differences between the `mSQL' C API and the MySQL C API are:
  4290.  
  4291.    * MySQL Server uses a `MYSQL' structure as a connection type (`mSQL'
  4292.      uses an `int').
  4293.  
  4294.    * `mysql_connect()' takes a pointer to a `MYSQL' structure as a
  4295.      parameter.  It is easy to define one globally or to use `malloc()'
  4296.      to get one.  `mysql_connect()' also takes two parameters for
  4297.      specifying the user and password.  You may set these to `NULL,
  4298.      NULL' for default use.
  4299.  
  4300.    * `mysql_error()' takes the `MYSQL' structure as a parameter.  Just
  4301.      add the parameter to your old `msql_error()' code if you are
  4302.      porting old code.
  4303.  
  4304.    * MySQL Server returns an error number and a text error message for
  4305.      all errors. `mSQL' returns only a text error message.
  4306.  
  4307.    * Some incompatibilities exist as a result of MySQL Server supporting
  4308.      multiple connections to the server from the same process.
  4309.  
  4310. How `mSQL' and MySQL Client/Server Communications Protocols Differ
  4311. ..................................................................
  4312.  
  4313. There are enough differences that it is impossible (or at least not
  4314. easy) to support both.
  4315.  
  4316. The most significant ways in which the MySQL protocol differs from the
  4317. `mSQL' protocol are listed here:
  4318.  
  4319.    * A message buffer may contain many result rows.
  4320.  
  4321.    * The message buffers are dynamically enlarged if the query or the
  4322.      result is bigger than the current buffer, up to a configurable
  4323.      server and client limit.
  4324.  
  4325.    * All packets are numbered to catch duplicated or missing packets.
  4326.  
  4327.    * All column values are sent in ASCII. The lengths of columns and
  4328.      rows are sent in packed binary coding (1, 2, or 3 bytes).
  4329.  
  4330.    * MySQL can read in the result unbuffered (without having to store
  4331.      the full set in the client).
  4332.  
  4333.    * If a single read/write takes more than 30 seconds, the server
  4334.      closes the connection.
  4335.  
  4336.    * If a connection is idle for 8 hours, the server closes the
  4337.      connection.
  4338.  
  4339. How `mSQL' 2.0 SQL Syntax Differs from MySQL
  4340. ............................................
  4341.  
  4342. *Column types*
  4343.  
  4344. `MySQL Server'
  4345.      Has the following additional types (among others; *note `CREATE
  4346.      TABLE': CREATE TABLE.):
  4347.         * `ENUM' type for one of a set of strings.
  4348.  
  4349.         * `SET' type for many of a set of strings.
  4350.  
  4351.         * `BIGINT' type for 64-bit integers.
  4352.  
  4353. `'
  4354.      MySQL Server also supports the following additional type
  4355.      attributes:
  4356.         * `UNSIGNED' option for integer and floating-point columns.
  4357.  
  4358.         * `ZEROFILL' option for integer columns.
  4359.  
  4360.         * `AUTO_INCREMENT' option for integer columns that are a
  4361.           `PRIMARY KEY'.  *Note `mysql_insert_id()': mysql_insert_id.
  4362.  
  4363.         * `DEFAULT' value for all columns.
  4364.  
  4365. `mSQL2'
  4366.      `mSQL' column types correspond to the MySQL types shown in the
  4367.      following table:
  4368.      `mSQL'     *Corresponding MySQL type*
  4369.      *type*     
  4370.      `CHAR(len)'`CHAR(len)'
  4371.      `TEXT(len)'`TEXT(len)'. `len' is the maximal length.  And
  4372.                 `LIKE' works.
  4373.      `INT'      `INT'. With many more options!
  4374.      `REAL'     `REAL'. Or `FLOAT'. Both 4- and 8-byte
  4375.                 versions are available.
  4376.      `UINT'     `INT UNSIGNED'
  4377.      `DATE'     `DATE'. Uses ANSI SQL format rather than
  4378.                 `mSQL''s own format.
  4379.      `TIME'     `TIME'
  4380.      `MONEY'    `DECIMAL(12,2)'. A fixed-point value with two
  4381.                 decimals.
  4382.  
  4383. *Index Creation*
  4384.  
  4385. `MySQL Server'
  4386.      Indexes may be specified at table creation time with the `CREATE
  4387.      TABLE' statement.
  4388.  
  4389. `mSQL'
  4390.      Indexes must be created after the table has been created, with
  4391.      separate `CREATE INDEX' statements.
  4392.  
  4393. *To Insert a Unique Identifier into a Table*
  4394.  
  4395. `MySQL Server'
  4396.      Use `AUTO_INCREMENT' as a column type specifier.  *Note
  4397.      `mysql_insert_id()': mysql_insert_id.
  4398.  
  4399. `mSQL'
  4400.      Create a `SEQUENCE' on a table and select the `_seq' column.
  4401.  
  4402. *To Obtain a Unique Identifier for a Row*
  4403.  
  4404. `MySQL Server'
  4405.      Add a `PRIMARY KEY' or `UNIQUE' key to the table and use this.
  4406.      New in Version 3.23.11: If the `PRIMARY' or `UNIQUE' key consists
  4407.      of only one column and this is of type integer, one can also refer
  4408.      to it as `_rowid'.
  4409.  
  4410. `mSQL'
  4411.      Use the `_rowid' column. Observe that `_rowid' may change over time
  4412.      depending on many factors.
  4413.  
  4414. *To Get the Time a Column Was Last Modified*
  4415.  
  4416. `MySQL Server'
  4417.      Add a `TIMESTAMP' column to the table. This column is
  4418.      automatically set to the current date and time for `INSERT' or
  4419.      `UPDATE' statements if you don't give the column a value or if you
  4420.      give it a `NULL' value.
  4421.  
  4422. `mSQL'
  4423.      Use the `_timestamp' column.
  4424.  
  4425. *`NULL' Value Comparisons*
  4426.  
  4427. `MySQL Server'
  4428.      MySQL Server follows ANSI SQL, and a comparison with `NULL' is
  4429.      always `NULL'.
  4430.  
  4431. `mSQL'
  4432.      In `mSQL', `NULL = NULL' is TRUE.  You must change `=NULL' to `IS
  4433.      NULL' and `<>NULL' to `IS NOT NULL' when porting old code from
  4434.      `mSQL' to MySQL Server.
  4435.  
  4436. *String Comparisons*
  4437.  
  4438. `MySQL Server'
  4439.      Normally, string comparisons are performed in case-independent
  4440.      fashion with the sort order determined by the current character
  4441.      set (ISO-8859-1 Latin1 by default).  If you don't like this,
  4442.      declare your columns with the `BINARY' attribute, which causes
  4443.      comparisons to be done according to the ASCII order used on the
  4444.      MySQL server host.
  4445.  
  4446. `mSQL'
  4447.      All string comparisons are performed in case-sensitive fashion with
  4448.      sorting in ASCII order.
  4449.  
  4450. *Case-insensitive Searching*
  4451.  
  4452. `MySQL Server'
  4453.      `LIKE' is a case-insensitive or case-sensitive operator, depending
  4454.      on the columns involved. If possible, MySQL uses indexes if the
  4455.      `LIKE' argument doesn't start with a wildcard character.
  4456.  
  4457. `mSQL'
  4458.      Use `CLIKE'.
  4459.  
  4460. *Handling of Trailing Spaces*
  4461.  
  4462. `MySQL Server'
  4463.      Strips all spaces at the end of `CHAR' and `VARCHAR' columns. Use
  4464.      a `TEXT' column if this behaviour is not desired.
  4465.  
  4466. `mSQL'
  4467.      Retains trailing space.
  4468.  
  4469. *`WHERE' Clauses*
  4470.  
  4471. `MySQL Server'
  4472.      MySQL correctly prioritises everything (`AND' is evaluated before
  4473.      `OR'). To get `mSQL' behaviour in MySQL Server, use parentheses
  4474.      (as shown in an example later in this section).
  4475.  
  4476. `mSQL'
  4477.      Evaluates everything from left to right. This means that some
  4478.      logical calculations with more than three arguments cannot be
  4479.      expressed in any way. It also means you must change some queries
  4480.      when you upgrade to MySQL Server. You do this easily by adding
  4481.      parentheses.  Suppose you have the following `mSQL' query:
  4482.           mysql> SELECT * FROM table WHERE a=1 AND b=2 OR a=3 AND b=4;
  4483.      To make MySQL Server evaluate this the way that `mSQL' would, you
  4484.      must add parentheses:
  4485.           mysql> SELECT * FROM table WHERE (a=1 AND (b=2 OR (a=3 AND (b=4))));
  4486.  
  4487. *Access Control*
  4488.  
  4489. `MySQL Server'
  4490.      Has tables to store grant (permission) options per user, host, and
  4491.      database. *Note Privileges::.
  4492.  
  4493. `mSQL'
  4494.      Has a file `mSQL.acl' in which you can grant read/write privileges
  4495.      for users.
  4496.  
  4497. How MySQL Compares to `PostgreSQL'
  4498. ----------------------------------
  4499.  
  4500. When reading the following, please note that both products are
  4501. continually evolving.  We at MySQL AB and the PostgreSQL developers are
  4502. both working on making our respective databases as good as possible, so
  4503. we are both a serious alternative to any commercial database.
  4504.  
  4505. The following comparison is made by us at MySQL AB.  We have tried to be
  4506. as accurate and fair as possible, but although we know MySQL Server
  4507. thoroughly, we don't have a full knowledge of all PostgreSQL features,
  4508. so we may have got some things wrong.  We will, however, correct these
  4509. when they come to our attention.
  4510.  
  4511. We would first like to note that PostgreSQL and MySQL Server are both
  4512. widely used products, but with different design goals, even if we are
  4513. both striving toward ANSI SQL compliancy.  This means that for some
  4514. applications MySQL Server is more suited, while for others PostgreSQL
  4515. is more suited.  When choosing which database to use, you should first
  4516. check if the database's feature set satisfies your application.  If you
  4517. need raw speed, MySQL Server is probably your best choice.  If you need
  4518. some of the extra features that only PostgreSQL can offer, you should
  4519. use `PostgreSQL'.
  4520.  
  4521. MySQL and PostgreSQL development strategies
  4522. ...........................................
  4523.  
  4524. When adding things to MySQL Server we take pride to do an optimal,
  4525. definite solution.  The code should be so good that we shouldn't have
  4526. any need to change it in the foreseeable future.  We also do not like
  4527. to sacrifice speed for features but instead will do our utmost to find
  4528. a solution that will give maximal throughput.  This means that
  4529. development will take a little longer, but the end result will be well
  4530. worth this.  This kind of development is only possible because all
  4531. server code are checked by one of a few (currently two) persons before
  4532. it's included in the MySQL server.
  4533.  
  4534. We at MySQL AB believe in frequent releases to be able to push out new
  4535. features quickly to our users.  Because of this we do a new small
  4536. release about every three weeks, and a major branch every year.  All
  4537. releases are thoroughly tested with our testing tools on a lot of
  4538. different platforms.
  4539.  
  4540. PostgreSQL is based on a kernel with lots of contributors. In this setup
  4541. it makes sense to prioritise adding a lot of new features, instead of
  4542. implementing them optimally, because one can always optimise things
  4543. later if there arises a need for this.
  4544.  
  4545. Another big difference between MySQL Server and PostgreSQL is that
  4546. nearly all of the code in the MySQL server is coded by developers that
  4547. are employed by MySQL AB and are still working on the server code. The
  4548. exceptions are the transaction engines and the regexp library.
  4549.  
  4550. This is in sharp contrast to the PostgreSQL code, the majority of which
  4551. is coded by a big group of people with different backgrounds.  It was
  4552. only recently that the PostgreSQL developers announced that their
  4553. current developer group had finally had time to take a look at all the
  4554. code in the current PostgreSQL release.
  4555.  
  4556. Both of the aforementioned development methods have their own merits
  4557. and drawbacks.  We here at MySQL AB think, of course, that our model is
  4558. better because our model gives better code consistency, more optimal
  4559. and reusable code, and in our opinion, fewer bugs.  Because we are the
  4560. authors of the MySQL server code, we are better able to coordinate new
  4561. features and releases.
  4562.  
  4563. Featurewise Comparison of MySQL and PostgreSQL
  4564. ..............................................
  4565.  
  4566. On the `crash-me' page (`http://www.mysql.com/information/crash-me.php')
  4567. you can find a list of those database constructs and limits that one
  4568. can detect automatically with a program.  Note, however, that a lot of
  4569. the numerical limits may be changed with startup options for their
  4570. respective databases.  This web page is, however, extremely useful when
  4571. you want to ensure that your applications work with many different
  4572. databases or when you want to convert your application from one
  4573. database to another.
  4574.  
  4575. MySQL Server offers the following advantages over PostgreSQL:
  4576.  
  4577.    * `MySQL' Server is generally much faster than PostgreSQL.  MySQL
  4578.      4.0.1 also has a query cache that can boost up the query speed for
  4579.      mostly-read-only sites many times.
  4580.  
  4581.    * MySQL has a much larger user base than PostgreSQL. Therefore, the
  4582.      code is tested more and has historically proven more stable than
  4583.      PostgreSQL.  MySQL Server is used more in production environments
  4584.      than PostgreSQL, mostly thanks to the fact that MySQL AB, formerly
  4585.      TCX DataKonsult AB, has provided top-quality commercial support
  4586.      for MySQL Server from the day it was released, whereas until
  4587.      recently PostgreSQL was unsupported.
  4588.  
  4589.    * MySQL Server works better on Windows than PostgreSQL does.  MySQL
  4590.      Server runs as a native Windows application (a service on
  4591.      NT/2000/XP), while PostgreSQL is run under the `Cygwin' emulation.
  4592.      We have heard that PostgreSQL is not yet that stable on Windows
  4593.      but we haven't been able to verify this ourselves.
  4594.  
  4595.    * MySQL has more APIs to other languages and is supported by more
  4596.      existing programs than PostgreSQL.  *Note Contrib::.
  4597.  
  4598.    * MySQL Server works on 24/7 heavy-duty systems.  In most
  4599.      circumstances you never have to run any cleanups on MySQL Server.
  4600.      PostgreSQL doesn't yet support 24/7 systems because you have to
  4601.      run `VACUUM' once in a while to reclaim space from `UPDATE' and
  4602.      `DELETE' commands and to perform statistics analyses that are
  4603.      critical to get good performance with PostgreSQL.  `VACUUM' is
  4604.      also needed after adding a lot of new rows to a table.  On a busy
  4605.      system with lots of changes, `VACUUM' must be run very frequently,
  4606.      in the worst cases even many times a day.  During the `VACUUM'
  4607.      run, which may take hours if the database is big, the database is,
  4608.      from a production standpoint, practically dead. Please note: in
  4609.      PostgreSQL version 7.2, basic vacuuming no longer locks tables,
  4610.      thus allowing normal user access during the vacuum.  A new `VACUUM
  4611.      FULL' command does old-style vacuum by locking the table and
  4612.      shrinking the on-disk copy of the table.
  4613.  
  4614.    * MySQL replication has been thoroughly tested, and is used by sites
  4615.      like:
  4616.         - Yahoo Finance (`http://finance.yahoo.com/')
  4617.  
  4618.         - Mobile.de (`http://www.mobile.de/')
  4619.  
  4620.         - Slashdot (`http://www.slashdot.org/')
  4621.  
  4622.    * Included in the MySQL distribution are two different testing
  4623.      suites, `mysql-test-run' and `crash-me'
  4624.      (`http://www.mysql.com/information/crash-me.php'), as well as a
  4625.      benchmark suite.  The test system is actively updated with code to
  4626.      test each new feature and almost all reproduceable bugs that have
  4627.      come to our attention.  We test MySQL Server with these on a lot
  4628.      of platforms before every release.  These tests are more
  4629.      sophisticated than anything we have seen from PostgreSQL, and they
  4630.      ensure that the MySQL Server is kept to a high standard.
  4631.  
  4632.    * There are far more books in print about MySQL Server than about
  4633.      PostgreSQL.  O'Reilly, SAMS, Que, and New Riders are all major
  4634.      publishers with books about MySQL.  All MySQL features are also
  4635.      documented in the MySQL online manual because when a new feature
  4636.      is implemented, the MySQL developers are required to document it
  4637.      before it's included in the source.
  4638.  
  4639.    * MySQL Server supports more of the standard ODBC functions than
  4640.      `PostgreSQL'.
  4641.  
  4642.    * MySQL Server has a much more sophisticated `ALTER TABLE'.
  4643.  
  4644.    * MySQL Server has support for tables without transactions for
  4645.      applications that need all the speed they can get. The tables may
  4646.      be memory-based, `HEAP' tables or disk based `MyISAM'.  *Note
  4647.      Table types::.
  4648.  
  4649.    * MySQL Server has support for two different storage engines that
  4650.      support transactions, `InnoDB', and `BerkeleyDB'.  Because every
  4651.      transaction engine performs differently under different
  4652.      conditions, this gives the application writer more options to find
  4653.      an optimal solution for his or her setup, if need be per
  4654.      individual table.  *Note Table types::.
  4655.  
  4656.    * `MERGE' tables gives you a unique way to instantly make a view over
  4657.      a set of identical tables and use these as one.  This is perfect
  4658.      for systems where you have log files that you order, for example,
  4659.      by month.  *Note MERGE::.
  4660.  
  4661.    * The option to compress read-only tables, but still have direct
  4662.      access to the rows in the table, gives you better performance by
  4663.      minimising disk reads.  This is very useful when you are archiving
  4664.      things.  *Note `myisampack': myisampack.
  4665.  
  4666.    * MySQL Server has internal support for full-text search. *Note
  4667.      Fulltext Search::.
  4668.  
  4669.    * You can access many databases from the same connection (depending,
  4670.      of course, on your privileges).
  4671.  
  4672.    * MySQL Server is coded from the start to be multi-threaded, while
  4673.      PostgreSQL uses processes.  Context switching and access to common
  4674.      storage areas is much faster between threads than between separate
  4675.      processes. This gives MySQL Server a big speed advantage in
  4676.      multi-user applications and also makes it easier for MySQL Server
  4677.      to take full advantage of symmetric multiprocessor (SMP) systems.
  4678.  
  4679.    * MySQL Server has a much more sophisticated privilege system than
  4680.      PostgreSQL.  While PostgreSQL only supports `INSERT', `SELECT',
  4681.      and `UPDATE/DELETE' grants per user on a database or a table,
  4682.      MySQL Server allows you to define a full set of different
  4683.      privileges on the database, table, and column level.  MySQL Server
  4684.      also allows you to specify the privilege on host and user
  4685.      combinations.  *Note GRANT::.
  4686.  
  4687.    * MySQL Server supports a compressed client/server protocol which
  4688.      improves performance over slow links.
  4689.  
  4690.    * MySQL Server employs a "storage engine" concept, and is the only
  4691.      relational database we know of built around this concept.  This
  4692.      allows different low-level table types to be called from the SQL
  4693.      engine, and each table type can be optimised for different
  4694.      performance characteristics.
  4695.  
  4696.    * All MySQL table types (except `InnoDB') are implemented as files
  4697.      (one table per file), which makes it really easy to back up, move,
  4698.      delete, and even symlink databases and tables, even when the
  4699.      server is down.
  4700.  
  4701.    * Tools to repair and optimise `MyISAM' tables (the most common
  4702.      MySQL table type).  A repair tool is only needed when a physical
  4703.      corruption of a datafile happens, usually from a hardware failure.
  4704.      It allows a majority of the data to be recovered.
  4705.  
  4706.    * Upgrading MySQL Server is painless.  When you are upgrading MySQL
  4707.      Server, you don't need to dump/restore your data, as you have to
  4708.      do with most PostgreSQL upgrades.
  4709.  
  4710. Drawbacks with MySQL Server compared to PostgreSQL:
  4711.  
  4712.    * The transaction support in MySQL Server is not yet as well tested
  4713.      as PostgreSQL's system.
  4714.  
  4715.    * Because MySQL Server uses threads, which are not yet flawless on
  4716.      many OSes, one must either use binaries from
  4717.      `http://www.mysql.com/downloads/', or carefully follow our
  4718.      instructions in *Note Installing source:: to get an optimal binary
  4719.      that works in all cases.
  4720.  
  4721.    * Table locking, as used by the non-transactional `MyISAM' tables, is
  4722.      in many cases faster than page locks, row locks, or versioning.
  4723.      The drawback, however, is that if one doesn't take into account
  4724.      how table locks work, a single long-running query can block a
  4725.      table for updates for a long time. This can usually be avoided
  4726.      when designing the application.  If not, one can always switch the
  4727.      trouble table to use one of the transactional table types. *Note
  4728.      Table locking::.
  4729.  
  4730.    * With UDF (user-defined functions) one can extend MySQL Server with
  4731.      both normal SQL functions and aggregates, but this is not yet as
  4732.      easy or as flexible as in PostgreSQL.  *Note Adding functions::.
  4733.  
  4734.    * Updates that run over multiple tables used to be harder to do in
  4735.      MySQL Server. However, this has been fixed in MySQL Server 4.0.2
  4736.      with multi-table `UPDATE' and in MySQL Server 4.1 with subselects.
  4737.      In MySQL Server 4.0 one can use multi-table deletes to delete from
  4738.      many tables at the same time. *Note DELETE::.
  4739.  
  4740. PostgreSQL currently offers the following advantages over MySQL Server:
  4741.  
  4742. Note that because we know the MySQL road map, we have included in the
  4743. following table the version when MySQL Server should support this
  4744. feature.  Unfortunately we couldn't do this for previous comparisons,
  4745. because we don't know the PostgreSQL roadmap.
  4746.  
  4747. *Feature*              *MySQL version*
  4748. Subselects             4.1
  4749. Foreign keys           5.0 (3.23 with InnoDB)
  4750. Views                  5.0
  4751. Stored procedures      5.0
  4752. Triggers               5.0
  4753. Unions                 4.0
  4754. Full join              4.1
  4755. Constraints            4.1 or 5.0
  4756. Cursors                4.1 or 5.0
  4757. R-trees                4.1 (for MyISAM
  4758.                        tables)
  4759. Inherited tables       Not planned
  4760. Extensible type        Not planned
  4761. system                 
  4762.  
  4763. Other reasons someone may consider using PostgreSQL:
  4764.  
  4765.    * Standard usage in PostgreSQL is closer to ANSI SQL in some cases.
  4766.  
  4767.    * One can speed up PostgreSQL by coding things as stored procedures.
  4768.  
  4769.    * For geographical data, R-trees make PostgreSQL better than MySQL
  4770.      Server.  (note: MySQL version 4.1 has R-trees for MyISAM tables).
  4771.  
  4772.    * The PostgreSQL optimiser can do some optimisation that the current
  4773.      MySQL optimiser can't do.  Most notable is doing joins when you
  4774.      don't have the proper keys in place and doing a join where you are
  4775.      using different keys combined with OR.  The MySQL benchmark suite
  4776.      at `http://www.mysql.com/information/benchmarks.html' shows you
  4777.      what kind of constructs you should watch out for when using
  4778.      different databases.
  4779.  
  4780.    * PostgreSQL has a bigger team of developers that contribute to the
  4781.      server.
  4782.  
  4783. Drawbacks with PostgreSQL compared to MySQL Server:
  4784.  
  4785.    * `VACUUM' makes PostgreSQL hard to use in a 24/7 environment.
  4786.  
  4787.    * Only transactional tables.
  4788.  
  4789.    * Much slower `INSERT', `DELETE', and `UPDATE'.
  4790.  
  4791. For a complete list of drawbacks, you should also examine the first
  4792. table in this section.
  4793.  
  4794. Benchmarking MySQL and PostgreSQL
  4795. .................................
  4796.  
  4797. The only `Open Source' benchmark that we know of that can be used to
  4798. benchmark MySQL Server and PostgreSQL (and other databases) is our own.
  4799. It can be found at `http://www.mysql.com/information/benchmarks.html'.
  4800.  
  4801. We have many times asked the PostgreSQL developers and some PostgreSQL
  4802. users to help us extend this benchmark to make it the definitive
  4803. benchmark for databases, but unfortunately we haven't gotten any
  4804. feedback for this.
  4805.  
  4806. We, the MySQL developers, have, because of this, spent a lot of hours
  4807. to get maximum performance from PostgreSQL for the benchmarks, but
  4808. because we don't know PostgreSQL intimately, we are sure that there are
  4809. things that we have missed.  We have on the benchmark page documented
  4810. exactly how we did run the benchmark so that it should be easy for
  4811. anyone to repeat and verify our results.
  4812.  
  4813. The benchmarks are usually run with and without the `--fast' option.
  4814. When run with `--fast' we are trying to use every trick the server can
  4815. do to get the code to execute as fast as possible.  The idea is that the
  4816. normal run should show how the server would work in a default setup and
  4817. the `--fast' run shows how the server would do if the application
  4818. developer would use extensions in the server to make his application run
  4819. faster.
  4820.  
  4821. When running with PostgreSQL and `--fast' we do a `VACUUM' after every
  4822. major table `UPDATE' and `DROP TABLE' to make the database in perfect
  4823. shape for the following `SELECT's.  The time for `VACUUM' is measured
  4824. separately.
  4825.  
  4826. When running with PostgreSQL 7.1.1 we could, however, not run with
  4827. `--fast' because during the `INSERT' test, the postmaster (the
  4828. PostgreSQL deamon) died and the database was so corrupted that it was
  4829. impossible to restart postmaster.   After this happened twice, we
  4830. decided to postpone the `--fast' test until the next PostgreSQL
  4831. release.  The details about the machine we run the benchmark on can be
  4832. found on the benchmark page.
  4833.  
  4834. Before going to the other benchmarks we know of, we would like to give
  4835. some background on benchmarks.
  4836.  
  4837. It's very easy to write a test that shows *any* database to be the best
  4838. database in the world, by just restricting the test to something the
  4839. database is very good at and not testing anything that the database is
  4840. not good at.  If one, after doing this, summarises the result as a
  4841. single figure, things are even easier.
  4842.  
  4843. This would be like us measuring the speed of MySQL Server compared to
  4844. PostgreSQL by looking at the summary time of the MySQL benchmarks on
  4845. our web page.  Based on this MySQL Server would be more than 40 times
  4846. faster than PostgreSQL, something that is, of course, not true.  We
  4847. could make things even worse by just taking the test where PostgreSQL
  4848. performs worst and claim that MySQL Server is more than 2000 times
  4849. faster than PostgreSQL.
  4850.  
  4851. The case is that MySQL does a lot of optimisations that PostgreSQL
  4852. doesn't do. This is, of course, also true the other way around.  An SQL
  4853. optimiser is a very complex thing, and a company could spend years just
  4854. making the optimiser faster and faster.
  4855.  
  4856. When looking at the benchmark results you should look for things that
  4857. you do in your application and just use these results to decide which
  4858. database would be best suited for your application.  The benchmark
  4859. results also show things a particular database is not good at and should
  4860. give you a notion about things to avoid and what you may have to do in
  4861. other ways.
  4862.  
  4863. We know of two benchmark tests that claim that PostgreSQL performs
  4864. better than MySQL Server.  These both where multi-user tests, a test
  4865. that we here at MySQL AB haven't had time to write and include in the
  4866. benchmark suite, mainly because it's a big task to do this in a manner
  4867. that is fair to all databases.
  4868.  
  4869. One is the benchmark paid for by Great Bridge, the company that for 16
  4870. months attempted to build a business based on PostgreSQL but now has
  4871. ceased operations. This is probably the worst benchmark we have ever
  4872. seen anyone conduct.  This was not only tuned to only test what
  4873. PostgreSQL is absolutely best at, but it was also totally unfair to
  4874. every other database involved in the test.
  4875.  
  4876. *Note*:  We know that even some of the main PostgreSQL developers did
  4877. not like the way Great Bridge conducted the benchmark, so we don't
  4878. blame the PostgreSQL team for the way the benchmark was done.
  4879.  
  4880. This benchmark has been condemned in a lot of postings and newsgroups,
  4881. so here we will just briefly repeat some things that were wrong with it.
  4882.  
  4883.    * The tests were run with an expensive commercial tool that makes it
  4884.      impossible for an `Open Source' company like us to verify the
  4885.      benchmarks, or even check how the benchmarks were really done.
  4886.      The tool is not even a true benchmark tool, but an
  4887.      application/setup testing tool.  To refer to this as a "standard"
  4888.      benchmark tool is to stretch the truth a long way.
  4889.  
  4890.    * Great Bridge admitted that they had optimised the PostgreSQL
  4891.      database (with `VACUUM' before the test) and tuned the startup for
  4892.      the tests, something they hadn't done for any of the other
  4893.      databases involved.  They say "This process optimises indexes and
  4894.      frees up disk space a bit.  The optimised indexes boost
  4895.      performance by some margin."  Our benchmarks clearly indicate that
  4896.      the difference in running a lot of selects on a database with and
  4897.      without `VACUUM' can easily differ by a factor of 10.
  4898.  
  4899.    * The test results were also strange.  The AS3AP test documentation
  4900.      mentions that the test does "selections, simple joins, projections,
  4901.      aggregates, one-tuple updates, and bulk updates."
  4902.  
  4903.      PostgreSQL is good at doing `SELECT's and `JOIN's (especially
  4904.      after a `VACUUM'), but doesn't perform as well on `INSERT's or
  4905.      `UPDATE's.  The benchmarks seem to indicate that only `SELECT's
  4906.      were done (or very few updates).  This could easily explain the
  4907.      good results for PostgreSQL in this test.  The bad results for
  4908.      MySQL will be obvious a bit down in this document.
  4909.  
  4910.    * They did run the so-called benchmark from a Windows machine
  4911.      against a Linux machine over ODBC, a setup that no normal database
  4912.      user would ever do when running a heavy multi-user application.
  4913.      This tested more the ODBC driver and the Windows protocol used
  4914.      between the clients than the database itself.
  4915.  
  4916.    * When running the database against Oracle and MS-SQL (Great Bridge
  4917.      has indirectly indicated the databases they used in the test), they
  4918.      didn't use the native protocol but instead ODBC.  Anyone that has
  4919.      ever used Oracle knows that all real applications use the native
  4920.      interface instead of ODBC.  Doing a test through ODBC and claiming
  4921.      that the results had anything to do with using the database in a
  4922.      real-world situation can't be regarded as fair.  They should have
  4923.      done two tests with and without ODBC to provide the right facts
  4924.      (after having gotten experts to tune all involved databases, of
  4925.      course).
  4926.  
  4927.    * They refer to the TPC-C tests, but they don't mention anywhere
  4928.      that the test they did was not a true TPC-C test and they were not
  4929.      even allowed to call it a TPC-C test.  A TPC-C test can only be
  4930.      conducted by the rules approved by the TPC Council
  4931.      (`http://www.tpc.org/'). Great Bridge didn't do that.  By doing
  4932.      this they have both violated the TPC trademark and miscredited
  4933.      their own benchmarks.  The rules set by the TPC Council are very
  4934.      strict to ensure that no one can produce false results or make
  4935.      unprovable statements.  Apparently Great Bridge wasn't interested
  4936.      in doing this.
  4937.  
  4938.    * After the first test, we contacted Great Bridge and mentioned to
  4939.      them some of the obvious mistakes they had done with MySQL Server:
  4940.  
  4941.         - Running with a debug version of our ODBC driver
  4942.  
  4943.         - Running on a Linux system that wasn't optimised for threads
  4944.  
  4945.         - Using an old MySQL version when there was a recommended newer
  4946.           one available
  4947.  
  4948.         - Not starting MySQL Server with the right options for heavy
  4949.           multi-user use (the default installation of MySQL Server is
  4950.           tuned for minimal resource use)
  4951.  
  4952.      Great Bridge did run a new test, with our optimised ODBC driver
  4953.      and with better startup options for MySQL Server, but refused to
  4954.      either use our updated glibc library or our standard binary (used
  4955.      by 80% of our users), which was statically linked with a fixed
  4956.      glibc library.
  4957.  
  4958.      According to what we know, Great Bridge did nothing to ensure that
  4959.      the other databases were set up correctly to run well in their test
  4960.      environment.  We are sure, however, that they didn't contact
  4961.      Oracle or Microsoft to ask for their advice in this matter. ;)
  4962.  
  4963.    * The benchmark was paid for by Great Bridge, and they decided to
  4964.      publish only partial, chosen results (instead of publishing it
  4965.      all).
  4966.  
  4967. Tim Perdue, a long-time PostgreSQL fan and a reluctant MySQL user,
  4968. published a comparison on PHPbuilder
  4969. (`http://www.phpbuilder.com/columns/tim20001112.php3').
  4970.  
  4971. When we became aware of the comparison, we phoned Tim Perdue about this
  4972. because there were a lot of strange things in his results.  For example,
  4973. he claimed that MySQL Server had a problem with five users in his
  4974. tests, when we know that there are users with similar machines as his
  4975. that are using MySQL Server with 2000 simultaneous connections doing
  4976. 400 queries per second.  (In this case the limit was the web bandwidth,
  4977. not the database.)
  4978.  
  4979. It sounded like he was using a Linux kernel that either had some
  4980. problems with many threads, such as kernels before 2.4, which had a
  4981. problem with many threads on multi-CPU machines. We have documented in
  4982. this manual how to fix this and Tim should be aware of this problem.
  4983.  
  4984. The other possible problem could have been an old glibc library and
  4985. that Tim didn't use a MySQL binary from our site, which is linked with
  4986. a corrected glibc library, but had compiled a version of his own.  In
  4987. any of these cases, the symptom would have been exactly what Tim had
  4988. measured.
  4989.  
  4990. We asked Tim if we could get access to his data so that we could repeat
  4991. the benchmark and if he could check the MySQL version on the machine to
  4992. find out what was wrong and he promised to come back to us about this.
  4993. He has not done that yet.
  4994.  
  4995. Because of this we can't put any trust in this benchmark either. :(
  4996.  
  4997. Over time things also change and the preceding benchmarks are not that
  4998. relevant anymore.  MySQL Server now has a couple of different storage
  4999. engines with different speed/concurrency tradeoffs.  *Note Table
  5000. types::. It would be interesting to see how the above tests would run
  5001. with the different transactional table types in MySQL Server.
  5002. PostgreSQL has, of course, also got new features since the test was
  5003. made.  As these tests are not publicly available there is no way for us
  5004. to know how the database would perform in the same tests today.
  5005.  
  5006. Conclusion:
  5007.  
  5008. The only benchmarks that exist today that anyone can download and run
  5009. against MySQL Server and PostgreSQL are the MySQL benchmarks.  We here
  5010. at MySQL AB believe that `Open Source' databases should be tested with
  5011. `Open Source' tools!  This is the only way to ensure that no one does
  5012. tests that nobody can reproduce and use this to claim that one database
  5013. is better than another.  Without knowing all the facts it's impossible
  5014. to answer the claims of the tester.
  5015.  
  5016. The thing we find strange is that every test we have seen about
  5017. PostgreSQL, that is impossible to reproduce, claims that PostgreSQL is
  5018. better in most cases while our tests, which anyone can reproduce,
  5019. clearly show otherwise.  With this we don't want to say that PostgreSQL
  5020. isn't good at many things (it is!) or that it isn't faster than MySQL
  5021. Server under certain conditions.  We would just like to see a fair test
  5022. where PostgreSQL performs very well, so that we could get some friendly
  5023. competition going!
  5024.  
  5025. For more information about our benchmark suite, see *Note MySQL
  5026. Benchmarks::.
  5027.  
  5028. We are working on an even better benchmark suite, including multi-user
  5029. tests, and a better documentation of what the individual tests really
  5030. do and how to add more tests to the suite.
  5031.  
  5032. MySQL Installation
  5033. ******************
  5034.  
  5035. This chapter describes how to obtain and install MySQL:
  5036.  
  5037.    * For a list of sites from which you can obtain MySQL, see *Note
  5038.      Getting MySQL: Getting MySQL.
  5039.  
  5040.    * To see which platforms are supported, see *Note Which OS::. Please
  5041.      note that not all supported systems are equally good for running
  5042.      MySQL on them.  On some it is much more robust and efficient than
  5043.      otherssee *Note Which OS:: for details.
  5044.  
  5045.    * Several versions of MySQL are available in both binary and source
  5046.      distributions.  We also provide public access to our current
  5047.      source tree for those who want to see our most recent developments
  5048.      and help us test new code.  To determine which version and type of
  5049.      distribution you should use, see *Note Which version::. When in
  5050.      doubt, use the binary distribution.
  5051.  
  5052.    * Installation instructions for binary and source distributions are
  5053.      described in *Note Installing binary::, and *Note Installing
  5054.      source::.  Each set of instructions includes a section on
  5055.      system-specific problems you may run into.
  5056.  
  5057.    * For post-installation procedures, see *Note Post-installation::.
  5058.      These procedures apply whether you install MySQL using a binary or
  5059.      source distribution.
  5060.  
  5061. Quick Standard Installation of MySQL
  5062. ====================================
  5063.  
  5064. Installing MySQL on Linux
  5065. -------------------------
  5066.  
  5067. The recommended way to install MySQL on Linux is by using an RPM file.
  5068. The MySQL RPMs are currently being built on a SuSE Linux 7.3 system but
  5069. should work on most versions of Linux that support `rpm' and use
  5070. `glibc'.
  5071.  
  5072. If you have problems with an RPM file, for example, if you receive the
  5073. error "`Sorry, the host 'xxxx' could not be looked up'"see *Note Binary
  5074. notes-Linux::.
  5075.  
  5076. The RPM files you may want to use are:
  5077.  
  5078.    * `MySQL-VERSION.i386.rpm'
  5079.  
  5080.      The MySQL server.  You will need this unless you only want to
  5081.      connect to a MySQL server running on another machine.
  5082.  
  5083.    * `MySQL-client-VERSION.i386.rpm'
  5084.  
  5085.      The standard MySQL client programs. You probably always want to
  5086.      install this package.
  5087.  
  5088.    * `MySQL-bench-VERSION.i386.rpm'
  5089.  
  5090.      Tests and benchmarks. Requires Perl and msql-mysql-modules RPMs.
  5091.  
  5092.    * `MySQL-devel-VERSION.i386.rpm'
  5093.  
  5094.      Libraries and include files needed if you want to compile other
  5095.      MySQL clients, such as the Perl modules.
  5096.  
  5097.    * `MySQL-embedded-VERSION.i386.rpm'
  5098.  
  5099.      The embedded MySQL server library. (MySQL 4.x only)
  5100.  
  5101.    * `MySQL-VERSION.src.rpm'
  5102.  
  5103.      This contains the source code for all of the previous packages. It
  5104.      can also be used to rebuild the RPMs on other architectures (for
  5105.      example, Alpha or SPARC).
  5106.  
  5107. To see all files in an RPM package, run:
  5108.      shell> rpm -qpl MySQL-VERSION.i386.rpm
  5109.  
  5110. To perform a standard minimal installation, run:
  5111.  
  5112.      shell> rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
  5113.  
  5114. To install just the client package, run:
  5115.  
  5116.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  5117.  
  5118. The RPM places data in `/var/lib/mysql'. The RPM also creates the
  5119. appropriate entries in `/etc/init.d/' to start the server automatically
  5120. at boot time. (This means that if you have performed a previous
  5121. installation, you may want to make a copy of your previously installed
  5122. MySQL startup file if you made any changes to it, so you don't lose
  5123. your changes.)
  5124.  
  5125. If you want to install the MySQL RPM on older Linux distributions that
  5126. do not support init scripts in `/etc/init.d' (directly or via a
  5127. symlink), you should create a symbolic link pointing to the old
  5128. location before installing the RPM:
  5129.  
  5130.      shell> cd /etc ; ln -s rc.d/init.d .
  5131.  
  5132. However, all current major Linux distributions should already support
  5133. this new directory layout as it is required for LSB (Linux Standard
  5134. Base) compliance.
  5135.  
  5136. After installing the RPM file(s), the `mysqld' daemon should be up and
  5137. running and you should now be able to start using MySQL.  *Note
  5138. Post-installation::.
  5139.  
  5140. If something goes wrong, you can find more information in the binary
  5141. installation chapter. *Note Installing binary::.
  5142.  
  5143. Installing MySQL on Windows
  5144. ---------------------------
  5145.  
  5146. The MySQL server for Windows is available in two distribution types:
  5147.   1. The binary distribution contains a setup program which installs
  5148.      everything you need so that you can start the server immediately.
  5149.  
  5150.   2. The source distribution contains all the code and support files
  5151.      for building the executables using the VC++ 6.0 compiler.  *Note
  5152.      Windows source build::.
  5153.  
  5154. Generally speaking, you should use the binary distribution.
  5155.  
  5156. You will need the following:
  5157.    * A 32-bit Windows Operating System such as 9x, Me, NT, 2000, or XP.
  5158.      The NT family (NT, Windows 2000 and XP) permits running the MySQL
  5159.      server as a service. *Note NT start::.
  5160.  
  5161.      If you want to use tables bigger than 4G, you should install MySQL
  5162.      on an NTFS or newer filesystem. Don't forget to use `MAX_ROWS' and
  5163.      `AVG_ROW_LENGTH' when you create the table. *Note CREATE TABLE::.
  5164.  
  5165.    * TCP/IP protocol support.
  5166.  
  5167.    * A copy of the MySQL binary or distribution for Windows, which can
  5168.      be downloaded from `http://www.mysql.com/downloads/'.
  5169.  
  5170.      Note: The distribution files are supplied with a zipped format and
  5171.      we recommend the use of an adequate FTP client with resume feature
  5172.      to avoid corruption of files during the download process.
  5173.  
  5174.    * A `ZIP' program to unpack the distribution file.
  5175.  
  5176.    * Enough space on the hard drive to unpack, install, and create the
  5177.      databases in accorandance with your requirements.
  5178.  
  5179.    * If you plan to connect to the MySQL server via `ODBC', you will
  5180.      also need the `MyODBC' driver. *Note ODBC::.
  5181.  
  5182. Installing the Binaries
  5183. .......................
  5184.  
  5185.   1. If you are working on an NT/2000/XP server, logon as a user with
  5186.      administrator privileges.
  5187.  
  5188.   2. If you are doing an upgrade of an earlier MySQL installation, it
  5189.      is necessary to stop the server. If you are running the server as
  5190.      a service, use:
  5191.  
  5192.           C:\> NET STOP MySQL
  5193.  
  5194.      Otherwise, use:
  5195.  
  5196.           C:\mysql\bin> mysqladmin -u root shutdown
  5197.  
  5198.   3. On NT/2000/XP machines, if you want to change the server executable
  5199.      (e.g., -max or -nt), it is also necessary to remove the service:
  5200.  
  5201.           C:\mysql\bin> mysqld-max-nt --remove
  5202.  
  5203.   4. Unzip the distribution file to a temporary directory.
  5204.  
  5205.   5. Run the `setup.exe' file to begin the installation process.  If
  5206.      you want to install into another directory than the default
  5207.      `c:\mysql', use the `Browse' button to specify your preferred
  5208.      directory.
  5209.  
  5210.   6. Finish the install process.
  5211.  
  5212. Preparing the Windows MySQL Environment
  5213. .......................................
  5214.  
  5215. Starting with MySQL 3.23.38, the Windows distribution includes both the
  5216. normal and the MySQL-Max server binaries.  Here is a list of the
  5217. different MySQL servers you can use:
  5218.  
  5219. *Binary*       *Description*
  5220. `mysqld'        Compiled with full debugging and automatic memory
  5221.                allocation checking, symbolic links, InnoDB, and BDB
  5222.                tables.
  5223. `mysqld-opt'    Optimised binary with no support for transactional
  5224.                tables.
  5225. `mysqld-nt'     Optimised binary for NT/2000/XP with support for named
  5226.                pipes.  You can run this version on Windows 9x/Me, but in
  5227.                this case no named pipes are created and you must have
  5228.                TCP/IP installed.
  5229. `mysqld-max'    Optimised binary with support for symbolic links, InnoDB
  5230.                and BDB tables.
  5231. `mysqld-max-nt' Like `mysqld-max', but compiled with support for named
  5232.                pipes.
  5233.  
  5234. Starting from 3.23.50, named pipes are only enabled if one starts
  5235. mysqld with `--enable-named-pipe'.
  5236.  
  5237. All of the preceding binaries are optimised for the Pentium Pro
  5238. processor but should work on any Intel processor >= i386.
  5239.  
  5240. You will need to use an option file to specify your MySQL configuration
  5241. under the following circumstances:
  5242.    * The installation or data directories are different from the default
  5243.      locations (`c:\mysql' and `c:\mysql\data').
  5244.  
  5245.    * You want to use one of these servers:
  5246.         * mysqld.exe
  5247.  
  5248.         * mysqld-max.exe
  5249.  
  5250.         * mysqld-max-nt.exe
  5251.  
  5252.    * You need to tune the server settings.
  5253.  
  5254. Normally you can use the `WinMySQLAdmin' tool to edit the option file
  5255. `my.ini'.  In this case you don't have to worry about the following
  5256. section.
  5257.  
  5258. There are two option files with the same function: `my.cnf' and
  5259. `my.ini'.  However, to avoid confusion, it's best if you use only of
  5260. one them. Both files are plain text.  The `my.cnf' file, if used,
  5261. should be created in the root directory of the C drive.  The `my.ini'
  5262. file, if used, should be created in the Windows system directory.  (This
  5263. directory is typically something like `C:\WINDOWS' or `C:\WINNT'.  You
  5264. can determine its exact location from the value of the `windir'
  5265. environment variable.)  MySQL looks first for the `my.ini' file, then
  5266. for the `my.cnf' file.
  5267.  
  5268. If your PC uses a boot loader where the C drive isn't the boot drive,
  5269. your only option is to use the `my.ini' file.  Also note that if you
  5270. use the `WinMySQLAdmin' tool, it uses only the `my.ini' file.  The
  5271. `\mysql\bin' directory contains a help file with instructions for using
  5272. this tool.
  5273.  
  5274. Using `notepad.exe', create the option file and edit the `[mysqld]'
  5275. section to specify values for the `basedir' and `datadir' parameters:
  5276.  
  5277.      [mysqld]
  5278.      # set basedir to installation path, e.g., c:/mysql
  5279.      basedir=the_install_path
  5280.      # set datadir to location of data directory,
  5281.      # e.g., c:/mysql/data or d:/mydata/data
  5282.      datadir=the_data_path
  5283.  
  5284. Note that Windows pathnames should be specified in option files using
  5285. forward slashes rather than backslashes.  If you do use backslashes, you
  5286. must double them.
  5287.  
  5288. If you would like to use a data directory different from the default of
  5289. `c:\mysql\data', you must copy the entire contents of the
  5290. `c:\mysql\data' directory to the new location.
  5291.  
  5292. If you want to use the `InnoDB' transactional tables, you need to
  5293. manually create two new directories to hold the InnoDB data and log
  5294. filese.g., `c:\ibdata' and `c:\iblogs'.  You will also need to add some
  5295. extra lines to the option file. *Note InnoDB start::.
  5296.  
  5297. If you don't want to use `InnoDB' tables, add the `skip-innodb' option
  5298. to the option file.
  5299.  
  5300. Now you are ready to test starting the server.
  5301.  
  5302. Starting the Server for the First Time
  5303. ......................................
  5304.  
  5305. Testing from a DOS command prompt is the best thing to do because the
  5306. server displays status messages that appear in the DOS window.  If
  5307. something is wrong with your configuration, these messages will make it
  5308. easier for you to identify and fix any problems.
  5309.  
  5310. Make sure you are in the directory where the server is located, then
  5311. enter this command:
  5312.  
  5313.      C:\mysql\bin> mysqld-max --standalone
  5314.  
  5315. You should see the following messages as the server starts up:
  5316.  
  5317.      InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist:
  5318.      InnoDB: a new database to be created!
  5319.      InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200
  5320.      InnoDB: Database physically writes the file full: wait...
  5321.      InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created
  5322.      InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280
  5323.      InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created
  5324.      InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280
  5325.      InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created
  5326.      InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280
  5327.      InnoDB: Doublewrite buffer not found: creating new
  5328.      InnoDB: Doublewrite buffer created
  5329.      InnoDB: creating foreign key constraint system tables
  5330.      InnoDB: foreign key constraint system tables created
  5331.      011024 10:58:25  InnoDB: Started
  5332.  
  5333. For further information about running MySQL on Windows, see *Note
  5334. Windows::.
  5335.  
  5336. General Installation Issues
  5337. ===========================
  5338.  
  5339. How to Get MySQL
  5340. ----------------
  5341.  
  5342. Check the MySQL homepage (`http://www.mysql.com/') for information
  5343. about the current version and for downloading instructions.
  5344.  
  5345. Our main mirror is located at `http://mirrors.sunsite.dk/mysql/'.
  5346.  
  5347. For a complete upto-date list of MySQL web/download mirrors, see
  5348. `http://www.mysql.com/downloads/mirrors.html'.  There you will also
  5349. find information about becoming a MySQL mirror site and how to report a
  5350. bad or out-of-date mirror.
  5351.  
  5352. Operating Systems Supported by MySQL
  5353. ------------------------------------
  5354.  
  5355. We use GNU Autoconf, so it is possible to port MySQL to all modern
  5356. systems with working Posix threads and a C++ compiler.  (To compile
  5357. only the client code, a C++ compiler is required but not threads.)  We
  5358. use and develop the software ourselves primarily on Sun Solaris
  5359. (Versions 2.5 - 2.7) and SuSE Linux Version 7.x.
  5360.  
  5361. Note that for many operating systems, the native thread support works
  5362. only in the latest versions. MySQL has been reported to compile
  5363. successfully on the following operating system/thread package
  5364. combinations:
  5365.  
  5366.    * AIX 4.x, 5.x with native threads.  *Note IBM-AIX::.
  5367.  
  5368.    * Amiga.
  5369.  
  5370.    * BSDI 2.x with the MIT-pthreads package.  *Note BSDI::.
  5371.  
  5372.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  5373.  
  5374.    * DEC Unix 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  5375.  
  5376.    * FreeBSD 2.x with the MIT-pthreads package.  *Note FreeBSD::.
  5377.  
  5378.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  5379.  
  5380.    * HP-UX 10.20 with the DCE threads or the MIT-pthreads package.
  5381.      *Note HP-UX 10.20::.
  5382.  
  5383.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  5384.  
  5385.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  5386.      Linux::.
  5387.  
  5388.    * Mac OS X.  *Note Mac OS X::.
  5389.  
  5390.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make).
  5391.      *Note NetBSD::.
  5392.  
  5393.    * OpenBSD > 2.5 with native threads. OpenBSD < 2.5 with the
  5394.      MIT-pthreads package.  *Note OpenBSD::.
  5395.  
  5396.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  5397.  
  5398.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  5399.  
  5400.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  5401.      Solaris::.
  5402.  
  5403.    * SunOS 4.x with the MIT-pthreads package.  *Note Solaris::.
  5404.  
  5405.    * Caldera (SCO) OpenServer with a recent port of the FSU Pthreads
  5406.      package.  *Note Caldera::.
  5407.  
  5408.    * Caldera (SCO) UnixWare 7.0.1.  *Note Caldera Unixware::.
  5409.  
  5410.    * Tru64 Unix
  5411.  
  5412.    * Windows 9x, Me, NT, 2000 and XP.  *Note Windows::.
  5413.  
  5414. Note that not all platforms are suited equally well for running MySQL.
  5415. How well a certain platform is suited for a high-load mission-critical
  5416. MySQL server is determined by the following factors:
  5417.  
  5418.    * General stability of the thread library. A platform may have
  5419.      excellent reputation otherwise, but if the thread library is
  5420.      unstable in the code that is called by MySQL, even if everything
  5421.      else is perfect, MySQL will be only as stable as the thread
  5422.      library.
  5423.  
  5424.    * The ability of the kernel and/or thread library to take advantage
  5425.      of *SMP* on multi-processor systems. In other words, when a process
  5426.      creates a thread, it should be possible for that thread to run on
  5427.      a different CPU than the original process.
  5428.  
  5429.    * The ability of the kernel and/or the thread library to run many
  5430.      threads which acquire/release a mutex over a short critical region
  5431.      frequently without excessive context switches. In other words, if
  5432.      the implementation of `pthread_mutex_lock()' is too anxious to
  5433.      yield CPU time, this will hurt MySQL tremendously. If this issue
  5434.      is not taken care of, adding extra CPUs will actually make MySQL
  5435.      slower.
  5436.  
  5437.    * General filesystem stability/performance.
  5438.  
  5439.    * Ability of the filesystem to deal with large files at all and deal
  5440.      with them efficiently, if your tables are big.
  5441.  
  5442.    * Our level of expertise here at MySQL AB with the platform. If we
  5443.      know a platform well, we introduce platform-specific
  5444.      optimisations/fixes enabled at compile time. We can also provide
  5445.      advice on configuring your system optimally for MySQL.
  5446.  
  5447.    * The amount of testing of similar configurations we have done
  5448.      internally.
  5449.  
  5450.    * The number of users that have successfully run MySQL on that
  5451.      platform in similar configurations. If this number is high, the
  5452.      chances of hitting some platform-specific surprises are much
  5453.      smaller.
  5454.  
  5455. Based on the preceding criteria, the best platforms for running MySQL
  5456. at this point are x86 with SuSE Linux 7.1, 2.4 kernel, and ReiserFS (or
  5457. any similar Linux distribution) and SPARC with Solaris 2.7 or 2.8.
  5458. FreeBSD comes third, but we really hope it will join the top club once
  5459. the thread library is improved. We also hope that at some point we will
  5460. be able to include all other platforms on which MySQL compiles, runs
  5461. okay, but not quite with the same level of stability and performance,
  5462. into the top category. This will require some effort on our part in
  5463. cooperation with the developers of the OS/library components MySQL
  5464. depends upon. If you are interested in making one of those components
  5465. better, are in a position to influence their development, and need more
  5466. detailed instructions on what MySQL needs to run better, send an e-mail
  5467. to <internals@lists.mysql.com>.
  5468.  
  5469. Please note that the preceding comparison is not to say that one OS is
  5470. better or worse than the other in general. We are talking about
  5471. choosing a particular OS for a dedicated purposerunning MySQL, and
  5472. compare platforms in that regard only. With this in mind, the result of
  5473. this comparison would be different if we included more issues into it.
  5474. And in some cases, the reason one OS is better than the other could
  5475. simply be that we have put forth more effort into testing on and
  5476. optimising for that particular platform.  We are just stating our
  5477. observations to help you decide on which platform to use MySQL on in
  5478. your setup.
  5479.  
  5480. Which MySQL Version to Use
  5481. --------------------------
  5482.  
  5483. The first decision to make is whether you want to use the latest
  5484. development release or the last stable release:
  5485.  
  5486.    * Normally, if you are beginning to use MySQL for the first time or
  5487.      trying to port it to some system for which there is no binary
  5488.      distribution, we recommend going with the stable release
  5489.      (currently version 3.23).  Note that all MySQL releases are
  5490.      checked with the MySQL benchmarks and an extensive test suite
  5491.      before each release (even the development releases).
  5492.  
  5493.    * Otherwise, if you are running an old system and want to upgrade,
  5494.      but don't want to take chances with a non-seamless upgrade, you
  5495.      should upgrade to the latest in the same branch you are using
  5496.      (where only the last version number is newer than yours).  We have
  5497.      tried to fix only fatal bugs and make small, relatively safe
  5498.      changes to that version.
  5499.  
  5500. The second decision to make is whether you want to use a source
  5501. distribution or a binary distribution.  In most cases you should
  5502. probably use a binary distribution, if one exists for your platform, as
  5503. this generally will be easier to install than a source distribution.
  5504.  
  5505. In the following cases you probably will be better off with a source
  5506. installation:
  5507.  
  5508.    * If you want to install MySQL at some explicit location.  (The
  5509.      standard binary distributions are "ready to run" at any place, but
  5510.      you may want to get even more flexibility).
  5511.  
  5512.    * To be able to satisfy different user requirements, we are
  5513.      providing two different binary versions: one compiled with the
  5514.      non-transactional storage engines (a small, fast binary), and one
  5515.      configured with the most important extended options like
  5516.      transaction-safe tables.  Both versions are compiled from the same
  5517.      source distribution.  All native `MySQL' clients can connect to
  5518.      both MySQL versions.
  5519.  
  5520.      The extended MySQL binary distribution is marked with the `-max'
  5521.      suffix and is configured with the same options as `mysqld-max'.
  5522.      *Note `mysqld-max': mysqld-max.
  5523.  
  5524.      If you want to use the MySQL-Max RPM, you must first install the
  5525.      standard MySQL RPM.
  5526.  
  5527.    * If you want to configure `mysqld' with some extra features that are
  5528.      not in the standard binary distributions.  Here is a list of the
  5529.      most common extra options that you may want to use:
  5530.  
  5531.         * `--with-innodb'
  5532.  
  5533.         * `--with-berkeley-db'
  5534.  
  5535.         * `--with-raid'
  5536.  
  5537.         * `--with-libwrap'
  5538.  
  5539.         * `--with-named-z-lib  (This is done for some of the binaries)'
  5540.  
  5541.         * `--with-debug[=full]'
  5542.  
  5543.    * The default binary distribution is normally compiled with support
  5544.      for all character sets and should work on a variety of processors
  5545.      from the same processor family.
  5546.  
  5547.      If you want a faster MySQL server you may want to recompile it
  5548.      with support for only the character sets you need, use a better
  5549.      compiler (like `pgcc'), or use compiler options that are better
  5550.      optimised for your processor.
  5551.  
  5552.    * If you have found a bug and reported it to the MySQL development
  5553.      team you will probably receive a patch that you need to apply to
  5554.      the source distribution to get the bug fixed.
  5555.  
  5556.    * If you want to read (and/or modify) the C and C++ code that makes
  5557.      up MySQL, you should get a source distribution.  The source code is
  5558.      always the ultimate manual.  Source distributions also contain more
  5559.      tests and examples than binary distributions.
  5560.  
  5561. The MySQL naming scheme uses release numbers that consist of three
  5562. numbers and a suffix.  For example, a release name like
  5563. `mysql-3.21.17-beta' is interpreted like this:
  5564.  
  5565.    * The first number (`3') describes the file format.  All Version 3
  5566.      releases have the same file format.
  5567.  
  5568.    * The second number (`21') is the release level.  Normally there are
  5569.      two to choose from. One is the release/stable branch (currently
  5570.      `23') and the other is the development branch (currently `4.0').
  5571.      Normally both are stable, but the development version may have
  5572.      quirks, may be missing documentation on new features, or may fail
  5573.      to compile on some systems.
  5574.  
  5575.    * The third number (`17') is the version number within the release
  5576.      level.  This is incremented for each new distribution.  Usually you
  5577.      want the latest version for the release level you have chosen.
  5578.  
  5579.    * The suffix (`beta') indicates the stability level of the release.
  5580.      The possible suffixes are:
  5581.  
  5582.         - `alpha' indicates that the release contains some large
  5583.           section of new code that hasn't been 100% tested.  Known bugs
  5584.           (usually there are none) should be documented in the News
  5585.           section.  *Note News::.  There are also new commands and
  5586.           extensions in most alpha releases.  Active development that
  5587.           may involve major code changes can occur on an alpha release,
  5588.           but everything will be tested before doing a release.  There
  5589.           should be no known bugs in any MySQL release.
  5590.  
  5591.         - `beta' means that all new code has been tested.  No major new
  5592.           features that could cause corruption on old code are added.
  5593.           There should be no known bugs.  A version changes from alpha
  5594.           to beta when there haven't been any reported fatal bugs
  5595.           within an alpha version for at least a month and we don't
  5596.           plan to add any features that could make any old command more
  5597.           unreliable.
  5598.  
  5599.         - `gamma' is a beta that has been around a while and seems to
  5600.           work fine.  Only minor fixes are added.  This is what many
  5601.           other companies call a release.
  5602.  
  5603.         - If there is no suffix, it means that the version has been run
  5604.           for a while at many different sites with no reports of bugs
  5605.           other than platform-specific bugs.  Only critical bug fixes
  5606.           are applied to the release. This is what we call a stable
  5607.           release.
  5608.  
  5609. All versions of MySQL are run through our standard tests and benchmarks
  5610. to ensure that they are relatively safe to use.  Because the standard
  5611. tests are extended over time to check for all previously found bugs,
  5612. the test suite keeps getting better.
  5613.  
  5614. Note that all releases have been tested at least with:
  5615.  
  5616. An internal test suite
  5617.      This is part of a production system for a customer.  It has many
  5618.      tables with hundreds of megabytes of data.
  5619.  
  5620. The MySQL benchmark suite
  5621.      This runs a range of common queries.  It is also a test to see
  5622.      whether the latest batch of optimisations actually made the code
  5623.      faster.  *Note MySQL Benchmarks::.
  5624.  
  5625. The `crash-me' test
  5626.      This tries to determine what features the database supports and
  5627.      what its capabilities and limitations are.  *Note MySQL
  5628.      Benchmarks::.
  5629.  
  5630. Another test is that we use the newest MySQL version in our internal
  5631. production environment, on at least one machine.  We have more than 100
  5632. gigabytes of data to work with.
  5633.  
  5634. Installation Layouts
  5635. --------------------
  5636.  
  5637. This section describes the default layout of the directories created by
  5638. installing binary and source distributions.
  5639.  
  5640. A binary distribution is installed by unpacking it at the installation
  5641. location you choose (typically `/usr/local/mysql') and creates the
  5642. following directories in that location:
  5643.  
  5644. *Directory* *Contents of directory*
  5645. `bin'       Client programs and the
  5646.             `mysqld' server
  5647. `data'      Log files, databases
  5648. `include'   Include (header) files
  5649. `lib'       Libraries
  5650. `scripts'   `mysql_install_db'
  5651. `share/mysql'Error message files
  5652. `sql-bench' Benchmarks
  5653.  
  5654. A source distribution is installed after you configure and compile it.
  5655. By default, the installation step installs files under `/usr/local', in
  5656. the following subdirectories:
  5657.  
  5658. *Directory* *Contents of directory*
  5659. `bin'       Client programs and scripts
  5660. `include/mysql'Include (header) files
  5661. `info'      Documentation in Info format
  5662. `lib/mysql' Libraries
  5663. `libexec'   The `mysqld' server
  5664. `share/mysql'Error message files
  5665. `sql-bench' Benchmarks and `crash-me' test
  5666. `var'       Databases and log files
  5667.  
  5668. Within an installation directory, the layout of a source installation
  5669. differs from that of a binary installation in the following ways:
  5670.  
  5671.    * The `mysqld' server is installed in the `libexec' directory rather
  5672.      than in the `bin' directory.
  5673.  
  5674.    * The data directory is `var' rather than `data'.
  5675.  
  5676.    * `mysql_install_db' is installed in the `/usr/local/bin' directory
  5677.      rather than in `/usr/local/mysql/scripts'.
  5678.  
  5679.    * The header file and library directories are `include/mysql' and
  5680.      `lib/mysql' rather than `include' and `lib'.
  5681.  
  5682. You can create your own binary installation from a compiled source
  5683. distribution by executing the script `scripts/make_binary_distribution'.
  5684.  
  5685. How and When Updates Are Released
  5686. ---------------------------------
  5687.  
  5688. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  5689. this with other MySQL users.  We try to make a release when we have
  5690. very useful features that others seem to have a need for.
  5691.  
  5692. We also try to help out users who request features that are easy to
  5693. implement.  We take note of what our licensed users want to have, and
  5694. we especially take note of what our extended e-mail supported customers
  5695. want and try to help them out.
  5696.  
  5697. No one has to download a new release.  The News section will tell you if
  5698. the new release has something you really want.  *Note News::.
  5699.  
  5700. We use the following policy when updating MySQL:
  5701.  
  5702.    * For each minor update, the last number in the version string is
  5703.      incremented.  When there are major new features or minor
  5704.      incompatibilities with previous versions, the second number in the
  5705.      version string is incremented.  When the file format changes, the
  5706.      first number is increased.
  5707.  
  5708.    * Stable-tested releases are meant to appear about 1-2 times a year,
  5709.      but if small bugs are found, a release with only bug fixes will be
  5710.      released.
  5711.  
  5712.    * Working releases/bug fixes to old releases are meant to appear
  5713.      about every 1-8 weeks.
  5714.  
  5715.    * Binary distributions for some platforms will be made by us for
  5716.      major releases.  Other people may make binary distributions for
  5717.      other systems but probably less frequently.
  5718.  
  5719.    * We usually make patches available as soon as we have located and
  5720.      fixed small bugs. They are posted to <bugs@lists.mysql.com> and
  5721.      will be added to the next release.
  5722.  
  5723.    * For non-critical but annoying bugs, we will add them the MySQL
  5724.      source repository and they will be fixed in the next release.
  5725.  
  5726.    * If there is, by any chance, a fatal bug in a release we will make
  5727.      a new release as soon as possible.  We would like other companies
  5728.      to do this, too.
  5729.  
  5730. The current stable release is Version 3.23; we have already moved active
  5731. development to Version 4.0.  Bugs will still be fixed in the stable
  5732. version.  We don't believe in a complete freeze, as this also leaves
  5733. out bug fixes and things that "must be done."  "Somewhat frozen" means
  5734. that we may add small things that "almost surely will not affect
  5735. anything that's already working."
  5736.  
  5737. MySQL uses a slightly different naming scheme from most other products.
  5738. In general it's relatively safe to use any version that has been out for
  5739. a couple of weeks without being replaced with a new version.  *Note
  5740. Which version::.
  5741.  
  5742. MySQL Binaries Compiled by MySQL AB
  5743. -----------------------------------
  5744.  
  5745. As a service, we at MySQL AB provide a set of binary distributions of
  5746. MySQL that are compiled at our site or at sites where customers kindly
  5747. have given us access to their machines.
  5748.  
  5749. These distributions are generated using the script
  5750. `Build-tools/Do-compile' which compiles the source code and creates the
  5751. binary `tar.gz' archive using `scripts/make_binary_distribution' These
  5752. binaries are configured and built with the following compilers and
  5753. options.
  5754.  
  5755. Binaries built on MySQL AB development systems:
  5756.  
  5757. Linux 2.4.xx i386 with `gcc' 2.95.3
  5758.      `CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2
  5759.      -mcpu=pentiumpro -felide-constructors" ./configure
  5760.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5761.      --enable-thread-safe-client --enable-local-infile
  5762.      --enable-assembler --disable-shared
  5763.      --with-client-ldflags=-all-static
  5764.      --with-mysqld-ldflags=-all-static'
  5765.  
  5766. Linux 2.4.xx ia64 with `ecc' (Intel C++ Itanium Compiler 7.0)
  5767.      `CC=ecc CFLAGS=-tpp1 CXX=ecc CXXFLAGS=-tpp1 ./configure
  5768.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5769.      --enable-thread-safe-client --enable-local-infile'
  5770.  
  5771. Linux 2.4.xx alpha with `ccc' (Compaq C V6.2-505 / Compaq C++ V6.3-006)
  5772.      `CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
  5773.      generic -noexceptions -nortti" ./configure
  5774.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5775.      --enable-thread-safe-client --enable-local-infile
  5776.      --with-mysqld-ldflags=-non_shared
  5777.      --with-client-ldflags=-non_shared --disable-shared'
  5778.  
  5779. Linux 2.2.xx sparc with `egcs' 1.1.2
  5780.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5781.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5782.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5783.      --with-extra-charsets=complex --enable-thread-safe-client
  5784.      --enable-local-infile --enable-assembler --disable-shared'
  5785.  
  5786. Linux 2.4.xx s390 with `gcc' 2.95.3
  5787.      `CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors"
  5788.      ./configure --prefix=/usr/local/mysql
  5789.      --with-extra-charsets=complex --enable-thread-safe-client
  5790.      --enable-local-infile --disable-shared
  5791.      --with-client-ldflags=-all-static
  5792.      --with-mysqld-ldflags=-all-static'
  5793.  
  5794. Sun Solaris 2.8 sparc with `gcc' 3.2
  5795.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5796.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5797.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5798.      --with-extra-charsets=complex --enable-thread-safe-client
  5799.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5800.      --with-named-curses-libs=-lcurses --disable-shared'
  5801.  
  5802. Sun Solaris 2.9 sparc with `gcc' 2.95.3
  5803.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5804.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5805.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5806.      --with-extra-charsets=complex --enable-thread-safe-client
  5807.      --enable-local-infile --enable-assembler
  5808.      --with-named-curses-libs=-lcurses --disable-shared'
  5809.  
  5810. Sun Solaris 2.9 sparc with `cc-5.0' (Sun Forte 5.0)
  5811.      `CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
  5812.      -D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
  5813.      ./configure --prefix=/usr/local/mysql
  5814.      --with-extra-charsets=complex --enable-thread-safe-client
  5815.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  5816.      --enable-thread-safe-client --disable-shared'
  5817.  
  5818. IBM AIX 4.3.2 ppc with `gcc' 3.2.1
  5819.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2
  5820.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  5821.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5822.      --with-extra-charsets=complex --enable-thread-safe-client
  5823.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  5824.  
  5825. IBM AIX 5.1.0 ppc with `gcc' 3.2.1
  5826.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-O2
  5827.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  5828.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5829.      --with-extra-charsets=complex --with-server-suffix="-pro"
  5830.      --enable-thread-safe-client --enable-local-infile
  5831.      --with-named-z-libs=no --disable-shared --with-innodb'
  5832.  
  5833. HP-UX 10.20 pa-risc1.1 with `gcc' 3.1
  5834.      `CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc
  5835.      CXXFLAGS="-DHPUX -I/opt/dce /include -felide-constructors
  5836.      -fno-exceptions -fno-rtti -O3 -fPIC" ./configure
  5837.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5838.      --enable-thread-safe-client --enable-local-infile  --with-pthread
  5839.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  5840.      --disable-shared'
  5841.  
  5842. HP-UX 11.11 pa-risc2.0 with `aCC' (HP ANSI C++ B3910B A.03.33)
  5843.      `CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
  5844.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5845.      --enable-thread-safe-client --enable-local-infile --disable-shared'
  5846.  
  5847. Apple MacOS X 10.2 powerpc with `gcc' 3.1
  5848.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  5849.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5850.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5851.      --with-extra-charsets=complex --enable-thread-safe-client
  5852.      --enable-local-infile  --disable-shared'
  5853.  
  5854. FreeBSD 4.7 i386 with `gcc' 2.95.4
  5855.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  5856.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5857.      --enable-thread-safe-client --enable-local-infile
  5858.      --enable-assembler --with-named-z-libs=not-used --disable-shared'
  5859.  
  5860. The following binaries are built on third-party systems kindly provided
  5861. to MySQL AB by other users. Please note that these are only provided as
  5862. a courtesy. Since MySQL AB does not have full control over these
  5863. systems, we can only provide limited support for the binaries built on
  5864. these systems.
  5865.  
  5866. SCO Unix 3.2v5.0.6 i386 with `gcc' 2.95.3
  5867.      `CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3
  5868.      -mpentium -felide-constructors" ./configure
  5869.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  5870.      --enable-thread-safe-client --enable-local-infile
  5871.      --with-named-z-libs=no --enable-thread-safe-client
  5872.      --disable-shared'
  5873.  
  5874. Caldera Open Unix 8.0.0 i386 with `CC' 3.2
  5875.      `CC=cc CFLAGS="-O" CXX=CC ./configure --prefix=/usr/local/mysql
  5876.      --with-extra-charsets=complex --enable-thread-safe-client
  5877.      --enable-local-infile --with-named-z-libs=no
  5878.      --enable-thread-safe-client --disable-shared'
  5879.  
  5880. Compaq Tru64 OSF/1 V5.1 732 alpha with `cc/cxx' (Compaq C V6.3-029i / DIGITAL C++ V6.1-027)
  5881.      `CC="cc -pthread" CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline
  5882.      speed -speculate all" CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias
  5883.      -fast -inline speed -speculate all -noexceptions -nortti"
  5884.      ./configure --prefix=/usr/local/mysql
  5885.      --with-extra-charsets=complex --enable-thread-safe-client
  5886.      --enable-local-infile --with-prefix=/usr/local/mysql
  5887.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  5888.      --disable-shared --with-mysqld-ldflags=-all-static'
  5889.  
  5890. SGI Irix 6.5 IP32 with `gcc' 3.0.1
  5891.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
  5892.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  5893.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  5894.      --with-extra-charsets=complex --enable-thread-safe-client
  5895.      --enable-local-infile  --disable-shared'
  5896.  
  5897. The following compile options have been used for binary packages MySQL
  5898. AB used to provide in the past. These binaries are currently not being
  5899. updated anymore, but the compile options are kept in here for reference
  5900. purposes.
  5901.  
  5902. Linux 2.2.x with x686 with `gcc' 2.95.2
  5903.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  5904.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  5905.      --prefix=/usr/local/mysql --enable-assembler
  5906.      --with-mysqld-ldflags=-all-static --disable-shared
  5907.      --with-extra-charsets=complex'
  5908.  
  5909. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1
  5910.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  5911.      --prefix=/usr/local/mysql --disable-shared
  5912.      --with-extra-charsets=complex --enable-assembler'
  5913.  
  5914. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or gcc 2.95.2 and newer
  5915.      `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors
  5916.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  5917.      --with-low-memory --with-extra-charsets=complex --enable-assembler'
  5918.  
  5919. SunOS 5.6 i86pc with `gcc' 2.8.1
  5920.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5921.      --with-low-memory --with-extra-charsets=complex'
  5922.  
  5923. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1
  5924.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  5925.      --with-extra-charsets=complex'
  5926.  
  5927. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2
  5928.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5929.      --with-extra-charsets=complex'
  5930.  
  5931. AIX 2 4 with `gcc' 2.7.2.2
  5932.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  5933.      --with-extra-charsets=complex'
  5934.  
  5935. Anyone who has more optimal options for any of the preceding
  5936. configurations listed can always mail them to the developer's mailing
  5937. list at <internals@lists.mysql.com>.
  5938.  
  5939. RPM distributions prior to MySQL Version 3.22 are user-contributed.
  5940. Beginning with Version 3.22, the RPMs are generated by us at MySQL AB.
  5941.  
  5942. If you want to compile a debug version of MySQL, you should add
  5943. `--with-debug' or `--with-debug=full' to the preceding configure lines
  5944. and remove any `-fomit-frame-pointer' options.
  5945.  
  5946. For the Windows distribution, please see *Note Windows installation::.
  5947.  
  5948. Installing a MySQL Binary Distribution
  5949. --------------------------------------
  5950.  
  5951. See also *Note Windows binary installation::, *Note Linux-RPM::, and
  5952. *Note Building clients::.
  5953.  
  5954. You need the following tools to install a MySQL binary distribution:
  5955.  
  5956.    * GNU `gunzip' to uncompress the distribution.
  5957.  
  5958.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  5959.      to work.  Sun `tar' is known to have problems.
  5960.  
  5961. An alternative installation method under Linux is to use RPM-based (RPM
  5962. Package Manager) distributions.  *Note Linux-RPM::.
  5963.  
  5964. If you run into problems, *please always use `mysqlbug'* when posting
  5965. questions to <mysql@lists.mysql.com>.  Even if the problem isn't a bug,
  5966. `mysqlbug' gathers system information that will help others solve your
  5967. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  5968. a solution to your problem!  You will find `mysqlbug' in the `bin'
  5969. directory after you unpack the distribution.  *Note Bug reports::.
  5970.  
  5971. The basic commands you must execute to install and use a MySQL binary
  5972. distribution are:
  5973.  
  5974.      shell> groupadd mysql
  5975.      shell> useradd -g mysql mysql
  5976.      shell> cd /usr/local
  5977.      shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  5978.      shell> ln -s full-path-to-mysql-VERSION-OS mysql
  5979.      shell> cd mysql
  5980.      shell> scripts/mysql_install_db
  5981.      shell> chown -R root  .
  5982.      shell> chown -R mysql data
  5983.      shell> chgrp -R mysql .
  5984.      shell> bin/safe_mysqld --user=mysql &
  5985.      or
  5986.      shell> bin/mysqld_safe --user=mysql &
  5987.      if you are running MySQL 4.x
  5988.  
  5989. You can add new users using the `bin/mysql_setpermission' script if you
  5990. install the `DBI' and `Msql-Mysql-modules' Perl modules.
  5991.  
  5992. A more detailed description follows.
  5993.  
  5994. To install a binary distribution, follow these steps, then proceed to
  5995. *Note Post-installation::, for post-installation setup and testing:
  5996.  
  5997.   1. Pick the directory under which you want to unpack the
  5998.      distribution, and move into it.  In the following example, we
  5999.      unpack the distribution under `/usr/local' and create a directory
  6000.      `/usr/local/mysql' into which MySQL is installed.  (The following
  6001.      instructions, therefore, assume you have permission to create
  6002.      files in `/usr/local'.  If that directory is protected, you will
  6003.      need to perform the installation as `root'.)
  6004.  
  6005.   2. Obtain a distribution file from one of the sites listed in *Note
  6006.      Getting MySQL: Getting MySQL.
  6007.  
  6008.      MySQL binary distributions are provided as compressed `tar'
  6009.      archives and have names like `mysql-VERSION-OS.tar.gz', where
  6010.      `VERSION' is a number (for example, `3.21.15'), and `OS' indicates
  6011.      the type of operating system for which the distribution is intended
  6012.      (for example, `pc-linux-gnu-i586').
  6013.  
  6014.   3. If you see a binary distribution marked with the `-max' suffix,
  6015.      this means that the binary has support for transaction-safe tables
  6016.      and other features. *Note `mysqld-max': mysqld-max.  Note that all
  6017.      binaries are built from the same MySQL source distribution.
  6018.  
  6019.   4. Add a user and group for `mysqld' to run as:
  6020.  
  6021.           shell> groupadd mysql
  6022.           shell> useradd -g mysql mysql
  6023.  
  6024.      These commands add the `mysql' group and the `mysql' user.  The
  6025.      syntax for `useradd' and `groupadd' may differ slightly on
  6026.      different versions of Unix.  They may also be called `adduser' and
  6027.      `addgroup'.  You may wish to call the user and group something
  6028.      else instead of `mysql'.
  6029.  
  6030.   5. Change into the intended installation directory:
  6031.  
  6032.           shell> cd /usr/local
  6033.  
  6034.   6. Unpack the distribution and create the installation directory:
  6035.  
  6036.           shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  6037.           shell> ln -s full-path-to-mysql-VERSION-OS mysql
  6038.  
  6039.      The first command creates a directory named `mysql-VERSION-OS'.
  6040.      The second command makes a symbolic link to that directory.  This
  6041.      lets you refer more easily to the installation directory as
  6042.      `/usr/local/mysql'.
  6043.  
  6044.   7. Change into the installation directory:
  6045.  
  6046.           shell> cd mysql
  6047.  
  6048.      You will find several files and subdirectories in the `mysql'
  6049.      directory.  The most important for installation purposes are the
  6050.      `bin' and `scripts' subdirectories.
  6051.  
  6052.     `bin'
  6053.           This directory contains client programs and the server You
  6054.           should add the full pathname of this directory to your `PATH'
  6055.           environment variable so that your shell finds the MySQL
  6056.           programs properly. *Note Environment variables::.
  6057.  
  6058.     `scripts'
  6059.           This directory contains the `mysql_install_db' script used to
  6060.           initialise the `mysql' database containing the grant tables
  6061.           that store the server access permissions.
  6062.  
  6063.   8. If you would like to use `mysqlaccess' and have the MySQL
  6064.      distribution in some non-standard place, you must change the
  6065.      location where `mysqlaccess' expects to find the `mysql' client.
  6066.      Edit the `bin/mysqlaccess' script at approximately line 18.
  6067.      Search for a line that looks like this:
  6068.  
  6069.           $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
  6070.  
  6071.      Change the path to reflect the location where `mysql' actually is
  6072.      stored on your system.  If you do not do this, you will get a
  6073.      `Broken pipe' error when you run `mysqlaccess'.
  6074.  
  6075.   9. Create the MySQL grant tables (necessary only if you haven't
  6076.      installed MySQL before):
  6077.           shell> scripts/mysql_install_db
  6078.  
  6079.      Note that MySQL versions older than Version 3.22.10 started the
  6080.      MySQL server when you run `mysql_install_db'.  This is no longer
  6081.      true!
  6082.  
  6083.  10. Change ownership of binaries to `root' and ownership of the data
  6084.      directory to the user that you will run `mysqld' as:
  6085.  
  6086.           shell> chown -R root  /usr/local/mysql/.
  6087.           shell> chown -R mysql /usr/local/mysql/data
  6088.           shell> chgrp -R mysql /usr/local/mysql/.
  6089.  
  6090.      The first command changes the `owner' attribute of the files to the
  6091.      `root' user, the second one changes the `owner' attribute of the
  6092.      data directory to the `mysql' user, and the third one changes the
  6093.      `group' attribute to the `mysql' group.
  6094.  
  6095.  11. If you want to install support for the Perl `DBI'/`DBD' interface,
  6096.      see *Note Perl support::.
  6097.  
  6098.  12. If you would like MySQL to start automatically when you boot your
  6099.      machine, you can copy `support-files/mysql.server' to the location
  6100.      where your system has its startup files.  More information can be
  6101.      found in the `support-files/mysql.server' script itself and in
  6102.      *Note Automatic start::.
  6103.  
  6104.  
  6105. After everything has been unpacked and installed, you should initialise
  6106. and test your distribution.
  6107.  
  6108. You can start the MySQL server with the following command:
  6109.  
  6110.      shell> bin/safe_mysqld --user=mysql &
  6111.  
  6112. Now proceed to *Note `safe_mysqld': safe_mysqld, and *Note
  6113. Post-installation::.
  6114.  
  6115. Installing a MySQL Source Distribution
  6116. ======================================
  6117.  
  6118. Before you proceed with the source installation, check first to see if
  6119. our binary is available for your platform and if it will work for you.
  6120. We put a lot of effort into making sure that our binaries are built
  6121. with the best possible options.
  6122.  
  6123. You need the following tools to build and install MySQL from source:
  6124.  
  6125.    * GNU `gunzip' to uncompress the distribution.
  6126.  
  6127.    * A reasonable `tar' to unpack the distribution.  GNU `tar' is known
  6128.      to work.  Sun `tar' is known to have problems.
  6129.  
  6130.    * A working ANSI C++ compiler.  `gcc' >= 2.95.2, `egcs' >= 1.0.2 or
  6131.      `egcs 2.91.66', SGI C++, and SunPro C++ are some of the compilers
  6132.      that are known to work.  `libg++' is not needed when using `gcc'.
  6133.      `gcc' 2.7.x has a bug that makes it impossible to compile some
  6134.      perfectly legal C++ files, such as `sql/sql_base.cc'.  If you only
  6135.      have `gcc' 2.7.x, you must upgrade your `gcc' to be able to
  6136.      compile MySQL. `gcc' 2.8.1 is also known to have problems on some
  6137.      platforms, so it should be avoided if a new compiler exists for
  6138.      the platform.
  6139.  
  6140.      `gcc' >= 2.95.2 is recommended when compiling MySQL Version 3.23.x.
  6141.  
  6142.    * A good `make' program.  GNU `make' is always recommended and is
  6143.      sometimes required.  If you have problems, we recommend trying GNU
  6144.      `make' 3.75 or newer.
  6145.  
  6146. If you are using a recent version of `gcc', recent enough to understand
  6147. the `-fno-exceptions' option, it is *very important* that you use it.
  6148. Otherwise, you may compile a binary that crashes randomly. We also
  6149. recommend that you use `-felide-constructors' and `-fno-rtti' along
  6150. with `-fno-exceptions'. When in doubt, do the following:
  6151.  
  6152.  
  6153.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions \
  6154.             -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler \
  6155.             --with-mysqld-ldflags=-all-static
  6156.  
  6157. On most systems this will give you a fast and stable binary.
  6158.  
  6159. If you run into problems, *please always use `mysqlbug'* when posting
  6160. questions to <mysql@lists.mysql.com>.  Even if the problem isn't a bug,
  6161. `mysqlbug' gathers system information that will help others solve your
  6162. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  6163. a solution to your problem!  You will find `mysqlbug' in the `scripts'
  6164. directory after you unpack the distribution.  *Note Bug reports::.
  6165.  
  6166. Quick Installation Overview
  6167. ---------------------------
  6168.  
  6169. The basic commands you must execute to install a MySQL source
  6170. distribution are:
  6171.  
  6172.      shell> groupadd mysql
  6173.      shell> useradd -g mysql mysql
  6174.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  6175.      shell> cd mysql-VERSION
  6176.      shell> ./configure --prefix=/usr/local/mysql
  6177.      shell> make
  6178.      shell> make install
  6179.      shell> scripts/mysql_install_db
  6180.      shell> chown -R root  /usr/local/mysql
  6181.      shell> chown -R mysql /usr/local/mysql/var
  6182.      shell> chgrp -R mysql /usr/local/mysql
  6183.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  6184.      shell> /usr/local/mysql/bin/safe_mysqld --user=mysql &
  6185.      or
  6186.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  6187.      if you are running MySQL 4.x.
  6188.  
  6189. If you want to have support for InnoDB tables, you should edit the
  6190. `/etc/my.cnf' file and remove the `#' character before the parameter
  6191. that starts with `innodb_...'.  *Note Option files::, and *Note InnoDB
  6192. start::.
  6193.  
  6194. If you start from a source RPM, do the following:
  6195.  
  6196.      shell> rpm --rebuild MySQL-VERSION.src.rpm
  6197.  
  6198. This will make a binary RPM that you can install.
  6199.  
  6200. You can add new users using the `bin/mysql_setpermission' script if you
  6201. install the `DBI' and `Msql-Mysql-modules' Perl modules.
  6202.  
  6203. A more detailed description follows.
  6204.  
  6205. To install a source distribution, follow these steps, then proceed to
  6206. *Note Post-installation::, for post-installation initialisation and
  6207. testing:
  6208.  
  6209.   1. Pick the directory under which you want to unpack the
  6210.      distribution, and move into it.
  6211.  
  6212.   2. Obtain a distribution file from one of the sites listed in *Note
  6213.      Getting MySQL: Getting MySQL.
  6214.  
  6215.   3. If you are interested in using Berkeley DB tables with MySQL, you
  6216.      will need to obtain a patched version of the Berkeley DB source
  6217.      code.  Please read the chapter on Berkeley DB tables before
  6218.      proceeding.  *Note BDB::.
  6219.  
  6220.      MySQL source distributions are provided as compressed `tar'
  6221.      archives and have names like `mysql-VERSION.tar.gz', where
  6222.      `VERSION' is a number like 3.23.55.
  6223.  
  6224.   4. Add a user and group for `mysqld' to run as:
  6225.  
  6226.           shell> groupadd mysql
  6227.           shell> useradd -g mysql mysql
  6228.  
  6229.      These commands add the `mysql' group and the `mysql' user.  The
  6230.      syntax for `useradd' and `groupadd' may differ slightly on
  6231.      different versions of Unix.  They may also be called `adduser' and
  6232.      `addgroup'.  You may wish to call the user and group something
  6233.      else instead of `mysql'.
  6234.  
  6235.   5. Unpack the distribution into the current directory:
  6236.           shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
  6237.  
  6238.      This command creates a directory named `mysql-VERSION'.
  6239.  
  6240.   6. Change into the top-level directory of the unpacked distribution:
  6241.  
  6242.           shell> cd mysql-VERSION
  6243.  
  6244.      Note that currently you must configure and build MySQL from this
  6245.      top-level directory.  You cannot build it in a different directory.
  6246.  
  6247.   7. Configure the release and compile everything:
  6248.  
  6249.           shell> ./configure --prefix=/usr/local/mysql
  6250.           shell> make
  6251.  
  6252.      When you run `configure', you might want to specify some options.
  6253.      Run `./configure --help' for a list of options.  *Note `configure'
  6254.      options: configure options, discusses some of the more useful
  6255.      options.
  6256.  
  6257.      If `configure' fails, and you are going to send mail to
  6258.      <mysql@lists.mysql.com> to ask for assistance, please include any
  6259.      lines from `config.log' that you think can help solve the problem.
  6260.      Also include the last couple of lines of output from `configure'
  6261.      if `configure' aborts.  Post the bug report using the `mysqlbug'
  6262.      script.  *Note Bug reports::.
  6263.  
  6264.      If the compile fails, see *Note Compilation problems::, for help
  6265.      with a number of common problems.
  6266.  
  6267.   8. Install everything:
  6268.  
  6269.           shell> make install
  6270.  
  6271.      You might need to run this command as `root'.
  6272.  
  6273.   9. Create the MySQL grant tables (necessary only if you haven't
  6274.      installed MySQL before):
  6275.  
  6276.           shell> scripts/mysql_install_db
  6277.  
  6278.      Note that MySQL versions older than Version 3.22.10 started the
  6279.      MySQL server when you run `mysql_install_db'.  This is no longer
  6280.      true!
  6281.  
  6282.  10. Change ownership of binaries to `root' and ownership of the data
  6283.      directory to the user that you will run `mysqld' as:
  6284.  
  6285.           shell> chown -R root  /usr/local/mysql
  6286.           shell> chown -R mysql /usr/local/mysql/var
  6287.           shell> chgrp -R mysql /usr/local/mysql
  6288.  
  6289.      The first command changes the `owner' attribute of the files to the
  6290.      `root' user, the second one changes the `owner' attribute of the
  6291.      data directory to the `mysql' user, and the third one changes the
  6292.      `group' attribute to the `mysql' group.
  6293.  
  6294.  11. If you want to install support for the Perl `DBI'/`DBD' interface,
  6295.      see *Note Perl support::.
  6296.  
  6297.  12. If you would like MySQL to start automatically when you boot your
  6298.      machine, you can copy `support-files/mysql.server' to the location
  6299.      where your system has its startup files.  More information can be
  6300.      found in the `support-files/mysql.server' script itself and in
  6301.      *Note Automatic start::.
  6302.  
  6303. After everything has been installed, you should initialise and test your
  6304. distribution:
  6305.  
  6306.      shell> /usr/local/mysql/bin/safe_mysqld --user=mysql &
  6307.  
  6308. If that command fails immediately with `mysqld daemon ended', you can
  6309. find some information in the file `mysql-data-directory/'hostname'.err'.
  6310. The likely reason is that you already have another `mysqld' server
  6311. running.  *Note Multiple servers::.
  6312.  
  6313. Now proceed to *Note Post-installation::.
  6314.  
  6315. Applying Patches
  6316. ----------------
  6317.  
  6318. Sometimes patches appear on the mailing list or are placed in the
  6319. patches area of the MySQL web site
  6320. (`http://www.mysql.com/downloads/patches.html').
  6321.  
  6322. To apply a patch from the mailing list, save the message in which the
  6323. patch appears in a file, change into the top-level directory of your
  6324. MySQL source tree, and run these commands:
  6325.  
  6326.      shell> patch -p1 < patch-file-name
  6327.      shell> rm config.cache
  6328.      shell> make clean
  6329.  
  6330. Patches from the FTP site are distributed as plain text files or as
  6331. files compressed with `gzip'.  Apply a plain patch as shown previously
  6332. for mailing list patches.  To apply a compressed patch, change into the
  6333. top-level directory of your MySQL source tree and run these commands:
  6334.  
  6335.      shell> gunzip < patch-file-name.gz | patch -p1
  6336.      shell> rm config.cache
  6337.      shell> make clean
  6338.  
  6339. After applying a patch, follow the instructions for a normal source
  6340. install, beginning with the `./configure' step.  After running the `make
  6341. install' step, restart your MySQL server.
  6342.  
  6343. You may need to bring down any currently running server before you run
  6344. `make install'.  (Use `mysqladmin shutdown' to do this.)  Some systems
  6345. do not allow you to install a new version of a program if it replaces
  6346. the version that is currently executing.
  6347.  
  6348. Typical `configure' Options
  6349. ---------------------------
  6350.  
  6351. The `configure' script gives you a great deal of control over how you
  6352. configure your MySQL distribution.  Typically you do this using options
  6353. on the `configure' command-line.  You can also affect `configure' using
  6354. certain environment variables.  *Note Environment variables::.  For a
  6355. list of options supported by `configure', run this command:
  6356.  
  6357.      shell> ./configure --help
  6358.  
  6359. Some of the more commonly-used `configure' options are described here:
  6360.  
  6361.    * To compile just the MySQL client libraries and client programs and
  6362.      not the server, use the `--without-server' option:
  6363.  
  6364.           shell> ./configure --without-server
  6365.  
  6366.      If you don't have a C++ compiler, `mysql' will not compile (it is
  6367.      the one client program that requires C++).  In this case, you can
  6368.      remove the code in `configure' that tests for the C++ compiler and
  6369.      then run `./configure' with the `--without-server' option. The
  6370.      compile step will still try to build `mysql', but you can ignore
  6371.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  6372.      tell it to continue with the rest of the build even if errors
  6373.      occur.)
  6374.  
  6375.    * If you want to get an embedded MySQL library (`libmysqld.a') you
  6376.      should use the `--with-embedded-server' option.
  6377.  
  6378.    * If you don't want your log files and database directories located
  6379.      under `/usr/local/var', use a `configure' command, something like
  6380.      one of these:
  6381.  
  6382.           shell> ./configure --prefix=/usr/local/mysql
  6383.           shell> ./configure --prefix=/usr/local \
  6384.                      --localstatedir=/usr/local/mysql/data
  6385.  
  6386.      The first command changes the installation prefix so that
  6387.      everything is installed under `/usr/local/mysql' rather than the
  6388.      default of `/usr/local'.  The second command preserves the default
  6389.      installation prefix, but overrides the default location for
  6390.      database directories (normally `/usr/local/var') and changes it to
  6391.      `/usr/local/mysql/data'.  After you have compiled MySQL, you can
  6392.      change these options with option files. *Note Option files::.
  6393.  
  6394.    * If you are using Unix and you want the MySQL socket located
  6395.      somewhere other than the default location (normally in the
  6396.      directory `/tmp' or `/var/run') use a `configure' command like
  6397.      this:
  6398.  
  6399.           shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  6400.  
  6401.      Note that the given file must be an absolute pathname!  You can
  6402.      also later change the location `mysql.sock' by using the MySQL
  6403.      option files. *Note Problems with mysql.sock::.
  6404.  
  6405.    * If you want to compile statically linked programs (for example, to
  6406.      make a binary distribution, to get more speed, or to work around
  6407.      problems with some RedHat Linux distributions), run `configure'
  6408.      like this:
  6409.  
  6410.           shell> ./configure --with-client-ldflags=-all-static \
  6411.                      --with-mysqld-ldflags=-all-static
  6412.  
  6413.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  6414.      installed, you can tell `configure' to use `gcc' as your C++
  6415.      compiler:
  6416.  
  6417.           shell> CC=gcc CXX=gcc ./configure
  6418.  
  6419.      When you use `gcc' as your C++ compiler, it will not attempt to
  6420.      link in `libg++' or `libstdc++'.  This may be a good idea to do
  6421.      even if you have the above libraries installed, as some versions
  6422.      of these libraries have caused strange problems for MySQL users in
  6423.      the past.
  6424.  
  6425.      Here are some common environment variables to set depending on the
  6426.      compiler you are using:
  6427.  
  6428.      *Compiler*    *Recommended options*
  6429.      gcc 2.7.2.1    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
  6430.      egcs 1.0.3a    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6431.                    -fno-exceptions -fno-rtti"
  6432.      gcc 2.95.2     CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3
  6433.                    -mpentiumpro \ -felide-constructors -fno-exceptions
  6434.                    -fno-rtti"
  6435.      pgcc 2.90.29   CFLAGS="-O3 -mpentiumpro -mstack-align-double"
  6436.      or newer      CXX=gcc \ CXXFLAGS="-O3 -mpentiumpro
  6437.                    -mstack-align-double -felide-constructors \
  6438.                    -fno-exceptions -fno-rtti"
  6439.  
  6440.      In most cases you can get a reasonably optimal MySQL binary by
  6441.      using the options from the preceding table and adding the
  6442.      following options to the configure line:
  6443.  
  6444.           --prefix=/usr/local/mysql --enable-assembler \
  6445.           --with-mysqld-ldflags=-all-static
  6446.  
  6447.      The full configure line would, in other words, be something like
  6448.      the following for all recent gcc versions:
  6449.  
  6450.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  6451.           -felide-constructors -fno-exceptions -fno-rtti" ./configure \
  6452.           --prefix=/usr/local/mysql --enable-assembler \
  6453.           --with-mysqld-ldflags=-all-static
  6454.  
  6455.      The binaries we provide on the MySQL web site at
  6456.      `http://www.mysql.com/' are all compiled with full optimisation and
  6457.      should be perfect for most users.  *Note MySQL binaries::.  There
  6458.      are some things you can tweak to make an even faster binary, but
  6459.      this is only for advanced users.  *Note Compile and link options::.
  6460.  
  6461.      If the build fails and produces errors about your compiler or
  6462.      linker not being able to create the shared library
  6463.      `libmysqlclient.so.#' (`#' is a version number), you can work
  6464.      around this problem by giving the `--disable-shared' option to
  6465.      `configure'.  In this case, `configure' will not build a shared
  6466.      `libmysqlclient.so.#' library.
  6467.  
  6468.    * You can configure MySQL not to use `DEFAULT' column values for
  6469.      non-`NULL' columns (that is, columns that are not allowed to be
  6470.      `NULL').  This causes `INSERT' statements to generate an error
  6471.      unless you explicitly specify values for all columns that require a
  6472.      non-`NULL' value.  To suppress use of default values, run
  6473.      `configure' like this:
  6474.  
  6475.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  6476.  
  6477.    * By default, MySQL uses the ISO-8859-1 (Latin1) character set. To
  6478.      change the default set, use the `--with-charset' option:
  6479.           shell> ./configure --with-charset=CHARSET
  6480.      `CHARSET' may be one of `big5', `cp1251', `cp1257', `czech',
  6481.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  6482.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  6483.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  6484.      `win1251ukr'.  *Note Character sets::.
  6485.  
  6486.      If you want to convert characters between the server and the
  6487.      client, you should take a look at the `SET CHARACTER SET' command.
  6488.      *Note `SET': SET OPTION.
  6489.  
  6490.      *Warning*: If you change character sets after having created any
  6491.      tables, you will have to run `myisamchk -r -q
  6492.      --set-character-set=charset' on every table. Your indexes may be
  6493.      sorted incorrectly otherwise.  (This can happen if you install
  6494.      MySQL, create some tables, then reconfigure MySQL to use a
  6495.      different character set and reinstall it.)
  6496.  
  6497.      With the option `--with-extra-charsets=LIST' you can define which
  6498.      additional character sets should be compiled into the server.
  6499.  
  6500.      Here `LIST' is either a list of character sets separated with
  6501.      spaces, `complex' to include all characters that can't be
  6502.      dynamically loaded, or `all' to include all character sets into
  6503.      the binaries.
  6504.  
  6505.    * To configure MySQL with debugging code, use the `--with-debug'
  6506.      option:
  6507.           shell> ./configure --with-debug
  6508.      This causes a safe memory allocator to be included that can find
  6509.      some errors and that provides output about what is happening.
  6510.      *Note Debugging server::.
  6511.  
  6512.    * If your client programs are using threads, you need to also
  6513.      compile a thread-safe version of the MySQL client library with the
  6514.      `--enable-thread-safe-client' configure options. This will create a
  6515.      `libmysqlclient_r' library with which you should link your threaded
  6516.      applications.  *Note Threaded clients::.
  6517.  
  6518.    * Options that pertain to particular systems can be found in the
  6519.      system-specific section of this manual.  *Note Operating System
  6520.      Specific Notes::.
  6521.  
  6522. Installing from the Development Source Tree
  6523. -------------------------------------------
  6524.  
  6525. *Caution*: You should read this section only if you are interested in
  6526. helping us test our new code. If you just want to get MySQL up and
  6527. running on your system, you should use a standard release distribution
  6528. (either a source or binary distribution will do).
  6529.  
  6530. To obtain our most recent development source tree, use these
  6531. instructions:
  6532.  
  6533.   1. Download `BitKeeper' from
  6534.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  6535.      `Bitkeeper' 3.0 or newer to access our repository.
  6536.  
  6537.   2. Follow the instructions to install it.
  6538.  
  6539.   3. After `BitKeeper' is installed, first go to the directory you want
  6540.      to work from, and then use one of the following commands to clone
  6541.      the MySQL version branch of your choice:
  6542.  
  6543.      To clone the 3.23 branch, use this command:
  6544.  
  6545.           shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
  6546.  
  6547.      To clone the 4.0 branch, use this command:
  6548.  
  6549.           shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
  6550.  
  6551.      To clone the 4.1 branch, use this command:
  6552.  
  6553.           shell> bk clone bk://mysql.bkbits.net/mysql-4.1 mysql-4.1
  6554.  
  6555.      In the preceding examples the source tree will be set up in the
  6556.      `mysql-3.23/', `mysql-4.0/', or `mysql-4.1/' subdirectory of your
  6557.      current directory.
  6558.  
  6559.      The initial download of the source tree may take a while,
  6560.      depending on the speed of your connection; be patient.
  6561.  
  6562.   4. You will need GNU `make', `autoconf 2.53 (or newer)', `automake
  6563.      1.5', `libtool 1.4', and `m4' to run the next set of commands.
  6564.      Note that `automake 1.7 or newer' doesn't yet work.
  6565.  
  6566.      If you are using trying to configure MySQL 4.1 you will also need
  6567.      `bison 1.75'.  Older versions of `bison' may report this error:
  6568.      `sql_yacc.yy:#####: fatal error: maximum table size (32767)
  6569.      exceeded'. Note: the maximum table size is not actually exceeded,
  6570.      the error is caused by bugs in these earlier `bison' versions.
  6571.  
  6572.      The typical command to do in a shell is:
  6573.  
  6574.           cd mysql-4.0
  6575.           bk -r get -Sq
  6576.           aclocal; autoheader; autoconf; automake
  6577.           (cd innobase ; aclocal; autoheader; autoconf; automake) # for InnoDB
  6578.           (cd bdb/dist ; sh s_all ) # for Berkeley DB
  6579.           ./configure  # Add your favorite options here
  6580.           make
  6581.  
  6582.      If you get some strange error during this stage, check that you
  6583.      really have `libtool' installed!
  6584.  
  6585.      A collection of our standard configure scripts is located in the
  6586.      `BUILD/' subdirectory.  If you are lazy, you can use
  6587.      `BUILD/compile-pentium-debug'. To compile on a different
  6588.      architecture, modify the script by removing flags that are
  6589.      Pentium-specific.
  6590.  
  6591.   5. When the build is done, run `make install'.  Be careful with this
  6592.      on a production machine; the command may overwrite your live
  6593.      release installation.  If you have another installation of MySQL,
  6594.      we recommand that you run `./configure' with different values for
  6595.      the `prefix', `with-tcp-port', and `unix-socket-path' options than
  6596.      those used for your production server.
  6597.  
  6598.   6. Play hard with your new installation and try to make the new
  6599.      features crash.  Start by running `make test'.  *Note MySQL test
  6600.      suite::.
  6601.  
  6602.   7. If you have gotten to the `make' stage and the distribution does
  6603.      not compile, please report it to <bugs@lists.mysql.com>.  If you
  6604.      have installed the latest versions of the required GNU tools, and
  6605.      they crash trying to process our configuration files, please
  6606.      report that also.  However, if you execute `aclocal' and get a
  6607.      `command not found' error or a similar problem, do not report it.
  6608.      Instead, make sure all the necessary tools are installed and that
  6609.      your `PATH' variable is set correctly so that your shell can find
  6610.      them.
  6611.  
  6612.   8. After the initial `bk clone' operation to get the source tree, you
  6613.      should run `bk pull' periodically to get the updates.
  6614.  
  6615.   9. You can examine the change history for the tree with all the diffs
  6616.      by using `bk sccstool'.  If you see some funny diffs or code that
  6617.      you have a question about, do not hesitate to send e-mail to
  6618.      <internals@lists.mysql.com>. Also, if you think you have a better
  6619.      idea on how to do something, send an e-mail to the same address
  6620.      with a patch.  `bk diffs' will produce a patch for you after you
  6621.      have made changes to the source. If you do not have the time to
  6622.      code your idea, just send a description.
  6623.  
  6624.  10. `BitKeeper' has a nice help utility that you can access via `bk
  6625.      helptool'.
  6626.  
  6627.  11. Please note that any commits (`bk ci' or `bk citool') will trigger
  6628.      the posting of a message with the changeset to our internals
  6629.      mailing list, as well as the usual openlogging.org submission with
  6630.      just the changeset comments.  Generally, you wouldn't need to use
  6631.      commit (since the public tree will not allow `bk push'), but
  6632.      rather use the `bk diffs' method described previously.
  6633.  
  6634.  
  6635. You can also browse changesets, comments and sourcecode online by
  6636. browsing to e.g. `http://mysql.bkbits.net/mysql-4.1' For MySQL 4.1.
  6637.  
  6638. The manual is in a separate tree which can be cloned with:
  6639.  
  6640.      shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
  6641.  
  6642. Problems Compiling?
  6643. -------------------
  6644.  
  6645. All MySQL programs compile cleanly for us with no warnings on Solaris
  6646. or Linux using `gcc'.  On other systems, warnings may occur due to
  6647. differences in system include files.  See *Note MIT-pthreads:: for
  6648. warnings that may occur when using MIT-pthreads.  For other problems,
  6649. check the following list.
  6650.  
  6651. The solution to many problems involves reconfiguring.  If you do need to
  6652. reconfigure, take note of the following:
  6653.  
  6654.    * If `configure' is run after it already has been run, it may use
  6655.      information that was gathered during its previous invocation.  This
  6656.      information is stored in `config.cache'.  When `configure' starts
  6657.      up, it looks for that file and reads its contents if it exists, on
  6658.      the assumption that the information is still correct.  That
  6659.      assumption is invalid when you reconfigure.
  6660.  
  6661.    * Each time you run `configure', you must run `make' again to
  6662.      recompile.  However, you may want to remove old object files from
  6663.      previous builds first because they were compiled using different
  6664.      configuration options.
  6665.  
  6666. To prevent old configuration information or object files from being
  6667. used, run these commands before rerunning `configure':
  6668.  
  6669.      shell> rm config.cache
  6670.      shell> make clean
  6671.  
  6672. Alternatively, you can run `make distclean'.
  6673.  
  6674. The following list describes some of the problems when compiling MySQL
  6675. that have been found to occur most often:
  6676.  
  6677.    * If you get errors when compiling `sql_yacc.cc', such as the ones
  6678.      shown here, you have probably run out of memory or swap space:
  6679.  
  6680.           Internal compiler error: program cc1plus got fatal signal 11
  6681.             or
  6682.           Out of virtual memory
  6683.             or
  6684.           Virtual memory exhausted
  6685.  
  6686.      The problem is that `gcc' requires huge amounts of memory to
  6687.      compile `sql_yacc.cc' with inline functions.  Try running
  6688.      `configure' with the `--with-low-memory' option:
  6689.  
  6690.           shell> ./configure --with-low-memory
  6691.  
  6692.      This option causes `-fno-inline' to be added to the compile line
  6693.      if you are using `gcc' and `-O0' if you are using something else.
  6694.      You should try the `--with-low-memory' option even if you have so
  6695.      much memory and swap space that you think you can't possibly have
  6696.      run out.  This problem has been observed to occur even on systems
  6697.      with generous hardware configurations, and the `--with-low-memory'
  6698.      option usually fixes it.
  6699.  
  6700.    * By default, `configure' picks `c++' as the compiler name and GNU
  6701.      `c++' links with `-lg++'.  If you are using `gcc', that behaviour
  6702.      can cause problems during configuration such as this:
  6703.  
  6704.           configure: error: installation or configuration problem:
  6705.           C++ compiler cannot create executables.
  6706.  
  6707.      You might also observe problems during compilation related to
  6708.      `g++', `libg++', or `libstdc++'.
  6709.  
  6710.      One cause of these problems is that you may not have `g++', or you
  6711.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  6712.      the `config.log' file.  It should contain the exact reason why
  6713.      your c++ compiler didn't work!  To work around these problems, you
  6714.      can use `gcc' as your C++ compiler.  Try setting the environment
  6715.      variable `CXX' to `"gcc -O3"'.  For example:
  6716.  
  6717.           shell> CXX="gcc -O3" ./configure
  6718.  
  6719.      This works because `gcc' compiles C++ sources as well as `g++'
  6720.      does, but does not link in `libg++' or `libstdc++' by default.
  6721.  
  6722.      Another way to fix these problems, of course, is to install `g++',
  6723.      `libg++', and `libstdc++'.  We would however like to recommend you
  6724.      to not use `libg++' or `libstdc++' with MySQL as this will only
  6725.      increase the binary size of mysqld without giving you any benefits.
  6726.      Some versions of these libraries have also caused strange problems
  6727.      for MySQL users in the past.
  6728.  
  6729.    * If your compile fails with errors, such as any of the following,
  6730.      you must upgrade your version of `make' to GNU `make':
  6731.  
  6732.           making all in mit-pthreads
  6733.           make: Fatal error in reader: Makefile, line 18:
  6734.           Badly formed macro assignment
  6735.             or
  6736.           make: file `Makefile' line 18: Must be a separator (:
  6737.             or
  6738.           pthread.h: No such file or directory
  6739.  
  6740.      Solaris and FreeBSD are known to have troublesome `make' programs.
  6741.  
  6742.      GNU `make' Version 3.75 is known to work.
  6743.  
  6744.    * If you want to define flags to be used by your C or C++ compilers,
  6745.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  6746.      environment variables.  You can also specify the compiler names
  6747.      this way using `CC' and `CXX'.  For example:
  6748.  
  6749.           shell> CC=gcc
  6750.           shell> CFLAGS=-O3
  6751.           shell> CXX=gcc
  6752.           shell> CXXFLAGS=-O3
  6753.           shell> export CC CFLAGS CXX CXXFLAGS
  6754.  
  6755.      See *Note MySQL binaries::, for a list of flag definitions that
  6756.      have been found to be useful on various systems.
  6757.  
  6758.    * If you get an error message like this, you need to upgrade your
  6759.      `gcc' compiler:
  6760.  
  6761.           client/libmysql.c:273: parse error before `__attribute__'
  6762.  
  6763.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  6764.      or `egcs' 1.0.3a instead.
  6765.  
  6766.    * If you get errors such as those shown here when compiling `mysqld',
  6767.      `configure' didn't correctly detect the type of the last argument
  6768.      to `accept()', `getsockname()', or `getpeername()':
  6769.  
  6770.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  6771.                type of the pointer value "&length" is "unsigned long", which
  6772.                is not compatible with "int".
  6773.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  6774.  
  6775.      To fix this, edit the `config.h' file (which is generated by
  6776.      `configure').  Look for these lines:
  6777.  
  6778.           /* Define as the base type of the last arg to accept */
  6779.           #define SOCKET_SIZE_TYPE XXX
  6780.  
  6781.      Change `XXX' to `size_t' or `int', depending on your operating
  6782.      system.  (Note that you will have to do this each time you run
  6783.      `configure' because `configure' regenerates `config.h'.)
  6784.  
  6785.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  6786.      the build process doesn't need to create `sql_yacc.cc', because
  6787.      MySQL comes with an already generated copy.  However, if you do
  6788.      need to re-create it, you might encounter this error:
  6789.  
  6790.           "sql_yacc.yy", line xxx fatal: default action causes potential...
  6791.  
  6792.      This is a sign that your version of `yacc' is deficient.  You
  6793.      probably need to install `bison' (the GNU version of `yacc') and
  6794.      use that instead.
  6795.  
  6796.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  6797.      with the `--with-debug' option, then recompile and link your
  6798.      clients with the new client library.  *Note Debugging client::.
  6799.  
  6800. MIT-pthreads Notes
  6801. ------------------
  6802.  
  6803. This section describes some of the issues involved in using
  6804. MIT-pthreads.
  6805.  
  6806. Note that on Linux you should *not* use MIT-pthreads but install
  6807. LinuxThreads!  *Note Linux::.
  6808.  
  6809. If your system does not provide native thread support, you will need to
  6810. build MySQL using the MIT-pthreads package.  This includes older
  6811. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  6812. *Note Which OS::.
  6813.  
  6814. Note, that beginning with MySQL 4.0.2 MIT-pthreads are no longer part of
  6815. the source distribution! If you require this package, you need to
  6816. download it separately from
  6817. <http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz>
  6818.  
  6819. After downloading, extract this source archive into the top level of the
  6820. MySQL source directory. It will create a new subdirectory
  6821. `mit-pthreads'.
  6822.  
  6823.    * On most systems, you can force MIT-pthreads to be used by running
  6824.      `configure' with the `--with-mit-threads' option:
  6825.  
  6826.           shell> ./configure --with-mit-threads
  6827.  
  6828.      Building in a non-source directory is not supported when using
  6829.      MIT-pthreads because we want to minimise our changes to this code.
  6830.  
  6831.    * The checks that determine whether to use MIT-pthreads occur only
  6832.      during the part of the configuration process that deals with the
  6833.      server code.  If you have configured the distribution using
  6834.      `--without-server' to build only the client code, clients will not
  6835.      know whether MIT-pthreads is being used and will use Unix socket
  6836.      connections by default.  Because Unix sockets do not work under
  6837.      MIT-pthreads on some platforms, this means you will need to use
  6838.      `-h' or `--host' when you run client programs.
  6839.  
  6840.    * When MySQL is compiled using MIT-pthreads, system locking is
  6841.      disabled by default for performance reasons.  You can tell the
  6842.      server to use system locking with the `--external-locking' option.
  6843.      This is only needed if you want to be able to run two MySQL
  6844.      servers against the same data files (not recommended).
  6845.  
  6846.    * Sometimes the pthread `bind()' command fails to bind to a socket
  6847.      without any error message (at least on Solaris).  The result is
  6848.      that all connections to the server fail.  For example:
  6849.  
  6850.           shell> mysqladmin version
  6851.           mysqladmin: connect to server at '' failed;
  6852.           error: 'Can't connect to mysql server on localhost (146)'
  6853.  
  6854.      The solution to this is to kill the `mysqld' server and restart it.
  6855.      This has only happened to us when we have forced the server down
  6856.      and done a restart immediately.
  6857.  
  6858.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  6859.      with `SIGINT' (break).  This is only noticeable when you run
  6860.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  6861.      terminate before the interrupt is served and the process stops.
  6862.  
  6863.    * When linking, you may receive warning messages like these (at
  6864.      least on Solaris); they can be ignored:
  6865.  
  6866.           ld: warning: symbol `_iob' has differing sizes:
  6867.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  6868.           file /usr/lib/libc.so value=0x140);
  6869.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  6870.           ld: warning: symbol `__iob' has differing sizes:
  6871.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  6872.           file /usr/lib/libc.so value=0x140);
  6873.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  6874.  
  6875.    * Some other warnings also can be ignored:
  6876.  
  6877.           implicit declaration of function `int strtoll(...)'
  6878.           implicit declaration of function `int strtoul(...)'
  6879.  
  6880.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  6881.      isn't needed, but may be interesting for someone.)
  6882.  
  6883. Windows Source Distribution
  6884. ---------------------------
  6885.  
  6886. You will need the following:
  6887.  
  6888.    * VC++ 6.0 compiler (updated with 4 or 5 SP and Pre-processor
  6889.      package) The Pre-processor package is necessary for the macro
  6890.      assembler.  More details at:
  6891.      `http://msdn.microsoft.com/vstudio/sp/vs6sp5/faq.asp'.
  6892.  
  6893.    * The MySQL source distribution for Windows, which can be downloaded
  6894.      from `http://www.mysql.com/downloads/'.
  6895.  
  6896. Building MySQL
  6897.  
  6898.   1. Create a work directory (e.g., workdir).
  6899.  
  6900.   2. Unpack the source distribution in the aforementioned directory.
  6901.  
  6902.   3. Start the VC++ 6.0 compiler.
  6903.  
  6904.   4. In the `File' menu, select `Open Workspace'.
  6905.  
  6906.   5. Open the `mysql.dsw' workspace you find on the work directory.
  6907.  
  6908.   6. From the `Build' menu, select the `Set Active Configuration' menu.
  6909.  
  6910.   7. Click over the screen selecting `mysqld - Win32 Debug' and click
  6911.      OK.
  6912.  
  6913.   8. Press `F7' to begin the build of the debug server, libs, and some
  6914.      client applications.
  6915.  
  6916.   9. When the compilation finishes, copy the libs and the executables
  6917.      to a separate directory.
  6918.  
  6919.  10. Compile the release versions that you want, in the same way.
  6920.  
  6921.  11. Create the directory for the MySQL stuff: e.g., `c:\mysql'
  6922.  
  6923.  12. From the workdir directory copy for the c:\mysql directory the
  6924.      following directories:
  6925.  
  6926.         * Data
  6927.  
  6928.         * Docs
  6929.  
  6930.         * Share
  6931.  
  6932.  13. Create the directory `c:\mysql\bin' and copy all the servers and
  6933.      clients that you compiled previously.
  6934.  
  6935.  14. If you want, also create the `lib' directory and copy the libs
  6936.      that you compiled previously.
  6937.  
  6938.  15. Do a clean using Visual Studio.
  6939.  
  6940. Set up and start the server in the same way as for the binary Windows
  6941. distribution. *Note Windows prepare environment::.
  6942.  
  6943. Post-installation Setup and Testing
  6944. ===================================
  6945.  
  6946. Once you've installed MySQL (from either a binary or source
  6947. distribution), you need to initialise the grant tables, start the
  6948. server, and make sure that the server works okay.  You may also wish to
  6949. arrange for the server to be started and stopped automatically when
  6950. your system starts up and shuts down.
  6951.  
  6952. Normally you install the grant tables and start the server like this
  6953. for installation from a source distribution:
  6954.  
  6955.      shell> ./scripts/mysql_install_db
  6956.      shell> cd mysql_installation_directory
  6957.      shell> ./bin/safe_mysqld --user=mysql &
  6958.  
  6959. For a binary distribution (not RPM or pkg packages), do this:
  6960.  
  6961.      shell> cd mysql_installation_directory
  6962.      shell> ./scripts/mysql_install_db
  6963.      shell> ./bin/safe_mysqld --user=mysql &
  6964.      or
  6965.      shell> ./bin/mysqld_safe --user=mysql &
  6966.      if you are running MySQL 4.x.
  6967.  
  6968. This creates the `mysql' database which will hold all database
  6969. privileges, the `test' database which you can use to test MySQL, and
  6970. also privilege entries for the user that run `mysql_install_db' and a
  6971. `root' user (without any passwords).  This also starts the `mysqld'
  6972. server.
  6973.  
  6974. `mysql_install_db' will not overwrite any old privilege tables, so it
  6975. should be safe to run in any circumstances.  If you don't want to have
  6976. the `test' database you can remove it with `mysqladmin -u root drop
  6977. test'.
  6978.  
  6979. Testing is most easily done from the top-level directory of the MySQL
  6980. distribution.  For a binary distribution, this is your installation
  6981. directory (typically something like `/usr/local/mysql').  For a source
  6982. distribution, this is the main directory of your MySQL source tree.
  6983.  
  6984. In the commands shown in this section and in the following subsections,
  6985. `BINDIR' is the path to the location in which programs like
  6986. `mysqladmin' and `safe_mysqld' are installed.  For a binary
  6987. distribution, this is the `bin' directory within the distribution.  For
  6988. a source distribution, `BINDIR' is probably `/usr/local/bin', unless
  6989. you specified an installation directory other than `/usr/local' when
  6990. you ran `configure'.  `EXECDIR' is the location in which the `mysqld'
  6991. server is installed.  For a binary distribution, this is the same as
  6992. `BINDIR'.  For a source distribution, `EXECDIR' is probably
  6993. `/usr/local/libexec'.
  6994.  
  6995. Testing is described in detail:
  6996.  
  6997.   1. If necessary, start the `mysqld' server and set up the initial
  6998.      MySQL grant tables containing the privileges that determine how
  6999.      users are allowed to connect to the server.  This is normally done
  7000.      with the `mysql_install_db' script:
  7001.  
  7002.           shell> scripts/mysql_install_db
  7003.  
  7004.      Typically, `mysql_install_db' needs to be run only the first time
  7005.      you install MySQL.  Therefore, if you are upgrading an existing
  7006.      installation, you can skip this step.  (However,
  7007.      `mysql_install_db' is quite safe to use and will not update any
  7008.      tables that already exist, so if you are unsure of what to do, you
  7009.      can always run `mysql_install_db'.)
  7010.  
  7011.      `mysql_install_db' creates six tables (`user', `db', `host',
  7012.      `tables_priv', `columns_priv', and `func') in the `mysql'
  7013.      database.  A description of the initial privileges is given in
  7014.      *Note Default privileges::.  Briefly, these privileges allow the
  7015.      MySQL `root' user to do anything, and allow anybody to create or
  7016.      use databases with a name of `test' or starting with `test_'.
  7017.  
  7018.      If you don't set up the grant tables, the following error will
  7019.      appear in the log file when you start the server:
  7020.  
  7021.           mysqld: Can't find file: 'host.frm'
  7022.  
  7023.      This may also happen with a binary MySQL distribution if you don't
  7024.      start MySQL by executing exactly `./bin/safe_mysqld'!  *Note
  7025.      `safe_mysqld': safe_mysqld.
  7026.  
  7027.      You might need to run `mysql_install_db' as `root'.  However, if
  7028.      you prefer, you can run the MySQL server as an unprivileged
  7029.      (non-`root') user, provided that the user can read and write files
  7030.      in the database directory.  Instructions for running MySQL as an
  7031.      unprivileged user are given in *Note Changing MySQL user: Changing
  7032.      MySQL user.
  7033.  
  7034.      If you have problems with `mysql_install_db', see *Note
  7035.      `mysql_install_db': mysql_install_db.
  7036.  
  7037.      There are some alternatives to running the `mysql_install_db'
  7038.      script as it is provided in the MySQL distribution:
  7039.  
  7040.         * You may want to edit `mysql_install_db' before running it, to
  7041.           change the initial privileges that are installed into the
  7042.           grant tables.  This is useful if you want to install MySQL on
  7043.           a lot of machines with the same privileges.  In this case you
  7044.           probably should need only to add a few extra `INSERT'
  7045.           statements to the `mysql.user' and `mysql.db' tables!
  7046.  
  7047.         * If you want to change things in the grant tables after
  7048.           installing them, you can run `mysql_install_db', then use
  7049.           `mysql -u root mysql' to connect to the grant tables as the
  7050.           MySQL `root' user and issue SQL statements to modify the
  7051.           grant tables directly.
  7052.  
  7053.         * It is possible to re-create the grant tables completely after
  7054.           they have already been created.  You might want to do this if
  7055.           you've already installed the tables but then want to
  7056.           re-create them after editing `mysql_install_db'.
  7057.  
  7058.      For more information about these alternatives, see *Note Default
  7059.      privileges::.
  7060.  
  7061.   2. Start the MySQL server like this:
  7062.  
  7063.           shell> cd mysql_installation_directory
  7064.           shell> bin/safe_mysqld &
  7065.  
  7066.      If you have problems starting the server, see *Note Starting
  7067.      server::.
  7068.  
  7069.   3. Use `mysqladmin' to verify that the server is running.  The
  7070.      following commands provide a simple test to check that the server
  7071.      is up and responding to connections:
  7072.  
  7073.           shell> BINDIR/mysqladmin version
  7074.           shell> BINDIR/mysqladmin variables
  7075.  
  7076.      The output from `mysqladmin version' varies slightly depending on
  7077.      your platform and version of MySQL, but should be similar to that
  7078.      shown here:
  7079.  
  7080.           shell> BINDIR/mysqladmin version
  7081.           mysqladmin  Ver 8.14 Distrib 3.23.32, for linux on i586
  7082.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  7083.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  7084.           and you are welcome to modify and redistribute it under the GPL license.
  7085.           
  7086.           Server version          3.23.32-debug
  7087.           Protocol version        10
  7088.           Connection              Localhost via Unix socket
  7089.           TCP port                3306
  7090.           UNIX socket             /tmp/mysql.sock
  7091.           Uptime:                 16 sec
  7092.           
  7093.           Threads: 1  Questions: 9  Slow queries: 0
  7094.           Opens: 7  Flush tables: 2  Open tables: 0
  7095.           Queries per second avg: 0.000
  7096.           Memory in use: 132K  Max memory used: 16773K
  7097.  
  7098.      To get a feeling for what else you can do with `BINDIR/mysqladmin',
  7099.      invoke it with the `--help' option.
  7100.  
  7101.   4. Verify that you can shut down the server:
  7102.  
  7103.           shell> BINDIR/mysqladmin -u root shutdown
  7104.  
  7105.   5. Verify that you can restart the server.  Do this using
  7106.      `safe_mysqld' or by invoking `mysqld' directly.  For example:
  7107.  
  7108.           shell> BINDIR/safe_mysqld --log &
  7109.  
  7110.      If `safe_mysqld' fails, try running it from the MySQL installation
  7111.      directory (if you are not already there).  If that doesn't work,
  7112.      see *Note Starting server::.
  7113.  
  7114.   6. Run some simple tests to verify that the server is working.  The
  7115.      output should be similar to what is shown here:
  7116.  
  7117.           shell> BINDIR/mysqlshow
  7118.           +-----------+
  7119.           | Databases |
  7120.           +-----------+
  7121.           | mysql     |
  7122.           +-----------+
  7123.           
  7124.           shell> BINDIR/mysqlshow mysql
  7125.           Database: mysql
  7126.           +--------------+
  7127.           |    Tables    |
  7128.           +--------------+
  7129.           | columns_priv |
  7130.           | db           |
  7131.           | func         |
  7132.           | host         |
  7133.           | tables_priv  |
  7134.           | user         |
  7135.           +--------------+
  7136.           
  7137.           shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql
  7138.           +------+--------+------+
  7139.           | host | db     | user |
  7140.           +------+--------+------+
  7141.           | %    | test   |      |
  7142.           | %    | test_% |      |
  7143.           +------+--------+------+
  7144.  
  7145.      There is also a benchmark suite in the `sql-bench' directory
  7146.      (under the MySQL installation directory) that you can use to
  7147.      compare how MySQL performs on different platforms.  The
  7148.      `sql-bench/Results' directory contains the results from many runs
  7149.      against different databases and platforms.  To run all tests,
  7150.      execute these commands:
  7151.  
  7152.           shell> cd sql-bench
  7153.           shell> run-all-tests
  7154.  
  7155.      If you don't have the `sql-bench' directory, you are probably
  7156.      using an RPM for a binary distribution.  (Source distribution RPMs
  7157.      include the benchmark directory.)  In this case, you must first
  7158.      install the benchmark suite before you can use it.  Beginning with
  7159.      MySQL Version 3.22, there are benchmark RPM files named
  7160.      `mysql-bench-VERSION-i386.rpm' that contain benchmark code and
  7161.      data.
  7162.  
  7163.      If you have a source distribution, you can also run the tests in
  7164.      the `tests' subdirectory. For example, to run
  7165.      `auto_increment.tst', do this:
  7166.  
  7167.           shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
  7168.  
  7169.      The expected results are shown in the `./tests/auto_increment.res'
  7170.      file.
  7171.  
  7172. Problems Running `mysql_install_db'
  7173. -----------------------------------
  7174.  
  7175. The purpose of the `mysql_install_db' script is to generate new MySQL
  7176. privilege tables.  It will not affect any other data!  It will also not
  7177. do anything if you already have MySQL privilege tables installed!
  7178.  
  7179. If you want to re-create your privilege tables, you should take down
  7180. the `mysqld' server, if it's running, and then do something like:
  7181.  
  7182.      mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  7183.      mysql_install_db
  7184.  
  7185. This section lists problems you might encounter when you run
  7186. `mysql_install_db':
  7187.  
  7188. *`mysql_install_db' doesn't install the grant tables*
  7189.      You may find that `mysql_install_db' fails to install the grant
  7190.      tables and terminates after displaying the following messages:
  7191.  
  7192.           starting mysqld daemon with databases from XXXXXX
  7193.           mysql daemon ended
  7194.  
  7195.      In this case, you should examine the log file very carefully!  The
  7196.      log should be located in the directory `XXXXXX' named by the error
  7197.      message, and should indicate why `mysqld' didn't start.  If you
  7198.      don't understand what happened, include the log when you post a
  7199.      bug report using `mysqlbug'!  *Note Bug reports::.
  7200.  
  7201. *There is already a `mysqld' daemon running*
  7202.      In this case, you probably don't have to run `mysql_install_db' at
  7203.      all.  You have to run `mysql_install_db' only once, when you
  7204.      install MySQL the first time.
  7205.  
  7206. *Installing a second `mysqld' daemon doesn't work when one daemon is running*
  7207.      This can happen when you already have an existing MySQL
  7208.      installation, but want to put a new installation in a different
  7209.      place (for example, for testing, or perhaps you simply want to run
  7210.      two installations at the same time).  Generally the problem that
  7211.      occurs when you try to run the second server is that it tries to
  7212.      use the same socket and port as the old one.  In this case you
  7213.      will get the error message: `Can't start server: Bind on TCP/IP
  7214.      port: Address already in use' or `Can't start server: Bind on unix
  7215.      socket...'. *Note Installing many servers::.
  7216.  
  7217. *You don't have write access to `/tmp'*
  7218.      If you don't have write access to create a socket file at the
  7219.      default place (in `/tmp') or permission to create temporary files
  7220.      in `/tmp,' you will get an error when running `mysql_install_db'
  7221.      or when starting or using `mysqld'.
  7222.  
  7223.      You can specify a different socket and temporary directory as
  7224.      follows:
  7225.  
  7226.           shell> TMPDIR=/some_tmp_dir/
  7227.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
  7228.           shell> export TMPDIR MYSQL_UNIX_PORT
  7229.  
  7230.      See *Note Problems with mysql.sock::.
  7231.  
  7232.      `some_tmp_dir' should be the path to some directory for which you
  7233.      have write permission. *Note Environment variables::.
  7234.  
  7235.      After this you should be able to run `mysql_install_db' and start
  7236.      the server with these commands:
  7237.  
  7238.           shell> scripts/mysql_install_db
  7239.           shell> BINDIR/safe_mysqld &
  7240.  
  7241. *`mysqld' crashes immediately*
  7242.      If you are running RedHat Version 5.0 with a version of `glibc'
  7243.      older than 2.0.7-5, you should make sure you have installed all
  7244.      `glibc' patches!  There is a lot of information about this in the
  7245.      MySQL mail archives.  Links to the mail archives are available
  7246.      online at `http://lists.mysql.com/'.  Also, see *Note Linux::.
  7247.  
  7248.      You can also start `mysqld' manually using the
  7249.      `--skip-grant-tables' option and add the privilege information
  7250.      yourself using `mysql':
  7251.  
  7252.           shell> BINDIR/safe_mysqld --skip-grant-tables &
  7253.           shell> BINDIR/mysql -u root mysql
  7254.  
  7255.      From `mysql', manually execute the SQL commands in
  7256.      `mysql_install_db'.  Make sure you run `mysqladmin
  7257.      flush-privileges' or `mysqladmin reload' afterward to tell the
  7258.      server to reload the grant tables.
  7259.  
  7260. Problems Starting the MySQL Server
  7261. ----------------------------------
  7262.  
  7263. If you are going to use tables that support transactions (InnoDB, BDB),
  7264. you should first create a `my.cnf' file and set startup options for the
  7265. table types you plan to use. *Note Table types::.
  7266.  
  7267. Generally, you start the `mysqld' server in one of these ways:
  7268.  
  7269.    * By invoking `mysql.server'.  This script is used primarily at
  7270.      system startup and shutdown, and is described more fully in *Note
  7271.      Automatic start::.
  7272.  
  7273.    * By invoking `safe_mysqld', which tries to determine the proper
  7274.      options for `mysqld' and then runs it with those options. *Note
  7275.      `safe_mysqld': safe_mysqld.
  7276.  
  7277.    * For Windows NT/2000/XP, please see *Note NT start::.
  7278.  
  7279.    * By invoking `mysqld' directly.
  7280.  
  7281. When the `mysqld' daemon starts up, it changes the directory to the
  7282. data directory.  This is where it expects to write log files and the pid
  7283. (process ID) file, and where it expects to find databases.
  7284.  
  7285. The data directory location is hardwired in when the distribution is
  7286. compiled.  However, if `mysqld' expects to find the data directory
  7287. somewhere other than where it really is on your system, it will not work
  7288. properly.  If you have problems with incorrect paths, you can find out
  7289. what options `mysqld' allows and what the default path settings are by
  7290. invoking `mysqld' with the `--help' option.  You can override the
  7291. defaults by specifying the correct pathnames as command-line arguments
  7292. to `mysqld'.  (These options can be used with `safe_mysqld' as well.)
  7293.  
  7294. Normally you should need to tell `mysqld' only the base directory under
  7295. which MySQL is installed.  You can do this with the `--basedir' option.
  7296. You can also use `--help' to check the effect of changing path options
  7297. (note that `--help' *must* be the final option of the `mysqld'
  7298. command).  For example:
  7299.  
  7300.      shell> EXECDIR/mysqld --basedir=/usr/local --help
  7301.  
  7302. Once you determine the path settings you want, start the server without
  7303. the `--help' option.
  7304.  
  7305. Whichever method you use to start the server, if it fails to start up
  7306. correctly, check the log file to see if you can find out why.  Log files
  7307. are located in the data directory (typically `/usr/local/mysql/data'
  7308. for a binary distribution, `/usr/local/var' for a source distribution,
  7309. and `\mysql\data\mysql.err' on Windows).  Look in the data directory for
  7310. files with names of the form `host_name.err' and `host_name.log' where
  7311. `host_name' is the name of your server host.  Then check the last few
  7312. lines of these files:
  7313.  
  7314.      shell> tail host_name.err
  7315.      shell> tail host_name.log
  7316.  
  7317. Look for something like the following in the log file:
  7318.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  7319.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  7320.      000729 14:50:10  Can't init databases
  7321.  
  7322. This means that you didn't start `mysqld' with `--bdb-no-recover' and
  7323. Berkeley DB found something wrong with its log files when it tried to
  7324. recover your databases.  To be able to continue, you should move away
  7325. the old Berkeley DB log file from the database directory to some other
  7326. place, where you can later examine it.  The log files are named
  7327. `log.0000000001', where the number will increase over time.
  7328.  
  7329. If you are running `mysqld' with BDB table support and `mysqld' core
  7330. dumps at start this could be because of some problems with the BDB
  7331. recover log.  In this case you can try starting `mysqld' with
  7332. `--bdb-no-recover'.  If this helps, then you should remove all `log.*'
  7333. files from the data directory and try starting `mysqld' again.
  7334.  
  7335. If you get the following error, it means that some other program (or
  7336. another `mysqld' server) is already using the TCP/IP port or socket
  7337. `mysqld' is trying to use:
  7338.  
  7339.      Can't start server: Bind on TCP/IP port: Address already in use
  7340.        or
  7341.      Can't start server : Bind on unix socket...
  7342.  
  7343. Use `ps' to make sure that you don't have another `mysqld' server
  7344. running.  If you can't find another server running, you can try to
  7345. execute the command `telnet your-host-name tcp-ip-port-number' and press
  7346. Enter a couple of times.  If you don't get an error message like
  7347. `telnet: Unable to connect to remote host: Connection refused',
  7348. something is using the TCP/IP port `mysqld' is trying to use.  See
  7349. *Note mysql_install_db:: and *Note Multiple servers::.
  7350.  
  7351. If `mysqld' is currently running, you can find out what path settings
  7352. it is using by executing this command:
  7353.  
  7354.      shell> mysqladmin variables
  7355.  
  7356. or
  7357.  
  7358.      shell> mysqladmin -h 'your-host-name' variables
  7359.  
  7360. If you get `Errcode 13', which means `Permission denied', when starting
  7361. `mysqld' this means that you didn't have the right to read/create files
  7362. in the MySQL database or log directory. In this case you should either
  7363. start `mysqld' as the root user or change the permissions for the
  7364. involved files and directories so that you have the right to use them.
  7365.  
  7366. If `safe_mysqld' starts the server but you can't connect to it, you
  7367. should make sure you have an entry in `/etc/hosts' that looks like this:
  7368.  
  7369.      127.0.0.1       localhost
  7370.  
  7371. This problem occurs only on systems that don't have a working thread
  7372. library and for which MySQL must be configured to use MIT-pthreads.
  7373.  
  7374. If you can't get `mysqld' to start you can try to make a trace file to
  7375. find the problem. *Note Making trace files::.
  7376.  
  7377. If you are using InnoDB tables, refer to the InnoDB-specific startup
  7378. options.  *Note InnoDB start::.
  7379.  
  7380. If you are using BDB (Berkeley DB) tables, you should familiarise
  7381. yourself with the different BDB-specific startup options.  *Note BDB
  7382. start::.
  7383.  
  7384. Starting and Stopping MySQL Automatically
  7385. -----------------------------------------
  7386.  
  7387. The `mysql.server' and `safe_mysqld' scripts can be used to start the
  7388. server automatically at system startup time. `mysql.server' can also be
  7389. used to stop the server.
  7390.  
  7391. The `mysql.server' script can be used to start or stop the server by
  7392. invoking it with `start' or `stop' arguments:
  7393.  
  7394.      shell> mysql.server start
  7395.      shell> mysql.server stop
  7396.  
  7397. `mysql.server' can be found in the `share/mysql' directory under the
  7398. MySQL installation directory or in the `support-files' directory of the
  7399. MySQL source tree.
  7400.  
  7401. Before `mysql.server' starts the server, it changes the directory to
  7402. the MySQL installation directory, then invokes `safe_mysqld'.  You
  7403. might need to edit `mysql.server' if you have a binary distribution
  7404. that you've installed in a non-standard location.  Modify it to `cd'
  7405. into the proper directory before it runs `safe_mysqld'. If you want the
  7406. server to run as some specific user, add an appropriate `user' line to
  7407. the `/etc/my.cnf' file, as shown later in this section.
  7408.  
  7409. `mysql.server stop' brings down the server by sending a signal to it.
  7410. You can also take down the server manually by executing `mysqladmin
  7411. shutdown'.
  7412.  
  7413. You need to add these start and stop commands to the appropriate places
  7414. in your `/etc/rc*' files when you want to start up MySQL automatically
  7415. on your server.
  7416.  
  7417. On most current Linux distributions, it is sufficient to copy the file
  7418. `mysql.server' into the `/etc/init.d' directory (or `/etc/rc.d/init.d'
  7419. on older Red Hat systems). Afterwards, run the following command to
  7420. enable the startup of MySQL on system bootup:
  7421.  
  7422.      shell> chkconfig --add mysql.server
  7423.  
  7424. As an alternative to the above, some operating systems also use
  7425. `/etc/rc.local' or `/etc/init.d/boot.local' to start additional
  7426. services on bootup. To start up MySQL using this method, you could
  7427. append something like the following to it:
  7428.  
  7429.      /bin/sh -c 'cd /usr/local/mysql ; ./bin/safe_mysqld --user=mysql &'
  7430.  
  7431. You can also add options for `mysql.server' in a global `/etc/my.cnf'
  7432. file.  A typical `/etc/my.cnf' file might look like this:
  7433.  
  7434.      [mysqld]
  7435.      datadir=/usr/local/mysql/var
  7436.      socket=/var/tmp/mysql.sock
  7437.      port=3306
  7438.      user=mysql
  7439.      
  7440.      [mysql_server]
  7441.      basedir=/usr/local/mysql
  7442.  
  7443. The `mysql.server' script understands the following options: `datadir',
  7444. `basedir', and `pid-file'.
  7445.  
  7446. The following table shows which option groups each of the startup
  7447. scripts read from option files:
  7448.  
  7449. *Script*    *Option groups*
  7450. `mysqld'    `mysqld' and `server'
  7451. `mysql.server'`mysql.server',
  7452.             `mysqld', and `server'
  7453. `safe_mysqld'`mysql.server',
  7454.             `mysqld', and `server'
  7455.  
  7456. *Note Option files::.
  7457.  
  7458. Upgrading/Downgrading MySQL
  7459. ===========================
  7460.  
  7461. You can always move the MySQL form and datafiles between different
  7462. versions on the same architecture as long as you have the same base
  7463. version of MySQL. The current base version is 3. If you change the
  7464. character set when running MySQL (which may also change the sort
  7465. order), you must run `myisamchk -r -q --set-character-set=charset' on
  7466. all tables.  Otherwise, your indexes may not be ordered correctly.
  7467.  
  7468. If you are afraid of new versions, you can always rename your old
  7469. `mysqld' to something like `mysqld-old-version-number'.  If your new
  7470. `mysqld' then does something unexpected, you can simply shut it down
  7471. and restart with your old `mysqld'!
  7472.  
  7473. When you do an upgrade you should also back up your old databases, of
  7474. course.
  7475.  
  7476. If after an upgrade, you experience problems with recompiled client
  7477. programs, like `Commands out of sync' or unexpected core dumps, you
  7478. probably have used an old header or library file when compiling your
  7479. programs.  In this case you should check the date for your `mysql.h'
  7480. file and `libmysqlclient.a' library to verify that they are from the new
  7481. MySQL distribution.  If not, please recompile your programs!
  7482.  
  7483. If you get some problems that the new `mysqld' server doesn't want to
  7484. start or that you can't connect without a password, check that you don't
  7485. have some old `my.cnf' file from your old installation!  You can check
  7486. this with: `program-name --print-defaults'.  If this outputs anything
  7487. other than the program name, you have an active `my.cnf' file that will
  7488. affect things!
  7489.  
  7490. It is a good idea to rebuild and reinstall the `Msql-Mysql-modules'
  7491. distribution whenever you install a new release of MySQL, particularly
  7492. if you notice symptoms such as all your `DBI' scripts dumping core
  7493. after you upgrade MySQL.
  7494.  
  7495. Upgrading From Version 4.0 to Version 4.1
  7496. -----------------------------------------
  7497.  
  7498. In general what you have to do when upgrading to 4.1 from an earlier
  7499. MySQL version:
  7500.  
  7501.    * Run the `mysql_fix_privilege_tables' to get the new password field
  7502.      that is needed for secure handling of passwords.
  7503.  
  7504. The following is a more complete lists tell what you have to watch out
  7505. for when upgrading to version 4.1;
  7506.  
  7507.    * Functions that return a DATE, DATETIME or TIME result is now fixed
  7508.      up when returned to the client.
  7509.  
  7510.           mysql> SELECT cast("2001-1-1" as DATE)
  7511.               -> '2001-01-01'
  7512.  
  7513.    * All column and tables now have a character set, which shows up in
  7514.      `SHOW CREATE TABLE' and `mysqldump'.  (MySQL 4.0.6 and above can
  7515.      read the new dump files, but not previous MySQL versions).
  7516.  
  7517.    * Timestamp is now returned as string of type `'YYYY-MM-DD
  7518.      HH:MM:DD''.  If you want to have this as a number you should add
  7519.      +0 to the timestamp column.  Different timestamp lengths are not
  7520.      supported.
  7521.  
  7522. Upgrading From Version 3.23 to Version 4.0
  7523. ------------------------------------------
  7524.  
  7525. In general what you have to do when upgrading to 4.0 from an earlier
  7526. MySQL version:
  7527.  
  7528.    * Run the `mysql_fix_privilege_tables' to add new privileges and
  7529.      features to the MySQL privilege tables.
  7530.  
  7531.    * Edit any MySQL startup scripts or configure files to not use any
  7532.      of the deprecated options listed below.
  7533.  
  7534.    * Convert your old ISAM files to MyISAM files with the command:
  7535.      `mysql_convert_table_format database'.  Note that this should only
  7536.      be run if all tables in the given database is ISAM or MyISAM
  7537.      tables. If this is not the case you should run `ALTER TABLE
  7538.      table_name TYPE=MyISAM' on all ISAM tables.
  7539.  
  7540.    * Ensure that you don't have any MySQL clients that uses shared
  7541.      libraries (like the perl Msql-Mysql-modules). If you have, you
  7542.      should recompile them as structures used in `libmysqlclient.so'
  7543.      have changed.
  7544.  
  7545. MySQL 4.0 will work even if you don't do the above, but you will not be
  7546. able to use the new security privileges that MySQL 4.0 and you may run
  7547. into problems when upgrading later to MySQL 4.1 or newer.  The ISAM file
  7548. format still works in MySQL 4.0 but it's deprecated and will be disabled
  7549. in MySQL 5.0.
  7550.  
  7551. Old clients should work with a Version 4.0 server without any problems.
  7552.  
  7553. Even if you do the above, you can still downgrade to MySQL 3.23.52 or
  7554. newer if you run into problems with the MySQL 4.0 series.  In this case
  7555. you have to do a `mysqldump' of any tables using a full-text index and
  7556. restore these in 3.23 (because 4.0 uses a new format for full-text
  7557. index).
  7558.  
  7559. The following is a more complete lists tell what you have to watch out
  7560. for when upgrading to version 4.0;
  7561.  
  7562.    * MySQL 4.0 has a lot of new privileges in the `mysql.user' table.
  7563.      *Note GRANT::.
  7564.  
  7565.      To get these new privileges to work, one must run the
  7566.      `mysql_fix_privilege_tables' script.  Until this script is run all
  7567.      users have the `SHOW DATABASES', `CREATE TEMPORARY TABLES', and
  7568.      `LOCK TABLES' privileges. `SUPER' and `EXECUTE' privileges take
  7569.      their value from `PROCESS'.  `REPLICATION SLAVE' and `REPLICATION
  7570.      CLIENT' take their values from `FILE'.
  7571.  
  7572.      If you have any scripts that creates new users, you may want to
  7573.      change them to use the new privileges.  If you are not using
  7574.      `GRANT' commands in the scripts, this is a good time to change
  7575.      your scripts.
  7576.  
  7577.      In version 4.0.2 the option `--safe-show-database' is deprecated
  7578.      (and no longer does anything). *Note Privileges options::.
  7579.  
  7580.      If you get access denied errors for new users in version 4.0.2, you
  7581.      should check if you need some of the new grants that you didn't
  7582.      need before.  In particular, you will need `REPLICATION SLAVE'
  7583.      (instead of `FILE') for new slaves.
  7584.  
  7585.    * The startup parameters `myisam_max_extra_sort_file_size' and
  7586.      `myisam_max_extra_sort_file_size' are now given in bytes (was
  7587.      megabytes before 4.0.3).  External system locking of MyISAM/ISAM
  7588.      files is now turned off by default.  One can turn this on by doing
  7589.      `--external-locking'. (For most users this is never needed).
  7590.  
  7591.    * The following startup variables/options have been renamed:
  7592.      *From*                             *to*.
  7593.      `myisam_bulk_insert_tree_size'     `bulk_insert_buffer_size'
  7594.      `query_cache_startup_type'         `query_cache_type'
  7595.      `record_buffer'                    `read_buffer_size'
  7596.      `record_rnd_buffer'                `read_rnd_buffer_size'
  7597.      `sort_buffer'                      `sort_buffer_size'
  7598.      `warnings'                         `log-warnings'
  7599.  
  7600.      The startup options `record_buffer', `sort_buffer' and `warnings'
  7601.      will still work in MySQL 4.0 but are deprecated.
  7602.  
  7603.    * The following SQL variables have changed name.
  7604.      *From*                             *To*.
  7605.      `SQL_BIG_TABLES'                   `BIG_TABLES'
  7606.      `SQL_LOW_PRIORITY_UPDATES'         `LOW_PRIORITY_UPDATES'
  7607.      `SQL_MAX_JOIN_SIZE'                `MAX_JOIN_SIZE'
  7608.      `SQL_QUERY_CACHE_TYPE'             `QUERY_CACHE_TYPE'
  7609.      The old names still work in MySQL 4.0 but are deprecated.
  7610.  
  7611.    * You have to use `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=#' instead of
  7612.      `SET SQL_SLAVE_SKIP_COUNTER=#'.
  7613.  
  7614.    * Renamed mysqld startup options `--skip-locking' to
  7615.      `--skip-external-locking' and `--enable-locking' to
  7616.      `--external-locking'.
  7617.  
  7618.    * `SHOW MASTER STATUS' now returns an empty set if binary log is not
  7619.      enabled.
  7620.  
  7621.    * `SHOW SLAVE STATUS' now returns an empty set if slave is not
  7622.      initialised.
  7623.  
  7624.    * mysqld now has the option `--temp-pool' enabled by default as this
  7625.      gives better performance with some OS (Most notable Linux).
  7626.  
  7627.    * `DOUBLE' and `FLOAT' columns now honour the `UNSIGNED' flag on
  7628.      storage (before, `UNSIGNED' was ignored for these columns).
  7629.  
  7630.    * `ORDER BY column DESC' now always sorts `NULL' values first; in
  7631.      3.23 this was not always consistent.
  7632.  
  7633.    * `SHOW INDEX' has 2 columns more (`Null' and `Index_type') than it
  7634.      had in 3.23.
  7635.  
  7636.    * `CHECK', `SIGNED', `LOCALTIME' and `LOCALTIMESTAMP' are now
  7637.      reserved words.
  7638.  
  7639.    * The result of all bitwise operators `|', `&', `<<', `>>', and `~'
  7640.      is now unsigned.  This may cause problems if you are using them in
  7641.      a context where you want a signed result.  *Note Cast Functions::.
  7642.  
  7643.    * *Note*: when you use subtraction between integer values where one
  7644.      is of type `UNSIGNED', the result will be unsigned!  In other
  7645.      words, before upgrading to MySQL 4.0, you should check your
  7646.      application for cases where you are subtracting a value from an
  7647.      unsigned entity and want a negative answer or subtracting an
  7648.      unsigned value from an integer column. You can disable this
  7649.      behaviour by using the `--sql-mode=NO_UNSIGNED_SUBTRACTION' option
  7650.      when starting `mysqld'.  *Note Cast Functions::.
  7651.  
  7652.    * To use `MATCH ... AGAINST (... IN BOOLEAN MODE)' with your tables,
  7653.      you need to rebuild them with `REPAIR TABLE table_name USE_FRM'.
  7654.  
  7655.    * `LOCATE()' and `INSTR()' are case-sensitive if one of the
  7656.      arguments is a binary string. Otherwise they are case-insensitive.
  7657.  
  7658.    * `STRCMP()' now uses the current character set when doing
  7659.      comparisons, which means that the default comparison behaviour now
  7660.      is case-insensitive.
  7661.  
  7662.    * `HEX(string)' now returns the characters in string converted to
  7663.      hexadecimal.  If you want to convert a number to hexadecimal, you
  7664.      should ensure that you call `HEX()' with a numeric argument.
  7665.  
  7666.    * In 3.23, `INSERT INTO ... SELECT' always had `IGNORE' enabled.  In
  7667.      4.0.1, MySQL will stop (and possibly roll back) in case of an
  7668.      error if you don't specify `IGNORE'.
  7669.  
  7670.    * `safe_mysqld' is renamed to `mysqld_safe'.  For some time we will
  7671.      in our binary distributions include `safe_mysqld' as a symlink to
  7672.      `mysqld_safe'.
  7673.  
  7674.    * The old C API functions `mysql_drop_db', `mysql_create_db', and
  7675.      `mysql_connect' are not supported anymore, unless you compile
  7676.      MySQL with `CFLAGS=-DUSE_OLD_FUNCTIONS'.  Instead of doing this,
  7677.      it is preferable to change the client to use the new 4.0 API.
  7678.  
  7679.    * In the `MYSQL_FIELD' structure, `length' and `max_length' have
  7680.      changed from `unsigned int' to `unsigned long'. This should not
  7681.      cause any problems, except that they may generate warning messages
  7682.      when used as arguments in the `printf()' class of functions.
  7683.  
  7684.    * You should use `TRUNCATE TABLE' when you want to delete all rows
  7685.      from a table and you don't care how many rows were deleted.
  7686.      (Because `TRUNCATE TABLE' is faster than `DELETE FROM table_name').
  7687.  
  7688.    * You will get an error if you have an active `LOCK TABLES' or
  7689.      transaction when trying to execute `TRUNCATE TABLE' or `DROP
  7690.      DATABASE'.
  7691.  
  7692.    * You should use integers to store values in BIGINT columns (instead
  7693.      of using strings, as you did in MySQL 3.23).  Using strings will
  7694.      still work, but using integers is more efficient.
  7695.  
  7696.    * Format of `SHOW OPEN TABLE' has changed.
  7697.  
  7698.    * Multi-threaded clients should use `mysql_thread_init()' and
  7699.      `mysql_thread_end()'. *Note Threaded clients::.
  7700.  
  7701.    * If you want to recompile the Perl DBD::mysql module, you must get
  7702.      Msql-Mysql-modules version 1.2218 or newer because the older DBD
  7703.      modules used the deprecated `drop_db()' call.
  7704.  
  7705.    * `RAND(seed)' returns a different random number series in 4.0 than
  7706.      in 3.23; this was done to further differentiate `RAND(seed)' and
  7707.      `RAND(seed+1)'.
  7708.  
  7709.    * The default type returned by `IFNULL(A,B)' is now set to be the
  7710.      more 'general' of the types of `A' and `B'. (The order is
  7711.      `STRING', `REAL' or `INTEGER').
  7712.  
  7713. Upgrading From Version 3.22 to Version 3.23
  7714. -------------------------------------------
  7715.  
  7716. MySQL Version 3.23 supports tables of the new `MyISAM' type and the old
  7717. `ISAM' type.  You don't have to convert your old tables to use these
  7718. with Version 3.23.  By default, all new tables will be created with
  7719. type `MyISAM' (unless you start `mysqld' with the
  7720. `--default-table-type=isam' option). You can change an `ISAM' table to
  7721. a `MyISAM' table with `ALTER TABLE table_name TYPE=MyISAM' or the Perl
  7722. script `mysql_convert_table_format'.
  7723.  
  7724. Version 3.22 and 3.21 clients will work without any problems with a
  7725. Version 3.23 server.
  7726.  
  7727. The following list tells what you have to watch out for when upgrading
  7728. to Version 3.23:
  7729.  
  7730.    * All tables that use the `tis620' character set must be fixed with
  7731.      `myisamchk -r' or `REPAIR TABLE'.
  7732.  
  7733.    * If you do a `DROP DATABASE' on a symbolic linked database, both the
  7734.      link and the original database are deleted.  (This didn't happen
  7735.      in 3.22 because configure didn't detect the `readlink' system
  7736.      call.)
  7737.  
  7738.    * `OPTIMIZE TABLE' now works only for `MyISAM' tables.  For other
  7739.      table types, you can use `ALTER TABLE' to optimise the table.
  7740.      During `OPTIMIZE TABLE' the table is now locked from other threads.
  7741.  
  7742.    * The MySQL client `mysql' is now by default started with the option
  7743.      `--no-named-commands (-g)'. This option can be disabled with
  7744.      `--enable-named-commands (-G)'. This may cause incompatibility
  7745.      problems in some casesfor example, in SQL scripts that use named
  7746.      commands without a semicolon!  Long format commands still work
  7747.      from the first line.
  7748.  
  7749.    * Date functions that work on parts of dates (like `MONTH()') will
  7750.      now return 0 for `0000-00-00' dates. (MySQL 3.22 returned `NULL'.)
  7751.  
  7752.    * If you are using the `german' character sort order, you must repair
  7753.      all your tables with `isamchk -r', as we have made some changes in
  7754.      the sort order!
  7755.  
  7756.    * The default return type of `IF' will now depend on both arguments
  7757.      and not only the first argument.
  7758.  
  7759.    * `AUTO_INCREMENT' will not work with negative numbers. The reason
  7760.      for this is that negative numbers caused problems when wrapping
  7761.      from -1 to 0.  `AUTO_INCREMENT' for MyISAM tables is now handled
  7762.      at a lower level and is much faster than before. For MyISAM tables
  7763.      old numbers are also not reused anymore, even if you delete some
  7764.      rows from the table.
  7765.  
  7766.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  7767.      `THEN', and `WHEN' are now reserved words.
  7768.  
  7769.    * `FLOAT(X)' is now a true floating-point type and not a value with a
  7770.      fixed number of decimals.
  7771.  
  7772.    * When declaring `DECIMAL(length,dec)' the length argument no longer
  7773.      includes a place for the sign or the decimal point.
  7774.  
  7775.    * A `TIME' string must now be of one of the following formats:
  7776.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  7777.      `[[[[[H]H]H]H]MM]SS[.fraction]'.
  7778.  
  7779.    * `LIKE' now compares strings using the same character comparison
  7780.      rules as `='.  If you require the old behaviour, you can compile
  7781.      MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  7782.  
  7783.    * `REGEXP' is now case-insensitive for normal (not binary) strings.
  7784.  
  7785.    * When you check/repair tables you should use `CHECK TABLE' or
  7786.      `myisamchk' for `MyISAM' tables (`.MYI') and `isamchk' for ISAM
  7787.      (`.ISM') tables.
  7788.  
  7789.    * If you want your `mysqldump' files to be compatible between MySQL
  7790.      Version 3.22 and Version 3.23, you should not use the `--opt' or
  7791.      `--all' option to `mysqldump'.
  7792.  
  7793.    * Check all your calls to `DATE_FORMAT()' to make sure there is a
  7794.      `%' before each format character.  (MySQL Version 3.22 and later
  7795.      already allowed this syntax.)
  7796.  
  7797.    * `mysql_fetch_fields_direct' is now a function (it was a macro) and
  7798.      it returns a pointer to a `MYSQL_FIELD' instead of a `MYSQL_FIELD'.
  7799.  
  7800.    * `mysql_num_fields()' can no longer be used on a `MYSQL*' object
  7801.      (it's now a function that takes `MYSQL_RES*' as an argument, so
  7802.      you should use `mysql_field_count()' instead).
  7803.  
  7804.    * In MySQL Version 3.22, the output of `SELECT DISTINCT ...' was
  7805.      almost always sorted.  In Version 3.23, you must use `GROUP BY' or
  7806.      `ORDER BY' to obtain sorted output.
  7807.  
  7808.    * `SUM()' now returns `NULL', instead of 0, if there are no matching
  7809.      rows. This is according to ANSI SQL.
  7810.  
  7811.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  7812.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  7813.      expression as `NOT NULL' = `NULL'.  `LPAD()' and `RPAD()' will
  7814.      shorten the result string if it's longer than the length argument.
  7815.  
  7816. Upgrading from Version 3.21 to Version 3.22
  7817. -------------------------------------------
  7818.  
  7819. Nothing that affects compatibility has changed between versions 3.21
  7820. and 3.22.  The only pitfall is that new tables that are created with
  7821. `DATE' type columns will use the new way to store the date. You can't
  7822. access these new fields from an old version of `mysqld'.
  7823.  
  7824. After installing MySQL Version 3.22, you should start the new server
  7825. and then run the `mysql_fix_privilege_tables' script. This will add the
  7826. new privileges that you need to use the `GRANT' command.  If you forget
  7827. this, you will get `Access denied' when you try to use `ALTER TABLE',
  7828. `CREATE INDEX', or `DROP INDEX'. If your MySQL root user requires a
  7829. password, you should give this as an argument to
  7830. `mysql_fix_privilege_tables'.
  7831.  
  7832. The C API interface to `mysql_real_connect()' has changed.  If you have
  7833. an old client program that calls this function, you must place a `0' for
  7834. the new `db' argument (or recode the client to send the `db' element
  7835. for faster connections).  You must also call `mysql_init()' before
  7836. calling `mysql_real_connect()'!  This change was done to allow the new
  7837. `mysql_options()' function to save options in the `MYSQL' handler
  7838. structure.
  7839.  
  7840. The `mysqld' variable `key_buffer' has changed names to
  7841. `key_buffer_size', but you can still use the old name in your startup
  7842. files.
  7843.  
  7844. Upgrading from Version 3.20 to Version 3.21
  7845. -------------------------------------------
  7846.  
  7847. If you are running a version older than Version 3.20.28 and want to
  7848. switch to Version 3.21, you need to do the following:
  7849.  
  7850. You can start the `mysqld' Version 3.21 server with `safe_mysqld
  7851. --old-protocol' to use it with clients from a Version 3.20 distribution.
  7852. In this case, the new client function `mysql_errno()' will not return
  7853. any server error, only `CR_UNKNOWN_ERROR' (but it works for client
  7854. errors), and the server uses the old `password()' checking rather than
  7855. the new one.
  7856.  
  7857. If you are *not* using the `--old-protocol' option to `mysqld', you
  7858. will need to make the following changes:
  7859.  
  7860.    * All client code must be recompiled. If you are using ODBC, you
  7861.      must get the new `MyODBC' 2.x driver.
  7862.  
  7863.    * The script `scripts/add_long_password' must be run to convert the
  7864.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  7865.  
  7866.    * All passwords must be reassigned in the `mysql.user' table (to get
  7867.      62-bit rather than 31-bit passwords).
  7868.  
  7869.    * The table format hasn't changed, so you don't have to convert any
  7870.      tables.
  7871.  
  7872. MySQL Version 3.20.28 and above can handle the new `user' table format
  7873. without affecting clients. If you have a MySQL version earlier than
  7874. Version 3.20.28, passwords will no longer work with it if you convert
  7875. the `user' table. So to be safe, you should first upgrade to at least
  7876. Version 3.20.28 and then upgrade to Version 3.21.
  7877.  
  7878. The new client code works with a 3.20.x `mysqld' server, so if you
  7879. experience problems with 3.21.x, you can use the old 3.20.x server
  7880. without having to recompile the clients again.
  7881.  
  7882. If you are not using the `--old-protocol' option to `mysqld', old
  7883. clients will issue the error message:
  7884.  
  7885.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  7886.  
  7887. The new Perl `DBI'/`DBD' interface also supports the old `mysqlperl'
  7888. interface.  The only change you have to make if you use `mysqlperl' is
  7889. to change the arguments to the `connect()' function.  The new arguments
  7890. are: `host', `database', `user', and `password' (the `user' and
  7891. `password' arguments have changed places).  *Note Perl `DBI' Class:
  7892. Perl DBI Class.
  7893.  
  7894. The following changes may affect queries in old applications:
  7895.  
  7896.    * `HAVING' must now be specified before any `ORDER BY' clause.
  7897.  
  7898.    * The parameters to `LOCATE()' have been swapped.
  7899.  
  7900.    * There are some new reserved words. The most notable are `DATE',
  7901.      `TIME', and `TIMESTAMP'.
  7902.  
  7903. Upgrading to Another Architecture
  7904. ---------------------------------
  7905.  
  7906. If you are using MySQL Version 3.23, you can copy the `.frm', `.MYI',
  7907. and `.MYD' files between different architectures that support the same
  7908. floating-point format.  (MySQL takes care of any byte-swapping issues.)
  7909.  
  7910. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  7911. respectively) are architecture-dependent and in some cases
  7912. OS-dependent.  If you want to move your applications to another machine
  7913. that has a different architecture or OS than your current machine, you
  7914. should not try to move a database by simply copying the files to the
  7915. other machine. Use `mysqldump' instead.
  7916.  
  7917. By default, `mysqldump' will create a file full of SQL statements.  You
  7918. can then transfer the file to the other machine and feed it as input to
  7919. the `mysql' client.
  7920.  
  7921. Try `mysqldump --help' to see what options are available.  If you are
  7922. moving the data to a newer version of MySQL, you should use `mysqldump
  7923. --opt' with the newer version to get a fast, compact dump.
  7924.  
  7925. The easiest (although not the fastest) way to move a database between
  7926. two machines is to run the following commands on the machine on which
  7927. the database is located:
  7928.  
  7929.      shell> mysqladmin -h 'other hostname' create db_name
  7930.      shell> mysqldump --opt db_name \
  7931.              | mysql -h 'other hostname' db_name
  7932.  
  7933. If you want to copy a database from a remote machine over a slow
  7934. network, you can use:
  7935.  
  7936.      shell> mysqladmin create db_name
  7937.      shell> mysqldump -h 'other hostname' --opt --compress db_name \
  7938.              | mysql db_name
  7939.  
  7940. You can also store the result in a file, then transfer the file to the
  7941. target machine and load the file into the database there.  For example,
  7942. you can dump a database to a file on the source machine like this:
  7943.  
  7944.      shell> mysqldump --quick db_name | gzip > db_name.contents.gz
  7945.  
  7946. (The file created in this example is compressed.) Transfer the file
  7947. containing the database contents to the target machine and run these
  7948. commands there:
  7949.  
  7950.      shell> mysqladmin create db_name
  7951.      shell> gunzip < db_name.contents.gz | mysql db_name
  7952.  
  7953. You can also use `mysqldump' and `mysqlimport' to accomplish the
  7954. database transfer.  For big tables, this is much faster than simply
  7955. using `mysqldump'.  In the following commands, `DUMPDIR' represents the
  7956. full pathname of the directory you use to store the output from
  7957. `mysqldump'.
  7958.  
  7959. First, create the directory for the output files and dump the database:
  7960.  
  7961.      shell> mkdir DUMPDIR
  7962.      shell> mysqldump --tab=DUMPDIR db_name
  7963.  
  7964. Then transfer the files in the `DUMPDIR' directory to some corresponding
  7965. directory on the target machine and load the files into MySQL there:
  7966.  
  7967.      shell> mysqladmin create db_name           # create database
  7968.      shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
  7969.      shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables
  7970.  
  7971. Also, don't forget to copy the `mysql' database because that's where the
  7972. grant tables (`user', `db', `host') are stored.  You may have to run
  7973. commands as the MySQL `root' user on the new machine until you have the
  7974. `mysql' database in place.
  7975.  
  7976. After you import the `mysql' database on the new machine, execute
  7977. `mysqladmin flush-privileges' so that the server reloads the grant table
  7978. information.
  7979.  
  7980. Operating System Specific Notes
  7981. ===============================
  7982.  
  7983. Linux Notes (All Linux Versions)
  7984. --------------------------------
  7985.  
  7986. The following notes regarding `glibc' apply only to the situation when
  7987. you build MySQL yourself. If you are running Linux on an x86 machine,
  7988. in most cases it is much better for you to just use our binary. We link
  7989. our binaries against the best patched version of `glibc' we can come up
  7990. with and with the best compiler options, in an attempt to make it
  7991. suitable for a high-load server. So if you read the following text, and
  7992. are in doubt about what you should do, try our binary first to see if
  7993. it meets your needs, and worry about your own build only after you have
  7994. discovered that our binary is not good enough. In that case, we would
  7995. appreciate a note about it, so we can build a better binary next time.
  7996. For a typical user, even for setups with a lot of concurrent
  7997. connections and/or tables exceeding the 2G limit, our binary in most
  7998. cases is the best choice.
  7999.  
  8000. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  8001. version that doesn't have `glibc2', you must install LinuxThreads
  8002. before trying to compile MySQL.   You can get LinuxThreads at
  8003. `http://www.mysql.com/downloads/os-linux.html'.
  8004.  
  8005. *Note*: we have seen some strange problems with Linux 2.2.14 and MySQL
  8006. on SMP systems. If you have a SMP system, we recommend you upgrade to
  8007. Linux 2.4 as soon as possible!  Your system will be faster and more
  8008. stable by doing this!
  8009.  
  8010. Note that `glibc' versions before and including Version 2.1.1 have a
  8011. fatal bug in `pthread_mutex_timedwait' handling, which is used when you
  8012. do `INSERT DELAYED'.  We recommend that you not use `INSERT DELAYED'
  8013. before upgrading glibc.
  8014.  
  8015. If you plan to have 1000+ concurrent connections, you will need to make
  8016. some changes to LinuxThreads, recompile it, and relink MySQL against
  8017. the new `libpthread.a'.  Increase `PTHREAD_THREADS_MAX' in
  8018. `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  8019. `STACK_SIZE' in `linuxthreads/internals.h' to 256 KB. The paths are
  8020. relative to the root of `glibc' Note that MySQL will not be stable with
  8021. around 600-1000 connections if `STACK_SIZE' is the default of 2 MB.
  8022.  
  8023. If MySQL can't open enough files, or connections, it may be that you
  8024. haven't configured Linux to handle enough files.
  8025.  
  8026. In Linux 2.2 and onward, you can check the number of allocated file
  8027. handles by doing:
  8028.  
  8029.      cat /proc/sys/fs/file-max
  8030.      cat /proc/sys/fs/dquot-max
  8031.      cat /proc/sys/fs/super-max
  8032.  
  8033. If you have more than 16 MB of memory, you should add something like the
  8034. following to your init scripts (e.g. `/etc/init.d/boot.local' on SuSE
  8035. Linux):
  8036.  
  8037.      echo 65536 > /proc/sys/fs/file-max
  8038.      echo 8192 > /proc/sys/fs/dquot-max
  8039.      echo 1024 > /proc/sys/fs/super-max
  8040.  
  8041. You can also run the preceding commands from the command-line as root,
  8042. but these settings will be lost the next time your computer reboots.
  8043.  
  8044. Alternatively, you can set these parameters on bootup by using the
  8045. `sysctl' tool, which is used by many Linux distributions (SuSE has
  8046. added it as well, beginning with SuSE Linux 8.0). Just put the following
  8047. values into a file named `/etc/sysctl.conf':
  8048.  
  8049.      # Increase some values for MySQL
  8050.      fs.file-max = 65536
  8051.      fs.dquot-max = 8192
  8052.      fs.super-max = 1024
  8053.  
  8054. You should also add the following to `/etc/my.cnf':
  8055.  
  8056.      [safe_mysqld]
  8057.      open-files-limit=8192
  8058.  
  8059. This should allow MySQL to create up to 8192 connections + files.
  8060.  
  8061. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  8062. stacks in the address space.  It needs to be large enough so that there
  8063. will be plenty of room for the stack of each individual thread, but
  8064. small enough to keep the stack of some threads from running into the
  8065. global `mysqld' data.  Unfortunately, the Linux implementation of
  8066. `mmap()', as we have experimentally discovered, will successfully unmap
  8067. an already mapped region if you ask it to map out an address already in
  8068. use, zeroing out the data on the entire page, instead of returning an
  8069. error.  So, the safety of `mysqld' or any other threaded application
  8070. depends on the "gentleman" behaviour of the code that creates threads.
  8071. The user must take measures to make sure the number of running threads
  8072. at any time is sufficiently low for thread stacks to stay away from the
  8073. global heap.  With `mysqld', you should enforce this "gentleman"
  8074. behaviour by setting a reasonable value for the `max_connections'
  8075. variable.
  8076.  
  8077. If you build MySQL yourself and do not want to mess with patching
  8078. LinuxThreads, you should set `max_connections' to a value no higher
  8079. than 500.  It should be even less if you have a large key buffer,  large
  8080. heap tables, or some other things that make `mysqld' allocate a lot of
  8081. memory, or if you are running a 2.2 kernel with a 2G patch. If you are
  8082. using our binary or RPM version 3.23.25 or later, you can safely set
  8083. `max_connections' at 1500, assuming no large key buffer or heap tables
  8084. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  8085. the more threads you can safely create.  We recommend the values between
  8086. 128K and 256K.
  8087.  
  8088. If you use a lot of concurrent connections, you may suffer from a
  8089. "feature" in the 2.2 kernel that penalises a process for forking or
  8090. cloning a child in an attempt to prevent a fork bomb attack.  This will
  8091. cause MySQL not to scale well as you increase the number of concurrent
  8092. clients.  On single-CPU systems, we have seen this manifested in a very
  8093. slow thread creation, which means it may take a long time to connect to
  8094. MySQL (as long as 1 minute), and it may take just as long to shut it
  8095. down.  On multiple-CPU systems, we have observed a gradual drop in
  8096. query speed as the number of clients increases.  In the process of
  8097. trying to find a solution, we have received a kernel patch from one of
  8098. our users, who claimed it made a lot of difference for his site.  The
  8099. patch is available at
  8100. `http://www.mysql.com/Downloads/Patches/linux-fork.patch'. We have now
  8101. done rather extensive testing of this patch on both development and
  8102. production systems.  It has significantly improved `MySQL' performance
  8103. without causing any problems and we now recommend it to our users who
  8104. are still running high-load servers on 2.2 kernels.  This issue has
  8105. been fixed in the 2.4 kernel, so if you are not satisfied with the
  8106. current performance of your system, rather than patching your 2.2
  8107. kernel, it might be easier to just upgrade to 2.4, which will also give
  8108. you a nice SMP boost in addition to fixing this fairness bug.
  8109.  
  8110. We have tested MySQL on the 2.4 kernel on a 2-CPU machine and found
  8111. MySQL scales *much* betterthere was virtually no slowdown on queries
  8112. throughput all the way up to 1000 clients, and the MySQL scaling factor
  8113. (computed as the ratio of maximum throughput to the throughput with one
  8114. client) was 180%.  We have observed similar results on a 4-CPU
  8115. systemvirtually no slowdown as the number of clients was increased up
  8116. to 1000, and 300% scaling factor. So for a high-load SMP server we
  8117. would definitely recommend the 2.4 kernel at this point. We have
  8118. discovered that it is essential to run `mysqld' process with the
  8119. highest possible priority on the 2.4 kernel to achieve maximum
  8120. performance.  This can be done by adding `renice -20 $$' command to
  8121. `safe_mysqld'. In our testing on a 4-CPU machine, increasing the
  8122. priority gave 60% increase in throughput with 400 clients.
  8123.  
  8124. We are currently also trying to collect more info on how well `MySQL'
  8125. performs on 2.4 kernel on 4-way and 8-way systems. If you have access
  8126. such a system and have done some benchmarks, please send a mail to
  8127. <docs@mysql.com> with the results - we will include them in the manual.
  8128.  
  8129. There is another issue that greatly hurts MySQL performance, especially
  8130. on SMP systems.  The implementation of mutex in LinuxThreads in
  8131. `glibc-2.1' is very bad for programs with many threads that only hold
  8132. the mutex for a short time. On an SMP system, ironic as it is, if you
  8133. link MySQL against unmodified `LinuxThreads', removing processors from
  8134. the machine improves MySQL performance in many cases.  We have made a
  8135. patch available for `glibc 2.1.3' to correct this behaviour
  8136. (`http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch').
  8137.  
  8138. With `glibc-2.2.2' MySQL version 3.23.36 will use the adaptive mutex,
  8139. which is much better than even the patched one in `glibc-2.1.3'. Be
  8140. warned, however, that under some conditions, the current mutex code in
  8141. `glibc-2.2.2' overspins, which hurts MySQL performance. The chance of
  8142. this condition can be reduced by renicing `mysqld' process to the
  8143. highest priority. We have also been able to correct the overspin
  8144. behaviour with a patch, available at
  8145. `http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch'.  It
  8146. combines the correction of overspin, maximum number of threads, and
  8147. stack spacing all in one. You will need to apply it in the
  8148. `linuxthreads' directory with `patch -p0
  8149. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  8150. form in to the future releases of `glibc-2.2'. In any case, if you link
  8151. against `glibc-2.2.2' you still need to correct `STACK_SIZE' and
  8152. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  8153. some more acceptable values for high-load MySQL setup in the future, so
  8154. that your own build can be reduced to `./configure; make; make install'.
  8155.  
  8156. We recommend that you use the above patches to build a special static
  8157. version of `libpthread.a' and use it only for statically linking
  8158. against `MySQL'. We know that the patches are safe for `MySQL' and
  8159. significantly improve its performance, but we cannot say anything about
  8160. other applications. If you link other applications against the patched
  8161. version of the library, or build a patched shared version and install
  8162. it on your system, you are doing it at your own risk with regard to
  8163. other applications that depend on `LinuxThreads'.
  8164.  
  8165. If you experience any strange problems during the installation of
  8166. MySQL, or with some common utilties hanging, it is very likely that
  8167. they are either library or compiler related. If this is the case, using
  8168. our binary will resolve them.
  8169.  
  8170. One known problem with the binary distribution is that with older Linux
  8171. systems that use `libc' (like RedHat 4.x or Slackware), you will get
  8172. some non-fatal problems with hostname resolution.  *Note Binary
  8173. notes-Linux::.
  8174.  
  8175. When using LinuxThreads you will see a minimum of three processes
  8176. running.  These are in fact threads.  There will be one thread for the
  8177. LinuxThreads manager, one thread to handle connections, and one thread
  8178. to handle alarms and signals.
  8179.  
  8180. Note that the Linux kernel and the LinuxThread library can by default
  8181. only have 1024 threads.  This means that you can only have up to 1021
  8182. connections to MySQL on an unpatched system.  The page
  8183. `http://www.volano.com/linuxnotes.html' contains information how to go
  8184. around this limit.
  8185.  
  8186. If you see a dead `mysqld' daemon process with `ps', this usually means
  8187. that you have found a bug in MySQL or you have a corrupted table. *Note
  8188. Crashing::.
  8189.  
  8190. To get a core dump on Linux if `mysqld' dies with a `SIGSEGV' signal,
  8191. you can start `mysqld' with the `--core-file' option.  Note that you
  8192. also probably need to raise the `core file size' by adding `ulimit -c
  8193. 1000000' to `safe_mysqld' or starting `safe_mysqld' with
  8194. `--core-file-size=1000000'.  *Note `safe_mysqld': safe_mysqld.
  8195.  
  8196. If you are linking your own MySQL client and get the error:
  8197.  
  8198.      ld.so.1: ./my: fatal: libmysqlclient.so.4:
  8199.      open failed: No such file or directory
  8200.  
  8201. When executing them, the problem can be avoided by one of the following
  8202. methods:
  8203.  
  8204.    * Link the client with the following flag (instead of `-Lpath'):
  8205.      `-Wl,r/path-libmysqlclient.so'.
  8206.  
  8207.    * Copy `libmysqclient.so' to `/usr/lib'.
  8208.  
  8209.    * Add the pathname of the directory where `libmysqlclient.so' is
  8210.      located to the `LD_RUN_PATH' environment variable before running
  8211.      your client.
  8212.  
  8213. If you are using the Fujitsu compiler `(fcc / FCC)' you will have some
  8214. problems compiling MySQL because the Linux header files are very `gcc'
  8215. oriented.
  8216.  
  8217. The following `configure' line should work with `fcc/FCC':
  8218.  
  8219.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE \
  8220.      -DCONST=const -DNO_STRTOLL_PROTO" CXX=FCC CXXFLAGS="-O -K fast -K lib \
  8221.      -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE -DCONST=const \
  8222.      -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO \
  8223.      '-D_EXTERN_INLINE=static __inline'" ./configure --prefix=/usr/local/mysql \
  8224.      --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared \
  8225.      --with-low-memory
  8226.  
  8227. Linux Notes for Binary Distributions
  8228. ....................................
  8229.  
  8230. MySQL needs at least Linux Version 2.0.
  8231.  
  8232. *Warning*: We have reports from some MySQL users that they have got
  8233. serious stability problems with MySQL with Linux kernel 2.2.14.  If you
  8234. are using this kernel you should upgrade to 2.2.19 (or newer) or to a
  8235. 2.4 kernel.  If you have a multi-cpu box, then you should seriously
  8236. consider using 2.4 as this will give you a significant speed boost.
  8237.  
  8238. The binary release is linked with `-static', which means you do not
  8239. normally need to worry about which version of the system libraries you
  8240. have. You need not install LinuxThreads, either.  A program linked with
  8241. `-static' is slightly bigger than a dynamically linked program but also
  8242. slightly faster (3-5%).  One problem, however, is that you can't use
  8243. user-definable functions (UDFs) with a statically linked program.  If
  8244. you are going to write or use UDF functions (this is something only for
  8245. C or C++ programmers), you must compile MySQL yourself, using dynamic
  8246. linking.
  8247.  
  8248. If you are using a `libc'-based system (instead of a `glibc2' system),
  8249. you will probably get some problems with hostname resolving and
  8250. `getpwnam()' with the binary release. (This is because `glibc'
  8251. unfortunately depends on some external libraries to resolve hostnames
  8252. and `getpwent()', even when compiled with `-static'). In this case you
  8253. probably get the following error message when you run
  8254. `mysql_install_db':
  8255.  
  8256.      Sorry, the host 'xxxx' could not be looked up
  8257.  
  8258. or the following error when you try to run `mysqld' with the `--user'
  8259. option:
  8260.  
  8261.      getpwnam: No such file or directory
  8262.  
  8263. You can solve this problem in one of the following ways:
  8264.  
  8265.    * Get a MySQL source distribution (an RPM or the `tar.gz'
  8266.      distribution) and install this instead.
  8267.  
  8268.    * Execute `mysql_install_db --force'; this will not execute the
  8269.      `resolveip' test in `mysql_install_db'.  The downside is that you
  8270.      can't use host names in the grant tables; you must use IP numbers
  8271.      instead (except for `localhost').  If you are using an old MySQL
  8272.      release that doesn't support `--force', you have to remove the
  8273.      `resolveip' test in `mysql_install' with an editor.
  8274.  
  8275.    * Start `mysqld' with `su' instead of using `--user'.
  8276.  
  8277. The Linux-Intel binary and RPM releases of MySQL are configured for the
  8278. highest possible speed.  We are always trying to use the fastest stable
  8279. compiler available.
  8280.  
  8281. MySQL Perl support requires Version Perl 5.004_03 or newer.
  8282.  
  8283. On some Linux 2.2 versions, you may get the error `Resource temporarily
  8284. unavailable' when you do a lot of new connections to a `mysqld' server
  8285. over TCP/IP.
  8286.  
  8287. The problem is that Linux has a delay between when you close a TCP/IP
  8288. socket and until this is actually freed by the system.  As there is only
  8289. room for a finite number of TCP/IP slots, you will get the above error
  8290. if you try to do too many new TCP/IP connections during a small time,
  8291. like when you run the MySQL `test-connect' benchmark over TCP/IP.
  8292.  
  8293. We have mailed about this problem a couple of times to different Linux
  8294. mailing lists but have never been able to resolve this properly.
  8295.  
  8296. The only known 'fix' to this problem is to use persistent connections in
  8297. your clients or use sockets, if you are running the database server and
  8298. clients on the same machine.  We hope that the `Linux 2.4' kernel will
  8299. fix this problem in the future.
  8300.  
  8301. Linux x86 Notes
  8302. ...............
  8303.  
  8304. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  8305. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  8306. have been some problems with the `glibc' RPMs from RedHat, so if you
  8307. have problems, check whether there are any updates!  The `glibc'
  8308. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  8309.  
  8310. If you are using Redhat 8.0 or a new glibc 2.2.x libray you should start
  8311. mysqld with the option `--thread-stack=192K'.  If you don't do it
  8312. mysqld will die in `gethostbyaddr()' because the new glibc library
  8313. requires > 128K memory on stack for this call.  This stack size is
  8314. default on MySQL 4.0.10 and above.
  8315.  
  8316. If you are using gcc 3.0 and above to compile MySQL, you must install
  8317. the `libstdc++v3' library before compiling MySQL; if you don't do this
  8318. you will get an error about a missing `__cxa_pure_virtual' symbol
  8319. during linking!
  8320.  
  8321. On some older Linux distributions, `configure' may produce an error
  8322. like this:
  8323.  
  8324.      Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file.
  8325.      See the Installation chapter in the Reference Manual.
  8326.  
  8327. Just do what the error message says and add an extra underscore to the
  8328. `_P' macro that has only one underscore, then try again.
  8329.  
  8330. You may get some warnings when compiling; those shown here can be
  8331. ignored:
  8332.  
  8333.      mysqld.cc -o objs-thread/mysqld.o
  8334.      mysqld.cc: In function `void init_signals()':
  8335.      mysqld.cc:315: warning: assignment of negative value `-1' to
  8336.      `long unsigned int'
  8337.      mysqld.cc: In function `void * signal_hand(void *)':
  8338.      mysqld.cc:346: warning: assignment of negative value `-1' to
  8339.      `long unsigned int'
  8340.  
  8341. `mysql.server' can be found in the `share/mysql' directory under the
  8342. MySQL installation directory or in the `support-files' directory of the
  8343. MySQL source tree.
  8344.  
  8345. If `mysqld' always core dumps when it starts up, the problem may be that
  8346. you have an old `/lib/libc.a'.  Try renaming it, then remove
  8347. `sql/mysqld' and do a new `make install' and try again.  This problem
  8348. has been reported on some Slackware installations.
  8349.  
  8350. If you get the following error when linking `mysqld', it means that
  8351. your `libg++.a' is not installed correctly:
  8352.  
  8353.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  8354.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  8355.  
  8356. You can avoid using `libg++.a' by running `configure' like this:
  8357.  
  8358.      shell> CXX=gcc ./configure
  8359.  
  8360. Linux SPARC Notes
  8361. .................
  8362.  
  8363. In some implementations, `readdir_r()' is broken.  The symptom is that
  8364. `SHOW DATABASES' always returns an empty set.  This can be fixed by
  8365. removing `HAVE_READDIR_R' from `config.h' after configuring and before
  8366. compiling.
  8367.  
  8368. Some problems will require patching your Linux installation.  The patch
  8369. can be found at
  8370. `http://www.mysql.com/Downloads/patches/Linux-sparc-2.0.30.diff'.  This
  8371. patch is against the Linux distribution `sparclinux-2.0.30.tar.gz' that
  8372. is available at `vger.rutgers.edu' (a version of Linux that was never
  8373. merged with the official 2.0.30).  You must also install LinuxThreads
  8374. Version 0.6 or newer.
  8375.  
  8376. Linux Alpha Notes
  8377. .................
  8378.  
  8379. MySQL Version 3.23.12 is the first MySQL version that is tested on
  8380. Linux-Alpha.  If you plan to use MySQL on Linux-Alpha, you should
  8381. ensure that you have this version or newer.
  8382.  
  8383. We have tested MySQL on Alpha with our benchmarks and test suite, and
  8384. it appears to work nicely.
  8385.  
  8386. We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP,
  8387. kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler
  8388. (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.
  8389.  
  8390. You can find the above compilers at
  8391. `http://www.support.compaq.com/alpha-tools/').  By using these
  8392. compilers, instead of gcc, we get about 9-14% better performance with
  8393. MySQL.
  8394.  
  8395. Note that until MySQL version 3.23.52 and 4.0.2 we optimised the binary
  8396. for the current CPU only (by using the `-fast' compile option); this
  8397. meant that you could only use our binaries if you had an Alpha EV6
  8398. processor.
  8399.  
  8400. Starting with all following releases we added the `-arch generic' flag
  8401. to our compile options, which makes sure the binary runs on all Alpha
  8402. processors. We also compile statically to avoid library problems.
  8403.  
  8404.      CC=ccc CFLAGS="-fast -arch generic" CXX=cxx \
  8405.      CXXFLAGS="-fast -arch generic -noexceptions -nortti" \
  8406.      ./configure --prefix=/usr/local/mysql --disable-shared \
  8407.      --with-extra-charsets=complex --enable-thread-safe-client \
  8408.      --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  8409.  
  8410. If you want to use egcs the following configure line worked for us:
  8411.  
  8412.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
  8413.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  8414.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  8415.      --disable-shared
  8416.  
  8417. Some known problems when running MySQL on Linux-Alpha:
  8418.  
  8419.    * Debugging threaded applications like MySQL will not work with `gdb
  8420.      4.18'.  You should download and use gdb 5.1 instead!
  8421.  
  8422.    * If you try linking `mysqld' statically when using `gcc', the
  8423.      resulting image will core dump at start.  In other words, *don't*
  8424.      use `--with-mysqld-ldflags=-all-static' with `gcc'.
  8425.  
  8426. Linux PowerPC Notes
  8427. ...................
  8428.  
  8429. MySQL should work on MkLinux with the newest `glibc' package (tested
  8430. with `glibc' 2.0.7).
  8431.  
  8432. Linux MIPS Notes
  8433. ................
  8434.  
  8435. To get MySQL to work on Qube2, (Linux Mips), you need the newest
  8436. `glibc' libraries (`glibc-2.0.7-29C2' is known to work).  You must also
  8437. use the `egcs' C++ compiler (`egcs-1.0.2-9', `gcc 2.95.2' or newer).
  8438.  
  8439. Linux IA64 Notes
  8440. ................
  8441.  
  8442. To get MySQL to compile on Linux IA64, we use the following compile
  8443. line: Using `gcc-2.96':
  8444.  
  8445.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  8446.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  8447.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  8448.      "--with-comment=Official MySQL binary" --with-extra-charsets=complex
  8449.  
  8450. On IA64 the MySQL client binaries are using shared libraries. This means
  8451. that if you install our binary distribution in some other place than
  8452. `/usr/local/mysql' you need to either modify `/etc/ld.so.conf' or add
  8453. the path to the directory where you have `libmysqlclient.so' to the
  8454. `LD_LIBRARY_PATH' environment variable.
  8455.  
  8456. *Note Link errors::.
  8457.  
  8458. Windows Notes
  8459. -------------
  8460.  
  8461. This section describes using MySQL on Windows. This information is also
  8462. provided in the `README' file that comes with the MySQL Windows
  8463. distribution. *Note Windows installation::.
  8464.  
  8465. Starting MySQL on Windows 95, 98 or Me
  8466. ......................................
  8467.  
  8468. MySQL uses TCP/IP to connect a client to a server. (This will allow any
  8469. machine on your network to connect to your MySQL server.)  Because of
  8470. this, you must install TCP/IP on your machine before starting MySQL.
  8471. You can find TCP/IP on your Windows CD-ROM.
  8472.  
  8473. Note that if you are using an old Windows 95 release (for example
  8474. OSR2), it's likely that you have an old Winsock package; MySQL requires
  8475. Winsock 2! You can get the newest Winsock from
  8476. `http://www.microsoft.com/'.  Windows 98 has the new Winsock 2 library,
  8477. so the above doesn't apply there.
  8478.  
  8479. To start the `mysqld' server, you should start an MS-DOS window and
  8480. type:
  8481.  
  8482.      C:\> C:\mysql\bin\mysqld
  8483.  
  8484. This will start `mysqld' in the background without a window.
  8485.  
  8486. You can kill the MySQL server by executing:
  8487.  
  8488.      C:\> C:\mysql\bin\mysqladmin -u root shutdown
  8489.  
  8490. This calls the MySQL administation utility as user `root', which is the
  8491. default Administrator in the MySQL grant system. Please note that the
  8492. MySQL grant system is wholly independent from any login users under
  8493. Windows.
  8494.  
  8495. Note that Windows 95/98/Me don't support creation of named pipes.  So
  8496. on those platforms, you can only use named pipes to connect to a remote
  8497. MySQL server running on a Windows NT/2000/XP server host.  (The MySQL
  8498. server must also support named pipes, of course.  For example, using
  8499. `mysqld-opt' under NT/2000/XP will not allow named pipe connections.
  8500. You should use either `mysqld-nt' or `mysqld-max-nt'.)
  8501.  
  8502. If `mysqld' doesn't start, please check the `\mysql\data\mysql.err'
  8503. file to see if the server wrote any message there to indicate the cause
  8504. of the problem.  You can also try to start the server with `mysqld
  8505. --standalone'; in this case, you may get some useful information on the
  8506. screen that may help solve the problem.
  8507.  
  8508. The last option is to start `mysqld' with `--standalone --debug'.  In
  8509. this case `mysqld' will write a log file `C:\mysqld.trace' that should
  8510. contain the reason why `mysqld' doesn't start. *Note Making trace
  8511. files::.
  8512.  
  8513. Use `mysqld --help' to display all the options that `mysqld'
  8514. understands!
  8515.  
  8516. Starting MySQL on Windows NT, 2000 or XP
  8517. ........................................
  8518.  
  8519. To get MySQL to work with TCP/IP on Windows NT 4, you must install
  8520. service pack 3 (or newer)!
  8521.  
  8522. Normally you should install MySQL as a service on Windows NT/2000/XP.
  8523. In case the server was already running, first stop it using the
  8524. following command:
  8525.  
  8526.      C:\mysql\bin> mysqladmin -u root shutdown
  8527.  
  8528. This calls the MySQL administation utility as user ``root'', which is
  8529. the default `Administrator' in the MySQL grant system.  Please note
  8530. that the MySQL grant system is wholly independent from any login users
  8531. under Windows.
  8532.  
  8533. Now install the server service:
  8534.  
  8535.      C:\mysql\bin> mysqld-max-nt --install
  8536.  
  8537. If any options are required, they must be specified as "`Start
  8538. parameters'" in the Windows `Services' utility before you start the
  8539. MySQL service.
  8540.  
  8541. The `Services' utility (`Windows Service Control Manager') can be found
  8542. in the `Windows Control Panel' (under `Administrative Tools' on Windows
  8543. 2000). It is advisable to close the Services utility while performing
  8544. the `--install' or `--remove' operations, this prevents some odd errors.
  8545.  
  8546. For information about which server binary to run, see *Note Windows
  8547. prepare environment::.
  8548.  
  8549. Please note that from MySQL version 3.23.44, you have the choice of set
  8550. up the service as `Manual' instead (if you don't wish the service to be
  8551. started automatically during the boot process):
  8552.  
  8553.      C:\mysql\bin> mysqld-max-nt --install-manual
  8554.  
  8555. The service is installed with the name `MySQL'. Once installed, it can
  8556. be immediately started from the `Services' utility, or by using the
  8557. command `NET START MySQL'.
  8558.  
  8559. Once running, `mysqld-max-nt' can be stopped using `mysqladmin', from
  8560. the Services utility, or by using the command `NET STOP MySQL'.
  8561.  
  8562. When running as a service, the operating system will automatically stop
  8563. the MySQL service on computer shutdown. In MySQL versions < 3.23.47,
  8564. Windows only waited for a few seconds for the shutdown to complete, and
  8565. killed the database server process if the time limit was exceeded
  8566. (potentially causing problems). For instance, at the next startup the
  8567. `InnoDB' storage engine had to do crash recovery. Starting from MySQL
  8568. version 3.23.48, the Windows will wait longer for the MySQL server
  8569. shutdown to complete. If you notice this is not enough for your
  8570. intallation, it is safest to run the MySQL server not as a service, but
  8571. from the Command prompt, and shut it down with `mysqladmin shutdown'.
  8572.  
  8573. There is a problem that Windows NT (but not Windows 2000/XP) by default
  8574. only waits 20 seconds for a service to shut down, and after that kills
  8575. the service process. You can increase this default by opening the
  8576. Registry Editor `\winnt\system32\regedt32.exe' and editing the value of
  8577. `WaitToKillServiceTimeout' at
  8578. `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' in the Registry
  8579. tree. Specify the new larger value in milliseconds, for example 120000
  8580. to have Windows NT wait upto 120 seconds.
  8581.  
  8582. Please note that when run as a service, `mysqld-max-nt' has no access
  8583. to a console and so no messages can be seen.  Errors can be checked in
  8584. `c:\mysql\data\mysql.err'.
  8585.  
  8586. If you have problems installing `mysqld-max-nt' as a service, try
  8587. starting it with the full path:
  8588.  
  8589.      C:\> C:\mysql\bin\mysqld-max-nt --install
  8590.  
  8591. If this doesn't work, you can get `mysqld-max-nt' to start properly by
  8592. fixing the path in the registry!
  8593.  
  8594. If you don't want to start `mysqld-max-nt' as a service, you can start
  8595. it as follows:
  8596.  
  8597.      C:\> C:\mysql\bin\mysqld-max-nt --standalone
  8598.  
  8599. or
  8600.  
  8601.      C:\> C:\mysql\bin\mysqld --standalone --debug
  8602.  
  8603. The last method gives you a debug trace in `C:\mysqld.trace'. *Note
  8604. Making trace files::.
  8605.  
  8606. Running MySQL on Windows
  8607. ........................
  8608.  
  8609. MySQL supports TCP/IP on all Windows platforms and named pipes on
  8610. NT/2000/XP. The default is to use named pipes for local connections on
  8611. NT/2000/XP and TCP/IP for all other cases if the client has TCP/IP
  8612. installed. The host name specifies which protocol is used:
  8613.  
  8614. *Host       *Protocol*
  8615. name*       
  8616. NULL         On NT/2000/XP, try named pipes first; if
  8617. (none)      that doesn't work, use TCP/IP.  On 9x/Me,
  8618.             TCP/IP is used.
  8619. .           Named pipes
  8620. localhost    TCP/IP to current host
  8621. hostname     TCP/IP
  8622.  
  8623. You can force a MySQL client to use named pipes by specifying the
  8624. `--pipe' option or by specifying `.' as the host name.  Use the
  8625. `--socket' option to specify the name of the pipe.
  8626.  
  8627. Note that starting from 3.23.50, named pipes are only enabled if mysqld
  8628. is started with `--enable-named-pipe'.  This is because some users have
  8629. experienced problems shutting down the MySQL server when one uses named
  8630. pipes.
  8631.  
  8632. You can test whether MySQL is working by executing the following
  8633. commands:
  8634.  
  8635.      C:\> C:\mysql\bin\mysqlshow
  8636.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  8637.      C:\> C:\mysql\bin\mysqladmin version status proc
  8638.      C:\> C:\mysql\bin\mysql test
  8639.  
  8640. If `mysqld' is slow to answer to connections on Windows 9x/Me, there is
  8641. probably a problem with your DNS.  In this case, start `mysqld' with
  8642. `--skip-name-resolve' and use only `localhost' and IP numbers in the
  8643. MySQL grant tables.  You can also avoid DNS when connecting to a
  8644. `mysqld-nt' MySQL server running on NT/2000/XP by using the `--pipe'
  8645. argument to specify use of named pipes.  This works for most MySQL
  8646. clients.
  8647.  
  8648. There are two versions of the MySQL command-line tool:
  8649. *Binary**Description*
  8650. `mysql' Compiled on native Windows, which offers
  8651.         very limited text editing capabilities.
  8652. `mysqlc'Compiled with the Cygnus GNU compiler and
  8653.         libraries, which offers `readline' editing.
  8654.  
  8655. If you want to use `mysqlc.exe', you must copy
  8656. `C:\mysql\lib\cygwinb19.dll' to your Windows system directory
  8657. (`\windows\system' or similar place).
  8658.  
  8659. The default privileges on Windows give all local users full privileges
  8660. to all databases without specifying a password.  To make MySQL more
  8661. secure, you should set a password for all users and remove the row in
  8662. the `mysql.user' table that has `Host='localhost'' and `User='''.
  8663.  
  8664. You should also add a password for the `root' user. The following
  8665. example starts by removing the anonymous user that has all privileges,
  8666. then sets a `root' user password:
  8667.  
  8668.      C:\> C:\mysql\bin\mysql mysql
  8669.      mysql> DELETE FROM user WHERE Host='localhost' AND User='';
  8670.      mysql> QUIT
  8671.      C:\> C:\mysql\bin\mysqladmin reload
  8672.      C:\> C:\mysql\bin\mysqladmin -u root password your_password
  8673.  
  8674. After you've set the password, if you want to take down the `mysqld'
  8675. server, you can do so using this command:
  8676.  
  8677.      C:\> mysqladmin --user=root --password=your_password shutdown
  8678.  
  8679. If you are using the old shareware version of MySQL Version 3.21 under
  8680. Windows, the above command will fail with an error: `parse error near
  8681. 'SET password''.  The solution for this is to download and upgrade to
  8682. the latest MySQL version, which is now freely available.
  8683.  
  8684. With the current MySQL versions you can easily add new users and change
  8685. privileges with `GRANT' and `REVOKE' commands.  *Note GRANT::.
  8686.  
  8687. Connecting to a Remote MySQL from Windows with SSH
  8688. ..................................................
  8689.  
  8690. Here is a note about how to connect to get a secure connection to remote
  8691. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  8692.  
  8693.    * Install an SSH client on your Windows machine.  As a user, the
  8694.      best non-free one I've found is from `SecureCRT' from
  8695.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  8696.      `http://www.f-secure.com/'. You can also find some free ones on
  8697.      `Google' at
  8698.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  8699.  
  8700.    * Start your Windows SSH client.  Set `Host_Name =
  8701.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  8702.      your server (probably not the same as your MySQL login/password.
  8703.  
  8704.    * Set up port forwarding. Either do a remote forward (Set
  8705.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  8706.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  8707.      `host: localhost', `remote port: 3306').
  8708.  
  8709.    * Save everything, otherwise you'll have to redo it the next time.
  8710.  
  8711.    * Log in to your server with SSH session you just created.
  8712.  
  8713.    * On your Windows machine, start some ODBC application (such as
  8714.      Access).
  8715.  
  8716.    * Create a new file in Windows and link to MySQL using the ODBC
  8717.      driver the same way you normally do, except type in `localhost'
  8718.      for the MySQL host servernot `yourmysqlservername'.
  8719.  
  8720. You should now have an ODBC connection to MySQL, encrypted using SSH.
  8721.  
  8722. Splitting Data Across Different Disks on Windows
  8723. ................................................
  8724.  
  8725. Beginning with MySQL Version 3.23.16, the `mysqld-max' and
  8726. `mysql-max-nt' servers in the MySQL distribution are compiled with the
  8727. `-DUSE_SYMDIR' option.  This allows you to put a database on different
  8728. disk by adding a symbolic link to it (in a manner similar to the way
  8729. that symbolic links work on Unix).
  8730.  
  8731. On Windows, you make a symbolic link to a database by creating a file
  8732. that contains the path to the destination directory and saving this in
  8733. the `mysql_data' directory under the filename `database.sym'.  Note
  8734. that the symbolic link will be used only if the directory
  8735. `mysql_data_dir\database' doesn't exist.
  8736.  
  8737. For example, if the MySQL data directory is `C:\mysql\data' and you
  8738. want to have database `foo' located at `D:\data\foo', you should create
  8739. the file `C:\mysql\data\foo.sym' that contains the text `D:\data\foo\'.
  8740. After that, all tables created in the database `foo' will be created
  8741. in `D:\data\foo'.
  8742.  
  8743. Note that because of the speed penalty you get when opening every table,
  8744. we have not enabled this by default even if you have compiled MySQL
  8745. with support for this. To enable symlinks you should put in your
  8746. `my.cnf' or `my.ini' file the following entry:
  8747.  
  8748.      [mysqld]
  8749.      use-symbolic-links
  8750.  
  8751. In MySQL 4.0 we will enable symlinks by default. Then you should
  8752. instead use the `skip-symlink' option if you want to disable this.
  8753.  
  8754. Compiling MySQL Clients on Windows
  8755. ..................................
  8756.  
  8757. In your source files, you should include `windows.h' before you include
  8758. `mysql.h':
  8759.  
  8760.      #if defined(_WIN32) || defined(_WIN64)
  8761.      #include <windows.h>
  8762.      #endif
  8763.      #include <mysql.h>
  8764.  
  8765. You can either link your code with the dynamic `libmysql.lib' library,
  8766. which is just a wrapper to load in `libmysql.dll' on demand, or link
  8767. with the static `mysqlclient.lib' library.
  8768.  
  8769. Note that as the mysqlclient libraries are compiled as threaded
  8770. libraries, you should also compile your code to be multi-threaded!
  8771.  
  8772. MySQL-Windows Compared to Unix MySQL
  8773. ....................................
  8774.  
  8775. MySQL-Windows has by now proven itself to be very stable. This version
  8776. of MySQL has the same features as the corresponding Unix version with
  8777. the following exceptions:
  8778.  
  8779. *Windows 95 and threads*
  8780.      Windows 95 leaks about 200 bytes of main memory for each thread
  8781.      creation.  Each connection in MySQL creates a new thread, so you
  8782.      shouldn't run `mysqld' for an extended time on Windows 95 if your
  8783.      server handles many connections!  Other versions of Windows don't
  8784.      suffer from this bug.
  8785.  
  8786. *Concurrent reads*
  8787.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  8788.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  8789.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  8790.      level interface with a virtual interface so that we can use the
  8791.      `readfile()'/`writefile()' interface on NT/2000/XP to get more
  8792.      speed.  The current implementation limits the number of open files
  8793.      MySQL can use to 1024, which means that you will not be able to
  8794.      run as many concurrent threads on NT/2000/XP as on Unix.
  8795.  
  8796. *Blocking read*
  8797.      MySQL uses a blocking read for each connection.  This means that:
  8798.  
  8799.         * A connection will not be disconnected automatically after 8
  8800.           hours, as happens with the Unix version of MySQL.
  8801.  
  8802.         * If a connection hangs, it's impossible to break it without
  8803.           killing MySQL.
  8804.  
  8805.         * `mysqladmin kill' will not work on a sleeping connection.
  8806.  
  8807.         * `mysqladmin shutdown' can't abort as long as there are
  8808.           sleeping connections.
  8809.  
  8810.      We plan to fix this problem when our Windows developers have
  8811.      figured out a nice workaround.
  8812.  
  8813. *`DROP DATABASE'*
  8814.      You can't drop a database that is in use by some thread.
  8815.  
  8816. *Killing MySQL from the task manager*
  8817.      You can't kill MySQL from the task manager or with the shutdown
  8818.      utility in Windows 95.  You must take it down with `mysqladmin
  8819.      shutdown'.
  8820.  
  8821. *Case-insensitive names*
  8822.      Filenames are case-insensitive on Windows, so database and table
  8823.      names are also case-insensitive in MySQL for Windows.  The only
  8824.      restriction is that database and table names must be specified
  8825.      using the same case throughout a given statement.  *Note Name case
  8826.      sensitivity::.
  8827.  
  8828. *The `\' directory character*
  8829.      Pathname components in Windows 95 are separated by the `\'
  8830.      character, which is also the escape character in MySQL.  If you
  8831.      are using `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', you
  8832.      must double the `\' character:
  8833.  
  8834.           mysql> LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
  8835.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  8836.  
  8837.      Alternatively, use Unix style filenames with `/' characters:
  8838.  
  8839.           mysql> LOAD DATA INFILE "C:/tmp/skr.txt" INTO TABLE skr;
  8840.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  8841.  
  8842. *`Can't open named pipe' error*
  8843.      If you use a MySQL 3.22 version on NT with the newest mysql-clients
  8844.      you will get the following error:
  8845.  
  8846.           error 2017: can't open named pipe to host: . pipe...
  8847.  
  8848.      This is because the release version of MySQL uses named pipes on NT
  8849.      by default.  You can avoid this error by using the
  8850.      `--host=localhost' option to the new MySQL clients or create an
  8851.      option file `C:\my.cnf' that contains the following information:
  8852.  
  8853.           [client]
  8854.           host = localhost
  8855.  
  8856.      Starting from 3.23.50, named pipes are only enabled if `mysqld' is
  8857.      started with `--enable-named-pipe'.
  8858.  
  8859. *`Access denied for user' error*
  8860.      If you get the error `Access denied for user: 'some-user@unknown'
  8861.      to database 'mysql'' when accessing a MySQL server on the same
  8862.      machine, this means that MySQL can't resolve your host name
  8863.      properly.
  8864.  
  8865.      To fix this, you should create a file `\windows\hosts' with the
  8866.      following information:
  8867.  
  8868.           127.0.0.1       localhost
  8869.  
  8870. *`ALTER TABLE'*
  8871.      While you are executing an `ALTER TABLE' statement, the table is
  8872.      locked from usage by other threads.  This has to do with the fact
  8873.      that on Windows, you can't delete a file that is in use by another
  8874.      threads.  (In the future, we may find some way to work around this
  8875.      problem.)
  8876.  
  8877. **
  8878.      `DROP TABLE' on a table that is in use by a `MERGE' table will not
  8879.      work on Windows because the `MERGE' handler does the table mapping
  8880.      hidden from the upper layer of MySQL.  Because Windows doesn't
  8881.      allow you to drop files that are open, you first must flush all
  8882.      `MERGE' tables (with `FLUSH TABLES') or drop the `MERGE' table
  8883.      before dropping the table.  We will fix this at the same time we
  8884.      introduce `VIEW's.
  8885.  
  8886. **
  8887.      `DATA DIRECTORY' and `INDEX DIRECTORY' directives in `CREATE
  8888.      TABLE' is ignored on Windows, because Windows doesn't support
  8889.      symbolic links.
  8890.  
  8891. Here are some open issues for anyone who might want to help us with the
  8892. Windows release:
  8893.  
  8894.    * Make a single-user `MYSQL.DLL' server.  This should include
  8895.      everything in a standard MySQL server, except thread creation.
  8896.      This will make MySQL much easier to use in applications that don't
  8897.      need a true client/server and don't need to access the server from
  8898.      other hosts.
  8899.  
  8900.    * Add some nice start and shutdown icons to the MySQL installation.
  8901.  
  8902.    * When registering `mysqld' as a service with `--install' (on NT) it
  8903.      would be nice if you could also add default options on the
  8904.      command-line.  For the moment, the workaround is to list the
  8905.      parameters in the `C:\my.cnf' file instead.
  8906.  
  8907.    * It would be really nice to be able to kill `mysqld' from the task
  8908.      manager.  For the moment, you must use `mysqladmin shutdown'.
  8909.  
  8910.    * Port `readline' to Windows for use in the `mysql' command-line
  8911.      tool.
  8912.  
  8913.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  8914.      `mysqladmin', and `mysqldump') would be nice.
  8915.  
  8916.    * It would be nice if the socket read and write functions in `net.c'
  8917.      were interruptible. This would make it possible to kill open
  8918.      threads with `mysqladmin kill' on Windows.
  8919.  
  8920.    * `mysqld' always starts in the "C" locale and not in the default
  8921.      locale.  We would like to have `mysqld' use the current locale for
  8922.      the sort order.
  8923.  
  8924.    * Add macros to use the faster thread-safe increment/decrement
  8925.      methods provided by Windows.
  8926.  
  8927. Other Windows-specific issues are described in the `README' file that
  8928. comes with the MySQL-Windows distribution.
  8929.  
  8930. Solaris Notes
  8931. -------------
  8932.  
  8933. On Solaris, you may run into trouble even before you get the MySQL
  8934. distribution unpacked!  Solaris `tar' can't handle long file names, so
  8935. you may see an error like this when you unpack MySQL:
  8936.  
  8937.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,\
  8938.      informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  8939.      tar: directory checksum error
  8940.  
  8941. In this case, you must use GNU `tar' (`gtar') to unpack the
  8942. distribution.  You can find a precompiled copy for Solaris at
  8943. `http://www.mysql.com/downloads/os-solaris.html'.
  8944.  
  8945. Sun native threads work only on Solaris 2.5 and higher.  For Version
  8946. 2.4 and earlier, MySQL will automatically use MIT-pthreads.  *Note
  8947. MIT-pthreads::.
  8948.  
  8949. If you get the following error from configure:
  8950.  
  8951.      checking for restartable system calls... configure: error can not run test
  8952.      programs while cross compiling
  8953.  
  8954. This means that you have something wrong with your compiler
  8955. installation!  In this case you should upgrade your compiler to a newer
  8956. version.  You may also be able to solve this problem by inserting the
  8957. following row into the `config.cache' file:
  8958.  
  8959.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  8960.  
  8961. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  8962. 2.95.2.  You can find this at `http://gcc.gnu.org/'.  Note that `egcs'
  8963. 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  8964.  
  8965. The recommended `configure' line when using `gcc' 2.95.2 is:
  8966.  
  8967.      CC=gcc CFLAGS="-O3" \
  8968.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  8969.      ./configure --prefix=/usr/local/mysql --with-low-memory --enable-assembler
  8970.  
  8971. If you have an UltraSPARC, you can get 4% more performance by adding
  8972. "-mcpu=v8 -Wa,-xarch=v8plusa" to CFLAGS and CXXFLAGS.
  8973.  
  8974. If you have Sun's Forte 5.0 (or newer) compiler, you can run
  8975. `configure' like this:
  8976.  
  8977.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt" \
  8978.      CXX=CC CXXFLAGS="-noex -mt" \
  8979.      ./configure --prefix=/usr/local/mysql --enable-assembler
  8980.  
  8981. You can create a 64 bit binary with:
  8982.  
  8983.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
  8984.      CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS="-xarch=v9" \
  8985.      ./configure --prefix=/usr/local/mysql --enable-assembler
  8986.  
  8987. In the MySQL benchmarks, we got a 4% speedup on an UltraSPARC when using
  8988. Forte 5.0 in 32 bit mode compared to using gcc 3.2 with -mcpu flags.
  8989.  
  8990. If you create a 64 bit binary, it's 4 % slower than the 32 bit binary,
  8991. but mysqld can instead handle more treads and memory.
  8992.  
  8993. If you get a problem with `fdatasync' or `sched_yield', you can fix
  8994. this by adding `LIBS=-lrt' to the configure line
  8995.  
  8996. The following paragraph is only relevant for older compilers than
  8997. WorkShop 5.3:
  8998.  
  8999. You may also have to edit the `configure' script to change this line:
  9000.  
  9001.      #if !defined(__STDC__) || __STDC__ != 1
  9002.  
  9003. to this:
  9004.  
  9005.      #if !defined(__STDC__)
  9006.  
  9007. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  9008. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  9009. (broken compiler or broken include file).
  9010.  
  9011. If `mysqld' issues the error message shown here when you run it, you
  9012. have tried to compile MySQL with the Sun compiler without enabling the
  9013. multi-thread option (`-mt'):
  9014.  
  9015.      libc internal error: _rmutex_unlock: rmutex not held
  9016.  
  9017. Add `-mt' to `CFLAGS' and `CXXFLAGS' and try again.
  9018.  
  9019. If you are using the SFW version of gcc (which comes with Solaris 8),
  9020. you must add `/opt/sfw/lib' to the environment variable
  9021. `LD_LIBRARY_PATH' before running configure.
  9022.  
  9023. If you are using the gcc available from `sunfreeware.com', you may have
  9024. many problems.  You should recompile gcc and GNU binutils on the
  9025. machine you will be running them from to avoid any problems.
  9026.  
  9027. If you get the following error when compiling MySQL with `gcc', it
  9028. means that your `gcc' is not configured for your version of Solaris:
  9029.  
  9030.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  9031.      ./thr_alarm.c: In function `signal_hand':
  9032.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  9033.  
  9034. The proper thing to do in this case is to get the newest version of
  9035. `gcc' and compile it with your current `gcc' compiler!  At least for
  9036. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  9037. include files that will break all programs that use threads (and
  9038. possibly other programs)!
  9039.  
  9040. Solaris doesn't provide static versions of all system libraries
  9041. (`libpthreads' and `libdl'), so you can't compile MySQL with
  9042. `--static'.  If you try to do so, you will get the error:
  9043.  
  9044.      ld: fatal: library -ldl: not found
  9045.      
  9046.      or
  9047.      
  9048.      undefined reference to `dlopen'
  9049.      
  9050.      or
  9051.      
  9052.      cannot find -lrt
  9053.  
  9054. If too many processes try to connect very rapidly to `mysqld', you will
  9055. see this error in the MySQL log:
  9056.  
  9057.      Error in accept: Protocol error
  9058.  
  9059. You might try starting the server with the `--set-variable back_log=50'
  9060. option as a workaround for this. Please note that `--set-variable' is
  9061. deprecated since MySQL 4.0, just use `--back_log=50' on its own.  *Note
  9062. Command-line options::.
  9063.  
  9064. If you are linking your own MySQL client, you might get the following
  9065. error when you try to execute it:
  9066.  
  9067.      ld.so.1: ./my: fatal: libmysqlclient.so.#:
  9068.      open failed: No such file or directory
  9069.  
  9070. The problem can be avoided by one of the following methods:
  9071.  
  9072.    * Link the client with the following flag (instead of `-Lpath'):
  9073.      `-Wl,r/full-path-to-libmysqlclient.so'.
  9074.  
  9075.    * Copy `libmysqclient.so' to `/usr/lib'.
  9076.  
  9077.    * Add the pathname of the directory where `libmysqlclient.so' is
  9078.      located to the `LD_RUN_PATH' environment variable before running
  9079.      your client.
  9080.  
  9081. If you have problems with configure trying to link with `-lz' and you
  9082. don't have `zlib' installed, you have two options:
  9083.  
  9084.    * If you want to be able to use the compressed communication
  9085.      protocol, you need to get and install zlib from ftp.gnu.org.
  9086.  
  9087.    * Configure with `--with-named-z-libs=no'.
  9088.  
  9089. If you are using gcc and have problems with loading `UDF' functions
  9090. into MySQL, try adding `-lgcc' to the link line for the `UDF' function.
  9091.  
  9092. If you would like MySQL to start automatically, you can copy
  9093. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  9094. link to it named `/etc/rc3.d/S99mysql.server'.
  9095.  
  9096. As Solaris doesn't support core files for `setuid()' applications, you
  9097. can't get a core file from `mysqld' if you are using the `--user'
  9098. option.
  9099.  
  9100. Solaris 2.7/2.8 Notes
  9101. .....................
  9102.  
  9103. You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  9104. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  9105.  
  9106. Note that MySQL Version 3.23.4 and above should be able to autodetect
  9107. new versions of Solaris and enable workarounds for the following
  9108. problems!
  9109.  
  9110. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  9111. following error when you use `gcc':
  9112.  
  9113.      /usr/include/widec.h:42: warning: `getwc' redefined
  9114.      /usr/include/wchar.h:326: warning: this is the location of the previous
  9115.      definition
  9116.  
  9117. If this occurs, you can do the following to fix the problem:
  9118.  
  9119. Copy `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include'
  9120. and change line 41 from:
  9121.  
  9122.      #if     !defined(lint) && !defined(__lint)
  9123.      
  9124.      to
  9125.      
  9126.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  9127.  
  9128. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  9129. way, after you make the fix, you should remove `config.cache' and run
  9130. `configure' again!
  9131.  
  9132. If you get errors like this when you run `make', it's because
  9133. `configure' didn't detect the `curses.h' file (probably because of the
  9134. error in `/usr/include/widec.h'):
  9135.  
  9136.      In file included from mysql.cc:50:
  9137.      /usr/include/term.h:1060: syntax error before `,'
  9138.      /usr/include/term.h:1081: syntax error before `;'
  9139.  
  9140. The solution to this is to do one of the following:
  9141.  
  9142.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  9143.      ./configure'.
  9144.  
  9145.    * Edit `/usr/include/widec.h' as indicted above and rerun configure.
  9146.  
  9147.    * Remove the `#define HAVE_TERM' line from `config.h' file and run
  9148.      `make' again.
  9149.  
  9150. If you get a problem that your linker can't find `-lz' when linking
  9151. your client program, the problem is probably that your `libz.so' file is
  9152. installed in `/usr/local/lib'.  You can fix this by one of the
  9153. following methods:
  9154.  
  9155.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  9156.  
  9157.    * Add a link to `libz.so' from `/lib'.
  9158.  
  9159.    * If you are using Solaris 8, you can install the optional zlib from
  9160.      your Solaris 8 CD distribution.
  9161.  
  9162.    * Configure MySQL with the `--with-named-z-libs=no' option.
  9163.  
  9164. Solaris x86 Notes
  9165. .................
  9166.  
  9167. On Solaris 2.8 on x86, `mysqld' will core dump if you run 'strip' in.
  9168.  
  9169. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  9170. problems with core dumps under load, you should use the following
  9171. `configure' command:
  9172.  
  9173.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  9174.      CXX=gcc \
  9175.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions \
  9176.      -fno-rtti -DHAVE_CURSES_H" \
  9177.      ./configure --prefix=/usr/local/mysql
  9178.  
  9179. This will avoid problems with the `libstdc++' library and with C++
  9180. exceptions.
  9181.  
  9182. If this doesn't help, you should compile a debug version and run it
  9183. with a trace file or under `gdb'.  *Note Using gdb on mysqld::.
  9184.  
  9185. BSD Notes
  9186. ---------
  9187.  
  9188. This section provides information for the various BSD flavours, as well
  9189. as specific versions within those.
  9190.  
  9191. FreeBSD Notes
  9192. .............
  9193.  
  9194. FreeBSD 3.x is recommended for running MySQL since the thread package
  9195. is much more integrated.
  9196.  
  9197. The easiest and therefore the preferred way to install is to use the
  9198. mysql-server and mysql-client ports available on
  9199. `http://www.freebsd.org/'.
  9200.  
  9201. Using these gives you:
  9202.    * A working MySQL with all optimisations known to work on your
  9203.      version of FreeBSD enabled.
  9204.  
  9205.    * Automatic configuration and build.
  9206.  
  9207.    * Startup scripts installed in /usr/local/etc/rc.d.
  9208.  
  9209.    * Ability to see which files that are installed with pkg_info -L.
  9210.      And to remove them all with pkg_delete if you no longer want MySQL
  9211.      on that machine.
  9212.  
  9213. It is recommended you use MIT-pthreads on FreeBSD 2.x and native
  9214. threads on Versions 3 and up. It is possible to run with  native
  9215. threads on some late 2.2.x versions but you may encounter problems
  9216. shutting down `mysqld'.
  9217.  
  9218. The MySQL `Makefile's require GNU make (`gmake') to work.  If you want
  9219. to compile MySQL you need to install GNU `make' first.
  9220.  
  9221. Be sure to have your name resolver setup correct.  Otherwise, you may
  9222. experience resolver delays or failures when connecting to `mysqld'.
  9223.  
  9224. Make sure that the `localhost' entry in the `/etc/hosts' file is
  9225. correct (otherwise, you will have problems connecting to the database).
  9226. The `/etc/hosts' file should start with a line:
  9227.  
  9228.      127.0.0.1       localhost localhost.your.domain
  9229.  
  9230. The recommended way to compile and install MySQL on FreeBSD with gcc
  9231. (2.95.2 and up) is:
  9232.  
  9233.      CC=gcc CFLAGS="-O2 -fno-strength-reduce" \
  9234.      CXX=gcc CXXFLAGS="-O2 -fno-rtti -fno-exceptions -felide-constructors \
  9235.      -fno-strength-reduce" \
  9236.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9237.      gmake
  9238.      gmake install
  9239.      ./scripts/mysql_install_db
  9240.      cd /usr/local/mysql
  9241.      ./bin/mysqld_safe &
  9242.  
  9243. If you notice that `configure' will use MIT-pthreads, you should read
  9244. the MIT-pthreads notes.  *Note MIT-pthreads::.
  9245.  
  9246. If you get an error from `make install' that it can't find
  9247. `/usr/include/pthreads', `configure' didn't detect that you need
  9248. MIT-pthreads.  This is fixed by executing these commands:
  9249.  
  9250.      shell> rm config.cache
  9251.      shell> ./configure --with-mit-threads
  9252.  
  9253. FreeBSD is also known to have a very low default file handle limit.
  9254. *Note Not enough file handles::.  Uncomment the ulimit -n section in
  9255. safe_mysqld or raise the limits for the `mysqld' user in /etc/login.conf
  9256. (and rebuild it with cap_mkdb /etc/login.conf).  Also be sure you set
  9257. the appropriate class for this user in the password file if you are not
  9258. using the default (use: chpass mysqld-user-name).  *Note `safe_mysqld':
  9259. safe_mysqld.
  9260.  
  9261. If you have a lot of memory you should consider rebuilding the kernel
  9262. to allow MySQL to take more than 512M of RAM.  Take a look at `option
  9263. MAXDSIZ' in the LINT config file for more info.
  9264.  
  9265. If you get problems with the current date in MySQL, setting the `TZ'
  9266. variable will probably help.  *Note Environment variables::.
  9267.  
  9268. To get a secure and stable system you should only use FreeBSD kernels
  9269. that are marked `-RELEASE'.
  9270.  
  9271. NetBSD notes
  9272. ............
  9273.  
  9274. To compile on NetBSD you need GNU `make'. Otherwise, the compile will
  9275. crash when `make' tries to run `lint' on C++ files.
  9276.  
  9277. OpenBSD 2.5 Notes
  9278. .................
  9279.  
  9280. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  9281. the following options:
  9282.  
  9283.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  9284.  
  9285. OpenBSD 2.8 Notes
  9286. .................
  9287.  
  9288. Our users have reported that OpenBSD 2.8 has a threading bug which
  9289. causes problems with MySQL.  The OpenBSD Developers have fixed the
  9290. problem, but as of January 25th, 2001, it's only available in the
  9291. "-current" branch.  The symptoms of this threading bug are: slow
  9292. response, high load, high CPU usage, and crashes.
  9293.  
  9294. If you get an error like `Error in accept:: Bad file descriptor' or
  9295. error 9 when trying to open tables or directories, the problem is
  9296. probably that you haven't allocated enough file descriptors for MySQL.
  9297.  
  9298. In this case try starting `safe_mysqld' as root with the following
  9299. options:
  9300.  
  9301. `--user=mysql --open-files-limit=2048'
  9302.  
  9303. BSD/OS Version 2.x Notes
  9304. ........................
  9305.  
  9306. If you get the following error when compiling MySQL, your `ulimit'
  9307. value for virtual memory is too low:
  9308.  
  9309.      item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  9310.      item_func.h:28: virtual memory exhausted
  9311.      make[2]: *** [item_func.o] Error 1
  9312.  
  9313. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  9314. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  9315. users have reported problems with `bash' and `ulimit'.
  9316.  
  9317. If you are using `gcc', you may also use have to use the
  9318. `--with-low-memory' flag for `configure' to be able to compile
  9319. `sql_yacc.cc'.
  9320.  
  9321. If you get problems with the current date in MySQL, setting the `TZ'
  9322. variable will probably help.  *Note Environment variables::.
  9323.  
  9324. BSD/OS Version 3.x Notes
  9325. ........................
  9326.  
  9327. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  9328. BSDIpatch M300-038.
  9329.  
  9330. Use the following command when configuring MySQL:
  9331.  
  9332.      shell> env CXX=shlicc++ CC=shlicc2 \
  9333.             ./configure \
  9334.                 --prefix=/usr/local/mysql \
  9335.                 --localstatedir=/var/mysql \
  9336.                 --without-perl \
  9337.                 --with-unix-socket-path=/var/mysql/mysql.sock
  9338.  
  9339. The following is also known to work:
  9340.  
  9341.      shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  9342.             ./configure \
  9343.                 --prefix=/usr/local/mysql \
  9344.                 --with-unix-socket-path=/var/mysql/mysql.sock
  9345.  
  9346. You can change the directory locations if you wish, or just use the
  9347. defaults by not specifying any locations.
  9348.  
  9349. If you have problems with performance under heavy load, try using the
  9350. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  9351. with the same priority; on BSDI Version 3.1, this gives better
  9352. performance (at least until BSDI fixes their thread scheduler).
  9353.  
  9354. If you get the error `virtual memory exhausted' while compiling, you
  9355. should try using `ulimit -v 80000' and run `make' again.  If this
  9356. doesn't work and you are using `bash', try switching to `csh' or `sh';
  9357. some BSDI users have reported problems with `bash' and `ulimit'.
  9358.  
  9359. BSD/OS Version 4.x Notes
  9360. ........................
  9361.  
  9362. BSDI Version 4.x has some thread-related bugs.  If you want to use
  9363. MySQL on this, you should install all thread-related patches.  At least
  9364. M400-023 should be installed.
  9365.  
  9366. On some BSDI Version 4.x systems, you may get problems with shared
  9367. libraries.  The symptom is that you can't execute any client programs,
  9368. for example, `mysqladmin'.  In this case you need to reconfigure not to
  9369. use shared libraries with the `--disable-shared' option to configure.
  9370.  
  9371. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  9372. after a while can't open tables.  This is because some library/system
  9373. related bug causes `mysqld' to change current directory without asking
  9374. for this!
  9375.  
  9376. The fix is to either upgrade to 3.23.34 or after running `configure'
  9377. remove the line `#define HAVE_REALPATH' from `config.h' before running
  9378. make.
  9379.  
  9380. Note that the above means that you can't symbolic link a database
  9381. directories to another database directory or symbolic link a table to
  9382. another database on BSDI!  (Making a symbolic link to another disk is
  9383. okay).
  9384.  
  9385. Mac OS X Notes
  9386. --------------
  9387.  
  9388. Mac OS X Public Beta
  9389. ....................
  9390.  
  9391. MySQL should work without any problems on Mac OS X Public Beta
  9392. (Darwin).  You don't need the pthread patches for this OS!
  9393.  
  9394. Mac OS X Server
  9395. ...............
  9396.  
  9397. Before trying to configure MySQL on Mac OS X server you must first
  9398. install the pthread package from `http://www.prnet.de/RegEx/mysql.html'.
  9399.  
  9400. Our binary for Mac OS X is compiled on Rhapsody 5.5 with the following
  9401. configure line:
  9402.  
  9403.      CC=gcc CFLAGS="-O2 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O2 \
  9404.      -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql \
  9405.      "--with-comment=Official MySQL binary" --with-extra-charsets=complex \
  9406.      --disable-shared
  9407.  
  9408. You might want to also add aliases to your shell's resource file to
  9409. access `mysql' and `mysqladmin' from the command-line:
  9410.  
  9411.      alias mysql '/usr/local/mysql/bin/mysql'
  9412.      alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
  9413.  
  9414. Other Unix Notes
  9415. ----------------
  9416.  
  9417. HP-UX Notes for Binary Distributions
  9418. ....................................
  9419.  
  9420. Some of the binary distributions of MySQL for HP-UX is distributed as
  9421. an HP depot file and as a tar file.  To use the depot file you must be
  9422. running at least HP-UX 10.x to have access to HP's software depot tools.
  9423.  
  9424. The HP version of MySQL was compiled on an HP 9000/8xx server under
  9425. HP-UX 10.20, and uses MIT-pthreads.  It is known to work well under
  9426. this configuration.  MySQL Version 3.22.26 and newer can also be built
  9427. with HP's native thread package.
  9428.  
  9429. Other configurations that may work:
  9430.  
  9431.    * HP 9000/7xx running HP-UX 10.20+
  9432.  
  9433.    * HP 9000/8xx running HP-UX 10.30
  9434.  
  9435. The following configurations almost definitely won't work:
  9436.  
  9437.    * HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
  9438.  
  9439.    * HP 9000/7xx or 8xx running HP-UX 9.x
  9440.  
  9441. To install the distribution, use one of the commands here, where
  9442. `/path/to/depot' is the full pathname of the depot file:
  9443.  
  9444.    * To install everything, including the server, client and
  9445.      development tools:
  9446.  
  9447.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
  9448.  
  9449.    * To install only the server:
  9450.  
  9451.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
  9452.  
  9453.    * To install only the client package:
  9454.  
  9455.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
  9456.  
  9457.    * To install only the development tools:
  9458.  
  9459.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
  9460.  
  9461. The depot places binaries and libraries in `/opt/mysql' and data in
  9462. `/var/opt/mysql'. The depot also creates the appropriate entries in
  9463. `/etc/init.d' and `/etc/rc2.d' to start the server automatically at
  9464. boot time.  Obviously, this entails being `root' to install.
  9465.  
  9466. To install the HP-UX tar.gz distribution, you must have a copy of GNU
  9467. `tar'.
  9468.  
  9469. HP-UX Version 10.20 Notes
  9470. .........................
  9471.  
  9472. There are a couple of small problems when compiling MySQL on HP-UX.  We
  9473. recommend that you use `gcc' instead of the HP-UX native compiler,
  9474. because `gcc' produces better code!
  9475.  
  9476. We recommend using gcc 2.95 on HP-UX.  Don't use high optimisation
  9477. flags (like -O6) as this may not be safe on HP-UX.
  9478.  
  9479. The following configure line should work with gcc 2.95:
  9480.  
  9481.      CFLAGS="-I/opt/dce/include -fpic" \
  9482.      CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
  9483.      -fno-rtti" CXX=gcc ./configure --with-pthread \
  9484.      --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
  9485.  
  9486. The following configure line should work with gcc 3.1:
  9487.  
  9488.      CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc \
  9489.      CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions \
  9490.      -fno-rtti -O3 -fPIC" ./configure --prefix=/usr/local/mysql \
  9491.      --with-extra-charsets=complex --enable-thread-safe-client \
  9492.      --enable-local-infile  --with-pthread \
  9493.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  9494.      --disable-shared
  9495.  
  9496. HP-UX Version 11.x Notes
  9497. ........................
  9498.  
  9499. For HP-UX Version 11.x we recommend MySQL Version 3.23.15 or later.
  9500.  
  9501. Because of some critical bugs in the standard HP-UX libraries, you
  9502. should install the following patches before trying to run MySQL on
  9503. HP-UX 11.0:
  9504.  
  9505.      PHKL_22840 Streams cumulative
  9506.      PHNE_22397 ARPA cumulative
  9507.  
  9508. This will solve the problem of getting `EWOULDBLOCK' from `recv()' and
  9509. `EBADF' from `accept()' in threaded applications.
  9510.  
  9511. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  9512. will get the error:
  9513.  
  9514.      In file included from /usr/include/unistd.h:11,
  9515.                       from ../include/global.h:125,
  9516.                       from mysql_priv.h:15,
  9517.                       from item.cc:19:
  9518.      /usr/include/sys/unistd.h:184: declaration of C function ...
  9519.      /usr/include/sys/pthread.h:440: previous declaration ...
  9520.      In file included from item.h:306,
  9521.                       from mysql_priv.h:158,
  9522.                       from item.cc:19:
  9523.  
  9524. The problem is that HP-UX doesn't define `pthreads_atfork()'
  9525. consistently.  It has conflicting prototypes in
  9526. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440
  9527. (details below).
  9528.  
  9529. One solution is to copy `/usr/include/sys/unistd.h' into
  9530. `mysql/include' and edit `unistd.h' and change it to match the
  9531. definition in `pthread.h'.  Here's the diff:
  9532.  
  9533.      183,184c183,184
  9534.      <      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  9535.      <                                                void (*child)());
  9536.      ---
  9537.      >      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  9538.      >                                                void (*child)(void));
  9539.  
  9540. After this, the following configure line should work:
  9541.  
  9542.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc \
  9543.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" \
  9544.      ./configure --prefix=/usr/local/mysql --disable-shared
  9545.  
  9546. If you are using MySQL 4.0.5 with the HP-UX compiler you can use:
  9547. (tested with cc B.11.11.04):
  9548.  
  9549.      CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure --with-extra-character-set=complex
  9550.  
  9551. You can ignore any errors of the following type:
  9552.  
  9553.      aCC: warning 901: unknown option: `-3': use +help for online documentation
  9554.  
  9555. If you get the following error from `configure'
  9556.  
  9557.      checking for cc option to accept ANSI C... no
  9558.      configure: error: MySQL requires a ANSI C compiler (and a C++ compiler).
  9559.      Try gcc. See the Installation chapter in the Reference Manual.
  9560.  
  9561. Check that you don't have the path to the K&R compiler before the path
  9562. to the HP-UX C and C++ compiler.
  9563.  
  9564. Another reason for not beeing able to compile is that you didn't define
  9565. the `+DD64' flags above.
  9566.  
  9567. IBM-AIX notes
  9568. .............
  9569.  
  9570. Automatic detection of `xlC' is missing from Autoconf, so a `configure'
  9571. command something like this is needed when compiling MySQL (This
  9572. example uses the IBM compiler):
  9573.  
  9574.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  9575.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  9576.      export CFLAGS="-I /usr/local/include"
  9577.      export LDFLAGS="-L /usr/local/lib"
  9578.      export CPPFLAGS=$CFLAGS
  9579.      export CXXFLAGS=$CFLAGS
  9580.      
  9581.      ./configure --prefix=/usr/local \
  9582.              --localstatedir=/var/mysql \
  9583.              --sysconfdir=/etc/mysql \
  9584.              --sbindir='/usr/local/bin' \
  9585.              --libexecdir='/usr/local/bin' \
  9586.              --enable-thread-safe-client \
  9587.              --enable-large-files
  9588.  
  9589. Above are the options used to compile the MySQL distribution that can
  9590. be found at `http://www-frec.bull.com/'.
  9591.  
  9592. If you change the `-O3' to `-O2' in the above configure line, you must
  9593. also remove the `-qstrict' option (this is a limitation in the IBM C
  9594. compiler).
  9595.  
  9596. If you are using `gcc' or `egcs' to compile MySQL, you *must* use the
  9597. `-fno-exceptions' flag, as the exception handling in `gcc'/`egcs' is
  9598. not thread-safe!  (This is tested with `egcs' 1.1.)  There are also
  9599. some known problems with IBM's assembler, which may cause it to
  9600. generate bad code when used with gcc.
  9601.  
  9602. We recommend the following `configure' line with `egcs' and `gcc 2.95'
  9603. on AIX:
  9604.  
  9605.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  9606.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  9607.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  9608.      ./configure --prefix=/usr/local/mysql --with-low-memory
  9609.  
  9610. The `-Wa,-many' is necessary for the compile to be successful.  IBM is
  9611. aware of this problem but is in to hurry to fix it because of the
  9612. workaround available.  We don't know if the `-fno-exceptions' is
  9613. required with `gcc 2.95', but as MySQL doesn't use exceptions and the
  9614. above option generates faster code, we recommend that you should always
  9615. use this option with `egcs / gcc'.
  9616.  
  9617. If you get a problem with assembler code try changing the -mcpu=xxx to
  9618. match your CPU. Typically power2, power, or powerpc may need to be used,
  9619. alternatively you might need to use 604 or 604e. I'm not positive but I
  9620. would think using "power" would likely be safe most of the time, even on
  9621. a power2 machine.
  9622.  
  9623. If you don't know what your CPU is then do a "uname -m", this will give
  9624. you back a string that looks like "000514676700", with a format of
  9625. xxyyyyyymmss where xx and ss are always 0's, yyyyyy is a unique system
  9626. id and mm is the id of the CPU Planar. A chart of these values can be
  9627. found at
  9628. `http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  9629. This will give you a machine type and a machine model you can use to
  9630. determine what type of CPU you have.
  9631.  
  9632. If you have problems with signals (MySQL dies unexpectedly under high
  9633. load) you may have found an OS bug with threads and signals.  In this
  9634. case you can tell MySQL not to use signals by configuring with:
  9635.  
  9636.      shell> CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  9637.             CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
  9638.             -DDONT_USE_THR_ALARM" \
  9639.             ./configure --prefix=/usr/local/mysql --with-debug --with-low-memory
  9640.  
  9641. This doesn't affect the performance of MySQL, but has the side effect
  9642. that you can't kill clients that are "sleeping" on a connection with
  9643. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  9644. die when it issues its next command.
  9645.  
  9646. On some versions of AIX, linking with `libbind.a' makes `getservbyname'
  9647. core dump.  This is an AIX bug and should be reported to IBM.
  9648.  
  9649. For AIX 4.2.1 and gcc you have to do the following changes.
  9650.  
  9651. After configuring, edit `config.h' and `include/my_config.h' and change
  9652. the line that says
  9653.  
  9654.      #define HAVE_SNPRINTF 1
  9655.  
  9656. to
  9657.  
  9658.      #undef HAVE_SNPRINTF
  9659.  
  9660. And finally, in `mysqld.cc' you need to add a prototype for initgoups.
  9661.  
  9662.      #ifdef _AIX41
  9663.      extern "C" int initgroups(const char *,int);
  9664.      #endif
  9665.  
  9666. If you need to allocate a lot of memory to the mysqld process, it's not
  9667. enough to just set 'ulimit -d unlimited'. You may also have to set in
  9668. `mysqld_safe' something like:
  9669.  
  9670.      export LDR_CNTRL='MAXDATA=0x80000000'
  9671.  
  9672. You can find more about using a lot of memory at:
  9673. `http://publib16.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/lrg_prg_support.htm'.
  9674.  
  9675. SunOS 4 Notes
  9676. .............
  9677.  
  9678. On SunOS 4, MIT-pthreads is needed to compile MySQL, which in turn
  9679. means you will need GNU `make'.
  9680.  
  9681. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  9682. You can use the following `configure' line to avoid this problem:
  9683.  
  9684.      shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
  9685.  
  9686. When compiling `readline', you may get warnings about duplicate defines.
  9687. These may be ignored.
  9688.  
  9689. When compiling `mysqld', there will be some `implicit declaration of
  9690. function' warnings. These may be ignored.
  9691.  
  9692. Alpha-DEC-UNIX Notes (Tru64)
  9693. ............................
  9694.  
  9695. If you are using egcs 1.1.2 on Digital Unix, you should upgrade to gcc
  9696. 2.95.2, as egcs on DEC has some serious bugs!
  9697.  
  9698. When compiling threaded programs under Digital Unix, the documentation
  9699. recommends using the `-pthread' option for `cc' and `cxx' and the
  9700. libraries `-lmach -lexc' (in addition to `-lpthread').  You should run
  9701. `configure' something like this:
  9702.  
  9703.      CC="cc -pthread" CXX="cxx -pthread -O" \
  9704.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  9705.  
  9706. When compiling `mysqld', you may see a couple of warnings like this:
  9707.  
  9708.      mysqld.cc: In function void handle_connections()':
  9709.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  9710.      accept(int,sockadddr *, int *)'
  9711.  
  9712. You can safely ignore these warnings.  They occur because `configure'
  9713. can detect only errors, not warnings.
  9714.  
  9715. If you start the server directly from the command-line, you may have
  9716. problems with it dying when you log out.  (When you log out, your
  9717. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  9718. the server like this:
  9719.  
  9720.      shell> nohup mysqld [options] &
  9721.  
  9722. `nohup' causes the command following it to ignore any `SIGHUP' signal
  9723. sent from the terminal.  Alternatively, start the server by running
  9724. `safe_mysqld', which invokes `mysqld' using `nohup' for you.  *Note
  9725. `safe_mysqld': safe_mysqld.
  9726.  
  9727. If you get a problem when compiling mysys/get_opt.c, just remove the
  9728. line #define _NO_PROTO from the start of that file!
  9729.  
  9730. If you are using Compac's CC compiler, the following configure line
  9731. should work:
  9732.  
  9733.      CC="cc -pthread"
  9734.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  9735.      CXX="cxx -pthread"
  9736.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host \
  9737.      -noexceptions -nortti"
  9738.      export CC CFLAGS CXX CXXFLAGS
  9739.      ./configure \
  9740.      --prefix=/usr/local/mysql \
  9741.      --with-low-memory \
  9742.      --enable-large-files \
  9743.      --enable-shared=yes \
  9744.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  9745.      gnumake
  9746.  
  9747. If you get a problem with libtool, when compiling with shared libraries
  9748. as above, when linking `mysql', you should be able to get around this
  9749. by issuing:
  9750.  
  9751.      cd mysql
  9752.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  9753.      -O4 -ansi_alias -ansi_args -fast -inline speed \
  9754.      -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  9755.      -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  9756.      ../readline/libreadline.a -lcurses \
  9757.      ../libmysql/.libs/libmysqlclient.so  -lm
  9758.      cd ..
  9759.      gnumake
  9760.      gnumake install
  9761.      scripts/mysql_install_db
  9762.  
  9763. Alpha-DEC-OSF/1 Notes
  9764. .....................
  9765.  
  9766. If you have problems compiling and have DEC `CC' and `gcc' installed,
  9767. try running `configure' like this:
  9768.  
  9769.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  9770.      ./configure --prefix=/usr/local/mysql
  9771.  
  9772. If you get problems with the `c_asm.h' file, you can create and use a
  9773. 'dummy' `c_asm.h' file with:
  9774.  
  9775.      touch include/c_asm.h
  9776.      CC=gcc CFLAGS=-I./include \
  9777.      CXX=gcc CXXFLAGS=-O3 \
  9778.      ./configure --prefix=/usr/local/mysql
  9779.  
  9780. Note that the following problems with the `ld' program can be fixed by
  9781. downloading the latest DEC (Compaq) patch kit from:
  9782. `http://ftp.support.compaq.com/public/unix/'.
  9783.  
  9784. On OSF/1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  9785. 878)" the compiler had some strange behaviour (undefined `asm' symbols).
  9786. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  9787. errors occuring while linking `mysqld').  On this system, we have
  9788. managed to compile MySQL with the following `configure' line, after
  9789. replacing `/bin/ld' with the version from OSF 4.0C:
  9790.  
  9791.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  9792.  
  9793. With the Digital compiler "C++ V6.1-029", the following should work:
  9794.  
  9795.      CC=cc -pthread
  9796.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  9797.             -arch host
  9798.      CXX=cxx -pthread
  9799.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  9800.                -arch host -noexceptions -nortti
  9801.      export CC CFLAGS CXX CXXFLAGS
  9802.      ./configure --prefix=/usr/mysql/mysql --with-mysqld-ldflags=-all-static \
  9803.                  --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
  9804.  
  9805. In some versions of OSF/1, the `alloca()' function is broken. Fix this
  9806. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  9807.  
  9808. The `alloca()' function also may have an incorrect prototype in
  9809. `/usr/include/alloca.h'.  This warning resulting from this can be
  9810. ignored.
  9811.  
  9812. `configure' will use the following thread libraries automatically:
  9813. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  9814.  
  9815. When using `gcc', you can also try running `configure' like this:
  9816.  
  9817.      shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ...
  9818.  
  9819. If you have problems with signals (MySQL dies unexpectedly under high
  9820. load), you may have found an OS bug with threads and signals. In this
  9821. case you can tell MySQL not to use signals by configuring with:
  9822.  
  9823.      shell> CFLAGS=-DDONT_USE_THR_ALARM \
  9824.             CXXFLAGS=-DDONT_USE_THR_ALARM \
  9825.             ./configure ...
  9826.  
  9827. This doesn't affect the performance of MySQL, but has the side effect
  9828. that you can't kill clients that are "sleeping" on a connection with
  9829. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  9830. die when it issues its next command.
  9831.  
  9832. With `gcc' 2.95.2, you will probably run into the following compile
  9833. error:
  9834.  
  9835.      sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
  9836.      Please submit a full bug report.
  9837.  
  9838. To fix this you should change to the `sql' directory and do a "cut and
  9839. paste" of the last `gcc' line, but change `-O3' to `-O0' (or add `-O0'
  9840. immediately after `gcc' if you don't have any `-O' option on your
  9841. compile line).  After this is done you can just change back to the
  9842. top-level directly and run `make' again.
  9843.  
  9844. SGI Irix Notes
  9845. ..............
  9846.  
  9847. If you are using Irix Version 6.5.3 or newer `mysqld' will only be able
  9848. to create threads if you run it as a user with `CAP_SCHED_MGT'
  9849. privileges (like `root') or give the `mysqld' server this privilege
  9850. with the following shell command:
  9851.  
  9852.      shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  9853.  
  9854. You may have to undefine some things in `config.h' after running
  9855. `configure' and before compiling.
  9856.  
  9857. In some Irix implementations, the `alloca()' function is broken.  If the
  9858. `mysqld' server dies on some `SELECT' statements, remove the lines from
  9859. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  9860. `mysqladmin create' doesn't work, remove the line from `config.h' that
  9861. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  9862. line as well.
  9863.  
  9864. SGI recommends that you install all of the patches on this page as a
  9865. set:
  9866. `http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html'
  9867.  
  9868. At the very minimum, you should install the latest kernel rollup, the
  9869. latest `rld' rollup, and the latest `libc' rollup.
  9870.  
  9871. You definitely need all the POSIX patches on this page, for pthreads
  9872. support:
  9873.  
  9874. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  9875.  
  9876. If you get the something like the following error when compiling
  9877. `mysql.cc':
  9878.  
  9879.      "/usr/include/curses.h", line 82: error(1084): invalid combination of type
  9880.  
  9881. Type the following in the top-level directory of your MySQL source tree:
  9882.  
  9883.      shell> extra/replace bool curses_bool < /usr/include/curses.h \
  9884.      > include/curses.h
  9885.      shell> make
  9886.  
  9887. There have also been reports of scheduling problems.  If only one
  9888. thread is running, things go slow.  Avoid this by starting another
  9889. client.  This may lead to a 2-to-10-fold increase in execution speed
  9890. thereafter for the other thread.  This is a poorly understood problem
  9891. with Irix threads; you may have to improvise to find solutions until
  9892. this can be fixed.
  9893.  
  9894. If you are compiling with `gcc', you can use the following `configure'
  9895. command:
  9896.  
  9897.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  9898.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
  9899.      --with-named-thread-libs=-lpthread
  9900.  
  9901. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  9902. following is reported to work
  9903.  
  9904.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  9905.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  9906.      -I/usr/local/include -L/usr/local/lib' ./configure \
  9907.      --prefix=/usr/local/mysql --with-innodb --with-berkeley-db \
  9908.      --with-libwrap=/usr/local \
  9909.      --with-named-curses-libs=/usr/local/lib/libncurses.a
  9910.  
  9911. Caldera (SCO) Notes
  9912. ...................
  9913.  
  9914. The current port is tested only on a "sco3.2v5.0.4" and "sco3.2v5.0.5"
  9915. system.  There has also been a lot of progress on a port to "sco
  9916. 3.2v4.2".
  9917.  
  9918. For the moment the recommended compiler on OpenServer is gcc 2.95.2.
  9919. With this you should be able to compile MySQL with just:
  9920.  
  9921.      CC=gcc CXX=gcc ./configure ... (options)
  9922.  
  9923.   1. For OpenServer 5.0.X you need to use gcc-2.95.2p1 or newer from the
  9924.      Skunkware.  `http://www.caldera.com/skunkware/' and choose browser
  9925.      OpenServer packages or by ftp to ftp2.caldera.com in the
  9926.      pub/skunkware/osr5/devtools/gcc directory.
  9927.  
  9928.   2. You need the port of GCC 2.5.x for this product and the Development
  9929.      system.  They are required on this version of Caldera (SCO) Unix.
  9930.      You cannot just use the GCC Dev system.
  9931.  
  9932.   3. You should get the FSU Pthreads package and install it first.
  9933.      This can be found at
  9934.      `http://www.cs.wustl.edu/~schmidt/ACE_wrappers/FSU-threads.tar.gz'.
  9935.      You can also get a precompiled package from
  9936.      `http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz'.
  9937.  
  9938.   4. FSU Pthreads can be compiled with Caldera (SCO) Unix 4.2 with
  9939.      tcpip.  Or OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0),
  9940.      with the Caldera (SCO) Development System installed using a good
  9941.      port of GCC 2.5.x ODT or OS 3.0 you will need a good port of GCC
  9942.      2.5.x There are a lot of problems without a good port.  The port
  9943.      for this product requires the SCO Unix Development system.
  9944.      Without it, you are missing the libraries and the linker that is
  9945.      needed.
  9946.  
  9947.   5. To build FSU Pthreads on your system, do the following:
  9948.  
  9949.        a. Run `./configure' in the `threads/src' directory and select
  9950.           the SCO OpenServer option. This command copies
  9951.           `Makefile.SCO5' to `Makefile'.
  9952.  
  9953.        b. Run `make'.
  9954.  
  9955.        c. To install in the default `/usr/include' directory, login as
  9956.           root, then `cd' to the `thread/src' directory, and run `make
  9957.           install'.
  9958.  
  9959.   6. Remember to use GNU `make' when making MySQL.
  9960.  
  9961.   7. If you don't start `safe_mysqld' as root, you probably will get
  9962.      only the default 110 open files per process.  `mysqld' will write
  9963.      a note about this in the log file.
  9964.  
  9965.   8. With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or
  9966.      newer.  You should also use gcc 2.95.2 or newer!
  9967.  
  9968.      The following `configure' command should work:
  9969.  
  9970.           shell> ./configure --prefix=/usr/local/mysql --disable-shared
  9971.  
  9972.   9. With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or
  9973.      newer.  The following `configure' command should work:
  9974.  
  9975.           shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  9976.                  ./configure \
  9977.                      --prefix=/usr/local/mysql \
  9978.                      --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  9979.                      --with-named-curses-libs="-lcurses"
  9980.  
  9981.      You may get some problems with some include files. In this case,
  9982.      you can find new SCO-specific include files at
  9983.      `http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz'.
  9984.      You should unpack this file in the `include' directory of your
  9985.      MySQL source tree.
  9986.  
  9987. Caldera (SCO) development notes:
  9988.  
  9989.    * MySQL should automatically detect FSU Pthreads and link `mysqld'
  9990.      with `-lgthreads -lsocket -lgthreads'.
  9991.  
  9992.    * The Caldera (SCO) development libraries are re-entrant in FSU
  9993.      Pthreads.  Caldera claim sthat its libraries' functions are
  9994.      re-entrant, so they must be reentrant with FSU Pthreads.  FSU
  9995.      Pthreads on OpenServer tries to use the SCO scheme to make
  9996.      re-entrant libraries.
  9997.  
  9998.    * FSU Pthreads (at least the version at `http://www.mysql.com/')
  9999.      comes linked with GNU `malloc'.  If you encounter problems with
  10000.      memory usage, make sure that `gmalloc.o' is included in
  10001.      `libgthreads.a' and `libgthreads.so'.
  10002.  
  10003.    * In FSU Pthreads, the following system calls are pthreads-aware:
  10004.      `read()', `write()', `getmsg()', `connect()', `accept()',
  10005.      `select()', and `wait()'.
  10006.  
  10007.    * The CSSA-2001-SCO.35.2 (the patch is listed in custom as
  10008.      erg711905-dscr_remap security patch (version 2.0.0) breaks FSU
  10009.      threads and makes mysqld unstable.  You have to remove this one if
  10010.      you want to run mysqld on an OpenServer 5.0.6 machine.
  10011.  
  10012. If you want to install DBI on Caldera (SCO), you have to edit the
  10013. `Makefile' in DBI-xxx and each subdirectory.
  10014.  
  10015. Note that the following assumes gcc 2.95.2 or newer:
  10016.  
  10017.      OLD:                                  NEW:
  10018.      CC = cc                               CC = gcc
  10019.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  10020.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  10021.      
  10022.      LD = ld                               LD = gcc -G -fpic
  10023.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  10024.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  10025.      
  10026.      LD = ld                               LD = gcc -G -fpic
  10027.      OPTIMISE = -Od                        OPTIMISE = -O1
  10028.      
  10029.      OLD:
  10030.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10031.      
  10032.      NEW:
  10033.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10034.  
  10035. This is because the Perl dynaloader will not load the `DBI' modules if
  10036. they were compiled with `icc' or `cc'.
  10037.  
  10038. Perl works best when compiled with `cc'.
  10039.  
  10040. Caldera (SCO) Unixware Version 7.0 Notes
  10041. ........................................
  10042.  
  10043. You must use a version of MySQL at least as recent as Version 3.22.13
  10044. because that version fixes some portability problems under Unixware.
  10045.  
  10046. We have been able to compile MySQL with the following `configure'
  10047. command on Unixware Version 7.0.1:
  10048.  
  10049.      CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
  10050.  
  10051. If you want to use `gcc', you must use `gcc' 2.95.2 or newer.
  10052.  
  10053. Caldera provides libsocket.so.2 at
  10054. `ftp://stage.caldera.com/pub/security/tools' for pre-OSR506 security
  10055. fixes. Also, the telnetd fix at
  10056. <ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/> as
  10057. both libsocket.so.2 and libresolv.so.1 with instructions for installing
  10058. on pre-OSR506 systems.
  10059.  
  10060. It's probably a good idea to install the above patches before trying to
  10061. compile/use MySQL.
  10062.  
  10063. OS/2 Notes
  10064. ----------
  10065.  
  10066. MySQL uses quite a few open files. Because of this, you should add
  10067. something like the following to your `CONFIG.SYS' file:
  10068.  
  10069.      SET EMXOPT=-c -n -h1024
  10070.  
  10071. If you don't do this, you will probably run into the following error:
  10072.  
  10073.      File 'xxxx' not found (Errcode: 24)
  10074.  
  10075. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  10076. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  10077. of the Pthreads library.  MySQL must be installed in a partition that
  10078. supports long filenames such as HPFS, FAT32, etc.
  10079.  
  10080. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  10081. not work with replacement shells such as `4OS2.EXE'.
  10082.  
  10083. The `scripts/mysql-install-db' script has been renamed.  It is now
  10084. called `install.cmd' and is a REXX script, which will set up the default
  10085. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  10086.  
  10087. Dynamic module support is compiled in but not fully tested. Dynamic
  10088. modules should be compiled using the Pthreads run-time library.
  10089.  
  10090.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  10091.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  10092.      mv example.dll example.udf
  10093.  
  10094. *Note*: Due to limitations in OS/2, UDF module name stems must not
  10095. exceed 8 characters. Modules are stored in the `/mysql2/udf' directory;
  10096. the `safe-mysqld.cmd' script will put this directory in the
  10097. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  10098. extensions are ignoredit is assumed to be `.udf'.  For example, in
  10099. Unix, the shared module might be named `example.so' and you would load
  10100. a function from it like this:
  10101.  
  10102.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
  10103.  
  10104. Is OS/2, the module would be named `example.udf', but you would not
  10105. specify the module extension:
  10106.  
  10107.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
  10108.  
  10109. BeOS Notes
  10110. ----------
  10111.  
  10112. We are really interested in getting MySQL to work on BeOS, but
  10113. unfortunately we don't have any person who knows BeOS or has time to do
  10114. a port.
  10115.  
  10116. We are interested in finding someone to do a port, and we will help them
  10117. with any technical questions they may have while doing the port.
  10118.  
  10119. We have previously talked with some BeOS developers that have said that
  10120. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  10121.  
  10122. Novell NetWare Notes
  10123. --------------------
  10124.  
  10125. We are really interested in getting MySQL to work on NetWare, but
  10126. unfortunately we don't have any person who knows NetWare or has time to
  10127. do a port.
  10128.  
  10129. We are interested in finding someone to do a port, and we will help them
  10130. with any technical questions they may have while doing the port.
  10131.  
  10132. Perl Installation Comments
  10133. ==========================
  10134.  
  10135. Installing Perl on Unix
  10136. -----------------------
  10137.  
  10138. Perl support for MySQL is provided by means of the `DBI'/`DBD' client
  10139. interface.  *Note Perl::.  The Perl `DBD'/`DBI' client code requires
  10140. Perl Version 5.004 or later.  The interface *will not work* if you have
  10141. an older version of Perl.
  10142.  
  10143. MySQL Perl support also requires that you've installed MySQL client
  10144. programming support.  If you installed MySQL from RPM files, client
  10145. programs are in the client RPM, but client programming support is in
  10146. the developer RPM.  Make sure you've installed the latter RPM.
  10147.  
  10148. As of Version 3.22.8, Perl support is distributed separately from the
  10149. main MySQL distribution.  If you want to install Perl support, the files
  10150. you will need can be obtained from
  10151. `http://www.mysql.com/downloads/api-dbi.html'.
  10152.  
  10153. The Perl distributions are provided as compressed `tar' archives and
  10154. have names like `MODULE-VERSION.tar.gz', where `MODULE' is the module
  10155. name and `VERSION' is the version number.  You should get the
  10156. `Data-Dumper', `DBI', and `Msql-Mysql-modules' distributions and
  10157. install them in that order.  The installation procedure is shown here.
  10158. The example shown is for the `Data-Dumper' module, but the procedure is
  10159. the same for all three distributions:
  10160.  
  10161.   1. Unpack the distribution into the current directory:
  10162.           shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf -
  10163.      This command creates a directory named `Data-Dumper-VERSION'.
  10164.  
  10165.   2. Change into the top-level directory of the unpacked distribution:
  10166.           shell> cd Data-Dumper-VERSION
  10167.  
  10168.   3. Build the distribution and compile everything:
  10169.           shell> perl Makefile.PL
  10170.           shell> make
  10171.           shell> make test
  10172.           shell> make install
  10173.  
  10174. The `make test' command is important because it verifies that the
  10175. module is working.  Note that when you run that command during the
  10176. `Msql-Mysql-modules' installation to exercise the interface code, the
  10177. MySQL server must be running or the test will fail.
  10178.  
  10179. It is a good idea to rebuild and reinstall the `Msql-Mysql-modules'
  10180. distribution whenever you install a new release of MySQL, particularly
  10181. if you notice symptoms such as all your `DBI' scripts dumping core
  10182. after you upgrade MySQL.
  10183.  
  10184. If you don't have the right to install Perl modules in the system
  10185. directory or if you to install local Perl modules, the following
  10186. reference may help you:
  10187.  
  10188.      `http://www.iserver.com/support/contrib/perl5/modules.html'
  10189.  
  10190. Look under the heading `Installing New Modules that Require Locally
  10191. Installed Modules'.
  10192.  
  10193. Installing ActiveState Perl on Windows
  10194. --------------------------------------
  10195.  
  10196. To install the MySQL `DBD' module with ActiveState Perl on Windows, you
  10197. should do the following:
  10198.  
  10199.    * Get ActiveState Perl from
  10200.      `http://www.activestate.com/Products/ActivePerl/' and install it.
  10201.  
  10202.    * Open a DOS shell.
  10203.  
  10204.    * If required, set the HTTP_proxy variable. For example, you might
  10205.      try:
  10206.  
  10207.           set HTTP_proxy=my.proxy.com:3128
  10208.  
  10209.    * Start the PPM program:
  10210.  
  10211.           C:\> c:\perl\bin\ppm.pl
  10212.  
  10213.    * If you have not already done so, install `DBI':
  10214.  
  10215.           ppm> install DBI
  10216.  
  10217.    * If this succeeds, run the following command:
  10218.  
  10219.           install \
  10220.           ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
  10221.  
  10222. The above should work at least with ActiveState Perl Version 5.6.
  10223.  
  10224. If you can't get the above to work, you should instead install the
  10225. `MyODBC' driver and connect to MySQL server through ODBC:
  10226.  
  10227.      use DBI;
  10228.      $dbh= DBI->connect("DBI:ODBC:$dsn","$user","$password") ||
  10229.        die "Got error $DBI::errstr when connecting to $dsn\n";
  10230.  
  10231. Installing the MySQL Perl Distribution on Windows
  10232. -------------------------------------------------
  10233.  
  10234. The MySQL Perl distribution contains `DBI', `DBD:MySQL' and `DBD:ODBC'.
  10235.  
  10236.    * Get the Perl distribution for Windows from
  10237.      `http://www.mysql.com/downloads/os-win32.html'.
  10238.  
  10239.    * Unzip the distribution in `C:' so that you get a `C:\PERL'
  10240.      directory.
  10241.  
  10242.    * Add the directory `C:\PERL\BIN' to your path.
  10243.  
  10244.    * Add the directory `C:\PERL\BIN\MSWIN32-x86-thread' or
  10245.      `C:\PERL\BIN\MSWIN32-x86' to your path.
  10246.  
  10247.    * Test that `perl' works by executing `perl -v' in a DOS shell.
  10248.  
  10249. Problems Using the Perl `DBI'/`DBD' Interface
  10250. ---------------------------------------------
  10251.  
  10252. If Perl reports that it can't find the `../mysql/mysql.so' module, then
  10253. the problem is probably that Perl can't locate the shared library
  10254. `libmysqlclient.so'.
  10255.  
  10256. You can fix this by any of the following methods:
  10257.  
  10258.    * Compile the `Msql-Mysql-modules' distribution with `perl
  10259.      Makefile.PL -static -config' rather than `perl Makefile.PL'.
  10260.  
  10261.    * Copy `libmysqlclient.so' to the directory where your other shared
  10262.      libraries are located (probably `/usr/lib' or `/lib').
  10263.  
  10264.    * On Linux you can add the pathname of the directory where
  10265.      `libmysqlclient.so' is located to the `/etc/ld.so.conf' file.
  10266.  
  10267.    * Add the pathname of the directory where `libmysqlclient.so' is
  10268.      located to the `LD_RUN_PATH' environment variable.
  10269.  
  10270. If you get the following errors from `DBD-mysql', you are probably
  10271. using `gcc' (or using an old binary compiled with `gcc'):
  10272.  
  10273.      /usr/bin/perl: can't resolve symbol '__moddi3'
  10274.      /usr/bin/perl: can't resolve symbol '__divdi3'
  10275.  
  10276. Add `-L/usr/lib/gcc-lib/... -lgcc' to the link command when the
  10277. `mysql.so' library gets built (check the output from `make' for
  10278. `mysql.so' when you compile the Perl client).  The `-L' option should
  10279. specify the pathname of the directory where `libgcc.a' is located on
  10280. your system.
  10281.  
  10282. Another cause of this problem may be that Perl and MySQL aren't both
  10283. compiled with `gcc'.  In this case, you can solve the mismatch by
  10284. compiling both with `gcc'.
  10285.  
  10286. If you get the following error from `Msql-Mysql-modules' when you run
  10287. the tests:
  10288.  
  10289.      t/00base............install_driver(mysql) failed:
  10290.      Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
  10291.      ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
  10292.      uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
  10293.  
  10294. it means that you need to include the compression library, -lz, to the
  10295. link line. This can be doing the following change in the file
  10296. `lib/DBD/mysql/Install.pm':
  10297.  
  10298.      $sysliblist .= " -lm";
  10299.      
  10300.      to
  10301.      
  10302.      $sysliblist .= " -lm -lz";
  10303.  
  10304. After this, you *must* run 'make realclean' and then proceed with the
  10305. installation from the beginning.
  10306.  
  10307. If you want to use the Perl module on a system that doesn't support
  10308. dynamic linking (like Caldera/SCO) you can generate a static version of
  10309. Perl that includes `DBI' and `DBD-mysql'.  The way this works is that
  10310. you generate a version of Perl with the `DBI' code linked in and
  10311. install it on top of your current Perl.  Then you use that to build a
  10312. version of Perl that additionally has the `DBD' code linked in, and
  10313. install that.
  10314.  
  10315. On Caldera (SCO), you must have the following environment variables set:
  10316.  
  10317.      shell> LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
  10318.      or
  10319.      shell> LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  10320.      /usr/progressive/lib:/usr/skunk/lib
  10321.      shell> LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  10322.      /usr/progressive/lib:/usr/skunk/lib
  10323.      shell> MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
  10324.      /usr/skunk/man:
  10325.  
  10326. First, create a Perl that includes a statically linked `DBI' by running
  10327. these commands in the directory where your `DBI' distribution is
  10328. located:
  10329.  
  10330.      shell> perl Makefile.PL -static -config
  10331.      shell> make
  10332.      shell> make install
  10333.      shell> make perl
  10334.  
  10335. Then you must install the new Perl. The output of `make perl' will
  10336. indicate the exact `make' command you will need to execute to perform
  10337. the installation.  On Caldera (SCO), this is `make -f Makefile.aperl
  10338. inst_perl MAP_TARGET=perl'.
  10339.  
  10340. Next, use the just-created Perl to create another Perl that also
  10341. includes a statically-linked `DBD::mysql' by running these commands in
  10342. the directory where your `Msql-Mysql-modules' distribution is located:
  10343.  
  10344.      shell> perl Makefile.PL -static -config
  10345.      shell> make
  10346.      shell> make install
  10347.      shell> make perl
  10348.  
  10349. Finally, you should install this new Perl.  Again, the output of `make
  10350. perl' indicates the command to use.
  10351.  
  10352. Tutorial Introduction
  10353. *********************
  10354.  
  10355. This chapter provides a tutorial introduction to MySQL by showing how
  10356. to use the `mysql' client program to create and use a simple database.
  10357. `mysql' (sometimes referred to as the "terminal monitor" or just
  10358. "monitor") is an interactive program that allows you to connect to a
  10359. MySQL server, run queries, and view the results.  `mysql' may also be
  10360. used in batch mode: you place your queries in a file beforehand, then
  10361. tell `mysql' to execute the contents of the file.  Both ways of using
  10362. `mysql' are covered here.
  10363.  
  10364. To see a list of options provided by `mysql', invoke it with the
  10365. `--help' option:
  10366.  
  10367.      shell> mysql --help
  10368.  
  10369. This chapter assumes that `mysql' is installed on your machine and that
  10370. a MySQL server is available to which you can connect.  If this is not
  10371. true, contact your MySQL administrator.  (If *you* are the
  10372. administrator, you will need to consult other sections of this manual.)
  10373.  
  10374. This chapter describes the entire process of setting up and using a
  10375. database.  If you are interested only in accessing an already-existing
  10376. database, you may want to skip over the sections that describe how to
  10377. create the database and the tables it contains.
  10378.  
  10379. Because this chapter is tutorial in nature, many details are
  10380. necessarily left out.  Consult the relevant sections of the manual for
  10381. more information on the topics covered here.
  10382.  
  10383. Connecting to and Disconnecting from the Server
  10384. ===============================================
  10385.  
  10386. To connect to the server, you'll usually need to provide a MySQL user
  10387. name when you invoke `mysql' and, most likely, a password.  If the
  10388. server runs on a machine other than the one where you log in, you'll
  10389. also need to specify a hostname.  Contact your administrator to find
  10390. out what connection parameters you should use to connect (that is, what
  10391. host, user name, and password to use).  Once you know the proper
  10392. parameters, you should be able to connect like this:
  10393.  
  10394.      shell> mysql -h host -u user -p
  10395.      Enter password: ********
  10396.  
  10397. The `********' represents your password; enter it when `mysql' displays
  10398. the `Enter password:' prompt.
  10399.  
  10400. If that works, you should see some introductory information followed by
  10401. a `mysql>' prompt:
  10402.  
  10403.      shell> mysql -h host -u user -p
  10404.      Enter password: ********
  10405.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  10406.      Your MySQL connection id is 459 to server version: 3.22.20a-log
  10407.      
  10408.      Type 'help' for help.
  10409.      
  10410.      mysql>
  10411.  
  10412. The prompt tells you that `mysql' is ready for you to enter commands.
  10413.  
  10414. Some MySQL installations allow users to connect as the anonymous
  10415. (unnamed) user to the server running on the local host.  If this is the
  10416. case on your machine, you should be able to connect to that server by
  10417. invoking `mysql' without any options:
  10418.  
  10419.      shell> mysql
  10420.  
  10421. After you have connected successfully, you can disconnect any time by
  10422. typing `QUIT' at the `mysql>' prompt:
  10423.  
  10424.      mysql> QUIT
  10425.      Bye
  10426.  
  10427. You can also disconnect by pressing Control-D.
  10428.  
  10429. Most examples in the following sections assume you are connected to the
  10430. server.  They indicate this by the `mysql>' prompt.
  10431.  
  10432. Entering Queries
  10433. ================
  10434.  
  10435. Make sure you are connected to the server, as discussed in the previous
  10436. section.  Doing so will not in itself select any database to work with,
  10437. but that's okay.  At this point, it's more important to find out a
  10438. little about how to issue queries than to jump right in creating
  10439. tables, loading data into them, and retrieving data from them.  This
  10440. section describes the basic principles of entering commands, using
  10441. several queries you can try out to familiarise yourself with how
  10442. `mysql' works.
  10443.  
  10444. Here's a simple command that asks the server to tell you its version
  10445. number and the current date.  Type it in as shown here following the
  10446. `mysql>' prompt and press Enter:
  10447.  
  10448.      mysql> SELECT VERSION(), CURRENT_DATE;
  10449.      +--------------+--------------+
  10450.      | VERSION()    | CURRENT_DATE |
  10451.      +--------------+--------------+
  10452.      | 3.22.20a-log | 1999-03-19   |
  10453.      +--------------+--------------+
  10454.      1 row in set (0.01 sec)
  10455.      mysql>
  10456.  
  10457. This query illustrates several things about `mysql':
  10458.  
  10459.    * A command normally consists of a SQL statement followed by a
  10460.      semicolon.  (There are some exceptions where a semicolon is not
  10461.      needed.  `QUIT', mentioned earlier, is one of them.  We'll get to
  10462.      others later.)
  10463.  
  10464.    * When you issue a command, `mysql' sends it to the server for
  10465.      execution and displays the results, then prints another `mysql>'
  10466.      to indicate that it is ready for another command.
  10467.  
  10468.    * `mysql' displays query output as a table (rows and columns).  The
  10469.      first row contains labels for the columns.  The rows following are
  10470.      the query results.  Normally, column labels are the names of the
  10471.      columns you fetch from database tables.  If you're retrieving the
  10472.      value of an expression rather than a table column (as in the
  10473.      example just shown), `mysql' labels the column using the
  10474.      expression itself.
  10475.  
  10476.    * `mysql' shows how many rows were returned and how long the query
  10477.      took to execute, which gives you a rough idea of server
  10478.      performance.  These values are imprecise because they represent
  10479.      wall clock time (not CPU or machine time), and because they are
  10480.      affected by factors such as server load and network latency.  (For
  10481.      brevity, the "rows in set" line is not shown in the remaining
  10482.      examples in this chapter.)
  10483.  
  10484. Keywords may be entered in any lettercase.  The following queries are
  10485. equivalent:
  10486.  
  10487.      mysql> SELECT VERSION(), CURRENT_DATE;
  10488.      mysql> select version(), current_date;
  10489.      mysql> SeLeCt vErSiOn(), current_DATE;
  10490.  
  10491. Here's another query.  It demonstrates that you can use `mysql' as a
  10492. simple calculator:
  10493.  
  10494.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  10495.      +-------------+---------+
  10496.      | SIN(PI()/4) | (4+1)*5 |
  10497.      +-------------+---------+
  10498.      |    0.707107 |      25 |
  10499.      +-------------+---------+
  10500.  
  10501. The commands shown thus far have been relatively short, single-line
  10502. statements.  You can even enter multiple statements on a single line.
  10503. Just end each one with a semicolon:
  10504.  
  10505.      mysql> SELECT VERSION(); SELECT NOW();
  10506.      +--------------+
  10507.      | VERSION()    |
  10508.      +--------------+
  10509.      | 3.22.20a-log |
  10510.      +--------------+
  10511.      
  10512.      +---------------------+
  10513.      | NOW()               |
  10514.      +---------------------+
  10515.      | 1999-03-19 00:15:33 |
  10516.      +---------------------+
  10517.  
  10518. A command need not be given all on a single line, so lengthy commands
  10519. that require several lines are not a problem.  `mysql' determines where
  10520. your statement ends by looking for the terminating semicolon, not by
  10521. looking for the end of the input line.  (In other words, `mysql'
  10522. accepts free-format input:  it collects input lines but does not
  10523. execute them until it sees the semicolon.)
  10524.  
  10525. Here's a simple multiple-line statement:
  10526.  
  10527.      mysql> SELECT
  10528.          -> USER()
  10529.          -> ,
  10530.          -> CURRENT_DATE;
  10531.      +--------------------+--------------+
  10532.      | USER()             | CURRENT_DATE |
  10533.      +--------------------+--------------+
  10534.      | joesmith@localhost | 1999-03-18   |
  10535.      +--------------------+--------------+
  10536.  
  10537. In this example, notice how the prompt changes from `mysql>' to `->'
  10538. after you enter the first line of a multiple-line query.  This is how
  10539. `mysql' indicates that it hasn't seen a complete statement and is
  10540. waiting for the rest.  The prompt is your friend, because it provides
  10541. valuable feedback.  If you use that feedback, you will always be aware
  10542. of what `mysql' is waiting for.
  10543.  
  10544. If you decide you don't want to execute a command that you are in the
  10545. process of entering, cancel it by typing `\c':
  10546.  
  10547.      mysql> SELECT
  10548.          -> USER()
  10549.          -> \c
  10550.      mysql>
  10551.  
  10552. Here, too, notice the prompt.  It switches back to `mysql>' after you
  10553. type `\c', providing feedback to indicate that `mysql' is ready for a
  10554. new command.
  10555.  
  10556. The following table shows each of the prompts you may see and
  10557. summarises what they mean about the state that `mysql' is in:
  10558.  
  10559. *Prompt**Meaning*
  10560. `mysql>'Ready for new command.
  10561. `       Waiting for next line of multiple-line command.
  10562. ->'     
  10563. `       Waiting for next line, collecting a string that begins
  10564. '>'     with a single quote (`'').
  10565. `       Waiting for next line, collecting a string that begins
  10566. ">'     with a double quote (`"').
  10567.  
  10568. Multiple-line statements commonly occur by accident when you intend to
  10569. issue a command on a single line, but forget the terminating semicolon.
  10570. In this case, `mysql' waits for more input:
  10571.  
  10572.      mysql> SELECT USER()
  10573.          ->
  10574.  
  10575. If this happens to you (you think you've entered a statement but the
  10576. only response is a `->' prompt), most likely `mysql' is waiting for the
  10577. semicolon.  If you don't notice what the prompt is telling you, you
  10578. might sit there for a while before realising what you need to do.
  10579. Enter a semicolon to complete the statement, and `mysql' will execute
  10580. it:
  10581.  
  10582.      mysql> SELECT USER()
  10583.          -> ;
  10584.      +--------------------+
  10585.      | USER()             |
  10586.      +--------------------+
  10587.      | joesmith@localhost |
  10588.      +--------------------+
  10589.  
  10590. The `'>' and `">' prompts occur during string collection.  In MySQL,
  10591. you can write strings surrounded by either `'' or `"' characters (for
  10592. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  10593. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  10594. that you've entered a line containing a string that begins with a `''
  10595. or `"' quote character, but have not yet entered the matching quote
  10596. that terminates the string.  That's fine if you really are entering a
  10597. multiple-line string, but how likely is that?  Not very.  More often,
  10598. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  10599. quote character.  For example:
  10600.  
  10601.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  10602.          ">
  10603.  
  10604. If you enter this `SELECT' statement, then press Enter and wait for the
  10605. result, nothing will happen.  Instead of wondering why this query takes
  10606. so long, notice the clue provided by the `">' prompt.  It tells you
  10607. that `mysql' expects to see the rest of an unterminated string.  (Do
  10608. you see the error in the statement?  The string `"Smith' is missing the
  10609. second quote.)
  10610.  
  10611. At this point, what do you do?  The simplest thing is to cancel the
  10612. command.  However, you cannot just type `\c' in this case, because
  10613. `mysql' interprets it as part of the string that it is collecting!
  10614. Instead, enter the closing quote character (so `mysql' knows you've
  10615. finished the string), then type `\c':
  10616.  
  10617.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  10618.          "> "\c
  10619.      mysql>
  10620.  
  10621. The prompt changes back to `mysql>', indicating that `mysql' is ready
  10622. for a new command.
  10623.  
  10624. It's important to know what the `'>' and `">' prompts signify, because
  10625. if you mistakenly enter an unterminated string, any further lines you
  10626. type will appear to be ignored by `mysql'including a line containing
  10627. `QUIT'!  This can be quite confusing, especially if you don't know that
  10628. you need to supply the terminating quote before you can cancel the
  10629. current command.
  10630.  
  10631. Creating and Using a Database
  10632. =============================
  10633.  
  10634. Now that you know how to enter commands, it's time to access a database.
  10635.  
  10636. Suppose you have several pets in your home (your menagerie) and you'd
  10637. like to keep track of various types of information about them.  You can
  10638. do so by creating tables to hold your data and loading them with the
  10639. desired information.  Then you can answer different sorts of questions
  10640. about your animals by retrieving data from the tables.  This section
  10641. shows you how to:
  10642.  
  10643.    * Create a database
  10644.  
  10645.    * Create a table
  10646.  
  10647.    * Load data into the table
  10648.  
  10649.    * Retrieve data from the table in various ways
  10650.  
  10651.    * Use multiple tables
  10652.  
  10653. The menagerie database will be simple (deliberately), but it is not
  10654. difficult to think of real-world situations in which a similar type of
  10655. database might be used.  For example, a database like this could be
  10656. used by a farmer to keep track of livestock, or by a veterinarian to
  10657. keep track of patient records.  A menagerie distribution containing
  10658. some of the queries and sample data used in the following sections can
  10659. be obtained from the MySQL web site.  It's available in either
  10660. compressed `tar' format
  10661. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz') or
  10662. Zip format
  10663. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip').
  10664.  
  10665. Use the `SHOW' statement to find out what databases currently exist on
  10666. the server:
  10667.  
  10668.      mysql> SHOW DATABASES;
  10669.      +----------+
  10670.      | Database |
  10671.      +----------+
  10672.      | mysql    |
  10673.      | test     |
  10674.      | tmp      |
  10675.      +----------+
  10676.  
  10677. The list of databases is probably different on your machine, but the
  10678. `mysql' and `test' databases are likely to be among them.  The `mysql'
  10679. database is required because it describes user access privileges.  The
  10680. `test' database is often provided as a workspace for users to try
  10681. things out.
  10682.  
  10683. Note that you may not see all databases if you don't have the `SHOW
  10684. DATABASES' privilege. *Note GRANT::.
  10685.  
  10686. If the `test' database exists, try to access it:
  10687.  
  10688.      mysql> USE test
  10689.      Database changed
  10690.  
  10691. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  10692. terminate such statements with a semicolon if you like; it does no
  10693. harm.)  The `USE' statement is special in another way, too:  it must be
  10694. given on a single line.
  10695.  
  10696. You can use the `test' database (if you have access to it) for the
  10697. examples that follow, but anything you create in that database can be
  10698. removed by anyone else with access to it.  For this reason, you should
  10699. probably ask your MySQL administrator for permission to use a database
  10700. of your own.  Suppose you want to call yours `menagerie'.  The
  10701. administrator needs to execute a command like this:
  10702.  
  10703.      mysql> GRANT ALL ON menagerie.* TO your_mysql_name;
  10704.  
  10705. where `your_mysql_name' is the MySQL user name assigned to you.
  10706.  
  10707. Creating and Selecting a Database
  10708. ---------------------------------
  10709.  
  10710. If the administrator creates your database for you when setting up your
  10711. permissions, you can begin using it.  Otherwise, you need to create it
  10712. yourself:
  10713.  
  10714.      mysql> CREATE DATABASE menagerie;
  10715.  
  10716. Under Unix, database names are case-sensitive (unlike SQL keywords), so
  10717. you must always refer to your database as `menagerie', not as
  10718. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  10719. table names.  (Under Windows, this restriction does not apply, although
  10720. you must refer to databases and tables using the same lettercase
  10721. throughout a given query.)
  10722.  
  10723. Creating a database does not select it for use; you must do that
  10724. explicitly.  To make `menagerie' the current database, use this command:
  10725.  
  10726.      mysql> USE menagerie
  10727.      Database changed
  10728.  
  10729. Your database needs to be created only once, but you must select it for
  10730. use each time you begin a `mysql' session.  You can do this by issuing a
  10731. `USE' statement as shown above.  Alternatively, you can select the
  10732. database on the command-line when you invoke `mysql'.  Just specify its
  10733. name after any connection parameters that you might need to provide.
  10734. For example:
  10735.  
  10736.      shell> mysql -h host -u user -p menagerie
  10737.      Enter password: ********
  10738.  
  10739. Note that `menagerie' is not your password on the command just shown.
  10740. If you want to supply your password on the command-line after the `-p'
  10741. option, you must do so with no intervening space (for example, as
  10742. `-pmypassword', not as `-p mypassword').  However, putting your
  10743. password on the command-line is not recommended, because doing so
  10744. exposes it to snooping by other users logged in on your machine.
  10745.  
  10746. Creating a Table
  10747. ----------------
  10748.  
  10749. Creating the database is the easy part, but at this point it's empty, as
  10750. `SHOW TABLES' will tell you:
  10751.  
  10752.      mysql> SHOW TABLES;
  10753.      Empty set (0.00 sec)
  10754.  
  10755. The harder part is deciding what the structure of your database should
  10756. be: what tables you will need and what columns will be in each of them.
  10757.  
  10758. You'll want a table that contains a record for each of your pets.  This
  10759. can be called the `pet' table, and it should contain, as a bare minimum,
  10760. each animal's name.  Because the name by itself is not very
  10761. interesting, the table should contain other information.  For example,
  10762. if more than one person in your family keeps pets, you might want to
  10763. list each animal's owner.  You might also want to record some basic
  10764. descriptive information such as species and sex.
  10765.  
  10766. How about age?  That might be of interest, but it's not a good thing to
  10767. store in a database.  Age changes as time passes, which means you'd
  10768. have to update your records often.  Instead, it's better to store a
  10769. fixed value such as date of birth.  Then, whenever you need age, you
  10770. can calculate it as the difference between the current date and the
  10771. birth date.  MySQL provides functions for doing date arithmetic, so
  10772. this is not difficult.  Storing birth date rather than age has other
  10773. advantages, too:
  10774.  
  10775.    * You can use the database for tasks such as generating reminders
  10776.      for upcoming pet birthdays.  (If you think this type of query is
  10777.      somewhat silly, note that it is the same question you might ask in
  10778.      the context of a business database to identify clients to whom
  10779.      you'll soon need to send out birthday greetings, for that
  10780.      computer-assisted personal touch.)
  10781.  
  10782.    * You can calculate age in relation to dates other than the current
  10783.      date.  For example, if you store death date in the database, you
  10784.      can easily calculate how old a pet was when it died.
  10785.  
  10786. You can probably think of other types of information that would be
  10787. useful in the `pet' table, but the ones identified so far are
  10788. sufficient for now: name, owner, species, sex, birth, and death.
  10789.  
  10790. Use a `CREATE TABLE' statement to specify the layout of your table:
  10791.  
  10792.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  10793.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  10794.  
  10795. `VARCHAR' is a good choice for the `name', `owner', and `species'
  10796. columns because the column values will vary in length.  The lengths of
  10797. those columns need not all be the same, and need not be `20'.  You can
  10798. pick any length from `1' to `255', whatever seems most reasonable to
  10799. you.  (If you make a poor choice and it turns out later that you need a
  10800. longer field, MySQL provides an `ALTER TABLE' statement.)
  10801.  
  10802. Several types of values can be chosen to represent sex in animal
  10803. records, such as `"m"' and `"f"', or perhaps `"male"' and `"female"'.
  10804. It's simplest to use the single characters `"m"' and `"f"'.
  10805.  
  10806. The use of the `DATE' data type for the `birth' and `death' columns is
  10807. a fairly obvious choice.
  10808.  
  10809. Now that you have created a table, `SHOW TABLES' should produce some
  10810. output:
  10811.  
  10812.      mysql> SHOW TABLES;
  10813.      +---------------------+
  10814.      | Tables in menagerie |
  10815.      +---------------------+
  10816.      | pet                 |
  10817.      +---------------------+
  10818.  
  10819. To verify that your table was created the way you expected, use a
  10820. `DESCRIBE' statement:
  10821.  
  10822.      mysql> DESCRIBE pet;
  10823.      +---------+-------------+------+-----+---------+-------+
  10824.      | Field   | Type        | Null | Key | Default | Extra |
  10825.      +---------+-------------+------+-----+---------+-------+
  10826.      | name    | varchar(20) | YES  |     | NULL    |       |
  10827.      | owner   | varchar(20) | YES  |     | NULL    |       |
  10828.      | species | varchar(20) | YES  |     | NULL    |       |
  10829.      | sex     | char(1)     | YES  |     | NULL    |       |
  10830.      | birth   | date        | YES  |     | NULL    |       |
  10831.      | death   | date        | YES  |     | NULL    |       |
  10832.      +---------+-------------+------+-----+---------+-------+
  10833.  
  10834. You can use `DESCRIBE' any time, for example, if you forget the names of
  10835. the columns in your table or what types they are.
  10836.  
  10837. Loading Data into a Table
  10838. -------------------------
  10839.  
  10840. After creating your table, you need to populate it.  The `LOAD DATA' and
  10841. `INSERT' statements are useful for this.
  10842.  
  10843. Suppose your pet records can be described as shown here.  (Observe that
  10844. MySQL expects dates in `'YYYY-MM-DD'' format; this may be different
  10845. from what you are used to.)
  10846.  
  10847. *name*  *owner* *species**sex**birth*     *death*
  10848. Fluffy  Harold  cat     f    1993-02-04  
  10849. Claws   Gwen    cat     m    1994-03-17  
  10850. Buffy   Harold  dog     f    1989-05-13  
  10851. Fang    Benny   dog     m    1990-08-27  
  10852. Bowser  Diane   dog     m    1998-08-31  1995-07-29
  10853. Chirpy  Gwen    bird    f    1998-09-11  
  10854. WhistlerGwen    bird         1997-12-09  
  10855. Slim    Benny   snake   m    1996-04-29  
  10856.  
  10857. Because you are beginning with an empty table, an easy way to populate
  10858. it is to create a text file containing a row for each of your animals,
  10859. then load the contents of the file into the table with a single
  10860. statement.
  10861.  
  10862. You could create a text file `pet.txt' containing one record per line,
  10863. with values separated by tabs, and given in the order in which the
  10864. columns were listed in the `CREATE TABLE' statement.  For missing
  10865. values (such as unknown sexes or death dates for animals that are still
  10866. living), you can use `NULL' values.  To represent these in your text
  10867. file, use `\N'.  For example, the record for Whistler the bird would
  10868. look like this (where the whitespace between values is a single tab
  10869. character):
  10870.  
  10871. *name*  *owner* *species**sex**birth*     *death*
  10872. `Whistler'`Gwen'  `bird'  `\N' `1997-12-09'`\N'
  10873.  
  10874. To load the text file `pet.txt' into the `pet' table, use this command:
  10875.  
  10876.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  10877.  
  10878. You can specify the column value separator and end of line marker
  10879. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  10880. are tab and linefeed.  These are sufficient for the statement to read
  10881. the file `pet.txt' properly.
  10882.  
  10883. When you want to add new records one at a time, the `INSERT' statement
  10884. is useful.  In its simplest form, you supply values for each column, in
  10885. the order in which the columns were listed in the `CREATE TABLE'
  10886. statement.  Suppose Diane gets a new hamster named Puffball.  You could
  10887. add a new record using an `INSERT' statement like this:
  10888.  
  10889.      mysql> INSERT INTO pet
  10890.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  10891.  
  10892. Note that string and date values are specified as quoted strings here.
  10893. Also, with `INSERT', you can insert `NULL' directly to represent a
  10894. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  10895.  
  10896. From this example, you should be able to see that there would be a lot
  10897. more typing involved to load your records initially using several
  10898. `INSERT' statements rather than a single `LOAD DATA' statement.
  10899.  
  10900. Retrieving Information from a Table
  10901. -----------------------------------
  10902.  
  10903. The `SELECT' statement is used to pull information from a table.  The
  10904. general form of the statement is:
  10905.  
  10906.      SELECT what_to_select
  10907.      FROM which_table
  10908.      WHERE conditions_to_satisfy
  10909.  
  10910. `what_to_select' indicates what you want to see.  This can be a list of
  10911. columns, or `*' to indicate "all columns." `which_table' indicates the
  10912. table from which you want to retrieve data.  The `WHERE' clause is
  10913. optional.  If it's present, `conditions_to_satisfy' specifies
  10914. conditions that rows must satisfy to qualify for retrieval.
  10915.  
  10916. Selecting All Data
  10917. ..................
  10918.  
  10919. The simplest form of `SELECT' retrieves everything from a table:
  10920.  
  10921.      mysql> SELECT * FROM pet;
  10922.      +----------+--------+---------+------+------------+------------+
  10923.      | name     | owner  | species | sex  | birth      | death      |
  10924.      +----------+--------+---------+------+------------+------------+
  10925.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  10926.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  10927.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  10928.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  10929.      | Bowser   | Diane  | dog     | m    | 1998-08-31 | 1995-07-29 |
  10930.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  10931.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  10932.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  10933.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  10934.      +----------+--------+---------+------+------------+------------+
  10935.  
  10936. This form of `SELECT' is useful if you want to review your entire table,
  10937. for instance, after you've just loaded it with your initial dataset.
  10938. As it happens, the output just shown reveals an error in your datafile:
  10939. Bowser appears to have been born after he died!  Consulting your
  10940. original pedigree papers, you find that the correct birth year is 1989,
  10941. not 1998.
  10942.  
  10943. There are least a couple of ways to fix this:
  10944.  
  10945.    * Edit the file `pet.txt' to correct the error, then empty the table
  10946.      and reload it using `DELETE' and `LOAD DATA':
  10947.  
  10948.           mysql> SET AUTOCOMMIT=1;  # Used for quick re-create of the table
  10949.           mysql> DELETE FROM pet;
  10950.           mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  10951.  
  10952.      However, if you do this, you must also re-enter the record for
  10953.      Puffball.
  10954.  
  10955.    * Fix only the erroneous record with an `UPDATE' statement:
  10956.  
  10957.           mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
  10958.  
  10959. As shown above, it is easy to retrieve an entire table.  But typically
  10960. you don't want to do that, particularly when the table becomes large.
  10961. Instead, you're usually more interested in answering a particular
  10962. question, in which case you specify some constraints on the information
  10963. you want.  Let's look at some selection queries in terms of questions
  10964. about your pets that they answer.
  10965.  
  10966. Selecting Particular Rows
  10967. .........................
  10968.  
  10969. You can select only particular rows from your table.  For example, if
  10970. you want to verify the change that you made to Bowser's birth date,
  10971. select Bowser's record like this:
  10972.  
  10973.      mysql> SELECT * FROM pet WHERE name = "Bowser";
  10974.      +--------+-------+---------+------+------------+------------+
  10975.      | name   | owner | species | sex  | birth      | death      |
  10976.      +--------+-------+---------+------+------------+------------+
  10977.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  10978.      +--------+-------+---------+------+------------+------------+
  10979.  
  10980. The output confirms that the year is correctly recorded now as 1989,
  10981. not 1998.
  10982.  
  10983. String comparisons are normally case-insensitive, so you can specify the
  10984. name as `"bowser"', `"BOWSER"', etc.  The query result will be the same.
  10985.  
  10986. You can specify conditions on any column, not just `name'.  For example,
  10987. if you want to know which animals were born after 1998, test the `birth'
  10988. column:
  10989.  
  10990.      mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
  10991.      +----------+-------+---------+------+------------+-------+
  10992.      | name     | owner | species | sex  | birth      | death |
  10993.      +----------+-------+---------+------+------------+-------+
  10994.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  10995.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  10996.      +----------+-------+---------+------+------------+-------+
  10997.  
  10998. You can combine conditions, for example, to locate female dogs:
  10999.  
  11000.      mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
  11001.      +-------+--------+---------+------+------------+-------+
  11002.      | name  | owner  | species | sex  | birth      | death |
  11003.      +-------+--------+---------+------+------------+-------+
  11004.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11005.      +-------+--------+---------+------+------------+-------+
  11006.  
  11007. The preceding query uses the `AND' logical operator.  There is also an
  11008. `OR' operator:
  11009.  
  11010.      mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
  11011.      +----------+-------+---------+------+------------+-------+
  11012.      | name     | owner | species | sex  | birth      | death |
  11013.      +----------+-------+---------+------+------------+-------+
  11014.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  11015.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  11016.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  11017.      +----------+-------+---------+------+------------+-------+
  11018.  
  11019. `AND' and `OR' may be intermixed.  If you do that, it's a good idea to
  11020. use parentheses to indicate how conditions should be grouped:
  11021.  
  11022.      mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
  11023.          -> OR (species = "dog" AND sex = "f");
  11024.      +-------+--------+---------+------+------------+-------+
  11025.      | name  | owner  | species | sex  | birth      | death |
  11026.      +-------+--------+---------+------+------------+-------+
  11027.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11028.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11029.      +-------+--------+---------+------+------------+-------+
  11030.  
  11031. Selecting Particular Columns
  11032. ............................
  11033.  
  11034. If you don't want to see entire rows from your table, just name the
  11035. columns in which you're interested, separated by commas.  For example,
  11036. if you want to know when your animals were born, select the `name' and
  11037. `birth' columns:
  11038.  
  11039.      mysql> SELECT name, birth FROM pet;
  11040.      +----------+------------+
  11041.      | name     | birth      |
  11042.      +----------+------------+
  11043.      | Fluffy   | 1993-02-04 |
  11044.      | Claws    | 1994-03-17 |
  11045.      | Buffy    | 1989-05-13 |
  11046.      | Fang     | 1990-08-27 |
  11047.      | Bowser   | 1989-08-31 |
  11048.      | Chirpy   | 1998-09-11 |
  11049.      | Whistler | 1997-12-09 |
  11050.      | Slim     | 1996-04-29 |
  11051.      | Puffball | 1999-03-30 |
  11052.      +----------+------------+
  11053.  
  11054. To find out who owns pets, use this query:
  11055.  
  11056.      mysql> SELECT owner FROM pet;
  11057.      +--------+
  11058.      | owner  |
  11059.      +--------+
  11060.      | Harold |
  11061.      | Gwen   |
  11062.      | Harold |
  11063.      | Benny  |
  11064.      | Diane  |
  11065.      | Gwen   |
  11066.      | Gwen   |
  11067.      | Benny  |
  11068.      | Diane  |
  11069.      +--------+
  11070.  
  11071. However, notice that the query simply retrieves the `owner' field from
  11072. each record, and some of them appear more than once.  To minimise the
  11073. output, retrieve each unique output record just once by adding the
  11074. keyword `DISTINCT':
  11075.  
  11076.      mysql> SELECT DISTINCT owner FROM pet;
  11077.      +--------+
  11078.      | owner  |
  11079.      +--------+
  11080.      | Benny  |
  11081.      | Diane  |
  11082.      | Gwen   |
  11083.      | Harold |
  11084.      +--------+
  11085.  
  11086. You can use a `WHERE' clause to combine row selection with column
  11087. selection.  For example, to get birth dates for dogs and cats only, use
  11088. this query:
  11089.  
  11090.      mysql> SELECT name, species, birth FROM pet
  11091.          -> WHERE species = "dog" OR species = "cat";
  11092.      +--------+---------+------------+
  11093.      | name   | species | birth      |
  11094.      +--------+---------+------------+
  11095.      | Fluffy | cat     | 1993-02-04 |
  11096.      | Claws  | cat     | 1994-03-17 |
  11097.      | Buffy  | dog     | 1989-05-13 |
  11098.      | Fang   | dog     | 1990-08-27 |
  11099.      | Bowser | dog     | 1989-08-31 |
  11100.      +--------+---------+------------+
  11101.  
  11102. Sorting Rows
  11103. ............
  11104.  
  11105. You may have noticed in the preceding examples that the result rows are
  11106. displayed in no particular order.  However, it's often easier to examine
  11107. query output when the rows are sorted in some meaningful way.  To sort a
  11108. result, use an `ORDER BY' clause.
  11109.  
  11110. Here are animal birthdays, sorted by date:
  11111.  
  11112.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  11113.      +----------+------------+
  11114.      | name     | birth      |
  11115.      +----------+------------+
  11116.      | Buffy    | 1989-05-13 |
  11117.      | Bowser   | 1989-08-31 |
  11118.      | Fang     | 1990-08-27 |
  11119.      | Fluffy   | 1993-02-04 |
  11120.      | Claws    | 1994-03-17 |
  11121.      | Slim     | 1996-04-29 |
  11122.      | Whistler | 1997-12-09 |
  11123.      | Chirpy   | 1998-09-11 |
  11124.      | Puffball | 1999-03-30 |
  11125.      +----------+------------+
  11126.  
  11127. On character type columns, sortinglike all other comparison
  11128. operationsis normally performed in a case-insensitive fashion.  This
  11129. means that the order will be undefined for columns that are identical
  11130. except for their case. You can force a case-sensitive sort by using the
  11131. BINARY cast: `ORDER BY BINARY(field)'.
  11132.  
  11133. To sort in reverse order, add the `DESC' (descending) keyword to the
  11134. name of the column you are sorting by:
  11135.  
  11136.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  11137.      +----------+------------+
  11138.      | name     | birth      |
  11139.      +----------+------------+
  11140.      | Puffball | 1999-03-30 |
  11141.      | Chirpy   | 1998-09-11 |
  11142.      | Whistler | 1997-12-09 |
  11143.      | Slim     | 1996-04-29 |
  11144.      | Claws    | 1994-03-17 |
  11145.      | Fluffy   | 1993-02-04 |
  11146.      | Fang     | 1990-08-27 |
  11147.      | Bowser   | 1989-08-31 |
  11148.      | Buffy    | 1989-05-13 |
  11149.      +----------+------------+
  11150.  
  11151. You can sort on multiple columns.  For example, to sort by type of
  11152. animal, then by birth date within animal type with youngest animals
  11153. first, use the following query:
  11154.  
  11155.      mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
  11156.      +----------+---------+------------+
  11157.      | name     | species | birth      |
  11158.      +----------+---------+------------+
  11159.      | Chirpy   | bird    | 1998-09-11 |
  11160.      | Whistler | bird    | 1997-12-09 |
  11161.      | Claws    | cat     | 1994-03-17 |
  11162.      | Fluffy   | cat     | 1993-02-04 |
  11163.      | Fang     | dog     | 1990-08-27 |
  11164.      | Bowser   | dog     | 1989-08-31 |
  11165.      | Buffy    | dog     | 1989-05-13 |
  11166.      | Puffball | hamster | 1999-03-30 |
  11167.      | Slim     | snake   | 1996-04-29 |
  11168.      +----------+---------+------------+
  11169.  
  11170. Note that the `DESC' keyword applies only to the column name immediately
  11171. preceding it (`birth'); `species' values are still sorted in ascending
  11172. order.
  11173.  
  11174. Date Calculations
  11175. .................
  11176.  
  11177. MySQL provides several functions that you can use to perform
  11178. calculations on dates, for example, to calculate ages or extract parts
  11179. of dates.
  11180.  
  11181. To determine how many years old each of your pets is, compute the
  11182. difference in the year part of the current date and the birth date, then
  11183. subtract one if the current date occurs earlier in the calendar year
  11184. than the birth date.  The following query shows, for each pet, the
  11185. birth date, the current date, and the age in years.
  11186.  
  11187.      mysql> SELECT name, birth, CURRENT_DATE,
  11188.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  11189.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  11190.          -> AS age
  11191.          -> FROM pet;
  11192.      +----------+------------+--------------+------+
  11193.      | name     | birth      | CURRENT_DATE | age  |
  11194.      +----------+------------+--------------+------+
  11195.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  11196.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  11197.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  11198.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  11199.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  11200.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  11201.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  11202.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  11203.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  11204.      +----------+------------+--------------+------+
  11205.  
  11206. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  11207. off the rightmost five characters that represent the `MM-DD' (calendar
  11208. year) part of the date.  The part of the expression that compares the
  11209. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  11210. down a year if `CURRENT_DATE' occurs earlier in the year than `birth'.
  11211. The full expression is somewhat ungainly, so an alias (`age') is used
  11212. to make the output column label more meaningful.
  11213.  
  11214. The query works, but the result could be scanned more easily if the rows
  11215. were presented in some order.  This can be done by adding an `ORDER BY
  11216. name' clause to sort the output by name:
  11217.  
  11218.      mysql> SELECT name, birth, CURRENT_DATE,
  11219.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  11220.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  11221.          -> AS age
  11222.          -> FROM pet ORDER BY name;
  11223.      +----------+------------+--------------+------+
  11224.      | name     | birth      | CURRENT_DATE | age  |
  11225.      +----------+------------+--------------+------+
  11226.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  11227.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  11228.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  11229.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  11230.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  11231.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  11232.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  11233.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  11234.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  11235.      +----------+------------+--------------+------+
  11236.  
  11237. To sort the output by `age' rather than `name', just use a different
  11238. `ORDER BY' clause:
  11239.  
  11240.      mysql> SELECT name, birth, CURRENT_DATE,
  11241.          -> (YEAR(CURRENT_DATE)-YEAR(birth))
  11242.          -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
  11243.          -> AS age
  11244.          -> FROM pet ORDER BY age;
  11245.      +----------+------------+--------------+------+
  11246.      | name     | birth      | CURRENT_DATE | age  |
  11247.      +----------+------------+--------------+------+
  11248.      | Chirpy   | 1998-09-11 | 2001-08-29   |    2 |
  11249.      | Puffball | 1999-03-30 | 2001-08-29   |    2 |
  11250.      | Whistler | 1997-12-09 | 2001-08-29   |    3 |
  11251.      | Slim     | 1996-04-29 | 2001-08-29   |    5 |
  11252.      | Claws    | 1994-03-17 | 2001-08-29   |    7 |
  11253.      | Fluffy   | 1993-02-04 | 2001-08-29   |    8 |
  11254.      | Fang     | 1990-08-27 | 2001-08-29   |   11 |
  11255.      | Bowser   | 1989-08-31 | 2001-08-29   |   11 |
  11256.      | Buffy    | 1989-05-13 | 2001-08-29   |   12 |
  11257.      +----------+------------+--------------+------+
  11258.  
  11259. A similar query can be used to determine age at death for animals that
  11260. have died.  You determine which animals these are by checking whether
  11261. the `death' value is `NULL'.  Then, for those with non-`NULL' values,
  11262. compute the difference between the `death' and `birth' values:
  11263.  
  11264.      mysql> SELECT name, birth, death,
  11265.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  11266.          -> AS age
  11267.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  11268.      +--------+------------+------------+------+
  11269.      | name   | birth      | death      | age  |
  11270.      +--------+------------+------------+------+
  11271.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  11272.      +--------+------------+------------+------+
  11273.  
  11274. The query uses `death IS NOT NULL' rather than `death <> NULL' because
  11275. `NULL' is a special value.  This is explained later.  *Note Working
  11276. with `NULL': Working with NULL.
  11277.  
  11278. What if you want to know which animals have birthdays next month?  For
  11279. this type of calculation, year and day are irrelevant; you simply want
  11280. to extract the month part of the `birth' column.  MySQL provides several
  11281. date-part extraction functions, such as `YEAR()', `MONTH()', and
  11282. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  11283. how it works, run a simple query that displays the value of both
  11284. `birth' and `MONTH(birth)':
  11285.  
  11286.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  11287.      +----------+------------+--------------+
  11288.      | name     | birth      | MONTH(birth) |
  11289.      +----------+------------+--------------+
  11290.      | Fluffy   | 1993-02-04 |            2 |
  11291.      | Claws    | 1994-03-17 |            3 |
  11292.      | Buffy    | 1989-05-13 |            5 |
  11293.      | Fang     | 1990-08-27 |            8 |
  11294.      | Bowser   | 1989-08-31 |            8 |
  11295.      | Chirpy   | 1998-09-11 |            9 |
  11296.      | Whistler | 1997-12-09 |           12 |
  11297.      | Slim     | 1996-04-29 |            4 |
  11298.      | Puffball | 1999-03-30 |            3 |
  11299.      +----------+------------+--------------+
  11300.  
  11301. Finding animals with birthdays in the upcoming month is easy, too.
  11302. Suppose the current month is April.  Then the month value is `4' and
  11303. you look for animals born in May (month 5) like this:
  11304.  
  11305.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  11306.      +-------+------------+
  11307.      | name  | birth      |
  11308.      +-------+------------+
  11309.      | Buffy | 1989-05-13 |
  11310.      +-------+------------+
  11311.  
  11312. There is a small complication if the current month is December, of
  11313. course.  You don't just add one to the month number (`12') and look for
  11314. animals born in month 13, because there is no such month.  Instead, you
  11315. look for animals born in January (month 1).
  11316.  
  11317. You can even write the query so that it works no matter what the current
  11318. month is.  That way you don't have to use a particular month number in
  11319. the query.  `DATE_ADD()' allows you to add a time interval to a given
  11320. date.  If you add a month to the value of `NOW()', then extract the
  11321. month part with `MONTH()', the result produces the month in which to
  11322. look for birthdays:
  11323.  
  11324.      mysql> SELECT name, birth FROM pet
  11325.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(NOW(), INTERVAL 1 MONTH));
  11326.  
  11327. A different way to accomplish the same task is to add `1' to get the
  11328. next month after the current one (after using the modulo function
  11329. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  11330.  
  11331.      mysql> SELECT name, birth FROM pet
  11332.          -> WHERE MONTH(birth) = MOD(MONTH(NOW()), 12) + 1;
  11333.  
  11334. Note that `MONTH' returns a number between 1 and 12. And
  11335. `MOD(something,12)' returns a number between 0 and 11. So the addition
  11336. has to be after the `MOD()', otherwise we would go from November (11)
  11337. to January (1).
  11338.  
  11339. Working with `NULL' Values
  11340. ..........................
  11341.  
  11342. The `NULL' value can be surprising until you get used to it.
  11343. Conceptually, `NULL' means missing value or unknown value and it is
  11344. treated somewhat differently than other values.  To test for `NULL',
  11345. you cannot use the arithmetic comparison operators such as `=', `<', or
  11346. `<>'.  To demonstrate this for yourself, try the following query:
  11347.  
  11348.      mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
  11349.      +----------+-----------+----------+----------+
  11350.      | 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |
  11351.      +----------+-----------+----------+----------+
  11352.      |     NULL |      NULL |     NULL |     NULL |
  11353.      +----------+-----------+----------+----------+
  11354.  
  11355. Clearly you get no meaningful results from these comparisons.  Use the
  11356. `IS NULL' and `IS NOT NULL' operators instead:
  11357.  
  11358.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  11359.      +-----------+---------------+
  11360.      | 1 IS NULL | 1 IS NOT NULL |
  11361.      +-----------+---------------+
  11362.      |         0 |             1 |
  11363.      +-----------+---------------+
  11364.  
  11365. Note that in MySQL, 0 or `NULL' means false and anything else means
  11366. true. The default truth value from a boolean operation is 1.
  11367.  
  11368. This special treatment of `NULL' is why, in the previous section, it
  11369. was necessary to determine which animals are no longer alive using
  11370. `death IS NOT NULL' instead of `death <> NULL'.
  11371.  
  11372. Two `NULL' values are regarded as equal in a `GROUP BY'.
  11373.  
  11374. When doing an `ORDER BY', `NULL' values are presented first.  In
  11375. versions prior to 4.0.2, if you sort in descending order using `DESC',
  11376. `NULL' values are presented last.
  11377.  
  11378. Pattern Matching
  11379. ................
  11380.  
  11381. MySQL provides standard SQL pattern matching as well as a form of
  11382. pattern matching based on extended regular expressions similar to those
  11383. used by Unix utilities such as `vi', `grep', and `sed'.
  11384.  
  11385. SQL pattern matching allows you to use `_' to match any single
  11386. character and `%' to match an arbitrary number of characters (including
  11387. zero characters).  In MySQL, SQL patterns are case-insensitive by
  11388. default.  Some examples are shown here.  Note that you do not use `='
  11389. or `<>' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  11390. comparison operators instead.
  11391.  
  11392. To find names beginning with `b':
  11393.  
  11394.      mysql> SELECT * FROM pet WHERE name LIKE "b%";
  11395.      +--------+--------+---------+------+------------+------------+
  11396.      | name   | owner  | species | sex  | birth      | death      |
  11397.      +--------+--------+---------+------+------------+------------+
  11398.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  11399.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  11400.      +--------+--------+---------+------+------------+------------+
  11401.  
  11402. To find names ending with `fy':
  11403.  
  11404.      mysql> SELECT * FROM pet WHERE name LIKE "%fy";
  11405.      +--------+--------+---------+------+------------+-------+
  11406.      | name   | owner  | species | sex  | birth      | death |
  11407.      +--------+--------+---------+------+------------+-------+
  11408.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  11409.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  11410.      +--------+--------+---------+------+------------+-------+
  11411.  
  11412. To find names containing a `w':
  11413.  
  11414.      mysql> SELECT * FROM pet WHERE name LIKE "%w%";
  11415.      +----------+-------+---------+------+------------+------------+
  11416.      | name     | owner | species | sex  | birth      | death      |
  11417.      +----------+-------+---------+------+------------+------------+
  11418.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  11419.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  11420.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  11421.      +----------+-------+---------+------+------------+------------+
  11422.  
  11423. To find names containing exactly five characters, use the `_' pattern
  11424. character:
  11425.  
  11426.      mysql> SELECT * FROM pet WHERE name LIKE "_____";
  11427.      +-------+--------+---------+------+------------+-------+
  11428.      | name  | owner  | species | sex  | birth      | death |
  11429.      +-------+--------+---------+------+------------+-------+
  11430.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11431.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11432.      +-------+--------+---------+------+------------+-------+
  11433.  
  11434. The other type of pattern matching provided by MySQL uses extended
  11435. regular expressions.  When you test for a match for this type of
  11436. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  11437. `NOT RLIKE', which are synonyms).
  11438.  
  11439. Some characteristics of extended regular expressions are:
  11440.  
  11441.    * `.' matches any single character.
  11442.  
  11443.    * A character class `[...]' matches any character within the
  11444.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  11445.      a range of characters, use a dash.  `[a-z]' matches any lowercase
  11446.      letter, whereas `[0-9]' matches any digit.
  11447.  
  11448.    * `*' matches zero or more instances of the thing preceding it.  For
  11449.      example, `x*' matches any number of `x' characters, `[0-9]*'
  11450.      matches any number of digits, and `.*' matches any number of
  11451.      anything.
  11452.  
  11453.    * The pattern matches if it occurs anywhere in the value being
  11454.      tested.  (SQL patterns match only if they match the entire value.)
  11455.  
  11456.    * To anchor a pattern so that it must match the beginning or end of
  11457.      the value being tested, use `^' at the beginning or `$' at the end
  11458.      of the pattern.
  11459.  
  11460. To demonstrate how extended regular expressions work, the `LIKE' queries
  11461. shown previously are rewritten here to use `REGEXP'.
  11462.  
  11463. To find names beginning with `b', use `^' to match the beginning of the
  11464. name:
  11465.  
  11466.      mysql> SELECT * FROM pet WHERE name REGEXP "^b";
  11467.      +--------+--------+---------+------+------------+------------+
  11468.      | name   | owner  | species | sex  | birth      | death      |
  11469.      +--------+--------+---------+------+------------+------------+
  11470.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  11471.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  11472.      +--------+--------+---------+------+------------+------------+
  11473.  
  11474. Prior to MySQL Version 3.23.4, `REGEXP' is case-sensitive, and the
  11475. previous query will return no rows. To match either lowercase or
  11476. uppercase `b', use this query instead:
  11477.  
  11478.      mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
  11479.  
  11480. From MySQL 3.23.4 on, to force a `REGEXP' comparison to be
  11481. case-sensitive, use the `BINARY' keyword to make one of the strings a
  11482. binary string. This query will match only lowercase `b' at the
  11483. beginning of a name:
  11484.  
  11485.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY "^b";
  11486.  
  11487. To find names ending with `fy', use `$' to match the end of the name:
  11488.  
  11489.      mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
  11490.      +--------+--------+---------+------+------------+-------+
  11491.      | name   | owner  | species | sex  | birth      | death |
  11492.      +--------+--------+---------+------+------------+-------+
  11493.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  11494.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  11495.      +--------+--------+---------+------+------------+-------+
  11496.  
  11497. To find names containing a lowercase or uppercase `w', use this query:
  11498.  
  11499.      mysql> SELECT * FROM pet WHERE name REGEXP "w";
  11500.      +----------+-------+---------+------+------------+------------+
  11501.      | name     | owner | species | sex  | birth      | death      |
  11502.      +----------+-------+---------+------+------------+------------+
  11503.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  11504.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  11505.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  11506.      +----------+-------+---------+------+------------+------------+
  11507.  
  11508. Because a regular expression pattern matches if it occurs anywhere in
  11509. the value, it is not necessary in the previous query to put a wildcard
  11510. on either side of the pattern to get it to match the entire value like
  11511. it would be if you used a SQL pattern.
  11512.  
  11513. To find names containing exactly five characters, use `^' and `$' to
  11514. match the beginning and end of the name, and five instances of `.' in
  11515. between:
  11516.  
  11517.      mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
  11518.      +-------+--------+---------+------+------------+-------+
  11519.      | name  | owner  | species | sex  | birth      | death |
  11520.      +-------+--------+---------+------+------------+-------+
  11521.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11522.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11523.      +-------+--------+---------+------+------------+-------+
  11524.  
  11525. You could also write the previous query using the `{n}'
  11526. "repeat-`n'-times" operator:
  11527.  
  11528.      mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
  11529.      +-------+--------+---------+------+------------+-------+
  11530.      | name  | owner  | species | sex  | birth      | death |
  11531.      +-------+--------+---------+------+------------+-------+
  11532.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11533.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11534.      +-------+--------+---------+------+------------+-------+
  11535.  
  11536. Counting Rows
  11537. .............
  11538.  
  11539. Databases are often used to answer the question, "How often does a
  11540. certain type of data occur in a table?"  For example, you might want to
  11541. know how many pets you have, or how many pets each owner has, or you
  11542. might want to perform various kinds of censuses on your animals.
  11543.  
  11544. Counting the total number of animals you have is the same question as
  11545. "How many rows are in the `pet' table?" because there is one record per
  11546. pet.  The `COUNT()' function counts the number of non-`NULL' results, so
  11547. the query to count your animals looks like this:
  11548.  
  11549.      mysql> SELECT COUNT(*) FROM pet;
  11550.      +----------+
  11551.      | COUNT(*) |
  11552.      +----------+
  11553.      |        9 |
  11554.      +----------+
  11555.  
  11556. Earlier, you retrieved the names of the people who owned pets.  You can
  11557. use `COUNT()' if you want to find out how many pets each owner has:
  11558.  
  11559.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  11560.      +--------+----------+
  11561.      | owner  | COUNT(*) |
  11562.      +--------+----------+
  11563.      | Benny  |        2 |
  11564.      | Diane  |        2 |
  11565.      | Gwen   |        3 |
  11566.      | Harold |        2 |
  11567.      +--------+----------+
  11568.  
  11569. Note the use of `GROUP BY' to group together all records for each
  11570. `owner'.  Without it, all you get is an error message:
  11571.  
  11572.      mysql> SELECT owner, COUNT(owner) FROM pet;
  11573.      ERROR 1140 at line 1: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  11574.      with no GROUP columns is illegal if there is no GROUP BY clause
  11575.  
  11576. `COUNT()' and `GROUP BY' are useful for characterising your data in
  11577. various ways.  The following examples show different ways to perform
  11578. animal census operations.
  11579.  
  11580. Number of animals per species:
  11581.  
  11582.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  11583.      +---------+----------+
  11584.      | species | COUNT(*) |
  11585.      +---------+----------+
  11586.      | bird    |        2 |
  11587.      | cat     |        2 |
  11588.      | dog     |        3 |
  11589.      | hamster |        1 |
  11590.      | snake   |        1 |
  11591.      +---------+----------+
  11592.  
  11593. Number of animals per sex:
  11594.  
  11595.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  11596.      +------+----------+
  11597.      | sex  | COUNT(*) |
  11598.      +------+----------+
  11599.      | NULL |        1 |
  11600.      | f    |        4 |
  11601.      | m    |        4 |
  11602.      +------+----------+
  11603.  
  11604. (In this output, `NULL' indicates sex unknown.)
  11605.  
  11606. Number of animals per combination of species and sex:
  11607.  
  11608.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  11609.      +---------+------+----------+
  11610.      | species | sex  | COUNT(*) |
  11611.      +---------+------+----------+
  11612.      | bird    | NULL |        1 |
  11613.      | bird    | f    |        1 |
  11614.      | cat     | f    |        1 |
  11615.      | cat     | m    |        1 |
  11616.      | dog     | f    |        1 |
  11617.      | dog     | m    |        2 |
  11618.      | hamster | f    |        1 |
  11619.      | snake   | m    |        1 |
  11620.      +---------+------+----------+
  11621.  
  11622. You need not retrieve an entire table when you use `COUNT()'.  For
  11623. example, the previous query, when performed just on dogs and cats,
  11624. looks like this:
  11625.  
  11626.      mysql> SELECT species, sex, COUNT(*) FROM pet
  11627.          -> WHERE species = "dog" OR species = "cat"
  11628.          -> GROUP BY species, sex;
  11629.      +---------+------+----------+
  11630.      | species | sex  | COUNT(*) |
  11631.      +---------+------+----------+
  11632.      | cat     | f    |        1 |
  11633.      | cat     | m    |        1 |
  11634.      | dog     | f    |        1 |
  11635.      | dog     | m    |        2 |
  11636.      +---------+------+----------+
  11637.  
  11638. Or, if you wanted the number of animals per sex only for known-sex
  11639. animals:
  11640.  
  11641.      mysql> SELECT species, sex, COUNT(*) FROM pet
  11642.          -> WHERE sex IS NOT NULL
  11643.          -> GROUP BY species, sex;
  11644.      +---------+------+----------+
  11645.      | species | sex  | COUNT(*) |
  11646.      +---------+------+----------+
  11647.      | bird    | f    |        1 |
  11648.      | cat     | f    |        1 |
  11649.      | cat     | m    |        1 |
  11650.      | dog     | f    |        1 |
  11651.      | dog     | m    |        2 |
  11652.      | hamster | f    |        1 |
  11653.      | snake   | m    |        1 |
  11654.      +---------+------+----------+
  11655.  
  11656. Using More Than one Table
  11657. .........................
  11658.  
  11659. The `pet' table keeps track of which pets you have.  If you want to
  11660. record other information about them, such as events in their lives like
  11661. visits to the vet or when litters are born, you need another table.
  11662. What should this table look like? It needs:
  11663.  
  11664.    * To contain the pet name so you know which animal each event
  11665.      pertains to.
  11666.  
  11667.    * A date so you know when the event occurred.
  11668.  
  11669.    * A field to describe the event.
  11670.  
  11671.    * An event type field, if you want to be able to categorise events.
  11672.  
  11673. Given these considerations, the `CREATE TABLE' statement for the
  11674. `event' table might look like this:
  11675.  
  11676.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  11677.          -> type VARCHAR(15), remark VARCHAR(255));
  11678.  
  11679. As with the `pet' table, it's easiest to load the initial records by
  11680. creating a tab-delimited text file containing the information:
  11681.  
  11682. *name*  *date*      *type*  *remark*
  11683. Fluffy  1995-05-15  litter  4 kittens, 3 female, 1
  11684.                             male
  11685. Buffy   1993-06-23  litter  5 puppies, 2 female, 3
  11686.                             male
  11687. Buffy   1994-06-19  litter  3 puppies, 3 female
  11688. Chirpy  1999-03-21  vet     needed beak straightened
  11689. Slim    1997-08-03  vet     broken rib
  11690. Bowser  1991-10-12  kennel  
  11691. Fang    1991-10-12  kennel  
  11692. Fang    1998-08-28  birthdayGave him a new chew toy
  11693. Claws   1998-03-17  birthdayGave him a new flea
  11694.                             collar
  11695. Whistler1998-12-09  birthdayFirst birthday
  11696.  
  11697. Load the records like this:
  11698.  
  11699.      mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
  11700.  
  11701. Based on what you've learned from the queries you've run on the `pet'
  11702. table, you should be able to perform retrievals on the records in the
  11703. `event' table; the principles are the same.  But when is the `event'
  11704. table by itself insufficient to answer questions you might ask?
  11705.  
  11706. Suppose you want to find out the ages of each pet when they had their
  11707. litters.  The `event' table indicates when this occurred, but to
  11708. calculate the age of the mother, you need her birth date.  Because that
  11709. is stored in the `pet' table, you need both tables for the query:
  11710.  
  11711.      mysql> SELECT pet.name,
  11712.          -> (TO_DAYS(date) - TO_DAYS(birth))/365 AS age,
  11713.          -> remark
  11714.          -> FROM pet, event
  11715.          -> WHERE pet.name = event.name AND type = "litter";
  11716.      +--------+------+-----------------------------+
  11717.      | name   | age  | remark                      |
  11718.      +--------+------+-----------------------------+
  11719.      | Fluffy | 2.27 | 4 kittens, 3 female, 1 male |
  11720.      | Buffy  | 4.12 | 5 puppies, 2 female, 3 male |
  11721.      | Buffy  | 5.10 | 3 puppies, 3 female         |
  11722.      +--------+------+-----------------------------+
  11723.  
  11724. There are several things to note about this query:
  11725.  
  11726.    * The `FROM' clause lists two tables because the query needs to pull
  11727.      information from both of them.
  11728.  
  11729.    * When combining (joining) information from multiple tables, you
  11730.      need to specify how records in one table can be matched to records
  11731.      in the other.  This is easy because they both have a `name'
  11732.      column.  The query uses `WHERE' clause to match up records in the
  11733.      two tables based on the `name' values.
  11734.  
  11735.    * Because the `name' column occurs in both tables, you must be
  11736.      specific about which table you mean when referring to the column.
  11737.      This is done by prepending the table name to the column name.
  11738.  
  11739. You need not have two different tables to perform a join.  Sometimes it
  11740. is useful to join a table to itself, if you want to compare records in
  11741. a table to other records in that same table.  For example, to find
  11742. breeding pairs among your pets, you can join the `pet' table with
  11743. itself to pair up males and females of like species:
  11744.  
  11745.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  11746.          -> FROM pet AS p1, pet AS p2
  11747.          -> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
  11748.      +--------+------+--------+------+---------+
  11749.      | name   | sex  | name   | sex  | species |
  11750.      +--------+------+--------+------+---------+
  11751.      | Fluffy | f    | Claws  | m    | cat     |
  11752.      | Buffy  | f    | Fang   | m    | dog     |
  11753.      | Buffy  | f    | Bowser | m    | dog     |
  11754.      +--------+------+--------+------+---------+
  11755.  
  11756. In this query, we specify aliases for the table name in order to refer
  11757. to the columns and keep straight which instance of the table each
  11758. column reference is associated with.
  11759.  
  11760. Getting Information About Databases and Tables
  11761. ==============================================
  11762.  
  11763. What if you forget the name of a database or table, or what the
  11764. structure of a given table is (for example, what its columns are
  11765. called)?  MySQL addresses this problem through several statements that
  11766. provide information about the databases and tables it supports.
  11767.  
  11768. You have already seen `SHOW DATABASES', which lists the databases
  11769. managed by the server.  To find out which database is currently
  11770. selected, use the `DATABASE()' function:
  11771.  
  11772.      mysql> SELECT DATABASE();
  11773.      +------------+
  11774.      | DATABASE() |
  11775.      +------------+
  11776.      | menagerie  |
  11777.      +------------+
  11778.  
  11779. If you haven't selected any database yet, the result is blank.
  11780.  
  11781. To find out what tables the current database contains (for example, when
  11782. you're not sure about the name of a table), use this command:
  11783.  
  11784.      mysql> SHOW TABLES;
  11785.      +---------------------+
  11786.      | Tables in menagerie |
  11787.      +---------------------+
  11788.      | event               |
  11789.      | pet                 |
  11790.      +---------------------+
  11791.  
  11792. If you want to find out about the structure of a table, the `DESCRIBE'
  11793. command is useful; it displays information about each of a table's
  11794. columns:
  11795.  
  11796.      mysql> DESCRIBE pet;
  11797.      +---------+-------------+------+-----+---------+-------+
  11798.      | Field   | Type        | Null | Key | Default | Extra |
  11799.      +---------+-------------+------+-----+---------+-------+
  11800.      | name    | varchar(20) | YES  |     | NULL    |       |
  11801.      | owner   | varchar(20) | YES  |     | NULL    |       |
  11802.      | species | varchar(20) | YES  |     | NULL    |       |
  11803.      | sex     | char(1)     | YES  |     | NULL    |       |
  11804.      | birth   | date        | YES  |     | NULL    |       |
  11805.      | death   | date        | YES  |     | NULL    |       |
  11806.      +---------+-------------+------+-----+---------+-------+
  11807.  
  11808. `Field' indicates the column name, `Type' is the data type for the
  11809. column, `NULL' indicates whether the column can contain `NULL' values,
  11810. `Key' indicates whether the column is indexed, and `Default' specifies
  11811. the column's default value.
  11812.  
  11813. If you have indexes on a table, `SHOW INDEX FROM tbl_name' produces
  11814. information about them.
  11815.  
  11816. Examples of Common Queries
  11817. ==========================
  11818.  
  11819. Here are examples of how to solve some common problems with MySQL.
  11820.  
  11821. Some of the examples use the table `shop' to hold the price of each
  11822. article (item number) for certain traders (dealers).  Supposing that
  11823. each trader has a single fixed price per article, then (`article',
  11824. `dealer') is a primary key for the records.
  11825.  
  11826. Start the command-line tool `mysql' and select a database:
  11827.  
  11828.      mysql your-database-name
  11829.  
  11830. (In most MySQL installations, you can use the database-name 'test').
  11831.  
  11832. You can create the example table as:
  11833.  
  11834.      CREATE TABLE shop (
  11835.       article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  11836.       dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  11837.       price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  11838.       PRIMARY KEY(article, dealer));
  11839.      
  11840.      INSERT INTO shop VALUES
  11841.      (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
  11842.      (3,'D',1.25),(4,'D',19.95);
  11843.  
  11844. Okay, so the example data is:
  11845.  
  11846.      mysql> SELECT * FROM shop;
  11847.      
  11848.      +---------+--------+-------+
  11849.      | article | dealer | price |
  11850.      +---------+--------+-------+
  11851.      |    0001 | A      |  3.45 |
  11852.      |    0001 | B      |  3.99 |
  11853.      |    0002 | A      | 10.99 |
  11854.      |    0003 | B      |  1.45 |
  11855.      |    0003 | C      |  1.69 |
  11856.      |    0003 | D      |  1.25 |
  11857.      |    0004 | D      | 19.95 |
  11858.      +---------+--------+-------+
  11859.  
  11860. The Maximum Value for a Column
  11861. ------------------------------
  11862.  
  11863. "What's the highest item number?"
  11864.  
  11865.      SELECT MAX(article) AS article FROM shop
  11866.      
  11867.      +---------+
  11868.      | article |
  11869.      +---------+
  11870.      |       4 |
  11871.      +---------+
  11872.  
  11873. The Row Holding the Maximum of a Certain Column
  11874. -----------------------------------------------
  11875.  
  11876. "Find number, dealer, and price of the most expensive article."
  11877.  
  11878. In ANSI SQL this is easily done with a subquery:
  11879.  
  11880.      SELECT article, dealer, price
  11881.      FROM   shop
  11882.      WHERE  price=(SELECT MAX(price) FROM shop)
  11883.  
  11884. In MySQL (which does not yet have subselects), just do it in two steps:
  11885.  
  11886.   1. Get the maximum price value from the table with a `SELECT'
  11887.      statement.
  11888.  
  11889.   2. Using this value compile the actual query:
  11890.           SELECT article, dealer, price
  11891.           FROM   shop
  11892.           WHERE  price=19.95
  11893.  
  11894. Another solution is to sort all rows descending by price and only get
  11895. the first row using the MySQL-specific `LIMIT' clause:
  11896.  
  11897.      SELECT article, dealer, price
  11898.      FROM   shop
  11899.      ORDER BY price DESC
  11900.      LIMIT 1
  11901.  
  11902. *NOTE*:  If there are several most expensive articles (for example,
  11903. each 19.95) the `LIMIT' solution shows only one of them!
  11904.  
  11905. Maximum of Column per Group
  11906. ---------------------------
  11907.  
  11908. "What's the highest price per article?"
  11909.  
  11910.      SELECT article, MAX(price) AS price
  11911.      FROM   shop
  11912.      GROUP BY article
  11913.      
  11914.      +---------+-------+
  11915.      | article | price |
  11916.      +---------+-------+
  11917.      |    0001 |  3.99 |
  11918.      |    0002 | 10.99 |
  11919.      |    0003 |  1.69 |
  11920.      |    0004 | 19.95 |
  11921.      +---------+-------+
  11922.  
  11923. The Rows Holding the Group-wise Maximum of a Certain Field
  11924. ----------------------------------------------------------
  11925.  
  11926. "For each article, find the dealer(s) with the most expensive price."
  11927.  
  11928. In ANSI SQL, I'd do it with a subquery like this:
  11929.  
  11930.      SELECT article, dealer, price
  11931.      FROM   shop s1
  11932.      WHERE  price=(SELECT MAX(s2.price)
  11933.                    FROM shop s2
  11934.                    WHERE s1.article = s2.article);
  11935.  
  11936. In MySQL it's best do it in several steps:
  11937.  
  11938.   1. Get the list of (article,maxprice).
  11939.  
  11940.   2. For each article get the corresponding rows that have the stored
  11941.      maximum price.
  11942.  
  11943. This can easily be done with a temporary table:
  11944.  
  11945.      CREATE TEMPORARY TABLE tmp (
  11946.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  11947.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  11948.      
  11949.      LOCK TABLES shop read;
  11950.      
  11951.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  11952.      
  11953.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  11954.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  11955.      
  11956.      UNLOCK TABLES;
  11957.      
  11958.      DROP TABLE tmp;
  11959.  
  11960. If you don't use a `TEMPORARY' table, you must also lock the 'tmp'
  11961. table.
  11962.  
  11963. "Can it be done with a single query?"
  11964.  
  11965. Yes, but only by using a quite inefficient trick that I call the
  11966. "MAX-CONCAT trick":
  11967.  
  11968.      SELECT article,
  11969.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  11970.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  11971.      FROM   shop
  11972.      GROUP BY article;
  11973.      
  11974.      +---------+--------+-------+
  11975.      | article | dealer | price |
  11976.      +---------+--------+-------+
  11977.      |    0001 | B      |  3.99 |
  11978.      |    0002 | A      | 10.99 |
  11979.      |    0003 | C      |  1.69 |
  11980.      |    0004 | D      | 19.95 |
  11981.      +---------+--------+-------+
  11982.  
  11983. The last example can, of course, be made a bit more efficient by doing
  11984. the splitting of the concatenated column in the client.
  11985.  
  11986. Using user variables
  11987. --------------------
  11988.  
  11989. You can use MySQL user variables to remember results without having to
  11990. store them in temporary variables in the client.  *Note Variables::.
  11991.  
  11992. For example, to find the articles with the highest and lowest price you
  11993. can do:
  11994.  
  11995.      mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
  11996.      mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
  11997.      +---------+--------+-------+
  11998.      | article | dealer | price |
  11999.      +---------+--------+-------+
  12000.      |    0003 | D      |  1.25 |
  12001.      |    0004 | D      | 19.95 |
  12002.      +---------+--------+-------+
  12003.  
  12004. Using Foreign Keys
  12005. ------------------
  12006.  
  12007. In MySQL 3.23.44 and up, `InnoDB' tables supports checking of foreign
  12008. key constraints. *Note InnoDB::.  See also *Note ANSI diff Foreign
  12009. Keys::.
  12010.  
  12011. You don't actually need foreign keys to join 2 tables.  The only thing
  12012. MySQL currently doesn't do (in table types other than `InnoDB'), is
  12013. `CHECK' to make sure that the keys you use really exist in the table(s)
  12014. you're referencing and it doesn't automatically delete rows from a
  12015. table with a foreign key definition. If you use your keys like normal,
  12016. it'll work just fine:
  12017.  
  12018.      CREATE TABLE person (
  12019.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  12020.          name CHAR(60) NOT NULL,
  12021.          PRIMARY KEY (id)
  12022.      );
  12023.      
  12024.      CREATE TABLE shirt (
  12025.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  12026.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  12027.          color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  12028.          owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),
  12029.          PRIMARY KEY (id)
  12030.      );
  12031.      
  12032.      
  12033.      INSERT INTO person VALUES (NULL, 'Antonio Paz');
  12034.      
  12035.      INSERT INTO shirt VALUES
  12036.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  12037.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  12038.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  12039.      
  12040.      
  12041.      INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
  12042.      
  12043.      INSERT INTO shirt VALUES
  12044.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  12045.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  12046.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  12047.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  12048.      
  12049.      
  12050.      SELECT * FROM person;
  12051.      +----+---------------------+
  12052.      | id | name                |
  12053.      +----+---------------------+
  12054.      |  1 | Antonio Paz         |
  12055.      |  2 | Lilliana Angelovska |
  12056.      +----+---------------------+
  12057.      
  12058.      SELECT * FROM shirt;
  12059.      +----+---------+--------+-------+
  12060.      | id | style   | color  | owner |
  12061.      +----+---------+--------+-------+
  12062.      |  1 | polo    | blue   |     1 |
  12063.      |  2 | dress   | white  |     1 |
  12064.      |  3 | t-shirt | blue   |     1 |
  12065.      |  4 | dress   | orange |     2 |
  12066.      |  5 | polo    | red    |     2 |
  12067.      |  6 | dress   | blue   |     2 |
  12068.      |  7 | t-shirt | white  |     2 |
  12069.      +----+---------+--------+-------+
  12070.      
  12071.      
  12072.      SELECT s.* FROM person p, shirt s
  12073.       WHERE p.name LIKE 'Lilliana%'
  12074.         AND s.owner = p.id
  12075.         AND s.color <> 'white';
  12076.      
  12077.      +----+-------+--------+-------+
  12078.      | id | style | color  | owner |
  12079.      +----+-------+--------+-------+
  12080.      |  4 | dress | orange |     2 |
  12081.      |  5 | polo  | red    |     2 |
  12082.      |  6 | dress | blue   |     2 |
  12083.      +----+-------+--------+-------+
  12084.  
  12085. Searching on Two Keys
  12086. ---------------------
  12087.  
  12088. MySQL doesn't yet optimise when you search on two different keys
  12089. combined with `OR' (searching on one key with different `OR' parts is
  12090. optimised quite well):
  12091.  
  12092.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
  12093.      OR  field2_index = '1'
  12094.  
  12095. The reason is that we haven't yet had time to come up with an efficient
  12096. way to handle this in the general case. (The `AND' handling is, in
  12097. comparison, now completely general and works very well.)
  12098.  
  12099. For the moment you can solve this very efficiently by using a
  12100. `TEMPORARY' table. This type of optimisation is also very good if you
  12101. are using very complicated queries where the SQL server does the
  12102. optimisations in the wrong order.
  12103.  
  12104.      CREATE TEMPORARY TABLE tmp
  12105.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
  12106.      INSERT INTO tmp
  12107.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  12108.      SELECT * from tmp;
  12109.      DROP TABLE tmp;
  12110.  
  12111. The above way to solve this query is in effect a `UNION' of two queries.
  12112. *Note UNION::.
  12113.  
  12114. Calculating Visits Per Day
  12115. --------------------------
  12116.  
  12117. The following shows an idea of how you can use the bit group functions
  12118. to calculate the number of days per month a user has visited a web page.
  12119.  
  12120.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL,
  12121.                   day INT(2) UNSIGNED ZEROFILL);
  12122.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),
  12123.                  (2000,2,23),(2000,2,23);
  12124.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
  12125.             GROUP BY year,month;
  12126.      
  12127.      Which returns:
  12128.      
  12129.      +------+-------+------+
  12130.      | year | month | days |
  12131.      +------+-------+------+
  12132.      | 2000 |    01 |    3 |
  12133.      | 2000 |    02 |    2 |
  12134.      +------+-------+------+
  12135.  
  12136. The above calculates how many different days was used for a given
  12137. year/month combination, with automatic removal of duplicate entries.
  12138.  
  12139. Using `AUTO_INCREMENT'
  12140. ----------------------
  12141.  
  12142. The `AUTO_INCREMENT' attribute can be used to generate a unique
  12143. identity for new rows:
  12144.  
  12145.      CREATE TABLE animals (
  12146.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  12147.                   name CHAR(30) NOT NULL,
  12148.                   PRIMARY KEY (id)
  12149.                   );
  12150.      INSERT INTO animals (name) VALUES ("dog"),("cat"),("penguin"),
  12151.                                        ("lax"),("whale");
  12152.      SELECT * FROM animals;
  12153.      
  12154.      Which returns:
  12155.      
  12156.      +----+---------+
  12157.      | id | name    |
  12158.      +----+---------+
  12159.      |  1 | dog     |
  12160.      |  2 | cat     |
  12161.      |  3 | penguin |
  12162.      |  4 | lax     |
  12163.      |  5 | whale   |
  12164.      +----+---------+
  12165.  
  12166. You can retrieve the used `AUTO_INCREMENT' key with the
  12167. `LAST_INSERT_ID()' SQL function or the `mysql_insert_id()' API function.
  12168. Note: for a multi-row insert, `LAST_INSERT_ID()'/`mysql_insert_id()'
  12169. will actually return the `AUTO_INCREMENT' key from the *first* inserted
  12170. row. This allows multi-row inserts to be reproduced on other servers.
  12171.  
  12172. For MyISAM and BDB tables you can specify `AUTO_INCREMENT' on secondary
  12173. column in a multi-column key.  In this case the generated value for the
  12174. autoincrement column is calculated as `MAX(auto_increment_column)+1)
  12175. WHERE prefix=given-prefix'.  This is useful when you want to put data
  12176. into ordered groups.
  12177.  
  12178.      CREATE TABLE animals (
  12179.                   grp ENUM('fish','mammal','bird') NOT NULL,
  12180.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  12181.                   name CHAR(30) NOT NULL,
  12182.                   PRIMARY KEY (grp,id)
  12183.                   );
  12184.      INSERT INTO animals (grp,name) VALUES("mammal","dog"),("mammal","cat"),
  12185.                        ("bird","penguin"),("fish","lax"),("mammal","whale");
  12186.      SELECT * FROM animals ORDER BY grp,id;
  12187.      
  12188.      Which returns:
  12189.      
  12190.      +--------+----+---------+
  12191.      | grp    | id | name    |
  12192.      +--------+----+---------+
  12193.      | fish   |  1 | lax     |
  12194.      | mammal |  1 | dog     |
  12195.      | mammal |  2 | cat     |
  12196.      | mammal |  3 | whale   |
  12197.      | bird   |  1 | penguin |
  12198.      +--------+----+---------+
  12199.  
  12200. Note that in this case, the `AUTO_INCREMENT' value will be reused if you
  12201. delete the row with the biggest `AUTO_INCREMENT' value in any group.
  12202.  
  12203. Using `mysql' in Batch Mode
  12204. ===========================
  12205.  
  12206. In the previous sections, you used `mysql' interactively to enter
  12207. queries and view the results.  You can also run `mysql' in batch mode.
  12208. To do this, put the commands you want to run in a file, then tell
  12209. `mysql' to read its input from the file:
  12210.  
  12211.      shell> mysql < batch-file
  12212.  
  12213. If you are running `mysql' under windows and have some special
  12214. characters in the file that causes problems, you can do:
  12215.  
  12216.      dos> mysql -e "source batch-file"
  12217.  
  12218. If you need to specify connection parameters on the command-line, the
  12219. command might look like this:
  12220.  
  12221.      shell> mysql -h host -u user -p < batch-file
  12222.      Enter password: ********
  12223.  
  12224. When you use `mysql' this way, you are creating a script file, then
  12225. executing the script.
  12226.  
  12227. If you want the script to continue even if you have errors, you should
  12228. use the `--force' command-line option.
  12229.  
  12230. Why use a script?  Here are a few reasons:
  12231.  
  12232.    * If you run a query repeatedly (say, every day or every week),
  12233.      making it a script allows you to avoid retyping it each time you
  12234.      execute it.
  12235.  
  12236.    * You can generate new queries from existing ones that are similar
  12237.      by copying and editing script files.
  12238.  
  12239.    * Batch mode can also be useful while you're developing a query,
  12240.      particularly for multiple-line commands or multiple-statement
  12241.      sequences of commands.  If you make a mistake, you don't have to
  12242.      retype everything.  Just edit your script to correct the error,
  12243.      then tell `mysql' to execute it again.
  12244.  
  12245.    * If you have a query that produces a lot of output, you can run the
  12246.      output through a pager rather than watching it scroll off the top
  12247.      of your screen:
  12248.  
  12249.           shell> mysql < batch-file | more
  12250.  
  12251.    * You can catch the output in a file for further processing:
  12252.  
  12253.           shell> mysql < batch-file > mysql.out
  12254.  
  12255.    * You can distribute your script to other people so they can run the
  12256.      commands, too.
  12257.  
  12258.    * Some situations do not allow for interactive use, for example,
  12259.      when you run a query from a `cron' job.  In this case, you must
  12260.      use batch mode.
  12261.  
  12262. The default output format is different (more concise) when you run
  12263. `mysql' in batch mode than when you use it interactively.  For example,
  12264. the output of `SELECT DISTINCT species FROM pet' looks like this when
  12265. run interactively:
  12266.  
  12267.      +---------+
  12268.      | species |
  12269.      +---------+
  12270.      | bird    |
  12271.      | cat     |
  12272.      | dog     |
  12273.      | hamster |
  12274.      | snake   |
  12275.      +---------+
  12276.  
  12277. But like this when run in batch mode:
  12278.  
  12279.      species
  12280.      bird
  12281.      cat
  12282.      dog
  12283.      hamster
  12284.      snake
  12285.  
  12286. If you want to get the interactive output format in batch mode, use
  12287. `mysql -t'.  To echo to the output the commands that are executed, use
  12288. `mysql -vvv'.
  12289.  
  12290. You can also use scripts in the `mysql' command-line prompt by using
  12291. the `source' command:
  12292.  
  12293.      mysql> source filename;
  12294.  
  12295. Queries from Twin Project
  12296. =========================
  12297.  
  12298. At Analytikerna and Lentus, we have been doing the systems and field
  12299. work for a big research project. This project is a collaboration
  12300. between the Institute of Environmental Medicine at Karolinska
  12301. Institutet Stockholm and the Section on Clinical Research in Aging and
  12302. Psychology at the University of Southern California.
  12303.  
  12304. The project involves a screening part where all twins in Sweden older
  12305. than 65 years are interviewed by telephone. Twins who meet certain
  12306. criteria are passed on to the next stage. In this latter stage, twins
  12307. who want to participate are visited by a doctor/nurse team. Some of the
  12308. examinations include physical and neuropsychological examination,
  12309. laboratory testing, neuroimaging, psychological status assessment, and
  12310. family history collection. In addition, data are collected on medical
  12311. and environmental risk factors.
  12312.  
  12313. More information about Twin studies can be found at:
  12314. `http://www.imm.ki.se/TWIN/TWINUKW.HTM'
  12315.  
  12316. The latter part of the project is administered with a web interface
  12317. written using Perl and MySQL.
  12318.  
  12319. Each night all data from the interviews are moved into a MySQL database.
  12320.  
  12321. Find all Non-distributed Twins
  12322. ------------------------------
  12323.  
  12324. The following query is used to determine who goes into the second part
  12325. of the project:
  12326.  
  12327.      SELECT
  12328.              CONCAT(p1.id, p1.tvab) + 0 AS tvid,
  12329.              CONCAT(p1.christian_name, " ", p1.surname) AS Name,
  12330.              p1.postal_code AS Code,
  12331.              p1.city AS City,
  12332.              pg.abrev AS Area,
  12333.              IF(td.participation = "Aborted", "A", " ") AS A,
  12334.              p1.dead AS dead1,
  12335.              l.event AS event1,
  12336.              td.suspect AS tsuspect1,
  12337.              id.suspect AS isuspect1,
  12338.              td.severe AS tsevere1,
  12339.              id.severe AS isevere1,
  12340.              p2.dead AS dead2,
  12341.              l2.event AS event2,
  12342.              h2.nurse AS nurse2,
  12343.              h2.doctor AS doctor2,
  12344.              td2.suspect AS tsuspect2,
  12345.              id2.suspect AS isuspect2,
  12346.              td2.severe AS tsevere2,
  12347.              id2.severe AS isevere2,
  12348.              l.finish_date
  12349.      FROM
  12350.              twin_project AS tp
  12351.              /* For Twin 1 */
  12352.              LEFT JOIN twin_data AS td ON tp.id = td.id
  12353.                        AND tp.tvab = td.tvab
  12354.              LEFT JOIN informant_data AS id ON tp.id = id.id
  12355.                        AND tp.tvab = id.tvab
  12356.              LEFT JOIN harmony AS h ON tp.id = h.id
  12357.                        AND tp.tvab = h.tvab
  12358.              LEFT JOIN lentus AS l ON tp.id = l.id
  12359.                        AND tp.tvab = l.tvab
  12360.              /* For Twin 2 */
  12361.              LEFT JOIN twin_data AS td2 ON p2.id = td2.id
  12362.                        AND p2.tvab = td2.tvab
  12363.              LEFT JOIN informant_data AS id2 ON p2.id = id2.id
  12364.                        AND p2.tvab = id2.tvab
  12365.              LEFT JOIN harmony AS h2 ON p2.id = h2.id
  12366.                        AND p2.tvab = h2.tvab
  12367.              LEFT JOIN lentus AS l2 ON p2.id = l2.id
  12368.                        AND p2.tvab = l2.tvab,
  12369.              person_data AS p1,
  12370.              person_data AS p2,
  12371.              postal_groups AS pg
  12372.      WHERE
  12373.              /* p1 gets main twin and p2 gets his/her twin. */
  12374.              /* ptvab is a field inverted from tvab */
  12375.              p1.id = tp.id AND p1.tvab = tp.tvab AND
  12376.              p2.id = p1.id AND p2.ptvab = p1.tvab AND
  12377.              /* Just the sceening survey */
  12378.              tp.survey_no = 5 AND
  12379.              /* Skip if partner died before 65 but allow emigration (dead=9) */
  12380.              (p2.dead = 0 OR p2.dead = 9 OR
  12381.               (p2.dead = 1 AND
  12382.                (p2.death_date = 0 OR
  12383.                 (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
  12384.                  >= 65))))
  12385.              AND
  12386.              (
  12387.              /* Twin is suspect */
  12388.              (td.future_contact = 'Yes' AND td.suspect = 2) OR
  12389.              /* Twin is suspect - Informant is Blessed */
  12390.              (td.future_contact = 'Yes' AND td.suspect = 1
  12391.                                         AND id.suspect = 1) OR
  12392.              /* No twin - Informant is Blessed */
  12393.              (ISNULL(td.suspect) AND id.suspect = 1
  12394.                                  AND id.future_contact = 'Yes') OR
  12395.              /* Twin broken off - Informant is Blessed */
  12396.              (td.participation = 'Aborted'
  12397.               AND id.suspect = 1 AND id.future_contact = 'Yes') OR
  12398.              /* Twin broken off - No inform - Have partner */
  12399.              (td.participation = 'Aborted' AND ISNULL(id.suspect)
  12400.                                            AND p2.dead = 0))
  12401.              AND
  12402.              l.event = 'Finished'
  12403.              /* Get at area code */
  12404.              AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
  12405.              /* Not already distributed */
  12406.              AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
  12407.              /* Has not refused or been aborted */
  12408.              AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
  12409.              OR h.status = 'Died' OR h.status = 'Other')
  12410.      ORDER BY
  12411.              tvid;
  12412.  
  12413. Some explanations:
  12414. `CONCAT(p1.id, p1.tvab) + 0 AS tvid'
  12415.      We want to sort on the concatenated `id' and `tvab' in numerical
  12416.      order. Adding `0' to the result causes MySQL to treat the result
  12417.      as a number.
  12418.  
  12419. column `id'
  12420.      This identifies a pair of twins. It is a key in all tables.
  12421.  
  12422. column `tvab'
  12423.      This identifies a twin in a pair. It has a value of `1' or `2'.
  12424.  
  12425. column `ptvab'
  12426.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  12427.      vice versa. It exists to save typing and to make it easier for
  12428.      MySQL to optimise the query.
  12429.  
  12430. This query demonstrates, among other things, how to do lookups on a
  12431. table from the same table with a join (`p1' and `p2'). In the example,
  12432. this is used to check whether a twin's partner died before the age of
  12433. 65. If so, the row is not returned.
  12434.  
  12435. All of the above exist in all tables with twin-related information. We
  12436. have a key on both `id,tvab' (all tables), and `id,ptvab'
  12437. (`person_data') to make queries faster.
  12438.  
  12439. On our production machine (A 200MHz UltraSPARC), this query returns
  12440. about 150-200 rows and takes less than one second.
  12441.  
  12442. The current number of records in the tables used above:
  12443. *Table*            *Rows*
  12444. `person_data'      71074
  12445. `lentus'           5291
  12446. `twin_project'     5286
  12447. `twin_data'        2012
  12448. `informant_data'   663
  12449. `harmony'          381
  12450. `postal_groups'    100
  12451.  
  12452. Show a Table on Twin Pair Status
  12453. --------------------------------
  12454.  
  12455. Each interview ends with a status code called `event'. The query shown
  12456. here is used to display a table over all twin pairs combined by event.
  12457. This indicates in how many pairs both twins are finished, in how many
  12458. pairs one twin is finished and the other refused, and so on.
  12459.  
  12460.      SELECT
  12461.              t1.event,
  12462.              t2.event,
  12463.              COUNT(*)
  12464.      FROM
  12465.              lentus AS t1,
  12466.              lentus AS t2,
  12467.              twin_project AS tp
  12468.      WHERE
  12469.              /* We are looking at one pair at a time */
  12470.              t1.id = tp.id
  12471.              AND t1.tvab=tp.tvab
  12472.              AND t1.id = t2.id
  12473.              /* Just the sceening survey */
  12474.              AND tp.survey_no = 5
  12475.              /* This makes each pair only appear once */
  12476.              AND t1.tvab='1' AND t2.tvab='2'
  12477.      GROUP BY
  12478.              t1.event, t2.event;
  12479.  
  12480. Using MySQL with Apache
  12481. =======================
  12482.  
  12483. There are programs that let you authenticate your users from a MySQL
  12484. database and also let you log your log files into a MySQL table.
  12485.  
  12486. You can change the Apache logging format to be easily readable by MySQL
  12487. by putting the following into the Apache configuration file:
  12488.  
  12489.      LogFormat \
  12490.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  12491.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  12492.  
  12493. In MySQL you can do something like this:
  12494.  
  12495.      LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
  12496.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  12497.  
  12498. Database Administration
  12499. ***********************
  12500.  
  12501. Configuring MySQL
  12502. =================
  12503.  
  12504. `mysqld' Command-line Options
  12505. -----------------------------
  12506.  
  12507. In most cases you should manage mysqld options through option files.
  12508. *Note Option files::.
  12509.  
  12510. `mysqld' and `mysqld.server' reads options from the `mysqld' and
  12511. `server' groups. `mysqld_safe' read options from the `mysqld',
  12512. `server', `mysqld_safe' and `safe_mysqld' groups.  An embedded MySQL
  12513. server usually reads options from the `server', `embedded' and
  12514. `xxxxx_SERVER', where `xxxxx' is the name of the application.
  12515.  
  12516. `mysqld' accepts the following command-line options:
  12517.  
  12518. `--ansi'
  12519.      Use ANSI SQL syntax instead of MySQL syntax.  *Note ANSI mode::.
  12520.  
  12521. `-b, --basedir=path'
  12522.      Path to installation directory. All paths are usually resolved
  12523.      relative to this.
  12524.  
  12525. `--big-tables'
  12526.      Allow big result sets by saving all temporary sets on file.  It
  12527.      solves most 'table full' errors, but also slows down the queries
  12528.      where in-memory tables would suffice.  Since Version 3.23.2, MySQL
  12529.      is able to solve it automatically by using memory for small
  12530.      temporary tables and switching to disk tables where necessary.
  12531.  
  12532. `--bind-address=IP'
  12533.      IP address to bind to.
  12534.  
  12535. `--character-sets-dir=path'
  12536.      Directory where character sets are.  *Note Character sets::.
  12537.  
  12538. `--chroot=path'
  12539.      Put `mysqld' daemon in chroot environment at startup. Recommended
  12540.      security measure since MySQL 4.0 (MySQL 3.23 is not able to provide
  12541.      100% closed chroot jail).  It somewhat limits `LOAD DATA INFILE'
  12542.      and `SELECT ... INTO OUTFILE' though.
  12543.  
  12544. `--core-file'
  12545.      Write a core file if `mysqld' dies.  For some systems you must also
  12546.      specify `--core-file-size' to `safe_mysqld'.  *Note `safe_mysqld':
  12547.      safe_mysqld.  Note that on some systems, like Solaris, you will
  12548.      not get a core file if you are also using the `--user' option.
  12549.  
  12550. `-h, --datadir=path'
  12551.      Path to the database root.
  12552.  
  12553. `--debug[...]='
  12554.      If MySQL is configured with `--with-debug', you can use this
  12555.      option to get a trace file of what `mysqld' is doing.  *Note
  12556.      Making trace files::.
  12557.  
  12558. `--default-character-set=charset'
  12559.      Set the default character set.  *Note Character sets::.
  12560.  
  12561. `--default-table-type=type'
  12562.      Set the default table type for tables.  *Note Table types::.
  12563.  
  12564. `--delay-key-write[= OFF | ON | ALL]'
  12565.      How MyISAM `DELAYED KEYS' should be used. *Note Server
  12566.      parameters::.
  12567.  
  12568. `--delay-key-write-for-all-tables;  In MySQL 4.0.3 you should use --delay-key-write=ALL instead.'
  12569.      Don't flush key buffers between writes for any `MyISAM' table.
  12570.      *Note Server parameters::.
  12571.  
  12572. `--des-key-file=filename'
  12573.      Read the default keys used by `DES_ENCRYPT()' and `DES_DECRYPT()'
  12574.      from this file.
  12575.  
  12576. `--enable-external-locking (was --enable-locking)'
  12577.      Enable system locking.  Note that if you use this option on a
  12578.      system on which `lockd' does not fully work (as on Linux), you
  12579.      will easily get mysqld to deadlock.
  12580.  
  12581. `--enable-named-pipe'
  12582.      Enable support for named pipes (only on NT/Win2000/XP).
  12583.  
  12584. `-T, --exit-info'
  12585.      This is a bit mask of different flags one can use for debugging the
  12586.      mysqld server; one should not use this option if one doesn't know
  12587.      exactly what it does!
  12588.  
  12589. `--flush'
  12590.      Flush all changes to disk after each SQL command.  Normally MySQL
  12591.      only does a write of all changes to disk after each SQL command
  12592.      and lets the operating system handle the syncing to disk.  *Note
  12593.      Crashing::.
  12594.  
  12595. `-?, --help'
  12596.      Display short help and exit.
  12597.  
  12598. `--init-file=file'
  12599.      Read SQL commands from this file at startup.
  12600.  
  12601. `-L, --language=...'
  12602.      Client error messages in given language.  May be given as a full
  12603.      path.  *Note Languages::.
  12604.  
  12605. `-l, --log[=file]'
  12606.      Log connections and queries to file. *Note Query log::.
  12607.  
  12608. `--log-isam[=file]'
  12609.      Log all ISAM/MyISAM changes to file (only used when debugging
  12610.      ISAM/MyISAM).
  12611.  
  12612. `--log-slow-queries[=file]'
  12613.      Log all queries that have taken more than `long_query_time'
  12614.      seconds to execute to file.  *Note Slow query log::.
  12615.  
  12616. `--log-update[=file]'
  12617.      Log updates to `file.#' where `#' is a unique number if not given.
  12618.      *Note Update log::.
  12619.  
  12620. `--log-long-format'
  12621.      Log some extra information to update log.  If you are using
  12622.      `--log-slow-queries' then queries that are not using indexes are
  12623.      logged to the slow query log.
  12624.  
  12625. `--low-priority-updates'
  12626.      Table-modifying operations (`INSERT'/`DELETE'/`UPDATE') will have
  12627.      lower priority than selects.  It can also be done via `{INSERT |
  12628.      REPLACE | UPDATE | DELETE} LOW_PRIORITY ...' to lower the priority
  12629.      of only one query, or by `SET LOW_PRIORITY_UPDATES=1' to change
  12630.      the priority in one thread.  *Note Table locking::.
  12631.  
  12632. `--memlock'
  12633.      Lock the `mysqld' process in memory.  This works only if your
  12634.      system supports the `mlockall()' system call (like Solaris).  This
  12635.      may help if you have a problem where the operating system is
  12636.      causing `mysqld' to swap on disk.
  12637.  
  12638. `--myisam-recover [=option[,option...]]]'
  12639.      Option is any combination of `DEFAULT', `BACKUP', `FORCE' or
  12640.      `QUICK'.  You can also set this explicitly to `""' if you want to
  12641.      disable this option. If this option is used, `mysqld' will on open
  12642.      check if the table is marked as crashed or if the table wasn't
  12643.      closed properly.  (The last option only works if you are running
  12644.      with `--skip-external-locking'.)  If this is the case `mysqld'
  12645.      will run check on the table. If the table was corrupted, `mysqld'
  12646.      will attempt to repair it.
  12647.  
  12648.      The following options affects how the repair works.
  12649.  
  12650.      *Option*   *Description*
  12651.      DEFAULT    The same as not giving any option to
  12652.                          `--myisam-recover'.
  12653.      BACKUP     If the data table was changed during recover,
  12654.                 save a                     backup of the
  12655.                 `table_name.MYD' datafile as
  12656.                  `table_name-datetime.BAK'.
  12657.      FORCE      Run recover even if we will lose more than one
  12658.                 row                     from the .MYD file.
  12659.      QUICK      Don't check the rows in the table if there
  12660.                 aren't any                     delete blocks.
  12661.  
  12662.      Before a table is automatically repaired, MySQL will add a note
  12663.      about this in the error log.  If you want to be able to recover
  12664.      from most things without user intervention, you should use the
  12665.      options `BACKUP,FORCE'.  This will force a repair of a table even
  12666.      if some rows would be deleted, but it will keep the old datafile
  12667.      as a backup so that you can later examine what happened.
  12668.  
  12669. `--pid-file=path'
  12670.      Path to pid file used by `safe_mysqld'.
  12671.  
  12672. `-P, --port=...'
  12673.      Port number to listen for TCP/IP connections.
  12674.  
  12675. `-o, --old-protocol'
  12676.      Use the 3.20 protocol for compatibility with some very old clients.
  12677.      *Note Upgrading-from-3.20::.
  12678.  
  12679. `--one-thread'
  12680.      Only use one thread (for debugging under Linux).  *Note Debugging
  12681.      server::.
  12682.  
  12683. `-O, --set-variable var=option'
  12684.      Give a variable a value. `--help' lists variables.  You can find a
  12685.      full description for all variables in the `SHOW VARIABLES' section
  12686.      in this manual.  *Note SHOW VARIABLES::.  The tuning server
  12687.      parameters section includes information of how to optimise these.
  12688.      Please note that `--set-variable' is deprecated since MySQL 4.0,
  12689.      just use `--var=option' on its own.  *Note Server parameters::.
  12690.  
  12691.      In MySQL 4.0.2 one can set a variable directly with
  12692.      `--variable-name=option' and `set-variable' is not anymore needed
  12693.      in option files.
  12694.  
  12695.      If you want to restrict the maximum value a startup option can be
  12696.      set to with `SET', you can define this by using the
  12697.      `--maximum-variable-name' command line option. *Note SET OPTION::.
  12698.  
  12699.      Note that when setting a variable to a value, MySQL may
  12700.      automatically correct it to stay within a given range and also
  12701.      adjusts the value a little to fix for the used algorithm.
  12702.  
  12703. `--safe-mode'
  12704.      Skip some optimise stages.
  12705.  
  12706. `--safe-show-database'
  12707.      With this option, the `SHOW DATABASES' command returns only those
  12708.      databases for which the user has some kind of privilege.  From
  12709.      version 4.0.2 this option is deprecated and doesn't do anything
  12710.      (the option is enabled by default) as we now have the `SHOW
  12711.      DATABASES' privilege. *Note GRANT::.
  12712.  
  12713. `--safe-user-create'
  12714.      If this is enabled, a user can't create new users with the GRANT
  12715.      command, if the user doesn't have `INSERT' privilege to the
  12716.      `mysql.user' table or any column in this table.
  12717.  
  12718. `--skip-bdb'
  12719.      Disable usage of BDB tables. This will save memory and may speed
  12720.      up some things.
  12721.  
  12722. `--skip-concurrent-insert'
  12723.      Turn off the ability to select and insert at the same time on
  12724.      `MyISAM' tables. (This is only to be used if you think you have
  12725.      found a bug in this feature.)
  12726.  
  12727. `--skip-delay-key-write; In MySQL 4.0.3 you should use --delay-key-write=OFF instead.'
  12728.      Ignore the `DELAY_KEY_WRITE' option for all tables.  *Note Server
  12729.      parameters::.
  12730.  
  12731. `--skip-grant-tables'
  12732.      This option causes the server not to use the privilege system at
  12733.      all.  This gives everyone *full access* to all databases!  (You
  12734.      can tell a running server to start using the grant tables again by
  12735.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  12736.  
  12737. `--skip-host-cache'
  12738.      Never use host name cache for faster name-ip resolution, but query
  12739.      DNS server on every connect instead.  *Note DNS::.
  12740.  
  12741. `--skip-innodb'
  12742.      Disable usage of Innodb tables.  This will save memory and disk
  12743.      space and speed up some things.
  12744.  
  12745. `--skip-external-locking (was --skip-locking)'
  12746.      Don't use system locking.  To use `isamchk' or `myisamchk' you must
  12747.      shut down the server.  *Note Stability::.  Note that in MySQL
  12748.      Version 3.23 you can use `REPAIR' and `CHECK' to repair/check
  12749.      `MyISAM' tables.
  12750.  
  12751. `--skip-name-resolve'
  12752.      Hostnames are not resolved.  All `Host' column values in the grant
  12753.      tables must be IP numbers or `localhost'.  *Note DNS::.
  12754.  
  12755. `--skip-networking'
  12756.      Don't listen for TCP/IP connections at all.  All interaction with
  12757.      `mysqld' must be made via Unix sockets.  This option is highly
  12758.      recommended for systems where only local requests are allowed.
  12759.      *Note DNS::.
  12760.  
  12761. `--skip-new'
  12762.      Don't use new, possible wrong routines.
  12763.  
  12764. `--skip-symlink'
  12765.      Don't delete or rename files that a symlinked file in the data
  12766.      directory points to.
  12767.  
  12768. `--skip-safemalloc'
  12769.      If MySQL is configured with `--with-debug=full', all programs will
  12770.      check the memory for overruns for every memory allocation and
  12771.      memory freeing.  As this checking is very slow, you can avoid
  12772.      this, when you don't need memory checking, by using this option.
  12773.  
  12774. `--skip-show-database'
  12775.      Don't allow `SHOW DATABASES' command, unless the user has the
  12776.      `SHOW DATABASES' privilege. From version 4.0.2 you should no longer
  12777.      need this option, since access can now be granted specifically
  12778.      with the `SHOW DATABASES' privilege.
  12779.  
  12780. `--skip-stack-trace'
  12781.      Don't write stack traces.  This option is useful when you are
  12782.      running `mysqld' under a debugger. On some systems you also have
  12783.      to use this option to get a core file. *Note Debugging server::.
  12784.  
  12785. `--skip-thread-priority'
  12786.      Disable using thread priorities for faster response time.
  12787.  
  12788. `--socket=path'
  12789.      Socket file to use for local connections instead of default
  12790.      `/tmp/mysql.sock'.
  12791.  
  12792. `--sql-mode=option[,option[,option...]]'
  12793.      Option can be any combination of: `REAL_AS_FLOAT',
  12794.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE', `SERIALIZE',
  12795.      `ONLY_FULL_GROUP_BY'.  It can also be empty (`""') if you want to
  12796.      reset this.
  12797.  
  12798.      By specifying all of the above options is same as using -ansi.
  12799.      With this option one can turn on only needed SQL modes. *Note ANSI
  12800.      mode::.
  12801.  
  12802. `--temp-pool'
  12803.      Using this option will cause most temporary files created to use a
  12804.      small set of names, rather than a unique name for each new file.
  12805.      This is to work around a problem in the Linux kernel dealing with
  12806.      creating a bunch of new files with different names. With the old
  12807.      behaviour, Linux seems to 'leak' memory, as it's being allocated
  12808.      to the directory entry cache instead of the disk cache.
  12809.  
  12810. `--transaction-isolation= { READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE }'
  12811.      Sets the default transaction isolation level.  *Note SET
  12812.      TRANSACTION::.
  12813.  
  12814. `-t, --tmpdir=path'
  12815.      Path for temporary files. It may be useful if your default `/tmp'
  12816.      directory resides on a partition too small to hold temporary
  12817.      tables.
  12818.  
  12819. `-u, --user= [user_name | userid]'
  12820.      Run `mysqld' daemon as user `user_name' or `userid' (numeric).
  12821.      This option is *mandatory* when starting `mysqld' as root.
  12822.  
  12823. `-V, --version'
  12824.      Output version information and exit.
  12825.  
  12826. `-W, --log-warnings  (Was --warnings)'
  12827.      Print out warnings like `Aborted connection...' to the `.err' file.
  12828.      *Note Communication errors::.
  12829.  
  12830. One can change most values for a running server with the `SET' command.
  12831. *Note SET OPTION::.
  12832.  
  12833. `my.cnf' Option Files
  12834. ---------------------
  12835.  
  12836. MySQL can, since Version 3.22, read default startup options for the
  12837. server and for clients from option files.
  12838.  
  12839. MySQL reads default options from the following files on Unix:
  12840.  
  12841. *Filename*                *Purpose*
  12842. `/etc/my.cnf'             Global options
  12843. `DATADIR/my.cnf'          Server-specific options
  12844. `defaults-extra-file'     The file specified with
  12845.                           -defaults-extra-file=#
  12846. `~/.my.cnf'               User-specific options
  12847.  
  12848. `DATADIR' is the MySQL data directory (typically
  12849. `/usr/local/mysql/data' for a binary installation or `/usr/local/var'
  12850. for a source installation).  Note that this is the directory that was
  12851. specified at configuration time, not the one specified with `--datadir'
  12852. when `mysqld' starts up!  (`--datadir' has no effect on where the
  12853. server looks for option files, because it looks for them before it
  12854. processes any command-line arguments.)
  12855.  
  12856. MySQL reads default options from the following files on Windows:
  12857.  
  12858. *Filename*                *Purpose*
  12859. `windows-system-directory\my.ini'Global options
  12860. `C:\my.cnf'               Global options
  12861.  
  12862. Note that on Windows, you should specify all paths with `/' instead of
  12863. `\'. If you use `\', you need to specify this twice, as `\' is the
  12864. escape character in MySQL.
  12865.  
  12866. MySQL tries to read option files in the order listed above.  If
  12867. multiple option files exist, an option specified in a file read later
  12868. takes precedence over the same option specified in a file read earlier.
  12869. Options specified on the command-line take precedence over options
  12870. specified in any option file.  Some options can be specified using
  12871. environment variables.  Options specified on the command-line or in
  12872. option files take precedence over environment variable values. *Note
  12873. Environment variables::.
  12874.  
  12875. The following programs support option files:  `mysql', `mysqladmin',
  12876. `mysqld', `mysqld_safe', `mysql.server', `mysqldump', `mysqlimport',
  12877. `mysqlshow', `mysqlcheck', `myisamchk', and `myisampack'.
  12878.  
  12879. Any long option that may be given on the command-line when running a
  12880. MySQL program can be given in an option file as well (without the
  12881. leading double dash).  Run the program with `--help' to get a list of
  12882. available options.
  12883.  
  12884. An option file can contain lines of the following forms:
  12885.  
  12886. `#comment'
  12887.      Comment lines start with `#' or `;'. Empty lines are ignored.
  12888.  
  12889. `[group]'
  12890.      `group' is the name of the program or group for which you want to
  12891.      set options.  After a group line, any `option' or `set-variable'
  12892.      lines apply to the named group until the end of the option file or
  12893.      another group line is given.
  12894.  
  12895. `option'
  12896.      This is equivalent to `--option' on the command-line.
  12897.  
  12898. `option=value'
  12899.      This is equivalent to `--option=value' on the command-line.
  12900.  
  12901. `set-variable = variable=value'
  12902.      This is equivalent to `--set-variable variable=value' on the
  12903.      command-line.  This syntax must be used to set a `mysqld' variable.
  12904.      Please note that `--set-variable' is deprecated since MySQL 4.0,
  12905.      just use `--variable=value' on its own.
  12906.  
  12907. The `client' group allows you to specify options that apply to all
  12908. MySQL clients (not `mysqld'). This is the perfect group to use to
  12909. specify the password you use to connect to the server.  (But make sure
  12910. the option file is readable and writable only by yourself.)
  12911.  
  12912. Note that for options and values, all leading and trailing blanks are
  12913. automatically deleted.  You may use the escape sequences `\b', `\t',
  12914. `\n', `\r', `\\', and `\s' in your value string (`\s' == blank).
  12915.  
  12916. Here is a typical global option file:
  12917.  
  12918.      [client]
  12919.      port=3306
  12920.      socket=/tmp/mysql.sock
  12921.      
  12922.      [mysqld]
  12923.      port=3306
  12924.      socket=/tmp/mysql.sock
  12925.      set-variable = key_buffer_size=16M
  12926.      set-variable = max_allowed_packet=1M
  12927.      
  12928.      [mysqldump]
  12929.      quick
  12930.  
  12931. Here is typical user option file:
  12932.  
  12933.      [client]
  12934.      # The following password will be sent to all standard MySQL clients
  12935.      password=my_password
  12936.      
  12937.      [mysql]
  12938.      no-auto-rehash
  12939.      set-variable = connect_timeout=2
  12940.      
  12941.      [mysqlhotcopy]
  12942.      interactive-timeout
  12943.  
  12944. If you have a source distribution, you will find sample configuration
  12945. files named `my-xxxx.cnf' in the `support-files' directory.  If you
  12946. have a binary distribution, look in the `DIR/support-files' directory,
  12947. where `DIR' is the pathname to the MySQL installation directory
  12948. (typically `/usr/local/mysql').  Currently there are sample
  12949. configuration files for small, medium, large, and very large systems.
  12950. You can copy `my-xxxx.cnf' to your home directory (rename the copy to
  12951. `.my.cnf') to experiment with this.
  12952.  
  12953. All MySQL clients that support option files support the following
  12954. options:
  12955.  
  12956. *Option*                         *Description*
  12957. -no-defaults                     Don't read any option files.
  12958. -print-defaults                  Print the program name and all options
  12959.                                  that it will get.
  12960. -defaults-file=full-path-to-default-fileOnly use the given configuration file.
  12961. -defaults-extra-file=full-path-to-default-fileRead this configuration file after the
  12962.                                  global configuration file but before
  12963.                                  the user configuration file.
  12964.  
  12965. Note that the above options must be first on the command-line to work!
  12966. `--print-defaults' may however be used directly after the
  12967. `--defaults-xxx-file' commands.
  12968.  
  12969. Note for developers:  Option file handling is implemented simply by
  12970. processing all matching options (that is, options in the appropriate
  12971. group) before any command-line arguments. This works nicely for
  12972. programs that use the last instance of an option that is specified
  12973. multiple times. If you have an old program that handles
  12974. multiply-specified options this way but doesn't read option files, you
  12975. need add only two lines to give it that capability.  Check the source
  12976. code of any of the standard MySQL clients to see how to do this.
  12977.  
  12978. In shell scripts you can use the `my_print_defaults' command to parse
  12979. the config files:
  12980.  
  12981.  
  12982.      shell> my_print_defaults client mysql
  12983.      --port=3306
  12984.      --socket=/tmp/mysql.sock
  12985.      --no-auto-rehash
  12986.  
  12987. The above output contains all options for the groups 'client' and
  12988. 'mysql'.
  12989.  
  12990. Installing Many Servers on the Same Machine
  12991. -------------------------------------------
  12992.  
  12993. In some cases you may want to have many different `mysqld' daemons
  12994. (servers) running on the same machine.  You may for example want to run
  12995. a new version of MySQL for testing together with an old version that is
  12996. in production.  Another case is when you want to give different users
  12997. access to different `mysqld' servers that they manage themselves.
  12998.  
  12999. One way to get a new server running is by starting it with a different
  13000. socket and port as follows:
  13001.  
  13002.      shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
  13003.      shell> MYSQL_TCP_PORT=3307
  13004.      shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
  13005.      shell> scripts/mysql_install_db
  13006.      shell> bin/safe_mysqld &
  13007.  
  13008. The environment variables appendix includes a list of other environment
  13009. variables you can use to affect `mysqld'. *Note Environment variables::.
  13010.  
  13011. The above is the quick and dirty way that one commonly uses for testing.
  13012. The nice thing with this is that all connections you do in the above
  13013. shell will automatically be directed to the new running server!
  13014.  
  13015. If you need to do this more permanently, you should create an option
  13016. file for each server. *Note Option files::.  In your startup script that
  13017. is executed at boot time you should specify for both servers:
  13018.  
  13019. `safe_mysqld --defaults-file=path-to-option-file'
  13020.  
  13021. At least the following options should be different per server:
  13022.  
  13023.    * port=#
  13024.  
  13025.    * socket=path
  13026.  
  13027.    * pid-file=path
  13028.  
  13029. The following options should be different, if they are used:
  13030.  
  13031.    * log=path
  13032.  
  13033.    * log-bin=path
  13034.  
  13035.    * log-update=path
  13036.  
  13037.    * log-isam=path
  13038.  
  13039.    * bdb-logdir=path
  13040.  
  13041. If you want more performance, you can also specify the following
  13042. differently:
  13043.  
  13044.    * tmpdir=path
  13045.  
  13046.    * bdb-tmpdir=path
  13047.  
  13048. *Note Command-line options::.
  13049.  
  13050. If you are installing binary MySQL versions (.tar files) and start them
  13051. with `./bin/safe_mysqld' then in most cases the only option you need to
  13052. add/change is the `socket' and `port' argument to `safe_mysqld'.
  13053.  
  13054. *Note Running Multiple MySQL Servers on the Same Machine: Multiple
  13055. servers.
  13056.  
  13057. Running Multiple MySQL Servers on the Same Machine
  13058. --------------------------------------------------
  13059.  
  13060. There are circumstances when you might want to run multiple servers on
  13061. the same machine.  For example, you might want to test a new MySQL
  13062. release while leaving your existing production setup undisturbed.  Or
  13063. you might be an Internet service provider that wants to provide
  13064. independent MySQL installations for different customers.
  13065.  
  13066. If you want to run multiple servers, the easiest way is to compile the
  13067. servers with different TCP/IP ports and socket files so they are not
  13068. both listening to the same TCP/IP port or socket file. *Note
  13069. `mysqld_multi': mysqld_multi.
  13070.  
  13071. Assume an existing server is configured for the default port number and
  13072. socket file.  Then configure the new server with a `configure' command
  13073. something like this:
  13074.  
  13075.      shell> ./configure  --with-tcp-port=port_number \
  13076.                   --with-unix-socket-path=file_name \
  13077.                   --prefix=/usr/local/mysql-3.22.9
  13078.  
  13079. Here `port_number' and `file_name' should be different from the default
  13080. port number and socket file pathname, and the `--prefix' value should
  13081. specify an installation directory different from the one under which
  13082. the existing MySQL installation is located.
  13083.  
  13084. You can check the socket used by any currently executing MySQL server
  13085. with this command:
  13086.  
  13087.      shell> mysqladmin -h hostname --port=port_number variables
  13088.  
  13089. Note that if you specify "`localhost'" as a hostname, `mysqladmin' will
  13090. default to using Unix sockets instead of TCP/IP.
  13091.  
  13092. If you have a MySQL server running on the port you used, you will get a
  13093. list of some of the most important configurable variables in MySQL,
  13094. including the socket name.
  13095.  
  13096. You don't have to recompile a new MySQL server just to start with a
  13097. different port and socket.  You can change the port and socket to be
  13098. used by specifying them at runtime as options to `safe_mysqld':
  13099.  
  13100.      shell> /path/to/safe_mysqld --socket=file_name --port=port_number
  13101.  
  13102. `mysqld_multi' can also take `safe_mysqld' (or `mysqld') as an argument
  13103. and pass the options from a configuration file to `safe_mysqld' and
  13104. further to `mysqld'.
  13105.  
  13106. If you run the new server on the same database directory as another
  13107. server with logging enabled, you should also specify the name of the log
  13108. files to `safe_mysqld' with `--log', `--log-update', or
  13109. `--log-slow-queries'.  Otherwise, both servers may be trying to write
  13110. to the same log file.
  13111.  
  13112. *Warning*: normally you should never have two servers that update data
  13113. in the same database!  If your OS doesn't support fault-free system
  13114. locking, this may lead to unpleasant surprises!
  13115.  
  13116. If you want to use another database directory for the second server, you
  13117. can use the `--datadir=path' option to `safe_mysqld'.
  13118.  
  13119. *Note* also that starting several MySQL servers (`mysqlds') in
  13120. different machines and letting them access one data directory over
  13121. `NFS' is generally a *bad idea*! The problem is that the `NFS' will
  13122. become the bottleneck with the speed. It is not meant for such use. And
  13123. last but not least, you would still have to come up with a solution how
  13124. to make sure that two or more `mysqlds' are not interfering with each
  13125. other. At the moment there is no platform that would 100% reliable do
  13126. the file locking (`lockd' daemon usually) in every situation. Yet there
  13127. would be one more possible risk with `NFS'; it would make the work even
  13128. more complicated for `lockd' daemon to handle. So make it easy for your
  13129. self and forget about the idea. The working solution is to have one
  13130. computer with an operating system that efficiently handles threads and
  13131. have several CPUs in it.
  13132.  
  13133. When you want to connect to a MySQL server that is running with a
  13134. different port than the port that is compiled into your client, you can
  13135. use one of the following methods:
  13136.  
  13137.    * Start the client with `--host 'hostname' --port=port_number' to
  13138.      connect with TCP/IP, or `[--host localhost] --socket=file_name' to
  13139.      connect via a Unix socket.
  13140.  
  13141.    * In your C or Perl programs, you can give the port or socket
  13142.      arguments when connecting to the MySQL server.
  13143.  
  13144.    * If your are using the Perl `DBD::mysql' module you can read the
  13145.      options from the MySQL option files.  *Note Option files::.
  13146.  
  13147.           $dsn = "DBI:mysql:test;mysql_read_default_group=client;
  13148.                   mysql_read_default_file=/usr/local/mysql/data/my.cnf"
  13149.           $dbh = DBI->connect($dsn, $user, $password);
  13150.  
  13151.    * Set the `MYSQL_UNIX_PORT' and `MYSQL_TCP_PORT' environment
  13152.      variables to point to the Unix socket and TCP/IP port before you
  13153.      start your clients.  If you normally use a specific socket or
  13154.      port, you should place commands to set these environment variables
  13155.      in your `.login' file.  *Note Environment variables::.
  13156.  
  13157.    * Specify the default socket and TCP/IP port in the `.my.cnf' file
  13158.      in your home directory. *Note Option files::.
  13159.  
  13160. General Security Issues and the MySQL Access Privilege System
  13161. =============================================================
  13162.  
  13163. MySQL has an advanced but non-standard security/privilege system.  This
  13164. section describes how it works.
  13165.  
  13166. General Security Guidelines
  13167. ---------------------------
  13168.  
  13169. Anyone using MySQL on a computer connected to the Internet should read
  13170. this section to avoid the most common security mistakes.
  13171.  
  13172. In discussing security, we emphasise the necessity of fully protecting
  13173. the entire server host (not simply the MySQL server) against all types
  13174. of applicable attacks: eavesdropping, altering, playback, and denial of
  13175. service. We do not cover all aspects of availability and fault tolerance
  13176. here.
  13177.  
  13178. MySQL uses security based on Access Control Lists (ACLs) for all
  13179. connections, queries, and other operations that a user may attempt to
  13180. perform. There is also some support for SSL-encrypted connections
  13181. between MySQL clients and servers. Many of the concepts discussed here
  13182. are not specific to MySQL at all; the same general ideas apply to
  13183. almost all applications.
  13184.  
  13185. When running MySQL, follow these guidelines whenever possible:
  13186.  
  13187.    * *Do not ever give anyone (except the mysql root user) access to the
  13188.      `user' table in the `mysql' database!*  This is critical.  *The
  13189.      encrypted password is the real password in MySQL.* Anyone who
  13190.      knows the password which is listed in the `user' table and has
  13191.      access to the host listed for the account *can easily log in as
  13192.      that user*.
  13193.  
  13194.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  13195.      commands are used for controlling access to MySQL. Do not grant
  13196.      any more privileges than necessary. Never grant privileges to all
  13197.      hosts.
  13198.  
  13199.      Checklist:
  13200.         - Try `mysql -u root'. If you are able to connect successfully
  13201.           to the server without being asked for a password, you have
  13202.           problems. Anyone can connect to your MySQL server as the MySQL
  13203.           `root' user with full privileges!  Review the MySQL
  13204.           installation instructions, paying particular attention to the
  13205.           item about setting a `root' password.
  13206.  
  13207.         - Use the command `SHOW GRANTS' and check to see who has access
  13208.           to what. Remove those privileges that are not necessary using
  13209.           the `REVOKE' command.
  13210.  
  13211.    * Do not keep any plain-text passwords in your database. When your
  13212.      computer becomes compromised, the intruder can take the full list
  13213.      of passwords and use them. Instead use `MD5()', `SHA1()' or
  13214.      another one-way hashing function.
  13215.  
  13216.    * Do not choose passwords from dictionaries. There are special
  13217.      programs to break them. Even passwords like "xfish98" are very
  13218.      bad.  Much better is "duag98" which contains the same word "fish"
  13219.      but typed one key to the left on a standard QWERTY keyboard.
  13220.      Another method is to use "Mhall" which is taken from the first
  13221.      characters of each word in the sentence "Mary had a little lamb."
  13222.      This is easy to remember and type, but difficult to guess for
  13223.      someone who does not know it.
  13224.  
  13225.    * Invest in a firewall. This protects you from at least 50% of all
  13226.      types of exploits in any software. Put MySQL behind the firewall
  13227.      or in a demilitarised zone (DMZ).
  13228.  
  13229.      Checklist:
  13230.         - Try to scan your ports from the Internet using a tool such as
  13231.           `nmap'. MySQL uses port 3306 by default. This port should be
  13232.           inaccessible from untrusted hosts. Another simple way to
  13233.           check whether or not your MySQL port is open is to try the
  13234.           following command from some remote machine, where
  13235.           `server_host' is the hostname of your MySQL server:
  13236.  
  13237.                shell> telnet server_host 3306
  13238.  
  13239.           If you get a connection and some garbage characters, the port
  13240.           is open, and should be closed on your firewall or router,
  13241.           unless you really have a good reason to keep it open. If
  13242.           `telnet' just hangs or the connection is refused, everything
  13243.           is OK; the port is blocked.
  13244.  
  13245.    * Do not trust any data entered by your users. They can try to trick
  13246.      your code by entering special or escaped character sequences in
  13247.      web forms, URLs, or whatever application you have built. Be sure
  13248.      that your application remains secure if a user enters something
  13249.      like "`; DROP DATABASE mysql;'". This is an extreme example, but
  13250.      large security leaks and data loss may occur as a result of
  13251.      hackers using similar techniques, if you do not prepare for them.
  13252.  
  13253.      Also remember to check numeric data. A common mistake is to
  13254.      protect only strings. Sometimes people think that if a database
  13255.      contains only publicly available data that it need not be
  13256.      protected. This is incorrect. At least denial-of-service type
  13257.      attacks can be performed on such databases. The simplest way to
  13258.      protect from this type of attack is to use apostrophes around the
  13259.      numeric constants: `SELECT * FROM table WHERE ID='234'' rather
  13260.      than `SELECT * FROM table WHERE ID=234'.  MySQL automatically
  13261.      converts this string to a number and strips all non-numeric
  13262.      symbols from it.
  13263.  
  13264.      Checklist:
  13265.         - All web applications:
  13266.              * Try to enter `'' and `"' in all your web forms. If you
  13267.                get any kind of MySQL error, investigate the problem
  13268.                right away.
  13269.  
  13270.              * Try to modify any dynamic URLs by adding `%22' (`"'),
  13271.                `%23' (`#'), and `%27' (`'') in the URL.
  13272.  
  13273.              * Try to modify datatypes in dynamic URLs from numeric
  13274.                ones to character ones containing characters from
  13275.                previous examples. Your application should be safe
  13276.                against this and similar attacks.
  13277.  
  13278.              * Try to enter characters, spaces, and special symbols
  13279.                instead of numbers in numeric fields. Your application
  13280.                should remove them before passing them to MySQL or your
  13281.                application should generate an error. Passing unchecked
  13282.                values to MySQL is very dangerous!
  13283.  
  13284.              * Check data sizes before passing them to MySQL.
  13285.  
  13286.              * Consider having your application connect to the database
  13287.                using a different user name than the one you use for
  13288.                administrative purposes. Do not give your applications
  13289.                any more access privileges than they need.
  13290.  
  13291.         - Users of PHP:
  13292.              * Check out the `addslashes()' function.  As of PHP 4.0.3,
  13293.                a `mysql_escape_string()' function is available that is
  13294.                based on the function of the same name in the MySQL C
  13295.                API.
  13296.  
  13297.         - Users of MySQL C API:
  13298.              * Check out the `mysql_real_escape_string()' API call.
  13299.  
  13300.         - Users of MySQL++:
  13301.              * Check out the `escape' and `quote' modifiers for query
  13302.                streams.
  13303.  
  13304.         - Users of Perl DBI:
  13305.              * Check out the `quote()' method or use placeholders.
  13306.  
  13307.         - Users of Java JDBC:
  13308.              * Use a `PreparedStatement' object and placeholders.
  13309.  
  13310.    * Do not transmit plain (unencrypted) data over the Internet. These
  13311.      data are accessible to everyone who has the time and ability to
  13312.      intercept it and use it for their own purposes. Instead, use an
  13313.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  13314.      connections as of Version 4.0.0.  SSH port-forwarding can be used
  13315.      to create an encrypted (and compressed) tunnel for the
  13316.      communication.
  13317.  
  13318.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  13319.      you can check whether MySQL data streams are unencrypted by
  13320.      issuing a command like the following:
  13321.  
  13322.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  13323.  
  13324.      (This works under Linux and should work with small modifications
  13325.      under other systems.)  Warning: If you do not see data this
  13326.      doesn't always actually mean that it is encrypted. If you need
  13327.      high security, you should consult with a security expert.
  13328.  
  13329. How to Make MySQL Secure Against Crackers
  13330. -----------------------------------------
  13331.  
  13332. When you connect to a MySQL server, you normally should use a password.
  13333. The password is not transmitted in clear text over the connection,
  13334. however the encryption algorithm is not very strong, and with some
  13335. effort a clever attacker can crack the password if he is able to sniff
  13336. the traffic between the client and the server. If the connection
  13337. between the client and the server goes through an untrusted network,
  13338. you should use an SSH tunnel to encrypt the communication.
  13339.  
  13340. All other information is transferred as text that can be read by anyone
  13341. who is able to watch the connection.  If you are concerned about this,
  13342. you can use the compressed protocol (in MySQL Version 3.22 and above)
  13343. to make things much harder.  To make things even more secure you should
  13344. use `ssh'.  You can find an `Open Source' `ssh' client at
  13345. `http://www.openssh.org/', and a commercial `ssh' client at
  13346. `http://www.ssh.com/'.  With this, you can get an encrypted TCP/IP
  13347. connection between a MySQL server and a MySQL client.
  13348.  
  13349. If you are using MySQL 4.0, you can also use internal OpenSSL support.
  13350. *Note Secure connections::.
  13351.  
  13352. To make a MySQL system secure, you should strongly consider the
  13353. following suggestions:
  13354.  
  13355.    * Use passwords for all MySQL users. Remember that anyone can log in
  13356.      as any other person as simply as `mysql -u other_user db_name' if
  13357.      `other_user' has no password.  It is common behaviour with
  13358.      client/server applications that the client may specify any user
  13359.      name.  You can change the password of all users by editing the
  13360.      `mysql_install_db' script before you run it, or only the password
  13361.      for the MySQL `root' user like this:
  13362.  
  13363.           shell> mysql -u root mysql
  13364.           mysql> UPDATE user SET Password=PASSWORD('new_password')
  13365.               ->             WHERE user='root';
  13366.           mysql> FLUSH PRIVILEGES;
  13367.  
  13368.    * Don't run the MySQL daemon as the Unix `root' user.  This is very
  13369.      dangerous, because any user with the `FILE' privilege will be able
  13370.      to create files as `root' (for example, `~root/.bashrc'). To
  13371.      prevent this, `mysqld' will refuse to run as `root' unless it is
  13372.      specified directly using a `--user=root' option.
  13373.  
  13374.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  13375.      can also create a new Unix user `mysql' to make everything even
  13376.      more secure.  If you run `mysqld' as another Unix user, you don't
  13377.      need to change the `root' user name in the `user' table, because
  13378.      MySQL user names have nothing to do with Unix user names.  To
  13379.      start `mysqld' as another Unix user, add a `user' line that
  13380.      specifies the user name to the `[mysqld]' group of the
  13381.      `/etc/my.cnf' option file or the `my.cnf' option file in the
  13382.      server's data directory. For example:
  13383.  
  13384.           [mysqld]
  13385.           user=mysql
  13386.  
  13387.      This will cause the server to start as the designated user whether
  13388.      you start it manually or by using `safe_mysqld' or `mysql.server'.
  13389.      For more details, see *Note Changing MySQL user::.
  13390.  
  13391.    * Don't support symlinks to tables (this can be disabled with the
  13392.      `--skip-symlink' option). This is especially important if you run
  13393.      `mysqld' as root as anyone that has write access to the mysqld data
  13394.      directories could then delete any file in the system!  *Note
  13395.      Symbolic links to tables::.
  13396.  
  13397.    * Check that the Unix user that `mysqld' runs as is the only user
  13398.      with read/write privileges in the database directories.
  13399.  
  13400.    * Don't give the `PROCESS' privilege to all users.  The output of
  13401.      `mysqladmin processlist' shows the text of the currently executing
  13402.      queries, so any user who is allowed to execute that command might
  13403.      be able to see if another user issues an `UPDATE user SET
  13404.      password=PASSWORD('not_secure')' query.
  13405.  
  13406.      `mysqld' reserves an extra connection for users who have the
  13407.      `PROCESS' privilege, so that a MySQL `root' user can log in and
  13408.      check things even if all normal connections are in use.
  13409.  
  13410.    * Don't give the `FILE' privilege to all users.  Any user that has
  13411.      this privilege can write a file anywhere in the filesystem with
  13412.      the privileges of the `mysqld' daemon!  To make this a bit safer,
  13413.      all files generated with `SELECT ... INTO OUTFILE' are readable to
  13414.      everyone, and you cannot overwrite existing files.
  13415.  
  13416.      The `FILE' privilege may also be used to read any file accessible
  13417.      to the Unix user that the server runs as.  This could be abused,
  13418.      for example, by using `LOAD DATA' to load `/etc/passwd' into a
  13419.      table, which can then be read with `SELECT'.
  13420.  
  13421.    * If you don't trust your DNS, you should use IP numbers instead of
  13422.      hostnames in the grant tables. In any case, you should be very
  13423.      careful about creating grant table entries using hostname values
  13424.      that contain wildcards!
  13425.  
  13426.    * If you want to restrict the number of connections for a single
  13427.      user, you can do this by setting the `max_user_connections'
  13428.      variable in `mysqld'.
  13429.  
  13430. Startup Options for `mysqld' Concerning Security
  13431. ------------------------------------------------
  13432.  
  13433. The following `mysqld' options affect security:
  13434.  
  13435. `--local-infile[=(0|1)]'
  13436.      If one uses `--local-infile=0' then one can't use `LOAD DATA LOCAL
  13437.      INFILE'.
  13438.  
  13439. `--safe-show-database'
  13440.      With this option, the `SHOW DATABASES' command returns only those
  13441.      databases for which the user has some kind of privilege.  From
  13442.      version 4.0.2 this option is deprecated and doesn't do anything
  13443.      (the option is enabled by default) as we now have the `SHOW
  13444.      DATABASES' privilege. *Note GRANT::.
  13445.  
  13446. `--safe-user-create'
  13447.      If this is enabled, an user can't create new users with the `GRANT'
  13448.      command, if the user doesn't have the `INSERT' privilege for the
  13449.      `mysql.user' table.  If you want to give a user access to just
  13450.      create new users with those privileges that the user has right to
  13451.      grant, you should give the user the following privilege:
  13452.  
  13453.           mysql> GRANT INSERT(user) ON mysql.user TO 'user'@'hostname';
  13454.  
  13455.      This will ensure that the user can't change any privilege columns
  13456.      directly, but has to use the `GRANT' command to give privileges to
  13457.      other users.
  13458.  
  13459. `--skip-grant-tables'
  13460.      This option causes the server not to use the privilege system at
  13461.      all. This gives everyone *full access* to all databases!  (You can
  13462.      tell a running server to start using the grant tables again by
  13463.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  13464.  
  13465. `--skip-name-resolve'
  13466.      Hostnames are not resolved.  All `Host' column values in the grant
  13467.      tables must be IP numbers or `localhost'.
  13468.  
  13469. `--skip-networking'
  13470.      Don't allow TCP/IP connections over the network.  All connections
  13471.      to `mysqld' must be made via Unix sockets.  This option is
  13472.      unsuitable when using a MySQL version prior to 3.23.27 with the
  13473.      MIT-pthreads package, because Unix sockets were not supported by
  13474.      MIT-pthreads at that time.
  13475.  
  13476. `--skip-show-database'
  13477.      Don't allow `SHOW DATABASES' command, unless the user has the
  13478.      `SHOW DATABASES' privilege. From version 4.0.2 you should no longer
  13479.      need this option, since access can now be granted specifically
  13480.      with the `SHOW DATABASES' privilege.
  13481.  
  13482. Security issues with LOAD DATA LOCAL
  13483. ------------------------------------
  13484.  
  13485. In MySQL 3.23.49 and MySQL 4.0.2, we added some new options to deal with
  13486. possible security issues when it comes to `LOAD DATA LOCAL'.
  13487.  
  13488. There are two possible problems with supporting this command:
  13489.  
  13490. As the reading of the file is initiated from the server, one could
  13491. theoretically create a patched MySQL server that could read any file on
  13492. the client machine that the current user has read access to, when the
  13493. client issues a query against the table.
  13494.  
  13495. In a web environment where the clients are connecting from a web
  13496. server, a user could use `LOAD DATA LOCAL' to read any files that the
  13497. web server process has read access to (assuming a user could run any
  13498. command against the SQL server).
  13499.  
  13500. There are two separate fixes for this:
  13501.  
  13502. If you don't configure MySQL with `--enable-local-infile', then `LOAD
  13503. DATA LOCAL' will be disabled by all clients, unless one calls
  13504. `mysql_options(... MYSQL_OPT_LOCAL_INFILE, 0)' in the client.  *Note
  13505. `mysql_options()': mysql_options.
  13506.  
  13507. For the `mysql' command-line client, `LOAD DATA LOCAL' can be enabled
  13508. by specifying the option `--local-infile[=1]', or disabled with
  13509. `--local-infile=0'.
  13510.  
  13511. By default, all MySQL clients and libraries are compiled with
  13512. `--enable-local-infile', to be compatible with MySQL 3.23.48 and before.
  13513.  
  13514. One can disable all `LOAD DATA LOCAL' commands in the MySQL server by
  13515. starting `mysqld' with `--local-infile=0'.
  13516.  
  13517. In the case that `LOAD DATA LOCAL INFILE' is disabled in the server or
  13518. the client, you will get the error message (1148):
  13519.  
  13520.      The used command is not allowed with this MySQL version
  13521.  
  13522. What the Privilege System Does
  13523. ------------------------------
  13524.  
  13525. The primary function of the MySQL privilege system is to authenticate a
  13526. user connecting from a given host, and to associate that user with
  13527. privileges on a database such as `SELECT', `INSERT', `UPDATE' and
  13528. `DELETE'.
  13529.  
  13530. Additional functionality includes the ability to have an anonymous user
  13531. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  13532. INFILE' and administrative operations.
  13533.  
  13534. How the Privilege System Works
  13535. ------------------------------
  13536.  
  13537. The MySQL privilege system ensures that all users may do exactly the
  13538. things that they are supposed to be allowed to do.  When you connect to
  13539. a MySQL server, your identity is determined by *the host from which you
  13540. connect* and *the user name you specify*.  The system grants privileges
  13541. according to your identity and *what you want to do*.
  13542.  
  13543. MySQL considers both your hostname and user name in identifying you
  13544. because there is little reason to assume that a given user name belongs
  13545. to the same person everywhere on the Internet.  For example, the user
  13546. `joe' who connects from `office.com' need not be the same person as the
  13547. user `joe' who connects from `elsewhere.com'.  MySQL handles this by
  13548. allowing you to distinguish users on different hosts that happen to
  13549. have the same name:  you can grant `joe' one set of privileges for
  13550. connections from `office.com', and a different set of privileges for
  13551. connections from `elsewhere.com'.
  13552.  
  13553. MySQL access control involves two stages:
  13554.  
  13555.    * Stage 1: The server checks whether you are even allowed to connect.
  13556.  
  13557.    * Stage 2: Assuming you can connect, the server checks each request
  13558.      you issue to see whether you have sufficient privileges to perform
  13559.      it.  For example, if you try to select rows from a table in a
  13560.      database or drop a table from the database, the server makes sure
  13561.      you have the `SELECT' privilege for the table or the `DROP'
  13562.      privilege for the database.
  13563.  
  13564. The server uses the `user', `db', and `host' tables in the `mysql'
  13565. database at both stages of access control.  The fields in these grant
  13566. tables are shown here:
  13567.  
  13568. *Table name*   `user'         `db'           `host'
  13569. *Scope         `Host'         `Host'         `Host'
  13570. fields*                                      
  13571.                `User'         `Db'           `Db'
  13572.                `Password'     `User'         
  13573. *Privilege     `Select_priv'  `Select_priv'  `Select_priv'
  13574. fields*                                      
  13575.                `Insert_priv'  `Insert_priv'  `Insert_priv'
  13576.                `Update_priv'  `Update_priv'  `Update_priv'
  13577.                `Delete_priv'  `Delete_priv'  `Delete_priv'
  13578.                `Index_priv'   `Index_priv'   `Index_priv'
  13579.                `Alter_priv'   `Alter_priv'   `Alter_priv'
  13580.                `Create_priv'  `Create_priv'  `Create_priv'
  13581.                `Drop_priv'    `Drop_priv'    `Drop_priv'
  13582.                `Grant_priv'   `Grant_priv'   `Grant_priv'
  13583.                `References_priv'               
  13584.                `Reload_priv'                 
  13585.                `Shutdown_priv'               
  13586.                `Process_priv'                
  13587.                `File_priv'                   
  13588.  
  13589. For the second stage of access control (request verification), the
  13590. server may, if the request involves tables, additionally consult the
  13591. `tables_priv' and `columns_priv' tables.  The fields in these tables
  13592. are shown here:
  13593.  
  13594. *Table name*   `tables_priv'  `columns_priv'
  13595. *Scope         `Host'         `Host'
  13596. fields*                       
  13597.                `Db'           `Db'
  13598.                `User'         `User'
  13599.                `Table_name'   `Table_name'
  13600.                               `Column_name'
  13601. *Privilege     `Table_priv'   `Column_priv'
  13602. fields*                       
  13603.                `Column_priv'  
  13604. *Other         `Timestamp'    `Timestamp'
  13605. fields*                       
  13606.                `Grantor'      
  13607.  
  13608. Each grant table contains scope fields and privilege fields.
  13609.  
  13610. Scope fields determine the scope of each entry in the tables, that is,
  13611. the context in which the entry applies.  For example, a `user' table
  13612. entry with `Host' and `User' values of `'thomas.loc.gov'' and `'bob''
  13613. would be used for authenticating connections made to the server by
  13614. `bob' from the host `thomas.loc.gov'.  Similarly, a `db' table entry
  13615. with `Host', `User', and `Db' fields of `'thomas.loc.gov'', `'bob'' and
  13616. `'reports'' would be used when `bob' connects from the host
  13617. `thomas.loc.gov' to access the `reports' database.  The `tables_priv'
  13618. and `columns_priv' tables contain scope fields indicating tables or
  13619. table/column combinations to which each entry applies.
  13620.  
  13621. For access-checking purposes, comparisons of `Host' values are
  13622. case-insensitive.  `User', `Password', `Db', and `Table_name' values
  13623. are case-sensitive.  `Column_name' values are case-insensitive in MySQL
  13624. Version 3.22.12 or later.
  13625.  
  13626. Privilege fields indicate the privileges granted by a table entry, that
  13627. is, what operations can be performed.  The server combines the
  13628. information in the various grant tables to form a complete description
  13629. of a user's privileges.  The rules used to do this are described in
  13630. *Note Request access::.
  13631.  
  13632. Scope fields are strings, declared as shown here; the default value for
  13633. each is the empty string:
  13634.  
  13635. *Field name*   *Type*      *Notes*
  13636. `Host'         `CHAR(60)'  
  13637. `User'         `CHAR(16)'  
  13638. `Password'     `CHAR(16)'  
  13639. `Db'           `CHAR(64)'  (`CHAR(60)' for the `tables_priv' and
  13640.                            `columns_priv' tables)
  13641. `Table_name'   `CHAR(60)'  
  13642. `Column_name'  `CHAR(60)'  
  13643.  
  13644. In the `user', `db' and `host' tables, all privilege fields are
  13645. declared as `ENUM('N','Y')'each can have a value of `'N'' or `'Y'', and
  13646. the default value is `'N''.
  13647.  
  13648. In the `tables_priv' and `columns_priv' tables, the privilege fields
  13649. are declared as `SET' fields:
  13650.  
  13651. *Table      *Field      *Possible set elements*
  13652. name*       name*       
  13653. `tables_priv'`Table_priv'`'Select', 'Insert', 'Update',
  13654.                         'Delete', 'Create', 'Drop', 'Grant',
  13655.                         'References', 'Index', 'Alter''
  13656. `tables_priv'`Column_priv'`'Select', 'Insert', 'Update',
  13657.                         'References''
  13658. `columns_priv'`Column_priv'`'Select', 'Insert', 'Update',
  13659.                         'References''
  13660.  
  13661. Briefly, the server uses the grant tables like this:
  13662.  
  13663.    * The `user' table scope fields determine whether to allow or reject
  13664.      incoming connections.  For allowed connections, any privileges
  13665.      granted in the `user' table indicate the user's global (superuser)
  13666.      privileges.  These privileges apply to *all* databases on the
  13667.      server.
  13668.  
  13669.    * The `db' and `host' tables are used together:
  13670.  
  13671.         - The `db' table scope fields determine which users can access
  13672.           which databases from which hosts.  The privilege fields
  13673.           determine which operations are allowed.
  13674.  
  13675.         - The `host' table is used as an extension of the `db' table
  13676.           when you want a given `db' table entry to apply to several
  13677.           hosts.  For example, if you want a user to be able to use a
  13678.           database from several hosts in your network, leave the `Host'
  13679.           value empty in the user's `db' table entry, then populate the
  13680.           `host' table with an entry for each of those hosts.  This
  13681.           mechanism is described more detail in *Note Request access::.
  13682.  
  13683.    * The `tables_priv' and `columns_priv' tables are similar to the
  13684.      `db' table, but are more fine-grained: they apply at the table and
  13685.      column levels rather than at the database level.
  13686.  
  13687. Note that administrative privileges (`RELOAD', `SHUTDOWN', etc.) are
  13688. specified only in the `user' table.  This is because administrative
  13689. operations are operations on the server itself and are not
  13690. database-specific, so there is no reason to list such privileges in the
  13691. other grant tables.  In fact, only the `user' table need be consulted
  13692. to determine whether you can perform an administrative operation.
  13693.  
  13694. The `FILE' privilege is specified only in the `user' table, too.  It is
  13695. not an administrative privilege as such, but your ability to read or
  13696. write files on the server host is independent of the database you are
  13697. accessing.
  13698.  
  13699. The `mysqld' server reads the contents of the grant tables once, when it
  13700. starts up.  Changes to the grant tables take effect as indicated in
  13701. *Note Privilege changes::.
  13702.  
  13703. When you modify the contents of the grant tables, it is a good idea to
  13704. make sure that your changes set up privileges the way you want.  For
  13705. help in diagnosing problems, see *Note Access denied::.  For advice on
  13706. security issues, see *Note Security::.
  13707.  
  13708. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  13709. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  13710. with the `--help' option to find out how it works.  Note that
  13711. `mysqlaccess' checks access using only the `user', `db' and `host'
  13712. tables.  It does not check table- or column-level privileges.
  13713.  
  13714. Privileges Provided by MySQL
  13715. ----------------------------
  13716.  
  13717. Information about user privileges is stored in the `user', `db',
  13718. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  13719. database (that is, in the database named `mysql').  The MySQL server
  13720. reads the contents of these tables when it starts up and under the
  13721. circumstances indicated in *Note Privilege changes::.
  13722.  
  13723. The names used in this manual to refer to the privileges provided by
  13724. MySQL version 4.0.2 are shown here, along with the table column name
  13725. associated with each privilege in the grant tables and the context in
  13726. which the privilege applies:
  13727.  
  13728. *Privilege* *Column*       *Context*
  13729. `ALTER'     `Alter_priv'   tables
  13730. `DELETE'    `Delete_priv'  tables
  13731. `INDEX'     `Index_priv'   tables
  13732. `INSERT'    `Insert_priv'  tables
  13733. `SELECT'    `Select_priv'  tables
  13734. `UPDATE'    `Update_priv'  tables
  13735. `CREATE'    `Create_priv'  databases, tables, or
  13736.                            indexes
  13737. `DROP'      `Drop_priv'    databases or tables
  13738. `GRANT'     `Grant_priv'   databases or tables
  13739. `REFERENCES'`References_priv'databases or tables
  13740. `CREATE     `Create_tmp_table_priv'server administration
  13741. TEMPORARY                  
  13742. TABLES'                    
  13743. `EXECUTE'   `Execute_priv' server administration
  13744. `FILE'      `File_priv'    file access on server
  13745. `LOCK       `Lock_tables_priv'server administration
  13746. TABLES'                    
  13747. `PROCESS'   `Process_priv' server administration
  13748. `RELOAD'    `Reload_priv'  server administration
  13749. `REPLICATION`Repl_client_priv'server administration
  13750. CLIENT'                    
  13751. `REPLICATION`Repl_slave_priv'server administration
  13752. SLAVE'                     
  13753. `SHOW       `Show_db_priv' server administration
  13754. DATABASES'                 
  13755. `SHUTDOWN'  `Shutdown_priv'server administration
  13756. `SUPER'     `Super_priv'   server administration
  13757.  
  13758. The `SELECT', `INSERT', `UPDATE', and `DELETE' privileges allow you to
  13759. perform operations on rows in existing tables in a database.
  13760.  
  13761. `SELECT' statements require the `SELECT' privilege only if they
  13762. actually retrieve rows from a table.  You can execute certain `SELECT'
  13763. statements even without permission to access any of the databases on the
  13764. server.  For example, you could use the `mysql' client as a simple
  13765. calculator:
  13766.  
  13767.      mysql> SELECT 1+1;
  13768.      mysql> SELECT PI()*2;
  13769.  
  13770. The `INDEX' privilege allows you to create or drop (remove) indexes.
  13771.  
  13772. The `ALTER' privilege allows you to use `ALTER TABLE'.
  13773.  
  13774. The `CREATE' and `DROP' privileges allow you to create new databases
  13775. and tables, or to drop (remove) existing databases and tables.
  13776.  
  13777. Note that if you grant the `DROP' privilege for the `mysql' database to
  13778. a user, that user can drop the database in which the MySQL access
  13779. privileges are stored!
  13780.  
  13781. The `GRANT' privilege allows you to give to other users those
  13782. privileges you yourself possess.
  13783.  
  13784. The `FILE' privilege gives you permission to read and write files on
  13785. the server using the `LOAD DATA INFILE' and `SELECT ... INTO OUTFILE'
  13786. statements.  Any user to whom this privilege is granted can read or
  13787. write any file that the MySQL server can read or write.
  13788.  
  13789. The remaining privileges are used for administrative operations, which
  13790. are performed using the `mysqladmin' program.  The table here shows
  13791. which `mysqladmin' commands each administrative privilege allows you to
  13792. execute:
  13793.  
  13794. *Privilege* *Commands permitted to privilege holders*
  13795. `RELOAD'    `reload', `refresh', `flush-privileges',
  13796.             `flush-hosts', `flush-logs', and `flush-tables'
  13797. `SHUTDOWN'  `shutdown'
  13798. `PROCESS'   `processlist'
  13799. `SUPER'     `kill'
  13800.  
  13801. The `reload' command tells the server to re-read the grant tables.  The
  13802. `refresh' command flushes all tables and opens and closes the log
  13803. files.  `flush-privileges' is a synonym for `reload'.  The other
  13804. `flush-*' commands perform functions similar to `refresh' but are more
  13805. limited in scope, and may be preferable in some instances.  For example,
  13806. if you want to flush just the log files, `flush-logs' is a better choice
  13807. than `refresh'.
  13808.  
  13809. The `shutdown' command shuts down the server.
  13810.  
  13811. The `processlist' command displays information about the threads
  13812. executing within the server.  The `kill' command kills server threads.
  13813. You can always display or kill your own threads, but you need the
  13814. `PROCESS' privilege to display and `SUPER' privilege to kill threads
  13815. initiated by other users. *Note KILL::.
  13816.  
  13817. It is a good idea in general to grant privileges only to those users
  13818. who need them, but you should exercise particular caution in granting
  13819. certain privileges:
  13820.  
  13821.    * The `GRANT' privilege allows users to give away their privileges to
  13822.      other users.  Two users with different privileges and with the
  13823.      `GRANT' privilege are able to combine privileges.
  13824.  
  13825.    * The `ALTER' privilege may be used to subvert the privilege system
  13826.      by renaming tables.
  13827.  
  13828.    * The `FILE' privilege can be abused to read any world-readable file
  13829.      on the server into a database table, the contents of which can
  13830.      then be accessed using `SELECT'. This includes the contents of all
  13831.      databases hosted by the server!
  13832.  
  13833.    * The `SHUTDOWN' privilege can be abused to deny service to other
  13834.      users entirely, by terminating the server.
  13835.  
  13836.    * The `PROCESS' privilege can be used to view the plain text of
  13837.      currently executing queries, including queries that set or change
  13838.      passwords.
  13839.  
  13840.    * Privileges on the `mysql' database can be used to change passwords
  13841.      and other access privilege information.  (Passwords are stored
  13842.      encrypted, so a malicious user cannot simply read them to know the
  13843.      plain text password.)  If they can access the `mysql.user' password
  13844.      column, they can use it to log into the MySQL server for the given
  13845.      user.  (With sufficient privileges, the same user can replace a
  13846.      password with a different one.)
  13847.  
  13848. There are some things that you cannot do with the MySQL privilege
  13849. system:
  13850.  
  13851.    * You cannot explicitly specify that a given user should be denied
  13852.      access.  That is, you cannot explicitly match a user and then
  13853.      refuse the connection.
  13854.  
  13855.    * You cannot specify that a user has privileges to create or drop
  13856.      tables in a database but not to create or drop the database itself.
  13857.  
  13858. Connecting to the MySQL Server
  13859. ------------------------------
  13860.  
  13861. MySQL client programs generally require that you specify connection
  13862. parameters when you want to access a MySQL server: the host you want to
  13863. connect to, your user name, and your password.  For example, the
  13864. `mysql' client can be started like this (optional arguments are enclosed
  13865. between `[' and `]'):
  13866.  
  13867.      shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
  13868.  
  13869. Alternate forms of the `-h', `-u', and `-p' options are
  13870. `--host=host_name', `--user=user_name', and `--password=your_pass'.
  13871. Note that there is _no space_ between `-p' or `--password=' and the
  13872. password following it.
  13873.  
  13874. *Note*: Specifying a password on the command-line is not secure!  Any
  13875. user on your system may then find out your password by typing a command
  13876. like: `ps auxww'.  *Note Option files::.
  13877.  
  13878. `mysql' uses default values for connection parameters that are missing
  13879. from the command-line:
  13880.  
  13881.    * The default hostname is `localhost'.
  13882.  
  13883.    * The default user name is your Unix login name.
  13884.  
  13885.    * No password is supplied if `-p' is missing.
  13886.  
  13887. Thus, for a Unix user `joe', the following commands are equivalent:
  13888.  
  13889.      shell> mysql -h localhost -u joe
  13890.      shell> mysql -h localhost
  13891.      shell> mysql -u joe
  13892.      shell> mysql
  13893.  
  13894. Other MySQL clients behave similarly.
  13895.  
  13896. On Unix systems, you can specify different default values to be used
  13897. when you make a connection, so that you need not enter them on the
  13898. command-line each time you invoke a client program.  This can be done
  13899. in a couple of ways:
  13900.  
  13901.    * You can specify connection parameters in the `[client]' section of
  13902.      the `.my.cnf' configuration file in your home directory.  The
  13903.      relevant section of the file might look like this:
  13904.  
  13905.           [client]
  13906.           host=host_name
  13907.           user=user_name
  13908.           password=your_pass
  13909.  
  13910.      *Note Option files::.
  13911.  
  13912.    * You can specify connection parameters using environment variables.
  13913.      The host can be specified for `mysql' using `MYSQL_HOST'.  The
  13914.      MySQL user name can be specified using `USER' (this is for Windows
  13915.      only).  The password can be specified using `MYSQL_PWD' (but this
  13916.      is insecure; see the next section).  *Note Environment variables::.
  13917.  
  13918. Access Control, Stage 1: Connection Verification
  13919. ------------------------------------------------
  13920.  
  13921. When you attempt to connect to a MySQL server, the server accepts or
  13922. rejects the connection based on your identity and whether you can
  13923. verify your identity by supplying the correct password.  If not, the
  13924. server denies access to you completely.  Otherwise, the server accepts
  13925. the connection, then enters Stage 2 and waits for requests.
  13926.  
  13927. Your identity is based on two pieces of information:
  13928.  
  13929.    * The host from which you connect
  13930.  
  13931.    * Your MySQL user name
  13932.  
  13933. Identity checking is performed using the three `user' table scope fields
  13934. (`Host', `User', and `Password').  The server accepts the connection
  13935. only if a `user' table entry matches your hostname and user name, and
  13936. you supply the correct password.
  13937.  
  13938. Values in the `user' table scope fields may be specified as follows:
  13939.  
  13940.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  13941.      to indicate the local host.
  13942.  
  13943.    * You can use the wildcard characters `%' and `_' in the `Host'
  13944.      field.
  13945.  
  13946.    * A `Host' value of `'%'' matches any hostname.
  13947.  
  13948.    * A blank `Host' value means that the privilege should be anded with
  13949.      the entry in the `host' table that matches the given host name.
  13950.      You can find more information about this in the next chapter.
  13951.  
  13952.    * As of MySQL Version 3.23, for `Host' values specified as IP
  13953.      numbers, you can specify a netmask indicating how many address
  13954.      bits to use for the network number. For example:
  13955.  
  13956.           mysql> GRANT ALL PRIVILEGES ON db.*
  13957.               -> TO david@'192.58.197.0/255.255.255.0';
  13958.  
  13959.      This will allow everyone to connect from an IP where the following
  13960.      is true:
  13961.  
  13962.           user_ip & netmask = host_ip.
  13963.  
  13964.      In the above example all IP:s in the interval 192.58.197.0 -
  13965.      192.58.197.255 can connect to the MySQL server.
  13966.  
  13967.    * Wildcard characters are not allowed in the `User' field, but you
  13968.      can specify a blank value, which matches any name.  If the `user'
  13969.      table entry that matches an incoming connection has a blank user
  13970.      name, the user is considered to be the anonymous user (the user
  13971.      with no name), rather than the name that the client actually
  13972.      specified.  This means that a blank user name is used for all
  13973.      further access checking for the duration of the connection (that
  13974.      is, during Stage 2).
  13975.  
  13976.    * The `Password' field can be blank.  This does not mean that any
  13977.      password matches, it means the user must connect without
  13978.      specifying a password.
  13979.  
  13980. Non-blank `Password' values represent encrypted passwords.  MySQL does
  13981. not store passwords in plaintext form for anyone to see.  Rather, the
  13982. password supplied by a user who is attempting to connect is encrypted
  13983. (using the `PASSWORD()' function). The encrypted password is then used
  13984. when the client/server is checking if the password is correct. (This is
  13985. done without the encrypted password ever traveling over the
  13986. connection.)  Note that from MySQL's point of view the encrypted
  13987. password is the REAL password, so you should not give anyone access to
  13988. it!  In particular, don't give normal users read access to the tables
  13989. in the `mysql' database!
  13990.  
  13991. The examples here show how various combinations of `Host' and `User'
  13992. values in `user' table entries apply to incoming connections:
  13993.  
  13994. `Host' *value*            `User'      *Connections matched by entry*
  13995.                           *value*     
  13996. `'thomas.loc.gov''        `'fred''    `fred', connecting from
  13997.                                       `thomas.loc.gov'
  13998. `'thomas.loc.gov''        `'''        Any user, connecting from
  13999.                                       `thomas.loc.gov'
  14000. `'%''                     `'fred''    `fred', connecting from any host
  14001. `'%''                     `'''        Any user, connecting from any host
  14002. `'%.loc.gov''             `'fred''    `fred', connecting from any host in
  14003.                                       the `loc.gov' domain
  14004. `'x.y.%''                 `'fred''    `fred', connecting from `x.y.net',
  14005.                                       `x.y.com',`x.y.edu', etc. (this is
  14006.                                       probably not useful)
  14007. `'144.155.166.177''       `'fred''    `fred', connecting from the host
  14008.                                       with IP address `144.155.166.177'
  14009. `'144.155.166.%''         `'fred''    `fred', connecting from any host in
  14010.                                       the `144.155.166' class C subnet
  14011. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  14012.  
  14013. Because you can use IP wildcard values in the `Host' field (for example,
  14014. `'144.155.166.%'' to match every host on a subnet), there is the
  14015. possibility that someone might try to exploit this capability by naming
  14016. a host `144.155.166.somewhere.com'.  To foil such attempts, MySQL
  14017. disallows matching on hostnames that start with digits and a dot. Thus,
  14018. if you have a host named something like `1.2.foo.com', its name will
  14019. never match the `Host' column of the grant tables.  Only an IP number
  14020. can match an IP wildcard value.
  14021.  
  14022. An incoming connection may be matched by more than one entry in the
  14023. `user' table.  For example, a connection from `thomas.loc.gov' by
  14024. `fred' would be matched by several of the entries just shown above.  How
  14025. does the server choose which entry to use if more than one matches?  The
  14026. server resolves this question by sorting the `user' table after reading
  14027. it at startup time, then looking through the entries in sorted order
  14028. when a user attempts to connect.  The first matching entry is the one
  14029. that is used.
  14030.  
  14031. `user' table sorting works as follows.  Suppose the `user' table looks
  14032. like this:
  14033.  
  14034.      +-----------+----------+-
  14035.      | Host      | User     | ...
  14036.      +-----------+----------+-
  14037.      | %         | root     | ...
  14038.      | %         | jeffrey  | ...
  14039.      | localhost | root     | ...
  14040.      | localhost |          | ...
  14041.      +-----------+----------+-
  14042.  
  14043. When the server reads in the table, it orders the entries with the
  14044. most-specific `Host' values first (`'%'' in the `Host' column means
  14045. "any host" and is least specific).  Entries with the same `Host' value
  14046. are ordered with the most-specific `User' values first (a blank `User'
  14047. value means "any user" and is least specific).  The resulting sorted
  14048. `user' table looks like this:
  14049.  
  14050.      +-----------+----------+-
  14051.      | Host      | User     | ...
  14052.      +-----------+----------+-
  14053.      | localhost | root     | ...
  14054.      | localhost |          | ...
  14055.      | %         | jeffrey  | ...
  14056.      | %         | root     | ...
  14057.      +-----------+----------+-
  14058.  
  14059. When a connection is attempted, the server looks through the sorted
  14060. entries and uses the first match found.  For a connection from
  14061. `localhost' by `jeffrey', the entries with `'localhost'' in the `Host'
  14062. column match first.  Of those, the entry with the blank user name
  14063. matches both the connecting hostname and user name.  (The
  14064. `'%'/'jeffrey'' entry would have matched, too, but it is not the first
  14065. match in the table.)
  14066.  
  14067. Here is another example.  Suppose the `user' table looks like this:
  14068.  
  14069.      +----------------+----------+-
  14070.      | Host           | User     | ...
  14071.      +----------------+----------+-
  14072.      | %              | jeffrey  | ...
  14073.      | thomas.loc.gov |          | ...
  14074.      +----------------+----------+-
  14075.  
  14076. The sorted table looks like this:
  14077.  
  14078.      +----------------+----------+-
  14079.      | Host           | User     | ...
  14080.      +----------------+----------+-
  14081.      | thomas.loc.gov |          | ...
  14082.      | %              | jeffrey  | ...
  14083.      +----------------+----------+-
  14084.  
  14085. A connection from `thomas.loc.gov' by `jeffrey' is matched by the first
  14086. entry, whereas a connection from `whitehouse.gov' by `jeffrey' is
  14087. matched by the second.
  14088.  
  14089. A common misconception is to think that for a given user name, all
  14090. entries that explicitly name that user will be used first when the
  14091. server attempts to find a match for the connection.  This is simply not
  14092. true.  The previous example illustrates this, where a connection from
  14093. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  14094. containing `'jeffrey'' as the `User' field value, but by the entry with
  14095. no user name!
  14096.  
  14097. If you have problems connecting to the server, print out the `user'
  14098. table and sort it by hand to see where the first match is being made.
  14099. If connection was successful, but your privileges are not what you
  14100. expected you may use `CURRENT_USER()' function (new in version 4.0.6)
  14101. to see what user/host combination your connection actually matched.
  14102. *Note `CURRENT_USER()': Miscellaneous functions.
  14103.  
  14104. Access Control, Stage 2: Request Verification
  14105. ---------------------------------------------
  14106.  
  14107. Once you establish a connection, the server enters Stage 2.  For each
  14108. request that comes in on the connection, the server checks whether you
  14109. have sufficient privileges to perform it, based on the type of
  14110. operation you wish to perform.  This is where the privilege fields in
  14111. the grant tables come into play.  These privileges can come from any of
  14112. the `user', `db', `host', `tables_priv', or `columns_priv' tables.  The
  14113. grant tables are manipulated with `GRANT' and `REVOKE' commands.  *Note
  14114. `GRANT': GRANT.  (You may find it helpful to refer to *Note
  14115. Privileges::, which lists the fields present in each of the grant
  14116. tables.)
  14117.  
  14118. The `user' table grants privileges that are assigned to you on a global
  14119. basis and that apply no matter what the current database is.  For
  14120. example, if the `user' table grants you the `DELETE' privilege, you can
  14121. delete rows from any database on the server host!  In other words,
  14122. `user' table privileges are superuser privileges.  It is wise to grant
  14123. privileges in the `user' table only to superusers such as server or
  14124. database administrators.  For other users, you should leave the
  14125. privileges in the `user' table set to `'N'' and grant privileges on a
  14126. database-specific basis only, using the `db' and `host' tables.
  14127.  
  14128. The `db' and `host' tables grant database-specific privileges.  Values
  14129. in the scope fields may be specified as follows:
  14130.  
  14131.    * The wildcard characters `%' and `_' can be used in the `Host' and
  14132.      `Db' fields of either table. If you wish to use for instance a `_'
  14133.      character as part of a database name, specify it as `\_' in the
  14134.      `GRANT' command.
  14135.  
  14136.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  14137.      `Host' value in the `db' table means "consult the `host' table for
  14138.      further information."
  14139.  
  14140.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  14141.  
  14142.    * A `'%'' or blank `Db' value in either table means "any database."
  14143.  
  14144.    * A blank `User' value in either table matches the anonymous user.
  14145.  
  14146. The `db' and `host' tables are read in and sorted when the server
  14147. starts up (at the same time that it reads the `user' table).  The `db'
  14148. table is sorted on the `Host', `Db', and `User' scope fields, and the
  14149. `host' table is sorted on the `Host' and `Db' scope fields.  As with
  14150. the `user' table, sorting puts the most-specific values first and
  14151. least-specific values last, and when the server looks for matching
  14152. entries, it uses the first match that it finds.
  14153.  
  14154. The `tables_priv' and `columns_priv' tables grant table- and
  14155. column-specific privileges.  Values in the scope fields may be
  14156. specified as follows:
  14157.  
  14158.    * The wildcard characters `%' and `_' can be used in the `Host'
  14159.      field of either table.
  14160.  
  14161.    * A `'%'' or blank `Host' value in either table means "any host."
  14162.  
  14163.    * The `Db', `Table_name' and `Column_name' fields cannot contain
  14164.      wildcards or be blank in either table.
  14165.  
  14166. The `tables_priv' and `columns_priv' tables are sorted on the `Host',
  14167. `Db', and `User' fields.  This is similar to `db' table sorting,
  14168. although the sorting is simpler because only the `Host' field may
  14169. contain wildcards.
  14170.  
  14171. The request verification process is described here.  (If you are
  14172. familiar with the access-checking source code, you will notice that the
  14173. description here differs slightly from the algorithm used in the code.
  14174. The description is equivalent to what the code actually does; it
  14175. differs only to make the explanation simpler.)
  14176.  
  14177. For administrative requests (`SHUTDOWN', `RELOAD', etc.), the server
  14178. checks only the `user' table entry, because that is the only table that
  14179. specifies administrative privileges.  Access is granted if the entry
  14180. allows the requested operation and denied otherwise.  For example, if
  14181. you want to execute `mysqladmin shutdown' but your `user' table entry
  14182. doesn't grant the `SHUTDOWN' privilege to you, access is denied without
  14183. even checking the `db' or `host' tables.  (They contain no
  14184. `Shutdown_priv' column, so there is no need to do so.)
  14185.  
  14186. For database-related requests (`INSERT', `UPDATE', etc.), the server
  14187. first checks the user's global (superuser) privileges by looking in the
  14188. `user' table entry.  If the entry allows the requested operation,
  14189. access is granted.  If the global privileges in the `user' table are
  14190. insufficient, the server determines the user's database-specific
  14191. privileges by checking the `db' and `host' tables:
  14192.  
  14193.   1. The server looks in the `db' table for a match on the `Host',
  14194.      `Db', and `User' fields.  The `Host' and `User' fields are matched
  14195.      to the connecting user's hostname and MySQL user name.  The `Db'
  14196.      field is matched to the database the user wants to access.  If
  14197.      there is no entry for the `Host' and `User', access is denied.
  14198.  
  14199.   2. If there is a matching `db' table entry and its `Host' field is
  14200.      not blank, that entry defines the user's database-specific
  14201.      privileges.
  14202.  
  14203.   3. If the matching `db' table entry's `Host' field is blank, it
  14204.      signifies that the `host' table enumerates which hosts should be
  14205.      allowed access to the database.  In this case, a further lookup is
  14206.      done in the `host' table to find a match on the `Host' and `Db'
  14207.      fields.  If no `host' table entry matches, access is denied.  If
  14208.      there is a match, the user's database-specific privileges are
  14209.      computed as the intersection (*not* the union!) of the privileges
  14210.      in the `db' and `host' table entries, that is, the privileges that
  14211.      are `'Y'' in both entries.  (This way you can grant general
  14212.      privileges in the `db' table entry and then selectively restrict
  14213.      them on a host-by-host basis using the `host' table entries.)
  14214.  
  14215. After determining the database-specific privileges granted by the `db'
  14216. and `host' table entries, the server adds them to the global privileges
  14217. granted by the `user' table.  If the result allows the requested
  14218. operation, access is granted.  Otherwise, the server checks the user's
  14219. table and column privileges in the `tables_priv' and `columns_priv'
  14220. tables and adds those to the user's privileges.  Access is allowed or
  14221. denied based on the result.
  14222.  
  14223. Expressed in boolean terms, the preceding description of how a user's
  14224. privileges are calculated may be summarised like this:
  14225.  
  14226.      global privileges
  14227.      OR (database privileges AND host privileges)
  14228.      OR table privileges
  14229.      OR column privileges
  14230.  
  14231. It may not be apparent why, if the global `user' entry privileges are
  14232. initially found to be insufficient for the requested operation, the
  14233. server adds those privileges to the database-, table-, and
  14234. column-specific privileges later. The reason is that a request might
  14235. require more than one type of privilege.  For example, if you execute
  14236. an `INSERT ...  SELECT' statement, you need both `INSERT' and `SELECT'
  14237. privileges.  Your privileges might be such that the `user' table entry
  14238. grants one privilege and the `db' table entry grants the other.  In
  14239. this case, you have the necessary privileges to perform the request,
  14240. but the server cannot tell that from either table by itself; the
  14241. privileges granted by the entries in both tables must be combined.
  14242.  
  14243. The `host' table can be used to maintain a list of secure servers.
  14244.  
  14245. At TcX, the `host' table contains a list of all machines on the local
  14246. network. These are granted all privileges.
  14247.  
  14248. You can also use the `host' table to indicate hosts that are *not*
  14249. secure.  Suppose you have a machine `public.your.domain' that is located
  14250. in a public area that you do not consider secure.  You can allow access
  14251. to all hosts on your network except that machine by using `host' table
  14252. entries like this:
  14253.  
  14254.      +--------------------+----+-
  14255.      | Host               | Db | ...
  14256.      +--------------------+----+-
  14257.      | public.your.domain | %  | ... (all privileges set to 'N')
  14258.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  14259.      +--------------------+----+-
  14260.  
  14261. Naturally, you should always test your entries in the grant tables (for
  14262. example, using `mysqlaccess') to make sure your access privileges are
  14263. actually set up the way you think they are.
  14264.  
  14265. Causes of `Access denied' Errors
  14266. --------------------------------
  14267.  
  14268. If you encounter `Access denied' errors when you try to connect to the
  14269. MySQL server, the following list indicates some courses of action you
  14270. can take to correct the problem:
  14271.  
  14272.    * After installing MySQL, did you run the `mysql_install_db' script
  14273.      to set up the initial grant table contents?  If not, do so.  *Note
  14274.      Default privileges::.  Test the initial privileges by executing
  14275.      this command:
  14276.  
  14277.           shell> mysql -u root test
  14278.  
  14279.      The server should let you connect without error.  You should also
  14280.      make sure you have a file `user.MYD' in the MySQL database
  14281.      directory.  Ordinarily, this is `PATH/var/mysql/user.MYD', where
  14282.      `PATH' is the pathname to the MySQL installation root.
  14283.  
  14284.    * After a fresh installation, you should connect to the server and
  14285.      set up your users and their access permissions:
  14286.  
  14287.           shell> mysql -u root mysql
  14288.  
  14289.      The server should let you connect because the MySQL `root' user
  14290.      has no password initially.  That is also a security risk, so
  14291.      setting the `root' password is something you should do while
  14292.      you're setting up your other MySQL users.
  14293.  
  14294.      If you try to connect as `root' and get this error:
  14295.  
  14296.           Access denied for user: '@unknown' to database mysql
  14297.  
  14298.      this means that you don't have an entry in the `user' table with a
  14299.      `User' column value of `'root'' and that `mysqld' cannot resolve
  14300.      the hostname for your client.  In this case, you must restart the
  14301.      server with the `--skip-grant-tables' option and edit your
  14302.      `/etc/hosts' or `\windows\hosts' file to add an entry for your
  14303.      host.
  14304.  
  14305.    * If you get an error like the following:
  14306.  
  14307.           shell> mysqladmin -u root -pxxxx ver
  14308.           Access denied for user: 'root@localhost' (Using password: YES)
  14309.  
  14310.      It means that you are using a wrong password. *Note Passwords::.
  14311.  
  14312.      If you have forgot the root password, you can restart `mysqld' with
  14313.      `--skip-grant-tables' to change the password.  *Note Resetting
  14314.      permissions::.
  14315.  
  14316.      If you get the above error even if you haven't specified a
  14317.      password, this means that you a wrong password in some `my.ini'
  14318.      file. *Note Option files::.  You can avoid using option files with
  14319.      the `--no-defaults' option, as follows:
  14320.  
  14321.           shell> mysqladmin --no-defaults -u root ver
  14322.  
  14323.    * If you updated an existing MySQL installation from a version
  14324.      earlier than Version 3.22.11 to Version 3.22.11 or later, did you
  14325.      run the `mysql_fix_privilege_tables' script?  If not, do so.  The
  14326.      structure of the grant tables changed with MySQL Version 3.22.11
  14327.      when the `GRANT' statement became functional.
  14328.  
  14329.    * If your privileges seem to have changed in the middle of a
  14330.      session, it may be that a superuser has changed them.  Reloading
  14331.      the grant tables affects new client connections, but it also
  14332.      affects existing connections as indicated in *Note Privilege
  14333.      changes::.
  14334.  
  14335.    * If you can't get your password to work, remember that you must use
  14336.      the `PASSWORD()' function if you set the password with the
  14337.      `INSERT', `UPDATE', or `SET PASSWORD' statements.  The
  14338.      `PASSWORD()' function is unnecessary if you specify the password
  14339.      using the `GRANT ... INDENTIFIED BY' statement or the `mysqladmin
  14340.      password' command.  *Note Passwords::.
  14341.  
  14342.    * `localhost' is a synonym for your local hostname, and is also the
  14343.      default host to which clients try to connect if you specify no host
  14344.      explicitly.  However, connections to `localhost' do not work if
  14345.      you are using a MySQL version prior to 3.23.27 that uses
  14346.      MIT-pthreads (`localhost' connections are made using Unix sockets,
  14347.      which were not supported by MIT-pthreads at that time).  To avoid
  14348.      this problem on such systems, you should use the `--host' option
  14349.      to name the server host explicitly.  This will make a TCP/IP
  14350.      connection to the `mysqld' server.  In this case, you must have
  14351.      your real hostname in `user' table entries on the server host.
  14352.      (This is true even if you are running a client program on the same
  14353.      host as the server.)
  14354.  
  14355.    * If you get an `Access denied' error when trying to connect to the
  14356.      database with `mysql -u user_name db_name', you may have a problem
  14357.      with the `user' table. Check this by executing `mysql -u root
  14358.      mysql' and issuing this SQL statement:
  14359.  
  14360.           mysql> SELECT * FROM user;
  14361.  
  14362.      The result should include an entry with the `Host' and `User'
  14363.      columns matching your computer's hostname and your MySQL user name.
  14364.  
  14365.    * The `Access denied' error message will tell you who you are trying
  14366.      to log in as, the host from which you are trying to connect, and
  14367.      whether or not you were using a password. Normally, you should
  14368.      have one entry in the `user' table that exactly matches the
  14369.      hostname and user name that were given in the error message. For
  14370.      example if you get an error message that contains `Using password:
  14371.      NO', this means that you tried to login without an password.
  14372.  
  14373.    * If you get the following error when you try to connect from a
  14374.      different host than the one on which the MySQL server is running,
  14375.      then there is no row in the `user' table that matches that host:
  14376.  
  14377.           Host ... is not allowed to connect to this MySQL server
  14378.  
  14379.      You can fix this by using the command-line tool `mysql' (on the
  14380.      server host!) to add a row to the `user', `db', or `host' table
  14381.      for the user/hostname combination from which you are trying to
  14382.      connect and then execute `mysqladmin flush-privileges'.  If you are
  14383.      not running MySQL Version 3.22 and you don't know the IP number or
  14384.      hostname of the machine from which you are connecting, you should
  14385.      put an entry with `'%'' as the `Host' column value in the `user'
  14386.      table and restart `mysqld' with the `--log' option on the server
  14387.      machine.  After trying to connect from the client machine, the
  14388.      information in the MySQL log will indicate how you really did
  14389.      connect.  (Then replace the `'%'' in the `user' table entry with
  14390.      the actual hostname that shows up in the log.  Otherwise, you'll
  14391.      have a system that is insecure.)
  14392.  
  14393.      Another reason for this error on Linux is that you are using a
  14394.      binary MySQL version that is compiled with a different glibc
  14395.      version than the one you are using.  In this case you should
  14396.      either upgrade your OS/glibc or download the source MySQL version
  14397.      and compile this yourself.  A source RPM is normally trivial to
  14398.      compile and install, so this isn't a big problem.
  14399.  
  14400.    * If you get an error message where the hostname is not shown or
  14401.      where the hostname is an IP, even if you try to connect with a
  14402.      hostname:
  14403.  
  14404.           shell> mysqladmin -u root -pxxxx -h some-hostname ver
  14405.           Access denied for user: 'root@' (Using password: YES)
  14406.  
  14407.      This means that MySQL got some error when trying to resolve the IP
  14408.      to a hostname.  In this case you can execute `mysqladmin
  14409.      flush-hosts' to reset the internal DNS cache. *Note DNS::.
  14410.  
  14411.      Some permanent solutions are:
  14412.  
  14413.         - Try to find out what is wrong with your DNS server and fix
  14414.           this.
  14415.  
  14416.         - Specify IPs instead of hostnames in the MySQL privilege
  14417.           tables.
  14418.  
  14419.         - Start `mysqld' with `--skip-name-resolve'.
  14420.  
  14421.         - Start `mysqld' with `--skip-host-cache'.
  14422.  
  14423.         - Connect to `localhost' if you are running the server and the
  14424.           client on the same machine.
  14425.  
  14426.         - Put the client machine names in `/etc/hosts'.
  14427.  
  14428.    * If `mysql -u root test' works but `mysql -h your_hostname -u root
  14429.      test' results in `Access denied', then you may not have the
  14430.      correct name for your host in the `user' table.  A common problem
  14431.      here is that the `Host' value in the user table entry specifies an
  14432.      unqualified hostname, but your system's name resolution routines
  14433.      return a fully qualified domain name (or vice-versa).  For
  14434.      example, if you have an entry with host `'tcx'' in the `user'
  14435.      table, but your DNS tells MySQL that your hostname is
  14436.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  14437.      the `user' table that contains the IP number of your host as the
  14438.      `Host' column value.  (Alternatively, you could add an entry to the
  14439.      `user' table with a `Host' value that contains a wildcard--for
  14440.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  14441.      *insecure* and is *not* recommended!)
  14442.  
  14443.    * If `mysql -u user_name test' works but `mysql -u user_name
  14444.      other_db_name' doesn't work, you don't have an entry for
  14445.      `other_db_name' listed in the `db' table.
  14446.  
  14447.    * If `mysql -u user_name db_name' works when executed on the server
  14448.      machine, but `mysql -u host_name -u user_name db_name' doesn't
  14449.      work when executed on another client machine, you don't have the
  14450.      client machine listed in the `user' table or the `db' table.
  14451.  
  14452.    * If you can't figure out why you get `Access denied', remove from
  14453.      the `user' table all entries that have `Host' values containing
  14454.      wildcards (entries that contain `%' or `_').  A very common error
  14455.      is to insert a new entry with `Host'=`'%'' and `User'=`'some
  14456.      user'', thinking that this will allow you to specify `localhost'
  14457.      to connect from the same machine.  The reason that this doesn't
  14458.      work is that the default privileges include an entry with
  14459.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  14460.      `Host' value `'localhost'' that is more specific than `'%'', it is
  14461.      used in preference to the new entry when connecting from
  14462.      `localhost'!  The correct procedure is to insert a second entry
  14463.      with `Host'=`'localhost'' and `User'=`'some_user'', or to remove
  14464.      the entry with `Host'=`'localhost'' and `User'=`'''.
  14465.  
  14466.    * If you get the following error, you may have a problem with the
  14467.      `db' or `host' table:
  14468.  
  14469.           Access to database denied
  14470.  
  14471.      If the entry selected from the `db' table has an empty value in the
  14472.      `Host' column, make sure there are one or more corresponding
  14473.      entries in the `host' table specifying which hosts the `db' table
  14474.      entry applies to.
  14475.  
  14476.      If you get the error when using the SQL commands `SELECT ...  INTO
  14477.      OUTFILE' or `LOAD DATA INFILE', your entry in the `user' table
  14478.      probably doesn't have the `FILE' privilege enabled.
  14479.  
  14480.    * Remember that client programs will use connection parameters
  14481.      specified in configuration files or environment variables.  *Note
  14482.      Environment variables::.  If a client seems to be sending the
  14483.      wrong default connection parameters when you don't specify them on
  14484.      the command-line, check your environment and the `.my.cnf' file in
  14485.      your home directory.  You might also check the system-wide MySQL
  14486.      configuration files, though it is far less likely that client
  14487.      connection parameters will be specified there. *Note Option
  14488.      files::.  If you get `Access denied' when you run a client without
  14489.      any options, make sure you haven't specified an old password in
  14490.      any of your option files!  *Note Option files::.
  14491.  
  14492.    * If you make changes to the grant tables directly (using an
  14493.      `INSERT' or `UPDATE' statement) and your changes seem to be
  14494.      ignored, remember that you must issue a `FLUSH PRIVILEGES'
  14495.      statement or execute a `mysqladmin flush-privileges' command to
  14496.      cause the server to re-read the privilege tables. Otherwise, your
  14497.      changes have no effect until the next time the server is
  14498.      restarted.  Remember that after you set the `root' password with
  14499.      an `UPDATE' command, you won't need to specify it until after you
  14500.      flush the privileges, because the server won't know you've changed
  14501.      the password yet!
  14502.  
  14503.    * If you have access problems with a Perl, PHP, Python, or ODBC
  14504.      program, try to connect to the server with `mysql -u user_name
  14505.      db_name' or `mysql -u user_name -pyour_pass db_name'.  If you are
  14506.      able to connect using the `mysql' client, there is a problem with
  14507.      your program and not with the access privileges.  (Note that there
  14508.      is no space between `-p' and the password; you can also use the
  14509.      `--password=your_pass' syntax to specify the password. If you use
  14510.      the `-p' option alone, MySQL will prompt you for the password.)
  14511.  
  14512.    * For testing, start the `mysqld' daemon with the
  14513.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  14514.      tables and use the `mysqlaccess' script to check whether your
  14515.      modifications have the desired effect.  When you are satisfied
  14516.      with your changes, execute `mysqladmin flush-privileges' to tell
  14517.      the `mysqld' server to start using the new grant tables.  *Note*:
  14518.      reloading the grant tables overrides the `--skip-grant-tables'
  14519.      option.  This allows you to tell the server to begin using the
  14520.      grant tables again without bringing it down and restarting it.
  14521.  
  14522.    * If everything else fails, start the `mysqld' daemon with a
  14523.      debugging option (for example, `--debug=d,general,query'). This
  14524.      will print host and user information about attempted connections,
  14525.      as well as information about each command issued. *Note Making
  14526.      trace files::.
  14527.  
  14528.    * If you have any other problems with the MySQL grant tables and
  14529.      feel you must post the problem to the mailing list, always provide
  14530.      a dump of the MySQL grant tables. You can dump the tables with the
  14531.      `mysqldump mysql' command. As always, post your problem using the
  14532.      `mysqlbug' script.  *Note Bug reports::.  In some cases you may
  14533.      need to restart `mysqld' with `--skip-grant-tables' to run
  14534.      `mysqldump'.
  14535.  
  14536. MySQL User Account Management
  14537. =============================
  14538.  
  14539. `GRANT' and `REVOKE' Syntax
  14540. ---------------------------
  14541.  
  14542.      GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
  14543.          ON {tbl_name | * | *.* | db_name.*}
  14544.          TO user_name [IDENTIFIED BY [PASSWORD] 'password']
  14545.              [, user_name [IDENTIFIED BY 'password'] ...]
  14546.          [REQUIRE
  14547.              NONE |
  14548.              [{SSL| X509}]
  14549.          [CIPHER cipher [AND]]
  14550.          [ISSUER issuer [AND]]
  14551.          [SUBJECT subject]]
  14552.          [WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR # |
  14553.                                MAX_UPDATES_PER_HOUR # |
  14554.                                MAX_CONNECTIONS_PER_HOUR #]]
  14555.      
  14556.      REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
  14557.          ON {tbl_name | * | *.* | db_name.*}
  14558.          FROM user_name [, user_name ...]
  14559.  
  14560. `GRANT' is implemented in MySQL Version 3.22.11 or later. For earlier
  14561. MySQL versions, the `GRANT' statement does nothing.
  14562.  
  14563. The `GRANT' and `REVOKE' commands allow system administrators to create
  14564. users and grant and revoke rights to MySQL users at four privilege
  14565. levels:
  14566.  
  14567. *Global level*
  14568.      Global privileges apply to all databases on a given server. These
  14569.      privileges are stored in the `mysql.user' table.
  14570.  
  14571. *Database level*
  14572.      Database privileges apply to all tables in a given database. These
  14573.      privileges are stored in the `mysql.db' and `mysql.host' tables.
  14574.  
  14575. *Table level*
  14576.      Table privileges apply to all columns in a given table. These
  14577.      privileges are stored in the `mysql.tables_priv' table.
  14578.  
  14579. *Column level*
  14580.      Column privileges apply to single columns in a given table. These
  14581.      privileges are stored in the `mysql.columns_priv' table.
  14582.  
  14583. If you give a grant for a users that doesn't exists, that user is
  14584. created.  For examples of how `GRANT' works, see *Note Adding users::.
  14585.  
  14586. For the `GRANT' and `REVOKE' statements, `priv_type' may be specified
  14587. as any of the following:
  14588.  
  14589. `ALL [PRIVILEGES]'     Sets all simple privileges except `WITH GRANT
  14590.                        OPTION'
  14591. `ALTER'                Allows usage of `ALTER TABLE'
  14592. `CREATE'               Allows usage of `CREATE TABLE'
  14593. `CREATE TEMPORARY      Allows usage of `CREATE TEMPORARY TABLE'
  14594. TABLES'                
  14595. `DELETE'               Allows usage of `DELETE'
  14596. `DROP'                 Allows usage of `DROP TABLE'.
  14597. `EXECUTE'              Allows the user to run stored procedures (for
  14598.                        MySQL 5.0)
  14599. `FILE'                 Allows usage of `SELECT ... INTO OUTFILE' and
  14600.                        `LOAD DATA INFILE'.
  14601. `INDEX'                Allows usage of `CREATE INDEX' and `DROP INDEX'
  14602. `INSERT'               Allows usage of `INSERT'
  14603. `LOCK TABLES'          Allows usage of `LOCK TABLES' on tables for which
  14604.                        one has the `SELECT' privilege.
  14605. `PROCESS'              Allows usage of `SHOW FULL PROCESSLIST'
  14606. `REFERENCES'           For the future
  14607. `RELOAD'               Allows usage of `FLUSH'
  14608. `REPLICATION CLIENT'   Gives the right to the user to ask where the
  14609.                        slaves/masters are.
  14610. `REPLICATION SLAVE'    Needed for the replication slaves (to read
  14611.                        binlogs from master).
  14612. `SELECT'               Allows usage of `SELECT'
  14613. `SHOW DATABASES'       `SHOW DATABASES' shows all databases.
  14614. `SHUTDOWN'             Allows usage of `mysqladmin shutdown'
  14615. `SUPER'                Allows one connect (once) even if max_connections
  14616.                        is reached and execute commands `CHANGE MASTER',
  14617.                        `KILL thread', `mysqladmin debug', `PURGE MASTER
  14618.                        LOGS' and `SET GLOBAL'
  14619. `UPDATE'               Allows usage of `UPDATE'
  14620. `USAGE'                Synonym for "no privileges."
  14621. `GRANT OPTION'         Synonym for `WITH GRANT OPTION'
  14622.  
  14623. `USAGE' can be used when you want to create a user that has no
  14624. privileges.
  14625.  
  14626. The privileges `CREATE TEMPORARY TABLES', `EXECUTE', `LOCK TABLES',
  14627. `REPLICATION ...', `SHOW DATABASES' and `SUPER' are new for in version
  14628. 4.0.2.  To use these new privileges after upgrading to 4.0.2, you have
  14629. to run the `mysql_fix_privilege_tables' script.
  14630.  
  14631. In older MySQL versions, the `PROCESS' privilege gives the same rights
  14632. as the new `SUPER' privilege.
  14633.  
  14634. To revoke the `GRANT' privilege from a user, use a `priv_type' value of
  14635. `GRANT OPTION':
  14636.  
  14637.      mysql> REVOKE GRANT OPTION ON ... FROM ...;
  14638.  
  14639. The only `priv_type' values you can specify for a table are `SELECT',
  14640. `INSERT', `UPDATE', `DELETE', `CREATE', `DROP', `GRANT OPTION',
  14641. `INDEX', and `ALTER'.
  14642.  
  14643. The only `priv_type' values you can specify for a column (that is, when
  14644. you use a `column_list' clause) are `SELECT', `INSERT', and `UPDATE'.
  14645.  
  14646. You can set global privileges by using `ON *.*' syntax.  You can set
  14647. database privileges by using `ON db_name.*' syntax. If you specify `ON
  14648. *' and you have a current database, you will set the privileges for
  14649. that database.  (*Warning*: if you specify `ON *' and you *don't* have
  14650. a current database, you will affect the global privileges!)
  14651.  
  14652. *Please note*: the `_' and `%' wildcards are allowed when specifying
  14653. database names in `GRANT' commands. This means that if you wish to use
  14654. for instance a `_' character as part of a database name, you should
  14655. specify it as `\_' in the `GRANT' command, to prevent the user from
  14656. being able to access additional databases matching the wildcard
  14657. pattern, e.g., `GRANT ... ON `foo\_bar`.* TO ...'.
  14658.  
  14659. In order to accommodate granting rights to users from arbitrary hosts,
  14660. MySQL supports specifying the `user_name' value in the form
  14661. `user@host'.  If you want to specify a `user' string containing special
  14662. characters (such as `-'), or a `host' string containing special
  14663. characters or wildcard characters (such as `%'), you can quote the user
  14664. or host name (for example, `'test-user'@'test-hostname'').
  14665.  
  14666. You can specify wildcards in the hostname.  For example,
  14667. `user@'%.loc.gov'' applies to `user' for any host in the `loc.gov'
  14668. domain, and `user@'144.155.166.%'' applies to `user' for any host in
  14669. the `144.155.166' class C subnet.
  14670.  
  14671. The simple form `user' is a synonym for `user@"%"'.
  14672.  
  14673. MySQL doesn't support wildcards in user names.  Anonymous users are
  14674. defined by inserting entries with `User=''' into the `mysql.user' table
  14675. or creating an user with an empty name with the `GRANT' command.
  14676.  
  14677. *Note*: if you allow anonymous users to connect to the MySQL server,
  14678. you should also grant privileges to all local users as `user@localhost'
  14679. because otherwise the anonymous user entry for the local host in the
  14680. `mysql.user' table will be used when the user tries to log into the
  14681. MySQL server from the local machine!
  14682.  
  14683. You can verify if this applies to you by executing this query:
  14684.  
  14685.      mysql> SELECT Host,User FROM mysql.user WHERE User='';
  14686.  
  14687. For the moment, `GRANT' only supports host, table, database, and column
  14688. names up to 60 characters long. A user name can be up to 16 characters.
  14689.  
  14690. The privileges for a table or column are formed from the logical OR of
  14691. the privileges at each of the four privilege levels.  For example, if
  14692. the `mysql.user' table specifies that a user has a global `SELECT'
  14693. privilege, this can't be denied by an entry at the database, table, or
  14694. column level.
  14695.  
  14696. The privileges for a column can be calculated as follows:
  14697.  
  14698.      global privileges
  14699.      OR (database privileges AND host privileges)
  14700.      OR table privileges
  14701.      OR column privileges
  14702.  
  14703. In most cases, you grant rights to a user at only one of the privilege
  14704. levels, so life isn't normally as complicated as above. The details of
  14705. the privilege-checking procedure are presented in *Note Privilege
  14706. system::.
  14707.  
  14708. If you grant privileges for a user/hostname combination that does not
  14709. exist in the `mysql.user' table, an entry is added and remains there
  14710. until deleted with a `DELETE' command.  In other words, `GRANT' may
  14711. create `user' table entries, but `REVOKE' will not remove them; you
  14712. must do that explicitly using `DELETE'.
  14713.  
  14714. In MySQL Version 3.22.12 or later, if a new user is created or if you
  14715. have global grant privileges, the user's password will be set to the
  14716. password specified by the `IDENTIFIED BY' clause, if one is given.  If
  14717. the user already had a password, it is replaced by the new one.
  14718.  
  14719. If you don't want to send the password in clear text you can use the
  14720. `PASSWORD' option followed by a scrambled password from SQL function
  14721. `PASSWORD()' or the C API function `make_scrambled_password(char *to,
  14722. const char *password)'.
  14723.  
  14724. *Warning*: if you create a new user but do not specify an `IDENTIFIED
  14725. BY' clause, the user has no password.  This is insecure.
  14726.  
  14727. Passwords can also be set with the `SET PASSWORD' command.  *Note
  14728. `SET': SET OPTION.
  14729.  
  14730. If you grant privileges for a database, an entry in the `mysql.db'
  14731. table is created if needed. When all privileges for the database have
  14732. been removed with `REVOKE', this entry is deleted.
  14733.  
  14734. If a user doesn't have any privileges on a table, the table is not
  14735. displayed when the user requests a list of tables (for example, with a
  14736. `SHOW TABLES' statement).
  14737.  
  14738. The `WITH GRANT OPTION' clause gives the user the ability to give to
  14739. other users any privileges the user has at the specified privilege
  14740. level.  You should be careful to whom you give the `GRANT' privilege,
  14741. as two users with different privileges may be able to join privileges!
  14742.  
  14743. `MAX_QUERIES_PER_HOUR #', `MAX_UPDATES_PER_HOUR #' and
  14744. `MAX_CONNECTIONS_PER_HOUR #' are new in MySQL version 4.0.2.  These
  14745. options limit the number of queries/updates and logins the user can do
  14746. during one hour. If `#' is 0 (default), then this means that there are
  14747. no limitations for that user. *Note User resources::.  Note: to specify
  14748. any of these options for an existing user without adding other
  14749. additional privileges, use `GRANT USAGE ... WITH MAX_...'.
  14750.  
  14751. You cannot grant another user a privilege you don't have yourself; the
  14752. `GRANT' privilege allows you to give away only those privileges you
  14753. possess.
  14754.  
  14755. Be aware that when you grant a user the `GRANT' privilege at a
  14756. particular privilege level, any privileges the user already possesses
  14757. (or is given in the future!) at that level are also grantable by that
  14758. user.  Suppose you grant a user the `INSERT' privilege on a database.
  14759. If you then grant the `SELECT' privilege on the database and specify
  14760. `WITH GRANT OPTION', the user can give away not only the `SELECT'
  14761. privilege, but also `INSERT'.  If you then grant the `UPDATE' privilege
  14762. to the user on the database, the user can give away the `INSERT',
  14763. `SELECT' and `UPDATE'.
  14764.  
  14765. You should not grant `ALTER' privileges to a normal user.  If you do
  14766. that, the user can try to subvert the privilege system by renaming
  14767. tables!
  14768.  
  14769. Note that if you are using table or column privileges for even one
  14770. user, the server examines table and column privileges for all users and
  14771. this will slow down MySQL a bit.
  14772.  
  14773. When `mysqld' starts, all privileges are read into memory.  Database,
  14774. table, and column privileges take effect at once, and user-level
  14775. privileges take effect the next time the user connects.  Modifications
  14776. to the grant tables that you perform using `GRANT' or `REVOKE' are
  14777. noticed by the server immediately.  If you modify the grant tables
  14778. manually (using `INSERT', `UPDATE', etc.), you should execute a `FLUSH
  14779. PRIVILEGES' statement or run `mysqladmin flush-privileges' to tell the
  14780. server to reload the grant tables.  *Note Privilege changes::.
  14781.  
  14782. The biggest differences between the ANSI SQL and MySQL versions of
  14783. `GRANT' are:
  14784.  
  14785.    * In MySQL privileges are given for an username + hostname
  14786.      combination and not only for an username.
  14787.  
  14788.    * ANSI SQL doesn't have global or database-level privileges, and
  14789.      ANSI SQL doesn't support all privilege types that MySQL supports.
  14790.      MySQL doesn't support the ANSI SQL `TRIGGER' or `UNDER' privileges.
  14791.  
  14792.    * ANSI SQL privileges are structured in a hierarchal manner. If you
  14793.      remove an user, all privileges the user has granted are revoked. In
  14794.      MySQL the granted privileges are not automatically revoked, but
  14795.      you have to revoke these yourself if needed.
  14796.  
  14797.    * In MySQL, if you have the `INSERT' privilege on only some of the
  14798.      columns in a table, you can execute `INSERT' statements on the
  14799.      table; the columns for which you don't have the `INSERT' privilege
  14800.      will be set to their default values. ANSI SQL requires you to have
  14801.      the `INSERT' privilege on all columns.
  14802.  
  14803.    * When you drop a table in ANSI SQL, all privileges for the table
  14804.      are revoked.  If you revoke a privilege in ANSI SQL, all
  14805.      privileges that were granted based on this privilege are also
  14806.      revoked. In MySQL, privileges can be dropped only with explicit
  14807.      `REVOKE' commands or by manipulating the MySQL grant tables.
  14808.  
  14809. For a description of using `REQUIRE', see *Note Secure connections::.
  14810.  
  14811. MySQL User Names and Passwords
  14812. ------------------------------
  14813.  
  14814. There are several distinctions between the way user names and passwords
  14815. are used by MySQL and the way they are used by Unix or Windows:
  14816.  
  14817.    * User names, as used by MySQL for authentication purposes, have
  14818.      nothing to do with Unix user names (login names) or Windows user
  14819.      names.  Most MySQL clients by default try to log in using the
  14820.      current Unix user name as the MySQL user name, but that is for
  14821.      convenience only.  Client programs allow a different name to be
  14822.      specified with the `-u' or `--user' options. This means that you
  14823.      can't make a database secure in any way unless all MySQL user
  14824.      names have passwords.  Anyone may attempt to connect to the server
  14825.      using any name, and they will succeed if they specify any name
  14826.      that doesn't have a password.
  14827.  
  14828.    * MySQL user names can be up to 16 characters long; Unix user names
  14829.      typically are limited to 8 characters.
  14830.  
  14831.    * MySQL passwords have nothing to do with Unix passwords.  There is
  14832.      no necessary connection between the password you use to log in to
  14833.      a Unix machine and the password you use to access a database on
  14834.      that machine.
  14835.  
  14836.    * MySQL encrypts passwords using a different algorithm than the one
  14837.      used during the Unix login process.  See the descriptions of the
  14838.      `PASSWORD()' and `ENCRYPT()' functions in *Note Miscellaneous
  14839.      functions::.  Note that even if the password is stored
  14840.      'scrambled', and knowing your 'scrambled' password is enough to be
  14841.      able to connect to the MySQL server!
  14842.  
  14843. MySQL users and their privileges are normally created with the `GRANT'
  14844. command. *Note GRANT::.
  14845.  
  14846. When you login to a MySQL server with a command-line client you should
  14847. specify the password with `--password=your-password'.  *Note
  14848. Connecting::.
  14849.  
  14850.      mysql --user=monty --password=guess database_name
  14851.  
  14852. If you want the client to prompt for a password, you should use
  14853. `--password' without any argument
  14854.  
  14855.      mysql --user=monty --password database_name
  14856.  
  14857. or the short form:
  14858.  
  14859.      mysql -u monty -p database_name
  14860.  
  14861. Note that in the last example the password is *not* 'database_name'.
  14862.  
  14863. If you want to use the `-p' option to supply a password you should do so
  14864. like this:
  14865.  
  14866.      mysql -u monty -pguess database_name
  14867.  
  14868. On some systems, the library call that MySQL uses to prompt for a
  14869. password will automatically cut the password to 8 characters. Internally
  14870. MySQL doesn't have any limit for the length of the password.
  14871.  
  14872. When Privilege Changes Take Effect
  14873. ----------------------------------
  14874.  
  14875. When `mysqld' starts, all grant table contents are read into memory and
  14876. become effective at that point.
  14877.  
  14878. Modifications to the grant tables that you perform using `GRANT',
  14879. `REVOKE', or `SET PASSWORD' are noticed by the server immediately.
  14880.  
  14881. If you modify the grant tables manually (using `INSERT', `UPDATE',
  14882. etc.), you should execute a `FLUSH PRIVILEGES' statement or run
  14883. `mysqladmin flush-privileges' or `mysqladmin reload' to tell the server
  14884. to reload the grant tables. Otherwise, your changes will have _no
  14885. effect_ until you restart the server. If you change the grant tables
  14886. manually but forget to reload the privileges, you will be wondering why
  14887. your changes don't seem to make any difference!
  14888.  
  14889. When the server notices that the grant tables have been changed,
  14890. existing client connections are affected as follows:
  14891.  
  14892.    * Table and column privilege changes take effect with the client's
  14893.      next request.
  14894.  
  14895.    * Database privilege changes take effect at the next `USE db_name'
  14896.      command.
  14897.  
  14898.    * Global privilege changes and password changes take effect the next
  14899.      time the client connects.
  14900.  
  14901. Setting Up the Initial MySQL Privileges
  14902. ---------------------------------------
  14903.  
  14904. After installing MySQL, you set up the initial access privileges by
  14905. running `scripts/mysql_install_db'.  *Note Quick install::.  The
  14906. `mysql_install_db' script starts up the `mysqld' server, then
  14907. initialises the grant tables to contain the following set of privileges:
  14908.  
  14909.    * The MySQL `root' user is created as a superuser who can do
  14910.      anything.  Connections must be made from the local host.
  14911.  
  14912.      *Note*: The initial `root' password is empty, so anyone can
  14913.      connect as `root' _without a password_ and be granted all
  14914.      privileges.
  14915.  
  14916.    * An anonymous user is created that can do anything with databases
  14917.      that have a name of `'test'' or starting with `'test_''.
  14918.      Connections must be made from the local host.  This means any
  14919.      local user can connect without a password and be treated as the
  14920.      anonymous user.
  14921.  
  14922.    * Other privileges are denied.  For example, normal users can't use
  14923.      `mysqladmin shutdown' or `mysqladmin processlist'.
  14924.  
  14925. *Note*: the default privileges are different for Windows.  *Note
  14926. Windows running::.
  14927.  
  14928. Because your installation is initially wide open, one of the first
  14929. things you should do is specify a password for the MySQL `root' user.
  14930. You can do this as follows (note that you specify the password using
  14931. the `PASSWORD()' function):
  14932.  
  14933.      shell> mysql -u root mysql
  14934.      mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
  14935.  
  14936. If you know what you are doing, you can also directly manipulate the
  14937. privilege tables:
  14938.  
  14939.      shell> mysql -u root mysql
  14940.      mysql> UPDATE user SET Password=PASSWORD('new_password')
  14941.          ->     WHERE user='root';
  14942.      mysql> FLUSH PRIVILEGES;
  14943.  
  14944. Another way to set the password is by using the `mysqladmin' command:
  14945.  
  14946.      shell> mysqladmin -u root password new_password
  14947.  
  14948. Only users with write/update access to the `mysql' database can change
  14949. the password for others users.  All normal users (not anonymous ones)
  14950. can only change their own password with either of the above commands or
  14951. with `SET PASSWORD=PASSWORD('new password')'.
  14952.  
  14953. Note that if you update the password in the `user' table directly using
  14954. the first method, you must tell the server to re-read the grant tables
  14955. (with `FLUSH PRIVILEGES'), because the change will go unnoticed
  14956. otherwise.
  14957.  
  14958. Once the `root' password has been set, thereafter you must supply that
  14959. password when you connect to the server as `root'.
  14960.  
  14961. You may wish to leave the `root' password blank so that you don't need
  14962. to specify it while you perform additional setup or testing. However,
  14963. be sure to set it before using your installation for any real
  14964. production work.
  14965.  
  14966. See the `scripts/mysql_install_db' script to see how it sets up the
  14967. default privileges.  You can use this as a basis to see how to add
  14968. other users.
  14969.  
  14970. If you want the initial privileges to be different from those just
  14971. described above, you can modify `mysql_install_db' before you run it.
  14972.  
  14973. To re-create the grant tables completely, remove all the `.frm',
  14974. `.MYI', and `.MYD' files in the directory containing the `mysql'
  14975. database.  (This is the directory named `mysql' under the database
  14976. directory, which is listed when you run `mysqld --help'.) Then run the
  14977. `mysql_install_db' script, possibly after editing it first to have the
  14978. privileges you want.
  14979.  
  14980. *Note*: for MySQL versions older than Version 3.22.10, you should not
  14981. delete the `.frm' files.  If you accidentally do this, you should copy
  14982. them back from your MySQL distribution before running
  14983. `mysql_install_db'.
  14984.  
  14985. Adding New Users to MySQL
  14986. -------------------------
  14987.  
  14988. You can add users two different ways: by using `GRANT' statements or by
  14989. manipulating the MySQL grant tables directly.  The preferred method is
  14990. to use `GRANT' statements, because they are more concise and less
  14991. error-prone. *Note GRANT::.
  14992.  
  14993. There are also a lot of contributed programs like `phpmyadmin' that can
  14994. be used to create and administrate users.
  14995.  
  14996. The following examples show how to use the `mysql' client to set up new
  14997. users.  These examples assume that privileges are set up according to
  14998. the defaults described in the previous section.  This means that to
  14999. make changes, you must be on the same machine where `mysqld' is
  15000. running, you must connect as the MySQL `root' user, and the `root' user
  15001. must have the `INSERT' privilege for the `mysql' database and the
  15002. `RELOAD' administrative privilege.  Also, if you have changed the
  15003. `root' user password, you must specify it for the `mysql' commands here.
  15004.  
  15005. You can add new users by issuing `GRANT' statements:
  15006.  
  15007.      shell> mysql --user=root mysql
  15008.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
  15009.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  15010.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%"
  15011.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  15012.      mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
  15013.      mysql> GRANT USAGE ON *.* TO dummy@localhost;
  15014.  
  15015. These `GRANT' statements set up three new users:
  15016.  
  15017. `monty'
  15018.      A full superuser who can connect to the server from anywhere, but
  15019.      who must use a password `'some_pass'' to do so.  Note that we must
  15020.      issue `GRANT' statements for both `monty@localhost' and
  15021.      `monty@"%"'.  If we don't add the entry with `localhost', the
  15022.      anonymous user entry for `localhost' that is created by
  15023.      `mysql_install_db' will take precedence when we connect from the
  15024.      local host, because it has a more specific `Host' field value and
  15025.      thus comes earlier in the `user' table sort order.
  15026.  
  15027. `admin'
  15028.      A user who can connect from `localhost' without a password and who
  15029.      is granted the `RELOAD' and `PROCESS' administrative privileges.
  15030.      This allows the user to execute the `mysqladmin reload',
  15031.      `mysqladmin refresh', and `mysqladmin flush-*' commands, as well as
  15032.      `mysqladmin processlist' .  No database-related privileges are
  15033.      granted.  (They can be granted later by issuing additional `GRANT'
  15034.      statements.)
  15035.  
  15036. `dummy'
  15037.      A user who can connect without a password, but only from the local
  15038.      host.  The global privileges are all set to `'N''the `USAGE'
  15039.      privilege type allows you to create a user with no privileges.  It
  15040.      is assumed that you will grant database-specific privileges later.
  15041.  
  15042. You can also add the same user access information directly by issuing
  15043. `INSERT' statements and then telling the server to reload the grant
  15044. tables:
  15045.  
  15046.      shell> mysql --user=root mysql
  15047.      mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
  15048.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  15049.      mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
  15050.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  15051.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  15052.          ->           Reload_priv='Y', Process_priv='Y';
  15053.      mysql> INSERT INTO user (Host,User,Password)
  15054.          ->                  VALUES('localhost','dummy','');
  15055.      mysql> FLUSH PRIVILEGES;
  15056.  
  15057. Depending on your MySQL version, you may have to use a different number
  15058. of `'Y'' values above (versions prior to Version 3.22.11 had fewer
  15059. privilege columns).  For the `admin' user, the more readable extended
  15060. `INSERT' syntax that is available starting with Version 3.22.11 is used.
  15061.  
  15062. Note that to set up a superuser, you need only create a `user' table
  15063. entry with the privilege fields set to `'Y''.  No `db' or `host' table
  15064. entries are necessary.
  15065.  
  15066. The privilege columns in the `user' table were not set explicitly in the
  15067. last `INSERT' statement (for the `dummy' user), so those columns are
  15068. assigned the default value of `'N''.  This is the same thing that
  15069. `GRANT USAGE' does.
  15070.  
  15071. The following example adds a user `custom' who can connect from hosts
  15072. `localhost', `server.domain', and `whitehouse.gov'.  He wants to access
  15073. the `bankaccount' database only from `localhost', the `expenses'
  15074. database only from `whitehouse.gov', and the `customer' database from
  15075. all three hosts.  He wants to use the password `stupid' from all three
  15076. hosts.
  15077.  
  15078. To set up this user's privileges using `GRANT' statements, run these
  15079. commands:
  15080.  
  15081.      shell> mysql --user=root mysql
  15082.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  15083.          ->     ON bankaccount.*
  15084.          ->     TO custom@localhost
  15085.          ->     IDENTIFIED BY 'stupid';
  15086.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  15087.          ->     ON expenses.*
  15088.          ->     TO custom@whitehouse.gov
  15089.          ->     IDENTIFIED BY 'stupid';
  15090.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  15091.          ->     ON customer.*
  15092.          ->     TO custom@'%'
  15093.          ->     IDENTIFIED BY 'stupid';
  15094.  
  15095. The reason that we do to grant statements for the user 'custom' is that
  15096. we want the give the user access to MySQL both from the local machine
  15097. with Unix sockets and from the remote machine 'whitehouse.gov' over
  15098. TCP/IP.
  15099.  
  15100. To set up the user's privileges by modifying the grant tables directly,
  15101. run these commands (note the `FLUSH PRIVILEGES' at the end):
  15102.  
  15103.      shell> mysql --user=root mysql
  15104.      mysql> INSERT INTO user (Host,User,Password)
  15105.          -> VALUES('localhost','custom',PASSWORD('stupid'));
  15106.      mysql> INSERT INTO user (Host,User,Password)
  15107.          -> VALUES('server.domain','custom',PASSWORD('stupid'));
  15108.      mysql> INSERT INTO user (Host,User,Password)
  15109.          -> VALUES('whitehouse.gov','custom',PASSWORD('stupid'));
  15110.      mysql> INSERT INTO db
  15111.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  15112.          ->  Create_priv,Drop_priv)
  15113.          -> VALUES
  15114.          -> ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
  15115.      mysql> INSERT INTO db
  15116.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  15117.          ->  Create_priv,Drop_priv)
  15118.          -> VALUES
  15119.          -> ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
  15120.      mysql> INSERT INTO db
  15121.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  15122.          ->  Create_priv,Drop_priv)
  15123.          -> VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y');
  15124.      mysql> FLUSH PRIVILEGES;
  15125.  
  15126. The first three `INSERT' statements add `user' table entries that allow
  15127. user `custom' to connect from the various hosts with the given
  15128. password, but grant no permissions to him (all privileges are set to the
  15129. default value of `'N'').  The next three `INSERT' statements add `db'
  15130. table entries that grant privileges to `custom' for the `bankaccount',
  15131. `expenses', and `customer' databases, but only when accessed from the
  15132. proper hosts.  As usual, when the grant tables are modified directly,
  15133. the server must be told to reload them (with `FLUSH PRIVILEGES') so
  15134. that the privilege changes take effect.
  15135.  
  15136. If you want to give a specific user access from any machine in a given
  15137. domain, you can issue a `GRANT' statement like the following:
  15138.  
  15139.      mysql> GRANT ...
  15140.          ->     ON *.*
  15141.          ->     TO myusername@"%.mydomainname.com"
  15142.          ->     IDENTIFIED BY 'mypassword';
  15143.  
  15144. To do the same thing by modifying the grant tables directly, do this:
  15145.  
  15146.      mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername',
  15147.          ->             PASSWORD('mypassword'),...);
  15148.      mysql> FLUSH PRIVILEGES;
  15149.  
  15150. Limiting user resources
  15151. -----------------------
  15152.  
  15153. Starting from MySQL 4.0.2 one can limit certain resources per user.
  15154.  
  15155. So far, the only available method of limiting usage of MySQL server
  15156. resources has been setting the `max_user_connections' startup variable
  15157. to a non-zero value. But this method is strictly global and does not
  15158. allow for management of individual users, which could be of particular
  15159. interest to Internet Service Providers.
  15160.  
  15161. Therefore, management of three resources is introduced on the
  15162. individual user level:
  15163.  
  15164.    * Number of all queries per hour: All commands that could be run by
  15165.      a user.
  15166.  
  15167.    * Number of all updates per hour: Any command that changes any table
  15168.      or database.
  15169.  
  15170.    * Number of connections made per hour: New connections opened per
  15171.      hour.
  15172.  
  15173. A user in the aforementioned context is a single entry in the `user'
  15174. table, which is uniquely identified by its `user' and `host' columns.
  15175.  
  15176. All users are by default not limited in using the above resources,
  15177. unless the limits are granted to them. These limits can be granted
  15178. *only* via global `GRANT (*.*)', using this syntax:
  15179.  
  15180.      GRANT ... WITH MAX_QUERIES_PER_HOUR N1
  15181.                     MAX_UPDATES_PER_HOUR N2
  15182.                     MAX_CONNECTIONS_PER_HOUR N3;
  15183.  
  15184. One can specify any combination of the above resources.  N1, N2 and N3
  15185. are integers and stands for count / hour.
  15186.  
  15187. If user reaches any of the above limits withing one hour, his
  15188. connection will be terminated or refused and the appropriate error
  15189. message shall be issued.
  15190.  
  15191. Current usage values for a particular user can be flushed (set to zero)
  15192. by issuing a `GRANT' statement with any of the above clauses, including
  15193. a `GRANT' statement with the current values.
  15194.  
  15195. Also, current values for all users will be flushed if privileges are
  15196. reloaded (in the server or using `mysqladmin reload') or if the `FLUSH
  15197. USER_RESOURCES' command is issued.
  15198.  
  15199. The feature is enabled as soon as a single user is granted with any of
  15200. the limiting `GRANT' clauses.
  15201.  
  15202. As a prerequisite for enabling this feature, the `user' table in the
  15203. `mysql' database must contain the additional columns, as defined in the
  15204. table creation scripts `mysql_install_db' and `mysql_install_db.sh' in
  15205. `scripts' subdirectory.
  15206.  
  15207. Setting Up Passwords
  15208. --------------------
  15209.  
  15210. In most cases you should use `GRANT' to set up your users/passwords, so
  15211. the following only applies for advanced users. *Note `GRANT': GRANT.
  15212.  
  15213. The examples in the preceding sections illustrate an important
  15214. principle: when you store a non-empty password using `INSERT' or
  15215. `UPDATE' statements, you must use the `PASSWORD()' function to encrypt
  15216. it.  This is because the `user' table stores passwords in encrypted
  15217. form, not as plaintext.  If you forget that fact, you are likely to
  15218. attempt to set passwords like this:
  15219.  
  15220.      shell> mysql -u root mysql
  15221.      mysql> INSERT INTO user (Host,User,Password)
  15222.          -> VALUES('%','jeffrey','biscuit');
  15223.      mysql> FLUSH PRIVILEGES;
  15224.  
  15225. The result is that the plaintext value `'biscuit'' is stored as the
  15226. password in the `user' table.  When the user `jeffrey' attempts to
  15227. connect to the server using this password, the `mysql' client encrypts
  15228. it with `PASSWORD()', generates an authentification vector based on
  15229. *encrypted* password and a random number, obtained from server, and
  15230. sends the result to the server.  The server uses the `password' value
  15231. in the `user' table (that is *not encrypted* value `'biscuit'') to
  15232. perform the same calculations, and compares results.  The comparison
  15233. fails and the server rejects the connection:
  15234.  
  15235.      shell> mysql -u jeffrey -pbiscuit test
  15236.      Access denied
  15237.  
  15238. Passwords must be encrypted when they are inserted in the `user' table,
  15239. so the `INSERT' statement should have been specified like this instead:
  15240.  
  15241.      mysql> INSERT INTO user (Host,User,Password)
  15242.          -> VALUES('%','jeffrey',PASSWORD('biscuit'));
  15243.  
  15244. You must also use the `PASSWORD()' function when you use `SET PASSWORD'
  15245. statements:
  15246.  
  15247.      mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
  15248.  
  15249. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  15250. the `mysqladmin password' command, the `PASSWORD()' function is
  15251. unnecessary.  They both take care of encrypting the password for you,
  15252. so you would specify a password of `'biscuit'' like this:
  15253.  
  15254.      mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
  15255.  
  15256. or
  15257.  
  15258.      shell> mysqladmin -u jeffrey password biscuit
  15259.  
  15260. *Note*: `PASSWORD()' does not perform password encryption in the same
  15261. way that Unix passwords are encrypted.  You should not assume that if
  15262. your Unix password and your MySQL password are the same, that
  15263. `PASSWORD()' will result in the same encrypted value as is stored in the
  15264. Unix password file. *Note User names::.
  15265.  
  15266. Keeping Your Password Secure
  15267. ----------------------------
  15268.  
  15269. It is inadvisable to specify your password in a way that exposes it to
  15270. discovery by other users.  The methods you can use to specify your
  15271. password when you run client programs are listed here, along with an
  15272. assessment of the risks of each method:
  15273.  
  15274.    * Never give a normal user access to the `mysql.user' table. Knowing
  15275.      the encrypted password for a user makes it possible to login as
  15276.      this user.  The passwords are only scrambled so that one shouldn't
  15277.      be able to see the real password you used (if you happen to use a
  15278.      similar password with your other applications).
  15279.  
  15280.    * Use a `-pyour_pass' or `--password=your_pass' option on the command
  15281.      line.  This is convenient but insecure, because your password
  15282.      becomes visible to system status programs (such as `ps') that may
  15283.      be invoked by other users to display command-lines.  (MySQL
  15284.      clients typically overwrite the command-line argument with zeroes
  15285.      during their initialisation sequence, but there is still a brief
  15286.      interval during which the value is visible.)
  15287.  
  15288.    * Use a `-p' or `--password' option (with no `your_pass' value
  15289.      specified).  In this case, the client program solicits the
  15290.      password from the terminal:
  15291.  
  15292.           shell> mysql -u user_name -p
  15293.           Enter password: ********
  15294.  
  15295.      The `*' characters represent your password.
  15296.  
  15297.      It is more secure to enter your password this way than to specify
  15298.      it on the command-line because it is not visible to other users.
  15299.      However, this method of entering a password is suitable only for
  15300.      programs that you run interactively.  If you want to invoke a
  15301.      client from a script that runs non-interactively, there is no
  15302.      opportunity to enter the password from the terminal. On some
  15303.      systems, you may even find that the first line of your script is
  15304.      read and interpreted (incorrectly) as your password!
  15305.  
  15306.    * Store your password in a configuration file.  For example, you can
  15307.      list your password in the `[client]' section of the `.my.cnf' file
  15308.      in your home directory:
  15309.  
  15310.           [client]
  15311.           password=your_pass
  15312.  
  15313.      If you store your password in `.my.cnf', the file should not be
  15314.      group or world readable or writable.  Make sure the file's access
  15315.      mode is `400' or `600'.
  15316.  
  15317.      *Note Option files::.
  15318.  
  15319.    * You can store your password in the `MYSQL_PWD' environment
  15320.      variable, but this method must be considered extremely insecure
  15321.      and should not be used.  Some versions of `ps' include an option
  15322.      to display the environment of running processes; your password
  15323.      will be in plain sight for all to see if you set `MYSQL_PWD'.
  15324.      Even on systems without such a version of `ps', it is unwise to
  15325.      assume there is no other method to observe process environments.
  15326.      *Note Environment variables::.
  15327.  
  15328. All in all, the safest methods are to have the client program prompt
  15329. for the password or to specify the password in a properly protected
  15330. `.my.cnf' file.
  15331.  
  15332. Using Secure Connections
  15333. ------------------------
  15334.  
  15335. Basics
  15336. ......
  15337.  
  15338. Beginning with version 4.0.0, MySQL has support for SSL encrypted
  15339. connections. To understand how MySQL uses SSL, it's necessary to
  15340. explain some basic SSL and X509 concepts. People who are already
  15341. familiar with them can skip this part.
  15342.  
  15343. By default, MySQL uses unencrypted connections between the client and
  15344. the server. This means that someone could watch all your traffic and
  15345. look at the data being sent or received.  They could even change the
  15346. data while it is in transit between client and server. Sometimes you
  15347. need to move information over public networks in a secure fashion; in
  15348. such cases, using an unencrypted connection is unacceptable.
  15349.  
  15350. SSL is a protocol that uses different encryption algorithms to ensure
  15351. that data received over a public network can be trusted. It has
  15352. mechanisms to detect any change, loss or replay of data. SSL also
  15353. incorporates algorithms to recognise and provide identity verification
  15354. using the X509 standard.
  15355.  
  15356. Encryption is the way to make any kind of data unreadable. In fact,
  15357. today's practice requires many additional security elements from
  15358. encryption algorithms.  They should resist many kind of known attacks
  15359. like just messing with the order of encrypted messages or replaying data
  15360. twice.
  15361.  
  15362. X509 is a standard that makes it possible to identify someone on the
  15363. Internet.  It is most commonly used in e-commerce applications. In basic
  15364. terms, there should be some company (called a "Certificate Authority")
  15365. that assigns electronic certificates to anyone who needs them.
  15366. Certificates rely on asymmetric encryption algorithms that have two
  15367. encryption keys (a public key and a secret key). A certificate owner
  15368. can prove his identity by showing his certificate to other party. A
  15369. certificate consists of its owner's public key. Any data encrypted with
  15370. this public key can be decrypted only using the corresponding secret
  15371. key, which is held by the owner of the certificate.
  15372.  
  15373. MySQL doesn't use encrypted connections by default, because doing so
  15374. would make the client/server protocol much slower. Any kind of
  15375. additional functionality requires the computer to do additional work and
  15376. encrypting data is a CPU-intensive operation that requires time and can
  15377. delay MySQL main tasks. By default MySQL is tuned to be fast as
  15378. possible.
  15379.  
  15380. If you need more information about SSL, X509, or encryption, you should
  15381. use your favourite Internet search engine and search for keywords in
  15382. which you are interested.
  15383.  
  15384. Requirements
  15385. ............
  15386.  
  15387. To get secure connections to work with MySQL you must do the following:
  15388.  
  15389.   1. Install the OpenSSL library. We have tested MySQL with OpenSSL
  15390.      0.9.6.  `http://www.openssl.org/'.
  15391.  
  15392.   2. Configure MySQL with `--with-vio --with-openssl'.
  15393.  
  15394.   3. If you are using an old MySQL installation, you have to update your
  15395.      `mysql.user' table with some new SSL-related columns. You can do
  15396.      this by running the `mysql_fix_privilege_tables.sh' script.  This
  15397.      is necessary if your grant tables date from a version prior to
  15398.      MySQL 4.0.0.
  15399.  
  15400.   4. You can check if a running `mysqld' server supports OpenSSL by
  15401.      examining if `SHOW VARIABLES LIKE 'have_openssl'' returns `YES'.
  15402.  
  15403. `GRANT' Options
  15404. ...............
  15405.  
  15406. MySQL can check X509 certificate attributes in addition to the normal
  15407. username/password scheme. All the usual options are still required
  15408. (username, password, IP address mask, database/table name).
  15409.  
  15410. There are different possibilities to limit connections:
  15411.  
  15412.    * Without any SSL or X509 options, all kind of encrypted/unencrypted
  15413.      connections are allowed if the username and password are valid.
  15414.  
  15415.    * `REQUIRE SSL' option limits the server to allow only SSL encrypted
  15416.      connections. Note that this option can be omitted if there are any
  15417.      ACL records which allow non-SSL connections.
  15418.  
  15419.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  15420.               -> IDENTIFIED BY "goodsecret" REQUIRE SSL;
  15421.  
  15422.    * `REQUIRE X509' means that the client should have a valid
  15423.      certificate but we do not care about the exact certificate, issuer
  15424.      or subject.  The only restriction is that it should be possible to
  15425.      verify its signature with one of the CA certificates.
  15426.  
  15427.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  15428.               -> IDENTIFIED BY "goodsecret" REQUIRE X509;
  15429.  
  15430.    * `REQUIRE ISSUER "issuer"' places a restriction on connection
  15431.      attempts: The client must present a valid X509 certificate issued
  15432.      by CA `"issuer"'.  Using X509 certificates always implies
  15433.      encryption, so the `SSL' option is unneccessary.
  15434.  
  15435.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  15436.               -> IDENTIFIED BY "goodsecret"
  15437.               -> REQUIRE ISSUER "C=FI, ST=Some-State, L=Helsinki,
  15438.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com";
  15439.  
  15440.    * `REQUIRE SUBJECT "subject"' requires clients to have valid X509
  15441.      certificate with subject `"subject"' on it. If the client presents
  15442.      a certificate that is valid but has a different `"subject"', the
  15443.      connection is disallowed.
  15444.  
  15445.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  15446.               -> IDENTIFIED BY "goodsecret"
  15447.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  15448.               "> O=MySQL demo client certificate,
  15449.               "> CN=Tonu Samuel/Email=tonu@mysql.com";
  15450.  
  15451.    * `REQUIRE CIPHER "cipher"' is needed to assure enough strong ciphers
  15452.      and keylengths will be used. SSL itself can be weak if old
  15453.      algorithms with short encryption keys are used. Using this option,
  15454.      we can ask for some exact cipher method to allow a connection.
  15455.  
  15456.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  15457.               -> IDENTIFIED BY "goodsecret"
  15458.               -> REQUIRE CIPHER "EDH-RSA-DES-CBC3-SHA";
  15459.  
  15460.      The `SUBJECT', `ISSUER', and `CIPHER' options can be combined in
  15461.      the `REQUIRE' clause like this:
  15462.  
  15463.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  15464.               -> IDENTIFIED BY "goodsecret"
  15465.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  15466.               "> O=MySQL demo client certificate,
  15467.               "> CN=Tonu Samuel/Email=tonu@mysql.com"
  15468.               -> AND ISSUER "C=FI, ST=Some-State, L=Helsinki,
  15469.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com"
  15470.               -> AND CIPHER "EDH-RSA-DES-CBC3-SHA";
  15471.  
  15472.      Starting from MySQL 4.0.4 the `AND' keyword is optional between
  15473.      `REQUIRE' options.
  15474.  
  15475.      The order of the options does not matter, but no option can be
  15476.      specified twice.
  15477.  
  15478. Disaster Prevention and Recovery
  15479. ================================
  15480.  
  15481. Database Backups
  15482. ----------------
  15483.  
  15484. Because MySQL tables are stored as files, it is easy to do a backup. To
  15485. get a consistent backup, do a `LOCK TABLES' on the relevant tables
  15486. followed by `FLUSH TABLES' for the tables.  *Note `LOCK TABLES': LOCK
  15487. TABLES.  *Note `FLUSH': FLUSH.  You only need a read lock; this allows
  15488. other threads to continue to query the tables while you are making a
  15489. copy of the files in the database directory.  The `FLUSH TABLE' is
  15490. needed to ensure that the all active index pages is written to disk
  15491. before you start the backup.
  15492.  
  15493. If you want to make a SQL level backup of a table, you can use `SELECT
  15494. INTO OUTFILE' or `BACKUP TABLE'. *Note SELECT::.  *Note BACKUP TABLE::.
  15495.  
  15496. Another way to back up a database is to use the `mysqldump' program or
  15497. the `mysqlhotcopy script'. *Note `mysqldump': mysqldump.  *Note
  15498. `mysqlhotcopy': mysqlhotcopy.
  15499.  
  15500.   1. Do a full backup of your databases:
  15501.  
  15502.           shell> mysqldump --tab=/path/to/some/dir --opt --all
  15503.           
  15504.           or
  15505.           
  15506.           shell> mysqlhotcopy database /path/to/some/dir
  15507.  
  15508.      You can also simply copy all table files (`*.frm', `*.MYD', and
  15509.      `*.MYI' files) as long as the server isn't updating anything.  The
  15510.      script `mysqlhotcopy' does use this method.
  15511.  
  15512.   2. Stop `mysqld' if it's running, then start it with the
  15513.      `--log-update[=file_name]' option.  *Note Update log::. The update
  15514.      log file(s) provide you with the information you need to replicate
  15515.      changes to the database that are made subsequent to the point at
  15516.      which you executed `mysqldump'.
  15517.  
  15518. If you have to restore something, try to recover your tables using
  15519. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  15520. all cases.  If `myisamchk' fails, try the following procedure (this
  15521. will only work if you have started MySQL with `--log-update', *note
  15522. Update log::):
  15523.  
  15524.   1. Restore the original `mysqldump' backup.
  15525.  
  15526.   2. Execute the following command to re-run the updates in the binary
  15527.      log:
  15528.  
  15529.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  15530.  
  15531.      If you are using the update log you can use:
  15532.  
  15533.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  15534.  
  15535. `ls' is used to get all the update log files in the right order.
  15536.  
  15537. You can also do selective backups with `SELECT * INTO OUTFILE
  15538. 'file_name' FROM tbl_name' and restore with `LOAD DATA INFILE
  15539. 'file_name' REPLACE ...' To avoid duplicate records, you need a
  15540. `PRIMARY KEY' or a `UNIQUE' key in the table. The `REPLACE' keyword
  15541. causes old records to be replaced with new ones when a new record
  15542. duplicates an old record on a unique key value.
  15543.  
  15544. If you get performance problems in making backups on your system, you
  15545. can solve this by setting up replication and do the backups on the slave
  15546. instead of on the master. *Note Replication Intro::.
  15547.  
  15548. If you are using a Veritas filesystem, you can do:
  15549.  
  15550.   1. From a client (or Perl), execute: `FLUSH TABLES WITH READ LOCK'.
  15551.  
  15552.   2. From another shell, execute: `mount vxfs snapshot'.
  15553.  
  15554.   3. From the first client, execute: `UNLOCK TABLES'.
  15555.  
  15556.   4. Copy files from snapshot.
  15557.  
  15558.   5. Unmount snapshot.
  15559.  
  15560. `BACKUP TABLE' Syntax
  15561. ---------------------
  15562.  
  15563.      BACKUP TABLE tbl_name[,tbl_name...] TO '/path/to/backup/directory'
  15564.  
  15565. Copies to the backup directory the minimum number of table files needed
  15566. to restore the table, after flushing any buffered changes to disk.
  15567. Currently works only for `MyISAM' tables.  For `MyISAM' tables, copies
  15568. `.frm' (definition)  and `.MYD' (data) files. The index file can be
  15569. rebuilt from those two.
  15570.  
  15571. Before using this command, please see *Note Backup::.
  15572.  
  15573. During the backup, a read lock will be held for each table, one at time,
  15574. as they are being backed up. If you want to back up several tables as a
  15575. snapshot, you must first issue `LOCK TABLES' obtaining a read lock for
  15576. each table in the group.
  15577.  
  15578. The command returns a table with the following columns:
  15579.  
  15580. *Column*    *Value*
  15581. Table       Table name
  15582. Op          Always "backup"
  15583. Msg_type    One of `status', `error',
  15584.             `info' or `warning'.
  15585. Msg_text    The message.
  15586.  
  15587. Note that `BACKUP TABLE' is only available in MySQL version 3.23.25 and
  15588. later.
  15589.  
  15590. `RESTORE TABLE' Syntax
  15591. ----------------------
  15592.  
  15593.      RESTORE TABLE tbl_name[,tbl_name...] FROM '/path/to/backup/directory'
  15594.  
  15595. Restores the table(s) from the backup that was made with `BACKUP
  15596. TABLE'. Existing tables will not be overwritten; if you try to restore
  15597. over an existing table, you will get an error. Restoring will take
  15598. longer than backing up due to the need to rebuild the index. The more
  15599. keys you have, the longer it will take. Just as `BACKUP TABLE',
  15600. `RESTORE TABLE' currently works only for `MyISAM' tables.
  15601.  
  15602. The command returns a table with the following columns:
  15603.  
  15604. *Column*    *Value*
  15605. Table       Table name
  15606. Op          Always "restore"
  15607. Msg_type    One of `status', `error',
  15608.             `info' or `warning'.
  15609. Msg_text    The message.
  15610.  
  15611. `CHECK TABLE' Syntax
  15612. --------------------
  15613.  
  15614.      CHECK TABLE tbl_name[,tbl_name...] [option [option...]]
  15615.      
  15616.      option = QUICK | FAST | MEDIUM | EXTENDED | CHANGED
  15617.  
  15618. `CHECK TABLE' works only on `MyISAM' and `InnoDB' tables. On `MyISAM'
  15619. tables it's the same thing as running `myisamchk -m table_name' on the
  15620. table.
  15621.  
  15622. If you don't specify any option `MEDIUM' is used.
  15623.  
  15624. Checks the table(s) for errors. For `MyISAM' tables the key statistics
  15625. are updated. The command returns a table with the following columns:
  15626.  
  15627. *Column*    *Value*
  15628. Table       Table name.
  15629. Op          Always "check".
  15630. Msg_type    One of `status', `error',
  15631.             `info', or `warning'.
  15632. Msg_text    The message.
  15633.  
  15634. Note that you can get many rows of information for each checked table.
  15635. The last row will be of `Msg_type status' and should normally be `OK'.
  15636. If you don't get `OK', or `Table is already up to date' you should
  15637. normally run a repair of the table. *Note Table maintenance::. `Table
  15638. is already up to date' means that the table the given `TYPE' told MySQL
  15639. that there wasn't any need to check the table.
  15640.  
  15641. The different check types stand for the following:
  15642.  
  15643. *Type*      *Meaning*
  15644. `QUICK'     Don't scan the rows to check for wrong links.
  15645. `FAST'      Only check tables which haven't been closed properly.
  15646. `CHANGED'   Only check tables which have been changed since last check
  15647.             or haven't been closed properly.
  15648. `MEDIUM'    Scan rows to verify that deleted links are okay. This also
  15649.             calculates a key checksum for the rows and verifies this
  15650.             with a calculated checksum for the keys.
  15651. `EXTENDED'  Do a full key lookup for all keys for each row.  This
  15652.             ensures that the table is 100% consistent, but will take a
  15653.             long time!
  15654.  
  15655. For dynamically sized `MyISAM' tables a started check will always do a
  15656. `MEDIUM' check. For statically sized rows we skip the row scan for
  15657. `QUICK' and `FAST' as the rows are very seldom corrupted.
  15658.  
  15659. You can combine check options as in:
  15660.  
  15661.      CHECK TABLE test_table FAST QUICK;
  15662.  
  15663. Which would simply do a quick check on the table to see whether it was
  15664. closed properly.
  15665.  
  15666. *Note*: that in some case `CHECK TABLE' will change the table!  This
  15667. happens if the table is marked as 'corrupted' or 'not closed properly'
  15668. but `CHECK TABLE' didn't find any problems in the table.  In this case
  15669. `CHECK TABLE' will mark the table as okay.
  15670.  
  15671. If a table is corrupted, then it's most likely that the problem is in
  15672. the indexes and not in the data part.  All of the above check types
  15673. checks the indexes thoroughly and should thus find most errors.
  15674.  
  15675. If you just want to check a table that you assume is okay, you should
  15676. use no check options or the `QUICK' option. The latter should be used
  15677. when you are in a hurry and can take the very small risk that `QUICK'
  15678. didn't find an error in the datafile. (In most cases MySQL should find,
  15679. under normal usage, any error in the data file. If this happens then
  15680. the table will be marked as 'corrupted', in which case the table can't
  15681. be used until it's repaired.)
  15682.  
  15683. `FAST' and `CHANGED' are mostly intended to be used from a script (for
  15684. example to be executed from `cron') if you want to check your table
  15685. from time to time. In most cases you `FAST' is to be prefered over
  15686. `CHANGED'.  (The only case when it isn't is when you suspect a bug you
  15687. have found a bug in the `MyISAM' code.)
  15688.  
  15689. `EXTENDED' is only to be used after you have run a normal check but
  15690. still get strange errors from a table when MySQL tries to update a row
  15691. or find a row by key (this is very unlikely if a normal check has
  15692. succeeded!).
  15693.  
  15694. Some things reported by check table, can't be corrected automatically:
  15695.  
  15696.    * `Found row where the auto_increment column has the value 0'.
  15697.  
  15698.      This means that you have in the table a row where the
  15699.      `AUTO_INCREMENT' index column contains the value 0.  (It's
  15700.      possible to create a row where the `AUTO_INCREMENT' column is 0 by
  15701.      explicitly setting the column to 0 with an `UPDATE' statement)
  15702.  
  15703.      This isn't an error in itself, but could cause trouble if you
  15704.      decide to dump the table and restore it or do an `ALTER TABLE' on
  15705.      the table. In this case the `AUTO_INCREMENT' column will change
  15706.      value, according to the rules of `AUTO_INCREMENT' columns, which
  15707.      could cause problems like a duplicate key error.
  15708.  
  15709.      To get rid of the warning, just execute an `UPDATE' statement to
  15710.      set the column to some other value than 0.
  15711.  
  15712. `REPAIR TABLE' Syntax
  15713. ---------------------
  15714.  
  15715.      REPAIR TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED] [USE_FRM]
  15716.  
  15717. `REPAIR TABLE' works only on `MyISAM' tables and is the same as running
  15718. `myisamchk -r table_name' on the table.
  15719.  
  15720. Normally you should never have to run this command, but if disaster
  15721. strikes you are very likely to get back all your data from a MyISAM
  15722. table with `REPAIR TABLE'. If your tables get corrupted a lot you should
  15723. try to find the reason for this! *Note Crashing::. *Note MyISAM table
  15724. problems::.
  15725.  
  15726. `REPAIR TABLE' repairs a possible corrupted table. The command returns a
  15727. table with the following columns:
  15728.  
  15729. *Column*    *Value*
  15730. Table       Table name
  15731. Op          Always "repair"
  15732. Msg_type    One of `status', `error',
  15733.             `info' or `warning'.
  15734. Msg_text    The message.
  15735.  
  15736. Note that you can get many rows of information for each repaired table.
  15737. The last one row will be of `Msg_type status' and should normally be
  15738. `OK'.  If you don't get `OK', you should try repairing the table with
  15739. `myisamchk -o', as `REPAIR TABLE' does not yet implement all the
  15740. options of `myisamchk'. In the near future, we will make it more
  15741. flexible.
  15742.  
  15743. If `QUICK' is given then MySQL will try to do a `REPAIR' of only the
  15744. index tree.
  15745.  
  15746. If you use `EXTENDED' then MySQL will create the index row by row
  15747. instead of creating one index at a time with sorting; this may be
  15748. better than sorting on fixed-length keys if you have long `CHAR' keys
  15749. that compress very well.  This type of repair is like that done by
  15750. `myisamchk --safe-recover'.
  15751.  
  15752. As of `MySQL' 4.0.2, there is a `USE_FRM' mode for `REPAIR'.  Use it if
  15753. the `.MYI' file is missing or if its header is corrupted.  In this mode
  15754. MySQL will recreate the table, using information from the `.frm' file.
  15755. This kind of repair cannot be done with `myisamchk'.
  15756.  
  15757. Using `myisamchk' for Table Maintenance and Crash Recovery
  15758. ----------------------------------------------------------
  15759.  
  15760. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  15761. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  15762. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  15763.  
  15764. To check/repair MyISAM tables (`.MYI' and `.MYD') you should use the
  15765. `myisamchk' utility. To check/repair ISAM tables (`.ISM' and `.ISD')
  15766. you should use the `isamchk' utility. *Note Table types::.
  15767.  
  15768. In the following text we will talk about `myisamchk', but everything
  15769. also applies to the old `isamchk'.
  15770.  
  15771. You can use the `myisamchk' utility to get information about your
  15772. database tables, check and repair them, or optimise them.  The following
  15773. sections describe how to invoke `myisamchk' (including a description of
  15774. its options), how to set up a table maintenance schedule, and how to
  15775. use `myisamchk' to perform its various functions.
  15776.  
  15777. You can, in most cases, also use the command `OPTIMIZE TABLES' to
  15778. optimise and repair tables, but this is not as fast or reliable (in case
  15779. of real fatal errors) as `myisamchk'.  On the other hand, `OPTIMIZE
  15780. TABLE' is easier to use and you don't have to worry about flushing
  15781. tables.  *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  15782.  
  15783. Even that the repair in `myisamchk' is quite secure, it's always a good
  15784. idea to make a backup _before_ doing a repair (or anything that could
  15785. make a lot of changes to a table)
  15786.  
  15787. `myisamchk' Invocation Syntax
  15788. .............................
  15789.  
  15790. `myisamchk' is invoked like this:
  15791.  
  15792.      shell> myisamchk [options] tbl_name
  15793.  
  15794. The `options' specify what you want `myisamchk' to do.  They are
  15795. described here.  (You can also get a list of options by invoking
  15796. `myisamchk --help'.)  With no options, `myisamchk' simply checks your
  15797. table.  To get more information or to tell `myisamchk' to take
  15798. corrective action, specify options as described here and in the
  15799. following sections.
  15800.  
  15801. `tbl_name' is the database table you want to check/repair.  If you run
  15802. `myisamchk' somewhere other than in the database directory, you must
  15803. specify the path to the file, because `myisamchk' has no idea where your
  15804. database is located.  Actually, `myisamchk' doesn't care whether the
  15805. files you are working on are located in a database directory; you can
  15806. copy the files that correspond to a database table into another
  15807. location and perform recovery operations on them there.
  15808.  
  15809. You can name several tables on the `myisamchk' command-line if you
  15810. wish.  You can also specify a name as an index file name (with the
  15811. `.MYI' suffix), which allows you to specify all tables in a directory
  15812. by using the pattern `*.MYI'.  For example, if you are in a database
  15813. directory, you can check all the tables in the directory like this:
  15814.  
  15815.      shell> myisamchk *.MYI
  15816.  
  15817. If you are not in the database directory, you can check all the tables
  15818. there by specifying the path to the directory:
  15819.  
  15820.      shell> myisamchk /path/to/database_dir/*.MYI
  15821.  
  15822. You can even check all tables in all databases by specifying a wildcard
  15823. with the path to the MySQL data directory:
  15824.  
  15825.      shell> myisamchk /path/to/datadir/*/*.MYI
  15826.  
  15827. The recommended way to quickly check all tables is:
  15828.  
  15829.      myisamchk --silent --fast /path/to/datadir/*/*.MYI
  15830.      isamchk --silent /path/to/datadir/*/*.ISM
  15831.  
  15832. If you want to check all tables and repair all tables that are
  15833. corrupted, you can use the following line:
  15834.  
  15835.      myisamchk --silent --force --fast --update-state -O key_buffer=64M \
  15836.                -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
  15837.                /path/to/datadir/*/*.MYI
  15838.      isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M \
  15839.              -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.ISM
  15840.  
  15841. The above assumes that you have more than 64 M free.
  15842.  
  15843. Note that if you get an error like:
  15844.  
  15845.      myisamchk: warning: 1 clients is using or hasn't closed the table properly
  15846.  
  15847. This means that you are trying to check a table that has been updated by
  15848. the another program (like the `mysqld' server) that hasn't yet closed
  15849. the file or that has died without closing the file properly.
  15850.  
  15851. If you `mysqld' is running, you must force a sync/close of all tables
  15852. with `FLUSH TABLES' and ensure that no one is using the tables while
  15853. you are running `myisamchk'.  In MySQL Version 3.23 the easiest way to
  15854. avoid this problem is to use `CHECK TABLE' instead of `myisamchk' to
  15855. check tables.
  15856.  
  15857. General Options for `myisamchk'
  15858. ...............................
  15859.  
  15860. `myisamchk' supports the following options.
  15861.  
  15862. `-# or --debug=debug_options'
  15863.      Output debug log. The `debug_options' string often is
  15864.      `'d:t:o,filename''.
  15865.  
  15866. `-? or --help'
  15867.      Display a help message and exit.
  15868.  
  15869. `-O var=option, --set-variable var=option'
  15870.      Set the value of a variable.  Please note that `--set-variable' is
  15871.      deprecated since MySQL 4.0, just use `--var=option' on its own.
  15872.      The possible variables and their default values for myisamchk can
  15873.      be examined with `myisamchk --help':
  15874.      *Variable*    *Value*
  15875.      key_buffer_size523264
  15876.      read_buffer_size262136
  15877.      write_buffer_size262136
  15878.      sort_buffer_size2097144
  15879.      sort_key_blocks16
  15880.      decode_bits   9
  15881.  
  15882.      `sort_buffer_size' is used when the keys are repaired by sorting
  15883.      keys, which is the normal case when you use `--recover'.
  15884.  
  15885.      `key_buffer_size' is used when you are checking the table with
  15886.      `--extended-check' or when the keys are repaired by inserting key
  15887.      row by row in to the table (like when doing normal inserts).
  15888.      Repairing through the key buffer is used in the following cases:
  15889.  
  15890.         * If you use `--safe-recover'.
  15891.  
  15892.         * If the temporary files needed to sort the keys would be more
  15893.           than twice as big as when creating the key file directly.
  15894.           This is often the case when you have big `CHAR', `VARCHAR' or
  15895.           `TEXT' keys as the sort needs to store the whole keys during
  15896.           sorting. If you have lots of temporary space and you can
  15897.           force `myisamchk' to repair by sorting you can use the
  15898.           `--sort-recover' option.
  15899.  
  15900.      Reparing through the key buffer takes much less disk space than
  15901.      using sorting, but is also much slower.
  15902.  
  15903.      If you want a faster repair, set the above variables to about 1/4
  15904.      of your available memory.  You can set both variables to big
  15905.      values, as only one of the above buffers will be used at a time.
  15906.  
  15907. `-s or --silent'
  15908.      Silent mode.  Write output only when errors occur. You can use `-s'
  15909.      twice (`-ss') to make `myisamchk' very silent.
  15910.  
  15911. `-v or --verbose'
  15912.      Verbose mode.  Print more information. This can be used with `-d'
  15913.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for more
  15914.      verbosity!
  15915.  
  15916. `-V or --version'
  15917.      Print the `myisamchk' version and exit.
  15918.  
  15919. `-w or, --wait'
  15920.      Instead of giving an error if the table is locked, wait until the
  15921.      table is unlocked before continuing.  Note that if you are running
  15922.      `mysqld' on the table with `--skip-external-locking', the table
  15923.      can only be locked by another `myisamchk' command.
  15924.  
  15925. Check Options for `myisamchk'
  15926. .............................
  15927.  
  15928. `-c or --check'
  15929.      Check table for errors. This is the default operation if you are
  15930.      not giving `myisamchk' any options that override this.
  15931.  
  15932. `-e or --extend-check'
  15933.      Check the table very thoroughly (which is quite slow if you have
  15934.      many indexes).  This option should only be used in extreme cases.
  15935.      Normally, `myisamchk' or `myisamchk --medium-check' should, in most
  15936.      cases, be able to find out if there are any errors in the table.
  15937.  
  15938.      If you are using `--extended-check' and have much memory, you
  15939.      should increase the value of `key_buffer_size' a lot!
  15940.  
  15941. `-F or --fast'
  15942.      Check only tables that haven't been closed properly.
  15943.  
  15944. `-C or --check-only-changed'
  15945.      Check only tables that have changed since the last check.
  15946.  
  15947. `-f or --force'
  15948.      Restart `myisamchk' with `-r' (repair) on the table, if
  15949.      `myisamchk' finds any errors in the table.
  15950.  
  15951. `-i or --information'
  15952.      Print informational statistics about the table that is checked.
  15953.  
  15954. `-m or --medium-check'
  15955.      Faster than extended-check, but only finds 99.99% of all errors.
  15956.      Should, however, be good enough for most cases.
  15957.  
  15958. `-U or --update-state'
  15959.      Store in the `.MYI' file when the table was checked and if the
  15960.      table crashed.  This should be used to get full benefit of the
  15961.      `--check-only-changed' option, but you shouldn't use this option
  15962.      if the `mysqld' server is using the table and you are running
  15963.      `mysqld' with `--skip-external-locking'.
  15964.  
  15965. `-T or --read-only'
  15966.      Don't mark table as checked. This is useful if you use `myisamchk'
  15967.      to check a table that is in use by some other application that
  15968.      doesn't use locking (like `mysqld --skip-external-locking').
  15969.  
  15970. Repair Options for myisamchk
  15971. ............................
  15972.  
  15973. The following options are used if you start `myisamchk' with `-r' or
  15974. `-o':
  15975.  
  15976. `-D # or --data-file-length=#'
  15977.      Max length of datafile (when re-creating datafile when it's
  15978.      'full').
  15979.  
  15980. `-e or --extend-check'
  15981.      Try to recover every possible row from the datafile.  Normally
  15982.      this will also find a lot of garbage rows. Don't use this option
  15983.      if you are not totally desperate.
  15984.  
  15985. `-f or --force'
  15986.      Overwrite old temporary files (`table_name.TMD') instead of
  15987.      aborting.
  15988.  
  15989. `-k # or keys-used=#'
  15990.      If you are using ISAM, tells the ISAM storage engine to update
  15991.      only the first `#' indexes.  If you are using `MyISAM', tells
  15992.      which keys to use, where each binary bit stands for one key (first
  15993.      key is bit 0).  This can be used to get faster inserts!
  15994.      Deactivated indexes can be reactivated by using `myisamchk -r'.
  15995.      keys.
  15996.  
  15997. `-l or --no-symlinks'
  15998.      Do not follow symbolic links. Normally `myisamchk' repairs the
  15999.      table a symlink points at.  This option doesn't exist in MySQL 4.0,
  16000.      as MySQL 4.0 will not remove symlinks during repair.
  16001.  
  16002. `-r or --recover'
  16003.      Can fix almost anything except unique keys that aren't unique
  16004.      (which is an extremely unlikely error with ISAM/MyISAM tables).
  16005.      If you want to recover a table, this is the option to try first.
  16006.      Only if myisamchk reports that the table can't be recovered by
  16007.      `-r', you should then try `-o'.  (Note that in the unlikely case
  16008.      that `-r' fails, the datafile is still intact.)  If you have lots
  16009.      of memory, you should increase the size of `sort_buffer_size'!
  16010.  
  16011. `-o or --safe-recover'
  16012.      Uses an old recovery method (reads through all rows in order and
  16013.      updates all index trees based on the found rows); this is an order
  16014.      of magnitude slower than `-r', but can handle a couple of very
  16015.      unlikely cases that `-r' cannot handle.  This recovery method also
  16016.      uses much less disk space than `-r'. Normally one should always
  16017.      first repair with `-r', and only if this fails use `-o'.
  16018.  
  16019.      If you have lots of memory, you should increase the size of
  16020.      `key_buffer_size'!
  16021.  
  16022. `-n or --sort-recover'
  16023.      Force `myisamchk' to use sorting to resolve the keys even if the
  16024.      temporary files should be very big.
  16025.  
  16026. `--character-sets-dir=...'
  16027.      Directory where character sets are stored.
  16028.  
  16029. `--set-character-set=name'
  16030.      Change the character set used by the index
  16031.  
  16032. `-t or --tmpdir=path'
  16033.      Path for storing temporary files. If this is not set, `myisamchk'
  16034.      will use the environment variable `TMPDIR' for this.
  16035.  
  16036. `-q or --quick'
  16037.      Faster repair by not modifying the datafile. One can give a second
  16038.      `-q' to force `myisamchk' to modify the original datafile in case
  16039.      of duplicate keys
  16040.  
  16041. `-u or --unpack'
  16042.      Unpack file packed with myisampack.
  16043.  
  16044. Other Options for `myisamchk'
  16045. .............................
  16046.  
  16047. Other actions that `myisamchk' can do, besides repair and check tables:
  16048.  
  16049. `-a or --analyze'
  16050.      Analyse the distribution of keys. This improves join performance by
  16051.      enabling the join optimiser to better choose in which order it
  16052.      should join the tables and which keys it should use: `myisamchk
  16053.      --describe --verbose table_name'' or using `SHOW KEYS' in MySQL.
  16054.  
  16055. `-d or --description'
  16056.      Prints some information about table.
  16057.  
  16058. `-A or --set-auto-increment[=value]'
  16059.      Force `AUTO_INCREMENT' to start at this or higher value. If no
  16060.      value is given, then sets the next `AUTO_INCREMENT' value to the
  16061.      highest used value for the auto key + 1.
  16062.  
  16063. `-S or --sort-index'
  16064.      Sort the index tree blocks in high-low order.  This will optimise
  16065.      seeks and will make table scanning by key faster.
  16066.  
  16067. `-R or --sort-records=#'
  16068.      Sorts records according to an index.  This makes your data much
  16069.      more localised and may speed up ranged `SELECT' and `ORDER BY'
  16070.      operations on this index. (It may be very slow to do a sort the
  16071.      first time!)  To find out a table's index numbers, use `SHOW
  16072.      INDEX', which shows a table's indexes in the same order that
  16073.      `myisamchk' sees them.  Indexes are numbered beginning with 1.
  16074.  
  16075. `myisamchk' Memory Usage
  16076. ........................
  16077.  
  16078. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  16079. uses no more memory than you specify with the `-O' options.  If you are
  16080. going to use `myisamchk' on very large files, you should first decide
  16081. how much memory you want it to use.  The default is to use only about
  16082. 3M to fix things.  By using larger values, you can get `myisamchk' to
  16083. operate faster.  For example, if you have more than 32M RAM, you could
  16084. use options such as these (in addition to any other options you might
  16085. specify):
  16086.  
  16087.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  16088.  
  16089. Using `-O sort=16M' should probably be enough for most cases.
  16090.  
  16091. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  16092. points to a memory filesystem, you may easily get out of memory errors.
  16093. If this happens, set `TMPDIR' to point at some directory with more
  16094. space and restart `myisamchk'.
  16095.  
  16096. When repairing, `myisamchk' will also need a lot of disk space:
  16097.  
  16098.    * Double the size of the record file (the original one and a copy).
  16099.      This space is not needed if one does a repair with `--quick', as
  16100.      in this case only the index file will be re-created.  This space
  16101.      is needed on the same disk as the original record file!
  16102.  
  16103.    * Space for the new index file that replaces the old one. The old
  16104.      index file is truncated at start, so one usually ignore this space.
  16105.      This space is needed on the same disk as the original index file!
  16106.  
  16107.    * When using `--recover' or `--sort-recover' (but not when using
  16108.      `--safe-recover'), you will need space for a sort buffer for:
  16109.      `(largest_key + row_pointer_length)*number_of_rows * 2'.  You can
  16110.      check the length of the keys and the row_pointer_length with
  16111.      `myisamchk -dv table'.  This space is allocated on the temporary
  16112.      disk (specified by `TMPDIR' or `--tmpdir=#').
  16113.  
  16114. If you have a problem with disk space during repair, you can try to use
  16115. `--safe-recover' instead of `--recover'.
  16116.  
  16117. Using `myisamchk' for Crash Recovery
  16118. ....................................
  16119.  
  16120. If you run `mysqld' with `--skip-external-locking' (which is the
  16121. default on some systems, like Linux), you can't reliably use `myisamchk'
  16122. to check a table when `mysqld' is using the same table.  If you can be
  16123. sure that no one is accessing the tables through `mysqld' while you run
  16124. `myisamchk', you only have to do `mysqladmin flush-tables' before you
  16125. start checking the tables.  If you can't guarantee the above, then you
  16126. must take down `mysqld' while you check the tables.  If you run
  16127. `myisamchk' while `mysqld' is updating the tables, you may get a
  16128. warning that a table is corrupt even if it isn't.
  16129.  
  16130. If you are not using `--skip-external-locking', you can use `myisamchk'
  16131. to check tables at any time.  While you do this, all clients that try
  16132. to update the table will wait until `myisamchk' is ready before
  16133. continuing.
  16134.  
  16135. If you use `myisamchk' to repair or optimise tables, you *must* always
  16136. ensure that the `mysqld' server is not using the table (this also
  16137. applies if you are using `--skip-external-locking').  If you don't take
  16138. down `mysqld' you should at least do a `mysqladmin flush-tables' before
  16139. you run `myisamchk'.  Your tables *may be corrupted* if the server and
  16140. `myisamchk' access the tables simultaneously.
  16141.  
  16142. This chapter describes how to check for and deal with data corruption
  16143. in MySQL databases.  If your tables get corrupted frequently you should
  16144. try to find the reason for this! *Note Crashing::.
  16145.  
  16146. The `MyISAM' table section contains reason for why a table could be
  16147. corrupted. *Note MyISAM table problems::.
  16148.  
  16149. When performing crash recovery, it is important to understand that each
  16150. table `tbl_name' in a database corresponds to three files in the
  16151. database directory:
  16152.  
  16153. *File*         *Purpose*
  16154. `tbl_name.frm' Table definition
  16155.                (form) file
  16156. `tbl_name.MYD' Datafile
  16157. `tbl_name.MYI' Index file
  16158.  
  16159. Each of these three file types is subject to corruption in various
  16160. ways, but problems occur most often in datafiles and index files.
  16161.  
  16162. `myisamchk' works by creating a copy of the `.MYD' (data) file row by
  16163. row. It ends the repair stage by removing the old `.MYD' file and
  16164. renaming the new file to the original file name.  If you use `--quick',
  16165. `myisamchk' does not create a temporary `.MYD' file, but instead
  16166. assumes that the `.MYD' file is correct and only generates a new index
  16167. file without touching the `.MYD' file. This is safe, because
  16168. `myisamchk' automatically detects if the `.MYD' file is corrupt and
  16169. aborts the repair in this case.  You can also give two `--quick'
  16170. options to `myisamchk'.  In this case, `myisamchk' does not abort on
  16171. some errors (like duplicate key) but instead tries to resolve them by
  16172. modifying the `.MYD' file. Normally the use of two `--quick' options is
  16173. useful only if you have too little free disk space to perform a normal
  16174. repair.  In this case you should at least make a backup before running
  16175. `myisamchk'.
  16176.  
  16177. How to Check Tables for Errors
  16178. ..............................
  16179.  
  16180. To check a MyISAM table, use the following commands:
  16181.  
  16182. `myisamchk tbl_name'
  16183.      This finds 99.99% of all errors. What it can't find is corruption
  16184.      that involves *only* the datafile (which is very unusual). If you
  16185.      want to check a table, you should normally run `myisamchk' without
  16186.      options or with either the `-s' or `--silent' option.
  16187.  
  16188. `myisamchk -m tbl_name'
  16189.      This finds 99.999% of all errors. It checks first all index
  16190.      entries for errors and then it reads through all rows. It
  16191.      calculates a checksum for all keys in the rows and verifies that
  16192.      they checksum matches the checksum for the keys in the index tree.
  16193.  
  16194. `myisamchk -e tbl_name'
  16195.      This does a complete and thorough check of all data (`-e' means
  16196.      "extended check"). It does a check-read of every key for each row
  16197.      to verify that they indeed point to the correct row.  This may
  16198.      take a long time on a big table with many keys.  `myisamchk' will
  16199.      normally stop after the first error it finds. If you want to
  16200.      obtain more information, you can add the `--verbose' (`-v')
  16201.      option.  This causes `myisamchk' to keep going, up through a
  16202.      maximum of 20 errors.  In normal usage, a simple `myisamchk' (with
  16203.      no arguments other than the table name) is sufficient.
  16204.  
  16205. `myisamchk -e -i tbl_name'
  16206.      Like the previous command, but the `-i' option tells `myisamchk' to
  16207.      print some informational statistics, too.
  16208.  
  16209. How to Repair Tables
  16210. ....................
  16211.  
  16212. In the following section we only talk about using `myisamchk' on
  16213. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  16214. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  16215. instead.
  16216.  
  16217. Starting with MySQL Version 3.23.14, you can repair MyISAM tables with
  16218. the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  16219.  
  16220. The symptoms of a corrupted table include queries that abort
  16221. unexpectedly and observable errors such as these:
  16222.  
  16223.    * `tbl_name.frm' is locked against change
  16224.  
  16225.    * Can't find file `tbl_name.MYI' (Errcode: ###)
  16226.  
  16227.    * Unexpected end of file
  16228.  
  16229.    * Record file is crashed
  16230.  
  16231.    * Got error ### from table handler
  16232.  
  16233.      To get more information about the error you can run `perror ###'.
  16234.      Here is the most common errors that indicates a problem with the
  16235.      table:
  16236.  
  16237.           shell> perror 126 127 132 134 135 136 141 144 145
  16238.           126 = Index file is crashed / Wrong file format
  16239.           127 = Record-file is crashed
  16240.           132 = Old database file
  16241.           134 = Record was already deleted (or record file crashed)
  16242.           135 = No more room in record file
  16243.           136 = No more room in index file
  16244.           141 = Duplicate unique key or constraint on write or update
  16245.           144 = Table is crashed and last repair failed
  16246.           145 = Table was marked as crashed and should be repaired
  16247.  
  16248.      Note that error 135, no more room in record file, is not an error
  16249.      that can be fixed by a simple repair. In this case you have to do:
  16250.  
  16251.           ALTER TABLE table MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;
  16252.  
  16253.  
  16254. In the other cases, you must repair your tables. `myisamchk' can
  16255. usually detect and fix most things that go wrong.
  16256.  
  16257. The repair process involves up to four stages, described here. Before
  16258. you begin, you should `cd' to the database directory and check the
  16259. permissions of the table files. Make sure they are readable by the Unix
  16260. user that `mysqld' runs as (and to you, because you need to access the
  16261. files you are checking).  If it turns out you need to modify files,
  16262. they must also be writable by you.
  16263.  
  16264. If you are using MySQL Version 3.23.16 and above, you can (and should)
  16265. use the `CHECK' and `REPAIR' commands to check and repair `MyISAM'
  16266. tables.  *Note CHECK TABLE::.  *Note REPAIR TABLE::.
  16267.  
  16268. The manual section about table maintenance includes the options to
  16269. `isamchk'/`myisamchk'.  *Note Table maintenance::.
  16270.  
  16271. The following section is for the cases where the above command fails or
  16272. if you want to use the extended features that `isamchk'/`myisamchk'
  16273. provides.
  16274.  
  16275. If you are going to repair a table from the command-line, you must first
  16276. take down the `mysqld' server. Note that when you do `mysqladmin
  16277. shutdown' on a remote server, the `mysqld' server will still be alive
  16278. for a while after `mysqladmin' returns, until all queries are stopped
  16279. and all keys have been flushed to disk.
  16280.  
  16281. *Stage 1: Checking your tables*
  16282.  
  16283. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  16284. Use the `-s' (silent) option to suppress unnecessary information.
  16285.  
  16286. If the `mysqld' server is done you should use the -update option to tell
  16287. `myisamchk' to mark the table as 'checked'.
  16288.  
  16289. You have to repair only those tables for which `myisamchk' announces an
  16290. error.  For such tables, proceed to Stage 2.
  16291.  
  16292. If you get weird errors when checking (such as `out of memory' errors),
  16293. or if `myisamchk' crashes, go to Stage 3.
  16294.  
  16295. *Stage 2: Easy safe repair*
  16296.  
  16297. Note: If you want repairing to go much faster, you should add: `-O
  16298. sort_buffer=# -O key_buffer=#' (where # is about 1/4 of the available
  16299. memory) to all `isamchk/myisamchk' commands.
  16300.  
  16301. First, try `myisamchk -r -q tbl_name' (`-r -q' means "quick recovery
  16302. mode"). This will attempt to repair the index file without touching the
  16303. datafile.  If the datafile contains everything that it should and the
  16304. delete links point at the correct locations within the datafile, this
  16305. should work, and the table is fixed. Start repairing the next table.
  16306. Otherwise, use the following procedure:
  16307.  
  16308.   1. Make a backup of the datafile before continuing.
  16309.  
  16310.   2. Use `myisamchk -r tbl_name' (`-r' means "recovery mode"). This will
  16311.      remove incorrect records and deleted records from the datafile and
  16312.      reconstruct the index file.
  16313.  
  16314.   3. If the preceding step fails, use `myisamchk --safe-recover
  16315.      tbl_name'.  Safe recovery mode uses an old recovery method that
  16316.      handles a few cases that regular recovery mode doesn't (but is
  16317.      slower).
  16318.  
  16319. If you get weird errors when repairing (such as `out of memory'
  16320. errors), or if `myisamchk' crashes, go to Stage 3.
  16321.  
  16322. *Stage 3: Difficult repair*
  16323.  
  16324. You should only reach this stage if the first 16K block in the index
  16325. file is destroyed or contains incorrect information, or if the index
  16326. file is missing.  In this case, it's necessary to create a new index
  16327. file. Do so as follows:
  16328.  
  16329.   1. Move the datafile to some safe place.
  16330.  
  16331.   2. Use the table description file to create new (empty) data and
  16332.      index files:
  16333.  
  16334.           shell> mysql db_name
  16335.           mysql> SET AUTOCOMMIT=1;
  16336.           mysql> TRUNCATE TABLE table_name;
  16337.           mysql> quit
  16338.  
  16339.      If your SQL version doesn't have `TRUNCATE TABLE', use `DELETE FROM
  16340.      table_name' instead.
  16341.  
  16342.   3. Copy the old datafile back onto the newly created datafile.
  16343.      (Don't just move the old file back onto the new file; you want to
  16344.      retain a copy in case something goes wrong.)
  16345.  
  16346. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  16347. be an endless loop.)
  16348.  
  16349. As of `MySQL' 4.0.2 you can also use `REPAIR ... USE_FRM' which
  16350. performs the whole procedure automatically.
  16351.  
  16352. *Stage 4: Very difficult repair*
  16353.  
  16354. You should reach this stage only if the description file has also
  16355. crashed. That should never happen, because the description file isn't
  16356. changed after the table is created:
  16357.  
  16358.   1. Restore the description file from a backup and go back to Stage 3.
  16359.      You can also restore the index file and go back to Stage 2.  In
  16360.      the latter case, you should start with `myisamchk -r'.
  16361.  
  16362.   2. If you don't have a backup but know exactly how the table was
  16363.      created, create a copy of the table in another database.  Remove
  16364.      the new datafile, then move the description and index files from
  16365.      the other database to your crashed database.  This gives you new
  16366.      description and index files, but leaves the datafile alone.  Go
  16367.      back to Stage 2 and attempt to reconstruct the index file.
  16368.  
  16369. Table Optimisation
  16370. ..................
  16371.  
  16372. To coalesce fragmented records and eliminate wasted space resulting from
  16373. deleting or updating records, run `myisamchk' in recovery mode:
  16374.  
  16375.      shell> myisamchk -r tbl_name
  16376.  
  16377. You can optimise a table in the same way using the SQL `OPTIMIZE TABLE'
  16378. statement.  `OPTIMIZE TABLE' does a repair of the table and a key
  16379. analysis, and also sorts the index tree to give faster key lookups.
  16380. There is also no possibility of unwanted interaction between a utility
  16381. and the server, because the server does all the work when you use
  16382. `OPTIMIZE TABLE'. *Note OPTIMIZE TABLE::.
  16383.  
  16384. `myisamchk' also has a number of other options you can use to improve
  16385. the performance of a table:
  16386.  
  16387.    * `-S', `--sort-index'
  16388.  
  16389.    * `-R index_num', `--sort-records=index_num'
  16390.  
  16391.    * `-a', `--analyze'
  16392.  
  16393. For a full description of the option. *Note myisamchk syntax::.
  16394.  
  16395. Setting Up a Table Maintenance Regimen
  16396. --------------------------------------
  16397.  
  16398. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  16399. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  16400. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  16401.  
  16402. It is a good idea to perform table checks on a regular basis rather than
  16403. waiting for problems to occur.  For maintenance purposes, you can use
  16404. `myisamchk -s' to check tables.  The `-s' option (short for `--silent')
  16405. causes `myisamchk' to run in silent mode, printing messages only when
  16406. errors occur.
  16407.  
  16408. It's also a good idea to check tables when the server starts up.  For
  16409. example, whenever the machine has done a reboot in the middle of an
  16410. update, you usually need to check all the tables that could have been
  16411. affected. (This is an "expected crashed table".) You could add a test to
  16412. `safe_mysqld' that runs `myisamchk' to check all tables that have been
  16413. modified during the last 24 hours if there is an old `.pid' (process
  16414. ID) file left after a reboot.  (The `.pid' file is created by `mysqld'
  16415. when it starts up and removed when it terminates normally.  The
  16416. presence of a `.pid' file at system startup time indicates that
  16417. `mysqld' terminated abnormally.)
  16418.  
  16419. An even better test would be to check any table whose last-modified time
  16420. is more recent than that of the `.pid' file.
  16421.  
  16422. You should also check your tables regularly during normal system
  16423. operation.  At MySQL AB, we run a `cron' job to check all our important
  16424. tables once a week, using a line like this in a `crontab' file:
  16425.  
  16426.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  16427.  
  16428. This prints out information about crashed tables so we can examine and
  16429. repair them when needed.
  16430.  
  16431. As we haven't had any unexpectedly crashed tables (tables that become
  16432. corrupted for reasons other than hardware trouble) for a couple of
  16433. years now (this is really true), once a week is more than enough for us.
  16434.  
  16435. We recommend that to start with, you execute `myisamchk -s' each night
  16436. on all tables that have been updated during the last 24 hours, until
  16437. you come to trust MySQL as much as we do.
  16438.  
  16439. Normally you don't need to maintain MySQL tables that much.  If you are
  16440. changing tables with dynamic size rows (tables with `VARCHAR', `BLOB'
  16441. or `TEXT' columns) or have tables with many deleted rows you may want
  16442. to from time to time (once a month?) defragment/reclaim space from the
  16443. tables.
  16444.  
  16445. You can do this by using `OPTIMIZE TABLE' on the tables in question or
  16446. if you can take the `mysqld' server down for a while do:
  16447.  
  16448.      isamchk -r --silent --sort-index -O sort_buffer_size=16M */*.ISM
  16449.      myisamchk -r --silent --sort-index  -O sort_buffer_size=16M */*.MYI
  16450.  
  16451. Getting Information About a Table
  16452. ---------------------------------
  16453.  
  16454. To get a description of a table or statistics about it, use the
  16455. commands shown here. We explain some of the information in more detail
  16456. later:
  16457.  
  16458.    * myisamchk -d tbl_name Runs `myisamchk' in "describe mode" to
  16459.      produce a description of your table. If you start the MySQL server
  16460.      using the `--skip-external-locking' option, `myisamchk' may report
  16461.      an error for a table that is updated while it runs.  However,
  16462.      because `myisamchk' doesn't change the table in describe mode,
  16463.      there isn't any risk of destroying data.
  16464.  
  16465.    * myisamchk -d -v tbl_name To produce more information about what
  16466.      `myisamchk' is doing, add `-v' to tell it to run in verbose mode.
  16467.  
  16468.    * myisamchk -eis tbl_name Shows only the most important information
  16469.      from a table. It is slow because it must read the whole table.
  16470.  
  16471.    * myisamchk -eiv tbl_name This is like `-eis', but tells you what is
  16472.      being done.
  16473.  
  16474. Example of `myisamchk -d' output:
  16475.      MyISAM file:     company.MYI
  16476.      Record format:   Fixed length
  16477.      Data records:    1403698  Deleted blocks:         0
  16478.      Recordlength:    226
  16479.      
  16480.      table description:
  16481.      Key Start Len Index   Type
  16482.      1   2     8   unique  double
  16483.      2   15    10  multip. text packed stripped
  16484.      3   219   8   multip. double
  16485.      4   63    10  multip. text packed stripped
  16486.      5   167   2   multip. unsigned short
  16487.      6   177   4   multip. unsigned long
  16488.      7   155   4   multip. text
  16489.      8   138   4   multip. unsigned long
  16490.      9   177   4   multip. unsigned long
  16491.          193   1           text
  16492.  
  16493. Example of `myisamchk -d -v' output:
  16494.      MyISAM file:         company
  16495.      Record format:       Fixed length
  16496.      File-version:        1
  16497.      Creation time:       1999-10-30 12:12:51
  16498.      Recover time:        1999-10-31 19:13:01
  16499.      Status:              checked
  16500.      Data records:           1403698  Deleted blocks:              0
  16501.      Datafile parts:         1403698  Deleted data:                0
  16502.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     3
  16503.      Max datafile length: 3791650815  Max keyfile length: 4294967294
  16504.      Recordlength:               226
  16505.      
  16506.      table description:
  16507.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  16508.      1   2     8   unique  double                      1 15845376      1024
  16509.      2   15    10  multip. text packed stripped        2 25062400      1024
  16510.      3   219   8   multip. double                     73 40907776      1024
  16511.      4   63    10  multip. text packed stripped        5 48097280      1024
  16512.      5   167   2   multip. unsigned short           4840 55200768      1024
  16513.      6   177   4   multip. unsigned long            1346 65145856      1024
  16514.      7   155   4   multip. text                     4995 75090944      1024
  16515.      8   138   4   multip. unsigned long              87 85036032      1024
  16516.      9   177   4   multip. unsigned long             178 96481280      1024
  16517.          193   1           text
  16518.  
  16519. Example of `myisamchk -eis' output:
  16520.      Checking MyISAM file: company
  16521.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  16522.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  16523.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  16524.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  16525.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16526.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16527.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16528.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16529.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  16530.      Total:    Keyblocks used:  98%  Packed:   17%
  16531.      
  16532.      Records:          1403698    M.recordlength:     226
  16533.      Packed:             0%
  16534.      Recordspace used:     100%   Empty space:          0%
  16535.      Blocks/Record:   1.00
  16536.      Record blocks:    1403698    Delete blocks:        0
  16537.      Recorddata:     317235748    Deleted data:         0
  16538.      Lost space:             0    Linkdata:             0
  16539.      
  16540.      User time 1626.51, System time 232.36
  16541.      Maximum resident set size 0, Integral resident set size 0
  16542.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  16543.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  16544.      Voluntary context switches 639, Involuntary context switches 28966
  16545.  
  16546. Example of `myisamchk -eiv' output:
  16547.      Checking MyISAM file: company
  16548.      Data records: 1403698   Deleted blocks:       0
  16549.      - check file-size
  16550.      - check delete-chain
  16551.      block_size 1024:
  16552.      index  1:
  16553.      index  2:
  16554.      index  3:
  16555.      index  4:
  16556.      index  5:
  16557.      index  6:
  16558.      index  7:
  16559.      index  8:
  16560.      index  9:
  16561.      No recordlinks
  16562.      - check index reference
  16563.      - check data record references index: 1
  16564.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  16565.      - check data record references index: 2
  16566.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  16567.      - check data record references index: 3
  16568.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  16569.      - check data record references index: 4
  16570.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  16571.      - check data record references index: 5
  16572.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16573.      - check data record references index: 6
  16574.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16575.      - check data record references index: 7
  16576.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16577.      - check data record references index: 8
  16578.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  16579.      - check data record references index: 9
  16580.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  16581.      Total:    Keyblocks used:   9%  Packed:   17%
  16582.      
  16583.      - check records and index references
  16584.      [LOTS OF ROW NUMBERS DELETED]
  16585.      
  16586.      Records:          1403698    M.recordlength:     226   Packed:             0%
  16587.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  16588.      Record blocks:    1403698    Delete blocks:        0
  16589.      Recorddata:     317235748    Deleted data:         0
  16590.      Lost space:             0    Linkdata:             0
  16591.      
  16592.      User time 1639.63, System time 251.61
  16593.      Maximum resident set size 0, Integral resident set size 0
  16594.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  16595.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  16596.      Voluntary context switches 10604, Involuntary context switches 122798
  16597.  
  16598. Here are the sizes of the data and index files for the table used in the
  16599. preceding examples:
  16600.  
  16601.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  16602.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  16603.  
  16604. Explanations for the types of information `myisamchk' produces are
  16605. given here.  The "keyfile" is the index file.  "Record" and "row" are
  16606. synonymous:
  16607.  
  16608.    * ISAM file Name of the ISAM (index) file.
  16609.  
  16610.    * Isam-version Version of ISAM format. Currently always 2.
  16611.  
  16612.    * Creation time When the datafile was created.
  16613.  
  16614.    * Recover time When the index/datafile was last reconstructed.
  16615.  
  16616.    * Data records How many records are in the table.
  16617.  
  16618.    * Deleted blocks How many deleted blocks still have reserved space.
  16619.      You can optimise your table to minimise this space.  *Note
  16620.      Optimisation::.
  16621.  
  16622.    * Data file: Parts For dynamic record format, this indicates how
  16623.      many data blocks there are. For an optimised table without
  16624.      fragmented records, this is the same as `Data records'.
  16625.  
  16626.    * Deleted data How many bytes of non-reclaimed deleted data there
  16627.      are.  You can optimise your table to minimise this space.  *Note
  16628.      Optimisation::.
  16629.  
  16630.    * Data file pointer The size of the datafile pointer, in bytes. It
  16631.      is usually 2, 3, 4, or 5 bytes. Most tables manage with 2 bytes,
  16632.      but this cannot be controlled from MySQL yet. For fixed tables,
  16633.      this is a record address. For dynamic tables, this is a byte
  16634.      address.
  16635.  
  16636.    * Keyfile pointer The size of the index file pointer, in bytes. It
  16637.      is usually 1, 2, or 3 bytes. Most tables manage with 2 bytes, but
  16638.      this is calculated automatically by MySQL. It is always a block
  16639.      address.
  16640.  
  16641.    * Max datafile length How long the table's datafile (`.MYD' file)
  16642.      can become, in bytes.
  16643.  
  16644.    * Max keyfile length How long the table's key file (`.MYI' file) can
  16645.      become, in bytes.
  16646.  
  16647.    * Recordlength How much space each record takes, in bytes.
  16648.  
  16649.    * Record format The format used to store table rows.  The examples
  16650.      shown above use `Fixed length'.  Other possible values are
  16651.      `Compressed' and `Packed'.
  16652.  
  16653.    * table description A list of all keys in the table. For each key,
  16654.      some low-level information is presented:
  16655.  
  16656.         - Key This key's number.
  16657.  
  16658.         - Start Where in the record this index part starts.
  16659.  
  16660.         - Len How long this index part is. For packed numbers, this
  16661.           should always be the full length of the column. For strings,
  16662.           it may be shorter than the full length of the indexed column,
  16663.           because you can index a prefix of a string column.
  16664.  
  16665.         - Index `unique' or `multip.' (multiple). Indicates whether one
  16666.           value can exist multiple times in this index.
  16667.  
  16668.         - Type What data-type this index part has. This is an ISAM
  16669.           data-type with the options `packed', `stripped' or `empty'.
  16670.  
  16671.         - Root Address of the root index block.
  16672.  
  16673.         - Blocksize The size of each index block. By default this is
  16674.           1024, but the value may be changed at compile time.
  16675.  
  16676.         - Rec/key This is a statistical value used by the optimiser. It
  16677.           tells how many records there are per value for this key. A
  16678.           unique key always has a value of 1. This may be updated after
  16679.           a table is loaded (or greatly changed) with `myisamchk -a'.
  16680.           If this is not updated at all, a default value of 30 is given.
  16681.  
  16682.    * In the first example above, the 9th key is a multi-part key with
  16683.      two parts.
  16684.  
  16685.    * Keyblocks used What percentage of the keyblocks are used. Because
  16686.      the table used in the examples had just been reorganised with
  16687.      `myisamchk', the values are very high (very near the theoretical
  16688.      maximum).
  16689.  
  16690.    * Packed MySQL tries to pack keys with a common suffix. This can
  16691.      only be used for `CHAR'/`VARCHAR'/`DECIMAL' keys. For long strings
  16692.      like names, this can significantly reduce the space used. In the
  16693.      third example above, the 4th key is 10 characters long and a 60%
  16694.      reduction in space is achieved.
  16695.  
  16696.    * Max levels How deep the B-tree for this key is. Large tables with
  16697.      long keys get high values.
  16698.  
  16699.    * Records How many rows are in the table.
  16700.  
  16701.    * M.recordlength The average record length. For tables with
  16702.      fixed-length records, this is the exact record length.
  16703.  
  16704.    * Packed MySQL strips spaces from the end of strings. The `Packed'
  16705.      value indicates the percentage of savings achieved by doing this.
  16706.  
  16707.    * Recordspace used What percentage of the datafile is used.
  16708.  
  16709.    * Empty space What percentage of the datafile is unused.
  16710.  
  16711.    * Blocks/Record Average number of blocks per record (that is, how
  16712.      many links a fragmented record is composed of). This is always 1.0
  16713.      for fixed-format tables. This value should stay as close to 1.0 as
  16714.      possible. If it gets too big, you can reorganise the table with
  16715.      `myisamchk'.  *Note Optimisation::.
  16716.  
  16717.    * Recordblocks How many blocks (links) are used. For fixed format,
  16718.      this is the same as the number of records.
  16719.  
  16720.    * Deleteblocks How many blocks (links) are deleted.
  16721.  
  16722.    * Recorddata How many bytes in the datafile are used.
  16723.  
  16724.    * Deleted data How many bytes in the datafile are deleted (unused).
  16725.  
  16726.    * Lost space If a record is updated to a shorter length, some space
  16727.      is lost. This is the sum of all such losses, in bytes.
  16728.  
  16729.    * Linkdata When the dynamic table format is used, record fragments
  16730.      are linked with pointers (4 to 7 bytes each). `Linkdata' is the
  16731.      sum of the amount of storage used by all such pointers.
  16732.  
  16733. If a table has been compressed with `myisampack', `myisamchk -d' prints
  16734. additional information about each table column.  See *Note
  16735. `myisampack': myisampack, for an example of this information and a
  16736. description of what it means.
  16737.  
  16738. Database Administration Language Reference
  16739. ==========================================
  16740.  
  16741. `OPTIMIZE TABLE' Syntax
  16742. -----------------------
  16743.  
  16744.      OPTIMIZE TABLE tbl_name[,tbl_name]...
  16745.  
  16746. `OPTIMIZE TABLE' should be used if you have deleted a large part of a
  16747. table or if you have made many changes to a table with variable-length
  16748. rows (tables that have `VARCHAR', `BLOB', or `TEXT' columns).  Deleted
  16749. records are maintained in a linked list and subsequent `INSERT'
  16750. operations reuse old record positions. You can use `OPTIMIZE TABLE' to
  16751. reclaim the unused space and to defragment the datafile.
  16752.  
  16753. For the moment, `OPTIMIZE TABLE' works only on `MyISAM' and `BDB'
  16754. tables. For `BDB' tables, `OPTIMIZE TABLE' is currently mapped to
  16755. `ANALYZE TABLE'.  *Note `ANALYZE TABLE': ANALYZE TABLE.
  16756.  
  16757. You can get `OPTIMIZE TABLE' to work on other table types by starting
  16758. `mysqld' with `--skip-new' or `--safe-mode', but in this case `OPTIMIZE
  16759. TABLE' is just mapped to `ALTER TABLE'.
  16760.  
  16761. `OPTIMIZE TABLE' works the following way:
  16762.    * If the table has deleted or split rows, repair the table.
  16763.  
  16764.    * If the index pages are not sorted, sort them.
  16765.  
  16766.    * If the statistics are not up to date (and the repair couldn't be
  16767.      done by sorting the index), update them.
  16768.  
  16769. `OPTIMIZE TABLE' for a `MyISAM' table is equivalent to running
  16770. `myisamchk --quick --check-only-changed --sort-index --analyze' on the
  16771. table.
  16772.  
  16773. Note that the table is locked during the time `OPTIMIZE TABLE' is
  16774. running!
  16775.  
  16776. `ANALYZE TABLE' Syntax
  16777. ----------------------
  16778.  
  16779.      ANALYZE TABLE tbl_name[,tbl_name...]
  16780.  
  16781. Analyse and store the key distribution for the table.  During the
  16782. analysis, the table is locked with a read lock.  This works on `MyISAM'
  16783. and `BDB' tables.
  16784.  
  16785. This is equivalent to running `myisamchk -a' on the table.
  16786.  
  16787. MySQL uses the stored key distribution to decide in which order tables
  16788. should be joined when one does a join on something else than a constant.
  16789.  
  16790. The command returns a table with the following columns:
  16791.  
  16792. *Column*    *Value*
  16793. Table       Table name
  16794. Op          Always "analyze"
  16795. Msg_type    One of `status', `error',
  16796.             `info' or `warning'.
  16797. Msg_text    The message.
  16798.  
  16799. You can check the stored key distribution with the `SHOW INDEX' command.
  16800. *Note SHOW DATABASE INFO::.
  16801.  
  16802. If the table hasn't changed since the last `ANALYZE TABLE' command, the
  16803. table will not be analysed again.
  16804.  
  16805. `FLUSH' Syntax
  16806. --------------
  16807.  
  16808.      FLUSH flush_option [,flush_option] ...
  16809.  
  16810. You should use the `FLUSH' command if you want to clear some of the
  16811. internal caches MySQL uses.  To execute `FLUSH', you must have the
  16812. `RELOAD' privilege.
  16813.  
  16814. `flush_option' can be any of the following:
  16815.  
  16816. *Option*           *Description*
  16817. `HOSTS'            Empties the host cache tables.  You should flush the
  16818.                    host tables if some of your hosts change IP number or
  16819.                    if you get the error message `Host ... is blocked'.
  16820.                    When more than `max_connect_errors' errors occur in a
  16821.                    row for a given host while connection to the MySQL
  16822.                    server, MySQL assumes something is wrong and blocks
  16823.                    the host from further connection requests.  Flushing
  16824.                    the host tables allows the host to attempt to connect
  16825.                    again. *Note Blocked host::. You can start `mysqld'
  16826.                    with `-O max_connect_errors=999999999' to avoid this
  16827.                    error message.
  16828. `DES_KEY_FILE'     Reloads the DES keys from the file that was specified
  16829.                    with the `--des-key-file' option at server startup
  16830.                    time.
  16831. `LOGS'             Closes and reopens all log files.  If you have
  16832.                    specified the update log file or a binary log file
  16833.                    without an extension, the extension number of the log
  16834.                    file will be incremented by one relative to the
  16835.                    previous file.  If you have used an extension in the
  16836.                    file name, MySQL will close and reopen the update log
  16837.                    file.  *Note Update log::. This is the same thing as
  16838.                    sending the `SIGHUP' signal to the `mysqld' server.
  16839. `PRIVILEGES'       Reloads the privileges from the grant tables in the
  16840.                    `mysql' database.
  16841. `QUERY CACHE'      Defragment the query cache to better utilise its
  16842.                    memory.  This command will not remove any queries
  16843.                    from the cache, unlike `RESET QUERY CACHE'.
  16844. `TABLES'           Closes all open tables and force all tables in use to
  16845.                    be closed. This also flushes the query cache.
  16846. `[TABLE | TABLES]  Flushes only the given tables.
  16847. tbl_name           
  16848. [,tbl_name...]'    
  16849. `TABLES WITH READ  Closes all open tables and locks all tables for all
  16850. LOCK'              databases with a read lock until you execute `UNLOCK
  16851.                    TABLES'. This is very convenient way to get backups
  16852.                    if you have a filesystem, like Veritas, that can take
  16853.                    snapshots in time.
  16854. `STATUS'           Resets most status variables to zero. This is
  16855.                    something one should only use when debugging a query.
  16856. `USER_RESOURCES'   Resets all user resources to zero. This will enable
  16857.                    blocked users to login again. *Note User resources::.
  16858.  
  16859. You can also access each of the commands shown above with the
  16860. `mysqladmin' utility, using the `flush-hosts', `flush-logs', `reload',
  16861. or `flush-tables' commands.
  16862.  
  16863. Take also a look at the `RESET' command used with replication.  *Note
  16864. `RESET': RESET.
  16865.  
  16866. `RESET' Syntax
  16867. --------------
  16868.  
  16869.      RESET reset_option [,reset_option] ...
  16870.  
  16871. The `RESET' command is used to clear things. It also acts as an stronger
  16872. version of the `FLUSH' command.  *Note `FLUSH': FLUSH.
  16873.  
  16874. To execute `RESET', you must have the `RELOAD' privilege.
  16875.  
  16876. *Option*           *Description*
  16877. `MASTER'           Deletes all binary logs listed in the index file,
  16878.                    resetting the binlog index file to be empty. In
  16879.                    pre-3.23.26 versions, `FLUSH MASTER' (Master)
  16880. `SLAVE'            Makes the slave forget its replication position in
  16881.                    the master logs. In pre 3.23.26 versions the command
  16882.                    was called `FLUSH SLAVE'(Slave)
  16883. `QUERY CACHE'      Removes all query results from the query cache.
  16884.  
  16885. `KILL' Syntax
  16886. -------------
  16887.  
  16888.      KILL thread_id
  16889.  
  16890. Each connection to `mysqld' runs in a separate thread.  You can see
  16891. which threads are running with the `SHOW PROCESSLIST' command and kill
  16892. a thread with the `KILL thread_id' command.
  16893.  
  16894. If you have the `PROCESS' privilege, you can see all threads.  If you
  16895. have the `SUPER' privilege, you can kill all threads.  Otherwise, you
  16896. can only see and kill your own threads.
  16897.  
  16898. You can also use the `mysqladmin processlist' and `mysqladmin kill'
  16899. commands to examine and kill threads.
  16900.  
  16901. When you do a `KILL', a thread-specific `kill flag' is set for the
  16902. thread.
  16903.  
  16904. In most cases it may take some time for the thread to die as the kill
  16905. flag is only checked at specific intervals.
  16906.  
  16907.    * In `SELECT', `ORDER BY' and `GROUP BY' loops, the flag is checked
  16908.      after reading a block of rows. If the kill flag is set the
  16909.      statement is aborted
  16910.  
  16911.    * When doing an `ALTER TABLE' the kill flag is checked before each
  16912.      block of rows are read from the original table. If the kill flag
  16913.      was set the command is aborted and the temporary table is deleted.
  16914.  
  16915.    * When doing an `UPDATE TABLE' and `DELETE TABLE', the kill flag is
  16916.      checked after each block read and after each updated or delete
  16917.      row. If the kill flag is set the statement is aborted.  Note that
  16918.      if you are not using transactions, the changes will not be rolled
  16919.      back!
  16920.  
  16921.    * `GET_LOCK()' will abort with `NULL'.
  16922.  
  16923.    * An `INSERT DELAYED' thread will quickly flush all rows it has in
  16924.      memory and die.
  16925.  
  16926.    * If the thread is in the table lock handler (state: `Locked'), the
  16927.      table lock will be quickly aborted.
  16928.  
  16929.    * If the thread is waiting for free disk space in a `write' call, the
  16930.      write is aborted with an disk full error message.
  16931.  
  16932. `SHOW' Syntax
  16933. -------------
  16934.  
  16935.         SHOW DATABASES [LIKE wild]
  16936.      or SHOW [OPEN] TABLES [FROM db_name] [LIKE wild]
  16937.      or SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
  16938.      or SHOW INDEX FROM tbl_name [FROM db_name]
  16939.      or SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  16940.      or SHOW STATUS [LIKE wild]
  16941.      or SHOW VARIABLES [LIKE wild]
  16942.      or SHOW LOGS
  16943.      or SHOW [FULL] PROCESSLIST
  16944.      or SHOW GRANTS FOR user
  16945.      or SHOW CREATE TABLE table_name
  16946.      or SHOW MASTER STATUS
  16947.      or SHOW MASTER LOGS
  16948.      or SHOW SLAVE STATUS
  16949.      or SHOW WARNINGS [LIMIT #]
  16950.      or SHOW ERRORS [LIMIT #]
  16951.  
  16952. `SHOW' provides information about databases, tables, columns, or status
  16953. information about the server. If the `LIKE wild' part is used, the
  16954. `wild' string can be a string that uses the SQL `%' and `_' wildcard
  16955. characters.
  16956.  
  16957. Retrieving information about Database, Tables, Columns, and Indexes
  16958. ...................................................................
  16959.  
  16960. You can use `db_name.tbl_name' as an alternative to the `tbl_name FROM
  16961. db_name' syntax.  These two statements are equivalent:
  16962.  
  16963.      mysql> SHOW INDEX FROM mytable FROM mydb;
  16964.      mysql> SHOW INDEX FROM mydb.mytable;
  16965.  
  16966. `SHOW DATABASES' lists the databases on the MySQL server host.  You can
  16967. also get this list using the `mysqlshow' command line tool.  In version
  16968. 4.0.2 you will only see those databases for which you have some kind of
  16969. privilege, if you don't have the global `SHOW DATABASES' privilege.
  16970.  
  16971. `SHOW TABLES' lists the tables in a given database.  You can also get
  16972. this list using the `mysqlshow db_name' command.
  16973.  
  16974. *Note*: if a user doesn't have any privileges for a table, the table
  16975. will not show up in the output from `SHOW TABLES' or `mysqlshow
  16976. db_name'.
  16977.  
  16978. `SHOW OPEN TABLES' lists the tables that are currently open in the
  16979. table cache. *Note Table cache::.  The `Comment' field tells how many
  16980. times the table is `cached' and `in_use'.
  16981.  
  16982. `SHOW COLUMNS' lists the columns in a given table.  If you specify the
  16983. `FULL' option, you will also get the privileges you have for each
  16984. column.  If the column types are different from what you expect them to
  16985. be based on a `CREATE TABLE' statement, note that MySQL sometimes
  16986. changes column types.  *Note Silent column changes::.
  16987.  
  16988. The `DESCRIBE' statement provides information similar to `SHOW COLUMNS'.
  16989. *Note `DESCRIBE': DESCRIBE.
  16990.  
  16991. `SHOW FIELDS' is a synonym for `SHOW COLUMNS', and `SHOW KEYS' is a
  16992. synonym for `SHOW INDEX'.  You can also list a table's columns or
  16993. indexes with `mysqlshow db_name tbl_name' or `mysqlshow -k db_name
  16994. tbl_name'.
  16995.  
  16996. `SHOW INDEX' returns the index information in a format that closely
  16997. resembles the `SQLStatistics' call in ODBC. The following columns are
  16998. returned:
  16999.  
  17000. *Column*    *Meaning*
  17001. `Table'     Name of the table.
  17002. `Non_unique'0 if the index can't contain duplicates.
  17003. `Key_name'  Name of the index.
  17004. `Seq_in_index'Column sequence number in index,
  17005.                                           starting
  17006.             with 1.
  17007. `Column_name'Column name.
  17008. `Collation' How the column is sorted in the index.
  17009.             In MySQL, this can have values
  17010.                                         `A'
  17011.             (Ascending) or `NULL' (Not
  17012.                                     sorted).
  17013. `Cardinality'Number of unique values in the index.
  17014.             This is updated by running
  17015.                                     `isamchk -a'.
  17016. `Sub_part'  Number of indexed characters if the
  17017.             column is only partly indexed.
  17018.                                          `NULL' if
  17019.             the entire key is indexed.
  17020. `Null'      Contains 'YES' if the column may
  17021.             contain `NULL'.
  17022. `Index_type'Index method used.
  17023. `Comment'   Various remarks.  For now, it tells in
  17024.             MySQL < 4.0.2 whether index is
  17025.             `FULLTEXT' or not.
  17026.  
  17027. Note that as the `Cardinality' is counted based on statistics stored as
  17028. integers, it's not necessarily accurate for small tables.
  17029.  
  17030. The `Null' and `Index_type' columns were added in MySQL 4.0.2.
  17031.  
  17032. `SHOW TABLE STATUS'
  17033. ...................
  17034.  
  17035.      SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  17036.  
  17037. `SHOW TABLE STATUS' (new in Version 3.23) works likes `SHOW STATUS',
  17038. but provides a lot of information about each table. You can also get
  17039. this list using the `mysqlshow --status db_name' command.  The
  17040. following columns are returned:
  17041.  
  17042. *Column*       *Meaning*
  17043. `Name'         Name of the table.
  17044. `Type'         Type of table. *Note Table types::.
  17045. `Row_format'   The row storage format (Fixed, Dynamic, or
  17046.                Compressed).
  17047. `Rows'         Number of rows.
  17048. `Avg_row_length'Average row length.
  17049. `Data_length'  Length of the datafile.
  17050. `Max_data_length'Max length of the datafile.
  17051. `Index_length' Length of the index file.
  17052. `Data_free'    Number of allocated but not used bytes.
  17053. `Auto_increment'Next autoincrement value.
  17054. `Create_time'  When the table was created.
  17055. `Update_time'  When the datafile was last updated.
  17056. `Check_time'   When the table was last checked.
  17057. `Create_options'Extra options used with `CREATE TABLE'.
  17058. `Comment'      The comment used when creating the table (or some
  17059.                information why MySQL couldn't access the table
  17060.                information).
  17061.  
  17062. `InnoDB' tables will report the free space in the tablespace in the
  17063. table comment.
  17064.  
  17065. `SHOW STATUS'
  17066. .............
  17067.  
  17068. `SHOW STATUS' provides server status information (like `mysqladmin
  17069. extended-status'). The output resembles that shown here, though the
  17070. format and numbers probably differ:
  17071.  
  17072.      +--------------------------+------------+
  17073.      | Variable_name            | Value      |
  17074.      +--------------------------+------------+
  17075.      | Aborted_clients          | 0          |
  17076.      | Aborted_connects         | 0          |
  17077.      | Bytes_received           | 155372598  |
  17078.      | Bytes_sent               | 1176560426 |
  17079.      | Connections              | 30023      |
  17080.      | Created_tmp_disk_tables  | 0          |
  17081.      | Created_tmp_tables       | 8340       |
  17082.      | Created_tmp_files        | 60         |
  17083.      | Delayed_insert_threads   | 0          |
  17084.      | Delayed_writes           | 0          |
  17085.      | Delayed_errors           | 0          |
  17086.      | Flush_commands           | 1          |
  17087.      | Handler_delete           | 462604     |
  17088.      | Handler_read_first       | 105881     |
  17089.      | Handler_read_key         | 27820558   |
  17090.      | Handler_read_next        | 390681754  |
  17091.      | Handler_read_prev        | 6022500    |
  17092.      | Handler_read_rnd         | 30546748   |
  17093.      | Handler_read_rnd_next    | 246216530  |
  17094.      | Handler_update           | 16945404   |
  17095.      | Handler_write            | 60356676   |
  17096.      | Key_blocks_used          | 14955      |
  17097.      | Key_read_requests        | 96854827   |
  17098.      | Key_reads                | 162040     |
  17099.      | Key_write_requests       | 7589728    |
  17100.      | Key_writes               | 3813196    |
  17101.      | Max_used_connections     | 0          |
  17102.      | Not_flushed_key_blocks   | 0          |
  17103.      | Not_flushed_delayed_rows | 0          |
  17104.      | Open_tables              | 1          |
  17105.      | Open_files               | 2          |
  17106.      | Open_streams             | 0          |
  17107.      | Opened_tables            | 44600      |
  17108.      | Questions                | 2026873    |
  17109.      | Select_full_join         | 0          |
  17110.      | Select_full_range_join   | 0          |
  17111.      | Select_range             | 99646      |
  17112.      | Select_range_check       | 0          |
  17113.      | Select_scan              | 30802      |
  17114.      | Slave_running            | OFF        |
  17115.      | Slave_open_temp_tables   | 0          |
  17116.      | Slow_launch_threads      | 0          |
  17117.      | Slow_queries             | 0          |
  17118.      | Sort_merge_passes        | 30         |
  17119.      | Sort_range               | 500        |
  17120.      | Sort_rows                | 30296250   |
  17121.      | Sort_scan                | 4650       |
  17122.      | Table_locks_immediate    | 1920382    |
  17123.      | Table_locks_waited       | 0          |
  17124.      | Threads_cached           | 0          |
  17125.      | Threads_created          | 30022      |
  17126.      | Threads_connected        | 1          |
  17127.      | Threads_running          | 1          |
  17128.      | Uptime                   | 80380      |
  17129.      +--------------------------+------------+
  17130.  
  17131. The status variables listed above have the following meaning:
  17132.  
  17133. *Variable*             *Meaning*
  17134. `Aborted_clients'      Number of connections aborted because the client
  17135.                        died without closing the connection properly.
  17136.                        *Note Communication errors::.
  17137. `Aborted_connects'     Number of tries to connect to the MySQL server
  17138.                        that failed. *Note Communication errors::.
  17139. `Bytes_received'       Number of bytes received from all clients.
  17140. `Bytes_sent'           Number of bytes sent to all clients.
  17141. `Com_xxx'              Number of times each xxx command has been
  17142.                        executed.
  17143. `Connections'          Number of connection attempts to the MySQL server.
  17144. `Created_tmp_disk_tables'Number of implicit temporary tables on disk
  17145.                        created while executing statements.
  17146. `Created_tmp_tables'   Number of implicit temporary tables in memory
  17147.                        created while executing statements.
  17148. `Created_tmp_files'    How many temporary files `mysqld' has created.
  17149. `Delayed_insert_threads'Number of delayed insert handler threads in use.
  17150. `Delayed_writes'       Number of rows written with `INSERT DELAYED'.
  17151. `Delayed_errors'       Number of rows written with `INSERT DELAYED' for
  17152.                        which some error occurred (probably `duplicate
  17153.                        key').
  17154. `Flush_commands'       Number of executed `FLUSH' commands.
  17155. `Handler_commit'       Number of internal `COMMIT' commands.
  17156. `Handler_delete'       Number of times a row was deleted from a table.
  17157. `Handler_read_first'   Number of times the first entry was read from an
  17158.                        index.  If this is high, it suggests that the
  17159.                        server is doing a lot of full index scans, for
  17160.                        example, `SELECT col1 FROM foo', assuming that
  17161.                        col1 is indexed.
  17162. `Handler_read_key'     Number of requests to read a row based on a key.
  17163.                        If this is high, it is a good indication that
  17164.                        your queries and tables are properly indexed.
  17165. `Handler_read_next'    Number of requests to read next row in key order.
  17166.                        This will be incremented if you are querying an
  17167.                        index column with a range constraint. This also
  17168.                        will be incremented if you are doing an index
  17169.                        scan.
  17170. `Handler_read_prev'    Number of requests to read previous row in key
  17171.                        order.  This is mainly used to optimise `ORDER BY
  17172.                        ... DESC'.
  17173. `Handler_read_rnd'     Number of requests to read a row based on a fixed
  17174.                        position.  This will be high if you are doing a
  17175.                        lot of queries that require sorting of the result.
  17176. `Handler_read_rnd_next'Number of requests to read the next row in the
  17177.                        datafile.  This will be high if you are doing a
  17178.                        lot of table scans. Generally this suggests that
  17179.                        your tables are not properly indexed or that your
  17180.                        queries are not written to take advantage of the
  17181.                        indexes you have.
  17182. `Handler_rollback'     Number of internal `ROLLBACK' commands.
  17183. `Handler_update'       Number of requests to update a row in a table.
  17184. `Handler_write'        Number of requests to insert a row in a table.
  17185. `Key_blocks_used'      The number of used blocks in the key cache.
  17186. `Key_read_requests'    The number of requests to read a key block from
  17187.                        the cache.
  17188. `Key_reads'            The number of physical reads of a key block from
  17189.                        disk.
  17190. `Key_write_requests'   The number of requests to write a key block to
  17191.                        the cache.
  17192. `Key_writes'           The number of physical writes of a key block to
  17193.                        disk.
  17194. `Max_used_connections' The maximum number of connections in use
  17195.                        simultaneously.
  17196. `Not_flushed_key_blocks'Keys blocks in the key cache that has changed but
  17197.                        hasn't yet been flushed to disk.
  17198. `Not_flushed_delayed_rows'Number of rows waiting to be written in `INSERT
  17199.                        DELAY' queues.
  17200. `Open_tables'          Number of tables that are open.
  17201. `Open_files'           Number of files that are open.
  17202. `Open_streams'         Number of streams that are open (used mainly for
  17203.                        logging).
  17204. `Opened_tables'        Number of tables that have been opened.
  17205. `Rpl_status'           Status of failsafe replication. (Not yet in use).
  17206. `Select_full_join'     Number of joins without keys (If this is 0, you
  17207.                        should carefully check the index of your tables).
  17208. `Select_full_range_join'Number of joins where we used a range search on
  17209.                        reference table.
  17210. `Select_range'         Number of joins where we used ranges on the first
  17211.                        table. (It's normally not critical even if this
  17212.                        is big.)
  17213. `Select_scan'          Number of joins where we did a full scan of the
  17214.                        first table.
  17215. `Select_range_check'   Number of joins without keys where we check for
  17216.                        key usage after each row (If this is 0, you
  17217.                        should carefully check the index of your tables).
  17218. `Questions'            Number of queries sent to the server.
  17219. `Slave_open_temp_tables'Number of temporary tables currently open by the
  17220.                        slave thread
  17221. `Slave_running'        Is `ON' if this is a slave that is connected to a
  17222.                        master.
  17223. `Slow_launch_threads'  Number of threads that have taken more than
  17224.                        `slow_launch_time' to create.
  17225. `Slow_queries'         Number of queries that have taken more than
  17226.                        `long_query_time'. *Note Slow query log::.
  17227. `Sort_merge_passes'    Number of merges passes the sort algoritm have
  17228.                        had to do. If this value is large you should
  17229.                        consider increasing `sort_buffer'.
  17230. `Sort_range'           Number of sorts that where done with ranges.
  17231. `Sort_rows'            Number of sorted rows.
  17232. `Sort_scan'            Number of sorts that where done by scanning the
  17233.                        table.
  17234. `ssl_xxx'              Variables used by SSL; Not yet implemented.
  17235. `Table_locks_immediate'Number of times a table lock was acquired
  17236.                        immediately. Available after 3.23.33.
  17237. `Table_locks_waited'   Number of times a table lock could not be
  17238.                        acquired immediately and a wait was needed. If
  17239.                        this is high, and you have performance problems,
  17240.                        you should first optimise your queries, and then
  17241.                        either split your table(s) or use replication.
  17242.                        Available after 3.23.33.
  17243. `Threads_cached'       Number of threads in the thread cache.
  17244. `Threads_connected'    Number of currently open connections.
  17245. `Threads_created'      Number of threads created to handle connections.
  17246. `Threads_running'      Number of threads that are not sleeping.
  17247. `Uptime'               How many seconds the server has been up.
  17248.  
  17249. Some comments about the above:
  17250.  
  17251.    * If `Opened_tables' is big, then your `table_cache' variable is
  17252.      probably too small.
  17253.  
  17254.    * If `Key_reads' is big, then your `key_buffer_size' variable is
  17255.      probably too small.  The cache hit rate can be calculated with
  17256.      `Key_reads'/`Key_read_requests'.
  17257.  
  17258.    * If `Handler_read_rnd' is big, then you probably have a lot of
  17259.      queries that require MySQL to scan whole tables or you have joins
  17260.      that don't use keys properly.
  17261.  
  17262.    * If `Threads_created' is big, you may want to increase the
  17263.      `thread_cache_size' variable.  The cache hit rate can be calculated
  17264.      with `Threads_created'/`Connections'.
  17265.  
  17266.    * If `Created_tmp_disk_tables' is big, you may want to increase the
  17267.      `tmp_table_size' variable to get the temporary tables memory-based
  17268.      instead of disk based.
  17269.  
  17270. `SHOW VARIABLES'
  17271. ................
  17272.  
  17273.      SHOW [GLOBAL | SESSION] VARIABLES [LIKE wild]
  17274.  
  17275. `SHOW VARIABLES' shows the values of some MySQL system variables.  You
  17276. can also get this information using the `mysqladmin variables' command.
  17277. If the default values are unsuitable, you can set most of these
  17278. variables using command-line options when `mysqld' starts up.  *Note
  17279. Command-line options::.
  17280.  
  17281. The options `GLOBAL' and `SESSION' are new in MySQL 4.0.3.  With
  17282. `GLOBAL' you will get the variables that will be used for new
  17283. connections to MySQL. With `SESSION' you will get the values that are
  17284. in effect for the current connection. If you are not using either
  17285. option, `SESSION' is used.
  17286.  
  17287. You can change most options with the  `SET' command.  *Note `SET': SET
  17288. OPTION.
  17289.  
  17290. The output resembles that shown here, though the format and numbers may
  17291. differ somewhat:
  17292.  
  17293.      +---------------------------------+------------------------------+
  17294.      | Variable_name                   | Value                        |
  17295.      +---------------------------------+------------------------------|
  17296.      | back_log                        | 50                           |
  17297.      | basedir                         | /usr/local/mysql             |
  17298.      | bdb_cache_size                  | 8388572                      |
  17299.      | bdb_log_buffer_size             | 32768                        |
  17300.      | bdb_home                        | /usr/local/mysql             |
  17301.      | bdb_max_lock                    | 10000                        |
  17302.      | bdb_logdir                      |                              |
  17303.      | bdb_shared_data                 | OFF                          |
  17304.      | bdb_tmpdir                      | /tmp/                        |
  17305.      | bdb_version                     | Sleepycat Software: ...     |
  17306.      | binlog_cache_size               | 32768                        |
  17307.      | bulk_insert_buffer_size         | 8388608                      |
  17308.      | character_set                   | latin1                       |
  17309.      | character_sets                  | latin1 big5 czech euc_kr     |
  17310.      | concurrent_insert               | ON                           |
  17311.      | connect_timeout                 | 5                            |
  17312.      | convert_character_set           |                              |
  17313.      | datadir                         | /usr/local/mysql/data/       |
  17314.      | delay_key_write                 | ON                           |
  17315.      | delayed_insert_limit            | 100                          |
  17316.      | delayed_insert_timeout          | 300                          |
  17317.      | delayed_queue_size              | 1000                         |
  17318.      | flush                           | OFF                          |
  17319.      | flush_time                      | 0                            |
  17320.      | ft_min_word_len                 | 4                            |
  17321.      | ft_max_word_len                 | 254                          |
  17322.      | ft_max_word_len_for_sort        | 20                           |
  17323.      | ft_boolean_syntax               | + -><()~*:""&|               |
  17324.      | have_bdb                        | YES                          |
  17325.      | have_innodb                     | YES                          |
  17326.      | have_isam                       | YES                          |
  17327.      | have_raid                       | NO                           |
  17328.      | have_symlink                    | DISABLED                     |
  17329.      | have_openssl                    | YES                          |
  17330.      | have_query_cache                | YES                          |
  17331.      | init_file                       |                              |
  17332.      | innodb_additional_mem_pool_size | 1048576                      |
  17333.      | innodb_buffer_pool_size         | 8388608                      |
  17334.      | innodb_data_file_path           | ibdata1:10M:autoextend       |
  17335.      | innodb_data_home_dir            |                              |
  17336.      | innodb_file_io_threads          | 4                            |
  17337.      | innodb_force_recovery           | 0                            |
  17338.      | innodb_thread_concurrency       | 8                            |
  17339.      | innodb_flush_log_at_trx_commit  | 0                            |
  17340.      | innodb_fast_shutdown            | ON                           |
  17341.      | innodb_flush_method             |                              |
  17342.      | innodb_lock_wait_timeout        | 50                           |
  17343.      | innodb_log_arch_dir             |                              |
  17344.      | innodb_log_archive              | OFF                          |
  17345.      | innodb_log_buffer_size          | 1048576                      |
  17346.      | innodb_log_file_size            | 5242880                      |
  17347.      | innodb_log_files_in_group       | 2                            |
  17348.      | innodb_log_group_home_dir       | ./                           |
  17349.      | innodb_mirrored_log_groups      | 1                            |
  17350.      | interactive_timeout             | 28800                        |
  17351.      | join_buffer_size                | 131072                       |
  17352.      | key_buffer_size                 | 16773120                     |
  17353.      | language                        | /usr/local/mysql/share/...   |
  17354.      | large_files_support             | ON                           |
  17355.      | local_infile                    | ON                           |
  17356.      | locked_in_memory                | OFF                          |
  17357.      | log                             | OFF                          |
  17358.      | log_update                      | OFF                          |
  17359.      | log_bin                         | OFF                          |
  17360.      | log_slave_updates               | OFF                          |
  17361.      | log_slow_queries                | OFF                          |
  17362.      | log_warnings                    | OFF                          |
  17363.      | long_query_time                 | 10                           |
  17364.      | low_priority_updates            | OFF                          |
  17365.      | lower_case_table_names          | OFF                          |
  17366.      | max_allowed_packet              | 1047552                      |
  17367.      | max_binlog_cache_size           | 4294967295                   |
  17368.      | max_binlog_size                 | 1073741824                   |
  17369.      | max_connections                 | 100                          |
  17370.      | max_connect_errors              | 10                           |
  17371.      | max_delayed_threads             | 20                           |
  17372.      | max_heap_table_size             | 16777216                     |
  17373.      | max_join_size                   | 4294967295                   |
  17374.      | max_sort_length                 | 1024                         |
  17375.      | max_user_connections            | 0                            |
  17376.      | max_tmp_tables                  | 32                           |
  17377.      | max_write_lock_count            | 4294967295                   |
  17378.      | myisam_max_extra_sort_file_size | 268435456                    |
  17379.      | myisam_max_sort_file_size       | 2147483647                   |
  17380.      | myisam_recover_options          | force                        |
  17381.      | myisam_sort_buffer_size         | 8388608                      |
  17382.      | net_buffer_length               | 16384                        |
  17383.      | net_read_timeout                | 30                           |
  17384.      | net_retry_count                 | 10                           |
  17385.      | net_write_timeout               | 60                           |
  17386.      | open_files_limit                | 0                            |
  17387.      | pid_file                        | /usr/local/mysql/name.pid    |
  17388.      | port                            | 3306                         |
  17389.      | protocol_version                | 10                           |
  17390.      | read_buffer_size                | 131072                       |
  17391.      | read_rnd_buffer_size            | 262144                       |
  17392.      | rpl_recovery_rank               | 0                            |
  17393.      | query_cache_limit               | 1048576                      |
  17394.      | query_cache_size                | 0                            |
  17395.      | query_cache_type                | ON                           |
  17396.      | safe_show_database              | OFF                          |
  17397.      | server_id                       | 0                            |
  17398.      | slave_net_timeout               | 3600                         |
  17399.      | skip_external_locking           | ON                           |
  17400.      | skip_networking                 | OFF                          |
  17401.      | skip_show_database              | OFF                          |
  17402.      | slow_launch_time                | 2                            |
  17403.      | socket                          | /tmp/mysql.sock              |
  17404.      | sort_buffer_size                | 2097116                      |
  17405.      | sql_mode                        | 0                            |
  17406.      | table_cache                     | 64                           |
  17407.      | table_type                      | MYISAM                       |
  17408.      | thread_cache_size               | 3                            |
  17409.      | thread_stack                    | 131072                       |
  17410.      | tx_isolation                    | READ-COMMITTED               |
  17411.      | timezone                        | EEST                         |
  17412.      | tmp_table_size                  | 33554432                     |
  17413.      | tmpdir                          | /tmp/                        |
  17414.      | version                         | 4.0.4-beta                   |
  17415.      | wait_timeout                    | 28800                        |
  17416.      +---------------------------------+------------------------------+
  17417.  
  17418. Each option is described here. Values for buffer sizes, lengths, and
  17419. stack sizes are given in bytes.  You can specify values with a suffix
  17420. of `K' or `M' to indicate kilobytes or megabytes. For example, `16M'
  17421. indicates 16 megabytes.  The case of suffix letters does not matter;
  17422. `16M' and `16m' are equivalent:
  17423.  
  17424.    * `ansi_mode'.  Is `ON' if `mysqld' was started with `--ansi'.
  17425.      *Note ANSI mode::.
  17426.  
  17427.    * `back_log' The number of outstanding connection requests MySQL can
  17428.      have. This comes into play when the main MySQL thread gets *very*
  17429.      many connection requests in a very short time. It then takes some
  17430.      time (although very little) for the main thread to check the
  17431.      connection and start a new thread. The `back_log' value indicates
  17432.      how many requests can be stacked during this short time before
  17433.      MySQL momentarily stops answering new requests. You need to
  17434.      increase this only if you expect a large number of connections in
  17435.      a short period of time.
  17436.  
  17437.      In other words, this value is the size of the listen queue for
  17438.      incoming TCP/IP connections.  Your operating system has its own
  17439.      limit on the size of this queue.  The manual page for the Unix
  17440.      `listen(2)' system call should have more details.  Check your OS
  17441.      documentation for the maximum value for this variable.  Attempting
  17442.      to set `back_log' higher than your operating system limit will be
  17443.      ineffective.
  17444.  
  17445.    * `basedir' The value of the `--basedir' option.
  17446.  
  17447.    * `bdb_cache_size' The buffer that is allocated to cache index and
  17448.      rows for `BDB' tables.  If you don't use `BDB' tables, you should
  17449.      start `mysqld' with `--skip-bdb' to not waste memory for this
  17450.      cache.
  17451.  
  17452.    * `bdb_log_buffer_size' The buffer that is allocated to cache index
  17453.      and rows for `BDB' tables.  If you don't use `BDB' tables, you
  17454.      should set this to 0 or start `mysqld' with `--skip-bdb' to not
  17455.      waste memory for this cache.
  17456.  
  17457.    * `bdb_home' The value of the `--bdb-home' option.
  17458.  
  17459.    * `bdb_max_lock' The maximum number of locks (10,000 by default) you
  17460.      can have active on a BDB table. You should increase this if you
  17461.      get errors of type `bdb: Lock table is out of available locks' or
  17462.      `Got error 12 from ...' when you have do long transactions or when
  17463.      `mysqld' has to examine a lot of rows to calculate the query.
  17464.  
  17465.    * `bdb_logdir' The value of the `--bdb-logdir' option.
  17466.  
  17467.    * `bdb_shared_data' Is `ON' if you are using `--bdb-shared-data'.
  17468.  
  17469.    * `bdb_tmpdir' The value of the `--bdb-tmpdir' option.
  17470.  
  17471.    * `binlog_cache_size'.  The size of the cache to hold the SQL
  17472.      statements for the binary log during a transaction.  If you often
  17473.      use big, multi-statement transactions you can increase this to get
  17474.      more performance. *Note COMMIT::.
  17475.  
  17476.    * `bulk_insert_buffer_size' (was `myisam_bulk_insert_tree_size')
  17477.      MyISAM uses special tree-like cache to make bulk inserts (that is,
  17478.      `INSERT ... SELECT', `INSERT ... VALUES (...), (...), ...', and
  17479.      `LOAD DATA INFILE') faster. This variable limits the size of the
  17480.      cache tree in bytes per thread. Setting it to 0 will disable this
  17481.      optimisation.  *Note*: this cache is only used when adding data to
  17482.      non-empty table.  Default value is 8 MB.
  17483.  
  17484.    * `character_set' The default character set.
  17485.  
  17486.    * `character_sets' The supported character sets.
  17487.  
  17488.    * `concurrent_inserts' If `ON' (the default), MySQL will allow you
  17489.      to use `INSERT' on `MyISAM' tables at the same time as you run
  17490.      `SELECT' queries on them.  You can turn this option off by
  17491.      starting `mysqld' with `--safe' or `--skip-new'.
  17492.  
  17493.    * `connect_timeout' The number of seconds the `mysqld' server is
  17494.      waiting for a connect packet before responding with `Bad
  17495.      handshake'.
  17496.  
  17497.    * `datadir' The value of the `--datadir' option.
  17498.  
  17499.    * `delay_key_write' Option for MyISAM tables. Can have one of the
  17500.      following values:
  17501.  
  17502.      OFF                  All CREATE TABLE ... DELAYED_KEY_WRITES are
  17503.                           ignored.
  17504.      ON                   (default)  MySQL will honor the
  17505.                           `DELAY_KEY_WRITE' option for `CREATE TABLE'.
  17506.      ALL                  All new opened tables are treated as if they
  17507.                           were created with the `DELAY_KEY_WRITE' option.
  17508.  
  17509.      If `DELAY_KEY_WRITE' is enabled this means that the key buffer for
  17510.      tables with this option will not get flushed on every index
  17511.      update, but only when a table is closed.  This will speed up
  17512.      writes on keys a lot, but you should add automatic checking of all
  17513.      tables with `myisamchk --fast --force' if you use this.
  17514.  
  17515.    * `delayed_insert_limit' After inserting `delayed_insert_limit'
  17516.      rows, the `INSERT DELAYED' handler will check if there are any
  17517.      `SELECT' statements pending. If so, it allows these to execute
  17518.      before continuing.
  17519.  
  17520.    * `delayed_insert_timeout' How long a `INSERT DELAYED' thread should
  17521.      wait for `INSERT' statements before terminating.
  17522.  
  17523.    * `delayed_queue_size' What size queue (in rows) should be allocated
  17524.      for handling `INSERT DELAYED'.  If the queue becomes full, any
  17525.      client that does `INSERT DELAYED' will wait until there is room in
  17526.      the queue again.
  17527.  
  17528.    * `flush' This is `ON' if you have started MySQL with the `--flush'
  17529.      option.
  17530.  
  17531.    * `flush_time' If this is set to a non-zero value, then every
  17532.      `flush_time' seconds all tables will be closed (to free up
  17533.      resources and sync things to disk). We only recommend this option
  17534.      on Windows 9x/Me, or on systems where you have very little
  17535.      resources.
  17536.  
  17537.    * `ft_min_word_len' The minimum length of the word to be included in
  17538.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  17539.      after changing this variable.* (This option is new for MySQL 4.0.)
  17540.  
  17541.    * `ft_max_word_len' The maximum length of the word to be included in
  17542.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  17543.      after changing this variable.* (This option is new for MySQL 4.0.)
  17544.  
  17545.    * `ft_max_word_len_for_sort' The maximum length of the word in a
  17546.      `FULLTEXT' index to be used in fast index recreation method in
  17547.      `REPAIR', `CREATE INDEX',  or `ALTER TABLE'.  Longer words are
  17548.      inserted the slow way.  The rule of the thumb is as follows: with
  17549.      `ft_max_word_len_for_sort' increasing, *MySQL* will create bigger
  17550.      temporary files (thus slowing the process down, due to disk I/O),
  17551.      and will put fewer keys in one sort block (again, decreasing the
  17552.      efficiency).  When `ft_max_word_len_for_sort' is too small,
  17553.      instead, *MySQL* will insert a lot of words into index the slow
  17554.      way, but short words will be inserted very quickly.
  17555.  
  17556.    * `ft_boolean_syntax' List of operators supported by `MATCH ...
  17557.      AGAINST(... IN BOOLEAN MODE)'.  *Note Fulltext Search::.
  17558.  
  17559.    * `have_innodb' `YES' if `mysqld' supports InnoDB tables. `DISABLED'
  17560.      if `--skip-innodb' is used.
  17561.  
  17562.    * `have_bdb' `YES' if `mysqld' supports Berkeley DB tables.
  17563.      `DISABLED' if `--skip-bdb' is used.
  17564.  
  17565.    * `have_raid' `YES' if `mysqld' supports the `RAID' option.
  17566.  
  17567.    * `have_openssl' `YES' if `mysqld' supports SSL (encryption) on the
  17568.      client/server protocol.
  17569.  
  17570.    * `init_file' The name of the file specified with the `--init-file'
  17571.      option when you start the server.  This is a file of SQL
  17572.      statements you want the server to execute when it starts.
  17573.  
  17574.    * `interactive_timeout' The number of seconds the server waits for
  17575.      activity on an interactive connection before closing it.  An
  17576.      interactive client is defined as a client that uses the
  17577.      `CLIENT_INTERACTIVE' option to `mysql_real_connect()'.  See also
  17578.      `wait_timeout'.
  17579.  
  17580.    * `join_buffer_size' The size of the buffer that is used for full
  17581.      joins (joins that do not use indexes).  The buffer is allocated
  17582.      one time for each full join between two tables. Increase this
  17583.      value to get a faster full join when adding indexes is not
  17584.      possible. (Normally the best way to get fast joins is to add
  17585.      indexes.)
  17586.  
  17587.    * `key_buffer_size' Index blocks are buffered and are shared by all
  17588.      threads.  `key_buffer_size' is the size of the buffer used for
  17589.      index blocks.
  17590.  
  17591.      Increase this to get better index handling (for all reads and
  17592.      multiple writes) to as much as you can afford; 64M on a 256M
  17593.      machine that mainly runs MySQL is quite common.  If you, however,
  17594.      make this too big (for instance more than 50% of your total
  17595.      memory) your system may start to page and become extremely slow.
  17596.      Remember that because MySQL does not cache data reads, you will
  17597.      have to leave some room for the OS filesystem cache.
  17598.  
  17599.      You can check the performance of the key buffer by doing `SHOW
  17600.      STATUS' and examine the variables `Key_read_requests',
  17601.      `Key_reads', `Key_write_requests', and `Key_writes'.  The
  17602.      `Key_reads/Key_read_request' ratio should normally be < 0.01.  The
  17603.      `Key_write/Key_write_requests' is usually near 1 if you are using
  17604.      mostly updates/deletes but may be much smaller if you tend to do
  17605.      updates that affect many at the same time or if you are using
  17606.      `DELAY_KEY_WRITE'. *Note `SHOW': SHOW.
  17607.  
  17608.      To get even more speed when writing many rows at the same time, use
  17609.      `LOCK TABLES'.  *Note `LOCK TABLES': LOCK TABLES.
  17610.  
  17611.    * `language' The language used for error messages.
  17612.  
  17613.    * `large_file_support' If `mysqld' was compiled with options for big
  17614.      file support.
  17615.  
  17616.    * `locked_in_memory' If `mysqld' was locked in memory with
  17617.      `--memlock'
  17618.  
  17619.    * `log' If logging of all queries is enabled.
  17620.  
  17621.    * `log_update' If the update log is enabled.
  17622.  
  17623.    * `log_bin' If the binary log is enabled.
  17624.  
  17625.    * `log_slave_updates' If the updates from the slave should be logged.
  17626.  
  17627.    * `long_query_time' If a query takes longer than this (in seconds),
  17628.      the `Slow_queries' counter will be incremented. If you are using
  17629.      `--log-slow-queries', the query will be logged to the slow query
  17630.      logfile. This value is measured in real time, not CPU time, so a
  17631.      query that may be under the threshold on a lightly loaded system
  17632.      may be above the threshold on a heavily loaded one.  *Note Slow
  17633.      query log::.
  17634.  
  17635.    * `lower_case_table_names' If set to 1 table names are stored in
  17636.      lowercase on disk and table name comparisons will be
  17637.      case-insensitive.  From version 4.0.2, this option also applies to
  17638.      database names.  *Note Name case sensitivity::.
  17639.  
  17640.    * `max_allowed_packet' The maximum size of one packet. The message
  17641.      buffer is initialised to `net_buffer_length' bytes, but can grow
  17642.      up to `max_allowed_packet' bytes when needed.  This value by
  17643.      default is small, to catch big (possibly wrong) packets.  You must
  17644.      increase this value if you are using big `BLOB' columns. It should
  17645.      be as big as the biggest `BLOB' you want to use.  The protocol
  17646.      limits for `max_allowed_packet' is 16M in MySQL 3.23 and 1G in
  17647.      MySQL 4.0.
  17648.  
  17649.    * `max_binlog_cache_size' If a multi-statement transaction requires
  17650.      more than this amount of memory, one will get the error
  17651.      "Multi-statement transaction required more than
  17652.      'max_binlog_cache_size' bytes of storage".
  17653.  
  17654.    * `max_binlog_size' Available after 3.23.33. If a write to the
  17655.      binary (replication) log exceeds the given value, rotate the logs.
  17656.      You cannot set it to less than 1024 bytes, or more than 1 GB.
  17657.      Default is 1 GB.
  17658.  
  17659.    * `max_connections' The number of simultaneous clients allowed.
  17660.      Increasing this value increases the number of file descriptors
  17661.      that `mysqld' requires.  See below for comments on file descriptor
  17662.      limits. *Note Too many connections::.
  17663.  
  17664.    * `max_connect_errors' If there is more than this number of
  17665.      interrupted connections from a host this host will be blocked from
  17666.      further connections.  You can unblock a host with the command
  17667.      `FLUSH HOSTS'.
  17668.  
  17669.    * `max_delayed_threads' Don't start more than this number of threads
  17670.      to handle `INSERT DELAYED' statements.  If you try to insert data
  17671.      into a new table after all `INSERT DELAYED' threads are in use,
  17672.      the row will be inserted as if the `DELAYED' attribute wasn't
  17673.      specified.
  17674.  
  17675.    * `max_heap_table_size' Don't allow creation of heap tables bigger
  17676.      than this.
  17677.  
  17678.    * `max_join_size' Joins that are probably going to read more than
  17679.      `max_join_size' records return an error. Set this value if your
  17680.      users tend to perform joins that lack a `WHERE' clause, that take
  17681.      a long time, and that return millions of rows.
  17682.  
  17683.    * `max_sort_length' The number of bytes to use when sorting `BLOB'
  17684.      or `TEXT' values (only the first `max_sort_length' bytes of each
  17685.      value are used; the rest are ignored).
  17686.  
  17687.    * `max_user_connections' The maximum number of active connections
  17688.      for a single user (0 = no limit).
  17689.  
  17690.    * `max_tmp_tables' (This option doesn't yet do anything.)  Maximum
  17691.      number of temporary tables a client can keep open at the same time.
  17692.  
  17693.    * `max_write_lock_count' After this many write locks, allow some
  17694.      read locks to run in between.
  17695.  
  17696.    * `myisam_recover_options' The value of the `--myisam-recover'
  17697.      option.
  17698.  
  17699.    * `myisam_sort_buffer_size' The buffer that is allocated when
  17700.      sorting the index when doing a `REPAIR' or when creating indexes
  17701.      with `CREATE INDEX' or `ALTER TABLE'.
  17702.  
  17703.    * `myisam_max_extra_sort_file_size'.  If the temporary file used for
  17704.      fast index creation would be bigger than using the key cache by
  17705.      the amount specified here, then prefer the key cache method.  This
  17706.      is mainly used to force long character keys in large tables to use
  17707.      the slower key cache method to create the index.  *Note* that this
  17708.      parameter is given in megabytes before 4.0.3 and in bytes starting
  17709.      from this version.
  17710.  
  17711.    * `myisam_max_sort_file_size' The maximum size of the temporary file
  17712.      MySQL is allowed to use while recreating the index (during
  17713.      `REPAIR', `ALTER TABLE' or `LOAD DATA INFILE'.  If the file-size
  17714.      would be bigger than this, the index will be created through the
  17715.      key cache (which is slower).  *Note* that this parameter is given
  17716.      in megabytes before 4.0.3 and in bytes starting from this version.
  17717.  
  17718.    * `net_buffer_length' The communication buffer is reset to this size
  17719.      between queries. This should not normally be changed, but if you
  17720.      have very little memory, you can set it to the expected size of a
  17721.      query.  (That is, the expected length of SQL statements sent by
  17722.      clients.  If statements exceed this length, the buffer is
  17723.      automatically enlarged, up to `max_allowed_packet' bytes.)
  17724.  
  17725.    * `net_read_timeout' Number of seconds to wait for more data from a
  17726.      connection before aborting the read.  Note that when we don't
  17727.      expect data from a connection, the timeout is defined by
  17728.      `write_timeout'. See also `slave_net_timeout'.
  17729.  
  17730.    * `net_retry_count' If a read on a communication port is
  17731.      interrupted, retry this many times before giving up.  This value
  17732.      should be quite high on `FreeBSD' as internal interrupts are sent
  17733.      to all threads.
  17734.  
  17735.    * `net_write_timeout' Number of seconds to wait for a block to be
  17736.      written to a connection before aborting the write.
  17737.  
  17738.    * `open_files_limit' If this is not 0, then `mysqld' will use this
  17739.      value to reserve file descriptors to use with `setrlimit()'.  If
  17740.      this value is 0 then `mysqld' will reserve `max_connections*5' or
  17741.      `max_connections + table_cache*2' (whichever is larger) number of
  17742.      files.  You should try increasing this if `mysqld' gives you the
  17743.      error 'Too many open files'.
  17744.  
  17745.    * `pid_file' The value of the `--pid-file' option.
  17746.  
  17747.    * `port' The value of the `--port' option.
  17748.  
  17749.    * `protocol_version' The protocol version used by the MySQL server.
  17750.  
  17751.    * `read_buffer_size' (was `record_buffer') Each thread that does a
  17752.      sequential scan allocates a buffer of this size for each table it
  17753.      scans. If you do many sequential scans, you may want to increase
  17754.      this value.
  17755.  
  17756.    * `record_rnd_buffer_size' When reading rows in sorted order after a
  17757.      sort, the rows are read through this buffer to avoid a disk seeks.
  17758.      Can improve `ORDER BY' by a lot if set to a high value.  As this
  17759.      is a thread-specific variable, one should not set this big
  17760.      globally, but just change this when running some specific big
  17761.      queries.
  17762.  
  17763.    * `query_cache_limit' Don't cache results that are bigger than this.
  17764.      (Default 1M).
  17765.  
  17766.    * `query_cache_size' The memory allocated to store results from old
  17767.      queries.  If this is 0, the query cache is disabled (default).
  17768.  
  17769.    * `query_cache_type' This may be set (only numeric) to
  17770.      *Value**Alias*   *Comment*
  17771.      0      OFF       Don't cache or retrieve results.
  17772.      1      ON        Cache all results except `SELECT SQL_NO_CACHE
  17773.                       ...' queries.
  17774.      2      DEMAND    Cache only `SELECT SQL_CACHE ...' queries.
  17775.  
  17776.    * `safe_show_database' Don't show databases for which the user
  17777.      doesn't have any database or table privileges. This can improve
  17778.      security if you're concerned about people being able to see what
  17779.      databases other users have. See also `skip_show_database'.
  17780.  
  17781.    * `server_id' The value of the `--server-id' option.
  17782.  
  17783.    * `skip_locking' Is OFF if `mysqld' uses external locking.
  17784.  
  17785.    * `skip_networking' Is ON if we only allow local (socket)
  17786.      connections.
  17787.  
  17788.    * `skip_show_database' This prevents people from doing `SHOW
  17789.      DATABASES' if they don't have the `PROCESS' privilege. This can
  17790.      improve security if you're concerned about people being able to
  17791.      see what databases other users have. See also `safe_show_database'.
  17792.  
  17793.    * `slave_net_timeout' Number of seconds to wait for more data from a
  17794.      master/slave connection before aborting the read.
  17795.  
  17796.    * `slow_launch_time' If creating the thread takes longer than this
  17797.      value (in seconds), the `Slow_launch_threads' counter will be
  17798.      incremented.
  17799.  
  17800.    * `socket' The Unix socket used by the server.
  17801.  
  17802.    * `sort_buffer' Each thread that needs to do a sort allocates a
  17803.      buffer of this size. Increase this value for faster `ORDER BY' or
  17804.      `GROUP BY' operations.  *Note Temporary files::.
  17805.  
  17806.    * `table_cache' The number of open tables for all threads.
  17807.      Increasing this value increases the number of file descriptors
  17808.      that `mysqld' requires.  You can check if you need to increase the
  17809.      table cache by checking the `Opened_tables' variable.  *Note
  17810.      `Opened_tables': SHOW STATUS.  If this variable is big and you
  17811.      don't do `FLUSH TABLES' a lot (which just forces all tables to be
  17812.      closed and reopenend), then you should increase the value of this
  17813.      variable.
  17814.  
  17815.      For more information about the table cache, see *Note Table
  17816.      cache::.
  17817.  
  17818.    * `table_type' The default table type.
  17819.  
  17820.    * `thread_cache_size' How many threads we should keep in a cache for
  17821.      reuse.  When a client disconnects, the client's threads are put in
  17822.      the cache if there aren't more than `thread_cache_size' threads
  17823.      from before.  All new threads are first taken from the cache, and
  17824.      only when the cache is empty is a new thread created.  This
  17825.      variable can be increased to improve performance if you have a lot
  17826.      of new connections. (Normally this doesn't give a notable
  17827.      performance improvement if you have a good thread implementation.)
  17828.      By examing the difference between the `Connections' and
  17829.      `Threads_created' status variables (*note SHOW STATUS:: for
  17830.      details) you can see how efficient thread cache is.
  17831.  
  17832.    * `thread_concurrency' On Solaris, `mysqld' will call
  17833.      `thr_setconcurrency()' with this value.  `thr_setconcurrency()'
  17834.      permits the application to give the threads system a hint for the
  17835.      desired number of threads that should be run at the same time.
  17836.  
  17837.    * `thread_stack' The stack size for each thread.  Many of the limits
  17838.      detected by the `crash-me' test are dependent on this value. The
  17839.      default is large enough for normal operation.  *Note MySQL
  17840.      Benchmarks::.
  17841.  
  17842.    * `timezone' The timezone for the server.
  17843.  
  17844.    * `tmp_table_size' If an in-memory temporary table exceeds this
  17845.      size, MySQL will automatically convert it to an on-disk `MyISAM'
  17846.      table.  Increase the value of `tmp_table_size' if you do many
  17847.      advanced `GROUP BY' queries and you have lots of memory.
  17848.  
  17849.    * `tmpdir' The directory used for temporary files and temporary
  17850.      tables.
  17851.  
  17852.    * `version' The version number for the server.
  17853.  
  17854.    * `wait_timeout' The number of seconds the server waits for activity
  17855.      on a not interactive connection before closing it.
  17856.  
  17857.      On thread startup `SESSION.WAIT_TIMEOUT' is initialised from
  17858.      `GLOBAL.WAIT_TIMEOUT' or `GLOBAL.INTERACTIVE_TIMEOUT' depending on
  17859.      the type of client (as defined by the `CLIENT_INTERACTIVE' connect
  17860.      option). See also `interactive_timeout'.
  17861.  
  17862. The manual section that describes tuning MySQL contains some
  17863. information of how to tune the above variables. *Note Server
  17864. parameters::.
  17865.  
  17866. `SHOW LOGS'
  17867. ...........
  17868.  
  17869. `SHOW LOGS' shows you status information about existing log files.  It
  17870. currently only displays information about Berkeley DB log files.
  17871.  
  17872.    * `File' shows the full path to the log file
  17873.  
  17874.    * `Type' shows the type of the log file (`BDB' for Berkeley DB log
  17875.      files)
  17876.  
  17877.    * `Status' shows the status of the log file (`FREE' if the file can
  17878.      be removed, or `IN USE' if the file is needed by the transaction
  17879.      subsystem)
  17880.  
  17881. `SHOW PROCESSLIST'
  17882. ..................
  17883.  
  17884. `SHOW [FULL] PROCESSLIST' shows you which threads are running.  You can
  17885. also get this information using the `mysqladmin processlist' command.
  17886. If you have the `SUPER' privilege, you can see all threads.  Otherwise,
  17887. you can see only your own threads.  *Note `KILL': KILL.  If you don't
  17888. use the `FULL' option, then only the first 100 characters of each query
  17889. will be shown.
  17890.  
  17891. This command is very useful if you get the 'too many connections' error
  17892. message and want to find out what's going on. MySQL reserves one extra
  17893. connection for a client with the `SUPER' privilege to ensure that you
  17894. should always be able to login and check the system (assuming you are
  17895. not giving this privilege to all your users).
  17896.  
  17897. Some states commonly seen in `mysqladmin processlist'
  17898.  
  17899.    * `Checking table' The thread is performing [automatic] checking of
  17900.      the table.
  17901.  
  17902.    * `Closing tables' Means that the thread is flushing the changed
  17903.      table data to disk and closing the used tables. This should be a
  17904.      fast operation.  If not, then you should check that you don't have
  17905.      a full disk or that the disk is not in very heavy use.
  17906.  
  17907.    * `Connect Out' Slave connecting to master.
  17908.  
  17909.    * `Copying to tmp table on disk' The temporary result set was larger
  17910.      than `tmp_table_size' and the thread is now changing the in
  17911.      memory-based temporary table to a disk based one to save memory.
  17912.  
  17913.    * `Creating tmp table' The thread is creating a temporary table to
  17914.      hold a part of the result for the query.
  17915.  
  17916.    * `deleting from main table' When executing the first part of a
  17917.      multi-table delete and we are only deleting from the first table.
  17918.  
  17919.    * `deleting from reference tables' When executing the second part of
  17920.      a multi-table delete and we are deleting the matched rows from the
  17921.      other tables.
  17922.  
  17923.    * `Flushing tables' The thread is executing `FLUSH TABLES' and is
  17924.      waiting for all threads to close their tables.
  17925.  
  17926.    * `Killed' Someone has sent a kill to the thread and it should abort
  17927.      next time it checks the kill flag.  The flag is checked in each
  17928.      major loop in MySQL, but in some cases it may still take a short
  17929.      time for the thread to die.  If the thread is locked by some other
  17930.      thread, the kill will take affect as soon as the other thread
  17931.      releases it's lock.
  17932.  
  17933.    * `Sending data' The thread is processing rows for a `SELECT'
  17934.      statement and is also sending data to the client.
  17935.  
  17936.    * `Sorting for group' The thread is doing a sort to satsify a `GROUP
  17937.      BY'.
  17938.  
  17939.    * `Sorting for order' The thread is doing a sort to satsify a `ORDER
  17940.      BY'.
  17941.  
  17942.    * `Opening tables' This simply means that the thread is trying to
  17943.      open a table. This is should be very fast procedure, unless
  17944.      something prevents opening. For example an `ALTER TABLE' or a
  17945.      `LOCK TABLE' can prevent opening a table until the command is
  17946.      finished.
  17947.  
  17948.    * `Removing duplicates' The query was using `SELECT DISTINCT' in
  17949.      such a way that MySQL couldn't optimise that distinct away at an
  17950.      early stage. Because of this MySQL has to do an extra stage to
  17951.      remove all duplicated rows before sending the result to the client.
  17952.  
  17953.    * `Reopen table' The thread got a lock for the table, but noticed
  17954.      after getting the lock that the underlying table structure
  17955.      changed. It has freed the lock, closed the table and is now trying
  17956.      to reopen it.
  17957.  
  17958.    * `Repair by sorting' The repair code is using sorting to create
  17959.      indexes.
  17960.  
  17961.    * `Repair with keycache' The repair code is using creating keys one
  17962.      by one through the key cache.  This is much slower than `Repair by
  17963.      sorting'.
  17964.  
  17965.    * `Searching rows for update' The thread is doing a first phase to
  17966.      find all matching rows before updating them.  This has to be done
  17967.      if the `UPDATE' is changing the index that is used to find the
  17968.      involved rows.
  17969.  
  17970.    * `Sleeping' The thread is wating for the client to send a new
  17971.      command to it.
  17972.  
  17973.    * `System lock' The thread is waiting for getting to get a external
  17974.      system lock for the table. If you are not using multiple mysqld
  17975.      servers that are accessing the same tables, you can disable system
  17976.      locks with the `--skip-external-locking' option.
  17977.  
  17978.    * `Upgrading lock' The `INSERT DELAYED' handler is trying to get a
  17979.      lock for the table to insert rows.
  17980.  
  17981.    * `Updating' The thread is searching for rows to update and updating
  17982.      them.
  17983.  
  17984.    * `User Lock' The thread is waiting on a `GET_LOCK()'.
  17985.  
  17986.    * `Waiting for tables' The thread got a notification that the
  17987.      underlying structure for a table has changed and it needs to
  17988.      reopen the table to get the new structure.  To be able to reopen
  17989.      the table it must however wait until all other threads have closed
  17990.      the table in question.
  17991.  
  17992.      This notification happens if another thread has used `FLUSH TABLES'
  17993.      or one of the following commands on the table in question: `FLUSH
  17994.      TABLES table_name', `ALTER TABLE', `RENAME TABLE', `REPAIR TABLE',
  17995.      `ANALYZE TABLE' or `OPTIMIZE TABLE'.
  17996.  
  17997.    * `waiting for handler insert' The `INSERT DELAYED' handler has
  17998.      processed all inserts and are waiting to get new ones.
  17999.  
  18000. Most states are very quick operations. If threads last in any of these
  18001. states for many seconds, there may be a problem around that needs to be
  18002. investigated.
  18003.  
  18004. There are some other states that are not mentioned previously, but most
  18005. of these are only useful to find bugs in `mysqld'.
  18006.  
  18007. `SHOW GRANTS'
  18008. .............
  18009.  
  18010. `SHOW GRANTS FOR user' lists the grant commands that must be issued to
  18011. duplicate the grants for a user.
  18012.  
  18013.      mysql> SHOW GRANTS FOR root@localhost;
  18014.      +---------------------------------------------------------------------+
  18015.      | Grants for root@localhost                                           |
  18016.      +---------------------------------------------------------------------+
  18017.      | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  18018.      +---------------------------------------------------------------------+
  18019.  
  18020. To list grants for the current session one may use `CURRENT_USER()'
  18021. function (new in version 4.0.6) to find out what user the session was
  18022. authentificated as.  *Note `CURRENT_USER()': Miscellaneous functions.
  18023.  
  18024. `SHOW CREATE TABLE'
  18025. ...................
  18026.  
  18027. Shows a `CREATE TABLE' statement that will create the given table:
  18028.  
  18029.      mysql> SHOW CREATE TABLE t\G
  18030.      *************************** 1. row ***************************
  18031.             Table: t
  18032.      Create Table: CREATE TABLE t (
  18033.        id int(11) default NULL auto_increment,
  18034.        s char(60) default NULL,
  18035.        PRIMARY KEY (id)
  18036.      ) TYPE=MyISAM
  18037.  
  18038. `SHOW CREATE TABLE' will quote table and column names according to
  18039. `SQL_QUOTE_SHOW_CREATE' option.  *Note `SET SQL_QUOTE_SHOW_CREATE': SET
  18040. OPTION.
  18041.  
  18042. `SHOW WARNINGS | ERRORS'
  18043. ........................
  18044.  
  18045.      SHOW WARNINGS [LIMIT #]
  18046.      SHOW ERRORS [LIMIT #]
  18047.  
  18048. This command is implemented in MySQL 4.1.0.
  18049.  
  18050. It shows the errors, warnings and notes that one got for the last
  18051. command.  The errors/warnings are reset for each new command that uses
  18052. a table.
  18053.  
  18054. The MySQL server sends back the total number of warnings and errors you
  18055. got for the last commend; This can be retrieved by calling
  18056. `mysql_warning_count()'.
  18057.  
  18058. Up to `max_error_count' messages are stored (Global and thread specific
  18059. variable).
  18060.  
  18061. You can retrieve the number of errors from `@error_count' and warnings
  18062. from `@warning_count'.
  18063.  
  18064. `SHOW WARNINGS' shows all errors, warnings and notes you got for the
  18065. last command while `SHOW ERRORS' only shows you the errors.
  18066.  
  18067.      mysql> DROP TABLE IF EXISTS no_such_table;
  18068.      mysql> SHOW WARNINGS;
  18069.      
  18070.      +-------+------+-------------------------------+
  18071.      | Level | Code | Message                       |
  18072.      +-------+------+-------------------------------+
  18073.      | Note  | 1051 | Unknown table 'no_such_table' |
  18074.      +-------+------+-------------------------------+
  18075.  
  18076. MySQL Localisation and International Usage
  18077. ==========================================
  18078.  
  18079. The Character Set Used for Data and Sorting
  18080. -------------------------------------------
  18081.  
  18082. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  18083. sorting according to Swedish/Finnish. This is the character set suitable
  18084. in the USA and western Europe.
  18085.  
  18086. All standard MySQL binaries are compiled with
  18087. `--with-extra-charsets=complex'.  This will add code to all standard
  18088. programs to be able to handle `latin1' and all multi-byte character
  18089. sets within the binary. Other character sets will be loaded from a
  18090. character-set definition file when needed.
  18091.  
  18092. The character set determines what characters are allowed in names and
  18093. how things are sorted by the `ORDER BY' and `GROUP BY' clauses of the
  18094. `SELECT' statement.
  18095.  
  18096. You can change the character set with the `--default-character-set'
  18097. option when you start the server.  The character sets available depend
  18098. on the `--with-charset=charset' and `--with-extra-charsets=
  18099. list-of-charset | complex | all' options to `configure', and the
  18100. character set configuration files listed in `SHAREDIR/charsets/Index'.
  18101. *Note configure options::.
  18102.  
  18103. If you change the character set when running MySQL (which may also
  18104. change the sort order), you must run `myisamchk -r -q
  18105. --set-character-set=charset' on all tables. Otherwise, your indexes may
  18106. not be ordered correctly.
  18107.  
  18108. When a client connects to a MySQL server, the server sends the default
  18109. character set in use to the client.  The client will switch to use this
  18110. character set for this connection.
  18111.  
  18112. One should use `mysql_real_escape_string()' when escaping strings for a
  18113. SQL query.  `mysql_real_escape_string()' is identical to the old
  18114. `mysql_escape_string()' function, except that it takes the `MYSQL'
  18115. connection handle as the first parameter.
  18116.  
  18117. If the client is compiled with different paths than where the server is
  18118. installed and the user who configured MySQL didn't include all
  18119. character sets in the MySQL binary, one must specify for the client
  18120. where it can find the additional character sets it will need if the
  18121. server runs with a different character set than the client.
  18122.  
  18123. One can specify this by putting in a MySQL option file:
  18124.  
  18125.      [client]
  18126.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  18127.  
  18128. where the path points to the directory in which the dynamic MySQL
  18129. character sets are stored.
  18130.  
  18131. One can force the client to use specific character set by specifying:
  18132.  
  18133.      [client]
  18134.      default-character-set=character-set-name
  18135.  
  18136. but normally this is never needed.
  18137.  
  18138. German character set
  18139. ....................
  18140.  
  18141. To get German sorting order, you should start `mysqld' with
  18142. `--default-character-set=latin1_de'.  This will give you the following
  18143. characteristics.
  18144.  
  18145. When sorting and comparing string's the following mapping is done on the
  18146. strings before doing the comparison:
  18147.  
  18148.      Σ  ->  ae
  18149.      ÷  ->  oe
  18150.      ⁿ  ->  ue
  18151.      ▀  ->  ss
  18152.  
  18153. All accented characters, are converted to their un-accented uppercase
  18154. counterpart.  All letters are converted to uppercase.
  18155.  
  18156. When comparing strings with `LIKE' the one -> two character mapping is
  18157. not done. All letters are converted to uppercase. Accent are removed
  18158. from all letters except: `▄', `ⁿ', `╓', `÷', `─' and `Σ'.
  18159.  
  18160. Non-English Error Messages
  18161. --------------------------
  18162.  
  18163. `mysqld' can issue error messages in the following languages: Czech,
  18164. Danish, Dutch, English (the default), Estonian, French, German, Greek,
  18165. Hungarian, Italian, Japanese, Korean, Norwegian, Norwegian-ny, Polish,
  18166. Portuguese, Romanian, Russian, Slovak, Spanish, and Swedish.
  18167.  
  18168. To start `mysqld' with a particular language, use either the
  18169. `--language=lang' or `-L lang' options. For example:
  18170.  
  18171.      shell> mysqld --language=swedish
  18172.  
  18173. or:
  18174.  
  18175.      shell> mysqld --language=/usr/local/share/swedish
  18176.  
  18177. Note that all language names are specified in lowercase.
  18178.  
  18179. The language files are located (by default) in
  18180. `MYSQL_BASE_DIR/share/LANGUAGE/'.
  18181.  
  18182. To update the error message file, you should edit the `errmsg.txt' file
  18183. and execute the following command to generate the `errmsg.sys' file:
  18184.  
  18185.      shell> comp_err errmsg.txt errmsg.sys
  18186.  
  18187. If you upgrade to a newer version of MySQL, remember to repeat your
  18188. changes with the new `errmsg.txt' file.
  18189.  
  18190. Adding a New Character Set
  18191. --------------------------
  18192.  
  18193. To add another character set to MySQL, use the following procedure.
  18194.  
  18195. Decide if the set is simple or complex.  If the character set does not
  18196. need to use special string collating routines for sorting and does not
  18197. need multi-byte character support, it is simple.  If it needs either of
  18198. those features, it is complex.
  18199.  
  18200. For example, `latin1' and `danish' are simple charactersets while
  18201. `big5' or `czech' are complex character sets.
  18202.  
  18203. In the following section, we have assumed that you name your character
  18204. set `MYSET'.
  18205.  
  18206. For a simple character set do the following:
  18207.  
  18208.   1. Add MYSET to the end of the `sql/share/charsets/Index' file Assign
  18209.      a unique number to it.
  18210.  
  18211.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use
  18212.      `sql/share/charsets/latin1.conf' as a base for this.)
  18213.  
  18214.      The syntax for the file very simple:
  18215.  
  18216.         * Comments start with a '#' character and proceed to the end of
  18217.           the line.
  18218.  
  18219.         * Words are separated by arbitrary amounts of whitespace.
  18220.  
  18221.         * When defining the character set, every word must be a number
  18222.           in hexadecimal format
  18223.  
  18224.         * The `ctype' array takes up the first 257 words. The
  18225.           `to_lower[]', `to_upper[]' and `sort_order[]' arrays take up
  18226.           256 words each after that.
  18227.  
  18228.      *Note Character arrays::.
  18229.  
  18230.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  18231.      `COMPILED_CHARSETS' lists in `configure.in'.
  18232.  
  18233.   4. Reconfigure, recompile, and test.
  18234.  
  18235.  
  18236. For a complex character set do the following:
  18237.  
  18238.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  18239.      distribution.
  18240.  
  18241.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  18242.      Assign a unique number to it.
  18243.  
  18244.   3. Look at one of the existing `ctype-*.c' files to see what needs to
  18245.      be defined, for example `strings/ctype-big5.c'. Note that the
  18246.      arrays in your file must have names like `ctype_MYSET',
  18247.      `to_lower_MYSET', and so on.  This corresponds to the arrays in
  18248.      the simple character set. *Note Character arrays::.  For a complex
  18249.      character set
  18250.  
  18251.   4. Near the top of the file, place a special comment like this:
  18252.  
  18253.           /*
  18254.            * This comment is parsed by configure to create ctype.c,
  18255.            * so don't change it unless you know what you are doing.
  18256.            *
  18257.            * .configure. number_MYSET=MYNUMBER
  18258.            * .configure. strxfrm_multiply_MYSET=N
  18259.            * .configure. mbmaxlen_MYSET=N
  18260.            */
  18261.  
  18262.      The `configure' program uses this comment to include the character
  18263.      set into the MySQL library automatically.
  18264.  
  18265.      The strxfrm_multiply and mbmaxlen lines will be explained in the
  18266.      following sections.  Only include these if you need the string
  18267.      collating functions or the multi-byte character set functions,
  18268.      respectively.
  18269.  
  18270.   5. You should then create some of the following functions:
  18271.  
  18272.         * `my_strncoll_MYSET()'
  18273.  
  18274.         * `my_strcoll_MYSET()'
  18275.  
  18276.         * `my_strxfrm_MYSET()'
  18277.  
  18278.         * `my_like_range_MYSET()'
  18279.  
  18280.      *Note String collating::.
  18281.  
  18282.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  18283.      `COMPILED_CHARSETS' lists in `configure.in'.
  18284.  
  18285.   7. Reconfigure, recompile, and test.
  18286.  
  18287. The file `sql/share/charsets/README' includes some more instructions.
  18288.  
  18289. If you want to have the character set included in the MySQL
  18290. distribution, mail a patch to <internals@lists.mysql.com>.
  18291.  
  18292. The Character Definition Arrays
  18293. -------------------------------
  18294.  
  18295. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  18296. and uppercase characters corresponding to each member of the character
  18297. set.  For example:
  18298.  
  18299.      to_lower['A'] should contain 'a'
  18300.      to_upper['a'] should contain 'A'
  18301.  
  18302. `sort_order[]' is a map indicating how characters should be ordered for
  18303. comparison and sorting purposes.  For many character sets, this is the
  18304. same as `to_upper[]' (which means sorting will be case-insensitive).
  18305. MySQL will sort characters based on the value of
  18306. `sort_order[character]'.  For more complicated sorting rules, see the
  18307. discussion of string collating below. *Note String collating::.
  18308.  
  18309. `ctype[]' is an array of bit values, with one element for one character.
  18310. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  18311. by character value, but `ctype[]' is indexed by character value + 1.
  18312. This is an old legacy to be able to handle `EOF'.)
  18313.  
  18314. You can find the following bitmask definitions in `m_ctype.h':
  18315.  
  18316.      #define _U      01      /* Uppercase */
  18317.      #define _L      02      /* Lowercase */
  18318.      #define _N      04      /* Numeral (digit) */
  18319.      #define _S      010     /* Spacing character */
  18320.      #define _P      020     /* Punctuation */
  18321.      #define _C      040     /* Control character */
  18322.      #define _B      0100    /* Blank */
  18323.      #define _X      0200    /* heXadecimal digit */
  18324.  
  18325. The `ctype[]' entry for each character should be the union of the
  18326. applicable bitmask values that describe the character.  For example,
  18327. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  18328. (`_X'), so `ctype['A'+1]' should contain the value:
  18329.  
  18330.      _U + _X = 01 + 0200 = 0201
  18331.  
  18332. String Collating Support
  18333. ------------------------
  18334.  
  18335. If the sorting rules for your language are too complex to be handled
  18336. with the simple `sort_order[]' table, you need to use the string
  18337. collating functions.
  18338.  
  18339. Right now the best documentation on this is the character sets that are
  18340. already implemented.  Look at the `big5', `czech', `gbk', `sjis', and
  18341. `tis160' character sets for examples.
  18342.  
  18343. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  18344. comment at the top of the file.  `N' should be set to the maximum ratio
  18345. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  18346. integer).
  18347.  
  18348. Multi-byte Character Support
  18349. ----------------------------
  18350.  
  18351. If your want to add support for a new character set that includes
  18352. multi-byte characters, you need to use the multi-byte character
  18353. functions.
  18354.  
  18355. Right now the best documentation on this is the character sets that are
  18356. already implemented.  Look at the `euc_kr', `gb2312', `gbk', `sjis',
  18357. and `ujis' character sets for examples. These are implemented in the
  18358. `ctype-'charset'.c' files in the `strings' directory.
  18359.  
  18360. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  18361. the top of the source file.  `N' should be set to the size in bytes of
  18362. the largest character in the set.
  18363.  
  18364. Problems With Character Sets
  18365. ----------------------------
  18366.  
  18367. If you try to use a character set that is not compiled into your binary,
  18368. you can run into a couple of different problems:
  18369.  
  18370.    * Your program has a wrong path to where the character sets are
  18371.      stored.  (Default `/usr/local/mysql/share/mysql/charsets').  This
  18372.      can be fixed by using the `--character-sets-dir' option to the
  18373.      program in question.
  18374.  
  18375.    * The character set is a multi-byte character set that can't be
  18376.      loaded dynamically.  In this case you have to recompile the
  18377.      program with the support for the character set.
  18378.  
  18379.    * The character set is a dynamic character set, but you don't have a
  18380.      configure file for it.  In this case you should install the
  18381.      configure file for the character set from a new MySQL distribution.
  18382.  
  18383.    * Your `Index' file doesn't contain the name for the character set.
  18384.  
  18385.           ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf' not found
  18386.           (Errcode: 2)
  18387.  
  18388.      In this case you should either get a new `Index' file or add by
  18389.      hand the name of any missing character sets.
  18390.  
  18391. For `MyISAM' tables, you can check the character set name and number
  18392. for a table with `myisamchk -dvv table_name'.
  18393.  
  18394. MySQL Server-Side Scripts and Utilities
  18395. =======================================
  18396.  
  18397. Overview of the Server-Side Scripts and Utilities
  18398. -------------------------------------------------
  18399.  
  18400. All MySQL programs take many different options. However, every MySQL
  18401. program provides a `--help' option that you can use to get a full
  18402. description of the program's different options. For example, try `mysql
  18403. --help'.
  18404.  
  18405. You can override default options for all standard programs with an
  18406. option file. *Note Option files::.
  18407.  
  18408. The following list briefly describes the server-side MySQL programs:
  18409.  
  18410. `myisamchk'
  18411.      Utility to describe, check, optimise, and repair MySQL tables.
  18412.      Because `myisamchk' has many functions, it is described in its own
  18413.      chapter. *Note MySQL Database Administration::.
  18414.  
  18415. `make_binary_distribution'
  18416.      Makes a binary release of a compiled MySQL. This could be sent by
  18417.      FTP to `/pub/mysql/Incoming' on `support.mysql.com' for the
  18418.      convenience of other MySQL users.
  18419.  
  18420. `mysqlbug'
  18421.      The MySQL bug report script.  This script should always be used
  18422.      when filing a bug report to the MySQL list.
  18423.  
  18424. `mysqld'
  18425.      The SQL daemon. This should always be running.
  18426.  
  18427. `mysql_install_db'
  18428.      Creates the MySQL grant tables with default privileges. This is
  18429.      usually executed only once, when first installing MySQL on a
  18430.      system.
  18431.  
  18432. `safe_mysqld', The Wrapper Around `mysqld'
  18433. ------------------------------------------
  18434.  
  18435. `safe_mysqld' is the recommended way to start a `mysqld' daemon on
  18436. Unix.  `safe_mysqld' adds some safety features such as restarting the
  18437. server when an error occurs and logging run-time information to a log
  18438. file.
  18439.  
  18440. If you don't use `--mysqld=#' or `--mysqld-version=#' `safe_mysqld'
  18441. will use an executable named `mysqld-max' if it exists. If not,
  18442. `safe_mysqld' will start `mysqld'.  This makes it very easy to test to
  18443. use `mysqld-max' instead of `mysqld'; just copy `mysqld-max' to where
  18444. you have `mysqld' and it will be used.
  18445.  
  18446. Normally one should never edit the `safe_mysqld' script, but instead
  18447. put the options to `safe_mysqld' in the `[safe_mysqld]' section in the
  18448. `my.cnf' file. `safe_mysqld' will read all options from the `[mysqld]',
  18449. `[server]' and `[safe_mysqld]' sections from the option files.  *Note
  18450. Option files::.
  18451.  
  18452. Note that all options on the command-line to `safe_mysqld' are passed
  18453. to `mysqld'.  If you wants to use any options in `safe_mysqld' that
  18454. `mysqld' doesn't support, you must specify these in the option file.
  18455.  
  18456. Most of the options to `safe_mysqld' are the same as the options to
  18457. `mysqld'. *Note Command-line options::.
  18458.  
  18459. `safe_mysqld' supports the following options:
  18460.  
  18461. `--basedir=path'
  18462.  
  18463. `--core-file-size=#'
  18464.      Size of the core file `mysqld' should be able to create. Passed to
  18465.      `ulimit -c'.
  18466.  
  18467. `--datadir=path'
  18468.  
  18469. `--defaults-extra-file=path'
  18470.  
  18471. `--defaults-file=path'
  18472.  
  18473. `--err-log=path'
  18474.  
  18475. `--ledir=path'
  18476.      Path to `mysqld'
  18477.  
  18478. `--log=path'
  18479.  
  18480. `--mysqld=mysqld-version'
  18481.      Name of the `mysqld' version in the `ledir' directory you want to
  18482.      start.
  18483.  
  18484. `--mysqld-version=version'
  18485.      Similar to `--mysqld=' but here you only give the suffix for
  18486.      `mysqld'.  For example if you use `--mysqld-version=max',
  18487.      `safe_mysqld' will start the `ledir/mysqld-max' version.  If the
  18488.      argument to `--mysqld-version' is empty, `ledir/mysqld' will be
  18489.      used.
  18490.  
  18491. `--no-defaults'
  18492.  
  18493. `--open-files-limit=#'
  18494.      Number of files `mysqld' should be able to open. Passed to `ulimit
  18495.      -n'. Note that you need to start `safe_mysqld' as root for this to
  18496.      work properly!
  18497.  
  18498. `--pid-file=path'
  18499.  
  18500. `--port=#'
  18501.  
  18502. `--socket=path'
  18503.  
  18504. `--timezone=#'
  18505.      Set the timezone (the `TZ') variable to the value of this
  18506.      parameter.
  18507.  
  18508. `--user=#'
  18509. The `safe_mysqld' script is written so that it normally is able to start
  18510. a server that was installed from either a source or a binary version of
  18511. MySQL, even if these install the server in slightly different
  18512. locations.  `safe_mysqld' expects one of these conditions to be true:
  18513.  
  18514.    * The server and databases can be found relative to the directory
  18515.      from which `safe_mysqld' is invoked.  `safe_mysqld' looks under
  18516.      its working directory for `bin' and `data' directories (for binary
  18517.      distributions) or for `libexec' and `var' directories (for source
  18518.      distributions).  This condition should be met if you execute
  18519.      `safe_mysqld' from your MySQL installation directory (for example,
  18520.      `/usr/local/mysql' for a binary distribution).
  18521.  
  18522.    * If the server and databases cannot be found relative to the
  18523.      working directory, `safe_mysqld' attempts to locate them by
  18524.      absolute pathnames.  Typical locations are `/usr/local/libexec'
  18525.      and `/usr/local/var'.  The actual locations are determined when
  18526.      the distribution was built from which `safe_mysqld' comes.  They
  18527.      should be correct if MySQL was installed in a standard location.
  18528.  
  18529. Because `safe_mysqld' will try to find the server and databases relative
  18530. to its own working directory, you can install a binary distribution of
  18531. MySQL anywhere, as long as you start `safe_mysqld' from the MySQL
  18532. installation directory:
  18533.  
  18534.      shell> cd mysql_installation_directory
  18535.      shell> bin/safe_mysqld &
  18536.  
  18537. If `safe_mysqld' fails, even when invoked from the MySQL installation
  18538. directory, you can modify it to use the path to `mysqld' and the
  18539. pathname options that are correct for your system.  Note that if you
  18540. upgrade MySQL in the future, your modified version of `safe_mysqld'
  18541. will be overwritten, so you should make a copy of your edited version
  18542. that you can reinstall.
  18543.  
  18544. `mysqld_multi', A Program for Managing Multiple MySQL Servers
  18545. -------------------------------------------------------------
  18546.  
  18547. `mysqld_multi' is meant for managing several `mysqld' processes that
  18548. listen for connections on different Unix sockets and TCP/IP ports.
  18549.  
  18550. The program will search for group(s) named `[mysqld#]' from `my.cnf'
  18551. (or the file named by the `--config-file=...' option), where `#' can be
  18552. any positive number starting from 1.  This number is referred to in the
  18553. following discussion as the option group number, or GNR.  Group numbers
  18554. distinquish option groups from one another and are used as arguments to
  18555. `mysqld_multi' to specify which servers you want to start, stop, or
  18556. obtain status for.  Options listed in these groups should be the same
  18557. as you would use in the usual `[mysqld]' group used for starting
  18558. `mysqld'.  (See, for example, *Note Automatic start::.)  However, for
  18559. `mysqld_multi', be sure that each group includes options for values
  18560. such as the port, socket, etc., to be used for each individual `mysqld'
  18561. process.
  18562.  
  18563. `mysqld_multi' is invoked using the following syntax:
  18564.  
  18565.      Usage: mysqld_multi [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  18566.      or     mysqld_multi [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  18567.  
  18568. Each GNR represents an option group number. You can start, stop or
  18569. report any GNR, or several of them at the same time. For an example of
  18570. how you might set up an option file, use this command:
  18571.  
  18572.      shell> mysqld_multi --example
  18573.  
  18574. The GNR values in the list can be comma-separated or combined with a
  18575. dash; in the latter case, all the GNRs between GNR1-GNR2 will be
  18576. affected. With no GNR argument, all groups listed in the option file
  18577. will be either started, stopped, or reported. Note that you must not
  18578. have any white spaces in the GNR list. Anything after a white space is
  18579. ignored.
  18580.  
  18581. `mysqld_multi' supports the following options:
  18582.  
  18583. `--config-file=...'
  18584.      Alternative config file. Note: This will not affect this program's
  18585.      own options (group `[mysqld_multi]'), but only groups `[mysqld#]'.
  18586.      Without this option, everything will be searched from the ordinary
  18587.      `my.cnf' file.
  18588.  
  18589. `--example'
  18590.      Display an example option file.
  18591.  
  18592. `--help'
  18593.      Print this help and exit.
  18594.  
  18595. `--log=...'
  18596.      Log file. Full path to and the name for the log file. Note: If the
  18597.      file exists, everything will be appended.
  18598.  
  18599. `--mysqladmin=...'
  18600.      `mysqladmin' binary to be used for a server shutdown.
  18601.  
  18602. `--mysqld=...'
  18603.      `mysqld' binary to be used. Note that you can give `safe_mysqld'
  18604.      to this option also. The options are passed to `mysqld'. Just make
  18605.      sure you have `mysqld' in your environment variable `PATH' or fix
  18606.      `safe_mysqld'.
  18607.  
  18608. `--no-log'
  18609.      Print to stdout instead of the log file. By default the log file is
  18610.      turned on.
  18611.  
  18612. `--password=...'
  18613.      Password for user for `mysqladmin'.
  18614.  
  18615. `--tcp-ip'
  18616.      Connect to the MySQL server(s) via the TCP/IP port instead of the
  18617.      Unix socket. This affects stopping and reporting.  If a socket file
  18618.      is missing, the server may still be running, but can be accessed
  18619.      only via the TCP/IP port.  By default, connections are made using
  18620.      the Unix socket.
  18621.  
  18622. `--user=...'
  18623.      MySQL user for `mysqladmin'.
  18624.  
  18625. `--version'
  18626.      Print the version number and exit.
  18627.  
  18628. Some notes about `mysqld_multi':
  18629.  
  18630.    * Make sure that the MySQL user, who is stopping the `mysqld'
  18631.      services (e.g using the `mysqladmin' program) have the same
  18632.      password and username for all the data directories accessed (to the
  18633.      `mysql' database) And make sure that the user has the `SHUTDOWN'
  18634.      privilege! If you have many data directories and many different
  18635.      `mysql' databases with different passwords for the MySQL `root'
  18636.      user, you may want to create a common `multi_admin' user for each
  18637.      using the same password (see below). Example how to do it:
  18638.           shell> mysql -u root -S /tmp/mysql.sock -proot_password -e
  18639.           "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'multipass'"
  18640.      *Note Privileges::.  You will have to do the above for each
  18641.      `mysqld' running in each data directory, that you have (just
  18642.      change the socket, `-S=...').
  18643.  
  18644.    * `pid-file' is very important, if you are using `safe_mysqld' to
  18645.      start `mysqld' (e.g., `--mysqld=safe_mysqld') Every `mysqld'
  18646.      should have its own `pid-file'. The advantage using `safe_mysqld'
  18647.      instead of `mysqld' directly here is, that `safe_mysqld' "guards"
  18648.      every `mysqld' process and will restart it, if a `mysqld' process
  18649.      terminates due to a signal sent using `kill -9', or for other
  18650.      reasons such as a segmentation fault (which MySQL should never do,
  18651.      of course ;). Please note that the `safe_mysqld' script may
  18652.      require that you start it from a certain place. This means that
  18653.      you may have to `cd' to a certain directory, before you start the
  18654.      `mysqld_multi'. If you have problems starting, please see the
  18655.      `safe_mysqld' script. Check especially the lines:
  18656.  
  18657.           --------------------------------------------------------------------------
  18658.           MY_PWD=`pwd` Check if we are starting this relative (for the binary
  18659.           release) if test -d /data/mysql -a -f ./share/mysql/english/errmsg.sys
  18660.           -a -x ./bin/mysqld
  18661.           --------------------------------------------------------------------------
  18662.  
  18663.      *Note `safe_mysqld': safe_mysqld.  The above test should be
  18664.      successful, or you may encounter problems.
  18665.  
  18666.    * Beware of the dangers starting multiple `mysqld's in the same data
  18667.      directory.  Use separate data directories, unless you *know* what
  18668.      you are doing!
  18669.  
  18670.    * The socket file and the TCP/IP port must be different for every
  18671.      `mysqld'.
  18672.  
  18673.    * The first and fifth `mysqld' group were intentionally left out from
  18674.      the example.  You may have 'gaps' in the config file. This gives
  18675.      you more flexibility.  The order in which the `mysqlds' are
  18676.      started or stopped depends on the order in which they appear in
  18677.      the config file.
  18678.  
  18679.    * When you want to refer to a certain group using GNR with this
  18680.      program, just use the number in the end of the group name.  For
  18681.      example, the GNR for a group named `[mysqld17]' is 17.
  18682.  
  18683.    * You may want to use option `--user' for `mysqld', but in order to
  18684.      do this you need to run the `mysqld_multi' script as the Unix
  18685.      `root' user. Having the option in the config file doesn't matter;
  18686.      you will just get a warning, if you are not the superuser and the
  18687.      `mysqlds' are started under *your* Unix account. *Important*: Make
  18688.      sure that the `pid-file' and the data directory are
  18689.      read+write(+execute for the latter one) accessible for *that* Unix
  18690.      user, who the specific `mysqld' process is started as. *Do not*
  18691.      use the Unix root account for this, unless you *know* what you are
  18692.      doing!
  18693.  
  18694.    * *Most important*: Make sure that you understand the meanings of
  18695.      the options that are passed to the `mysqld's and *why one would
  18696.      want* to have separate `mysqld' processes. Starting multiple
  18697.      `mysqld's in one data directory *will not* give you extra
  18698.      performance in a threaded system!
  18699.  
  18700. *Note Multiple servers::.
  18701.  
  18702. This is an example of the config file on behalf of `mysqld_multi'.
  18703.  
  18704.      # This file should probably be in your home dir (~/.my.cnf) or /etc/my.cnf
  18705.      # Version 2.1 by Jani Tolonen
  18706.      
  18707.      [mysqld_multi]
  18708.      mysqld     = /usr/local/bin/safe_mysqld
  18709.      mysqladmin = /usr/local/bin/mysqladmin
  18710.      user       = multi_admin
  18711.      password   = multipass
  18712.      
  18713.      [mysqld2]
  18714.      socket     = /tmp/mysql.sock2
  18715.      port       = 3307
  18716.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  18717.      datadir    = /usr/local/mysql/var2
  18718.      language   = /usr/local/share/mysql/english
  18719.      user       = john
  18720.      
  18721.      [mysqld3]
  18722.      socket     = /tmp/mysql.sock3
  18723.      port       = 3308
  18724.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  18725.      datadir    = /usr/local/mysql/var3
  18726.      language   = /usr/local/share/mysql/swedish
  18727.      user       = monty
  18728.      
  18729.      [mysqld4]
  18730.      socket     = /tmp/mysql.sock4
  18731.      port       = 3309
  18732.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  18733.      datadir    = /usr/local/mysql/var4
  18734.      language   = /usr/local/share/mysql/estonia
  18735.      user       = tonu
  18736.      
  18737.      [mysqld6]
  18738.      socket     = /tmp/mysql.sock6
  18739.      port       = 3311
  18740.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  18741.      datadir    = /usr/local/mysql/var6
  18742.      language   = /usr/local/share/mysql/japanese
  18743.      user       = jani
  18744.  
  18745. *Note Option files::.
  18746.  
  18747. `myisampack', The MySQL Compressed Read-only Table Generator
  18748. ------------------------------------------------------------
  18749.  
  18750. `myisampack' is used to compress MyISAM tables, and `pack_isam' is used
  18751. to compress ISAM tables. Because ISAM tables are deprecated, we will
  18752. only discuss `myisampack' here, but everything said about `myisampack'
  18753. should also be true for `pack_isam'.
  18754.  
  18755. `myisampack' works by compressing each column in the table separately.
  18756. The information needed to decompress columns is read into memory when
  18757. the table is opened. This results in much better performance when
  18758. accessing individual records, because you only have to uncompress
  18759. exactly one record, not a much larger disk block as when using Stacker
  18760. on MS-DOS.  Usually, `myisampack' packs the datafile 40%-70%.
  18761.  
  18762. MySQL uses memory mapping (`mmap()') on compressed tables and falls
  18763. back to normal read/write file usage if `mmap()' doesn't work.
  18764.  
  18765. Please note the following:
  18766.    * After packing, the table is read-only. This is generally intended
  18767.      (such as when accessing packed tables on a CD). Also allowing
  18768.      writes to a packed table is on our TODO list but with low priority.
  18769.  
  18770.    * `myisampack' can also pack `BLOB' or `TEXT' columns.  The older
  18771.      `pack_isam' (for `ISAM' tables) can not do this.
  18772.  
  18773. `myisampack' is invoked like this:
  18774.  
  18775.      shell> myisampack [options] filename ...
  18776.  
  18777. Each filename should be the name of an index (`.MYI') file.  If you are
  18778. not in the database directory, you should specify the pathname to the
  18779. file.  It is permissible to omit the `.MYI' extension.
  18780.  
  18781. `myisampack' supports the following options:
  18782.  
  18783. `-b, --backup'
  18784.      Make a backup of the table as `tbl_name.OLD'.
  18785.  
  18786. `-#, --debug=debug_options'
  18787.      Output debug log. The `debug_options' string often is
  18788.      `'d:t:o,filename''.
  18789.  
  18790. `-f, --force'
  18791.      Force packing of the table even if it becomes bigger or if the
  18792.      temporary file exists.  `myisampack' creates a temporary file
  18793.      named `tbl_name.TMD' while it compresses the table.  If you kill
  18794.      `myisampack', the `.TMD' file may not be deleted.  Normally,
  18795.      `myisampack' exits with an error if it finds that `tbl_name.TMD'
  18796.      exists.  With `--force', `myisampack' packs the table anyway.
  18797.  
  18798. `-?, --help'
  18799.      Display a help message and exit.
  18800.  
  18801. `-j big_tbl_name, --join=big_tbl_name'
  18802.      Join all tables named on the command-line into a single table
  18803.      `big_tbl_name'.  All tables that are to be combined *must* be
  18804.      identical (same column names and types, same indexes, etc.).
  18805.  
  18806. `-p #, --packlength=#'
  18807.      Specify the record length storage size, in bytes.  The value
  18808.      should be 1, 2, or 3.  (`myisampack' stores all rows with length
  18809.      pointers of 1, 2, or 3 bytes.  In most normal cases, `myisampack'
  18810.      can determine the right length value before it begins packing the
  18811.      file, but it may notice during the packing process that it could
  18812.      have used a shorter length. In this case, `myisampack' will print
  18813.      a note that the next time you pack the same file, you could use a
  18814.      shorter record length.)
  18815.  
  18816. `-s, --silent'
  18817.      Silent mode.  Write output only when errors occur.
  18818.  
  18819. `-t, --test'
  18820.      Don't actually pack table, just test packing it.
  18821.  
  18822. `-T dir_name, --tmp_dir=dir_name'
  18823.      Use the named directory as the location in which to write the
  18824.      temporary table.
  18825.  
  18826. `-v, --verbose'
  18827.      Verbose mode.  Write information about progress and packing result.
  18828.  
  18829. `-V, --version'
  18830.      Display version information and exit.
  18831.  
  18832. `-w, --wait'
  18833.      Wait and retry if table is in use.  If the `mysqld' server was
  18834.      invoked with the `--skip-external-locking' option, it is not a
  18835.      good idea to invoke `myisampack' if the table might be updated
  18836.      during the packing process.
  18837.  
  18838. The sequence of commands shown here illustrates a typical table
  18839. compression session:
  18840.  
  18841.      shell> ls -l station.*
  18842.      -rw-rw-r--   1 monty    my         994128 Apr 17 19:00 station.MYD
  18843.      -rw-rw-r--   1 monty    my          53248 Apr 17 19:00 station.MYI
  18844.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  18845.      
  18846.      shell> myisamchk -dvv station
  18847.      
  18848.      MyISAM file:     station
  18849.      Isam-version:  2
  18850.      Creation time: 1996-03-13 10:08:58
  18851.      Recover time:  1997-02-02  3:06:43
  18852.      Data records:              1192  Deleted blocks:              0
  18853.      Datafile: Parts:           1192  Deleted data:                0
  18854.      Datafile pointer (bytes):     2  Keyfile pointer (bytes):     2
  18855.      Max datafile length:   54657023  Max keyfile length:   33554431
  18856.      Recordlength:               834
  18857.      Record format: Fixed length
  18858.      
  18859.      table description:
  18860.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  18861.      1   2     4   unique  unsigned long              1024       1024          1
  18862.      2   32    30  multip. text                      10240       1024          1
  18863.      
  18864.      Field Start Length Type
  18865.      1     1     1
  18866.      2     2     4
  18867.      3     6     4
  18868.      4     10    1
  18869.      5     11    20
  18870.      6     31    1
  18871.      7     32    30
  18872.      8     62    35
  18873.      9     97    35
  18874.      10    132   35
  18875.      11    167   4
  18876.      12    171   16
  18877.      13    187   35
  18878.      14    222   4
  18879.      15    226   16
  18880.      16    242   20
  18881.      17    262   20
  18882.      18    282   20
  18883.      19    302   30
  18884.      20    332   4
  18885.      21    336   4
  18886.      22    340   1
  18887.      23    341   8
  18888.      24    349   8
  18889.      25    357   8
  18890.      26    365   2
  18891.      27    367   2
  18892.      28    369   4
  18893.      29    373   4
  18894.      30    377   1
  18895.      31    378   2
  18896.      32    380   8
  18897.      33    388   4
  18898.      34    392   4
  18899.      35    396   4
  18900.      36    400   4
  18901.      37    404   1
  18902.      38    405   4
  18903.      39    409   4
  18904.      40    413   4
  18905.      41    417   4
  18906.      42    421   4
  18907.      43    425   4
  18908.      44    429   20
  18909.      45    449   30
  18910.      46    479   1
  18911.      47    480   1
  18912.      48    481   79
  18913.      49    560   79
  18914.      50    639   79
  18915.      51    718   79
  18916.      52    797   8
  18917.      53    805   1
  18918.      54    806   1
  18919.      55    807   20
  18920.      56    827   4
  18921.      57    831   4
  18922.      
  18923.      shell> myisampack station.MYI
  18924.      Compressing station.MYI: (1192 records)
  18925.      - Calculating statistics
  18926.      
  18927.      normal:     20  empty-space:      16  empty-zero:        12  empty-fill:  11
  18928.      pre-space:   0  end-space:        12  table-lookups:      5  zero:         7
  18929.      Original trees:  57  After join: 17
  18930.      - Compressing file
  18931.      87.14%
  18932.      
  18933.      shell> ls -l station.*
  18934.      -rw-rw-r--   1 monty    my         127874 Apr 17 19:00 station.MYD
  18935.      -rw-rw-r--   1 monty    my          55296 Apr 17 19:04 station.MYI
  18936.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  18937.      
  18938.      shell> myisamchk -dvv station
  18939.      
  18940.      MyISAM file:     station
  18941.      Isam-version:  2
  18942.      Creation time: 1996-03-13 10:08:58
  18943.      Recover time:  1997-04-17 19:04:26
  18944.      Data records:              1192  Deleted blocks:              0
  18945.      Datafile: Parts:           1192  Deleted data:                0
  18946.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     1
  18947.      Max datafile length:   16777215  Max keyfile length:     131071
  18948.      Recordlength:               834
  18949.      Record format: Compressed
  18950.      
  18951.      table description:
  18952.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  18953.      1   2     4   unique  unsigned long             10240       1024          1
  18954.      2   32    30  multip. text                      54272       1024          1
  18955.      
  18956.      Field Start Length Type                         Huff tree  Bits
  18957.      1     1     1      constant                             1     0
  18958.      2     2     4      zerofill(1)                          2     9
  18959.      3     6     4      no zeros, zerofill(1)                2     9
  18960.      4     10    1                                           3     9
  18961.      5     11    20     table-lookup                         4     0
  18962.      6     31    1                                           3     9
  18963.      7     32    30     no endspace, not_always              5     9
  18964.      8     62    35     no endspace, not_always, no empty    6     9
  18965.      9     97    35     no empty                             7     9
  18966.      10    132   35     no endspace, not_always, no empty    6     9
  18967.      11    167   4      zerofill(1)                          2     9
  18968.      12    171   16     no endspace, not_always, no empty    5     9
  18969.      13    187   35     no endspace, not_always, no empty    6     9
  18970.      14    222   4      zerofill(1)                          2     9
  18971.      15    226   16     no endspace, not_always, no empty    5     9
  18972.      16    242   20     no endspace, not_always              8     9
  18973.      17    262   20     no endspace, no empty                8     9
  18974.      18    282   20     no endspace, no empty                5     9
  18975.      19    302   30     no endspace, no empty                6     9
  18976.      20    332   4      always zero                          2     9
  18977.      21    336   4      always zero                          2     9
  18978.      22    340   1                                           3     9
  18979.      23    341   8      table-lookup                         9     0
  18980.      24    349   8      table-lookup                        10     0
  18981.      25    357   8      always zero                          2     9
  18982.      26    365   2                                           2     9
  18983.      27    367   2      no zeros, zerofill(1)                2     9
  18984.      28    369   4      no zeros, zerofill(1)                2     9
  18985.      29    373   4      table-lookup                        11     0
  18986.      30    377   1                                           3     9
  18987.      31    378   2      no zeros, zerofill(1)                2     9
  18988.      32    380   8      no zeros                             2     9
  18989.      33    388   4      always zero                          2     9
  18990.      34    392   4      table-lookup                        12     0
  18991.      35    396   4      no zeros, zerofill(1)               13     9
  18992.      36    400   4      no zeros, zerofill(1)                2     9
  18993.      37    404   1                                           2     9
  18994.      38    405   4      no zeros                             2     9
  18995.      39    409   4      always zero                          2     9
  18996.      40    413   4      no zeros                             2     9
  18997.      41    417   4      always zero                          2     9
  18998.      42    421   4      no zeros                             2     9
  18999.      43    425   4      always zero                          2     9
  19000.      44    429   20     no empty                             3     9
  19001.      45    449   30     no empty                             3     9
  19002.      46    479   1                                          14     4
  19003.      47    480   1                                          14     4
  19004.      48    481   79     no endspace, no empty               15     9
  19005.      49    560   79     no empty                             2     9
  19006.      50    639   79     no empty                             2     9
  19007.      51    718   79     no endspace                         16     9
  19008.      52    797   8      no empty                             2     9
  19009.      53    805   1                                          17     1
  19010.      54    806   1                                           3     9
  19011.      55    807   20     no empty                             3     9
  19012.      56    827   4      no zeros, zerofill(2)                2     9
  19013.      57    831   4      no zeros, zerofill(1)                2     9
  19014.  
  19015. The information printed by `myisampack' is described here:
  19016.  
  19017. `normal'
  19018.      The number of columns for which no extra packing is used.
  19019.  
  19020. `empty-space'
  19021.      The number of columns containing values that are only spaces;
  19022.      these will occupy 1 bit.
  19023.  
  19024. `empty-zero'
  19025.      The number of columns containing values that are only binary 0's;
  19026.      these will occupy 1 bit.
  19027.  
  19028. `empty-fill'
  19029.      The number of integer columns that don't occupy the full byte
  19030.      range of their type; these are changed to a smaller type (for
  19031.      example, an `INTEGER' column may be changed to `MEDIUMINT').
  19032.  
  19033. `pre-space'
  19034.      The number of decimal columns that are stored with leading spaces.
  19035.      In this case, each value will contain a count for the number of
  19036.      leading spaces.
  19037.  
  19038. `end-space'
  19039.      The number of columns that have a lot of trailing spaces.  In this
  19040.      case, each value will contain a count for the number of trailing
  19041.      spaces.
  19042.  
  19043. `table-lookup'
  19044.      The column had only a small number of different values, which were
  19045.      converted to an `ENUM' before Huffman compression.
  19046.  
  19047. `zero'
  19048.      The number of columns for which all values are zero.
  19049.  
  19050. `Original trees'
  19051.      The initial number of Huffman trees.
  19052.  
  19053. `After join'
  19054.      The number of distinct Huffman trees left after joining trees to
  19055.      save some header space.
  19056.  
  19057. After a table has been compressed, `myisamchk -dvv' prints additional
  19058. information about each field:
  19059.  
  19060. `Type'
  19061.      The field type may contain the following descriptors:
  19062.  
  19063.     `constant'
  19064.           All rows have the same value.
  19065.  
  19066.     `no endspace'
  19067.           Don't store endspace.
  19068.  
  19069.     `no endspace, not_always'
  19070.           Don't store endspace and don't do end space compression for
  19071.           all values.
  19072.  
  19073.     `no endspace, no empty'
  19074.           Don't store endspace. Don't store empty values.
  19075.  
  19076.     `table-lookup'
  19077.           The column was converted to an `ENUM'.
  19078.  
  19079.     `zerofill(n)'
  19080.           The most significant `n' bytes in the value are always 0 and
  19081.           are not stored.
  19082.  
  19083.     `no zeros'
  19084.           Don't store zeros.
  19085.  
  19086.     `always zero'
  19087.           0 values are stored in 1 bit.
  19088.  
  19089. `Huff tree'
  19090.      The Huffman tree associated with the field.
  19091.  
  19092. `Bits'
  19093.      The number of bits used in the Huffman tree.
  19094.  
  19095. After you have run `pack_isam'/`myisampack' you must run
  19096. `isamchk'/`myisamchk' to re-create the index.  At this time you can
  19097. also sort the index blocks and create statistics needed for the MySQL
  19098. optimiser to work more efficiently:
  19099.  
  19100.      myisamchk -rq --analyze --sort-index table_name.MYI
  19101.      isamchk   -rq --analyze --sort-index table_name.ISM
  19102.  
  19103. After you have installed the packed table into the MySQL database
  19104. directory you should do `mysqladmin flush-tables' to force `mysqld' to
  19105. start using the new table.
  19106.  
  19107. If you want to unpack a packed table, you can do this with the
  19108. `--unpack' option to `isamchk' or `myisamchk'.
  19109.  
  19110. `mysqld-max', An Extended `mysqld' Server
  19111. -----------------------------------------
  19112.  
  19113. `mysqld-max' is the MySQL server (`mysqld') configured with the
  19114. following configure options:
  19115.  
  19116. *Option*               *Comment*
  19117. -with-server-suffix=-maxAdd a suffix to the `mysqld'
  19118.                        version string.
  19119. -with-innodb           Support for InnoDB tables.
  19120. -with-bdb              Support for Berkeley DB (BDB)
  19121.                        tables
  19122. CFLAGS=-DUSE_SYMDIR    Symbolic links support for
  19123.                        Windows.
  19124.  
  19125. You can find the MySQL-max binaries at
  19126. `http://www.mysql.com/downloads/mysql-max-3.23.html'.
  19127.  
  19128. The Windows MySQL binary distributions includes both the standard
  19129. `mysqld.exe' binary and the `mysqld-max.exe' binary.
  19130. `http://www.mysql.com/downloads/mysql-3.23.html'.  *Note Windows
  19131. installation::.
  19132.  
  19133. Note that as InnoDB and Berkeley DB are not available for all platforms,
  19134. some of the `Max' binaries may not have support for both of these.  You
  19135. can check which table types are supported by doing the following query:
  19136.  
  19137.      mysql> SHOW VARIABLES LIKE "have_%";
  19138.      +---------------+-------+
  19139.      | Variable_name | Value |
  19140.      +---------------+-------+
  19141.      | have_bdb      | YES   |
  19142.      | have_innodb   | NO    |
  19143.      | have_isam     | YES   |
  19144.      | have_raid     | NO    |
  19145.      | have_openssl  | NO    |
  19146.      +---------------+-------+
  19147.  
  19148. The meaning of the values are:
  19149.  
  19150. *Value*     *Meaning*
  19151. `YES'       The option is activated and usable.
  19152. `NO'        MySQL is not compiled with support for this option.
  19153. `DISABLED'  The xxxx option is disabled because one started `mysqld'
  19154.             with `--skip-xxxx' or because one didn't start `mysqld' with
  19155.             all needed options to enable the option.  In this case the
  19156.             `hostname.err' file should contain a reason for why the
  19157.             option is disabled.
  19158.  
  19159. *Note*:  To be able to create InnoDB tables you *must* edit your
  19160. startup options to include at least the `innodb_data_file_path' option.
  19161. *Note InnoDB start::.
  19162.  
  19163. To get better performance for BDB tables, you should add some
  19164. configuration options for these too. *Note BDB start::.
  19165.  
  19166. `safe_mysqld' will automatically try to start any `mysqld' binary with
  19167. the `-max' suffix. This makes it very easy to test out a another
  19168. `mysqld' binary in an existing installation.  Just run `configure' with
  19169. the options you want and then install the new `mysqld' binary as
  19170. `mysqld-max' in the same directory where your old `mysqld' binary is.
  19171. *Note `safe_mysqld': safe_mysqld.
  19172.  
  19173. The `mysqld-max' RPM uses the above mentioned `safe_mysqld' feature. It
  19174. just installs the `mysqld-max' executable and `safe_mysqld' will
  19175. automatically use this executable when `safe_mysqld' is restarted.
  19176.  
  19177. The following table shows which table types our standard MySQL-Max
  19178. binaries includes:
  19179.  
  19180. *System*    `BDB'   `InnoDB'
  19181. AIX 4.3     N       Y
  19182. HP-UX 11.0  N       Y
  19183. Linux-Alpha N       Y
  19184. Linux-Intel Y       Y
  19185. Linux-IA64  N       Y
  19186. Solaris-IntelN       Y
  19187. Solaris-SPARCY       Y
  19188. Caldera     Y       Y
  19189. (SCO) OSR5          
  19190. UnixWare    Y       Y
  19191. Windows/NT  Y       Y
  19192.  
  19193. MySQL Client-Side Scripts and Utilities
  19194. =======================================
  19195.  
  19196. Overview of the Client-Side Scripts and Utilities
  19197. -------------------------------------------------
  19198.  
  19199. All MySQL clients that communicate with the server using the
  19200. `mysqlclient' library use the following environment variables:
  19201.  
  19202. *Name*             *Description*
  19203. `MYSQL_UNIX_PORT'  The default socket; used for connections
  19204.                    to `localhost'
  19205. `MYSQL_TCP_PORT'   The default TCP/IP port
  19206. `MYSQL_PWD'        The default password
  19207. `MYSQL_DEBUG'      Debug-trace options when debugging
  19208. `TMPDIR'           The directory where temporary tables/files
  19209.                    are created
  19210.  
  19211. Use of `MYSQL_PWD' is insecure.  *Note Connecting::.
  19212.  
  19213. The `mysql' client uses the file named in the `MYSQL_HISTFILE'
  19214. environment variable to save the command-line history. The default
  19215. value for the history file is `$HOME/.mysql_history', where `$HOME' is
  19216. the value of the `HOME' environment variable. *Note Environment
  19217. variables::.
  19218.  
  19219. All MySQL programs take many different options. However, every MySQL
  19220. program provides a `--help' option that you can use to get a full
  19221. description of the program's different options. For example, try `mysql
  19222. --help'.
  19223.  
  19224. You can override default options for all standard client programs with
  19225. an option file. *Note Option files::.
  19226.  
  19227. The following list briefly describes the client-side MySQL programs:
  19228.  
  19229. `msql2mysql'
  19230.      A shell script that converts `mSQL' programs to MySQL. It doesn't
  19231.      handle all cases, but it gives a good start when converting.
  19232.  
  19233. `mysqlaccess'
  19234.      A script that checks the access privileges for a host, user, and
  19235.      database combination.
  19236.  
  19237. `mysqladmin'
  19238.      Utility for performing administrative operations, such as creating
  19239.      or dropping databases, reloading the grant tables, flushing tables
  19240.      to disk, and reopening log files.  `mysqladmin' can also be used
  19241.      to retrieve version, process, and status information from the
  19242.      server.  *Note `mysqladmin': mysqladmin.
  19243.  
  19244. `mysqldump'
  19245.      Dumps a MySQL database into a file as SQL statements or as
  19246.      tab-separated text files. Enhanced freeware originally by Igor
  19247.      Romanenko.  *Note `mysqldump': mysqldump.
  19248.  
  19249. `mysqlimport'
  19250.      Imports text files into their respective tables using `LOAD DATA
  19251.      INFILE'. *Note `mysqlimport': mysqlimport.
  19252.  
  19253. `mysqlshow'
  19254.      Displays information about databases, tables, columns, and indexes.
  19255.  
  19256. `replace'
  19257.      A utility program that is used by `msql2mysql', but that has more
  19258.      general applicability as well.  `replace' changes strings in place
  19259.      in files or on the standard input. Uses a finite state machine to
  19260.      match longer strings first. Can be used to swap strings. For
  19261.      example, this command swaps `a' and `b' in the given files:
  19262.  
  19263.           shell> replace a b b a -- file1 file2 ...
  19264.  
  19265. `mysql', The Command-line Tool
  19266. ------------------------------
  19267.  
  19268. `mysql' is a simple SQL shell (with GNU `readline' capabilities).  It
  19269. supports interactive and non-interactive use. When used interactively,
  19270. query results are presented in an ASCII-table format. When used
  19271. non-interactively (for example, as a filter), the result is presented in
  19272. tab-separated format.  (The output format can be changed using
  19273. command-line options.)  You can run scripts simply like this:
  19274.  
  19275.      shell> mysql database < script.sql > output.tab
  19276.  
  19277. If you have problems due to insufficient memory in the client, use the
  19278. `--quick' option!  This forces `mysql' to use `mysql_use_result()'
  19279. rather than `mysql_store_result()' to retrieve the result set.
  19280.  
  19281. Using `mysql' is very easy. Just start it as follows: `mysql database'
  19282. or `mysql --user=user_name --password=your_password database'. Type a
  19283. SQL statement, end it with `;', `\g', or `\G' and press Enter.
  19284.  
  19285. `mysql' supports the following options:
  19286.  
  19287. `-?, --help'
  19288.      Display this help and exit.
  19289.  
  19290. `-A, --no-auto-rehash'
  19291.      No automatic rehashing. One has to use 'rehash' to get table and
  19292.      field completion. This gives a quicker start of mysql.
  19293.  
  19294. `--prompt=...'
  19295.      Set the mysql prompt to specified format.
  19296.  
  19297. `-b, --no-beep'
  19298.      Turn off beep-on-error.
  19299.  
  19300. `-B, --batch'
  19301.      Print results with a tab as separator, each row on a new line.
  19302.      Doesn't use history file.
  19303.  
  19304. `--character-sets-dir=...'
  19305.      Directory where character sets are located.
  19306.  
  19307. `-C, --compress'
  19308.      Use compression in server/client protocol.
  19309.  
  19310. `-#, --debug[=...]'
  19311.      Debug log. Default is 'd:t:o,/tmp/mysql.trace'.
  19312.  
  19313. `-D, --database=...'
  19314.      Database to use. This is mainly useful in the `my.cnf' file.
  19315.  
  19316. `--default-character-set=...'
  19317.      Set the default character set.
  19318.  
  19319. `-e, --execute=...'
  19320.      Execute command and quit. (Output like with -batch)
  19321.  
  19322. `-E, --vertical'
  19323.      Print the output of a query (rows) vertically. Without this option
  19324.      you can also force this output by ending your statements with `\G'.
  19325.  
  19326. `-f, --force'
  19327.      Continue even if we get a SQL error.
  19328.  
  19329. `-g, --no-named-commands'
  19330.      Named commands are disabled. Use \* form only, or use named
  19331.      commands only in the beginning of a line ending with a semicolon
  19332.      (`;'). Since Version 10.9, the client now starts with this option
  19333.      *enabled* by default!  With the -g option, long format commands
  19334.      will still work from the first line, however.
  19335.  
  19336. `-G, --enable-named-commands'
  19337.      Named commands are *enabled*.  Long format commands are allowed as
  19338.      well as shortened \* commands.
  19339.  
  19340. `-i, --ignore-space'
  19341.      Ignore space after function names.
  19342.  
  19343. `-h, --host=...'
  19344.      Connect to the given host.
  19345.  
  19346. `-H, --html'
  19347.      Produce HTML output.
  19348.  
  19349. `-X, --xml'
  19350.      Produce XML output.
  19351.  
  19352. `-L, --skip-line-numbers'
  19353.      Don't write line number for errors. Useful when one wants to
  19354.      compare result files that includes error messages
  19355.  
  19356. `--no-pager'
  19357.      Disable pager and print to stdout. See interactive help (\h) also.
  19358.  
  19359. `--no-tee'
  19360.      Disable outfile. See interactive help (\h) also.
  19361.  
  19362. `-n, --unbuffered'
  19363.      Flush buffer after each query.
  19364.  
  19365. `-N, --skip-column-names'
  19366.      Don't write column names in results.
  19367.  
  19368. `-O, --set-variable var=option'
  19369.      Give a variable a value. `--help' lists variables.  Please note
  19370.      that `--set-variable' is deprecated since MySQL 4.0, just use
  19371.      `--var=option' on its own.
  19372.  
  19373. `-o, --one-database'
  19374.      Only update the default database. This is useful for skipping
  19375.      updates to other database in the update log.
  19376.  
  19377. ``--pager[=...]''
  19378.      Output type. Default is your `ENV' variable `PAGER'. Valid pagers
  19379.      are less, more, cat [> filename], etc.  See interactive help (\h)
  19380.      also. This option does not work in batch mode. Pager works only in
  19381.      Unix.
  19382.  
  19383. `-p[password], --password[=...]'
  19384.      Password to use when connecting to server. If a password is not
  19385.      given on the command-line, you will be prompted for it.  Note that
  19386.      if you use the short form `-p' you can't have a space between the
  19387.      option and the password.
  19388.  
  19389. `-P  --port=...'
  19390.      TCP/IP port number to use for connection.
  19391.  
  19392. `-q, --quick'
  19393.      Don't cache result, print it row-by-row. This may slow down the
  19394.      server if the output is suspended. Doesn't use history file.
  19395.  
  19396. `-r, --raw'
  19397.      Write column values without escape conversion. Used with `--batch'
  19398.  
  19399. `-s, --silent'
  19400.      Be more silent.
  19401.  
  19402. `-S  --socket=...'
  19403.      Socket file to use for connection.
  19404.  
  19405. `-t  --table'
  19406.      Output in table format. This is default in non-batch mode.
  19407.  
  19408. `-T, --debug-info'
  19409.      Print some debug information at exit.
  19410.  
  19411. `--tee=...'
  19412.      Append everything into outfile. See interactive help (\h) also.
  19413.      Does not work in batch mode.
  19414.  
  19415. `-u, --user=#'
  19416.      User for login if not current user.
  19417.  
  19418. `-U, --safe-updates[=#], --i-am-a-dummy[=#]'
  19419.      Only allow `UPDATE' and `DELETE' that uses keys. See below for
  19420.      more information about this option.  You can reset this option if
  19421.      you have it in your `my.cnf' file by using `--safe-updates=0'.
  19422.  
  19423. `-v, --verbose'
  19424.      More verbose output (-v -v -v gives the table output format).
  19425.  
  19426. `-V, --version'
  19427.      Output version information and exit.
  19428.  
  19429. `-w, --wait'
  19430.      Wait and retry if connection is down instead of aborting.
  19431.  
  19432. You can also set the following variables with `-O' or `--set-variable';
  19433. please note that `--set-variable' is deprecated since MySQL 4.0, just
  19434. use `--var=option' on its own:
  19435.  
  19436. *Variable Name*    *Default**Description*
  19437. connect_timeout    0       Number of seconds before timeout connection.
  19438. max_allowed_packet 16777216Max packetlength to send/receive from to server
  19439. net_buffer_length  16384   Buffer for TCP/IP and socket communication
  19440. select_limit       1000    Automatic limit for SELECT when using
  19441.                            -i-am-a-dummy
  19442. max_join_size      1000000 Automatic limit for rows in a join when using
  19443.                            -i-am-a-dummy.
  19444.  
  19445. If you type 'help' on the command-line, `mysql' will print out the
  19446. commands that it supports:
  19447.  
  19448.      mysql> help
  19449.      
  19450.      MySQL commands:
  19451.      help    (\h)    Display this text.
  19452.      ?       (\h)    Synonym for `help'.
  19453.      clear   (\c)    Clear command.
  19454.      connect (\r)    Reconnect to the server.
  19455.                      Optional arguments are db and host.
  19456.      edit    (\e)    Edit command with $EDITOR.
  19457.      ego     (\G)    Send command to mysql server,
  19458.                      display result vertically.
  19459.      exit    (\q)    Exit mysql. Same as quit.
  19460.      go      (\g)    Send command to mysql server.
  19461.      nopager (\n)    Disable pager, print to stdout.
  19462.      notee   (\t)    Don't write into outfile.
  19463.      pager   (\P)    Set PAGER [to_pager].
  19464.                      Print the query results via PAGER.
  19465.      print   (\p)    Print current command.
  19466.      prompt  (\R)    Change your mysql prompt.
  19467.      quit    (\q)    Quit mysql.
  19468.      rehash  (\#)    Rebuild completion hash.
  19469.      source  (\.)    Execute a SQL script file.
  19470.                      Takes a file name as an argument.
  19471.      status  (\s)    Get status information from the server.
  19472.      tee     (\T)    Set outfile [to_outfile].
  19473.                      Append everything into given outfile.
  19474.      use     (\u)    Use another database.
  19475.                      Takes database name as argument.
  19476.  
  19477. The `pager' command works only in Unix.
  19478.  
  19479. The `status' command gives you some information about the connection
  19480. and the server you are using. If you are running in the
  19481. `--safe-updates' mode, `status' will also print the values for the
  19482. `mysql' variables that affect your queries.
  19483.  
  19484. A useful startup option for beginners (introduced in MySQL Version
  19485. 3.23.11) is `--safe-updates' (or `--i-am-a-dummy' for users that has at
  19486. some time done a `DELETE FROM table_name' but forgot the `WHERE'
  19487. clause).  When using this option, `mysql' sends the following command
  19488. to the MySQL server when opening the connection:
  19489.  
  19490.      SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#,
  19491.          SQL_MAX_JOIN_SIZE=#max_join_size#"
  19492.  
  19493. where `#select_limit#' and `#max_join_size#' are variables that can be
  19494. set from the `mysql' command-line. *Note `SET': SET OPTION.
  19495.  
  19496. The effect of the above is:
  19497.  
  19498.    * You are not allowed to do an `UPDATE' or `DELETE' statement if you
  19499.      don't have a key constraint in the `WHERE' part. One can, however,
  19500.      force an `UPDATE/DELETE' by using `LIMIT':
  19501.           UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1;
  19502.  
  19503.    * All big results are automatically limited to `#select_limit#' rows.
  19504.  
  19505.    * `SELECT's that will probably need to examine more than
  19506.      `#max_join_size' row combinations will be aborted.
  19507.  
  19508. Some useful hints about the `mysql' client:
  19509.  
  19510. Some data is much more readable when displayed vertically, instead of
  19511. the usual horizontal box type output. For example longer text, which
  19512. includes new lines, is often much easier to be read with vertical
  19513. output.
  19514.  
  19515.      mysql> SELECT * FROM mails WHERE LENGTH(txt) < 300 lIMIT 300,1\G
  19516.      *************************** 1. row ***************************
  19517.        msg_nro: 3068
  19518.           date: 2000-03-01 23:29:50
  19519.      time_zone: +0200
  19520.      mail_from: Monty
  19521.          reply: monty@no.spam.com
  19522.        mail_to: "Thimble Smith" <tim@no.spam.com>
  19523.            sbj: UTF-8
  19524.            txt: >>>>> "Thimble" == Thimble Smith writes:
  19525.      
  19526.      Thimble> Hi.  I think this is a good idea.  Is anyone familiar with UTF-8
  19527.      Thimble> or Unicode? Otherwise, I'll put this on my TODO list and see what
  19528.      Thimble> happens.
  19529.      
  19530.      Yes, please do that.
  19531.      
  19532.      Regards,
  19533.      Monty
  19534.           file: inbox-jani-1
  19535.           hash: 190402944
  19536.      1 row in set (0.09 sec)
  19537.  
  19538. For logging, you can use the `tee' option. The `tee' can be started
  19539. with option `--tee=...', or from the command-line interactively with
  19540. command `tee'. All the data displayed on the screen will also be
  19541. appended into a given file. This can be very useful for debugging
  19542. purposes also. The `tee' can be disabled from the command-line with
  19543. command `notee'. Executing `tee' again starts logging again. Without a
  19544. parameter the previous file will be used. Note that `tee' will flush
  19545. the results into the file after each command, just before the
  19546. command-line appears again waiting for the next command.
  19547.  
  19548. Browsing, or searching the results in the interactive mode in Unix less,
  19549. more, or any other similar program, is now possible with option
  19550. `--pager[=...]'. Without argument, `mysql' client will look for
  19551. environment variable PAGER and set `pager' to that.  `pager' can be
  19552. started from the interactive command-line with command `pager' and
  19553. disabled with command `nopager'.  The command takes an argument
  19554. optionally and the `pager' will be set to that. Command `pager' can be
  19555. called without an argument, but this requires that the option `--pager'
  19556. was used, or the `pager' will default to stdout. `pager' works only in
  19557. Unix, since it uses the popen() function, which doesn't exist in
  19558. Windows. In Windows, the `tee' option can be used instead, although it
  19559. may not be as handy as `pager' can be in some situations.
  19560.  
  19561. A few tips about `pager':
  19562.    * You can use it to write to a file:
  19563.           mysql> pager cat > /tmp/log.txt
  19564.      and the results will only go to a file. You can also pass any
  19565.      options for the programs that you want to use with the `pager':
  19566.           mysql> pager less -n -i -S
  19567.  
  19568.    * From the above do note the option '-S'. You may find it very
  19569.      useful when browsing the results; try the option with horizontal
  19570.      output (end commands with '\g', or ';') and with vertical output
  19571.      (end commands with '\G'). Sometimes a very wide result set is hard
  19572.      to be read from the screen, with option -S to less you can browse
  19573.      the results within the interactive less from left to right,
  19574.      preventing lines longer than your screen from being continued to
  19575.      the next line. This can make the result set much more readable.
  19576.      You can swith the mode between on and off within the interactive
  19577.      less with '-S'. See the 'h' for more help about less.
  19578.  
  19579.    * You can combine very complex ways to handle the results, for
  19580.      example the following would send the results to two files in two
  19581.      different directories, on two different hard-disks mounted on /dr1
  19582.      and /dr2, yet let the results still be seen on the screen via less:
  19583.           mysql> pager cat | tee /dr1/tmp/res.txt | \
  19584.           tee /dr2/tmp/res2.txt | less -n -i -S
  19585.  
  19586.  
  19587. You can also combine the two functions above; have the `tee' enabled,
  19588. `pager' set to 'less' and you will be able to browse the results in
  19589. unix 'less' and still have everything appended into a file the same
  19590. time. The difference between Unix `tee' used with the `pager' and the
  19591. `mysql' client in-built `tee', is that the in-built `tee' works even if
  19592. you don't have the Unix `tee' available. The in-built `tee' also logs
  19593. everything that is printed on the screen, where the Unix `tee' used
  19594. with `pager' doesn't log quite that much. Last, but not least, the
  19595. interactive `tee' is more handy to switch on and off, when you want to
  19596. log something into a file, but want to be able to turn the feature off
  19597. sometimes.
  19598.  
  19599. From MySQL version 4.0.2 it is possible to change the prompt in the
  19600. `mysql' command-line client.
  19601.  
  19602. You can use the following prompt options:
  19603. *Option**Description*
  19604. \v      mysqld version
  19605. \d      database in use
  19606. \h      host connected to
  19607. \p      port connected on
  19608. \u      username
  19609. \U      full username@host
  19610. \\      `\'
  19611. \n      new line break
  19612. \t      tab
  19613. \       space
  19614. \_      space
  19615. \R      military hour time (0-23)
  19616. \r      standard hour time (1-12)
  19617. \m      minutes
  19618. \y      two digit year
  19619. \Y      four digit year
  19620. \D      full date format
  19621. \s      seconds
  19622. \w      day of the week in three letter
  19623.         format (Mon, Tue, ...)
  19624. \P      am/pm
  19625. \o      month in number format
  19626. \O      month in three letter format (Jan,
  19627.         Feb, ...)
  19628. \c      counter that counts up for each
  19629.         command you do
  19630.  
  19631. `\' followed by any other letter just becomes that letter.
  19632.  
  19633. You may set the prompt in the following places:
  19634.  
  19635. *Environment Variable*
  19636.      You may set the `MYSQL_PS1' environment variable to a prompt
  19637.      string.  For example:
  19638.  
  19639.           shell> export MYSQL_PS1="(\u@\h) [\d]> "
  19640.  
  19641. *`my.cnf'*
  19642.  
  19643. *`.my.cnf'*
  19644.      You may set the `prompt' option in any MySQL configuration file,
  19645.      in the `mysql' group.  For example:
  19646.  
  19647.           [mysql]
  19648.           prompt=(\u@\h) [\d]>\_
  19649.  
  19650. *Command Line*
  19651.      You may set the `--prompt' option on the command line to `mysql'.
  19652.      For example:
  19653.  
  19654.           shell> mysql --prompt="(\u@\h) [\d]> "
  19655.           
  19656.           (user@host) [database]>
  19657.  
  19658. *Interactively*
  19659.      You may also use the `prompt' (or `\R') command to change your
  19660.      prompt interactively.  For example:
  19661.  
  19662.           mysql> prompt (\u@\h) [\d]>\_
  19663.           PROMPT set to '(\u@\h) [\d]>\_'
  19664.           (user@host) [database]>
  19665.           (user@host) [database]> prompt
  19666.           Returning to default PROMPT of mysql>
  19667.           mysql>
  19668.  
  19669. `mysqladmin', Administrating a MySQL Server
  19670. -------------------------------------------
  19671.  
  19672. A utility for performing administrative operations. The syntax is:
  19673.  
  19674.      shell> mysqladmin [OPTIONS] command [command-option] command ...
  19675.  
  19676. You can get a list of the options your version of `mysqladmin' supports
  19677. by executing `mysqladmin --help'.
  19678.  
  19679. The current `mysqladmin' supports the following commands:
  19680.  
  19681. `create databasename'
  19682.      Create a new database.
  19683.  
  19684. `drop databasename'
  19685.      Delete a database and all its tables.
  19686.  
  19687. `extended-status'
  19688.      Gives an extended status message from the server.
  19689.  
  19690. `flush-hosts'
  19691.      Flush all cached hosts.
  19692.  
  19693. `flush-logs'
  19694.      Flush all logs.
  19695.  
  19696. `flush-tables'
  19697.      Flush all tables.
  19698.  
  19699. `flush-privileges'
  19700.      Reload grant tables (same as reload).
  19701.  
  19702. `kill id,id,...'
  19703.      Kill mysql threads.
  19704.  
  19705. `password'
  19706.      Set a new password. Change old password to new-password.
  19707.  
  19708. `ping'
  19709.      Check if mysqld is alive.
  19710.  
  19711. `processlist'
  19712.      Show list of active threads in server.
  19713.  
  19714. `reload'
  19715.      Reload grant tables.
  19716.  
  19717. `refresh'
  19718.      Flush all tables and close and open logfiles.
  19719.  
  19720. `shutdown'
  19721.      Take server down.
  19722.  
  19723. `slave-start'
  19724.      Start slave replication thread.
  19725.  
  19726. `slave-stop'
  19727.      Stop slave replication thread.
  19728.  
  19729. `status'
  19730.      Gives a short status message from the server.
  19731.  
  19732. `variables'
  19733.      Prints variables available.
  19734.  
  19735. `version'
  19736.      Get version info from server.
  19737.  
  19738. All commands can be shortened to their unique prefix.  For example:
  19739.  
  19740.      shell> mysqladmin proc stat
  19741.      +----+-------+-----------+----+-------------+------+-------+------+
  19742.      | Id | User  | Host      | db | Command     | Time | State | Info |
  19743.      +----+-------+-----------+----+-------------+------+-------+------+
  19744.      | 6  | monty | localhost |    | Processlist | 0    |       |      |
  19745.      +----+-------+-----------+----+-------------+------+-------+------+
  19746.      Uptime: 10077  Threads: 1  Questions: 9  Slow queries: 0
  19747.      Opens: 6 Flush tables: 1  Open tables: 2
  19748.      Memory in use: 1092K  Max memory used: 1116K
  19749.  
  19750. The `mysqladmin status' command result has the following columns:
  19751.  
  19752. *Column*       *Description*
  19753. Uptime         Number of seconds the MySQL server has been up.
  19754. Threads        Number of active threads (clients).
  19755. Questions      Number of questions from clients since
  19756.                `mysqld' was started.
  19757. Slow queries   Queries that have taken more than
  19758.                `long_query_time' seconds. *Note Slow query
  19759.                log::.
  19760. Opens          How many tables `mysqld' has opened.
  19761. Flush tables   Number of `flush ...', `refresh', and `reload'
  19762.                commands.
  19763. Open tables    Number of tables that are open now.
  19764. Memory in use  Memory allocated directly by the `mysqld' code
  19765.                (only available when MySQL is compiled with
  19766.                -with-debug=full).
  19767. Max memory     Maximum memory allocated directly by the
  19768. used           `mysqld' code (only available when MySQL is
  19769.                compiled with -with-debug=full).
  19770.  
  19771. If you do `mysqladmin shutdown' on a socket (in other words, on a the
  19772. computer where `mysqld' is running), `mysqladmin' will wait until the
  19773. MySQL `pid-file' is removed to ensure that the `mysqld' server has
  19774. stopped properly.
  19775.  
  19776. Using `mysqlcheck' for Table Maintenance and Crash Recovery
  19777. -----------------------------------------------------------
  19778.  
  19779. Since MySQL version 3.23.38 you will be able to use a new checking and
  19780. repairing tool for `MyISAM' tables. The difference to `myisamchk' is
  19781. that `mysqlcheck' should be used when the `mysqld' server is running,
  19782. where as `myisamchk' should be used when it is not. The benefit is that
  19783. you no longer have to take the server down for checking or repairing
  19784. your tables.
  19785.  
  19786. `mysqlcheck' uses MySQL server commands `CHECK', `REPAIR', `ANALYZE'
  19787. and `OPTIMIZE' in a convenient way for the user.
  19788.  
  19789. There are three alternative ways to invoke `mysqlcheck':
  19790.  
  19791.      shell> mysqlcheck [OPTIONS] database [tables]
  19792.      shell> mysqlcheck [OPTIONS] --databases DB1 [DB2 DB3...]
  19793.      shell> mysqlcheck [OPTIONS] --all-databases
  19794.  
  19795. So it can be used in a similar way as `mysqldump' when it comes to what
  19796. databases and tables you want to choose.
  19797.  
  19798. `mysqlcheck' does have a special feature compared to the other clients;
  19799. the default behaviour, checking tables (-c), can be changed by renaming
  19800. the binary. So if you want to have a tool that repairs tables by
  19801. default, you should just copy `mysqlcheck' to your harddrive with a new
  19802. name, `mysqlrepair', or alternatively make a symbolic link to
  19803. `mysqlrepair' and name the symbolic link as `mysqlrepair'. If you
  19804. invoke `mysqlrepair' now, it will repair tables by default.
  19805.  
  19806. The names that you can use to change `mysqlcheck' default behaviour are
  19807. here:
  19808.  
  19809.      mysqlrepair:   The default option will be -r
  19810.      mysqlanalyze:  The default option will be -a
  19811.      mysqloptimize: The default option will be -o
  19812.  
  19813. The options available for `mysqlcheck' are listed here, please check
  19814. what your version supports with `mysqlcheck --help'.
  19815.  
  19816. `-A, --all-databases'
  19817.      Check all the databases. This will be same as -databases with all
  19818.      databases selected
  19819.  
  19820. `-1, --all-in-1'
  19821.      Instead of making one query for each table, execute all queries in
  19822.      1 query separately for each database. Table names will be in a
  19823.      comma separated list.
  19824.  
  19825. `-a, --analyze'
  19826.      Analyse given tables.
  19827.  
  19828. `--auto-repair'
  19829.      If a checked table is corrupted, automatically fix it. Repairing
  19830.      will be done after all tables have been checked, if corrupted ones
  19831.      were found.
  19832.  
  19833. `-#, --debug=...'
  19834.      Output debug log. Often this is 'd:t:o,filename'
  19835.  
  19836. `--character-sets-dir=...'
  19837.      Directory where character sets are
  19838.  
  19839. `-c, --check'
  19840.      Check table for errors
  19841.  
  19842. `-C, --check-only-changed'
  19843.      Check only tables that have changed since last check or haven't
  19844.      been closed properly.
  19845.  
  19846. `--compress'
  19847.      Use compression in server/client protocol.
  19848.  
  19849. `-?, --help'
  19850.      Display this help message and exit.
  19851.  
  19852. `-B, --databases'
  19853.      To check several databases. Note the difference in usage; in this
  19854.      case no tables are given. All name arguments are regarded as
  19855.      database names.
  19856.  
  19857. `--default-character-set=...'
  19858.      Set the default character set
  19859.  
  19860. `-F, --fast'
  19861.      Check only tables that hasn't been closed properly
  19862.  
  19863. `-f, --force'
  19864.      Continue even if we get an sql-error.
  19865.  
  19866. `-e, --extended'
  19867.      If you are using this option with CHECK TABLE, it will ensure that
  19868.      the table is 100 percent consistent, but will take a long time.
  19869.  
  19870.      If you are using this option with REPAIR TABLE, it will run an
  19871.      extended repair on the table, which may not only take a long time
  19872.      to execute, but may produce a lot of garbage rows also!
  19873.  
  19874. `-h, --host=...'
  19875.      Connect to host.
  19876.  
  19877. `-m, --medium-check'
  19878.      Faster than extended-check, but only finds 99.99 percent of all
  19879.      errors. Should be good enough for most cases.
  19880.  
  19881. `-o, --optimize'
  19882.      Optimise table
  19883.  
  19884. `-p, --password[=...]'
  19885.      Password to use when connecting to server. If password is not given
  19886.      it's solicited on the tty.
  19887.  
  19888. `-P, --port=...'
  19889.      Port number to use for connection.
  19890.  
  19891. `-q, --quick'
  19892.      If you are using this option with CHECK TABLE, it prevents the
  19893.      check from scanning the rows to check for wrong links. This is the
  19894.      fastest check.
  19895.  
  19896.      If you are using this option with REPAIR TABLE, it will try to
  19897.      repair only the index tree. This is the fastest repair method for
  19898.      a table.
  19899.  
  19900. `-r, --repair'
  19901.      Can fix almost anything except unique keys that aren't unique.
  19902.  
  19903. `-s, --silent'
  19904.      Print only error messages.
  19905.  
  19906. `-S, --socket=...'
  19907.      Socket file to use for connection.
  19908.  
  19909. `--tables'
  19910.      Overrides option -databases (-B).
  19911.  
  19912. `-u, --user=#'
  19913.      User for login if not current user.
  19914.  
  19915. `-v, --verbose'
  19916.      Print info about the various stages.
  19917.  
  19918. `-V, --version'
  19919.      Output version information and exit.
  19920.  
  19921. `mysqldump', Dumping Table Structure and Data
  19922. ---------------------------------------------
  19923.  
  19924. Utility to dump a database or a collection of database for backup or for
  19925. transferring the data to another SQL server (not necessarily a MySQL
  19926. server).  The dump will contain SQL statements to create the table
  19927. and/or populate the table.
  19928.  
  19929. If you are doing a backup on the server, you should consider using the
  19930. `mysqlhotcopy' instead. *Note `mysqlhotcopy': mysqlhotcopy.
  19931.  
  19932.      shell> mysqldump [OPTIONS] database [tables]
  19933.      OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
  19934.      OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
  19935.  
  19936. If you don't give any tables or use the `--databases' or
  19937. `--all-databases', the whole database(s) will be dumped.
  19938.  
  19939. You can get a list of the options your version of `mysqldump' supports
  19940. by executing `mysqldump --help'.
  19941.  
  19942. Note that if you run `mysqldump' without `--quick' or `--opt',
  19943. `mysqldump' will load the whole result set into memory before dumping
  19944. the result.  This will probably be a problem if you are dumping a big
  19945. database.
  19946.  
  19947. Note that if you are using a new copy of the `mysqldump' program and
  19948. you are going to do a dump that will be read into a very old MySQL
  19949. server, you should not use the `--opt' or `-e' options.
  19950.  
  19951. `mysqldump' supports the following options:
  19952.  
  19953. `--add-locks'
  19954.      Add `LOCK TABLES' before and `UNLOCK TABLE' after each table dump.
  19955.      (To get faster inserts into MySQL.)
  19956.  
  19957. `--add-drop-table'
  19958.      Add a `drop table' before each create statement.
  19959.  
  19960. `-A, --all-databases'
  19961.      Dump all the databases. This will be same as `--databases' with all
  19962.      databases selected.
  19963.  
  19964. `-a, --all'
  19965.      Include all MySQL-specific create options.
  19966.  
  19967. `--allow-keywords'
  19968.      Allow creation of column names that are keywords.  This works by
  19969.      prefixing each column name with the table name.
  19970.  
  19971. `-c, --complete-insert'
  19972.      Use complete insert statements (with column names).
  19973.  
  19974. `-C, --compress'
  19975.      Compress all information between the client and the server if both
  19976.      support compression.
  19977.  
  19978. `-B, --databases'
  19979.      To dump several databases. Note the difference in usage. In this
  19980.      case no tables are given. All name arguments are regarded as
  19981.      database names.  `USE db_name;' will be included in the output
  19982.      before each new database.
  19983.  
  19984. `--delayed'
  19985.      Insert rows with the `INSERT DELAYED' command.
  19986.  
  19987. `-e, --extended-insert'
  19988.      Use the new multiline `INSERT' syntax. (Gives more compact and
  19989.      faster inserts statements.)
  19990.  
  19991. `-#, --debug[=option_string]'
  19992.      Trace usage of the program (for debugging).
  19993.  
  19994. `--help'
  19995.      Display a help message and exit.
  19996.  
  19997. `--fields-terminated-by=...'
  19998. `--fields-enclosed-by=...'
  19999. `--fields-optionally-enclosed-by=...'
  20000. `--fields-escaped-by=...'
  20001. `--lines-terminated-by=...'
  20002.      These options are used with the `-T' option and have the same
  20003.      meaning as the corresponding clauses for `LOAD DATA INFILE'.
  20004.      *Note `LOAD DATA': LOAD DATA.
  20005.  
  20006. `-F, --flush-logs'
  20007.      Flush log file in the MySQL server before starting the dump.
  20008.  
  20009. `-f, --force,'
  20010.      Continue even if we get a SQL error during a table dump.
  20011.  
  20012. `-h, --host=..'
  20013.      Dump data from the MySQL server on the named host. The default host
  20014.      is `localhost'.
  20015.  
  20016. `-l, --lock-tables.'
  20017.      Lock all tables before starting the dump.  The tables are locked
  20018.      with `READ LOCAL' to allow concurrent inserts in the case of
  20019.      `MyISAM' tables.
  20020.  
  20021.      Please note that when dumping multiple databases, `--lock-tables'
  20022.      will lock tables for each database separately. So using this
  20023.      option will not guarantee your tables will be logically consistent
  20024.      between databases.  Tables in different databases may be dumped in
  20025.      completely different states.
  20026.  
  20027. `-K, --disable-keys'
  20028.      `/*!40000 ALTER TABLE tb_name DISABLE KEYS */;' and `/*!40000
  20029.      ALTER TABLE tb_name ENABLE KEYS */;' will be put in the output.
  20030.      This will make loading the data into a MySQL 4.0 server faster as
  20031.      the indexes are created after all data are inserted.
  20032.  
  20033. `-n, --no-create-db'
  20034.      `CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be
  20035.      put in the output. The above line will be added otherwise, if a
  20036.      `--databases' or `--all-databases' option was given.
  20037.  
  20038. `-t, --no-create-info'
  20039.      Don't write table creation information (the `CREATE TABLE'
  20040.      statement).
  20041.  
  20042. `-d, --no-data'
  20043.      Don't write any row information for the table.  This is very
  20044.      useful if you just want to get a dump of the structure for a table!
  20045.  
  20046. `--opt'
  20047.      Same as `--quick --add-drop-table --add-locks --extended-insert
  20048.      --lock-tables'.  Should give you the fastest possible dump for
  20049.      reading into a MySQL server.
  20050.  
  20051. `-pyour_pass, --password[=your_pass]'
  20052.      The password to use when connecting to the server. If you specify
  20053.      no `=your_pass' part, `mysqldump' you will be prompted for a
  20054.      password.
  20055.  
  20056. `-P port_num, --port=port_num'
  20057.      The TCP/IP port number to use for connecting to a host.  (This is
  20058.      used for connections to hosts other than `localhost', for which
  20059.      Unix sockets are used.)
  20060.  
  20061. `-q, --quick'
  20062.      Don't buffer query, dump directly to stdout. Uses
  20063.      `mysql_use_result()' to do this.
  20064.  
  20065. `-Q, --quote-names'
  20066.      Quote table and column names within ``' characters.
  20067.  
  20068. `-r, --result-file=...'
  20069.      Direct output to a given file. This option should be used in MSDOS,
  20070.      because it prevents new line `\n' from being converted to `\n\r'
  20071.      (new line + carriage return).
  20072.  
  20073. `--single-transaction'
  20074.      This option issues a `BEGIN' SQL command before dumping data from
  20075.      server. It is mostly useful with `InnoDB' tables and
  20076.      `READ_COMMITTED' transaction isolation level, as in this mode it
  20077.      will dump the consistent state of the database at the time then
  20078.      `BEGIN' was issued without blocking any applications.
  20079.  
  20080.      When using this option you should keep in mind that only
  20081.      transactional tables will be dumped in a consistent state, e.g.,
  20082.      any `MyISAM' or `HEAP' tables dumped while using this option may
  20083.      still change state.
  20084.  
  20085.      The `--single-transaction' option was added in version 4.0.2.
  20086.      This option is mutually exclusive with the `--lock-tables' option
  20087.      as `LOCK TABLES' already commits a previous transaction internally.
  20088.  
  20089. `-S /path/to/socket, --socket=/path/to/socket'
  20090.      The socket file to use when connecting to `localhost' (which is the
  20091.      default host).
  20092.  
  20093. `--tables'
  20094.      Overrides option -databases (-B).
  20095.  
  20096. `-T, --tab=path-to-some-directory'
  20097.      Creates a `table_name.sql' file, that contains the SQL CREATE
  20098.      commands, and a `table_name.txt' file, that contains the data, for
  20099.      each give table.  The format of the `.txt' file is made according
  20100.      to the `--fields-xxx' and `--lines--xxx' options.  *Note*: This
  20101.      option only works if `mysqldump' is run on the same machine as the
  20102.      `mysqld' daemon, and the user/group that `mysqld' is running as
  20103.      (normally user `mysql', group `mysql') needs to have permission to
  20104.      create/write a file at the location you specify.
  20105.  
  20106. `-u user_name, --user=user_name'
  20107.      The MySQL user name to use when connecting to the server. The
  20108.      default value is your Unix login name.
  20109.  
  20110. `-O var=option, --set-variable var=option'
  20111.      Set the value of a variable.  The possible variables are listed
  20112.      below.  Please note that `--set-variable' is deprecated since
  20113.      MySQL 4.0, just use `--var=option' on its own.
  20114.  
  20115. `-v, --verbose'
  20116.      Verbose mode.  Print out more information on what the program does.
  20117.  
  20118. `-V, --version'
  20119.      Print version information and exit.
  20120.  
  20121. `-w, --where='where-condition''
  20122.      Dump only selected records. Note that quotes are mandatory:
  20123.  
  20124. `-X, --xml'
  20125.      Dumps a database as well formed XML
  20126.  
  20127. `-x, --first-slave'
  20128.      Locks all tables across all databases.
  20129.  
  20130.           "--where=user='jimf'" "-wuserid>1" "-wuserid<1"
  20131.  
  20132. `-O net_buffer_length=#, where # < 16M'
  20133.      When creating multi-row-insert statements (as with option
  20134.      `--extended-insert' or `--opt'), `mysqldump' will create rows up
  20135.      to `net_buffer_length' length. If you increase this variable, you
  20136.      should also ensure that the `max_allowed_packet' variable in the
  20137.      MySQL server is bigger than the `net_buffer_length'.
  20138.  
  20139. The most normal use of `mysqldump' is probably for making a backup of
  20140. whole databases. *Note Backup::.
  20141.  
  20142.      mysqldump --opt database > backup-file.sql
  20143.  
  20144. You can read this back into MySQL with:
  20145.  
  20146.      mysql database < backup-file.sql
  20147.  
  20148. or
  20149.  
  20150.      mysql -e "source /patch-to-backup/backup-file.sql" database
  20151.  
  20152. However, it's also very useful to populate another MySQL server with
  20153. information from a database:
  20154.  
  20155.      mysqldump --opt database | mysql ---host=remote-host -C database
  20156.  
  20157. It is possible to dump several databases with one command:
  20158.  
  20159.      mysqldump --databases database1 [database2 ...] > my_databases.sql
  20160.  
  20161. If all the databases are wanted, one can use:
  20162.  
  20163.      mysqldump --all-databases > all_databases.sql
  20164.  
  20165. `mysqlhotcopy', Copying MySQL Databases and Tables
  20166. --------------------------------------------------
  20167.  
  20168. `mysqlhotcopy' is a Perl script that uses `LOCK TABLES', `FLUSH TABLES'
  20169. and `cp' or `scp' to quickly make a backup of a database.  It's the
  20170. fastest way to make a backup of the database or single tables, but it
  20171. can only be run on the same machine where the database directories are.
  20172.  
  20173.      mysqlhotcopy db_name [/path/to/new_directory]
  20174.      
  20175.      mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
  20176.      
  20177.      mysqlhotcopy db_name./regex/
  20178.  
  20179. `mysqlhotcopy' supports the following options:
  20180.  
  20181. `-?, --help'
  20182.      Display a help screen and exit
  20183.  
  20184. `-u, --user=#'
  20185.      User for database login
  20186.  
  20187. `-p, --password=#'
  20188.      Password to use when connecting to server
  20189.  
  20190. `-P, --port=#'
  20191.      Port to use when connecting to local server
  20192.  
  20193. `-S, --socket=#'
  20194.      Socket to use when connecting to local server
  20195.  
  20196. `--allowold'
  20197.      Don't abort if target already exists (rename it _old)
  20198.  
  20199. `--keepold'
  20200.      Don't delete previous (now renamed) target when done
  20201.  
  20202. `--noindices'
  20203.      Don't include full index files in copy to make the backup smaller
  20204.      and faster The indexes can later be reconstructed with `myisamchk
  20205.      -rq.'.
  20206.  
  20207. `--method=#'
  20208.      Method for copy (`cp' or `scp').
  20209.  
  20210. `-q, --quiet'
  20211.      Be silent except for errors
  20212.  
  20213. `--debug'
  20214.      Enable debug
  20215.  
  20216. `-n, --dryrun'
  20217.      Report actions without doing them
  20218.  
  20219. `--regexp=#'
  20220.      Copy all databases with names matching regexp
  20221.  
  20222. `--suffix=#'
  20223.      Suffix for names of copied databases
  20224.  
  20225. `--checkpoint=#'
  20226.      Insert checkpoint entry into specified db.table
  20227.  
  20228. `--flushlog'
  20229.      Flush logs once all tables are locked.
  20230.  
  20231. `--tmpdir=#'
  20232.      Temporary directory (instead of /tmp).
  20233.  
  20234. You can use `perldoc mysqlhotcopy' to get more complete documentation
  20235. for `mysqlhotcopy'.
  20236.  
  20237. `mysqlhotcopy' reads the groups `[client]' and  `[mysqlhotcopy]' from
  20238. the option files.
  20239.  
  20240. To be able to execute `mysqlhotcopy' you need write access to the
  20241. backup directory, the `SELECT' privilege for the tables you are about to
  20242. copy and the MySQL `RELOAD' privilege (to be able to execute `FLUSH
  20243. TABLES').
  20244.  
  20245. `mysqlimport', Importing Data from Text Files
  20246. ---------------------------------------------
  20247.  
  20248. `mysqlimport' provides a command-line interface to the `LOAD DATA
  20249. INFILE' SQL statement.  Most options to `mysqlimport' correspond
  20250. directly to the same options to `LOAD DATA INFILE'.  *Note `LOAD DATA':
  20251. LOAD DATA.
  20252.  
  20253. `mysqlimport' is invoked like this:
  20254.  
  20255.      shell> mysqlimport [options] database textfile1 [textfile2 ...]
  20256.  
  20257. For each text file named on the command-line, `mysqlimport' strips any
  20258. extension from the filename and uses the result to determine which
  20259. table to import the file's contents into.  For example, files named
  20260. `patient.txt', `patient.text', and `patient' would all be imported into
  20261. a table named `patient'.
  20262.  
  20263. `mysqlimport' supports the following options:
  20264.  
  20265. `-c, --columns=...'
  20266.      This option takes a comma-separated list of field names as an
  20267.      argument.  The field list is used to create a proper `LOAD DATA
  20268.      INFILE' command, which is then passed to MySQL. *Note `LOAD DATA':
  20269.      LOAD DATA.
  20270.  
  20271. `-C, --compress'
  20272.      Compress all information between the client and the server if both
  20273.      support compression.
  20274.  
  20275. `-#, --debug[=option_string]'
  20276.      Trace usage of the program (for debugging).
  20277.  
  20278. `-d, --delete'
  20279.      Empty the table before importing the text file.
  20280.  
  20281. `--fields-terminated-by=...'
  20282. `--fields-enclosed-by=...'
  20283. `--fields-optionally-enclosed-by=...'
  20284. `--fields-escaped-by=...'
  20285. `--lines-terminated-by=...'
  20286.      These options have the same meaning as the corresponding clauses
  20287.      for `LOAD DATA INFILE'. *Note `LOAD DATA': LOAD DATA.
  20288.  
  20289. `-f, --force'
  20290.      Ignore errors.  For example, if a table for a text file doesn't
  20291.      exist, continue processing any remaining files.  Without `--force',
  20292.      `mysqlimport' exits if a table doesn't exist.
  20293.  
  20294. `--help'
  20295.      Display a help message and exit.
  20296.  
  20297. `-h host_name, --host=host_name'
  20298.      Import data to the MySQL server on the named host. The default host
  20299.      is `localhost'.
  20300.  
  20301. `-i, --ignore'
  20302.      See the description for the `--replace' option.
  20303.  
  20304. `-l, --lock-tables'
  20305.      Lock *all* tables for writing before processing any text files.
  20306.      This ensures that all tables are synchronised on the server.
  20307.  
  20308. `-L, --local'
  20309.      Read input files from the client.  By default, text files are
  20310.      assumed to be on the server if you connect to `localhost' (which
  20311.      is the default host).
  20312.  
  20313. `-pyour_pass, --password[=your_pass]'
  20314.      The password to use when connecting to the server. If you specify
  20315.      no `=your_pass' part, `mysqlimport' you will be prompted for a
  20316.      password.
  20317.  
  20318. `-P port_num, --port=port_num'
  20319.      The TCP/IP port number to use for connecting to a host.  (This is
  20320.      used for connections to hosts other than `localhost', for which
  20321.      Unix sockets are used.)
  20322.  
  20323. `-r, --replace'
  20324.      The `--replace' and `--ignore' options control handling of input
  20325.      records that duplicate existing records on unique key values.  If
  20326.      you specify `--replace', new rows replace existing rows that have
  20327.      the same unique key value. If you specify `--ignore', input rows
  20328.      that duplicate an existing row on a unique key value are skipped.
  20329.      If you don't specify either option, an error occurs when a
  20330.      duplicate key value is found, and the rest of the text file is
  20331.      ignored.
  20332.  
  20333. `-s, --silent'
  20334.      Silent mode.  Write output only when errors occur.
  20335.  
  20336. `-S /path/to/socket, --socket=/path/to/socket'
  20337.      The socket file to use when connecting to `localhost' (which is the
  20338.      default host).
  20339.  
  20340. `-u user_name, --user=user_name'
  20341.      The MySQL user name to use when connecting to the server. The
  20342.      default value is your Unix login name.
  20343.  
  20344. `-v, --verbose'
  20345.      Verbose mode.  Print out more information what the program does.
  20346.  
  20347. `-V, --version'
  20348.      Print version information and exit.
  20349.  
  20350. Here is a sample run using `mysqlimport':
  20351.  
  20352.      $ mysql --version
  20353.      mysql  Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686)
  20354.      $ uname -a
  20355.      Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown
  20356.      $ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
  20357.      $ ed
  20358.      a
  20359.      100     Max Sydow
  20360.      101     Count Dracula
  20361.      .
  20362.      w imptest.txt
  20363.      32
  20364.      q
  20365.      $ od -c imptest.txt
  20366.      0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
  20367.      0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
  20368.      0000040
  20369.      $ mysqlimport --local test imptest.txt
  20370.      test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
  20371.      $ mysql -e 'SELECT * FROM imptest' test
  20372.      +------+---------------+
  20373.      | id   | n             |
  20374.      +------+---------------+
  20375.      |  100 | Max Sydow     |
  20376.      |  101 | Count Dracula |
  20377.      +------+---------------+
  20378.  
  20379. Showing Databases, Tables, and Columns
  20380. --------------------------------------
  20381.  
  20382. `mysqlshow' can be used to quickly look at which databases exist, their
  20383. tables, and the table's columns.
  20384.  
  20385. With the `mysql' program you can get the same information with the
  20386. `SHOW' commands.  *Note SHOW::.
  20387.  
  20388. `mysqlshow' is invoked like this:
  20389.  
  20390.      shell> mysqlshow [OPTIONS] [database [table [column]]]
  20391.  
  20392.    * If no database is given, all matching databases are shown.
  20393.  
  20394.    * If no table is given, all matching tables in the database are
  20395.      shown.
  20396.  
  20397.    * If no column is given, all matching columns and column types in
  20398.      the table are shown.
  20399.  
  20400. Note that in newer MySQL versions, you only see those
  20401. database/tables/columns for which you have some privileges.
  20402.  
  20403. If the last argument contains a shell or SQL wildcard (`*', `?', `%' or
  20404. `_') then only what's matched by the wildcard is shown.  If a database
  20405. contains underscore(s), those should be escaped with backslash (some
  20406. Unix shells will require two), in order to get tables / columns
  20407. properly. '*' are converted into SQL '%' wildcard and '?' into SQL '_'
  20408. wildcard.  This may cause some confusion when you try to display the
  20409. columns for a table with a `_' as in this case `mysqlshow' only shows
  20410. you the table names that match the pattern.  This is easily fixed by
  20411. adding an extra `%' last on the command-line (as a separate argument).
  20412.  
  20413. perror, Explaining Error Codes
  20414. ------------------------------
  20415.  
  20416. For most system errors MySQL will, in addition to a internal text
  20417. message, also print the system error code in one of the following
  20418. styles: `message ... (errno: #)' or `message ... (Errcode: #)'.
  20419.  
  20420. You can find out what the error code means by either examining the
  20421. documentation for your system or use the `perror' utility.
  20422.  
  20423. `perror' prints a description for a system error code, or an MyISAM/ISAM
  20424. storage engine (table handler) error code.
  20425.  
  20426. `perror' is invoked like this:
  20427.  
  20428.      shell> perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  20429.      
  20430.      Example:
  20431.      
  20432.      shell> perror 13 64
  20433.      Error code  13:  Permission denied
  20434.      Error code  64:  Machine is not on the network
  20435.  
  20436. Note that the error messages are mostly system dependent!
  20437.  
  20438. How to Run SQL Commands from a Text File
  20439. ----------------------------------------
  20440.  
  20441. The `mysql' client typically is used interactively, like this:
  20442.  
  20443.      shell> mysql database
  20444.  
  20445. However, it's also possible to put your SQL commands in a file and tell
  20446. `mysql' to read its input from that file.  To do so, create a text file
  20447. `text_file' that contains the commands you wish to execute.  Then
  20448. invoke `mysql' as shown here:
  20449.  
  20450.      shell> mysql database < text_file
  20451.  
  20452. You can also start your text file with a `USE db_name' statement.  In
  20453. this case, it is unnecessary to specify the database name on the command
  20454. line:
  20455.  
  20456.      shell> mysql < text_file
  20457.  
  20458. If you are already running `mysql', you can execute a SQL script file
  20459. using the `source' command:
  20460.  
  20461.      mysql> source filename;
  20462.  
  20463. For more information about batch mode, *Note Batch mode::.
  20464.  
  20465. The MySQL Log Files
  20466. ===================
  20467.  
  20468. MySQL has several different log files that can help you find out what's
  20469. going on inside `mysqld':
  20470.  
  20471. *Log file*     *Description*
  20472. The error log  Problems encountering starting, running or stopping
  20473.                `mysqld'.
  20474. The isam log   Logs all changes to the ISAM tables. Used only for
  20475.                debugging the isam code.
  20476. The query log  Established connections and executed queries.
  20477. The update     Deprecated: Stores all statements that changes data
  20478. log            
  20479. The binary     Stores all statements that changes something. Used also
  20480. log            for replication
  20481. The slow log   Stores all queries that took more than `long_query_time'
  20482.                to execute or didn't use indexes.
  20483.  
  20484. All logs can be found in the `mysqld' data directory.  You can force
  20485. `mysqld' to reopen the log files (or in some cases switch to a new log)
  20486. by executing `FLUSH LOGS'. *Note FLUSH::.
  20487.  
  20488. The Error Log
  20489. -------------
  20490.  
  20491. `mysqld' writes all errors to the stderr, which the `safe_mysqld'
  20492. script redirects to a file called `'hostname'.err'.  (On Windows,
  20493. `mysqld' writes this directly to `\mysql\data\mysql.err'.)
  20494.  
  20495. This contains information indicating when `mysqld' was started and
  20496. stopped and also any critical errors found when running.  If `mysqld'
  20497. dies unexpectedly and `safe_mysqld' needs to restart `mysqld',
  20498. `safe_mysqld' will write a `restarted mysqld' row in this file.  This
  20499. log also holds a warning if `mysqld' notices a table that needs to be
  20500. automatically checked or repaired.
  20501.  
  20502. On some operating systems, the error log will contain a stack trace for
  20503. where `mysqld' died. This can be used to find out where `mysqld' died.
  20504. *Note Using stack trace::.
  20505.  
  20506. The General Query Log
  20507. ---------------------
  20508.  
  20509. If you want to know what happens within `mysqld', you should start it
  20510. with `--log[=file]'.  This will log all connections and queries to the
  20511. log file (by default named `'hostname'.log').  This log can be very
  20512. useful when you suspect an error in a client and want to know exactly
  20513. what `mysqld' thought the client sent to it.
  20514.  
  20515. Older versions of the `mysql.server' script (from MySQL 3.23.4 to
  20516. 3.23.8) pass `safe_mysqld' a `--log' option (enable general query log).
  20517. If you need better performance when you start using MySQL in a
  20518. production environment, you can remove the `--log' option from
  20519. `mysql.server' or change it to `--log-bin'. *Note Binary log::.
  20520.  
  20521. The entries in this log are written as `mysqld' receives the questions.
  20522. This may be different from the order in which the statements are
  20523. executed.  This is in contrast to the update log and the binary log
  20524. which are written after the query is executed, but before any locks are
  20525. released.
  20526.  
  20527. The Update Log
  20528. --------------
  20529.  
  20530. *Note*: the update log is replaced by the binary log. *Note Binary
  20531. log::.  With this you can do anything that you can do with the update
  20532. log.
  20533.  
  20534. When started with the `--log-update[=file_name]' option, `mysqld'
  20535. writes a log file containing all SQL commands that update data. If no
  20536. filename is given, it defaults to the name of the host machine. If a
  20537. filename is given, but it doesn't contain a path, the file is written
  20538. in the data directory. If `file_name' doesn't have an extension,
  20539. `mysqld' will create log file names like so: `file_name.###', where
  20540. `###' is a number that is incremented each time you execute `mysqladmin
  20541. refresh', execute `mysqladmin flush-logs', execute the `FLUSH LOGS'
  20542. statement, or restart the server.
  20543.  
  20544. *Note*: for the above scheme to work, you must not create your own
  20545. files with the same filename as the update log + some extensions that
  20546. may be regarded as a number, in the directory used by the update log!
  20547.  
  20548. If you use the `--log' or `-l' options, `mysqld' writes a general log
  20549. with a filename of `hostname.log', and restarts and refreshes do not
  20550. cause a new log file to be generated (although it is closed and
  20551. reopened). In this case you can copy it (on Unix) by doing:
  20552.  
  20553.      mv hostname.log hostname-old.log
  20554.      mysqladmin flush-logs
  20555.      cp hostname-old.log to-backup-directory
  20556.      rm hostname-old.log
  20557.  
  20558. Update logging is smart because it logs only statements that really
  20559. update data. So an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  20560. rows is not written to the log. It even skips `UPDATE' statements that
  20561. set a column to the value it already has.
  20562.  
  20563. The update logging is done immediately after a query completes but
  20564. before any locks are released or any commit is done. This ensures that
  20565. the log will be logged in the execution order.
  20566.  
  20567. If you want to update a database from update log files, you could do the
  20568. following (assuming your update logs have names of the form
  20569. `file_name.###'):
  20570.  
  20571.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  20572.  
  20573. `ls' is used to get all the log files in the right order.
  20574.  
  20575. This can be useful if you have to revert to backup files after a crash
  20576. and you want to redo the updates that occurred between the time of the
  20577. backup and the crash.
  20578.  
  20579. The Binary Update Log
  20580. ---------------------
  20581.  
  20582. The intention is that the binary log should replace the update log, so
  20583. we recommend you to switch to this log format as soon as possible!
  20584.  
  20585. The binary log contains all information that is available in the update
  20586. log in a more efficient format. It also contains information about how
  20587. long each query took that updated the database.  It doesn't contain
  20588. queries that don't modify any data.  If you want to log all queries
  20589. (for example to find a problem query) you should use the general query
  20590. log. *Note Query log::.
  20591.  
  20592. The binary log is also used when you are replicating a slave from a
  20593. master.  *Note Replication::.
  20594.  
  20595. When started with the `--log-bin[=file_name]' option, `mysqld' writes a
  20596. log file containing all SQL commands that update data. If no file name
  20597. is given, it defaults to the name of the host machine followed by
  20598. `-bin'. If file name is given, but it doesn't contain a path, the file
  20599. is written in the data directory.
  20600.  
  20601. If you supply an extension to `--log-bin=filename.extension', the
  20602. extension will be silenty removed.
  20603.  
  20604. To the binary log filename `mysqld' will append an extension that is a
  20605. number that is incremented each time you execute `mysqladmin refresh',
  20606. execute `mysqladmin flush-logs', execute the `FLUSH LOGS' statement or
  20607. restart the server. A new binary log will also automatically be created
  20608. when it reaches `max_binlog_size'. You can delete all not active binary
  20609. log files with the `RESET MASTER' command. *Note RESET::.
  20610.  
  20611. You can use the following options to `mysqld' to affect what is logged
  20612. to the binary log:
  20613.  
  20614. *Option*                    *Description*
  20615. `binlog-do-db=database_name' Tells the master it should log updates for
  20616.                             the specified database, and exclude all
  20617.                             others not explicitly mentioned.  (Example:
  20618.                             `binlog-do-db=some_database')
  20619. `binlog-ignore-db=database_name' Tells the master that updates to the given
  20620.                             database should not be logged to the binary
  20621.                             log (Example:
  20622.                             `binlog-ignore-db=some_database')
  20623.  
  20624. To be able to know which different binary log files have been used,
  20625. `mysqld' will also create a binary log index file that contains the
  20626. name of all used binary log files. By default this has the same name as
  20627. the binary log file, with the extension `'.index''.  You can change the
  20628. name of the binary log index file with the `--log-bin-index=[filename]'
  20629. option.
  20630.  
  20631. If you are using replication, you should not delete old binary log
  20632. files until you are sure that no slave will ever need to use them.  One
  20633. way to do this is to do `mysqladmin flush-logs' once a day and then
  20634. remove any logs that are more than 3 days old.
  20635.  
  20636. You can examine the binary log file with the `mysqlbinlog' command.
  20637. For example, you can update a MySQL server from the binary log as
  20638. follows:
  20639.  
  20640.      shell> mysqlbinlog log-file | mysql -h server_name
  20641.  
  20642. You can also use the `mysqlbinlog' program to read the binary log
  20643. directly from a remote MySQL server!
  20644.  
  20645. `mysqlbinlog --help' will give you more information of how to use this
  20646. program!
  20647.  
  20648. If you are using `BEGIN [WORK]' or `SET AUTOCOMMIT=0', you must use the
  20649. MySQL binary log for backups instead of the old update log.
  20650.  
  20651. The binary logging is done immediately after a query completes but
  20652. before any locks are released or any commit is done. This ensures that
  20653. the log will be logged in the execution order.
  20654.  
  20655. Updates to non-transactional tables are stored in the binary log
  20656. immediately after execution.  For transactional tables such as `BDB' or
  20657. `InnoDB' tables, all updates (`UPDATE', `DELETE' or `INSERT') that
  20658. change tables are cached until a `COMMIT' command is sent to the
  20659. server. At this point `mysqld' writes the whole transaction to the
  20660. binary log before the `COMMIT' is executed.  very thread will, on
  20661. start, allocate a buffer of `binlog_cache_size' to buffer queries.  If
  20662. a query is bigger than this, the thread will open a temporary file to
  20663. store the transaction.  The temporary file will be deleted when the
  20664. thread ends.
  20665.  
  20666. The `max_binlog_cache_size' (default 4G) can be used to restrict the
  20667. total size used to cache a multi-query transaction.  If a transaction is
  20668. bigger than this it will fail and roll back.
  20669.  
  20670. If you are using the update or binary log, concurrent inserts will be
  20671. converted to normal inserts when using `CREATE ... SELECT' or `INSERT
  20672. ... SELECT'.  This is to ensure that you can recreate an exact copy of
  20673. your tables by applying the log on a backup.
  20674.  
  20675. The Slow Query Log
  20676. ------------------
  20677.  
  20678. When started with the `--log-slow-queries[=file_name]' option, `mysqld'
  20679. writes a log file containing all SQL commands that took more than
  20680. `long_query_time' to execute. The time to get the initial table locks
  20681. are not counted as execution time.
  20682.  
  20683. The slow query log is logged after the query is executed and after all
  20684. locks has been released. This may be different from the order in which
  20685. the statements are executed.
  20686.  
  20687. If no file name is given, it defaults to the name of the host machine
  20688. suffixed with `-slow.log'. If a filename is given, but doesn't contain
  20689. a path, the file is written in the data directory.
  20690.  
  20691. The slow query log can be used to find queries that take a long time to
  20692. execute and are thus candidates for optimisation. With a large log, that
  20693. can become a difficult task. You can pipe the slow query log through the
  20694. `mysqldumpslow' command to get a summary of the queries which appear in
  20695. the log.
  20696.  
  20697. You are using `--log-long-format' then also queries that are not using
  20698. indexes are printed. *Note Command-line options::.
  20699.  
  20700. Log File Maintenance
  20701. --------------------
  20702.  
  20703. The MySQL Server can create a number of different log files, which make
  20704. it easy to see what is going on. *Note Log Files::. One must however
  20705. regularly clean up these files, to ensure that the logs don't take up
  20706. too much disk space.
  20707.  
  20708. When using MySQL with log files, you will, from time to time, want to
  20709. remove/backup old log files and tell MySQL to start logging on new
  20710. files.  *Note Backup::.
  20711.  
  20712. On a Linux (`Redhat') installation, you can use the `mysql-log-rotate'
  20713. script for this. If you installed MySQL from an RPM distribution, the
  20714. script should have been installed automatically.  Note that you should
  20715. be careful with this if you are using the log for replication!
  20716.  
  20717. On other systems you must install a short script yourself that you
  20718. start from `cron' to handle log files.
  20719.  
  20720. You can force MySQL to start using new log files by using `mysqladmin
  20721. flush-logs' or by using the SQL command `FLUSH LOGS'.  If you are using
  20722. MySQL Version 3.21 you must use `mysqladmin refresh'.
  20723.  
  20724. The above command does the following:
  20725.  
  20726.    * If standard logging (`--log') or slow query logging
  20727.      (`--log-slow-queries') is used, closes and reopens the log file
  20728.      (`mysql.log' and ``hostname`-slow.log' as default).
  20729.  
  20730.    * If update logging (`--log-update') is used, closes the update log
  20731.      and opens a new log file with a higher sequence number.
  20732.  
  20733. If you are using only an update log, you only have to flush the logs
  20734. and then move away the old update log files to a backup.  If you are
  20735. using the normal logging, you can do something like:
  20736.  
  20737.      shell> cd mysql-data-directory
  20738.      shell> mv mysql.log mysql.old
  20739.      shell> mysqladmin flush-logs
  20740.  
  20741. and then take a backup and remove `mysql.old'.
  20742.  
  20743. Replication in MySQL
  20744. ====================
  20745.  
  20746. This section describes the various replication features in MySQL.  It
  20747. serves as a reference to the options available with replication.  You
  20748. will be introduced to replication and learn how to implement it.
  20749. Toward the end, there are some frequently asked questions and
  20750. descriptions of problems and how to solve them.
  20751.  
  20752. We suggest that you visit our website at `http://www.mysql.com/' often
  20753. and read updates to this section. Replication is constantly being
  20754. improved, and we update the manual frequently with the most current
  20755. information.
  20756.  
  20757. Introduction
  20758. ------------
  20759.  
  20760. One way replication can be used is to increase both robustness and
  20761. speed. For robustness you can have two systems and can switch to the
  20762. backup if you have problems with the master. The extra speed is
  20763. achieved by sending a part of the non-updating queries to the replica
  20764. server. Of course this only works if non-updating queries dominate, but
  20765. that is the normal case.
  20766.  
  20767. Starting in Version 3.23.15, MySQL supports one-way replication
  20768. internally. One server acts as the master, while the other acts as the
  20769. slave. Note that one server could play the roles of master in one pair
  20770. and slave in the other. The master server keeps a binary log of updates
  20771. (*note Binary log::) and an index file to binary logs to keep track of
  20772. log rotation.  The slave, upon connecting, informs the master where it
  20773. left off since the last successfully propagated update, catches up on
  20774. the updates, and then blocks and waits for the master to notify it of
  20775. the new updates.
  20776.  
  20777. Note that if you are replicating a database, all updates to this
  20778. database should be done through the master!
  20779.  
  20780. Another benefit of using replication is that one can get live backups of
  20781. the system by doing a backup on a slave instead of doing it on the
  20782. master. *Note Backup::.
  20783.  
  20784. Replication Implementation Overview
  20785. -----------------------------------
  20786.  
  20787. MySQL replication is based on the server keeping track of all changes
  20788. to your database (updates, deletes, etc) in the binary log (*note
  20789. Binary log::) and the slave server(s) reading the saved queries from
  20790. the master server's binary log so that the slave can execute the same
  20791. queries on its copy of the data.
  20792.  
  20793. It is *very important* to realise that the binary log is simply a
  20794. record starting from a fixed point in time (the moment you enable binary
  20795. logging). Any slaves which you set up will need copies of all the data
  20796. from your master as it existed the moment that you enabled binary
  20797. logging on the master. If you start your slaves with data that doesn't
  20798. agree with what was on the master *when the binary log was started*,
  20799. your slaves may fail.
  20800.  
  20801. Please see the following table for an indication of master-slave
  20802. compatibility between different versions. With regard to version 4.0,
  20803. we recommend using same version on both sides.
  20804.  
  20805.                     *Master*    *Master**Master**Master*
  20806.                     *3.23.33    *4.0.0* *4.0.1* *4.0.3 and
  20807.                     and up*                     up*
  20808. *Slave* *3.23.33    yes         no      no      no
  20809.         and up*                                 
  20810. *Slave* *4.0.0*     no          yes     no      no
  20811. *Slave* *4.0.1*     yes         no      yes     no
  20812. *Slave* *4.0.3 and  yes         no      no      yes
  20813.         up*                                     
  20814.  
  20815. *Note*: MySQL Version 4.0.2 is not recommended for replication.
  20816.  
  20817. Starting from 4.0.0, one can use `LOAD DATA FROM MASTER' to set up a
  20818. slave. Be aware that `LOAD DATA FROM MASTER' currently works only if
  20819. all the tables on the master are `MyISAM' type, and will acquire a
  20820. global read lock, so no writes are possible while the tables are being
  20821. transferred from the master. This limitation is of a temporary nature,
  20822. and is due to the fact that we have not yet implemented hot lock-free
  20823. table backup.  It will be removed in the future 4.0 branch versions
  20824. once we implement hot backup enabling `LOAD DATA FROM MASTER' to work
  20825. without blocking master updates.
  20826.  
  20827. Due to the above limitation, we recommend that at this point  you use
  20828. `LOAD DATA FROM MASTER' only if the dataset on the master is relatively
  20829. small, or if a prolonged read lock on the master is acceptable. While
  20830. the actual speed of `LOAD DATA FROM MASTER' may vary from system to
  20831. system, a good rule for a rough estimate of how long it is going to
  20832. take is 1 second per 1 MB of the datafile. You will get close to the
  20833. estimate if both master and slave are equivalent to 700 MHz Pentium,
  20834. are connected through 100 MBit/s network, and your index file is about
  20835. half the size of your data file. Of course, your mileage will vary from
  20836. system to system, the above rule just gives you a rough order of
  20837. magnitude estimate.
  20838.  
  20839. Once a slave is properly configured and running, it will simply connect
  20840. to the master and wait for updates to process. If the master goes away
  20841. or the slave loses connectivity with your master, it will keep trying to
  20842. connect every `master-connect-retry' seconds until it is able to
  20843. reconnect and resume listening for updates.
  20844.  
  20845. Each slave keeps track of where it left off. The master server has no
  20846. knowledge of how many slaves there are or which ones are up-to-date at
  20847. any given time.
  20848.  
  20849. The next section explains the master/slave setup process in more detail.
  20850.  
  20851. How To Set Up Replication
  20852. -------------------------
  20853.  
  20854. Here is a quick description of how to set up complete replication on
  20855. your current MySQL server. It assumes you want to replicate all your
  20856. databases and have not configured replication before. You will need to
  20857. shutdown your master server briefly to complete the steps outlined here.
  20858.  
  20859. While this method is the most straightforward way to set up a slave, it
  20860. is not the only one. For example, if you already have a snapshot of the
  20861. master, and the master already has server id set and binary logging
  20862. enabled, you can set up a slave without shutting the master down or
  20863. even blocking the updates.  For more details, please see *Note
  20864. Replication FAQ::.
  20865.  
  20866. If you want to become a real MySQL replication guru, we suggest that you
  20867. begin by studying, pondering, and trying all commands mentioned in
  20868. *Note Replication SQL::. You should also familiarise yourself with
  20869. replication startup options in `my.cnf' in *Note Replication Options::.
  20870.  
  20871.   1. Make sure you have a recent version of MySQL installed on the
  20872.      master and slave(s).
  20873.  
  20874.      Use Version 3.23.29 or higher. Previous releases used a different
  20875.      binary log format and had bugs which have been fixed in newer
  20876.      releases. Please, do not report bugs until you have verified that
  20877.      the problem is present in the latest release.
  20878.  
  20879.   2. Set up special a replication user on the master with the `FILE'
  20880.      (in MySQL versions older than 4.0.2) or `REPLICATION SLAVE'
  20881.      privilege in newer MySQL versions.  You must also have given
  20882.      permission to connect from all the slaves. If the user is only
  20883.      doing replication (which is recommended), you don't need to grant
  20884.      any additional privileges.
  20885.  
  20886.      For example, to create a user named `repl' which can access your
  20887.      master from any host, you might use this command:
  20888.  
  20889.           mysql> GRANT FILE ON *.* TO repl@"%" IDENTIFIED BY '<password>';
  20890.  
  20891.   3. If you are using MyISAM tables, flush all the tables and block
  20892.      write queries by executing `FLUSH TABLES WITH READ LOCK' command.
  20893.  
  20894.           mysql> FLUSH TABLES WITH READ LOCK;
  20895.  
  20896.      and then take a snapshot of the data on your master server.
  20897.  
  20898.      The easiest way to do this (on Unix) is to simply use *tar* to
  20899.      produce an archive of your entire data directory. The exact data
  20900.      directory location depends on your installation.
  20901.  
  20902.           tar -cvf /tmp/mysql-snapshot.tar /path/to/data-dir
  20903.  
  20904.      Windows users can use `WinZIP' or similar software to create an
  20905.      archive of the data directory.
  20906.  
  20907.      After or during the process of taking a snapshot, read the value
  20908.      of the current binary log name and the offset on the master:
  20909.  
  20910.           mysql > SHOW MASTER STATUS;
  20911.           +---------------+----------+--------------+-------------------------------+
  20912.           | File          | Position | Binlog_do_db | Binlog_ignore_db              |
  20913.           +---------------+----------+--------------+-------------------------------+
  20914.           | mysql-bin.003 | 73       | test,bar     | foo,manual,sasha_likes_to_run |
  20915.           +---------------+----------+--------------+-------------------------------+
  20916.           1 row in set (0.06 sec)
  20917.  
  20918.      The `File' column shows the name of the log,  while `Position'
  20919.      shows the offset. n the above example, the binary log value is
  20920.      `mysql-bin.003' and the offset is 73. Record the values - you will
  20921.      need to use them later when you are setting up the slave.
  20922.  
  20923.      Once you have taken the snapshot and recorded the log name and
  20924.      offset, you can re-enable write activity on the master:
  20925.  
  20926.           mysql> UNLOCK TABLES;
  20927.  
  20928.      If you are using InnoDB tables, ideally you should use the InnoDB
  20929.      Hot Backup tool that is available to those who purchase MySQL
  20930.      commercial licenses, support, or the backup tool itself. It will
  20931.      take a consistent snapshot without acquiring any locks on the
  20932.      master server, and record the log name and offset corresponding to
  20933.      the snapshot to be later used on the slave. More information about
  20934.      the tool is avaliable at `http://www.innodb.com/hotbackup.html'.
  20935.  
  20936.      Without the hot backup tool, the quickest way to take a snapshot
  20937.      of  InnoDB tables is to shut the master server down and copy the
  20938.      data files, the logs, and the table definition files (`.frm'). To
  20939.      record the current log file name and offset, you should do the
  20940.      following before you shut down the server:
  20941.  
  20942.           mysql> FLUSH TABLES WITH READ LOCK;
  20943.           mysql> SHOW MASTER STATUS;
  20944.  
  20945.      And then record the log name and the offset from the output of
  20946.      `SHOW MASTER STATUS' as was shown earlier. Once you have recorded
  20947.      the log name and the offset, shut the server down without
  20948.      unlocking the tables to make sure it goes down with the snapshot
  20949.      corresponding to the current log file and offset:
  20950.  
  20951.           shell> mysqladmin -uroot shutdown
  20952.  
  20953.      If the master has been previously running without `log-bin'
  20954.      enabled, the values of log name and position will be empty when
  20955.      you run `SHOW MASTER STATUS'. In that case, record empty string
  20956.      (") for the log name, and 4 for the offset.
  20957.  
  20958.   4. Make sure that `my.cnf' on the master has  `log-bin' if it is not
  20959.      there already and `server-id=unique number' in the `[mysqld]'
  20960.      section. If those options are not present, add them and restart
  20961.      the server.  It is very important that the id of the slave is
  20962.      different from the id of the master. Think of `server-id' as
  20963.      something similar to the IP address - it uniquely identifies the
  20964.      server instance in the community of replication partners.
  20965.  
  20966.           [mysqld]
  20967.           log-bin
  20968.           server-id=1
  20969.  
  20970.   5. Add the following to `my.cnf' on the slave(s):
  20971.  
  20972.           server-id=<some unique number between 1 and 2^32-1 that is different from
  20973.            that of the master>
  20974.  
  20975.      replacing the values in <> with what is relevant to your system.
  20976.  
  20977.      `server-id' must be different for each server participating in
  20978.      replication.  If you don't specify a server-id, it will be set to
  20979.      1 if you have not defined `master-host', else it will be set to 2.
  20980.      Note that in the case of `server-id' omission the master will
  20981.      refuse connections from all slaves, and the slave will refuse to
  20982.      connect to a master. Thus, omitting `server-id' is only good for
  20983.      backup with a binary log.
  20984.  
  20985.   6. While the slave is running, make it forget about the old
  20986.      replication configuration if it has been replicating previously:
  20987.  
  20988.           mysql> RESET SLAVE;
  20989.  
  20990.   7. Copy the snapshot data into your data directory on your slave(s).
  20991.      Make sure that the privileges on the files and directories are
  20992.      correct. The user which MySQL runs as needs to be able to read and
  20993.      write to them, just as on the master.
  20994.  
  20995.   8. Restart the slave(s).
  20996.  
  20997.   9. Once the slave comes up, execute the following command:
  20998.  
  20999.           mysql> CHANGE MASTER TO MASTER_HOST='<master host name>',
  21000.            MASTER_USER='<replication user name>',
  21001.            MASTER_PASSWORD='<replication password>',
  21002.            MASTER_LOG_FILE='<recorded log file name>',
  21003.            MASTER_LOG_POS=<recorded log offset>;
  21004.  
  21005.      replacing the values in <> with the actual values relevant to your
  21006.      system.
  21007.  
  21008.  10. Start the slave thread:
  21009.  
  21010.           mysql> SLAVE START;
  21011.  
  21012.  
  21013. After you have done the above, the slave(s) should connect to the master
  21014. and catch up on any updates which happened since the snapshot was taken.
  21015.  
  21016. If you have forgotten to set `server-id' for the slave you will get the
  21017. following error in the error log file:
  21018.  
  21019.      Warning: one should set server_id to a non-0 value if master_host is set.
  21020.      The server will not act as a slave.
  21021.  
  21022. If you have forgotten to do this for the master, the slaves will not be
  21023. able to connect to the master.
  21024.  
  21025. If a slave is not able to replicate for any reason, you will find error
  21026. messages in the error log on the slave.
  21027.  
  21028. Once a slave is replicating, you will find a file called `master.info'
  21029. in the same directory as your error log. The `master.info' file is used
  21030. by the slave to keep track of how much of the master's binary log it
  21031. has processed. *Do not* remove or edit the file, unless you really know
  21032. what you are doing. Even in that case, it is preferred that you use
  21033. `CHANGE MASTER TO' command.
  21034.  
  21035. Now that you have a snapshot, you can use it to set up other slaves. To
  21036. do so, follow the slave portion of the procedure described above. You
  21037. do not need to take another snapshot of the master.
  21038.  
  21039. Replication Features and Known Problems
  21040. ---------------------------------------
  21041.  
  21042. Here is an explanation of what is supported and what is not:
  21043.  
  21044.    * Replication will be done correctly with `AUTO_INCREMENT',
  21045.      `LAST_INSERT_ID()', and `TIMESTAMP' values.
  21046.  
  21047.    * `RAND()' in updates does not replicate properly. Use
  21048.      `RAND(some_non_rand_expr)' if you are replicating updates with
  21049.      `RAND()'. You can, for example, use `UNIX_TIMESTAMP()' for the
  21050.      argument to `RAND()'.
  21051.  
  21052.    * You have to use the same character set (`--default-character-set')
  21053.      on the master and the slave. If not, you may get duplicate key
  21054.      errors on the slave, because a key that is regarded as unique in
  21055.      the master character set may not be unique in the slave character
  21056.      set.
  21057.  
  21058.    * In 3.23, `LOAD DATA INFILE' will be handled properly as long as
  21059.      the file still resides on the master server at the time of update
  21060.      propagation. `LOAD LOCAL DATA INFILE' will be skipped. In 4.0, this
  21061.      limitation is not present - all forms of `LOAD DATA INFILE' are
  21062.      properly replicated.
  21063.  
  21064.    * Update queries that use user variables are not replication-safe
  21065.      (yet).
  21066.  
  21067.    * `FLUSH' commands are not stored in the binary log and are because
  21068.      of this not replicated to the slaves. This is not normally a
  21069.      problem as `FLUSH' doesn't change anything. This does however mean
  21070.      that if you update the MySQL privilege tables directly without
  21071.      using the `GRANT' statement and you replicate the `mysql' privilege
  21072.      database, you must do a `FLUSH PRIVILEGES' on your slaves to put
  21073.      the new privileges into effect.
  21074.  
  21075.    * Temporary tables starting in 3.23.29 are replicated properly with
  21076.      the exception of the case when you shut down slave server ( not
  21077.      just slave thread), you have some temporary tables open, and they
  21078.      are used in subsequent updates.  To deal with this problem
  21079.      shutting down the slave, do `SLAVE STOP', check
  21080.      `Slave_open_temp_tables' variable to see if it is 0, then issue
  21081.      `mysqladmin shutdown'. If the number is not 0, restart the slave
  21082.      thread with `SLAVE START' and see if you have better luck next
  21083.      time. There will be a cleaner solution, but it has to wait until
  21084.      version 4.0.  In earlier versions temporary tables are not
  21085.      replicated properly - we recommend that you either upgrade, or
  21086.      execute `SET SQL_LOG_BIN=0' on your clients before all queries
  21087.      with temp tables.
  21088.  
  21089.    * MySQL only supports one master and many slaves. In 4.x, we will
  21090.      add a voting algorithm to automatically change master if something
  21091.      goes wrong with the current master. We will also introduce 'agent'
  21092.      processes to help do load balancing by sending select queries to
  21093.      different slaves.
  21094.  
  21095.    * Starting in Version 3.23.26, it is safe to connect servers in a
  21096.      circular master-slave relationship with `log-slave-updates'
  21097.      enabled.  Note, however, that many queries will not work right in
  21098.      this kind of setup unless your client code is written to take care
  21099.      of the potential problems that can happen from updates that occur
  21100.      in different sequence on different servers.
  21101.  
  21102.      This means that you can do a setup like the following:
  21103.  
  21104.           A -> B -> C -> A
  21105.  
  21106.      This setup will only works if you only do non conflicting updates
  21107.      between the tables.  In other words, if you insert data in A and
  21108.      C, you should never insert a row in A that may have a conflicting
  21109.      key with a row insert in C.  You should also not update the sam
  21110.      rows on two servers if the order in which the updates are applied
  21111.      matters.
  21112.  
  21113.      Note that the log format has changed in Version 3.23.26 so that
  21114.      pre-3.23.26 slaves will not be able to read it.
  21115.  
  21116.    * If the query on the slave gets an error, the slave thread will
  21117.      terminate, and a message will appear in the `.err' file. You should
  21118.      then connect to the slave manually, fix the cause of the error (for
  21119.      example, non-existent table), and then run the `SLAVE START' SQL
  21120.      command (available starting in Version 3.23.16). In Version
  21121.      3.23.15, you will have to restart the server.
  21122.  
  21123.    * If connection to the master is lost, the slave will retry
  21124.      immediately, and then in case of failure every
  21125.      `master-connect-retry' (default 60) seconds. Because of this, it
  21126.      is safe to shut down the master, and then restart it after a
  21127.      while. The slave will also be able to deal with network
  21128.      connectivity outages.
  21129.  
  21130.    * Shutting down the slave (cleanly) is also safe, as it keeps track
  21131.      of where it left off.  Unclean shutdowns might produce problems,
  21132.      especially if disk cache was not synced before the system died.
  21133.      Your system fault tolerance will be greatly increased if you have
  21134.      a good UPS.
  21135.  
  21136.    * If the master is listening on a non-standard port, you will also
  21137.      need to specify this with `master-port' parameter in `my.cnf' .
  21138.  
  21139.    * In Version 3.23.15, all of the tables and databases will be
  21140.      replicated. Starting in Version 3.23.16, you can restrict
  21141.      replication to a set of databases with `replicate-do-db'
  21142.      directives in `my.cnf' or just exclude a set of databases with
  21143.      `replicate-ignore-db'. Note that up until Version 3.23.23, there
  21144.      was a bug that did not properly deal with `LOAD DATA INFILE' if
  21145.      you did it in a database that was excluded from replication.
  21146.  
  21147.    * Starting in Version 3.23.16, `SET SQL_LOG_BIN = 0' will turn off
  21148.      replication (binary) logging on the master, and `SET SQL_LOG_BIN =
  21149.      1' will turn it back on - you must have the `SUPER' (in MySQL
  21150.      4.0.2 and above) or `PROCESS' (in older MySQL versions) privilege
  21151.      to do this.
  21152.  
  21153.    * Starting in Version 3.23.19, you can clean up stale replication
  21154.      leftovers when something goes wrong and you want a clean start
  21155.      with `FLUSH MASTER' and `FLUSH SLAVE' commands. In Version 3.23.26
  21156.      we have renamed them to `RESET MASTER' and `RESET SLAVE'
  21157.      respectively to clarify what they do. The old `FLUSH' variants
  21158.      still work, though, for compatibility.
  21159.  
  21160.    * Starting in Version 3.23.23, you can change masters and adjust log
  21161.      position with `CHANGE MASTER TO'.
  21162.  
  21163.    * Starting in Version 3.23.23, you tell the master that updates in
  21164.      certain databases should not be logged to the binary log with
  21165.      `binlog-ignore-db'.
  21166.  
  21167.    * Starting in Version 3.23.26, you can use `replicate-rewrite-db' to
  21168.      tell the slave to apply updates from one database on the master to
  21169.      the one with a different name on the slave.
  21170.  
  21171.    * Starting in Version 3.23.28, you can use `PURGE MASTER LOGS TO
  21172.      'log-name'' to get rid of old logs while the slave is running.
  21173.      This will remove all old logs before, but not including
  21174.      `'log-name''.
  21175.  
  21176.    * Due to the non-transactional nature of MyISAM tables, it is
  21177.      possible to have a query that will only partially update a table
  21178.      and return an error code. This can happen, for example, on a
  21179.      multi-row insert that has one row violating a key constraint, or
  21180.      if a long update query is killed after updating some of the rows.
  21181.      If that happens on the master, the slave thread will exit and wait
  21182.      for the DBA to decide what to do about it unless the error code is
  21183.      legitimate and the query execution results in the same error code.
  21184.      If this error code validation behaviour is not desirable, some (
  21185.      or all) errors could be masked out with `slave-skip-errors' option
  21186.      starting in Version 3.23.47.
  21187.  
  21188.    * While individual tables can be excluded from replication with
  21189.      `replicate-do-table'/`replicate-ignore-table' or
  21190.      `replicate-wild-do-table'/`replicate-wild-ignore-table', there are
  21191.      currently some design deficiencies that in some rather rare cases
  21192.      produce unexpected results. The replication protocol does not
  21193.      inform the slave explicitly which tables are going to be modified
  21194.      by the query - so the slave has to parse the query to know this.
  21195.      To avoid redundant parsing for queries that will end up actually
  21196.      being executed, table exclusion is currently implemented by
  21197.      sending the query to the standard MySQL parser, which will
  21198.      short-circuit the query and report success if it detects that the
  21199.      table should be ignored. In addition to several inefficiencies,
  21200.      this approach is also more bug prone, and there are two known bugs
  21201.      as of Version 3.23.49 - because the parser automatically opens the
  21202.      table when parsing some queries the ignored table has to exist on
  21203.      the slave. The other bug is that if the ignored table gets
  21204.      partially updated, the slave thread will not notice that the table
  21205.      actually should have been ignored and will suspend the replication
  21206.      process. While the above bugs are conceptually very simple to fix,
  21207.      we have not yet found a way to do this without a significant code
  21208.      change that would compromise the stability status of 3.23 branch.
  21209.      There exists a workaround for both if in the rare case it happens
  21210.      to affect your application - use `slave-skip-errors'.
  21211.  
  21212. Replication Options in `my.cnf'
  21213. -------------------------------
  21214.  
  21215. If you are using replication, we recommend that you use MySQL Version
  21216. 3.23.33 or later. Older versions work, but they do have some bugs and
  21217. are missing some features. Some of the options mentioned here may not
  21218. be available in your version if it is not the most recent one. For all
  21219. options specific to the 4.0 branch, there is a note indicating so.
  21220. Otherwise, if you discover that the option you are interested in is not
  21221. available in your 3.23 version, and you really need it, please upgrade
  21222. to the most recent 3.23 branch.
  21223.  
  21224. Please be aware that 4.0 branch is still in alpha, so some things may
  21225. not be working as smoothly as you would like. If you really would like
  21226. to try the new features of 4.0, we recommend you do it in such a way
  21227. that in case there is a problem  your mission critical applications
  21228. will not be disrupted.
  21229.  
  21230. On both master and slave you need to use the `server-id' option.  This
  21231. sets a unique replication id. You should pick a unique value in the
  21232. range between 1 to 2^32-1 for each master and slave.  Example:
  21233. `server-id=3'
  21234.  
  21235. The following table describes the options you can use for the `MASTER':
  21236.  
  21237. *Option*                    *Description*
  21238. `log-bin=filename'           Write to a binary update log to the
  21239.                             specified location. Note that if you give it
  21240.                             a parameter with an extension (for example,
  21241.                             `log-bin=/mysql/logs/replication.log' )
  21242.                             versions up to 3.23.24 will not work right
  21243.                             during replication if you do `FLUSH LOGS' .
  21244.                             The problem is fixed in Version 3.23.25. If
  21245.                             you are using this kind of log name, `FLUSH
  21246.                             LOGS' will be ignored on binlog. To clear
  21247.                             the log, run `FLUSH MASTER', and do not
  21248.                             forget to run `FLUSH SLAVE' on all slaves.
  21249.                             In Versions 3.23.26 and later, you should use
  21250.                             `RESET MASTER' and `RESET SLAVE'
  21251. `log-bin-index=filename'     Because the user could issue the `FLUSH
  21252.                             LOGS' command, we need to know which log is
  21253.                             currently active and which ones have been
  21254.                             rotated out and in what sequence. This
  21255.                             information is stored in the binary log
  21256.                             index file.  The default is
  21257.                             ``hostname`.index'. You should not need to
  21258.                             change this.
  21259.                             
  21260.                             Example: `log-bin-index=db.index'
  21261. `sql-bin-update-same'        If set, setting `SQL_LOG_BIN' to a value
  21262.                             will automatically set `SQL_LOG_UPDATE' to
  21263.                             the same value and vice versa.
  21264. `binlog-do-db=database_name' Tells the master that it should log updates
  21265.                             to the binary log if the current database is
  21266.                             `database_name'. All other databases are
  21267.                             ignored.  Note that if you use this, you
  21268.                             should ensure that you do updates only in
  21269.                             the current database.
  21270.                             
  21271.                             Example: `binlog-do-db=sales'
  21272. `binlog-ignore-db=database_name' Tells the master that updates where the
  21273.                             current database is `database_name' should
  21274.                             not be stored in the binary log.  Note that
  21275.                             if you use this, you should ensure that you
  21276.                             do updates only in the current database.
  21277.                             
  21278.                             Example: `binlog-ignore-db=accounting'
  21279.  
  21280. The following table describes the options you can use for the `SLAVE':
  21281.  
  21282. *Option*                    *Description*
  21283. `master-host=host'           Master hostname or IP address for
  21284.                             replication. If not set, the slave thread
  21285.                             will not be started. Note that the setting
  21286.                             of `master-host' will be ignored if there
  21287.                             exists a valid `master.info' file. Probably a
  21288.                             better name for this options would have been
  21289.                             something like `bootstrap-master-host', but
  21290.                             it is too late to change now.
  21291.                             
  21292.                             Example:
  21293.                             `master-host=db-master.mycompany.com'
  21294. `master-user=username'       The username the slave thread will use for
  21295.                             authentication when connecting to the
  21296.                             master. The user must have the `FILE'
  21297.                             privilege. If the master user is not set,
  21298.                             user `test' is assumed. The value in
  21299.                             `master.info' will take precedence if it can
  21300.                             be read.
  21301.                             
  21302.                             Example: `master-user=scott'
  21303. `master-password=password'   The password the slave thread will
  21304.                             authenticate with when connecting to the
  21305.                             master. If not set, an empty password is
  21306.                             assumed.The value in `master.info' will take
  21307.                             precedence if it can be read.
  21308.                             
  21309.                             Example: `master-password=tiger'
  21310. `master-port=portnumber'     The port the master is listening on. If not
  21311.                             set, the compiled setting of `MYSQL_PORT' is
  21312.                             assumed. If you have not tinkered with
  21313.                             `configure' options, this should be 3306.
  21314.                             The value in `master.info' will take
  21315.                             precedence if it can be read.
  21316.                             
  21317.                             Example: `master-port=3306'
  21318. `master-connect-retry=seconds' The number of seconds the slave thread will
  21319.                             sleep before retrying to connect to the
  21320.                             master in case the master goes down or the
  21321.                             connection is lost.  Default is 60.
  21322.                             
  21323.                             Example: `master-connect-retry=60'
  21324. `master-ssl'                 Available after 4.0.0. Turn SSL on for
  21325.                             replication. Be warned that is this is a
  21326.                             relatively new feature.
  21327.                             
  21328.                             Example: `master-ssl'
  21329. `master-ssl-key'             Available after 4.0.0. Master SSL keyfile
  21330.                             name. Only applies if you have enabled
  21331.                             `master-ssl'.
  21332.                             
  21333.                             Example: `master-ssl-key=SSL/master-key.pem'
  21334. `master-ssl-cert'            Available after 4.0.0. Master SSL
  21335.                             certificate file name. Only applies if you
  21336.                             have enabled `master-ssl'.
  21337.                             
  21338.                             Example: `master-ssl-key=SSL/master-cert.pem'
  21339. `master-info-file=filename'  The location of the file that remembers
  21340.                             where we left off on the master during the
  21341.                             replication process. The default is
  21342.                             `master.info' in the data directory. You
  21343.                             should not need to change this.
  21344.                             
  21345.                             Example: `master-info-file=master.info'
  21346. `report-host'                Available after 4.0.0. Hostname or IP of
  21347.                             the slave to be reported to the master
  21348.                             during slave registration. Will appear in
  21349.                             the output of `SHOW SLAVE HOSTS'. Leave
  21350.                             unset if you do not want the slave to
  21351.                             register itself with the master. Note that
  21352.                             it is not sufficient for the master to
  21353.                             simply read the IP of the slave off the
  21354.                             socket once the slave connects. Due to `NAT'
  21355.                             and other routing issues, that IP may not be
  21356.                             valid for connecting to the slave from the
  21357.                             master or other hosts.
  21358.                             
  21359.                             Example: `report-host=slave1.mycompany.com'
  21360. `report-port'                Available after 4.0.0. Port for connecting
  21361.                             to slave reported to the master during slave
  21362.                             registration.  Set it only if the slave is
  21363.                             listening on a non-default port or if you
  21364.                             have a special tunnel from the master or
  21365.                             other clients to the slave. If not sure,
  21366.                             leave this option unset.
  21367. `replicate-do-table=db_name.table_name' Tells the slave thread to restrict
  21368.                             replication to the specified table.  To
  21369.                             specify more than one table, use the
  21370.                             directive multiple times, once for each
  21371.                             table.  This will work for cross-database
  21372.                             updates, in contrast to `replicate-do-db'.
  21373.                             
  21374.                             Example:
  21375.                             `replicate-do-table=some_db.some_table'
  21376. `replicate-ignore-table=db_name.table_name' Tells the slave thread to not replicate any
  21377.                             command that updates the specified table
  21378.                             (even if any other tables may be update by
  21379.                             the same command). To specify more than one
  21380.                             table to ignore, use the directive multiple
  21381.                             times, once for each table. This will work
  21382.                             for cross-datbase updates, in contrast to
  21383.                             `replicate-ignore-db'.
  21384.                             
  21385.                             Example:
  21386.                             `replicate-ignore-table=db_name.some_table'
  21387. `replicate-wild-do-table=db_name.table_name' Tells the slave thread to restrict
  21388.                             replication to queries where any of the
  21389.                             updated tables match the specified wildcard
  21390.                             pattern.  To specify more than one table,
  21391.                             use the directive multiple times, once for
  21392.                             each table.  This will work for
  21393.                             cross-database updates.
  21394.                             
  21395.                             Example: `replicate-wild-do-table=foo%.bar%'
  21396.                             will replicate only updates that uses a
  21397.                             table in any databases that start with `foo'
  21398.                             and whose table names start with `bar'.
  21399. `replicate-wild-ignore-table=db_name.table_name' Tells the slave thread to not replicate a
  21400.                             query where any table matches the given
  21401.                             wildcard pattern. To specify more than one
  21402.                             table to ignore, use the directive multiple
  21403.                             times, once for each table. This will work
  21404.                             for cross-database updates.
  21405.                             
  21406.                             Example:
  21407.                             `replicate-wild-ignore-table=foo%.bar%' will
  21408.                             not do updates to tables in databases that
  21409.                             start with `foo' and whose table names start
  21410.                             with `bar'.
  21411. `replicate-ignore-db=database_name' Tells the slave thread to not replicate any
  21412.                             command where the current database is
  21413.                             `database_name'. To specify more than one
  21414.                             database to ignore, use the directive
  21415.                             multiple times, once for each database.  You
  21416.                             should not use this directive if you are
  21417.                             using cross table updates and you don't want
  21418.                             these update to be replicated.
  21419.                             
  21420.                             The main reason for this behaviour is that
  21421.                             it's hard from the command alone know if a
  21422.                             query should be replicated or not; For
  21423.                             example if you are using multi-table-delete
  21424.                             or multi-table-update commands in MySQL 4.x
  21425.                             that goes across multiple databases.  It's
  21426.                             also very fast to just check the current
  21427.                             database, as this only has to be done once
  21428.                             at connect time or when the database changes.
  21429.                             
  21430.                             If you need cross database updates to work,
  21431.                             make sure you have 3.23.28 or later, and use
  21432.                             `replicate-wild-ignore-table=db_name.%'.
  21433.                             
  21434.                             Example: `replicate-ignore-db=some_db'
  21435. `replicate-do-db=database_name' Tells the slave thread to restrict
  21436.                             replication to commands where the current
  21437.                             database is `database_name'.  To specify
  21438.                             more than one database, use the directive
  21439.                             multiple times, once for each database. Note
  21440.                             that this will not replicate cross-database
  21441.                             queries such as `UPDATE some_db.some_table
  21442.                             SET foo='bar'' while having selected a
  21443.                             different or no database. If you need cross
  21444.                             database updates to work, make sure you have
  21445.                             3.23.28 or later, and use
  21446.                             `replicate-wild-do-table=db_name.%'.
  21447.                             
  21448.                             Example: `replicate-do-db=some_db'
  21449. `log-slave-updates'          Tells the slave to log the updates from the
  21450.                             slave thread to the binary log. Off by
  21451.                             default. You will need to turn it on if you
  21452.                             plan to daisy-chain the slaves.
  21453. `replicate-rewrite-db=from_name->to_name' Updates to a database with a different name
  21454.                             than the original.
  21455.                             
  21456.                             Example:
  21457.                             `replicate-rewrite-db=master_db_name->slave_db_name'
  21458. `slave-skip-errors=          Available only in 3.23.47 and later. Tells
  21459. [err_code1,err_code2,... |  the slave thread to continue replication
  21460. all]'                       when a query returns an error from the
  21461.                             provided list. Normally, replication will
  21462.                             discontinue when an error is encountered,
  21463.                             giving the user a chance to resolve the
  21464.                             inconsistency in the data manually. Do not
  21465.                             use this option unless you fully understand
  21466.                             why you are getting the errors.  If there
  21467.                             are no bugs in your replication setup and
  21468.                             client programs, and no bugs in MySQL
  21469.                             itself, you should never get an abort with
  21470.                             error. Indiscriminate use of this option
  21471.                             will result in slaves being hopelessly out
  21472.                             of sync with the master and you having no
  21473.                             idea how the problem happened.
  21474.                             
  21475.                             For error codes, you should use the numbers
  21476.                             provided by the error message in your slave
  21477.                             error log and in the output of `SHOW SLAVE
  21478.                             STATUS'. Full list of error messages can be
  21479.                             found in the source distribution in
  21480.                             `Docs/mysqld_error.txt'.
  21481.                             
  21482.                             You can (but should not) also use a very
  21483.                             non-recommended value of `all' which will
  21484.                             ignore all error messages and keep barging
  21485.                             along regardless.  Needless to say, if you
  21486.                             use it, we make no promises regarding your
  21487.                             data integrity. Please do not complain if
  21488.                             your data on the slave is not anywhere close
  21489.                             to what it is on the master in this case -
  21490.                             you have been warned.
  21491.                             
  21492.                             Example:
  21493.                             
  21494.                             `slave-skip-errors=1062,1053' or
  21495.                             `slave-skip-errors=all'
  21496. `skip-slave-start'           Tells the slave server not to start the
  21497.                             slave on the startup.  The user can start it
  21498.                             later with `SLAVE START'.
  21499. `slave_compressed_protocol=#' If 1, then use compression on the
  21500.                             slave/client protocol if both slave and
  21501.                             master support this.
  21502. `slave_net_timeout=#'        Number of seconds to wait for more data
  21503.                             from the master before aborting the read.
  21504.  
  21505. SQL Commands Related to Replication
  21506. -----------------------------------
  21507.  
  21508. Replication can be controlled through the SQL interface. Here is the
  21509. summary of commands:
  21510.  
  21511. *Command*                        *Description*
  21512. `SLAVE START'                    Starts the slave thread.  As of MySQL
  21513.                                  4.0.2, you can add `IO_THREAD' or
  21514.                                  `SQL_THREAD' options to the statement
  21515.                                  to start the I/O thread or the SQL
  21516.                                  thread.  The I/O thread reads queries
  21517.                                  from the master server and stores them
  21518.                                  in the relay log.  The SQL thread reads
  21519.                                  the relay log and executes the queries.
  21520.                                  (Slave)
  21521. `SLAVE STOP'                     Stops the slave thread. Like `SLAVE
  21522.                                  START', this statement may be used with
  21523.                                  `IO_THREAD' and `SQL_THREAD' options.
  21524.                                  (Slave)
  21525. `SET SQL_LOG_BIN=0'              Disables update logging if the user has
  21526.                                  the `SUPER' privilege.   Ignored
  21527.                                  otherwise. (Master)
  21528. `SET SQL_LOG_BIN=1'              Re-enables update logging if the user
  21529.                                  has the `SUPER' privilege.   Ignored
  21530.                                  otherwise. (Master)
  21531. `SET GLOBAL                      Skip the next `n' events from the
  21532. SQL_SLAVE_SKIP_COUNTER=n'        master. Only valid when the slave
  21533.                                  thread is not running, otherwise, gives
  21534.                                  an error. Useful for recovering from
  21535.                                  replication glitches.
  21536. `RESET MASTER'                   Deletes all binary logs listed in the
  21537.                                  index file, resetting the binlog index
  21538.                                  file to be empty. In pre-3.23.26
  21539.                                  versions, use `FLUSH MASTER'.  (Master)
  21540. `RESET SLAVE'                    Makes the slave forget its replication
  21541.                                  position in the master logs. In pre
  21542.                                  3.23.26 versions the command was called
  21543.                                  `FLUSH SLAVE'. (Slave)
  21544. `LOAD TABLE tblname FROM MASTER' Downloads a copy of the table from
  21545.                                  master to the slave. Implemented
  21546.                                  mainly for debugging of `LOAD DATA FROM
  21547.                                  MASTER', but some "gourmet"  users
  21548.                                  might find it useful for other things.
  21549.                                  Do not use it if you consider  yourself
  21550.                                  the average "non-hacker" type user.
  21551.                                  (Slave)
  21552. `LOAD DATA FROM MASTER'           Available starting in 4.0.0. Takes a
  21553.                                  snapshot of the master and copies it to
  21554.                                  the slave. Updates the values of
  21555.                                  `MASTER_LOG_FILE' and `MASTER_LOG_POS'
  21556.                                  so that the slave will start
  21557.                                  replicating from the correct position.
  21558.                                  Will honor table and database exclusion
  21559.                                  rules specified with `replicate-*'
  21560.                                  options. So far works only with
  21561.                                  `MyISAM' tables and acquires a global
  21562.                                  read lock on the master while taking
  21563.                                  the snapshot. In the future it is
  21564.                                  planned to make it work with `InnoDB'
  21565.                                  tables and to remove the need for
  21566.                                  global read lock using the non-blocking
  21567.                                  online backup feature.
  21568.                                  
  21569.                                  Note that `LOAD DATA FROM MASTER' does
  21570.                                  *NOT* copy of any tables in the `mysql'
  21571.                                  database.  This is to make it easy to
  21572.                                  have different users and privileges on
  21573.                                  the master and the slave.
  21574. `CHANGE MASTER TO                Changes the master parameters to the
  21575. master_def_list'                 values specified in `master_def_list'
  21576.                                  and restarts the slave thread.
  21577.                                  `master_def_list' is a comma-separated
  21578.                                  list of `master_def' where `master_def'
  21579.                                  is one of the following: `MASTER_HOST',
  21580.                                  `MASTER_USER', `MASTER_PASSWORD',
  21581.                                  `MASTER_PORT', `MASTER_CONNECT_RETRY',
  21582.                                  `MASTER_LOG_FILE', `MASTER_LOG_POS'.
  21583.                                  For example:
  21584.                                  
  21585.                                       CHANGE MASTER TO
  21586.                                         MASTER_HOST='master2.mycompany.com',
  21587.                                         MASTER_USER='replication',
  21588.                                         MASTER_PASSWORD='bigs3cret',
  21589.                                         MASTER_PORT=3306,
  21590.                                         MASTER_LOG_FILE='master2-bin.001',
  21591.                                         MASTER_LOG_POS=4;
  21592.                                  You only need to specify the values
  21593.                                  that need to be changed. The values that
  21594.                                  you omit will stay the same with the
  21595.                                  exception of when you change the host or
  21596.                                  the port. In that case, the slave will
  21597.                                  assume that since you are connecting to
  21598.                                  a different host or a different port,
  21599.                                  the master is different. Therefore, the
  21600.                                  old values of log and position are not
  21601.                                  applicable anymore, and will
  21602.                                  automatically be reset to an empty
  21603.                                  string and 0, respectively (the start
  21604.                                  values). Note that if you restart the
  21605.                                  slave, it will remember its last master.
  21606.                                  If this is not desirable, you should
  21607.                                  delete the `master.info' file before
  21608.                                  restarting, and the slave will read its
  21609.                                  master from `my.cnf' or the
  21610.                                  command-line.
  21611.                                  
  21612.                                  This command is useful for setting up a
  21613.                                  slave when you have the snapshot of the
  21614.                                  master and have recorded the log and
  21615.                                  the offset on the master that the
  21616.                                  snapshot corresponds to. You can run
  21617.                                  `CHANGE MASTER TO
  21618.                                  MASTER_LOG_FILE='log_name_on_master',
  21619.                                  MASTER_LOG_POS=log_offset_on_master' on
  21620.                                  the slave after restoring the snapshot.
  21621.                                  (Slave)
  21622. `SHOW MASTER STATUS'             Provides status information on the
  21623.                                  binlog of the master. (Master)
  21624. `SHOW SLAVE HOSTS'               Available after 4.0.0. Gives a listing
  21625.                                  of slaves currently registered with the
  21626.                                  master. (Master)
  21627. `SHOW SLAVE STATUS'              Provides status information on
  21628.                                  essential parameters of the slave
  21629.                                  thread. (Slave)
  21630. `SHOW MASTER LOGS'               Only available starting in Version
  21631.                                  3.23.28. Lists the binary logs on the
  21632.                                  master. You should use this command
  21633.                                  prior to `PURGE MASTER LOGS TO' to find
  21634.                                  out how far you should go. (Master)
  21635. `SHOW BINLOG EVENTS [ IN          Shows the events in the binary update
  21636. 'logname' ] [ FROM pos ]  [      log. Primarily used for
  21637. LIMIT [offset,] rows ] '         testing/debugging, but can also be used
  21638.                                  by regular clients that for some reason
  21639.                                  need to read the binary log contents.
  21640.                                  (Master)
  21641. `SHOW NEW MASTER FOR SLAVE WITH   This command is used when a slave of a
  21642. MASTER_LOG_FILE='logfile' AND    possibly dead/unavailable master needs
  21643. MASTER_LOG_POS=pos AND           to be switched to replicate off another
  21644. MASTER_LOG_SEQ=log_seq AND       slave that has been replicating the
  21645. MASTER_SERVER_ID=server_id'      same master. The command will return
  21646.                                  recalculated replication coordinates
  21647.                                  (the slave's current binary log file
  21648.                                  name and position within that file).
  21649.                                  The output can be used in a subsequent
  21650.                                  `CHANGE MASTER TO' command. Normal
  21651.                                  users should never need to run this
  21652.                                  command. It is primarily reserved for
  21653.                                  internal use by the fail-safe
  21654.                                  replication code. We may later change
  21655.                                  the syntax if we find a more intuitive
  21656.                                  way to describe this operation.
  21657. `PURGE MASTER LOGS TO 'logname'' Available starting in Version 3.23.28.
  21658.                                  Deletes all the replication logs that
  21659.                                  are listed in the log index as being
  21660.                                  prior to the specified log, and removes
  21661.                                  them from the log index, so that the
  21662.                                  given log now becomes the first.
  21663.                                  Example:
  21664.                                  
  21665.                                       PURGE MASTER LOGS TO 'mysql-bin.010'
  21666.                                  This command will do nothing and fail
  21667.                                  with an error if you have an active
  21668.                                  slave that is currently reading one of
  21669.                                  the logs you are trying to delete.
  21670.                                  However, if you have a dormant slave,
  21671.                                  and happen to purge one of the logs it
  21672.                                  wants to read, the slave will be unable
  21673.                                  to replicate once it comes up.  The
  21674.                                  command is safe to run while slaves are
  21675.                                  replicating - you do not need to stop
  21676.                                  them.
  21677.                                  
  21678.                                  You must first check all the slaves
  21679.                                  with `SHOW SLAVE STATUS' to see which
  21680.                                  log they are on, then do a listing of
  21681.                                  the logs on the master with `SHOW
  21682.                                  MASTER LOGS', find the earliest log
  21683.                                  among all the slaves (if all the slaves
  21684.                                  are up to date, this will be the last
  21685.                                  log on the list), backup all the logs
  21686.                                  you are about to delete (optional) and
  21687.                                  purge up to the target log.
  21688.  
  21689. Replication FAQ
  21690. ---------------
  21691.  
  21692. *Q*: How do I configure a slave if the master is already running and I
  21693. do not want to stop it?
  21694.  
  21695. *A*: There are several options. If you have taken a backup of the
  21696. master at some point and recorded the binlog name and offset ( from the
  21697. output of `SHOW MASTER STATUS' ) corresponding to the snapshot, do the
  21698. following:
  21699.  
  21700.    * Make sure unique server id is assigned to the slave.
  21701.  
  21702.    * Execute `CHANGE MASTER TO MASTER_HOST='master-host-name',
  21703.      MASTER_USER='master-user-name', MASTER_PASSWORD='master-pass',
  21704.      MASTER_LOG_FILE='recorded-log-name',
  21705.      MASTER_LOG_POS=recorded_log_pos'
  21706.  
  21707.    * Execute `SLAVE START'
  21708.  
  21709. If you do not have a backup of the master already, here is a quick way
  21710. to do it consistently:
  21711.  
  21712.    * `FLUSH TABLES WITH READ LOCK'
  21713.  
  21714.    * `gtar zcf /tmp/backup.tar.gz /var/lib/mysql' ( or a variation of
  21715.      this)
  21716.  
  21717.    * `SHOW MASTER STATUS' - make sure to record the output - you will
  21718.      need it later
  21719.  
  21720.    * `UNLOCK TABLES'
  21721.  
  21722. Afterwards, follow the instructions for the case when you have a
  21723. snapshot and have recorded the log name and offset. You can use the
  21724. same snapshot to set up several slaves. As long as the binary logs of
  21725. the master are left intact, you can wait as long as several days or in
  21726. some cases maybe a month to set up a slave once you have the snapshot
  21727. of the master. In theory the waiting gap can be infinite. The two
  21728. practical limitations is the diskspace of the master getting filled
  21729. with old logs, and the amount of time it will take the slave to catch
  21730. up.
  21731.  
  21732. In version 4.0.0 and newer, you can also use `LOAD DATA FROM MASTER'.
  21733. This is a convenient command that will take a snapshot, restore it to
  21734. the slave, and adjust the log name and offset on the slave all at once.
  21735. In the future, `LOAD DATA FROM MASTER' will be the recommended way to
  21736. set up a slave.  Be warned, howerver, that the read lock may be held
  21737. for a long time if you use this command. It is not yet implemented as
  21738. efficiently as we would like to have it. If you have large tables, the
  21739. preferred method at this time is still with a local `tar' snapshot
  21740. after executing `FLUSH TABLES WITH READ LOCK'.
  21741.  
  21742. *Q*: Does the slave need to be connected to the master all the time?
  21743.  
  21744. *A*: No, it does not. You can have the slave go down or stay
  21745. disconnected for hours or even days, then reconnect, catch up on the
  21746. updates, and then disconnect or go down for a while again. So you can,
  21747. for example, use master-slave setup over a dial-up link that is up only
  21748. for short periods of time. The implications of that are that at any
  21749. given time the slave is not guaranteed to be in sync with the master
  21750. unless you take some special measures. In the future, we will have the
  21751. option to block the master until at least one slave is in sync.
  21752.  
  21753. *Q*: How do I force the master to block updates until the slave catches
  21754. up?
  21755.  
  21756. *A*: Execute the following commands:
  21757.  
  21758.    * Master: `FLUSH TABLES WITH READ LOCK'
  21759.  
  21760.    * Master: `SHOW MASTER STATUS' - record the log name and the offset
  21761.  
  21762.    * Slave: `SELECT MASTER_POS_WAIT('recorded_log_name',
  21763.      recorded_log_offset)' When the select returns, the slave is
  21764.      currently in sync with the master
  21765.  
  21766.    * Master: `UNLOCK TABLES' - now the master will continue updates.
  21767.  
  21768. *Q*: Why do I sometimes see more than one `Binlog_Dump' thread on the
  21769. master after I have restarted the slave?
  21770.  
  21771. *A*: `Binlog_Dump' is a continuous process that is handled by the
  21772. server in the following way:
  21773.  
  21774.    * Catch up on the updates.
  21775.  
  21776.    * Once there are no more updates left, go into `pthread_cond_wait()',
  21777.      from which we can be awakened either by an update or a kill.
  21778.  
  21779.    * On wake up, check the reason. If we are not supposed to die,
  21780.      continue the `Binlog_dump' loop.
  21781.  
  21782.    * If there is some fatal error, such as detecting a dead client,
  21783.      terminate the loop.
  21784.  
  21785. So if the slave thread stops on the slave, the corresponding
  21786. `Binlog_Dump' thread on the master will not notice it until after at
  21787. least one update to the master (or a kill), which is needed to wake it
  21788. up from `pthread_cond_wait()'.  In the meantime, the slave could have
  21789. opened another connection, which resulted in another `Binlog_Dump'
  21790. thread.
  21791.  
  21792. The above problem should not be present in Version 3.23.26 and later
  21793. versions.  In Version 3.23.26 we added `server-id' to each replication
  21794. server, and now all the old zombie threads are killed on the master
  21795. when a new replication thread connects from the same slave
  21796.  
  21797. *Q*: How do I rotate replication logs?
  21798.  
  21799. *A*: In Version 3.23.28 you should use `PURGE MASTER LOGS TO' command
  21800. after determining which logs can be deleted, and optionally backing
  21801. them up first. In earlier versions the process is much more painful,
  21802. and cannot be safely done without stopping all the slaves in the case
  21803. that you plan to re-use log names. You will need to stop the slave
  21804. threads, edit the binary log index file, delete all the old logs,
  21805. restart the master, start slave threads, and then remove the old log
  21806. files.
  21807.  
  21808. *Q*: How do I upgrade on a hot replication setup?
  21809.  
  21810. *A*: If you are upgrading  pre-3.23.26 versions, you should just lock
  21811. the master tables, let the slave catch up, then run `FLUSH MASTER' on
  21812. the master, and `FLUSH SLAVE' on the slave to reset the logs, then
  21813. restart new versions of the master and the slave. Note that the slave
  21814. can stay down for some time - since the master is logging all the
  21815. updates, the slave will be able to catch up once it is up and can
  21816. connect.
  21817.  
  21818. After 3.23.26, we have locked the replication protocol for
  21819. modifications, so you can upgrade masters and slave on the fly to a
  21820. newer 3.23 version and you can have different versions of MySQL running
  21821. on the slave and the master, as long as they are both newer than
  21822. 3.23.26.
  21823.  
  21824. *Q*: What issues should I be aware of when setting up two-way
  21825. replication?
  21826.  
  21827. *A*: MySQL replication currently does not support any locking protocol
  21828. between master and slave to guarantee the atomicity of a distributed
  21829. (cross-server) update. In other words, it is possible for client A to
  21830. make an update to  co-master 1, and in the meantime, before it
  21831. propagates to co-master 2, client B could make an update to co-master 2
  21832. that will make the update of client A work differently than it did on
  21833. co-master 1. Thus when the update of client A will make it to co-master
  21834. 2, it will produce  tables that will be different from what you have on
  21835. co-master 1, even after all the updates from co-master 2 have also
  21836. propagated. So you should not co-chain two servers in a two-way
  21837. replication relationship, unless you are sure that you updates can
  21838. safely happen in any order, or unless you take care of mis-ordered
  21839. updates somehow in the client code.
  21840.  
  21841. You must also realise that two-way replication actually does not improve
  21842. performance very much, if at all, as far as updates are concerned. Both
  21843. servers need to do the same amount of updates each, as you would have
  21844. one server do. The only difference is that there will be a little less
  21845. lock contention, because the updates originating on another server will
  21846. be serialised in one slave thread. This benefit, though, might be
  21847. offset by network delays.
  21848.  
  21849. *Q*: How can I use replication to improve performance of my system?
  21850.  
  21851. *A*: You should set up one server as the master, and direct all writes
  21852. to it, and configure as many slaves as you have the money and rackspace
  21853. for, distributing the reads among the master and the slaves.  You can
  21854. also start the slaves with `--skip-bdb', `--low-priority-updates' and
  21855. `--delay-key-write=ALL' to get speed improvements for the slave.  In
  21856. this case the slave will use non-transactional `MyISAM' tables instead
  21857. of `BDB' tables to get more speed.
  21858.  
  21859. *Q*: What should I do to prepare my client code to use
  21860. performance-enhancing replication?
  21861.  
  21862. *A*: If the part of your code that is responsible for database access
  21863. has been properly abstracted/modularised, converting it to run with the
  21864. replicated setup should be very smooth and easy - just change the
  21865. implementation of your database access to read from some slave or the
  21866. master, and to always write to the master. If your code does not have
  21867. this level of abstraction, setting up a replicated system will give you
  21868. an opportunity/motivation to it clean up.   You should start by
  21869. creating a wrapper library /module with the following functions:
  21870.  
  21871.    * `safe_writer_connect()'
  21872.  
  21873.    * `safe_reader_connect()'
  21874.  
  21875.    * `safe_reader_query()'
  21876.  
  21877.    * `safe_writer_query()'
  21878.  
  21879. `safe_' means that the function will take care of handling all the
  21880. error conditions.
  21881.  
  21882. You should then convert your client code to use the wrapper library.
  21883. It may be a painful and scary process at first, but it will pay off in
  21884. the long run. All applications that follow the above pattern will be
  21885. able to take advantage of one-master/many slaves solution.  The code
  21886. will be a lot easier to maintain, and adding troubleshooting options
  21887. will be trivial. You will just need to modify one or two functions, for
  21888. example, to log how long each query took, or which query, among your
  21889. many thousands, gave you an error. If you have written a lot of code
  21890. already, you may want to automate the conversion task by using Monty's
  21891. `replace' utility, which comes with the standard distribution of MySQL,
  21892. or just write your own Perl script.  Hopefully, your code follows some
  21893. recognisable pattern. If not, then you are probably better off
  21894. rewriting it anyway, or at least going through and manually beating it
  21895. into a pattern.
  21896.  
  21897. Note that, of course, you can use different names for the functions.
  21898. What is important is having unified interface for connecting for reads,
  21899. connecting for writes, doing a read, and doing a write.
  21900.  
  21901. *Q*: When and how much can MySQL replication improve the performance of
  21902. my system?
  21903.  
  21904. *A*: MySQL replication is most beneficial for a system with frequent
  21905. reads and not so frequent writes. In theory, by using a one master/many
  21906. slaves setup you can scale by adding more slaves until you either run
  21907. out of network bandwidth, or your update load grows to the point that
  21908. the master cannot handle it.
  21909.  
  21910. In order to determine how many slaves you can get before the added
  21911. benefits begin to level out, and how much you can improve performance
  21912. of your site, you need to know your query patterns, and empirically
  21913. (by benchmarking) determine the relationship between the throughput on
  21914. reads (reads per second, or `max_reads') and on writes `max_writes') on
  21915. a typical master and a typical slave. The example here will show you a
  21916. rather simplified calculation of what you can get with replication for
  21917. our imagined system.
  21918.  
  21919. Let's say our system load consists of 10% writes and 90% reads, and we
  21920. have determined that `max_reads' = 1200 - 2 * `max_writes', or in other
  21921. words, our system can do 1200 reads per second with no writes, our
  21922. average write is twice as slow as average read, and the relationship is
  21923. linear. Let us suppose that our master and slave are of the same
  21924. capacity, and we have N slaves and 1 master. Then we have for each
  21925. server (master or slave):
  21926.  
  21927. `reads = 1200 - 2 * writes' (from bencmarks)
  21928.  
  21929. `reads = 9* writes / (N + 1) ' (reads split, but writes go to all
  21930. servers)
  21931.  
  21932. `9*writes/(N+1) + 2 * writes = 1200'
  21933.  
  21934. `writes = 1200/(2 + 9/(N+1)'
  21935.  
  21936. So if N = 0, which means we have no replication, our system can handle
  21937. 1200/11, about 109 writes per second (which means we will have 9 times
  21938. as many reads due to the nature of our application).
  21939.  
  21940. If N = 1, we can get up to 184 writes per second.
  21941.  
  21942. If N = 8, we get up to 400.
  21943.  
  21944. If N = 17, 480 writes.
  21945.  
  21946. Eventually as N approaches infinity (and our budget negative infinity),
  21947. we can get very close to 600 writes per second, increasing system
  21948. throughput about 5.5 times. However, with only 8 servers, we increased
  21949. it almost 4 times already.
  21950.  
  21951. Note that our computations assumed infinite network bandwidth, and
  21952. neglected several other factors that could turn out to be significant on
  21953. your system. In many cases, you may not be able to make a computation
  21954. similar to the one above that will accurately predict what will happen
  21955. on your system if you add N replication slaves. However, answering the
  21956. following questions should help you decided whether and how much, if at
  21957. all, the replication will improve the performance of your system:
  21958.  
  21959.    * What is the read/write ratio on your system?
  21960.  
  21961.    * How much more write load can one server handle if you reduce the
  21962.      reads?
  21963.  
  21964.    * How many slaves do you have bandwidth for on your network?
  21965.  
  21966. *Q*: How can I use replication to provide redundancy/high availability?
  21967.  
  21968. *A*: With the currently available features, you would have to set up a
  21969. master and a slave (or several slaves), and write a script that will
  21970. monitor the master to see if it is up, and instruct your applications
  21971. and the slaves of the master change in case of failure. Some
  21972. suggestions:
  21973.  
  21974.    * To tell a slave to change the master use the `CHANGE MASTER TO'
  21975.      command.
  21976.  
  21977.    * A good way to keep your applications informed as to the location
  21978.      of the master is by having a dynamic DNS entry for the master.
  21979.      With `bind' you can use `nsupdate' to dynamically update your DNS.
  21980.  
  21981.    * You should run your slaves with the `log-bin' option and without
  21982.      `log-slave-updates'. This way the slave will be ready to become a
  21983.      master as soon as you issue `STOP SLAVE'; `RESET MASTER', and
  21984.      `CHANGE MASTER TO' on the other slaves. It will also help you catch
  21985.      spurious updates that may happen because of misconfiguration of the
  21986.      slave (ideally, you want to configure access rights so that no
  21987.      client can update the slave, except for the slave thread) combined
  21988.      with the bugs in your client programs (they should never update
  21989.      the slave directly).
  21990.  
  21991.  
  21992. We are currently working on integrating an automatic master election
  21993. system into MySQL, but until it is ready, you will have to create your
  21994. own monitoring tools.
  21995.  
  21996. Troubleshooting Replication
  21997. ---------------------------
  21998.  
  21999. If you have followed the instructions, and your replication setup is not
  22000. working, first eliminate the user error factor by checking the
  22001. following:
  22002.  
  22003.    * Is the master logging to the binary log? Check with `SHOW MASTER
  22004.      STATUS'.  If it is, `Position' will be non-zero. If not, verify
  22005.      that you have given the master `log-bin' option and have set
  22006.      `server-id'.
  22007.  
  22008.    * Is the slave running? Check with `SHOW SLAVE STATUS'. The answer
  22009.      is found in `Slave_running' column. If not, verify slave options
  22010.      and check the error log for messages.
  22011.  
  22012.    * If the slave is running, did it establish connection with the
  22013.      master? Do `SHOW PROCESSLIST', find the thread with `system user'
  22014.      value in `User' column and `none' in the `Host' column, and check
  22015.      the `State' column. If it says `connecting to master', verify the
  22016.      privileges for the replication user on the master, master host
  22017.      name, your DNS setup, whether the master is actually running,
  22018.      whether it is reachable from the slave, and if all that seems
  22019.      okay, read the error logs.
  22020.  
  22021.    * If the slave was running, but then stopped, look at SHOW SLAVE
  22022.      STATUS output and check the error logs. It usually happens when
  22023.      some query that succeeded on the master fails on the slave. This
  22024.      should never happen if you have taken a proper snapshot of the
  22025.      master, and never modify the data on the slave outside of the
  22026.      slave thread. If it does, it is a bug, read below on how to report
  22027.      it.
  22028.  
  22029.    * If a query on that succeeded on the master refuses to run on the
  22030.      slave, and a full database resync ( the proper thing to do ) does
  22031.      not seem feasible, try the following:
  22032.         - First see if there is some stray record in the way.
  22033.           Understand how it got there, then delete it and run `SLAVE
  22034.           START'
  22035.  
  22036.         - If the above does not work or does not apply, try to
  22037.           understand if it would be safe to make the update manually (
  22038.           if needed) and then ignore the next query from the master.
  22039.  
  22040.         - If you have decided you can skip the next query, do `SET
  22041.           GLOBAL SQL_SLAVE_SKIP_COUNTER=1; SLAVE START;' to skip a
  22042.           query that does not use `AUTO_INCREMENT' or
  22043.           `LAST_INSERT_ID()',  or `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
  22044.           SLAVE START;' otherwise. The reason queries that use
  22045.           `AUTO_INCREMENT' or `LAST_INSERT_ID()' are different is that
  22046.           they take two events in the binary log of the master.
  22047.  
  22048.         - If you are sure the slave started out perfectly in sync with
  22049.           the master, and no one has updated  the tables involved
  22050.           outside of slave thread, report the bug, so you will not have
  22051.           to do the above tricks again.
  22052.  
  22053.    * Make sure you are not running into an old bug by upgrading to the
  22054.      most recent version.
  22055.  
  22056.    * If all else fails, read the error logs. If they are big, `grep -i
  22057.      slave /path/to/your-log.err' on the slave. There is no generic
  22058.      pattern to search for on the master, as the only errors it logs
  22059.      are general system errors - if it can, it will send the error to
  22060.      the slave when things go wrong.
  22061.  
  22062. When you have determined that there is no user error involved, and
  22063. replication still either does not work at all or is unstable, it is
  22064. time to start working on a bug report. We need to get as much info as
  22065. possible from you to be able to track down the bug. Please do spend
  22066. some time and effort preparing a good bug report. Ideally, we would
  22067. like to have a test case in the format found in `mysql-test/t/rpl*'
  22068. directory of the source tree. If you submit a test case like that, you
  22069. can expect a patch within a day or two in most cases, although, of
  22070. course, you mileage may vary depending on a number of factors.
  22071.  
  22072. The second best option is to write a simple program with easily
  22073. configurable connection arguments for the master and the slave that
  22074. will demonstrate the problem on our systems. You can write one in Perl
  22075. or in C, depending on which language you know better.
  22076.  
  22077. If you have one of the above ways to demonstrate the bug, use
  22078. `mysqlbug' to prepare a bug report and send it to
  22079. <bugs@lists.mysql.com>. If you have a phantom - a problem that does
  22080. occur but you cannot duplicate "at will":
  22081.  
  22082.    * Verify that there is no user error involved. For example, if you
  22083.      update the slave outside of the slave thread, the data will be out
  22084.      of sync, and you can have unique key violations on updates, in
  22085.      which case the slave thread will stop and wait for you to clean up
  22086.      the tables manually to bring them in sync.
  22087.  
  22088.    * Run slave with `log-slave-updates' and `log-bin' - this will keep
  22089.      a log of all updates on the slave.
  22090.  
  22091.    * Save all evidence before resetting the replication. If we have no
  22092.      or only sketchy information, it would take us a while to track
  22093.      down the problem. The evidence you should collect is:
  22094.         - All binary logs on the master
  22095.  
  22096.         - All binary log on the slave
  22097.  
  22098.         - The output of `SHOW MASTER STATUS' on the master at the time
  22099.           you have discovered the problem
  22100.  
  22101.         - The output of `SHOW SLAVE STATUS' on the master at the time
  22102.           you have discovered the problem
  22103.  
  22104.         - Error logs on the master and on the slave
  22105.  
  22106.    * Use `mysqlbinlog' to examine the binary logs. The following should
  22107.      be helpful to find the trouble query, for example:
  22108.           mysqlbinlog -j pos_from_slave_status /path/to/log_from_slave_status | head
  22109.  
  22110. Once you have collected the evidence on the phantom problem, try hard to
  22111. isolate it into a separate test case first. Then report the problem to
  22112. <bugs@lists.mysql.com> with as much info as possible.
  22113.  
  22114. MySQL Optimisation
  22115. ******************
  22116.  
  22117. Optimisation is a complicated task because it ultimately requires
  22118. understanding of the whole system. While it may be possible to do some
  22119. local optimisations with small knowledge of your system or application,
  22120. the more optimal you want your system to become the more you will have
  22121. to know about it.
  22122.  
  22123. This chapter will try to explain and give some examples of different
  22124. ways to optimise MySQL.  Remember, however, that there are always some
  22125. (increasingly harder) additional ways to make the system even faster.
  22126.  
  22127. Optimisation Overview
  22128. =====================
  22129.  
  22130. The most important part for getting a system fast is of course the basic
  22131. design. You also need to know what kinds of things your system will be
  22132. doing, and what your bottlenecks are.
  22133.  
  22134. The most common bottlenecks are:
  22135.    * Disk seeks.  It takes time for the disk to find a piece of data.
  22136.      With modern disks in 1999, the mean time for this is usually lower
  22137.      than 10ms, so we can in theory do about 100 seeks a second. This
  22138.      time improves slowly with new disks and is very hard to optimise
  22139.      for a single table. The way to optimise this is to spread the data
  22140.      on more than one disk.
  22141.  
  22142.    * Disk reading/writing.  When the disk is at the correct position we
  22143.      need to read the data. With modern disks in 1999, one disk
  22144.      delivers something like 10-20MB/s. This is easier to optimise than
  22145.      seeks because you can read in parallel from multiple disks.
  22146.  
  22147.    * CPU cycles.  When we have the data in main memory (or if it
  22148.      already were there) we need to process it to get to our result.
  22149.      Having small tables compared to the memory is the most common
  22150.      limiting factor. But then, with small tables speed is usually not
  22151.      the problem.
  22152.  
  22153.    * Memory bandwidth.  When the CPU needs more data than can fit in
  22154.      the CPU cache the main memory bandwidth becomes a bottleneck. This
  22155.      is an uncommon bottleneck for most systems, but one should be
  22156.      aware of it.
  22157.  
  22158. MySQL Design Limitations/Tradeoffs
  22159. ----------------------------------
  22160.  
  22161. When using the MyISAM storage engine, MySQL uses extremely fast table
  22162. locking (multiple readers / single writers). The biggest problem with
  22163. this table type is a if you have a mix of a steady stream of updates and
  22164. slow selects on the same table.  If this is a problem with some tables,
  22165. you can use another table type for these. *Note Table types::.
  22166.  
  22167. MySQL can work with both transactional and not transactional tables.  To
  22168. be able to work smoothly with not transactional tables (which can't
  22169. rollback if something goes wrong), MySQL has the following rules:
  22170.  
  22171.    * All columns has default values.
  22172.  
  22173.    * If you insert a 'wrong' value in a column like a `NULL' in a `NOT
  22174.      NULL' column or a too big numerical value in a numerical column,
  22175.      MySQL will instead of giving an error instead set the column to
  22176.      the 'best possible value'.  For numerical values this is 0, the
  22177.      smallest possible values or the largest possible value. For
  22178.      strings this is either the empty string or the longest possible
  22179.      string that can be in the column.
  22180.  
  22181.    * All calculated expressions returns a value that can be used
  22182.      instead of signaling an error condition. For example 1/0 returns
  22183.      `NULL'
  22184.  
  22185. The reason for the above rules is that we can't check these conditions
  22186. before the query starts to execute.  If we encounter a problem after
  22187. updating a few rows, we can't just rollback as the table type may not
  22188. support this.  We can't stop because in that case the update would be
  22189. 'half done' which is probably the worst possible scenario.  In this case
  22190. it's better to 'do the best you can' and then continue as if nothing
  22191. happened.
  22192.  
  22193. The above means that one should not use MySQL to check fields content,
  22194. but one should do this in the application.
  22195.  
  22196. Portability
  22197. -----------
  22198.  
  22199. Because all SQL servers implement different parts of SQL, it takes work
  22200. to write portable SQL applications. For very simple selects/inserts it
  22201. is very easy, but the more you need the harder it gets. If you want an
  22202. application that is fast with many databases it becomes even harder!
  22203.  
  22204. To make a complex application portable you need to choose a number of
  22205. SQL servers that it should work with.
  22206.  
  22207. You can use the MySQL `crash-me' program/web-page
  22208. `http://www.mysql.com/information/crash-me.php' to find functions,
  22209. types, and limits you can use with a selection of database servers.
  22210. Crash-me now tests far from everything possible, but it is still
  22211. comprehensive with about 450 things tested.
  22212.  
  22213. For example, you shouldn't have column names longer than 18 characters
  22214. if you want to be able to use Informix or DB2.
  22215.  
  22216. Both the MySQL benchmarks and `crash-me' programs are very
  22217. database-independent.  By taking a look at how we have handled this, you
  22218. can get a feeling for what you have to do to write your application
  22219. database-independent.  The benchmarks themselves can be found in the
  22220. `sql-bench' directory in the MySQL source distribution. They are
  22221. written in Perl with DBI database interface (which solves the access
  22222. part of the problem).
  22223.  
  22224. See `http://www.mysql.com/information/benchmarks.html' for the results
  22225. from this benchmark.
  22226.  
  22227. As you can see in these results, all databases have some weak points.
  22228. That is, they have different design compromises that lead to different
  22229. behaviour.
  22230.  
  22231. If you strive for database independence, you need to get a good feeling
  22232. for each SQL server's bottlenecks. MySQL is very fast in retrieving and
  22233. updating things, but will have a problem in mixing slow readers/writers
  22234. on the same table. Oracle, on the other hand, has a big problem when
  22235. you try to access rows that you have recently updated (until they are
  22236. flushed to disk). Transaction databases in general are not very good at
  22237. generating summary tables from log tables, as in this case row locking
  22238. is almost useless.
  22239.  
  22240. To get your application _really_ database-independent, you need to
  22241. define an easy extendable interface through which you manipulate your
  22242. data. As C++ is available on most systems, it makes sense to use a C++
  22243. classes interface to the databases.
  22244.  
  22245. If you use some specific feature for some database (like the `REPLACE'
  22246. command in MySQL), you should code a method for the other SQL servers
  22247. to implement the same feature (but slower).  With MySQL you can use the
  22248. `/*!  */' syntax to add MySQL-specific keywords to a query.  The code
  22249. inside `/**/' will be treated as a comment (ignored) by most other SQL
  22250. servers.
  22251.  
  22252. If high performance is more important than exactness, as in some web
  22253. applications, it is possibile to create an application layer that
  22254. caches all results to give you even higher performance. By letting old
  22255. results 'expire' after a while, you can keep the cache reasonably
  22256. fresh.  This provides a method to handle high load spikes, in which case
  22257. you can dynamically increase the cache and set the expire timeout higher
  22258. until things get back to normal.
  22259.  
  22260. In this case the table creation information should contain information
  22261. of the initial size of the cache and how often the table should normally
  22262. be refreshed.
  22263.  
  22264. What Have We Used MySQL For?
  22265. ----------------------------
  22266.  
  22267. During MySQL initial development, the features of MySQL were made to
  22268. fit our largest customer. They handle data warehousing for a couple of
  22269. the biggest retailers in Sweden.
  22270.  
  22271. From all stores, we get weekly summaries of all bonus card transactions,
  22272. and we are expected to provide useful information for the store owners
  22273. to help them find how their advertisement campaigns are affecting their
  22274. customers.
  22275.  
  22276. The data is quite huge (about 7 million summary transactions per month),
  22277. and we have data for 4-10 years that we need to present to the users.
  22278. We got weekly requests from the customers that they want to get
  22279. 'instant' access to new reports from this data.
  22280.  
  22281. We solved this by storing all information per month in compressed
  22282. 'transaction' tables. We have a set of simple macros (script) that
  22283. generates summary tables grouped by different criteria (product group,
  22284. customer id, store ...) from the transaction tables.  The reports are
  22285. web pages that are dynamically generated by a small Perl script that
  22286. parses a web page, executes the SQL statements in it, and inserts the
  22287. results. We would have used PHP or mod_perl instead but they were not
  22288. available at that time.
  22289.  
  22290. For graphical data we wrote a simple tool in `C' that can produce GIFs
  22291. based on the result of a SQL query (with some processing of the
  22292. result). This is also dynamically executed from the Perl script that
  22293. parses the `HTML' files.
  22294.  
  22295. In most cases a new report can simply be done by copying an existing
  22296. script and modifying the SQL query in it.  In some cases, we will need
  22297. to add more fields to an existing summary table or generate a new one,
  22298. but this is also quite simple, as we keep all transactions tables on
  22299. disk.  (Currently we have at least 50G of transactions tables and 200G
  22300. of other customer data.)
  22301.  
  22302. We also let our customers access the summary tables directly with ODBC
  22303. so that the advanced users can themselves experiment with the data.
  22304.  
  22305. We haven't had any problems handling this with quite modest Sun Ultra
  22306. SPARCstation (2x200 Mhz). We recently upgraded one of our servers to a 2
  22307. CPU 400 Mhz UltraSPARC, and we are now planning to start handling
  22308. transactions on the product level, which would mean a ten-fold increase
  22309. of data. We think we can keep up with this by just adding more disk to
  22310. our systems.
  22311.  
  22312. We are also experimenting with Intel-Linux to be able to get more CPU
  22313. power cheaper. Now that we have the binary portable database format (new
  22314. in Version 3.23), we will start to use this for some parts of the
  22315. application.
  22316.  
  22317. Our initial feelings are that Linux will perform much better on
  22318. low-to-medium load and Solaris will perform better when you start to
  22319. get a high load because of extreme disk IO, but we don't yet have
  22320. anything conclusive about this. After some discussion with a Linux
  22321. Kernel developer, this might be a side effect of Linux giving so much
  22322. resources to the batch job that the interactive performance gets very
  22323. low. This makes the machine feel very slow and unresponsive while big
  22324. batches are going. Hopefully this will be better handled in future
  22325. Linux Kernels.
  22326.  
  22327. The MySQL Benchmark Suite
  22328. -------------------------
  22329.  
  22330. This should contain a technical description of the MySQL benchmark
  22331. suite (and `crash-me'), but that description is not written yet.
  22332. Currently, you can get a good idea of the benchmark by looking at the
  22333. code and results in the `sql-bench' directory in any MySQL source
  22334. distributions.
  22335.  
  22336. This benchmark suite is meant to be a benchmark that will tell any user
  22337. what things a given SQL implementation performs well or poorly at.
  22338.  
  22339. Note that this benchmark is single threaded, so it measures the minimum
  22340. time for the operations. We plan to in the future add a lot of
  22341. multi-threaded tests to the benchmark suite.
  22342.  
  22343. For example, (run on the same NT 4.0 machine):
  22344.  
  22345. *Reading 2000000 rows by  *Seconds**Seconds*
  22346. index*                            
  22347. mysql                     367     249
  22348. mysql_odbc                464     
  22349. db2_odbc                  1206    
  22350. informix_odbc             121126  
  22351. ms-sql_odbc               1634    
  22352. oracle_odbc               20800   
  22353. solid_odbc                877     
  22354. sybase_odbc               17614   
  22355.  
  22356. *Inserting (350768)       *Seconds**Seconds*
  22357. rows*                             
  22358. mysql                     381     206
  22359. mysql_odbc                619     
  22360. db2_odbc                  3460    
  22361. informix_odbc             2692    
  22362. ms-sql_odbc               4012    
  22363. oracle_odbc               11291   
  22364. solid_odbc                1801    
  22365. sybase_odbc               4802    
  22366.  
  22367. In the above test MySQL was run with a 8M index cache.
  22368.  
  22369. We have gathered some more benchmark results at
  22370. `http://www.mysql.com/information/benchmarks.html'.
  22371.  
  22372. Note that Oracle is not included because they asked to be removed. All
  22373. Oracle benchmarks have to be passed by Oracle! We believe that makes
  22374. Oracle benchmarks *very* biased because the above benchmarks are
  22375. supposed to show what a standard installation can do for a single
  22376. client.
  22377.  
  22378. To run the benchmark suite, you have to download a MySQL source
  22379. distribution, install the perl DBI driver, the perl DBD driver for the
  22380. database you want to test and then do:
  22381.  
  22382.      cd sql-bench
  22383.      perl run-all-tests --server=#
  22384.  
  22385. where # is one of supported servers. You can get a list of all options
  22386. and supported servers by doing `run-all-tests --help'.
  22387.  
  22388. `crash-me' tries to determine what features a database supports and
  22389. what its capabilities and limitations are by actually running queries.
  22390. For example, it determines:
  22391.  
  22392.    * What column types are supported
  22393.  
  22394.    * How many indexes are supported
  22395.  
  22396.    * What functions are supported
  22397.  
  22398.    * How big a query can be
  22399.  
  22400.    * How big a `VARCHAR' column can be
  22401.  
  22402. We can find the result from `crash-me' on a lot of different databases
  22403. at `http://www.mysql.com/information/crash-me.php'.
  22404.  
  22405. Using Your Own Benchmarks
  22406. -------------------------
  22407.  
  22408. You should definitely benchmark your application and database to find
  22409. out where the bottlenecks are.  By fixing it (or by replacing the
  22410. bottleneck with a 'dummy module') you can then easily identify the next
  22411. bottleneck (and so on).  Even if the overall performance for your
  22412. application is sufficient, you should at least make a plan for each
  22413. bottleneck, and decide how to solve it if someday you really need the
  22414. extra performance.
  22415.  
  22416. For an example of portable benchmark programs, look at the MySQL
  22417. benchmark suite. *Note MySQL Benchmarks: MySQL Benchmarks. You can take
  22418. any program from this suite and modify it for your needs. By doing
  22419. this, you can try different solutions to your problem and test which is
  22420. really the fastest solution for you.
  22421.  
  22422. It is very common that some problems only occur when the system is very
  22423. heavily loaded. We have had many customers who contact us when they
  22424. have a (tested) system in production and have encountered load
  22425. problems. In every one of these cases so far, it has been problems with
  22426. basic design (table scans are *not good* at high load) or OS/Library
  22427. issues. Most of this would be a *lot* easier to fix if the systems were
  22428. not already in production.
  22429.  
  22430. To avoid problems like this, you should put some effort into
  22431. benchmarking your whole application under the worst possible load!  You
  22432. can use Super Smack for this, and it is available at:
  22433. `http://www.mysql.com/Downloads/super-smack/super-smack-1.0.tar.gz'.
  22434. As the name suggests, it can bring your system down to its knees if you
  22435. ask it, so make sure to use it only on your development systems.
  22436.  
  22437. Optimising `SELECT's and Other Queries
  22438. ======================================
  22439.  
  22440. First, one thing that affects all queries: The more complex permission
  22441. system setup you have, the more overhead you get.
  22442.  
  22443. If you do not have any `GRANT' statements done, MySQL will optimise the
  22444. permission checking somewhat. So if you have a very high volume it may
  22445. be worth the time to avoid grants. Otherwise, more permission check
  22446. results in a larger overhead.
  22447.  
  22448. If your problem is with some explicit MySQL function, you can always
  22449. time this in the MySQL client:
  22450.  
  22451.      mysql> SELECT BENCHMARK(1000000,1+1);
  22452.      +------------------------+
  22453.      | BENCHMARK(1000000,1+1) |
  22454.      +------------------------+
  22455.      |                      0 |
  22456.      +------------------------+
  22457.      1 row in set (0.32 sec)
  22458.  
  22459. The above shows that MySQL can execute 1,000,000 `+' expressions in
  22460. 0.32 seconds on a `PentiumII 400MHz'.
  22461.  
  22462. All MySQL functions should be very optimised, but there may be some
  22463. exceptions, and the `BENCHMARK(loop_count,expression)' is a great tool
  22464. to find out if this is a problem with your query.
  22465.  
  22466. `EXPLAIN' Syntax (Get Information About a `SELECT')
  22467. ---------------------------------------------------
  22468.  
  22469.          EXPLAIN tbl_name
  22470.      or  EXPLAIN SELECT select_options
  22471.  
  22472. `EXPLAIN tbl_name' is a synonym for `DESCRIBE tbl_name' or `SHOW
  22473. COLUMNS FROM tbl_name'.
  22474.  
  22475. When you precede a `SELECT' statement with the keyword `EXPLAIN', MySQL
  22476. explains how it would process the `SELECT', providing information about
  22477. how tables are joined and in which order.
  22478.  
  22479. With the help of `EXPLAIN', you can see when you must add indexes to
  22480. tables to get a faster `SELECT' that uses indexes to find the records.
  22481.  
  22482. You should frequently run `ANALYZE TABLE' to update table statistics
  22483. such as cardinality of keys which can affect the choices the optimiser
  22484. makes. *Note ANALYZE TABLE::.
  22485.  
  22486. You can also see if the optimiser joins the tables in an optimal order.
  22487. To force the optimiser to use a specific join order for a `SELECT'
  22488. statement, add a `STRAIGHT_JOIN' clause.
  22489.  
  22490. For non-simple joins, `EXPLAIN' returns a row of information for each
  22491. table used in the `SELECT' statement. The tables are listed in the order
  22492. they would be read.  MySQL resolves all joins using a single-sweep
  22493. multi-join method. This means that MySQL reads a row from the first
  22494. table, then finds a matching row in the second table, then in the third
  22495. table and so on. When all tables are processed, it outputs the selected
  22496. columns and backtracks through the table list until a table is found
  22497. for which there are more matching rows. The next row is read from this
  22498. table and the process continues with the next table.
  22499.  
  22500. In MySQL version 4.1 the `EXPLAIN' output was changed to work better
  22501. with constructs like `UNION's, subqueries and derived tables. Most
  22502. notable is the addition of two new columns: `id' and `select_type'.
  22503.  
  22504. Output from `EXPLAIN' consists of the following columns:
  22505.  
  22506. `id'
  22507.      `SELECT' identifier, the sequential number of this `SELECT' within
  22508.      the query.
  22509.  
  22510. `select_type'
  22511.      Type of `SELECT' clause, which can be any of the following:
  22512.  
  22513.     `SIMPLE'
  22514.           Simple `SELECT' (without `UNION's or subqueries).
  22515.  
  22516.     `PRIMARY'
  22517.           Outermost `SELECT'.
  22518.  
  22519.     `UNION'
  22520.           Second and further `UNION' `SELECT's.
  22521.  
  22522.     `DEPENDENT UNION'
  22523.           Second and further `UNION' `SELECTS's, dependent on outer
  22524.           subquery.
  22525.  
  22526.     `SUBSELECT'
  22527.           First `SELECT' in subquery.
  22528.  
  22529.     `DEPENDENT SUBSELECT'
  22530.           First `SELECT', dependent on outer subquery.
  22531.  
  22532.     `DERIVED'
  22533.           Derived table `SELECT'.
  22534.  
  22535. `table'
  22536.      The table to which the row of output refers.
  22537.  
  22538. `type'
  22539.      The join type. The different join types are listed here, ordered
  22540.      from best to worst type:
  22541.  
  22542.     `system'
  22543.           The table has only one row (= system table). This is a
  22544.           special case of the `const' join type.
  22545.  
  22546.     `const'
  22547.           The table has at most one matching row, which will be read at
  22548.           the start of the query. Because there is only one row, values
  22549.           from the column in this row can be regarded as constants by
  22550.           the rest of the optimiser. `const' tables are very fast as
  22551.           they are read only once!
  22552.  
  22553.     `eq_ref'
  22554.           One row will be read from this table for each combination of
  22555.           rows from the previous tables.  This is the best possible
  22556.           join type, other than the `const' types.  It is used when all
  22557.           parts of an index are used by the join and the index is
  22558.           `UNIQUE' or a `PRIMARY KEY'.
  22559.  
  22560.     `ref'
  22561.           All rows with matching index values will be read from this
  22562.           table for each combination of rows from the previous tables.
  22563.           `ref' is used if the join uses only a leftmost prefix of the
  22564.           key, or if the key is not `UNIQUE' or a `PRIMARY KEY' (in
  22565.           other words, if the join cannot select a single row based on
  22566.           the key value).  If the key that is used matches only a few
  22567.           rows, this join type is good.
  22568.  
  22569.     `range'
  22570.           Only rows that are in a given range will be retrieved, using
  22571.           an index to select the rows.  The `key' column indicates
  22572.           which index is used.  The `key_len' contains the longest key
  22573.           part that was used.  The `ref' column will be `NULL' for this
  22574.           type.
  22575.  
  22576.     `index'
  22577.           This is the same as `ALL', except that only the index tree is
  22578.           scanned.  This is usually faster than `ALL', as the index
  22579.           file is usually smaller than the datafile.
  22580.  
  22581.     `ALL'
  22582.           A full table scan will be done for each combination of rows
  22583.           from the previous tables.  This is normally not good if the
  22584.           table is the first table not marked `const', and usually
  22585.           *very* bad in all other cases. You normally can avoid `ALL'
  22586.           by adding more indexes, so that the row can be retrieved
  22587.           based on constant values or column values from earlier tables.
  22588.  
  22589. `possible_keys'
  22590.      The `possible_keys' column indicates which indexes MySQL could use
  22591.      to find the rows in this table. Note that this column is totally
  22592.      independent of the order of the tables. That means that some of
  22593.      the keys in possible_keys may not be usable in practice with the
  22594.      generated table order.
  22595.  
  22596.      If this column is empty, there are no relevant indexes. In this
  22597.      case, you may be able to improve the performance of your query by
  22598.      examining the `WHERE' clause to see if it refers to some column or
  22599.      columns that would be suitable for indexing.  If so, create an
  22600.      appropriate index and check the query with `EXPLAIN' again. *Note
  22601.      ALTER TABLE::.
  22602.  
  22603.      To see what indexes a table has, use `SHOW INDEX FROM tbl_name'.
  22604.  
  22605. `key'
  22606.      The `key' column indicates the key (index) that MySQL actually
  22607.      decided to use. The key is `NULL' if no index was chosen. To force
  22608.      MySQL to use an key listed in the `possible_keys' column, use `USE
  22609.      KEY/IGNORE KEY' in your query.  *Note SELECT::.
  22610.  
  22611.      Also, running `myisamchk --analyze' (*note myisamchk syntax::) or
  22612.      `ANALYZE TABLE' (*note ANALYZE TABLE::) on the table will help the
  22613.      optimiser choose better indexes.
  22614.  
  22615. `key_len'
  22616.      The `key_len' column indicates the length of the key that MySQL
  22617.      decided to use.  The length is `NULL' if the `key' is `NULL'. Note
  22618.      that this tells us how many parts of a multi-part key MySQL will
  22619.      actually use.
  22620.  
  22621. `ref'
  22622.      The `ref' column shows which columns or constants are used with the
  22623.      `key' to select rows from the table.
  22624.  
  22625. `rows'
  22626.      The `rows' column indicates the number of rows MySQL believes it
  22627.      must examine to execute the query.
  22628.  
  22629. `Extra'
  22630.      This column contains additional information of how MySQL will
  22631.      resolve the query. Here is an explanation of the different text
  22632.      strings that can be found in this column:
  22633.  
  22634.     `Distinct'
  22635.           MySQL will not continue searching for more rows for the
  22636.           current row combination after it has found the first matching
  22637.           row.
  22638.  
  22639.     `Not exists'
  22640.           MySQL was able to do a `LEFT JOIN' optimisation on the query
  22641.           and will not examine more rows in this table for the previous
  22642.           row combination after it finds one row that matches the `LEFT
  22643.           JOIN' criteria.
  22644.  
  22645.           Here is an example for this:
  22646.  
  22647.                SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
  22648.  
  22649.           Assume that `t2.id' is defined with `NOT NULL'.  In this case
  22650.           MySQL will scan `t1' and look up the rows in `t2' through
  22651.           `t1.id'. If MySQL finds a matching row in `t2', it knows that
  22652.           `t2.id' can never be `NULL', and will not scan through the
  22653.           rest of the rows in `t2' that has the same `id'.  In other
  22654.           words, for each row in `t1', MySQL only needs to do a single
  22655.           lookup in `t2', independent of how many matching rows there
  22656.           are in `t2'.
  22657.  
  22658.     ``range checked for each record (index map: #)''
  22659.           MySQL didn't find a real good index to use. It will, instead,
  22660.           for each row combination in the preceding tables, do a check
  22661.           on which index to use (if any), and use this index to
  22662.           retrieve the rows from the table.  This isn't very fast but
  22663.           is faster than having to do a join without an index.
  22664.  
  22665.     `Using filesort'
  22666.           MySQL will need to do an extra pass to find out how to
  22667.           retrieve the rows in sorted order.  The sort is done by going
  22668.           through all rows according to the `join type' and storing the
  22669.           sort key + pointer to the row for all rows that match the
  22670.           `WHERE'. Then the keys are sorted. Finally the rows are
  22671.           retrieved in sorted order.
  22672.  
  22673.     `Using index'
  22674.           The column information is retrieved from the table using only
  22675.           information in the index tree without having to do an
  22676.           additional seek to read the actual row.  This can be done
  22677.           when all the used columns for the table are part of the same
  22678.           index.
  22679.  
  22680.     `Using temporary'
  22681.           To resolve the query MySQL will need to create a temporary
  22682.           table to hold the result.  This typically happens if you do an
  22683.           `ORDER BY' on a different column set than you did a `GROUP
  22684.           BY' on.
  22685.  
  22686.     `Using where'
  22687.           A `WHERE' clause will be used to restrict which rows will be
  22688.           matched against the next table or sent to the client.  If you
  22689.           don't have this information and the table is of type `ALL' or
  22690.           `index', you may have something wrong in your query (if you
  22691.           don't intend to fetch/examine all rows from the table).
  22692.  
  22693.      If you want to get your queries as fast as possible, you should
  22694.      look out for `Using filesort' and `Using temporary'.
  22695.  
  22696. You can get a good indication of how good a join is by multiplying all
  22697. values in the `rows' column of the `EXPLAIN' output. This should tell
  22698. you roughly how many rows MySQL must examine to execute the query. This
  22699. number is also used when you restrict queries with the `max_join_size'
  22700. variable.  *Note Server parameters::.
  22701.  
  22702. The following example shows how a `JOIN' can be optimised progressively
  22703. using the information provided by `EXPLAIN'.
  22704.  
  22705. Suppose you have the `SELECT' statement shown here, that you examine
  22706. using `EXPLAIN':
  22707.  
  22708.      EXPLAIN SELECT tt.TicketNumber, tt.TimeIn,
  22709.                  tt.ProjectReference, tt.EstimatedShipDate,
  22710.                  tt.ActualShipDate, tt.ClientID,
  22711.                  tt.ServiceCodes, tt.RepetitiveID,
  22712.                  tt.CurrentProcess, tt.CurrentDPPerson,
  22713.                  tt.RecordVolume, tt.DPPrinted, et.COUNTRY,
  22714.                  et_1.COUNTRY, do.CUSTNAME
  22715.              FROM tt, et, et AS et_1, do
  22716.              WHERE tt.SubmitTime IS NULL
  22717.                  AND tt.ActualPC = et.EMPLOYID
  22718.                  AND tt.AssignedPC = et_1.EMPLOYID
  22719.                  AND tt.ClientID = do.CUSTNMBR;
  22720.  
  22721. For this example, assume that:
  22722.  
  22723.    * The columns being compared have been declared as follows:
  22724.  
  22725.      *Table* *Column*   *Column
  22726.                         type*
  22727.      `tt'    `ActualPC' `CHAR(10)'
  22728.      `tt'    `AssignedPC'`CHAR(10)'
  22729.      `tt'    `ClientID' `CHAR(10)'
  22730.      `et'    `EMPLOYID' `CHAR(15)'
  22731.      `do'    `CUSTNMBR' `CHAR(15)'
  22732.  
  22733.    * The tables have the indexes shown here:
  22734.  
  22735.      *Table* *Index*
  22736.      `tt'    `ActualPC'
  22737.      `tt'    `AssignedPC'
  22738.      `tt'    `ClientID'
  22739.      `et'    `EMPLOYID' (primary
  22740.              key)
  22741.      `do'    `CUSTNMBR' (primary
  22742.              key)
  22743.  
  22744.    * The `tt.ActualPC' values aren't evenly distributed.
  22745.  
  22746. Initially, before any optimisations have been performed, the `EXPLAIN'
  22747. statement produces the following information:
  22748.  
  22749.      table type possible_keys                key  key_len ref  rows  Extra
  22750.      et    ALL  PRIMARY                      NULL NULL    NULL 74
  22751.      do    ALL  PRIMARY                      NULL NULL    NULL 2135
  22752.      et_1  ALL  PRIMARY                      NULL NULL    NULL 74
  22753.      tt    ALL  AssignedPC,ClientID,ActualPC NULL NULL    NULL 3872
  22754.            range checked for each record (key map: 35)
  22755.  
  22756. Because `type' is `ALL' for each table, this output indicates that
  22757. MySQL is doing a full join for all tables!  This will take quite a long
  22758. time, as the product of the number of rows in each table must be
  22759. examined!  For the case at hand, this is `74 * 2135 * 74 * 3872 =
  22760. 45,268,558,720' rows.  If the tables were bigger, you can only imagine
  22761. how long it would take.
  22762.  
  22763. One problem here is that MySQL can't (yet) use indexes on columns
  22764. efficiently if they are declared differently.  In this context,
  22765. `VARCHAR' and `CHAR' are the same unless they are declared as different
  22766. lengths. Because `tt.ActualPC' is declared as `CHAR(10)' and
  22767. `et.EMPLOYID' is declared as `CHAR(15)', there is a length mismatch.
  22768.  
  22769. To fix this disparity between column lengths, use `ALTER TABLE' to
  22770. lengthen `ActualPC' from 10 characters to 15 characters:
  22771.  
  22772.      mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15);
  22773.  
  22774. Now `tt.ActualPC' and `et.EMPLOYID' are both `VARCHAR(15)'.  Executing
  22775. the `EXPLAIN' statement again produces this result:
  22776.  
  22777.      table type   possible_keys   key     key_len ref         rows    Extra
  22778.      tt    ALL    AssignedPC,ClientID,ActualPC NULL NULL NULL 3872    Using where
  22779.      do    ALL    PRIMARY         NULL    NULL    NULL        2135
  22780.            range checked for each record (key map: 1)
  22781.      et_1  ALL    PRIMARY         NULL    NULL    NULL        74
  22782.            range checked for each record (key map: 1)
  22783.      et    eq_ref PRIMARY         PRIMARY 15      tt.ActualPC 1
  22784.  
  22785. This is not perfect, but is much better (the product of the `rows'
  22786. values is now less by a factor of 74). This version is executed in a
  22787. couple of seconds.
  22788.  
  22789. A second alteration can be made to eliminate the column length
  22790. mismatches for the `tt.AssignedPC = et_1.EMPLOYID' and `tt.ClientID =
  22791. do.CUSTNMBR' comparisons:
  22792.  
  22793.      mysql> ALTER TABLE tt MODIFY AssignedPC VARCHAR(15),
  22794.          ->                MODIFY ClientID   VARCHAR(15);
  22795.  
  22796. Now `EXPLAIN' produces the output shown here:
  22797.  
  22798.      table type   possible_keys   key      key_len ref           rows Extra
  22799.      et    ALL    PRIMARY         NULL     NULL    NULL          74
  22800.      tt    ref    AssignedPC,     ActualPC 15      et.EMPLOYID   52   where used
  22801.                   ClientID,
  22802.                   ActualPC
  22803.      et_1  eq_ref PRIMARY         PRIMARY  15      tt.AssignedPC 1
  22804.      do    eq_ref PRIMARY         PRIMARY  15      tt.ClientID   1
  22805.  
  22806. This is almost as good as it can get.
  22807.  
  22808. The remaining problem is that, by default, MySQL assumes that values in
  22809. the `tt.ActualPC' column are evenly distributed, and that isn't the
  22810. case for the `tt' table.  Fortunately, it is easy to tell MySQL about
  22811. this:
  22812.  
  22813.      shell> myisamchk --analyze PATH_TO_MYSQL_DATABASE/tt
  22814.      shell> mysqladmin refresh
  22815.  
  22816. Now the join is perfect, and `EXPLAIN' produces this result:
  22817.  
  22818.      table type   possible_keys key     key_len ref           rows Extra
  22819.      tt    ALL    AssignedPC    NULL    NULL    NULL          3872 where used
  22820.                   ClientID,
  22821.                   ActualPC
  22822.      et    eq_ref PRIMARY       PRIMARY 15      tt.ActualPC   1
  22823.      et_1  eq_ref PRIMARY       PRIMARY 15      tt.AssignedPC 1
  22824.      do    eq_ref PRIMARY       PRIMARY 15      tt.ClientID   1
  22825.  
  22826. Note that the `rows' column in the output from `EXPLAIN' is an educated
  22827. guess from the MySQL join optimiser. To optimise a query, you should
  22828. check if the numbers are even close to the truth.  If not, you may get
  22829. better performance by using `STRAIGHT_JOIN' in your `SELECT' statement
  22830. and trying to list the tables in a different order in the `FROM' clause.
  22831.  
  22832. Estimating Query Performance
  22833. ----------------------------
  22834.  
  22835. In most cases you can estimate the performance by counting disk seeks.
  22836. For small tables, you can usually find the row in 1 disk seek (as the
  22837. index is probably cached).  For bigger tables, you can estimate that
  22838. (using B++ tree indexes) you will need: `log(row_count) /
  22839. log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) +
  22840. 1' seeks to find a row.
  22841.  
  22842. In MySQL an index block is usually 1024 bytes and the data pointer is
  22843. usually 4 bytes. A 500,000 row table with an index length of 3 (medium
  22844. integer) gives you: `log(500,000)/log(1024/3*2/(3+4)) + 1' = 4 seeks.
  22845.  
  22846. As the above index would require about 500,000 * 7 * 3/2 = 5.2M,
  22847. (assuming that the index buffers are filled to 2/3, which is typical)
  22848. you will probably have much of the index in memory and you will probably
  22849. only need 1-2 calls to read data from the OS to find the row.
  22850.  
  22851. For writes, however, you will need 4 seek requests (as above) to find
  22852. where to place the new index and normally 2 seeks to update the index
  22853. and write the row.
  22854.  
  22855. Note that the above doesn't mean that your application will slowly
  22856. degenerate by log N!  As long as everything is cached by the OS or SQL
  22857. server things will only go marginally slower while the table gets
  22858. bigger. After the data gets too big to be cached, things will start to
  22859. go much slower until your applications is only bound by disk-seeks
  22860. (which increase by log N). To avoid this, increase the index cache as
  22861. the data grows. *Note Server parameters::.
  22862.  
  22863. Speed of `SELECT' Queries
  22864. -------------------------
  22865.  
  22866. In general, when you want to make a slow `SELECT ... WHERE' faster, the
  22867. first thing to check is whether you can add an index. *Note MySQL
  22868. indexes: MySQL indexes. All references between different tables should
  22869. usually be done with indexes. You can use the `EXPLAIN' command to
  22870. determine which indexes are used for a `SELECT'.  *Note `EXPLAIN':
  22871. EXPLAIN.
  22872.  
  22873. Some general tips:
  22874.  
  22875.    * To help MySQL optimise queries better, run `myisamchk --analyze'
  22876.      on a table after it has been loaded with relevant data. This
  22877.      updates a value for each index part that indicates the average
  22878.      number of rows that have the same value.  (For unique indexes,
  22879.      this is always 1, of course.)  MySQL will use this to decide which
  22880.      index to choose when you connect two tables with 'a non-constant
  22881.      expression'.  You can check the result from the `analyze' run by
  22882.      doing `SHOW INDEX FROM table_name' and examining the `Cardinality'
  22883.      column.
  22884.  
  22885.    * To sort an index and data according to an index, use `myisamchk
  22886.      --sort-index --sort-records=1' (if you want to sort on index 1).
  22887.      If you have a unique index from which you want to read all records
  22888.      in order according to that index, this is a good way to make that
  22889.      faster.  Note, however, that this sorting isn't written optimally
  22890.      and will take a long time for a large table!
  22891.  
  22892. How MySQL Optimises `WHERE' Clauses
  22893. -----------------------------------
  22894.  
  22895. The `WHERE' optimisations are put in the `SELECT' part here because
  22896. they are mostly used with `SELECT', but the same optimisations apply for
  22897. `WHERE' in `DELETE' and `UPDATE' statements.
  22898.  
  22899. Also note that this section is incomplete. MySQL does many
  22900. optimisations, and we have not had time to document them all.
  22901.  
  22902. Some of the optimisations performed by MySQL are listed here:
  22903.  
  22904.    * Removal of unnecessary parentheses:
  22905.              ((a AND b) AND c OR (((a AND b) AND (c AND d))))
  22906.           -> (a AND b AND c) OR (a AND b AND c AND d)
  22907.  
  22908.    * Constant folding:
  22909.              (a<b AND b=c) AND a=5
  22910.           -> b>5 AND b=c AND a=5
  22911.  
  22912.    * Constant condition removal (needed because of constant folding):
  22913.              (B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
  22914.           -> B=5 OR B=6
  22915.  
  22916.    * Constant expressions used by indexes are evaluated only once.
  22917.  
  22918.    * `COUNT(*)' on a single table without a `WHERE' is retrieved
  22919.      directly from the table information for `MyISAM' and `HEAP' tables.
  22920.      This is also done for any `NOT NULL' expression when used with
  22921.      only one table.
  22922.  
  22923.    * Early detection of invalid constant expressions. MySQL quickly
  22924.      detects that some `SELECT' statements are impossible and returns
  22925.      no rows.
  22926.  
  22927.    * `HAVING' is merged with `WHERE' if you don't use `GROUP BY' or
  22928.      group functions (`COUNT()', `MIN()'...).
  22929.  
  22930.    * For each sub-join, a simpler `WHERE' is constructed to get a fast
  22931.      `WHERE' evaluation for each sub-join and also to skip records as
  22932.      soon as possible.
  22933.  
  22934.    * All constant tables are read first, before any other tables in the
  22935.      query.  A constant table is:
  22936.         - An empty table or a table with 1 row.
  22937.  
  22938.         - A table that is used with a `WHERE' clause on a `UNIQUE'
  22939.           index, or a `PRIMARY KEY', where all index parts are used
  22940.           with constant expressions and the index parts are defined as
  22941.           `NOT NULL'.
  22942.      All the following tables are used as constant tables:
  22943.           mysql> SELECT * FROM t WHERE primary_key=1;
  22944.           mysql> SELECT * FROM t1,t2
  22945.               ->          WHERE t1.primary_key=1 AND t2.primary_key=t1.id;
  22946.  
  22947.    * The best join combination to join the tables is found by trying all
  22948.      possibilities. If all columns in `ORDER BY' and in `GROUP BY' come
  22949.      from the same table, then this table is preferred first when
  22950.      joining.
  22951.  
  22952.    * If there is an `ORDER BY' clause and a different `GROUP BY'
  22953.      clause, or if the `ORDER BY' or `GROUP BY' contains columns from
  22954.      tables other than the first table in the join queue, a temporary
  22955.      table is created.
  22956.  
  22957.    * If you use `SQL_SMALL_RESULT', MySQL will use an in-memory
  22958.      temporary table.
  22959.  
  22960.    * Each table index is queried, and the best index that spans fewer
  22961.      than 30% of the rows is used. If no such index can be found, a
  22962.      quick table scan is used.
  22963.  
  22964.    * In some cases, MySQL can read rows from the index without even
  22965.      consulting the datafile.  If all columns used from the index are
  22966.      numeric, then only the index tree is used to resolve the query.
  22967.  
  22968.    * Before each record is output, those that do not match the `HAVING'
  22969.      clause are skipped.
  22970.  
  22971. Some examples of queries that are very fast:
  22972.  
  22973.      mysql> SELECT COUNT(*) FROM tbl_name;
  22974.      mysql> SELECT MIN(key_part1),MAX(key_part1) FROM tbl_name;
  22975.      mysql> SELECT MAX(key_part2) FROM tbl_name
  22976.          ->        WHERE key_part_1=constant;
  22977.      mysql> SELECT ... FROM tbl_name
  22978.          ->        ORDER BY key_part1,key_part2,... LIMIT 10;
  22979.      mysql> SELECT ... FROM tbl_name
  22980.          ->        ORDER BY key_part1 DESC,key_part2 DESC,... LIMIT 10;
  22981.  
  22982. The following queries are resolved using only the index tree (assuming
  22983. the indexed columns are numeric):
  22984.  
  22985.      mysql> SELECT key_part1,key_part2 FROM tbl_name WHERE key_part1=val;
  22986.      mysql> SELECT COUNT(*) FROM tbl_name
  22987.          ->        WHERE key_part1=val1 AND key_part2=val2;
  22988.      mysql> SELECT key_part2 FROM tbl_name GROUP BY key_part1;
  22989.  
  22990. The following queries use indexing to retrieve the rows in sorted order
  22991. without a separate sorting pass:
  22992.  
  22993.      mysql> SELECT ... FROM tbl_name
  22994.          ->            ORDER BY key_part1,key_part2,... ;
  22995.      mysql> SELECT ... FROM tbl_name
  22996.          ->            ORDER BY key_part1 DESC,key_part2 DESC,... ;
  22997.  
  22998. How MySQL Optimises `DISTINCT'
  22999. ------------------------------
  23000.  
  23001. `DISTINCT' is converted to a `GROUP BY' on all columns, `DISTINCT'
  23002. combined with `ORDER BY' will in many cases also need a temporary table.
  23003.  
  23004. When combining `LIMIT #' with `DISTINCT', MySQL will stop as soon as it
  23005. finds `#' unique rows.
  23006.  
  23007. If you don't use columns from all used tables, MySQL will stop the
  23008. scanning of the not used tables as soon as it has found the first match.
  23009.  
  23010.      SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;
  23011.  
  23012. In the case, assuming `t1' is used before `t2' (check with `EXPLAIN'),
  23013. then MySQL will stop reading from `t2' (for that particular row in
  23014. `t1') when the first row in `t2' is found.
  23015.  
  23016. How MySQL Optimises `LEFT JOIN' and `RIGHT JOIN'
  23017. ------------------------------------------------
  23018.  
  23019. `A LEFT JOIN B' in MySQL is implemented as follows:
  23020.  
  23021.    * The table `B' is set to be dependent on table `A' and all tables
  23022.      that `A' is dependent on.
  23023.  
  23024.    * The table `A' is set to be dependent on all tables (except `B')
  23025.      that are used in the `LEFT JOIN' condition.
  23026.  
  23027.    * All `LEFT JOIN' conditions are moved to the `WHERE' clause.
  23028.  
  23029.    * All standard join optimisations are done, with the exception that
  23030.      a table is always read after all tables it is dependent on.  If
  23031.      there is a circular dependence then MySQL will issue an error.
  23032.  
  23033.    * All standard `WHERE' optimisations are done.
  23034.  
  23035.    * If there is a row in `A' that matches the `WHERE' clause, but there
  23036.      wasn't any row in `B' that matched the `LEFT JOIN' condition, then
  23037.      an extra `B' row is generated with all columns set to `NULL'.
  23038.  
  23039.    * If you use `LEFT JOIN' to find rows that don't exist in some table
  23040.      and you have the following test: `column_name IS NULL' in the
  23041.      `WHERE' part, where column_name is a column that is declared as
  23042.      `NOT NULL', then MySQL will stop searching after more rows (for a
  23043.      particular key combination) after it has found one row that
  23044.      matches the `LEFT JOIN' condition.
  23045.  
  23046. `RIGHT JOIN' is implemented analogously as `LEFT JOIN'.
  23047.  
  23048. The table read order forced by `LEFT JOIN' and `STRAIGHT JOIN' will
  23049. help the join optimiser (which calculates in which order tables should
  23050. be joined) to do its work much more quickly, as there are fewer table
  23051. permutations to check.
  23052.  
  23053. Note that the above means that if you do a query of type:
  23054.  
  23055.      SELECT * FROM a,b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key)
  23056.               WHERE b.key=d.key
  23057.  
  23058. MySQL will do a full scan on `b' as the `LEFT JOIN' will force it to be
  23059. read before `d'.
  23060.  
  23061. The fix in this case is to change the query to:
  23062.  
  23063.      SELECT * FROM b,a LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key)
  23064.               WHERE b.key=d.key
  23065.  
  23066. How MySQL Optimises `ORDER BY'
  23067. ------------------------------
  23068.  
  23069. In some cases MySQL can uses index to satisfy an `ORDER BY' or `GROUP
  23070. BY' request without doing any extra sorting.
  23071.  
  23072. The index can also be used even if the `ORDER BY' doesn't match the
  23073. index exactly, as long as all the unused index parts and all the extra
  23074. are `ORDER BY' columns are constants in the `WHERE' clause. The
  23075. following queries will use the index to resolve the `ORDER BY' / `GROUP
  23076. BY' part:
  23077.  
  23078.      SELECT * FROM t1 ORDER BY key_part1,key_part2,...
  23079.      SELECT * FROM t1 WHERE key_part1=constant ORDER BY key_part2
  23080.      SELECT * FROM t1 WHERE key_part1=constant GROUP BY key_part2
  23081.      SELECT * FROM t1 ORDER BY key_part1 DESC,key_part2 DESC
  23082.      SELECT * FROM t1 WHERE key_part1=1 ORDER BY key_part1 DESC,key_part2 DESC
  23083.  
  23084. Some cases where MySQL can *not* use indexes to resolve the `ORDER BY':
  23085. (Note that MySQL will still use indexes to find the rows that matches
  23086. the `WHERE' clause):
  23087.  
  23088.    * You are doing an `ORDER BY' on different keys:
  23089.  
  23090.      `SELECT * FROM t1 ORDER BY key1,key2'
  23091.  
  23092.    * You are doing an `ORDER BY' using non-consecutive key parts.
  23093.  
  23094.      `SELECT * FROM t1 WHERE key2=constant ORDER BY key_part2'
  23095.  
  23096.    * You are mixing `ASC' and `DESC'.
  23097.  
  23098.      `SELECT * FROM t1 ORDER BY key_part1 DESC,key_part2 ASC'
  23099.  
  23100.    * The key used to fetch the rows are not the same one that is used to
  23101.      do the `ORDER BY':
  23102.  
  23103.      `SELECT * FROM t1 WHERE key2=constant ORDER BY key1'
  23104.  
  23105.    * You are joining many tables and the columns you are doing an `ORDER
  23106.      BY' on are not all from the first not-`const' table that is used to
  23107.      retrieve rows (This is the first table in the `EXPLAIN' output
  23108.      which doesn't use a `const' row fetch method).
  23109.  
  23110.    * You have different `ORDER BY' and `GROUP BY' expressions.
  23111.  
  23112.    * The used table index is an index type that doesn't store rows in
  23113.      order.  (Like the `HASH' index in `HEAP' tables).
  23114.  
  23115.    * The index colum may contain `NULL' values and one is using `ORDER
  23116.      BY ... DESC'.  This is because in SQL `NULL' values is always
  23117.      sorted before normal values, independent of you are using `DESC'
  23118.      or not.
  23119.  
  23120. In the cases where MySQL have to sort the result, it uses the following
  23121. algorithm:
  23122.  
  23123.    * Read all rows according to key or by table scanning.  Rows that
  23124.      don't match the `WHERE' clause are skipped.
  23125.  
  23126.    * Store the sort-key in a buffer (of size `sort_buffer').
  23127.  
  23128.    * When the buffer gets full, run a qsort on it and store the result
  23129.      in a temporary file.  Save a pointer to the sorted block.  (In the
  23130.      case where all rows fits into the sort buffer, no temporary file
  23131.      is created)
  23132.  
  23133.    * Repeat the above until all rows have been read.
  23134.  
  23135.    * Do a multi-merge of up to `MERGEBUFF' (7) regions to one block in
  23136.      another temporary file.  Repeat until all blocks from the first
  23137.      file are in the second file.
  23138.  
  23139.    * Repeat the following until there is less than `MERGEBUFF2' (15)
  23140.      blocks left.
  23141.  
  23142.    * On the last multi-merge, only the pointer to the row (last part of
  23143.      the sort-key) is written to a result file.
  23144.  
  23145.    * Now the code in `sql/records.cc' will be used to read through them
  23146.      in sorted order by using the row pointers in the result file.  To
  23147.      optimise this, we read in a big block of row pointers, sort these
  23148.      and then we read the rows in the sorted order into a row buffer
  23149.      (`record_rnd_buffer') .
  23150.  
  23151. You can with `EXPLAIN SELECT ... ORDER BY' check if MySQL can use
  23152. indexes to resolve the query.  If you get `Using filesort' in the
  23153. `extra' column, then MySQL can't use indexes to resolve the `ORDER BY'.
  23154. *Note EXPLAIN::.
  23155.  
  23156. If you want to have a higher `ORDER BY' speed, you should first see if
  23157. you can get MySQL to use indexes instead of having to do an extra
  23158. sorting phase. If this is not possible, then you can do:
  23159.  
  23160.    * Increase the size of the `sort_buffer' variable.
  23161.  
  23162.    * Increase the size of the `record_rnd_buffer' variable.
  23163.  
  23164.    * Change `tmpdir' to point to a dedicated disk with lots of empty
  23165.      space.
  23166.  
  23167. How MySQL Optimises `LIMIT'
  23168. ---------------------------
  23169.  
  23170. In some cases MySQL will handle the query differently when you are
  23171. using `LIMIT #' and not using `HAVING':
  23172.  
  23173.    * If you are selecting only a few rows with `LIMIT', MySQL will use
  23174.      indexes in some cases when it normally would prefer to do a full
  23175.      table scan.
  23176.  
  23177.    * If you use `LIMIT #' with `ORDER BY', MySQL will end the sorting
  23178.      as soon as it has found the first `#' lines instead of sorting the
  23179.      whole table.
  23180.  
  23181.    * When combining `LIMIT #' with `DISTINCT', MySQL will stop as soon
  23182.      as it finds `#' unique rows.
  23183.  
  23184.    * In some cases a `GROUP BY' can be resolved by reading the key in
  23185.      order (or do a sort on the key) and then calculate summaries until
  23186.      the key value changes.  In this case `LIMIT #' will not calculate
  23187.      any unnecessary `GROUP BY's.
  23188.  
  23189.    * As soon as MySQL has sent the first `#' rows to the client, it
  23190.      will abort the query (if you are not using `SQL_CALC_FOUND_ROWS').
  23191.  
  23192.    * `LIMIT 0' will always quickly return an empty set.  This is useful
  23193.      to check the query and to get the column types of the result
  23194.      columns.
  23195.  
  23196.    * When the server uses temporary tables to resolve the query, the
  23197.      `LIMIT #' is used to calculate how much space is required.
  23198.  
  23199. Speed of `INSERT' Queries
  23200. -------------------------
  23201.  
  23202. The time to insert a record consists approximately of:
  23203.  
  23204.    * Connect:                 (3)
  23205.  
  23206.    * Sending query to server: (2)
  23207.  
  23208.    * Parsing query:           (2)
  23209.  
  23210.    * Inserting record:        (1 x size of record)
  23211.  
  23212.    * Inserting indexes:       (1 x number of indexes)
  23213.  
  23214.    * Close:                   (1)
  23215.  
  23216. where the numbers are somewhat proportional to the overall time. This
  23217. does not take into consideration the initial overhead to open tables
  23218. (which is done once for each concurrently running query).
  23219.  
  23220. The size of the table slows down the insertion of indexes by log N
  23221. (B-trees).
  23222.  
  23223. Some ways to speed up inserts:
  23224.  
  23225.    * If you are inserting many rows from the same client at the same
  23226.      time, use multiple value lists `INSERT' statements. This is much
  23227.      faster (many times in some cases) than using separate `INSERT'
  23228.      statements.  If you are adding data to non-empty table, you may
  23229.      tune up `bulk_insert_buffer_size'u`bulk_insert_buffer_size'
  23230.      variable to make it even faster.  *Note `bulk_insert_buffer_size':
  23231.      SHOW VARIABLES.
  23232.  
  23233.    * If you are inserting a lot of rows from different clients, you can
  23234.      get higher speed by using the `INSERT DELAYED' statement. *Note
  23235.      `INSERT': INSERT.
  23236.  
  23237.    * Note that with `MyISAM' tables you can insert rows at the same time
  23238.      `SELECT's are running if there are no deleted rows in the tables.
  23239.  
  23240.    * When loading a table from a text file, use `LOAD DATA INFILE'. This
  23241.      is usually 20 times faster than using a lot of `INSERT' statements.
  23242.      *Note `LOAD DATA': LOAD DATA.
  23243.  
  23244.    * It is possible with some extra work to make `LOAD DATA INFILE' run
  23245.      even faster when the table has many indexes. Use the following
  23246.      procedure:
  23247.  
  23248.        1. Optionally create the table with `CREATE TABLE'. For example,
  23249.           using `mysql' or Perl-DBI.
  23250.  
  23251.        2. Execute a `FLUSH TABLES' statement or the shell command
  23252.           `mysqladmin flush-tables'.
  23253.  
  23254.        3. Use `myisamchk --keys-used=0 -rq /path/to/db/tbl_name'. This
  23255.           will remove all usage of all indexes from the table.
  23256.  
  23257.        4. Insert data into the table with `LOAD DATA INFILE'. This will
  23258.           not update any indexes and will therefore be very fast.
  23259.  
  23260.        5. If you are going to only read the table in the future, run
  23261.           `myisampack' on it to make it smaller. *Note Compressed
  23262.           format::.
  23263.  
  23264.        6. Re-create the indexes with `myisamchk -r -q
  23265.           /path/to/db/tbl_name'. This will create the index tree in
  23266.           memory before writing it to disk, which is much faster
  23267.           because it avoids lots of disk seeks. The resulting index
  23268.           tree is also perfectly balanced.
  23269.  
  23270.        7. Execute a `FLUSH TABLES' statement or the shell command
  23271.           `mysqladmin flush-tables'.
  23272.  
  23273.      Note that `LOAD DATA INFILE' also does the above optimisation if
  23274.      you insert into an empty table; the main difference with the above
  23275.      procedure is that you can let `myisamchk' allocate much more
  23276.      temporary memory for the index creation that you may want MySQL to
  23277.      allocate for every index recreation.
  23278.  
  23279.      Since MySQL 4.0 you can also use `ALTER TABLE tbl_name DISABLE
  23280.      KEYS' instead of `myisamchk --keys-used=0 -rq
  23281.      /path/to/db/tbl_name' and `ALTER TABLE tbl_name ENABLE KEYS'
  23282.      instead of `myisamchk -r -q /path/to/db/tbl_name'. This way you
  23283.      can also skip `FLUSH TABLES' steps.
  23284.  
  23285.    * You can speed up insertions that is done over multiple statements
  23286.      by locking your tables:
  23287.  
  23288.           mysql> LOCK TABLES a WRITE;
  23289.           mysql> INSERT INTO a VALUES (1,23),(2,34),(4,33);
  23290.           mysql> INSERT INTO a VALUES (8,26),(6,29);
  23291.           mysql> UNLOCK TABLES;
  23292.  
  23293.      The main speed difference is that the index buffer is flushed to
  23294.      disk only once, after all `INSERT' statements have completed.
  23295.      Normally there would be as many index buffer flushes as there are
  23296.      different `INSERT' statements. Locking is not needed if you can
  23297.      insert all rows with a single statement.
  23298.  
  23299.      For transactional tables, you should use `BEGIN/COMMIT' instead of
  23300.      `LOCK TABLES' to get a speedup.
  23301.  
  23302.      Locking will also lower the total time of multi-connection tests,
  23303.      but the maximum wait time for some threads will go up (because
  23304.      they wait for locks).  For example:
  23305.  
  23306.           thread 1 does 1000 inserts
  23307.           thread 2, 3, and 4 does 1 insert
  23308.           thread 5 does 1000 inserts
  23309.  
  23310.      If you don't use locking, 2, 3, and 4 will finish before 1 and 5.
  23311.      If you use locking, 2, 3, and 4 probably will not finish before 1
  23312.      or 5, but the total time should be about 40% faster.
  23313.  
  23314.      As `INSERT', `UPDATE', and `DELETE' operations are very fast in
  23315.      MySQL, you will obtain better overall performance by adding locks
  23316.      around everything that does more than about 5 inserts or updates
  23317.      in a row.  If you do very many inserts in a row, you could do a
  23318.      `LOCK TABLES' followed by an `UNLOCK TABLES' once in a while
  23319.      (about each 1000 rows) to allow other threads access to the table.
  23320.      This would still result in a nice performance gain.
  23321.  
  23322.      Of course, `LOAD DATA INFILE' is much faster for loading data.
  23323.  
  23324. To get some more speed for both `LOAD DATA INFILE' and `INSERT',
  23325. enlarge the key buffer. *Note Server parameters::.
  23326.  
  23327. Speed of `UPDATE' Queries
  23328. -------------------------
  23329.  
  23330. Update queries are optimised as a `SELECT' query with the additional
  23331. overhead of a write. The speed of the write is dependent on the size of
  23332. the data that is being updated and the number of indexes that are
  23333. updated.  Indexes that are not changed will not be updated.
  23334.  
  23335. Also, another way to get fast updates is to delay updates and then do
  23336. many updates in a row later. Doing many updates in a row is much quicker
  23337. than doing one at a time if you lock the table.
  23338.  
  23339. Note that, with dynamic record format, updating a record to a longer
  23340. total length may split the record.  So if you do this often, it is very
  23341. important to `OPTIMIZE TABLE' sometimes.  *Note `OPTIMIZE TABLE':
  23342. OPTIMIZE TABLE.
  23343.  
  23344. Speed of `DELETE' Queries
  23345. -------------------------
  23346.  
  23347. If you want to delete all rows in the table, you should use `TRUNCATE
  23348. TABLE table_name'. *Note TRUNCATE::.
  23349.  
  23350. The time to delete a record is exactly proportional to the number of
  23351. indexes. To delete records more quickly, you can increase the size of
  23352. the index cache. *Note Server parameters::.
  23353.  
  23354. Other Optimisation Tips
  23355. -----------------------
  23356.  
  23357. Unsorted tips for faster systems:
  23358.  
  23359.    * Use persistent connections to the database to avoid the connection
  23360.      overhead. If you can't use persistent connections and you are
  23361.      doing a lot of new connections to the database, you may want to
  23362.      change the value of the `thread_cache_size' variable. *Note Server
  23363.      parameters::.
  23364.  
  23365.    * Always check that all your queries really use the indexes you have
  23366.      created in the tables. In MySQL you can do this with the `EXPLAIN'
  23367.      command. *Note Explain: (manual)EXPLAIN.
  23368.  
  23369.    * Try to avoid complex `SELECT' queries on `MyISAM' tables that are
  23370.      updated a lot. This is to avoid problems with table locking.
  23371.  
  23372.    * The new `MyISAM' tables can insert rows in a table without deleted
  23373.      rows at the same time another table is reading from it.  If this
  23374.      is important for you, you should consider methods where you don't
  23375.      have to delete rows or run `OPTIMIZE TABLE' after you have deleted
  23376.      a lot of rows.
  23377.  
  23378.    * Use `ALTER TABLE ... ORDER BY expr1,expr2...' if you mostly
  23379.      retrieve rows in `expr1,expr2...' order.  By using this option
  23380.      after big changes to the table, you may be able to get higher
  23381.      performance.
  23382.  
  23383.    * In some cases it may make sense to introduce a column that is
  23384.      'hashed' based on information from other columns. If this column
  23385.      is short and reasonably unique it may be much faster than a big
  23386.      index on many columns. In MySQL it's very easy to use this extra
  23387.      column: `SELECT * FROM table_name WHERE hash=MD5(CONCAT(col1,col2))
  23388.      AND col_1='constant' AND col_2='constant''
  23389.  
  23390.    * For tables that change a lot you should try to avoid all `VARCHAR'
  23391.      or `BLOB' columns. You will get dynamic row length as soon as you
  23392.      are using a single `VARCHAR' or `BLOB' column. *Note Table types::.
  23393.  
  23394.    * It's not normally useful to split a table into different tables
  23395.      just because the rows gets 'big'. To access a row, the biggest
  23396.      performance hit is the disk seek to find the first byte of the
  23397.      row. After finding the data most new disks can read the whole row
  23398.      fast enough for most applications. The only cases where it really
  23399.      matters to split up a table is if it's a dynamic row size table
  23400.      (see above) that you can change to a fixed row size, or if you
  23401.      very often need to scan the table and don't need most of the
  23402.      columns. *Note Table types::.
  23403.  
  23404.    * If you very often need to calculate things based on information
  23405.      from a lot of rows (like counts of things), it's probably much
  23406.      better to introduce a new table and update the counter in real
  23407.      time. An update of type `UPDATE table set count=count+1 where
  23408.      index_column=constant' is very fast!
  23409.  
  23410.      This is really important when you use MySQL table types like
  23411.      MyISAM and ISAM that only have table locking (multiple readers /
  23412.      single writers). This will also give better performance with most
  23413.      databases, as the row locking manager in this case will have less
  23414.      to do.
  23415.  
  23416.    * If you need to collect statistics from big log tables, use summary
  23417.      tables instead of scanning the whole table. Maintaining the
  23418.      summaries should be much faster than trying to do statistics
  23419.      'live'. It's much faster to regenerate new summary tables from the
  23420.      logs when things change (depending on business decisions) than to
  23421.      have to change the running application!
  23422.  
  23423.    * If possible, one should classify reports as 'live' or
  23424.      'statistical', where data needed for statistical reports are only
  23425.      generated based on summary tables that are generated from the
  23426.      actual data.
  23427.  
  23428.    * Take advantage of the fact that columns have default values. Insert
  23429.      values explicitly only when the value to be inserted differs from
  23430.      the default. This reduces the parsing that MySQL need to do and
  23431.      improves the insert speed.
  23432.  
  23433.    * In some cases it's convenient to pack and store data into a blob.
  23434.      In this case you have to add some extra code in your application
  23435.      to pack/unpack things in the blob, but this may save a lot of
  23436.      accesses at some stage.  This is practical when you have data that
  23437.      doesn't conform to a static table structure.
  23438.  
  23439.    * Normally you should try to keep all data non-redundant (what is
  23440.      called 3rd normal form in database theory), but you should not be
  23441.      afraid of duplicating things or creating summary tables if you
  23442.      need these to gain more speed.
  23443.  
  23444.    * Stored procedures or UDF (user-defined functions) may be a good
  23445.      way to get more performance.  In this case you should, however,
  23446.      always have a way to do this some other (slower) way if you use
  23447.      some database that doesn't support this.
  23448.  
  23449.    * You can always gain something by caching queries/answers in your
  23450.      application and trying to do many inserts/updates at the same
  23451.      time.  If your database supports lock tables (like MySQL and
  23452.      Oracle), this should help to ensure that the index cache is only
  23453.      flushed once after all updates.
  23454.  
  23455.    * Use `INSERT /*! DELAYED */' when you do not need to know when your
  23456.      data is written. This speeds things up because many records can be
  23457.      written with a single disk write.
  23458.  
  23459.    * Use `INSERT /*! LOW_PRIORITY */' when you want your selects to be
  23460.      more important.
  23461.  
  23462.    * Use `SELECT /*! HIGH_PRIORITY */' to get selects that jump the
  23463.      queue. That is, the select is done even if there is somebody
  23464.      waiting to do a write.
  23465.  
  23466.    * Use the multi-line `INSERT' statement to store many rows with one
  23467.      SQL command (many SQL servers supports this).
  23468.  
  23469.    * Use `LOAD DATA INFILE' to load bigger amounts of data. This is
  23470.      faster than normal inserts and will be even faster when `myisamchk'
  23471.      is integrated in `mysqld'.
  23472.  
  23473.    * Use `AUTO_INCREMENT' columns to make unique values.
  23474.  
  23475.    * Use `OPTIMIZE TABLE' once in a while to avoid fragmentation when
  23476.      using a dynamic table format. *Note `OPTIMIZE TABLE': OPTIMIZE
  23477.      TABLE.
  23478.  
  23479.    * Use `HEAP' tables to get more speed when possible. *Note Table
  23480.      types::.
  23481.  
  23482.    * When using a normal web server setup, images should be stored as
  23483.      files. That is, store only a file reference in the database.  The
  23484.      main reason for this is that a normal web server is much better at
  23485.      caching files than database contents. So it it's much easier to
  23486.      get a fast system if you are using files.
  23487.  
  23488.    * Use in memory tables for non-critical data that are accessed often
  23489.      (like information about the last shown banner for users that don't
  23490.      have cookies).
  23491.  
  23492.    * Columns with identical information in different tables should be
  23493.      declared identical and have identical names. Before Version 3.23
  23494.      you got slow joins otherwise.
  23495.  
  23496.      Try to keep the names simple (use `name' instead of
  23497.      `customer_name' in the customer table). To make your names portable
  23498.      to other SQL servers you should keep them shorter than 18
  23499.      characters.
  23500.  
  23501.    * If you need really high speed, you should take a look at the
  23502.      low-level interfaces for data storage that the different SQL
  23503.      servers support!  For example, by accessing the MySQL `MyISAM'
  23504.      directly, you could get a speed increase of 2-5 times compared to
  23505.      using the SQL interface.  To be able to do this the data must be
  23506.      on the same server as the application, and usually it should only
  23507.      be accessed by one process (because external file locking is
  23508.      really slow).  One could eliminate the above problems by
  23509.      introducing low-level `MyISAM' commands in the MySQL server (this
  23510.      could be one easy way to get more performance if needed).  By
  23511.      carefully designing the database interface, it should be quite
  23512.      easy to support this types of optimisation.
  23513.  
  23514.    * In many cases it's faster to access data from a database (using a
  23515.      live connection) than accessing a text file, just because the
  23516.      database is likely to be more compact than the text file (if you
  23517.      are using numerical data), and this will involve fewer disk
  23518.      accesses.  You will also save code because you don't have to parse
  23519.      your text files to find line and column boundaries.
  23520.  
  23521.    * You can also use replication to speed things up. *Note
  23522.      Replication::.
  23523.  
  23524.    * Declaring a table with `DELAY_KEY_WRITE=1' will make the updating
  23525.      of indexes faster, as these are not logged to disk until the file
  23526.      is closed.  The downside is that you should run `myisamchk' on
  23527.      these tables before you start `mysqld' to ensure that they are
  23528.      okay if something killed `mysqld' in the middle.  As the key
  23529.      information can always be generated from the data, you should not
  23530.      lose anything by using `DELAY_KEY_WRITE'.
  23531.  
  23532. Locking Issues
  23533. ==============
  23534.  
  23535. How MySQL Locks Tables
  23536. ----------------------
  23537.  
  23538. You can find a discussion about different locking methods in the
  23539. appendix.  *Note Locking methods::.
  23540.  
  23541. All locking in MySQL is deadlock-free, except for `InnoDB' and `BDB'
  23542. type tables.  This is managed by always requesting all needed locks at
  23543. once at the beginning of a query and always locking the tables in the
  23544. same order.
  23545.  
  23546. `InnoDB' type tables automatically acquire their row locks and `BDB'
  23547. type tables their page locks during the processing of SQL statements,
  23548. not at the start of the transaction.
  23549.  
  23550. The locking method MySQL uses for `WRITE' locks works as follows:
  23551.  
  23552.    * If there are no locks on the table, put a write lock on it.
  23553.  
  23554.    * Otherwise, put the lock request in the write lock queue.
  23555.  
  23556. The locking method MySQL uses for `READ' locks works as follows:
  23557.  
  23558.    * If there are no write locks on the table, put a read lock on it.
  23559.  
  23560.    * Otherwise, put the lock request in the read lock queue.
  23561.  
  23562. When a lock is released, the lock is made available to the threads in
  23563. the write lock queue, then to the threads in the read lock queue.
  23564.  
  23565. This means that if you have many updates on a table, `SELECT'
  23566. statements will wait until there are no more updates.
  23567.  
  23568. To work around this for the case where you want to do many `INSERT' and
  23569. `SELECT' operations on a table, you can insert rows in a temporary
  23570. table and update the real table with the records from the temporary
  23571. table once in a while.
  23572.  
  23573. This can be done with the following code:
  23574.      mysql> LOCK TABLES real_table WRITE, insert_table WRITE;
  23575.      mysql> INSERT INTO real_table SELECT * FROM insert_table;
  23576.      mysql> TRUNCATE TABLE insert_table;
  23577.      mysql> UNLOCK TABLES;
  23578.  
  23579. You can use the `LOW_PRIORITY' options with `INSERT', `UPDATE' or
  23580. `DELETE' or `HIGH_PRIORITY' with `SELECT' if you want to prioritise
  23581. retrieval in some specific cases.  You can also start `mysqld' with
  23582. `--low-priority-updates' to get the same behaveour.
  23583.  
  23584. Using `SQL_BUFFER_RESULT' can also help making table locks shorter.
  23585. *Note SELECT::.
  23586.  
  23587. You could also change the locking code in `mysys/thr_lock.c' to use a
  23588. single queue.  In this case, write locks and read locks would have the
  23589. same priority, which might help some applications.
  23590.  
  23591. Table Locking Issues
  23592. --------------------
  23593.  
  23594. The table locking code in MySQL is deadlock free.
  23595.  
  23596. MySQL uses table locking (instead of row locking or column locking) on
  23597. all table types, except `InnoDB' and `BDB' tables, to achieve a very
  23598. high lock speed.  For large tables, table locking is much better than
  23599. row locking for most applications, but there are, of course, some
  23600. pitfalls.
  23601.  
  23602. For `InnoDB' and `BDB' tables, MySQL only uses table locking if you
  23603. explicitly lock the table with `LOCK TABLES'.  For these table types we
  23604. recommend you to not use `LOCK TABLES' at all, because `InnoDB' uses
  23605. automatic row level locking and `BDB' uses page level locking to ensure
  23606. transaction isolation.
  23607.  
  23608. In MySQL Version 3.23.7 and above, you can insert rows into `MyISAM'
  23609. tables at the same time other threads are reading from the table.  Note
  23610. that currently this only works if there are no holes after deleted rows
  23611. in the table at the time the insert is made. When all holes has been
  23612. filled with new data, concurrent inserts will automatically be enabled
  23613. again.
  23614.  
  23615. Table locking enables many threads to read from a table at the same
  23616. time, but if a thread wants to write to a table, it must first get
  23617. exclusive access.  During the update, all other threads that want to
  23618. access this particular table will wait until the update is ready.
  23619.  
  23620. As updates on tables normally are considered to be more important than
  23621. `SELECT', all statements that update a table have higher priority than
  23622. statements that retrieve information from a table. This should ensure
  23623. that updates are not 'starved' because one issues a lot of heavy
  23624. queries against a specific table. (You can change this by using
  23625. `LOW_PRIORITY' with the statement that does the update or
  23626. `HIGH_PRIORITY' with the `SELECT' statement.)
  23627.  
  23628. Starting from MySQL Version 3.23.7 one can use the
  23629. `max_write_lock_count' variable to force MySQL to temporary give all
  23630. `SELECT' statements, that wait for a table, a higher priority after a
  23631. specific number of inserts on a table.
  23632.  
  23633. Table locking is, however, not very good under the following senario:
  23634.  
  23635.    * A client issues a `SELECT' that takes a long time to run.
  23636.  
  23637.    * Another client then issues an `UPDATE' on a used table. This client
  23638.      will wait until the `SELECT' is finished.
  23639.  
  23640.    * Another client issues another `SELECT' statement on the same
  23641.      table. As `UPDATE' has higher priority than `SELECT', this `SELECT'
  23642.      will wait for the `UPDATE' to finish.  It will also wait for the
  23643.      first `SELECT' to finish!
  23644.  
  23645.    * A thread is waiting for something like `full disk', in which case
  23646.      all threads that wants to access the problem table will also be
  23647.      put in a waiting state until more disk space is made available.
  23648.  
  23649. Some possible solutions to this problem are:
  23650.  
  23651.    * Try to get the `SELECT' statements to run faster. You may have to
  23652.      create some summary tables to do this.
  23653.  
  23654.    * Start `mysqld' with `--low-priority-updates'.  This will give all
  23655.      statements that update (modify) a table lower priority than a
  23656.      `SELECT' statement. In this case the last `SELECT' statement in
  23657.      the previous scenario would execute before the `INSERT' statement.
  23658.  
  23659.    * You can give a specific `INSERT', `UPDATE', or `DELETE' statement
  23660.      lower priority with the `LOW_PRIORITY' attribute.
  23661.  
  23662.    * Start `mysqld' with a low value for `max_write_lock_count' to give
  23663.      `READ' locks after a certain number of `WRITE' locks.
  23664.  
  23665.    * You can specify that all updates from a specific thread should be
  23666.      done with low priority by using the SQL command: `SET
  23667.      LOW_PRIORITY_UPDATES=1'.  *Note `SET': SET OPTION.
  23668.  
  23669.    * You can specify that a specific `SELECT' is very important with the
  23670.      `HIGH_PRIORITY' attribute. *Note `SELECT': SELECT.
  23671.  
  23672.    * If you have problems with `INSERT' combined with `SELECT', switch
  23673.      to use the new `MyISAM' tables as these support concurrent
  23674.      `SELECT's and `INSERT's.
  23675.  
  23676.    * If you mainly mix `INSERT' and `SELECT' statements, the `DELAYED'
  23677.      attribute to `INSERT' will probably solve your problems.  *Note
  23678.      `INSERT': INSERT.
  23679.  
  23680.    * If you have problems with `SELECT' and `DELETE', the `LIMIT'
  23681.      option to `DELETE' may help. *Note `DELETE': DELETE.
  23682.  
  23683. Optimising Database Structure
  23684. =============================
  23685.  
  23686. Design Choices
  23687. --------------
  23688.  
  23689. MySQL keeps row data and index data in separate files. Many (almost
  23690. all) other databases mix row and index data in the same file. We
  23691. believe that the MySQL choice is better for a very wide range of modern
  23692. systems.
  23693.  
  23694. Another way to store the row data is to keep the information for each
  23695. column in a separate area (examples are SDBM and Focus). This will
  23696. cause a performance hit for every query that accesses more than one
  23697. column. Because this degenerates so quickly when more than one column
  23698. is accessed, we believe that this model is not good for general purpose
  23699. databases.
  23700.  
  23701. The more common case is that the index and data are stored together
  23702. (like in Oracle/Sybase et al). In this case you will find the row
  23703. information at the leaf page of the index. The good thing with this
  23704. layout is that it, in many cases, depending on how well the index is
  23705. cached, saves a disk read.  The bad things with this layout are:
  23706.  
  23707.    * Table scanning is much slower because you have to read through the
  23708.      indexes to get at the data.
  23709.  
  23710.    * You can't use only the index table to retrieve data for a query.
  23711.  
  23712.    * You lose a lot of space, as you must duplicate indexes from the
  23713.      nodes (as you can't store the row in the nodes).
  23714.  
  23715.    * Deletes will degenerate the table over time (as indexes in nodes
  23716.      are usually not updated on delete).
  23717.  
  23718.    * It's harder to cache only the index data.
  23719.  
  23720. Get Your Data as Small as Possible
  23721. ----------------------------------
  23722.  
  23723. One of the most basic optimisation is to get your data (and indexes) to
  23724. take as little space on the disk (and in memory) as possible. This can
  23725. give huge improvements because disk reads are faster and normally less
  23726. main memory will be used. Indexing also takes less resources if done on
  23727. smaller columns.
  23728.  
  23729. MySQL supports a lot of different table types and row formats.
  23730. Choosing the right table format may give you a big performance gain.
  23731. *Note Table types::.
  23732.  
  23733. You can get better performance on a table and minimise storage space
  23734. using the techniques listed here:
  23735.  
  23736.    * Use the most efficient (smallest) types possible. MySQL has many
  23737.      specialised types that save disk space and memory.
  23738.  
  23739.    * Use the smaller integer types if possible to get smaller tables.
  23740.      For example, `MEDIUMINT' is often better than `INT'.
  23741.  
  23742.    * Declare columns to be `NOT NULL' if possible. It makes everything
  23743.      faster and you save one bit per column. Note that if you really
  23744.      need `NULL' in your application you should definitely use it. Just
  23745.      avoid having it on all columns by default.
  23746.  
  23747.    * If you don't have any variable-length columns (`VARCHAR', `TEXT',
  23748.      or `BLOB' columns), a fixed-size record format is used. This is
  23749.      faster but unfortunately may waste some space.  *Note `MyISAM'
  23750.      table formats: MyISAM table formats.
  23751.  
  23752.    * The primary index of a table should be as short as possible. This
  23753.      makes identification of one row easy and efficient.
  23754.  
  23755.    * For each table, you have to decide which storage/index method to
  23756.      use. *Note Table types::.
  23757.  
  23758.    * Only create the indexes that you really need. Indexes are good for
  23759.      retrieval but bad when you need to store things fast. If you mostly
  23760.      access a table by searching on a combination of columns, make an
  23761.      index on them. The first index part should be the most used
  23762.      column. If you are *always* using many columns, you should use the
  23763.      column with more duplicates first to get better compression of the
  23764.      index.
  23765.  
  23766.    * If it's very likely that a column has a unique prefix on the first
  23767.      number of characters, it's better to only index this prefix. MySQL
  23768.      supports an index on a part of a character column. Shorter indexes
  23769.      are faster not only because they take less disk space but also
  23770.      because they will give you more hits in the index cache and thus
  23771.      fewer disk seeks. *Note Server parameters::.
  23772.  
  23773.    * In some circumstances it can be beneficial to split into two a
  23774.      table that is scanned very often. This is especially true if it is
  23775.      a dynamic format table and it is possible to use a smaller static
  23776.      format table that can be used to find the relevant rows when
  23777.      scanning the table.
  23778.  
  23779. How MySQL Uses Indexes
  23780. ----------------------
  23781.  
  23782. Indexes are used to find rows with a specific value of one column fast.
  23783. Without an index MySQL has to start with the first record and then read
  23784. through the whole table until it finds the relevant rows. The bigger
  23785. the table, the more this costs. If the table has an index for the
  23786. columns in question, MySQL can quickly get a position to seek to in the
  23787. middle of the datafile without having to look at all the data. If a
  23788. table has 1000 rows, this is at least 100 times faster than reading
  23789. sequentially. Note that if you need to access almost all 1000 rows it
  23790. is faster to read sequentially because we then avoid disk seeks.
  23791.  
  23792. All MySQL indexes (`PRIMARY', `UNIQUE', and `INDEX') are stored in
  23793. B-trees. Strings are automatically prefix- and end-space compressed.
  23794. *Note `CREATE INDEX': CREATE INDEX.
  23795.  
  23796. Indexes are used to:
  23797.    * Quickly find the rows that match a `WHERE' clause.
  23798.  
  23799.    * Retrieve rows from other tables when performing joins.
  23800.  
  23801.    * Find the `MAX()' or `MIN()' value for a specific indexed column.
  23802.      This is optimised by a preprocessor that checks if you are using
  23803.      `WHERE' key_part_# = constant on all key parts < N.  In this case
  23804.      MySQL will do a single key lookup and replace the `MIN()'
  23805.      expression with a constant.  If all expressions are replaced with
  23806.      constants, the query will return at once:
  23807.  
  23808.           SELECT MIN(key_part2),MAX(key_part2) FROM table_name where key_part1=10
  23809.  
  23810.    * Sort or group a table if the sorting or grouping is done on a
  23811.      leftmost prefix of a usable key (for example, `ORDER BY
  23812.      key_part_1,key_part_2 '). The key is read in reverse order if all
  23813.      key parts are followed by `DESC'.  *Note ORDER BY optimisation::.
  23814.  
  23815.    * In some cases a query can be optimised to retrieve values without
  23816.      consulting the datafile. If all used columns for some table are
  23817.      numeric and form a leftmost prefix for some key, the values may be
  23818.      retrieved from the index tree for greater speed:
  23819.  
  23820.           SELECT key_part3 FROM table_name WHERE key_part1=1
  23821.  
  23822.  
  23823. Suppose you issue the following `SELECT' statement:
  23824.  
  23825.      mysql> SELECT * FROM tbl_name WHERE col1=val1 AND col2=val2;
  23826.  
  23827. If a multiple-column index exists on `col1' and `col2', the appropriate
  23828. rows can be fetched directly. If separate single-column indexes exist
  23829. on `col1' and `col2', the optimiser tries to find the most restrictive
  23830. index by deciding which index will find fewer rows and using that index
  23831. to fetch the rows.
  23832.  
  23833. If the table has a multiple-column index, any leftmost prefix of the
  23834. index can be used by the optimiser to find rows. For example, if you
  23835. have a three-column index on `(col1,col2,col3)', you have indexed
  23836. search capabilities on `(col1)', `(col1,col2)', and `(col1,col2,col3)'.
  23837.  
  23838. MySQL can't use a partial index if the columns don't form a leftmost
  23839. prefix of the index.  Suppose you have the `SELECT' statements shown
  23840. here:
  23841.  
  23842.      mysql> SELECT * FROM tbl_name WHERE col1=val1;
  23843.      mysql> SELECT * FROM tbl_name WHERE col2=val2;
  23844.      mysql> SELECT * FROM tbl_name WHERE col2=val2 AND col3=val3;
  23845.  
  23846. If an index exists on `(col1,col2,col3)', only the first query shown
  23847. above uses the index. The second and third queries do involve indexed
  23848. columns, but `(col2)' and `(col2,col3)' are not leftmost prefixes of
  23849. `(col1,col2,col3)'.
  23850.  
  23851. MySQL also uses indexes for `LIKE' comparisons if the argument to
  23852. `LIKE' is a constant string that doesn't start with a wildcard
  23853. character.  For example, the following `SELECT' statements use indexes:
  23854.  
  23855.      mysql> SELECT * FROM tbl_name WHERE key_col LIKE "Patrick%";
  23856.      mysql> SELECT * FROM tbl_name WHERE key_col LIKE "Pat%_ck%";
  23857.  
  23858. In the first statement, only rows with `"Patrick" <= key_col <
  23859. "Patricl"' are considered.  In the second statement, only rows with
  23860. `"Pat" <= key_col < "Pau"' are considered.
  23861.  
  23862. The following `SELECT' statements will not use indexes:
  23863.      mysql> SELECT * FROM tbl_name WHERE key_col LIKE "%Patrick%";
  23864.      mysql> SELECT * FROM tbl_name WHERE key_col LIKE other_col;
  23865.  
  23866. In the first statement, the `LIKE' value begins with a wildcard
  23867. character.  In the second statement, the `LIKE' value is not a constant.
  23868.  
  23869. MySQL 4.0 does another optimisation on `LIKE'.  If you use `... LIKE
  23870. "%string%"' and `string' is longer than 3 characters, MySQL will use
  23871. the `Turbo Boyer-Moore' algorithm to initialise the pattern for the
  23872. string and then use this pattern to perform the search quicker.
  23873.  
  23874. Searching using `column_name IS NULL' will use indexes if column_name
  23875. is an index.
  23876.  
  23877. MySQL normally uses the index that finds the least number of rows. An
  23878. index is used for columns that you compare with the following operators:
  23879. `=', `>', `>=', `<', `<=', `BETWEEN', and a `LIKE' with a non-wildcard
  23880. prefix like `'something%''.
  23881.  
  23882. Any index that doesn't span all `AND' levels in the `WHERE' clause is
  23883. not used to optimise the query. In other words:  To be able to use an
  23884. index, a prefix of the index must be used in every `AND' group.
  23885.  
  23886. The following `WHERE' clauses use indexes:
  23887.      ... WHERE index_part1=1 AND index_part2=2 AND other_column=3
  23888.      ... WHERE index=1 OR A=10 AND index=2      /* index = 1 OR index = 2 */
  23889.      ... WHERE index_part1='hello' AND index_part_3=5
  23890.                /* optimised like "index_part1='hello'" */
  23891.      ... WHERE index1=1 and index2=2 or index1=3 and index3=3;
  23892.                /* Can use index on index1 but not on index2 or index 3 */
  23893.  
  23894. These `WHERE' clauses do *NOT* use indexes:
  23895.      ... WHERE index_part2=1 AND index_part3=2  /* index_part_1 is not used */
  23896.      ... WHERE index=1 OR A=10                  /* Index is not used in
  23897.                                                              both AND parts */
  23898.      ... WHERE index_part1=1 OR index_part2=10  /* No index spans all rows  */
  23899.  
  23900. Note that in some cases MySQL will not use an index, even if one would
  23901. be available.  Some of the cases where this happens are:
  23902.  
  23903.    * If the use of the index would require MySQL to access more than
  23904.      30% of the rows in the table.  (In this case a table scan is
  23905.      probably much faster, as this will require us to do much fewer
  23906.      seeks.)  Note that if such a query uses `LIMIT' to only retrieve
  23907.      part of the rows, MySQL will use an index anyway, as it can much
  23908.      more quickly find the few rows to return in the result.
  23909.  
  23910.    * If the index range may contain `NULL' values and you are using
  23911.      `ORDER BY ... DESC'
  23912.  
  23913. Column Indexes
  23914. --------------
  23915.  
  23916. All MySQL column types can be indexed.  Use of indexes on the relevant
  23917. columns is the best way to improve the performance of `SELECT'
  23918. operations.
  23919.  
  23920. The maximum number of keys and the maximum index length is defined per
  23921. storage engine. *Note Table types::. You can with all storage engines
  23922. have at least 16 keys and a total index length of at least 256 bytes.
  23923.  
  23924. For `CHAR' and `VARCHAR' columns, you can index a prefix of a column.
  23925. This is much faster and requires less disk space than indexing the
  23926. whole column.  The syntax to use in the `CREATE TABLE' statement to
  23927. index a column prefix looks like this:
  23928.  
  23929.      KEY index_name (col_name(length))
  23930.  
  23931. The example here creates an index for the first 10 characters of the
  23932. `name' column:
  23933.  
  23934.      mysql> CREATE TABLE test (
  23935.          ->        name CHAR(200) NOT NULL,
  23936.          ->        KEY index_name (name(10)));
  23937.  
  23938. For `BLOB' and `TEXT' columns, you must index a prefix of the column.
  23939. You cannot index the entire column.
  23940.  
  23941. In MySQL Version 3.23.23 or later, you can also create special
  23942. `FULLTEXT' indexes. They are used for full-text search. Only the
  23943. `MyISAM' table type supports `FULLTEXT' indexes. They can be created
  23944. only from `CHAR', `VARCHAR', and `TEXT' columns.  Indexing always
  23945. happens over the entire column and partial indexing is not supported.
  23946. See *Note Fulltext Search:: for details.
  23947.  
  23948. Multiple-Column Indexes
  23949. -----------------------
  23950.  
  23951. MySQL can create indexes on multiple columns.  An index may consist of
  23952. up to 15 columns. (On `CHAR' and `VARCHAR' columns you can also use a
  23953. prefix of the column as a part of an index.)
  23954.  
  23955. A multiple-column index can be considered a sorted array containing
  23956. values that are created by concatenating the values of the indexed
  23957. columns.
  23958.  
  23959. MySQL uses multiple-column indexes in such a way that queries are fast
  23960. when you specify a known quantity for the first column of the index in a
  23961. `WHERE' clause, even if you don't specify values for the other columns.
  23962.  
  23963. Suppose a table is created using the following specification:
  23964.  
  23965.      mysql> CREATE TABLE test (
  23966.          ->       id INT NOT NULL,
  23967.          ->       last_name CHAR(30) NOT NULL,
  23968.          ->       first_name CHAR(30) NOT NULL,
  23969.          ->       PRIMARY KEY (id),
  23970.          ->       INDEX name (last_name,first_name));
  23971.  
  23972. Then the index `name' is an index over `last_name' and `first_name'.
  23973. The index will be used for queries that specify values in a known range
  23974. for `last_name', or for both `last_name' and `first_name'.  Therefore,
  23975. the `name' index will be used in the following queries:
  23976.  
  23977.      mysql> SELECT * FROM test WHERE last_name="Widenius";
  23978.      
  23979.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  23980.          ->                    AND first_name="Michael";
  23981.      
  23982.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  23983.          ->                    AND (first_name="Michael" OR first_name="Monty");
  23984.      
  23985.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  23986.          ->                    AND first_name >="M" AND first_name < "N";
  23987.  
  23988. However, the `name' index will NOT be used in the following queries:
  23989.  
  23990.      mysql> SELECT * FROM test WHERE first_name="Michael";
  23991.      
  23992.      mysql> SELECT * FROM test WHERE last_name="Widenius"
  23993.          ->                    OR first_name="Michael";
  23994.  
  23995. For more information on the manner in which MySQL uses indexes to
  23996. improve query performance, see *Note MySQL indexes: MySQL indexes.
  23997.  
  23998. Why So Many Open tables?
  23999. ------------------------
  24000.  
  24001. When you run `mysqladmin status', you'll see something like this:
  24002.  
  24003.      Uptime: 426 Running threads: 1 Questions: 11082 Reloads: 1 Open tables: 12
  24004.  
  24005. This can be somewhat perplexing if you only have 6 tables.
  24006.  
  24007. MySQL is multi-threaded, so it may have many queries on the same table
  24008. simultaneously. To minimise the problem with two threads having
  24009. different states on the same file, the table is opened independently by
  24010. each concurrent thread. This takes some memory but will normaly increase
  24011. performance.  Wth `ISAM' and `MyISAM' tables this also requires one
  24012. extra file descriptor for the datafile. With these table types the index
  24013. file descriptor is shared between all threads.
  24014.  
  24015. You can read more about this topic in the next section. *Note Table
  24016. cache::.
  24017.  
  24018. How MySQL Opens and Closes Tables
  24019. ---------------------------------
  24020.  
  24021. `table_cache', `max_connections', and `max_tmp_tables' affect the
  24022. maximum number of files the server keeps open.  If you increase one or
  24023. both of these values, you may run up against a limit imposed by your
  24024. operating system on the per-process number of open file descriptors.
  24025. However, you can increase the limit on many systems.  Consult your OS
  24026. documentation to find out how to do this, because the method for
  24027. changing the limit varies widely from system to system.
  24028.  
  24029. `table_cache' is related to `max_connections'.  For example, for 200
  24030. concurrent running connections, you should have a table cache of at
  24031. least `200 * n', where `n' is the maximum number of tables in a join.
  24032. You also need to reserve some extra file descriptors for temporary
  24033. tables and files.
  24034.  
  24035. Make sure that your operating system can handle the number of open file
  24036. descriptors implied by the `table_cache' setting.  If `table_cache' is
  24037. set too high, MySQL may run out of file descriptors and refuse
  24038. connections, fail to perform queries, and be very unreliable.  You also
  24039. have to take into account that the `MyISAM' storage engine needs two
  24040. file descriptors for each unique open table. You can in increase the
  24041. number of file descriptors available for MySQL with the
  24042. `--open-files-limit=#' startup option. *Note Not enough file handles::.
  24043.  
  24044. The cache of open tables will be keept at a level of `table_cache'
  24045. entries (default 64; this can be changed with the `-O table_cache=#'
  24046. option to `mysqld').  Note that in MySQL may temporarly open even more
  24047. tables to be able to execute queries.
  24048.  
  24049. A not used table is closed and removed from the table cache under the
  24050. following circumstances:
  24051.  
  24052.    * When the cache is full and a thread tries to open a table that is
  24053.      not in the cache.
  24054.  
  24055.    * When the cache contains more than `table_cache' entries and a
  24056.      thread is no longer using a table.
  24057.  
  24058.    * When someone executes `mysqladmin refresh' or `mysqladmin
  24059.      flush-tables'.
  24060.  
  24061.    * When someone executes a `FLUSH TABLES' statement.
  24062.  
  24063. When the table cache fills up, the server uses the following procedure
  24064. to locate a cache entry to use:
  24065.  
  24066.    * Tables that are not currently in use are released, in
  24067.      least-recently-used order.
  24068.  
  24069.    * If the cache is full and no tables can be released, but a new
  24070.      table needs to be opened, the cache is temporarily extended as
  24071.      necessary.
  24072.  
  24073.    * If the cache is in a temporarily-extended state and a table goes
  24074.      from in-use to not-in-use state, the table is closed and released
  24075.      from the cache.
  24076.  
  24077. A table is opened for each concurrent access. This means that if you
  24078. have two threads accessing the same table or access the table twice in
  24079. the same query (with `AS') the table needs to be opened twice.  The
  24080. first open of any table takes two file descriptors; each additional use
  24081. of the table takes only one file descriptor.  The extra descriptor for
  24082. the first open is used for the index file; this descriptor is shared
  24083. among all threads.
  24084.  
  24085. If you are opening a table with the `HANDLER table_name OPEN'
  24086. statement, a dedicated table object is allocated for the thread.  This
  24087. table object is not shared by other threads an will not be closed until
  24088. the thread calls `HANDLER table_name CLOSE' or the thread dies.  *Note
  24089. `HANDLER': HANDLER.  When this happens, the table is put back in the
  24090. table cache (if it isn't full).
  24091.  
  24092. You can check if your table cache is too small by checking the `mysqld'
  24093. variable `Opened_tables'.  If this is quite big, even if you haven't
  24094. done a lot of `FLUSH TABLES', you should increase your table cache.
  24095. *Note `Opened_tables': SHOW STATUS.
  24096.  
  24097. Drawbacks to Creating Large Numbers of Tables in the Same Database
  24098. ------------------------------------------------------------------
  24099.  
  24100. If you have many files in a directory, open, close, and create
  24101. operations will be slow.  If you execute `SELECT' statements on many
  24102. different tables, there will be a little overhead when the table cache
  24103. is full, because for every table that has to be opened, another must be
  24104. closed. You can reduce this overhead by making the table cache larger.
  24105.  
  24106. Optimising the MySQL Server
  24107. ===========================
  24108.  
  24109. System/Compile Time and Startup Parameter Tuning
  24110. ------------------------------------------------
  24111.  
  24112. We start with the system level things since some of these decisions have
  24113. to be made very early. In other cases a fast look at this part may
  24114. suffice because it not that important for the big gains. However, it is
  24115. always nice to have a feeling about how much one could gain by changing
  24116. things at this level.
  24117.  
  24118. The default OS to use is really important!  To get the most use of
  24119. multiple-CPU machines one should use Solaris (because the threads works
  24120. really nice) or Linux (because the 2.2 kernel has really good SMP
  24121. support). Also on 32-bit machines Linux has a 2G file-size limit by
  24122. default. Hopefully this will be fixed soon when new filesystems are
  24123. released (XFS/Reiserfs).  If you have a desperate need for files bigger
  24124. than 2G on Linux-intel 32 bit, you should get the LFS patch for the ext2
  24125. filesystem.
  24126.  
  24127. Because we have not run MySQL in production on that many platforms, we
  24128. advice you to test your intended platform before choosing it, if
  24129. possible.
  24130.  
  24131. Other tips:
  24132.    * If you have enough RAM, you could remove all swap devices. Some
  24133.      operating systems will use a swap device in some contexts even if
  24134.      you have free memory.
  24135.  
  24136.    * Use the `--skip-external-locking' MySQL option to avoid external
  24137.      locking. Note that this will not impact MySQL's functionality as
  24138.      long as you only run one server. Just remember to take down the
  24139.      server (or lock relevant parts) before you run `myisamchk'. On
  24140.      some system this switch is mandatory because the external locking
  24141.      does not work in any case.
  24142.  
  24143.      The `--skip-external-locking' option is on by default when
  24144.      compiling with MIT-pthreads, because `flock()' isn't fully
  24145.      supported by MIT-pthreads on all platforms.  It's also on default
  24146.      for Linux as Linux file locking are not yet safe.
  24147.  
  24148.      The only case when you can't use `--skip-external-locking' is if
  24149.      you run multiple MySQL _servers_ (not clients) on the same data,
  24150.      or run `myisamchk' on the table without first flushing and locking
  24151.      the `mysqld' server tables first.
  24152.  
  24153.      You can still use `LOCK TABLES'/`UNLOCK TABLES' even if you are
  24154.      using `--skip-external-locking'
  24155.  
  24156. Tuning Server Parameters
  24157. ------------------------
  24158.  
  24159. You can get the default buffer sizes used by the `mysqld' server with
  24160. this command:
  24161.  
  24162.      shell> mysqld --help
  24163.  
  24164. This command produces a list of all `mysqld' options and configurable
  24165. variables. The output includes the default values and looks something
  24166. like this:
  24167.  
  24168.      Possible variables for option --set-variable (-O) are:
  24169.      back_log                 current value: 5
  24170.      bdb_cache_size           current value: 1048540
  24171.      binlog_cache_size        current value: 32768
  24172.      connect_timeout          current value: 5
  24173.      delayed_insert_timeout   current value: 300
  24174.      delayed_insert_limit     current value: 100
  24175.      delayed_queue_size       current value: 1000
  24176.      flush_time               current value: 0
  24177.      interactive_timeout      current value: 28800
  24178.      join_buffer_size         current value: 131072
  24179.      key_buffer_size          current value: 1048540
  24180.      lower_case_table_names   current value: 0
  24181.      long_query_time          current value: 10
  24182.      max_allowed_packet       current value: 1048576
  24183.      max_binlog_cache_size    current value: 4294967295
  24184.      max_connections          current value: 100
  24185.      max_connect_errors       current value: 10
  24186.      max_delayed_threads      current value: 20
  24187.      max_heap_table_size      current value: 16777216
  24188.      max_join_size            current value: 4294967295
  24189.      max_sort_length          current value: 1024
  24190.      max_tmp_tables           current value: 32
  24191.      max_write_lock_count     current value: 4294967295
  24192.      myisam_sort_buffer_size  current value: 8388608
  24193.      net_buffer_length        current value: 16384
  24194.      net_retry_count          current value: 10
  24195.      net_read_timeout         current value: 30
  24196.      net_write_timeout        current value: 60
  24197.      read_buffer_size         current value: 131072
  24198.      record_rnd_buffer_size   current value: 131072
  24199.      slow_launch_time         current value: 2
  24200.      sort_buffer              current value: 2097116
  24201.      table_cache              current value: 64
  24202.      thread_concurrency       current value: 10
  24203.      tmp_table_size           current value: 1048576
  24204.      thread_stack             current value: 131072
  24205.      wait_timeout             current value: 28800
  24206.  
  24207. Please note that `--set-variable' is deprecated since MySQL 4.0, just
  24208. use `--var=option' on its own.
  24209.  
  24210. If there is a `mysqld' server currently running, you can see what
  24211. values it actually is using for the variables by executing this command:
  24212.  
  24213.      shell> mysqladmin variables
  24214.  
  24215. You can find a full description for all variables in the `SHOW
  24216. VARIABLES' section in this manual. *Note SHOW VARIABLES::.
  24217.  
  24218. You can also see some statistics from a running server by issuing the
  24219. command `SHOW STATUS'. *Note SHOW STATUS::.
  24220.  
  24221. MySQL uses algorithms that are very scalable, so you can usually run
  24222. with very little memory. If you, however, give MySQL more memory, you
  24223. will normally also get better performance.
  24224.  
  24225. When tuning a MySQL server, the two most important variables to use are
  24226. `key_buffer_size' and `table_cache'.  You should first feel confident
  24227. that you have these right before trying to change any of the other
  24228. variables.
  24229.  
  24230. If you have much memory (>=256M) and many tables and want maximum
  24231. performance with a moderate number of clients, you should use something
  24232. like this:
  24233.  
  24234.      shell> safe_mysqld -O key_buffer=64M -O table_cache=256 \
  24235.                 -O sort_buffer=4M -O read_buffer_size=1M &
  24236.  
  24237. If you have only 128M and only a few tables, but you still do a lot of
  24238. sorting, you can use something like:
  24239.  
  24240.      shell> safe_mysqld -O key_buffer=16M -O sort_buffer=1M
  24241.  
  24242. If you have little memory and lots of connections, use something like
  24243. this:
  24244.  
  24245.      shell> safe_mysqld -O key_buffer=512k -O sort_buffer=100k \
  24246.                 -O read_buffer_size=100k &
  24247.  
  24248. or even:
  24249.  
  24250.      shell> safe_mysqld -O key_buffer=512k -O sort_buffer=16k \
  24251.                 -O table_cache=32 -O read_buffer_size=8k -O net_buffer_length=1K &
  24252.  
  24253. If you are doing a `GROUP BY' or `ORDER BY' on files that are much
  24254. bigger than your available memory you should increase the value of
  24255. `record_rnd_buffer' to speed up the reading of rows after the sorting
  24256. is done.
  24257.  
  24258. When you have installed MySQL, the `support-files' directory will
  24259. contain some different `my.cnf' example files, `my-huge.cnf',
  24260. `my-large.cnf', `my-medium.cnf', and `my-small.cnf', you can use as a
  24261. base to optimise your system.
  24262.  
  24263. If there are very many connections, "swapping problems" may occur unless
  24264. `mysqld' has been configured to use very little memory for each
  24265. connection. `mysqld' performs better if you have enough memory for all
  24266. connections, of course.
  24267.  
  24268. Note that if you change an option to `mysqld', it remains in effect only
  24269. for that instance of the server.
  24270.  
  24271. To see the effects of a parameter change, do something like this:
  24272.  
  24273.      shell> mysqld -O key_buffer=32m --help
  24274.  
  24275. Make sure that the `--help' option is last; otherwise, the effect of any
  24276. options listed after it on the command-line will not be reflected in the
  24277. output.
  24278.  
  24279. How Compiling and Linking Affects the Speed of MySQL
  24280. ----------------------------------------------------
  24281.  
  24282. Most of the following tests are done on Linux with the MySQL
  24283. benchmarks, but they should give some indication for other operating
  24284. systems and workloads.
  24285.  
  24286. You get the fastest executable when you link with `-static'.
  24287.  
  24288. On Linux, you will get the fastest code when compiling with `pgcc' and
  24289. `-O3'. To compile `sql_yacc.cc' with these options, you need about 200M
  24290. memory because `gcc/pgcc' needs a lot of memory to make all functions
  24291. inline. You should also set `CXX=gcc' when configuring MySQL to avoid
  24292. inclusion of the `libstdc++' library (it is not needed). Note that with
  24293. some versions of `pgcc', the resulting code will only run on true
  24294. Pentium processors, even if you use the compiler option that you want
  24295. the resulting code to be working on all x586 type processors (like AMD).
  24296.  
  24297. By just using a better compiler and/or better compiler options you can
  24298. get a 10-30% speed increase in your application.  This is particularly
  24299. important if you compile the SQL server yourself!
  24300.  
  24301. We have tested both the Cygnus CodeFusion and Fujitsu compilers, but
  24302. when we tested them, neither was sufficiently bug free to allow MySQL
  24303. to be compiled with optimisations on.
  24304.  
  24305. When you compile MySQL you should only include support for the
  24306. character sets that you are going to use. (Option `--with-charset=xxx'.)
  24307. The standard MySQL binary distributions are compiled with support for
  24308. all character sets.
  24309.  
  24310. Here is a list of some measurements that we have done:
  24311.    * If you use `pgcc' and compile everything with `-O6', the `mysqld'
  24312.      server is 1% faster than with `gcc' 2.95.2.
  24313.  
  24314.    * If you link dynamically (without `-static'), the result is 13%
  24315.      slower on Linux.  Note that you still can use a dynamic linked
  24316.      MySQL library. It is only the server that is critical for
  24317.      performance.
  24318.  
  24319.    * If you strip your `mysqld' binary with `strip libexec/mysqld', the
  24320.      resulting binary can be up to 4% faster.
  24321.  
  24322.    * If you connect using TCP/IP rather than Unix sockets, the result
  24323.      is 7.5% slower on the same computer. (If you are connection to
  24324.      `localhost', MySQL will, by default, use sockets.)
  24325.  
  24326.    * If you connect using TCP/IP from another computer over a 100M
  24327.      Ethernet, things will be 8-11% slower.
  24328.  
  24329.    * When running our benchmark tests using secure connections (all data
  24330.      encrypted with internal SSL support) things were 55% slower.
  24331.  
  24332.    * If you compile with `--with-debug=full', then you will lose 20%
  24333.      for most queries, but some queries may take substantially longer
  24334.      (The MySQL benchmarks ran 35% slower) If you use `--with-debug',
  24335.      then you will only lose 15%.  By starting a `mysqld' version
  24336.      compiled with `--with-debug=full' with `--skip-safemalloc' the end
  24337.      result should be close to when configuring with `--with-debug'.
  24338.  
  24339.    * On a Sun UltraSPARC-IIe, Forte 5.0 is 4% faster than `gcc' 3.2
  24340.  
  24341.    * On a Sun UltraSPARC-IIe, Forte 5.0 is 4% faster in 32 bit mode
  24342.      than in 64 bit mode.
  24343.  
  24344.    * Compiling with `gcc' 2.95.2 for UltraSPARC with the option
  24345.      `-mcpu=v8 -Wa,-xarch=v8plusa' gives 4% more performance.
  24346.  
  24347.    * On Solaris 2.5.1, MIT-pthreads is 8-12% slower than Solaris native
  24348.      threads on a single processor. With more load/CPUs the difference
  24349.      should get bigger.
  24350.  
  24351.    * Running with `--log-bin' makes mysqld 1% slower.
  24352.  
  24353.    * Compiling on Linux-x86 using gcc without frame pointers
  24354.      `-fomit-frame-pointer' or `-fomit-frame-pointer -ffixed-ebp' makes
  24355.      `mysqld' 1-4% faster.
  24356.  
  24357. The MySQL-Linux distribution provided by MySQL AB used to be compiled
  24358. with `pgcc', but we had to go back to regular gcc because of a bug in
  24359. `pgcc' that would generate the code that does not run on AMD. We will
  24360. continue using gcc until that bug is resolved.  In the meantime, if you
  24361. have a non-AMD machine, you can get a faster binary by compiling with
  24362. `pgcc'.  The standard MySQL Linux binary is linked statically to get it
  24363. faster and more portable.
  24364.  
  24365. How MySQL Uses Memory
  24366. ---------------------
  24367.  
  24368. The following list indicates some of the ways that the `mysqld' server
  24369. uses memory.  Where applicable, the name of the server variable relevant
  24370. to the memory use is given:
  24371.  
  24372.    * The key buffer (variable `key_buffer_size') is shared by all
  24373.      threads; other buffers used by the server are allocated as needed.
  24374.      *Note Server parameters::.
  24375.  
  24376.    * Each connection uses some thread-specific space: A stack (default
  24377.      64K, variable `thread_stack'), a connection buffer (variable
  24378.      `net_buffer_length'), and a result buffer (variable
  24379.      `net_buffer_length'). The connection buffer and result buffer are
  24380.      dynamically enlarged up to `max_allowed_packet' when needed.  When
  24381.      a query is running, a copy of the current query string is also
  24382.      allocated.
  24383.  
  24384.    * All threads share the same base memory.
  24385.  
  24386.    * Only the compressed `ISAM' / `MyISAM' tables are memory mapped.
  24387.      This is because the 32-bit memory space of 4GB is not large enough
  24388.      for most big tables. When systems with a 64-bit address space
  24389.      become more common we may add general support for memory mapping.
  24390.  
  24391.    * Each request doing a sequential scan over a table allocates a read
  24392.      buffer (variable `record_buffer').
  24393.  
  24394.    * When reading rows in 'random' order (for example after a sort) a
  24395.      random-read buffer is allocated to avoid disk seeks.  (variable
  24396.      `record_rnd_buffer').
  24397.  
  24398.    * All joins are done in one pass, and most joins can be done without
  24399.      even using a temporary table. Most temporary tables are
  24400.      memory-based (`HEAP') tables.  Temporary tables with a big record
  24401.      length (calculated as the sum of all column lengths) or that
  24402.      contain `BLOB' columns are stored on disk.
  24403.  
  24404.      One problem in MySQL versions before Version 3.23.2 is that if a
  24405.      `HEAP' table exceeds the size of `tmp_table_size', you get the
  24406.      error `The table tbl_name is full'. In newer versions this is
  24407.      handled by automatically changing the in-memory (`HEAP') table to
  24408.      a disk-based (`MyISAM') table as necessary. To work around this
  24409.      problem, you can increase the temporary table size by setting the
  24410.      `tmp_table_size' option to `mysqld', or by setting the SQL option
  24411.      `BIG_TABLES' in the client program.  *Note `SET' Syntax: SET
  24412.      OPTION. In MySQL Version 3.20, the maximum size of the temporary
  24413.      table was `record_buffer*16', so if you are using this version,
  24414.      you have to increase the value of `record_buffer'. You can also
  24415.      start `mysqld' with the `--big-tables' option to always store
  24416.      temporary tables on disk. However, this will affect the speed of
  24417.      many complicated queries.
  24418.  
  24419.    * Most requests doing a sort allocates a sort buffer and 0-2
  24420.      temporary files depending on the result set size. *Note Temporary
  24421.      files::.
  24422.  
  24423.    * Almost all parsing and calculating is done in a local memory
  24424.      store. No memory overhead is needed for small items and the normal
  24425.      slow memory allocation and freeing is avoided. Memory is allocated
  24426.      only for unexpectedly large strings (this is done with `malloc()'
  24427.      and `free()').
  24428.  
  24429.    * Each index file is opened once and the datafile is opened once for
  24430.      each concurrently running thread. For each concurrent thread, a
  24431.      table structure, column structures for each column, and a buffer
  24432.      of size `3 * n' is allocated (where `n' is the maximum row length,
  24433.      not counting `BLOB' columns). A `BLOB' uses 5 to 8 bytes plus the
  24434.      length of the `BLOB' data. The `ISAM'/`MyISAM' storage engines
  24435.      will use one extra row buffer for internal usage.
  24436.  
  24437.    * For each table having `BLOB' columns, a buffer is enlarged
  24438.      dynamically to read in larger `BLOB' values. If you scan a table,
  24439.      a buffer as large as the largest `BLOB' value is allocated.
  24440.  
  24441.    * Storage engines for all in-use tables are saved in a cache and
  24442.      managed as a FIFO. Normally the cache has 64 entries. If a table
  24443.      has been used by two running threads at the same time, the cache
  24444.      contains two entries for the table. *Note Table cache::.
  24445.  
  24446.    * A `mysqladmin flush-tables' command closes all tables that are not
  24447.      in use and marks all in-use tables to be closed when the currently
  24448.      executing thread finishes. This will effectively free most in-use
  24449.      memory.
  24450.  
  24451. `ps' and other system status programs may report that `mysqld' uses a
  24452. lot of memory. This may be caused by thread-stacks on different memory
  24453. addresses. For example, the Solaris version of `ps' counts the unused
  24454. memory between stacks as used memory. You can verify this by checking
  24455. available swap with `swap -s'. We have tested `mysqld' with commercial
  24456. memory-leakage detectors, so there should be no memory leaks.
  24457.  
  24458. How MySQL uses DNS
  24459. ------------------
  24460.  
  24461. When a new thread connects to `mysqld', `mysqld' will span a new thread
  24462. to handle the request.  This thread will first check if the hostname is
  24463. in the hostname cache. If not the thread will call `gethostbyaddr_r()'
  24464. and `gethostbyname_r()' to resolve the hostname.
  24465.  
  24466. If the operating system doesn't support the above thread-safe calls, the
  24467. thread will lock a mutex and call `gethostbyaddr()' and
  24468. `gethostbyname()' instead. Note that in this case no other thread can
  24469. resolve other hostnames that is not in the hostname cache until the
  24470. first thread is ready.
  24471.  
  24472. You can disable DNS host lookup by starting `mysqld' with
  24473. `--skip-name-resolve'.  In this case you can however only use IP names
  24474. in the MySQL privilege tables.
  24475.  
  24476. If you have a very slow DNS and many hosts, you can get more
  24477. performance by either disabling DNS lookop with `--skip-name-resolve'
  24478. or by increasing the `HOST_CACHE_SIZE' define (default: 128) and
  24479. recompile `mysqld'.
  24480.  
  24481. You can disable the hostname cache with `--skip-host-cache'. You can
  24482. clear the hostname cache with `FLUSH HOSTS' or `mysqladmin flush-hosts'.
  24483.  
  24484. If you don't want to allow connections over `TCP/IP', you can do this
  24485. by starting `mysqld' with `--skip-networking'.
  24486.  
  24487. `SET' Syntax
  24488. ------------
  24489.  
  24490.      SET [GLOBAL | SESSION] sql_variable=expression, [[GLOBAL | SESSION] sql_variable=expression...]
  24491.  
  24492. `SET' sets various options that affect the operation of the server or
  24493. your client.
  24494.  
  24495. The following examples shows the different syntaxes one can use to set
  24496. variables:
  24497.  
  24498. In old MySQL versions we allowed the use of the `SET OPTION' syntax,
  24499. but this syntax is now deprecated.
  24500.  
  24501. In MySQL 4.0.3 we added the `GLOBAL' and `SESSION' options and access
  24502. to most important startup variables.
  24503.  
  24504. `LOCAL' can be used as a synonym for `SESSION'.
  24505.  
  24506. If you set several variables on the same command line, the last used
  24507. `GLOBAL | SESSION' mode is used.
  24508.  
  24509.      SET sort_buffer_size=10000;
  24510.      SET @@local.sort_buffer_size=10000;
  24511.      SET GLOBAL sort_buffer_size=1000000, SESSION sort_buffer_size=1000000;
  24512.      SET @@sort_buffer_size=1000000;
  24513.      SET @@global.sort_buffer_size=1000000, @@local.sort_buffer_size=1000000;
  24514.  
  24515. The `@@variable_name' syntax is supported to make MySQL syntax
  24516. compatible with some other databases.
  24517.  
  24518. The different system variables one can set are described in the system
  24519. variable section of this manual. *Note System Variables::.
  24520.  
  24521. If you are using `SESSION' (the default) the option you set remains in
  24522. effect until the current session ends, or until you set the option to a
  24523. different value. If you use `GLOBAL', which require the `SUPER'
  24524. privilege, the option is remembered and used for new connections until
  24525. the server restarts. If you want to make an option permanent, you
  24526. should set it in one of the MySQL option files. *Note Option files::.
  24527.  
  24528. To avoid wrong usage MySQL will give an error if you use `SET GLOBAL'
  24529. with a variable that can only be used with `SET SESSION' or if you are
  24530. not using `SET GLOBAL' with a global variable.
  24531.  
  24532. If you want to set a `SESSION' variable to the `GLOBAL' value or a
  24533. `GLOBAL' value to the MySQL default value, you can set it to `DEFAULT'.
  24534.  
  24535.      SET max_join_size=DEFAULT;
  24536.  
  24537. This is identical to:
  24538.  
  24539.      SET @@session.max_join_size=@@global.max_join_size;
  24540.  
  24541. If you want to restrict the maximum value a startup option can be set to
  24542. with the `SET' command, you can specify this by using the
  24543. `--maximum-variable-name' command line option. *Note Command-line
  24544. options::.
  24545.  
  24546. You can get a list of most variables with `SHOW VARIABLES'.  *Note SHOW
  24547. VARIABLES::.  You can get the value for a specific value with the
  24548. `@@[global.|local.]variable_name' syntax:
  24549.      SHOW VARIABLES like "max_join_size";
  24550.      SHOW GLOBAL VARIABLES like "max_join_size";
  24551.      SELECT @@max_join_size, @@global.max_join_size;
  24552.  
  24553. Here follows a description of the variables that uses a the variables
  24554. that uses a non-standard `SET' syntax and some of the other variables.
  24555. The other variable definitions can be found in the system variable
  24556. section, among the startup options or in the description of `SHOW
  24557. VARIABLES'. *Note System Variables::. *Note Command-line options::.
  24558. *Note SHOW VARIABLES::.
  24559.  
  24560. `CHARACTER SET character_set_name | DEFAULT'
  24561.      This maps all strings from and to the client with the given
  24562.      mapping.  Currently the only option for `character_set_name' is
  24563.      `cp1251_koi8', but you can easily add new mappings by editing the
  24564.      `sql/convert.cc' file in the MySQL source distribution.  The
  24565.      default mapping can be restored by using a `character_set_name'
  24566.      value of `DEFAULT'.
  24567.  
  24568.      Note that the syntax for setting the `CHARACTER SET' option differs
  24569.      from the syntax for setting the other options.
  24570.  
  24571. `PASSWORD = PASSWORD('some password')'
  24572.      Set the password for the current user. Any non-anonymous user can
  24573.      change his own password!
  24574.  
  24575. `PASSWORD FOR user = PASSWORD('some password')'
  24576.      Set the password for a specific user on the current server host.
  24577.      Only a user with access to the `mysql' database can do this.  The
  24578.      user should be given in `user@hostname' format, where `user' and
  24579.      `hostname' are exactly as they are listed in the `User' and `Host'
  24580.      columns of the `mysql.user' table entry.  For example, if you had
  24581.      an entry with `User' and `Host' fields of `'bob'' and
  24582.      `'%.loc.gov'', you would write:
  24583.  
  24584.           mysql> SET PASSWORD FOR bob@"%.loc.gov" = PASSWORD("newpass");
  24585.  
  24586.      Which is equivalent to:
  24587.  
  24588.           mysql> UPDATE mysql.user SET password=PASSWORD("newpass")
  24589.               ->                   WHERE user="bob' AND host="%.loc.gov";
  24590.  
  24591. `SQL_AUTO_IS_NULL = 0 | 1'
  24592.      If set to `1' (default) then one can find the last inserted row
  24593.      for a table with an `AUTO_INCREMENT' column with the following
  24594.      construct: `WHERE auto_increment_column IS NULL'.  This is used by
  24595.      some ODBC programs like Access.
  24596.  
  24597. `AUTOCOMMIT= 0 | 1'
  24598.      If set to `1' all changes to a table will be done at once. To start
  24599.      a multi-command transaction, you have to use the `BEGIN'
  24600.      statement. *Note COMMIT::. If set to `0' you have to use `COMMIT' /
  24601.      `ROLLBACK' to accept/revoke that transaction. *Note COMMIT::.  Note
  24602.      that when you change from not `AUTOCOMMIT' mode to `AUTOCOMMIT'
  24603.      mode, MySQL will do an automatic `COMMIT' on any open transactions.
  24604.  
  24605. `BIG_TABLES = 0 | 1'
  24606.      If set to `1', all temporary tables are stored on disk rather than
  24607.      in memory.  This will be a little slower, but you will not get the
  24608.      error `The table tbl_name is full' for big `SELECT' operations that
  24609.      require a large temporary table.  The default value for a new
  24610.      connection is `0' (that is, use in-memory temporary tables).  This
  24611.      option was before named `SQL_BIG_TABLES'.
  24612.  
  24613. `SQL_BIG_SELECTS = 0 | 1'
  24614.      If set to `0', MySQL will abort if a `SELECT' is attempted that
  24615.      probably will take a very long time. This is useful when an
  24616.      inadvisable `WHERE' statement has been issued. A big query is
  24617.      defined as a `SELECT' that probably will have to examine more than
  24618.      `max_join_size' rows.  The default value for a new connection is
  24619.      `1' (which will allow all `SELECT' statements).
  24620.  
  24621. `SQL_BUFFER_RESULT = 0 | 1'
  24622.      `SQL_BUFFER_RESULT' will force the result from `SELECT's to be put
  24623.      into a temporary table. This will help MySQL free the table locks
  24624.      early and will help in cases where it takes a long time to send
  24625.      the result set to the client.
  24626.  
  24627. `LOW_PRIORITY_UPDATES = 0 | 1'
  24628.      If set to `1', all `INSERT', `UPDATE', `DELETE', and `LOCK TABLE
  24629.      WRITE' statements wait until there is no pending `SELECT' or `LOCK
  24630.      TABLE READ' on the affected table.  This option was before named
  24631.      `SQL_LOW_PRIORITY_UPDATES'.
  24632.  
  24633. `MAX_JOIN_SIZE = value | DEFAULT'
  24634.      Don't allow `SELECT's that will probably need to examine more than
  24635.      `value' row combinations.  By setting this value, you can catch
  24636.      `SELECT's where keys are not used properly and that would probably
  24637.      take a long time. Setting this to a value other than `DEFAULT'
  24638.      will reset the `SQL_BIG_SELECTS' flag.  If you set the
  24639.      `SQL_BIG_SELECTS' flag again, the `SQL_MAX_JOIN_SIZE' variable
  24640.      will be ignored.  You can set a default value for this variable by
  24641.      starting `mysqld' with `-O max_join_size=#'.  This option was
  24642.      before named `SQL_MAX_JOIN_SIZE'.
  24643.  
  24644.      Note that if the result of the query is already in the query
  24645.      cache, the above check will not be made. Instead, MySQL will send
  24646.      the result to the client. Since the query result is already
  24647.      computed and it will not burden the server to send the result to
  24648.      the client.
  24649.  
  24650. `QUERY_CACHE_TYPE = OFF | ON | DEMAND'
  24651.  
  24652. `QUERY_CACHE_TYPE = 0   | 1  | 2'
  24653.      Set query cache setting for this thread.
  24654.      *Option*      *Description*
  24655.      0 or OFF      Don't cache or retrieve results.
  24656.      1 or ON       Cache all results except `SELECT SQL_NO_CACHE
  24657.                    ...' queries.
  24658.      2 or DEMAND   Cache only `SELECT SQL_CACHE ...' queries.
  24659.  
  24660. `SQL_SAFE_UPDATES = 0 | 1'
  24661.      If set to `1', MySQL will abort if an `UPDATE' or `DELETE' is
  24662.      attempted that doesn't use a key or `LIMIT' in the `WHERE' clause.
  24663.      This makes it possible to catch wrong updates when creating SQL
  24664.      commands by hand.
  24665.  
  24666. `SQL_SELECT_LIMIT = value | DEFAULT'
  24667.      The maximum number of records to return from `SELECT' statements.
  24668.      If a `SELECT' has a `LIMIT' clause, the `LIMIT' takes precedence
  24669.      over the value of `SQL_SELECT_LIMIT'.  The default value for a new
  24670.      connection is "unlimited." If you have changed the limit, the
  24671.      default value can be restored by using a `SQL_SELECT_LIMIT' value
  24672.      of `DEFAULT'.
  24673.  
  24674. `SQL_LOG_OFF = 0 | 1'
  24675.      If set to `1', no logging will be done to the standard log for this
  24676.      client, if the client has the `SUPER' privilege.  This does not
  24677.      affect the update log!
  24678.  
  24679. `SQL_LOG_UPDATE = 0 | 1'
  24680.      If set to `0', no logging will be done to the update log for the
  24681.      client, if the client has the `SUPER' privilege.  This does not
  24682.      affect the standard log!
  24683.  
  24684. `SQL_QUOTE_SHOW_CREATE = 0 | 1'
  24685.      If set to `1', `SHOW CREATE TABLE' will quote table and column
  24686.      names. This is *on* by default, for replication of tables with
  24687.      fancy column names to work.  *Note `SHOW CREATE TABLE': SHOW
  24688.      CREATE TABLE.
  24689.  
  24690. `TIMESTAMP = timestamp_value | DEFAULT'
  24691.      Set the time for this client.  This is used to get the original
  24692.      timestamp if you use the update log to restore rows.
  24693.      `timestamp_value' should be a Unix epoch timestamp, not a MySQL
  24694.      timestamp.
  24695.  
  24696. `LAST_INSERT_ID = #'
  24697.      Set the value to be returned from `LAST_INSERT_ID()'. This is
  24698.      stored in the update log when you use `LAST_INSERT_ID()' in a
  24699.      command that updates a table.
  24700.  
  24701. `INSERT_ID = #'
  24702.      Set the value to be used by the following `INSERT' or `ALTER TABLE'
  24703.      command when inserting an `AUTO_INCREMENT' value.  This is mainly
  24704.      used with the update log.
  24705.  
  24706. Disk Issues
  24707. ===========
  24708.  
  24709.    * As mentioned before, disks seeks are a big performance bottleneck.
  24710.      This problems gets more and more apparent when the data starts to
  24711.      grow so large that effective caching becomes impossible. For large
  24712.      databases, where you access data more or less randomly, you can be
  24713.      sure that you will need at least one disk seek to read and a
  24714.      couple of disk seeks to write things. To minimise this problem,
  24715.      use disks with low seek times.
  24716.  
  24717.    * Increase the number of available disk spindles (and thereby reduce
  24718.      the seek overhead) by either symlink files to different disks or
  24719.      striping the disks.
  24720.  
  24721.     *Using symbolic links*
  24722.           This means that you symlink the index and/or datafile(s) from
  24723.           the normal data directory to another disk (that may also be
  24724.           striped). This makes both the seek and read times better (if
  24725.           the disks are not used for other things). *Note Symbolic
  24726.           links::.
  24727.  
  24728.     *Striping*
  24729.           Striping means that you have many disks and put the first
  24730.           block on the first disk, the second block on the second disk,
  24731.           and the Nth on the (N mod number_of_disks) disk, and so on.
  24732.           This means if your normal data size is less than the stripe
  24733.           size (or perfectly aligned) you will get much better
  24734.           performance. Note that striping is very dependent on the OS
  24735.           and stripe-size. So benchmark your application with different
  24736.           stripe-sizes. *Note Custom Benchmarks::.
  24737.  
  24738.           Note that the speed difference for striping is *very*
  24739.           dependent on the parameters. Depending on how you set the
  24740.           striping parameters and number of disks you may get a
  24741.           difference in orders of magnitude. Note that you have to
  24742.           choose to optimise for random or sequential access.
  24743.  
  24744.    * For reliability you may want to use RAID 0+1 (striping +
  24745.      mirroring), but in this case you will need 2*N drives to hold N
  24746.      drives of data. This is probably the best option if you have the
  24747.      money for it!  You may, however, also have to invest in some
  24748.      volume-management software to handle it efficiently.
  24749.  
  24750.    * A good option is to have semi-important data (that can be
  24751.      regenerated) on RAID 0 disk while storing really important data
  24752.      (like host information and logs) on a RAID 0+1 or RAID N disk.
  24753.