home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / mysql / docs / manual.txt next >
Encoding:
Text File  |  2003-09-09  |  2.6 MB  |  68,342 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 Development Roadmap
  41.     MySQL 4.0 in a Nutshell
  42.       Features Available in MySQL 4.0
  43.       Embedded MySQL Server
  44.     MySQL 4.1 in a Nutshell
  45.       Features Available in MySQL 4.1
  46.       Stepwise Rollout
  47.       Ready for Immediate Development Use
  48.     MySQL 5.0, The Next Development Release
  49.   MySQL Information Sources
  50.     MySQL Mailing Lists
  51.       The MySQL Mailing Lists
  52.       Asking Questions or Reporting Bugs
  53.       How to Report Bugs or Problems
  54.       Guidelines for Answering Questions on the Mailing List
  55.     MySQL Community Support on IRC (Internet Relay Chat)
  56.   How Standards-compatible Is MySQL?
  57.     What Standards Does MySQL Follow?
  58.     Running MySQL in ANSI Mode
  59.     MySQL Extensions To The SQL-92 Standard
  60.     MySQL Differences Compared To SQL-92
  61.       Subqueries
  62.       `SELECT INTO TABLE'
  63.       Transactions and Atomic Operations
  64.       Stored Procedures and Triggers
  65.       Foreign Keys
  66.       Views
  67.       `--' as the Start of a Comment
  68.     How MySQL deals with constraints
  69.       Constraint PRIMARY KEY / UNIQUE
  70.       Constraint `NOT NULL' and `DEFAULT' values
  71.       Constraint `ENUM' and `SET'
  72.     Known Errors and Design Deficiencies in MySQL
  73.       Errors in 3.23 Fixed in a Later MySQL Version
  74.       Open Bugs / Design Deficiencies in MySQL
  75.   MySQL and The Future (The TODO)
  76.     New Features Planned For 4.1
  77.     New Features Planned For 5.0
  78.     New Features Planned For 5.1
  79.     New Features Planned For The Near Future
  80.     New Features Planned For The Mid-Term Future
  81.     New Features We Don't Plan To Do
  82.  
  83. MySQL Installation
  84.   Quick Standard Installation of MySQL
  85.     Installing MySQL on Windows
  86.       Installing the Binaries
  87.       Preparing the Windows MySQL Environment
  88.       Starting the Server for the First Time
  89.     Installing MySQL on Linux
  90.     Installing MySQL on Mac OS X
  91.     Installing MySQL on NetWare
  92.       Installing the MySQL for NetWare Binaries
  93.   General Installation Issues
  94.     How to Get MySQL
  95.     Verifying Package Integrity Using `MD5 Checksums' or `GnuPG'
  96.     Operating Systems Supported by MySQL
  97.     Which MySQL Version to Use
  98.     Installation Layouts
  99.     How and When Updates Are Released
  100.     Release Philosophy - No Known Bugs in Releases
  101.     MySQL Binaries Compiled by MySQL AB
  102.     Installing a MySQL Binary Distribution
  103.   Installing a MySQL Source Distribution
  104.     Quick Installation Overview
  105.     Applying Patches
  106.     Typical `configure' Options
  107.     Installing from the Development Source Tree
  108.     Problems Compiling MySQL?
  109.     MIT-pthreads Notes
  110.     Windows Source Distribution
  111.   Post-installation Setup and Testing
  112.     Problems Running `mysql_install_db'
  113.     Problems Starting the MySQL Server
  114.     Starting and Stopping MySQL Automatically
  115.   Upgrading/Downgrading MySQL
  116.     Upgrading From Version 4.0 to 4.1
  117.       Preparing to Upgrade From Version 4.0 to 4.1
  118.       What to do when upgrading from 4.0 to 4.1
  119.     Upgrading From Version 3.23 to 4.0
  120.     Upgrading From Version 3.22 to 3.23
  121.     Upgrading from Version 3.21 to 3.22
  122.     Upgrading from Version 3.20 to 3.21
  123.     Upgrading to Another Architecture
  124.     Upgrading MySQL under Windows
  125.   Operating System Specific 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 MySQL Remotely from Windows with SSH
  131.       Distributing Data Across Different Disks on Windows
  132.       Compiling MySQL Clients on Windows
  133.       MySQL for Windows Compared to Unix MySQL
  134.     Linux Notes (All Linux Versions)
  135.       Linux Notes for Binary Distributions
  136.       Linux x86 Notes
  137.       Linux SPARC Notes
  138.       Linux Alpha Notes
  139.       Linux PowerPC Notes
  140.       Linux MIPS Notes
  141.       Linux IA-64 Notes
  142.     Solaris Notes
  143.       Solaris 2.7/2.8 Notes
  144.       Solaris x86 Notes
  145.     BSD Notes
  146.       FreeBSD Notes
  147.       NetBSD Notes
  148.       OpenBSD 2.5 Notes
  149.       OpenBSD 2.8 Notes
  150.       BSD/OS Version 2.x Notes
  151.       BSD/OS Version 3.x Notes
  152.       BSD/OS Version 4.x Notes
  153.     Mac OS X Notes
  154.       Mac OS X 10.x
  155.       Mac OS X Server 1.2 (Rhapsody)
  156.     Other Unix Notes
  157.       HP-UX Notes for Binary Distributions
  158.       HP-UX Version 10.20 Notes
  159.       HP-UX Version 11.x Notes
  160.       IBM-AIX notes
  161.       SunOS 4 Notes
  162.       Alpha-DEC-UNIX Notes (Tru64)
  163.       Alpha-DEC-OSF/1 Notes
  164.       SGI Irix Notes
  165.       SCO Notes
  166.       SCO UnixWare Version 7.1.x Notes
  167.     OS/2 Notes
  168.     Novell NetWare Notes
  169.     BeOS Notes
  170.   Perl Installation Comments
  171.     Installing Perl on Unix
  172.     Installing ActiveState Perl on Windows
  173.     Problems Using the Perl `DBI'/`DBD' Interface
  174.  
  175. Tutorial Introduction
  176.   Connecting to and Disconnecting from the Server
  177.   Entering Queries
  178.   Creating and Using a Database
  179.     Creating and Selecting a Database
  180.     Creating a Table
  181.     Loading Data into a Table
  182.     Retrieving Information from a Table
  183.       Selecting All Data
  184.       Selecting Particular Rows
  185.       Selecting Particular Columns
  186.       Sorting Rows
  187.       Date Calculations
  188.       Working with `NULL' Values
  189.       Pattern Matching
  190.       Counting Rows
  191.       Using More Than one Table
  192.   Getting Information About Databases and Tables
  193.   Using `mysql' in Batch Mode
  194.   Examples of Common Queries
  195.     The Maximum Value for a Column
  196.     The Row Holding the Maximum of a Certain Column
  197.     Maximum of Column per Group
  198.     The Rows Holding the Group-wise Maximum of a Certain Field
  199.     Using User Variables
  200.     Using Foreign Keys
  201.     Searching on Two Keys
  202.     Calculating Visits Per Day
  203.     Using `AUTO_INCREMENT'
  204.   Queries from the Twin Project
  205.     Find All Non-distributed Twins
  206.     Show a Table of Twin Pair Status
  207.   Using MySQL with Apache
  208.  
  209. Database Administration
  210.   Configuring MySQL
  211.     `mysqld' Command-line Options
  212.     `my.cnf' Option Files
  213.     Running Multiple MySQL Servers on the Same Machine
  214.       Running Multiple Servers on Windows
  215.       Running Multiple Servers on Unix
  216.       Using Client Programs in a Multiple-Server Environment
  217.   General Security Issues and the MySQL Access Privilege System
  218.     General Security Guidelines
  219.     How to Make MySQL Secure Against Crackers
  220.     Startup Options for `mysqld' Concerning Security
  221.     Security issues with `LOAD DATA LOCAL'
  222.     What the Privilege System Does
  223.     How the Privilege System Works
  224.     Privileges Provided by MySQL
  225.     Connecting to the MySQL Server
  226.     Access Control, Stage 1: Connection Verification
  227.     Access Control, Stage 2: Request Verification
  228.     Password Hashing in MySQL 4.1
  229.     Causes of `Access denied' Errors
  230.   MySQL User Account Management
  231.     `GRANT' and `REVOKE' Syntax
  232.     MySQL User Names and Passwords
  233.     When Privilege Changes Take Effect
  234.     Setting Up the Initial MySQL Privileges
  235.     Adding New Users to MySQL
  236.     Limiting user resources
  237.     Setting Up Passwords
  238.     Keeping Your Password Secure
  239.     Using Secure Connections
  240.       Basics
  241.       Requirements
  242.       Setting Up SSL Certificates for MySQL
  243.       `GRANT' Options
  244.   Disaster Prevention and Recovery
  245.     Database Backups
  246.     `BACKUP TABLE' Syntax
  247.     `RESTORE TABLE' Syntax
  248.     `CHECK TABLE' Syntax
  249.     `REPAIR TABLE' Syntax
  250.     Using `myisamchk' for Table Maintenance and Crash Recovery
  251.       `myisamchk' Invocation Syntax
  252.       General Options for `myisamchk'
  253.       Check Options for `myisamchk'
  254.       Repair Options for myisamchk
  255.       Other Options for `myisamchk'
  256.       `myisamchk' Memory Usage
  257.       Using `myisamchk' for Crash Recovery
  258.       How to Check Tables for Errors
  259.       How to Repair Tables
  260.       Table Optimisation
  261.     Setting Up a Table Maintenance Regimen
  262.     Getting Information About a Table
  263.   Database Administration Language Reference
  264.     `OPTIMIZE TABLE' Syntax
  265.     `ANALYZE TABLE' Syntax
  266.     `FLUSH' Syntax
  267.     `RESET' Syntax
  268.     `PURGE MASTER LOGS' Syntax
  269.     `KILL' Syntax
  270.     `SHOW' Syntax
  271.       Retrieving information about Database, Tables, Columns, and Indexes
  272.       `SHOW TABLE STATUS'
  273.       `SHOW STATUS'
  274.       `SHOW VARIABLES'
  275.       `SHOW [BDB] LOGS'
  276.       `SHOW PROCESSLIST'
  277.       `SHOW GRANTS'
  278.       `SHOW CREATE TABLE'
  279.       `SHOW WARNINGS | ERRORS'
  280.       `SHOW TABLE TYPES'
  281.       `SHOW PRIVILEGES'
  282.   MySQL Localisation and International Usage
  283.     The Character Set Used for Data and Sorting
  284.       German character set
  285.     Non-English Error Messages
  286.     Adding a New Character Set
  287.     The Character Definition Arrays
  288.     String Collating Support
  289.     Multi-byte Character Support
  290.     Problems With Character Sets
  291.   MySQL Server-Side Scripts and Utilities
  292.     Overview of the Server-Side Scripts and Utilities
  293.     `mysqld_safe', The Wrapper Around `mysqld'
  294.     `mysqld_multi', A Program for Managing Multiple MySQL Servers
  295.     `myisampack', The MySQL Compressed Read-only Table Generator
  296.     `mysqld-max', An Extended `mysqld' Server
  297.   MySQL Client-Side Scripts and Utilities
  298.     Overview of the Client-Side Scripts and Utilities
  299.     `mysql', The Command-line Tool
  300.     `mysqladmin', Administrating a MySQL Server
  301.     `mysqlbinlog', Executing the queries from a binary log
  302.     Using `mysqlcheck' for Table Maintenance and Crash Recovery
  303.     `mysqldump', Dumping Table Structure and Data
  304.     `mysqlhotcopy', Copying MySQL Databases and Tables
  305.     `mysqlimport', Importing Data from Text Files
  306.     `mysqlshow', Showing Databases, Tables, and Columns
  307.     `mysql_config', Get compile options for compiling clients
  308.     `perror', Explaining Error Codes
  309.     How to Run SQL Commands from a Text File
  310.   The MySQL Log Files
  311.     The Error Log
  312.     The General Query Log
  313.     The Update Log
  314.     The Binary Log
  315.     The Slow Query Log
  316.     Log File Maintenance
  317.   Replication in MySQL
  318.     Introduction
  319.     Replication Implementation Overview
  320.     Replication Implementation Details
  321.     How To Set Up Replication
  322.     Replication Features and Known Problems
  323.     Replication Options in `my.cnf'
  324.     SQL Commands Related to Replication
  325.       `START SLAVE' (slave)
  326.       `STOP SLAVE' (slave)
  327.       `SET SQL_LOG_BIN=0|1' (master)
  328.       `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n' (slave)
  329.       `RESET MASTER' (master)
  330.       `RESET SLAVE' (slave)
  331.       `LOAD TABLE tblname FROM MASTER' (slave)
  332.       `LOAD DATA FROM MASTER' (slave)
  333.       `CHANGE MASTER TO master_def_list' (slave)
  334.       `MASTER_POS_WAIT()' (slave)
  335.       `SHOW MASTER STATUS' (master)
  336.       `SHOW SLAVE HOSTS' (master)
  337.       `SHOW SLAVE STATUS' (slave)
  338.       `SHOW MASTER LOGS' (master)
  339.       `SHOW BINLOG EVENTS' (master)
  340.       `PURGE MASTER LOGS' (master)
  341.     Replication FAQ
  342.     Troubleshooting Replication
  343.  
  344. MySQL Optimisation
  345.   Optimisation Overview
  346.     MySQL Design Limitations/Tradeoffs
  347.     Portability
  348.     What Have We Used MySQL For?
  349.     The MySQL Benchmark Suite
  350.     Using Your Own Benchmarks
  351.   Optimising `SELECT's and Other Queries
  352.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  353.     Estimating Query Performance
  354.     Speed of `SELECT' Queries
  355.     How MySQL Optimises `WHERE' Clauses
  356.     How MySQL Optimises `IS NULL'
  357.     How MySQL Optimises `DISTINCT'
  358.     How MySQL Optimises `LEFT JOIN' and `RIGHT JOIN'
  359.     How MySQL Optimises `ORDER BY'
  360.     How MySQL Optimises `LIMIT'
  361.     Speed of `INSERT' Queries
  362.     Speed of `UPDATE' Queries
  363.     Speed of `DELETE' Queries
  364.     Other Optimisation Tips
  365.   Locking Issues
  366.     How MySQL Locks Tables
  367.     Table Locking Issues
  368.   Optimising Database Structure
  369.     Design Choices
  370.     Get Your Data as Small as Possible
  371.     How MySQL Uses Indexes
  372.     Column Indexes
  373.     Multiple-Column Indexes
  374.     Why So Many Open tables?
  375.     How MySQL Opens and Closes Tables
  376.     Drawbacks to Creating Large Numbers of Tables in the Same Database
  377.   Optimising the MySQL Server
  378.     System/Compile Time and Startup Parameter Tuning
  379.     Tuning Server Parameters
  380.     How Compiling and Linking Affects the Speed of MySQL
  381.     How MySQL Uses Memory
  382.     How MySQL uses DNS
  383.     `SET' Syntax
  384.   Disk Issues
  385.     Using Symbolic Links
  386.       Using Symbolic Links for Databases
  387.       Using Symbolic Links for Tables
  388.  
  389. MySQL Language Reference
  390.   Language Structure
  391.     Literals: How to Write Strings and Numbers
  392.       Strings
  393.       Numbers
  394.       Hexadecimal Values
  395.       `NULL' Values
  396.     Database, Table, Index, Column, and Alias Names
  397.     Case Sensitivity in Names
  398.     User Variables
  399.     System Variables
  400.     Comment Syntax
  401.     Is MySQL Picky About Reserved Words?
  402.   Column Types
  403.     Numeric Types
  404.     Date and Time Types
  405.       Y2K Issues and Date Types
  406.       The `DATETIME', `DATE', and `TIMESTAMP' Types
  407.       The `TIME' Type
  408.       The `YEAR' Type
  409.     String Types
  410.       The `CHAR' and `VARCHAR' Types
  411.       The `BLOB' and `TEXT' Types
  412.       The `ENUM' Type
  413.       The `SET' Type
  414.     Choosing the Right Type for a Column
  415.     Using Column Types from Other Database Engines
  416.     Column Type Storage Requirements
  417.   Functions for Use in `SELECT' and `WHERE' Clauses
  418.     Non-Type-Specific Operators and Functions
  419.       Parentheses
  420.       Comparison Operators
  421.       Logical Operators
  422.       Control Flow Functions
  423.     String Functions
  424.       String Comparison Functions
  425.       Case-Sensitivity
  426.     Numeric Functions
  427.       Arithmetic Operations
  428.       Mathematical Functions
  429.     Date and Time Functions
  430.     Cast Functions
  431.     Other Functions
  432.       Bit Functions
  433.       Miscellaneous Functions
  434.     Functions and Modifiers for Use with `GROUP BY' Clauses
  435.       `GROUP BY' Functions
  436.       `GROUP BY' Modifiers
  437.       `GROUP BY' with Hidden Fields
  438.   Data Manipulation: `SELECT', `INSERT', `UPDATE', `DELETE'
  439.     `SELECT' Syntax
  440.       `JOIN' Syntax
  441.       `UNION' Syntax
  442.     `HANDLER' Syntax
  443.     `INSERT' Syntax
  444.       `INSERT ... SELECT' Syntax
  445.     `INSERT DELAYED' Syntax
  446.     `UPDATE' Syntax
  447.     `DELETE' Syntax
  448.     `TRUNCATE' Syntax
  449.     `REPLACE' Syntax
  450.     `LOAD DATA INFILE' Syntax
  451.     `DO' Syntax
  452.   Data Definition: `CREATE', `DROP', `ALTER'
  453.     `CREATE DATABASE' Syntax
  454.     `DROP DATABASE' Syntax
  455.     `CREATE TABLE' Syntax
  456.       Silent Column Specification Changes
  457.     `ALTER TABLE' Syntax
  458.     `RENAME TABLE' Syntax
  459.     `DROP TABLE' Syntax
  460.     `CREATE INDEX' Syntax
  461.     `DROP INDEX' Syntax
  462.   Basic MySQL User Utility Commands
  463.     `USE' Syntax
  464.     `DESCRIBE' Syntax (Get Information About Columns)
  465.   MySQL Transactional and Locking Commands
  466.     `START TRANSACTION', `COMMIT', and `ROLLBACK' Syntax
  467.     `SAVEPOINT' and `ROLLBACK TO SAVEPOINT' Syntax
  468.     `LOCK TABLES' and `UNLOCK TABLES' Syntax
  469.     `SET TRANSACTION' Syntax
  470.   MySQL Full-text Search
  471.     Full-text Restrictions
  472.     Fine-tuning MySQL Full-text Search
  473.     Full-text Search TODO
  474.   MySQL Query Cache
  475.     How The Query Cache Operates
  476.     Query Cache Configuration
  477.     Query Cache Options in `SELECT'
  478.     Query Cache Status and Maintenance
  479.  
  480. MySQL Table Types
  481.   `MyISAM' Tables
  482.     Space Needed for Keys
  483.     `MyISAM' Table Formats
  484.       Static (Fixed-length) Table Characteristics
  485.       Dynamic Table Characteristics
  486.       Compressed Table Characteristics
  487.     `MyISAM' Table Problems
  488.       Corrupted `MyISAM' Tables
  489.       Clients is using or hasn't closed the table properly
  490.   `MERGE' Tables
  491.     `MERGE' Table Problems
  492.   `ISAM' Tables
  493.   `HEAP' Tables
  494.   `InnoDB' Tables
  495.     InnoDB Tables Overview
  496.     InnoDB in MySQL Version 3.23
  497.     InnoDB Startup Options
  498.     Creating InnoDB Tablespace
  499.       If Something Goes Wrong in Database Creation
  500.     Creating InnoDB Tables
  501.       Converting MyISAM Tables to InnoDB
  502.       Foreign Key Constraints
  503.     Adding and Removing InnoDB Data and Log Files
  504.     Backing up and Recovering an InnoDB Database
  505.       Forcing recovery
  506.       Checkpoints
  507.     Moving an InnoDB Database to Another Machine
  508.     InnoDB Transaction Model
  509.       Consistent Read
  510.       Locking Reads
  511.       Next-key Locking: Avoiding the Phantom Problem
  512.       Locks Set by Different SQL Statements in `InnoDB'
  513.       Deadlock Detection and Rollback
  514.       An Example of How the Consistent Read Works in `InnoDB'
  515.       How to cope with deadlocks?
  516.       Performance Tuning Tips
  517.       The `InnoDB' Monitor
  518.     Implementation of Multi-versioning
  519.     Table and Index Structures
  520.       Physical Structure of an Index
  521.       Insert Buffering
  522.       Adaptive Hash Indexes
  523.       Physical Record Structure
  524.       How an Auto-increment Column Works in InnoDB
  525.     File Space Management and Disk I/O
  526.       Disk I/O
  527.       File Space Management
  528.       Defragmenting a Table
  529.     Error Handling
  530.     Restrictions on InnoDB Tables
  531.     InnoDB Change History
  532.       MySQL/InnoDB-4.0.14, July 22, 2003
  533.       MySQL/InnoDB-3.23.57, June 20, 2003
  534.       MySQL/InnoDB-4.0.13, May 20, 2003
  535.       MySQL/InnoDB-4.1.0, April 3, 2003
  536.       MySQL/InnoDB-3.23.56, March 17, 2003
  537.       MySQL/InnoDB-4.0.12, March 18, 2003
  538.       MySQL/InnoDB-4.0.11, February 25, 2003
  539.       MySQL/InnoDB-4.0.10, February 4, 2003
  540.       MySQL/InnoDB-3.23.55, January 24, 2003
  541.       MySQL/InnoDB-4.0.9, January 14, 2003
  542.       MySQL/InnoDB-4.0.8, January 7, 2003
  543.       MySQL/InnoDB-4.0.7, December 26, 2002
  544.       MySQL/InnoDB-4.0.6, December 19, 2002
  545.       MySQL/InnoDB-3.23.54, December 12, 2002
  546.       MySQL/InnoDB-4.0.5, November 18, 2002
  547.       MySQL/InnoDB-3.23.53, October 9, 2002
  548.       MySQL/InnoDB-4.0.4, October 2, 2002
  549.       MySQL/InnoDB-4.0.3, August 28, 2002
  550.       MySQL/InnoDB-3.23.52, August 16, 2002
  551.       MySQL/InnoDB-4.0.2, July 10, 2002
  552.       MySQL/InnoDB-3.23.51, June 12, 2002
  553.       MySQL/InnoDB-3.23.50, April 23, 2002
  554.       MySQL/InnoDB-3.23.49, February 17, 2002
  555.       MySQL/InnoDB-3.23.48, February 9, 2002
  556.       MySQL/InnoDB-3.23.47, December 28, 2001
  557.       MySQL/InnoDB-4.0.1, December 23, 2001
  558.       MySQL/InnoDB-3.23.46, November 30, 2001
  559.       MySQL/InnoDB-3.23.45, November 23, 2001
  560.       MySQL/InnoDB-3.23.44, November 2, 2001
  561.       MySQL/InnoDB-3.23.43, October 4, 2001
  562.       MySQL/InnoDB-3.23.42, September 9, 2001
  563.       MySQL/InnoDB-3.23.41, August 13, 2001
  564.       MySQL/InnoDB-3.23.40, July 16, 2001
  565.       MySQL/InnoDB-3.23.39, June 13, 2001
  566.       MySQL/InnoDB-3.23.38, May 12, 2001
  567.     `InnoDB' Contact Information
  568.   `BDB' or `BerkeleyDB' Tables
  569.     Overview of `BDB' Tables
  570.     Installing `BDB'
  571.     `BDB' startup options
  572.     Characteristics of `BDB' tables:
  573.     Things we need to fix for `BDB' in the near future:
  574.     Operating systems supported by `BDB'
  575.     Restrictions on `BDB' Tables
  576.     Errors That May Occur When Using `BDB' Tables
  577.  
  578. National Character Sets and Unicode in MySQL 4.1
  579.   Character Sets and Collations in General
  580.   Character Sets and Collations in MySQL
  581.   Determining The Default Character Set And Collation
  582.     Server Character Set and Collation
  583.     Database Character Set and Collation
  584.     Table Character Set and Collation
  585.     Column Character Set and Collation
  586.     Examples of Character Set and Collation Assignment
  587.     Connection Character Sets and Collations
  588.     Character String Literal Character Set and Collation
  589.     `COLLATE' Clause in Various Parts of an SQL Query
  590.     `COLLATE' Clause Precedence
  591.     `BINARY' Operator
  592.     Some Special Cases Where the Collation Determination is Tricky
  593.     Collations Must Be for the Right Character Set
  594.     An example of the Effect of Collation
  595.   Operations Affected by Character Set Support
  596.     Result Strings
  597.     `CONVERT()'
  598.     `CAST()'
  599.     `SHOW CHARACTER SET'
  600.     `SHOW COLLATION'
  601.     `SHOW CREATE DATABASE'
  602.     `SHOW FULL COLUMNS'
  603.   Unicode Support
  604.   UTF8 for Metadata
  605.   Compatibility with Other DBMSs
  606.   New Character Set Configuration File format
  607.   National Character Set
  608.   Upgrading from MySQL 4.0
  609.     4.0 Character Sets and Corresponding 4.1 Character Set/Collation Pairs
  610.   The Character Sets and Collations that MySQL Supports
  611.     The Unicode Character Sets
  612.     Platform Specific Character Sets
  613.     Character Sets for South Europe and Middle East
  614.     The Asian Character Sets
  615.     The Baltic Character Sets
  616.     The Cyrillic Character Sets
  617.     The Central European Character Sets
  618.     The West European Character Sets
  619.  
  620. MySQL APIs
  621.   MySQL C API
  622.     C API Datatypes
  623.     C API Function Overview
  624.     C API Function Descriptions
  625.       `mysql_affected_rows()'
  626.       `mysql_change_user()'
  627.       `mysql_character_set_name()'
  628.       `mysql_close()'
  629.       `mysql_connect()'
  630.       `mysql_create_db()'
  631.       `mysql_data_seek()'
  632.       `mysql_debug()'
  633.       `mysql_drop_db()'
  634.       `mysql_dump_debug_info()'
  635.       `mysql_eof()'
  636.       `mysql_errno()'
  637.       `mysql_error()'
  638.       `mysql_escape_string()'
  639.       `mysql_fetch_field()'
  640.       `mysql_fetch_fields()'
  641.       `mysql_fetch_field_direct()'
  642.       `mysql_fetch_lengths()'
  643.       `mysql_fetch_row()'
  644.       `mysql_field_count()'
  645.       `mysql_field_seek()'
  646.       `mysql_field_tell()'
  647.       `mysql_free_result()'
  648.       `mysql_get_client_info()'
  649.       `mysql_get_server_version()'
  650.       `mysql_get_host_info()'
  651.       `mysql_get_proto_info()'
  652.       `mysql_get_server_info()'
  653.       `mysql_info()'
  654.       `mysql_init()'
  655.       `mysql_insert_id()'
  656.       `mysql_kill()'
  657.       `mysql_list_dbs()'
  658.       `mysql_list_fields()'
  659.       `mysql_list_processes()'
  660.       `mysql_list_tables()'
  661.       `mysql_num_fields()'
  662.       `mysql_num_rows()'
  663.       `mysql_options()'
  664.       `mysql_ping()'
  665.       `mysql_query()'
  666.       `mysql_real_connect()'
  667.       `mysql_real_escape_string()'
  668.       `mysql_real_query()'
  669.       `mysql_reload()'
  670.       `mysql_row_seek()'
  671.       `mysql_row_tell()'
  672.       `mysql_select_db()'
  673.       `mysql_sqlstate()'
  674.       `mysql_shutdown()'
  675.       `mysql_stat()'
  676.       `mysql_store_result()'
  677.       `mysql_thread_id()'
  678.       `mysql_use_result()'
  679.       `mysql_commit()'
  680.       `mysql_rollback()'
  681.       `mysql_autocommit()'
  682.       `mysql_more_results()'
  683.       `mysql_next_result()'
  684.     C API Prepared Statements
  685.     C API Prepared Statement Datatypes
  686.     C API Prepared Statement Function Overview
  687.     C API Prepared Statement Function Descriptions
  688.       `mysql_prepare()'
  689.       `mysql_param_count()'
  690.       `mysql_prepare_result()'
  691.       `mysql_bind_param()'
  692.       `mysql_execute()'
  693.       `mysql_stmt_affected_rows()'
  694.       `mysql_bind_result()'
  695.       `mysql_stmt_store_result()'
  696.       `mysql_stmt_data_seek()'
  697.       `mysql_stmt_row_seek()'
  698.       `mysql_stmt_row_tell()'
  699.       `mysql_stmt_num_rows()'
  700.       `mysql_fetch()'
  701.       `mysql_send_long_data()'
  702.       `mysql_stmt_close()'
  703.       `mysql_stmt_errno()'
  704.       `mysql_stmt_error()'
  705.       `mysql_stmt_sqlstate()'
  706.     C API Handling of Multiple Query Execution
  707.     C API Handling of Date and Time Values
  708.     C API Threaded Function Descriptions
  709.       `my_init()'
  710.       `mysql_thread_init()'
  711.       `mysql_thread_end()'
  712.       `mysql_thread_safe()'
  713.     C API Embedded Server Function Descriptions
  714.       `mysql_server_init()'
  715.       `mysql_server_end()'
  716.     Common questions and problems when using the C API
  717.       Why Is It that After `mysql_query()' Returns Success, `mysql_store_result()' Sometimes Returns `NULL'?
  718.       What Results Can I Get From a Query?
  719.       How Can I Get the Unique ID for the Last Inserted Row?
  720.       Problems Linking with the C API
  721.     Building Client Programs
  722.     How to Make a Threaded Client
  723.     libmysqld, the Embedded MySQL Server Library
  724.       Overview of the Embedded MySQL Server Library
  725.       Compiling Programs with `libmysqld'
  726.       Restrictions when using the Embedded MySQL Server
  727.       Using Option Files with the Embedded Server
  728.       Things left to do in Embedded Server (TODO)
  729.       A Simple Embedded Server Example
  730.       Licensing the Embedded Server
  731.   MySQL ODBC Support
  732.     How To Install MyODBC
  733.     How to Fill in the Various Fields in the ODBC Administrator Program
  734.     Connect parameters for MyODBC
  735.     How to Report Problems with MyODBC
  736.     Programs Known to Work with MyODBC
  737.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  738.     Reporting Problems with MyODBC
  739.   MySQL Java Connectivity (JDBC)
  740.   MySQL PHP API
  741.     Common Problems with MySQL and PHP
  742.   MySQL Perl API
  743.     `DBI' with `DBD::mysql'
  744.     The `DBI' Interface
  745.     More `DBI'/`DBD' Information
  746.   MySQL C++ API
  747.     Borland C++
  748.   MySQL Python API
  749.   MySQL Tcl API
  750.   MySQL Eiffel Wrapper
  751.  
  752. Error Handling in MySQL
  753.   Error Returns
  754.  
  755. Spatial Extensions in MySQL
  756.   Introduction
  757.   The OpenGIS Geometry Model
  758.     The Geometry Class Hierarchy
  759.     Class `Geometry'
  760.     Class `Point'
  761.     Class `Curve'
  762.     Class `LineString'
  763.     Class `Surface'
  764.     Class `Polygon'
  765.     Class `GeometryCollection'
  766.     Class `MultiPoint'
  767.     Class `MultiCurve'
  768.     Class `MultiLineString'
  769.     Class `MultiSurface'
  770.     Class `MultiPolygon'
  771.   Supported Spatial Data Formats
  772.     Well-Known Text (WKT) Format
  773.     Well-Known Binary (WKB) Format
  774.   Creating a Spatially Enabled MySQL Database
  775.     MySQL Spatial Datatypes
  776.     Creating Spatial Values
  777.       Creating Geometry Values Using WKT Functions
  778.       Creating Geometry Values Using WKB Functions
  779.       Creating Geometry Values Using MySQL-Specific Functions
  780.     Creating Spatial Columns
  781.     Populating Spatial Columns
  782.     Fetching Spatial Data
  783.       Fetching Spatial Data in Internal Format
  784.       Fetching Spatial Data in WKT Format
  785.       Fetching Spatial Data in WKB Format
  786.   Analysing Spatial Information
  787.     Functions To Convert Geometries Between Formats
  788.     `Geometry' Property Analysis Functions
  789.       General Geometry Property Analysis Functions
  790.       `Point' Property Analysis Functions
  791.       `LineString' Property Analysis Functions
  792.       `MultiLineString' Property Analysis Functions
  793.       `Polygon' Property Analysis Functions
  794.       `MultiPolygon' Property Analysis Functions
  795.       `GeometryCollection' Property Analysis Functions
  796.     Functions That Create New Geometries From Existing Ones
  797.       Geometry Functions That Produce New Geometries
  798.       Spatial Operators
  799.     Functions For Testing Spatial Relations Between Geometric Objects
  800.     Relations On Geometry Minimal Bounding Rectangles (MBRs)
  801.     Functions That Test Spatial Relationships Between Geometries
  802.   Optimising Spatial Analysis
  803.     Creating Spatial Indexes
  804.     Using a Spatial Index
  805.   MySQL Conformance And Compatibility
  806.     GIS Features That Are Not Yet Implemented
  807.  
  808. Extending MySQL
  809.   MySQL Internals
  810.     MySQL Threads
  811.     MySQL Test Suite
  812.       Running the MySQL Test Suite
  813.       Extending the MySQL Test Suite
  814.       Reporting Bugs in the MySQL Test Suite
  815.   Adding New Functions to MySQL
  816.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  817.     Adding a New User-definable Function
  818.       UDF Calling Sequences for simple functions
  819.       UDF Calling Sequences for aggregate functions
  820.       Argument Processing
  821.       Return Values and Error Handling
  822.       Compiling and Installing User-definable Functions
  823.     Adding a New Native Function
  824.   Adding New Procedures to MySQL
  825.     Procedure Analyse
  826.     Writing a Procedure
  827.  
  828. Problems and Common Errors
  829.   How to Determine What Is Causing Problems
  830.   Common Errors When Using MySQL
  831.     `Access denied' Error
  832.     `MySQL server has gone away' Error
  833.     `Can't connect to [local] MySQL server' Error
  834.     `Client does not support authentication protocol' error
  835.     `Host '...' is blocked' Error
  836.     `Too many connections' Error
  837.     `Some non-transactional changed tables couldn't be rolled back' Error
  838.     `Out of memory' Error
  839.     `Packet too large' Error
  840.     Communication Errors / Aborted Connection
  841.     `The table is full' Error
  842.     `Can't create/write to file' Error
  843.     `Commands out of sync' Error in Client
  844.     `Ignoring user' Error
  845.     `Table 'xxx' doesn't exist' Error
  846.     `Can't initialize character set xxx' error
  847.     File Not Found
  848.   Installation Related Issues
  849.     Problems When Linking with the MySQL Client Library
  850.     How to Run MySQL As a Normal User
  851.     Problems with File Permissions
  852.   Administration Related Issues
  853.     What To Do If MySQL Keeps Crashing
  854.     How to Reset a Forgotten Root Password
  855.     How MySQL Handles a Full Disk
  856.     Where MySQL Stores Temporary Files
  857.     How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'
  858.     Time Zone Problems
  859.   Query Related Issues
  860.     Case-Sensitivity in Searches
  861.     Problems Using `DATE' Columns
  862.     Problems with `NULL' Values
  863.     Problems with `alias'
  864.     Deleting Rows from Related Tables
  865.     Solving Problems with No Matching Rows
  866.     Problems with Floating-Point Comparison
  867.   Optimiser Related Issues
  868.     How to avoid table scan,,,
  869.   Table Definition Related Issues
  870.     Problems with `ALTER TABLE'.
  871.     How To Change the Order of Columns in a Table
  872.     TEMPORARY TABLE problems
  873.  
  874. Contributed Programs
  875.   APIs
  876.   Converters
  877.   Utilities
  878.  
  879. Credits
  880.   Developers at MySQL AB
  881.   Contributors to MySQL
  882.   Supporters to MySQL
  883.  
  884. MySQL Change History
  885.   Changes in release 5.0.0 (Development)
  886.   Changes in release 4.1.x (Alpha)
  887.     Changes in release 4.1.1 (not released yet)
  888.     Changes in release 4.1.0 (03 Apr 2003: Alpha)
  889.   Changes in release 4.0.x (Production)
  890.     Changes in release 4.0.16 (not released yet)
  891.     Changes in release 4.0.15 (to be released soon)
  892.     Changes in release 4.0.14 (18 Jul 2003)
  893.     Changes in release 4.0.13 (16 May 2003)
  894.     Changes in release 4.0.12 (15 Mar 2003: Production)
  895.     Changes in release 4.0.11 (20 Feb 2003)
  896.     Changes in release 4.0.10 (29 Jan 2003)
  897.     Changes in release 4.0.9 (09 Jan 2003)
  898.     Changes in release 4.0.8 (07 Jan 2003)
  899.     Changes in release 4.0.7 (20 Dec 2002)
  900.     Changes in release 4.0.6 (14 Dec 2002: Gamma)
  901.     Changes in release 4.0.5 (13 Nov 2002)
  902.     Changes in release 4.0.4 (29 Sep 2002)
  903.     Changes in release 4.0.3 (26 Aug 2002: Beta)
  904.     Changes in release 4.0.2 (01 Jul 2002)
  905.     Changes in release 4.0.1 (23 Dec 2001)
  906.     Changes in release 4.0.0 (Oct 2001: Alpha)
  907.   Changes in release 3.23.x (Recent; still supported)
  908.     Changes in release 3.23.59 (not released yet)
  909.     Changes in release 3.23.58 (to be released soon)
  910.     Changes in release 3.23.57 (06 Jun 2003)
  911.     Changes in release 3.23.56 (13 Mar 2003)
  912.     Changes in release 3.23.55 (23 Jan 2003)
  913.     Changes in release 3.23.54 (05 Dec 2002)
  914.     Changes in release 3.23.53 (09 Oct 2002)
  915.     Changes in release 3.23.52 (14 Aug 2002)
  916.     Changes in release 3.23.51 (31 May 2002)
  917.     Changes in release 3.23.50 (21 Apr 2002)
  918.     Changes in release 3.23.49
  919.     Changes in release 3.23.48 (07 Feb 2002)
  920.     Changes in release 3.23.47 (27 Dec 2001)
  921.     Changes in release 3.23.46 (29 Nov 2001)
  922.     Changes in release 3.23.45 (22 Nov 2001)
  923.     Changes in release 3.23.44 (31 Oct 2001)
  924.     Changes in release 3.23.43 (04 Oct 2001)
  925.     Changes in release 3.23.42 (08 Sep 2001)
  926.     Changes in release 3.23.41 (11 Aug 2001)
  927.     Changes in release 3.23.40
  928.     Changes in release 3.23.39 (12 Jun 2001)
  929.     Changes in release 3.23.38 (09 May 2001)
  930.     Changes in release 3.23.37 (17 Apr 2001)
  931.     Changes in release 3.23.36 (27 Mar 2001)
  932.     Changes in release 3.23.35 (15 Mar 2001)
  933.     Changes in release 3.23.34a
  934.     Changes in release 3.23.34 (10 Mar 2001)
  935.     Changes in release 3.23.33 (09 Feb 2001)
  936.     Changes in release 3.23.32 (22 Jan 2001: Production)
  937.     Changes in release 3.23.31 (17 Jan 2001)
  938.     Changes in release 3.23.30 (04 Jan 2001)
  939.     Changes in release 3.23.29 (16 Dec 2000)
  940.     Changes in release 3.23.28 (22 Nov 2000: Gamma)
  941.     Changes in release 3.23.27 (24 Oct 2000)
  942.     Changes in release 3.23.26 (18 Oct 2000)
  943.     Changes in release 3.23.25 (29 Sep 2000)
  944.     Changes in release 3.23.24 (08 Sep 2000)
  945.     Changes in release 3.23.23 (01 Sep 2000)
  946.     Changes in release 3.23.22 (31 Jul 2000)
  947.     Changes in release 3.23.21
  948.     Changes in release 3.23.20
  949.     Changes in release 3.23.19
  950.     Changes in release 3.23.18
  951.     Changes in release 3.23.17
  952.     Changes in release 3.23.16
  953.     Changes in release 3.23.15 (May 2000: Beta)
  954.     Changes in release 3.23.14
  955.     Changes in release 3.23.13
  956.     Changes in release 3.23.12 (07 Mar 2000)
  957.     Changes in release 3.23.11
  958.     Changes in release 3.23.10
  959.     Changes in release 3.23.9
  960.     Changes in release 3.23.8 (02 Jan 2000)
  961.     Changes in release 3.23.7 (10 Dec 1999)
  962.     Changes in release 3.23.6
  963.     Changes in release 3.23.5 (20 Oct 1999)
  964.     Changes in release 3.23.4 (28 Sep 1999)
  965.     Changes in release 3.23.3
  966.     Changes in release 3.23.2 (09 Aug 1999)
  967.     Changes in release 3.23.1
  968.     Changes in release 3.23.0 (05 Aug 1999: Alpha)
  969.   Changes in release 3.22.x (Old; discontinued)
  970.     Changes in release 3.22.35
  971.     Changes in release 3.22.34
  972.     Changes in release 3.22.33
  973.     Changes in release 3.22.32 (14 Feb 2000)
  974.     Changes in release 3.22.31
  975.     Changes in release 3.22.30
  976.     Changes in release 3.22.29 (02 Jan 2000)
  977.     Changes in release 3.22.28 (20 Oct 1999)
  978.     Changes in release 3.22.27
  979.     Changes in release 3.22.26 (16 Sep 1999)
  980.     Changes in release 3.22.25
  981.     Changes in release 3.22.24 (05 Jul 1999)
  982.     Changes in release 3.22.23 (08 Jun 1999)
  983.     Changes in release 3.22.22 (30 Apr 1999)
  984.     Changes in release 3.22.21
  985.     Changes in release 3.22.20 (18 Mar 1999)
  986.     Changes in release 3.22.19 (Mar 1999: Production)
  987.     Changes in release 3.22.18
  988.     Changes in release 3.22.17
  989.     Changes in release 3.22.16 (Feb 1999: Gamma)
  990.     Changes in release 3.22.15
  991.     Changes in release 3.22.14
  992.     Changes in release 3.22.13
  993.     Changes in release 3.22.12
  994.     Changes in release 3.22.11
  995.     Changes in release 3.22.10
  996.     Changes in release 3.22.9
  997.     Changes in release 3.22.8
  998.     Changes in release 3.22.7 (Sep 1998: Beta)
  999.     Changes in release 3.22.6
  1000.     Changes in release 3.22.5
  1001.     Changes in release 3.22.4
  1002.     Changes in release 3.22.3
  1003.     Changes in release 3.22.2
  1004.     Changes in release 3.22.1 (Jun 1998: Alpha)
  1005.     Changes in release 3.22.0
  1006.   Changes in release 3.21.x
  1007.     Changes in release 3.21.33
  1008.     Changes in release 3.21.32
  1009.     Changes in release 3.21.31
  1010.     Changes in release 3.21.30
  1011.     Changes in release 3.21.29
  1012.     Changes in release 3.21.28
  1013.     Changes in release 3.21.27
  1014.     Changes in release 3.21.26
  1015.     Changes in release 3.21.25
  1016.     Changes in release 3.21.24
  1017.     Changes in release 3.21.23
  1018.     Changes in release 3.21.22
  1019.     Changes in release 3.21.21a
  1020.     Changes in release 3.21.21
  1021.     Changes in release 3.21.20
  1022.     Changes in release 3.21.19
  1023.     Changes in release 3.21.18
  1024.     Changes in release 3.21.17
  1025.     Changes in release 3.21.16
  1026.     Changes in release 3.21.15
  1027.     Changes in release 3.21.14b
  1028.     Changes in release 3.21.14a
  1029.     Changes in release 3.21.13
  1030.     Changes in release 3.21.12
  1031.     Changes in release 3.21.11
  1032.     Changes in release 3.21.10
  1033.     Changes in release 3.21.9
  1034.     Changes in release 3.21.8
  1035.     Changes in release 3.21.7
  1036.     Changes in release 3.21.6
  1037.     Changes in release 3.21.5
  1038.     Changes in release 3.21.4
  1039.     Changes in release 3.21.3
  1040.     Changes in release 3.21.2
  1041.     Changes in release 3.21.0
  1042.   Changes in release 3.20.x
  1043.     Changes in release 3.20.18
  1044.     Changes in release 3.20.17
  1045.     Changes in release 3.20.16
  1046.     Changes in release 3.20.15
  1047.     Changes in release 3.20.14
  1048.     Changes in release 3.20.13
  1049.     Changes in release 3.20.11
  1050.     Changes in release 3.20.10
  1051.     Changes in release 3.20.9
  1052.     Changes in release 3.20.8
  1053.     Changes in release 3.20.7
  1054.     Changes in release 3.20.6
  1055.     Changes in release 3.20.3
  1056.     Changes in release 3.20.0
  1057.   Changes in release 3.19.x
  1058.     Changes in release 3.19.5
  1059.     Changes in release 3.19.4
  1060.     Changes in release 3.19.3
  1061.  
  1062. Porting to Other Systems
  1063.   Debugging a MySQL server
  1064.     Compiling MYSQL for Debugging
  1065.     Creating Trace Files
  1066.     Debugging mysqld under gdb
  1067.     Using a Stack Trace
  1068.     Using Log Files to Find Cause of Errors in mysqld
  1069.     Making a Test Case If You Experience Table Corruption
  1070.   Debugging a MySQL client
  1071.   The DBUG Package
  1072.   Locking methods
  1073.   Comments about RTS threads
  1074.   Differences between different thread packages
  1075.  
  1076. Environment Variables
  1077.  
  1078. MySQL Regular Expressions
  1079.  
  1080. GNU General Public License
  1081.  
  1082. GNU Lesser General Public License
  1083.  
  1084. SQL command, type and function index
  1085.  
  1086. Concept Index
  1087.  
  1088.  
  1089. This is the Reference Manual for the `MySQL Database System'.  This
  1090. version refers to the 4.0.15 version of `MySQL Server' but it is also
  1091. applicable for any older version (such as 3.23 and 4.0-production) as
  1092. changes are always indicated. There are also references for version 5.0
  1093. (development).
  1094.  
  1095. General Information
  1096. *******************
  1097.  
  1098. The `MySQL' (R) software delivers a very fast, multi-threaded,
  1099. multi-user, and robust `SQL' (`Structured Query Language') database
  1100. server.  `MySQL Server' is intended for mission-critical, heavy-load
  1101. production systems as well as for embedding into mass-deployed software.
  1102. `MySQL' is a trademark of `MySQL AB'.
  1103.  
  1104. The `MySQL' software is `Dual Licensed'. Users can choose to use the
  1105. `MySQL' software as an `Open Source'/`Free Software' product under the
  1106. terms of the `GNU General Public License'
  1107. (`http://www.gnu.org/licenses/') or can purchase a standard commercial
  1108. license from `MySQL AB'.  *Note Licensing and Support::.
  1109.  
  1110. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1111. information about the `MySQL' software.
  1112.  
  1113. The following list describes some sections of particular interest in
  1114. this manual:
  1115.  
  1116.    * For information about the company behind the `MySQL Database
  1117.      Server', see *Note What is MySQL AB::.
  1118.  
  1119.    * For a discussion about the capabilities of the `MySQL Database
  1120.      Server', see *Note Features::.
  1121.  
  1122.    * For installation instructions, see *Note Installing::.
  1123.  
  1124.    * For tips on porting the `MySQL Database Software' to new
  1125.      architectures or operating systems, see *Note Porting::.
  1126.  
  1127.    * For information about upgrading from a Version 4.0 release, see
  1128.      *Note Upgrading-from-4.0::.
  1129.  
  1130.    * For information about upgrading from a Version 3.23 release, see
  1131.      *Note Upgrading-from-3.23::.
  1132.  
  1133.    * For information about upgrading from a Version 3.22 release, see
  1134.      *Note Upgrading-from-3.22::.
  1135.  
  1136.    * For a tutorial introduction to the `MySQL Database Server', see
  1137.      *Note Tutorial::.
  1138.  
  1139.    * For examples of `SQL' and benchmarking information, see the
  1140.      benchmarking directory (`sql-bench' in the distribution).
  1141.  
  1142.    * For a history of new features and bug fixes, see *Note News::.
  1143.  
  1144.    * For a list of currently known bugs and misfeatures, see *Note
  1145.      Bugs::.
  1146.  
  1147.    * For future plans, see *Note TODO::.
  1148.  
  1149.    * For a list of all the contributors to this project, see *Note
  1150.      Credits::.
  1151.  
  1152. *Important*:
  1153.  
  1154. Reports of errors (often called bugs), as well as questions and
  1155. comments, should be sent to the general MySQL mailing list.  *Note
  1156. Mailing-list::.  *Note Bug reports::.
  1157.  
  1158. The `mysqlbug' script should be used to generate bug reports on Unix.
  1159. (Windows distributions contain a file `mysqlbug.txt' in the base
  1160. directory that can be used as a template for a bug report.)
  1161.  
  1162. For source distributions, the `mysqlbug' script can be found in the
  1163. `scripts' directory. For binary distributions, `mysqlbug' can be found
  1164. in the `bin' directory (`/usr/bin' for the `MySQL-server' RPM package).
  1165.  
  1166. If you have found a sensitive security bug in `MySQL Server', you
  1167. should send an e-mail to <security@mysql.com>.
  1168.  
  1169. About This Manual
  1170. =================
  1171.  
  1172. This is the `MySQL' reference manual; it documents `MySQL' up to
  1173. Version 4.0.15. Functional changes are always indicated with reference
  1174. to the version, so this manual is also suitable if you are using an
  1175. older version of the `MySQL' software (such as 3.23 or 4.0-production).
  1176. There are also references for version 5.0 (development).
  1177.  
  1178. Being a reference manual, it does not provide general instruction on
  1179. `SQL' or relational database concepts.
  1180.  
  1181. As the `MySQL Database Software' is under constant development, the
  1182. manual is also updated frequently.  The most recent version of this
  1183. manual is available at `http://www.mysql.com/documentation/' in many
  1184. different formats, including HTML, PDF, and Windows HLP versions.
  1185.  
  1186. The primary document is the Texinfo file.  The HTML version is produced
  1187. automatically using a modified version of `texi2html'.  The plain text
  1188. and Info versions are produced with `makeinfo'.  The PostScript version
  1189. is produced using `texi2dvi' and `dvips'.  The PDF version is produced
  1190. with `pdftex'.
  1191.  
  1192. If you have a hard time finding information in the manual, you can try
  1193. our searchable version at `http://www.mysql.com/doc/'.
  1194.  
  1195. If you have any suggestions concerning additions or corrections to this
  1196. manual, please send them to the documentation team at <docs@mysql.com>.
  1197.  
  1198. This manual was initially written by David Axmark and Michael (Monty)
  1199. Widenius. It is now maintained by the MySQL Documentation Team,
  1200. consisting of Arjen Lentz, Paul DuBois and Stefan Hinz.  For the many
  1201. other contributors, see *Note Credits::.
  1202.  
  1203. The copyright (2003) to this manual is owned by the Swedish company
  1204. `MySQL AB'. *Note Copyright::.
  1205.  
  1206. Conventions Used in This Manual
  1207. -------------------------------
  1208.  
  1209. This manual uses certain typographical conventions:
  1210.  
  1211. `constant'
  1212.      Constant-width font is used for command names and options; SQL
  1213.      statements; database, table, and column names; C and Perl code;
  1214.      and environment variables.  Example: "To see how `mysqladmin'
  1215.      works, invoke it with the `--help' option."
  1216.  
  1217. `filename'
  1218.      Constant-width font with surrounding quotes is used for filenames
  1219.      and pathnames.  Example: "The distribution is installed under the
  1220.      `/usr/local/' directory."
  1221.  
  1222. `c'
  1223.      Constant-width font with surrounding quotes is also used to
  1224.      indicate character sequences.  Example: "To specify a wildcard,
  1225.      use the `%' character."
  1226.  
  1227. _italic_
  1228.      Italic font is used for emphasis, _like this_.
  1229.  
  1230. *boldface*
  1231.      Boldface font is used in table headings and to convey *especially
  1232.      strong emphasis*.
  1233.  
  1234. When commands are shown that are meant to be executed by a particular
  1235. program, the program is indicated by a prompt shown before the command.
  1236. For example, `shell>' indicates a command that you execute from your
  1237. login shell, and `mysql>' indicates a command that you execute from the
  1238. `mysql' client program:
  1239.  
  1240.      shell> type a shell command here
  1241.      mysql> type a mysql command here
  1242.  
  1243. Shell commands are shown using Bourne shell syntax.  If you are using a
  1244. `csh'-style shell, you may need to issue commands slightly differently.
  1245. For example, the sequence to set an environment variable and run a
  1246. command looks like this in Bourne shell syntax:
  1247.  
  1248.      shell> VARNAME=value some_command
  1249.  
  1250. For `csh', you would execute the sequence like this:
  1251.  
  1252.      shell> setenv VARNAME value
  1253.      shell> some_command
  1254.  
  1255. Database, table, and column names must often be substituted into
  1256. commands.  To indicate that such substitution is necessary, this manual
  1257. uses `db_name', `tbl_name', and `col_name'.  For example, you might see
  1258. a statement like this:
  1259.  
  1260.      mysql> SELECT col_name FROM db_name.tbl_name;
  1261.  
  1262. This means that if you were to enter a similar statement, you would
  1263. supply your own database, table, and column names, perhaps like this:
  1264.  
  1265.      mysql> SELECT author_name FROM biblio_db.author_list;
  1266.  
  1267. SQL keywords are not case-sensitive and may be written in uppercase or
  1268. lowercase.  This manual uses uppercase.
  1269.  
  1270. In syntax descriptions, square brackets (`[' and `]') are used to
  1271. indicate optional words or clauses.  For example, in the following
  1272. statement, `IF EXISTS' is optional:
  1273.  
  1274.      DROP TABLE [IF EXISTS] tbl_name
  1275.  
  1276. When a syntax element consists of a number of alternatives, the
  1277. alternatives are separated by vertical bars (`|').  When one member
  1278. from a set of choices *may* be chosen, the alternatives are listed
  1279. within square brackets (`[' and `]'):
  1280.  
  1281.      TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  1282.  
  1283. When one member from a set of choices *must* be chosen, the
  1284. alternatives are listed within braces (`{' and `}'):
  1285.  
  1286.      {DESCRIBE | DESC} tbl_name {col_name | wild}
  1287.  
  1288. What Is MySQL?
  1289. ==============
  1290.  
  1291. `MySQL', the most popular `Open Source' SQL database, is developed,
  1292. distributed, and supported by `MySQL AB'.  `MySQL AB' is a commercial
  1293. company, founded by the MySQL developers, that builds its business
  1294. providing services around the `MySQL' database.  *Note What is MySQL
  1295. AB::.
  1296.  
  1297. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1298. information about `MySQL' software and `MySQL AB'.
  1299.  
  1300. `MySQL' is a database management system.
  1301.      A database is a structured collection of data.  It may be anything
  1302.      from a simple shopping list to a picture gallery or the vast
  1303.      amounts of information in a corporate network.  To add, access,
  1304.      and process data stored in a computer database, you need a
  1305.      database management system such as `MySQL' Server.  Since
  1306.      computers are very good at handling large amounts of data,
  1307.      database management systems play a central role in computing, as
  1308.      stand-alone utilities or as parts of other applications.
  1309.  
  1310. MySQL is a relational database management system.
  1311.      A relational database stores data in separate tables rather than
  1312.      putting all the data in one big storeroom.  This adds speed and
  1313.      flexibility.  The `SQL' part of "`MySQL'" stands for "`Structured
  1314.      Query Language'". SQL is the most common standardised language
  1315.      used to access databases and is defined by the ANSI/ISO SQL
  1316.      Standard.(The SQL standard has been evolving since 1986 and
  1317.      several versions exist. In this manual, "`SQL-92'" refers to the
  1318.      standard released in 1992, "`SQL-99'" refers to the standard
  1319.      released in 1999, and "`SQL:2003'" refers to the version of the
  1320.      standard that is expected to be released in mid-2003.We use the
  1321.      term "`the SQL standard'" to mean the current version of the SQL
  1322.      Standard at any time.)
  1323.  
  1324. MySQL software is `Open Source'.
  1325.      `Open Source' means that it is possible for anyone to use and
  1326.      modify the software.  Anybody can download the `MySQL' software
  1327.      from the Internet and use it without paying anything.  If you
  1328.      wish, you may study the source code and change it to suit your
  1329.      needs.  The `MySQL' software uses the `GPL' (`GNU General Public
  1330.      License'), `http://www.gnu.org/licenses/', to define what you may
  1331.      and may not do with the software in different situations.  If you
  1332.      feel uncomfortable with the `GPL' or need to embed `MySQL' code
  1333.      into a commercial application you can buy a commercially licensed
  1334.      version from us.  *Note MySQL licenses::.
  1335.  
  1336. Why use the MySQL Database Server?
  1337.      The `MySQL Database Server' is very fast, reliable, and easy to
  1338.      use.  If that is what you are looking for, you should give it a
  1339.      try.  `MySQL Server' also has a practical set of features
  1340.      developed in close cooperation with our users.  You can find a
  1341.      performance comparison of `MySQL Server' with other database
  1342.      managers on our benchmark page.  *Note MySQL Benchmarks::.
  1343.  
  1344.      `MySQL Server' was originally developed to handle large databases
  1345.      much faster than existing solutions and has been successfully used
  1346.      in highly demanding production environments for several years.
  1347.      Though under constant development, `MySQL Server' today offers a
  1348.      rich and useful set of functions.  Its connectivity, speed, and
  1349.      security make `MySQL Server' highly suited for accessing databases
  1350.      on the Internet.
  1351.  
  1352. The technical features of MySQL Server
  1353.      For advanced technical information, see *Note Reference::.  The
  1354.      `MySQL Database Software' is a client/server system that consists
  1355.      of a multi-threaded `SQL' server that supports different backends,
  1356.      several different client programs and libraries, administrative
  1357.      tools, and a wide range of programming interfaces (APIs).
  1358.  
  1359.      We also provide `MySQL Server' as a multi-threaded library which
  1360.      you can link into your application to get a smaller, faster,
  1361.      easier-to-manage product.
  1362.  
  1363. There is a large amount of contributed MySQL software available.
  1364.      It is very likely that you will find that your favorite
  1365.      application or language already supports the `MySQL Database
  1366.      Server'.
  1367.  
  1368. The official way to pronounce `MySQL' is "My Ess Que Ell" (not "my
  1369. sequel"), but we don't mind if you pronounce it as "my sequel" or in
  1370. some other localised way.
  1371.  
  1372. History of MySQL
  1373. ----------------
  1374.  
  1375. We started out with the intention of using `mSQL' to connect to our
  1376. tables using our own fast low-level (ISAM) routines. However, after some
  1377. testing we came to the conclusion that `mSQL' was not fast enough nor
  1378. flexible enough for our needs.  This resulted in a new SQL interface to
  1379. our database but with almost the same API interface as `mSQL'.  This
  1380. API was chosen to ease porting of third-party code.
  1381.  
  1382. The derivation of the name `MySQL' is not clear.  Our base directory
  1383. and a large number of our libraries and tools have had the prefix "my"
  1384. for well over 10 years.  However, co-founder Monty Widenius's daughter
  1385. (some years younger) is also named My.  Which of the two gave its name
  1386. to `MySQL' is still a mystery, even for us.
  1387.  
  1388. The name of the MySQL Dolphin (our logo) is `Sakila'. `Sakila' was
  1389. chosen by the founders of MySQL AB from a huge list of names suggested
  1390. by users in our "Name the Dolphin" contest. The winning name was
  1391. submitted by Ambrose Twebaze, an open source software developer from
  1392. Swaziland, Africa.  According to Ambrose, the name Sakila has its roots
  1393. in SiSwati, the local language of Swaziland. Sakila is also the name of
  1394. a town in Arusha, Tanzania, near Ambrose's country of origin, Uganda.
  1395.  
  1396. The Main Features of MySQL
  1397. --------------------------
  1398.  
  1399. The following list describes some of the important characteristics of
  1400. the `MySQL Database Software'. *Note MySQL 4.0 Nutshell::.
  1401.  
  1402. Internals and Portability
  1403.         * Written in C and C++.  Tested with a broad range of different
  1404.           compilers.
  1405.  
  1406.         * Works on many different platforms.  *Note Which OS::.
  1407.  
  1408.         * Uses GNU Automake, Autoconf, and Libtool for portability.
  1409.  
  1410.         * APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and
  1411.           Tcl.  *Note Clients::.
  1412.  
  1413.         * Fully multi-threaded using kernel threads.  This means it can
  1414.           easily use multiple CPUs if available.
  1415.  
  1416.         * Transactional and non-transactional storage engines.
  1417.  
  1418.         * Very fast B-tree disk tables (MyISAM) with index compression.
  1419.  
  1420.         * Relatively easy to add another storage engine. This is useful
  1421.           if you want to add an SQL interface to an in-house database.
  1422.  
  1423.         * A very fast thread-based memory allocation system.
  1424.  
  1425.         * Very fast joins using an optimised one-sweep multi-join.
  1426.  
  1427.         * In-memory hash tables which are used as temporary tables.
  1428.  
  1429.         * SQL functions are implemented through a highly optimised
  1430.           class library and should be as fast as possible.  Usually
  1431.           there isn't any memory allocation at all after query
  1432.           initialisation.
  1433.  
  1434.         * The `MySQL' code gets tested with Purify (a commercial memory
  1435.           leakage detector) as well as with Valgrind, a `GPL' tool
  1436.           (`http://developer.kde.org/~sewardj/').
  1437.  
  1438.         * Available as client/server or embedded (linked) version.
  1439.  
  1440. Column Types
  1441.         * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8
  1442.           bytes long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT',
  1443.           `BLOB', `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR',
  1444.           `SET', and `ENUM' types.  *Note Column types::.
  1445.  
  1446.         * Fixed-length and variable-length records.
  1447.  
  1448. Commands and Functions
  1449.         * Full operator and function support in the `SELECT' and `WHERE'
  1450.           clauses of queries.  For example:
  1451.  
  1452.                mysql> SELECT CONCAT(first_name, " ", last_name)
  1453.                    -> FROM tbl_name
  1454.                    -> WHERE income/dependents > 10000 AND age > 30;
  1455.  
  1456.         * Full support for SQL `GROUP BY' and `ORDER BY' clauses.
  1457.           Support for group functions (`COUNT()', `COUNT(DISTINCT ...)',
  1458.           `AVG()', `STD()', `SUM()', `MAX()', `MIN()', and
  1459.           `GROUP_CONCAT()').
  1460.  
  1461.         * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with
  1462.           both standard SQL and ODBC syntax.
  1463.  
  1464.         * Support for aliases on tables and columns as required by
  1465.           SQL-92.
  1466.  
  1467.         * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number
  1468.           of rows that were changed (affected).  It is possible to
  1469.           return the number of rows matched instead by setting a flag
  1470.           when connecting to the server.
  1471.  
  1472.         * The `MySQL'-specific `SHOW' command can be used to retrieve
  1473.           information about databases, tables, and indexes.  The
  1474.           `EXPLAIN' command can be used to determine how the optimiser
  1475.           resolves a query.
  1476.  
  1477.         * Function names do not clash with table or column names.  For
  1478.           example, `ABS' is a valid column name.  The only restriction
  1479.           is that for a function call, no spaces are allowed between
  1480.           the function name and the `(' that follows it.  *Note
  1481.           Reserved words::.
  1482.  
  1483.         * You can mix tables from different databases in the same query
  1484.           (as of Version 3.22).
  1485.  
  1486. Security
  1487.         * A privilege and password system that is very flexible and
  1488.           secure, and allows host-based verification.  Passwords are
  1489.           secure because all password traffic is encrypted when you
  1490.           connect to a server.
  1491.  
  1492. Scalability and Limits
  1493.         * Handles large databases.  We use `MySQL Server' with
  1494.           databases that contain 50 million records. We also know of
  1495.           users that use `MySQL Server' with 60,000 tables and about
  1496.           5,000,000,000 rows.
  1497.  
  1498.         * Up to 32 indexes per table are allowed.  Each index may
  1499.           consist of 1 to 16 columns or parts of columns.  The maximum
  1500.           index width is 500 bytes (this may be changed when compiling
  1501.           `MySQL Server').  An index may use a prefix of a `CHAR' or
  1502.           `VARCHAR' field.
  1503.  
  1504. Connectivity
  1505.         * Clients may connect to the `MySQL' server using TCP/IP
  1506.           Sockets, Unix Sockets (Unix), or Named Pipes (NT).
  1507.  
  1508.         * ODBC (Open-DataBase-Connectivity) support for Win32 (with
  1509.           source).  All ODBC 2.5 functions are supported, as are many
  1510.           others.  For example, you can use MS Access to connect to
  1511.           your `MySQL' server.  *Note ODBC::.
  1512.  
  1513. Localisation
  1514.         * The server can provide error messages to clients in many
  1515.           languages.  *Note Languages::.
  1516.  
  1517.         * Full support for several different character sets, including
  1518.           ISO-8859-1 (Latin1), german, big5, ujis, and more.  For
  1519.           example, the Scandinavian characters `a^', `a"' and `o"' are
  1520.           allowed in table and column names.
  1521.  
  1522.         * All data is saved in the chosen character set.  All
  1523.           comparisons for normal string columns are case-insensitive.
  1524.  
  1525.         * Sorting is done according to the chosen character set (the
  1526.           Swedish way by default).  It is possible to change this when
  1527.           the `MySQL' server is started.  To see an example of very
  1528.           advanced sorting, look at the Czech sorting code.  `MySQL
  1529.           Server' supports many different character sets that can be
  1530.           specified at compile and runtime.
  1531.  
  1532. Clients and Tools
  1533.         * Includes `myisamchk', a very fast utility for table checking,
  1534.           optimisation, and repair.  All of the functionality of
  1535.           `myisamchk' is also available through the SQL interface.
  1536.           *Note MySQL Database Administration::.
  1537.  
  1538.         * All `MySQL' programs can be invoked with the `--help' or `-?'
  1539.           options to obtain online assistance.
  1540.  
  1541. How Stable Is MySQL?
  1542. --------------------
  1543.  
  1544. This section addresses the questions "_How stable is MySQL Server?_"
  1545. and "_Can I depend on MySQL Server in this project?_" We will try to
  1546. clarify these issues and answer some important questions that concern
  1547. many potential users. The information in this section is based on data
  1548. gathered from the mailing list, which is very active in identifying
  1549. problems as well as reporting types of use.
  1550.  
  1551. Original code stems back from the early '80s, providing a stable code
  1552. base, and the ISAM table format remains backward-compatible.  At TcX,
  1553. the predecessor of `MySQL AB', `MySQL' code has worked in projects
  1554. since mid-1996, without any problems.  When the `MySQL Database
  1555. Software' was released to a wider public, our new users quickly found
  1556. some pieces of "untested code". Each new release since then has had
  1557. fewer portability problems (even though each new release has also had
  1558. many new features).
  1559.  
  1560. Each release of the `MySQL Server' has been usable. Problems have
  1561. occurred only when users try code from the "gray zones."  Naturally,
  1562. new users don't know what the gray zones are; this section therefore
  1563. attempts to document those areas that are currently known.  The
  1564. descriptions mostly deal with Version 3.23 and 4.0 of `MySQL Server'.
  1565. All known and reported bugs are fixed in the latest version, with the
  1566. exception of those listed in the bugs section, which are things that
  1567. are design-related.  *Note Bugs::.
  1568.  
  1569. The `MySQL Server' design is multi-layered with independent modules.
  1570. Some of the newer modules are listed here with an indication of how
  1571. well-tested each of them is:
  1572.  
  1573. *Replication - Gamma*
  1574.      Large server clusters using replication are in production use, with
  1575.      good results. Work on enhanced replication features is continuing
  1576.      in `MySQL' 4.x.
  1577.  
  1578. *`InnoDB' tables - Stable (in 3.23 from 3.23.49)*
  1579.      The `InnoDB' transactional storage engine has been declared stable
  1580.      in the `MySQL' 3.23 tree, starting from version 3.23.49.  `InnoDB'
  1581.      is being used in large, heavy-load production systems.
  1582.  
  1583. *`BDB' tables - Gamma*
  1584.      The `Berkeley DB' code is very stable, but we are still improving
  1585.      the `BDB' transactional storage engine interface in `MySQL
  1586.      Server', so it will take some time before this is as well tested
  1587.      as the other table types.
  1588.  
  1589. *`FULLTEXT' - Beta*
  1590.      Full-text search works but is not yet widely used.  Important
  1591.      enhancements have been implemented in `MySQL' 4.0.
  1592.  
  1593. *`MyODBC 3.51' (uses ODBC SDK 3.51) - Stable*
  1594.      In wide production use. Some issues brought up appear to be
  1595.      application-related and independent of the ODBC driver or
  1596.      underlying database server.
  1597.  
  1598. *Automatic recovery of `MyISAM' tables - Gamma*
  1599.      This status applies only to the new code in the `MyISAM' storage
  1600.      engine that checks if the table was closed properly on open and
  1601.      executes an automatic check/repair of the table if it wasn't.
  1602.  
  1603. *Bulk-insert - Alpha*
  1604.      New feature in `MyISAM' tables in `MySQL' 4.0 for faster insert of
  1605.      many rows.
  1606.  
  1607. *Locking - Gamma*
  1608.      This is very system-dependent.  On some systems there are big
  1609.      problems using standard OS locking (`fcntl()').  In these cases,
  1610.      you should run `mysqld' with the `--skip-external-locking' flag.
  1611.      Problems are known to occur on some Linux systems, and on SunOS
  1612.      when using NFS-mounted filesystems.
  1613.  
  1614. `MySQL AB' provides high-quality support for paying customers, and the
  1615. `MySQL' mailing list usually provides answers to common questions. Bugs
  1616. are usually fixed right away with a patch; for serious bugs, there is
  1617. almost always a new release.
  1618.  
  1619. How Big Can MySQL Tables Be?
  1620. ----------------------------
  1621.  
  1622. `MySQL' Version 3.22 had a 4 GB (4 gigabyte) limit on table size. With
  1623. the `MyISAM' table type in `MySQL' Version 3.23, the maximum table size
  1624. was pushed up to 8 million terabytes (2 ^ 63 bytes).
  1625.  
  1626. In effect, then, the table size for `MySQL' databases is normally
  1627. limited by the operating system.
  1628.  
  1629. Note, however, that operating systems have their own file-size limits.
  1630. Here are some examples:
  1631.  
  1632. *Operating System*     *File-Size Limit*
  1633. Linux-Intel 32 bit     2 GB, much more when using LFS
  1634. Linux-Alpha            8 TB (?)
  1635. Solaris 2.5.1          2 GB (possible 4GB with patch)
  1636. Solaris 2.6            4 GB (can be changed with flag)
  1637. Solaris 2.7 Intel      4 GB
  1638. Solaris 2.7            512 GB
  1639. UltraSPARC             
  1640.  
  1641. On Linux 2.2 you can get tables larger than 2 GB in size by using the
  1642. LFS patch for the ext2 filesystem. On Linux 2.4 patches also exist for
  1643. ReiserFS to get support for big files. Most current distributions are
  1644. based on kernel 2.4 and already include all the required Large File
  1645. Support (LFS) patches. However, the maximum available file size still
  1646. depends on several factors, one of them being the file system used to
  1647. store MySQL tables.
  1648.  
  1649. For a very detailed overview about LFS in Linux, have a look at Andreas
  1650. Jaeger's "Large File Support in Linux" page at
  1651. <http://www.suse.de/~aj/linux_lfs.html>.
  1652.  
  1653. By default, `MySQL' tables have a maximum size of about 4 GB.  You can
  1654. check the maximum table size for a table with the `SHOW TABLE STATUS'
  1655. command or with the `myisamchk -dv table_name'.  *Note SHOW::.
  1656.  
  1657. If you need a table that will be larger than 4 GB in size (and your
  1658. operating system supports it), set the `AVG_ROW_LENGTH' and `MAX_ROWS'
  1659. parameters accordingly when you create your table.  *Note CREATE
  1660. TABLE::.  You can also set these parameters later, with `ALTER TABLE'.
  1661. *Note ALTER TABLE::.
  1662.  
  1663. If your big table is a read-only table, you could use `myisampack' to
  1664. merge and compress many tables into one.  `myisampack' usually
  1665. compresses a table by at least 50%, so you can have, in effect, much
  1666. bigger tables.  *Note `myisampack': myisampack.
  1667.  
  1668. You can get around the operating system file limit for `MyISAM'
  1669. datafiles using the `RAID' option. *Note CREATE TABLE::.
  1670.  
  1671. Another solution can be the included `MERGE' library, which allows you
  1672. to handle a collection of identical tables as one.  *Note `MERGE'
  1673. tables: MERGE.
  1674.  
  1675. Year 2000 Compliance
  1676. --------------------
  1677.  
  1678. The `MySQL Server' itself has no problems with Year 2000 (Y2K)
  1679. compliance:
  1680.  
  1681.    * `MySQL Server' uses Unix time functions and has no problems with
  1682.      dates until `2069'. All 2-digit years are considered to be in the
  1683.      range `1970' to `2069', which means that if you store `01' in a
  1684.      `YEAR' column, `MySQL Server' treats it as `2001'.
  1685.  
  1686.    * All `MySQL' date functions are stored in one file, `sql/time.cc',
  1687.      and are coded very carefully to be year 2000-safe.
  1688.  
  1689.    * In `MySQL' Version 3.22 and later, the `YEAR' column type can
  1690.      store years `0' and `1901' to `2155' in one byte and display them
  1691.      using two or four digits.
  1692.  
  1693. You may run into problems with applications that use `MySQL Server' in
  1694. a way that is not Y2K-safe.  For example, many old applications store
  1695. or manipulate years using 2-digit values (which are ambiguous) rather
  1696. than 4-digit values.  This problem may be compounded by applications
  1697. that use values such as `00' or `99' as "missing" value indicators.
  1698.  
  1699. Unfortunately, these problems may be difficult to fix because different
  1700. applications may be written by different programmers, each of whom may
  1701. use a different set of conventions and date-handling functions.
  1702.  
  1703. Here is a simple demonstration illustrating that `MySQL Server' doesn't
  1704. have any problems with dates until the year 2030:
  1705.  
  1706.      mysql> DROP TABLE IF EXISTS y2k;
  1707.      Query OK, 0 rows affected (0.01 sec)
  1708.      
  1709.      mysql> CREATE TABLE y2k (date DATE,
  1710.          ->                   date_time DATETIME,
  1711.          ->                   time_stamp TIMESTAMP);
  1712.      Query OK, 0 rows affected (0.00 sec)
  1713.      
  1714.      mysql> INSERT INTO y2k VALUES
  1715.          -> ("1998-12-31","1998-12-31 23:59:59",19981231235959),
  1716.          -> ("1999-01-01","1999-01-01 00:00:00",19990101000000),
  1717.          -> ("1999-09-09","1999-09-09 23:59:59",19990909235959),
  1718.          -> ("2000-01-01","2000-01-01 00:00:00",20000101000000),
  1719.          -> ("2000-02-28","2000-02-28 00:00:00",20000228000000),
  1720.          -> ("2000-02-29","2000-02-29 00:00:00",20000229000000),
  1721.          -> ("2000-03-01","2000-03-01 00:00:00",20000301000000),
  1722.          -> ("2000-12-31","2000-12-31 23:59:59",20001231235959),
  1723.          -> ("2001-01-01","2001-01-01 00:00:00",20010101000000),
  1724.          -> ("2004-12-31","2004-12-31 23:59:59",20041231235959),
  1725.          -> ("2005-01-01","2005-01-01 00:00:00",20050101000000),
  1726.          -> ("2030-01-01","2030-01-01 00:00:00",20300101000000),
  1727.          -> ("2050-01-01","2050-01-01 00:00:00",20500101000000);
  1728.      Query OK, 13 rows affected (0.01 sec)
  1729.      Records: 13  Duplicates: 0  Warnings: 0
  1730.      
  1731.      mysql> SELECT * FROM y2k;
  1732.      +------------+---------------------+----------------+
  1733.      | date       | date_time           | time_stamp     |
  1734.      +------------+---------------------+----------------+
  1735.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1736.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1737.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1738.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1739.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1740.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1741.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1742.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1743.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1744.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1745.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  1746.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  1747.      | 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
  1748.      +------------+---------------------+----------------+
  1749.      13 rows in set (0.00 sec)
  1750.  
  1751. This example shows that the `DATE' and `DATETIME' datatypes will not
  1752. give any problems with future dates (they handle dates until the year
  1753. 9999).
  1754.  
  1755. The `TIMESTAMP' datatype, which is used to store the current time,
  1756. supports values that range from `19700101000000' to `20300101000000' on
  1757. 32-bit machines (signed value).  On 64-bit machines, `TIMESTAMP'
  1758. handles values up to `2106' (unsigned value).
  1759.  
  1760. Even though `MySQL Server' is Y2K-compliant, it is your responsibility
  1761. to provide unambiguous input.  See *Note Y2K issues:: for `MySQL
  1762. Server''s rules for dealing with ambiguous date input data (data
  1763. containing 2-digit year values).
  1764.  
  1765. What Is MySQL AB?
  1766. =================
  1767.  
  1768. `MySQL AB' is the company of the `MySQL' founders and main developers.
  1769. `MySQL AB' was originally established in Sweden by David Axmark, Allan
  1770. Larsson, and Michael `Monty' Widenius.
  1771.  
  1772. The developers of the `MySQL' server are all employed by the company.
  1773. We are a virtual organisation with people in a dozen countries around
  1774. the world. We communicate extensively over the Net every day with one
  1775. another and with our users, supporters, and partners.
  1776.  
  1777. We are dedicated to developing the `MySQL' software and spreading our
  1778. database to new users. `MySQL AB' owns the copyright to the `MySQL'
  1779. source code, the `MySQL' logo and trademark, and this manual. *Note
  1780. What-is::.
  1781.  
  1782. The `MySQL' core values show our dedication to `MySQL' and `Open
  1783. Source'.
  1784.  
  1785. We want the `MySQL Database Software' to be:
  1786.    * The best and the most widely used database in the world.
  1787.  
  1788.    * Available to, and affordable by all.
  1789.  
  1790.    * Easy to use.
  1791.  
  1792.    * Continuously improving while remaining fast and safe.
  1793.  
  1794.    * Fun to use and improve.
  1795.  
  1796.    * Free from bugs.
  1797.  
  1798. `MySQL AB' and the people at `MySQL AB':
  1799.    * Promote `Open Source' philosophy and support the `Open Source'
  1800.      community.
  1801.  
  1802.    * Aim to be good citizens.
  1803.  
  1804.    * Prefer partners that share our values and mind-set.
  1805.  
  1806.    * Answer e-mail and provide support.
  1807.  
  1808.    * Are a virtual company, networking with others.
  1809.  
  1810.    * Work against software patents.
  1811.  
  1812. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1813. information about `MySQL' and `MySQL AB'.
  1814.  
  1815. By the way, the "AB" part of the company name is the acronym for the
  1816. Swedish "aktiebolag", or "stock company."  It translates to "MySQL,
  1817. Inc." In fact, MySQL Inc. and MySQL GmbH are examples of MySQL AB
  1818. subsidiaries. They are located in the US and Germany, respectively.
  1819.  
  1820. The Business Model and Services of MySQL AB
  1821. -------------------------------------------
  1822.  
  1823. One of the most common questions we encounter is: "_How can you make a
  1824. living from something you give away for free?_" This is how.
  1825.  
  1826. `MySQL AB' makes money on support, services, commercial licenses, and
  1827. royalties. We use these revenues to fund product development and to
  1828. expand the `MySQL' business.
  1829.  
  1830. The company has been profitable since its inception. In October 2001,
  1831. we accepted venture financing from leading Scandinavian investors and a
  1832. handful of business angels. This investment is used to solidify our
  1833. business model and build a basis for sustainable growth.
  1834.  
  1835. Support
  1836. .......
  1837.  
  1838. `MySQL AB' is run and owned by the founders and main developers of the
  1839. `MySQL' database. The developers are committed to giving support to
  1840. customers and other users in order to stay in touch with their needs
  1841. and problems. All our support is given by qualified developers. Really
  1842. tricky questions are answered by Michael `Monty' Widenius, principal
  1843. author of the `MySQL Server'.  *Note Support::.
  1844.  
  1845. For more information and ordering support at various levels, see
  1846. `http://www.mysql.com/support/' or contact our sales staff at
  1847. <sales@mysql.com>.
  1848.  
  1849. Training and Certification
  1850. ..........................
  1851.  
  1852. `MySQL AB' delivers `MySQL' and related training worldwide.  We offer
  1853. both open courses and in-house courses tailored to the specific needs
  1854. of your company. `MySQL Training' is also available through our
  1855. partners, the `Authorised MySQL Training Centers'.
  1856.  
  1857. Our training material uses the same example databases used in our
  1858. documentation and our sample applications, and is always updated to
  1859. reflect the latest `MySQL' version. Our trainers are backed by the
  1860. development team to guarantee the quality of the training and the
  1861. continuous development of the course material. This also ensures that
  1862. no questions raised during the courses remain unanswered.
  1863.  
  1864. Attending our training courses will enable you to achieve your `MySQL'
  1865. application goals. You will also:
  1866.    * Save time.
  1867.  
  1868.    * Improve the performance of your application(s).
  1869.  
  1870.    * Reduce or eliminate the need for additional hardware, decreasing
  1871.      cost.
  1872.  
  1873.    * Enhance security.
  1874.  
  1875.    * Increase customers' and co-workers' satisfaction.
  1876.  
  1877.    * Prepare yourself for `MySQL Certification'.
  1878.  
  1879. If you are interested in our training as a potential participant or as
  1880. a training partner, please visit the training section at
  1881. `http://www.mysql.com/training/' or contact us at: <training@mysql.com>.
  1882.  
  1883. For details about the `MySQL Certification Program', please see
  1884. `http://www.mysql.com/certification/'.
  1885.  
  1886. Consulting
  1887. ..........
  1888.  
  1889. `MySQL AB' and its `Authorised Partners' offer consulting services to
  1890. users of `MySQL Server' and to those who embed `MySQL Server' in their
  1891. own software, all over the world.
  1892.  
  1893. Our consultants can help you design and tune your databases, construct
  1894. efficient queries, tune your platform for optimal performance, resolve
  1895. migration issues, set up replication, build robust transactional
  1896. applications, and more.  We also help customers embed `MySQL Server' in
  1897. their products and applications for large-scale deployment.
  1898.  
  1899. Our consultants work in close collaboration with our development team,
  1900. which ensures the technical quality of our professional services.
  1901. Consulting assignments range from 2-day power-start sessions to
  1902. projects that span weeks and months. Our expertise not only covers
  1903. `MySQL Server'--it also extends into programming and scripting
  1904. languages such as PHP, Perl, and more.
  1905.  
  1906. If you are interested in our consulting services or want to become a
  1907. consulting partner, please visit the consulting section of our web site
  1908. at `http://www.mysql.com/consulting/' or contact our consulting staff
  1909. at <consulting@mysql.com>.
  1910.  
  1911. Commercial Licenses
  1912. ...................
  1913.  
  1914. The `MySQL' database is released under the `GNU General Public License'
  1915. (`GPL').  This means that the `MySQL' software can be used free of
  1916. charge under the `GPL'. If you do not want to be bound by the `GPL'
  1917. terms (such as the requirement that your application must also be `GPL',
  1918. you may purchase a commercial license for the same product from `MySQL
  1919. AB'; see `http://www.mysql.com/products/pricing.html'.  Since `MySQL
  1920. AB' owns the copyright to the `MySQL' source code, we are able to
  1921. employ `Dual Licensing', which means that the same product is available
  1922. under `GPL' and under a commercial license. This does not in any way
  1923. affect the `Open Source' commitment of `MySQL AB'. For details about
  1924. when a commercial license is required, please see *Note MySQL
  1925. licenses::.
  1926.  
  1927. We also sell commercial licenses of third-party `Open Source GPL'
  1928. software that adds value to `MySQL Server'. A good example is the
  1929. `InnoDB' transactional storage engine that offers `ACID' support,
  1930. row-level locking, crash recovery, multi-versioning, foreign key
  1931. support, and more. *Note InnoDB::.
  1932.  
  1933. Partnering
  1934. ..........
  1935.  
  1936. `MySQL AB' has a worldwide partner programme that covers training
  1937. courses, consulting and support, publications, plus reselling and
  1938. distributing `MySQL' and related products. `MySQL AB Partners' get
  1939. visibility on the `http://www.mysql.com/' web site and the right to use
  1940. special versions of the `MySQL' trademarks to identify their products
  1941. and promote their business.
  1942.  
  1943. If you are interested in becoming a `MySQL AB Partner', please e-mail
  1944. <partner@mysql.com>.
  1945.  
  1946. The word `MySQL' and the `MySQL' dolphin logo are trademarks of `MySQL
  1947. AB'. *Note MySQL AB Logos and Trademarks::.  These trademarks represent
  1948. a significant value that the `MySQL' founders have built over the years.
  1949.  
  1950. Advertising
  1951. ...........
  1952.  
  1953. The `MySQL' web site (`http://www.mysql.com/') is popular among
  1954. developers and users. In October 2001, we served 10 million page views.
  1955. Our visitors represent a group that makes purchase decisions and
  1956. recommendations for both software and hardware. Twelve percent of our
  1957. visitors authorise purchase decisions, and only nine percent are not
  1958. involved in purchase decisions at all. More than 65% have made one or
  1959. more online business purchases within the last half-year, and 70% plan
  1960. to make one in the next few months.
  1961.  
  1962. Contact Information
  1963. -------------------
  1964.  
  1965. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1966. information about `MySQL' and `MySQL AB'.
  1967.  
  1968. For press services and inquiries not covered in our News releases
  1969. (`http://www.mysql.com/news/'), please send an e-mail to
  1970. <press@mysql.com>.
  1971.  
  1972. If you have a valid support contract with `MySQL AB', you will get
  1973. timely, precise answers to your technical questions about the `MySQL'
  1974. software. For more information, see *Note Support::.  On our web site,
  1975. see `http://www.mysql.com/support/', or send an e-mail to
  1976. <sales@mysql.com>.
  1977.  
  1978. For information about `MySQL' training, please visit the training
  1979. section at `http://www.mysql.com/training/'. If you have restricted
  1980. access to the Internet, please contact the `MySQL AB' training staff
  1981. via e-mail at <training@mysql.com>.  *Note Business Services Training::.
  1982.  
  1983. For information on the `MySQL Certification Program', please see
  1984. `http://www.mysql.com/certification/'.  *Note Business Services
  1985. Training::.
  1986.  
  1987. If you're interested in consulting, please visit the consulting section
  1988. of our web site at `http://www.mysql.com/consulting/'. If you have
  1989. restricted access to the Internet, please contact the `MySQL AB'
  1990. consulting staff via e-mail at <consulting@mysql.com>.  *Note Business
  1991. Services Consulting::.
  1992.  
  1993. Commercial licenses may be purchased online at
  1994. `https://order.mysql.com/'. There you will also find information on how
  1995. to fax your purchase order to `MySQL AB'. More information about
  1996. licensing can be found at `http://www.mysql.com/products/pricing.html'.
  1997. If you have questions regarding licensing or you want a quote for a
  1998. high-volume license deal, please fill in the contact form on our web
  1999. site (`http://www.mysql.com/') or send an e-mail message to
  2000. <licensing@mysql.com> (for licensing questions) or to <sales@mysql.com>
  2001. (for sales inquiries).  *Note MySQL licenses::.
  2002.  
  2003. If you represent a business that is interested in partnering with
  2004. `MySQL AB', please send an e-mail to <partner@mysql.com>.  *Note
  2005. Business Services Partnering::.
  2006.  
  2007. For more information on the `MySQL' trademark policy, refer to
  2008. `http://www.mysql.com/company/trademark.html' or send an e-mail to
  2009. <trademark@mysql.com>.  *Note MySQL AB Logos and Trademarks::.
  2010.  
  2011. If you are interested in any of the `MySQL AB' jobs listed in our jobs
  2012. section (`http://www.mysql.com/company/jobs/'), please send an e-mail
  2013. to <jobs@mysql.com>.  Please do not send your CV as an attachment, but
  2014. rather as plain text at the end of your e-mail message.
  2015.  
  2016. For general discussion among our many users, please direct your
  2017. attention to the appropriate mailing list.  *Note Questions::.
  2018.  
  2019. Reports of errors (often called bugs), as well as questions and
  2020. comments, should be sent to the general MySQL mailing list.  *Note
  2021. Mailing-list::.  If you have found a sensitive security bug in the
  2022. `MySQL Server', please send an e-mail to <security@mysql.com>.  *Note
  2023. Bug reports::.
  2024.  
  2025. If you have benchmark results that we can publish, please contact us
  2026. via e-mail at <benchmarks@mysql.com>.
  2027.  
  2028. If you have suggestions concerning additions or corrections to this
  2029. manual, please send them to the manual team via e-mail at
  2030. <docs@mysql.com>.
  2031.  
  2032. For questions or comments about the workings or content of the `MySQL'
  2033. web site (`http://www.mysql.com/'), please send an e-mail to
  2034. <webmaster@mysql.com>.
  2035.  
  2036. `MySQL AB' has a privacy policy, which can be read at
  2037. `http://www.mysql.com/company/privacy.html'.  For any queries regarding
  2038. this policy, please send an e-mail to <privacy@mysql.com>.
  2039.  
  2040. For all other inquires, please send an e-mail to <info@mysql.com>.
  2041.  
  2042. MySQL Support and Licensing
  2043. ===========================
  2044.  
  2045. This section describes `MySQL' support and licensing arrangements.
  2046.  
  2047. Support Offered by MySQL AB
  2048. ---------------------------
  2049.  
  2050. Technical support from `MySQL AB' means individualised answers to your
  2051. unique problems direct from the software engineers who code the `MySQL'
  2052. database engine.
  2053.  
  2054. We try to take a broad and inclusive view of technical support. Almost
  2055. any problem involving `MySQL' software is important to us if it's
  2056. important to you.  Typically customers seek help on how to get
  2057. different commands and utilities to work, remove performance
  2058. bottlenecks, restore crashed systems, understand operating system or
  2059. networking impacts on `MySQL', set up best practices for backup and
  2060. recovery, utilise APIs, and so on.  Our support covers only the `MySQL'
  2061. server and our own utilities, not third-party products that access the
  2062. `MySQL' server, though we try to help with these where we can.
  2063.  
  2064. Detailed information about our various support options is given at
  2065. `http://www.mysql.com/support/', where support contracts can also be
  2066. ordered online. If you have restricted access to the Internet, please
  2067. contact our sales staff via e-mail at <sales@mysql.com>.
  2068.  
  2069. Technical support is like life insurance. You can live happily without
  2070. it for years, but when your hour arrives it becomes critically
  2071. important, yet it's too late to buy it.  If you use `MySQL Server' for
  2072. important applications and encounter sudden difficulties, it may be too
  2073. time consuming to figure out all the answers yourself. You may need
  2074. immediate access to the most experienced `MySQL' troubleshooters
  2075. available, those employed by `MySQL AB'.
  2076.  
  2077. Copyrights and Licenses Used by MySQL
  2078. -------------------------------------
  2079.  
  2080. `MySQL AB' owns the copyright to the `MySQL' source code, the `MySQL'
  2081. logos and trademarks and this manual.  *Note What is MySQL AB::.
  2082. Several different licenses are relevant to the `MySQL' distribution:
  2083.  
  2084.   1. All the `MySQL'-specific source in the server, the `mysqlclient'
  2085.      library and the client, as well as the `GNU' `readline' library is
  2086.      covered by the `GNU General Public License'.  *Note GPL license::.
  2087.      The text of this license can be found as the file `COPYING' in the
  2088.      distribution.
  2089.  
  2090.   2. The `GNU' `getopt' library is covered by the `GNU Lesser General
  2091.      Public License'.  *Note LGPL license::.
  2092.  
  2093.   3. Some parts of the source (the `regexp' library) are covered by a
  2094.      Berkeley-style copyright.
  2095.  
  2096.   4. Older versions of `MySQL' (3.22 and earlier) are subject to a
  2097.      stricter license (`http://www.mysql.com/products/mypl.html').  See
  2098.      the documentation of the specific version for information.
  2099.  
  2100.   5. The `MySQL' reference manual is currently *not* distributed under
  2101.      a `GPL'-style license. Use of the manual is subject to the
  2102.      following terms:
  2103.         * Conversion to other formats is allowed, but the actual content
  2104.           may not be altered or edited in any way.
  2105.  
  2106.         * You may create a printed copy for your own personal use.
  2107.  
  2108.         * For all other uses, such as selling printed copies or using
  2109.           (parts of) the manual in another publication, prior written
  2110.           agreement from `MySQL AB' is required.
  2111.      Please send an e-mail to <docs@mysql.com> for more information or
  2112.      if you are interested in doing a translation.
  2113.  
  2114. For information about how the `MySQL' licenses work in practice, please
  2115. refer to *Note MySQL licenses::.  Also see *Note MySQL AB Logos and
  2116. Trademarks::.
  2117.  
  2118. MySQL Licenses
  2119. --------------
  2120.  
  2121. The `MySQL' software is released under the `GNU General Public License'
  2122. (`GPL'), which is probably the best known `Open Source' license.  The
  2123. formal terms of the `GPL' license can be found at
  2124. `http://www.gnu.org/licenses/'.  See also
  2125. `http://www.gnu.org/licenses/gpl-faq.html' and
  2126. `http://www.gnu.org/philosophy/enforcing-gpl.html'.
  2127.  
  2128. Since the `MySQL' software is released under the `GPL', it may often be
  2129. used for free, but for certain uses you may want or need to buy
  2130. commercial licenses from `MySQL AB' at `https://order.mysql.com/'.  See
  2131. `http://www.mysql.com/products/licensing.html' for more information.
  2132.  
  2133. Older versions of `MySQL' (3.22 and earlier) are subject to a stricter
  2134. license (`http://www.mysql.com/products/mypl.html').  See the
  2135. documentation of the specific version for information.
  2136.  
  2137. Please note that the use of the `MySQL' software under commercial
  2138. license, `GPL', or the old `MySQL' license does not automatically give
  2139. you the right to use `MySQL AB' trademarks.  *Note MySQL AB Logos and
  2140. Trademarks::.
  2141.  
  2142. Using the MySQL Software Under a Commercial License
  2143. ...................................................
  2144.  
  2145. The `GPL' license is contagious in the sense that when a program is
  2146. linked to a `GPL' program all the source code for all the parts of the
  2147. resulting product must also be released under the `GPL'.  If you do not
  2148. follow this `GPL' requirement, you break the license terms and forfeit
  2149. your right to use the `GPL' program altogether.  You also risk damages.
  2150.  
  2151. You need a commercial license:
  2152.  
  2153.    * When you link a program with any `GPL' code from the `MySQL'
  2154.      software and don't want the resulting product to be licensed under
  2155.      `GPL', perhaps because you want to build a commercial product or
  2156.      keep the added non-`GPL' code closed source for other reasons.
  2157.      When purchasing commercial licenses, you are not using the `MySQL'
  2158.      software under `GPL' even though it's the same code.
  2159.  
  2160.    * When you distribute a non-`GPL' application that *only* works with
  2161.      the `MySQL' software and ship it with the `MySQL' software. This
  2162.      type of solution is considered to be linking even if it's done
  2163.      over a network.
  2164.  
  2165.    * When you distribute copies of the `MySQL' software without
  2166.      providing the source code as required under the `GPL' license.
  2167.  
  2168.    * When you want to support the further development of the `MySQL'
  2169.      database even if you don't formally need a commercial license.
  2170.      Purchasing support directly from `MySQL AB' is another good way of
  2171.      contributing to the development of the `MySQL' software, with
  2172.      immediate advantages for you.  *Note Support::.
  2173.  
  2174. If you require a license, you will need one for each installation of the
  2175. `MySQL' software. This covers any number of CPUs on a machine, and there
  2176. is no artificial limit on the number of clients that connect to the
  2177. server in any way.
  2178.  
  2179. For commercial licenses, please visit our website at
  2180. `http://www.mysql.com/products/licensing.html'.  For support contracts,
  2181. see `http://www.mysql.com/support/'.  If you have special needs or you
  2182. have restricted access to the Internet, please contact our sales staff
  2183. via e-mail at <sales@mysql.com>.
  2184.  
  2185. Using the MySQL Software for Free Under GPL
  2186. ...........................................
  2187.  
  2188. You can use the `MySQL' software for free under the `GPL' if you adhere
  2189. to the conditions of the `GPL'.  For additional details, including
  2190. answers to common questions about the `GPL', see the generic FAQ from
  2191. the Free Software Foundation at
  2192. `http://www.gnu.org/licenses/gpl-faq.html'.  Common uses of the `GPL'
  2193. include:
  2194.  
  2195.    * When you distribute both your own application and the `MySQL'
  2196.      source code under the `GPL' with your product.
  2197.  
  2198.    * When you distribute the `MySQL' source code bundled with other
  2199.      programs that are not linked to or dependent on the `MySQL' system
  2200.      for their functionality even if you sell the distribution
  2201.      commercially.  This is called mere aggregation in the `GPL'
  2202.      license.
  2203.  
  2204.    * When you are not distributing *any* part of the `MySQL' system,
  2205.      you can use it for free.
  2206.  
  2207.    * When you are an Internet Service Provider (ISP), offering web
  2208.      hosting with `MySQL' servers for your customers.  We encourage
  2209.      people to use ISPs that have MySQL support, as this will give them
  2210.      the confidence that their ISP will, in fact, have the resources to
  2211.      solve any problems they may experience with the `MySQL'
  2212.      installation. Even if an ISP does not have a commercial license
  2213.      for `MySQL Server', their customers should at least be given read
  2214.      access to the source of the `MySQL' installation so that the
  2215.      customers can verify that it is correctly patched.
  2216.  
  2217.    * When you use the `MySQL' database software in conjunction with a
  2218.      web server, you do not need a commercial license (so long as it is
  2219.      not a product you distribute). This is true even if you run a
  2220.      commercial web server that uses `MySQL Server', because you are not
  2221.      distributing any part of the `MySQL' system. However, in this case
  2222.      we would like you to purchase `MySQL' support because the `MySQL'
  2223.      software is helping your enterprise.
  2224.  
  2225. If your use of `MySQL' database software does not require a commercial
  2226. license, we encourage you to purchase support from `MySQL AB' anyway.
  2227. This way you contribute toward `MySQL' development and also gain
  2228. immediate advantages for yourself. *Note Support::.
  2229.  
  2230. If you use the `MySQL' database software in a commercial context such
  2231. that you profit by its use, we ask that you further the development of
  2232. the `MySQL' software by purchasing some level of support.  We feel that
  2233. if the `MySQL' database helps your business, it is reasonable to ask
  2234. that you help `MySQL AB'.  (Otherwise, if you ask us support questions,
  2235. you are not only using for free something into which we've put a lot a
  2236. work, you're asking us to provide free support, too.)
  2237.  
  2238. MySQL AB Logos and Trademarks
  2239. -----------------------------
  2240.  
  2241. Many users of the `MySQL' database want to display the `MySQL AB'
  2242. dolphin logo on their web sites, books, or boxed products. We welcome
  2243. and encourage this, although it should be noted that the word `MySQL'
  2244. and the `MySQL' dolphin logo are trademarks of `MySQL AB' and may only
  2245. be used as stated in our trademark policy at
  2246. `http://www.mysql.com/company/trademark.html'.
  2247.  
  2248. The Original MySQL Logo
  2249. .......................
  2250.  
  2251. The `MySQL' dolphin logo was designed by the Finnish advertising agency
  2252. Priority in 2001.  The dolphin was chosen as a suitable symbol for the
  2253. `MySQL' database since it is a smart, fast, and lean animal,
  2254. effortlessly navigating oceans of data. We also happen to like dolphins.
  2255.  
  2256. The original `MySQL' logo may only be used by representatives of `MySQL
  2257. AB' and by those having a written agreement allowing them to do so.
  2258.  
  2259. MySQL Logos that may be Used Without Written Permission
  2260. .......................................................
  2261.  
  2262. We have designed a set of special _Conditional Use_ logos that may be
  2263. downloaded from our web site at `http://www.mysql.com/press/logos.html'
  2264. and used on third-party web sites without written permission from
  2265. `MySQL AB'.  The use of these logos is not entirely unrestricted but,
  2266. as the name implies, subject to our trademark policy that is also
  2267. available on our web site. You should read through the trademark policy
  2268. if you plan to use them. The requirements are basically as follows:
  2269.  
  2270.    * Use the logo you need as displayed on the `http://www.mysql.com/'
  2271.      site. You may scale it to fit your needs, but may not change
  2272.      colours or design, or alter the graphics in any way.
  2273.  
  2274.    * Make it evident that you, and not `MySQL AB', are the creator and
  2275.      owner of the site that displays the `MySQL' trademark.
  2276.  
  2277.    * Don't use the trademark in a way that is detrimental to `MySQL AB'
  2278.      or to the value of `MySQL AB' trademarks. We reserve the right to
  2279.      revoke the right to use the `MySQL AB' trademark.
  2280.  
  2281.    * If you use the trademark on a web site, make it clickable, leading
  2282.      directly to `http://www.mysql.com/'.
  2283.  
  2284.    * If you are use the `MySQL' database under `GPL' in an application,
  2285.      your application must be `Open Source' and must be able to connect
  2286.      to a `MySQL' server.
  2287.  
  2288. Contact us via e-mail at <trademark@mysql.com> to inquire about special
  2289. arrangements to fit your needs.
  2290.  
  2291. When do you need a Written Permission to use MySQL Logos?
  2292. .........................................................
  2293.  
  2294. You need written permission from `MySQL AB' before using `MySQL' logos
  2295. in the following cases:
  2296.  
  2297.    * When displaying any `MySQL AB' logo anywhere except on your web
  2298.      site.
  2299.  
  2300.    * When displaying any `MySQL AB' logo except the _Conditional Use_
  2301.      logos mentioned previously on web sites or elsewhere.
  2302.  
  2303. Due to legal and commercial reasons we monitor the use of MySQL
  2304. trademarks on products, books, and other items. We usually require a
  2305. fee for displaying `MySQL AB' logos on commercial products, since we
  2306. think it is reasonable that some of the revenue is returned to fund
  2307. further development of the `MySQL' database.
  2308.  
  2309. MySQL AB Partnership Logos
  2310. ..........................
  2311.  
  2312. `MySQL' partnership logos may be used only by companies and persons
  2313. having a written partnership agreement with `MySQL AB'. Partnerships
  2314. include certification as a `MySQL' trainer or consultant.  For more
  2315. information, please see *Note Partnering: Business Services Partnering.
  2316.  
  2317. Using the word `MySQL' in Printed Text or Presentations
  2318. .......................................................
  2319.  
  2320. `MySQL AB' welcomes references to the `MySQL' database, but it should
  2321. be noted that the word `MySQL' is a trademark of `MySQL AB'.  Because
  2322. of this, you must append the trademark symbol (`TM') to the first or
  2323. most prominent use of the word `MySQL' in a text and, where
  2324. appropriate, state that `MySQL' is a trademark of `MySQL AB'. For more
  2325. information, please refer to our trademark policy at
  2326. `http://www.mysql.com/company/trademark.html'.
  2327.  
  2328. Using the word `MySQL' in Company and Product Names
  2329. ...................................................
  2330.  
  2331. Use of the word `MySQL' in product or company names or in Internet
  2332. domain names is not allowed without written permission from `MySQL AB'.
  2333.  
  2334. MySQL Development Roadmap
  2335. =========================
  2336.  
  2337. This section provides a snapshot of the MySQL development roadmap,
  2338. including major features implemented or planned for MySQL 4.0, 4.1, and
  2339. 5.0.  The following sections provide information for each release.
  2340. Plans for some of the most requested features are summarized in the
  2341. following table.
  2342.  
  2343. *Feature*              *MySQL version*
  2344. Unions                 4.0
  2345. Subqueries             4.1
  2346. R-trees                4.1 (for MyISAM
  2347.                        tables)
  2348. Stored procedures      5.0
  2349. Cursors                5.0
  2350. Foreign keys           5.1 (3.23 with InnoDB)
  2351. Views                  5.1
  2352. Triggers               5.1
  2353. Full outer join        5.1
  2354. Constraints            5.1
  2355.  
  2356. MySQL 4.0 in a Nutshell
  2357. -----------------------
  2358.  
  2359. Long promised by `MySQL AB' and long awaited by our users, MySQL Server
  2360. 4.0 is now available in production version.
  2361.  
  2362. MySQL 4.0 is available for download from `http://www.mysql.com/' and
  2363. from our mirrors. MySQL 4.0 has been tested by a large number of users
  2364. and is in production use at many large sites.
  2365.  
  2366. The major new features of MySQL Server 4.0 are geared toward our
  2367. existing business and community users, enhancing the MySQL database
  2368. software as the solution for mission-critical, heavy-load database
  2369. systems.  Other new features target the users of embedded databases.
  2370.  
  2371. MySQL Version 4.0.12 was declared stable for production use in March
  2372. 2003. This means that, in future, only bug fixes will be done for the
  2373. 4.0 release series and only critical bug fixes will be done for the
  2374. older 3.23 series.  *Note Upgrading-from-3.23::.
  2375.  
  2376. New features to the `MySQL' software are being added to MySQL 4.1 which
  2377. is now also available (alpha version).  *Note MySQL 4.1 Nutshell::.
  2378.  
  2379. Features Available in MySQL 4.0
  2380. ...............................
  2381.  
  2382. Speed enhancements
  2383.         * MySQL 4.0 has a query cache that can give a huge speed boost
  2384.           to applications with repetitive queries. *Note Query Cache::.
  2385.  
  2386.         * Version 4.0 further increases the speed of MySQL Server in a
  2387.           number of areas, such as bulk `INSERT's, searching on packed
  2388.           indexes, creation of `FULLTEXT' indexes, and
  2389.           `COUNT(DISTINCT)'.
  2390.  
  2391. Embedded MySQL Server introduced
  2392.         * The new Embedded Server library (instead of client/server)
  2393.           can easily be used in standalone and embedded applications.
  2394.           *Note Nutshell Embedded MySQL::.
  2395.  
  2396. InnoDB storage engine as standard
  2397.         * The `InnoDB' storage engine is now offered as a standard
  2398.           feature of the `MySQL' server. This means full support for
  2399.           ACID _transactions_, _foreign keys_ with cascading
  2400.           UPDATE/DELETE, and _row-level locking_ are now standard
  2401.           features.  *Note InnoDB::.
  2402.  
  2403. New functionality
  2404.         * The enhanced `FULLTEXT' search properties of MySQL Server 4.0
  2405.           enables `FULLTEXT' indexing of large text masses with both
  2406.           binary and natural-language searching logic. You can
  2407.           customise minimal word length and define your own stop word
  2408.           lists in any human language, enabling a new set of
  2409.           applications to be built on MySQL Server.  *Note Fulltext
  2410.           Search::.
  2411.  
  2412. Standards compliance, portability, and migration
  2413.         * Features to simplify migration from other database systems to
  2414.           MySQL Server include `TRUNCATE TABLE' (as in Oracle).
  2415.  
  2416.         * Many users will also be happy to learn that MySQL Server now
  2417.           supports the `UNION' statement, a long-awaited standard SQL
  2418.           feature.
  2419.  
  2420.         * MySQL can now run natively on the Novell NetWare 6.0 platform.
  2421.           *Note Novell NetWare::.
  2422.  
  2423. Internationalisation
  2424.         * Our German, Austrian, and Swiss users will note that `MySQL'
  2425.           now supports a new character set, `latin1_de', which ensures
  2426.           that the _German sorting order_ sorts words with umlauts in
  2427.           the same order as do German telephone books.
  2428.  
  2429. Usability enhancements
  2430.      In the process of building features for new users, we have not
  2431.      forgotten requests from our community of loyal users.
  2432.  
  2433.         * Most `mysqld' parameters (startup options) can now be set
  2434.           without taking down the servers. This is a convenient feature
  2435.           for Database Administrators (DBAs).  *Note SET OPTION::.
  2436.  
  2437.         * Multi-table `DELETE' and `UPDATE' statements have been added..
  2438.  
  2439.         * Support has been added for `symbolic linking' to `MyISAM' at
  2440.           the table level (and not just the database level as before)
  2441.           and for enabling symlink handling by default on Windows.
  2442.  
  2443.         * `SQL_CALC_FOUND_ROWS' and `FOUND_ROWS()' are new functions
  2444.           that make it possible to find out the number of rows a
  2445.           `SELECT' query that includes a `LIMIT' clause would have
  2446.           returned without that clause.
  2447.  
  2448. The news section of this manual includes a more in-depth list of
  2449. features.  *Note News-4.0.x::.
  2450.  
  2451. Embedded MySQL Server
  2452. .....................
  2453.  
  2454. `libmysqld' makes MySQL Server suitable for a vastly expanded realm of
  2455. applications. Using the embedded MySQL server library, one can embed
  2456. MySQL Server into various applications and electronics devices, where
  2457. the end user has no knowledge of there actually being an underlying
  2458. database. Embedded MySQL Server is ideal for use behind the scenes in
  2459. Internet appliances, public kiosks, turnkey hardware/software
  2460. combination units, high performance Internet servers, self-contained
  2461. databases distributed on CD-ROM, and so on.
  2462.  
  2463. Many users of `libmysqld' will benefit from the MySQL _Dual Licensing_.
  2464. For those not wishing to be bound by the `GPL', the software is also
  2465. made available under a commercial license.  The embedded MySQL library
  2466. uses the same interface as the normal client library, so it is
  2467. convenient and easy to use. *Note libmysqld::.
  2468.  
  2469. MySQL 4.1 in a Nutshell
  2470. -----------------------
  2471.  
  2472. MySQL Server 4.0 laid the foundation for new features such as _nested
  2473. subqueries_ and _Unicode_ (implemented in version 4.1) and for the work
  2474. on SQL-99 _stored procedures_ being done for version 5.0. These
  2475. features come at the top of the wish list of many of our customers.
  2476.  
  2477. With these additions, critics of the MySQL Database Server have to be
  2478. more imaginative than ever in pointing out deficiencies in the MySQL
  2479. Database Management System. Already well-known for its stability,
  2480. speed, and ease of use, MySQL Server will be able to fulfill the
  2481. requirement checklists of very demanding buyers.
  2482.  
  2483. Features Available in MySQL 4.1
  2484. ...............................
  2485.  
  2486. The features listed in this section are implemented in MySQL 4.1. A few
  2487. other features are still planned for MySQL 4.1. *Note TODO MySQL 4.1::.
  2488.  
  2489. Most new features being coded, such as _stored procedures_, will be
  2490. available in MySQL 5.0. *Note TODO MySQL 5.0::.
  2491.  
  2492. Support for subqueries and derived tables
  2493.         * Subqueries are now supported. Here is an example:
  2494.                SELECT * FROM t1 WHERE t1.a=(SELECT t2.b FROM t2);
  2495.                
  2496.                SELECT * FROM t1 WHERE (1,2,3) IN (SELECT a,b,c FROM t2);
  2497.  
  2498.         * Derived tables (unnamed views) are now supported. Basically,
  2499.           a derived table is a subquery in the `FROM' clause of a
  2500.           `SELECT' statement. Here is an example:
  2501.                SELECT t1.a FROM t1, (SELECT * FROM t2) t3 WHERE t1.a=t3.a;
  2502.  
  2503. Speed enhancements
  2504.         * Faster binary protocol with prepared statements and parameter
  2505.           binding.  *Note C API Prepared statements::.
  2506.  
  2507.         * `BTREE' indexing is now supported for `HEAP' tables,
  2508.           significantly improving response time for non-exact searches.
  2509.  
  2510. New functionality
  2511.         * `CREATE TABLE table LIKE table' allows you to create a new
  2512.           table with the exact structure of an existing table, using a
  2513.           single command.
  2514.  
  2515.         * Support for OpenGIS spatial types (geographical data).  *Note
  2516.           Spatial extensions in MySQL::.
  2517.  
  2518. Standards compliance, portability, and migration
  2519.         * The new client/server protocol adds the ability to pass
  2520.           multiple warnings to the client, rather than only a single
  2521.           result. This makes jobs such as bulk loading of data much
  2522.           easier to track.  `SHOW WARNINGS' shows warnings for the last
  2523.           command.  *Note SHOW WARNINGS::.
  2524.  
  2525. Internationalisation
  2526.         * To support our ever expanding user base using local languages
  2527.           in applications, the MySQL software now offers extensive
  2528.           Unicode (UTF8) support.
  2529.  
  2530.         * Character sets can now be defined per column, table, and
  2531.           database.  This allows for a high degree of flexibility in
  2532.           application design, particularly for multi-language web sites.
  2533.  
  2534.         * The documentation for this improved character set support is
  2535.           being developed and will be added to the manual soon.
  2536.  
  2537. Usability enhancements
  2538.         * In response to popular demand, we have added a server-based
  2539.           `HELP command' that can be used in the `mysql' command line
  2540.           client (and other clients) to get help for SQL commands.  The
  2541.           advantage of having this information on the server side is
  2542.           that the information is always applicable for that particular
  2543.           server version.
  2544.  
  2545.         * In the new client/server protocol, multi-line queries can now
  2546.           be enabled.  This allows you to issue several queries in a
  2547.           single call and then read all the results in one go.  *Note C
  2548.           API multiple queries::.
  2549.  
  2550.         * A new `INSERT ... ON DUPLICATE KEY UPDATE ...' syntax has been
  2551.           implemented. This allows you to `UPDATE' an existing row if
  2552.           the `INSERT' would have caused a duplicate in a `PRIMARY' or
  2553.           `UNIQUE' key (index).  *Note INSERT::.
  2554.  
  2555.         * We have designed a new aggregate function `GROUP_CONCAT()',
  2556.           adding the extremely useful capability of concatenating
  2557.           columns from grouped rows into a single result string.  *Note
  2558.           Group by functions::.
  2559.  
  2560.         * The new client/server protocol supports multiple result sets.
  2561.  
  2562. The news section in this manual includes a more in-depth list of
  2563. features.  *Note News-4.1.x::.
  2564.  
  2565. Stepwise Rollout
  2566. ................
  2567.  
  2568. New features are being added to MySQL 4.1, which is already available
  2569. for download (alpha version). *Note Nutshell Ready for Immediate Use::.
  2570.  
  2571. The set of features that are being added to version 4.1 is mostly
  2572. fixed. Additional development is already ongoing for version 5.0.
  2573. MySQL 4.1 will go through the steps of _Alpha_ (during which time new
  2574. features might still be added/changed), _Beta_ (when we have feature
  2575. freeze and only bug corrections will be done), and _Gamma_ (indicating
  2576. that a production release is just weeks ahead).  At the end of this
  2577. process, MySQL 4.1 will become the new production release.
  2578.  
  2579. Ready for Immediate Development Use
  2580. ...................................
  2581.  
  2582. MySQL 4.1 is currently in the alpha stage, and binaries are available
  2583. for download at `http://www.mysql.com/downloads/mysql-4.1.html'.  All
  2584. binary releases pass our extensive test suite without any errors on the
  2585. platforms on which we test.  *Note News-4.1.x::.
  2586.  
  2587. For those wishing to use the most recent development source for MySQL
  2588. 4.1, we have made our 4.1 BitKeeper repository publicly available.
  2589. *Note Installing source tree::.
  2590.  
  2591. MySQL 5.0, The Next Development Release
  2592. ---------------------------------------
  2593.  
  2594. New development for MySQL is focused on the 5.0 release, featuring
  2595. Stored Procedures and other new features.  *Note TODO MySQL 5.0::.
  2596.  
  2597. For those wishing to take a look at the bleeding edge of MySQL
  2598. development, we have made our BitKeeper repository for MySQL version
  2599. 5.0 publicly available.  *Note Installing source tree::.
  2600.  
  2601. MySQL Information Sources
  2602. =========================
  2603.  
  2604. MySQL Mailing Lists
  2605. -------------------
  2606.  
  2607. This section introduces you to the MySQL mailing lists and gives some
  2608. guidelines as to how the lists should be used. When you subscribe to a
  2609. mailing list, you will receive, as e-mail messages, all postings to the
  2610. list. You will also be able to send your own questions and answers to
  2611. the list.
  2612.  
  2613. The MySQL Mailing Lists
  2614. .......................
  2615.  
  2616. To subscribe to or unsubscribe from any of the mailing lists described
  2617. in this section, visit `http://lists.mysql.com/'.  Please *do not* send
  2618. messages about subscribing or unsubscribing to any of the mailing
  2619. lists, because such messages are distributed automatically to thousands
  2620. of other users.
  2621.  
  2622. Your local site may have many subscribers to a MySQL mailing list.  If
  2623. so, the site may have a local mailing list, so that messages sent from
  2624. `lists.mysql.com' to your site are propagated to the local list.  In
  2625. such cases, please contact your system administrator to be added to or
  2626. dropped from the local MySQL list.
  2627.  
  2628. If you wish to have traffic for a mailing list go to a separate mailbox
  2629. in your mail program, set up a filter based on the message headers.
  2630. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  2631. list messages.
  2632.  
  2633. The MySQL mailing lists are as follows:
  2634.  
  2635. ``announce''
  2636.      This list is for announcements of new versions of MySQL and related
  2637.      programs.  This is a low-volume list to which all MySQL users
  2638.      should subscribe.
  2639.  
  2640. ``mysql''
  2641.      This is the main list for general MySQL discussion.  Please note
  2642.      that some topics are better discussed on the more-specialised
  2643.      lists.  If you post to the wrong list, you may not get an answer.
  2644.  
  2645. ``mysql-digest''
  2646.      This is the `mysql' list in digest form.  Subscribing to this list
  2647.      means you will get all list messages, sent as one large mail
  2648.      message once a day.
  2649.  
  2650. ``bugs''
  2651.      This list will be of interest to you if you want to stay informed
  2652.      about issues reported since the last release of `MySQL' or if you
  2653.      want to be actively involved in the process of bug hunting and
  2654.      fixing.  *Note Bug reports::.
  2655.  
  2656. ``bugs-digest''
  2657.      This is the `bugs' list in digest form.
  2658.  
  2659. ``internals''
  2660.      This list is for people who work on the MySQL code.  This is also
  2661.      the forum for discussions on MySQL development and post patches.
  2662.  
  2663. ``internals-digest''
  2664.      This is the `internals' list in digest form.
  2665.  
  2666. ``mysqldoc''
  2667.      This list is for people who work on the MySQL documentation:
  2668.      people from MySQL AB, translators, and other community members.
  2669.  
  2670. ``mysqldoc-digest''
  2671.      This is the `mysqldoc' list in digest form.
  2672.  
  2673. ``benchmarks''
  2674.      This list is for anyone interested in performance issues.
  2675.      Discussions concentrate on database performance (not limited to
  2676.      MySQL) but also include broader categories such as performance of
  2677.      the kernel, file system, disk system, and so on.
  2678.  
  2679. ``benchmarks-digest''
  2680.      This is the `benchmarks' list in digest form.
  2681.  
  2682. ``packagers''
  2683.      This list is for discussions on packaging and distributing MySQL.
  2684.      This is the forum used by distribution maintainers to exchange
  2685.      ideas on packaging MySQL and on ensuring that MySQL looks and
  2686.      feels as similar as possible on all supported platforms and
  2687.      operating systems.
  2688.  
  2689. ``packagers-digest''
  2690.      This is the `packagers' list in digest form.
  2691.  
  2692. ``java''
  2693.      This list is for discussions about the MySQL server and Java.It is
  2694.      mostly used to discuss JDBC drivers, including MySQL Connector/J.
  2695.  
  2696. ``java-digest''
  2697.      This is the `java' list in digest form.
  2698.  
  2699. ``win32''
  2700.      This list is for all things concerning the MySQL software on
  2701.      Microsoft operating systems, such as Windows 9x/Me/NT/2000/XP.
  2702.  
  2703. ``win32-digest''
  2704.      This is the `win32' list in digest form.
  2705.  
  2706. ``myodbc''
  2707.      This list is for all things concerning connecting to the MySQL
  2708.      server with ODBC.
  2709.  
  2710. ``myodbc-digest''
  2711.      This is the `myodbc' list in digest form.
  2712.  
  2713. ``mysqlcc''
  2714.      This list is for all things concerning the `MySQL Control Center'
  2715.      graphical client.
  2716.  
  2717. ``mysqlcc-digest''
  2718.      This is the `mysqlcc' list in digest form.
  2719.  
  2720. ``plusplus''
  2721.      This list is for all things concerning programming with the C++
  2722.      API to MySQL.
  2723.  
  2724. ``plusplus-digest''
  2725.      This is the `plusplus' list in digest form.
  2726.  
  2727. ``msql-mysql-modules''
  2728.      This list is for all things concerning the Perl support for MySQL
  2729.      with `msql-mysql-modules', which is now named `DBD-mysql'.
  2730.  
  2731. ``msql-mysql-modules-digest''
  2732.      This is the `msql-mysql-modules' list in digest form.
  2733.  
  2734. If you're unable to get an answer to your question(s) from a `MySQL'
  2735. mailing list, one option is to pay for support from MySQL AB. This will
  2736. put you in direct contact with MySQL developers. *Note Support::.
  2737.  
  2738. The following table shows some MySQL mailing lists in languages other
  2739. than English.  These lists are not operated by MySQL AB, so we can't
  2740. guarantee their quality.
  2741.  
  2742. `<mysql-france-subscribe@yahoogroups.com> A French mailing list'
  2743.  
  2744. `<list@tinc.net> A Korean mailing list'
  2745.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2746.  
  2747. `<mysql-de-request@lists.4t2.com> A German mailing list'
  2748.      E-mail `subscribe mysql-de your@e-mail.address' to this list.  You
  2749.      can find information about this mailing list at
  2750.      `http://www.4t2.com/mysql/'.
  2751.  
  2752. `<mysql-br-request@listas.linkway.com.br> A Portuguese mailing list'
  2753.      E-mail `subscribe mysql-br your@e-mail.address' to this list.
  2754.  
  2755. `<mysql-alta@elistas.net> A Spanish mailing list'
  2756.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2757.  
  2758. Asking Questions or Reporting Bugs
  2759. ..................................
  2760.  
  2761. Before posting a bug report or question, please do the following:
  2762.  
  2763.    * Start by searching the MySQL online manual at:
  2764.      `http://www.mysql.com/doc/'
  2765.      We try to keep the manual up to date by updating it frequently with
  2766.      solutions to newly found problems. The change history appendix
  2767.      (`http://www.mysql.com/doc/en/News.html') can be particularly
  2768.      useful since it is quite possible that a newer version already
  2769.      contains a solution to your problem.
  2770.  
  2771.    * Search in the bugs database at `http://bugs.mysql.com/' to see
  2772.      whether the bug has already been reported/solved.
  2773.  
  2774.    * Search the MySQL mailing list archives:
  2775.      `http://lists.mysql.com/'
  2776.    * You can also use `http://www.mysql.com/search/' to search all the
  2777.      web pages (including the manual) that are located at
  2778.      `http://www.mysql.com/'.
  2779.  
  2780. If you can't find an answer in the manual or the archives, check with
  2781. your local MySQL expert.  If you still can't find an answer to your
  2782. question, please follow the guidelines on sending mail to a MySQL
  2783. mailing list, outlined in the next section, before contacting us.
  2784.  
  2785. How to Report Bugs or Problems
  2786. ..............................
  2787.  
  2788. Our bugs database is public, and can be browsed and searched by anyone
  2789. at `http://bugs.mysql.com/'.  If you log into the system, you will also
  2790. be able to enter new reports.
  2791.  
  2792. Writing a good bug report takes patience, but doing it right the first
  2793. time saves time both for us and for yourself.  A good bug report,
  2794. containing a full test case for the bug, makes it very likely that we
  2795. will fix the bug in the next release.  This section will help you write
  2796. your report correctly so that you don't waste your time doing things
  2797. that may not help us much or at all.
  2798.  
  2799. We encourage everyone to use the `mysqlbug' script to generate a bug
  2800. report (or a report about any problem).  `mysqlbug' can be found in the
  2801. `scripts' directory (source distribution) and in the `bin' directory
  2802. under your MySQL installation directory (binary distribution).  If you
  2803. are unable to use `mysqlbug' (for instance, if you are running on
  2804. Windows), it is still vital that you include all the necessary
  2805. information noted in this section (most importantly a description of
  2806. the operating system and the MySQL version).
  2807.  
  2808. The `mysqlbug' script helps you generate a report by determining much
  2809. of the following information automatically, but if something important
  2810. is missing, please include it with your message.  Please read this
  2811. section carefully and make sure that all the information described here
  2812. is included in your report.
  2813.  
  2814. Preferably, you should test the problem using the latest production or
  2815. development version of MySQL Server before posting.  Anyone should be
  2816. able to repeat the bug by just using '`mysql test < script'' on the
  2817. included test case or run the shell or Perl script that is included in
  2818. the bug report.
  2819.  
  2820. All bugs posted in the bugs database at `http://bugs.mysql.com/' will
  2821. be corrected or documented in the next MySQL release. If only minor
  2822. code changes are needed to correct a problem, we will also post a patch
  2823. that fixes the problem.
  2824.  
  2825. The normal place to report bugs is `http://bugs.mysql.com/'.
  2826.  
  2827. If you have found a sensitive security bug in MySQL, please send an
  2828. e-mail to <security@mysql.com>.
  2829.  
  2830. If you have a repeatable bug report, please report this into the bugs
  2831. database at `http://bugs.mysql.com/'.  Note that even in this case it's
  2832. good to run the `mysqlbug' script first to find information about your
  2833. system.  Any bug that we are able to repeat has a high chance of being
  2834. fixed in the next MySQL release.
  2835.  
  2836. To report other problems, you can use one of the MySQL mailing lists.
  2837.  
  2838. Remember that it is possible for us to respond to a message containing
  2839. too much information, but not to one containing too little.  People
  2840. often omit facts because they think they know the cause of a problem
  2841. and assume that some details don't matter.  A good principle is: if you
  2842. are in doubt about stating something, state it.  It is a thousand times
  2843. faster and less troublesome to write a couple of lines more in your
  2844. report than to be forced to ask again and wait for the answer because
  2845. you didn't include enough information the first time.
  2846.  
  2847. The most common errors made in bug reports are (a) not including the
  2848. version number of the MySQL distribution used and (b) not fully
  2849. describing the platform on which the MySQL server is installed
  2850. (including the platform type and version number).  This is highly
  2851. relevant information, and in 99 cases out of 100 the bug report is
  2852. useless without it.  Very often we get questions like, "Why doesn't
  2853. this work for me?" Then we find that the feature requested wasn't
  2854. implemented in that MySQL version, or that a bug described in a report
  2855. has already been fixed in newer MySQL versions.  Sometimes the error is
  2856. platform-dependent; in such cases, it is next to impossible for us to
  2857. fix anything without knowing the operating system and the version
  2858. number of the platform.
  2859.  
  2860. Remember also to provide information about your compiler, if it is
  2861. related to the problem.  Often people find bugs in compilers and think
  2862. the problem is MySQL-related.  Most compilers are under development all
  2863. the time and become better version by version.  To determine whether
  2864. your problem depends on your compiler, we need to know what compiler
  2865. you use.  Note that every compiling problem should be regarded as a bug
  2866. and reported accordingly.
  2867.  
  2868. It is most helpful when a good description of the problem is included
  2869. in the bug report.  That is, give a good example of all the things you
  2870. did that led to the problem and describe, in exact detail, the problem
  2871. itself.  The best reports are those that include a full example showing
  2872. how to reproduce the bug or problem.  *Note Reproduceable test case::.
  2873.  
  2874. If a program produces an error message, it is very important to include
  2875. the message in your report.  If we try to search for something from the
  2876. archives using programs, it is better that the error message reported
  2877. exactly matches the one that the program produces.  (Even the case
  2878. should be observed.)  You should never try to remember what the error
  2879. message was; instead, copy and paste the entire message into your
  2880. report.
  2881.  
  2882. If you have a problem with MyODBC, please try to generate a MyODBC
  2883. trace file and send it with your report.  *Note MyODBC bug report::.
  2884.  
  2885. Please remember that many of the people who will read your report will
  2886. do so using an 80-column display.  When generating reports or examples
  2887. using the `mysql' command-line tool, you should therefore use the
  2888. `--vertical' option (or the `\G' statement terminator) for output that
  2889. would exceed the available width for such a display (for example, with
  2890. the `EXPLAIN SELECT' statement; see the example later in this section).
  2891.  
  2892. Please include the following information in your report:
  2893.  
  2894.    * The version number of the MySQL distribution you are using (for
  2895.      example, MySQL Version 4.0.12). You can find out which version you
  2896.      are running by executing `mysqladmin version'.  `mysqladmin' can be
  2897.      found in the `bin' directory under your MySQL installation
  2898.      directory.
  2899.  
  2900.    * The manufacturer and model of the machine on which you experience
  2901.      the problem.
  2902.  
  2903.    * The operating system name and version.  For most operating
  2904.      systems, you can get this information by executing the Unix
  2905.      command `uname -a'.  If you work with Windows, you can usually get
  2906.      the name and version number by double-clicking your "My Computer"
  2907.      icon and pulling down the "Help/About Windows" menu.
  2908.  
  2909.    * Sometimes the amount of memory (real and virtual) is relevant. If
  2910.      in doubt, include these values.
  2911.  
  2912.    * If you are using a source distribution of the MySQL software, the
  2913.      name and version number of the compiler used is needed.  If you
  2914.      have a binary distribution, the distribution name is needed.
  2915.  
  2916.    * If the problem occurs during compilation, include the exact error
  2917.      message(s) and also a few lines of context around the offending
  2918.      code in the file where the error occurrs.
  2919.  
  2920.    * If `mysqld' died, you should also report the query that crashed
  2921.      `mysqld'.  You can usually find this out by running `mysqld' with
  2922.      logging enabled.  *Note Using log files::.
  2923.  
  2924.    * If a database table is related to the problem, include the output
  2925.      from `mysqldump --no-data db_name tbl_name1 tbl_name2 ...'.  This
  2926.      is very easy to do and is a powerful way to get information about
  2927.      any table in a database.  The information will help us create a
  2928.      situation matching the one you have.
  2929.  
  2930.    * For speed-related bugs or problems with `SELECT' statements, you
  2931.      should always include the output of `EXPLAIN SELECT ...', and at
  2932.      least the number of rows that the `SELECT' statement produces.  You
  2933.      should also include the output from `SHOW CREATE TABLE tbl_name'
  2934.      for each involved table. The more information you give about your
  2935.      situation, the more likely it is that someone can help you.  The
  2936.      following is an example of a very good bug report (it should of
  2937.      course be posted with the `mysqlbug' script).
  2938.  
  2939.      Example run using the `mysql' command-line tool (note the use of
  2940.      the `\G' statement terminator for statements whose output width
  2941.      would otherwise exceed that of an 80-column display device):
  2942.  
  2943.           mysql> SHOW VARIABLES;
  2944.           mysql> SHOW COLUMNS FROM ...\G
  2945.                  <output from SHOW COLUMNS>
  2946.           mysql> EXPLAIN SELECT ...\G
  2947.                  <output from EXPLAIN>
  2948.           mysql> FLUSH STATUS;
  2949.           mysql> SELECT ...;
  2950.                  <A short version of the output from SELECT,
  2951.                  including the time taken to run the query>
  2952.           mysql> SHOW STATUS;
  2953.                  <output from SHOW STATUS>
  2954.  
  2955.    * If a bug or problem occurs while running `mysqld', try to provide
  2956.      an input script that will reproduce the anomaly.  This script
  2957.      should include any necessary source files.  The more closely the
  2958.      script can reproduce your situation, the better.  If you can make
  2959.      a reproducible test case, you should post it on
  2960.      `http://bugs.mysql.com/' for high-priority treatment.
  2961.  
  2962.      If you can't provide a script, you should at least include the
  2963.      output from `mysqladmin variables extended-status processlist' in
  2964.      your mail to provide some information on how your system is
  2965.      performing.
  2966.  
  2967.    * If you can't produce a test case with only a few rows, or if the
  2968.      test table is too big to be mailed to the mailing list (more than
  2969.      10 rows), you should dump your tables using `mysqldump' and create
  2970.      a `README' file that describes your problem.
  2971.  
  2972.      Create a compressed archive of your files using `tar' and `gzip'
  2973.      or `zip', and use `ftp' to transfer the archive to
  2974.      `ftp://support.mysql.com/pub/mysql/secret/'.  Then enter the
  2975.      problem into our bugs database at `http://bugs.mysql.com/'.
  2976.  
  2977.    * If you think that the MySQL server produces a strange result from
  2978.      a query, include not only the result, but also your opinion of
  2979.      what the result should be, and an account describing the basis for
  2980.      your opinion.
  2981.  
  2982.    * When giving an example of the problem, it's better to use the
  2983.      variable names, table names, etc., that exist in your actual
  2984.      situation than to come up with new names.  The problem could be
  2985.      related to the name of a variable or table.  These cases are rare,
  2986.      perhaps, but it is better to be safe than sorry.  After all, it
  2987.      should be easier for you to provide an example that uses your
  2988.      actual situation, and it is by all means better for us.  In case
  2989.      you have data you don't want to show to others, you can use `ftp'
  2990.      to transfer it to `ftp://support.mysql.com/pub/mysql/secret/'.  If
  2991.      the data is really top secret and you don't want to show it even
  2992.      to us, then go ahead and provide an example using other names, but
  2993.      please regard this as the last choice.
  2994.  
  2995.    * Include all the options given to the relevant programs, if
  2996.      possible.  For example, indicate the options that you use when you
  2997.      start the `mysqld' daemon as well as the options that you use to
  2998.      run any MySQL client programs.  The options to programs like
  2999.      `mysqld' and `mysql', and to the `configure' script, are often
  3000.      keys to answers and are very relevant.  It is never a bad idea to
  3001.      include them.  If you use any modules, such as Perl or PHP, please
  3002.      include the version number(s) of those as well.
  3003.  
  3004.    * If your question is related to the privilege system, please
  3005.      include the output of `mysqlaccess', the output of `mysqladmin
  3006.      reload', and all the error messages you get when trying to
  3007.      connect.  When you test your privileges, you should first run
  3008.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  3009.      and try to connect with the program that gives you trouble.
  3010.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  3011.      installation directory.
  3012.  
  3013.    * If you have a patch for a bug, do include it.  But don't assume
  3014.      the patch is all we need, or that we will use it, if you don't
  3015.      provide some necessary information such as test cases showing the
  3016.      bug that your patch fixes.  We might find problems with your patch
  3017.      or we might not understand it at all; if so, we can't use it.
  3018.  
  3019.      If we can't verify exactly what the patch is meant for, we won't
  3020.      use it.  Test cases will help us here.  Show that the patch will
  3021.      handle all the situations that may occur.  If we find a borderline
  3022.      case (even a rare one) where the patch won't work, it may be
  3023.      useless.
  3024.  
  3025.    * Guesses about what the bug is, why it occurs, or what it depends on
  3026.      are usually wrong.  Even the MySQL team can't guess such things
  3027.      without first using a debugger to determine the real cause of a
  3028.      bug.
  3029.  
  3030.    * Indicate in your bug report that you have checked the reference
  3031.      manual and mail archive so that others know you have tried to
  3032.      solve the problem yourself.
  3033.  
  3034.    * If you get a `parse error', please check your syntax closely.  If
  3035.      you can't find something wrong with it, it's extremely likely that
  3036.      your current version of MySQL Server doesn't support the syntax
  3037.      you are using.  If you are using the current version and the
  3038.      manual at `http://www.mysql.com/doc/' doesn't cover the syntax you
  3039.      are using, MySQL Server doesn't support your query.  In this case,
  3040.      your only options are to implement the syntax yourself or e-mail
  3041.      <licensing@mysql.com> and ask for an offer to implement it.
  3042.  
  3043.      If the manual covers the syntax you are using, but you have an
  3044.      older version of MySQL Server, you should check the MySQL change
  3045.      history to see when the syntax was implemented.  In this case, you
  3046.      have the option of upgrading to a newer version of MySQL Server.
  3047.      *Note News::.
  3048.  
  3049.    * If your problem is that your data appears corrupt or you get
  3050.      errors when you access a particular table, you should first check
  3051.      and then try repairing your tables with `myisamchk' or `CHECK
  3052.      TABLE' and `REPAIR TABLE'.  *Note MySQL Database Administration::.
  3053.  
  3054.    * If you often get corrupted tables you should try to find out when
  3055.      and why this happens.  In this case, the
  3056.      `mysql-data-directory/'hostname'.err' file may contain some
  3057.      information about what happened.  *Note Error log::.  Please
  3058.      include any relevant information from this file in your bug
  3059.      report.  Normally `mysqld' should *never* crash a table if nothing
  3060.      killed it in the middle of an update.  If you can find the cause
  3061.      of `mysqld' dying, it's much easier for us to provide you with a
  3062.      fix for the problem.  *Note What is crashing::.
  3063.  
  3064.    * If possible, download and install the most recent version of MySQL
  3065.      Server and check whether it solves your problem.  All versions of
  3066.      the MySQL software are thoroughly tested and should work without
  3067.      problems.  We believe in making everything as backward-compatible
  3068.      as possible, and you should be able to switch MySQL versions
  3069.      without difficulty.  *Note Which version::.
  3070.  
  3071. If you are a support customer, please cross-post the bug report to
  3072. <mysql-support@mysql.com> for higher-priority treatment, as well as to
  3073. the appropriate mailing list to see if someone else has experienced (and
  3074. perhaps solved) the problem.
  3075.  
  3076. For information on reporting bugs in `MyODBC', see *Note ODBC
  3077. Problems::.
  3078.  
  3079. For solutions to some common problems, see *Note Problems::.
  3080.  
  3081. When answers are sent to you individually and not to the mailing list,
  3082. it is considered good etiquette to summarise the answers and send the
  3083. summary to the mailing list so that others may have the benefit of
  3084. responses you received that helped you solve your problem.
  3085.  
  3086. Guidelines for Answering Questions on the Mailing List
  3087. ......................................................
  3088.  
  3089. If you consider your answer to have broad interest, you may want to
  3090. post it to the mailing list instead of replying directly to the
  3091. individual who asked.  Try to make your answer general enough that
  3092. people other than the original poster may benefit from it.  When you
  3093. post to the list, please make sure that your answer is not a
  3094. duplication of a previous answer.
  3095.  
  3096. Try to summarise the essential part of the question in your reply;
  3097. don't feel obliged to quote the entire original message.
  3098.  
  3099. Please don't post mail messages from your browser with HTML mode turned
  3100. on.  Many users don't read mail with a browser.
  3101.  
  3102. MySQL Community Support on IRC (Internet Relay Chat)
  3103. ----------------------------------------------------
  3104.  
  3105. In addition to the various MySQL mailing lists, you can find experienced
  3106. community people on `IRC' (`Internet Relay Chat').  These are the best
  3107. networks/channels currently known to us:
  3108.  
  3109.    * *freenode* (see `http://www.freenode.net/' for servers)
  3110.         * `#mysql' Primarily MySQL questions but other database and SQL
  3111.           questions welcome.
  3112.  
  3113.         * `#mysqlphp' Questions about MySQL+PHP, a popular combination.
  3114.  
  3115.         * `#mysqlperl' Questions about MySQL+Perl, another popular
  3116.           combination.
  3117.  
  3118.    * *EFnet* (see `http://www.efnet.org/' for servers)
  3119.         * `#mysql' MySQL questions.
  3120.  
  3121. If you are looking for IRC client software to connect to an IRC network,
  3122. take a look at `X-Chat' (`http://www.xchat.org/').  X-Chat (GPL
  3123. licensed) is available for Unix as well as for Windows platforms.
  3124.  
  3125. How Standards-compatible Is MySQL?
  3126. ==================================
  3127.  
  3128. This section describes how MySQL relates to the ANSI/ISO SQL standards.
  3129. MySQL Server has many extensions to the SQL standard, and here you will
  3130. find out what they are and how to use them.  You will also find
  3131. information about functionality missing from MySQL Server, and how to
  3132. work around some differences.
  3133.  
  3134. Our goal is to not, without a very good reason, restrict MySQL Server
  3135. usability for any usage.  Even if we don't have the resources to do
  3136. development for every possible use, we are always willing to help and
  3137. offer suggestions to people who are trying to use MySQL Server in new
  3138. territories.
  3139.  
  3140. One of our main goals with the product is to continue to work toward
  3141. compliance with the SQL-99 standard, but without sacrificing speed or
  3142. reliability.  We are not afraid to add extensions to SQL or support for
  3143. non-SQL features if this greatly increases the usability of MySQL
  3144. Server for a big part of our users.  (The new `HANDLER' interface in
  3145. MySQL Server 4.0 is an example of this strategy. *Note `HANDLER':
  3146. HANDLER.)
  3147.  
  3148. We will continue to support transactional and non-transactional
  3149. databases to satisfy both heavy web/logging usage and mission-critical
  3150. 24/7 usage.
  3151.  
  3152. MySQL Server was designed from the start to work with medium size
  3153. databases (10-100 million rows, or about 100 MB per table) on small
  3154. computer systems.  We will continue to extend MySQL Server to work even
  3155. better with terabyte-size databases, as well as to make it possible to
  3156. compile a reduced MySQL version that is more suitable for hand-held
  3157. devices and embedded usage.  The compact design of the MySQL server
  3158. makes both of these directions possible without any conflicts in the
  3159. source tree.
  3160.  
  3161. We are currently not targeting realtime support or clustered databases
  3162. (even if you can already do a lot of things with our replication
  3163. services).
  3164.  
  3165. We don't believe that one should have native XML support in the
  3166. database, but will instead add the XML support our users request from
  3167. us on the client side.  We think it's better to keep the main server
  3168. code as "lean and clean" as possible and instead develop libraries to
  3169. deal with the complexity on the client side.  This is part of the
  3170. strategy mentioned previously of not sacrificing speed or reliability
  3171. in the server.
  3172.  
  3173. What Standards Does MySQL Follow?
  3174. ---------------------------------
  3175.  
  3176. Entry-level SQL-92. ODBC levels 0-3.51.
  3177.  
  3178. We are aiming toward supporting the full SQL-99 standard, but without
  3179. concessions to speed and quality of the code.
  3180.  
  3181. Running MySQL in ANSI Mode
  3182. --------------------------
  3183.  
  3184. If you start `mysqld' with the `--ansi' or `--sql-mode=ANSI' option,
  3185. the following behaviours of MySQL Server change:
  3186.  
  3187.    * `||' is a string concatenation operator rather than a synonym for
  3188.      `OR'.
  3189.  
  3190.    * `"' is treated as an identifier quote character (like the MySQL
  3191.      Server ``' quote character) and not as a string quote character.
  3192.      You can still use ``' to quote identifers in ANSI mode. An
  3193.      implication of this is that you cannot use double quotes to quote
  3194.      a literal string, because it will be intepreted as an identifier.
  3195.  
  3196.    * You can have any number of spaces between a function name and the
  3197.      `(' character.  This forces all function names to be treated as
  3198.      reserved words. As a result, if you want to access any database,
  3199.      table, or column name that is a reserved word, you must quote it.
  3200.      For example, because there is a `USER()' function, the name of the
  3201.      `user' table in the `mysql' database and the `User' column in that
  3202.      table become reserved, so you must quote them:
  3203.  
  3204.           SELECT "User" FROM mysql."user";
  3205.  
  3206.    * `REAL' is a synonym for `FLOAT' instead of a synonym for `DOUBLE'.
  3207.  
  3208.    * The default transaction isolation level is `SERIALIZABLE'.  *Note
  3209.      `SET TRANSACTION': SET TRANSACTION.
  3210.  
  3211.    * You can use a field/expression in `GROUP BY' that is not in the
  3212.      field list.
  3213.  
  3214. Running the server in ANSI mode is the same as starting it with these
  3215. options:
  3216.  
  3217.      --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  3218.      --transaction-isolation=SERIALIZABLE
  3219.  
  3220. In MySQL 4.1, you can achieve the same effect with these two statements:
  3221.  
  3222.      SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3223.      SET GLOBAL sql_mode =
  3224.        "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY";
  3225.  
  3226. In MySQL 4.1.1, the `sql_mode' options shown can be also be set with:
  3227.  
  3228.      SET GLOBAL sql_mode="ansi";
  3229.  
  3230. In this case, the value of the `sql_mode' variable will be set to all
  3231. options that are relevant for ANSI mode. You can check the result by
  3232. doing:
  3233.  
  3234.      mysql> SET GLOBAL sql_mode="ansi";
  3235.      mysql> SELECT @@GLOBAL.sql_mode;
  3236.               -> "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI"
  3237.  
  3238. MySQL Extensions To The SQL-92 Standard
  3239. ---------------------------------------
  3240.  
  3241. MySQL Server includes some extensions that you probably will not find in
  3242. other SQL databases.  Be warned that if you use them, your code will
  3243. not be portable to other SQL servers.  In some cases, you can write
  3244. code that includes MySQL extensions, but is still portable, by using
  3245. comments of the form `/*! ... */'.  In this case, MySQL Server will
  3246. parse and execute the code within the comment as it would any other
  3247. MySQL statement, but other SQL servers will ignore the extensions.  For
  3248. example:
  3249.  
  3250.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  3251.  
  3252. If you add a version number after the `'!'', the syntax will be
  3253. executed only if the MySQL version is equal to or newer than the used
  3254. version number:
  3255.  
  3256.      CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
  3257.  
  3258. This means that if you have Version 3.23.02 or newer, MySQL Server will
  3259. use the `TEMPORARY' keyword.
  3260.  
  3261. The following is a list of MySQL extensions:
  3262.  
  3263.    * The field types `MEDIUMINT', `SET', `ENUM', and the different
  3264.      `BLOB' and `TEXT' types.
  3265.  
  3266.    * The field attributes `AUTO_INCREMENT', `BINARY', `NULL',
  3267.      `UNSIGNED', and `ZEROFILL'.
  3268.  
  3269.    * All string comparisons are case-insensitive by default, with sort
  3270.      ordering determined by the current character set (ISO-8859-1
  3271.      Latin1 by default).  If you don't like this, you should declare
  3272.      your columns with the `BINARY' attribute or use the `BINARY' cast,
  3273.      which causes comparisons to be done according to the ASCII order
  3274.      used on the MySQL server host.
  3275.  
  3276.    * MySQL Server maps each database to a directory under the MySQL
  3277.      data directory, and tables within a database to filenames in the
  3278.      database directory.
  3279.  
  3280.      This has a few implications:
  3281.  
  3282.         - Database names and table names are case-sensitive in MySQL
  3283.           Server on operating systems that have case-sensitive
  3284.           filenames (like most Unix systems). *Note Name case
  3285.           sensitivity::.
  3286.  
  3287.         - Database, table, index, column, or alias names may begin with
  3288.           a digit (but may not consist solely of digits).
  3289.  
  3290.         - You can use standard system commands to back up, rename,
  3291.           move, delete, and copy tables.  For example, to rename a
  3292.           table, rename the `.MYD', `.MYI', and `.frm' files to which
  3293.           the table corresponds.
  3294.  
  3295.    * In SQL statements, you can access tables from different databases
  3296.      with the `db_name.tbl_name' syntax.  Some SQL servers provide the
  3297.      same functionality but call this `User space'.  MySQL Server
  3298.      doesn't support tablespaces as in: `create table
  3299.      ralph.my_table...IN my_tablespace'.
  3300.  
  3301.    * `LIKE' is allowed on numeric columns.
  3302.  
  3303.    * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT' statement.
  3304.      *Note `SELECT': SELECT.
  3305.  
  3306.    * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  3307.  
  3308.    * `EXPLAIN SELECT' to get a description of how tables are joined.
  3309.  
  3310.    * Use of index names, indexes on a prefix of a field, and use of
  3311.      `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  3312.      TABLE': CREATE TABLE.
  3313.  
  3314.    * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  3315.  
  3316.    * Use of `COUNT(DISTINCT list)' where `list' has more than one
  3317.      element.
  3318.  
  3319.    * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  3320.      `IGNORE' or `RENAME' in an `ALTER TABLE' statement. *Note `ALTER
  3321.      TABLE': ALTER TABLE.
  3322.  
  3323.    * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  3324.  
  3325.    * Use of multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  3326.      `ALTER TABLE' statement.
  3327.  
  3328.    * Use of `DROP TABLE' with the keywords `IF EXISTS'.
  3329.  
  3330.    * You can drop multiple tables with a single `DROP TABLE' statement.
  3331.  
  3332.    * The `ORDER BY' and `LIMIT' clauses of the `UPDATE' and `DELETE'
  3333.      statements.
  3334.  
  3335.    * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  3336.  
  3337.    * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE', `DELETE',
  3338.      and `UPDATE' statements.
  3339.  
  3340.    * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  3341.      compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD DATA':
  3342.      LOAD DATA.
  3343.  
  3344.    * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and `REPAIR
  3345.      TABLE' statements.
  3346.  
  3347.    * The `SHOW' statement.  *Note `SHOW': SHOW.
  3348.  
  3349.    * Strings may be enclosed by either `"' or `'', not just by `''.
  3350.  
  3351.    * Use of the escape `\' character.
  3352.  
  3353.    * The `SET' statement. *Note `SET': SET OPTION.
  3354.  
  3355.    * You don't need to name all selected columns in the `GROUP BY' part.
  3356.      This gives better performance for some very specific, but quite
  3357.      normal queries.  *Note Group by functions::.
  3358.  
  3359.    * One can specify `ASC' and `DESC' with `GROUP BY'.
  3360.  
  3361.    * To make it easier for users who come from other SQL environments,
  3362.      MySQL Server supports aliases for many functions. For example, all
  3363.      string functions support both standard SQL syntax and ODBC syntax.
  3364.  
  3365.    * MySQL Server understands the `||' and `&&' operators to mean
  3366.      logical OR and AND, as in the C programming language.  In MySQL
  3367.      Server, `||' and `OR' are synonyms, as are `&&' and `AND'.
  3368.      Because of this nice syntax, MySQL Server doesn't support the
  3369.      standard SQL-99 `||' operator for string concatenation; use
  3370.      `CONCAT()' instead. Because `CONCAT()' takes any number of
  3371.      arguments, it's easy to convert use of the `||' operator to MySQL
  3372.      Server.
  3373.  
  3374.    * `CREATE DATABASE' or `DROP DATABASE'.  *Note `CREATE DATABASE':
  3375.      CREATE DATABASE.
  3376.  
  3377.    * The `%' operator is a synonym for `MOD()'.  That is, `N % M' is
  3378.      equivalent to `MOD(N,M)'.  `%' is supported for C programmers and
  3379.      for compatibility with PostgreSQL.
  3380.  
  3381.    * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  3382.      `OR', or `LIKE' operators may be used in column comparisons to the
  3383.      left of the `FROM' in `SELECT' statements.  For example:
  3384.  
  3385.           mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  3386.  
  3387.    * The `LAST_INSERT_ID()' function.  *Note `mysql_insert_id()':
  3388.      mysql_insert_id.
  3389.  
  3390.    * The `REGEXP' and `NOT REGEXP' extended regular expression
  3391.      operators.
  3392.  
  3393.    * `CONCAT()' or `CHAR()' with one argument or more than two
  3394.      arguments.  (In MySQL Server, these functions can take any number
  3395.      of arguments.)
  3396.  
  3397.    * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()', `FORMAT()',
  3398.      `IF()', `PASSWORD()', `ENCRYPT()', `MD5()', `ENCODE()', `DECODE()',
  3399.      `PERIOD_ADD()', `PERIOD_DIFF()', `TO_DAYS()', or `WEEKDAY()'
  3400.      functions.
  3401.  
  3402.    * Use of `TRIM()' to trim substrings.  SQL-99 supports removal of
  3403.      single characters only.
  3404.  
  3405.    * The `GROUP BY' functions `STD()', `BIT_OR()', `BIT_AND()', and
  3406.      `GROUP_CONCAT()'.  *Note Group by functions::.
  3407.  
  3408.    * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note `REPLACE':
  3409.      REPLACE.
  3410.  
  3411.    * The `FLUSH', `RESET' and `DO' statements.
  3412.  
  3413.    * The ability to set variables in a statement with `:=':
  3414.           SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg FROM test_table;
  3415.           SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  3416.  
  3417.  
  3418. MySQL Differences Compared To SQL-92
  3419. ------------------------------------
  3420.  
  3421. We try to make MySQL Server follow the ANSI SQL standard
  3422. (SQL-92/SQL-99) and the ODBC SQL standard, but in some cases MySQL
  3423. Server does things differently:
  3424.  
  3425.    * For `VARCHAR' columns, trailing spaces are removed when the value
  3426.      is stored. *Note Bugs::.
  3427.  
  3428.    * In some cases, `CHAR' columns are silently changed to `VARCHAR'
  3429.      columns. *Note Silent column changes::.
  3430.  
  3431.    * Privileges for a table are not automatically revoked when you
  3432.      delete a table. You must explicitly issue a `REVOKE' to revoke
  3433.      privileges for a table. *Note `GRANT': GRANT.
  3434.  
  3435.    * `NULL AND FALSE' will evaluate to `NULL' and not to `FALSE'.  This
  3436.      is because we don't think it's good to have to evaluate a lot of
  3437.      extra conditions in this case.
  3438.  
  3439. For a prioritised list indicating when new extensions will be added to
  3440. MySQL Server, you should consult the online MySQL TODO list at
  3441. `http://www.mysql.com/doc/en/TODO.html'.  That is the latest version of
  3442. the TODO list in this manual. *Note TODO::.
  3443.  
  3444. Subqueries
  3445. ..........
  3446.  
  3447. Subqueries are supported in MySQL version 4.1.  *Note Nutshell 4.1
  3448. features::.
  3449.  
  3450. Up to version 4.0, only nested queries of the form `INSERT ... SELECT
  3451. ...' and `REPLACE ... SELECT ...' are supported.  You can, however, use
  3452. the function `IN()' in other contexts.
  3453.  
  3454. You can often rewrite the query without a subquery:
  3455.  
  3456.      SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
  3457.  
  3458. This can be rewritten as:
  3459.  
  3460.      SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
  3461.  
  3462. The queries:
  3463.      SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
  3464.      SELECT * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2
  3465.                                             WHERE table1.id=table2.id);
  3466.  
  3467. Can be rewritten as:
  3468.  
  3469.      SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id
  3470.                                             WHERE table2.id IS NULL;
  3471.  
  3472. Using a `LEFT [OUTER] JOIN' is generally much faster than an equivalent
  3473. subquery because the server can optimise it better, a fact that is not
  3474. specific to MySQL Server alone.  Prior to SQL-92, outer joins did not
  3475. exist, so subqueries were the only way to do certain things in those
  3476. bygone days. But that is no longer the case, MySQL Server and many
  3477. other modern database systems offer a whole range of outer joins types.
  3478.  
  3479. For more complicated subqueries you can often create temporary tables
  3480. to hold the subquery.  In some cases, however, this option will not
  3481. work. The most frequently encountered of these cases arises with
  3482. `DELETE' statements, for which standard SQL does not support joins
  3483. (except in subqueries).  For this situation there are three options
  3484. available:
  3485.  
  3486.    * The first option is to upgrade to MySQL version 4.1.
  3487.  
  3488.    * The second option is to use a procedural programming language
  3489.      (such as Perl or PHP) to submit a `SELECT' query to obtain the
  3490.      primary keys for the records to be deleted, and then use these
  3491.      values to construct the `DELETE' statement (`DELETE FROM ... WHERE
  3492.      ... IN (key1, key2, ...)').
  3493.  
  3494.    * The third option is to use interactive SQL to construct a set of
  3495.      `DELETE' statements automatically, using the MySQL extension
  3496.      `CONCAT()' (in lieu of the standard `||' operator).  For example:
  3497.  
  3498.           SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', "'", tab1.pkid, "'", ';')
  3499.             FROM tab1, tab2
  3500.            WHERE tab1.col1 = tab2.col2;
  3501.  
  3502.      You can place this query in a script file and redirect input from
  3503.      it to the `mysql' command-line interpreter, piping its output back
  3504.      to a second instance of the interpreter:
  3505.  
  3506.           shell> mysql --skip-column-names mydb < myscript.sql | mysql mydb
  3507.  
  3508. MySQL Server 4.0 supports multi-table `DELETE's that can be used to
  3509. efficiently delete rows based on information from one table or even
  3510. from many tables at the same time.
  3511.  
  3512. `SELECT INTO TABLE'
  3513. ...................
  3514.  
  3515. MySQL Server doesn't yet support the Oracle SQL extension: `SELECT ...
  3516. INTO TABLE ...'.  Instead, MySQL Server supports the SQL-99 syntax
  3517. `INSERT INTO ... SELECT ...', which is basically the same thing. *Note
  3518. INSERT SELECT::.
  3519.  
  3520.      INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID
  3521.             FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;
  3522.  
  3523. Alternatively, you can use `SELECT INTO OUTFILE...' or `CREATE TABLE
  3524. ... SELECT'.
  3525.  
  3526. Transactions and Atomic Operations
  3527. ..................................
  3528.  
  3529. MySQL Server (version 3.23-max and all versions 4.0 and above) supports
  3530. transactions with the `InnoDB' and `BDB' `Transactional storage
  3531. engines'.  `InnoDB' provides _full_ `ACID' compliance.  *Note Table
  3532. types::.
  3533.  
  3534. The other non-transactional table types (such as `MyISAM') in MySQL
  3535. Server follow a different paradigm for data integrity called "`Atomic
  3536. Operations'." In transactional terms, `MyISAM' tables effectively
  3537. always operate in `AUTOCOMMIT=1' mode.  Atomic operations often offer
  3538. comparable integrity with higher performance.
  3539.  
  3540. With MySQL Server supporting both paradigms, the user is able to decide
  3541. if he needs the speed of atomic operations or if he needs to use
  3542. transactional features in his applications. This choice can be made on
  3543. a per-table basis.
  3544.  
  3545. As noted, the trade off for transactional vs. non-transactional table
  3546. types lies mostly in performance. Transactional tables have
  3547. significantly higher memory and diskspace requirements, and more CPU
  3548. overhead.  That said, transactional table types such as `InnoDB' do of
  3549. course offer many unique features. MySQL Server's modular design allows
  3550. the concurrent use of all these different storage engines to suit
  3551. different requirements and deliver optimum performance in all
  3552. situations.
  3553.  
  3554. But how does one use the features of MySQL Server to maintain rigorous
  3555. integrity even with the non-transactional `MyISAM' tables, and how do
  3556. these features compare with the transactional table types?
  3557.  
  3558.   1. In the transactional paradigm, if your applications are written in
  3559.      a way that is dependent on the calling of `ROLLBACK' instead of
  3560.      `COMMIT' in critical situations, transactions are more convenient.
  3561.      Transactions also ensure that unfinished updates or corrupting
  3562.      activities are not committed to the database; the server is given
  3563.      the opportunity to do an automatic rollback and your database is
  3564.      saved.
  3565.  
  3566.      MySQL Server, in almost all cases, allows you to resolve potential
  3567.      problems by including simple checks before updates and by running
  3568.      simple scripts that check the databases for inconsistencies and
  3569.      automatically repair or warn if such an inconsistency occurs. Note
  3570.      that just by using the MySQL log or even adding one extra log, one
  3571.      can normally fix tables perfectly with no data integrity loss.
  3572.  
  3573.   2. More often than not, critical transactional updates can be
  3574.      rewritten to be atomic. Generally speaking, all integrity problems
  3575.      that transactions solve can be done with `LOCK TABLES' or atomic
  3576.      updates, ensuring that you never will get an automatic abort from
  3577.      the server, which is a common problem with transactional database
  3578.      systems.
  3579.  
  3580.   3. Even a transactional system can lose data if the server goes down.
  3581.      The difference between different systems lies in just how small the
  3582.      time-lap is where they could lose data. No system is 100% secure,
  3583.      only "secure enough." Even Oracle, reputed to be the safest of
  3584.      transactional database systems, is reported to sometimes lose data
  3585.      in such situations.
  3586.  
  3587.      To be safe with MySQL Server, whether using transactional tables
  3588.      or not, you only need to have backups and have the binary logging
  3589.      turned on. With this you can recover from any situation that you
  3590.      could with any other transactional database system.  It is, of
  3591.      course, always good to have backups, independent of which database
  3592.      system you use.
  3593.  
  3594. The transactional paradigm has its benefits and its drawbacks. Many
  3595. users and application developers depend on the ease with which they can
  3596. code around problems where an abort appears to be, or is necessary.
  3597. However, even if you are new to the atomic operations paradigm, or more
  3598. familiar with transactions, do consider the speed benefit that
  3599. non-transactional tables can offer on the order of three to five times
  3600. the speed of the fastest and most optimally tuned transactional tables.
  3601.  
  3602. In situations where integrity is of highest importance, MySQL Server
  3603. offers transaction-level reliability and integrity even for
  3604. non-transactional tables.  If you lock tables with `LOCK TABLES', all
  3605. updates will stall until any integrity checks are made. If you only
  3606. obtain a read lock (as opposed to a write lock), reads and inserts are
  3607. still allowed to happen. The new inserted records will not be seen by
  3608. any of the clients that have a read lock until they release their read
  3609. locks. With `INSERT DELAYED' you can queue inserts into a local queue,
  3610. until the locks are released, without having the client wait for the
  3611. insert to complete. *Note INSERT DELAYED::.
  3612.  
  3613. "Atomic," in the sense that we mean it, is nothing magical. It only
  3614. means that you can be sure that while each specific update is running,
  3615. no other user can interfere with it, and there will never be an
  3616. automatic rollback (which can happen with transactional tables if you
  3617. are not very careful).  MySQL Server also guarantees that there will
  3618. not be any dirty reads.
  3619.  
  3620. Following are some techniques for working with non-transactional tables:
  3621.  
  3622.    * Loops that need transactions normally can be coded with the help of
  3623.      `LOCK TABLES', and you don't need cursors when you can update
  3624.      records on the fly.
  3625.  
  3626.    * To avoid using `ROLLBACK', you can use the following strategy:
  3627.  
  3628.        1. Use `LOCK TABLES ...' to lock all the tables you want to
  3629.           access.
  3630.  
  3631.        2. Test conditions.
  3632.  
  3633.        3. Update if everything is okay.
  3634.  
  3635.        4. Use `UNLOCK TABLES' to release your locks.
  3636.  
  3637.      This is usually a much faster method than using transactions with
  3638.      possible `ROLLBACK's, although not always. The only situation this
  3639.      solution doesn't handle is when someone kills the threads in the
  3640.      middle of an update. In this case, all locks will be released but
  3641.      some of the updates may not have been executed.
  3642.  
  3643.    * You can also use functions to update records in a single operation.
  3644.      You can get a very efficient application by using the following
  3645.      techniques:
  3646.  
  3647.         * Modify fields relative to their current value.
  3648.  
  3649.         * Update only those fields that actually have changed.
  3650.  
  3651.      For example, when we are doing updates to some customer
  3652.      information, we update only the customer data that has changed and
  3653.      test only that none of the changed data, or data that depends on
  3654.      the changed data, has changed compared to the original row. The
  3655.      test for changed data is done with the `WHERE' clause in the
  3656.      `UPDATE' statement. If the record wasn't updated, we give the
  3657.      client a message: "Some of the data you have changed has been
  3658.      changed by another user." Then we show the old row versus the new
  3659.      row in a window, so the user can decide which version of the
  3660.      customer record he should use.
  3661.  
  3662.      This gives us something that is similar to column locking but is
  3663.      actually even better because we only update some of the columns,
  3664.      using values that are relative to their current values.  This
  3665.      means that typical `UPDATE' statements look something like these:
  3666.  
  3667.           UPDATE tablename SET pay_back=pay_back+125;
  3668.           
  3669.           UPDATE customer
  3670.             SET
  3671.               customer_date='current_date',
  3672.               address='new address',
  3673.               phone='new phone',
  3674.               money_he_owes_us=money_he_owes_us-125
  3675.             WHERE
  3676.               customer_id=id AND address='old address' AND phone='old phone';
  3677.  
  3678.      As you can see, this is very efficient and works even if another
  3679.      client has changed the values in the `pay_back' or
  3680.      `money_he_owes_us' columns.
  3681.  
  3682.    * In many cases, users have wanted `ROLLBACK' and/or `LOCK TABLES'
  3683.      for the purpose of managing unique identifiers for some tables.
  3684.      This can be handled much more efficiently by using an
  3685.      `AUTO_INCREMENT' column and either the SQL function
  3686.      `LAST_INSERT_ID()' or the C API function `mysql_insert_id()'.
  3687.      *Note `mysql_insert_id()': mysql_insert_id.
  3688.  
  3689.      You can generally code around row-level locking. Some situations
  3690.      really need it, but they are very few. `InnoDB' tables support
  3691.      row-level locking. With MyISAM, you can use a flag column in the
  3692.      table and do something like the following:
  3693.  
  3694.           UPDATE tbl_name SET row_flag=1 WHERE id=ID;
  3695.  
  3696.      MySQL returns 1 for the number of affected rows if the row was
  3697.      found and `row_flag' wasn't already 1 in the original row.
  3698.  
  3699.      You can think of it as though MySQL Server changed the preceding
  3700.      query to:
  3701.  
  3702.           UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;
  3703.  
  3704. Stored Procedures and Triggers
  3705. ..............................
  3706.  
  3707. Stored procedures are being implemented in our version 5.0 development
  3708. tree.  *Note Installing source tree::.
  3709.  
  3710. This effort is based on SQL-99, which has a basic syntax similar (but
  3711. not identical) to Oracle PL/SQL. In addition to this, we are
  3712. implementing the SQL-99 framework to hook in external languages.
  3713.  
  3714. A stored procedure is a set of SQL commands that can be compiled and
  3715. stored in the server. Once this has been done, clients don't need to
  3716. keep re-issuing the entire query but can refer to the stored procedure.
  3717. This provides better overall performance because the query has to be
  3718. parsed only once, and less information needs to be sent between the
  3719. server and the client. You can also raise the conceptual level by
  3720. having libraries of functions in the server.  However, stored
  3721. procedures of course do increase the load on the database server
  3722. system, as more of the work is done on the server side and less on the
  3723. client (application) side.
  3724.  
  3725. Triggers will also be implemented. A trigger is effectively a type of
  3726. stored procedure, one that is invoked when a particular event occurs.
  3727. For example, you can install a stored procedure that is triggered each
  3728. time a record is deleted from a transactional table and that stored
  3729. procedure automatically deletes the corresponding customer from a
  3730. customer table when all his transactions are deleted.
  3731.  
  3732. Foreign Keys
  3733. ............
  3734.  
  3735. In MySQL Server 3.23.44 and up, `InnoDB' tables support checking of
  3736. foreign key constraints, including `CASCADE', `ON DELETE', and `ON
  3737. UPDATE'. *Note InnoDB foreign key constraints::.
  3738.  
  3739. For other table types, MySQL Server only parses the `FOREIGN KEY'
  3740. syntax in `CREATE TABLE' commands, but does not use/store this info.
  3741.  
  3742. Note that foreign keys in SQL are not used to join tables, but are used
  3743. mostly for checking referential integrity (foreign key constraints).  If
  3744. you want to get results from multiple tables from a `SELECT' statement,
  3745. you do this by joining tables:
  3746.  
  3747.      SELECT * FROM table1,table2 WHERE table1.id = table2.id;
  3748.  
  3749. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  3750.  
  3751. When used as a constraint, `FOREIGN KEY's don't need to be used if the
  3752. application inserts rows into `MyISAM' tables in the proper order.
  3753.  
  3754. For `MyISAM' tables, you can work around the lack of `ON DELETE' by
  3755. adding the appropriate `DELETE' statement to an application when you
  3756. delete records from a table that has a foreign key. In practice this is
  3757. as quick (in some cases quicker) and much more portable than using
  3758. foreign keys.
  3759.  
  3760. In MySQL Server 4.0 you can use multi-table delete to delete rows from
  3761. many tables with one command. *Note DELETE::.
  3762.  
  3763. The `FOREIGN KEY' syntax without `ON DELETE ...' is often used by ODBC
  3764. applications to produce automatic `WHERE' clauses.
  3765.  
  3766. In the near future we will extend the `FOREIGN KEY' implementation so
  3767. that the information is stored in the table specification file and may
  3768. be retrieved by `mysqldump' and ODBC. At a later stage we will
  3769. implement foreign key constraints for `MyISAM' tables as well.
  3770.  
  3771. Do keep in mind that foreign keys are often misused, which can cause
  3772. severe problems. Even when used properly, it is not a magic solution for
  3773. the referential integrity problem, although it can make things easier.
  3774.  
  3775. Some advantages of foreign key enforcement:
  3776.  
  3777.    * Assuming proper design of the relations, foreign key constraints
  3778.      will make it more difficult for a programmer to introduce an
  3779.      inconsistency into the database.
  3780.  
  3781.    * Using cascading updates and deletes can simplify the client code.
  3782.  
  3783.    * Properly designed foreign key rules aid in documenting relations
  3784.      between tables.
  3785.  
  3786. Disadvantages:
  3787.  
  3788.    * Mistakes, which are easy to make in designing key relations, can
  3789.      cause severe problems--for example, circular rules, or the wrong
  3790.      combination of cascading deletes.
  3791.  
  3792.    * A properly written application will make sure (internally) that it
  3793.      is not violating referential integrity constraints before
  3794.      proceding with a query. Thus, additional checks on the database
  3795.      level will only slow down performance for such an application.
  3796.  
  3797.    * It is not uncommon for a DBA to make such a complex topology of
  3798.      relations that it becomes very difficult, and in some cases
  3799.      impossible, to back up or restore individual tables.
  3800.  
  3801. Views
  3802. .....
  3803.  
  3804. We plan to implement views in MySQL Server in version 5.1
  3805.  
  3806. Historically, MySQL Server has been most used in applications and on web
  3807. systems where the application writer has full control over database
  3808. usage. Of course, usage has shifted over time, and so we find that an
  3809. increasing number of users now regard views as an important aspect.
  3810.  
  3811. Views are useful for allowing users to access a set of relations as if
  3812. it were a single table, and limiting their access to just that.  Many
  3813. DBMS don't allow updates to a view, instead you have to perform the
  3814. updates on the individual tables.
  3815.  
  3816. Views can also be used to restrict access to rows (a subset of a
  3817. particular table).  One does not need views to restrict access to
  3818. columns, as MySQL Server has a sophisticated privilege system.  *Note
  3819. Privilege system::.
  3820.  
  3821. In designing our implementation of views, we aim toward (as fully as
  3822. possible within the confines of SQL) compliance with "*Codd's Rule #6*"
  3823. for relational database systems: all views that are theoretically
  3824. updatable, should in practice also be updatable.  This is a complex
  3825. issue, and we are taking the time to make sure we get it right.
  3826.  
  3827. The implementation itself will be done in stages.  Unnamed views
  3828. (_derived tables_, a subquery in the `FROM' clause of a `SELECT') are
  3829. already implemented in version 4.1.
  3830.  
  3831. *Note*: If you are an enterprise level user with an urgent need for
  3832. views, please contact <sales@mysql.com> to discuss sponsoring options.
  3833. Targeted financing of this particular effort by one or more companies
  3834. would allow us to allocate additional resources to it.  One example of
  3835. a feature sponsored in the past is replication.
  3836.  
  3837. `--' as the Start of a Comment
  3838. ..............................
  3839.  
  3840. Some other SQL databases use `--' to start comments.  MySQL Server has
  3841. `#' as the start comment character. You can also use the C comment
  3842. style `/* this is a comment */' with MySQL Server.  *Note Comments::.
  3843.  
  3844. MySQL Server Version 3.23.3 and above support the `--' comment style,
  3845. provided the comment is followed by a space (or by a control character
  3846. such as a newline).  This is because this comment style has caused many
  3847. problems with automatically generated SQL queries that have used
  3848. something like the following code, where we automatically insert the
  3849. value of the payment for `!payment!':
  3850.  
  3851.      UPDATE tbl_name SET credit=credit-!payment!
  3852.  
  3853. Think about what happens if the value of `payment' is negative.
  3854. Because `1--1' is legal in SQL, the consequences of allowing comments
  3855. to start with `--' are terrible.
  3856.  
  3857. Using our implementation of this method of commenting in MySQL Server
  3858. Version 3.23.3 and up, `1-- This is a comment' is actually safe.
  3859.  
  3860. Another safe feature is that the `mysql' command-line client removes
  3861. all lines that start with `--'.
  3862.  
  3863. The following information is relevant only if you are running a MySQL
  3864. version earlier than 3.23.3:
  3865.  
  3866. If you have an SQL program in a text file that contains `--' comments
  3867. you should use:
  3868.  
  3869.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  3870.               | mysql database
  3871.  
  3872. instead of the usual:
  3873.  
  3874.      shell> mysql database < text-file-with-funny-comments.sql
  3875.  
  3876. You can also edit the command file "in place" to change the `--'
  3877. comments to `#' comments:
  3878.  
  3879.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  3880.  
  3881. Change them back with this command:
  3882.  
  3883.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  3884.  
  3885. How MySQL deals with constraints
  3886. --------------------------------
  3887.  
  3888. As MySQL allows you to work with both transactional and
  3889. non-transactional tables (which don't allow rollback), constraint
  3890. handling is a bit different in MySQL than in other databases.
  3891.  
  3892. We have to handle the case when you have updated a lot of rows with a
  3893. non-transactional table which can't rollback on errors.
  3894.  
  3895. The basic philosophy is to try to give an error for anything that we can
  3896. detect on compile time but try to recover from any errors we get run
  3897. time.  We do this in most cases, but not yet for all. *Note TODO
  3898. future::.
  3899.  
  3900. The basic options MySQL has is to stop the statement in the middle or do
  3901. it's best to recover from the problem and continue.
  3902.  
  3903. Here follows what happens with the different types of constraints.
  3904.  
  3905. Constraint PRIMARY KEY / UNIQUE
  3906. ...............................
  3907.  
  3908. Normally you will get an error when you try to `INSERT' / `UPDATE' a
  3909. row that causes a primary key, unique key or foreign key violation.  If
  3910. you are using a transactional storage engine, like InnoDB, MySQL will
  3911. automatically roll back the transaction.  If you are using a
  3912. non-transactional storage engine MySQL will stop at the wrong row and
  3913. leave the rest of the rows unprocessed.
  3914.  
  3915. To make life easier MySQL has added support for the `IGNORE' directive
  3916. to most commands that can cause a key violation (like `INSERT IGNORE
  3917. ...'). In this case MySQL will ignore any key violation and continue
  3918. with processing the next row.  You can get information of what MySQL
  3919. did with the `mysql_info()' API function and in later MySQL 4.1 version
  3920. with the `SHOW WARNINGS' command. *Note mysql_info::. *Note SHOW
  3921. WARNINGS::.
  3922.  
  3923. Note that for the moment only `InnoDB' tables support foreign keys.
  3924. *Note InnoDB foreign key constraints::.  Foreign key support in
  3925. `MyISAM' tables is scheduled for inclusion in the MySQL 5.0 source tree.
  3926.  
  3927. Constraint `NOT NULL' and `DEFAULT' values
  3928. ..........................................
  3929.  
  3930. To be able to support easy handling of non-transactional tables all
  3931. fields in MySQL have default values.
  3932.  
  3933. If you insert a 'wrong' value in a column like a `NULL' in a `NOT NULL'
  3934. column or a too big numerical value in a numerical column, MySQL will
  3935. instead of giving an error instead set the column to the 'best possible
  3936. value'.  For numerical values this is 0, the smallest possible values
  3937. or the largest possible value. For strings this is either the empty
  3938. string or the longest possible string that can be in the column.
  3939.  
  3940. This means that if you try to store `NULL' into a column that doesn't
  3941. take `NULL' values, MySQL Server will store 0 or `''' (empty string) in
  3942. it instead. This last behaviour can, for single row inserts, be changed
  3943. with the `-DDONT_USE_DEFAULT_FIELDS' compile option.) *Note configure
  3944. options::.  This causes `INSERT' statements to generate an error unless
  3945. you explicitly specify values for all columns that require a non-`NULL'
  3946. value.
  3947.  
  3948. The reason for the above rules is that we can't check these conditions
  3949. before the query starts to execute.  If we encounter a problem after
  3950. updating a few rows, we can't just rollback as the table type may not
  3951. support this.  The option to stop is not that good as in this case the
  3952. update would be 'half done' which is probably the worst possible
  3953. scenario.  In this case it's better to 'do the best you can' and then
  3954. continue as if nothing happened.  In MySQL 5.0 we plan to improve this
  3955. by providing warnings for automatic field conversions, plus an option
  3956. to let you roll back statements that only use transactional tables in
  3957. case one such statement does a field assignment that is not allowed.
  3958.  
  3959. The above means that one should generally not use MySQL to check field
  3960. content, but instead handle this in the application.
  3961.  
  3962. Constraint `ENUM' and `SET'
  3963. ...........................
  3964.  
  3965. In MySQL 4.x `ENUM' is not a real constrain but a more efficient way to
  3966. store fields that can only contain a given set of values.  This is
  3967. because of the same reasons `NOT NULL' is not honoured.  *Note
  3968. constraint NOT NULL::.
  3969.  
  3970. If you insert an wrong value in an `ENUM' field, it will be set to the
  3971. reserved enum number `0', which will be displayed as an empty string in
  3972. string context. *Note ENUM::.
  3973.  
  3974. If you insert an wrong option in a `SET' field, the wrong value will be
  3975. ignored. *Note SET::.
  3976.  
  3977. Known Errors and Design Deficiencies in MySQL
  3978. ---------------------------------------------
  3979.  
  3980. Errors in 3.23 Fixed in a Later MySQL Version
  3981. .............................................
  3982.  
  3983. The following known errors/bugs are not fixed in MySQL 3.23 because
  3984. fixing them would involves changing a lot of code which could introduce
  3985. other even worse bugs. The bugs are also classified as 'not fatal' or
  3986. 'bearable'.
  3987.  
  3988.    * One can get a deadlock when doing `LOCK TABLE' on multiple tables
  3989.      and then in the same connection doing a `DROP TABLE' on one of
  3990.      them while another thread is trying to lock the table.  One can
  3991.      however do a `KILL' on any of the involved threads to resolve this.
  3992.      Fixed in 4.0.12.
  3993.  
  3994.    * `SELECT MAX(key_column) FROM t1,t2,t3...' where one of the tables
  3995.      are empty doesn't return `NULL' but instead the maximum value for
  3996.      the column.  Fixed in 4.0.11.
  3997.  
  3998.    * `DELETE FROM heap_table' without a `WHERE' doesn't work on a locked
  3999.      HEAP table.
  4000.  
  4001. Open Bugs / Design Deficiencies in MySQL
  4002. ........................................
  4003.  
  4004. The following problems are known and fixing them is a high priority:
  4005.  
  4006.    * `FLUSH TABLES WITH READ LOCK' does not block `CREATE TABLE' or
  4007.      `COMMIT', which make cause a problem with the binary log position
  4008.      when doing a full backup of tables and the binary log.
  4009.  
  4010.    * `ANALYZE TABLE' on a BDB table may in some cases make the table
  4011.      unusable until one has restarted `mysqld'.  When this happens you
  4012.      will see errors like the following in the MySQL error file:
  4013.  
  4014.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  4015.  
  4016.    * MySQL accepts parentheses in the `FROM' part, but silently ignores
  4017.      them.  The reason for not giving an error is that many clients
  4018.      that automatically generate queries add parentheses in the `FROM'
  4019.      part even where they are not needed.
  4020.  
  4021.    * Concatenating many `RIGHT JOINS' or combining `LEFT' and `RIGHT'
  4022.      join in the same query may not give a correct answer as MySQL only
  4023.      generates `NULL' rows for the table preceding a `LEFT' or before a
  4024.      `RIGHT' join.  This will be fixed in 5.0 at the same time we add
  4025.      support for parentheses in the `FROM' part.
  4026.  
  4027.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  4028.      running multi-statement transactions until all those transactions
  4029.      complete.  (The transaction will probably be ignored.)
  4030.  
  4031.    * `ANALYZE TABLE', `OPTIMIZE TABLE', and `REPAIR TABLE' may cause
  4032.      problems on tables for which you are using `INSERT DELAYED'.
  4033.  
  4034.    * Doing a `LOCK TABLE ...' and `FLUSH TABLES ...' doesn't guarantee
  4035.      that there isn't a half-finished transaction in progress on the
  4036.      table.
  4037.  
  4038.    * BDB tables are a bit slow to open. If you have many BDB tables in a
  4039.      database, it will take a long time to use the `mysql' client on the
  4040.      database if you are not using the `-A' option or if you are using
  4041.      `rehash'. This is especially notable when you have a big table
  4042.      cache.
  4043.  
  4044.    * Replication uses query-level logging: the master writes the
  4045.      executed queries to the binary log. This is a very fast, compact
  4046.      and efficient logging method which works perfectly in most cases.
  4047.      However, currently there is a theoretical chance (though we never
  4048.      heard about it coming true) that the data on the master and slave
  4049.      become different if a query is designed in such a way that the
  4050.      data modification is non-deterministic, that is, left to the will
  4051.      of the query optimiser (which generally is no good practice, even
  4052.      outside of replication!). For example:
  4053.  
  4054.         - `CREATE ... SELECT' or `INSERT ... SELECT' which feeds zeros
  4055.           or `NULL's into an `auto_increment' column.
  4056.  
  4057.         - `DELETE' if you are deleting rows from a table which has
  4058.           foreign keys with `ON DELETE CASCADE' properties.
  4059.  
  4060.         - `REPLACE ... SELECT', `INSERT IGNORE ... SELECT' if you have
  4061.           duplicate key values in the inserted data.
  4062.      *IF and only if all these queries have NO `ORDER BY' clause
  4063.      guaranteeing a deterministic order*.
  4064.  
  4065.      Indeed, for example for `INSERT ... SELECT' with no `ORDER BY',
  4066.      the `SELECT' may return rows in a different order (which will
  4067.      result in a row having different ranks, hence getting a different
  4068.      number in the `auto_increment' column), depending on the choices
  4069.      made by the optimisers on the master and slave. A query will be
  4070.      optimised differently on the master and slave only if :
  4071.  
  4072.         - The files used by the two queries are not exactly the same;
  4073.           for example `OPTIMIZE TABLE' was run on the master tables and
  4074.           not on the slave tables (to fix this, since MySQL 4.1.1,
  4075.           `OPTIMIZE', `ANALYZE' and `REPAIR' are written to the binary
  4076.           log).
  4077.  
  4078.         - The table is stored in a different storage engine on the
  4079.           master than on the slave (one can run with different storage
  4080.           engines on the slave and master: for example InnoDB on the
  4081.           master and MyISAM on the slave, if the slave has less
  4082.           available disk space).
  4083.  
  4084.         - The MySQL buffers' sizes (`key_buffer_size' etc) are
  4085.           different on the master and slave.
  4086.  
  4087.         - The master and slave run different MySQL versions, and the
  4088.           optimiser code is different between these versions.
  4089.  
  4090.      This problem may also affect database restoration using
  4091.      `mysqlbinlog|mysql'.
  4092.  
  4093.      The easiest way to avoid this problem in all cases is add an
  4094.      `ORDER BY' clause to such non-deterministic queries to ensure that
  4095.      the rows are always stored/modified in the same order.  In future
  4096.      MySQL versions we will automatically add an `ORDER BY' clause when
  4097.      needed.
  4098.  
  4099.  
  4100. The following problems are known and will be fixed in due time:
  4101.  
  4102.    * `LIKE' is not `multi-byte character' safe. Comparison is done
  4103.      character by character.
  4104.  
  4105.    *  When using `RPAD' function, or any other string function that ends
  4106.      up adding blanks to the right, in a query that has to use temporary
  4107.      table to be resolved, then all resulting strings will be RTRIM'ed.
  4108.      This is an example of the query:
  4109.  
  4110.      `SELECT    RPAD(t1.field1, 50, ' ') AS f2,    RPAD(t2.field2, 50, '
  4111.      ') AS f1  FROM    table1 as t1     LEFT JOIN table2 AS t2 ON
  4112.      t1.record=t2.joinID ORDER BY t2.record;'
  4113.  
  4114.      Final result of this bug is that use will not be able to get
  4115.      blanks on the right side of the resulting field.
  4116.  
  4117.      The above behaviour exists in all versions of MySQL.
  4118.  
  4119.      The reason for this is due to the fact that HEAP tables, which are
  4120.      used first for temporary tables, are not capable of handling
  4121.      VARCHAR columns.
  4122.  
  4123.      This behaviour will be fixed in one of the 4.1 series releases.
  4124.  
  4125.    * Because of how table definitions files are stored one can't use
  4126.      character 255 (`CHAR(255)') in table names, column names or enums.
  4127.      This is scheduled to be fixed in version 5.1 when we have new table
  4128.      definition format files.
  4129.  
  4130.    * When using `SET CHARACTER SET', one can't use translated
  4131.      characters in database, table, and column names.
  4132.  
  4133.    * One can't use `_' or `%' with `ESCAPE' in `LIKE ... ESCAPE'.
  4134.  
  4135.    * If you have a `DECIMAL' column with a  number stored in different
  4136.      formats (+01.00, 1.00, 01.00), `GROUP BY' may regard each value as
  4137.      a different value.
  4138.  
  4139.    * `DELETE FROM merge_table' used without a `WHERE' will only clear
  4140.      the mapping for the table, not delete everything in the mapped
  4141.      tables.
  4142.  
  4143.    * You cannot build the server in another directory when using
  4144.      MIT-pthreads. Because this requires changes to MIT-pthreads, we
  4145.      are not likely to fix this. *Note MIT-pthreads::.
  4146.  
  4147.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  4148.      or `DISTINCT'. Only the first `max_sort_length' bytes (default
  4149.      1024) are used when comparing `BLOB's in these cases.  This can be
  4150.      changed with the `-O max_sort_length' option to `mysqld'. A
  4151.      workaround for most cases is to use a substring: `SELECT DISTINCT
  4152.      LEFT(blob,2048) FROM tbl_name'.
  4153.  
  4154.    * Calculation is done with `BIGINT' or `DOUBLE' (both are normally
  4155.      64 bits long). It depends on the function which precision one
  4156.      gets. The general rule is that bit functions are done with `BIGINT'
  4157.      precision, `IF', and `ELT()' with `BIGINT' or `DOUBLE' precision
  4158.      and the rest with `DOUBLE' precision.  One should try to avoid
  4159.      using unsigned long long values if they resolve to be bigger than
  4160.      63 bits (9223372036854775807) for anything else than bit fields.
  4161.      MySQL Server 4.0 has better `BIGINT' handling than 3.23.
  4162.  
  4163.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  4164.      have all trailing spaces removed when retrieved. For `CHAR' types
  4165.      this is okay, and may be regarded as a feature according to
  4166.      SQL-92. The bug is that in MySQL Server, `VARCHAR' columns are
  4167.      treated the same way.
  4168.  
  4169.    * You can only have up to 255 `ENUM' and `SET' columns in one table.
  4170.  
  4171.    * In `MIN()', `MAX()' and other aggregate functions, MySQL currently
  4172.      compares `ENUM' and `SET' columns by their string value rather
  4173.      than by the string's relative position in the set.
  4174.  
  4175.    * `mysqld_safe' redirects all messages from `mysqld' to the `mysqld'
  4176.      log.  One problem with this is that if you execute `mysqladmin
  4177.      refresh' to close and reopen the log, `stdout' and `stderr' are
  4178.      still redirected to the old log.  If you use `--log' extensively,
  4179.      you should edit `mysqld_safe' to log to `'hostname'.err' instead
  4180.      of `'hostname'.log' so you can easily reclaim the space for the
  4181.      old log by deleting the old one and executing `mysqladmin refresh'.
  4182.  
  4183.    * In the `UPDATE' statement, columns are updated from left to right.
  4184.      If you refer to an updated column, you will get the updated value
  4185.      instead of the original value. For example:
  4186.  
  4187.           mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
  4188.  
  4189.      This will update `KEY' with `2' instead of with `1'.
  4190.  
  4191.    * You can't use temporary tables more than once in the same query.
  4192.      For example, the following doesn't work:
  4193.  
  4194.           mysql> SELECT * FROM temporary_table, temporary_table AS t2;
  4195.  
  4196.    * `RENAME' doesn't work with `TEMPORARY' tables or tables used in a
  4197.      `MERGE' table.
  4198.  
  4199.    * The optimiser may handle `DISTINCT' differently if you are using
  4200.      'hidden' columns in a join or not.  In a join, hidden columns are
  4201.      counted as part of the result (even if they are not shown) while in
  4202.      normal queries hidden columns don't participate in the `DISTINCT'
  4203.      comparison.  We will probably change this in the future to never
  4204.      compare the hidden columns when executing `DISTINCT'.
  4205.  
  4206.      An example of this is:
  4207.  
  4208.           SELECT DISTINCT mp3id FROM band_downloads
  4209.                  WHERE userid = 9 ORDER BY id DESC;
  4210.  
  4211.      and
  4212.  
  4213.           SELECT DISTINCT band_downloads.mp3id
  4214.                  FROM band_downloads,band_mp3
  4215.                  WHERE band_downloads.userid = 9
  4216.                  AND band_mp3.id = band_downloads.mp3id
  4217.                  ORDER BY band_downloads.id DESC;
  4218.  
  4219.      In the second case you may in MySQL Server 3.23.x get two
  4220.      identical rows in the result set (because the hidden `id' column
  4221.      may differ).
  4222.  
  4223.      Note that this happens only for queries where you don't have the
  4224.      ORDER BY columns in the result, something that you are not allowed
  4225.      to do in SQL-92.
  4226.  
  4227.    * Because MySQL Server allows you to work with table types that don't
  4228.      support transactions, and thus can't `rollback' data, some things
  4229.      behave a little differently in MySQL Server than in other SQL
  4230.      servers.  This is just to ensure that MySQL Server never needs to
  4231.      do a rollback for an SQL command.  This may be a little awkward at
  4232.      times as column values must be checked in the application, but
  4233.      this will actually give you a nice speed increase as it allows
  4234.      MySQL Server to do some optimisations that otherwise would be very
  4235.      hard to do.
  4236.  
  4237.      If you set a column to an incorrect value, MySQL Server will,
  4238.      instead of doing a rollback, store the `best possible value' in
  4239.      the column:
  4240.  
  4241.         - If you try to store a value outside the range in a numerical
  4242.           column, MySQL Server will instead store the smallest or
  4243.           biggest possible value in the column.
  4244.  
  4245.         - If you try to store a string that doesn't start with a number
  4246.           into a numerical column, MySQL Server will store 0 into it.
  4247.  
  4248.         - If you try to store `NULL' into a column that doesn't take
  4249.           `NULL' values, MySQL Server will store 0 or `''' (empty
  4250.           string) in it instead. (This behaviour can, however, be
  4251.           changed with the -DDONT_USE_DEFAULT_FIELDS compile option.)
  4252.  
  4253.         - MySQL allows you to store some wrong date values into `DATE'
  4254.           and `DATETIME' columns (like 2000-02-31 or 2000-02-00).  The
  4255.           idea is that it's not the SQL server job to validate date.
  4256.           If MySQL can store a date and retrieve exactly the same date,
  4257.           then MySQL will store the date. If the date is totally wrong
  4258.           (outside the server's ability to store it), then the special
  4259.           date value 0000-00-00 will be stored in the column.
  4260.  
  4261.         - If you set an `ENUM' column to an unsupported value, it will
  4262.           be set to the error value `empty string', with numeric value
  4263.           0.
  4264.  
  4265.         - If you set a `SET' column to an unsupported value, the value
  4266.           will be ignored.
  4267.  
  4268.  
  4269.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  4270.      in some cases the `PROCEDURE' will not transform the columns.
  4271.  
  4272.    * Creation of a table of type `MERGE' doesn't check if the underlying
  4273.      tables are of compatible types.
  4274.  
  4275.    * MySQL Server can't yet handle `NaN', `-Inf', and `Inf' values in
  4276.      double. Using these will cause problems when trying to export and
  4277.      import data. We should as an intermediate solution change `NaN' to
  4278.      `NULL' (if possible) and `-Inf' and `Inf' to the minimum
  4279.      respective maximum possible `double' value.
  4280.  
  4281.    * `LIMIT' on negative numbers are treated as big positive numbers.
  4282.  
  4283.    * If you use `ALTER TABLE' to first add a `UNIQUE' index to a table
  4284.      used in a `MERGE' table and then use `ALTER TABLE' to add a normal
  4285.      index on the `MERGE' table, the key order will be different for
  4286.      the tables if there was an old key that was not unique in the
  4287.      table. This is because `ALTER TABLE' puts `UNIQUE' keys before
  4288.      normal keys to be able to detect duplicate keys as early as
  4289.      possible.
  4290.  
  4291. The following are known bugs in earlier versions of MySQL:
  4292.  
  4293.    * You can get a hung thread if you do a `DROP TABLE' on a table that
  4294.      is one among many tables that is locked with `LOCK TABLES'.
  4295.  
  4296.    * In the following case you can get a core dump:
  4297.  
  4298.         - Delayed insert handler has pending inserts to a table.
  4299.  
  4300.         - `LOCK table' with `WRITE'.
  4301.  
  4302.         - `FLUSH TABLES'.
  4303.  
  4304.    * Before MySQL Server Version 3.23.2 an `UPDATE' that updated a key
  4305.      with a `WHERE' on the same key may have failed because the key was
  4306.      used to search for records and the same row may have been found
  4307.      multiple times:
  4308.  
  4309.           UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
  4310.  
  4311.      A workaround is to use:
  4312.  
  4313.           mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
  4314.  
  4315.      This will work because MySQL Server will not use an index on
  4316.      expressions in the `WHERE' clause.
  4317.  
  4318.    * Before MySQL Server Version 3.23, all numeric types were treated as
  4319.      fixed-point fields. That means you had to specify how many decimals
  4320.      a floating-point field shall have. All results were returned with
  4321.      the correct number of decimals.
  4322.  
  4323. For platform-specific bugs, see the sections about compiling and
  4324. porting.
  4325.  
  4326. MySQL and The Future (The TODO)
  4327. ===============================
  4328.  
  4329. This section summarises the features that we plan to implement in
  4330. `MySQL Server'. The lists are broken up per version, and the items are
  4331. approximately in the order they will be done.
  4332.  
  4333. *Note*: If you are an enterprise level user with an urgent need for a
  4334. particular feature, please contact <sales@mysql.com> to discuss
  4335. sponsoring options. Targeted financing by one or more companies allows
  4336. us to allocate additional resources for that specific purpose.  One
  4337. example of a feature sponsored in the past is replication.
  4338.  
  4339. New Features Planned For 4.1
  4340. ----------------------------
  4341.  
  4342. The features below are not yet implemented in MySQL 4.1, but are planned
  4343. for implementation before MySQL 4.1 moves into its beta phase.  For a
  4344. list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  4345. features::.
  4346.  
  4347.    * Stable OpenSSL support (MySQL 4.0 supports rudimentary, not 100%
  4348.      tested, support for OpenSSL).
  4349.  
  4350.    * Character set casts and syntax for handling multiple character
  4351.      sets.
  4352.  
  4353.    * More testing of prepared statements and multiple characters sets
  4354.      for one table.
  4355.  
  4356. Development of other things has already shifted to the 5.0 tree.
  4357.  
  4358. New Features Planned For 5.0
  4359. ----------------------------
  4360.  
  4361. The following features are planned for inclusion into MySQL 5.0.  Note
  4362. that because we have many developers that are working on different
  4363. projects, there will also be many additional features. There is also a
  4364. small chance that some of these features will be added to MySQL 4.1.
  4365. For a list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  4366. features::.
  4367.  
  4368. For those wishing to take a look at the bleeding edge of MySQL
  4369. development, we have made our BitKeeper repository for MySQL version
  4370. 5.0 publicly available.  *Note Installing source tree::.
  4371.  
  4372. Stored Procedures
  4373.         * Stored procedures are currently being implemented.  This
  4374.           effort is based on SQL-99, which has a basic syntax similar
  4375.           (but not identical) to Oracle PL/SQL. We will also implement
  4376.           the SQL-99 framework to hook in external languages, and
  4377.           (where possible) compatibility with, for example, PL/SQL and
  4378.           T-SQL.
  4379.  
  4380. New functionality
  4381.         * Elementary cursor support.
  4382.  
  4383.         * Visible `RTREE' index for MyISAM tables.  In 4.1 RTREE
  4384.           indexes are used internally for geometrical data, but not
  4385.           directly usable.
  4386.  
  4387.         * Dynamic length rows for HEAP tables.
  4388.  
  4389. Standards compliance, portability and migration
  4390.         * Add true `VARCHAR' support (there is already support for this
  4391.           in `MyISAM').
  4392.  
  4393. Speed enhancements
  4394.         * `SHOW COLUMNS FROM table_name' (used by `mysql' client to
  4395.           allow expansions of column names) should not open the table,
  4396.           only the definition file. This will require less memory and
  4397.           be much faster.
  4398.  
  4399.         * Allow `DELETE' on `MyISAM' tables to use the record cache.
  4400.           To do this, we need to update the threads record cache when
  4401.           we update the `.MYD' file.
  4402.  
  4403.         * Better in-memory (`HEAP') tables:
  4404.              * Dynamic size rows.
  4405.  
  4406.              * Faster row handling (less copying).
  4407.  
  4408. Internationalisation
  4409.         * When using `SET CHARACTER SET' we should translate the whole
  4410.           query at once and not only strings. This will enable users to
  4411.           use the translated characters in database, table, and column
  4412.           names.
  4413.  
  4414. Usability enhancements
  4415.         * Resolving the issue of `RENAME TABLE' on a table used in an
  4416.           active `MERGE' table possibly corrupting the table.
  4417.  
  4418. New Features Planned For 5.1
  4419. ----------------------------
  4420.  
  4421. New functionality
  4422.         * `FOREIGN KEY' support for all table types.
  4423.  
  4424.         * Column-level constraints.
  4425.  
  4426.         * Fail-safe replication.
  4427.  
  4428.         * Online backup with very low performance penalty.  The online
  4429.           backup will make it easy to add a new replication slave
  4430.           without taking down the master.
  4431.  
  4432. Speed enhancements
  4433.         * New text based table definition file format (`.frm' files)
  4434.           and a table cache for table definitions.  This will enable us
  4435.           to do faster queries of table structures and do more
  4436.           efficient foreign key support.
  4437.  
  4438.         * Optimise `BIT' type to take 1 bit (now `BIT' takes 1 char).
  4439.  
  4440. Usability enhancements
  4441.         * Add options to the client/server protocol to get progress
  4442.           notes for long running commands.
  4443.  
  4444.         * Implement `RENAME DATABASE'. To make this safe for all
  4445.           storage engines, it should work as follows:
  4446.              * Create the new database.
  4447.  
  4448.              * For every table do a rename of the table to another
  4449.                database, as we do with the `RENAME' command.
  4450.  
  4451.              * Drop the old database.
  4452.  
  4453.         * New internal file interface change.  This will make all file
  4454.           handling much more general and make it easier to add
  4455.           extensions like RAID.  (The current implementation is a hack.)
  4456.  
  4457. New Features Planned For The Near Future
  4458. ----------------------------------------
  4459.  
  4460. New functionality
  4461.         * Oracle-like `CONNECT BY PRIOR ...' to search tree-like
  4462.           (hierarchical) structures.
  4463.  
  4464.         * Add all missing SQL-92 and ODBC 3.0 types.
  4465.  
  4466.         * Add `SUM(DISTINCT)'.
  4467.  
  4468.         * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do
  4469.           a concurrent insert at the end of the file if the file is
  4470.           read-locked.
  4471.  
  4472.         * Allow update of variables in `UPDATE' statements. For example:
  4473.           `UPDATE TABLE foo SET @a=a+b,a=@a, b=@a+c'.
  4474.  
  4475.         * Change when user variables are updated so that one can use
  4476.           them with `GROUP BY', as in the following example: `SELECT
  4477.           id, @a:=COUNT(*), SUM(sum_col)/@a FROM table_name GROUP BY
  4478.           id'.
  4479.  
  4480.         * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  4481.           `TIMESTAMP' and `AUTO_INCREMENT' fields.
  4482.  
  4483.         * Added `LOAD DATA INFILE ... UPDATE' syntax.
  4484.              * For tables with primary keys, if the data contains the
  4485.                primary key, entries matching that primary key are
  4486.                updated from the remainder of the columns. However,
  4487.                columns *missing* from the incoming data feed are not
  4488.                touched.
  4489.  
  4490.              * For tables with primary keys that are missing some part
  4491.                of the key in the incoming data stream, or that have no
  4492.                primary key, the feed is treated as a `LOAD DATA INFILE
  4493.                ... REPLACE INTO' now.
  4494.  
  4495.         * Make `LOAD DATA INFILE' understand syntax like:
  4496.                LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
  4497.                     TEXT_FIELDS (text_field1, text_field2, text_field3)
  4498.                     SET table_field1=CONCAT(text_field1, text_field2),
  4499.                         table_field3=23
  4500.                     IGNORE text_field3
  4501.           This can be used to skip over extra columns in the text file,
  4502.           or update columns based on expressions of the read data.
  4503.  
  4504.         * New functions for working with `SET' type columns:
  4505.              * `ADD_TO_SET(value,set)'
  4506.  
  4507.              * `REMOVE_FROM_SET(value,set)'
  4508.  
  4509.         * If you abort `mysql' in the middle of a query, you should open
  4510.           another connection and kill the old running query.
  4511.           Alternatively, an attempt should be made to detect this in
  4512.           the server.
  4513.  
  4514.         * Add a storage engine interface for table information so that
  4515.           you can use it as a system table. This would be a bit slow if
  4516.           you requested information about all tables, but very
  4517.           flexible.  `SHOW INFO FROM tbl_name' for basic table
  4518.           information should be implemented.
  4519.  
  4520.         * Allow `SELECT a FROM crash_me LEFT JOIN crash_me2 USING (a)';
  4521.           in this case `a' is assumed to come from the `crash_me' table.
  4522.  
  4523.         * `DELETE' and `REPLACE' options to the `UPDATE' statement
  4524.           (this will delete rows when one gets a duplicate key error
  4525.           while updating).
  4526.  
  4527.         * Change the format of `DATETIME' to store fractions of seconds.
  4528.  
  4529.         * Make it possible to use the new GNU regexp library instead of
  4530.           the current one (the GNU library should be much faster than
  4531.           the old one).
  4532.  
  4533. Standards compliance, portability and migration
  4534.         * Don't add automatic `DEFAULT' values to columns.  Give an
  4535.           error when using an `INSERT' that doesn't contain a column
  4536.           that doesn't have a `DEFAULT'.
  4537.  
  4538.         * Add `ANY()', `EVERY()', and `SOME()' group functions. In
  4539.           standard SQL these work only on boolean columns, but we can
  4540.           extend these to work on any columns/expressions by applying:
  4541.           value == 0 -> FALSE and value <> 0 -> TRUE.
  4542.  
  4543.         * Fix that the type for `MAX(column)' is the same as the column
  4544.           type:
  4545.                mysql> CREATE TABLE t1 (a DATE);
  4546.                mysql> INSERT INTO t1 VALUES (NOW());
  4547.                mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
  4548.                mysql> SHOW COLUMNS FROM t2;
  4549.  
  4550. Speed enhancements
  4551.         * Don't allow more than a defined number of threads to run
  4552.           MyISAM recover at the same time.
  4553.  
  4554.         * Change `INSERT ... SELECT' to optionally use concurrent
  4555.           inserts.
  4556.  
  4557.         * Add an option to periodically flush key pages for tables with
  4558.           delayed keys if they haven't been used in a while.
  4559.  
  4560.         * Allow join on key parts (optimisation issue).
  4561.  
  4562.         * Add simulation of `pread()'/`pwrite()' on Windows to enable
  4563.           concurrent inserts.
  4564.  
  4565.         * A logfile analyser that could parse out information about
  4566.           which tables are hit most often, how often multi-table joins
  4567.           are executed, etc.  It should help users identify areas or
  4568.           table design that could be optimised to execute much more
  4569.           efficient queries.
  4570.  
  4571. Internationalisation
  4572.  
  4573. Usability enhancements
  4574.         * Return the original field types() when doing `SELECT
  4575.           MIN(column) ... GROUP BY'.
  4576.  
  4577.         * Make it possible to specify `long_query_time' with a
  4578.           granularity in microseconds.
  4579.  
  4580.         * Link the `myisampack' code into the server, enabling a PACK or
  4581.           COMPRESS command on the server.
  4582.  
  4583.         * Add a temporary key buffer cache during
  4584.           `INSERT/DELETE/UPDATE' so that we can gracefully recover if
  4585.           the index file gets full.
  4586.  
  4587.         * If you perform an `ALTER TABLE' on a table that is symlinked
  4588.           to another disk, create temporary tables on this disk.
  4589.  
  4590.         * Implement a `DATE/DATETIME' type that handles time zone
  4591.           information properly so that dealing with dates in different
  4592.           time zones is easier.
  4593.  
  4594.         * Fix configure so that one can compile all libraries (like
  4595.           `MyISAM') without threads.
  4596.  
  4597.         * Allow SQL variables in `LIMIT', like in `LIMIT @a,@b'.
  4598.  
  4599.         * Automatic output from `mysql' to a web browser.
  4600.  
  4601.         * `LOCK DATABASES' (with various options).
  4602.  
  4603.         * Many more variables for `SHOW STATUS'.  Records reads and
  4604.           updates.  Selects on 1 table and selects with joins.  Mean
  4605.           number of tables in select. Number of `ORDER BY' and `GROUP
  4606.           BY' queries.
  4607.  
  4608.         * `mysqladmin copy database new-database'; requires `COPY'
  4609.           command to be added to `mysqld'.
  4610.  
  4611.         * Processlist should show number of queries/threads.
  4612.  
  4613.         * `SHOW HOSTS' for printing information about the hostname
  4614.           cache.
  4615.  
  4616.         * Change table names from empty strings to `NULL' for
  4617.           calculated columns.
  4618.  
  4619.         * Don't use `Item_copy_string' on numerical values to avoid
  4620.           number->string->number conversion in case of: `SELECT
  4621.           COUNT(*)*(id+0) FROM table_name GROUP BY id'
  4622.  
  4623.         * Change so that `ALTER TABLE' doesn't abort clients that
  4624.           execute `INSERT DELAYED'.
  4625.  
  4626.         * Fix so that when columns are referenced in an `UPDATE' clause,
  4627.           they contain the old values from before the update started.
  4628.  
  4629. New operating systems
  4630.         * Port of the MySQL code to QNX.
  4631.  
  4632.         * Port of the MySQL clients to LynxOS.
  4633.  
  4634. New Features Planned For The Mid-Term Future
  4635. --------------------------------------------
  4636.  
  4637.    * Implement function:
  4638.      `get_changed_tables(timeout,table1,table2,...)'.
  4639.  
  4640.    * Change reading through tables to use memmap when possible. Now only
  4641.      compressed tables use memmap.
  4642.  
  4643.    * Make the automatic timestamp code nicer.  Add timestamps to the
  4644.      update log with `SET TIMESTAMP=#;'.
  4645.  
  4646.    * Use read/write mutex in some places to get more speed.
  4647.  
  4648.    * Simple views (stepwise implementation up to full functionality).
  4649.      *Note ANSI diff Views::.
  4650.  
  4651.    * Automatically close some tables if a table, temporary table, or
  4652.      temporary files gets error 23 (not enough open files).
  4653.  
  4654.    * When one finds a field=#, change all occurrences of field to #.
  4655.      Now this is only done for some simple cases.
  4656.  
  4657.    * Change all const expressions with calculated expressions if
  4658.      possible.
  4659.  
  4660.    * Optimise key = expression. At the moment only key = field or key =
  4661.      constant are optimised.
  4662.  
  4663.    * Join some of the copy functions for nicer code.
  4664.  
  4665.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  4666.      better error messages (5 days).
  4667.  
  4668.    * Change the parser to use only one rule per different number of
  4669.      arguments in function.
  4670.  
  4671.    * Use of full calculation names in the order part (for ACCESS97).
  4672.  
  4673.    * `MINUS', `INTERSECT', and `FULL OUTER JOIN'.  (Currently `UNION'
  4674.      [in 4.0] and `LEFT|RIGHT OUTER JOIN' are supported.)
  4675.  
  4676.    * `SQL_OPTION MAX_SELECT_TIME=#' to put a time limit on a query.
  4677.  
  4678.    * Make the update log write to a database.
  4679.  
  4680.    * Enhance `LIMIT' to allow retrieval of data from the end of a
  4681.      result set.
  4682.  
  4683.    * Alarm around client connect/read/write functions.
  4684.  
  4685.    * Please note the changes to `mysqld_safe': according to FSSTND
  4686.      (which Debian tries to follow) PID files should go into
  4687.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  4688.      be nice if you could put the "DATADIR" in the first declaration of
  4689.      "pidfile" and "log", so the placement of these files can be
  4690.      changed with a single statement.
  4691.  
  4692.    * Allow a client to request logging.
  4693.  
  4694.    * Add use of `zlib()' for `gzip'-ed files to `LOAD DATA INFILE'.
  4695.  
  4696.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  4697.  
  4698.    * Change to use semaphores when counting threads.  One should first
  4699.      implement a semaphore library to MIT-pthreads.
  4700.  
  4701.    * Don't assign a new `AUTO_INCREMENT' value when one sets a column
  4702.      to 0.  Use `NULL' instead.
  4703.  
  4704.    * Add full support for `JOIN' with parentheses.
  4705.  
  4706.    * As an alternative for one thread/connection manage a pool of
  4707.      threads to handle the queries.
  4708.  
  4709.    * Allow one to get more than one lock with `GET_LOCK'.  When doing
  4710.      this, one must also handle the possible deadlocks this change will
  4711.      introduce.
  4712.  
  4713. Time is given according to amount of work, not real time.
  4714.  
  4715. New Features We Don't Plan To Do
  4716. --------------------------------
  4717.  
  4718.    * Nothing; we aim toward full compliance with SQL-92/SQL-99.
  4719.  
  4720. MySQL Installation
  4721. ******************
  4722.  
  4723. This chapter describes how to obtain and install MySQL:
  4724.  
  4725.    * For a list of sites from which you can obtain MySQL, see *Note
  4726.      Getting MySQL: Getting MySQL.
  4727.  
  4728.    * To see which platforms are supported, see *Note Which OS::. Please
  4729.      note that not all supported systems are equally good for running
  4730.      MySQL on them.  On some it is much more robust and efficient than
  4731.      others--see *Note Which OS:: for details.
  4732.  
  4733.    * Several versions of MySQL are available in both binary and source
  4734.      distributions.  We also provide public access to our current
  4735.      source tree for those who want to see our most recent developments
  4736.      and help us test new code.  To determine which version and type of
  4737.      distribution you should use, see *Note Which version::. When in
  4738.      doubt, use a binary distribution.
  4739.  
  4740.    * Installation instructions for binary and source distributions are
  4741.      described in *Note Installing binary::, and *Note Installing
  4742.      source::.  Each set of instructions includes a section on
  4743.      system-specific problems you may run into.
  4744.  
  4745.    * For post-installation procedures, see *Note Post-installation::.
  4746.      These procedures apply whether you install MySQL using a binary or
  4747.      source distribution.
  4748.  
  4749. Quick Standard Installation of MySQL
  4750. ====================================
  4751.  
  4752. This chapter covers the installation of MySQL on platforms where we
  4753. offer packages using the native packaging format of the respective
  4754. platform. However, binary distributions of MySQL are available for many
  4755. other platforms as well, see *Note Installing binary:: for generic
  4756. installation instructions for these packages that apply to all
  4757. platforms.
  4758.  
  4759. See *Note General Installation Issues:: for more information on what
  4760. other binary distributions are available on how to obtain them.
  4761.  
  4762. Installing MySQL on Windows
  4763. ---------------------------
  4764.  
  4765. The MySQL server for Windows is available in two distribution formats:
  4766.  
  4767.    * The binary distribution contains a setup program that installs
  4768.      everything you need so that you can start the server immediately.
  4769.  
  4770.    * The source distribution contains all the code and support files
  4771.      for building the executables using the VC++ 6.0 compiler.  *Note
  4772.      Windows source build::.
  4773.  
  4774.  
  4775. Generally speaking, you should use the binary distribution. It's
  4776. simpler, and you need no additional tools to get MySQL up and running.
  4777.  
  4778. You will need the following:
  4779.  
  4780.    * A 32-bit Windows Operating System such as 9x, Me, NT, 2000, or XP.
  4781.      The NT family (Windows NT, 2000, and XP) permits you to run the
  4782.      MySQL server as a service. *Note NT start::.
  4783.  
  4784.      If you need tables with a size larger than 4 GB, install MySQL on
  4785.      an NTFS or newer filesystem. Don't forget to use `MAX_ROWS' and
  4786.      `AVG_ROW_LENGTH' when you create tables.  *Note `CREATE TABLE':
  4787.      CREATE TABLE.
  4788.  
  4789.    * TCP/IP protocol support.
  4790.  
  4791.    * A copy of the MySQL binary distribution for Windows, which can be
  4792.      downloaded from `http://www.mysql.com/downloads/'.
  4793.  
  4794.      Note: The distribution files are supplied with a zipped format and
  4795.      we recommend the use of an adequate FTP client with resume feature
  4796.      to avoid corruption of files during the download process.
  4797.  
  4798.    * A `ZIP' program to unpack the distribution file.
  4799.  
  4800.    * Enough space on the hard drive to unpack, install, and create the
  4801.      databases in accordance with your requirements.
  4802.  
  4803.    * If you plan to connect to the MySQL server via ODBC, you will also
  4804.      need the `MyODBC' driver. *Note ODBC::.
  4805.  
  4806.  
  4807. Installing the Binaries
  4808. .......................
  4809.  
  4810.   1. If you are working on an NT/2000/XP server, log on as a user with
  4811.      administrator privileges.
  4812.  
  4813.   2. If you are doing an upgrade of an earlier MySQL installation, it
  4814.      is necessary to stop the current server. If you are running the
  4815.      server as a service, stop it using this command:
  4816.  
  4817.           C:\> NET STOP MySQL
  4818.  
  4819.      Otherwise, stop the server like this:
  4820.  
  4821.           C:\mysql\bin> mysqladmin -u root shutdown
  4822.  
  4823.   3. On NT/2000/XP machines, if you want to change the server executable
  4824.      (for example, `-max' or `-nt'), it is also necessary to remove the
  4825.      service:
  4826.  
  4827.           C:\mysql\bin> mysqld --remove
  4828.  
  4829.   4. Exit the `WinMySQLadmin' program if it is running.
  4830.  
  4831.   5. Unzip the distribution file to a temporary directory.
  4832.  
  4833.   6. Run the `setup.exe' program to begin the installation process.  If
  4834.      you want to install into another directory than the default
  4835.      (`C:\mysql'), use the `Browse' button to specify your preferred
  4836.      directory.
  4837.  
  4838.   7. Finish the install process.
  4839.  
  4840.  
  4841. Preparing the Windows MySQL Environment
  4842. .......................................
  4843.  
  4844. Starting with MySQL 3.23.38, the Windows distribution includes both the
  4845. normal and the MySQL-Max server binaries.  Here is a list of the
  4846. different MySQL servers from which you can choose:
  4847.  
  4848. *Binary*       *Description*
  4849. `mysqld'       Compiled with full debugging and automatic memory
  4850.                allocation checking, symbolic links, `InnoDB', and `BDB'
  4851.                tables.
  4852. `mysqld-opt'   Optimised binary with no support for transactional tables
  4853.                in version 3.23. For version 4.0, `InnoDB' is enabled.
  4854. `mysqld-nt'    Optimised binary for NT/2000/XP with support for named
  4855.                pipes.
  4856. `mysqld-max'   Optimised binary with support for symbolic links,
  4857.                `InnoDB' and `BDB' tables.
  4858. `mysqld-max-nt'Like `mysqld-max', but compiled with support for named
  4859.                pipes.
  4860.  
  4861. All of the preceding binaries are optimised for modern Intel processors
  4862. but should work on any Intel processor >= i386.
  4863.  
  4864. When run on a version of Windows that supports named pipes (NT, 2000,
  4865. XP), the `mysqld-nt' and `mysqld-max-nt' servers support named pipe
  4866. connections.  However, starting from 3.23.50, named pipes are enabled
  4867. only if you start these servers with the `--enable-named-pipe' option.
  4868. (The servers can be run on Windows 98 or Me, but TCP/IP must be
  4869. installed, and named pipe connections cannot be used. On Windows 95,
  4870. these servers cannot be used.)
  4871.  
  4872. You will find it helpful to use an option file to specify your MySQL
  4873. configuration under the following circumstances:
  4874.  
  4875.    * The installation or data directories are different from the default
  4876.      locations (`C:\mysql' and `C:\mysql\data').
  4877.  
  4878.    * You need to tune the server settings.  For example, if you want to
  4879.      use the `InnoDB' transactional tables in MySQL version 3.23, you
  4880.      need to manually create two new directories to hold the `InnoDB'
  4881.      data and log files--such as, `C:\ibdata' and `C:\iblogs'.  You
  4882.      will also need to add some extra lines to the option file, as
  4883.      described in *Note `InnoDB' start: InnoDB start.  (As of MySQL
  4884.      4.0, InnoDB will create its datafiles and log files in the data
  4885.      directory by default. This means you need not configure InnoDB
  4886.      explicitly, though you may still wish to do so.)
  4887.  
  4888.  
  4889. On Windows, the MySQL installer places the data directory directly under
  4890. the directory where you install MySQL.  If you would like to use a data
  4891. directory in a different location, you should copy the entire contents
  4892. of the `data' directory to the new location. For example, the default
  4893. installation places MySQL in `C:\mysql' and the data directory in
  4894. `C:\mysql\data'. If you want to use a data directory of `E:\mydata',
  4895. you must copy `C:\mysql\data' there. You will also need to use a
  4896. `--datadir' option to specify the location of the new data directory.
  4897.  
  4898. Normally you can use the `WinMySQLAdmin' tool to edit the option file
  4899. `my.ini'.  In this case you don't have to worry about the following
  4900. discussion.
  4901.  
  4902. There are two option files with the same function: `C:\my.cnf', and the
  4903. `my.ini' file in the Windows directory.  (This directory typically is
  4904. named something like `C:\WINDOWS' or `C:\WinNT'.  You can determine its
  4905. exact location from the value of the `WINDIR' environment variable.)
  4906. MySQL looks first for the `my.ini' file, then for the `my.cnf' file.
  4907. However, to avoid confusion, it's best if you use only one of these
  4908. files. Both files are plain text.
  4909.  
  4910. If your PC uses a boot loader where the `C:' drive isn't the boot drive,
  4911. your only option is to use the `my.ini' file.  Also note that if you
  4912. use the `WinMySQLAdmin' tool, it uses only the `my.ini' file.  The
  4913. `\mysql\bin' directory contains a help file with instructions for using
  4914. this tool.
  4915.  
  4916. Using the `notepad' program, create the option file and edit the
  4917. `[mysqld]' section to specify values for the `basedir' and `datadir'
  4918. parameters:
  4919.  
  4920.      [mysqld]
  4921.      # set basedir to your installation path, for example, C:/mysql
  4922.      basedir=the_install_path
  4923.      # set datadir to the location of your data directory,
  4924.      # for example, C:/mysql/data or D:/mydata/data
  4925.      datadir=the_data_path
  4926.  
  4927. Note that Windows pathnames should be specified in option files using
  4928. forward slashes rather than backslashes.  If you do use backslashes, you
  4929. must double them.
  4930.  
  4931. Now you are ready to test starting the server.
  4932.  
  4933. Starting the Server for the First Time
  4934. ......................................
  4935.  
  4936. Testing is best done from a command prompt in a console window (a "DOS
  4937. window"). This way you can have the server display status messages in
  4938. the window where they are easy to see.  If something is wrong with your
  4939. configuration, these messages will make it easier for you to identify
  4940. and fix any problems.
  4941.  
  4942. Make sure you are in the directory where the server is located, then
  4943. enter this command:
  4944.  
  4945.      shell> mysqld --console
  4946.  
  4947. For servers that include `InnoDB' support, you should see the following
  4948. messages as the server starts up:
  4949.  
  4950.      InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist:
  4951.      InnoDB: a new database to be created!
  4952.      InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200
  4953.      InnoDB: Database physically writes the file full: wait...
  4954.      InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created
  4955.      InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280
  4956.      InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created
  4957.      InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280
  4958.      InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created
  4959.      InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280
  4960.      InnoDB: Doublewrite buffer not found: creating new
  4961.      InnoDB: Doublewrite buffer created
  4962.      InnoDB: creating foreign key constraint system tables
  4963.      InnoDB: foreign key constraint system tables created
  4964.      011024 10:58:25  InnoDB: Started
  4965.  
  4966. When the server finishes its startup sequence, you should see something
  4967. like this, which indicates that the server is ready to service client
  4968. connections::
  4969.  
  4970.      mysqld: ready for connections
  4971.      Version: '4.0.14-log'  socket: ''  port: 3306
  4972.  
  4973. The server will continue to write to the console any further diagnostic
  4974. output it produces.  You can open a new console window in which to run
  4975. client programs.
  4976.  
  4977. If you omit the `--console' option, the server writes diagnostic output
  4978. to the error log in the data directory. The error log is the file with
  4979. the `.err' extension.
  4980.  
  4981. For further information about running MySQL on Windows, see *Note
  4982. Windows::.
  4983.  
  4984. Installing MySQL on Linux
  4985. -------------------------
  4986.  
  4987. The recommended way to install MySQL on Linux is by using the RPM
  4988. packages. The MySQL RPMs are currently built on a SuSE Linux 7.3 system
  4989. but should work on most versions of Linux that support `rpm' and use
  4990. `glibc'.
  4991.  
  4992. If you have problems with an RPM file (for example, if you receive the
  4993. error "`Sorry, the host 'xxxx' could not be looked up'"), see *Note
  4994. Binary notes-Linux::.
  4995.  
  4996. In most cases, you only need to install the `MySQL-server' and
  4997. `MySQL-client' packages to get a functional MySQL installation. The
  4998. other packages are not required for a standard installation.  If you
  4999. want to run a MySQL Max server that has additional capabilities, you
  5000. should install the `MySQL-Max' RPM after installing the `MySQL-server'
  5001. RPM.  *Note `mysqld-max': mysqld-max.
  5002.  
  5003. If you get a dependency failure when trying to install the MySQL 4.0
  5004. packages (for example, "`error: removing these packages would break
  5005. dependencies: libmysqlclient.so.10 is needed by ...'"), you should also
  5006. install the package `MySQL-shared-compat', which includes both the
  5007. shared libraries for backward compatibility (`libmysqlclient.so.12' for
  5008. MySQL 4.0 and `libmysqlclient.so.10' for MySQL 3.23).
  5009.  
  5010. Many Linux distributions still ship with MySQL 3.23 and they usually
  5011. link applications dynamically to save disk space. If these shared
  5012. libraries are in a separate package (for example, `MySQL-shared'), it is
  5013. sufficient to simply leave this package installed and just upgrade the
  5014. MySQL server and client packages (which are statically linked and do
  5015. not depend on the shared libraries). For distributions that include the
  5016. shared libraries in the same package as the MySQL server (for example,
  5017. Red Hat Linux), you could either install our 3.23 `MySQL-shared' RPM,
  5018. or use the `MySQL-shared-compat' package instead.
  5019.  
  5020. The following RPM packages are available:
  5021.  
  5022.    * `MySQL-server-VERSION.i386.rpm'
  5023.  
  5024.      The MySQL server.  You will need this unless you only want to
  5025.      connect to a MySQL server running on another machine. Please note
  5026.      that this package was called `MySQL-VERSION.i386.rpm' before MySQL
  5027.      4.0.10.
  5028.  
  5029.    * `MySQL-Max-VERSION.i386.rpm'
  5030.  
  5031.      The MySQL Max server. This server has additional capabilities that
  5032.      the one in the `MySQL-server' RPM does not.  You must install the
  5033.      `MySQL-server' RPM first, because the `MySQL-Max' RPM depends on
  5034.      it.
  5035.  
  5036.    * `MySQL-client-VERSION.i386.rpm'
  5037.  
  5038.      The standard MySQL client programs. You probably always want to
  5039.      install this package.
  5040.  
  5041.    * `MySQL-bench-VERSION.i386.rpm'
  5042.  
  5043.      Tests and benchmarks. Requires Perl and the `DBD-mysql' module.
  5044.  
  5045.    * `MySQL-devel-VERSION.i386.rpm'
  5046.  
  5047.      The libraries and include files that are needed if you want to
  5048.      compile other MySQL clients, such as the Perl modules.
  5049.  
  5050.    * `MySQL-shared-VERSION.i386.rpm'
  5051.  
  5052.      This package contains the shared libraries (`libmysqlclient.so*')
  5053.      that certain languages and applications need to dynamically load
  5054.      and use MySQL.
  5055.  
  5056.    * `MySQL-shared-compat-VERSION.i386.rpm'
  5057.  
  5058.      This package includes the shared libraries for both MySQL 3.23 and
  5059.      MySQL 4.0. Install this package instead of `MySQL-shared', if you
  5060.      have applications installed that are dynamically linked against
  5061.      MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking
  5062.      the library dependencies. This package is available since MySQL
  5063.      4.0.13.
  5064.  
  5065.    * `MySQL-embedded-VERSION.i386.rpm'
  5066.  
  5067.      The embedded MySQL server library (from MySQL 4.0).
  5068.  
  5069.    * `MySQL-VERSION.src.rpm'
  5070.  
  5071.      This contains the source code for all of the previous packages. It
  5072.      can also be used to rebuild the RPMs on other architectures (for
  5073.      example, Alpha or SPARC).
  5074.  
  5075. To see all files in an RPM package (for example, a `MySQL-server' RPM),
  5076. run:
  5077.  
  5078.      shell> rpm -qpl MySQL-server-VERSION.i386.rpm
  5079.  
  5080. To perform a standard minimal installation, run:
  5081.  
  5082.      shell> rpm -i MySQL-server-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
  5083.  
  5084. To install just the client package, run:
  5085.  
  5086.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  5087.  
  5088. The server RPM places data under the `/var/lib/mysql' directory. The
  5089. RPM also creates the appropriate entries in `/etc/init.d/' to start the
  5090. server automatically at boot time. (This means that if you have
  5091. performed a previous installation and have made changes to its startup
  5092. script, you may want to make a copy of the script so you don't lose it
  5093. when you install a newer RPM.) See *Note Automatic start:: for more
  5094. information on how MySQL can be started automatically on system startup.
  5095.  
  5096. If you want to install the MySQL RPM on older Linux distributions that
  5097. do not support initialisation scripts in `/etc/init.d' (directly or via
  5098. a symlink), you should create a symbolic link that points to the
  5099. location where your initialisation scripts actually are installed. For
  5100. example, if that location is `/etc/rc.d/init.d', use these commands
  5101. before installing the RPM to create `/etc/init.d' as a symbolic link
  5102. that points there:
  5103.  
  5104.      shell> cd /etc ; ln -s rc.d/init.d .
  5105.  
  5106. However, all current major Linux distributions should already support
  5107. the new directory layout that uses `/etc/init.d', because it is
  5108. required for LSB (Linux Standard Base) compliance.
  5109.  
  5110. If the RPM files that you install include `MySQL-server', the `mysqld'
  5111. daemon should be up and running after installation.  You should now be
  5112. able to start using MySQL.  *Note Post-installation::.
  5113.  
  5114. If something goes wrong, you can find more information in the binary
  5115. installation chapter. *Note Installing binary::.
  5116.  
  5117. Installing MySQL on Mac OS X
  5118. ----------------------------
  5119.  
  5120. Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.2
  5121. ("Jaguar") using a Mac OS X `PKG' binary package instead of the binary
  5122. tarball distribution. Please note that older versions of Mac OS X (for
  5123. example, 10.1.x) are not supported by this package.
  5124.  
  5125. The package is located inside a disk image (`.dmg') file, that you
  5126. first need to mount by double-clicking its icon in the Finder. It should
  5127. then mount the image and display its contents.
  5128.  
  5129. *NOTE*: Before proceeding with the installation, be sure to shut down
  5130. all running MySQL server instances by either using the MySQL Manager
  5131. Application (on Mac OS X Server) or via `mysqladmin shutdown' on the
  5132. command line.
  5133.  
  5134. To actually install the MySQL PKG, double click on the package icon.
  5135. This launches the Mac OS Package Installer, which will guide you through
  5136. the installation of MySQL.
  5137.  
  5138. The Mac OS X PKG of MySQL will install itself into
  5139. `/usr/local/mysql-<version>' and will also install a symbolic link
  5140. `/usr/local/mysql', pointing to the new location. If a directory named
  5141. `/usr/local/mysql' already exists, it will be renamed to
  5142. `/usr/local/mysql.bak' first. Additionally, it will install the grant
  5143. tables in the `mysql' database by executing `mysql_install_db' after
  5144. the installation.
  5145.  
  5146. The installation layout is similar to the one of the binary
  5147. distribution; all MySQL binaries are located in the directory
  5148. `/usr/local/mysql/bin'.  The MySQL socket file is created as
  5149. `/tmp/mysql.sock' by default.  *Note Installation layouts::.
  5150.  
  5151. MySQL installation requires a Mac OS X user account named `mysql' (a
  5152. user account with this name should exist by default on Mac OS X 10.2
  5153. and up).
  5154.  
  5155. If you are running Mac OS X Server, you already have a version of MySQL
  5156. installed:
  5157.  
  5158.    * Mac OS X Server 10.2-10.2.2 come with MySQL 3.23.51 installed
  5159.  
  5160.    * Mac OS X Server 10.2.3-10.2.6 ship with MySQL 3.23.53
  5161.  
  5162. This manual section covers the installation of the official MySQL Mac
  5163. OS X PKG only.  Make sure to read Apple's help about installing MySQL
  5164. (Run the "Help View" application, select "Mac OS X Server" help, and do
  5165. a search for "MySQL" and read the item entitled "Installing MySQL").
  5166.  
  5167. Especially note that the pre-installed version of MySQL on Mac OS X
  5168. Server is started with the command `safe_mysqld' instead of
  5169. `mysqld_safe'.
  5170.  
  5171. If you previously used Marc Liyanage's MySQL packages for Mac OS X from
  5172. `http://www.entropy.ch', you can simply follow the update instructions
  5173. for packages using the binary installation layout as given on his pages.
  5174.  
  5175. If you are upgrading from Marc's 3.23.xx versions or from the Mac OS X
  5176. Server version of MySQL to the official MySQL PKG, you also need to
  5177. convert the existing MySQL privilege tables using the
  5178. `mysql_fix_privilege_tables' script, since some new security privileges
  5179. have been added.  *Note Upgrading-from-3.23::.
  5180.  
  5181. If you would like to automatically start up MySQL during system bootup,
  5182. you also need to install the MySQL Startup Item. Starting with MySQL
  5183. 4.0.15, it is part of the Mac OS X installation disk images as a
  5184. separate installation package. Simply double-click the
  5185. `MySQLStartupItem.pkg' icon and follow the instructions to install it.
  5186.  
  5187. Note that this only has to be done once! There is no need to install the
  5188. Startup Item every time you upgrade the MySQL package.
  5189.  
  5190. The Startup Item will be installed into `/Library/StartupItems/MySQL'.
  5191. It adds a variable `MYSQLCOM=-YES-' to the system configuration file
  5192. `/etc/hostconfig'. If you would like to disable the automatic startup
  5193. of MySQL, simply change this variable to `MYSQLCOM=-NO-'.
  5194.  
  5195. On Mac OS X Server, the Startup Item installation script will
  5196. automatically disable the startup of the default MySQL installation by
  5197. changing the variable `MYSQL' in `/etc/hostconfig' to `MYSQL=-NO-'. This
  5198. is to avoid conflicts on bootup. However, it does not shut down an
  5199. already running MySQL server.
  5200.  
  5201. After the installation, you can start up MySQL by running the following
  5202. commands in a terminal window. Please note that you need to have
  5203. administrator privileges to perform this task.
  5204.  
  5205. If you have installed the Startup Item:
  5206.  
  5207.      shell> sudo /Library/StartupItems/MySQL/MySQL start
  5208.      (Enter your password, if necessary)
  5209.      (Press Control-D or enter "exit" to exit the shell)
  5210.  
  5211. If you don't use the Startup Item, enter the following command sequence:
  5212.  
  5213.      shell> cd /usr/local/mysql
  5214.      shell> sudo ./bin/mysqld_safe
  5215.      (Enter your password, if necessary)
  5216.      (Press Control-Z)
  5217.      shell> bg
  5218.      (Press Control-D or enter "exit" to exit the shell)
  5219.  
  5220. You should now be able to connect to the MySQL server, for example, by
  5221. running `/usr/local/mysql/bin/mysql'.
  5222.  
  5223. If you installed MySQL for the first time, *please remember to set a
  5224. password for the MySQL `root' user!*
  5225.  
  5226. This is done with the following two commands:
  5227.  
  5228.      /usr/local/mysql/bin/mysqladmin -u root password <password>
  5229.      /usr/local/mysql/bin/mysqladmin -u root -h `hostname` password <password>
  5230.  
  5231. You might want to also add aliases to your shell's resource file to
  5232. access `mysql' and `mysqladmin' from the command line:
  5233.  
  5234.      alias mysql '/usr/local/mysql/bin/mysql'
  5235.      alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
  5236.  
  5237. Alternatively, you could simply add `/usr/local/mysql/bin' to your
  5238. `PATH' environment variable, for example, by adding the following to
  5239. `$HOME/.tcshrc':
  5240.  
  5241.      setenv PATH ${PATH}:/usr/local/mysql/bin
  5242.  
  5243. Please note that installing a new MySQL PKG does not remove the
  5244. directory of an older installation. Unfortunately, the Mac OS X
  5245. Installer does not yet offer the functionality required to properly
  5246. upgrade previously installed packages.
  5247.  
  5248. After you have copied over the MySQL database files from the previous
  5249. version and have successfully started the new version, you should
  5250. consider removing the old installation files to save disk space.
  5251. Additionally, you should also remove older versions of the Package
  5252. Receipt directories located in `/Library/Receipts/mysql-<version>.pkg'.
  5253.  
  5254. Installing MySQL on NetWare
  5255. ---------------------------
  5256.  
  5257. As of version 4.0.11, the MySQL server is available for Novell NetWare
  5258. in binary package form. In order to host MySQL, the NetWare server must
  5259. meet these requirements:
  5260.  
  5261.    * NetWare version 6.5, or NetWare 6.0 with Support Pack 3 installed
  5262.      (You can obtain this at
  5263.      `http://support.novell.com/filefinder/13659/index.html').  The
  5264.      system must meet Novell's minimum requirements to run the
  5265.      respective version of NetWare.
  5266.  
  5267.    * MySQL data, as well as the binaries themselves, must be installed
  5268.      on an NSS volume; traditional volumes are not supported.
  5269.  
  5270. The binary package for NetWare can be obtained at
  5271. `http://www.mysql.com/downloads/'.
  5272.  
  5273. If you are running MySQL on NetWare 6.0, we strongly suggest that you
  5274. use the `--skip-external-locking' option on the command line. It will
  5275. also be neccesary to use `CHECK TABLE' and `REPAIR TABLE' instead of
  5276. `myisamchk', because `myisamchk' makes use of external locking.
  5277. External locking is known to have problems on NetWare 6.0; the problem
  5278. has been eliminated in NetWare 6.5.
  5279.  
  5280. Installing the MySQL for NetWare Binaries
  5281. .........................................
  5282.  
  5283.   1. If you are upgrading from a prior installation, stop the MySQL
  5284.      server.  This is done from the server console, using:
  5285.  
  5286.           SERVER:  mysqladmin -u root shutdown
  5287.  
  5288.   2. Log on to the target server from a client machine with access to
  5289.      the location where you will install MySQL.
  5290.  
  5291.   3. Extract the binary package zip file onto the server. Be sure to
  5292.      allow the paths in the zip file to be used. It is safe to simply
  5293.      extract the file to `SYS:\'.
  5294.  
  5295.      If you are upgrading from a prior installation, you may need to
  5296.      copy the data directory (for example, `SYS:MYSQL\DATA') now, as
  5297.      well as `my.cnf' if you have customised it. You can then delete
  5298.      the old copy of MySQL.
  5299.  
  5300.   4. You may wish to rename the directory to something more consistent
  5301.      and easy to use. We recommend using `SYS:MYSQL'; examples in the
  5302.      manual will use this to refer to the installation directory in
  5303.      general.
  5304.  
  5305.   5. At the server console, add a search path for the directory
  5306.      containing the MySQL NLMs. For example:
  5307.  
  5308.           SERVER:  SEARCH ADD SYS:MYSQL\BIN
  5309.  
  5310.   6. Install the initial database, if needed, by executing
  5311.      `mysql_install_db' at the server console.
  5312.  
  5313.   7. Start the MySQL server using `mysqld_safe' at the server console.
  5314.  
  5315.   8. To finish the installation, you should also add the following
  5316.      commands to `autoexec.ncf'. For example, if your MySQL
  5317.      installation is in `SYS:MYSQL' and you want MySQL to start
  5318.      automatically, you could add these lines:
  5319.  
  5320.           #Starts the MySQL 4.0.x database server
  5321.           SEARCH ADD SYS:MYSQL\BIN
  5322.           MYSQLD_SAFE
  5323.  
  5324.      If you are using NetWare 6.0, you should add the
  5325.      `--skip-external-locking' flag:
  5326.  
  5327.           #Starts the MySQL 4.0.x database server
  5328.           SEARCH ADD SYS:MYSQL\BIN
  5329.           MYSQLD_SAFE --skip-external-locking
  5330.  
  5331.  
  5332. If there was an existing installation of MySQL on the server, be sure
  5333. to check for existing MySQL startup commands in `autoexec.ncf', and
  5334. edit or delete them as necessary.
  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 up-to-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. Verifying Package Integrity Using `MD5 Checksums' or `GnuPG'
  5353. ------------------------------------------------------------
  5354.  
  5355. After you have downloaded the MySQL package that suits your needs and
  5356. before you attempt to install it, you should make sure it is intact and
  5357. has not been tampered with.
  5358.  
  5359. MySQL AB offers two means of integrity checking: `MD5 checksums' and
  5360. cryptographic signatures using `GnuPG', the `GNU Privacy Guard'.
  5361.  
  5362. Verifying the `MD5 Checksum'
  5363. ----------------------------
  5364.  
  5365. After you have downloaded the package, you should check, if the MD5
  5366. checksum matches the one provided on the MySQL download pages. Each
  5367. package has an individual checksum, that you can verify with the
  5368. following command:
  5369.  
  5370.      shell> md5sum <package>
  5371.  
  5372. Note, that not all operating systems support the `md5sum' command - on
  5373. some it is simply called `md5', others do not ship it at all. On Linux,
  5374. it is part of the `GNU Text Utilities' package, which is available for
  5375. a wide range of platforms. You can download the source code from
  5376. `http://www.gnu.org/software/textutils/' as well. If you have `OpenSSL'
  5377. installed, you can also use the command `openssl md5 <package>'
  5378. instead. A DOS/Windows implementation of the `md5' command is available
  5379. from `http://www.fourmilab.ch/md5/'.
  5380.  
  5381. Example:
  5382.      shell> md5sum mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz
  5383.      155836a7ed8c93aee6728a827a6aa153
  5384.                      mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz
  5385.  
  5386. You should check, if the resulting checksum matches the one printed on
  5387. the download page right below the respective package.
  5388.  
  5389. Most mirror sites also offer a file named `MD5SUMS', which also includes
  5390. the MD5 checksums for all files included in the `Downloads' directory.
  5391. Please note however that it's very easy to modify this file and it's
  5392. not a very reliable method. If in doubt, you should consult different
  5393. mirror sites and compare the results.
  5394.  
  5395. Signature Checking Using `GnuPG'
  5396. --------------------------------
  5397.  
  5398. A more reliable method of verifying the integrity of a package is using
  5399. cryptographic signatures. MySQL AB uses the `GNU Privacy Guard'
  5400. (`GnuPG'), an `Open Source' alternative to the very well-known `Pretty
  5401. Good Privacy' (`PGP') by Phil Zimmermann.  See `http://www.gnupg.org/'
  5402. and `http://www.openpgp.org/' for more information about
  5403. `OpenPGP'/`GnuPG' and how to obtain and install `GnuPG' on your system.
  5404. Most Linux distributions already ship with `GnuPG' installed by default.
  5405.  
  5406. Beginning with MySQL 4.0.10 (February 2003), MySQL AB has started
  5407. signing their downloadable packages with `GnuPG'. Cryptographic
  5408. signatures are a much more reliable method of verifying the integrity
  5409. and authenticity of a file.
  5410.  
  5411. To verify the signature for a specific package, you first need to
  5412. obtain a copy of MySQL AB's public GPG build key <build@mysql.com>. You
  5413. can either cut and paste it directly from here, or obtain it from
  5414. `http://www.keyserver.net/'.
  5415.  
  5416.      Key ID:
  5417.      pub  1024D/5072E1F5 2003-02-03
  5418.           MySQL Package signing key (www.mysql.com) <build@mysql.com>
  5419.      Fingerprint: A4A9 4068 76FC BD3C 4567  70C8 8C71 8D3B 5072 E1F5
  5420.      
  5421.      Public Key (ASCII-armored):
  5422.      
  5423.      -----BEGIN PGP PUBLIC KEY BLOCK-----
  5424.      Version: GnuPG v1.0.6 (GNU/Linux)
  5425.      Comment: For info see http://www.gnupg.org
  5426.      
  5427.      mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3
  5428.      RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ
  5429.      fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3
  5430.      BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW
  5431.      hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV
  5432.      K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE
  5433.      kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI
  5434.      QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep
  5435.      rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFj
  5436.      a2FnZSBzaWduaW5nIGtleSAod3d3Lm15c3FsLmNvbSkgPGJ1aWxkQG15c3FsLmNv
  5437.      bT6IXQQTEQIAHQUCPj6jDAUJCWYBgAULBwoDBAMVAwIDFgIBAheAAAoJEIxxjTtQ
  5438.      cuH1cY4AnilUwTXn8MatQOiG0a/bPxrvK/gCAJ4oinSNZRYTnblChwFaazt7PF3q
  5439.      zIhMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAn1mxHijft00bKXvu
  5440.      cSo/pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJ
  5441.      YiKJAAoJELb1zU3GuiQ/lpEAoIhpp6BozKI8p6eaabzF5MlJH58pAKCu/ROofK8J
  5442.      Eg2aLos+5zEYrB/LsrkCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/l
  5443.      xaZoJYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRi
  5444.      Rjd1DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE
  5445.      7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fm
  5446.      Le11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p
  5447.      /1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqq
  5448.      a8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSaf
  5449.      anFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOW
  5450.      I39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42Lmu
  5451.      QT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt92
  5452.      6s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZ
  5453.      Whe70YGNPw1yjWJT1IhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4A
  5454.      n3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uUq/SlsQ==
  5455.      =YJkx
  5456.      -----END PGP PUBLIC KEY BLOCK-----
  5457.  
  5458. You can import this key into your public `GPG' keyring by using `gpg
  5459. --import'. See the `GPG' documentation for more info on how to work
  5460. with public keys.
  5461.  
  5462. After you have downloaded and imported the public build key, now
  5463. download your desired MySQL package and the corresponding signature,
  5464. which is also available from the download page.  The signature has the
  5465. file name extension `.asc'. For example, the signature for
  5466. `mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz' would be
  5467. `mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz.asc'.  Make sure that
  5468. both files are stored in the same directory and then run the following
  5469. command to verify the signature for this file:
  5470.  
  5471.      shell> gpg --verify <package>.asc
  5472.      
  5473.      Example:
  5474.      
  5475.      shell> gpg --verify mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz.asc
  5476.      gpg: Warning: using insecure memory!
  5477.      gpg: Signature made Mon 03 Feb 2003 08:50:39 PM MET using DSA key ID 5072E1F5
  5478.      gpg: Good signature from
  5479.           "MySQL Package signing key (www.mysql.com) <build@mysql.com>"
  5480.  
  5481. The "Good signature" message indicates that everything is all right.
  5482.  
  5483. For `RPM' packages, there is no separate signature - `RPM' packages
  5484. actually have a built-in `GPG' signature and `MD5 checksum'. You can
  5485. verify them by running the following command:
  5486.  
  5487.      shell> rpm --checksig <package>.rpm
  5488.      
  5489.      Example:
  5490.      
  5491.      shell> rpm --checksig MySQL-server-4.0.10-0.i386.rpm
  5492.      MySQL-server-4.0.10-0.i386.rpm: md5 gpg OK
  5493.  
  5494. *Note:* If you are using RPM 4.1 and it complains about `(GPG) NOT OK
  5495. (MISSING KEYS: GPG#5072e1f5)' (even though you have imported it into
  5496. your GPG public keyring), you need to import the key into the RPM
  5497. keyring first. RPM 4.1 no longer uses your GPG keyring (and GPG
  5498. itself), but rather maintains its own keyring (because it's a system
  5499. wide application and the GPG public keyring is user-specific file). To
  5500. import the MySQL public key into the RPM keyring, please use the
  5501. following command:
  5502.  
  5503.      shell> rpm --import <pubkey>
  5504.      
  5505.      Example:
  5506.      
  5507.      shell> rpm --import mysql_pubkey.asc
  5508.  
  5509. In case you notice that the `MD5 checksum' or `GPG' signatures do not
  5510. match, first try to download the respective package one more time,
  5511. maybe from another mirror site. If you repeatedly can not successfully
  5512. verify the integrity of the package, please notify us about such
  5513. incidents including the full package name and the download site you
  5514. have been using at <webmaster@mysql.com> or <build@mysql.com>.
  5515.  
  5516. Operating Systems Supported by MySQL
  5517. ------------------------------------
  5518.  
  5519. We use GNU Autoconf, so it is possible to port MySQL to all modern
  5520. systems with working Posix threads and a C++ compiler.  (To compile
  5521. only the client code, a C++ compiler is required but not threads.)  We
  5522. use and develop the software ourselves primarily on Linux (SuSE and Red
  5523. Hat), FreeBSD and Sun Solaris (Versions 8 and 9).
  5524.  
  5525. Note that for many operating systems, the native thread support works
  5526. only in the latest versions. MySQL has been reported to compile
  5527. successfully on the following operating system/thread package
  5528. combinations:
  5529.  
  5530.    * AIX 4.x, 5.x with native threads.  *Note IBM-AIX::.
  5531.  
  5532.    * Amiga.
  5533.  
  5534.    * BSDI 2.x with the MIT-pthreads package.  *Note BSDI::.
  5535.  
  5536.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  5537.  
  5538.    * SCO OpenServer with a recent port of the FSU Pthreads package.
  5539.      *Note SCO::.
  5540.  
  5541.    * SCO UnixWare 7.1.x.  *Note SCO UnixWare::.
  5542.  
  5543.    * DEC Unix 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  5544.  
  5545.    * FreeBSD 2.x with the MIT-pthreads package.  *Note FreeBSD::.
  5546.  
  5547.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  5548.  
  5549.    * FreeBSD 4.x with Linuxthreads.  *Note FreeBSD::.
  5550.  
  5551.    * HP-UX 10.20 with the DCE threads or the MIT-pthreads package.
  5552.      *Note HP-UX 10.20::.
  5553.  
  5554.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  5555.  
  5556.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  5557.      Linux::.
  5558.  
  5559.    * Mac OS X.  *Note Mac OS X::.
  5560.  
  5561.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make).
  5562.      *Note NetBSD::.
  5563.  
  5564.    * Novell NetWare 6.0.  *Note Novell NetWare::.
  5565.  
  5566.    * OpenBSD > 2.5 with native threads. OpenBSD < 2.5 with the
  5567.      MIT-pthreads package.  *Note OpenBSD::.
  5568.  
  5569.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  5570.  
  5571.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  5572.  
  5573.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  5574.      Solaris::.
  5575.  
  5576.    * SunOS 4.x with the MIT-pthreads package.  *Note Solaris::.
  5577.  
  5578.    * Tru64 Unix
  5579.  
  5580.    * Windows 9x, Me, NT, 2000 and XP.  *Note Windows::.
  5581.  
  5582. Note that not all platforms are suited equally well for running MySQL.
  5583. How well a certain platform is suited for a high-load mission-critical
  5584. MySQL server is determined by the following factors:
  5585.  
  5586.    * General stability of the thread library. A platform may have
  5587.      excellent reputation otherwise, but if the thread library is
  5588.      unstable in the code that is called by MySQL, even if everything
  5589.      else is perfect, MySQL will be only as stable as the thread
  5590.      library.
  5591.  
  5592.    * The ability of the kernel and/or thread library to take advantage
  5593.      of *SMP* on multi-processor systems. In other words, when a process
  5594.      creates a thread, it should be possible for that thread to run on
  5595.      a different CPU than the original process.
  5596.  
  5597.    * The ability of the kernel and/or the thread library to run many
  5598.      threads which acquire/release a mutex over a short critical region
  5599.      frequently without excessive context switches. In other words, if
  5600.      the implementation of `pthread_mutex_lock()' is too anxious to
  5601.      yield CPU time, this will hurt MySQL tremendously. If this issue
  5602.      is not taken care of, adding extra CPUs will actually make MySQL
  5603.      slower.
  5604.  
  5605.    * General filesystem stability/performance.
  5606.  
  5607.    * Ability of the filesystem to deal with large files at all and deal
  5608.      with them efficiently, if your tables are big.
  5609.  
  5610.    * Our level of expertise here at MySQL AB with the platform. If we
  5611.      know a platform well, we introduce platform-specific
  5612.      optimisations/fixes enabled at compile time. We can also provide
  5613.      advice on configuring your system optimally for MySQL.
  5614.  
  5615.    * The amount of testing of similar configurations we have done
  5616.      internally.
  5617.  
  5618.    * The number of users that have successfully run MySQL on that
  5619.      platform in similar configurations. If this number is high, the
  5620.      chances of hitting some platform-specific surprises are much
  5621.      smaller.
  5622.  
  5623. Based on the preceding criteria, the best platforms for running MySQL
  5624. at this point are x86 with SuSE Linux 8.2, 2.4 kernel, and ReiserFS (or
  5625. any similar Linux distribution) and SPARC with Solaris (2.7-9). FreeBSD
  5626. comes third, but we really hope it will join the top club once the
  5627. thread library is improved. We also hope that at some point we will be
  5628. able to include all other platforms on which MySQL compiles, runs okay,
  5629. but not quite with the same level of stability and performance, into
  5630. the top category. This will require some effort on our part in
  5631. cooperation with the developers of the OS/library components MySQL
  5632. depends upon. If you are interested in making one of those components
  5633. better, are in a position to influence their development, and need more
  5634. detailed instructions on what MySQL needs to run better, send an e-mail
  5635. to the MySQL internals mailing list.  *Note Mailing-list::.
  5636.  
  5637. Please note that the preceding comparison is not to say that one OS is
  5638. better or worse than the other in general. We are talking about
  5639. choosing a particular OS for a dedicated purpose--running MySQL, and
  5640. compare platforms in that regard only. With this in mind, the result of
  5641. this comparison would be different if we included more issues into it.
  5642. And in some cases, the reason one OS is better than the other could
  5643. simply be that we have put forth more effort into testing on and
  5644. optimising for that particular platform.  We are just stating our
  5645. observations to help you decide on which platform to use MySQL on in
  5646. your setup.
  5647.  
  5648. Which MySQL Version to Use
  5649. --------------------------
  5650.  
  5651. The first decision to make is whether you want to use the latest
  5652. development release or the last production (stable) release:
  5653.  
  5654.    * Normally, if you are beginning to use MySQL for the first time or
  5655.      trying to port it to some system for which there is no binary
  5656.      distribution, we recommend going with the production release
  5657.      (currently version 4.0).  Note that all MySQL releases are checked
  5658.      with the MySQL benchmarks and an extensive test suite before each
  5659.      release (even the development releases).
  5660.  
  5661.    * Otherwise, if you are running an old system and want to upgrade,
  5662.      but don't want to take chances with a non-seamless upgrade, you
  5663.      should upgrade to the latest in the same branch you are using
  5664.      (where only the last version number is newer than yours).  We have
  5665.      tried to fix only fatal bugs and make small, relatively safe
  5666.      changes to that version.
  5667.  
  5668. The second decision to make is whether you want to use a source
  5669. distribution or a binary distribution.  In most cases you should
  5670. probably use a binary distribution, if one exists for your platform, as
  5671. this generally will be easier to install than a source distribution.
  5672.  
  5673. In the following cases you probably will be better off with a source
  5674. installation:
  5675.  
  5676.    * If you want to install MySQL at some explicit location.  (The
  5677.      standard binary distributions are "ready to run" at any place, but
  5678.      you may want to get even more flexibility).
  5679.  
  5680.    * To be able to satisfy different user requirements, we are
  5681.      providing two different binary versions: one compiled with the
  5682.      non-transactional storage engines (a small, fast binary), and one
  5683.      configured with the most important extended options like
  5684.      transaction-safe tables.  Both versions are compiled from the same
  5685.      source distribution.  All native `MySQL' clients can connect to
  5686.      both MySQL versions.
  5687.  
  5688.      The extended MySQL binary distribution is marked with the `-max'
  5689.      suffix and is configured with the same options as `mysqld-max'.
  5690.      *Note `mysqld-max': mysqld-max.
  5691.  
  5692.      If you want to use the `MySQL-Max' RPM, you must first install the
  5693.      standard `MySQL-server' RPM.
  5694.  
  5695.    * If you want to configure `mysqld' with some extra features that are
  5696.      not in the standard binary distributions.  Here is a list of the
  5697.      most common extra options that you may want to use:
  5698.  
  5699.         * `--with-innodb' (default for MySQL 4.0 and onwards)
  5700.  
  5701.         * `--with-berkeley-db' (not available on all platforms)
  5702.  
  5703.         * `--with-raid'
  5704.  
  5705.         * `--with-libwrap'
  5706.  
  5707.         * `--with-named-z-libs' (This is done for some of the binaries)
  5708.  
  5709.         * `--with-debug[=full]'
  5710.  
  5711.    * The default binary distribution is normally compiled with support
  5712.      for all character sets and should work on a variety of processors
  5713.      from the same processor family.
  5714.  
  5715.      If you want a faster MySQL server you may want to recompile it
  5716.      with support for only the character sets you need, use a better
  5717.      compiler (like `pgcc'), or use compiler options that are better
  5718.      optimised for your processor.
  5719.  
  5720.    * If you have found a bug and reported it to the MySQL development
  5721.      team you will probably receive a patch that you need to apply to
  5722.      the source distribution to get the bug fixed.
  5723.  
  5724.    * If you want to read (and/or modify) the C and C++ code that makes
  5725.      up MySQL, you should get a source distribution.  The source code is
  5726.      always the ultimate manual.  Source distributions also contain more
  5727.      tests and examples than binary distributions.
  5728.  
  5729. The MySQL naming scheme uses release numbers that consist of three
  5730. numbers and a suffix.  For example, a release name like
  5731. `mysql-4.1.0-alpha' is interpreted like this:
  5732.  
  5733.    * The first number (`4') is the major version and also describes the
  5734.      file format.  All Version 4 releases have the same file format.
  5735.  
  5736.    * The second number (`1') is the release level.
  5737.  
  5738.    * The third number (`0') is the version number within the release
  5739.      level.  This is incremented for each new distribution.  Usually you
  5740.      want the latest version for the release level you have chosen.
  5741.  
  5742.    * The suffix (`alpha') indicates the stability level of the release.
  5743.      The possible suffixes are:
  5744.  
  5745.         - `alpha' indicates that the release contains some large
  5746.           section of new code that hasn't been 100% tested.  Known bugs
  5747.           (usually there are none) should be documented in the News
  5748.           section.  *Note News::.  There are also new commands and
  5749.           extensions in most alpha releases.  Active development that
  5750.           may involve major code changes can occur on an alpha release,
  5751.           but everything will be tested before doing a release.  There
  5752.           should be no known bugs in any MySQL release.
  5753.  
  5754.         - `beta' means that all new code has been tested.  No major new
  5755.           features that could cause corruption on old code are added.
  5756.           There should be no known bugs.  A version changes from alpha
  5757.           to beta when there haven't been any reported fatal bugs
  5758.           within an alpha version for at least a month and we don't
  5759.           plan to add any features that could make any old command more
  5760.           unreliable.
  5761.  
  5762.         - `gamma' is a beta that has been around a while and seems to
  5763.           work fine.  Only minor fixes are added.  This is what many
  5764.           other companies call a release.
  5765.  
  5766.         - If there is no suffix, it means that the version has been run
  5767.           for a while at many different sites with no reports of bugs
  5768.           other than platform-specific bugs.  Only critical bug fixes
  5769.           are applied to the release. This is what we call a production
  5770.           (stable) release.
  5771.  
  5772. In the MySQL development process, multiple versions co-exist and are at
  5773. a different stage. Naturally, relevant bugfixes from an earlier series
  5774. also propagate upward.
  5775.    * For the old stable/production series `3.23', new versions are only
  5776.      released for critical bugs.
  5777.  
  5778.    * The current series `4.0') is stable/production quality, with new
  5779.      versions released for bugfixes. No new features are added that
  5780.      could influence the code stability.
  5781.  
  5782.    * In the alpha branch `4.1' major new features are added. Sources
  5783.      and binaries are available for use and testing on development
  5784.      systems.
  5785.  
  5786.    * The development branch `5.0' is only available from the BitKeeper
  5787.      tree.
  5788.  
  5789. All versions of MySQL are run through our standard tests and benchmarks
  5790. to ensure that they are relatively safe to use.  Because the standard
  5791. tests are extended over time to check for all previously found bugs,
  5792. the test suite keeps getting better.
  5793.  
  5794. Note that all releases have been tested at least with:
  5795.  
  5796. An internal test suite
  5797.      This is part of a production system for a customer.  It has many
  5798.      tables with hundreds of megabytes of data.
  5799.  
  5800. The MySQL benchmark suite
  5801.      This runs a range of common queries.  It is also a test to see
  5802.      whether the latest batch of optimisations actually made the code
  5803.      faster.  *Note MySQL Benchmarks::.
  5804.  
  5805. The `crash-me' test
  5806.      This tries to determine what features the database supports and
  5807.      what its capabilities and limitations are.  *Note MySQL
  5808.      Benchmarks::.
  5809.  
  5810. Another test is that we use the newest MySQL version in our internal
  5811. production environment, on at least one machine.  We have more than 100
  5812. gigabytes of data to work with.
  5813.  
  5814. Installation Layouts
  5815. --------------------
  5816.  
  5817. This section describes the default layout of the directories created by
  5818. installing binary and source distributions.
  5819.  
  5820. A binary distribution is installed by unpacking it at the installation
  5821. location you choose (typically `/usr/local/mysql') and creates the
  5822. following directories in that location:
  5823.  
  5824. *Directory* *Contents of directory*
  5825. `bin'       Client programs and the
  5826.             `mysqld' server
  5827. `data'      Log files, databases
  5828. `docs'      Documentation, ChangeLog
  5829. `include'   Include (header) files
  5830. `lib'       Libraries
  5831. `scripts'   `mysql_install_db'
  5832. `share/mysql'Error message files
  5833. `sql-bench' Benchmarks
  5834.  
  5835. A source distribution is installed after you configure and compile it.
  5836. By default, the installation step installs files under `/usr/local', in
  5837. the following subdirectories:
  5838.  
  5839. *Directory* *Contents of directory*
  5840. `bin'       Client programs and scripts
  5841. `include/mysql'Include (header) files
  5842. `info'      Documentation in Info format
  5843. `lib/mysql' Libraries
  5844. `libexec'   The `mysqld' server
  5845. `share/mysql'Error message files
  5846. `sql-bench' Benchmarks and `crash-me' test
  5847. `var'       Databases and log files
  5848.  
  5849. Within an installation directory, the layout of a source installation
  5850. differs from that of a binary installation in the following ways:
  5851.  
  5852.    * The `mysqld' server is installed in the `libexec' directory rather
  5853.      than in the `bin' directory.
  5854.  
  5855.    * The data directory is `var' rather than `data'.
  5856.  
  5857.    * `mysql_install_db' is installed in the `/usr/local/bin' directory
  5858.      rather than in `/usr/local/mysql/scripts'.
  5859.  
  5860.    * The header file and library directories are `include/mysql' and
  5861.      `lib/mysql' rather than `include' and `lib'.
  5862.  
  5863. You can create your own binary installation from a compiled source
  5864. distribution by executing the script `scripts/make_binary_distribution'.
  5865.  
  5866. How and When Updates Are Released
  5867. ---------------------------------
  5868.  
  5869. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  5870. this with other MySQL users.  We try to make a release when we have
  5871. very useful features that others seem to have a need for.
  5872.  
  5873. We also try to help out users who request features that are easy to
  5874. implement.  We take note of what our licensed users want to have, and
  5875. we especially take note of what our extended e-mail supported customers
  5876. want and try to help them out.
  5877.  
  5878. No one has to download a new release.  The News section will tell you if
  5879. the new release has something you really want.  *Note News::.
  5880.  
  5881. We use the following policy when updating MySQL:
  5882.  
  5883.    * For each minor update, the last number in the version string is
  5884.      incremented.  When there are major new features or minor
  5885.      incompatibilities with previous versions, the second number in the
  5886.      version string is incremented.  When the file format changes, the
  5887.      first number is increased.
  5888.  
  5889.    * Production (stable-tested) releases are meant to appear about 1-2
  5890.      times a year, but if small bugs are found, a release with only bug
  5891.      fixes will be released.
  5892.  
  5893.    * Working releases/bug fixes to old releases are meant to appear
  5894.      about every 1-8 weeks.
  5895.  
  5896.    * Binary distributions for some platforms will be made by us for
  5897.      major releases.  Other people may make binary distributions for
  5898.      other systems but probably less frequently.
  5899.  
  5900.    * We usually make patches available as soon as we have located and
  5901.      fixed small bugs. They usually are immediately available from our
  5902.      public BitKeeper repositories. They will also be included in the
  5903.      next release.
  5904.  
  5905.    * Non-critical but annoying bugs will be added to the MySQL source
  5906.      repository and they will be fixed in the next release.
  5907.  
  5908.    * If there is, by any chance, a fatal bug in a release we will make
  5909.      a new release as soon as possible.  We would like other companies
  5910.      to do this, too.
  5911.  
  5912. The current production release is Version 4.0; we have already moved
  5913. active development to Version 4.1 and 5.0.  Bugs will still be fixed in
  5914. the 4.0 version, and critical bugs also in the 3.23 series.  We don't
  5915. believe in a complete freeze, as this also leaves out bug fixes and
  5916. things that "must be done."  "Somewhat frozen" means that we may add
  5917. small things that "almost surely will not affect anything that's
  5918. already working."
  5919.  
  5920. MySQL uses a slightly different naming scheme from most other products.
  5921. In general it's relatively safe to use any version that has been out for
  5922. a couple of weeks without being replaced with a new version.  *Note
  5923. Which version::.
  5924.  
  5925. Release Philosophy - No Known Bugs in Releases
  5926. ----------------------------------------------
  5927.  
  5928. We put a lot of time and effort into making our releases bug free.  To
  5929. our knowledge, we have not released a single MySQL version with any
  5930. _known_ 'fatal' repeatable bugs.
  5931.  
  5932. A fatal bug is something that crashes MySQL under normal usage, gives
  5933. wrong answers for normal queries, or has a security problem.
  5934.  
  5935. We have documented all open problems, bugs and things that are
  5936. dependent on design decisions.  *Note Bugs::.
  5937.  
  5938. Our aim is to fix everything that is fixable, but without risking
  5939. making a stable MySQL version less stable. In certain cases, this means
  5940. we can fix an issue in the development version(s), but not in the
  5941. stable (production) version. Naturally, we document such issues so that
  5942. users are aware.
  5943.  
  5944. Here is a description of how our build process works:
  5945.    * We monitor bugs from our customer support list, the MySQL external
  5946.      mailing lists and the bugs database at `http://bugs.mysql.com/'.
  5947.  
  5948.    * All reported bugs for live versions are entered into the bugs
  5949.      database.
  5950.  
  5951.    * When we fix a bug, we always try to make a test case of it and
  5952.      include this into our test system to ensure that the bug will never
  5953.      come back. (About 90% of all fixed bugs have a test case.)
  5954.  
  5955.    * We also create test cases for all new features we add to MySQL.
  5956.  
  5957.    * Before we start to build a new MySQL release, we ensure that all
  5958.      reported repeatable bugs for the MySQL version (3.23.x, 4.0.x, etc)
  5959.      are fixed.  If something is impossible to fix (because some
  5960.      internal design decision in MySQL) we document this in the manual.
  5961.      *Note Bugs::.
  5962.  
  5963.    * We do a build on all platforms for which we support binaries (15+
  5964.      platforms) and run our test suite and benchmark suite on all of
  5965.      them.
  5966.  
  5967.    * We will not publish a binary for a platform for which the test or
  5968.      benchmark suite fails.  If it's a general error in the source, we
  5969.      fix this and do the build plus tests on all systems again, from
  5970.      scratch.
  5971.  
  5972.    * If we, during the build and test process (which takes 2-3 days),
  5973.      receive a report regarding a fatal bug (for example, one that
  5974.      causes a core dump), we fix this and restart the build process.
  5975.  
  5976.    * After publishing the binaries on `http://www.mysql.com/', we send
  5977.      out an announce email on the `mysql' and `announce' mailing lists.
  5978.      *Note Mailing-list::.  The announcement message contains a list of
  5979.      all changes to the release and any known problems with the release.
  5980.      (The 'known problems' section in the release notes has only been
  5981.      needed in a handful of releases.)
  5982.  
  5983.    * To quickly give our users access to the latest MySQL features, we
  5984.      do a new MySQL release every 4-5 weeks.
  5985.  
  5986.    * If we, after the release is done, get any bug reports that there
  5987.      was (after all) anything critically wrong with the build on a
  5988.      specific platform, we will fix this at once and build a new `'a''
  5989.      release for that platform. Thanks to our large user base, problems
  5990.      are found quickly.
  5991.  
  5992.    * Our track record for making good releases is quite good.  In the
  5993.      last 150 releases, we had to do a new build for less than 10
  5994.      releases (in 3 of these cases, the bug was a faulty glibc library
  5995.      on one of our build machines that took us a long time to track
  5996.      down).
  5997.  
  5998. MySQL Binaries Compiled by MySQL AB
  5999. -----------------------------------
  6000.  
  6001. As a service, we at MySQL AB provide a set of binary distributions of
  6002. MySQL that are compiled at our site or at sites where customers kindly
  6003. have given us access to their machines.
  6004.  
  6005. In addition to the binaries provided in platform-specific package
  6006. formats (see *Note Quick Standard Installation::), we do offer binary
  6007. distributions for a number of platforms by means of compressed tar
  6008. archives (`.tar.gz').
  6009.  
  6010. These distributions are generated using the script
  6011. `Build-tools/Do-compile' which compiles the source code and creates the
  6012. binary `tar.gz' archive using `scripts/make_binary_distribution' These
  6013. binaries are configured and built with the following compilers and
  6014. options.
  6015.  
  6016. Binaries built on MySQL AB development systems:
  6017.  
  6018. Linux 2.4.xx x86 with `gcc' 2.95.3
  6019.      `CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2
  6020.      -mcpu=pentiumpro -felide-constructors" ./configure
  6021.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6022.      --enable-thread-safe-client --enable-local-infile
  6023.      --enable-assembler --disable-shared
  6024.      --with-client-ldflags=-all-static
  6025.      --with-mysqld-ldflags=-all-static'
  6026.  
  6027. Linux 2.4.xx Intel Itanium 2 with `ecc' (Intel C++ Itanium Compiler 7.0)
  6028.      `CC=ecc CFLAGS="-O2 -tpp2 -ip -nolib_inline" CXX=ecc CXXFLAGS="-O2
  6029.      -tpp2 -ip -nolib_inline" ./configure --prefix=/usr/local/mysql
  6030.      --with-extra-charsets=complex --enable-thread-safe-client
  6031.      --enable-local-infile'
  6032.  
  6033. Linux 2.4.xx Intel Itanium with `ecc' (Intel C++ Itanium Compiler 7.0)
  6034.      `CC=ecc CFLAGS=-tpp1 CXX=ecc CXXFLAGS=-tpp1 ./configure
  6035.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6036.      --enable-thread-safe-client --enable-local-infile'
  6037.  
  6038. Linux 2.4.xx alpha with `ccc' (Compaq C V6.2-505 / Compaq C++ V6.3-006)
  6039.      `CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
  6040.      generic -noexceptions -nortti" ./configure
  6041.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6042.      --enable-thread-safe-client --enable-local-infile
  6043.      --with-mysqld-ldflags=-non_shared
  6044.      --with-client-ldflags=-non_shared --disable-shared'
  6045.  
  6046. Linux 2.4.xx s390 with `gcc' 2.95.3
  6047.      `CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors"
  6048.      ./configure --prefix=/usr/local/mysql
  6049.      --with-extra-charsets=complex --enable-thread-safe-client
  6050.      --enable-local-infile --disable-shared
  6051.      --with-client-ldflags=-all-static
  6052.      --with-mysqld-ldflags=-all-static'
  6053.  
  6054. Linux 2.4.xx x86_64 (AMD64) with `gcc' 3.2.1
  6055.      `CXX=gcc ./configure --prefix=/usr/local/mysql
  6056.      --with-extra-charsets=complex --enable-thread-safe-client
  6057.      --enable-local-infile  --disable-shared'
  6058.  
  6059. Sun Solaris 8 x86 with `gcc' 3.2.3
  6060.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6061.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6062.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6063.      --localstatedir=/usr/local/mysql/data
  6064.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6065.      --enable-thread-safe-client --enable-local-infile
  6066.      --disable-shared --with-innodb'
  6067.  
  6068. Sun Solaris 8 sparc with `gcc' 3.2
  6069.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6070.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6071.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6072.      --with-extra-charsets=complex --enable-thread-safe-client
  6073.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6074.      --with-named-curses-libs=-lcurses --disable-shared'
  6075.  
  6076. Sun Solaris 8 sparc 64bit with `gcc' 3.2
  6077.      `CC=gcc CFLAGS="-O3 -m64 -fno-omit-frame-pointer" CXX=gcc
  6078.      CXXFLAGS="-O3 -m64 -fno-omit-frame-pointer -felide-constructors
  6079.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6080.      --with-extra-charsets=complex --enable-thread-safe-client
  6081.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6082.      --with-named-curses-libs=-lcurses --disable-shared'
  6083.  
  6084. Sun Solaris 9 sparc with `gcc' 2.95.3
  6085.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6086.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6087.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6088.      --with-extra-charsets=complex --enable-thread-safe-client
  6089.      --enable-local-infile --enable-assembler
  6090.      --with-named-curses-libs=-lcurses --disable-shared'
  6091.  
  6092. Sun Solaris 9 sparc with `cc-5.0' (Sun Forte 5.0)
  6093.      `CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
  6094.      -D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
  6095.      ./configure --prefix=/usr/local/mysql
  6096.      --with-extra-charsets=complex --enable-thread-safe-client
  6097.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6098.      --enable-thread-safe-client --disable-shared'
  6099.  
  6100. IBM AIX 4.3.2 ppc with `gcc' 3.2.3
  6101.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2
  6102.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  6103.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6104.      --with-extra-charsets=complex --enable-thread-safe-client
  6105.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  6106.  
  6107. IBM AIX 4.3.3 ppc with `xlC_r' (IBM Visual Age C/C++ 6.0)
  6108.      `CC=xlc_r CFLAGS="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  6109.      CXX=xlC_r CXXFLAGS ="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  6110.      ./configure --prefix=/usr/local/mysql
  6111.      --localstatedir=/usr/local/mysql/data
  6112.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6113.      --enable-thread-safe-client --enable-local-infile
  6114.      --with-named-z-libs=no --disable-shared --with-innodb'
  6115.  
  6116. IBM AIX 5.1.0 ppc with `gcc' 3.3
  6117.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-O2
  6118.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  6119.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6120.      --with-extra-charsets=complex --with-server-suffix="-pro"
  6121.      --enable-thread-safe-client --enable-local-infile
  6122.      --with-named-z-libs=no --disable-shared'
  6123.  
  6124. HP-UX 10.20 pa-risc1.1 with `gcc' 3.1
  6125.      `CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc
  6126.      CXXFLAGS="-DHPUX -I/opt/dce /include -felide-constructors
  6127.      -fno-exceptions -fno-rtti -O3 -fPIC" ./configure
  6128.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6129.      --enable-thread-safe-client --enable-local-infile  --with-pthread
  6130.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  6131.      --disable-shared'
  6132.  
  6133. HP-UX 11.11 pa-risc2.0 64bit with `aCC' (HP ANSI C++ B3910B A.03.33)
  6134.      `CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
  6135.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6136.      --enable-thread-safe-client --enable-local-infile --disable-shared'
  6137.  
  6138. HP-UX 11.11 pa-risc2.0 32bit with `aCC' (HP ANSI C++ B3910B A.03.33)
  6139.      `CC=cc CXX=aCC CFLAGS="+DAportable" CXXFLAGS="+DAportable"
  6140.      ./configure --prefix=/usr/local/mysql
  6141.      --localstatedir=/usr/local/mysql/data
  6142.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6143.      --enable-thread-safe-client --enable-local-infile
  6144.      --disable-shared --with-innodb'
  6145.  
  6146. Apple Mac OS X 10.2 powerpc with `gcc' 3.1
  6147.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6148.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6149.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6150.      --with-extra-charsets=complex --enable-thread-safe-client
  6151.      --enable-local-infile  --disable-shared'
  6152.  
  6153. FreeBSD 4.7 i386 with `gcc' 2.95.4
  6154.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  6155.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6156.      --enable-thread-safe-client --enable-local-infile
  6157.      --enable-assembler --with-named-z-libs=not-used --disable-shared'
  6158.  
  6159. QNX Neutrino 6.2.1 i386 with `gcc' 2.95.3qnx-nto 20010315
  6160.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6161.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6162.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6163.      --with-extra-charsets=complex --enable-thread-safe-client
  6164.      --enable-local-infile  --disable-shared'
  6165.  
  6166. The following binaries are built on third-party systems kindly provided
  6167. to MySQL AB by other users. Please note that these are only provided as
  6168. a courtesy. Since MySQL AB does not have full control over these
  6169. systems, we can only provide limited support for the binaries built on
  6170. these systems.
  6171.  
  6172. SCO Unix 3.2v5.0.6 i386 with `gcc' 2.95.3
  6173.      `CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3
  6174.      -mpentium -felide-constructors" ./configure
  6175.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6176.      --enable-thread-safe-client --enable-local-infile
  6177.      --with-named-z-libs=no --enable-thread-safe-client
  6178.      --disable-shared'
  6179.  
  6180. SCO OpenUnix 8.0.0 i386 with `CC' 3.2
  6181.      `CC=cc CFLAGS="-O" CXX=CC ./configure --prefix=/usr/local/mysql
  6182.      --with-extra-charsets=complex --enable-thread-safe-client
  6183.      --enable-local-infile --with-named-z-libs=no
  6184.      --enable-thread-safe-client --disable-shared'
  6185.  
  6186. Compaq Tru64 OSF/1 V5.1 732 alpha with `cc/cxx' (Compaq C V6.3-029i / DIGITAL C++ V6.1-027)
  6187.      `CC="cc -pthread" CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline
  6188.      speed -speculate all" CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias
  6189.      -fast -inline speed -speculate all -noexceptions -nortti"
  6190.      ./configure --prefix=/usr/local/mysql
  6191.      --with-extra-charsets=complex --enable-thread-safe-client
  6192.      --enable-local-infile --with-prefix=/usr/local/mysql
  6193.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  6194.      --disable-shared --with-mysqld-ldflags=-all-static'
  6195.  
  6196. SGI Irix 6.5 IP32 with `gcc' 3.0.1
  6197.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
  6198.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6199.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6200.      --with-extra-charsets=complex --enable-thread-safe-client
  6201.      --enable-local-infile  --disable-shared'
  6202.  
  6203. FreeBSD 5.0 sparc64 with `gcc' 3.2.1
  6204.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  6205.      --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
  6206.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6207.      --enable-thread-safe-client --enable-local-infile --disable-shared
  6208.      --with-innodb'
  6209.  
  6210. The following compile options have been used for binary packages MySQL
  6211. AB used to provide in the past. These binaries are no longer being
  6212. updated, but the compile options are kept here for reference purposes.
  6213.  
  6214. Linux 2.2.xx sparc with `egcs' 1.1.2
  6215.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6216.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6217.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6218.      --with-extra-charsets=complex --enable-thread-safe-client
  6219.      --enable-local-infile --enable-assembler --disable-shared'
  6220.  
  6221. Linux 2.2.x with x686 with `gcc' 2.95.2
  6222.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  6223.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  6224.      --prefix=/usr/local/mysql --enable-assembler
  6225.      --with-mysqld-ldflags=-all-static --disable-shared
  6226.      --with-extra-charsets=complex'
  6227.  
  6228. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1
  6229.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  6230.      --prefix=/usr/local/mysql --disable-shared
  6231.      --with-extra-charsets=complex --enable-assembler'
  6232.  
  6233. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or gcc 2.95.2 and newer
  6234.      `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6235.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6236.      --with-low-memory --with-extra-charsets=complex --enable-assembler'
  6237.  
  6238. SunOS 5.6 i86pc with `gcc' 2.8.1
  6239.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6240.      --with-low-memory --with-extra-charsets=complex'
  6241.  
  6242. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1
  6243.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  6244.      --with-extra-charsets=complex'
  6245.  
  6246. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2
  6247.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6248.      --with-extra-charsets=complex'
  6249.  
  6250. AIX 2 4 with `gcc' 2.7.2.2
  6251.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6252.      --with-extra-charsets=complex'
  6253.  
  6254. Anyone who has more optimal options for any of the preceding
  6255. configurations listed can always mail them to the MySQL internals s
  6256. mailing list.  *Note Mailing-list::.
  6257.  
  6258. RPM distributions prior to MySQL Version 3.22 are user-contributed.
  6259. Beginning with Version 3.22, the RPMs are generated by us at MySQL AB.
  6260.  
  6261. If you want to compile a debug version of MySQL, you should add
  6262. `--with-debug' or `--with-debug=full' to the preceding configure lines
  6263. and remove any `-fomit-frame-pointer' options.
  6264.  
  6265. For the Windows distribution, please see *Note Windows installation::.
  6266.  
  6267. Installing a MySQL Binary Distribution
  6268. --------------------------------------
  6269.  
  6270. This chapter covers the installation of MySQL binary distributions
  6271. (`.tar.gz' Archives) for various platforms (see *Note MySQL binaries::
  6272. for a detailed list).
  6273.  
  6274. In addition to these generic packages, we also offer binaries in
  6275. platform-specific package formats for selected platforms.  See *Note
  6276. Quick Standard Installation:: for more information on how to install
  6277. these.
  6278.  
  6279. The generic MySQL binary distributions are packaged as gzip-compressed
  6280. GNU tar archives (`.tar.gz'). You need the following tools to install a
  6281. MySQL binary distribution:
  6282.  
  6283.    * GNU `gunzip' to uncompress the distribution.
  6284.  
  6285.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  6286.      to work. Some `tar' implementations that come pre-installed with
  6287.      the operating system (e.g. Sun `tar') are known to have problems
  6288.      (with long file names, for example). In that case, you should
  6289.      install GNU `tar' first.
  6290.  
  6291. If you run into problems, *please always use `mysqlbug'* when posting
  6292. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  6293. `mysqlbug' gathers system information that will help others solve your
  6294. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  6295. a solution to your problem.  You will find `mysqlbug' in the `bin'
  6296. directory after you unpack the distribution.  *Note Bug reports::.
  6297.  
  6298. The basic commands you must execute to install and use a MySQL binary
  6299. distribution are:
  6300.  
  6301.      shell> groupadd mysql
  6302.      shell> useradd -g mysql mysql
  6303.      shell> cd /usr/local
  6304.      shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  6305.      shell> ln -s full-path-to-mysql-VERSION-OS mysql
  6306.      shell> cd mysql
  6307.      shell> scripts/mysql_install_db
  6308.      shell> chown -R root  .
  6309.      shell> chown -R mysql data
  6310.      shell> chgrp -R mysql .
  6311.      shell> bin/mysqld_safe --user=mysql &
  6312.      or
  6313.      shell> bin/mysqld_safe --user=mysql &
  6314.      if you are running MySQL 4.x
  6315.  
  6316. You can add new users using the `bin/mysql_setpermission' script if you
  6317. install the `DBI' and `DBD-mysql' Perl modules.
  6318.  
  6319. A more detailed description follows.
  6320.  
  6321. To install a binary distribution, follow these steps, then proceed to
  6322. *Note Post-installation::, for post-installation setup and testing:
  6323.  
  6324.   1. Pick the directory under which you want to unpack the
  6325.      distribution, and move into it.  In the following example, we
  6326.      unpack the distribution under `/usr/local' and create a directory
  6327.      `/usr/local/mysql' into which MySQL is installed.  (The following
  6328.      instructions, therefore, assume you have permission to create
  6329.      files in `/usr/local'.  If that directory is protected, you will
  6330.      need to perform the installation as `root'.)
  6331.  
  6332.   2. Obtain a distribution file from one of the sites listed in *Note
  6333.      Getting MySQL: Getting MySQL.
  6334.  
  6335.      MySQL binary distributions are provided as compressed `tar'
  6336.      archives and have names like `mysql-VERSION-OS.tar.gz', where
  6337.      `VERSION' is a number (for example, `3.21.15'), and `OS' indicates
  6338.      the type of operating system for which the distribution is intended
  6339.      (for example, `pc-linux-gnu-i586').  Note that all binaries are
  6340.      built from the same MySQL source distribution.
  6341.  
  6342.   3. Add a user and group for `mysqld' to run as:
  6343.  
  6344.           shell> groupadd mysql
  6345.           shell> useradd -g mysql mysql
  6346.  
  6347.      These commands add the `mysql' group and the `mysql' user.  The
  6348.      syntax for `useradd' and `groupadd' may differ slightly on
  6349.      different versions of Unix.  They may also be called `adduser' and
  6350.      `addgroup'.  You may wish to call the user and group something
  6351.      else instead of `mysql'.
  6352.  
  6353.   4. Change into the intended installation directory:
  6354.  
  6355.           shell> cd /usr/local
  6356.  
  6357.   5. Unpack the distribution and create the installation directory:
  6358.  
  6359.           shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  6360.           shell> ln -s full-path-to-mysql-VERSION-OS mysql
  6361.  
  6362.      Using GNU tar, you can also replace the first line with the
  6363.      following alternative command to decompress and extract the
  6364.      distribution in one go:
  6365.  
  6366.           shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
  6367.  
  6368.      The first command creates a directory named `mysql-VERSION-OS'.
  6369.      The second command makes a symbolic link to that directory.  This
  6370.      lets you refer more easily to the installation directory as
  6371.      `/usr/local/mysql'.
  6372.  
  6373.   6. Change into the installation directory:
  6374.  
  6375.           shell> cd mysql
  6376.  
  6377.      You will find several files and subdirectories in the `mysql'
  6378.      directory.  The most important for installation purposes are the
  6379.      `bin' and `scripts' subdirectories.
  6380.  
  6381.     `bin'
  6382.           This directory contains client programs and the server You
  6383.           should add the full pathname of this directory to your `PATH'
  6384.           environment variable so that your shell finds the MySQL
  6385.           programs properly. *Note Environment variables::.
  6386.  
  6387.     `scripts'
  6388.           This directory contains the `mysql_install_db' script used to
  6389.           initialise the `mysql' database containing the grant tables
  6390.           that store the server access permissions.
  6391.  
  6392.   7. If you would like to use `mysqlaccess' and have the MySQL
  6393.      distribution in some non-standard place, you must change the
  6394.      location where `mysqlaccess' expects to find the `mysql' client.
  6395.      Edit the `bin/mysqlaccess' script at approximately line 18.
  6396.      Search for a line that looks like this:
  6397.  
  6398.           $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
  6399.  
  6400.      Change the path to reflect the location where `mysql' actually is
  6401.      stored on your system.  If you do not do this, you will get a
  6402.      `Broken pipe' error when you run `mysqlaccess'.
  6403.  
  6404.   8. Create the MySQL grant tables (necessary only if you haven't
  6405.      installed MySQL before):
  6406.           shell> scripts/mysql_install_db
  6407.  
  6408.      Note that MySQL versions older than Version 3.22.10 started the
  6409.      MySQL server when you run `mysql_install_db'.  This is no longer
  6410.      true.
  6411.  
  6412.   9. Change ownership of binaries to `root' and ownership of the data
  6413.      directory to the user that you will run `mysqld' as:
  6414.  
  6415.           shell> chown -R root  /usr/local/mysql/.
  6416.           shell> chown -R mysql /usr/local/mysql/data
  6417.           shell> chgrp -R mysql /usr/local/mysql/.
  6418.  
  6419.      The first command changes the `owner' attribute of the files to the
  6420.      `root' user, the second one changes the `owner' attribute of the
  6421.      data directory to the `mysql' user, and the third one changes the
  6422.      `group' attribute to the `mysql' group.
  6423.  
  6424.  10. If you want to install support for the Perl `DBI'/`DBD' interface,
  6425.      see *Note Perl support::.
  6426.  
  6427.  11. If you would like MySQL to start automatically when you boot your
  6428.      machine, you can copy `support-files/mysql.server' to the location
  6429.      where your system has its startup files.  More information can be
  6430.      found in the `support-files/mysql.server' script itself and in
  6431.      *Note Automatic start::.
  6432.  
  6433.  
  6434. After everything has been unpacked and installed, you should initialise
  6435. and test your distribution.
  6436.  
  6437. You can start the MySQL server with the following command:
  6438.  
  6439.      shell> bin/mysqld_safe --user=mysql &
  6440.  
  6441. Now proceed to *Note `mysqld_safe': mysqld_safe, and *Note
  6442. Post-installation::.
  6443.  
  6444. Installing a MySQL Source Distribution
  6445. ======================================
  6446.  
  6447. Before you proceed with the source installation, check first to see if
  6448. our binary is available for your platform and if it will work for you.
  6449. We put a lot of effort into making sure that our binaries are built
  6450. with the best possible options.
  6451.  
  6452. You need the following tools to build and install MySQL from source:
  6453.  
  6454.    * GNU `gunzip' to uncompress the distribution.
  6455.  
  6456.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  6457.      to work. Some `tar' implementations that come pre-installed with
  6458.      the operating system (e.g. Sun `tar') are known to have problems
  6459.      (with long file names, for example). In that case, you should
  6460.      install GNU `tar' first.
  6461.  
  6462.    * A working ANSI C++ compiler.  `gcc' >= 2.95.2, `egcs' >= 1.0.2 or
  6463.      `egcs 2.91.66', SGI C++, and SunPro C++ are some of the compilers
  6464.      that are known to work.  `libg++' is not needed when using `gcc'.
  6465.      `gcc' 2.7.x has a bug that makes it impossible to compile some
  6466.      perfectly legal C++ files, such as `sql/sql_base.cc'.  If you only
  6467.      have `gcc' 2.7.x, you must upgrade your `gcc' to be able to
  6468.      compile MySQL. `gcc' 2.8.1 is also known to have problems on some
  6469.      platforms, so it should be avoided if a new compiler exists for
  6470.      the platform.
  6471.  
  6472.      `gcc' >= 2.95.2 is recommended when compiling MySQL Version 3.23.x.
  6473.  
  6474.    * A good `make' program.  GNU `make' is always recommended and is
  6475.      sometimes required.  If you have problems, we recommend trying GNU
  6476.      `make' 3.75 or newer.
  6477.  
  6478. If you are using a recent version of `gcc', recent enough to understand
  6479. the `-fno-exceptions' option, it is *very important* that you use it.
  6480. Otherwise, you may compile a binary that crashes randomly. We also
  6481. recommend that you use `-felide-constructors' and `-fno-rtti' along
  6482. with `-fno-exceptions'. When in doubt, do the following:
  6483.  
  6484.  
  6485.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions \
  6486.             -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler \
  6487.             --with-mysqld-ldflags=-all-static
  6488.  
  6489. On most systems this will give you a fast and stable binary.
  6490.  
  6491. If you run into problems, *please always use `mysqlbug'* when posting
  6492. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  6493. `mysqlbug' gathers system information that will help others solve your
  6494. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  6495. a solution to your problem.  You will find `mysqlbug' in the `scripts'
  6496. directory after you unpack the distribution.  *Note Bug reports::.
  6497.  
  6498. Quick Installation Overview
  6499. ---------------------------
  6500.  
  6501. The basic commands you must execute to install a MySQL source
  6502. distribution are:
  6503.  
  6504.      shell> groupadd mysql
  6505.      shell> useradd -g mysql mysql
  6506.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  6507.      shell> cd mysql-VERSION
  6508.      shell> ./configure --prefix=/usr/local/mysql
  6509.      shell> make
  6510.      shell> make install
  6511.      shell> scripts/mysql_install_db
  6512.      shell> chown -R root  /usr/local/mysql
  6513.      shell> chown -R mysql /usr/local/mysql/var
  6514.      shell> chgrp -R mysql /usr/local/mysql
  6515.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  6516.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  6517.  
  6518. If your version of MySQL is older than 4.0, use `safe_mysqld' rather
  6519. than `mysqld_safe'.
  6520.  
  6521. If you want to have support for InnoDB tables, you should edit the
  6522. `/etc/my.cnf' file and remove the `#' character before the parameter
  6523. that starts with `innodb_...'.  *Note Option files::, and *Note InnoDB
  6524. start::.
  6525.  
  6526. If you start from a source RPM, do the following:
  6527.  
  6528.      shell> rpm --rebuild --clean MySQL-VERSION.src.rpm
  6529.  
  6530. This will make a binary RPM that you can install.
  6531.  
  6532. You can add new users using the `bin/mysql_setpermission' script if you
  6533. install the `DBI' and `DBD-mysql' Perl modules.
  6534.  
  6535. A more detailed description follows.
  6536.  
  6537. To install a source distribution, follow these steps, then proceed to
  6538. *Note Post-installation::, for post-installation initialisation and
  6539. testing:
  6540.  
  6541.   1. Pick the directory under which you want to unpack the
  6542.      distribution, and move into it.
  6543.  
  6544.   2. Obtain a distribution file from one of the sites listed in *Note
  6545.      Getting MySQL: Getting MySQL.
  6546.  
  6547.   3. If you are interested in using Berkeley DB tables with MySQL, you
  6548.      will need to obtain a patched version of the Berkeley DB source
  6549.      code.  Please read the chapter on Berkeley DB tables before
  6550.      proceeding.  *Note BDB::.
  6551.  
  6552.      MySQL source distributions are provided as compressed `tar'
  6553.      archives and have names like `mysql-VERSION.tar.gz', where
  6554.      `VERSION' is a number like 4.0.15.
  6555.  
  6556.   4. Add a user and group for `mysqld' to run as:
  6557.  
  6558.           shell> groupadd mysql
  6559.           shell> useradd -g mysql mysql
  6560.  
  6561.      These commands add the `mysql' group and the `mysql' user.  The
  6562.      syntax for `useradd' and `groupadd' may differ slightly on
  6563.      different versions of Unix.  They may also be called `adduser' and
  6564.      `addgroup'.  You may wish to call the user and group something
  6565.      else instead of `mysql'.
  6566.  
  6567.   5. Unpack the distribution into the current directory:
  6568.           shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
  6569.  
  6570.      This command creates a directory named `mysql-VERSION'.
  6571.  
  6572.   6. Change into the top-level directory of the unpacked distribution:
  6573.  
  6574.           shell> cd mysql-VERSION
  6575.  
  6576.      Note that currently you must configure and build MySQL from this
  6577.      top-level directory.  You cannot build it in a different directory.
  6578.  
  6579.   7. Configure the release and compile everything:
  6580.  
  6581.           shell> ./configure --prefix=/usr/local/mysql
  6582.           shell> make
  6583.  
  6584.      When you run `configure', you might want to specify some options.
  6585.      Run `./configure --help' for a list of options.  *Note `configure'
  6586.      options: configure options, discusses some of the more useful
  6587.      options.
  6588.  
  6589.      If `configure' fails, and you are going to send mail to a MySQL
  6590.      mailing list to ask for assistance, please include any lines from
  6591.      `config.log' that you think can help solve the problem.  Also
  6592.      include the last couple of lines of output from `configure' if
  6593.      `configure' aborts.  Post the bug report using the `mysqlbug'
  6594.      script.  *Note Bug reports::.
  6595.  
  6596.      If the compile fails, see *Note Compilation problems::, for help
  6597.      with a number of common problems.
  6598.  
  6599.   8. Install everything:
  6600.  
  6601.           shell> make install
  6602.  
  6603.      You might need to run this command as `root'.
  6604.  
  6605.   9. Create the MySQL grant tables (necessary only if you haven't
  6606.      installed MySQL before):
  6607.  
  6608.           shell> scripts/mysql_install_db
  6609.  
  6610.      Note that MySQL versions older than Version 3.22.10 started the
  6611.      MySQL server when you run `mysql_install_db'.  This is no longer
  6612.      true.
  6613.  
  6614.  10. Change ownership of binaries to `root' and ownership of the data
  6615.      directory to the user that you will run `mysqld' as:
  6616.  
  6617.           shell> chown -R root  /usr/local/mysql
  6618.           shell> chown -R mysql /usr/local/mysql/var
  6619.           shell> chgrp -R mysql /usr/local/mysql
  6620.  
  6621.      The first command changes the `owner' attribute of the files to the
  6622.      `root' user, the second one changes the `owner' attribute of the
  6623.      data directory to the `mysql' user, and the third one changes the
  6624.      `group' attribute to the `mysql' group.
  6625.  
  6626.  11. If you want to install support for the Perl `DBI'/`DBD' interface,
  6627.      see *Note Perl support::.
  6628.  
  6629.  12. If you would like MySQL to start automatically when you boot your
  6630.      machine, you can copy `support-files/mysql.server' to the location
  6631.      where your system has its startup files.  More information can be
  6632.      found in the `support-files/mysql.server' script itself and in
  6633.      *Note Automatic start::.
  6634.  
  6635. After everything has been installed, you should initialise and test your
  6636. distribution:
  6637.  
  6638.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  6639.  
  6640. If that command fails immediately with `mysqld daemon ended', you can
  6641. find some information in the file `mysql-data-directory/'hostname'.err'.
  6642. The likely reason is that you already have another `mysqld' server
  6643. running.  *Note Multiple servers::.
  6644.  
  6645. Now proceed to *Note Post-installation::.
  6646.  
  6647. Applying Patches
  6648. ----------------
  6649.  
  6650. Sometimes patches appear on the mailing list or are placed in the
  6651. patches area of the MySQL web site
  6652. (`http://www.mysql.com/downloads/patches.html').
  6653.  
  6654. To apply a patch from the mailing list, save the message in which the
  6655. patch appears in a file, change into the top-level directory of your
  6656. MySQL source tree, and run these commands:
  6657.  
  6658.      shell> patch -p1 < patch-file-name
  6659.      shell> rm config.cache
  6660.      shell> make clean
  6661.  
  6662. Patches from the FTP site are distributed as plain text files or as
  6663. files compressed with `gzip'.  Apply a plain patch as shown previously
  6664. for mailing list patches.  To apply a compressed patch, change into the
  6665. top-level directory of your MySQL source tree and run these commands:
  6666.  
  6667.      shell> gunzip < patch-file-name.gz | patch -p1
  6668.      shell> rm config.cache
  6669.      shell> make clean
  6670.  
  6671. After applying a patch, follow the instructions for a normal source
  6672. install, beginning with the `./configure' step.  After running the `make
  6673. install' step, restart your MySQL server.
  6674.  
  6675. You may need to bring down any currently running server before you run
  6676. `make install'.  (Use `mysqladmin shutdown' to do this.)  Some systems
  6677. do not allow you to install a new version of a program if it replaces
  6678. the version that is currently executing.
  6679.  
  6680. Typical `configure' Options
  6681. ---------------------------
  6682.  
  6683. The `configure' script gives you a great deal of control over how you
  6684. configure your MySQL distribution.  Typically you do this using options
  6685. on the `configure' command-line.  You can also affect `configure' using
  6686. certain environment variables.  *Note Environment variables::.  For a
  6687. list of options supported by `configure', run this command:
  6688.  
  6689.      shell> ./configure --help
  6690.  
  6691. Some of the more commonly-used `configure' options are described here:
  6692.  
  6693.    * To compile just the MySQL client libraries and client programs and
  6694.      not the server, use the `--without-server' option:
  6695.  
  6696.           shell> ./configure --without-server
  6697.  
  6698.      If you don't have a C++ compiler, `mysql' will not compile (it is
  6699.      the one client program that requires C++).  In this case, you can
  6700.      remove the code in `configure' that tests for the C++ compiler and
  6701.      then run `./configure' with the `--without-server' option. The
  6702.      compile step will still try to build `mysql', but you can ignore
  6703.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  6704.      tell it to continue with the rest of the build even if errors
  6705.      occur.)
  6706.  
  6707.    * If you want to get an embedded MySQL library (`libmysqld.a') you
  6708.      should use the `--with-embedded-server' option.
  6709.  
  6710.    * If you don't want your log files and database directories located
  6711.      under `/usr/local/var', use a `configure' command, something like
  6712.      one of these:
  6713.  
  6714.           shell> ./configure --prefix=/usr/local/mysql
  6715.           shell> ./configure --prefix=/usr/local \
  6716.                      --localstatedir=/usr/local/mysql/data
  6717.  
  6718.      The first command changes the installation prefix so that
  6719.      everything is installed under `/usr/local/mysql' rather than the
  6720.      default of `/usr/local'.  The second command preserves the default
  6721.      installation prefix, but overrides the default location for
  6722.      database directories (normally `/usr/local/var') and changes it to
  6723.      `/usr/local/mysql/data'.  After you have compiled MySQL, you can
  6724.      change these options with option files. *Note Option files::.
  6725.  
  6726.    * If you are using Unix and you want the MySQL socket located
  6727.      somewhere other than the default location (normally in the
  6728.      directory `/tmp' or `/var/run') use a `configure' command like
  6729.      this:
  6730.  
  6731.           shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  6732.  
  6733.      Note that the given file must be an absolute pathname.  You can
  6734.      also later change the location `mysql.sock' by using the MySQL
  6735.      option files. *Note Problems with mysql.sock::.
  6736.  
  6737.    * If you want to compile statically linked programs (for example, to
  6738.      make a binary distribution, to get more speed, or to work around
  6739.      problems with some Red Hat Linux distributions), run `configure'
  6740.      like this:
  6741.  
  6742.           shell> ./configure --with-client-ldflags=-all-static \
  6743.                      --with-mysqld-ldflags=-all-static
  6744.  
  6745.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  6746.      installed, you can tell `configure' to use `gcc' as your C++
  6747.      compiler:
  6748.  
  6749.           shell> CC=gcc CXX=gcc ./configure
  6750.  
  6751.      When you use `gcc' as your C++ compiler, it will not attempt to
  6752.      link in `libg++' or `libstdc++'.  This may be a good idea to do
  6753.      even if you have the above libraries installed, as some versions
  6754.      of these libraries have caused strange problems for MySQL users in
  6755.      the past.
  6756.  
  6757.      Here are some common environment variables to set depending on the
  6758.      compiler you are using:
  6759.  
  6760.      *Compiler*    *Recommended options*
  6761.      gcc 2.7.2.1    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
  6762.      egcs 1.0.3a    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6763.                    -fno-exceptions -fno-rtti"
  6764.      gcc 2.95.2     CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3
  6765.                    -mpentiumpro \ -felide-constructors -fno-exceptions
  6766.                    -fno-rtti"
  6767.      pgcc 2.90.29   CFLAGS="-O3 -mpentiumpro -mstack-align-double"
  6768.      or newer      CXX=gcc \ CXXFLAGS="-O3 -mpentiumpro
  6769.                    -mstack-align-double -felide-constructors \
  6770.                    -fno-exceptions -fno-rtti"
  6771.  
  6772.      In most cases you can get a reasonably optimal MySQL binary by
  6773.      using the options from the preceding table and adding the
  6774.      following options to the configure line:
  6775.  
  6776.           --prefix=/usr/local/mysql --enable-assembler \
  6777.           --with-mysqld-ldflags=-all-static
  6778.  
  6779.      The full configure line would, in other words, be something like
  6780.      the following for all recent gcc versions:
  6781.  
  6782.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  6783.           -felide-constructors -fno-exceptions -fno-rtti" ./configure \
  6784.           --prefix=/usr/local/mysql --enable-assembler \
  6785.           --with-mysqld-ldflags=-all-static
  6786.  
  6787.      The binaries we provide on the MySQL web site at
  6788.      `http://www.mysql.com/' are all compiled with full optimisation and
  6789.      should be perfect for most users.  *Note MySQL binaries::.  There
  6790.      are some things you can tweak to make an even faster binary, but
  6791.      this is only for advanced users.  *Note Compile and link options::.
  6792.  
  6793.      If the build fails and produces errors about your compiler or
  6794.      linker not being able to create the shared library
  6795.      `libmysqlclient.so.#' (`#' is a version number), you can work
  6796.      around this problem by giving the `--disable-shared' option to
  6797.      `configure'.  In this case, `configure' will not build a shared
  6798.      `libmysqlclient.so.#' library.
  6799.  
  6800.    * You can configure MySQL not to use `DEFAULT' column values for
  6801.      non-`NULL' columns (that is, columns that are not allowed to be
  6802.      `NULL'). *Note constraint NOT NULL::.
  6803.  
  6804.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  6805.  
  6806.    * By default, MySQL uses the ISO-8859-1 (Latin1) character set. To
  6807.      change the default set, use the `--with-charset' option:
  6808.           shell> ./configure --with-charset=CHARSET
  6809.      `CHARSET' may be one of `big5', `cp1251', `cp1257', `czech',
  6810.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  6811.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  6812.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  6813.      `win1251ukr'.  *Note Character sets::.
  6814.  
  6815.      If you want to convert characters between the server and the
  6816.      client, you should take a look at the `SET CHARACTER SET' command.
  6817.      *Note `SET': SET OPTION.
  6818.  
  6819.      *Warning*: If you change character sets after having created any
  6820.      tables, you will have to run `myisamchk -r -q
  6821.      --set-character-set=charset' on every table. Your indexes may be
  6822.      sorted incorrectly otherwise.  (This can happen if you install
  6823.      MySQL, create some tables, then reconfigure MySQL to use a
  6824.      different character set and reinstall it.)
  6825.  
  6826.      With the option `--with-extra-charsets=LIST' you can define which
  6827.      additional character sets should be compiled into the server.
  6828.  
  6829.      Here `LIST' is either a list of character sets separated with
  6830.      spaces, `complex' to include all characters that can't be
  6831.      dynamically loaded, or `all' to include all character sets into
  6832.      the binaries.
  6833.  
  6834.    * To configure MySQL with debugging code, use the `--with-debug'
  6835.      option:
  6836.           shell> ./configure --with-debug
  6837.      This causes a safe memory allocator to be included that can find
  6838.      some errors and that provides output about what is happening.
  6839.      *Note Debugging server::.
  6840.  
  6841.    * If your client programs are using threads, you need to also
  6842.      compile a thread-safe version of the MySQL client library with the
  6843.      `--enable-thread-safe-client' configure options. This will create a
  6844.      `libmysqlclient_r' library with which you should link your threaded
  6845.      applications.  *Note Threaded clients::.
  6846.  
  6847.    * Options that pertain to particular systems can be found in the
  6848.      system-specific section of this manual.  *Note Operating System
  6849.      Specific Notes::.
  6850.  
  6851. Installing from the Development Source Tree
  6852. -------------------------------------------
  6853.  
  6854. *Caution*: You should read this section only if you are interested in
  6855. helping us test our new code. If you just want to get MySQL up and
  6856. running on your system, you should use a standard release distribution
  6857. (either a source or binary distribution will do).
  6858.  
  6859. To obtain our most recent development source tree, use these
  6860. instructions:
  6861.  
  6862.   1. Download `BitKeeper' from
  6863.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  6864.      `Bitkeeper' 3.0 or newer to access our repository.
  6865.  
  6866.   2. Follow the instructions to install it.
  6867.  
  6868.   3. After `BitKeeper' is installed, first go to the directory you want
  6869.      to work from, and then use one of the following commands to clone
  6870.      the MySQL version branch of your choice:
  6871.  
  6872.      To clone the 3.23 (old) branch, use this command:
  6873.  
  6874.           shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
  6875.  
  6876.      To clone the 4.0 (stable/production) branch, use this command:
  6877.  
  6878.           shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
  6879.  
  6880.      To clone the 4.1 alpha branch, use this command:
  6881.  
  6882.           shell> bk clone bk://mysql.bkbits.net/mysql-4.1 mysql-4.1
  6883.  
  6884.      To clone the 5.0 development branch, use this command:
  6885.  
  6886.           shell> bk clone bk://mysql.bkbits.net/mysql-5.0 mysql-5.0
  6887.  
  6888.      In the preceding examples the source tree will be set up in the
  6889.      `mysql-3.23/', `mysql-4.0/', `mysql-4.1/', or `mysql-5.0/'
  6890.      subdirectory of your current directory.
  6891.  
  6892.      If you are behind a firewall and can only initiate HTTP
  6893.      connections, you can also use `BitKeeper' via HTTP.
  6894.  
  6895.      If you are required to use a proxy server, simply set the
  6896.      environment variable `http_proxy' to point to your proxy:
  6897.  
  6898.           shell> export http_proxy="http://your.proxy.server:8080/"
  6899.  
  6900.      Now, simply replace the `bk://' with `http://' when doing a clone.
  6901.      Example:
  6902.  
  6903.           shell> bk clone http://mysql.bkbits.net/mysql-4.1 mysql-4.1
  6904.  
  6905.      The initial download of the source tree may take a while,
  6906.      depending on the speed of your connection - please be patient.
  6907.  
  6908.   4. You will need *GNU* `make', `autoconf 2.53 (or newer)', `automake
  6909.      1.5', `libtool 1.4', and `m4' to run the next set of commands.
  6910.      Even though many operating system already come with their own
  6911.      implementation of `make', chances are high that the compilation
  6912.      fails with strange error messages. Therefore it is highly
  6913.      recommended to use GNU `make' (sometimes also named `gmake') by
  6914.      all means.
  6915.  
  6916.      Fortunately, a large number of operating systems already ship with
  6917.      the GNU toolchain preinstalled or supply installable packages of
  6918.      these. In any case, they can also be downloaded from the following
  6919.      locations:
  6920.  
  6921.         * <http://www.gnu.org/software/autoconf/>
  6922.  
  6923.         * <http://www.gnu.org/software/automake/>
  6924.  
  6925.         * <http://www.gnu.org/software/libtool/>
  6926.  
  6927.         * <http://www.gnu.org/software/make/>
  6928.  
  6929.      If you are trying to configure MySQL 4.1, you will also need GNU
  6930.      `bison 1.75'.  Older versions of `bison' may report this error:
  6931.      `sql_yacc.yy:#####: fatal error: maximum table size (32767)
  6932.      exceeded'. Note: the maximum table size is not actually exceeded,
  6933.      the error is caused by bugs in these earlier `bison' versions.
  6934.  
  6935.      Versions of MySQL before version 4.1 may also compile with other
  6936.      `yacc' implementations (e.g. BSD `yacc' 91.7.30). For later
  6937.      versions, GNU `bison' is a requirement.
  6938.  
  6939.      The typical command to do in a shell is:
  6940.  
  6941.           cd mysql-4.0
  6942.           bk -r edit
  6943.           aclocal; autoheader; autoconf; automake
  6944.           (cd innobase ; aclocal; autoheader; autoconf; automake) # for InnoDB
  6945.           (cd bdb/dist ; sh s_all ) # for Berkeley DB
  6946.           ./configure  # Add your favorite options here
  6947.           make
  6948.  
  6949.      If you get some strange error during this stage, check that you
  6950.      really have `libtool' installed.
  6951.  
  6952.      A collection of our standard configure scripts is located in the
  6953.      `BUILD/' subdirectory.  If you are lazy, you can use
  6954.      `BUILD/compile-pentium-debug'. To compile on a different
  6955.      architecture, modify the script by removing flags that are
  6956.      Pentium-specific.
  6957.  
  6958.   5. When the build is done, run `make install'.  Be careful with this
  6959.      on a production machine; the command may overwrite your live
  6960.      release installation.  If you have another installation of MySQL,
  6961.      we recommend that you run `./configure' with different values for
  6962.      the `prefix', `with-tcp-port', and `unix-socket-path' options than
  6963.      those used for your production server.
  6964.  
  6965.   6. Play hard with your new installation and try to make the new
  6966.      features crash.  Start by running `make test'.  *Note MySQL test
  6967.      suite::.
  6968.  
  6969.   7. If you have gotten to the `make' stage and the distribution does
  6970.      not compile, please report it in our bugs database at
  6971.      `http://bugs.mysql.com/'.  If you have installed the latest
  6972.      versions of the required GNU tools, and they crash trying to
  6973.      process our configuration files, please report that also.
  6974.      However, if you execute `aclocal' and get a `command not found'
  6975.      error or a similar problem, do not report it.  Instead, make sure
  6976.      all the necessary tools are installed and that your `PATH'
  6977.      variable is set correctly so that your shell can find them.
  6978.  
  6979.   8. After the initial `bk clone' operation to get the source tree, you
  6980.      should run `bk pull' periodically to get the updates.
  6981.  
  6982.   9. You can examine the change history for the tree with all the diffs
  6983.      by using `bk sccstool'.  If you see some funny diffs or code that
  6984.      you have a question about, do not hesitate to send e-mail to the
  6985.      MySQL internals mailing list.  *Note Mailing-list::.  Also, if you
  6986.      think you have a better idea on how to do something, send an
  6987.      e-mail to the same address with a patch.  `bk diffs' will produce
  6988.      a patch for you after you have made changes to the source. If you
  6989.      do not have the time to code your idea, just send a description.
  6990.  
  6991.  10. `BitKeeper' has a nice help utility that you can access via `bk
  6992.      helptool'.
  6993.  
  6994.  11. Please note that any commits (`bk ci' or `bk citool') will trigger
  6995.      the posting of a message with the changeset to our internals
  6996.      mailing list, as well as the usual openlogging.org submission with
  6997.      just the changeset comments.  Generally, you wouldn't need to use
  6998.      commit (since the public tree will not allow `bk push'), but
  6999.      rather use the `bk diffs' method described previously.
  7000.  
  7001.  
  7002. You can also browse changesets, comments and sourcecode online by
  7003. browsing to for example, `http://mysql.bkbits.net:8080/mysql-4.1' For
  7004. MySQL 4.1.
  7005.  
  7006. The manual is in a separate tree which can be cloned with:
  7007.  
  7008.      shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
  7009.  
  7010. There are also public BitKeeper trees for MySQL Control Center and
  7011. Connector/ODBC. They can be cloned respectively as follows.
  7012.  
  7013. To clone MySQL Control center, use this command:
  7014.  
  7015.      shell> bk clone http://mysql.bkbits.net/mysqlcc mysqlcc
  7016.  
  7017. To clone Connector/ODBC, use this command:
  7018.  
  7019.      shell> bk clone http://mysql.bkbits.net/myodbc3 myodbc3
  7020.  
  7021. Problems Compiling MySQL?
  7022. -------------------------
  7023.  
  7024. All MySQL programs compile cleanly for us with no warnings on Solaris
  7025. or Linux using `gcc'.  On other systems, warnings may occur due to
  7026. differences in system include files.  See *Note MIT-pthreads:: for
  7027. warnings that may occur when using MIT-pthreads.  For other problems,
  7028. check the following list.
  7029.  
  7030. The solution to many problems involves reconfiguring.  If you do need to
  7031. reconfigure, take note of the following:
  7032.  
  7033.    * If `configure' is run after it already has been run, it may use
  7034.      information that was gathered during its previous invocation.  This
  7035.      information is stored in `config.cache'.  When `configure' starts
  7036.      up, it looks for that file and reads its contents if it exists, on
  7037.      the assumption that the information is still correct.  That
  7038.      assumption is invalid when you reconfigure.
  7039.  
  7040.    * Each time you run `configure', you must run `make' again to
  7041.      recompile.  However, you may want to remove old object files from
  7042.      previous builds first because they were compiled using different
  7043.      configuration options.
  7044.  
  7045. To prevent old configuration information or object files from being
  7046. used, run these commands before rerunning `configure':
  7047.  
  7048.      shell> rm config.cache
  7049.      shell> make clean
  7050.  
  7051. Alternatively, you can run `make distclean'.
  7052.  
  7053. The following list describes some of the problems when compiling MySQL
  7054. that have been found to occur most often:
  7055.  
  7056.    * If you get errors when compiling `sql_yacc.cc', such as the ones
  7057.      shown here, you have probably run out of memory or swap space:
  7058.  
  7059.           Internal compiler error: program cc1plus got fatal signal 11
  7060.             or
  7061.           Out of virtual memory
  7062.             or
  7063.           Virtual memory exhausted
  7064.  
  7065.      The problem is that `gcc' requires huge amounts of memory to
  7066.      compile `sql_yacc.cc' with inline functions.  Try running
  7067.      `configure' with the `--with-low-memory' option:
  7068.  
  7069.           shell> ./configure --with-low-memory
  7070.  
  7071.      This option causes `-fno-inline' to be added to the compile line
  7072.      if you are using `gcc' and `-O0' if you are using something else.
  7073.      You should try the `--with-low-memory' option even if you have so
  7074.      much memory and swap space that you think you can't possibly have
  7075.      run out.  This problem has been observed to occur even on systems
  7076.      with generous hardware configurations, and the `--with-low-memory'
  7077.      option usually fixes it.
  7078.  
  7079.    * By default, `configure' picks `c++' as the compiler name and GNU
  7080.      `c++' links with `-lg++'.  If you are using `gcc', that behaviour
  7081.      can cause problems during configuration such as this:
  7082.  
  7083.           configure: error: installation or configuration problem:
  7084.           C++ compiler cannot create executables.
  7085.  
  7086.      You might also observe problems during compilation related to
  7087.      `g++', `libg++', or `libstdc++'.
  7088.  
  7089.      One cause of these problems is that you may not have `g++', or you
  7090.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  7091.      the `config.log' file.  It should contain the exact reason why
  7092.      your C++ compiler didn't work.  To work around these problems, you
  7093.      can use `gcc' as your C++ compiler.  Try setting the environment
  7094.      variable `CXX' to `"gcc -O3"'.  For example:
  7095.  
  7096.           shell> CXX="gcc -O3" ./configure
  7097.  
  7098.      This works because `gcc' compiles C++ sources as well as `g++'
  7099.      does, but does not link in `libg++' or `libstdc++' by default.
  7100.  
  7101.      Another way to fix these problems, of course, is to install `g++',
  7102.      `libg++', and `libstdc++'.  We would however like to recommend you
  7103.      to not use `libg++' or `libstdc++' with MySQL as this will only
  7104.      increase the binary size of mysqld without giving you any benefits.
  7105.      Some versions of these libraries have also caused strange problems
  7106.      for MySQL users in the past.
  7107.  
  7108.      Using `gcc' as the C++ compiler is also required, if you want to
  7109.      compile MySQL with RAID functionality (see *Note CREATE TABLE::
  7110.      for more info on RAID table type) and you are using GNU `gcc'
  7111.      version 3 and above. If you get errors like the ones below during
  7112.      the linking stage when you configure MySQL to compile with the
  7113.      option `--with-raid', try to use `gcc' as your C++ compiler by
  7114.      defining the above mentioned environment variable `CXX':
  7115.  
  7116.           gcc -O3 -DDBUG_OFF -rdynamic -o isamchk isamchk.o sort.o  libnisam.a
  7117.           ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread
  7118.           -lz -lcrypt -lnsl -lm -lpthread
  7119.           ../mysys/libmysys.a(raid.o)(.text+0x79): In function `my_raid_create':
  7120.           : undefined reference to `operator new(unsigned)'
  7121.           ../mysys/libmysys.a(raid.o)(.text+0xdd): In function `my_raid_create':
  7122.           : undefined reference to `operator delete(void*)'
  7123.           ../mysys/libmysys.a(raid.o)(.text+0x129): In function `my_raid_open':
  7124.           : undefined reference to `operator new(unsigned)'
  7125.           ../mysys/libmysys.a(raid.o)(.text+0x189): In function `my_raid_open':
  7126.           : undefined reference to `operator delete(void*)'
  7127.           ../mysys/libmysys.a(raid.o)(.text+0x64b): In function `my_raid_close':
  7128.           : undefined reference to `operator delete(void*)'
  7129.           collect2: ld returned 1 exit status
  7130.  
  7131.    * If your compile fails with errors, such as any of the following,
  7132.      you must upgrade your version of `make' to GNU `make':
  7133.  
  7134.           making all in mit-pthreads
  7135.           make: Fatal error in reader: Makefile, line 18:
  7136.           Badly formed macro assignment
  7137.             or
  7138.           make: file `Makefile' line 18: Must be a separator (:
  7139.             or
  7140.           pthread.h: No such file or directory
  7141.  
  7142.      Solaris and FreeBSD are known to have troublesome `make' programs.
  7143.  
  7144.      GNU `make' Version 3.75 is known to work.
  7145.  
  7146.    * If you want to define flags to be used by your C or C++ compilers,
  7147.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  7148.      environment variables.  You can also specify the compiler names
  7149.      this way using `CC' and `CXX'.  For example:
  7150.  
  7151.           shell> CC=gcc
  7152.           shell> CFLAGS=-O3
  7153.           shell> CXX=gcc
  7154.           shell> CXXFLAGS=-O3
  7155.           shell> export CC CFLAGS CXX CXXFLAGS
  7156.  
  7157.      See *Note MySQL binaries::, for a list of flag definitions that
  7158.      have been found to be useful on various systems.
  7159.  
  7160.    * If you get an error message like this, you need to upgrade your
  7161.      `gcc' compiler:
  7162.  
  7163.           client/libmysql.c:273: parse error before `__attribute__'
  7164.  
  7165.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  7166.      or `egcs' 1.0.3a instead.
  7167.  
  7168.    * If you get errors such as those shown here when compiling `mysqld',
  7169.      `configure' didn't correctly detect the type of the last argument
  7170.      to `accept()', `getsockname()', or `getpeername()':
  7171.  
  7172.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  7173.                type of the pointer value ''length'' is ''unsigned long'', which
  7174.                is not compatible with ''int''.
  7175.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  7176.  
  7177.      To fix this, edit the `config.h' file (which is generated by
  7178.      `configure').  Look for these lines:
  7179.  
  7180.           /* Define as the base type of the last arg to accept */
  7181.           #define SOCKET_SIZE_TYPE XXX
  7182.  
  7183.      Change `XXX' to `size_t' or `int', depending on your operating
  7184.      system.  (Note that you will have to do this each time you run
  7185.      `configure' because `configure' regenerates `config.h'.)
  7186.  
  7187.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  7188.      the build process doesn't need to create `sql_yacc.cc', because
  7189.      MySQL comes with an already generated copy.  However, if you do
  7190.      need to re-create it, you might encounter this error:
  7191.  
  7192.           "sql_yacc.yy", line xxx fatal: default action causes potential...
  7193.  
  7194.      This is a sign that your version of `yacc' is deficient.  You
  7195.      probably need to install `bison' (the GNU version of `yacc') and
  7196.      use that instead.
  7197.  
  7198.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  7199.      with the `--with-debug' option, then recompile and link your
  7200.      clients with the new client library.  *Note Debugging client::.
  7201.  
  7202.    * If you get a compilation error on Linux (e.g. SuSE Linux 8.1 or
  7203.      Red Hat Linux 7.3) similar to the following one:
  7204.  
  7205.           libmysql.c:1329: warning: passing arg 5 of `gethostbyname_r' from incompatible pointer type
  7206.           libmysql.c:1329: too few arguments to function `gethostbyname_r'
  7207.           libmysql.c:1329: warning: assignment makes pointer from integer without a cast
  7208.           make[2]: *** [libmysql.lo] Error 1
  7209.  
  7210.      By default, the `configure' script attempts to determine the
  7211.      correct number of arguments by using `g++' the GNU C++ compiler.
  7212.      This test yields wrong results, if `g++' is not installed. There
  7213.      are two ways to work around this problem:
  7214.  
  7215.         * Make sure that the GNU C++ `g++' is installed. On some Linux
  7216.           distributions, the required package is called `gpp', on
  7217.           others it is named `gcc-c++'.
  7218.  
  7219.         * Use `gcc' as your C++ compiler by setting the `CXX'
  7220.           environment variable to `gcc':
  7221.                export CXX="gcc"
  7222.  
  7223.      Please note that you need to run `configure' again afterwards.
  7224.  
  7225.  
  7226. MIT-pthreads Notes
  7227. ------------------
  7228.  
  7229. This section describes some of the issues involved in using
  7230. MIT-pthreads.
  7231.  
  7232. Note that on Linux you should *not* use MIT-pthreads but use the
  7233. installed LinuxThreads implementation instead.  *Note Linux::.
  7234.  
  7235. If your system does not provide native thread support, you will need to
  7236. build MySQL using the MIT-pthreads package.  This includes older
  7237. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  7238. *Note Which OS::.
  7239.  
  7240. Note, that beginning with MySQL 4.0.2 MIT-pthreads are no longer part of
  7241. the source distribution. If you require this package, you need to
  7242. download it separately from
  7243. <http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz>
  7244.  
  7245. After downloading, extract this source archive into the top level of the
  7246. MySQL source directory. It will create a new subdirectory
  7247. `mit-pthreads'.
  7248.  
  7249.    * On most systems, you can force MIT-pthreads to be used by running
  7250.      `configure' with the `--with-mit-threads' option:
  7251.  
  7252.           shell> ./configure --with-mit-threads
  7253.  
  7254.      Building in a non-source directory is not supported when using
  7255.      MIT-pthreads because we want to minimise our changes to this code.
  7256.  
  7257.    * The checks that determine whether to use MIT-pthreads occur only
  7258.      during the part of the configuration process that deals with the
  7259.      server code.  If you have configured the distribution using
  7260.      `--without-server' to build only the client code, clients will not
  7261.      know whether MIT-pthreads is being used and will use Unix socket
  7262.      connections by default.  Because Unix sockets do not work under
  7263.      MIT-pthreads on some platforms, this means you will need to use
  7264.      `-h' or `--host' when you run client programs.
  7265.  
  7266.    * When MySQL is compiled using MIT-pthreads, system locking is
  7267.      disabled by default for performance reasons.  You can tell the
  7268.      server to use system locking with the `--external-locking' option.
  7269.      This is only needed if you want to be able to run two MySQL
  7270.      servers against the same datafiles (not recommended).
  7271.  
  7272.    * Sometimes the pthread `bind()' command fails to bind to a socket
  7273.      without any error message (at least on Solaris).  The result is
  7274.      that all connections to the server fail.  For example:
  7275.  
  7276.           shell> mysqladmin version
  7277.           mysqladmin: connect to server at '' failed;
  7278.           error: 'Can't connect to mysql server on localhost (146)'
  7279.  
  7280.      The solution to this is to kill the `mysqld' server and restart it.
  7281.      This has only happened to us when we have forced the server down
  7282.      and done a restart immediately.
  7283.  
  7284.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  7285.      with `SIGINT' (break).  This is only noticeable when you run
  7286.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  7287.      terminate before the interrupt is served and the process stops.
  7288.  
  7289.    * When linking, you may receive warning messages like these (at
  7290.      least on Solaris); they can be ignored:
  7291.  
  7292.           ld: warning: symbol `_iob' has differing sizes:
  7293.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  7294.           file /usr/lib/libc.so value=0x140);
  7295.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  7296.           ld: warning: symbol `__iob' has differing sizes:
  7297.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  7298.           file /usr/lib/libc.so value=0x140);
  7299.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  7300.  
  7301.    * Some other warnings also can be ignored:
  7302.  
  7303.           implicit declaration of function `int strtoll(...)'
  7304.           implicit declaration of function `int strtoul(...)'
  7305.  
  7306.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  7307.      isn't needed, but may be interesting for someone.)
  7308.  
  7309. Windows Source Distribution
  7310. ---------------------------
  7311.  
  7312. You will need the following:
  7313.  
  7314.    * VC++ 6.0 compiler (updated with 4 or 5 SP and Pre-processor
  7315.      package) The Pre-processor package is necessary for the macro
  7316.      assembler.  More details at:
  7317.      `http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/faq.aspx'.
  7318.  
  7319.    * The MySQL source distribution for Windows, which can be downloaded
  7320.      from `http://www.mysql.com/downloads/'.
  7321.  
  7322. Building MySQL:
  7323.  
  7324.   1. Create a work directory (for example, `workdir').
  7325.  
  7326.   2. Unpack the source distribution in the aforementioned directory.
  7327.  
  7328.   3. Start the VC++ 6.0 compiler.
  7329.  
  7330.   4. In the `File' menu, select `Open Workspace'.
  7331.  
  7332.   5. Open the `mysql.dsw' workspace you find on the work directory.
  7333.  
  7334.   6. From the `Build' menu, select the `Set Active Configuration' menu.
  7335.  
  7336.   7. Click over the screen selecting `mysqld - Win32 Debug' and click
  7337.      OK.
  7338.  
  7339.   8. Press `F7' to begin the build of the debug server, libraries, and
  7340.      some client applications.
  7341.  
  7342.   9. When the compilation finishes, copy the libraries and the
  7343.      executables to a separate directory.
  7344.  
  7345.  10. Compile the release versions that you want, in the same way.
  7346.  
  7347.  11. Create the directory into which to install the MySQL stuff (for
  7348.      example, `c:\mysql').
  7349.  
  7350.  12. From the `workdir' directory copy into the `c:\mysql' directory the
  7351.      following directories:
  7352.  
  7353.         * `Data'
  7354.  
  7355.         * `Docs'
  7356.  
  7357.         * `Share'
  7358.  
  7359.  13. Create the directory `c:\mysql\bin' and copy into it all the
  7360.      servers and clients that you just compiled.
  7361.  
  7362.  14. If you want, also create the `c:\mysql\lib' directory and copy the
  7363.      libraries that you just compiled.
  7364.  
  7365.  15. Do a clean using Visual Studio.
  7366.  
  7367. Set up and start the server in the same way as for the binary Windows
  7368. distribution. *Note Windows prepare environment::.
  7369.  
  7370. Post-installation Setup and Testing
  7371. ===================================
  7372.  
  7373. Once you've installed MySQL (from either a binary or source
  7374. distribution), you need to initialise the grant tables, start the
  7375. server, and make sure that the server works okay.  You may also wish to
  7376. arrange for the server to be started and stopped automatically when
  7377. your system starts up and shuts down.
  7378.  
  7379. Normally you install the grant tables and start the server like this
  7380. for installation from a source distribution:
  7381.  
  7382.      shell> ./scripts/mysql_install_db
  7383.      shell> cd mysql_installation_directory
  7384.      shell> ./bin/mysqld_safe --user=mysql &
  7385.  
  7386. For a binary distribution (not RPM or pkg packages), do this:
  7387.  
  7388.      shell> cd mysql_installation_directory
  7389.      shell> ./scripts/mysql_install_db
  7390.      shell> ./bin/mysqld_safe --user=mysql &
  7391.  
  7392. The `mysql_install_db' script creates the `mysql' database which will
  7393. hold all database privileges, the `test' database which you can use to
  7394. test MySQL, and also privilege entries for the user that runs
  7395. `mysql_install_db' and a `root' user.  The entries are created without
  7396. passwords.  The `mysqld_safe' script starts the `mysqld' server.  (If
  7397. your version of MySQL is older than 4.0, use `safe_mysqld' rather than
  7398. `mysqld_safe'.)
  7399.  
  7400. `mysql_install_db' will not overwrite any old privilege tables, so it
  7401. should be safe to run in any circumstances.  If you don't want to have
  7402. the `test' database you can remove it with `mysqladmin -u root drop
  7403. test' after starting the server.
  7404.  
  7405. Testing is most easily done from the top-level directory of the MySQL
  7406. distribution.  For a binary distribution, this is your installation
  7407. directory (typically something like `/usr/local/mysql').  For a source
  7408. distribution, this is the main directory of your MySQL source tree.
  7409.  
  7410. In the commands shown in this section and in the following subsections,
  7411. `BINDIR' is the path to the location in which programs like
  7412. `mysqladmin' and `mysqld_safe' are installed.  For a binary
  7413. distribution, this is the `bin' directory within the distribution.  For
  7414. a source distribution, `BINDIR' is probably `/usr/local/bin', unless
  7415. you specified an installation directory other than `/usr/local' when
  7416. you ran `configure'.  `EXECDIR' is the location in which the `mysqld'
  7417. server is installed.  For a binary distribution, this is the same as
  7418. `BINDIR'.  For a source distribution, `EXECDIR' is probably
  7419. `/usr/local/libexec'.
  7420.  
  7421. Testing is described in detail:
  7422.  
  7423.   1. If necessary, start the `mysqld' server and set up the initial
  7424.      MySQL grant tables containing the privileges that determine how
  7425.      users are allowed to connect to the server.  This is normally done
  7426.      with the `mysql_install_db' script:
  7427.  
  7428.           shell> scripts/mysql_install_db
  7429.  
  7430.      Typically, `mysql_install_db' needs to be run only the first time
  7431.      you install MySQL.  Therefore, if you are upgrading an existing
  7432.      installation, you can skip this step.  (However,
  7433.      `mysql_install_db' is quite safe to use and will not update any
  7434.      tables that already exist, so if you are unsure of what to do, you
  7435.      can always run `mysql_install_db'.)
  7436.  
  7437.      `mysql_install_db' creates six tables (`user', `db', `host',
  7438.      `tables_priv', `columns_priv', and `func') in the `mysql'
  7439.      database.  A description of the initial privileges is given in
  7440.      *Note Default privileges::.  Briefly, these privileges allow the
  7441.      MySQL `root' user to do anything, and allow anybody to create or
  7442.      use databases with a name of `test' or starting with `test_'.
  7443.  
  7444.      If you don't set up the grant tables, the following error will
  7445.      appear in the log file when you start the server:
  7446.  
  7447.           mysqld: Can't find file: 'host.frm'
  7448.  
  7449.      This may also happen with a binary MySQL distribution if you don't
  7450.      start MySQL by executing exactly `./bin/mysqld_safe'.  *Note
  7451.      `mysqld_safe': mysqld_safe.
  7452.  
  7453.      You might need to run `mysql_install_db' as `root'.  However, if
  7454.      you prefer, you can run the MySQL server as an unprivileged
  7455.      (non-`root') user, provided that the user can read and write files
  7456.      in the database directory.  Instructions for running MySQL as an
  7457.      unprivileged user are given in *Note Changing MySQL user: Changing
  7458.      MySQL user.
  7459.  
  7460.      If you have problems with `mysql_install_db', see *Note
  7461.      `mysql_install_db': mysql_install_db.
  7462.  
  7463.      There are some alternatives to running the `mysql_install_db'
  7464.      script as it is provided in the MySQL distribution:
  7465.  
  7466.         * You may want to edit `mysql_install_db' before running it, to
  7467.           change the initial privileges that are installed into the
  7468.           grant tables.  This is useful if you want to install MySQL on
  7469.           a lot of machines with the same privileges.  In this case you
  7470.           probably should need only to add a few extra `INSERT'
  7471.           statements to the `mysql.user' and `mysql.db' tables.
  7472.  
  7473.         * If you want to change things in the grant tables after
  7474.           installing them, you can run `mysql_install_db', then use
  7475.           `mysql -u root mysql' to connect to the grant tables as the
  7476.           MySQL `root' user and issue SQL statements to modify the
  7477.           grant tables directly.
  7478.  
  7479.         * It is possible to re-create the grant tables completely after
  7480.           they have already been created.  You might want to do this if
  7481.           you've already installed the tables but then want to
  7482.           re-create them after editing `mysql_install_db'.
  7483.  
  7484.      For more information about these alternatives, see *Note Default
  7485.      privileges::.
  7486.  
  7487.   2. Start the MySQL server like this:
  7488.  
  7489.           shell> cd mysql_installation_directory
  7490.           shell> bin/mysqld_safe &
  7491.  
  7492.      If you have problems starting the server, see *Note Starting
  7493.      server::.
  7494.  
  7495.   3. Use `mysqladmin' to verify that the server is running.  The
  7496.      following commands provide a simple test to check that the server
  7497.      is up and responding to connections:
  7498.  
  7499.           shell> BINDIR/mysqladmin version
  7500.           shell> BINDIR/mysqladmin variables
  7501.  
  7502.      The output from `mysqladmin version' varies slightly depending on
  7503.      your platform and version of MySQL, but should be similar to that
  7504.      shown here:
  7505.  
  7506.           shell> BINDIR/mysqladmin version
  7507.           mysqladmin  Ver 8.14 Distrib 3.23.32, for linux on i586
  7508.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  7509.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  7510.           and you are welcome to modify and redistribute it under the GPL license.
  7511.           
  7512.           Server version          3.23.32-debug
  7513.           Protocol version        10
  7514.           Connection              Localhost via Unix socket
  7515.           TCP port                3306
  7516.           UNIX socket             /tmp/mysql.sock
  7517.           Uptime:                 16 sec
  7518.           
  7519.           Threads: 1  Questions: 9  Slow queries: 0
  7520.           Opens: 7  Flush tables: 2  Open tables: 0
  7521.           Queries per second avg: 0.000
  7522.           Memory in use: 132K  Max memory used: 16773K
  7523.  
  7524.      To get a feeling for what else you can do with `BINDIR/mysqladmin',
  7525.      invoke it with the `--help' option.
  7526.  
  7527.   4. Verify that you can shut down the server:
  7528.  
  7529.           shell> BINDIR/mysqladmin -u root shutdown
  7530.  
  7531.   5. Verify that you can restart the server.  Do this using
  7532.      `mysqld_safe' or by invoking `mysqld' directly.  For example:
  7533.  
  7534.           shell> BINDIR/mysqld_safe --log &
  7535.  
  7536.      If `mysqld_safe' fails, try running it from the MySQL installation
  7537.      directory (if you are not already there).  If that doesn't work,
  7538.      see *Note Starting server::.
  7539.  
  7540.   6. Run some simple tests to verify that the server is working.  The
  7541.      output should be similar to what is shown here:
  7542.  
  7543.           shell> BINDIR/mysqlshow
  7544.           +-----------+
  7545.           | Databases |
  7546.           +-----------+
  7547.           | mysql     |
  7548.           +-----------+
  7549.           
  7550.           shell> BINDIR/mysqlshow mysql
  7551.           Database: mysql
  7552.           +--------------+
  7553.           |    Tables    |
  7554.           +--------------+
  7555.           | columns_priv |
  7556.           | db           |
  7557.           | func         |
  7558.           | host         |
  7559.           | tables_priv  |
  7560.           | user         |
  7561.           +--------------+
  7562.           
  7563.           shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql
  7564.           +------+--------+------+
  7565.           | host | db     | user |
  7566.           +------+--------+------+
  7567.           | %    | test   |      |
  7568.           | %    | test_% |      |
  7569.           +------+--------+------+
  7570.  
  7571.      There is also a benchmark suite in the `sql-bench' directory
  7572.      (under the MySQL installation directory) that you can use to
  7573.      compare how MySQL performs on different platforms. The benchmark
  7574.      suite is written in Perl, using the Perl DBI module to provide a
  7575.      database-independent interface to the various databases. The
  7576.      following additional Perl modules are required to run the
  7577.      benchmark suite:
  7578.  
  7579.           DBI
  7580.           DBD-mysql
  7581.           Data-Dumper
  7582.           Data-ShowTable
  7583.  
  7584.      These modules can be obtained from CPAN `http://www.cpan.org/'.
  7585.      *Note Perl installation::.
  7586.  
  7587.      The `sql-bench/Results' directory contains the results from many
  7588.      runs against different databases and platforms.  To run all tests,
  7589.      execute these commands:
  7590.  
  7591.           shell> cd sql-bench
  7592.           shell> run-all-tests
  7593.  
  7594.      If you don't have the `sql-bench' directory, you are probably
  7595.      using an RPM for a binary distribution.  (Source distribution RPMs
  7596.      include the benchmark directory.)  In this case, you must first
  7597.      install the benchmark suite before you can use it.  Beginning with
  7598.      MySQL Version 3.22, there are benchmark RPM files named
  7599.      `mysql-bench-VERSION-i386.rpm' that contain benchmark code and
  7600.      data.
  7601.  
  7602.      If you have a source distribution, you can also run the tests in
  7603.      the `tests' subdirectory. For example, to run
  7604.      `auto_increment.tst', do this:
  7605.  
  7606.           shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
  7607.  
  7608.      The expected results are shown in the `./tests/auto_increment.res'
  7609.      file.
  7610.  
  7611. Problems Running `mysql_install_db'
  7612. -----------------------------------
  7613.  
  7614. The purpose of the `mysql_install_db' script is to generate new MySQL
  7615. privilege tables.  It will not affect any other data.  It will also not
  7616. do anything if you already have MySQL privilege tables installed.
  7617.  
  7618. If you want to re-create your privilege tables, you should take down
  7619. the `mysqld' server, if it's running, and then do something like:
  7620.  
  7621.      mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  7622.      mysql_install_db
  7623.  
  7624. This section lists problems you might encounter when you run
  7625. `mysql_install_db':
  7626.  
  7627. *`mysql_install_db' doesn't install the grant tables*
  7628.      You may find that `mysql_install_db' fails to install the grant
  7629.      tables and terminates after displaying the following messages:
  7630.  
  7631.           starting mysqld daemon with databases from XXXXXX
  7632.           mysql daemon ended
  7633.  
  7634.      In this case, you should examine the log file very carefully.  The
  7635.      log should be located in the directory `XXXXXX' named by the error
  7636.      message, and should indicate why `mysqld' didn't start.  If you
  7637.      don't understand what happened, include the log when you post a
  7638.      bug report using `mysqlbug'.  *Note Bug reports::.
  7639.  
  7640. *There is already a `mysqld' daemon running*
  7641.      In this case, you probably don't have to run `mysql_install_db' at
  7642.      all.  You have to run `mysql_install_db' only once, when you
  7643.      install MySQL the first time.
  7644.  
  7645. *Installing a second `mysqld' daemon doesn't work when one daemon is running*
  7646.      This can happen when you already have an existing MySQL
  7647.      installation, but want to put a new installation in a different
  7648.      place (for example, for testing, or perhaps you simply want to run
  7649.      two installations at the same time).  Generally the problem that
  7650.      occurs when you try to run the second server is that it tries to
  7651.      use the same socket and port as the old one.  In this case you
  7652.      will get the error message: `Can't start server: Bind on TCP/IP
  7653.      port: Address already in use' or `Can't start server: Bind on unix
  7654.      socket...'. *Note Multiple servers::.
  7655.  
  7656. *You don't have write access to `/tmp'*
  7657.      If you don't have write access to create a socket file at the
  7658.      default place (in `/tmp') or permission to create temporary files
  7659.      in `/tmp,' you will get an error when running `mysql_install_db'
  7660.      or when starting or using `mysqld'.
  7661.  
  7662.      You can specify a different socket and temporary directory as
  7663.      follows:
  7664.  
  7665.           shell> TMPDIR=/some_tmp_dir/
  7666.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
  7667.           shell> export TMPDIR MYSQL_UNIX_PORT
  7668.  
  7669.      See *Note Problems with mysql.sock::.
  7670.  
  7671.      `some_tmp_dir' should be the path to some directory for which you
  7672.      have write permission. *Note Environment variables::.
  7673.  
  7674.      After this you should be able to run `mysql_install_db' and start
  7675.      the server with these commands:
  7676.  
  7677.           shell> scripts/mysql_install_db
  7678.           shell> BINDIR/mysqld_safe &
  7679.  
  7680. *`mysqld' crashes immediately*
  7681.      If you are running Red Hat Version 5.0 with a version of `glibc'
  7682.      older than 2.0.7-5, you should make sure you have installed all
  7683.      `glibc' patches.  There is a lot of information about this in the
  7684.      MySQL mail archives.  Links to the mail archives are available
  7685.      online at `http://lists.mysql.com/'.  Also, see *Note Linux::.
  7686.  
  7687.      You can also start `mysqld' manually using the
  7688.      `--skip-grant-tables' option and add the privilege information
  7689.      yourself using `mysql':
  7690.  
  7691.           shell> BINDIR/mysqld_safe --skip-grant-tables &
  7692.           shell> BINDIR/mysql -u root mysql
  7693.  
  7694.      From `mysql', manually execute the SQL commands in
  7695.      `mysql_install_db'.  Make sure you run `mysqladmin
  7696.      flush-privileges' or `mysqladmin reload' afterward to tell the
  7697.      server to reload the grant tables.
  7698.  
  7699. Problems Starting the MySQL Server
  7700. ----------------------------------
  7701.  
  7702. If you are going to use tables that support transactions (InnoDB, BDB),
  7703. you should first create a `my.cnf' file and set startup options for the
  7704. table types you plan to use. *Note Table types::.
  7705.  
  7706. Generally, you start the `mysqld' server in one of these ways:
  7707.  
  7708.    * By invoking `mysql.server'.  This script is used primarily at
  7709.      system startup and shutdown, and is described more fully in *Note
  7710.      Automatic start::.
  7711.  
  7712.    * By invoking `mysqld_safe', which tries to determine the proper
  7713.      options for `mysqld' and then runs it with those options. *Note
  7714.      `mysqld_safe': mysqld_safe.
  7715.  
  7716.    * For Windows NT/2000/XP, please see *Note NT start::.
  7717.  
  7718.    * By invoking `mysqld' directly.
  7719.  
  7720. When the `mysqld' daemon starts up, it changes the directory to the
  7721. data directory.  This is where it expects to write log files and the pid
  7722. (process ID) file, and where it expects to find databases.
  7723.  
  7724. The data directory location is hardwired in when the distribution is
  7725. compiled.  However, if `mysqld' expects to find the data directory
  7726. somewhere other than where it really is on your system, it will not work
  7727. properly.  If you have problems with incorrect paths, you can find out
  7728. what options `mysqld' allows and what the default path settings are by
  7729. invoking `mysqld' with the `--help' option.  You can override the
  7730. defaults by specifying the correct pathnames as command-line arguments
  7731. to `mysqld'.  (These options can be used with `mysqld_safe' as well.)
  7732.  
  7733. Normally you should need to tell `mysqld' only the base directory under
  7734. which MySQL is installed.  You can do this with the `--basedir' option.
  7735. You can also use `--help' to check the effect of changing path options
  7736. (note that `--help' *must* be the final option of the `mysqld'
  7737. command).  For example:
  7738.  
  7739.      shell> EXECDIR/mysqld --basedir=/usr/local --help
  7740.  
  7741. Once you determine the path settings you want, start the server without
  7742. the `--help' option.
  7743.  
  7744. Whichever method you use to start the server, if it fails to start up
  7745. correctly, check the log file to see if you can find out why.  Log files
  7746. are located in the data directory (typically `/usr/local/mysql/data'
  7747. for a binary distribution, `/usr/local/var' for a source distribution,
  7748. and `\mysql\data\mysql.err' on Windows).  Look in the data directory for
  7749. files with names of the form `host_name.err' and `host_name.log' where
  7750. `host_name' is the name of your server host.  Then check the last few
  7751. lines of these files:
  7752.  
  7753.      shell> tail host_name.err
  7754.      shell> tail host_name.log
  7755.  
  7756. Look for something like the following in the log file:
  7757.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  7758.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  7759.      000729 14:50:10  Can't init databases
  7760.  
  7761. This means that you didn't start `mysqld' with `--bdb-no-recover' and
  7762. Berkeley DB found something wrong with its log files when it tried to
  7763. recover your databases.  To be able to continue, you should move away
  7764. the old Berkeley DB log file from the database directory to some other
  7765. place, where you can later examine it.  The log files are named
  7766. `log.0000000001', where the number will increase over time.
  7767.  
  7768. If you are running `mysqld' with BDB table support and `mysqld' core
  7769. dumps at start this could be because of some problems with the BDB
  7770. recover log.  In this case you can try starting `mysqld' with
  7771. `--bdb-no-recover'.  If this helps, then you should remove all `log.*'
  7772. files from the data directory and try starting `mysqld' again.
  7773.  
  7774. If you get the following error, it means that some other program (or
  7775. another `mysqld' server) is already using the TCP/IP port or socket
  7776. `mysqld' is trying to use:
  7777.  
  7778.      Can't start server: Bind on TCP/IP port: Address already in use
  7779.        or
  7780.      Can't start server : Bind on unix socket...
  7781.  
  7782. Use `ps' to make sure that you don't have another `mysqld' server
  7783. running.  If you can't find another server running, you can try to
  7784. execute the command `telnet your-host-name tcp-ip-port-number' and press
  7785. Enter a couple of times.  If you don't get an error message like
  7786. `telnet: Unable to connect to remote host: Connection refused',
  7787. something is using the TCP/IP port `mysqld' is trying to use.  See
  7788. *Note mysql_install_db:: and *Note Multiple servers::.
  7789.  
  7790. If `mysqld' is currently running, you can find out what path settings
  7791. it is using by executing this command:
  7792.  
  7793.      shell> mysqladmin variables
  7794.  
  7795. or
  7796.  
  7797.      shell> mysqladmin -h 'your-host-name' variables
  7798.  
  7799. If you get `Errcode 13', which means `Permission denied', when starting
  7800. `mysqld' this means that you didn't have the right to read/create files
  7801. in the MySQL database or log directory. In this case you should either
  7802. start `mysqld' as the `root' user or change the permissions for the
  7803. involved files and directories so that you have the right to use them.
  7804.  
  7805. If `mysqld_safe' starts the server but you can't connect to it, you
  7806. should make sure you have an entry in `/etc/hosts' that looks like this:
  7807.  
  7808.      127.0.0.1       localhost
  7809.  
  7810. This problem occurs only on systems that don't have a working thread
  7811. library and for which MySQL must be configured to use MIT-pthreads.
  7812.  
  7813. If you can't get `mysqld' to start you can try to make a trace file to
  7814. find the problem. *Note Making trace files::.
  7815.  
  7816. If you are using InnoDB tables, refer to the InnoDB-specific startup
  7817. options.  *Note InnoDB start::.
  7818.  
  7819. If you are using BDB (Berkeley DB) tables, you should familiarise
  7820. yourself with the different BDB-specific startup options.  *Note BDB
  7821. start::.
  7822.  
  7823. Starting and Stopping MySQL Automatically
  7824. -----------------------------------------
  7825.  
  7826. The `mysql.server' and `mysqld_safe' scripts can be used to start the
  7827. server automatically at system startup time. `mysql.server' can also be
  7828. used to stop the server.
  7829.  
  7830. The `mysql.server' script can be used to start or stop the server by
  7831. invoking it with `start' or `stop' arguments:
  7832.  
  7833.      shell> mysql.server start
  7834.      shell> mysql.server stop
  7835.  
  7836. `mysql.server' can be found in the `share/mysql' directory under the
  7837. MySQL installation directory or in the `support-files' directory of the
  7838. MySQL source tree.
  7839.  
  7840. Note that if you use the Linux RPM package
  7841. (`MySQL-server-VERSION.rpm'), the `mysql.server' script has already
  7842. been installed as `/etc/init.d/mysql' - you don't have to install it
  7843. manually. See *Note Linux-RPM:: for more information on the Linux RPM
  7844. packages.
  7845.  
  7846. On Mac OS X, you can install a separate MySQL Startup Item package to
  7847. enable the automatic startup of MySQL on system bootup.  See *Note Mac
  7848. OS X installation:: for details.
  7849.  
  7850. Before `mysql.server' starts the server, it changes the directory to
  7851. the MySQL installation directory, then invokes `mysqld_safe'.  You
  7852. might need to edit `mysql.server' if you have a binary distribution
  7853. that you've installed in a non-standard location.  Modify it to `cd'
  7854. into the proper directory before it runs `mysqld_safe'. If you want the
  7855. server to run as some specific user, add an appropriate `user' line to
  7856. the `/etc/my.cnf' file, as shown later in this section.
  7857.  
  7858. `mysql.server stop' brings down the server by sending a signal to it.
  7859. You can also take down the server manually by executing `mysqladmin
  7860. shutdown'.
  7861.  
  7862. You need to add these start and stop commands to the appropriate places
  7863. in your `/etc/rc*' files when you want to start up MySQL automatically
  7864. on your server.
  7865.  
  7866. On most current Linux distributions, it is sufficient to copy the file
  7867. `mysql.server' into the `/etc/init.d' directory (or `/etc/rc.d/init.d'
  7868. on older Red Hat systems). Afterwards, run the following command to
  7869. enable the startup of MySQL on system bootup:
  7870.  
  7871.      shell> chkconfig --add mysql.server
  7872.  
  7873. On FreeBSD startup scripts generally should go in
  7874. `/usr/local/etc/rc.d/'. The `rc(8)' manual page also states that
  7875. scripts in this directory are only executed, if their basename matches
  7876. the shell globbing pattern `*.sh'. Any other files or directories
  7877. present within the directory are silently ignored. In other words, on
  7878. FreeBSD you should install the file `mysql.server' as
  7879. `/usr/local/etc/rc.d/mysql.server.sh' to enable automatic startup.
  7880.  
  7881. As an alternative to the above, some operating systems also use
  7882. `/etc/rc.local' or `/etc/init.d/boot.local' to start additional
  7883. services on bootup. To start up MySQL using this method, you could
  7884. append something like the following to it:
  7885.  
  7886.      /bin/sh -c 'cd /usr/local/mysql ; ./bin/mysqld_safe --user=mysql &'
  7887.  
  7888. You can also add options for `mysql.server' in a global `/etc/my.cnf'
  7889. file.  A typical `/etc/my.cnf' file might look like this:
  7890.  
  7891.      [mysqld]
  7892.      datadir=/usr/local/mysql/var
  7893.      socket=/var/tmp/mysql.sock
  7894.      port=3306
  7895.      user=mysql
  7896.      
  7897.      [mysql.server]
  7898.      basedir=/usr/local/mysql
  7899.  
  7900. The `mysql.server' script understands the following options: `datadir',
  7901. `basedir', and `pid-file'.
  7902.  
  7903. The following table shows which option groups each startup script reads
  7904. from option files:
  7905.  
  7906. *Script*    *Option groups*
  7907. `mysqld'    `[mysqld]' and `[server]'
  7908. `mysql.server'`[mysql.server]', `[mysqld]', and `[server]'
  7909. `mysqld_safe'`[mysqld]', `[server]', and `[mysqld_safe]'
  7910.  
  7911. For backward compatibility, `mysql.server' also reads the
  7912. `[mysql_server]' group and `mysqld_safe' also reads the `[safe_mysqld]'
  7913. group. However, you should update your option files to use the
  7914. `[mysql.server]' and `[mysqld_safe]' groups instead.
  7915.  
  7916. *Note Option files::.
  7917.  
  7918. Upgrading/Downgrading MySQL
  7919. ===========================
  7920.  
  7921. Before you do an upgrade, you should back up your old databases.
  7922.  
  7923. You can always move the MySQL form files and datafiles between different
  7924. versions on the same architecture as long as you have the same base
  7925. version of MySQL. The current base version is 4. If you change the
  7926. character set when running MySQL, you must run `myisamchk -r -q
  7927. --set-character-set=charset' on all tables.  Otherwise, your indexes
  7928. may not be ordered correctly, because changing the character set may
  7929. also change the sort order.
  7930.  
  7931. If you are afraid of new versions, you can always rename your old
  7932. `mysqld' to something like `mysqld-old-version-number'.  If your new
  7933. `mysqld' then does something unexpected, you can simply shut it down
  7934. and restart with your old `mysqld'.
  7935.  
  7936. If, after an upgrade, you experience problems with recompiled client
  7937. programs, such as `Commands out of sync' or unexpected core dumps, you
  7938. probably have used an old header or library file when compiling your
  7939. programs.  In this case you should check the date for your `mysql.h'
  7940. file and `libmysqlclient.a' library to verify that they are from the new
  7941. MySQL distribution.  If not, please recompile your programs.
  7942.  
  7943. If problems occur, such as that the new `mysqld' server doesn't want to
  7944. start or that you can't connect without a password, check that you don't
  7945. have some old `my.cnf' file from your old installation.  You can check
  7946. this with: `program-name --print-defaults'.  If this outputs anything
  7947. other than the program name, you have an active `my.cnf' file that will
  7948. affect things.
  7949.  
  7950. It is a good idea to rebuild and reinstall the Perl `DBD-mysql' module
  7951. whenever you install a new release of MySQL. The same applies to other
  7952. MySQL interfaces as well, such as the Python `MySQLdb' module.
  7953.  
  7954. Upgrading From Version 4.0 to 4.1
  7955. ---------------------------------
  7956.  
  7957. Preparing to Upgrade From Version 4.0 to 4.1
  7958. ............................................
  7959.  
  7960. Some visible things have changed between MySQL 4.0 and MySQL 4.1 to fix
  7961. some critical bugs and make MySQL more compatible with the ANSI SQL
  7962. standard.
  7963.  
  7964. Instead of adding options (and a lot of code) to try to make 4.1 behave
  7965. like 4.0 we have taken another approach:
  7966.  
  7967. We have added to the later MySQL 4.0 releases (from 4.0.12 on) the
  7968. `--new' startup option for `mysqld', which gives you the 4.1 behaviour
  7969. for the most critical changes.  You can also set this behaviour for a
  7970. given client connection with the `SET @@new=1 command'.
  7971.  
  7972. If you believe that some of the following changes will affect you when
  7973. you upgrade to 4.1, we recommend that before upgrading to 4.1, you
  7974. download the latest MySQL 4.0 version and make sure that your
  7975. applications work in the `--new' mode.  This way you will have a smooth
  7976. painless upgrade to 4.1 later.
  7977.  
  7978. In MySQL 4.1 we have done some things that may affect applications.
  7979. The following is a list of things that you have to watch out for when
  7980. upgrading to version 4.1:
  7981.  
  7982.    *   * The interface to aggregated UDF functions has changed a bit. One
  7983.      must now declare a `clear' function for each aggregate function.
  7984.  
  7985.    * `TIMESTAMP' is now returned as a string with the format
  7986.      `'YYYY-MM-DD HH:MM:SS''. If you want to have this as a number (like
  7987.      Version 4.0 does) should add +0 to `TIMESTAMP' columns when you
  7988.      retrieve them.  Different `TIMESTAMP' display widths are no longer
  7989.      supported.
  7990.  
  7991.      This change was necessary for SQL standards compliance. In a future
  7992.      version, a further change will be made (backward compatible with
  7993.      this change), allowing the timestamp length to indicate the
  7994.      desired number of digits for fractions of a second.
  7995.  
  7996.    * For functions that produce a `DATE', `DATETIME', or `TIME' value,
  7997.      the result returned to the client now is fixed up to have a
  7998.      temporal type. For example, in MySQL 4.1, you get this result:
  7999.  
  8000.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  8001.               -> '2001-01-01 00:00:00'
  8002.  
  8003.      In MySQL 4.0, the result is different:
  8004.  
  8005.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  8006.               -> '2001-01-01'
  8007.  
  8008.    * Binary values such as `0xFFDF' now are assumed to be strings
  8009.      instead of numbers.  This fixes some problems with character sets
  8010.      where it's convenient to input the string as a binary values.
  8011.      With this change, you should use `CAST()' if you want to compare
  8012.      binary values numerically as integers:
  8013.  
  8014.           SELECT CAST(0xFEFF AS UNSIGNED INTEGER) < CAST(0xFF AS UNSIGNED INTEGER)
  8015.  
  8016.      Using binary items in a numeric context or comparing them using the
  8017.      `=' operator should work as before.  (The `--new' option can be
  8018.      used to make the server behave as 4.1 in this repect from 4.0.13
  8019.      on.)
  8020.  
  8021.    * `AUTO_INCREMENT' columns cannot take `DEFAULT' values. (In 4.0
  8022.      these were just silently ignored; in 4.1, an error occurs).
  8023.  
  8024.    * `SERIALIZE' is no longer a valid option value for the `sql_mode'
  8025.      variable.  You should use `SET TRANSACTION ISOLATION LEVEL
  8026.      SERIALIZABLE' instead. `SERIALIZE' is no longer valid for the
  8027.      `--sql-mode' option for `mysqld', either. Use
  8028.      `--transaction-isolation=SERIALIZABLE' instead.
  8029.  
  8030.    * All column and tables now have a character set, which shows up in
  8031.      `SHOW CREATE TABLE' and `mysqldump'.  (MySQL versions 4.0.6 and
  8032.      above can read the new dump files; older versions cannot.)
  8033.  
  8034.    * If you are running multiple servers on the same Windows machine,
  8035.      you should use a different `--shared_memory_base_name' option on
  8036.      all machines.
  8037.  
  8038.  
  8039. *Note:* The table definition format used in `.frm' files has changed
  8040. slightly in 4.1.  MySQL 4.0 versions from 4.0.11 on can read the new
  8041. `.frm' format directly, but older versions cannot.  If you need to move
  8042. tables from 4.1 to an earlier MySQL version, you should use `mysqldump'.
  8043. *Note `mysqldump': mysqldump.
  8044.  
  8045. If you are running MySQL Server on Windows, please also see *Note
  8046. Windows upgrading::.
  8047.  
  8048. What to do when upgrading from 4.0 to 4.1
  8049. .........................................
  8050.  
  8051. In general, upgrading to 4.1 from an earlier MySQL version involves the
  8052. following steps:
  8053.  
  8054.    * Check the changes section if there is some change that may affect
  8055.      your application. *Note Prepare-upgrade-4.0-4.1::.
  8056.  
  8057.    * Read the 4.1 news items to see what significant new features you
  8058.      can use in 4.1.  *Note News-4.1.x::.
  8059.  
  8060.    * Run the script `mysql_fix_privilege_tables' to generate the new
  8061.      longer `Password' column that is needed for secure handling of
  8062.      passwords.
  8063.  
  8064.  
  8065. The password hashing mechanism has changed in 4.1 to provide better
  8066. security, but this may cause compatibility problems if you still have
  8067. clients that use the client library from 4.0 or earlier.  (It is very
  8068. likely that you will have 4.0 clients in situations where clients
  8069. connect from remote hosts that have not yet upgraded to 4.1).  The
  8070. following list indicates some possible upgrade strategies.  They
  8071. represent various tradeoffs between the goal of compatibility with old
  8072. clients and the goal of security.
  8073.  
  8074.    * Don't upgrade to 4.1. No behaviour will change, but of course you
  8075.      cannot use any of the new features provided by the 4.1
  8076.      client/server protocol, either.  (MySQL 4.1 has an extended
  8077.      client/server protocol that offers such features as prepared
  8078.      statements and multiple result sets.)  *Note C API Prepared
  8079.      statements::.
  8080.  
  8081.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  8082.      widen the `Password' column in the `user' table so that it can
  8083.      hold long password hashes.  But run the server with the
  8084.      `--old-passwords' option to provide backward compatibility that
  8085.      allows pre-4.1 clients to continue to connect to their short-hash
  8086.      accounts.  Eventually, when all your clients are upgraded to 4.1,
  8087.      you can stop using the `--old-passwords' server option. You can
  8088.      also change the passwords for your MySQL accounts to use the new
  8089.      more secure format.
  8090.  
  8091.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  8092.      widen the `Password' column in the `user' table.  If you know that
  8093.      all clients also have been upgraded to 4.1, don't run the server
  8094.      with the `--old-passwords' option.  Instead, change the passwords
  8095.      on all existing accounts so that they have the new format.  A
  8096.      pure-4.1 installation is the most secure.
  8097.  
  8098.  
  8099. Further background on password hashing with respect to client
  8100. authentication and password-changing operations may be found in *Note
  8101. Password hashing::.
  8102.  
  8103. Upgrading From Version 3.23 to 4.0
  8104. ----------------------------------
  8105.  
  8106. In general, you should do the following when upgrading to 4.0 from an
  8107. earlier MySQL version:
  8108.  
  8109.    * Run the script `mysql_fix_privilege_tables' to add new privileges
  8110.      and features to the MySQL privilege tables.
  8111.  
  8112.    * Edit any MySQL startup scripts or configure files to not use any
  8113.      of the deprecated options described later in this section.
  8114.  
  8115.    * Convert your old `ISAM' files to `MyISAM' files with the
  8116.      `mysql_convert_table_format database' script. (This is a Perl
  8117.      script; it requires that DBI be installed.) To convert the tables
  8118.      in a given database, use this command:
  8119.  
  8120.           shell> mysql_convert_table_format database db_name
  8121.  
  8122.      Note that this should only be used if all tables in the given
  8123.      database are `ISAM' or `MyISAM' tables. To avoid converting tables
  8124.      of other types to `MyISAM', you can explicitly list the names of
  8125.      your `ISAM' tables after the database name on the command line.
  8126.      You can also issue a `ALTER TABLE table_name TYPE=MyISAM'
  8127.      statement for each `ISAM' table to convert it to `MyISAM'.
  8128.  
  8129.    * Ensure that you don't have any MySQL clients that use shared
  8130.      libraries (like the Perl `DBD-mysql' mode). If you do, you should
  8131.      recompile them, because the data structures used in
  8132.      `libmysqlclient.so' have changed.  The same applies to other MySQL
  8133.      interfaces as well, such as the Python `MySQLdb' module.
  8134.  
  8135.  
  8136. MySQL 4.0 will work even if you don't do the above, but you will not be
  8137. able to use the new security privileges that MySQL 4.0 and you may run
  8138. into problems when upgrading later to MySQL 4.1 or newer.  The `ISAM'
  8139. file format still works in MySQL 4.0 but it's deprecated and will be
  8140. disabled in MySQL 5.0.
  8141.  
  8142. Old clients should work with a Version 4.0 server without any problems.
  8143.  
  8144. Even if you do the above, you can still downgrade to MySQL 3.23.52 or
  8145. newer if you run into problems with the MySQL 4.0 series.  In this
  8146. case, you must use `mysqldump' to dump any tables that use full-text
  8147. indexes and reload the dump file into the 3.23 server.  This is
  8148. necessary because 4.0 uses a new format for full-text indexing.
  8149.  
  8150. The following is a more complete list that tells what you must watch out
  8151. for when upgrading to version 4.0:
  8152.  
  8153.    * MySQL 4.0 has a lot of new privileges in the `mysql.user' table.
  8154.      *Note `GRANT': GRANT.
  8155.  
  8156.      To get these new privileges to work, you must run the
  8157.      `mysql_fix_privilege_tables' script.  Until you do, all users have
  8158.      the `SHOW DATABASES', `CREATE TEMPORARY TABLES', and `LOCK TABLES'
  8159.      privileges. `SUPER' and `EXECUTE' privileges take their value from
  8160.      `PROCESS'.  `REPLICATION SLAVE' and `REPLICATION CLIENT' take their
  8161.      values from `FILE'.
  8162.  
  8163.      If you have any scripts that create new users, you may want to
  8164.      change them to use the new privileges.  If you are not using
  8165.      `GRANT' commands in the scripts, this is a good time to change
  8166.      your scripts to use `GRANT' instead of modifying the grant tables
  8167.      directly..
  8168.  
  8169.      From version 4.0.2 on, the option `--safe-show-database' is
  8170.      deprecated (and no longer does anything). *Note Privileges
  8171.      options::.
  8172.  
  8173.      If you get `Access denied' errors for new users in version 4.0.2
  8174.      and up, you should check if you need some of the new grants that
  8175.      you didn't need before.  In particular, you will need `REPLICATION
  8176.      SLAVE' (instead of `FILE') for new slaves.
  8177.  
  8178.    * `safe_mysqld' is renamed to `mysqld_safe'.  For backward
  8179.      compatibility, binary distributions will for some time include
  8180.      `safe_mysqld' as a symlink to `mysqld_safe'.
  8181.  
  8182.    * The startup parameters `myisam_max_extra_sort_file_size' and
  8183.      `myisam_max_extra_sort_file_size' are now given in bytes (they
  8184.      were given in megabytes before 4.0.3).
  8185.  
  8186.    * External system locking of `MyISAM'/`ISAM' files is now turned off
  8187.      by default.  Your can turn this on by doing `--external-locking'.
  8188.      (However, this is never needed for most users.)
  8189.  
  8190.    * The following startup variables/options have been renamed:
  8191.  
  8192.      *Old Name*                         *New Name*
  8193.      `myisam_bulk_insert_tree_size'     `bulk_insert_buffer_size'
  8194.      `query_cache_startup_type'         `query_cache_type'
  8195.      `record_buffer'                    `read_buffer_size'
  8196.      `record_rnd_buffer'                `read_rnd_buffer_size'
  8197.      `sort_buffer'                      `sort_buffer_size'
  8198.      `warnings'                         `log-warnings'
  8199.      `--err-log'                        `--log-error' (for `mysqld_safe')
  8200.  
  8201.      The startup options `record_buffer', `sort_buffer' and `warnings'
  8202.      will still work in MySQL 4.0 but are deprecated.
  8203.  
  8204.    * The following SQL variables have changed name.
  8205.  
  8206.      *Old Name*                         *New Name*
  8207.      `SQL_BIG_TABLES'                   `BIG_TABLES'
  8208.      `SQL_LOW_PRIORITY_UPDATES'         `LOW_PRIORITY_UPDATES'
  8209.      `SQL_MAX_JOIN_SIZE'                `MAX_JOIN_SIZE'
  8210.      `SQL_QUERY_CACHE_TYPE'             `QUERY_CACHE_TYPE'
  8211.      The old names still work in MySQL 4.0 but are deprecated.
  8212.  
  8213.    * You have to use `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=#' instead of
  8214.      `SET SQL_SLAVE_SKIP_COUNTER=#'.
  8215.  
  8216.    * The `mysqld' startup options `--skip-locking' and
  8217.      `--enable-locking' were renamed to `--skip-external-locking' and
  8218.      `--external-locking'.
  8219.  
  8220.    * `SHOW MASTER STATUS' now returns an empty set if binary logging is
  8221.      not enabled.
  8222.  
  8223.    * `SHOW SLAVE STATUS' now returns an empty set if slave is not
  8224.      initialised.
  8225.  
  8226.    * `mysqld' now has the option `--temp-pool' enabled by default as
  8227.      this gives better performance with some operating systems (most
  8228.      notably Linux).
  8229.  
  8230.    * `DOUBLE' and `FLOAT' columns now honour the `UNSIGNED' flag on
  8231.      storage (before, `UNSIGNED' was ignored for these columns).
  8232.  
  8233.    * `ORDER BY col_name DESC' sorts `NULL' values last, as of MySQL
  8234.      4.0.11. In 3.23 and in earlier 4.0 versions, this was not always
  8235.      consistent.
  8236.  
  8237.    * `SHOW INDEX' has two more columns (`Null' and `Index_type') than
  8238.      it had in 3.23.
  8239.  
  8240.    * `CHECK', `SIGNED', `LOCALTIME' and `LOCALTIMESTAMP' are now
  8241.      reserved words.
  8242.  
  8243.    * The result of all bitwise operators (`|', `&', `<<', `>>', and
  8244.      `~')) is now unsigned.  This may cause problems if you are using
  8245.      them in a context where you want a signed result.  *Note Cast
  8246.      Functions::.
  8247.  
  8248.    * *Note*: when you use subtraction between integer values where one
  8249.      is of type `UNSIGNED', the result will be unsigned.  In other
  8250.      words, before upgrading to MySQL 4.0, you should check your
  8251.      application for cases where you are subtracting a value from an
  8252.      unsigned entity and want a negative answer or subtracting an
  8253.      unsigned value from an integer column. You can disable this
  8254.      behaviour by using the `--sql-mode=NO_UNSIGNED_SUBTRACTION' option
  8255.      when starting `mysqld'.  *Note Cast Functions::.
  8256.  
  8257.    * To use `MATCH ... AGAINST (... IN BOOLEAN MODE)' with your tables,
  8258.      you need to rebuild them with `REPAIR TABLE table_name USE_FRM'.
  8259.  
  8260.    * `LOCATE()' and `INSTR()' are case-sensitive if one of the
  8261.      arguments is a binary string. Otherwise they are case-insensitive.
  8262.  
  8263.    * `STRCMP()' now uses the current character set when doing
  8264.      comparisons, which means that the default comparison behaviour now
  8265.      is case-insensitive.
  8266.  
  8267.    * `HEX(string)' now returns the characters in `string' converted to
  8268.      hexadecimal.  If you want to convert a number to hexadecimal, you
  8269.      should ensure that you call `HEX()' with a numeric argument.
  8270.  
  8271.    * In 3.23, `INSERT INTO ... SELECT' always had `IGNORE' enabled.  In
  8272.      4.0.1, MySQL will stop (and possibly roll back) by default in case
  8273.      of an error unless you specify `IGNORE'.
  8274.  
  8275.    * The old C API functions `mysql_drop_db()', `mysql_create_db()', and
  8276.      `mysql_connect()' are no longer supported unless you compile MySQL
  8277.      with `CFLAGS=-DUSE_OLD_FUNCTIONS'.  However, it is preferable to
  8278.      change client programs to use the new 4.0 API instead.
  8279.  
  8280.    * In the `MYSQL_FIELD' structure, `length' and `max_length' have
  8281.      changed from `unsigned int' to `unsigned long'. This should not
  8282.      cause any problems, except that they may generate warning messages
  8283.      when used as arguments in the `printf()' class of functions.
  8284.  
  8285.    * You should use `TRUNCATE TABLE' when you want to delete all rows
  8286.      from a table and you don't need to obtain a count of the number of
  8287.      rows that were deleted.  (`DELETE FROM table_name' returns a row
  8288.      count in 4.0, and `TRUNCATE TABLE' is faster.)
  8289.  
  8290.    * You will get an error if you have an active `LOCK TABLES' or
  8291.      transaction when trying to execute `TRUNCATE TABLE' or `DROP
  8292.      DATABASE'.
  8293.  
  8294.    * You should use integers to store values in `BIGINT' columns
  8295.      (instead of using strings, as you did in MySQL 3.23).  Using
  8296.      strings will still work, but using integers is more efficient.
  8297.  
  8298.    * The format of `SHOW OPEN TABLES' has changed.
  8299.  
  8300.    * Multi-threaded clients should use `mysql_thread_init()' and
  8301.      `mysql_thread_end()'. *Note Threaded clients::.
  8302.  
  8303.    * If you want to recompile the Perl `DBD::mysql' module, you must get
  8304.      `DBD-mysql' version 1.2218 or newer because older DBD modules used
  8305.      the deprecated `mysql_drop_db()' call.  Version 2.1022 or newer is
  8306.      recommended.
  8307.  
  8308.    * `RAND(seed)' returns a different random number series in 4.0 than
  8309.      in 3.23; this was done to further differentiate `RAND(seed)' and
  8310.      `RAND(seed+1)'.
  8311.  
  8312.    * The default type returned by `IFNULL(A,B)' is now set to be the
  8313.      more 'general' of the types of `A' and `B'. (The
  8314.      general-to-specific order is string, `REAL' or `INTEGER').
  8315.  
  8316.  
  8317. If you are running MySQL Server on Windows, please also see *Note
  8318. Windows upgrading::. If you are using replication, please also see
  8319. *Note Replication Implementation::.
  8320.  
  8321. Upgrading From Version 3.22 to 3.23
  8322. -----------------------------------
  8323.  
  8324. MySQL Version 3.23 supports tables of the new `MyISAM' type and the old
  8325. `ISAM' type.  You don't have to convert your old tables to use these
  8326. with Version 3.23.  By default, all new tables will be created with
  8327. type `MyISAM' (unless you start `mysqld' with the
  8328. `--default-table-type=isam' option). You can convert an `ISAM' table to
  8329. `MyISAM' format with `ALTER TABLE table_name TYPE=MyISAM' or the Perl
  8330. script `mysql_convert_table_format'.
  8331.  
  8332. Version 3.22 and 3.21 clients will work without any problems with a
  8333. Version 3.23 server.
  8334.  
  8335. The following list tells what you have to watch out for when upgrading
  8336. to Version 3.23:
  8337.  
  8338.    * All tables that use the `tis620' character set must be fixed with
  8339.      `myisamchk -r' or `REPAIR TABLE'.
  8340.  
  8341.    * If you do a `DROP DATABASE' on a symbolically-linked database,
  8342.      both the link and the original database are deleted.  (This didn't
  8343.      happen in 3.22 because `configure' didn't detect the availability
  8344.      of the `readlink()' system call.)
  8345.  
  8346.    * `OPTIMIZE TABLE' now works only for `MyISAM' tables.  For other
  8347.      table types, you can use `ALTER TABLE' to optimise the table.
  8348.      During `OPTIMIZE TABLE', the table is now locked to prevent it
  8349.      from being used by other threads.
  8350.  
  8351.    * The MySQL client `mysql' is now by default started with the option
  8352.      `--no-named-commands (-g)'. This option can be disabled with
  8353.      `--enable-named-commands (-G)'. This may cause incompatibility
  8354.      problems in some cases--for example, in SQL scripts that use named
  8355.      commands without a semicolon.  Long format commands still work
  8356.      from the first line.
  8357.  
  8358.    * Date functions that work on parts of dates (like `MONTH()') will
  8359.      now return 0 for `0000-00-00' dates. (In MySQL 3.22, these
  8360.      functions returned `NULL'.)
  8361.  
  8362.    * If you are using the `german' character sort order for `ISAM'
  8363.      tables, you must repair them with `isamchk -r', because we have
  8364.      made some changes in the sort order.
  8365.  
  8366.    * The default return type of `IF()' now depends on both arguments
  8367.      and not only the first argument.
  8368.  
  8369.    * `AUTO_INCREMENT' columns should not be used to store negative
  8370.      numbers. The reason for this is that negative numbers caused
  8371.      problems when wrapping from -1 to 0.  You should not store 0 in
  8372.      `AUTO_INCREMENT' columns, either; `CHECK TABLE' will complain
  8373.      about 0 values because they may change if you dump and restore the
  8374.      table.  `AUTO_INCREMENT' for `MyISAM' tables is now handled at a
  8375.      lower level and is much faster than before. In addition, for
  8376.      `MyISAM' tables, old numbers are no longer reused, even if you
  8377.      delete rows from the table.
  8378.  
  8379.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  8380.      `THEN', and `WHEN' are now reserved words.
  8381.  
  8382.    * `FLOAT(X)' is now a true floating-point type and not a value with a
  8383.      fixed number of decimals.
  8384.  
  8385.    * When declaring columns using a `DECIMAL(length,dec)' type, the
  8386.      `length' argument no longer includes a place for the sign or the
  8387.      decimal point.
  8388.  
  8389.    * A `TIME' string must now be of one of the following formats:
  8390.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  8391.      `[[[[[H]H]H]H]MM]SS[.fraction]'.
  8392.  
  8393.    * `LIKE' now compares strings using the same character comparison
  8394.      rules as for the `=' operator.  If you require the old behaviour,
  8395.      you can compile MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  8396.  
  8397.    * `REGEXP' is now case-insensitive if neither of the strings are
  8398.      binary strings.
  8399.  
  8400.    * When you check or repair `MyISAM' (`.MYI') tables, you should use
  8401.      the `CHECK TABLE' statement or the `myisamchk' command. For `ISAM'
  8402.      (`.ISM') tables, use the `isamchk' command.
  8403.  
  8404.    * If you want your `mysqldump' files to be compatible between MySQL
  8405.      Version 3.22 and Version 3.23, you should not use the `--opt' or
  8406.      `--all' option to `mysqldump'.
  8407.  
  8408.    * Check all your calls to `DATE_FORMAT()' to make sure there is a
  8409.      `%' before each format character.  (MySQL Version 3.22 and later
  8410.      already allowed this syntax.)
  8411.  
  8412.    * `mysql_fetch_fields_direct()' is now a function (it used to be a
  8413.      macro) and it returns a pointer to a `MYSQL_FIELD' instead of a
  8414.      `MYSQL_FIELD'.
  8415.  
  8416.    * `mysql_num_fields()' can no longer be used on a `MYSQL*' object
  8417.      (it's now a function that takes a `MYSQL_RES*' value as an
  8418.      argument). With a `MYSQL*' object, you should now use
  8419.      `mysql_field_count()' instead.
  8420.  
  8421.    * In MySQL Version 3.22, the output of `SELECT DISTINCT ...' was
  8422.      almost always sorted.  In Version 3.23, you must use `GROUP BY' or
  8423.      `ORDER BY' to obtain sorted output.
  8424.  
  8425.    * `SUM()' now returns `NULL' instead of 0 if there are no matching
  8426.      rows. This is required by SQL-99.
  8427.  
  8428.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  8429.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  8430.      expression as `NOT NULL' = `NULL'.
  8431.  
  8432.    * `LPAD()' and `RPAD()' now shorten the result string if it's longer
  8433.      than the length argument.
  8434.  
  8435. Upgrading from Version 3.21 to 3.22
  8436. -----------------------------------
  8437.  
  8438. Nothing that affects compatibility has changed between versions 3.21
  8439. and 3.22.  The only pitfall is that new tables that are created with
  8440. `DATE' type columns will use the new way to store the date. You can't
  8441. access these new columns from an old version of `mysqld'.
  8442.  
  8443. After installing MySQL Version 3.22, you should start the new server
  8444. and then run the `mysql_fix_privilege_tables' script. This will add the
  8445. new privileges that you need to use the `GRANT' command.  If you forget
  8446. this, you will get `Access denied' when you try to use `ALTER TABLE',
  8447. `CREATE INDEX', or `DROP INDEX'. If your MySQL `root' user requires a
  8448. password, you should give this as an argument to
  8449. `mysql_fix_privilege_tables'.
  8450.  
  8451. The C API interface to `mysql_real_connect()' has changed.  If you have
  8452. an old client program that calls this function, you must place a `0' for
  8453. the new `db' argument (or recode the client to send the `db' element
  8454. for faster connections).  You must also call `mysql_init()' before
  8455. calling `mysql_real_connect()'.  This change was done to allow the new
  8456. `mysql_options()' function to save options in the `MYSQL' handler
  8457. structure.
  8458.  
  8459. The `mysqld' variable `key_buffer' has been renamed to
  8460. `key_buffer_size', but you can still use the old name in your startup
  8461. files.
  8462.  
  8463. Upgrading from Version 3.20 to 3.21
  8464. -----------------------------------
  8465.  
  8466. If you are running a version older than Version 3.20.28 and want to
  8467. switch to Version 3.21, you need to do the following:
  8468.  
  8469. You can start the `mysqld' Version 3.21 server with the
  8470. `--old-protocol' option to use it with clients from a Version 3.20
  8471. distribution.  In this case, the new client function `mysql_errno()'
  8472. will not return any server error, only `CR_UNKNOWN_ERROR' (but it works
  8473. for client errors), and the server uses the old pre-3.21 `password()'
  8474. checking rather than the new method.
  8475.  
  8476. If you are *not* using the `--old-protocol' option to `mysqld', you
  8477. will need to make the following changes:
  8478.  
  8479.    * All client code must be recompiled. If you are using ODBC, you
  8480.      must get the new `MyODBC' 2.x driver.
  8481.  
  8482.    * The script `scripts/add_long_password' must be run to convert the
  8483.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  8484.  
  8485.    * All passwords must be reassigned in the `mysql.user' table (to get
  8486.      62-bit rather than 31-bit passwords).
  8487.  
  8488.    * The table format hasn't changed, so you don't have to convert any
  8489.      tables.
  8490.  
  8491.  
  8492. MySQL Version 3.20.28 and above can handle the new `user' table format
  8493. without affecting clients. If you have a MySQL version earlier than
  8494. Version 3.20.28, passwords will no longer work with it if you convert
  8495. the `user' table. So to be safe, you should first upgrade to at least
  8496. Version 3.20.28 and then upgrade to Version 3.21.
  8497.  
  8498. The new client code works with a 3.20.x `mysqld' server, so if you
  8499. experience problems with 3.21.x, you can use the old 3.20.x server
  8500. without having to recompile the clients again.
  8501.  
  8502. If you are not using the `--old-protocol' option to `mysqld', old
  8503. clients will be unable to connect and will issue the following error
  8504. message:
  8505.  
  8506.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  8507.  
  8508. The new Perl `DBI'/`DBD' interface also supports the old `mysqlperl'
  8509. interface.  The only change you have to make if you use `mysqlperl' is
  8510. to change the arguments to the `connect()' function.  The new arguments
  8511. are: `host', `database', `user', and `password' (note that the `user'
  8512. and `password' arguments have changed places).  *Note Perl `DBI' Class:
  8513. Perl DBI Class.
  8514.  
  8515. The following changes may affect queries in old applications:
  8516.  
  8517.    * `HAVING' must now be specified before any `ORDER BY' clause.
  8518.  
  8519.    * The parameters to `LOCATE()' have been swapped.
  8520.  
  8521.    * There are some new reserved words. The most notable are `DATE',
  8522.      `TIME', and `TIMESTAMP'.
  8523.  
  8524.  
  8525. Upgrading to Another Architecture
  8526. ---------------------------------
  8527.  
  8528. If you are using MySQL Version 3.23, you can copy the `.frm', `.MYI',
  8529. and `.MYD' files for `MyISAM' tables between different architectures
  8530. that support the same floating-point format.  (MySQL takes care of any
  8531. byte-swapping issues.)  *Note `MyISAM' Tables: MyISAM.
  8532.  
  8533. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  8534. respectively) are architecture-dependent and in some cases
  8535. OS-dependent.  If you want to move your applications to another machine
  8536. that has a different architecture or OS than your current machine, you
  8537. should not try to move a database by simply copying the files to the
  8538. other machine. Use `mysqldump' instead.
  8539.  
  8540. By default, `mysqldump' will create a file containing SQL statements.
  8541. You can then transfer the file to the other machine and feed it as input
  8542. to the `mysql' client.
  8543.  
  8544. Try `mysqldump --help' to see what options are available.  If you are
  8545. moving the data to a newer version of MySQL, you should use `mysqldump
  8546. --opt' with the newer version to get a fast, compact dump.
  8547.  
  8548. The easiest (although not the fastest) way to move a database between
  8549. two machines is to run the following commands on the machine on which
  8550. the database is located:
  8551.  
  8552.      shell> mysqladmin -h 'other hostname' create db_name
  8553.      shell> mysqldump --opt db_name \
  8554.              | mysql -h 'other hostname' db_name
  8555.  
  8556. If you want to copy a database from a remote machine over a slow
  8557. network, you can use:
  8558.  
  8559.      shell> mysqladmin create db_name
  8560.      shell> mysqldump -h 'other hostname' --opt --compress db_name \
  8561.              | mysql db_name
  8562.  
  8563. You can also store the result in a file, then transfer the file to the
  8564. target machine and load the file into the database there.  For example,
  8565. you can dump a database to a file on the source machine like this:
  8566.  
  8567.      shell> mysqldump --quick db_name | gzip > db_name.contents.gz
  8568.  
  8569. (The file created in this example is compressed.) Transfer the file
  8570. containing the database contents to the target machine and run these
  8571. commands there:
  8572.  
  8573.      shell> mysqladmin create db_name
  8574.      shell> gunzip < db_name.contents.gz | mysql db_name
  8575.  
  8576. You can also use `mysqldump' and `mysqlimport' to transfer the database.
  8577. For big tables, this is much faster than simply using `mysqldump'.  In
  8578. the following commands, `DUMPDIR' represents the full pathname of the
  8579. directory you use to store the output from `mysqldump'.
  8580.  
  8581. First, create the directory for the output files and dump the database:
  8582.  
  8583.      shell> mkdir DUMPDIR
  8584.      shell> mysqldump --tab=DUMPDIR db_name
  8585.  
  8586. Then transfer the files in the `DUMPDIR' directory to some corresponding
  8587. directory on the target machine and load the files into MySQL there:
  8588.  
  8589.      shell> mysqladmin create db_name           # create database
  8590.      shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
  8591.      shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables
  8592.  
  8593. Also, don't forget to copy the `mysql' database because that's where the
  8594. grant tables (`user', `db', `host') are stored.  You may have to run
  8595. commands as the MySQL `root' user on the new machine until you have the
  8596. `mysql' database in place.
  8597.  
  8598. After you import the `mysql' database on the new machine, execute
  8599. `mysqladmin flush-privileges' so that the server reloads the grant table
  8600. information.
  8601.  
  8602. Upgrading MySQL under Windows
  8603. -----------------------------
  8604.  
  8605. When upgrading MySQL under Windows, please follow these steps:
  8606.  
  8607.   1. Download the latest Windows distribution of MySQL.
  8608.  
  8609.   2. Choose a time of day with low usage, where a maintenance break is
  8610.      acceptable.
  8611.  
  8612.   3. Alert the users that still are active about the maintenance break.
  8613.  
  8614.   4. Stop the running MySQL Server (for example, with `NET STOP mysql'
  8615.      if you are running MySQL as a service, or with `mysqladmin
  8616.      shutdown' otherwise).
  8617.  
  8618.   5. Exit the `WinMySQLadmin' program if it is running.
  8619.  
  8620.   6. Run the installation script of the Windows distribution, by
  8621.      clicking the "Install" button in WinZip and following the
  8622.      installation steps of the script.
  8623.  
  8624.   7. You may either overwrite your old MySQL installation (usually
  8625.      located at `C:\mysql'), or install it into a different directory,
  8626.      such as `C:\mysql4'. Overwriting the old installation is
  8627.      recommended.
  8628.  
  8629.   8. The version of MySQL that is started as a service is determined by
  8630.      the `basedir' parameter in the `my.ini' file of your Windows
  8631.      directory (for example, `C:\WINNT').
  8632.  
  8633.   9. Restart the server (for example, with `NET START mysql' if you run
  8634.      MYSQL as a service, or by invoking `mysqld' directly otherwise).
  8635.  
  8636.  
  8637. Possible error situations:
  8638.      A system error has occurred.
  8639.      System error 1067 has occurred.
  8640.      The process terminated unexpectedly.
  8641.  
  8642. This cryptic error means that your `my.cnf' file (by default
  8643. `C:\my.cnf') contains an option that cannot be recognised by MySQL. You
  8644. can verify that this is the case by trying to restart MySQL with the
  8645. `my.cnf' file renamed, for example, to `my.cnf.old' to prevent the
  8646. server from using it.  Once you have verified it, you need to identify
  8647. which option is the culprit. Create a new `my.cnf' file and move parts
  8648. of the old file to it (restarting the server after you move each part)
  8649. until you determine which part causes server startup to fail.
  8650.  
  8651. Operating System Specific Notes
  8652. ===============================
  8653.  
  8654. Windows Notes
  8655. -------------
  8656.  
  8657. This section describes using MySQL on Windows. This information is also
  8658. provided in the `README' file that comes with the MySQL Windows
  8659. distribution. *Note Windows installation::.
  8660.  
  8661. On Windows 95, 98, or Me, MySQL clients always connect to the server
  8662. using TCP/IP. On NT-based systems such as Windows NT, 2000, or XP,
  8663. clients have two options. They can use TCP/IP, or they can use a named
  8664. pipe if the server supports named pipe connections.
  8665.  
  8666. For information about which server binary to run, see *Note Windows
  8667. prepare environment::.
  8668.  
  8669. The examples in this section assume that MySQL is installed under the
  8670. default location of `C:\mysql'. Adjust the pathnames shown in the
  8671. examples if you have MySQL installed in a different location.
  8672.  
  8673. Starting MySQL on Windows 95, 98, or Me
  8674. .......................................
  8675.  
  8676. On these versions of Windows, MySQL uses TCP/IP to connect a client to
  8677. a server. (This will allow any machine on your network to connect to
  8678. your MySQL server.)  Because of this, you must make sure that TCP/IP
  8679. support is installed on your machine before starting MySQL.  You can
  8680. find TCP/IP on your Windows CD-ROM.
  8681.  
  8682. Note that if you are using an old Windows 95 release (for example,
  8683. OSR2), it's likely that you have an old Winsock package; MySQL requires
  8684. Winsock 2! You can get the newest Winsock from
  8685. `http://www.microsoft.com/'.  Windows 98 has the new Winsock 2 library,
  8686. so it is unnecessary to update the library.
  8687.  
  8688. To start the `mysqld' server, you should start a console window (a
  8689. "DOS" window) and enter this command:
  8690.  
  8691.      shell> C:\mysql\bin\mysqld
  8692.  
  8693. This will start `mysqld' in the background. That is, after the server
  8694. starts up, you should see another command prompt. (Note that if you
  8695. start the server this way on Windows NT, 2000, or XP, the server will
  8696. run in the foreground and the next command prompt will not appear until
  8697. the server exits.  To run client programs while the server is running,
  8698. you should open another console window.)
  8699.  
  8700. You can stop the MySQL server by executing this command:
  8701.  
  8702.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  8703.  
  8704. This invokes the MySQL administrative utility `mysqladmin' to connect
  8705. to the server as `root', which is the default administrative account in
  8706. the MySQL grant system. Please note that users in the MySQL grant
  8707. system are wholly independent from any login users under Windows.
  8708.  
  8709. If `mysqld' doesn't start, please check the error log to see if the
  8710. server wrote any messages there to indicate the cause of the problem.
  8711. The error log is located in the `C:\mysql\data' directory. It is the
  8712. file with a suffix of `.err'. You can also try to start the server as
  8713. `mysqld --console'; in this case, you may get some useful information
  8714. on the screen that may help solve the problem.
  8715.  
  8716. The last option is to start `mysqld' with `--standalone --debug'.  In
  8717. this case `mysqld' will write a log file `C:\mysqld.trace' that should
  8718. contain the reason why `mysqld' doesn't start. *Note Making trace
  8719. files::.
  8720.  
  8721. Use `mysqld --help' to display all the options that `mysqld'
  8722. understands!
  8723.  
  8724. Starting MySQL on Windows NT, 2000, or XP
  8725. .........................................
  8726.  
  8727. To get MySQL to work with TCP/IP on Windows NT 4, you must install
  8728. service pack 3 (or newer)!
  8729.  
  8730. Normally you should install MySQL as a service on Windows NT/2000/XP.
  8731. In case the server was already running, first stop it using the
  8732. following command:
  8733.  
  8734.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  8735.  
  8736. This invokes the MySQL administrative utility `mysqladmin' to connect
  8737. to the server as `root', which is the default administrative account in
  8738. the MySQL grant system. Please note that users in the MySQL grant
  8739. system are wholly independent from any login users under Windows.
  8740.  
  8741. Now install the server as a service:
  8742.  
  8743.      shell> C:\mysql\bin\mysqld --install
  8744.  
  8745. The service is installed with the name `MySql'. Once installed, it can
  8746. be immediately started from the `Services' utility, or by using the
  8747. command `NET START MySql'.
  8748.  
  8749. Once running, `mysqld' can be stopped by using the Services utility,
  8750. the command `NET STOP MySql', or the command `mysqladmin shutdown'.
  8751.  
  8752. If any startup options are required, you can place them in the
  8753. `[mysqld]' group of any of the standard option files. As of MySQL
  8754. 4.0.3, you can place options in the `[mysqld]' group of any option file
  8755. and use a `--defaults-file' option to tell the server the name of the
  8756. file when you install the service. For example:
  8757.  
  8758.      shell> C:\mysql\bin\mysqld --install MySql --defaults-file=C:\my-opts.cnf
  8759.  
  8760. You can also specify options as "`Start parameters'" in the Windows
  8761. `Services' utility before you start the MySQL service.
  8762.  
  8763. The `Services' utility (`Windows Service Control Manager') can be found
  8764. in the `Windows Control Panel' (under `Administrative Tools' on Windows
  8765. 2000). It is advisable to close the Services utility while performing
  8766. the `--install' or `--remove' operations, this prevents some odd errors.
  8767.  
  8768. Please note that from MySQL version 3.23.44, you have the choice of
  8769. setting up the service as `Manual' instead (if you don't wish the
  8770. service to be started automatically during the boot process):
  8771.  
  8772.      shell> C:\mysql\bin\mysqld --install-manual
  8773.  
  8774. When MySQL is running as a service, the operating system will
  8775. automatically stop the server on computer shutdown. In MySQL versions
  8776. older than 3.23.47, Windows waited only for a few seconds for the
  8777. shutdown to complete, and killed the database server process if the
  8778. time limit was exceeded. This had the potential to cause problems.
  8779. (For example, at the next startup the `InnoDB' storage engine had to do
  8780. crash recovery.) Starting from MySQL version 3.23.48, Windows waits
  8781. longer for the MySQL server shutdown to complete. If you notice this
  8782. still is not enough for your installation, it is safest not to run the
  8783. MySQL server as a service. Instead, run it from the command-line
  8784. prompt, and shut it down with `mysqladmin shutdown'.
  8785.  
  8786. There is a problem that Windows NT (but not Windows 2000/XP) by default
  8787. only waits 20 seconds for a service to shut down, and after that kills
  8788. the service process. You can increase this default by opening the
  8789. Registry Editor `\winnt\system32\regedt32.exe' and editing the value of
  8790. `WaitToKillServiceTimeout' at
  8791. `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' in the Registry
  8792. tree. Specify the new larger value in milliseconds (for example, 120000
  8793. to have Windows NT wait up to 120 seconds).
  8794.  
  8795. Please note that when run as a service, `mysqld' has no access to a
  8796. console and so no messages can be seen.  Errors can be checked in the
  8797. error log, which is located in the `C:\mysql\data' directory. It is the
  8798. file with a suffix of `.err'.
  8799.  
  8800. If you have problems installing `mysqld' as a service using just the
  8801. server name, try installing it using its full pathname:
  8802.  
  8803.      shell> C:\mysql\bin\mysqld --install
  8804.  
  8805. If that doesn't work, you can get `mysqld' to start properly by fixing
  8806. the path in the registry!
  8807.  
  8808. If you don't want to start `mysqld' as a service, you can start it from
  8809. the command line the same way as for Windows 95, 98, or Me. For
  8810. instructions, see *Note Win95 start::.
  8811.  
  8812. Running MySQL on Windows
  8813. ........................
  8814.  
  8815. MySQL supports TCP/IP on all Windows platforms. The `mysqld-nt' and
  8816. `mysql-max-nt' servers support named pipes on NT, 2000, and XP.  The
  8817. default is to use TCP/IP regardless of the platform, because named
  8818. pipes are actually slower than TCP/IP, and because some users have
  8819. experienced problems shutting down the MySQL server when named pipes
  8820. are used. Starting from 3.23.50, named pipes are only enabled for
  8821. `mysqld-nt' and `mysql-max-nt' if they are started with the
  8822. `--enable-named-pipe' option.
  8823.  
  8824. You can force a MySQL client to use named pipes by specifying the
  8825. `--pipe' option or by specifying `.' as the host name.  Use the
  8826. `--socket' option to specify the name of the pipe.  In MySQL 4.1, you
  8827. should use the `--protocol=PIPE' option.
  8828.  
  8829. You can test whether the MySQL server is working by executing any of the
  8830. following commands:
  8831.  
  8832.      C:\> C:\mysql\bin\mysqlshow
  8833.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  8834.      C:\> C:\mysql\bin\mysqladmin version status proc
  8835.      C:\> C:\mysql\bin\mysql test
  8836.  
  8837. If `mysqld' is slow to answer to connections on Windows 9x/Me, there is
  8838. probably a problem with your DNS.  In this case, start `mysqld' with the
  8839. `--skip-name-resolve' option and use only `localhost' and IP numbers in
  8840. the `Host' column of the MySQL grant tables.
  8841.  
  8842. There are two versions of the MySQL command-line tool:
  8843. *Binary**Description*
  8844. `mysql' Compiled on native Windows, offering
  8845.         limited text editing capabilities.
  8846. `mysqlc'Compiled with the Cygnus GNU compiler and
  8847.         libraries, which offers `readline' editing.
  8848.  
  8849. If you want to use `mysqlc', you must have a copy of the
  8850. `cygwinb19.dll' library installed somewhere that `mysqlc' can find it.
  8851. If your distribution of MySQL doesn't have this library installed in the
  8852. same directory as `mysqlc' (the `bin' directory under the base
  8853. directory of your MySQL installation, look in the `lib' directory to
  8854. find it and copy it to your Windows system directory (`\windows\system'
  8855. or similar place).
  8856.  
  8857. The default privileges on Windows give all local users full privileges
  8858. to all databases without specifying a password.  To make MySQL more
  8859. secure, you should set a password for all users and remove the row in
  8860. the `mysql.user' table that has `Host='localhost'' and `User='''.
  8861.  
  8862. You should also add a password for the `root' user. The following
  8863. example starts by removing the anonymous user that has all privileges,
  8864. then sets a `root' user password:
  8865.  
  8866.      C:\> C:\mysql\bin\mysql mysql
  8867.      mysql> DELETE FROM user WHERE Host='localhost' AND User='';
  8868.      mysql> QUIT
  8869.      C:\> C:\mysql\bin\mysqladmin reload
  8870.      C:\> C:\mysql\bin\mysqladmin -u root password your_password
  8871.  
  8872. After you've set the password, if you want to shut down the `mysqld'
  8873. server, you can do so using this command:
  8874.  
  8875.      C:\> mysqladmin --user=root --password=your_password shutdown
  8876.  
  8877. If you are using the old shareware version of MySQL Version 3.21 under
  8878. Windows, the above command will fail with an error: `parse error near
  8879. 'SET password''.  The solution to this problem is to upgrade to a newer
  8880. version of MySQL.
  8881.  
  8882. With the current MySQL versions you can easily add new users and change
  8883. privileges with `GRANT' and `REVOKE' commands.  *Note `GRANT': GRANT.
  8884.  
  8885. Connecting to MySQL Remotely from Windows with SSH
  8886. ..................................................
  8887.  
  8888. Here is a note about how to connect to get a secure connection to remote
  8889. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  8890.  
  8891.   1. Install an SSH client on your Windows machine.  As a user, the
  8892.      best non-free one I've found is from `SecureCRT' from
  8893.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  8894.      `http://www.f-secure.com/'. You can also find some free ones on
  8895.      `Google' at
  8896.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  8897.  
  8898.   2. Start your Windows SSH client.  Set `Host_Name =
  8899.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  8900.      your server (probably not the same as your MySQL login/password.
  8901.  
  8902.   3. Set up port forwarding. Either do a remote forward (Set
  8903.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  8904.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  8905.      `host: localhost', `remote port: 3306').
  8906.  
  8907.   4. Save everything, otherwise you'll have to redo it the next time.
  8908.  
  8909.   5. Log in to your server with SSH session you just created.
  8910.  
  8911.   6. On your Windows machine, start some ODBC application (such as
  8912.      Access).
  8913.  
  8914.   7. Create a new file in Windows and link to MySQL using the ODBC
  8915.      driver the same way you normally do, except type in `localhost'
  8916.      for the MySQL host server--not `yourmysqlservername'.
  8917.  
  8918. You should now have an ODBC connection to MySQL, encrypted using SSH.
  8919.  
  8920. Distributing Data Across Different Disks on Windows
  8921. ...................................................
  8922.  
  8923. Beginning with MySQL Version 3.23.16, the `mysqld-max' and
  8924. `mysql-max-nt' servers in the MySQL distribution are compiled with the
  8925. `-DUSE_SYMDIR' option.  This allows you to put a database on a
  8926. different disk by setting up a symbolic link to it (in a manner similar
  8927. to the way that symbolic links work on Unix).
  8928.  
  8929. On Windows, you make a symbolic link to a database by creating a file
  8930. that contains the path to the destination directory and saving this in
  8931. the data directory using the filename `db_name.sym', where `db_name' is
  8932. the database name.  Note that the symbolic link will not be used if a
  8933. directory with the database name exists.
  8934.  
  8935. For example, if the MySQL data directory is `C:\mysql\data' and you
  8936. want to have database `foo' located at `D:\data\foo', you should create
  8937. the file `C:\mysql\data\foo.sym' that contains the text `D:\data\foo\'.
  8938. After that, all tables created in the database `foo' will be created
  8939. in `D:\data\foo'.
  8940.  
  8941. Note that because of the speed penalty you get when opening every table,
  8942. we have not enabled this by default even if you have compiled MySQL
  8943. with support for this. To enable symlinks you should put in your
  8944. `my.cnf' or `my.ini' file the following entry:
  8945.  
  8946.      [mysqld]
  8947.      symbolic-links
  8948.  
  8949. In MySQL 4.0, symbolic links are enabled by default. If you don't need
  8950. them, you can disable them with the `skip-symbolic-links' option.
  8951.  
  8952. Compiling MySQL Clients on Windows
  8953. ..................................
  8954.  
  8955. In your source files, you should include `my_global.h' before `mysql.h':
  8956.  
  8957.      #include <my_global.h>
  8958.      #include <mysql.h>
  8959.  
  8960. `my_global.h' includes any other files needed for Windows compatibility
  8961. (such as `windows.h') if you compile your program on Windows.
  8962.  
  8963. You can either link your code with the dynamic `libmysql.lib' library,
  8964. which is just a wrapper to load in `libmysql.dll' on demand, or link
  8965. with the static `mysqlclient.lib' library.
  8966.  
  8967. Note that because the MySQL client libraries are compiled as threaded
  8968. libraries, you should also compile your code to be multi-threaded!
  8969.  
  8970. MySQL for Windows Compared to Unix MySQL
  8971. ........................................
  8972.  
  8973. MySQL for Windows has by now proven itself to be very stable. The
  8974. Windows version of MySQL has the same features as the corresponding
  8975. Unix version, with the following exceptions:
  8976.  
  8977. *Windows 95 and threads*
  8978.      Windows 95 leaks about 200 bytes of main memory for each thread
  8979.      creation.  Each connection in MySQL creates a new thread, so you
  8980.      shouldn't run `mysqld' for an extended time on Windows 95 if your
  8981.      server handles many connections!  Other versions of Windows don't
  8982.      suffer from this bug.
  8983.  
  8984. *Concurrent reads*
  8985.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  8986.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  8987.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  8988.      level interface with a virtual interface so that we can use the
  8989.      `readfile()'/`writefile()' interface on NT/2000/XP to get more
  8990.      speed.  The current implementation limits the number of open files
  8991.      MySQL can use to 1024, which means that you will not be able to
  8992.      run as many concurrent threads on NT/2000/XP as on Unix.
  8993.  
  8994. *Blocking read*
  8995.      MySQL uses a blocking read for each connection, which has the
  8996.      following implications:
  8997.  
  8998.         * A connection will not be disconnected automatically after 8
  8999.           hours, as happens with the Unix version of MySQL.
  9000.  
  9001.         * If a connection hangs, it's impossible to break it without
  9002.           killing MySQL.
  9003.  
  9004.         * `mysqladmin kill' will not work on a sleeping connection.
  9005.  
  9006.         * `mysqladmin shutdown' can't abort as long as there are
  9007.           sleeping connections.
  9008.  
  9009.      We plan to fix this problem when our Windows developers have
  9010.      figured out a nice workaround.
  9011.  
  9012. *`DROP DATABASE'*
  9013.      You can't drop a database that is in use by some thread.
  9014.  
  9015. *Killing MySQL from the task manager*
  9016.      You can't kill MySQL from the task manager or with the shutdown
  9017.      utility in Windows 95.  You must take it down with `mysqladmin
  9018.      shutdown'.
  9019.  
  9020. *Case-insensitive names*
  9021.      Filenames are case-insensitive on Windows, so database and table
  9022.      names are also case-insensitive in MySQL for Windows.  The only
  9023.      restriction is that database and table names must be specified
  9024.      using the same case throughout a given statement.  *Note Name case
  9025.      sensitivity::.
  9026.  
  9027. *The `\' directory character*
  9028.      Pathname components in Windows 95 are separated by the `\'
  9029.      character, which is also the escape character in MySQL.  If you
  9030.      are using `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', you
  9031.      must double the `\' character:
  9032.  
  9033.           mysql> LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
  9034.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  9035.  
  9036.      Alternatively, use Unix style filenames with `/' characters:
  9037.  
  9038.           mysql> LOAD DATA INFILE "C:/tmp/skr.txt" INTO TABLE skr;
  9039.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  9040.  
  9041. *Problems with pipes.*
  9042.      Pipes doesn't work reliably in the Windows command-line prompt.
  9043.      If the pipe includes the character `^Z' / `CHAR(24)', Windows will
  9044.      think it has encountered end-of-file and abort the program.
  9045.  
  9046.      This is mainly a problem when you try to apply a binary log as
  9047.      follows:
  9048.  
  9049.           mysqlbinlog binary-log-name | mysql --user=root
  9050.  
  9051.      If you get a problem applying the log and suspect it's because of
  9052.      an `^Z' / `CHAR(24)' character you can use the following
  9053.      workaround:
  9054.  
  9055.           mysqlbinlog binary-log-file --result-file=/tmp/bin.sql
  9056.           mysql --user=root --execute "source /tmp/bin.sql"
  9057.  
  9058.      The latter command also can be used to reliably read in any SQL
  9059.      file that may contain binary data.
  9060.  
  9061. *`Can't open named pipe' error*
  9062.      If you use a MySQL 3.22 version on NT with the newest mysql-clients
  9063.      you will get the following error:
  9064.  
  9065.           error 2017: can't open named pipe to host: . pipe...
  9066.  
  9067.      This is because the release version of MySQL uses named pipes on NT
  9068.      by default.  You can avoid this error by using the
  9069.      `--host=localhost' option to the new MySQL clients or create an
  9070.      option file `C:\my.cnf' that contains the following information:
  9071.  
  9072.           [client]
  9073.           host = localhost
  9074.  
  9075.      Starting from 3.23.50, named pipes are enabled only if `mysqld-nt'
  9076.      or `mysqld-max-nt' is started with `--enable-named-pipe'.
  9077.  
  9078. *`Access denied for user' error*
  9079.      If you get the error `Access denied for user: 'some-user@unknown'
  9080.      to database 'mysql'' when accessing a MySQL server on the same
  9081.      machine, this means that MySQL can't resolve your host name
  9082.      properly.
  9083.  
  9084.      To fix this, you should create a file `\windows\hosts' with the
  9085.      following information:
  9086.  
  9087.           127.0.0.1       localhost
  9088.  
  9089. *`ALTER TABLE'*
  9090.      While you are executing an `ALTER TABLE' statement, the table is
  9091.      locked from usage by other threads.  This has to do with the fact
  9092.      that on Windows, you can't delete a file that is in use by another
  9093.      threads.  (In the future, we may find some way to work around this
  9094.      problem.)
  9095.  
  9096. *`DROP TABLE'*
  9097.      `DROP TABLE' on a table that is in use by a `MERGE' table will not
  9098.      work on Windows because the `MERGE' handler does the table mapping
  9099.      hidden from the upper layer of MySQL.  Because Windows doesn't
  9100.      allow you to drop files that are open, you first must flush all
  9101.      `MERGE' tables (with `FLUSH TABLES') or drop the `MERGE' table
  9102.      before dropping the table.  We will fix this at the same time we
  9103.      introduce `VIEW's.
  9104.  
  9105. *`DATA DIRECTORY' and `INDEX DIRECTORY'*
  9106.      The `DATA DIRECTORY' and `INDEX DIRECTORY' options for `CREATE
  9107.      TABLE' are ignored on Windows, because Windows doesn't support
  9108.      symbolic links.
  9109.  
  9110. Here are some open issues for anyone who might want to help us with the
  9111. Windows release:
  9112.  
  9113.    * Add some nice start and shutdown icons to the MySQL installation.
  9114.  
  9115.    * It would be really nice to be able to kill `mysqld' from the task
  9116.      manager.  For the moment, you must use `mysqladmin shutdown'.
  9117.  
  9118.    * Port `readline' to Windows for use in the `mysql' command-line
  9119.      tool.
  9120.  
  9121.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  9122.      `mysqladmin', and `mysqldump') would be nice.
  9123.  
  9124.    * It would be nice if the socket read and write functions in `net.c'
  9125.      were interruptible. This would make it possible to kill open
  9126.      threads with `mysqladmin kill' on Windows.
  9127.  
  9128.    * Add macros to use the faster thread-safe increment/decrement
  9129.      methods provided by Windows.
  9130.  
  9131. Other Windows-specific issues are described in the `README' file that
  9132. comes with the Windows distribution of MySQL.
  9133.  
  9134. Linux Notes (All Linux Versions)
  9135. --------------------------------
  9136.  
  9137. The following notes regarding `glibc' apply only to the situation when
  9138. you build MySQL yourself. If you are running Linux on an x86 machine,
  9139. in most cases it is much better for you to just use our binary. We link
  9140. our binaries against the best patched version of `glibc' we can come up
  9141. with and with the best compiler options, in an attempt to make it
  9142. suitable for a high-load server. So if you read the following text, and
  9143. are in doubt about what you should do, try our binary first to see if
  9144. it meets your needs, and worry about your own build only after you have
  9145. discovered that our binary is not good enough. In that case, we would
  9146. appreciate a note about it, so we can build a better binary next time.
  9147. For a typical user, even for setups with a lot of concurrent
  9148. connections and/or tables exceeding the 2G limit, our binary in most
  9149. cases is the best choice.
  9150.  
  9151. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  9152. version that doesn't have `glibc2', you must install LinuxThreads
  9153. before trying to compile MySQL.   You can get LinuxThreads at
  9154. `http://www.mysql.com/downloads/os-linux.html'.
  9155.  
  9156. *Note*: we have seen some strange problems with Linux 2.2.14 and MySQL
  9157. on SMP systems. If you have a SMP system, we recommend you upgrade to
  9158. Linux 2.4 as soon as possible.  Your system will be faster and more
  9159. stable by doing this.
  9160.  
  9161. Note that `glibc' versions before and including Version 2.1.1 have a
  9162. fatal bug in `pthread_mutex_timedwait' handling, which is used when you
  9163. do `INSERT DELAYED'.  We recommend that you not use `INSERT DELAYED'
  9164. before upgrading glibc.
  9165.  
  9166. If you plan to have 1000+ concurrent connections, you will need to make
  9167. some changes to LinuxThreads, recompile it, and relink MySQL against
  9168. the new `libpthread.a'.  Increase `PTHREAD_THREADS_MAX' in
  9169. `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  9170. `STACK_SIZE' in `linuxthreads/internals.h' to 256 KB. The paths are
  9171. relative to the root of `glibc' Note that MySQL will not be stable with
  9172. around 600-1000 connections if `STACK_SIZE' is the default of 2 MB.
  9173.  
  9174. If MySQL can't open enough files, or connections, it may be that you
  9175. haven't configured Linux to handle enough files.
  9176.  
  9177. In Linux 2.2 and onward, you can check the number of allocated file
  9178. handles by doing:
  9179.  
  9180.      cat /proc/sys/fs/file-max
  9181.      cat /proc/sys/fs/dquot-max
  9182.      cat /proc/sys/fs/super-max
  9183.  
  9184. If you have more than 16 MB of memory, you should add something like the
  9185. following to your init scripts (for example, `/etc/init.d/boot.local'
  9186. on SuSE Linux):
  9187.  
  9188.      echo 65536 > /proc/sys/fs/file-max
  9189.      echo 8192 > /proc/sys/fs/dquot-max
  9190.      echo 1024 > /proc/sys/fs/super-max
  9191.  
  9192. You can also run the preceding commands from the command-line as root,
  9193. but these settings will be lost the next time your computer reboots.
  9194.  
  9195. Alternatively, you can set these parameters on bootup by using the
  9196. `sysctl' tool, which is used by many Linux distributions (SuSE has
  9197. added it as well, beginning with SuSE Linux 8.0). Just put the following
  9198. values into a file named `/etc/sysctl.conf':
  9199.  
  9200.      # Increase some values for MySQL
  9201.      fs.file-max = 65536
  9202.      fs.dquot-max = 8192
  9203.      fs.super-max = 1024
  9204.  
  9205. You should also add the following to `/etc/my.cnf':
  9206.  
  9207.      [mysqld_safe]
  9208.      open-files-limit=8192
  9209.  
  9210. This should allow MySQL to create up to 8192 connections + files.
  9211.  
  9212. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  9213. stacks in the address space.  It needs to be large enough so that there
  9214. will be plenty of room for the stack of each individual thread, but
  9215. small enough to keep the stack of some threads from running into the
  9216. global `mysqld' data.  Unfortunately, the Linux implementation of
  9217. `mmap()', as we have experimentally discovered, will successfully unmap
  9218. an already mapped region if you ask it to map out an address already in
  9219. use, zeroing out the data on the entire page, instead of returning an
  9220. error.  So, the safety of `mysqld' or any other threaded application
  9221. depends on the "gentleman" behaviour of the code that creates threads.
  9222. The user must take measures to make sure the number of running threads
  9223. at any time is sufficiently low for thread stacks to stay away from the
  9224. global heap.  With `mysqld', you should enforce this "gentleman"
  9225. behaviour by setting a reasonable value for the `max_connections'
  9226. variable.
  9227.  
  9228. If you build MySQL yourself and do not want to mess with patching
  9229. LinuxThreads, you should set `max_connections' to a value no higher
  9230. than 500.  It should be even less if you have a large key buffer,  large
  9231. heap tables, or some other things that make `mysqld' allocate a lot of
  9232. memory, or if you are running a 2.2 kernel with a 2G patch. If you are
  9233. using our binary or RPM version 3.23.25 or later, you can safely set
  9234. `max_connections' at 1500, assuming no large key buffer or heap tables
  9235. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  9236. the more threads you can safely create.  We recommend the values between
  9237. 128K and 256K.
  9238.  
  9239. If you use a lot of concurrent connections, you may suffer from a
  9240. "feature" in the 2.2 kernel that penalises a process for forking or
  9241. cloning a child in an attempt to prevent a fork bomb attack.  This will
  9242. cause MySQL not to scale well as you increase the number of concurrent
  9243. clients.  On single-CPU systems, we have seen this manifested in a very
  9244. slow thread creation, which means it may take a long time to connect to
  9245. MySQL (as long as 1 minute), and it may take just as long to shut it
  9246. down.  On multiple-CPU systems, we have observed a gradual drop in
  9247. query speed as the number of clients increases.  In the process of
  9248. trying to find a solution, we have received a kernel patch from one of
  9249. our users, who claimed it made a lot of difference for his site.  The
  9250. patch is available at
  9251. `http://www.mysql.com/Downloads/Patches/linux-fork.patch'. We have now
  9252. done rather extensive testing of this patch on both development and
  9253. production systems.  It has significantly improved `MySQL' performance
  9254. without causing any problems and we now recommend it to our users who
  9255. are still running high-load servers on 2.2 kernels.  This issue has
  9256. been fixed in the 2.4 kernel, so if you are not satisfied with the
  9257. current performance of your system, rather than patching your 2.2
  9258. kernel, it might be easier to just upgrade to 2.4, which will also give
  9259. you a nice SMP boost in addition to fixing this fairness bug.
  9260.  
  9261. We have tested MySQL on the 2.4 kernel on a 2-CPU machine and found
  9262. MySQL scales *much* better--there was virtually no slowdown on queries
  9263. throughput all the way up to 1000 clients, and the MySQL scaling factor
  9264. (computed as the ratio of maximum throughput to the throughput with one
  9265. client) was 180%.  We have observed similar results on a 4-CPU
  9266. system--virtually no slowdown as the number of clients was increased up
  9267. to 1000, and 300% scaling factor. So for a high-load SMP server we
  9268. would definitely recommend the 2.4 kernel at this point. We have
  9269. discovered that it is essential to run `mysqld' process with the
  9270. highest possible priority on the 2.4 kernel to achieve maximum
  9271. performance.  This can be done by adding `renice -20 $$' command to
  9272. `mysqld_safe'. In our testing on a 4-CPU machine, increasing the
  9273. priority gave 60% increase in throughput with 400 clients.
  9274.  
  9275. We are currently also trying to collect more information on how well
  9276. `MySQL' performs on 2.4 kernel on 4-way and 8-way systems. If you have
  9277. access such a system and have done some benchmarks, please send a mail
  9278. to <docs@mysql.com> with the results - we will include them in the
  9279. manual.
  9280.  
  9281. There is another issue that greatly hurts MySQL performance, especially
  9282. on SMP systems.  The implementation of mutex in LinuxThreads in
  9283. `glibc-2.1' is very bad for programs with many threads that only hold
  9284. the mutex for a short time. On an SMP system, ironic as it is, if you
  9285. link MySQL against unmodified `LinuxThreads', removing processors from
  9286. the machine improves MySQL performance in many cases.  We have made a
  9287. patch available for `glibc 2.1.3' to correct this behaviour
  9288. (`http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch').
  9289.  
  9290. With `glibc-2.2.2' MySQL version 3.23.36 will use the adaptive mutex,
  9291. which is much better than even the patched one in `glibc-2.1.3'. Be
  9292. warned, however, that under some conditions, the current mutex code in
  9293. `glibc-2.2.2' overspins, which hurts MySQL performance. The chance of
  9294. this condition can be reduced by renicing `mysqld' process to the
  9295. highest priority. We have also been able to correct the overspin
  9296. behaviour with a patch, available at
  9297. `http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch'.  It
  9298. combines the correction of overspin, maximum number of threads, and
  9299. stack spacing all in one. You will need to apply it in the
  9300. `linuxthreads' directory with `patch -p0
  9301. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  9302. form in to the future releases of `glibc-2.2'. In any case, if you link
  9303. against `glibc-2.2.2' you still need to correct `STACK_SIZE' and
  9304. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  9305. some more acceptable values for high-load MySQL setup in the future, so
  9306. that your own build can be reduced to `./configure; make; make install'.
  9307.  
  9308. We recommend that you use the above patches to build a special static
  9309. version of `libpthread.a' and use it only for statically linking
  9310. against `MySQL'. We know that the patches are safe for `MySQL' and
  9311. significantly improve its performance, but we cannot say anything about
  9312. other applications. If you link other applications against the patched
  9313. version of the library, or build a patched shared version and install
  9314. it on your system, you are doing it at your own risk with regard to
  9315. other applications that depend on `LinuxThreads'.
  9316.  
  9317. If you experience any strange problems during the installation of
  9318. MySQL, or with some common utilities hanging, it is very likely that
  9319. they are either library or compiler related. If this is the case, using
  9320. our binary will resolve them.
  9321.  
  9322. One known problem with the binary distribution is that with older Linux
  9323. systems that use `libc' (like Red Hat 4.x or Slackware), you will get
  9324. some non-fatal problems with hostname resolution.  *Note Binary
  9325. notes-Linux::.
  9326.  
  9327. When using LinuxThreads you will see a minimum of three processes
  9328. running.  These are in fact threads.  There will be one thread for the
  9329. LinuxThreads manager, one thread to handle connections, and one thread
  9330. to handle alarms and signals.
  9331.  
  9332. Note that the Linux kernel and the LinuxThread library can by default
  9333. only have 1024 threads.  This means that you can only have up to 1021
  9334. connections to MySQL on an unpatched system.  The page
  9335. `http://www.volano.com/linuxnotes.html' contains information how to go
  9336. around this limit.
  9337.  
  9338. If you see a dead `mysqld' daemon process with `ps', this usually means
  9339. that you have found a bug in MySQL or you have a corrupted table. *Note
  9340. Crashing::.
  9341.  
  9342. To get a core dump on Linux if `mysqld' dies with a `SIGSEGV' signal,
  9343. you can start `mysqld' with the `--core-file' option.  Note that you
  9344. also probably need to raise the `core file size' by adding `ulimit -c
  9345. 1000000' to `mysqld_safe' or starting `mysqld_safe' with
  9346. `--core-file-size=1000000'.  *Note `mysqld_safe': mysqld_safe.
  9347.  
  9348. If you are linking your own MySQL client and get the error:
  9349.  
  9350.      ld.so.1: ./my: fatal: libmysqlclient.so.4:
  9351.      open failed: No such file or directory
  9352.  
  9353. When executing them, the problem can be avoided by one of the following
  9354. methods:
  9355.  
  9356.    * Link the client with the following flag (instead of `-Lpath'):
  9357.      `-Wl,r/path-libmysqlclient.so'.
  9358.  
  9359.    * Copy `libmysqclient.so' to `/usr/lib'.
  9360.  
  9361.    * Add the pathname of the directory where `libmysqlclient.so' is
  9362.      located to the `LD_RUN_PATH' environment variable before running
  9363.      your client.
  9364.  
  9365. If you are using the Fujitsu compiler `(fcc / FCC)' you will have some
  9366. problems compiling MySQL because the Linux header files are very `gcc'
  9367. oriented.
  9368.  
  9369. The following `configure' line should work with `fcc/FCC':
  9370.  
  9371.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE \
  9372.      -DCONST=const -DNO_STRTOLL_PROTO" CXX=FCC CXXFLAGS="-O -K fast -K lib \
  9373.      -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE -DCONST=const \
  9374.      -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO \
  9375.      '-D_EXTERN_INLINE=static __inline'" ./configure --prefix=/usr/local/mysql \
  9376.      --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared \
  9377.      --with-low-memory
  9378.  
  9379. Linux Notes for Binary Distributions
  9380. ....................................
  9381.  
  9382. MySQL needs at least Linux Version 2.0.
  9383.  
  9384. *Warning*: We have reports from some MySQL users that they have got
  9385. serious stability problems with MySQL with Linux kernel 2.2.14.  If you
  9386. are using this kernel you should upgrade to 2.2.19 (or newer) or to a
  9387. 2.4 kernel.  If you have a multi-cpu box, then you should seriously
  9388. consider using 2.4 as this will give you a significant speed boost.
  9389.  
  9390. The binary release is linked with `-static', which means you do not
  9391. normally need to worry about which version of the system libraries you
  9392. have. You need not install LinuxThreads, either.  A program linked with
  9393. `-static' is slightly bigger than a dynamically linked program but also
  9394. slightly faster (3-5%).  One problem, however, is that you can't use
  9395. user-definable functions (UDFs) with a statically linked program.  If
  9396. you are going to write or use UDFs (this is something for C or C++
  9397. programmers only), you must compile MySQL yourself, using dynamic
  9398. linking.
  9399.  
  9400. If you are using a `libc'-based system (instead of a `glibc2' system),
  9401. you will probably get some problems with hostname resolving and
  9402. `getpwnam()' with the binary release. (This is because `glibc'
  9403. unfortunately depends on some external libraries to resolve hostnames
  9404. and `getpwent()', even when compiled with `-static'). In this case you
  9405. probably get the following error message when you run
  9406. `mysql_install_db':
  9407.  
  9408.      Sorry, the host 'xxxx' could not be looked up
  9409.  
  9410. or the following error when you try to run `mysqld' with the `--user'
  9411. option:
  9412.  
  9413.      getpwnam: No such file or directory
  9414.  
  9415. You can solve this problem in one of the following ways:
  9416.  
  9417.    * Get a MySQL source distribution (an RPM or the `tar.gz'
  9418.      distribution) and install this instead.
  9419.  
  9420.    * Execute `mysql_install_db --force'; this will not execute the
  9421.      `resolveip' test in `mysql_install_db'.  The downside is that you
  9422.      can't use host names in the grant tables; you must use IP numbers
  9423.      instead (except for `localhost').  If you are using an old MySQL
  9424.      release that doesn't support `--force', you have to remove the
  9425.      `resolveip' test in `mysql_install' with an editor.
  9426.  
  9427.    * Start `mysqld' with `su' instead of using `--user'.
  9428.  
  9429. The Linux-Intel binary and RPM releases of MySQL are configured for the
  9430. highest possible speed.  We are always trying to use the fastest stable
  9431. compiler available.
  9432.  
  9433. MySQL Perl support requires Version Perl 5.004_03 or newer.
  9434.  
  9435. On some Linux 2.2 versions, you may get the error `Resource temporarily
  9436. unavailable' when you do a lot of new connections to a `mysqld' server
  9437. over TCP/IP.
  9438.  
  9439. The problem is that Linux has a delay between when you close a TCP/IP
  9440. socket and until this is actually freed by the system.  As there is only
  9441. room for a finite number of TCP/IP slots, you will get the above error
  9442. if you try to do too many new TCP/IP connections during a small time,
  9443. like when you run the MySQL `test-connect' benchmark over TCP/IP.
  9444.  
  9445. We have mailed about this problem a couple of times to different Linux
  9446. mailing lists but have never been able to resolve this properly.
  9447.  
  9448. The only known 'fix' to this problem is to use persistent connections in
  9449. your clients or use sockets, if you are running the database server and
  9450. clients on the same machine.  We hope that the `Linux 2.4' kernel will
  9451. fix this problem in the future.
  9452.  
  9453. Linux x86 Notes
  9454. ...............
  9455.  
  9456. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  9457. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  9458. have been some problems with the `glibc' RPMs from Red Hat, so if you
  9459. have problems, check whether there are any updates.  The `glibc'
  9460. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  9461.  
  9462. If you are using Red Hat 8.0 or a new `glibc' 2.2.x library, you should
  9463. start `mysqld' with the option `--thread-stack=192K'.  (Use `-O
  9464. thread_stack=192K' before MySQL 4.) If you don't do this, `mysqld' will
  9465. die in `gethostbyaddr()' because the new `glibc' library requires a
  9466. stack size greater than 128K for this call. This stack size is now the
  9467. default on MySQL 4.0.10 and above.
  9468.  
  9469. If you are using `gcc' 3.0 and above to compile MySQL, you must install
  9470. the `libstdc++v3' library before compiling MySQL; if you don't do this,
  9471. you will get an error about a missing `__cxa_pure_virtual' symbol
  9472. during linking.
  9473.  
  9474. On some older Linux distributions, `configure' may produce an error
  9475. like this:
  9476.  
  9477.      Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file.
  9478.      See the Installation chapter in the Reference Manual.
  9479.  
  9480. Just do what the error message says and add an extra underscore to the
  9481. `_P' macro that has only one underscore, then try again.
  9482.  
  9483. You may get some warnings when compiling; those shown here can be
  9484. ignored:
  9485.  
  9486.      mysqld.cc -o objs-thread/mysqld.o
  9487.      mysqld.cc: In function `void init_signals()':
  9488.      mysqld.cc:315: warning: assignment of negative value `-1' to
  9489.      `long unsigned int'
  9490.      mysqld.cc: In function `void * signal_hand(void *)':
  9491.      mysqld.cc:346: warning: assignment of negative value `-1' to
  9492.      `long unsigned int'
  9493.  
  9494. `mysql.server' can be found in the `share/mysql' directory under the
  9495. MySQL installation directory or in the `support-files' directory of the
  9496. MySQL source tree.
  9497.  
  9498. If `mysqld' always core dumps when it starts up, the problem may be that
  9499. you have an old `/lib/libc.a'.  Try renaming it, then remove
  9500. `sql/mysqld' and do a new `make install' and try again.  This problem
  9501. has been reported on some Slackware installations.
  9502.  
  9503. If you get the following error when linking `mysqld', it means that
  9504. your `libg++.a' is not installed correctly:
  9505.  
  9506.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  9507.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  9508.  
  9509. You can avoid using `libg++.a' by running `configure' like this:
  9510.  
  9511.      shell> CXX=gcc ./configure
  9512.  
  9513. Linux SPARC Notes
  9514. .................
  9515.  
  9516. In some implementations, `readdir_r()' is broken.  The symptom is that
  9517. `SHOW DATABASES' always returns an empty set.  This can be fixed by
  9518. removing `HAVE_READDIR_R' from `config.h' after configuring and before
  9519. compiling.
  9520.  
  9521. Some problems will require patching your Linux installation.  The patch
  9522. can be found at
  9523. `http://www.mysql.com/Downloads/patches/Linux-sparc-2.0.30.diff'.  This
  9524. patch is against the Linux distribution `sparclinux-2.0.30.tar.gz' that
  9525. is available at `vger.rutgers.edu' (a version of Linux that was never
  9526. merged with the official 2.0.30).  You must also install LinuxThreads
  9527. Version 0.6 or newer.
  9528.  
  9529. Linux Alpha Notes
  9530. .................
  9531.  
  9532. MySQL Version 3.23.12 is the first MySQL version that is tested on
  9533. Linux-Alpha.  If you plan to use MySQL on Linux-Alpha, you should
  9534. ensure that you have this version or newer.
  9535.  
  9536. We have tested MySQL on Alpha with our benchmarks and test suite, and
  9537. it appears to work nicely.
  9538.  
  9539. We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP,
  9540. kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler
  9541. (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.
  9542.  
  9543. You can find the above compilers at
  9544. `http://www.support.compaq.com/alpha-tools/'.  By using these compilers,
  9545. instead of gcc, we get about 9-14% better performance with MySQL.
  9546.  
  9547. Note that until MySQL version 3.23.52 and 4.0.2 we optimised the binary
  9548. for the current CPU only (by using the `-fast' compile option); this
  9549. meant that you could only use our binaries if you had an Alpha EV6
  9550. processor.
  9551.  
  9552. Starting with all following releases we added the `-arch generic' flag
  9553. to our compile options, which makes sure the binary runs on all Alpha
  9554. processors. We also compile statically to avoid library problems.
  9555.  
  9556.      CC=ccc CFLAGS="-fast -arch generic" CXX=cxx \
  9557.      CXXFLAGS="-fast -arch generic -noexceptions -nortti" \
  9558.      ./configure --prefix=/usr/local/mysql --disable-shared \
  9559.      --with-extra-charsets=complex --enable-thread-safe-client \
  9560.      --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  9561.  
  9562. If you want to use egcs the following configure line worked for us:
  9563.  
  9564.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
  9565.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  9566.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  9567.      --disable-shared
  9568.  
  9569. Some known problems when running MySQL on Linux-Alpha:
  9570.  
  9571.    * Debugging threaded applications like MySQL will not work with `gdb
  9572.      4.18'.  You should download and use gdb 5.1 instead!
  9573.  
  9574.    * If you try linking `mysqld' statically when using `gcc', the
  9575.      resulting image will core dump at start.  In other words, *don't*
  9576.      use `--with-mysqld-ldflags=-all-static' with `gcc'.
  9577.  
  9578. Linux PowerPC Notes
  9579. ...................
  9580.  
  9581. MySQL should work on MkLinux with the newest `glibc' package (tested
  9582. with `glibc' 2.0.7).
  9583.  
  9584. Linux MIPS Notes
  9585. ................
  9586.  
  9587. To get MySQL to work on Qube2, (Linux Mips), you need the newest
  9588. `glibc' libraries (`glibc-2.0.7-29C2' is known to work).  You must also
  9589. use the `egcs' C++ compiler (`egcs-1.0.2-9', `gcc 2.95.2' or newer).
  9590.  
  9591. Linux IA-64 Notes
  9592. .................
  9593.  
  9594. To get MySQL to compile on Linux IA-64, we use the following compile
  9595. line: Using `gcc-2.96':
  9596.  
  9597.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  9598.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  9599.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  9600.      "--with-comment=Official MySQL binary" --with-extra-charsets=complex
  9601.  
  9602. On IA-64, the MySQL client binaries use shared libraries. This means
  9603. that if you install our binary distribution in some other place than
  9604. `/usr/local/mysql' you need to add the path of the directory where you
  9605. have `libmysqlclient.so' installed either to the `/etc/ld.so.conf' file
  9606. or to the value of your `LD_LIBRARY_PATH' environment variable.
  9607.  
  9608. *Note Link errors::.
  9609.  
  9610. Solaris Notes
  9611. -------------
  9612.  
  9613. On Solaris, you may run into trouble even before you get the MySQL
  9614. distribution unpacked!  Solaris `tar' can't handle long file names, so
  9615. you may see an error like this when you unpack MySQL:
  9616.  
  9617.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,\
  9618.      informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  9619.      tar: directory checksum error
  9620.  
  9621. In this case, you must use GNU `tar' (`gtar') to unpack the
  9622. distribution.  You can find a precompiled copy for Solaris at
  9623. `http://www.mysql.com/downloads/os-solaris.html'.
  9624.  
  9625. Sun native threads only work on Solaris 2.5 and higher.  For Version
  9626. 2.4 and earlier, MySQL will automatically use MIT-pthreads.  *Note
  9627. MIT-pthreads::.
  9628.  
  9629. If you get the following error from configure:
  9630.  
  9631.      checking for restartable system calls... configure: error can not run test
  9632.      programs while cross compiling
  9633.  
  9634. This means that you have something wrong with your compiler
  9635. installation!  In this case you should upgrade your compiler to a newer
  9636. version.  You may also be able to solve this problem by inserting the
  9637. following row into the `config.cache' file:
  9638.  
  9639.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  9640.  
  9641. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  9642. 2.95.2 or 3.2. You can find this at `http://gcc.gnu.org/'.  Note that
  9643. `egcs' 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  9644.  
  9645. The recommended `configure' line when using `gcc' 2.95.2 is:
  9646.  
  9647.      CC=gcc CFLAGS="-O3" \
  9648.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  9649.      ./configure --prefix=/usr/local/mysql --with-low-memory --enable-assembler
  9650.  
  9651. If you have an UltraSPARC, you can get 4% more performance by adding
  9652. "-mcpu=v8 -Wa,-xarch=v8plusa" to CFLAGS and CXXFLAGS.
  9653.  
  9654. If you have Sun's Forte 5.0 (or newer) compiler, you can run
  9655. `configure' like this:
  9656.  
  9657.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt" \
  9658.      CXX=CC CXXFLAGS="-noex -mt" \
  9659.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9660.  
  9661. You can create a 64 bit binary using Sun's Forte compiler with the
  9662. following compile flags:
  9663.  
  9664.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
  9665.      CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS="-xarch=v9" \
  9666.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9667.  
  9668. To create a 64bit Solaris binary using `gcc', add `-m64' to `CFLAGS'
  9669. and `CXXFLAGS'. Note that this only works with MySQL 4.0 and up - MySQL
  9670. 3.23 does not include the required modifications to support this.
  9671.  
  9672. In the MySQL benchmarks, we got a 4% speedup on an UltraSPARC when using
  9673. Forte 5.0 in 32 bit mode compared to using gcc 3.2 with -mcpu flags.
  9674.  
  9675. If you create a 64 bit binary, it's 4 % slower than the 32 bit binary,
  9676. but `mysqld' can instead handle more treads and memory.
  9677.  
  9678. If you get a problem with `fdatasync' or `sched_yield', you can fix
  9679. this by adding `LIBS=-lrt' to the configure line
  9680.  
  9681. The following paragraph is only relevant for older compilers than
  9682. WorkShop 5.3:
  9683.  
  9684. You may also have to edit the `configure' script to change this line:
  9685.  
  9686.      #if !defined(__STDC__) || __STDC__ != 1
  9687.  
  9688. to this:
  9689.  
  9690.      #if !defined(__STDC__)
  9691.  
  9692. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  9693. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  9694. (broken compiler or broken include file).
  9695.  
  9696. If `mysqld' issues the error message shown here when you run it, you
  9697. have tried to compile MySQL with the Sun compiler without enabling the
  9698. multi-thread option (`-mt'):
  9699.  
  9700.      libc internal error: _rmutex_unlock: rmutex not held
  9701.  
  9702. Add `-mt' to `CFLAGS' and `CXXFLAGS' and try again.
  9703.  
  9704. If you are using the SFW version of gcc (which comes with Solaris 8),
  9705. you must add `/opt/sfw/lib' to the environment variable
  9706. `LD_LIBRARY_PATH' before running configure.
  9707.  
  9708. If you are using the gcc available from `sunfreeware.com', you may have
  9709. many problems.  You should recompile gcc and GNU binutils on the
  9710. machine you will be running them from to avoid any problems.
  9711.  
  9712. If you get the following error when compiling MySQL with `gcc', it
  9713. means that your `gcc' is not configured for your version of Solaris:
  9714.  
  9715.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  9716.      ./thr_alarm.c: In function `signal_hand':
  9717.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  9718.  
  9719. The proper thing to do in this case is to get the newest version of
  9720. `gcc' and compile it with your current `gcc' compiler!  At least for
  9721. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  9722. include files that will break all programs that use threads (and
  9723. possibly other programs)!
  9724.  
  9725. Solaris doesn't provide static versions of all system libraries
  9726. (`libpthreads' and `libdl'), so you can't compile MySQL with
  9727. `--static'.  If you try to do so, you will get the error:
  9728.  
  9729.      ld: fatal: library -ldl: not found
  9730.      
  9731.      or
  9732.      
  9733.      undefined reference to `dlopen'
  9734.      
  9735.      or
  9736.      
  9737.      cannot find -lrt
  9738.  
  9739. If too many processes try to connect very rapidly to `mysqld', you will
  9740. see this error in the MySQL log:
  9741.  
  9742.      Error in accept: Protocol error
  9743.  
  9744. You might try starting the server with the `--set-variable back_log=50'
  9745. option as a workaround for this. Please note that `--set-variable' is
  9746. deprecated since MySQL 4.0, just use `--back_log=50' on its own.  *Note
  9747. Command-line options::.
  9748.  
  9749. If you are linking your own MySQL client, you might get the following
  9750. error when you try to execute it:
  9751.  
  9752.      ld.so.1: ./my: fatal: libmysqlclient.so.#:
  9753.      open failed: No such file or directory
  9754.  
  9755. The problem can be avoided by one of the following methods:
  9756.  
  9757.    * Link the client with the following flag (instead of `-Lpath'):
  9758.      `-Wl,r/full-path-to-libmysqlclient.so'.
  9759.  
  9760.    * Copy `libmysqclient.so' to `/usr/lib'.
  9761.  
  9762.    * Add the pathname of the directory where `libmysqlclient.so' is
  9763.      located to the `LD_RUN_PATH' environment variable before running
  9764.      your client.
  9765.  
  9766. If you have problems with configure trying to link with `-lz' and you
  9767. don't have `zlib' installed, you have two options:
  9768.  
  9769.    * If you want to be able to use the compressed communication
  9770.      protocol, you need to get and install zlib from ftp.gnu.org.
  9771.  
  9772.    * Configure with `--with-named-z-libs=no'.
  9773.  
  9774. If you are using gcc and have problems with loading user defined
  9775. functions (`UDF's) into MySQL, try adding `-lgcc' to the link line for
  9776. the `UDF'.
  9777.  
  9778. If you would like MySQL to start automatically, you can copy
  9779. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  9780. link to it named `/etc/rc3.d/S99mysql.server'.
  9781.  
  9782. As Solaris doesn't support core files for `setuid()' applications, you
  9783. can't get a core file from `mysqld' if you are using the `--user'
  9784. option.
  9785.  
  9786. Solaris 2.7/2.8 Notes
  9787. .....................
  9788.  
  9789. You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  9790. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  9791.  
  9792. Note that MySQL Version 3.23.4 and above should be able to autodetect
  9793. new versions of Solaris and enable workarounds for the following
  9794. problems!
  9795.  
  9796. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  9797. following error when you use `gcc':
  9798.  
  9799.      /usr/include/widec.h:42: warning: `getwc' redefined
  9800.      /usr/include/wchar.h:326: warning: this is the location of the previous
  9801.      definition
  9802.  
  9803. If this occurs, you can do the following to fix the problem:
  9804.  
  9805. Copy `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include'
  9806. and change line 41 from:
  9807.  
  9808.      #if     !defined(lint) && !defined(__lint)
  9809.      
  9810.      to
  9811.      
  9812.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  9813.  
  9814. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  9815. way, after you make the fix, you should remove `config.cache' and run
  9816. `configure' again!
  9817.  
  9818. If you get errors like this when you run `make', it's because
  9819. `configure' didn't detect the `curses.h' file (probably because of the
  9820. error in `/usr/include/widec.h'):
  9821.  
  9822.      In file included from mysql.cc:50:
  9823.      /usr/include/term.h:1060: syntax error before `,'
  9824.      /usr/include/term.h:1081: syntax error before `;'
  9825.  
  9826. The solution to this is to do one of the following:
  9827.  
  9828.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  9829.      ./configure'.
  9830.  
  9831.    * Edit `/usr/include/widec.h' as indicted above and rerun configure.
  9832.  
  9833.    * Remove the `#define HAVE_TERM' line from `config.h' file and run
  9834.      `make' again.
  9835.  
  9836. If you get a problem that your linker can't find `-lz' when linking
  9837. your client program, the problem is probably that your `libz.so' file is
  9838. installed in `/usr/local/lib'.  You can fix this by one of the
  9839. following methods:
  9840.  
  9841.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  9842.  
  9843.    * Add a link to `libz.so' from `/lib'.
  9844.  
  9845.    * If you are using Solaris 8, you can install the optional zlib from
  9846.      your Solaris 8 CD distribution.
  9847.  
  9848.    * Configure MySQL with the `--with-named-z-libs=no' option.
  9849.  
  9850. Solaris x86 Notes
  9851. .................
  9852.  
  9853. On Solaris 8 on x86, `mysqld' will dump core if you remove the debug
  9854. symbols using `strip'.
  9855.  
  9856. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  9857. problems with core dumps under load, you should use the following
  9858. `configure' command:
  9859.  
  9860.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  9861.      CXX=gcc \
  9862.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions \
  9863.      -fno-rtti -DHAVE_CURSES_H" \
  9864.      ./configure --prefix=/usr/local/mysql
  9865.  
  9866. This will avoid problems with the `libstdc++' library and with C++
  9867. exceptions.
  9868.  
  9869. If this doesn't help, you should compile a debug version and run it
  9870. with a trace file or under `gdb'.  *Note Using gdb on mysqld::.
  9871.  
  9872. BSD Notes
  9873. ---------
  9874.  
  9875. This section provides information for the various BSD flavours, as well
  9876. as specific versions within those.
  9877.  
  9878. FreeBSD Notes
  9879. .............
  9880.  
  9881. FreeBSD 4.x or newer is recommended for running MySQL since the thread
  9882. package is much more integrated.
  9883.  
  9884. The easiest and therefore the preferred way to install is to use the
  9885. mysql-server and mysql-client ports available on
  9886. `http://www.freebsd.org/'.
  9887.  
  9888. Using these gives you:
  9889.    * A working MySQL with all optimisations known to work on your
  9890.      version of FreeBSD enabled.
  9891.  
  9892.    * Automatic configuration and build.
  9893.  
  9894.    * Startup scripts installed in /usr/local/etc/rc.d.
  9895.  
  9896.    * Ability to see which files that are installed with pkg_info -L.
  9897.      And to remove them all with pkg_delete if you no longer want MySQL
  9898.      on that machine.
  9899.  
  9900. It is recommended you use MIT-pthreads on FreeBSD 2.x and native
  9901. threads on Versions 3 and up. It is possible to run with native threads
  9902. on some late 2.2.x versions but you may encounter problems shutting
  9903. down `mysqld'.
  9904.  
  9905. Unfortunately, certain function calls on FreeBSD are not yet fully
  9906. thread-safe, most notably the `gethostbyname()' function, which is used
  9907. by MySQL to convert host names into IP addresses. Under certain
  9908. circumstances, the `mysqld' process will suddenly cause 100% CPU load
  9909. and will be unresponsive. If you encounter this, try to start up MySQL
  9910. using the `--skip-name-resolve' option.
  9911.  
  9912. Alternatively, you can link MySQL on FreeBSD 4.x against the
  9913. LinuxThreads library, which avoids a few of the problems that the
  9914. native FreeBSD thread implementation has. For a very good comparison of
  9915. LinuxThreads vs. native threads have a look at Jeremy Zawodny's article
  9916. "FreeBSD or Linux for your MySQL Server?" at
  9917. `http://jeremy.zawodny.com/blog/archives/000697.html'
  9918.  
  9919. The known problems when using LinuxThreads on FreeBSD are:
  9920.  
  9921.    * `wait_timeout' is not working (probably signal handling problem in
  9922.      FreeBSD/LinuxThreads).  This is supposed to get fixed in FreeBSD
  9923.      5.0.  The symptom is that persistent connections can hang for *a
  9924.      long* time without getting closed done.
  9925.  
  9926. The MySQL `Makefile's require GNU make (`gmake') to work.  If you want
  9927. to compile MySQL you need to install GNU `make' first.
  9928.  
  9929. Be sure to have your name resolver setup correct.  Otherwise, you may
  9930. experience resolver delays or failures when connecting to `mysqld'.
  9931.  
  9932. Make sure that the `localhost' entry in the `/etc/hosts' file is
  9933. correct (otherwise, you will have problems connecting to the database).
  9934. The `/etc/hosts' file should start with a line:
  9935.  
  9936.      127.0.0.1       localhost localhost.your.domain
  9937.  
  9938. The recommended way to compile and install MySQL on FreeBSD with gcc
  9939. (2.95.2 and up) is:
  9940.  
  9941.      CC=gcc CFLAGS="-O2 -fno-strength-reduce" \
  9942.      CXX=gcc CXXFLAGS="-O2 -fno-rtti -fno-exceptions -felide-constructors \
  9943.      -fno-strength-reduce" \
  9944.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9945.      gmake
  9946.      gmake install
  9947.      ./scripts/mysql_install_db
  9948.      cd /usr/local/mysql
  9949.      ./bin/mysqld_safe &
  9950.  
  9951. If you notice that `configure' will use MIT-pthreads, you should read
  9952. the MIT-pthreads notes.  *Note MIT-pthreads::.
  9953.  
  9954. If you get an error from `make install' that it can't find
  9955. `/usr/include/pthreads', `configure' didn't detect that you need
  9956. MIT-pthreads.  This is fixed by executing these commands:
  9957.  
  9958.      shell> rm config.cache
  9959.      shell> ./configure --with-mit-threads
  9960.  
  9961. FreeBSD is also known to have a very low default file handle limit.
  9962. *Note Not enough file handles::.  Uncomment the `ulimit -n' section in
  9963. `mysqld_safe' or raise the limits for the `mysqld' user in
  9964. /etc/login.conf (and rebuild it with cap_mkdb /etc/login.conf).  Also
  9965. be sure you set the appropriate class for this user in the password
  9966. file if you are not using the default (use: chpass mysqld-user-name).
  9967. *Note `mysqld_safe': mysqld_safe.
  9968.  
  9969. If you have a lot of memory you should consider rebuilding the kernel
  9970. to allow MySQL to take more than 512M of RAM.  Take a look at `option
  9971. MAXDSIZ' in the LINT config file for more info.
  9972.  
  9973. If you get problems with the current date in MySQL, setting the `TZ'
  9974. variable will probably help.  *Note Environment variables::.
  9975.  
  9976. To get a secure and stable system you should only use FreeBSD kernels
  9977. that are marked `-RELEASE'.
  9978.  
  9979. NetBSD Notes
  9980. ............
  9981.  
  9982. To compile on NetBSD you need GNU `make'. Otherwise, the compile will
  9983. crash when `make' tries to run `lint' on C++ files.
  9984.  
  9985. OpenBSD 2.5 Notes
  9986. .................
  9987.  
  9988. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  9989. the following options:
  9990.  
  9991.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  9992.  
  9993. OpenBSD 2.8 Notes
  9994. .................
  9995.  
  9996. Our users have reported that OpenBSD 2.8 has a threading bug which
  9997. causes problems with MySQL.  The OpenBSD Developers have fixed the
  9998. problem, but as of January 25th, 2001, it's only available in the
  9999. "-current" branch.  The symptoms of this threading bug are: slow
  10000. response, high load, high CPU usage, and crashes.
  10001.  
  10002. If you get an error like `Error in accept:: Bad file descriptor' or
  10003. error 9 when trying to open tables or directories, the problem is
  10004. probably that you haven't allocated enough file descriptors for MySQL.
  10005.  
  10006. In this case, try starting `mysqld_safe' as `root' with the following
  10007. options:
  10008.  
  10009.      shell> mysqld_safe --user=mysql --open-files-limit=2048 &
  10010.  
  10011. BSD/OS Version 2.x Notes
  10012. ........................
  10013.  
  10014. If you get the following error when compiling MySQL, your `ulimit'
  10015. value for virtual memory is too low:
  10016.  
  10017.      item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  10018.      item_func.h:28: virtual memory exhausted
  10019.      make[2]: *** [item_func.o] Error 1
  10020.  
  10021. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  10022. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  10023. users have reported problems with `bash' and `ulimit'.
  10024.  
  10025. If you are using `gcc', you may also use have to use the
  10026. `--with-low-memory' flag for `configure' to be able to compile
  10027. `sql_yacc.cc'.
  10028.  
  10029. If you get problems with the current date in MySQL, setting the `TZ'
  10030. variable will probably help.  *Note Environment variables::.
  10031.  
  10032. BSD/OS Version 3.x Notes
  10033. ........................
  10034.  
  10035. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  10036. BSDIpatch M300-038.
  10037.  
  10038. Use the following command when configuring MySQL:
  10039.  
  10040.      shell> env CXX=shlicc++ CC=shlicc2 \
  10041.             ./configure \
  10042.                 --prefix=/usr/local/mysql \
  10043.                 --localstatedir=/var/mysql \
  10044.                 --without-perl \
  10045.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10046.  
  10047. The following is also known to work:
  10048.  
  10049.      shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  10050.             ./configure \
  10051.                 --prefix=/usr/local/mysql \
  10052.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10053.  
  10054. You can change the directory locations if you wish, or just use the
  10055. defaults by not specifying any locations.
  10056.  
  10057. If you have problems with performance under heavy load, try using the
  10058. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  10059. with the same priority; on BSDI Version 3.1, this gives better
  10060. performance (at least until BSDI fixes their thread scheduler).
  10061.  
  10062. If you get the error `virtual memory exhausted' while compiling, you
  10063. should try using `ulimit -v 80000' and run `make' again.  If this
  10064. doesn't work and you are using `bash', try switching to `csh' or `sh';
  10065. some BSDI users have reported problems with `bash' and `ulimit'.
  10066.  
  10067. BSD/OS Version 4.x Notes
  10068. ........................
  10069.  
  10070. BSDI Version 4.x has some thread-related bugs.  If you want to use
  10071. MySQL on this, you should install all thread-related patches.  At least
  10072. M400-023 should be installed.
  10073.  
  10074. On some BSDI Version 4.x systems, you may get problems with shared
  10075. libraries.  The symptom is that you can't execute any client programs,
  10076. for example, `mysqladmin'.  In this case you need to reconfigure not to
  10077. use shared libraries with the `--disable-shared' option to configure.
  10078.  
  10079. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  10080. after a while can't open tables.  This is because some library/system
  10081. related bug causes `mysqld' to change current directory without asking
  10082. for this!
  10083.  
  10084. The fix is to either upgrade to 3.23.34 or after running `configure'
  10085. remove the line `#define HAVE_REALPATH' from `config.h' before running
  10086. make.
  10087.  
  10088. Note that the above means that you can't symbolic link a database
  10089. directories to another database directory or symbolic link a table to
  10090. another database on BSDI!  (Making a symbolic link to another disk is
  10091. okay).
  10092.  
  10093. Mac OS X Notes
  10094. --------------
  10095.  
  10096. Mac OS X 10.x
  10097. .............
  10098.  
  10099. MySQL should work without any problems on Mac OS X 10.x (Darwin). You
  10100. don't need the pthread patches for this OS!
  10101.  
  10102. This also applies to Mac OS X 10.x Server. Compiling for the Server
  10103. platform is the same as for the client version of Mac OS X. However
  10104. please note that MySQL comes preinstalled on the Server!
  10105.  
  10106. Our binary for Mac OS X is compiled on Darwin 6.3 with the following
  10107. configure line:
  10108.  
  10109.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  10110.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  10111.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  10112.      --with-extra-charsets=complex --enable-thread-safe-client \
  10113.      --enable-local-infile --disable-shared
  10114.  
  10115. *Note Mac OS X installation::.
  10116.  
  10117. Mac OS X Server 1.2 (Rhapsody)
  10118. ..............................
  10119.  
  10120. Before trying to configure MySQL on Mac OS X Server 1.2 (aka Rhapsody)
  10121. you must first install the pthread package from
  10122. `http://www.prnet.de/RegEx/mysql.html'.
  10123.  
  10124. *Note Mac OS X installation::.
  10125.  
  10126. Other Unix Notes
  10127. ----------------
  10128.  
  10129. HP-UX Notes for Binary Distributions
  10130. ....................................
  10131.  
  10132. Some of the binary distributions of MySQL for HP-UX are distributed as
  10133. an HP depot file and as a tar file.  To use the depot file you must be
  10134. running at least HP-UX 10.x to have access to HP's software depot tools.
  10135.  
  10136. The HP version of MySQL was compiled on an HP 9000/8xx server under
  10137. HP-UX 10.20, and uses MIT-pthreads.  It is known to work well under
  10138. this configuration.  MySQL Version 3.22.26 and newer can also be built
  10139. with HP's native thread package.
  10140.  
  10141. Other configurations that may work:
  10142.  
  10143.    * HP 9000/7xx running HP-UX 10.20+
  10144.  
  10145.    * HP 9000/8xx running HP-UX 10.30
  10146.  
  10147. The following configurations almost definitely won't work:
  10148.  
  10149.    * HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
  10150.  
  10151.    * HP 9000/7xx or 8xx running HP-UX 9.x
  10152.  
  10153. To install the distribution, use one of the commands here, where
  10154. `/path/to/depot' is the full pathname of the depot file:
  10155.  
  10156.    * To install everything, including the server, client and
  10157.      development tools:
  10158.  
  10159.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
  10160.  
  10161.    * To install only the server:
  10162.  
  10163.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
  10164.  
  10165.    * To install only the client package:
  10166.  
  10167.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
  10168.  
  10169.    * To install only the development tools:
  10170.  
  10171.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
  10172.  
  10173. The depot places binaries and libraries in `/opt/mysql' and data in
  10174. `/var/opt/mysql'. The depot also creates the appropriate entries in
  10175. `/etc/init.d' and `/etc/rc2.d' to start the server automatically at
  10176. boot time.  Obviously, this entails being `root' to install.
  10177.  
  10178. To install the HP-UX tar.gz distribution, you must have a copy of GNU
  10179. `tar'.
  10180.  
  10181. HP-UX Version 10.20 Notes
  10182. .........................
  10183.  
  10184. There are a couple of small problems when compiling MySQL on HP-UX.  We
  10185. recommend that you use `gcc' instead of the HP-UX native compiler,
  10186. because `gcc' produces better code!
  10187.  
  10188. We recommend using `gcc' 2.95 on HP-UX.  Don't use high optimisation
  10189. flags (like -O6) as this may not be safe on HP-UX.
  10190.  
  10191. The following `configure' line should work with `gcc' 2.95:
  10192.  
  10193.      CFLAGS="-I/opt/dce/include -fpic" \
  10194.      CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
  10195.      -fno-rtti" CXX=gcc ./configure --with-pthread \
  10196.      --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
  10197.  
  10198. The following `configure' line should work with `gcc' 3.1:
  10199.  
  10200.      CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc \
  10201.      CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions \
  10202.      -fno-rtti -O3 -fPIC" ./configure --prefix=/usr/local/mysql \
  10203.      --with-extra-charsets=complex --enable-thread-safe-client \
  10204.      --enable-local-infile  --with-pthread \
  10205.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  10206.      --disable-shared
  10207.  
  10208. HP-UX Version 11.x Notes
  10209. ........................
  10210.  
  10211. For HP-UX Version 11.x, we recommend MySQL Version 3.23.15 or later.
  10212.  
  10213. Because of some critical bugs in the standard HP-UX libraries, you
  10214. should install the following patches before trying to run MySQL on
  10215. HP-UX 11.0:
  10216.  
  10217.      PHKL_22840 Streams cumulative
  10218.      PHNE_22397 ARPA cumulative
  10219.  
  10220. This will solve the problem of getting `EWOULDBLOCK' from `recv()' and
  10221. `EBADF' from `accept()' in threaded applications.
  10222.  
  10223. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  10224. will get the error:
  10225.  
  10226.      In file included from /usr/include/unistd.h:11,
  10227.                       from ../include/global.h:125,
  10228.                       from mysql_priv.h:15,
  10229.                       from item.cc:19:
  10230.      /usr/include/sys/unistd.h:184: declaration of C function ...
  10231.      /usr/include/sys/pthread.h:440: previous declaration ...
  10232.      In file included from item.h:306,
  10233.                       from mysql_priv.h:158,
  10234.                       from item.cc:19:
  10235.  
  10236. The problem is that HP-UX doesn't define `pthreads_atfork()'
  10237. consistently.  It has conflicting prototypes in
  10238. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440
  10239. (details below).
  10240.  
  10241. One solution is to copy `/usr/include/sys/unistd.h' into
  10242. `mysql/include' and edit `unistd.h' and change it to match the
  10243. definition in `pthread.h'.  Here's the diff:
  10244.  
  10245.      183,184c183,184
  10246.      <      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  10247.      <                                                void (*child)());
  10248.      ---
  10249.      >      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  10250.      >                                                void (*child)(void));
  10251.  
  10252. After this, the following configure line should work:
  10253.  
  10254.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc \
  10255.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" \
  10256.      ./configure --prefix=/usr/local/mysql --disable-shared
  10257.  
  10258. If you are using MySQL 4.0.5 with the HP-UX compiler you can use:
  10259. (tested with cc B.11.11.04):
  10260.  
  10261.      CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure --with-extra-character-set=complex
  10262.  
  10263. You can ignore any errors of the following type:
  10264.  
  10265.      aCC: warning 901: unknown option: `-3': use +help for online documentation
  10266.  
  10267. If you get the following error from `configure'
  10268.  
  10269.      checking for cc option to accept ANSI C... no
  10270.      configure: error: MySQL requires a ANSI C compiler (and a C++ compiler).
  10271.      Try gcc. See the Installation chapter in the Reference Manual.
  10272.  
  10273. Check that you don't have the path to the K&R compiler before the path
  10274. to the HP-UX C and C++ compiler.
  10275.  
  10276. Another reason for not beeing able to compile is that you didn't define
  10277. the `+DD64' flags above.
  10278.  
  10279. Another possibility for HP-UX 11 is to use MySQL binaries for HP-UX
  10280. 10.20.  We have received reports from some users that these binaries
  10281. work fine on HP-UX 11.00. If you encounter problems, be sure to check
  10282. your HP-UX patch level.
  10283.  
  10284. IBM-AIX notes
  10285. .............
  10286.  
  10287. Automatic detection of `xlC' is missing from Autoconf, so a `configure'
  10288. command something like this is needed when compiling MySQL (This
  10289. example uses the IBM compiler):
  10290.  
  10291.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  10292.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  10293.      export CFLAGS="-I /usr/local/include"
  10294.      export LDFLAGS="-L /usr/local/lib"
  10295.      export CPPFLAGS=$CFLAGS
  10296.      export CXXFLAGS=$CFLAGS
  10297.      
  10298.      ./configure --prefix=/usr/local \
  10299.                      --localstatedir=/var/mysql \
  10300.                      --sysconfdir=/etc/mysql \
  10301.                      --sbindir='/usr/local/bin' \
  10302.                      --libexecdir='/usr/local/bin' \
  10303.                      --enable-thread-safe-client \
  10304.                      --enable-large-files
  10305.  
  10306. Above are the options used to compile the MySQL distribution that can
  10307. be found at `http://www-frec.bull.com/'.
  10308.  
  10309. If you change the `-O3' to `-O2' in the above configure line, you must
  10310. also remove the `-qstrict' option (this is a limitation in the IBM C
  10311. compiler).
  10312.  
  10313. If you are using `gcc' or `egcs' to compile MySQL, you *must* use the
  10314. `-fno-exceptions' flag, as the exception handling in `gcc'/`egcs' is
  10315. not thread-safe!  (This is tested with `egcs' 1.1.)  There are also
  10316. some known problems with IBM's assembler, which may cause it to
  10317. generate bad code when used with gcc.
  10318.  
  10319. We recommend the following `configure' line with `egcs' and `gcc 2.95'
  10320. on AIX:
  10321.  
  10322.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  10323.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  10324.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  10325.      ./configure --prefix=/usr/local/mysql --with-low-memory
  10326.  
  10327. The `-Wa,-many' is necessary for the compile to be successful.  IBM is
  10328. aware of this problem but is in to hurry to fix it because of the
  10329. workaround available.  We don't know if the `-fno-exceptions' is
  10330. required with `gcc 2.95', but as MySQL doesn't use exceptions and the
  10331. above option generates faster code, we recommend that you should always
  10332. use this option with `egcs / gcc'.
  10333.  
  10334. If you get a problem with assembler code try changing the -mcpu=xxx to
  10335. match your CPU. Typically power2, power, or powerpc may need to be used,
  10336. alternatively you might need to use 604 or 604e. I'm not positive but I
  10337. would think using "power" would likely be safe most of the time, even on
  10338. a power2 machine.
  10339.  
  10340. If you don't know what your CPU is then do a "uname -m", this will give
  10341. you back a string that looks like "000514676700", with a format of
  10342. xxyyyyyymmss where xx and ss are always 0's, yyyyyy is a unique system
  10343. id and mm is the id of the CPU Planar. A chart of these values can be
  10344. found at
  10345. `http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  10346. This will give you a machine type and a machine model you can use to
  10347. determine what type of CPU you have.
  10348.  
  10349. If you have problems with signals (MySQL dies unexpectedly under high
  10350. load) you may have found an OS bug with threads and signals.  In this
  10351. case you can tell MySQL not to use signals by configuring with:
  10352.  
  10353.      shell> CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  10354.             CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
  10355.             -DDONT_USE_THR_ALARM" \
  10356.             ./configure --prefix=/usr/local/mysql --with-debug --with-low-memory
  10357.  
  10358. This doesn't affect the performance of MySQL, but has the side effect
  10359. that you can't kill clients that are "sleeping" on a connection with
  10360. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  10361. die when it issues its next command.
  10362.  
  10363. On some versions of AIX, linking with `libbind.a' makes `getservbyname'
  10364. core dump.  This is an AIX bug and should be reported to IBM.
  10365.  
  10366. For AIX 4.2.1 and gcc you have to do the following changes.
  10367.  
  10368. After configuring, edit `config.h' and `include/my_config.h' and change
  10369. the line that says
  10370.  
  10371.      #define HAVE_SNPRINTF 1
  10372.  
  10373. to
  10374.  
  10375.      #undef HAVE_SNPRINTF
  10376.  
  10377. And finally, in `mysqld.cc' you need to add a prototype for initgoups.
  10378.  
  10379.      #ifdef _AIX41
  10380.      extern "C" int initgroups(const char *,int);
  10381.      #endif
  10382.  
  10383. If you need to allocate a lot of memory to the mysqld process, it's not
  10384. enough to just set 'ulimit -d unlimited'. You may also have to set in
  10385. `mysqld_safe' something like:
  10386.  
  10387.      export LDR_CNTRL='MAXDATA=0x80000000'
  10388.  
  10389. You can find more about using a lot of memory at:
  10390. `http://publib16.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/lrg_prg_support.htm'.
  10391.  
  10392. SunOS 4 Notes
  10393. .............
  10394.  
  10395. On SunOS 4, MIT-pthreads is needed to compile MySQL, which in turn
  10396. means you will need GNU `make'.
  10397.  
  10398. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  10399. You can use the following `configure' line to avoid this problem:
  10400.  
  10401.      shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
  10402.  
  10403. When compiling `readline', you may get warnings about duplicate defines.
  10404. These may be ignored.
  10405.  
  10406. When compiling `mysqld', there will be some `implicit declaration of
  10407. function' warnings. These may be ignored.
  10408.  
  10409. Alpha-DEC-UNIX Notes (Tru64)
  10410. ............................
  10411.  
  10412. If you are using egcs 1.1.2 on Digital Unix, you should upgrade to gcc
  10413. 2.95.2, as egcs on DEC has some serious bugs!
  10414.  
  10415. When compiling threaded programs under Digital Unix, the documentation
  10416. recommends using the `-pthread' option for `cc' and `cxx' and the
  10417. libraries `-lmach -lexc' (in addition to `-lpthread').  You should run
  10418. `configure' something like this:
  10419.  
  10420.      CC="cc -pthread" CXX="cxx -pthread -O" \
  10421.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  10422.  
  10423. When compiling `mysqld', you may see a couple of warnings like this:
  10424.  
  10425.      mysqld.cc: In function void handle_connections()':
  10426.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  10427.      accept(int,sockadddr *, int *)'
  10428.  
  10429. You can safely ignore these warnings.  They occur because `configure'
  10430. can detect only errors, not warnings.
  10431.  
  10432. If you start the server directly from the command-line, you may have
  10433. problems with it dying when you log out.  (When you log out, your
  10434. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  10435. the server like this:
  10436.  
  10437.      shell> nohup mysqld [options] &
  10438.  
  10439. `nohup' causes the command following it to ignore any `SIGHUP' signal
  10440. sent from the terminal.  Alternatively, start the server by running
  10441. `mysqld_safe', which invokes `mysqld' using `nohup' for you.  *Note
  10442. `mysqld_safe': mysqld_safe.
  10443.  
  10444. If you get a problem when compiling mysys/get_opt.c, just remove the
  10445. line #define _NO_PROTO from the start of that file!
  10446.  
  10447. If you are using Compaq's CC compiler, the following configure line
  10448. should work:
  10449.  
  10450.      CC="cc -pthread"
  10451.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  10452.      CXX="cxx -pthread"
  10453.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host \
  10454.      -noexceptions -nortti"
  10455.      export CC CFLAGS CXX CXXFLAGS
  10456.      ./configure \
  10457.      --prefix=/usr/local/mysql \
  10458.      --with-low-memory \
  10459.      --enable-large-files \
  10460.      --enable-shared=yes \
  10461.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  10462.      gnumake
  10463.  
  10464. If you get a problem with libtool, when compiling with shared libraries
  10465. as above, when linking `mysql', you should be able to get around this
  10466. by issuing:
  10467.  
  10468.      cd mysql
  10469.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  10470.      -O4 -ansi_alias -ansi_args -fast -inline speed \
  10471.      -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  10472.      -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  10473.      ../readline/libreadline.a -lcurses \
  10474.      ../libmysql/.libs/libmysqlclient.so  -lm
  10475.      cd ..
  10476.      gnumake
  10477.      gnumake install
  10478.      scripts/mysql_install_db
  10479.  
  10480. Alpha-DEC-OSF/1 Notes
  10481. .....................
  10482.  
  10483. If you have problems compiling and have DEC `CC' and `gcc' installed,
  10484. try running `configure' like this:
  10485.  
  10486.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  10487.      ./configure --prefix=/usr/local/mysql
  10488.  
  10489. If you get problems with the `c_asm.h' file, you can create and use a
  10490. 'dummy' `c_asm.h' file with:
  10491.  
  10492.      touch include/c_asm.h
  10493.      CC=gcc CFLAGS=-I./include \
  10494.      CXX=gcc CXXFLAGS=-O3 \
  10495.      ./configure --prefix=/usr/local/mysql
  10496.  
  10497. Note that the following problems with the `ld' program can be fixed by
  10498. downloading the latest DEC (Compaq) patch kit from:
  10499. `http://ftp.support.compaq.com/public/unix/'.
  10500.  
  10501. On OSF/1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  10502. 878)" the compiler had some strange behaviour (undefined `asm' symbols).
  10503. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  10504. errors occurring while linking `mysqld').  On this system, we have
  10505. managed to compile MySQL with the following `configure' line, after
  10506. replacing `/bin/ld' with the version from OSF 4.0C:
  10507.  
  10508.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  10509.  
  10510. With the Digital compiler "C++ V6.1-029", the following should work:
  10511.  
  10512.      CC=cc -pthread
  10513.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  10514.             -arch host
  10515.      CXX=cxx -pthread
  10516.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  10517.                -arch host -noexceptions -nortti
  10518.      export CC CFLAGS CXX CXXFLAGS
  10519.      ./configure --prefix=/usr/mysql/mysql --with-mysqld-ldflags=-all-static \
  10520.                  --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
  10521.  
  10522. In some versions of OSF/1, the `alloca()' function is broken. Fix this
  10523. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  10524.  
  10525. The `alloca()' function also may have an incorrect prototype in
  10526. `/usr/include/alloca.h'.  This warning resulting from this can be
  10527. ignored.
  10528.  
  10529. `configure' will use the following thread libraries automatically:
  10530. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  10531.  
  10532. When using `gcc', you can also try running `configure' like this:
  10533.  
  10534.      shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ...
  10535.  
  10536. If you have problems with signals (MySQL dies unexpectedly under high
  10537. load), you may have found an OS bug with threads and signals. In this
  10538. case you can tell MySQL not to use signals by configuring with:
  10539.  
  10540.      shell> CFLAGS=-DDONT_USE_THR_ALARM \
  10541.             CXXFLAGS=-DDONT_USE_THR_ALARM \
  10542.             ./configure ...
  10543.  
  10544. This doesn't affect the performance of MySQL, but has the side effect
  10545. that you can't kill clients that are "sleeping" on a connection with
  10546. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  10547. die when it issues its next command.
  10548.  
  10549. With `gcc' 2.95.2, you will probably run into the following compile
  10550. error:
  10551.  
  10552.      sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
  10553.      Please submit a full bug report.
  10554.  
  10555. To fix this you should change to the `sql' directory and do a "cut and
  10556. paste" of the last `gcc' line, but change `-O3' to `-O0' (or add `-O0'
  10557. immediately after `gcc' if you don't have any `-O' option on your
  10558. compile line).  After this is done you can just change back to the
  10559. top-level directly and run `make' again.
  10560.  
  10561. SGI Irix Notes
  10562. ..............
  10563.  
  10564. If you are using Irix Version 6.5.3 or newer `mysqld' will only be able
  10565. to create threads if you run it as a user with `CAP_SCHED_MGT'
  10566. privileges (like `root') or give the `mysqld' server this privilege
  10567. with the following shell command:
  10568.  
  10569.      shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  10570.  
  10571. You may have to undefine some things in `config.h' after running
  10572. `configure' and before compiling.
  10573.  
  10574. In some Irix implementations, the `alloca()' function is broken.  If the
  10575. `mysqld' server dies on some `SELECT' statements, remove the lines from
  10576. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  10577. `mysqladmin create' doesn't work, remove the line from `config.h' that
  10578. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  10579. line as well.
  10580.  
  10581. SGI recommends that you install all of the patches on this page as a
  10582. set:
  10583. `http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html'
  10584.  
  10585. At the very minimum, you should install the latest kernel rollup, the
  10586. latest `rld' rollup, and the latest `libc' rollup.
  10587.  
  10588. You definitely need all the POSIX patches on this page, for pthreads
  10589. support:
  10590.  
  10591. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  10592.  
  10593. If you get the something like the following error when compiling
  10594. `mysql.cc':
  10595.  
  10596.      "/usr/include/curses.h", line 82: error(1084): invalid combination of type
  10597.  
  10598. Type the following in the top-level directory of your MySQL source tree:
  10599.  
  10600.      shell> extra/replace bool curses_bool < /usr/include/curses.h \
  10601.      > include/curses.h
  10602.      shell> make
  10603.  
  10604. There have also been reports of scheduling problems.  If only one
  10605. thread is running, things go slow.  Avoid this by starting another
  10606. client.  This may lead to a 2-to-10-fold increase in execution speed
  10607. thereafter for the other thread.  This is a poorly understood problem
  10608. with Irix threads; you may have to improvise to find solutions until
  10609. this can be fixed.
  10610.  
  10611. If you are compiling with `gcc', you can use the following `configure'
  10612. command:
  10613.  
  10614.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  10615.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
  10616.      --with-named-thread-libs=-lpthread
  10617.  
  10618. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  10619. following is reported to work
  10620.  
  10621.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  10622.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  10623.      -I/usr/local/include -L/usr/local/lib' ./configure \
  10624.      --prefix=/usr/local/mysql --with-innodb --with-berkeley-db \
  10625.      --with-libwrap=/usr/local \
  10626.      --with-named-curses-libs=/usr/local/lib/libncurses.a
  10627.  
  10628. SCO Notes
  10629. .........
  10630.  
  10631. The current port is tested only on "sco3.2v5.0.5", "sco3.2v5.0.6" and
  10632. "sco3.2v5.0.7" systems.  There has also been a lot of progress on a
  10633. port to "sco 3.2v4.2".
  10634.  
  10635. For the moment the recommended compiler on OpenServer is gcc 2.95.2.
  10636. With this you should be able to compile MySQL with just:
  10637.  
  10638.      CC=gcc CXX=gcc ./configure ... (options)
  10639.  
  10640.   1. For OpenServer 5.0.x you need to use gcc-2.95.2p1 or newer from the
  10641.      Skunkware.  `http://www.sco.com/skunkware/' and choose browser
  10642.      OpenServer packages or by ftp to ftp2.caldera.com in the
  10643.      pub/skunkware/osr5/devtools/gcc directory.
  10644.  
  10645.   2. You need the port of GCC 2.5.x for this product and the Development
  10646.      system.  They are required on this version of SCO Unix.  You cannot
  10647.      just use the GCC Dev system.
  10648.  
  10649.   3. You should get the FSU Pthreads package and install it first.
  10650.      This can be found at
  10651.      `http://moss.csc.ncsu.edu/~mueller/ftp/pub/PART/pthreads.tar.gz'.
  10652.      You can also get a precompiled package from
  10653.      `http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz'.
  10654.  
  10655.   4. FSU Pthreads can be compiled with SCO Unix 4.2 with tcpip.  Or
  10656.      OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0), with the SCO
  10657.      Development System installed using a good port of GCC 2.5.x ODT or
  10658.      OS 3.0 you will need a good port of GCC 2.5.x There are a lot of
  10659.      problems without a good port.  The port for this product requires
  10660.      the SCO Unix Development system.  Without it, you are missing the
  10661.      libraries and the linker that is needed.
  10662.  
  10663.   5. To build FSU Pthreads on your system, do the following:
  10664.  
  10665.        1. Run `./configure' in the `threads/src' directory and select
  10666.           the SCO OpenServer option. This command copies
  10667.           `Makefile.SCO5' to `Makefile'.
  10668.  
  10669.        2. Run `make'.
  10670.  
  10671.        3. To install in the default `/usr/include' directory, login as
  10672.           root, then `cd' to the `thread/src' directory, and run `make
  10673.           install'.
  10674.  
  10675.   6. Remember to use GNU `make' when making MySQL.
  10676.  
  10677.   7. If you don't start `mysqld_safe' as `root', you probably will get
  10678.      only the default 110 open files per process.  `mysqld' will write
  10679.      a note about this in the log file.
  10680.  
  10681.   8. With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or
  10682.      newer.  You should also use gcc 2.95.2 or newer!
  10683.  
  10684.      The following `configure' command should work:
  10685.  
  10686.           shell> ./configure --prefix=/usr/local/mysql --disable-shared
  10687.  
  10688.   9. With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or
  10689.      newer.  The following `configure' command should work:
  10690.  
  10691.           shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  10692.                  ./configure \
  10693.                      --prefix=/usr/local/mysql \
  10694.                      --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  10695.                      --with-named-curses-libs="-lcurses"
  10696.  
  10697.      You may get some problems with some include files. In this case,
  10698.      you can find new SCO-specific include files at
  10699.      `http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz'.
  10700.      You should unpack this file in the `include' directory of your
  10701.      MySQL source tree.
  10702.  
  10703. SCO development notes:
  10704.  
  10705.    * MySQL should automatically detect FSU Pthreads and link `mysqld'
  10706.      with `-lgthreads -lsocket -lgthreads'.
  10707.  
  10708.    * The SCO development libraries are re-entrant in FSU Pthreads.  SCO
  10709.      claim's that its libraries' functions are re-entrant, so they must
  10710.      be reentrant with FSU Pthreads.  FSU Pthreads on OpenServer tries
  10711.      to use the SCO scheme to make re-entrant libraries.
  10712.  
  10713.    * FSU Pthreads (at least the version at `http://www.mysql.com/')
  10714.      comes linked with GNU `malloc'.  If you encounter problems with
  10715.      memory usage, make sure that `gmalloc.o' is included in
  10716.      `libgthreads.a' and `libgthreads.so'.
  10717.  
  10718.    * In FSU Pthreads, the following system calls are pthreads-aware:
  10719.      `read()', `write()', `getmsg()', `connect()', `accept()',
  10720.      `select()', and `wait()'.
  10721.  
  10722.    * The CSSA-2001-SCO.35.2 (the patch is listed in custom as
  10723.      erg711905-dscr_remap security patch (version 2.0.0) breaks FSU
  10724.      threads and makes mysqld unstable.  You have to remove this one if
  10725.      you want to run mysqld on an OpenServer 5.0.6 machine.
  10726.  
  10727.    * SCO provides Operating Systems Patches at
  10728.      `ftp://ftp.sco.com/pub/openserver5' for OpenServer 5.0.x
  10729.  
  10730.    * SCO provides secruity fixes and libsocket.so.2 at
  10731.      `ftp://ftp.sco.com/pub/security/OpenServer' and
  10732.      `ftp://ftp.sco.com/pub/security/sse' for OpenServer 5.0.x
  10733.  
  10734.    * pre-OSR506 security fixes. Also, the telnetd fix at
  10735.      `ftp://stage.caldera.com/pub/security/openserver/' or
  10736.      `ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/'
  10737.      as both libsocket.so.2 and libresolv.so.1 with instructions for
  10738.      installing on pre-OSR506 systems.
  10739.  
  10740.      It's probably a good idea to install the above patches before
  10741.      trying to compile/use MySQL.
  10742.  
  10743. If you want to install DBI on SCO, you have to edit the `Makefile' in
  10744. DBI-xxx and each subdirectory.
  10745.  
  10746. Note that the following assumes gcc 2.95.2 or newer:
  10747.  
  10748.      OLD:                                  NEW:
  10749.      CC = cc                               CC = gcc
  10750.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  10751.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  10752.      
  10753.      LD = ld                               LD = gcc -G -fpic
  10754.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  10755.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  10756.      
  10757.      LD = ld                               LD = gcc -G -fpic
  10758.      OPTIMISE = -Od                        OPTIMISE = -O1
  10759.      
  10760.      OLD:
  10761.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10762.      
  10763.      NEW:
  10764.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10765.  
  10766. This is because the Perl dynaloader will not load the `DBI' modules if
  10767. they were compiled with `icc' or `cc'.
  10768.  
  10769. Perl works best when compiled with `cc'.
  10770.  
  10771. SCO UnixWare Version 7.1.x Notes
  10772. ................................
  10773.  
  10774. You must use a version of MySQL at least as recent as Version 3.22.13
  10775. and of UnixWare 7.1.0 because these version fixes some portability and
  10776. OS problems under UnixWare.
  10777.  
  10778. We have been able to compile MySQL with the following `configure'
  10779. command on UnixWare Version 7.1.x:
  10780.  
  10781.      CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
  10782.  
  10783. If you want to use `gcc', you must use `gcc' 2.95.2 or newer.
  10784.  
  10785.      CC=gcc CXX=g++ ./configure --prefix=/usr/local/mysql
  10786.  
  10787.   1. SCO provides Operating Systems Patches at
  10788.      `ftp://ftp.sco.com/pub/unixware7' for UnixWare 7.1.1 and 7.1.3
  10789.      `ftp://ftp.sco.com/pub/openunix8' for OpenUNIX 8.0.0
  10790.  
  10791.   2. SCO provides information about Security Fixes at
  10792.      `ftp://ftp.sco.com/pub/security/OpenUNIX' for OpenUNIX
  10793.      `ftp://ftp.sco.com/pub/security/UnixWare' for UnixWare
  10794.  
  10795. OS/2 Notes
  10796. ----------
  10797.  
  10798. MySQL uses quite a few open files. Because of this, you should add
  10799. something like the following to your `CONFIG.SYS' file:
  10800.  
  10801.      SET EMXOPT=-c -n -h1024
  10802.  
  10803. If you don't do this, you will probably run into the following error:
  10804.  
  10805.      File 'xxxx' not found (Errcode: 24)
  10806.  
  10807. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  10808. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  10809. of the Pthreads library.  MySQL must be installed in a partition that
  10810. supports long filenames such as HPFS, FAT32, etc.
  10811.  
  10812. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  10813. not work with replacement shells such as `4OS2.EXE'.
  10814.  
  10815. The `scripts/mysql-install-db' script has been renamed.  It is now
  10816. called `install.cmd' and is a REXX script, which will set up the default
  10817. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  10818.  
  10819. Dynamic module support is compiled in but not fully tested. Dynamic
  10820. modules should be compiled using the Pthreads run-time library.
  10821.  
  10822.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  10823.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  10824.      mv example.dll example.udf
  10825.  
  10826. *Note*: Due to limitations in OS/2, UDF module name stems must not
  10827. exceed 8 characters. Modules are stored in the `/mysql2/udf' directory;
  10828. the `safe-mysqld.cmd' script will put this directory in the
  10829. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  10830. extensions are ignored--it is assumed to be `.udf'.  For example, in
  10831. Unix, the shared module might be named `example.so' and you would load
  10832. a function from it like this:
  10833.  
  10834.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
  10835.  
  10836. In OS/2, the module would be named `example.udf', but you would not
  10837. specify the module extension:
  10838.  
  10839.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
  10840.  
  10841. Novell NetWare Notes
  10842. --------------------
  10843.  
  10844. Porting `MySQL' to `NetWare' was an effort spearheaded by `Novell'.
  10845. Novell customers will be pleased to note that NetWare 6.5 will ship
  10846. with bundled MySQL binaries, complete with an automatic commercial use
  10847. license for all servers running that version of NetWare.
  10848.  
  10849. *Note NetWare installation::.
  10850.  
  10851. MySQL for NetWare is compiled using a combination of `Metrowerks
  10852. Codewarrior for NetWare' and special cross-compilation versions of the
  10853. GNU autotools. Check back here in the future for more information on
  10854. building and optimising MySQL for NetWare.
  10855.  
  10856. BeOS Notes
  10857. ----------
  10858.  
  10859. We have in the past talked with some BeOS developers that have said that
  10860. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  10861.  
  10862. Perl Installation Comments
  10863. ==========================
  10864.  
  10865. Installing Perl on Unix
  10866. -----------------------
  10867.  
  10868. Perl support for MySQL is provided by means of the `DBI'/`DBD' client
  10869. interface.  *Note Perl::.  The Perl `DBD'/`DBI' client code requires
  10870. Perl Version 5.004 or later.  The interface *will not work* if you have
  10871. an older version of Perl.
  10872.  
  10873. MySQL Perl support also requires that you've installed MySQL client
  10874. programming support.  If you installed MySQL from RPM files, client
  10875. programs are in the client RPM, but client programming support is in
  10876. the developer RPM.  Make sure you've installed the latter RPM.
  10877.  
  10878. As of Version 3.22.8, Perl support is distributed separately from the
  10879. main MySQL distribution.  If you want to install Perl support, the files
  10880. you will need can be obtained from
  10881. `http://www.mysql.com/downloads/api-dbi.html'.
  10882.  
  10883. The Perl distributions are provided as compressed `tar' archives and
  10884. have names like `MODULE-VERSION.tar.gz', where `MODULE' is the module
  10885. name and `VERSION' is the version number.  You should get the
  10886. `Data-Dumper', `DBI', and `DBD-mysql' distributions and install them in
  10887. that order.  The installation procedure is shown here.  The example
  10888. shown is for the `Data-Dumper' module, but the procedure is the same
  10889. for all three distributions:
  10890.  
  10891.   1. Unpack the distribution into the current directory:
  10892.           shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf -
  10893.      This command creates a directory named `Data-Dumper-VERSION'.
  10894.  
  10895.   2. Change into the top-level directory of the unpacked distribution:
  10896.           shell> cd Data-Dumper-VERSION
  10897.  
  10898.   3. Build the distribution and compile everything:
  10899.           shell> perl Makefile.PL
  10900.           shell> make
  10901.           shell> make test
  10902.           shell> make install
  10903.  
  10904. The `make test' command is important because it verifies that the
  10905. module is working.  Note that when you run that command during the
  10906. `DBD-mysql' installation to exercise the interface code, the MySQL
  10907. server must be running or the test will fail.
  10908.  
  10909. It is a good idea to rebuild and reinstall the `DBD-mysql' distribution
  10910. whenever you install a new release of MySQL, particularly if you notice
  10911. symptoms such as all your `DBI' scripts dumping core after you upgrade
  10912. MySQL.
  10913.  
  10914. If you don't have the right to install Perl modules in the system
  10915. directory or if you to install local Perl modules, the following
  10916. reference may help you:
  10917.  
  10918.      `http://www.iserver.com/support/contrib/perl5/modules.html'
  10919.  
  10920. Look under the heading `Installing New Modules that Require Locally
  10921. Installed Modules'.
  10922.  
  10923. Installing ActiveState Perl on Windows
  10924. --------------------------------------
  10925.  
  10926. To install the MySQL `DBD' module with ActiveState Perl on Windows, you
  10927. should do the following:
  10928.  
  10929.    * Get ActiveState Perl from
  10930.      `http://www.activestate.com/Products/ActivePerl/' and install it.
  10931.  
  10932.    * Open a DOS shell.
  10933.  
  10934.    * If required, set the HTTP_proxy variable. For example, you might
  10935.      try:
  10936.  
  10937.           set HTTP_proxy=my.proxy.com:3128
  10938.  
  10939.    * Start the PPM program:
  10940.  
  10941.           C:\> c:\perl\bin\ppm.pl
  10942.  
  10943.    * If you have not already done so, install `DBI':
  10944.  
  10945.           ppm> install DBI
  10946.  
  10947.    * If this succeeds, run the following command:
  10948.  
  10949.           install \
  10950.           ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
  10951.  
  10952. The above should work at least with ActiveState Perl Version 5.6.
  10953.  
  10954. If you can't get the above to work, you should instead install the
  10955. `MyODBC' driver and connect to MySQL server through ODBC:
  10956.  
  10957.      use DBI;
  10958.      $dbh= DBI->connect("DBI:ODBC:$dsn","$user","$password") ||
  10959.        die "Got error $DBI::errstr when connecting to $dsn\n";
  10960.  
  10961. Problems Using the Perl `DBI'/`DBD' Interface
  10962. ---------------------------------------------
  10963.  
  10964. If Perl reports that it can't find the `../mysql/mysql.so' module, then
  10965. the problem is probably that Perl can't locate the shared library
  10966. `libmysqlclient.so'.
  10967.  
  10968. You can fix this by any of the following methods:
  10969.  
  10970.    * Compile the `DBD-mysql' distribution with `perl Makefile.PL
  10971.      -static -config' rather than `perl Makefile.PL'.
  10972.  
  10973.    * Copy `libmysqlclient.so' to the directory where your other shared
  10974.      libraries are located (probably `/usr/lib' or `/lib').
  10975.  
  10976.    * On Linux you can add the pathname of the directory where
  10977.      `libmysqlclient.so' is located to the `/etc/ld.so.conf' file.
  10978.  
  10979.    * Add the pathname of the directory where `libmysqlclient.so' is
  10980.      located to the `LD_RUN_PATH' environment variable.
  10981.  
  10982. If you get the following errors from `DBD-mysql', you are probably
  10983. using `gcc' (or using an old binary compiled with `gcc'):
  10984.  
  10985.      /usr/bin/perl: can't resolve symbol '__moddi3'
  10986.      /usr/bin/perl: can't resolve symbol '__divdi3'
  10987.  
  10988. Add `-L/usr/lib/gcc-lib/... -lgcc' to the link command when the
  10989. `mysql.so' library gets built (check the output from `make' for
  10990. `mysql.so' when you compile the Perl client).  The `-L' option should
  10991. specify the pathname of the directory where `libgcc.a' is located on
  10992. your system.
  10993.  
  10994. Another cause of this problem may be that Perl and MySQL aren't both
  10995. compiled with `gcc'.  In this case, you can solve the mismatch by
  10996. compiling both with `gcc'.
  10997.  
  10998. If you get the following error from `DBD-mysql' when you run the tests:
  10999.  
  11000.      t/00base............install_driver(mysql) failed:
  11001.      Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
  11002.      ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
  11003.      uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
  11004.  
  11005. it means that you need to include the compression library, -lz, to the
  11006. link line. This can be doing the following change in the file
  11007. `lib/DBD/mysql/Install.pm':
  11008.  
  11009.      $sysliblist .= " -lm";
  11010.      
  11011.      to
  11012.      
  11013.      $sysliblist .= " -lm -lz";
  11014.  
  11015. After this, you *must* run 'make realclean' and then proceed with the
  11016. installation from the beginning.
  11017.  
  11018. If you want to use the Perl module on a system that doesn't support
  11019. dynamic linking (like SCO) you can generate a static version of Perl
  11020. that includes `DBI' and `DBD-mysql'.  The way this works is that you
  11021. generate a version of Perl with the `DBI' code linked in and install it
  11022. on top of your current Perl.  Then you use that to build a version of
  11023. Perl that additionally has the `DBD' code linked in, and install that.
  11024.  
  11025. On SCO, you must have the following environment variables set:
  11026.  
  11027.      shell> LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
  11028.      or
  11029.      shell> LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11030.      /usr/progressive/lib:/usr/skunk/lib
  11031.      shell> LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11032.      /usr/progressive/lib:/usr/skunk/lib
  11033.      shell> MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
  11034.      /usr/skunk/man:
  11035.  
  11036. First, create a Perl that includes a statically linked `DBI' by running
  11037. these commands in the directory where your `DBI' distribution is
  11038. located:
  11039.  
  11040.      shell> perl Makefile.PL -static -config
  11041.      shell> make
  11042.      shell> make install
  11043.      shell> make perl
  11044.  
  11045. Then you must install the new Perl. The output of `make perl' will
  11046. indicate the exact `make' command you will need to execute to perform
  11047. the installation.  On SCO, this is `make -f Makefile.aperl inst_perl
  11048. MAP_TARGET=perl'.
  11049.  
  11050. Next, use the just-created Perl to create another Perl that also
  11051. includes a statically-linked `DBD::mysql' by running these commands in
  11052. the directory where your `DBD-mysql' distribution is located:
  11053.  
  11054.      shell> perl Makefile.PL -static -config
  11055.      shell> make
  11056.      shell> make install
  11057.      shell> make perl
  11058.  
  11059. Finally, you should install this new Perl.  Again, the output of `make
  11060. perl' indicates the command to use.
  11061.  
  11062. Tutorial Introduction
  11063. *********************
  11064.  
  11065. This chapter provides a tutorial introduction to MySQL by showing how
  11066. to use the `mysql' client program to create and use a simple database.
  11067. `mysql' (sometimes referred to as the "terminal monitor" or just
  11068. "monitor") is an interactive program that allows you to connect to a
  11069. MySQL server, run queries, and view the results.  `mysql' may also be
  11070. used in batch mode: you place your queries in a file beforehand, then
  11071. tell `mysql' to execute the contents of the file.  Both ways of using
  11072. `mysql' are covered here.
  11073.  
  11074. To see a list of options provided by `mysql', invoke it with the
  11075. `--help' option:
  11076.  
  11077.      shell> mysql --help
  11078.  
  11079. This chapter assumes that `mysql' is installed on your machine and that
  11080. a MySQL server is available to which you can connect.  If this is not
  11081. true, contact your MySQL administrator.  (If *you* are the
  11082. administrator, you will need to consult other sections of this manual.)
  11083.  
  11084. This chapter describes the entire process of setting up and using a
  11085. database.  If you are interested only in accessing an already-existing
  11086. database, you may want to skip over the sections that describe how to
  11087. create the database and the tables it contains.
  11088.  
  11089. Because this chapter is tutorial in nature, many details are necessarily
  11090. omitted.  Consult the relevant sections of the manual for more
  11091. information on the topics covered here.
  11092.  
  11093. Connecting to and Disconnecting from the Server
  11094. ===============================================
  11095.  
  11096. To connect to the server, you'll usually need to provide a MySQL user
  11097. name when you invoke `mysql' and, most likely, a password.  If the
  11098. server runs on a machine other than the one where you log in, you'll
  11099. also need to specify a hostname.  Contact your administrator to find
  11100. out what connection parameters you should use to connect (that is, what
  11101. host, user name, and password to use).  Once you know the proper
  11102. parameters, you should be able to connect like this:
  11103.  
  11104.      shell> mysql -h host -u user -p
  11105.      Enter password: ********
  11106.  
  11107. The `********' represents your password; enter it when `mysql' displays
  11108. the `Enter password:' prompt.
  11109.  
  11110. If that works, you should see some introductory information followed by
  11111. a `mysql>' prompt:
  11112.  
  11113.      shell> mysql -h host -u user -p
  11114.      Enter password: ********
  11115.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  11116.      Your MySQL connection id is 25338 to server version: 4.0.14-log
  11117.      
  11118.      Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  11119.      
  11120.      mysql>
  11121.  
  11122. The prompt tells you that `mysql' is ready for you to enter commands.
  11123.  
  11124. Some MySQL installations allow users to connect as the anonymous
  11125. (unnamed) user to the server running on the local host.  If this is the
  11126. case on your machine, you should be able to connect to that server by
  11127. invoking `mysql' without any options:
  11128.  
  11129.      shell> mysql
  11130.  
  11131. After you have connected successfully, you can disconnect any time by
  11132. typing `QUIT' (or `\q') at the `mysql>' prompt:
  11133.  
  11134.      mysql> QUIT
  11135.      Bye
  11136.  
  11137. On Unix, you can also disconnect by pressing Control-D.
  11138.  
  11139. Most examples in the following sections assume you are connected to the
  11140. server.  They indicate this by the `mysql>' prompt.
  11141.  
  11142. Entering Queries
  11143. ================
  11144.  
  11145. Make sure you are connected to the server, as discussed in the previous
  11146. section.  Doing so will not in itself select any database to work with,
  11147. but that's okay.  At this point, it's more important to find out a
  11148. little about how to issue queries than to jump right in creating
  11149. tables, loading data into them, and retrieving data from them.  This
  11150. section describes the basic principles of entering commands, using
  11151. several queries you can try out to familiarise yourself with how
  11152. `mysql' works.
  11153.  
  11154. Here's a simple command that asks the server to tell you its version
  11155. number and the current date.  Type it in as shown here following the
  11156. `mysql>' prompt and press Enter:
  11157.  
  11158.      mysql> SELECT VERSION(), CURRENT_DATE;
  11159.      +--------------+--------------+
  11160.      | VERSION()    | CURRENT_DATE |
  11161.      +--------------+--------------+
  11162.      | 3.22.20a-log | 1999-03-19   |
  11163.      +--------------+--------------+
  11164.      1 row in set (0.01 sec)
  11165.      mysql>
  11166.  
  11167. This query illustrates several things about `mysql':
  11168.  
  11169.    * A command normally consists of an SQL statement followed by a
  11170.      semicolon.  (There are some exceptions where a semicolon may be
  11171.      omitted.  `QUIT', mentioned earlier, is one of them.  We'll get to
  11172.      others later.)
  11173.  
  11174.    * When you issue a command, `mysql' sends it to the server for
  11175.      execution and displays the results, then prints another `mysql>'
  11176.      prompt to indicate that it is ready for another command.
  11177.  
  11178.    * `mysql' displays query output in tabular form (rows and columns).
  11179.      The first row contains labels for the columns.  The rows following
  11180.      are the query results.  Normally, column labels are the names of
  11181.      the columns you fetch from database tables.  If you're retrieving
  11182.      the value of an expression rather than a table column (as in the
  11183.      example just shown), `mysql' labels the column using the
  11184.      expression itself.
  11185.  
  11186.    * `mysql' shows how many rows were returned and how long the query
  11187.      took to execute, which gives you a rough idea of server
  11188.      performance.  These values are imprecise because they represent
  11189.      wall clock time (not CPU or machine time), and because they are
  11190.      affected by factors such as server load and network latency.  (For
  11191.      brevity, the "rows in set" line is not shown in the remaining
  11192.      examples in this chapter.)
  11193.  
  11194. Keywords may be entered in any lettercase.  The following queries are
  11195. equivalent:
  11196.  
  11197.      mysql> SELECT VERSION(), CURRENT_DATE;
  11198.      mysql> select version(), current_date;
  11199.      mysql> SeLeCt vErSiOn(), current_DATE;
  11200.  
  11201. Here's another query.  It demonstrates that you can use `mysql' as a
  11202. simple calculator:
  11203.  
  11204.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  11205.      +-------------+---------+
  11206.      | SIN(PI()/4) | (4+1)*5 |
  11207.      +-------------+---------+
  11208.      |    0.707107 |      25 |
  11209.      +-------------+---------+
  11210.  
  11211. The queries shown thus far have been relatively short, single-line
  11212. statements.  You can even enter multiple statements on a single line.
  11213. Just end each one with a semicolon:
  11214.  
  11215.      mysql> SELECT VERSION(); SELECT NOW();
  11216.      +--------------+
  11217.      | VERSION()    |
  11218.      +--------------+
  11219.      | 3.22.20a-log |
  11220.      +--------------+
  11221.      
  11222.      +---------------------+
  11223.      | NOW()               |
  11224.      +---------------------+
  11225.      | 1999-03-19 00:15:33 |
  11226.      +---------------------+
  11227.  
  11228. A command need not be given all on a single line, so lengthy commands
  11229. that require several lines are not a problem.  `mysql' determines where
  11230. your statement ends by looking for the terminating semicolon, not by
  11231. looking for the end of the input line.  (In other words, `mysql'
  11232. accepts free-format input:  it collects input lines but does not
  11233. execute them until it sees the semicolon.)
  11234.  
  11235. Here's a simple multiple-line statement:
  11236.  
  11237.      mysql> SELECT
  11238.          -> USER()
  11239.          -> ,
  11240.          -> CURRENT_DATE;
  11241.      +--------------------+--------------+
  11242.      | USER()             | CURRENT_DATE |
  11243.      +--------------------+--------------+
  11244.      | joesmith@localhost | 1999-03-18   |
  11245.      +--------------------+--------------+
  11246.  
  11247. In this example, notice how the prompt changes from `mysql>' to `->'
  11248. after you enter the first line of a multiple-line query.  This is how
  11249. `mysql' indicates that it hasn't seen a complete statement and is
  11250. waiting for the rest.  The prompt is your friend, because it provides
  11251. valuable feedback.  If you use that feedback, you will always be aware
  11252. of what `mysql' is waiting for.
  11253.  
  11254. If you decide you don't want to execute a command that you are in the
  11255. process of entering, cancel it by typing `\c':
  11256.  
  11257.      mysql> SELECT
  11258.          -> USER()
  11259.          -> \c
  11260.      mysql>
  11261.  
  11262. Here, too, notice the prompt.  It switches back to `mysql>' after you
  11263. type `\c', providing feedback to indicate that `mysql' is ready for a
  11264. new command.
  11265.  
  11266. The following table shows each of the prompts you may see and
  11267. summarises what they mean about the state that `mysql' is in:
  11268.  
  11269. *Prompt**Meaning*
  11270. `mysql>'Ready for new command.
  11271. `       Waiting for next line of multiple-line command.
  11272. ->'     
  11273. `       Waiting for next line, collecting a string that begins
  11274. '>'     with a single quote (`'').
  11275. `       Waiting for next line, collecting a string that begins
  11276. ">'     with a double quote (`"').
  11277.  
  11278. Multiple-line statements commonly occur by accident when you intend to
  11279. issue a command on a single line, but forget the terminating semicolon.
  11280. In this case, `mysql' waits for more input:
  11281.  
  11282.      mysql> SELECT USER()
  11283.          ->
  11284.  
  11285. If this happens to you (you think you've entered a statement but the
  11286. only response is a `->' prompt), most likely `mysql' is waiting for the
  11287. semicolon.  If you don't notice what the prompt is telling you, you
  11288. might sit there for a while before realising what you need to do.
  11289. Enter a semicolon to complete the statement, and `mysql' will execute
  11290. it:
  11291.  
  11292.      mysql> SELECT USER()
  11293.          -> ;
  11294.      +--------------------+
  11295.      | USER()             |
  11296.      +--------------------+
  11297.      | joesmith@localhost |
  11298.      +--------------------+
  11299.  
  11300. The `'>' and `">' prompts occur during string collection.  In MySQL,
  11301. you can write strings surrounded by either `'' or `"' characters (for
  11302. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  11303. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  11304. that you've entered a line containing a string that begins with a `''
  11305. or `"' quote character, but have not yet entered the matching quote
  11306. that terminates the string.  That's fine if you really are entering a
  11307. multiple-line string, but how likely is that?  Not very.  More often,
  11308. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  11309. quote character.  For example:
  11310.  
  11311.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  11312.          ">
  11313.  
  11314. If you enter this `SELECT' statement, then press Enter and wait for the
  11315. result, nothing will happen.  Instead of wondering why this query takes
  11316. so long, notice the clue provided by the `">' prompt.  It tells you
  11317. that `mysql' expects to see the rest of an unterminated string.  (Do
  11318. you see the error in the statement?  The string `"Smith' is missing the
  11319. second quote.)
  11320.  
  11321. At this point, what do you do?  The simplest thing is to cancel the
  11322. command.  However, you cannot just type `\c' in this case, because
  11323. `mysql' interprets it as part of the string that it is collecting!
  11324. Instead, enter the closing quote character (so `mysql' knows you've
  11325. finished the string), then type `\c':
  11326.  
  11327.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  11328.          "> "\c
  11329.      mysql>
  11330.  
  11331. The prompt changes back to `mysql>', indicating that `mysql' is ready
  11332. for a new command.
  11333.  
  11334. It's important to know what the `'>' and `">' prompts signify, because
  11335. if you mistakenly enter an unterminated string, any further lines you
  11336. type will appear to be ignored by `mysql'--including a line containing
  11337. `QUIT'!  This can be quite confusing, especially if you don't know that
  11338. you need to supply the terminating quote before you can cancel the
  11339. current command.
  11340.  
  11341. Creating and Using a Database
  11342. =============================
  11343.  
  11344. Now that you know how to enter commands, it's time to access a database.
  11345.  
  11346. Suppose you have several pets in your home (your menagerie) and you'd
  11347. like to keep track of various types of information about them.  You can
  11348. do so by creating tables to hold your data and loading them with the
  11349. desired information.  Then you can answer different sorts of questions
  11350. about your animals by retrieving data from the tables.  This section
  11351. shows you how to:
  11352.  
  11353.    * Create a database
  11354.  
  11355.    * Create a table
  11356.  
  11357.    * Load data into the table
  11358.  
  11359.    * Retrieve data from the table in various ways
  11360.  
  11361.    * Use multiple tables
  11362.  
  11363. The menagerie database will be simple (deliberately), but it is not
  11364. difficult to think of real-world situations in which a similar type of
  11365. database might be used.  For example, a database like this could be
  11366. used by a farmer to keep track of livestock, or by a veterinarian to
  11367. keep track of patient records.  A menagerie distribution containing
  11368. some of the queries and sample data used in the following sections can
  11369. be obtained from the MySQL web site.  It's available in either
  11370. compressed `tar' format
  11371. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz') or
  11372. Zip format
  11373. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip').
  11374.  
  11375. Use the `SHOW' statement to find out what databases currently exist on
  11376. the server:
  11377.  
  11378.      mysql> SHOW DATABASES;
  11379.      +----------+
  11380.      | Database |
  11381.      +----------+
  11382.      | mysql    |
  11383.      | test     |
  11384.      | tmp      |
  11385.      +----------+
  11386.  
  11387. The list of databases is probably different on your machine, but the
  11388. `mysql' and `test' databases are likely to be among them.  The `mysql'
  11389. database is required because it describes user access privileges.  The
  11390. `test' database is often provided as a workspace for users to try
  11391. things out.
  11392.  
  11393. Note that you may not see all databases if you don't have the `SHOW
  11394. DATABASES' privilege. *Note `GRANT': GRANT.
  11395.  
  11396. If the `test' database exists, try to access it:
  11397.  
  11398.      mysql> USE test
  11399.      Database changed
  11400.  
  11401. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  11402. terminate such statements with a semicolon if you like; it does no
  11403. harm.)  The `USE' statement is special in another way, too:  it must be
  11404. given on a single line.
  11405.  
  11406. You can use the `test' database (if you have access to it) for the
  11407. examples that follow, but anything you create in that database can be
  11408. removed by anyone else with access to it.  For this reason, you should
  11409. probably ask your MySQL administrator for permission to use a database
  11410. of your own.  Suppose you want to call yours `menagerie'.  The
  11411. administrator needs to execute a command like this:
  11412.  
  11413.      mysql> GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';
  11414.  
  11415. where `your_mysql_name' is the MySQL user name assigned to you and
  11416. `your_client_host' is the host from which you connect to the server.
  11417.  
  11418. Creating and Selecting a Database
  11419. ---------------------------------
  11420.  
  11421. If the administrator creates your database for you when setting up your
  11422. permissions, you can begin using it.  Otherwise, you need to create it
  11423. yourself:
  11424.  
  11425.      mysql> CREATE DATABASE menagerie;
  11426.  
  11427. Under Unix, database names are case-sensitive (unlike SQL keywords), so
  11428. you must always refer to your database as `menagerie', not as
  11429. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  11430. table names.  (Under Windows, this restriction does not apply, although
  11431. you must refer to databases and tables using the same lettercase
  11432. throughout a given query.)
  11433.  
  11434. Creating a database does not select it for use; you must do that
  11435. explicitly.  To make `menagerie' the current database, use this command:
  11436.  
  11437.      mysql> USE menagerie
  11438.      Database changed
  11439.  
  11440. Your database needs to be created only once, but you must select it for
  11441. use each time you begin a `mysql' session.  You can do this by issuing a
  11442. `USE' statement as shown above.  Alternatively, you can select the
  11443. database on the command-line when you invoke `mysql'.  Just specify its
  11444. name after any connection parameters that you might need to provide.
  11445. For example:
  11446.  
  11447.      shell> mysql -h host -u user -p menagerie
  11448.      Enter password: ********
  11449.  
  11450. Note that `menagerie' is not your password on the command just shown.
  11451. If you want to supply your password on the command-line after the `-p'
  11452. option, you must do so with no intervening space (for example, as
  11453. `-pmypassword', not as `-p mypassword').  However, putting your
  11454. password on the command-line is not recommended, because doing so
  11455. exposes it to snooping by other users logged in on your machine.
  11456.  
  11457. Creating a Table
  11458. ----------------
  11459.  
  11460. Creating the database is the easy part, but at this point it's empty, as
  11461. `SHOW TABLES' will tell you:
  11462.  
  11463.      mysql> SHOW TABLES;
  11464.      Empty set (0.00 sec)
  11465.  
  11466. The harder part is deciding what the structure of your database should
  11467. be: what tables you will need and what columns will be in each of them.
  11468.  
  11469. You'll want a table that contains a record for each of your pets.  This
  11470. can be called the `pet' table, and it should contain, as a bare minimum,
  11471. each animal's name.  Because the name by itself is not very
  11472. interesting, the table should contain other information.  For example,
  11473. if more than one person in your family keeps pets, you might want to
  11474. list each animal's owner.  You might also want to record some basic
  11475. descriptive information such as species and sex.
  11476.  
  11477. How about age?  That might be of interest, but it's not a good thing to
  11478. store in a database.  Age changes as time passes, which means you'd
  11479. have to update your records often.  Instead, it's better to store a
  11480. fixed value such as date of birth.  Then, whenever you need age, you
  11481. can calculate it as the difference between the current date and the
  11482. birth date.  MySQL provides functions for doing date arithmetic, so
  11483. this is not difficult.  Storing birth date rather than age has other
  11484. advantages, too:
  11485.  
  11486.    * You can use the database for tasks such as generating reminders
  11487.      for upcoming pet birthdays.  (If you think this type of query is
  11488.      somewhat silly, note that it is the same question you might ask in
  11489.      the context of a business database to identify clients to whom
  11490.      you'll soon need to send out birthday greetings, for that
  11491.      computer-assisted personal touch.)
  11492.  
  11493.    * You can calculate age in relation to dates other than the current
  11494.      date.  For example, if you store death date in the database, you
  11495.      can easily calculate how old a pet was when it died.
  11496.  
  11497. You can probably think of other types of information that would be
  11498. useful in the `pet' table, but the ones identified so far are
  11499. sufficient for now: name, owner, species, sex, birth, and death.
  11500.  
  11501. Use a `CREATE TABLE' statement to specify the layout of your table:
  11502.  
  11503.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  11504.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  11505.  
  11506. `VARCHAR' is a good choice for the `name', `owner', and `species'
  11507. columns because the column values will vary in length.  The lengths of
  11508. those columns need not all be the same, and need not be `20'.  You can
  11509. pick any length from `1' to `255', whatever seems most reasonable to
  11510. you.  (If you make a poor choice and it turns out later that you need a
  11511. longer field, MySQL provides an `ALTER TABLE' statement.)
  11512.  
  11513. Several types of values can be chosen to represent sex in animal
  11514. records, such as `"m"' and `"f"', or perhaps `"male"' and `"female"'.
  11515. It's simplest to use the single characters `"m"' and `"f"'.
  11516.  
  11517. The use of the `DATE' datatype for the `birth' and `death' columns is a
  11518. fairly obvious choice.
  11519.  
  11520. Now that you have created a table, `SHOW TABLES' should produce some
  11521. output:
  11522.  
  11523.      mysql> SHOW TABLES;
  11524.      +---------------------+
  11525.      | Tables in menagerie |
  11526.      +---------------------+
  11527.      | pet                 |
  11528.      +---------------------+
  11529.  
  11530. To verify that your table was created the way you expected, use a
  11531. `DESCRIBE' statement:
  11532.  
  11533.      mysql> DESCRIBE pet;
  11534.      +---------+-------------+------+-----+---------+-------+
  11535.      | Field   | Type        | Null | Key | Default | Extra |
  11536.      +---------+-------------+------+-----+---------+-------+
  11537.      | name    | varchar(20) | YES  |     | NULL    |       |
  11538.      | owner   | varchar(20) | YES  |     | NULL    |       |
  11539.      | species | varchar(20) | YES  |     | NULL    |       |
  11540.      | sex     | char(1)     | YES  |     | NULL    |       |
  11541.      | birth   | date        | YES  |     | NULL    |       |
  11542.      | death   | date        | YES  |     | NULL    |       |
  11543.      +---------+-------------+------+-----+---------+-------+
  11544.  
  11545. You can use `DESCRIBE' any time, for example, if you forget the names of
  11546. the columns in your table or what types they have.
  11547.  
  11548. Loading Data into a Table
  11549. -------------------------
  11550.  
  11551. After creating your table, you need to populate it.  The `LOAD DATA' and
  11552. `INSERT' statements are useful for this.
  11553.  
  11554. Suppose your pet records can be described as shown here.  (Observe that
  11555. MySQL expects dates in `'YYYY-MM-DD'' format; this may be different
  11556. from what you are used to.)
  11557.  
  11558. *name*  *owner* *species**sex**birth*        *death*
  11559. Fluffy  Harold  cat     f    1993-02-04     
  11560. Claws   Gwen    cat     m    1994-03-17     
  11561. Buffy   Harold  dog     f    1989-05-13     
  11562. Fang    Benny   dog     m    1990-08-27     
  11563. Bowser  Diane   dog     m    1979-08-31     1995-07-29
  11564. Chirpy  Gwen    bird    f    1998-09-11     
  11565. WhistlerGwen    bird         1997-12-09     
  11566. Slim    Benny   snake   m    1996-04-29     
  11567.  
  11568. Because you are beginning with an empty table, an easy way to populate
  11569. it is to create a text file containing a row for each of your animals,
  11570. then load the contents of the file into the table with a single
  11571. statement.
  11572.  
  11573. You could create a text file `pet.txt' containing one record per line,
  11574. with values separated by tabs, and given in the order in which the
  11575. columns were listed in the `CREATE TABLE' statement.  For missing
  11576. values (such as unknown sexes or death dates for animals that are still
  11577. living), you can use `NULL' values.  To represent these in your text
  11578. file, use `\N' (backslash, capital-N).  For example, the record for
  11579. Whistler the bird would look like this (where the whitespace between
  11580. values is a single tab character):
  11581.  
  11582. *name*  *owner* *species**sex**birth*        *death*
  11583. `Whistler'`Gwen'  `bird'  `\N' `1997-12-09'   `\N'
  11584.  
  11585. To load the text file `pet.txt' into the `pet' table, use this command:
  11586.  
  11587.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  11588.  
  11589. You can specify the column value separator and end of line marker
  11590. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  11591. are tab and linefeed.  These are sufficient for the statement to read
  11592. the file `pet.txt' properly.
  11593.  
  11594. If the statement fails, it is likely that your MySQL installation does
  11595. not have local file capability enabled by default.  See *Note `LOAD
  11596. DATA LOCAL': LOAD DATA LOCAL for information on how to change this.
  11597.  
  11598. When you want to add new records one at a time, the `INSERT' statement
  11599. is useful.  In its simplest form, you supply values for each column, in
  11600. the order in which the columns were listed in the `CREATE TABLE'
  11601. statement.  Suppose Diane gets a new hamster named Puffball.  You could
  11602. add a new record using an `INSERT' statement like this:
  11603.  
  11604.      mysql> INSERT INTO pet
  11605.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  11606.  
  11607. Note that string and date values are specified as quoted strings here.
  11608. Also, with `INSERT', you can insert `NULL' directly to represent a
  11609. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  11610.  
  11611. From this example, you should be able to see that there would be a lot
  11612. more typing involved to load your records initially using several
  11613. `INSERT' statements rather than a single `LOAD DATA' statement.
  11614.  
  11615. Retrieving Information from a Table
  11616. -----------------------------------
  11617.  
  11618. The `SELECT' statement is used to pull information from a table.  The
  11619. general form of the statement is:
  11620.  
  11621.      SELECT what_to_select
  11622.      FROM which_table
  11623.      WHERE conditions_to_satisfy;
  11624.  
  11625. `what_to_select' indicates what you want to see.  This can be a list of
  11626. columns, or `*' to indicate "all columns." `which_table' indicates the
  11627. table from which you want to retrieve data.  The `WHERE' clause is
  11628. optional.  If it's present, `conditions_to_satisfy' specifies
  11629. conditions that rows must satisfy to qualify for retrieval.
  11630.  
  11631. Selecting All Data
  11632. ..................
  11633.  
  11634. The simplest form of `SELECT' retrieves everything from a table:
  11635.  
  11636.      mysql> SELECT * FROM pet;
  11637.      +----------+--------+---------+------+------------+------------+
  11638.      | name     | owner  | species | sex  | birth      | death      |
  11639.      +----------+--------+---------+------+------------+------------+
  11640.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  11641.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  11642.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  11643.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  11644.      | Bowser   | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
  11645.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  11646.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  11647.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  11648.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  11649.      +----------+--------+---------+------+------------+------------+
  11650.  
  11651. This form of `SELECT' is useful if you want to review your entire table,
  11652. for instance, after you've just loaded it with your initial dataset.
  11653. For example, you may happen to think that the birth date for Bowser
  11654. doesn't seem quite right.  Consulting your original pedigree papers,
  11655. you find that the correct birth year should be 1989, not 1979.
  11656.  
  11657. There are least a couple of ways to fix this:
  11658.  
  11659.    * Edit the file `pet.txt' to correct the error, then empty the table
  11660.      and reload it using `DELETE' and `LOAD DATA':
  11661.  
  11662.           mysql> DELETE FROM pet;
  11663.           mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  11664.  
  11665.      However, if you do this, you must also re-enter the record for
  11666.      Puffball.
  11667.  
  11668.    * Fix only the erroneous record with an `UPDATE' statement:
  11669.  
  11670.           mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
  11671.  
  11672.      The `UPDATE' changes only the record in question and does not
  11673.      require you to reload the table.
  11674.  
  11675. Selecting Particular Rows
  11676. .........................
  11677.  
  11678. As shown in the preceding section, it is easy to retrieve an entire
  11679. table.  Just omit the `WHERE' clause from the `SELECT' statement.  But
  11680. typically you don't want to see the entire table, particularly when it
  11681. becomes large.  Instead, you're usually more interested in answering a
  11682. particular question, in which case you specify some constraints on the
  11683. information you want.  Let's look at some selection queries in terms of
  11684. questions about your pets that they answer.
  11685.  
  11686. You can select only particular rows from your table.  For example, if
  11687. you want to verify the change that you made to Bowser's birth date,
  11688. select Bowser's record like this:
  11689.  
  11690.      mysql> SELECT * FROM pet WHERE name = "Bowser";
  11691.      +--------+-------+---------+------+------------+------------+
  11692.      | name   | owner | species | sex  | birth      | death      |
  11693.      +--------+-------+---------+------+------------+------------+
  11694.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  11695.      +--------+-------+---------+------+------------+------------+
  11696.  
  11697. The output confirms that the year is correctly recorded now as 1989,
  11698. not 1979.
  11699.  
  11700. String comparisons normally are case-insensitive, so you can specify the
  11701. name as `"bowser"', `"BOWSER"', etc.  The query result will be the same.
  11702.  
  11703. You can specify conditions on any column, not just `name'.  For example,
  11704. if you want to know which animals were born after 1998, test the `birth'
  11705. column:
  11706.  
  11707.      mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
  11708.      +----------+-------+---------+------+------------+-------+
  11709.      | name     | owner | species | sex  | birth      | death |
  11710.      +----------+-------+---------+------+------------+-------+
  11711.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  11712.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  11713.      +----------+-------+---------+------+------------+-------+
  11714.  
  11715. You can combine conditions, for example, to locate female dogs:
  11716.  
  11717.      mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
  11718.      +-------+--------+---------+------+------------+-------+
  11719.      | name  | owner  | species | sex  | birth      | death |
  11720.      +-------+--------+---------+------+------------+-------+
  11721.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11722.      +-------+--------+---------+------+------------+-------+
  11723.  
  11724. The preceding query uses the `AND' logical operator.  There is also an
  11725. `OR' operator:
  11726.  
  11727.      mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
  11728.      +----------+-------+---------+------+------------+-------+
  11729.      | name     | owner | species | sex  | birth      | death |
  11730.      +----------+-------+---------+------+------------+-------+
  11731.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  11732.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  11733.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  11734.      +----------+-------+---------+------+------------+-------+
  11735.  
  11736. `AND' and `OR' may be intermixed, though `AND' has higher precedence
  11737. than `OR'.  If you use both operators, it's a good idea to use
  11738. parentheses to indicate explicitly how conditions should be grouped:
  11739.  
  11740.      mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
  11741.          -> OR (species = "dog" AND sex = "f");
  11742.      +-------+--------+---------+------+------------+-------+
  11743.      | name  | owner  | species | sex  | birth      | death |
  11744.      +-------+--------+---------+------+------------+-------+
  11745.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11746.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11747.      +-------+--------+---------+------+------------+-------+
  11748.  
  11749. Selecting Particular Columns
  11750. ............................
  11751.  
  11752. If you don't want to see entire rows from your table, just name the
  11753. columns in which you're interested, separated by commas.  For example,
  11754. if you want to know when your animals were born, select the `name' and
  11755. `birth' columns:
  11756.  
  11757.      mysql> SELECT name, birth FROM pet;
  11758.      +----------+------------+
  11759.      | name     | birth      |
  11760.      +----------+------------+
  11761.      | Fluffy   | 1993-02-04 |
  11762.      | Claws    | 1994-03-17 |
  11763.      | Buffy    | 1989-05-13 |
  11764.      | Fang     | 1990-08-27 |
  11765.      | Bowser   | 1989-08-31 |
  11766.      | Chirpy   | 1998-09-11 |
  11767.      | Whistler | 1997-12-09 |
  11768.      | Slim     | 1996-04-29 |
  11769.      | Puffball | 1999-03-30 |
  11770.      +----------+------------+
  11771.  
  11772. To find out who owns pets, use this query:
  11773.  
  11774.      mysql> SELECT owner FROM pet;
  11775.      +--------+
  11776.      | owner  |
  11777.      +--------+
  11778.      | Harold |
  11779.      | Gwen   |
  11780.      | Harold |
  11781.      | Benny  |
  11782.      | Diane  |
  11783.      | Gwen   |
  11784.      | Gwen   |
  11785.      | Benny  |
  11786.      | Diane  |
  11787.      +--------+
  11788.  
  11789. However, notice that the query simply retrieves the `owner' field from
  11790. each record, and some of them appear more than once.  To minimise the
  11791. output, retrieve each unique output record just once by adding the
  11792. keyword `DISTINCT':
  11793.  
  11794.      mysql> SELECT DISTINCT owner FROM pet;
  11795.      +--------+
  11796.      | owner  |
  11797.      +--------+
  11798.      | Benny  |
  11799.      | Diane  |
  11800.      | Gwen   |
  11801.      | Harold |
  11802.      +--------+
  11803.  
  11804. You can use a `WHERE' clause to combine row selection with column
  11805. selection.  For example, to get birth dates for dogs and cats only, use
  11806. this query:
  11807.  
  11808.      mysql> SELECT name, species, birth FROM pet
  11809.          -> WHERE species = "dog" OR species = "cat";
  11810.      +--------+---------+------------+
  11811.      | name   | species | birth      |
  11812.      +--------+---------+------------+
  11813.      | Fluffy | cat     | 1993-02-04 |
  11814.      | Claws  | cat     | 1994-03-17 |
  11815.      | Buffy  | dog     | 1989-05-13 |
  11816.      | Fang   | dog     | 1990-08-27 |
  11817.      | Bowser | dog     | 1989-08-31 |
  11818.      +--------+---------+------------+
  11819.  
  11820. Sorting Rows
  11821. ............
  11822.  
  11823. You may have noticed in the preceding examples that the result rows are
  11824. displayed in no particular order.  It's often easier to examine query
  11825. output when the rows are sorted in some meaningful way.  To sort a
  11826. result, use an `ORDER BY' clause.
  11827.  
  11828. Here are animal birthdays, sorted by date:
  11829.  
  11830.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  11831.      +----------+------------+
  11832.      | name     | birth      |
  11833.      +----------+------------+
  11834.      | Buffy    | 1989-05-13 |
  11835.      | Bowser   | 1989-08-31 |
  11836.      | Fang     | 1990-08-27 |
  11837.      | Fluffy   | 1993-02-04 |
  11838.      | Claws    | 1994-03-17 |
  11839.      | Slim     | 1996-04-29 |
  11840.      | Whistler | 1997-12-09 |
  11841.      | Chirpy   | 1998-09-11 |
  11842.      | Puffball | 1999-03-30 |
  11843.      +----------+------------+
  11844.  
  11845. On character type columns, sorting--like all other comparison
  11846. operations--is normally performed in a case-insensitive fashion.  This
  11847. means that the order will be undefined for columns that are identical
  11848. except for their case. You can force a case-sensitive sort for a column
  11849. by using the `BINARY' cast: `ORDER BY BINARY col_name'.
  11850.  
  11851. The default sort order is ascending, with smallest values first.  To
  11852. sort in reverse (descending) order, add the `DESC' keyword to the name
  11853. of the column you are sorting by:
  11854.  
  11855.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  11856.      +----------+------------+
  11857.      | name     | birth      |
  11858.      +----------+------------+
  11859.      | Puffball | 1999-03-30 |
  11860.      | Chirpy   | 1998-09-11 |
  11861.      | Whistler | 1997-12-09 |
  11862.      | Slim     | 1996-04-29 |
  11863.      | Claws    | 1994-03-17 |
  11864.      | Fluffy   | 1993-02-04 |
  11865.      | Fang     | 1990-08-27 |
  11866.      | Bowser   | 1989-08-31 |
  11867.      | Buffy    | 1989-05-13 |
  11868.      +----------+------------+
  11869.  
  11870. You can sort on multiple columns, and you can sort columns in different
  11871. directions.  For example, to sort by type of animal in ascending order,
  11872. then by birth date within animal type in descending order (youngest
  11873. animals first), use the following query:
  11874.  
  11875.      mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
  11876.      +----------+---------+------------+
  11877.      | name     | species | birth      |
  11878.      +----------+---------+------------+
  11879.      | Chirpy   | bird    | 1998-09-11 |
  11880.      | Whistler | bird    | 1997-12-09 |
  11881.      | Claws    | cat     | 1994-03-17 |
  11882.      | Fluffy   | cat     | 1993-02-04 |
  11883.      | Fang     | dog     | 1990-08-27 |
  11884.      | Bowser   | dog     | 1989-08-31 |
  11885.      | Buffy    | dog     | 1989-05-13 |
  11886.      | Puffball | hamster | 1999-03-30 |
  11887.      | Slim     | snake   | 1996-04-29 |
  11888.      +----------+---------+------------+
  11889.  
  11890. Note that the `DESC' keyword applies only to the column name immediately
  11891. preceding it (`birth'); it does not affect the `species' column sort
  11892. order.
  11893.  
  11894. Date Calculations
  11895. .................
  11896.  
  11897. MySQL provides several functions that you can use to perform
  11898. calculations on dates, for example, to calculate ages or extract parts
  11899. of dates.
  11900.  
  11901. To determine how many years old each of your pets is, compute the
  11902. difference in the year part of the current date and the birth date, then
  11903. subtract one if the current date occurs earlier in the calendar year
  11904. than the birth date.  The following query shows, for each pet, the
  11905. birth date, the current date, and the age in years.
  11906.  
  11907.      mysql> SELECT name, birth, CURDATE(),
  11908.          -> (YEAR(CURDATE())-YEAR(birth))
  11909.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  11910.          -> AS age
  11911.          -> FROM pet;
  11912.      +----------+------------+------------+------+
  11913.      | name     | birth      | CURDATE()  | age  |
  11914.      +----------+------------+------------+------+
  11915.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  11916.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  11917.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  11918.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  11919.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  11920.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  11921.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  11922.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  11923.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  11924.      +----------+------------+------------+------+
  11925.  
  11926. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  11927. off the rightmost five characters that represent the `MM-DD' (calendar
  11928. year) part of the date.  The part of the expression that compares the
  11929. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  11930. down a year if `CURDATE()' occurs earlier in the year than `birth'.
  11931. The full expression is somewhat ungainly, so an alias (`age') is used
  11932. to make the output column label more meaningful.
  11933.  
  11934. The query works, but the result could be scanned more easily if the rows
  11935. were presented in some order.  This can be done by adding an `ORDER BY
  11936. name' clause to sort the output by name:
  11937.  
  11938.      mysql> SELECT name, birth, CURDATE(),
  11939.          -> (YEAR(CURDATE())-YEAR(birth))
  11940.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  11941.          -> AS age
  11942.          -> FROM pet ORDER BY name;
  11943.      +----------+------------+------------+------+
  11944.      | name     | birth      | CURDATE()  | age  |
  11945.      +----------+------------+------------+------+
  11946.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  11947.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  11948.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  11949.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  11950.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  11951.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  11952.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  11953.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  11954.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  11955.      +----------+------------+------------+------+
  11956.  
  11957. To sort the output by `age' rather than `name', just use a different
  11958. `ORDER BY' clause:
  11959.  
  11960.      mysql> SELECT name, birth, CURDATE(),
  11961.          -> (YEAR(CURDATE())-YEAR(birth))
  11962.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  11963.          -> AS age
  11964.          -> FROM pet ORDER BY age;
  11965.      +----------+------------+------------+------+
  11966.      | name     | birth      | CURDATE()  | age  |
  11967.      +----------+------------+------------+------+
  11968.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  11969.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  11970.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  11971.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  11972.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  11973.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  11974.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  11975.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  11976.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  11977.      +----------+------------+------------+------+
  11978.  
  11979. A similar query can be used to determine age at death for animals that
  11980. have died.  You determine which animals these are by checking whether
  11981. the `death' value is `NULL'.  Then, for those with non-`NULL' values,
  11982. compute the difference between the `death' and `birth' values:
  11983.  
  11984.      mysql> SELECT name, birth, death,
  11985.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  11986.          -> AS age
  11987.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  11988.      +--------+------------+------------+------+
  11989.      | name   | birth      | death      | age  |
  11990.      +--------+------------+------------+------+
  11991.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  11992.      +--------+------------+------------+------+
  11993.  
  11994. The query uses `death IS NOT NULL' rather than `death <> NULL' because
  11995. `NULL' is a special value that cannot be compared using the usual
  11996. comparison operators.  This is discussed later.  *Note Working with
  11997. `NULL': Working with NULL.
  11998.  
  11999. What if you want to know which animals have birthdays next month?  For
  12000. this type of calculation, year and day are irrelevant; you simply want
  12001. to extract the month part of the `birth' column.  MySQL provides several
  12002. date-part extraction functions, such as `YEAR()', `MONTH()', and
  12003. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  12004. how it works, run a simple query that displays the value of both
  12005. `birth' and `MONTH(birth)':
  12006.  
  12007.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  12008.      +----------+------------+--------------+
  12009.      | name     | birth      | MONTH(birth) |
  12010.      +----------+------------+--------------+
  12011.      | Fluffy   | 1993-02-04 |            2 |
  12012.      | Claws    | 1994-03-17 |            3 |
  12013.      | Buffy    | 1989-05-13 |            5 |
  12014.      | Fang     | 1990-08-27 |            8 |
  12015.      | Bowser   | 1989-08-31 |            8 |
  12016.      | Chirpy   | 1998-09-11 |            9 |
  12017.      | Whistler | 1997-12-09 |           12 |
  12018.      | Slim     | 1996-04-29 |            4 |
  12019.      | Puffball | 1999-03-30 |            3 |
  12020.      +----------+------------+--------------+
  12021.  
  12022. Finding animals with birthdays in the upcoming month is easy, too.
  12023. Suppose the current month is April.  Then the month value is `4' and
  12024. you look for animals born in May (month `5') like this:
  12025.  
  12026.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  12027.      +-------+------------+
  12028.      | name  | birth      |
  12029.      +-------+------------+
  12030.      | Buffy | 1989-05-13 |
  12031.      +-------+------------+
  12032.  
  12033. There is a small complication if the current month is December, of
  12034. course.  You don't just add one to the month number (`12') and look for
  12035. animals born in month `13', because there is no such month.  Instead,
  12036. you look for animals born in January (month `1').
  12037.  
  12038. You can even write the query so that it works no matter what the current
  12039. month is.  That way you don't have to use a particular month number in
  12040. the query.  `DATE_ADD()' allows you to add a time interval to a given
  12041. date.  If you add a month to the value of `CURDATE()', then extract the
  12042. month part with `MONTH()', the result produces the month in which to
  12043. look for birthdays:
  12044.  
  12045.      mysql> SELECT name, birth FROM pet
  12046.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(), INTERVAL 1 MONTH));
  12047.  
  12048. A different way to accomplish the same task is to add `1' to get the
  12049. next month after the current one (after using the modulo function
  12050. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  12051.  
  12052.      mysql> SELECT name, birth FROM pet
  12053.          -> WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1;
  12054.  
  12055. Note that `MONTH' returns a number between `1' and `12'. And
  12056. `MOD(something,12)' returns a number between `0' and `11'. So the
  12057. addition has to be after the `MOD()', otherwise we would go from
  12058. November (`11') to January (`1').
  12059.  
  12060. Working with `NULL' Values
  12061. ..........................
  12062.  
  12063. The `NULL' value can be surprising until you get used to it.
  12064. Conceptually, `NULL' means missing value or unknown value and it is
  12065. treated somewhat differently than other values.  To test for `NULL',
  12066. you cannot use the arithmetic comparison operators such as `=', `<', or
  12067. `<>'.  To demonstrate this for yourself, try the following query:
  12068.  
  12069.      mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
  12070.      +----------+-----------+----------+----------+
  12071.      | 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |
  12072.      +----------+-----------+----------+----------+
  12073.      |     NULL |      NULL |     NULL |     NULL |
  12074.      +----------+-----------+----------+----------+
  12075.  
  12076. Clearly you get no meaningful results from these comparisons.  Use the
  12077. `IS NULL' and `IS NOT NULL' operators instead:
  12078.  
  12079.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  12080.      +-----------+---------------+
  12081.      | 1 IS NULL | 1 IS NOT NULL |
  12082.      +-----------+---------------+
  12083.      |         0 |             1 |
  12084.      +-----------+---------------+
  12085.  
  12086. Note that in MySQL, `0' or `NULL' means false and anything else means
  12087. true. The default truth value from a boolean operation is `1'.
  12088.  
  12089. This special treatment of `NULL' is why, in the previous section, it
  12090. was necessary to determine which animals are no longer alive using
  12091. `death IS NOT NULL' instead of `death <> NULL'.
  12092.  
  12093. Two `NULL' values are regarded as equal in a `GROUP BY'.
  12094.  
  12095. When doing an `ORDER BY', `NULL' values are presented first if you do
  12096. `ORDER BY ... ASC' and last if you do `ORDER BY ... DESC'.
  12097.  
  12098. Note that MySQL 4.0.2 to 4.0.10 incorrectly always sorts `NULL' values
  12099. first regardless of the sort direction.
  12100.  
  12101. Pattern Matching
  12102. ................
  12103.  
  12104. MySQL provides standard SQL pattern matching as well as a form of
  12105. pattern matching based on extended regular expressions similar to those
  12106. used by Unix utilities such as `vi', `grep', and `sed'.
  12107.  
  12108. SQL pattern matching allows you to use `_' to match any single
  12109. character and `%' to match an arbitrary number of characters (including
  12110. zero characters).  In MySQL, SQL patterns are case-insensitive by
  12111. default.  Some examples are shown here.  Note that you do not use `='
  12112. or `<>' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  12113. comparison operators instead.
  12114.  
  12115. To find names beginning with `b':
  12116.  
  12117.      mysql> SELECT * FROM pet WHERE name LIKE "b%";
  12118.      +--------+--------+---------+------+------------+------------+
  12119.      | name   | owner  | species | sex  | birth      | death      |
  12120.      +--------+--------+---------+------+------------+------------+
  12121.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  12122.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  12123.      +--------+--------+---------+------+------------+------------+
  12124.  
  12125. To find names ending with `fy':
  12126.  
  12127.      mysql> SELECT * FROM pet WHERE name LIKE "%fy";
  12128.      +--------+--------+---------+------+------------+-------+
  12129.      | name   | owner  | species | sex  | birth      | death |
  12130.      +--------+--------+---------+------+------------+-------+
  12131.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  12132.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  12133.      +--------+--------+---------+------+------------+-------+
  12134.  
  12135. To find names containing a `w':
  12136.  
  12137.      mysql> SELECT * FROM pet WHERE name LIKE "%w%";
  12138.      +----------+-------+---------+------+------------+------------+
  12139.      | name     | owner | species | sex  | birth      | death      |
  12140.      +----------+-------+---------+------+------------+------------+
  12141.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  12142.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12143.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  12144.      +----------+-------+---------+------+------------+------------+
  12145.  
  12146. To find names containing exactly five characters, use fives instances of
  12147. the `_' pattern character:
  12148.  
  12149.      mysql> SELECT * FROM pet WHERE name LIKE "_____";
  12150.      +-------+--------+---------+------+------------+-------+
  12151.      | name  | owner  | species | sex  | birth      | death |
  12152.      +-------+--------+---------+------+------------+-------+
  12153.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12154.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12155.      +-------+--------+---------+------+------------+-------+
  12156.  
  12157. The other type of pattern matching provided by MySQL uses extended
  12158. regular expressions.  When you test for a match for this type of
  12159. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  12160. `NOT RLIKE', which are synonyms).
  12161.  
  12162. Some characteristics of extended regular expressions are:
  12163.  
  12164.    * `.' matches any single character.
  12165.  
  12166.    * A character class `[...]' matches any character within the
  12167.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  12168.      a range of characters, use a dash.  `[a-z]' matches any letter,
  12169.      whereas `[0-9]' matches any digit.
  12170.  
  12171.    * `*' matches zero or more instances of the thing preceding it.  For
  12172.      example, `x*' matches any number of `x' characters, `[0-9]*'
  12173.      matches any number of digits, and `.*' matches any number of
  12174.      anything.
  12175.  
  12176.    * A `REGEXP' pattern match succeed if the pattern matches anywhere
  12177.      in the value being tested.  (This differs from a `LIKE' pattern
  12178.      match, which succeeds only if the pattern matches the entire
  12179.      value.)
  12180.  
  12181.    * To anchor a pattern so that it must match the beginning or end of
  12182.      the value being tested, use `^' at the beginning or `$' at the end
  12183.      of the pattern.
  12184.  
  12185. To demonstrate how extended regular expressions work, the `LIKE' queries
  12186. shown previously are rewritten here to use `REGEXP'.
  12187.  
  12188. To find names beginning with `b', use `^' to match the beginning of the
  12189. name:
  12190.  
  12191.      mysql> SELECT * FROM pet WHERE name REGEXP "^b";
  12192.      +--------+--------+---------+------+------------+------------+
  12193.      | name   | owner  | species | sex  | birth      | death      |
  12194.      +--------+--------+---------+------+------------+------------+
  12195.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  12196.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  12197.      +--------+--------+---------+------+------------+------------+
  12198.  
  12199. Prior to MySQL Version 3.23.4, `REGEXP' is case-sensitive, and the
  12200. previous query will return no rows. In this case, to match either
  12201. lowercase or uppercase `b', use this query instead:
  12202.  
  12203.      mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
  12204.  
  12205. From MySQL 3.23.4 on, if you really want to force a `REGEXP' comparison
  12206. to be case-sensitive, use the `BINARY' keyword to make one of the
  12207. strings a binary string. This query will match only lowercase `b' at
  12208. the beginning of a name:
  12209.  
  12210.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY "^b";
  12211.  
  12212. To find names ending with `fy', use `$' to match the end of the name:
  12213.  
  12214.      mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
  12215.      +--------+--------+---------+------+------------+-------+
  12216.      | name   | owner  | species | sex  | birth      | death |
  12217.      +--------+--------+---------+------+------------+-------+
  12218.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  12219.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  12220.      +--------+--------+---------+------+------------+-------+
  12221.  
  12222. To find names containing a `w', use this query:
  12223.  
  12224.      mysql> SELECT * FROM pet WHERE name REGEXP "w";
  12225.      +----------+-------+---------+------+------------+------------+
  12226.      | name     | owner | species | sex  | birth      | death      |
  12227.      +----------+-------+---------+------+------------+------------+
  12228.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  12229.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12230.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  12231.      +----------+-------+---------+------+------------+------------+
  12232.  
  12233. Because a regular expression pattern matches if it occurs anywhere in
  12234. the value, it is not necessary in the previous query to put a wildcard
  12235. on either side of the pattern to get it to match the entire value like
  12236. it would be if you used an SQL pattern.
  12237.  
  12238. To find names containing exactly five characters, use `^' and `$' to
  12239. match the beginning and end of the name, and five instances of `.' in
  12240. between:
  12241.  
  12242.      mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
  12243.      +-------+--------+---------+------+------------+-------+
  12244.      | name  | owner  | species | sex  | birth      | death |
  12245.      +-------+--------+---------+------+------------+-------+
  12246.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12247.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12248.      +-------+--------+---------+------+------------+-------+
  12249.  
  12250. You could also write the previous query using the `{n}'
  12251. "repeat-`n'-times" operator:
  12252.  
  12253.      mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
  12254.      +-------+--------+---------+------+------------+-------+
  12255.      | name  | owner  | species | sex  | birth      | death |
  12256.      +-------+--------+---------+------+------------+-------+
  12257.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12258.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12259.      +-------+--------+---------+------+------------+-------+
  12260.  
  12261. Counting Rows
  12262. .............
  12263.  
  12264. Databases are often used to answer the question, "How often does a
  12265. certain type of data occur in a table?"  For example, you might want to
  12266. know how many pets you have, or how many pets each owner has, or you
  12267. might want to perform various kinds of census operations on your
  12268. animals.
  12269.  
  12270. Counting the total number of animals you have is the same question as
  12271. "How many rows are in the `pet' table?" because there is one record per
  12272. pet.  `COUNT(*)' counts the number of rows, so the query to count your
  12273. animals looks like this:
  12274.  
  12275.      mysql> SELECT COUNT(*) FROM pet;
  12276.      +----------+
  12277.      | COUNT(*) |
  12278.      +----------+
  12279.      |        9 |
  12280.      +----------+
  12281.  
  12282. Earlier, you retrieved the names of the people who owned pets.  You can
  12283. use `COUNT()' if you want to find out how many pets each owner has:
  12284.  
  12285.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  12286.      +--------+----------+
  12287.      | owner  | COUNT(*) |
  12288.      +--------+----------+
  12289.      | Benny  |        2 |
  12290.      | Diane  |        2 |
  12291.      | Gwen   |        3 |
  12292.      | Harold |        2 |
  12293.      +--------+----------+
  12294.  
  12295. Note the use of `GROUP BY' to group together all records for each
  12296. `owner'.  Without it, all you get is an error message:
  12297.  
  12298.      mysql> SELECT owner, COUNT(*) FROM pet;
  12299.      ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  12300.      with no GROUP columns is illegal if there is no GROUP BY clause
  12301.  
  12302. `COUNT()' and `GROUP BY' are useful for characterising your data in
  12303. various ways.  The following examples show different ways to perform
  12304. animal census operations.
  12305.  
  12306. Number of animals per species:
  12307.  
  12308.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  12309.      +---------+----------+
  12310.      | species | COUNT(*) |
  12311.      +---------+----------+
  12312.      | bird    |        2 |
  12313.      | cat     |        2 |
  12314.      | dog     |        3 |
  12315.      | hamster |        1 |
  12316.      | snake   |        1 |
  12317.      +---------+----------+
  12318.  
  12319. Number of animals per sex:
  12320.  
  12321.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  12322.      +------+----------+
  12323.      | sex  | COUNT(*) |
  12324.      +------+----------+
  12325.      | NULL |        1 |
  12326.      | f    |        4 |
  12327.      | m    |        4 |
  12328.      +------+----------+
  12329.  
  12330. (In this output, `NULL' indicates that the sex is unknown.)
  12331.  
  12332. Number of animals per combination of species and sex:
  12333.  
  12334.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  12335.      +---------+------+----------+
  12336.      | species | sex  | COUNT(*) |
  12337.      +---------+------+----------+
  12338.      | bird    | NULL |        1 |
  12339.      | bird    | f    |        1 |
  12340.      | cat     | f    |        1 |
  12341.      | cat     | m    |        1 |
  12342.      | dog     | f    |        1 |
  12343.      | dog     | m    |        2 |
  12344.      | hamster | f    |        1 |
  12345.      | snake   | m    |        1 |
  12346.      +---------+------+----------+
  12347.  
  12348. You need not retrieve an entire table when you use `COUNT()'.  For
  12349. example, the previous query, when performed just on dogs and cats,
  12350. looks like this:
  12351.  
  12352.      mysql> SELECT species, sex, COUNT(*) FROM pet
  12353.          -> WHERE species = "dog" OR species = "cat"
  12354.          -> GROUP BY species, sex;
  12355.      +---------+------+----------+
  12356.      | species | sex  | COUNT(*) |
  12357.      +---------+------+----------+
  12358.      | cat     | f    |        1 |
  12359.      | cat     | m    |        1 |
  12360.      | dog     | f    |        1 |
  12361.      | dog     | m    |        2 |
  12362.      +---------+------+----------+
  12363.  
  12364. Or, if you wanted the number of animals per sex only for known-sex
  12365. animals:
  12366.  
  12367.      mysql> SELECT species, sex, COUNT(*) FROM pet
  12368.          -> WHERE sex IS NOT NULL
  12369.          -> GROUP BY species, sex;
  12370.      +---------+------+----------+
  12371.      | species | sex  | COUNT(*) |
  12372.      +---------+------+----------+
  12373.      | bird    | f    |        1 |
  12374.      | cat     | f    |        1 |
  12375.      | cat     | m    |        1 |
  12376.      | dog     | f    |        1 |
  12377.      | dog     | m    |        2 |
  12378.      | hamster | f    |        1 |
  12379.      | snake   | m    |        1 |
  12380.      +---------+------+----------+
  12381.  
  12382. Using More Than one Table
  12383. .........................
  12384.  
  12385. The `pet' table keeps track of which pets you have.  If you want to
  12386. record other information about them, such as events in their lives like
  12387. visits to the vet or when litters are born, you need another table.
  12388. What should this table look like? It needs:
  12389.  
  12390.    * To contain the pet name so you know which animal each event
  12391.      pertains to.
  12392.  
  12393.    * A date so you know when the event occurred.
  12394.  
  12395.    * A field to describe the event.
  12396.  
  12397.    * An event type field, if you want to be able to categorise events.
  12398.  
  12399. Given these considerations, the `CREATE TABLE' statement for the
  12400. `event' table might look like this:
  12401.  
  12402.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  12403.          -> type VARCHAR(15), remark VARCHAR(255));
  12404.  
  12405. As with the `pet' table, it's easiest to load the initial records by
  12406. creating a tab-delimited text file containing the information:
  12407.  
  12408. *name*      *date*      *type*      *remark*
  12409. Fluffy      1995-05-15  litter      4 kittens, 3 female, 1
  12410.                                     male
  12411. Buffy       1993-06-23  litter      5 puppies, 2 female, 3
  12412.                                     male
  12413. Buffy       1994-06-19  litter      3 puppies, 3 female
  12414. Chirpy      1999-03-21  vet         needed beak straightened
  12415. Slim        1997-08-03  vet         broken rib
  12416. Bowser      1991-10-12  kennel      
  12417. Fang        1991-10-12  kennel      
  12418. Fang        1998-08-28  birthday    Gave him a new chew toy
  12419. Claws       1998-03-17  birthday    Gave him a new flea
  12420.                                     collar
  12421. Whistler    1998-12-09  birthday    First birthday
  12422.  
  12423. Load the records like this:
  12424.  
  12425.      mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
  12426.  
  12427. Based on what you've learned from the queries you've run on the `pet'
  12428. table, you should be able to perform retrievals on the records in the
  12429. `event' table; the principles are the same.  But when is the `event'
  12430. table by itself insufficient to answer questions you might ask?
  12431.  
  12432. Suppose you want to find out the ages at which each pet had its
  12433. litters. We saw earlier how to calculate ages from two dates.  The
  12434. litter date of the mother is in the `event' table, but to calculate her
  12435. age on that date you need her birth date, which is stored in the `pet'
  12436. table.  This means the query requires both tables:
  12437.  
  12438.      mysql> SELECT pet.name,
  12439.          -> (YEAR(date)-YEAR(birth)) - (RIGHT(date,5)<RIGHT(birth,5)) AS age,
  12440.          -> remark
  12441.          -> FROM pet, event
  12442.          -> WHERE pet.name = event.name AND type = "litter";
  12443.      +--------+------+-----------------------------+
  12444.      | name   | age  | remark                      |
  12445.      +--------+------+-----------------------------+
  12446.      | Fluffy |    2 | 4 kittens, 3 female, 1 male |
  12447.      | Buffy  |    4 | 5 puppies, 2 female, 3 male |
  12448.      | Buffy  |    5 | 3 puppies, 3 female         |
  12449.      +--------+------+-----------------------------+
  12450.  
  12451. There are several things to note about this query:
  12452.  
  12453.    * The `FROM' clause lists two tables because the query needs to pull
  12454.      information from both of them.
  12455.  
  12456.    * When combining (joining) information from multiple tables, you
  12457.      need to specify how records in one table can be matched to records
  12458.      in the other.  This is easy because they both have a `name'
  12459.      column.  The query uses `WHERE' clause to match up records in the
  12460.      two tables based on the `name' values.
  12461.  
  12462.    * Because the `name' column occurs in both tables, you must be
  12463.      specific about which table you mean when referring to the column.
  12464.      This is done by prepending the table name to the column name.
  12465.  
  12466. You need not have two different tables to perform a join.  Sometimes it
  12467. is useful to join a table to itself, if you want to compare records in
  12468. a table to other records in that same table.  For example, to find
  12469. breeding pairs among your pets, you can join the `pet' table with
  12470. itself to produce candidate pairs of males and females of like species:
  12471.  
  12472.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  12473.          -> FROM pet AS p1, pet AS p2
  12474.          -> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
  12475.      +--------+------+--------+------+---------+
  12476.      | name   | sex  | name   | sex  | species |
  12477.      +--------+------+--------+------+---------+
  12478.      | Fluffy | f    | Claws  | m    | cat     |
  12479.      | Buffy  | f    | Fang   | m    | dog     |
  12480.      | Buffy  | f    | Bowser | m    | dog     |
  12481.      +--------+------+--------+------+---------+
  12482.  
  12483. In this query, we specify aliases for the table name in order to refer
  12484. to the columns and keep straight which instance of the table each
  12485. column reference is associated with.
  12486.  
  12487. Getting Information About Databases and Tables
  12488. ==============================================
  12489.  
  12490. What if you forget the name of a database or table, or what the
  12491. structure of a given table is (for example, what its columns are
  12492. called)?  MySQL addresses this problem through several statements that
  12493. provide information about the databases and tables it supports.
  12494.  
  12495. You have already seen `SHOW DATABASES', which lists the databases
  12496. managed by the server.  To find out which database is currently
  12497. selected, use the `DATABASE()' function:
  12498.  
  12499.      mysql> SELECT DATABASE();
  12500.      +------------+
  12501.      | DATABASE() |
  12502.      +------------+
  12503.      | menagerie  |
  12504.      +------------+
  12505.  
  12506. If you haven't selected any database yet, the result is blank.
  12507.  
  12508. To find out what tables the current database contains (for example, when
  12509. you're not sure about the name of a table), use this command:
  12510.  
  12511.      mysql> SHOW TABLES;
  12512.      +---------------------+
  12513.      | Tables in menagerie |
  12514.      +---------------------+
  12515.      | event               |
  12516.      | pet                 |
  12517.      +---------------------+
  12518.  
  12519. If you want to find out about the structure of a table, the `DESCRIBE'
  12520. command is useful; it displays information about each of a table's
  12521. columns:
  12522.  
  12523.      mysql> DESCRIBE pet;
  12524.      +---------+-------------+------+-----+---------+-------+
  12525.      | Field   | Type        | Null | Key | Default | Extra |
  12526.      +---------+-------------+------+-----+---------+-------+
  12527.      | name    | varchar(20) | YES  |     | NULL    |       |
  12528.      | owner   | varchar(20) | YES  |     | NULL    |       |
  12529.      | species | varchar(20) | YES  |     | NULL    |       |
  12530.      | sex     | char(1)     | YES  |     | NULL    |       |
  12531.      | birth   | date        | YES  |     | NULL    |       |
  12532.      | death   | date        | YES  |     | NULL    |       |
  12533.      +---------+-------------+------+-----+---------+-------+
  12534.  
  12535. `Field' indicates the column name, `Type' is the datatype for the
  12536. column, `NULL' indicates whether the column can contain `NULL' values,
  12537. `Key' indicates whether the column is indexed, and `Default' specifies
  12538. the column's default value.
  12539.  
  12540. If you have indexes on a table, `SHOW INDEX FROM tbl_name' produces
  12541. information about them.
  12542.  
  12543. Using `mysql' in Batch Mode
  12544. ===========================
  12545.  
  12546. In the previous sections, you used `mysql' interactively to enter
  12547. queries and view the results.  You can also run `mysql' in batch mode.
  12548. To do this, put the commands you want to run in a file, then tell
  12549. `mysql' to read its input from the file:
  12550.  
  12551.      shell> mysql < batch-file
  12552.  
  12553. If you are running `mysql' under Windows and have some special
  12554. characters in the file that cause problems, you can do this:
  12555.  
  12556.      dos> mysql -e "source batch-file"
  12557.  
  12558. If you need to specify connection parameters on the command line, the
  12559. command might look like this:
  12560.  
  12561.      shell> mysql -h host -u user -p < batch-file
  12562.      Enter password: ********
  12563.  
  12564. When you use `mysql' this way, you are creating a script file, then
  12565. executing the script.
  12566.  
  12567. If you want the script to continue even if some of the statements in it
  12568. produce errors, you should use the `--force' command-line option.
  12569.  
  12570. Why use a script?  Here are a few reasons:
  12571.  
  12572.    * If you run a query repeatedly (say, every day or every week),
  12573.      making it a script allows you to avoid retyping it each time you
  12574.      execute it.
  12575.  
  12576.    * You can generate new queries from existing ones that are similar
  12577.      by copying and editing script files.
  12578.  
  12579.    * Batch mode can also be useful while you're developing a query,
  12580.      particularly for multiple-line commands or multiple-statement
  12581.      sequences of commands.  If you make a mistake, you don't have to
  12582.      retype everything.  Just edit your script to correct the error,
  12583.      then tell `mysql' to execute it again.
  12584.  
  12585.    * If you have a query that produces a lot of output, you can run the
  12586.      output through a pager rather than watching it scroll off the top
  12587.      of your screen:
  12588.  
  12589.           shell> mysql < batch-file | more
  12590.  
  12591.    * You can catch the output in a file for further processing:
  12592.  
  12593.           shell> mysql < batch-file > mysql.out
  12594.  
  12595.    * You can distribute your script to other people so they can run the
  12596.      commands, too.
  12597.  
  12598.    * Some situations do not allow for interactive use, for example,
  12599.      when you run a query from a `cron' job.  In this case, you must
  12600.      use batch mode.
  12601.  
  12602. The default output format is different (more concise) when you run
  12603. `mysql' in batch mode than when you use it interactively.  For example,
  12604. the output of `SELECT DISTINCT species FROM pet' looks like this when
  12605. `mysql' is run interactively:
  12606.  
  12607.      +---------+
  12608.      | species |
  12609.      +---------+
  12610.      | bird    |
  12611.      | cat     |
  12612.      | dog     |
  12613.      | hamster |
  12614.      | snake   |
  12615.      +---------+
  12616.  
  12617. In batch mode, the output looks like this instead:
  12618.  
  12619.      species
  12620.      bird
  12621.      cat
  12622.      dog
  12623.      hamster
  12624.      snake
  12625.  
  12626. If you want to get the interactive output format in batch mode, use
  12627. `mysql -t'.  To echo to the output the commands that are executed, use
  12628. `mysql -vvv'.
  12629.  
  12630. You can also use scripts from the `mysql' prompt by using the `source'
  12631. command:
  12632.  
  12633.      mysql> source filename;
  12634.  
  12635. Examples of Common Queries
  12636. ==========================
  12637.  
  12638. Here are examples of how to solve some common problems with MySQL.
  12639.  
  12640. Some of the examples use the table `shop' to hold the price of each
  12641. article (item number) for certain traders (dealers).  Supposing that
  12642. each trader has a single fixed price per article, then (`article',
  12643. `dealer') is a primary key for the records.
  12644.  
  12645. Start the command-line tool `mysql' and select a database:
  12646.  
  12647.      shell> mysql your-database-name
  12648.  
  12649. (In most MySQL installations, you can use the database name `test').
  12650.  
  12651. You can create and populate the example table with these statements:
  12652.  
  12653.      mysql> CREATE TABLE shop (
  12654.          -> article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  12655.          -> dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  12656.          -> price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  12657.          -> PRIMARY KEY(article, dealer));
  12658.      mysql> INSERT INTO shop VALUES
  12659.          -> (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
  12660.          -> (3,'D',1.25),(4,'D',19.95);
  12661.  
  12662. After issuing the statements, the table should have the following
  12663. contents:
  12664.  
  12665.      mysql> SELECT * FROM shop;
  12666.      +---------+--------+-------+
  12667.      | article | dealer | price |
  12668.      +---------+--------+-------+
  12669.      |    0001 | A      |  3.45 |
  12670.      |    0001 | B      |  3.99 |
  12671.      |    0002 | A      | 10.99 |
  12672.      |    0003 | B      |  1.45 |
  12673.      |    0003 | C      |  1.69 |
  12674.      |    0003 | D      |  1.25 |
  12675.      |    0004 | D      | 19.95 |
  12676.      +---------+--------+-------+
  12677.  
  12678. The Maximum Value for a Column
  12679. ------------------------------
  12680.  
  12681. "What's the highest item number?"
  12682.  
  12683.      SELECT MAX(article) AS article FROM shop;
  12684.      
  12685.      +---------+
  12686.      | article |
  12687.      +---------+
  12688.      |       4 |
  12689.      +---------+
  12690.  
  12691. The Row Holding the Maximum of a Certain Column
  12692. -----------------------------------------------
  12693.  
  12694. "Find number, dealer, and price of the most expensive article."
  12695.  
  12696. In SQL-99 (and MySQL Version 4.1) this is easily done with a subquery:
  12697.  
  12698.      SELECT article, dealer, price
  12699.      FROM   shop
  12700.      WHERE  price=(SELECT MAX(price) FROM shop);
  12701.  
  12702. In MySQL versions prior to 4.1, just do it in two steps:
  12703.  
  12704.   1. Get the maximum price value from the table with a `SELECT'
  12705.      statement.
  12706.           mysql> SELECT MAX(price) FROM shop;
  12707.           +------------+
  12708.           | MAX(price) |
  12709.           +------------+
  12710.           |      19.95 |
  12711.           +------------+
  12712.  
  12713.   2. Using the value 19.95 shown by the previous query to be the maximum
  12714.      article price, write a query to locate and display the
  12715.      corresponding record:
  12716.           mysql> SELECT article, dealer, price
  12717.               -> FROM   shop
  12718.               -> WHERE  price=19.95;
  12719.           +---------+--------+-------+
  12720.           | article | dealer | price |
  12721.           +---------+--------+-------+
  12722.           |    0004 | D      | 19.95 |
  12723.           +---------+--------+-------+
  12724.  
  12725. Another solution is to sort all rows descending by price and only get
  12726. the first row using the MySQL-specific `LIMIT' clause:
  12727.  
  12728.      SELECT article, dealer, price
  12729.      FROM   shop
  12730.      ORDER BY price DESC
  12731.      LIMIT 1;
  12732.  
  12733. *NOTE*:  If there were several most expensive articles, each with a
  12734. price of 19.95, the `LIMIT' solution would show only one of them!
  12735.  
  12736. Maximum of Column per Group
  12737. ---------------------------
  12738.  
  12739. "What's the highest price per article?"
  12740.  
  12741.      SELECT article, MAX(price) AS price
  12742.      FROM   shop
  12743.      GROUP BY article
  12744.      
  12745.      +---------+-------+
  12746.      | article | price |
  12747.      +---------+-------+
  12748.      |    0001 |  3.99 |
  12749.      |    0002 | 10.99 |
  12750.      |    0003 |  1.69 |
  12751.      |    0004 | 19.95 |
  12752.      +---------+-------+
  12753.  
  12754. The Rows Holding the Group-wise Maximum of a Certain Field
  12755. ----------------------------------------------------------
  12756.  
  12757. "For each article, find the dealer(s) with the most expensive price."
  12758.  
  12759. In SQL-99 (and MySQL Version 4.1 or greater), the problem can be solved
  12760. with a subquery like this:
  12761.  
  12762.      SELECT article, dealer, price
  12763.      FROM   shop s1
  12764.      WHERE  price=(SELECT MAX(s2.price)
  12765.                    FROM shop s2
  12766.                    WHERE s1.article = s2.article);
  12767.  
  12768. In MySQL versions prior to 4.1, it's best do it in several steps:
  12769.  
  12770.   1. Get the list of (article,maxprice) pairs.
  12771.  
  12772.   2. For each article, get the corresponding rows that have the stored
  12773.      maximum price.
  12774.  
  12775. This can easily be done with a temporary table and a join:
  12776.  
  12777.      CREATE TEMPORARY TABLE tmp (
  12778.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  12779.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  12780.      
  12781.      LOCK TABLES shop READ;
  12782.      
  12783.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  12784.      
  12785.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  12786.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  12787.      
  12788.      UNLOCK TABLES;
  12789.      
  12790.      DROP TABLE tmp;
  12791.  
  12792. If you don't use a `TEMPORARY' table, you must also lock the `tmp'
  12793. table.
  12794.  
  12795. "Can it be done with a single query?"
  12796.  
  12797. Yes, but only by using a quite inefficient trick called the "MAX-CONCAT
  12798. trick":
  12799.  
  12800.      SELECT article,
  12801.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  12802.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  12803.      FROM   shop
  12804.      GROUP BY article;
  12805.      
  12806.      +---------+--------+-------+
  12807.      | article | dealer | price |
  12808.      +---------+--------+-------+
  12809.      |    0001 | B      |  3.99 |
  12810.      |    0002 | A      | 10.99 |
  12811.      |    0003 | C      |  1.69 |
  12812.      |    0004 | D      | 19.95 |
  12813.      +---------+--------+-------+
  12814.  
  12815. The last example can, of course, be made a bit more efficient by doing
  12816. the splitting of the concatenated column in the client.
  12817.  
  12818. Using User Variables
  12819. --------------------
  12820.  
  12821. You can use MySQL user variables to remember results without having to
  12822. store them in temporary variables in the client.  *Note Variables::.
  12823.  
  12824. For example, to find the articles with the highest and lowest price you
  12825. can do this:
  12826.  
  12827.      mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
  12828.      mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
  12829.      +---------+--------+-------+
  12830.      | article | dealer | price |
  12831.      +---------+--------+-------+
  12832.      |    0003 | D      |  1.25 |
  12833.      |    0004 | D      | 19.95 |
  12834.      +---------+--------+-------+
  12835.  
  12836. Using Foreign Keys
  12837. ------------------
  12838.  
  12839. In MySQL 3.23.44 and up, `InnoDB' tables support checking of foreign
  12840. key constraints. *Note `InnoDB': InnoDB.  See also *Note ANSI diff
  12841. Foreign Keys::.
  12842.  
  12843. You don't actually need foreign keys to join 2 tables.  For table types
  12844. other than `InnoDB'), the only things MySQL currently doesn't do are 1)
  12845. `CHECK' to make sure that the keys you use really exist in the table(s)
  12846. you're referencing and 2) automatically delete rows from a table with a
  12847. foreign key definition. Using your keys to join tables will work just
  12848. fine:
  12849.  
  12850.      CREATE TABLE person (
  12851.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  12852.          name CHAR(60) NOT NULL,
  12853.          PRIMARY KEY (id)
  12854.      );
  12855.      
  12856.      CREATE TABLE shirt (
  12857.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  12858.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  12859.          colour ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  12860.          owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),
  12861.          PRIMARY KEY (id)
  12862.      );
  12863.      
  12864.      
  12865.      INSERT INTO person VALUES (NULL, 'Antonio Paz');
  12866.      
  12867.      INSERT INTO shirt VALUES
  12868.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  12869.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  12870.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  12871.      
  12872.      
  12873.      INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
  12874.      
  12875.      INSERT INTO shirt VALUES
  12876.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  12877.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  12878.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  12879.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  12880.      
  12881.      
  12882.      SELECT * FROM person;
  12883.      +----+---------------------+
  12884.      | id | name                |
  12885.      +----+---------------------+
  12886.      |  1 | Antonio Paz         |
  12887.      |  2 | Lilliana Angelovska |
  12888.      +----+---------------------+
  12889.      
  12890.      SELECT * FROM shirt;
  12891.      +----+---------+--------+-------+
  12892.      | id | style   | colour | owner |
  12893.      +----+---------+--------+-------+
  12894.      |  1 | polo    | blue   |     1 |
  12895.      |  2 | dress   | white  |     1 |
  12896.      |  3 | t-shirt | blue   |     1 |
  12897.      |  4 | dress   | orange |     2 |
  12898.      |  5 | polo    | red    |     2 |
  12899.      |  6 | dress   | blue   |     2 |
  12900.      |  7 | t-shirt | white  |     2 |
  12901.      +----+---------+--------+-------+
  12902.      
  12903.      
  12904.      SELECT s.* FROM person p, shirt s
  12905.       WHERE p.name LIKE 'Lilliana%'
  12906.         AND s.owner = p.id
  12907.         AND s.colour <> 'white';
  12908.      
  12909.      +----+-------+--------+-------+
  12910.      | id | style | colour | owner |
  12911.      +----+-------+--------+-------+
  12912.      |  4 | dress | orange |     2 |
  12913.      |  5 | polo  | red    |     2 |
  12914.      |  6 | dress | blue   |     2 |
  12915.      +----+-------+--------+-------+
  12916.  
  12917. Searching on Two Keys
  12918. ---------------------
  12919.  
  12920. MySQL doesn't yet optimise when you search on two different keys
  12921. combined with `OR' (searching on one key with different `OR' parts is
  12922. optimised quite well):
  12923.  
  12924.      SELECT field1_index, field2_index FROM test_table
  12925.      WHERE field1_index = '1' OR  field2_index = '1'
  12926.  
  12927. The reason is that we haven't yet had time to come up with an efficient
  12928. way to handle this in the general case. (The `AND' handling is, in
  12929. comparison, now completely general and works very well.)
  12930.  
  12931. In MySQL 4.0 and up, you can solve this problem efficiently by using a
  12932. `UNION' that combines the output of two separate `SELECT' statements.
  12933. *Note UNION::.  Each `SELECT' searches only one key and can be
  12934. optimised:
  12935.  
  12936.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
  12937.      UNION
  12938.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  12939.  
  12940. Prior to MySQL 4.0, you can achieve the same effect by using a
  12941. `TEMPORARY' table and separate `SELECT' statements.  This type of
  12942. optimisation is also very good if you are using very complicated
  12943. queries where the SQL server does the optimisations in the wrong order.
  12944.  
  12945.      CREATE TEMPORARY TABLE tmp
  12946.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
  12947.      INSERT INTO tmp
  12948.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  12949.      SELECT * from tmp;
  12950.      DROP TABLE tmp;
  12951.  
  12952. The above way to solve this query is in effect a `UNION' of two queries.
  12953.  
  12954. Calculating Visits Per Day
  12955. --------------------------
  12956.  
  12957. The following example shows how you can use the bit group functions to
  12958. calculate the number of days per month a user has visited a web page.
  12959.  
  12960.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL,
  12961.                   day INT(2) UNSIGNED ZEROFILL);
  12962.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),
  12963.                  (2000,2,23),(2000,2,23);
  12964.  
  12965. The example table contains year-month-day values representing visits by
  12966. users to the page. To determine how many different days in each month
  12967. these visits occur, use this query:
  12968.  
  12969.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
  12970.             GROUP BY year,month;
  12971.  
  12972. Which returns:
  12973.  
  12974.      +------+-------+------+
  12975.      | year | month | days |
  12976.      +------+-------+------+
  12977.      | 2000 |    01 |    3 |
  12978.      | 2000 |    02 |    2 |
  12979.      +------+-------+------+
  12980.  
  12981. The query calculates how many different days appear in the table for
  12982. each year/month combination, with automatic removal of duplicate
  12983. entries.
  12984.  
  12985. Using `AUTO_INCREMENT'
  12986. ----------------------
  12987.  
  12988. The `AUTO_INCREMENT' attribute can be used to generate a unique
  12989. identity for new rows:
  12990.  
  12991.      CREATE TABLE animals (
  12992.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  12993.                   name CHAR(30) NOT NULL,
  12994.                   PRIMARY KEY (id)
  12995.                   );
  12996.      INSERT INTO animals (name) VALUES ("dog"),("cat"),("penguin"),
  12997.                                        ("lax"),("whale"),("ostrich");
  12998.      SELECT * FROM animals;
  12999.  
  13000. Which returns:
  13001.  
  13002.      +----+---------+
  13003.      | id | name    |
  13004.      +----+---------+
  13005.      |  1 | dog     |
  13006.      |  2 | cat     |
  13007.      |  3 | penguin |
  13008.      |  4 | lax     |
  13009.      |  5 | whale   |
  13010.      |  6 | ostrich |
  13011.      +----+---------+
  13012.  
  13013. You can retrieve the most recent `AUTO_INCREMENT' value with the
  13014. `LAST_INSERT_ID()' SQL function or the `mysql_insert_id()' C API
  13015. function.  Note: For a multiple-row insert,
  13016. `LAST_INSERT_ID()'/`mysql_insert_id()' will actually return the
  13017. `AUTO_INCREMENT' key from the *first* of the inserted rows.  This
  13018. allows multiple-row inserts to be reproduced correctly on other servers
  13019. in a replication setup.
  13020.  
  13021. For `MyISAM' and `BDB' tables you can specify `AUTO_INCREMENT' on a
  13022. secondary column in a multiple-column index.  In this case, the
  13023. generated value for the `AUTO_INCREMENT' column is calculated as
  13024. `MAX(auto_increment_column)+1) WHERE prefix=given-prefix'.  This is
  13025. useful when you want to put data into ordered groups.
  13026.  
  13027.      CREATE TABLE animals (
  13028.                   grp ENUM('fish','mammal','bird') NOT NULL,
  13029.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13030.                   name CHAR(30) NOT NULL,
  13031.                   PRIMARY KEY (grp,id)
  13032.                   );
  13033.      INSERT INTO animals (grp,name) VALUES("mammal","dog"),("mammal","cat"),
  13034.                        ("bird","penguin"),("fish","lax"),("mammal","whale"),
  13035.                        ("bird","ostrich");
  13036.      SELECT * FROM animals ORDER BY grp,id;
  13037.  
  13038. Which returns:
  13039.  
  13040.      +--------+----+---------+
  13041.      | grp    | id | name    |
  13042.      +--------+----+---------+
  13043.      | fish   |  1 | lax     |
  13044.      | mammal |  1 | dog     |
  13045.      | mammal |  2 | cat     |
  13046.      | mammal |  3 | whale   |
  13047.      | bird   |  1 | penguin |
  13048.      | bird   |  2 | ostrich |
  13049.      +--------+----+---------+
  13050.  
  13051. Note that in this case (when the `AUTO_INCREMENT' column is part of a
  13052. multiple-column index), `AUTO_INCREMENT' values will be reused if you
  13053. delete the row with the biggest `AUTO_INCREMENT' value in any group.
  13054. This happens even for `MyISAM' tables, for which `AUTO_INCREMENT'
  13055. values normally are not reused.)
  13056.  
  13057. Queries from the Twin Project
  13058. =============================
  13059.  
  13060. At Analytikerna and Lentus, we have been doing the systems and field
  13061. work for a big research project. This project is a collaboration
  13062. between the Institute of Environmental Medicine at Karolinska
  13063. Institutet Stockholm and the Section on Clinical Research in Aging and
  13064. Psychology at the University of Southern California.
  13065.  
  13066. The project involves a screening part where all twins in Sweden older
  13067. than 65 years are interviewed by telephone. Twins who meet certain
  13068. criteria are passed on to the next stage. In this latter stage, twins
  13069. who want to participate are visited by a doctor/nurse team. Some of the
  13070. examinations include physical and neuropsychological examination,
  13071. laboratory testing, neuroimaging, psychological status assessment, and
  13072. family history collection. In addition, data are collected on medical
  13073. and environmental risk factors.
  13074.  
  13075. More information about Twin studies can be found at:
  13076. `http://www.mep.ki.se/twinreg/index_en.html'
  13077.  
  13078. The latter part of the project is administered with a web interface
  13079. written using Perl and MySQL.
  13080.  
  13081. Each night all data from the interviews is moved into a MySQL database.
  13082.  
  13083. Find All Non-distributed Twins
  13084. ------------------------------
  13085.  
  13086. The following query is used to determine who goes into the second part
  13087. of the project:
  13088.  
  13089.      SELECT
  13090.              CONCAT(p1.id, p1.tvab) + 0 AS tvid,
  13091.              CONCAT(p1.christian_name, " ", p1.surname) AS Name,
  13092.              p1.postal_code AS Code,
  13093.              p1.city AS City,
  13094.              pg.abrev AS Area,
  13095.              IF(td.participation = "Aborted", "A", " ") AS A,
  13096.              p1.dead AS dead1,
  13097.              l.event AS event1,
  13098.              td.suspect AS tsuspect1,
  13099.              id.suspect AS isuspect1,
  13100.              td.severe AS tsevere1,
  13101.              id.severe AS isevere1,
  13102.              p2.dead AS dead2,
  13103.              l2.event AS event2,
  13104.              h2.nurse AS nurse2,
  13105.              h2.doctor AS doctor2,
  13106.              td2.suspect AS tsuspect2,
  13107.              id2.suspect AS isuspect2,
  13108.              td2.severe AS tsevere2,
  13109.              id2.severe AS isevere2,
  13110.              l.finish_date
  13111.      FROM
  13112.              twin_project AS tp
  13113.              /* For Twin 1 */
  13114.              LEFT JOIN twin_data AS td ON tp.id = td.id
  13115.                        AND tp.tvab = td.tvab
  13116.              LEFT JOIN informant_data AS id ON tp.id = id.id
  13117.                        AND tp.tvab = id.tvab
  13118.              LEFT JOIN harmony AS h ON tp.id = h.id
  13119.                        AND tp.tvab = h.tvab
  13120.              LEFT JOIN lentus AS l ON tp.id = l.id
  13121.                        AND tp.tvab = l.tvab
  13122.              /* For Twin 2 */
  13123.              LEFT JOIN twin_data AS td2 ON p2.id = td2.id
  13124.                        AND p2.tvab = td2.tvab
  13125.              LEFT JOIN informant_data AS id2 ON p2.id = id2.id
  13126.                        AND p2.tvab = id2.tvab
  13127.              LEFT JOIN harmony AS h2 ON p2.id = h2.id
  13128.                        AND p2.tvab = h2.tvab
  13129.              LEFT JOIN lentus AS l2 ON p2.id = l2.id
  13130.                        AND p2.tvab = l2.tvab,
  13131.              person_data AS p1,
  13132.              person_data AS p2,
  13133.              postal_groups AS pg
  13134.      WHERE
  13135.              /* p1 gets main twin and p2 gets his/her twin. */
  13136.              /* ptvab is a field inverted from tvab */
  13137.              p1.id = tp.id AND p1.tvab = tp.tvab AND
  13138.              p2.id = p1.id AND p2.ptvab = p1.tvab AND
  13139.              /* Just the sceening survey */
  13140.              tp.survey_no = 5 AND
  13141.              /* Skip if partner died before 65 but allow emigration (dead=9) */
  13142.              (p2.dead = 0 OR p2.dead = 9 OR
  13143.               (p2.dead = 1 AND
  13144.                (p2.death_date = 0 OR
  13145.                 (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
  13146.                  >= 65))))
  13147.              AND
  13148.              (
  13149.              /* Twin is suspect */
  13150.              (td.future_contact = 'Yes' AND td.suspect = 2) OR
  13151.              /* Twin is suspect - Informant is Blessed */
  13152.              (td.future_contact = 'Yes' AND td.suspect = 1
  13153.                                         AND id.suspect = 1) OR
  13154.              /* No twin - Informant is Blessed */
  13155.              (ISNULL(td.suspect) AND id.suspect = 1
  13156.                                  AND id.future_contact = 'Yes') OR
  13157.              /* Twin broken off - Informant is Blessed */
  13158.              (td.participation = 'Aborted'
  13159.               AND id.suspect = 1 AND id.future_contact = 'Yes') OR
  13160.              /* Twin broken off - No inform - Have partner */
  13161.              (td.participation = 'Aborted' AND ISNULL(id.suspect)
  13162.                                            AND p2.dead = 0))
  13163.              AND
  13164.              l.event = 'Finished'
  13165.              /* Get at area code */
  13166.              AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
  13167.              /* Not already distributed */
  13168.              AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
  13169.              /* Has not refused or been aborted */
  13170.              AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
  13171.              OR h.status = 'Died' OR h.status = 'Other')
  13172.      ORDER BY
  13173.              tvid;
  13174.  
  13175. Some explanations:
  13176. `CONCAT(p1.id, p1.tvab) + 0 AS tvid'
  13177.      We want to sort on the concatenated `id' and `tvab' in numerical
  13178.      order. Adding `0' to the result causes MySQL to treat the result
  13179.      as a number.
  13180.  
  13181. column `id'
  13182.      This identifies a pair of twins. It is a key in all tables.
  13183.  
  13184. column `tvab'
  13185.      This identifies a twin in a pair. It has a value of `1' or `2'.
  13186.  
  13187. column `ptvab'
  13188.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  13189.      vice versa. It exists to save typing and to make it easier for
  13190.      MySQL to optimise the query.
  13191.  
  13192. This query demonstrates, among other things, how to do lookups on a
  13193. table from the same table with a join (`p1' and `p2'). In the example,
  13194. this is used to check whether a twin's partner died before the age of
  13195. 65. If so, the row is not returned.
  13196.  
  13197. All of the above exist in all tables with twin-related information. We
  13198. have a key on both `id,tvab' (all tables), and `id,ptvab'
  13199. (`person_data') to make queries faster.
  13200.  
  13201. On our production machine (A 200MHz UltraSPARC), this query returns
  13202. about 150-200 rows and takes less than one second.
  13203.  
  13204. The current number of records in the tables used above:
  13205. *Table*            *Rows*
  13206. `person_data'      71074
  13207. `lentus'           5291
  13208. `twin_project'     5286
  13209. `twin_data'        2012
  13210. `informant_data'   663
  13211. `harmony'          381
  13212. `postal_groups'    100
  13213.  
  13214. Show a Table of Twin Pair Status
  13215. --------------------------------
  13216.  
  13217. Each interview ends with a status code called `event'. The query shown
  13218. here is used to display a table over all twin pairs combined by event.
  13219. This indicates in how many pairs both twins are finished, in how many
  13220. pairs one twin is finished and the other refused, and so on.
  13221.  
  13222.      SELECT
  13223.              t1.event,
  13224.              t2.event,
  13225.              COUNT(*)
  13226.      FROM
  13227.              lentus AS t1,
  13228.              lentus AS t2,
  13229.              twin_project AS tp
  13230.      WHERE
  13231.              /* We are looking at one pair at a time */
  13232.              t1.id = tp.id
  13233.              AND t1.tvab=tp.tvab
  13234.              AND t1.id = t2.id
  13235.              /* Just the sceening survey */
  13236.              AND tp.survey_no = 5
  13237.              /* This makes each pair only appear once */
  13238.              AND t1.tvab='1' AND t2.tvab='2'
  13239.      GROUP BY
  13240.              t1.event, t2.event;
  13241.  
  13242. Using MySQL with Apache
  13243. =======================
  13244.  
  13245. There are programs that let you authenticate your users from a MySQL
  13246. database and also let you write your log files into a MySQL table.
  13247.  
  13248. You can change the Apache logging format to be easily readable by MySQL
  13249. by putting the following into the Apache configuration file:
  13250.  
  13251.      LogFormat \
  13252.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  13253.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  13254.  
  13255. To load a log file in that format into MySQL, you can use a statement
  13256. something like this:
  13257.  
  13258.      LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
  13259.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  13260.  
  13261. The named table should be created to have columns that correspond to
  13262. those that the `LogFormat' line writes to the log file.
  13263.  
  13264. Database Administration
  13265. ***********************
  13266.  
  13267. Configuring MySQL
  13268. =================
  13269.  
  13270. `mysqld' Command-line Options
  13271. -----------------------------
  13272.  
  13273. In most cases you should manage `mysqld' options through option files.
  13274. *Note Option files::.
  13275.  
  13276. `mysqld' and `mysqld.server' read options from the `mysqld' and
  13277. `server' groups. `mysqld_safe' read options from the `mysqld',
  13278. `server', `mysqld_safe' and `safe_mysqld' groups.  An embedded MySQL
  13279. server usually reads options from the `server', `embedded' and
  13280. `xxxxx_SERVER', where `xxxxx' is the name of the application.
  13281.  
  13282. `mysqld' accepts a lot of command-line options. Here follows some of
  13283. the most common ones. For a full list execute `mysqld --help'.  Options
  13284. used for replication are listed in a separate section, see *Note
  13285. Replication Options::.
  13286.  
  13287. `--ansi'
  13288.      Use SQL-99 syntax instead of MySQL syntax.  *Note ANSI mode::.
  13289.  
  13290. `-b, --basedir=path'
  13291.      Path to installation directory. All paths are usually resolved
  13292.      relative to this.
  13293.  
  13294. `--big-tables'
  13295.      Allow big result sets by saving all temporary sets on file.  It
  13296.      solves most 'table full' errors, but also slows down the queries
  13297.      where in-memory tables would suffice.  Since Version 3.23.2, MySQL
  13298.      is able to solve it automatically by using memory for small
  13299.      temporary tables and switching to disk tables where necessary.
  13300.  
  13301. `--bind-address=IP'
  13302.      IP address to bind to.
  13303.  
  13304. `--console'
  13305.      Write the error log messages to stderr/stdout even if `--log-error'
  13306.      is specified.  On Windows, `mysqld' will not close the console
  13307.      screen if this option is used.
  13308.  
  13309. `--character-sets-dir=path'
  13310.      Directory where character sets are.  *Note Character sets::.
  13311.  
  13312. `--chroot=path'
  13313.      Put `mysqld' daemon in chroot environment at startup. Recommended
  13314.      security measure since MySQL 4.0 (MySQL 3.23 is not able to provide
  13315.      100% closed chroot jail).  It somewhat limits `LOAD DATA INFILE'
  13316.      and `SELECT ... INTO OUTFILE' though.
  13317.  
  13318. `--core-file'
  13319.      Write a core file if `mysqld' dies.  For some systems you must also
  13320.      specify `--core-file-size' to `mysqld_safe'.  *Note `mysqld_safe':
  13321.      mysqld_safe.  Note that on some systems, like Solaris, you will
  13322.      not get a core file if you are also using the `--user' option.
  13323.  
  13324. `-h, --datadir=path'
  13325.      Path to the database root.
  13326.  
  13327. `--debug[...]='
  13328.      If MySQL is configured with `--with-debug', you can use this
  13329.      option to get a trace file of what `mysqld' is doing.  *Note
  13330.      Making trace files::.
  13331.  
  13332. `--default-character-set=charset'
  13333.      Set the default character set.  *Note Character sets::.
  13334.  
  13335. `--default-table-type=type'
  13336.      Set the default table type for tables.  *Note Table types::.
  13337.  
  13338. `--delay-key-write[= OFF | ON | ALL]'
  13339.      How MyISAM `DELAYED KEYS' should be used. *Note Server
  13340.      parameters::.
  13341.  
  13342. `--delay-key-write-for-all-tables;  In MySQL 4.0.3 you should use --delay-key-write=ALL instead.'
  13343.      Don't flush key buffers between writes for any `MyISAM' table.
  13344.      *Note Server parameters::.
  13345.  
  13346. `--des-key-file=filename'
  13347.      Read the default keys used by `DES_ENCRYPT()' and `DES_DECRYPT()'
  13348.      from this file.
  13349.  
  13350. `--enable-external-locking (was --enable-locking)'
  13351.      Enable system locking.  Note that if you use this option on a
  13352.      system on which `lockd' does not fully work (as on Linux), you
  13353.      will easily get mysqld to deadlock.
  13354.  
  13355. `--enable-named-pipe'
  13356.      Enable support for named pipes (only on NT/Win2000/XP).
  13357.  
  13358. `-T, --exit-info'
  13359.      This is a bit mask of different flags one can use for debugging the
  13360.      mysqld server; one should not use this option if one doesn't know
  13361.      exactly what it does!
  13362.  
  13363. `--flush'
  13364.      Flush all changes to disk after each SQL command.  Normally MySQL
  13365.      only does a write of all changes to disk after each SQL command
  13366.      and lets the operating system handle the syncing to disk.  *Note
  13367.      Crashing::.
  13368.  
  13369. `-?, --help'
  13370.      Display short help and exit.
  13371.  
  13372. `--init-file=file'
  13373.      Read SQL commands from this file at startup.
  13374.  
  13375. `-L, --language=...'
  13376.      Client error messages in given language.  May be given as a full
  13377.      path.  *Note Languages::.
  13378.  
  13379. `-l, --log[=file]'
  13380.      Log connections and queries to file. *Note Query log::.
  13381.  
  13382. `--log-bin=[file]'
  13383.      Log all queries that change data to the file. Used for backup and
  13384.      replication.  *Note Binary log::.
  13385.  
  13386. `--log-bin-index[=file]'
  13387.      Index file for binary log file names. *Note Binary log::.
  13388.  
  13389. `--log-error[=file]'
  13390.      Log errors and startup messages to this file. *Note Error log::.
  13391.  
  13392. `--log-isam[=file]'
  13393.      Log all ISAM/MyISAM changes to file (only used when debugging
  13394.      ISAM/MyISAM).
  13395.  
  13396. `--log-slow-queries[=file]'
  13397.      Log all queries that have taken more than `long_query_time'
  13398.      seconds to execute to file.  *Note Slow query log::.
  13399.  
  13400. `--log-update[=file]'
  13401.      Log updates to `file.#' where `#' is a unique number if not given.
  13402.      *Note Update log::. The update log is deprecated and will be
  13403.      removed in MySQL 5.0; you should use the binary log instead
  13404.      (`--log-bin'). *Note Binary log::. Starting from version 5.0,
  13405.      using `--log-update' will just turn on the binlog instead.
  13406.  
  13407. `--log-long-format'
  13408.      Log some extra information to the update log.  If you are using
  13409.      `--log-slow-queries' then queries that are not using indexes are
  13410.      logged to the slow query log.
  13411.  
  13412. `--low-priority-updates'
  13413.      Table-modifying operations (`INSERT'/`DELETE'/`UPDATE') will have
  13414.      lower priority than selects.  It can also be done via `{INSERT |
  13415.      REPLACE | UPDATE | DELETE} LOW_PRIORITY ...' to lower the priority
  13416.      of only one query, or by `SET LOW_PRIORITY_UPDATES=1' to change
  13417.      the priority in one thread.  *Note Table locking::.
  13418.  
  13419. `--memlock'
  13420.      Lock the `mysqld' process in memory.  This works only if your
  13421.      system supports the `mlockall()' system call (like Solaris).  This
  13422.      may help if you have a problem where the operating system is
  13423.      causing `mysqld' to swap on disk.  Note that use of this option
  13424.      requires that you run the server as `root', which is normally not
  13425.      a good idea for security reasons.
  13426.  
  13427. `--myisam-recover [=option[,option...]]]'
  13428.      Option is any combination of `DEFAULT', `BACKUP', `FORCE' or
  13429.      `QUICK'.  You can also set this explicitly to `""' if you want to
  13430.      disable this option. If this option is used, `mysqld' will on open
  13431.      check if the table is marked as crashed or if the table wasn't
  13432.      closed properly.  (The last option only works if you are running
  13433.      with `--skip-external-locking'.)  If this is the case `mysqld'
  13434.      will run check on the table. If the table was corrupted, `mysqld'
  13435.      will attempt to repair it.
  13436.  
  13437.      The following options affects how the repair works.
  13438.  
  13439.      *Option*   *Description*
  13440.      DEFAULT    The same as not giving any option to
  13441.                          `--myisam-recover'.
  13442.      BACKUP     If the data table was changed during recover,
  13443.                 save a                     backup of the
  13444.                 `table_name.MYD' datafile as
  13445.                  `table_name-datetime.BAK'.
  13446.      FORCE      Run recover even if we will lose more than one
  13447.                 row                     from the .MYD file.
  13448.      QUICK      Don't check the rows in the table if there
  13449.                 aren't any                     delete blocks.
  13450.  
  13451.      Before a table is automatically repaired, MySQL will add a note
  13452.      about this in the error log.  If you want to be able to recover
  13453.      from most things without user intervention, you should use the
  13454.      options `BACKUP,FORCE'.  This will force a repair of a table even
  13455.      if some rows would be deleted, but it will keep the old datafile
  13456.      as a backup so that you can later examine what happened.
  13457.  
  13458. `--new'
  13459.      From version 4.0.12, the `--new' option can be used to make the
  13460.      server behave as 4.1 in certain aspects, easing a 4.0 to 4.1
  13461.      upgrade:
  13462.         * `TIMESTAMP' is returned as a string with the format
  13463.           `'YYYY-MM-DD HH:MM:SS''.  *Note Column types::.
  13464.  
  13465. `--pid-file=path'
  13466.      Path to pid file used by `mysqld_safe'.
  13467.  
  13468. `-P, --port=...'
  13469.      Port number to listen for TCP/IP connections.
  13470.  
  13471. `-o, --old-protocol'
  13472.      Use the 3.20 protocol for compatibility with some very old clients.
  13473.      *Note Upgrading-from-3.20::.
  13474.  
  13475. `--one-thread'
  13476.      Only use one thread (for debugging under Linux).  *Note Debugging
  13477.      server::.
  13478.  
  13479. `--open-files-limit='
  13480.      To change the number of file descriptors available to `mysqld'.
  13481.      If this is not set or set to 0, then `mysqld' will use this value
  13482.      to reserve file descriptors to use with `setrlimit()'.  If this
  13483.      value is 0 then `mysqld' will reserve `max_connections*5' or
  13484.      `max_connections + table_cache*2' (whichever is larger) number of
  13485.      files.  You should try increasing this if `mysqld' gives you the
  13486.      error 'Too many open files'.
  13487.  
  13488. `-O, --set-variable var=option'
  13489.      Give a variable a value. `--help' lists variables.  You can find a
  13490.      full description for all variables in the `SHOW VARIABLES' section
  13491.      in this manual.  *Note SHOW VARIABLES::.  The tuning server
  13492.      parameters section includes information of how to optimise these.
  13493.      Please note that `--set-variable' is deprecated since MySQL 4.0,
  13494.      just use `--var=option' on its own.  *Note Server parameters::.
  13495.  
  13496.      In MySQL 4.0.2 one can set a variable directly with
  13497.      `--variable-name=option' and `set-variable' is no longer needed in
  13498.      option files.
  13499.  
  13500.      If you want to restrict the maximum value a startup option can be
  13501.      set to with `SET', you can define this by using the
  13502.      `--maximum-variable-name' command line option. *Note SET OPTION::.
  13503.  
  13504.      Note that when setting a variable to a value, MySQL may
  13505.      automatically correct it to stay within a given range and also
  13506.      adjusts the value a little to fix for the used algorithm.
  13507.  
  13508. `--safe-mode'
  13509.      Skip some optimise stages.
  13510.  
  13511. `--safe-show-database'
  13512.      With this option, the `SHOW DATABASES' command returns only those
  13513.      databases for which the user has some kind of privilege.  From
  13514.      version 4.0.2 this option is deprecated and doesn't do anything
  13515.      (the option is enabled by default) as we now have the `SHOW
  13516.      DATABASES' privilege. *Note GRANT::.
  13517.  
  13518. `--safe-user-create'
  13519.      If this is enabled, a user can't create new users with the GRANT
  13520.      command, if the user doesn't have `INSERT' privilege to the
  13521.      `mysql.user' table or any column in this table.
  13522.  
  13523. `--skip-bdb'
  13524.      Disable usage of BDB tables. This will save memory and may speed
  13525.      up some things.
  13526.  
  13527. `--skip-concurrent-insert'
  13528.      Turn off the ability to select and insert at the same time on
  13529.      `MyISAM' tables. (This is only to be used if you think you have
  13530.      found a bug in this feature.)
  13531.  
  13532. `--skip-delay-key-write'
  13533.      In MySQL 4.0.3 you should use -delay-key-write=OFF instead.
  13534.      Ignore the `DELAY_KEY_WRITE' option for all tables.  *Note Server
  13535.      parameters::.
  13536.  
  13537. `--skip-grant-tables'
  13538.      This option causes the server not to use the privilege system at
  13539.      all.  This gives everyone *full access* to all databases!  (You
  13540.      can tell a running server to start using the grant tables again by
  13541.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  13542.  
  13543. `--skip-host-cache'
  13544.      Never use host name cache for faster name-ip resolution, but query
  13545.      DNS server on every connect instead.  *Note DNS::.
  13546.  
  13547. `--skip-innodb'
  13548.      Disable usage of Innodb tables.  This will save memory and disk
  13549.      space and speed up some things.
  13550.  
  13551. `--skip-external-locking (was --skip-locking)'
  13552.      Don't use system locking.  To use `isamchk' or `myisamchk' you must
  13553.      shut down the server.  *Note Stability::.  Note that in MySQL
  13554.      Version 3.23 you can use `REPAIR' and `CHECK' to repair/check
  13555.      `MyISAM' tables.
  13556.  
  13557. `--skip-name-resolve'
  13558.      Hostnames are not resolved.  All `Host' column values in the grant
  13559.      tables must be IP numbers or `localhost'.  *Note DNS::.
  13560.  
  13561. `--skip-networking'
  13562.      Don't listen for TCP/IP connections at all.  All interaction with
  13563.      `mysqld' must be made via named pipes or Unix sockets.  This
  13564.      option is highly recommended for systems where only local requests
  13565.      are allowed.  *Note DNS::.
  13566.  
  13567. `--skip-new'
  13568.      Don't use new, possibly wrong routines.
  13569.  
  13570. `--skip-symlink'
  13571.      Deprecated option in 4.0.13;  use `--skip-symbolic-links' instead.
  13572.  
  13573. `--symbolic-links, --skip-symbolic-links'
  13574.      Enable or disable symbolic link support. This option has different
  13575.      effects on Windows and Unix.
  13576.  
  13577.      On Windows, enabling symbolic links allows you to establish a
  13578.      symbolic link to a database directory by creating a
  13579.      `directory.sym' file that contains the path to the real directory.
  13580.      *Note Windows symbolic links::.
  13581.  
  13582.      On Unix, enabling symbolic links means that you can link a
  13583.      `MyISAM' index file or datafile to another directory with the
  13584.      `INDEX DIRECTORY' or `DATA DIRECTORY' options of the `CREATE
  13585.      TABLE' statement.  If you delete or rename the table, the files
  13586.      that its symbolic links point to also will be deleted or renamed.
  13587.  
  13588. `--skip-safemalloc'
  13589.      If MySQL is configured with `--with-debug=full', all programs
  13590.      check memory for overruns for every memory allocation and memory
  13591.      freeing operations.  This checking is very slow, so for the server
  13592.      you can avoid it when you don't need it by using the
  13593.      `--skip-safemalloc' option.
  13594.  
  13595. `--skip-show-database'
  13596.      Don't allow the `SHOW DATABASES' command, unless the user has the
  13597.      `SHOW DATABASES' privilege.
  13598.  
  13599. `--skip-stack-trace'
  13600.      Don't write stack traces.  This option is useful when you are
  13601.      running `mysqld' under a debugger. On some systems, you also must
  13602.      use this option to get a core file. *Note Debugging server::.
  13603.  
  13604. `--skip-thread-priority'
  13605.      Disable using thread priorities for faster response time.
  13606.  
  13607. `--socket=path'
  13608.      On Unix, the socket file to use for local connections (default
  13609.      `/tmp/mysql.sock').  On Windows, the pipe name to use for local
  13610.      connections that use a named pipe (default `MySql').
  13611.  
  13612. `--sql-mode=value[,value[,value...]]'
  13613.      The option values can be any combination of: `REAL_AS_FLOAT',
  13614.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  13615.      `ONLY_FULL_GROUP_BY', `NO_UNSIGNED_SUBTRACTION',
  13616.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', `NO_KEY_OPTIONS',
  13617.      `NO_DIR_IN_CREATE', `MYSQL323', `MYSQL40', `DB2', `MSSQL',
  13618.      `ORACLE', `POSTGRESQL', `SAPDB', or `ANSI'.  The value also can be
  13619.      empty (`--sql-mode=""') if you want to reset it.
  13620.  
  13621.      Several of the option values are used for compatibility with other
  13622.      servers.  If specified, they cause the server to omit from the
  13623.      output of `SHOW CREATE TABLE' those parts of the statement that
  13624.      are not understood by earlier versions of MySQL or other database
  13625.      servers.  Using these option values results in `CREATE TABLE'
  13626.      statements that are more portable for use with other servers:
  13627.  
  13628.         * The `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS',
  13629.           `NO_DIR_IN_CREATE', and `NO_KEY_OPTIONS' values cause
  13630.           omission of table options, or options pertaining to column or
  13631.           index definitions.
  13632.  
  13633.         * The values `MYSQL323' and `MYSQL40' are for compatibility with
  13634.           MySQL 3.23 and MySQL 4.0.
  13635.  
  13636.         * The values used for compatibility with other servers are
  13637.           `DB2', `MSSQL', `ORACLE', `POSTGRESQL', and `SAPDB'.
  13638.  
  13639.  
  13640.      These options also affect the output of `mysqldump', because that
  13641.      program uses `SHOW CREATE TABLE' to obtain the table-creation
  13642.      statements that it includes in its own output.
  13643.  
  13644.      Several of the option values have a complex effect because they
  13645.      are shorthand for a group or set of values.  For example, you can
  13646.      tell the server to run in ANSI mode by using the `--sql-mode=ANSI'
  13647.      (or `--ansi') option, which is equivalent to specifying both of
  13648.      the following command-line options:
  13649.  
  13650.           --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  13651.           --transaction-isolation=SERIALIZABLE
  13652.  
  13653.      Note that specifying ANSI mode in this way also has the effect of
  13654.      setting the transaction isolation level.  For more information
  13655.      about running the server in ANSI mode, see *Note ANSI mode::.
  13656.  
  13657.      Other "group" values are `DB2', `MSSQL', `ORACLE', `POSTGRESQL',
  13658.      and `SAPDB'.  Specifying any of them turns on the
  13659.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  13660.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', and `NO_KEY_OPTIONS'
  13661.      values.
  13662.  
  13663.      The `--sql-mode' option was added in MySQL 3.23.41. The
  13664.      `NO_UNSIGNED_SUBTRACTION' value was added in 4.0.0. The
  13665.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', `NO_KEY_OPTIONS',
  13666.      `MYSQL323', `MYSQL40', `DB2', `MSSQL', `ORACLE', `POSTGRESQL',
  13667.      `SAPDB', and values were added in 4.1.1.  `ANSI' was added in
  13668.      4.1.1.
  13669.  
  13670. `--temp-pool'
  13671.      Using this option will cause most temporary files created by the
  13672.      server to use a small set of names, rather than a unique name for
  13673.      each new file. This is to work around a problem in the Linux kernel
  13674.      dealing with creating many new files with different names. With
  13675.      the old behaviour, Linux seems to "leak" memory, as it's being
  13676.      allocated to the directory entry cache rather than to the disk
  13677.      cache.
  13678.  
  13679. `--transaction-isolation={ READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE }'
  13680.      Sets the default transaction isolation level.  *Note `SET
  13681.      TRANSACTION': SET TRANSACTION.
  13682.  
  13683. `-t, --tmpdir=path'
  13684.      Path of the directory to use for creating temporary files. It may
  13685.      be useful if your default `/tmp' directory resides on a partition
  13686.      that is too small to hold temporary tables.  Starting from MySQL
  13687.      4.1, this option accepts several paths that are used in
  13688.      round-robin fashion. Paths should be separated by colon characters
  13689.      (`:') on Unix and semicolon characters (`;') on Windows.
  13690.  
  13691. `-u, --user={user_name | user_id}'
  13692.      Run the `mysqld' server as the user having the name `user_name' or
  13693.      numeric user ID `user_id'.  ("User" in this context refers to a
  13694.      system login account, not a MySQL user listed in the grant tables.)
  13695.  
  13696.      This option is *mandatory* when starting `mysqld' as `root'.  The
  13697.      server will change its user ID during its startup sequence,
  13698.      causing it to run as that particular user rather than as `root'.
  13699.      *Note Security::.
  13700.  
  13701.      Starting from MySQL 3.23.56 and 4.0.12: To avoid a possible
  13702.      security hole where a user adds a `--user=root' option to some
  13703.      `my.cnf' file (thus causing the server to run as `root'), `mysqld'
  13704.      uses only the first `--user' option specified and produces a
  13705.      warning if there are multiple `--user' options. Options in
  13706.      `/etc/my.cnf' and `datadir/my.cnf' are processed before
  13707.      command-line options, so it is recommended that you put a `--user'
  13708.      option in `/etc/my.cnf' and specify a value other than `root'. The
  13709.      option in `/etc/my.cnf' will be found before any other `--user'
  13710.      options, which ensures that the server runs as a user other than
  13711.      `root', and that a warning results if any other `--user' option is
  13712.      found.
  13713.  
  13714. `-V, --version'
  13715.      Display version information and exit.
  13716.  
  13717. `-W, --log-warnings'
  13718.      Print out warnings like `Aborted connection...' to the `.err'
  13719.      file. Enabling this option is recommended, for example, if you use
  13720.      replication (you will get more information about what is happening,
  13721.      such as messages about network failures and reconnections). *Note
  13722.      Communication errors::.
  13723.  
  13724.      This option used to be called `--warnings'.
  13725.  
  13726. You can change most values for a running server with the `SET' command.
  13727. *Note `SET OPTION': SET OPTION.
  13728.  
  13729. `my.cnf' Option Files
  13730. ---------------------
  13731.  
  13732. MySQL can, since Version 3.22, read default startup options for the
  13733. server and for clients from option files.
  13734.  
  13735. On Windows, MySQL reads default options from the following files:
  13736.  
  13737. *Filename*                *Purpose*
  13738. `windows-directory\my.ini'Global options
  13739. `C:\my.cnf'               Global options
  13740.  
  13741. `windows-directory' is the location of your Windows directory.
  13742.  
  13743. On Unix, MySQL reads default options from the following files:
  13744.  
  13745. *Filename*                *Purpose*
  13746. `/etc/my.cnf'             Global options
  13747. `DATADIR/my.cnf'          Server-specific options
  13748. `defaults-extra-file'     The file specified with
  13749.                           `--defaults-extra-file=path'
  13750. `~/.my.cnf'               User-specific options
  13751.  
  13752. `DATADIR' is the MySQL data directory (typically
  13753. `/usr/local/mysql/data' for a binary installation or `/usr/local/var'
  13754. for a source installation).  Note that this is the directory that was
  13755. specified at configuration time, not the one specified with `--datadir'
  13756. when `mysqld' starts up!  (`--datadir' has no effect on where the
  13757. server looks for option files, because the server looks for files
  13758. before it processes any command-line arguments.)
  13759.  
  13760. Note that on Windows you should specify all paths in option files with
  13761. `/' instead of `\'. If you use `\', you need to specify it twice,
  13762. because `\' is the escape character in MySQL.
  13763.  
  13764. MySQL tries to read option files in the order listed above.  If
  13765. multiple option files exist, an option specified in a file read later
  13766. takes precedence over the same option specified in a file read earlier.
  13767. Options specified on the command-line take precedence over options
  13768. specified in any option file.  Some options can be specified using
  13769. environment variables.  Options specified on the command-line or in
  13770. option files take precedence over environment variable values. *Note
  13771. Environment variables::.
  13772.  
  13773. The following programs support option files:  `mysql', `mysqladmin',
  13774. `mysqld', `mysqld_safe', `mysql.server', `mysqldump', `mysqlimport',
  13775. `mysqlshow', `mysqlcheck', `myisamchk', and `myisampack'.
  13776.  
  13777. Since Version 4.0.2, you can use the `loose' prefix for command-line
  13778. options (or options in my.cnf). If an option is prefixed by `loose', the
  13779. program reading it will not exit with an error if an option is unknown,
  13780. but will rather only issue a warning:
  13781.  
  13782.      shell> mysql --loose-no-such-option
  13783.  
  13784. Any long option that may be given on the command-line when running a
  13785. MySQL program can be given in an option file as well (without the
  13786. leading double dash).  Run the program with the `--help' option to get
  13787. a list of available options.
  13788.  
  13789. An option file can contain lines of the following forms:
  13790.  
  13791. `#comment'
  13792.      Comment lines start with `#' or `;'. Empty lines are ignored.
  13793.  
  13794. `[group]'
  13795.      `group' is the name of the program or group for which you want to
  13796.      set options.  After a group line, any `option' or `set-variable'
  13797.      lines apply to the named group until the end of the option file or
  13798.      another group line is given.
  13799.  
  13800. `option'
  13801.      This is equivalent to `--option' on the command-line.
  13802.  
  13803. `option=value'
  13804.      This is equivalent to `--option=value' on the command-line.
  13805.  
  13806. `set-variable = variable=value'
  13807.      This is equivalent to `--set-variable variable=value' on the
  13808.      command-line.  Please note that `--set-variable' is deprecated
  13809.      since MySQL 4.0; as of that version, program variable names can be
  13810.      used as option names.  On the command line, just use
  13811.      `--variable=value'. In an option file, use `variable=value'.
  13812.  
  13813. The `[client]' group allows you to specify options that apply to all
  13814. MySQL clients (not `mysqld'). This is the perfect group to use to
  13815. specify the password that you use to connect to the server.  (But make
  13816. sure the option file is readable and writable only by yourself.)
  13817.  
  13818. Note that for options and values, all leading and trailing blanks are
  13819. automatically deleted.  You may use the escape sequences `\b', `\t',
  13820. `\n', `\r', `\\', and `\s' in your value string (`\s' == blank).
  13821.  
  13822. Here is a typical global option file:
  13823.  
  13824.      [client]
  13825.      port=3306
  13826.      socket=/tmp/mysql.sock
  13827.      
  13828.      [mysqld]
  13829.      port=3306
  13830.      socket=/tmp/mysql.sock
  13831.      set-variable = key_buffer_size=16M
  13832.      set-variable = max_allowed_packet=1M
  13833.      
  13834.      [mysqldump]
  13835.      quick
  13836.  
  13837. Here is typical user option file:
  13838.  
  13839.      [client]
  13840.      # The following password will be sent to all standard MySQL clients
  13841.      password=my_password
  13842.      
  13843.      [mysql]
  13844.      no-auto-rehash
  13845.      set-variable = connect_timeout=2
  13846.      
  13847.      [mysqlhotcopy]
  13848.      interactive-timeout
  13849.  
  13850. If you have a source distribution, you will find sample configuration
  13851. files named `my-xxxx.cnf' in the `support-files' directory.  If you
  13852. have a binary distribution, look in the `DIR/support-files' directory,
  13853. where `DIR' is the pathname to the MySQL installation directory
  13854. (typically `C:\mysql' or `/usr/local/mysql').  Currently there are
  13855. sample configuration files for small, medium, large, and very large
  13856. systems.  You can copy `my-xxxx.cnf' to your home directory (rename the
  13857. copy to `.my.cnf') to experiment with this.
  13858.  
  13859. All MySQL programs that support option files support the following
  13860. options:
  13861.  
  13862. *Option*                         *Description*
  13863. `--no-defaults'                  Don't read any option files.
  13864. `--print-defaults'               Print the program name and all options
  13865.                                  that it will get.
  13866. `--defaults-file=full-path-to-default-file'Only use the given configuration file.
  13867. `--defaults-extra-file=full-path-to-default-file'Read this configuration file after the
  13868.                                  global configuration file but before
  13869.                                  the user configuration file.
  13870.  
  13871. Note that the options just shown must be first on the command line to
  13872. work, with the exception that `--print-defaults' may be used
  13873. immediately after `--defaults-file' or `--defaults-extra-file'.
  13874.  
  13875. Note for developers:  Option file handling is implemented simply by
  13876. processing all matching options (that is, options in the appropriate
  13877. group) before any command-line arguments. This works nicely for
  13878. programs that use the last instance of an option that is specified
  13879. multiple times. If you have an old program that handles multiply
  13880. specified options this way but doesn't read option files, you need add
  13881. only two lines to give it that capability.  Check the source code of
  13882. any of the standard MySQL clients to see how to do this.
  13883.  
  13884. In shell scripts, you can use the `my_print_defaults' command to parse
  13885. the option files. The following example shows the output that
  13886. `my_print_defaults' might produce when asked to show the options found
  13887. in the `[client]' and `[mysql]' groups:
  13888.  
  13889.  
  13890.      shell> my_print_defaults client mysql
  13891.      --port=3306
  13892.      --socket=/tmp/mysql.sock
  13893.      --no-auto-rehash
  13894.  
  13895. Running Multiple MySQL Servers on the Same Machine
  13896. --------------------------------------------------
  13897.  
  13898. In some cases you might want to run multiple `mysqld' servers on the
  13899. same machine.  For example, you might want to test a new MySQL release
  13900. while leaving your existing production setup undisturbed.  Or you may
  13901. want to give different users access to different `mysqld' servers that
  13902. they manage themselves.  (For example, you might be an Internet service
  13903. provider that wants to provide independent MySQL installations for
  13904. different customers.)
  13905.  
  13906. When you run multiple servers on a single machine, each server must have
  13907. unique values for several operating parameters. At least the following
  13908. options must be different for each server:
  13909.  
  13910.    * `--port=port_num'
  13911.  
  13912.    * `--socket=path'
  13913.  
  13914.    * `--shared-memory-base-name=name' (Windows only; new in MySQL 4.1)
  13915.  
  13916.    * `--pid-file=path' (Unix only)
  13917.  
  13918. `--port' controls the port number for TCP/IP connections.  `--socket'
  13919. controls the socket file path on Unix and the name of the named pipe on
  13920. Windows. (It's necessary to specify distinct pipe names on Windows only
  13921. for those servers that support named pipe connections.)
  13922. `--shared-memory-base-name' designates the shared memory name used by a
  13923. Windows server to allow clients to connect via shared memory.
  13924. `--pid-file' indicates the name of the file in which a Unix server
  13925. writes its process ID.
  13926.  
  13927. If you use the following options, they must be different for each
  13928. server:
  13929.  
  13930.    * `--log=path'
  13931.  
  13932.    * `--log-bin=path'
  13933.  
  13934.    * `--log-update=path'
  13935.  
  13936.    * `--log-error=path'
  13937.  
  13938.    * `--log-isam=path'
  13939.  
  13940.    * `--bdb-logdir=path'
  13941.  
  13942. If you want more performance, you can also specify the following options
  13943. differently for each server, to spread load between several physical
  13944. disks:
  13945.  
  13946.    * `--tmpdir=path'
  13947.  
  13948.    * `--bdb-tmpdir=path'
  13949.  
  13950. *Note Command-line options::.
  13951.  
  13952. Generally, each server should also use a different data directory,
  13953. which is specified using the `--datadir=path' option.
  13954.  
  13955. If you have multiple MySQL installations in different locations,
  13956. normally you can specify the base installation directory for each
  13957. server with the `--basedir=path' option to cause each server to use a
  13958. different data directory, log files, and PID file. (The defaults for
  13959. all these values are determined relative to the base directory.) In
  13960. that case, the only other options you need to specify are the
  13961. `--socket' and `--port' options.  For example, suppose you install
  13962. binary MySQL versions (`.tar' files) in different locations and start
  13963. them using the command `./bin/mysqld_safe' under the corresponding base
  13964. directory of each installation.  `mysqld_safe' will determine the proper
  13965. `--basedir' option to pass to `mysqld', and you need specify only the
  13966. `--socket' and `--port' options to `mysqld_safe'.
  13967.  
  13968. As discussed in the following sections, it is possible to start
  13969. additional servers by setting environment variables or by specifying
  13970. appropriate command-line options.  However, if you need to run multiple
  13971. servers on a more permanent basis, it will be more convenient to use
  13972. option files to specify for each server those option values that must
  13973. be unique to it.  *Note Option files::.
  13974.  
  13975. *Warning*: Normally you should never have two servers that update data
  13976. in the same databases!  If your OS doesn't support fault-free system
  13977. locking, this may lead to unpleasant surprises!  If (despite this
  13978. warning) you run multiple servers using the same data directory and
  13979. they have logging enabled, you must specify the names of the log files
  13980. using the appropriate options.  Otherwise, the servers may try to log
  13981. to the same files.
  13982.  
  13983. This warning against sharing a data directory among servers also applies
  13984. in an NFS environment.  Allowing several MySQL servers to access a
  13985. common data directory over NFS is a *bad idea*!
  13986.  
  13987.    * The primary problem is that NFS will become the speed bottleneck.
  13988.      It is not meant for such use.
  13989.  
  13990.    * You also will have to come up with a solution how to make sure
  13991.      that two or more servers do not interfere with each other. At the
  13992.      moment there is no platform that will 100% reliably do the file
  13993.      locking in every situation (usually this is handled by the `lockd'
  13994.      daemon).  Yet there would be one more possible risk with NFS; it
  13995.      would make the work even more complicated for `lockd' daemon to
  13996.      handle.
  13997.  
  13998.  
  13999. Make it easy for yourself: Forget about sharing a data directory among
  14000. servers over NFS. A better solution is to have one computer with an
  14001. operating system that efficiently handles threads and have several CPUs
  14002. in it.
  14003.  
  14004. Running Multiple Servers on Windows
  14005. ...................................
  14006.  
  14007. You can run multiple servers on Windows by starting them manually from
  14008. the command line, each with appropriate operating parameters. On
  14009. Windows NT-based systems, you also have the option of installing
  14010. several servers as services and running them that way. General
  14011. instructions for running MySQL servers from the command line or as
  14012. services are given in *Note Windows::. This section describes how to
  14013. make sure you start each server with different values for those startup
  14014. options that must be unique per server, such as the data directory.
  14015. (These options are described in *Note Multiple servers::.)
  14016.  
  14017. Starting Multiple Windows Servers at the Command Line
  14018. .....................................................
  14019.  
  14020. To start multiple servers manually from the command line, you can
  14021. specify the appropriate options on the command line or in an option
  14022. file. It's more convenient to place the options in an option file, but
  14023. it's necessary to make sure that each server gets its own set of
  14024. options. To do this, create an option file for each server and tell the
  14025. server the filename with a `--defaults-file' option when you run it.
  14026.  
  14027. Suppose you want to run `mysqld' on port 3307 with a data directory of
  14028. `C:\mydata1', and `mysqld-max' on port 3308 with a data directory of
  14029. `C:\mydata2'. To accomplish this, create two option files. For example,
  14030. create one file `C:\my-opts1.cnf' that looks like this:
  14031.  
  14032.      [mysqld]
  14033.      datadir = C:/mydata1
  14034.      port = 3307
  14035.  
  14036. Create a second file `C:\my-opts2.cnf' that looks like this:
  14037.  
  14038.      [mysqld]
  14039.      datadir = C:/mydata2
  14040.      port = 3308
  14041.  
  14042. Then start each server with its own option file:
  14043.  
  14044.      shell> mysqld --defaults-file=C:\my-opts1.cnf
  14045.      shell> mysqld-max --defaults-file=C:\my-opts2.cnf
  14046.  
  14047. (On NT, the servers will start in the foreground, so you'll need to
  14048. issue those two commands in separate console windows.)
  14049.  
  14050. To shut down the servers, you must connect to the appropriate port
  14051. number:
  14052.  
  14053.      shell> mysqladmin --port=3307 shutdown
  14054.      shell> mysqladmin --port=3308 shutdown
  14055.  
  14056. If you want to allow named pipe connections in addition to TCP/IP
  14057. connections, use the `mysqld-nt' or `mysqld-max-nt' servers and specify
  14058. options that enable the named pipe and specify its name. (Each server
  14059. must have a unique pipe name.)  For example, the `C:\my-opts1.cnf' file
  14060. might be written like this:
  14061.  
  14062.      [mysqld]
  14063.      datadir = C:/mydata1
  14064.      port = 3307
  14065.      enable-named-pipe
  14066.      socket = mypipe1
  14067.  
  14068. Then start the server this way:
  14069.  
  14070.      shell> mysqld-nt --defaults-file=C:\my-opts1.cnf
  14071.  
  14072. `C:\my-opts2.cnf' would be modified similarly.
  14073.  
  14074. Starting Multiple Windows Servers as Services
  14075. .............................................
  14076.  
  14077. On NT-based systems, you can install multiple servers as services.
  14078. (This is possible as of MySQL 4.0.2.) In this case, you must make sure
  14079. that each server uses a different service name in addition to all the
  14080. other parameters that must be unique per server.
  14081.  
  14082. For the following instructions, assume that you want to run `mysqld-nt'
  14083. servers from two different versions of MySQL that are installed at
  14084. `C:\mysql-4.0.8' and `C:\mysql-4.0.14', respectively. (This might be
  14085. the case if you're running 4.0.8 as your production server, but want to
  14086. test 4.0.14 before upgrading to it.)
  14087.  
  14088. The following principles are relevant when installing a MySQL service
  14089. with the `--install' (or `--install-manual') option:
  14090.  
  14091.    * If you specify no service name, the server uses the default
  14092.      service name of `MySql' and the server reads options from the
  14093.      `[mysqld]' group in the standard option files.
  14094.  
  14095.    * If you specify a service name after the `--install' option, the
  14096.      server ignores the `[mysqld]' option group and instead reads
  14097.      options from the group that has the same name as the service.
  14098.  
  14099.    * If you specify a `--defaults-file' option after the service name,
  14100.      the server ignores the standard option files and reads options
  14101.      only from the `[mysqld]' group of the named file.
  14102.  
  14103. These principles give you several ways to set up multiple services.
  14104. The following instructions describe some examples. Before trying any of
  14105. them, be sure you shut down and remove any existing MySQL services
  14106. first.
  14107.  
  14108.    * Specify the options for all services in one of the standard option
  14109.      files.  To do this, use the `[mysqld]' group for the server that
  14110.      is installed under the default service name (`MySql'). For other
  14111.      servers, use a group name that is the same as the service name.
  14112.      Suppose you want to run the 4.0.8 `mysqld-nt' using the default
  14113.      service name and the 4.0.14 `mysqld-nt' using the service name
  14114.      `mysqld2'.  In this case, you can use the `[mysqld]' group for
  14115.      4.0.8 and the `[mysqld2]' group for 4.0.14.  For example, you can
  14116.      set up `C:\my.cnf' like this:
  14117.  
  14118.           # options for default service (MySql)
  14119.           [mysqld]
  14120.           basedir = C:/mysql-4.0.8
  14121.           port = 3307
  14122.           enable-named-pipe
  14123.           socket = mypipe1
  14124.           
  14125.           # options for mysqld2 service
  14126.           [mysqld2]
  14127.           basedir = C:/mysql-4.0.14
  14128.           port = 3308
  14129.           enable-named-pipe
  14130.           socket = mypipe2
  14131.  
  14132.      Install the services like this:
  14133.  
  14134.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install
  14135.           shell> C:\mysql-4.0.14\bin\mysqld-nt --install mysqld2
  14136.  
  14137.      To start the services, use the services manager, or use `NET START'
  14138.      with the appropriate service names:
  14139.  
  14140.           shell> NET START MySql
  14141.           shell> NET START mysqld2
  14142.  
  14143.      To stop the services, use the services manager, or use `NET STOP'
  14144.      with the same service names.
  14145.  
  14146.    * Specify options for each server in separate files and use
  14147.      `--defaults-file' when you install the services to tell each server
  14148.      what file to use.  In this case, each file should list options
  14149.      using a `[mysqld]' group.
  14150.  
  14151.      With this approach, to specify options for the 4.0.8 `mysqld-nt',
  14152.      create a file `C:\my-opts1.cnf' that looks like this:
  14153.  
  14154.           [mysqld]
  14155.           basedir = C:/mysql-4.0.8
  14156.           port = 3307
  14157.           enable-named-pipe
  14158.           socket = mypipe1
  14159.  
  14160.      For the 4.0.14 `mysqld-nt', create a file `C:\my-opts2.cnf' that
  14161.      looks like this:
  14162.  
  14163.           [mysqld]
  14164.           basedir = C:/mysql-4.0.14
  14165.           port = 3308
  14166.           enable-named-pipe
  14167.           socket = mypipe2
  14168.  
  14169.      Install the services as follows (enter each command on a single
  14170.      line):
  14171.  
  14172.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install MySql
  14173.                      --defaults-file=C:\my-opts1.cnf
  14174.           shell> C:\mysql-4.0.14\bin\mysqld-nt --install mysqld2
  14175.                      --defaults-file=C:\my-opts2.cnf
  14176.  
  14177.      To use a `--defaults-file' option when you install a MySQL server
  14178.      as a service, you must precede the option with the service name.
  14179.      That is why the first command names the `MySql' service
  14180.      explicitly, even though that is the default service name.
  14181.  
  14182.      Start and stop the services the same way as in the preceding
  14183.      example.
  14184.  
  14185.  
  14186. To remove multiple services, use `mysqld --remove' for each one,
  14187. specifying a service name following the `--remove' option if the
  14188. service to remove has a name different than the default.
  14189.  
  14190. Running Multiple Servers on Unix
  14191. ................................
  14192.  
  14193. The easiest way is to run multiple servers on Unix is to compile them
  14194. with different TCP/IP ports and socket files so that each one is
  14195. listening on different network interfaces. Also, by compiling in
  14196. different base directories for each installation, that automatically
  14197. results in different compiled-in data directory, log file, and PID file
  14198. locations for each of your servers.
  14199.  
  14200. Assume an existing server is configured for the default port number and
  14201. socket file.  To configure a new server to have different operating
  14202. parameters, use a `configure' command something like this:
  14203.  
  14204.      shell> ./configure --with-tcp-port=port_number \
  14205.                   --with-unix-socket-path=file_name \
  14206.                   --prefix=/usr/local/mysql-4.0.14
  14207.  
  14208. Here `port_number' and `file_name' should be different from the default
  14209. port number and socket file pathname, and the `--prefix' value should
  14210. specify an installation directory different than the one under which
  14211. the existing MySQL installation is located.
  14212.  
  14213. If you have a MySQL server listening on a given port number, you can
  14214. use the following command to find out what operating parameters it is
  14215. using for several important configurable variables, including the base
  14216. directory and socket name:
  14217.  
  14218.      shell> mysqladmin --host=host_name --port=port_number variables
  14219.  
  14220. With the information displayed by that command, you can tell what option
  14221. values *not* to use when configuring an additional server.
  14222.  
  14223. Note that if you specify "`localhost'" as a hostname, `mysqladmin' will
  14224. default to using a Unix socket connection rather than TCP/IP.  In MySQL
  14225. 4.1, you can explicitly specify the connection protocol to use by using
  14226. the `--protocol={TCP | SOCKET | PIPE | MEMORY}' option.
  14227.  
  14228. You don't have to compile a new MySQL server just to start with a
  14229. different socket file and TCP/IP port number.  It is also possible to
  14230. specify those values at runtime. One way to do so is by using
  14231. command-line options:
  14232.  
  14233.      shell> /path/to/mysqld_safe --socket=file_name --port=port_number
  14234.  
  14235. To use another database directory for the second server, pass a
  14236. `--datadir=path' option to `mysqld_safe'.
  14237.  
  14238. Another way to achieve a similar effect is to use environment variables
  14239. to set the socket name and port number:
  14240.  
  14241.      shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
  14242.      shell> MYSQL_TCP_PORT=3307
  14243.      shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
  14244.      shell> scripts/mysql_install_db
  14245.      shell> bin/mysqld_safe &
  14246.  
  14247. This is a quick and dirty method for starting a second server to use
  14248. for testing.  The nice thing about this method is that the environment
  14249. variable settings will apply to any client programs that you invoke from
  14250. the above shell. Thus, connections for those clients automatically will
  14251. be directed to the second server!
  14252.  
  14253. *Note Environment variables:: includes a list of other environment
  14254. variables you can use to affect `mysqld'.
  14255.  
  14256. For automatic server execution, your startup script that is executed at
  14257. boot time should execute the following command once for each server
  14258. with an appropriate option file path for each command:
  14259.  
  14260.      mysqld_safe --defaults-file=path-to-option-file
  14261.  
  14262. Each option file should contain option values specific to a given
  14263. server.
  14264.  
  14265. On Unix, the `mysqld_multi' script is another way to start multiple
  14266. servers.  *Note `mysqld_multi': mysqld_multi.
  14267.  
  14268. Using Client Programs in a Multiple-Server Environment
  14269. ......................................................
  14270.  
  14271. When you want to connect with a client program to a MySQL server that is
  14272. listening to different network interfaces than those compiled into your
  14273. client, you can use one of the following methods:
  14274.  
  14275.    * Start the client with `--host=host_name --port=port_number' to
  14276.      connect via TCP/IP to a remote host, or with `--host=localhost
  14277.      --socket=file_name' to connect to a local host via a Unix socket
  14278.      or a Windows named pipe.
  14279.  
  14280.    * As of MySQL 4.1, start the client with `--protocol=tcp' to connect
  14281.      via TCP/IP, `--protocol=socket' to connect via a Unix socket,
  14282.      `--protocol=pipe' to connect via a named pipe, or
  14283.      `--protocol=memory' to connect via shared memory.  For TCP/IP
  14284.      connections, you may also need to specify `--host' and `--port'
  14285.      options.  For the other types of connections, you may need to
  14286.      specify a `--socket' option to specify a socket or named pipe
  14287.      name, or a `--shared-memory-base-name' option to specify the
  14288.      shared memory name.
  14289.  
  14290.    * On Unix, set the `MYSQL_UNIX_PORT' and `MYSQL_TCP_PORT'
  14291.      environment variables to point to the Unix socket and TCP/IP port
  14292.      before you start your clients.  If you normally use a specific
  14293.      socket or port, you can place commands to set these environment
  14294.      variables in your `.login' file so that they apply each time you
  14295.      log in.  *Note Environment variables::.
  14296.  
  14297.    * Specify the default socket and TCP/IP port in the `[client]' group
  14298.      of an option file. Foe example, you can use `C:\my.cnf' on
  14299.      Windows, or the `.my.cnf' file in your home directory on Unix.
  14300.      *Note Option files::.
  14301.  
  14302.    * In a C program, you can specify the port or socket arguments in the
  14303.      `mysql_real_connect()' call.  You can also have the program read
  14304.      option files by calling `mysql_options()'.  *Note C API
  14305.      functions::.
  14306.  
  14307.    * If you are using the Perl `DBD::mysql' module, you can read the
  14308.      options from the MySQL option files. For example:
  14309.  
  14310.           $dsn = "DBI:mysql:test;mysql_read_default_group=client;"
  14311.                   . "mysql_read_default_file=/usr/local/mysql/data/my.cnf";
  14312.           $dbh = DBI->connect($dsn, $user, $password);
  14313.  
  14314.      *Note Perl DBI Class::.
  14315.  
  14316.  
  14317. General Security Issues and the MySQL Access Privilege System
  14318. =============================================================
  14319.  
  14320. MySQL has an advanced but non-standard security/privilege system.  This
  14321. section describes how it works.
  14322.  
  14323. General Security Guidelines
  14324. ---------------------------
  14325.  
  14326. Anyone using MySQL on a computer connected to the Internet should read
  14327. this section to avoid the most common security mistakes.
  14328.  
  14329. In discussing security, we emphasise the necessity of fully protecting
  14330. the entire server host (not simply the MySQL server) against all types
  14331. of applicable attacks: eavesdropping, altering, playback, and denial of
  14332. service. We do not cover all aspects of availability and fault tolerance
  14333. here.
  14334.  
  14335. MySQL uses security based on Access Control Lists (ACLs) for all
  14336. connections, queries, and other operations that a user may attempt to
  14337. perform. There is also some support for SSL-encrypted connections
  14338. between MySQL clients and servers. Many of the concepts discussed here
  14339. are not specific to MySQL at all; the same general ideas apply to
  14340. almost all applications.
  14341.  
  14342. When running MySQL, follow these guidelines whenever possible:
  14343.  
  14344.    * *Do not ever give anyone (except the mysql `root' user) access to
  14345.      the `user' table in the `mysql' database!*  This is critical.
  14346.      *The encrypted password is the real password in MySQL.* Anyone who
  14347.      knows the password which is listed in the `user' table and has
  14348.      access to the host listed for the account *can easily log in as
  14349.      that user*.
  14350.  
  14351.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  14352.      commands are used for controlling access to MySQL. Do not grant
  14353.      any more privileges than necessary. Never grant privileges to all
  14354.      hosts.
  14355.  
  14356.      Checklist:
  14357.         - Try `mysql -u root'. If you are able to connect successfully
  14358.           to the server without being asked for a password, you have
  14359.           problems. Anyone can connect to your MySQL server as the MySQL
  14360.           `root' user with full privileges!  Review the MySQL
  14361.           installation instructions, paying particular attention to the
  14362.           item about setting a `root' password.
  14363.  
  14364.         - Use the command `SHOW GRANTS' and check to see who has access
  14365.           to what. Remove those privileges that are not necessary using
  14366.           the `REVOKE' command.
  14367.  
  14368.    * Do not keep any plain-text passwords in your database. When your
  14369.      computer becomes compromised, the intruder can take the full list
  14370.      of passwords and use them. Instead use `MD5()', `SHA1()' or
  14371.      another one-way hashing function.
  14372.  
  14373.    * Do not choose passwords from dictionaries. There are special
  14374.      programs to break them. Even passwords like "xfish98" are very
  14375.      bad.  Much better is "duag98" which contains the same word "fish"
  14376.      but typed one key to the left on a standard QWERTY keyboard.
  14377.      Another method is to use "Mhall" which is taken from the first
  14378.      characters of each word in the sentence "Mary had a little lamb."
  14379.      This is easy to remember and type, but difficult to guess for
  14380.      someone who does not know it.
  14381.  
  14382.    * Invest in a firewall. This protects you from at least 50% of all
  14383.      types of exploits in any software. Put MySQL behind the firewall
  14384.      or in a demilitarised zone (DMZ).
  14385.  
  14386.      Checklist:
  14387.         - Try to scan your ports from the Internet using a tool such as
  14388.           `nmap'. MySQL uses port 3306 by default. This port should be
  14389.           inaccessible from untrusted hosts. Another simple way to
  14390.           check whether or not your MySQL port is open is to try the
  14391.           following command from some remote machine, where
  14392.           `server_host' is the hostname of your MySQL server:
  14393.  
  14394.                shell> telnet server_host 3306
  14395.  
  14396.           If you get a connection and some garbage characters, the port
  14397.           is open, and should be closed on your firewall or router,
  14398.           unless you really have a good reason to keep it open. If
  14399.           `telnet' just hangs or the connection is refused, everything
  14400.           is OK; the port is blocked.
  14401.  
  14402.    * Do not trust any data entered by your users. They can try to trick
  14403.      your code by entering special or escaped character sequences in
  14404.      web forms, URLs, or whatever application you have built. Be sure
  14405.      that your application remains secure if a user enters something
  14406.      like "`; DROP DATABASE mysql;'". This is an extreme example, but
  14407.      large security leaks and data loss may occur as a result of
  14408.      hackers using similar techniques, if you do not prepare for them.
  14409.  
  14410.      Also remember to check numeric data. A common mistake is to
  14411.      protect only strings. Sometimes people think that if a database
  14412.      contains only publicly available data that it need not be
  14413.      protected. This is incorrect. At least denial-of-service type
  14414.      attacks can be performed on such databases. The simplest way to
  14415.      protect from this type of attack is to use apostrophes around the
  14416.      numeric constants: `SELECT * FROM table WHERE ID='234'' rather
  14417.      than `SELECT * FROM table WHERE ID=234'.  MySQL automatically
  14418.      converts this string to a number and strips all non-numeric
  14419.      symbols from it.
  14420.  
  14421.      Checklist:
  14422.         - All web applications:
  14423.              * Try to enter `'' and `"' in all your web forms. If you
  14424.                get any kind of MySQL error, investigate the problem
  14425.                right away.
  14426.  
  14427.              * Try to modify any dynamic URLs by adding `%22' (`"'),
  14428.                `%23' (`#'), and `%27' (`'') in the URL.
  14429.  
  14430.              * Try to modify datatypes in dynamic URLs from numeric
  14431.                ones to character ones containing characters from
  14432.                previous examples. Your application should be safe
  14433.                against this and similar attacks.
  14434.  
  14435.              * Try to enter characters, spaces, and special symbols
  14436.                instead of numbers in numeric fields. Your application
  14437.                should remove them before passing them to MySQL or your
  14438.                application should generate an error. Passing unchecked
  14439.                values to MySQL is very dangerous!
  14440.  
  14441.              * Check data sizes before passing them to MySQL.
  14442.  
  14443.              * Consider having your application connect to the database
  14444.                using a different user name than the one you use for
  14445.                administrative purposes. Do not give your applications
  14446.                any more access privileges than they need.
  14447.  
  14448.         - Users of PHP:
  14449.              * Check out the `addslashes()' function.  As of PHP 4.0.3,
  14450.                a `mysql_escape_string()' function is available that is
  14451.                based on the function of the same name in the MySQL C
  14452.                API.
  14453.  
  14454.         - Users of MySQL C API:
  14455.              * Check out the `mysql_real_escape_string()' API call.
  14456.  
  14457.         - Users of MySQL++:
  14458.              * Check out the `escape' and `quote' modifiers for query
  14459.                streams.
  14460.  
  14461.         - Users of Perl DBI:
  14462.              * Check out the `quote()' method or use placeholders.
  14463.  
  14464.         - Users of Java JDBC:
  14465.              * Use a `PreparedStatement' object and placeholders.
  14466.  
  14467.    * Do not transmit plain (unencrypted) data over the Internet. These
  14468.      data are accessible to everyone who has the time and ability to
  14469.      intercept it and use it for their own purposes. Instead, use an
  14470.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  14471.      connections as of Version 4.0.0.  SSH port-forwarding can be used
  14472.      to create an encrypted (and compressed) tunnel for the
  14473.      communication.
  14474.  
  14475.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  14476.      you can check whether MySQL data streams are unencrypted by
  14477.      issuing a command like the following:
  14478.  
  14479.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  14480.  
  14481.      (This works under Linux and should work with small modifications
  14482.      under other systems.)  Warning: If you do not see data this
  14483.      doesn't always actually mean that it is encrypted. If you need
  14484.      high security, you should consult with a security expert.
  14485.  
  14486. How to Make MySQL Secure Against Crackers
  14487. -----------------------------------------
  14488.  
  14489. When you connect to a MySQL server, you normally should use a password.
  14490. The password is not transmitted in clear text over the connection,
  14491. however the encryption algorithm is not very strong, and with some
  14492. effort a clever attacker can crack the password if he is able to sniff
  14493. the traffic between the client and the server. If the connection
  14494. between the client and the server goes through an untrusted network,
  14495. you should use an SSH tunnel to encrypt the communication.
  14496.  
  14497. All other information is transferred as text that can be read by anyone
  14498. who is able to watch the connection.  If you are concerned about this,
  14499. you can use the compressed protocol (in MySQL Version 3.22 and above)
  14500. to make things much harder.  To make things even more secure you should
  14501. use `ssh'.  You can find an `Open Source' `ssh' client at
  14502. `http://www.openssh.org/', and a commercial `ssh' client at
  14503. `http://www.ssh.com/'.  With this, you can get an encrypted TCP/IP
  14504. connection between a MySQL server and a MySQL client.
  14505.  
  14506. If you are using MySQL 4.0, you can also use internal OpenSSL support.
  14507. *Note Secure connections::.
  14508.  
  14509. To make a MySQL system secure, you should strongly consider the
  14510. following suggestions:
  14511.  
  14512.    * Use passwords for all MySQL users. Remember that anyone can log in
  14513.      as any other person as simply as `mysql -u other_user db_name' if
  14514.      `other_user' has no password.  It is common behaviour with
  14515.      client/server applications that the client may specify any user
  14516.      name.  You can change the password of all users by editing the
  14517.      `mysql_install_db' script before you run it, or only the password
  14518.      for the MySQL `root' user like this:
  14519.  
  14520.           shell> mysql -u root mysql
  14521.           mysql> UPDATE user SET Password=PASSWORD('new_password')
  14522.               ->             WHERE user='root';
  14523.           mysql> FLUSH PRIVILEGES;
  14524.  
  14525.    * Don't run the MySQL daemon as the Unix `root' user.  This is very
  14526.      dangerous, because any user with the `FILE' privilege will be able
  14527.      to create files as `root' (for example, `~root/.bashrc'). To
  14528.      prevent this, `mysqld' will refuse to run as `root' unless it is
  14529.      specified directly using a `--user=root' option.
  14530.  
  14531.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  14532.      can also create a new Unix user `mysql' to make everything even
  14533.      more secure.  If you run `mysqld' as another Unix user, you don't
  14534.      need to change the `root' user name in the `user' table, because
  14535.      MySQL user names have nothing to do with Unix user names.  To
  14536.      start `mysqld' as another Unix user, add a `user' line that
  14537.      specifies the user name to the `[mysqld]' group of the
  14538.      `/etc/my.cnf' option file or the `my.cnf' option file in the
  14539.      server's data directory. For example:
  14540.  
  14541.           [mysqld]
  14542.           user=mysql
  14543.  
  14544.      This will cause the server to start as the designated user whether
  14545.      you start it manually or by using `mysqld_safe' or `mysql.server'.
  14546.      For more details, see *Note Changing MySQL user::.
  14547.  
  14548.    * Don't support symlinks to tables (this can be disabled with the
  14549.      `--skip-symlink' option). This is especially important if you run
  14550.      `mysqld' as root as anyone that has write access to the mysqld data
  14551.      directories could then delete any file in the system!  *Note
  14552.      Symbolic links to tables::.
  14553.  
  14554.    * Check that the Unix user that `mysqld' runs as is the only user
  14555.      with read/write privileges in the database directories.
  14556.  
  14557.    * Don't give the `PROCESS' privilege to all users.  The output of
  14558.      `mysqladmin processlist' shows the text of the currently executing
  14559.      queries, so any user who is allowed to execute that command might
  14560.      be able to see if another user issues an `UPDATE user SET
  14561.      password=PASSWORD('not_secure')' query.
  14562.  
  14563.      `mysqld' reserves an extra connection for users who have the
  14564.      `PROCESS' privilege, so that a MySQL `root' user can log in and
  14565.      check things even if all normal connections are in use.
  14566.  
  14567.    * Don't give the `FILE' privilege to all users.  Any user that has
  14568.      this privilege can write a file anywhere in the filesystem with
  14569.      the privileges of the `mysqld' daemon!  To make this a bit safer,
  14570.      all files generated with `SELECT ... INTO OUTFILE' are writeable
  14571.      by everyone, and you cannot overwrite existing files.
  14572.  
  14573.      The `FILE' privilege may also be used to read any world readable
  14574.      file that is accessible to the Unix user that the server runs as.
  14575.      One can also read any file to the current database (which the user
  14576.      need some privilege for).  This could be abused, for example, by
  14577.      using `LOAD DATA' to load `/etc/passwd' into a table, which can
  14578.      then be read with `SELECT'.
  14579.  
  14580.    * If you don't trust your DNS, you should use IP numbers instead of
  14581.      hostnames in the grant tables. In any case, you should be very
  14582.      careful about creating grant table entries using hostname values
  14583.      that contain wildcards!
  14584.  
  14585.    * If you want to restrict the number of connections for a single
  14586.      user, you can do this by setting the `max_user_connections'
  14587.      variable in `mysqld'.
  14588.  
  14589. Startup Options for `mysqld' Concerning Security
  14590. ------------------------------------------------
  14591.  
  14592. The following `mysqld' options affect security:
  14593.  
  14594. `--local-infile[=(0|1)]'
  14595.      If one uses `--local-infile=0' then one can't use `LOAD DATA LOCAL
  14596.      INFILE'.
  14597.  
  14598. `--safe-show-database'
  14599.      With this option, the `SHOW DATABASES' command returns only those
  14600.      databases for which the user has some kind of privilege.  From
  14601.      version 4.0.2 this option is deprecated and doesn't do anything
  14602.      (the option is enabled by default) as we now have the `SHOW
  14603.      DATABASES' privilege. *Note GRANT::.
  14604.  
  14605. `--safe-user-create'
  14606.      If this is enabled, an user can't create new users with the `GRANT'
  14607.      command, if the user doesn't have the `INSERT' privilege for the
  14608.      `mysql.user' table.  If you want to give a user access to just
  14609.      create new users with those privileges that the user has right to
  14610.      grant, you should give the user the following privilege:
  14611.  
  14612.           mysql> GRANT INSERT(user) ON mysql.user TO 'user'@'hostname';
  14613.  
  14614.      This will ensure that the user can't change any privilege columns
  14615.      directly, but has to use the `GRANT' command to give privileges to
  14616.      other users.
  14617.  
  14618. `--skip-grant-tables'
  14619.      This option causes the server not to use the privilege system at
  14620.      all. This gives everyone *full access* to all databases!  (You can
  14621.      tell a running server to start using the grant tables again by
  14622.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  14623.  
  14624. `--skip-name-resolve'
  14625.      Hostnames are not resolved.  All `Host' column values in the grant
  14626.      tables must be IP numbers or `localhost'.
  14627.  
  14628. `--skip-networking'
  14629.      Don't allow TCP/IP connections over the network.  All connections
  14630.      to `mysqld' must be made via Unix sockets.  This option is
  14631.      unsuitable when using a MySQL version prior to 3.23.27 with the
  14632.      MIT-pthreads package, because Unix sockets were not supported by
  14633.      MIT-pthreads at that time.
  14634.  
  14635. `--skip-show-database'
  14636.      Don't allow `SHOW DATABASES' command, unless the user has the
  14637.      `SHOW DATABASES' privilege. From version 4.0.2 you should no longer
  14638.      need this option, since access can now be granted specifically
  14639.      with the `SHOW DATABASES' privilege.
  14640.  
  14641. Security issues with `LOAD DATA LOCAL'
  14642. --------------------------------------
  14643.  
  14644. In MySQL 3.23.49 and MySQL 4.0.2, we added some new options to deal with
  14645. possible security issues when it comes to `LOAD DATA LOCAL'.
  14646.  
  14647. There are two possible problems with supporting this command:
  14648.  
  14649. As the reading of the file is initiated from the server, one could
  14650. theoretically create a patched MySQL server that could read any file on
  14651. the client machine that the current user has read access to, when the
  14652. client issues a query against the table.
  14653.  
  14654. In a web environment where the clients are connecting from a web
  14655. server, a user could use `LOAD DATA LOCAL' to read any files that the
  14656. web server process has read access to (assuming a user could run any
  14657. command against the SQL server).
  14658.  
  14659. There are two separate fixes for this:
  14660.  
  14661. If you don't configure MySQL with `--enable-local-infile', then `LOAD
  14662. DATA LOCAL' will be disabled by all clients, unless one calls
  14663. `mysql_options(... MYSQL_OPT_LOCAL_INFILE, 0)' in the client.  *Note
  14664. `mysql_options()': mysql_options.
  14665.  
  14666. For the `mysql' command-line client, `LOAD DATA LOCAL' can be enabled
  14667. by specifying the option `--local-infile[=1]', or disabled with
  14668. `--local-infile=0'.
  14669.  
  14670. By default, all MySQL clients and libraries are compiled with
  14671. `--enable-local-infile', to be compatible with MySQL 3.23.48 and before.
  14672.  
  14673. One can disable all `LOAD DATA LOCAL' commands in the MySQL server by
  14674. starting `mysqld' with `--local-infile=0'.
  14675.  
  14676. In the case that `LOAD DATA LOCAL INFILE' is disabled in the server or
  14677. the client, you will get the error message (1148):
  14678.  
  14679.      The used command is not allowed with this MySQL version
  14680.  
  14681. What the Privilege System Does
  14682. ------------------------------
  14683.  
  14684. The primary function of the MySQL privilege system is to authenticate a
  14685. user connecting from a given host, and to associate that user with
  14686. privileges on a database such as `SELECT', `INSERT', `UPDATE' and
  14687. `DELETE'.
  14688.  
  14689. Additional functionality includes the ability to have an anonymous user
  14690. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  14691. INFILE' and administrative operations.
  14692.  
  14693. How the Privilege System Works
  14694. ------------------------------
  14695.  
  14696. The MySQL privilege system ensures that all users may do exactly the
  14697. things that they are supposed to be allowed to do.  When you connect to
  14698. a MySQL server, your identity is determined by *the host from which you
  14699. connect* and *the user name you specify*.  The system grants privileges
  14700. according to your identity and *what you want to do*.
  14701.  
  14702. MySQL considers both your hostname and user name in identifying you
  14703. because there is little reason to assume that a given user name belongs
  14704. to the same person everywhere on the Internet.  For example, the user
  14705. `joe' who connects from `office.com' need not be the same person as the
  14706. user `joe' who connects from `elsewhere.com'.  MySQL handles this by
  14707. allowing you to distinguish users on different hosts that happen to
  14708. have the same name:  you can grant `joe' one set of privileges for
  14709. connections from `office.com', and a different set of privileges for
  14710. connections from `elsewhere.com'.
  14711.  
  14712. MySQL access control involves two stages:
  14713.  
  14714.    * Stage 1: The server checks whether you are even allowed to connect.
  14715.  
  14716.    * Stage 2: Assuming you can connect, the server checks each request
  14717.      you issue to see whether you have sufficient privileges to perform
  14718.      it.  For example, if you try to select rows from a table in a
  14719.      database or drop a table from the database, the server makes sure
  14720.      you have the `SELECT' privilege for the table or the `DROP'
  14721.      privilege for the database.
  14722.  
  14723. Note that if your privileges are changed (either by yourself or someone
  14724. else) while you are connected, those changes will not necessarily take
  14725. effect with your next query or queries. See *Note Privilege changes::
  14726. for details.
  14727.  
  14728. The server uses the `user', `db', and `host' tables in the `mysql'
  14729. database at both stages of access control.  The fields in these grant
  14730. tables are shown here:
  14731.  
  14732. *Table name*   *user*         *db*           *host*
  14733. *Scope fields* `Host'         `Host'         `Host'
  14734.                `User'         `Db'           `Db'
  14735.                `Password'     `User'         
  14736. *Privilege     `Select_priv'  `Select_priv'  `Select_priv'
  14737. fields*                                      
  14738.                `Insert_priv'  `Insert_priv'  `Insert_priv'
  14739.                `Update_priv'  `Update_priv'  `Update_priv'
  14740.                `Delete_priv'  `Delete_priv'  `Delete_priv'
  14741.                `Index_priv'   `Index_priv'   `Index_priv'
  14742.                `Alter_priv'   `Alter_priv'   `Alter_priv'
  14743.                `Create_priv'  `Create_priv'  `Create_priv'
  14744.                `Drop_priv'    `Drop_priv'    `Drop_priv'
  14745.                `Grant_priv'   `Grant_priv'   `Grant_priv'
  14746.                `References_priv'               
  14747.                `Reload_priv'                 
  14748.                `Shutdown_priv'               
  14749.                `Process_priv'                
  14750.                `File_priv'                   
  14751.                `Show_db_priv'                
  14752.                `Super_priv'                  
  14753.                `Create_tmp_table_priv'`Create_tmp_table_priv'`Create_tmp_table_priv'
  14754.                `Lock_tables_priv'`Lock_tables_priv'`Lock_tables_priv'
  14755.                `Execute_priv'                
  14756.                `Repl_slave_priv'               
  14757.                `Repl_client_priv'               
  14758.                `ssl_type'                    
  14759.                `ssl_cypher'                  
  14760.                `x509_issuer'                 
  14761.                `x509_cubject'                
  14762.                `max_questions'               
  14763.                `max_updates'                 
  14764.                `max_connections'               
  14765.  
  14766. For the second stage of access control (request verification), the
  14767. server may, if the request involves tables, additionally consult the
  14768. `tables_priv' and `columns_priv' tables.  The fields in these tables
  14769. are shown here:
  14770.  
  14771. *Table name*   *tables_priv*  *columns_priv*
  14772. *Scope         `Host'         `Host'
  14773. fields*                       
  14774.                `Db'           `Db'
  14775.                `User'         `User'
  14776.                `Table_name'   `Table_name'
  14777.                               `Column_name'
  14778. *Privilege     `Table_priv'   `Column_priv'
  14779. fields*                       
  14780.                `Column_priv'  
  14781. *Other         `Timestamp'    `Timestamp'
  14782. fields*                       
  14783.                `Grantor'      
  14784.  
  14785. Each grant table contains scope fields and privilege fields.
  14786.  
  14787. Scope fields determine the scope of each entry in the tables, that is,
  14788. the context in which the entry applies.  For example, a `user' table
  14789. entry with `Host' and `User' values of `'thomas.loc.gov'' and `'bob''
  14790. would be used for authenticating connections made to the server by
  14791. `bob' from the host `thomas.loc.gov'.  Similarly, a `db' table entry
  14792. with `Host', `User', and `Db' fields of `'thomas.loc.gov'', `'bob'' and
  14793. `'reports'' would be used when `bob' connects from the host
  14794. `thomas.loc.gov' to access the `reports' database.  The `tables_priv'
  14795. and `columns_priv' tables contain scope fields indicating tables or
  14796. table/column combinations to which each entry applies.
  14797.  
  14798. For access-checking purposes, comparisons of `Host' values are
  14799. case-insensitive.  `User', `Password', `Db', and `Table_name' values
  14800. are case-sensitive.  `Column_name' values are case-insensitive in MySQL
  14801. Version 3.22.12 or later.
  14802.  
  14803. Privilege fields indicate the privileges granted by a table entry, that
  14804. is, what operations can be performed.  The server combines the
  14805. information in the various grant tables to form a complete description
  14806. of a user's privileges.  The rules used to do this are described in
  14807. *Note Request access::.
  14808.  
  14809. Scope fields are strings, declared as shown here; the default value for
  14810. each is the empty string:
  14811.  
  14812. *Field name*   *Type*      *Notes*
  14813. `Host'         `CHAR(60)'  
  14814. `User'         `CHAR(16)'  
  14815. `Password'     `CHAR(16)'  
  14816. `Db'           `CHAR(64)'  (`CHAR(60)' for the `tables_priv' and
  14817.                            `columns_priv' tables)
  14818. `Table_name'   `CHAR(60)'  
  14819. `Column_name'  `CHAR(60)'  
  14820.  
  14821. In the `user', `db' and `host' tables, all privilege fields are
  14822. declared as `ENUM('N','Y')'--each can have a value of `'N'' or `'Y'',
  14823. and the default value is `'N''.
  14824.  
  14825. In the `tables_priv' and `columns_priv' tables, the privilege fields
  14826. are declared as `SET' fields:
  14827.  
  14828. *Table      *Field      *Possible set elements*
  14829. name*       name*       
  14830. `tables_priv'`Table_priv'`'Select', 'Insert', 'Update',
  14831.                         'Delete', 'Create', 'Drop', 'Grant',
  14832.                         'References', 'Index', 'Alter''
  14833. `tables_priv'`Column_priv'`'Select', 'Insert', 'Update',
  14834.                         'References''
  14835. `columns_priv'`Column_priv'`'Select', 'Insert', 'Update',
  14836.                         'References''
  14837.  
  14838. Briefly, the server uses the grant tables like this:
  14839.  
  14840.    * The `user' table scope fields determine whether to allow or reject
  14841.      incoming connections.  For allowed connections, any privileges
  14842.      granted in the `user' table indicate the user's global (superuser)
  14843.      privileges.  These privileges apply to *all* databases on the
  14844.      server.
  14845.  
  14846.    * The `db' and `host' tables are used together:
  14847.  
  14848.         - The `db' table scope fields determine which users can access
  14849.           which databases from which hosts.  The privilege fields
  14850.           determine which operations are allowed.
  14851.  
  14852.         - The `host' table is used as an extension of the `db' table
  14853.           when you want a given `db' table entry to apply to several
  14854.           hosts.  For example, if you want a user to be able to use a
  14855.           database from several hosts in your network, leave the `Host'
  14856.           value empty in the user's `db' table entry, then populate the
  14857.           `host' table with an entry for each of those hosts.  This
  14858.           mechanism is described more detail in *Note Request access::.
  14859.  
  14860.    * The `tables_priv' and `columns_priv' tables are similar to the
  14861.      `db' table, but are more fine-grained: they apply at the table and
  14862.      column levels rather than at the database level.
  14863.  
  14864. Note that administrative privileges (`RELOAD', `SHUTDOWN', etc.) are
  14865. specified only in the `user' table.  This is because administrative
  14866. operations are operations on the server itself and are not
  14867. database-specific, so there is no reason to list such privileges in the
  14868. other grant tables.  In fact, only the `user' table need be consulted
  14869. to determine whether you can perform an administrative operation.
  14870.  
  14871. The `FILE' privilege is specified only in the `user' table, too.  It is
  14872. not an administrative privilege as such, but your ability to read or
  14873. write files on the server host is independent of the database you are
  14874. accessing.
  14875.  
  14876. The `mysqld' server reads the contents of the grant tables once, when it
  14877. starts up.  Changes to the grant tables take effect as indicated in
  14878. *Note Privilege changes::.
  14879.  
  14880. When you modify the contents of the grant tables, it is a good idea to
  14881. make sure that your changes set up privileges the way you want.  For
  14882. help in diagnosing problems, see *Note Access denied::.  For advice on
  14883. security issues, see *Note Security::.
  14884.  
  14885. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  14886. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  14887. with the `--help' option to find out how it works.  Note that
  14888. `mysqlaccess' checks access using only the `user', `db' and `host'
  14889. tables.  It does not check table- or column-level privileges.
  14890.  
  14891. Privileges Provided by MySQL
  14892. ----------------------------
  14893.  
  14894. Information about user privileges is stored in the `user', `db',
  14895. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  14896. database (that is, in the database named `mysql').  The MySQL server
  14897. reads the contents of these tables when it starts up and under the
  14898. circumstances indicated in *Note Privilege changes::.
  14899.  
  14900. The names used in this manual to refer to the privileges provided by
  14901. MySQL version 4.0.2 are shown here, along with the table column name
  14902. associated with each privilege in the grant tables and the context in
  14903. which the privilege applies:
  14904.  
  14905. *Privilege* *Column*       *Context*
  14906. `ALTER'     `Alter_priv'   tables
  14907. `DELETE'    `Delete_priv'  tables
  14908. `INDEX'     `Index_priv'   tables
  14909. `INSERT'    `Insert_priv'  tables
  14910. `SELECT'    `Select_priv'  tables
  14911. `UPDATE'    `Update_priv'  tables
  14912. `CREATE'    `Create_priv'  databases, tables, or
  14913.                            indexes
  14914. `DROP'      `Drop_priv'    databases or tables
  14915. `GRANT'     `Grant_priv'   databases or tables
  14916. `REFERENCES'`References_priv'databases or tables
  14917. `CREATE     `Create_tmp_table_priv'server administration
  14918. TEMPORARY                  
  14919. TABLES'                    
  14920. `EXECUTE'   `Execute_priv' server administration
  14921. `FILE'      `File_priv'    file access on server
  14922. `LOCK       `Lock_tables_priv'server administration
  14923. TABLES'                    
  14924. `PROCESS'   `Process_priv' server administration
  14925. `RELOAD'    `Reload_priv'  server administration
  14926. `REPLICATION`Repl_client_priv'server administration
  14927. CLIENT'                    
  14928. `REPLICATION`Repl_slave_priv'server administration
  14929. SLAVE'                     
  14930. `SHOW       `Show_db_priv' server administration
  14931. DATABASES'                 
  14932. `SHUTDOWN'  `Shutdown_priv'server administration
  14933. `SUPER'     `Super_priv'   server administration
  14934.  
  14935. The `SELECT', `INSERT', `UPDATE', and `DELETE' privileges allow you to
  14936. perform operations on rows in existing tables in a database.
  14937.  
  14938. `SELECT' statements require the `SELECT' privilege only if they
  14939. actually retrieve rows from a table.  You can execute certain `SELECT'
  14940. statements even without permission to access any of the databases on the
  14941. server.  For example, you could use the `mysql' client as a simple
  14942. calculator:
  14943.  
  14944.      mysql> SELECT 1+1;
  14945.      mysql> SELECT PI()*2;
  14946.  
  14947. The `INDEX' privilege allows you to create or drop (remove) indexes.
  14948.  
  14949. The `ALTER' privilege allows you to use `ALTER TABLE'.
  14950.  
  14951. The `CREATE' and `DROP' privileges allow you to create new databases
  14952. and tables, or to drop (remove) existing databases and tables.
  14953.  
  14954. Note that if you grant the `DROP' privilege for the `mysql' database to
  14955. a user, that user can drop the database in which the MySQL access
  14956. privileges are stored!
  14957.  
  14958. The `GRANT' privilege allows you to give to other users those
  14959. privileges you yourself possess.
  14960.  
  14961. The `FILE' privilege gives you permission to read and write files on
  14962. the server using the `LOAD DATA INFILE' and `SELECT ... INTO OUTFILE'
  14963. statements.  Any user to whom this privilege is granted can read any
  14964. world readable file accessable by the MySQL server and create a new
  14965. world readable file in any directory where the MySQL server can write.
  14966. The user can also read any file in the current database directory.  The
  14967. user can however not change any existing file.
  14968.  
  14969. The remaining privileges are used for administrative operations, which
  14970. are performed using the `mysqladmin' program.  The table here shows
  14971. which `mysqladmin' commands each administrative privilege allows you to
  14972. execute:
  14973.  
  14974. *Privilege* *Commands permitted to privilege holders*
  14975. `RELOAD'    `reload', `refresh', `flush-privileges',
  14976.             `flush-hosts', `flush-logs', and `flush-tables'
  14977. `SHUTDOWN'  `shutdown'
  14978. `PROCESS'   `processlist'
  14979. `SUPER'     `kill'
  14980.  
  14981. The `reload' command tells the server to re-read the grant tables.  The
  14982. `refresh' command flushes all tables and opens and closes the log
  14983. files.  `flush-privileges' is a synonym for `reload'.  The other
  14984. `flush-*' commands perform functions similar to `refresh' but are more
  14985. limited in scope, and may be preferable in some instances.  For example,
  14986. if you want to flush just the log files, `flush-logs' is a better choice
  14987. than `refresh'.
  14988.  
  14989. The `shutdown' command shuts down the server.
  14990.  
  14991. The `processlist' command displays information about the threads
  14992. executing within the server.  The `kill' command kills server threads.
  14993. You can always display or kill your own threads, but you need the
  14994. `PROCESS' privilege to display and `SUPER' privilege to kill threads
  14995. initiated by other users. *Note KILL::.
  14996.  
  14997. It is a good idea in general to grant privileges only to those users
  14998. who need them, but you should exercise particular caution in granting
  14999. certain privileges:
  15000.  
  15001.    * The `GRANT' privilege allows users to give away their privileges to
  15002.      other users.  Two users with different privileges and with the
  15003.      `GRANT' privilege are able to combine privileges.
  15004.  
  15005.    * The `ALTER' privilege may be used to subvert the privilege system
  15006.      by renaming tables.
  15007.  
  15008.    * The `FILE' privilege can be abused to read any world-readable file
  15009.      on the server or any file in the current database directory on the
  15010.      server into a database table, the contents of which can then be
  15011.      accessed using `SELECT'.
  15012.  
  15013.    * The `SHUTDOWN' privilege can be abused to deny service to other
  15014.      users entirely, by terminating the server.
  15015.  
  15016.    * The `PROCESS' privilege can be used to view the plain text of
  15017.      currently executing queries, including queries that set or change
  15018.      passwords.
  15019.  
  15020.    * Privileges on the `mysql' database can be used to change passwords
  15021.      and other access privilege information.  (Passwords are stored
  15022.      encrypted, so a malicious user cannot simply read them to know the
  15023.      plain text password.)  If they can access the `mysql.user' password
  15024.      column, they can use it to log into the MySQL server for the given
  15025.      user.  (With sufficient privileges, the same user can replace a
  15026.      password with a different one.)
  15027.  
  15028. There are some things that you cannot do with the MySQL privilege
  15029. system:
  15030.  
  15031.    * You cannot explicitly specify that a given user should be denied
  15032.      access.  That is, you cannot explicitly match a user and then
  15033.      refuse the connection.
  15034.  
  15035.    * You cannot specify that a user has privileges to create or drop
  15036.      tables in a database but not to create or drop the database itself.
  15037.  
  15038. Connecting to the MySQL Server
  15039. ------------------------------
  15040.  
  15041. MySQL client programs generally require that you specify connection
  15042. parameters when you want to access a MySQL server: the host you want to
  15043. connect to, your user name, and your password.  For example, the
  15044. `mysql' client can be started like this (optional arguments are enclosed
  15045. between `[' and `]'):
  15046.  
  15047.      shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
  15048.  
  15049. Alternate forms of the `-h', `-u', and `-p' options are
  15050. `--host=host_name', `--user=user_name', and `--password=your_pass'.
  15051. Note that there is _no space_ between `-p' or `--password=' and the
  15052. password following it.
  15053.  
  15054. *Note*: Specifying a password on the command-line is not secure!  Any
  15055. user on your system may then find out your password by typing a command
  15056. like: `ps auxww'.  *Note Option files::.
  15057.  
  15058. `mysql' uses default values for connection parameters that are missing
  15059. from the command-line:
  15060.  
  15061.    * The default hostname is `localhost'.
  15062.  
  15063.    * The default user name is your Unix login name.
  15064.  
  15065.    * No password is supplied if `-p' is missing.
  15066.  
  15067. Thus, for a Unix user `joe', the following commands are equivalent:
  15068.  
  15069.      shell> mysql -h localhost -u joe
  15070.      shell> mysql -h localhost
  15071.      shell> mysql -u joe
  15072.      shell> mysql
  15073.  
  15074. Other MySQL clients behave similarly.
  15075.  
  15076. On Unix systems, you can specify different default values to be used
  15077. when you make a connection, so that you need not enter them on the
  15078. command-line each time you invoke a client program.  This can be done
  15079. in a couple of ways:
  15080.  
  15081.    * You can specify connection parameters in the `[client]' section of
  15082.      the `.my.cnf' configuration file in your home directory.  The
  15083.      relevant section of the file might look like this:
  15084.  
  15085.           [client]
  15086.           host=host_name
  15087.           user=user_name
  15088.           password=your_pass
  15089.  
  15090.      *Note Option files::.
  15091.  
  15092.    * You can specify connection parameters using environment variables.
  15093.      The host can be specified for `mysql' using `MYSQL_HOST'.  The
  15094.      MySQL user name can be specified using `USER' (this is for Windows
  15095.      only).  The password can be specified using `MYSQL_PWD' (but this
  15096.      is insecure; see the next section).  *Note Environment variables::.
  15097.  
  15098. Access Control, Stage 1: Connection Verification
  15099. ------------------------------------------------
  15100.  
  15101. When you attempt to connect to a MySQL server, the server accepts or
  15102. rejects the connection based on your identity and whether you can
  15103. verify your identity by supplying the correct password.  If not, the
  15104. server denies access to you completely.  Otherwise, the server accepts
  15105. the connection, then enters Stage 2 and waits for requests.
  15106.  
  15107. Your identity is based on two pieces of information:
  15108.  
  15109.    * The host from which you connect
  15110.  
  15111.    * Your MySQL user name
  15112.  
  15113. Identity checking is performed using the three `user' table scope fields
  15114. (`Host', `User', and `Password').  The server accepts the connection
  15115. only if a `user' table entry matches your hostname and user name, and
  15116. you supply the correct password.
  15117.  
  15118. Values in the `user' table scope fields may be specified as follows:
  15119.  
  15120.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  15121.      to indicate the local host.
  15122.  
  15123.    * You can use the wildcard characters `%' and `_' in the `Host'
  15124.      field.
  15125.  
  15126.    * A `Host' value of `'%'' matches any hostname.
  15127.  
  15128.    * A blank `Host' value means that the privilege should be anded with
  15129.      the entry in the `host' table that matches the given host name.
  15130.      You can find more information about this in the next chapter.
  15131.  
  15132.    * As of MySQL Version 3.23, for `Host' values specified as IP
  15133.      numbers, you can specify a netmask indicating how many address
  15134.      bits to use for the network number. For example:
  15135.  
  15136.           mysql> GRANT ALL PRIVILEGES ON db.*
  15137.               -> TO david@'192.58.197.0/255.255.255.0';
  15138.  
  15139.      This will allow everyone to connect from an IP where the following
  15140.      is true:
  15141.  
  15142.           user_ip & netmask = host_ip.
  15143.  
  15144.      In the above example all IP:s in the interval 192.58.197.0 -
  15145.      192.58.197.255 can connect to the MySQL server.
  15146.  
  15147.    * Wildcard characters are not allowed in the `User' field, but you
  15148.      can specify a blank value, which matches any name.  If the `user'
  15149.      table entry that matches an incoming connection has a blank user
  15150.      name, the user is considered to be the anonymous user (the user
  15151.      with no name), rather than the name that the client actually
  15152.      specified.  This means that a blank user name is used for all
  15153.      further access checking for the duration of the connection (that
  15154.      is, during Stage 2).
  15155.  
  15156.    * The `Password' field can be blank.  This does not mean that any
  15157.      password matches, it means the user must connect without
  15158.      specifying a password.
  15159.  
  15160. Non-blank `Password' values represent encrypted passwords.  MySQL does
  15161. not store passwords in plaintext form for anyone to see.  Rather, the
  15162. password supplied by a user who is attempting to connect is encrypted
  15163. (using the `PASSWORD()' function). The encrypted password is then used
  15164. when the client/server is checking if the password is correct. (This is
  15165. done without the encrypted password ever traveling over the
  15166. connection.)  Note that from MySQL's point of view the encrypted
  15167. password is the REAL password, so you should not give anyone access to
  15168. it!  In particular, don't give normal users read access to the tables
  15169. in the `mysql' database!  From version 4.1, MySQL employs a different
  15170. password and login mechanism that is secure even if TCP/IP packets are
  15171. sniffed and/or the mysql database is captured.
  15172.  
  15173. The examples here show how various combinations of `Host' and `User'
  15174. values in `user' table entries apply to incoming connections:
  15175.  
  15176. `Host' *value*            `User'      *Connections matched by entry*
  15177.                           *value*     
  15178. `'thomas.loc.gov''        `'fred''    `fred', connecting from
  15179.                                       `thomas.loc.gov'
  15180. `'thomas.loc.gov''        `'''        Any user, connecting from
  15181.                                       `thomas.loc.gov'
  15182. `'%''                     `'fred''    `fred', connecting from any host
  15183. `'%''                     `'''        Any user, connecting from any host
  15184. `'%.loc.gov''             `'fred''    `fred', connecting from any host in
  15185.                                       the `loc.gov' domain
  15186. `'x.y.%''                 `'fred''    `fred', connecting from `x.y.net',
  15187.                                       `x.y.com',`x.y.edu', etc. (this is
  15188.                                       probably not useful)
  15189. `'144.155.166.177''       `'fred''    `fred', connecting from the host
  15190.                                       with IP address `144.155.166.177'
  15191. `'144.155.166.%''         `'fred''    `fred', connecting from any host in
  15192.                                       the `144.155.166' class C subnet
  15193. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  15194.  
  15195. Because you can use IP wildcard values in the `Host' field (for example,
  15196. `'144.155.166.%'' to match every host on a subnet), there is the
  15197. possibility that someone might try to exploit this capability by naming
  15198. a host `144.155.166.somewhere.com'.  To foil such attempts, MySQL
  15199. disallows matching on hostnames that start with digits and a dot. Thus,
  15200. if you have a host named something like `1.2.foo.com', its name will
  15201. never match the `Host' column of the grant tables.  Only an IP number
  15202. can match an IP wildcard value.
  15203.  
  15204. An incoming connection may be matched by more than one entry in the
  15205. `user' table.  For example, a connection from `thomas.loc.gov' by
  15206. `fred' would be matched by several of the entries just shown above.  How
  15207. does the server choose which entry to use if more than one matches?  The
  15208. server resolves this question by sorting the `user' table after reading
  15209. it at startup time, then looking through the entries in sorted order
  15210. when a user attempts to connect.  The first matching entry is the one
  15211. that is used.
  15212.  
  15213. `user' table sorting works as follows.  Suppose the `user' table looks
  15214. like this:
  15215.  
  15216.      +-----------+----------+-
  15217.      | Host      | User     | ...
  15218.      +-----------+----------+-
  15219.      | %         | root     | ...
  15220.      | %         | jeffrey  | ...
  15221.      | localhost | root     | ...
  15222.      | localhost |          | ...
  15223.      +-----------+----------+-
  15224.  
  15225. When the server reads in the table, it orders the entries with the
  15226. most-specific `Host' values first (`'%'' in the `Host' column means
  15227. "any host" and is least specific).  Entries with the same `Host' value
  15228. are ordered with the most-specific `User' values first (a blank `User'
  15229. value means "any user" and is least specific).  The resulting sorted
  15230. `user' table looks like this:
  15231.  
  15232.      +-----------+----------+-
  15233.      | Host      | User     | ...
  15234.      +-----------+----------+-
  15235.      | localhost | root     | ...
  15236.      | localhost |          | ...
  15237.      | %         | jeffrey  | ...
  15238.      | %         | root     | ...
  15239.      +-----------+----------+-
  15240.  
  15241. When a connection is attempted, the server looks through the sorted
  15242. entries and uses the first match found.  For a connection from
  15243. `localhost' by `jeffrey', the entries with `'localhost'' in the `Host'
  15244. column match first.  Of those, the entry with the blank user name
  15245. matches both the connecting hostname and user name.  (The
  15246. `'%'/'jeffrey'' entry would have matched, too, but it is not the first
  15247. match in the table.)
  15248.  
  15249. Here is another example.  Suppose the `user' table looks like this:
  15250.  
  15251.      +----------------+----------+-
  15252.      | Host           | User     | ...
  15253.      +----------------+----------+-
  15254.      | %              | jeffrey  | ...
  15255.      | thomas.loc.gov |          | ...
  15256.      +----------------+----------+-
  15257.  
  15258. The sorted table looks like this:
  15259.  
  15260.      +----------------+----------+-
  15261.      | Host           | User     | ...
  15262.      +----------------+----------+-
  15263.      | thomas.loc.gov |          | ...
  15264.      | %              | jeffrey  | ...
  15265.      +----------------+----------+-
  15266.  
  15267. A connection from `thomas.loc.gov' by `jeffrey' is matched by the first
  15268. entry, whereas a connection from `whitehouse.gov' by `jeffrey' is
  15269. matched by the second.
  15270.  
  15271. A common misconception is to think that for a given user name, all
  15272. entries that explicitly name that user will be used first when the
  15273. server attempts to find a match for the connection.  This is simply not
  15274. true.  The previous example illustrates this, where a connection from
  15275. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  15276. containing `'jeffrey'' as the `User' field value, but by the entry with
  15277. no user name!
  15278.  
  15279. If you have problems connecting to the server, print out the `user'
  15280. table and sort it by hand to see where the first match is being made.
  15281. If connection was successful, but your privileges are not what you
  15282. expected you may use `CURRENT_USER()' function (new in version 4.0.6)
  15283. to see what user/host combination your connection actually matched.
  15284. *Note `CURRENT_USER()': Miscellaneous functions.
  15285.  
  15286. Access Control, Stage 2: Request Verification
  15287. ---------------------------------------------
  15288.  
  15289. Once you establish a connection, the server enters Stage 2.  For each
  15290. request that comes in on the connection, the server checks whether you
  15291. have sufficient privileges to perform it, based on the type of
  15292. operation you wish to perform.  This is where the privilege fields in
  15293. the grant tables come into play.  These privileges can come from any of
  15294. the `user', `db', `host', `tables_priv', or `columns_priv' tables.  The
  15295. grant tables are manipulated with `GRANT' and `REVOKE' commands.  *Note
  15296. `GRANT': GRANT.  (You may find it helpful to refer to *Note
  15297. Privileges::, which lists the fields present in each of the grant
  15298. tables.)
  15299.  
  15300. The `user' table grants privileges that are assigned to you on a global
  15301. basis and that apply no matter what the current database is.  For
  15302. example, if the `user' table grants you the `DELETE' privilege, you can
  15303. delete rows from any database on the server host!  In other words,
  15304. `user' table privileges are superuser privileges.  It is wise to grant
  15305. privileges in the `user' table only to superusers such as server or
  15306. database administrators.  For other users, you should leave the
  15307. privileges in the `user' table set to `'N'' and grant privileges on a
  15308. database-specific basis only, using the `db' and `host' tables.
  15309.  
  15310. The `db' and `host' tables grant database-specific privileges.  Values
  15311. in the scope fields may be specified as follows:
  15312.  
  15313.    * The wildcard characters `%' and `_' can be used in the `Host' and
  15314.      `Db' fields of either table. If you wish to use for instance a `_'
  15315.      character as part of a database name, specify it as `\_' in the
  15316.      `GRANT' command.
  15317.  
  15318.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  15319.      `Host' value in the `db' table means "consult the `host' table for
  15320.      further information."
  15321.  
  15322.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  15323.  
  15324.    * A `'%'' or blank `Db' value in either table means "any database."
  15325.  
  15326.    * A blank `User' value in either table matches the anonymous user.
  15327.  
  15328. The `db' and `host' tables are read in and sorted when the server
  15329. starts up (at the same time that it reads the `user' table).  The `db'
  15330. table is sorted on the `Host', `Db', and `User' scope fields, and the
  15331. `host' table is sorted on the `Host' and `Db' scope fields.  As with
  15332. the `user' table, sorting puts the most-specific values first and
  15333. least-specific values last, and when the server looks for matching
  15334. entries, it uses the first match that it finds.
  15335.  
  15336. The `tables_priv' and `columns_priv' tables grant table- and
  15337. column-specific privileges.  Values in the scope fields may be
  15338. specified as follows:
  15339.  
  15340.    * The wildcard characters `%' and `_' can be used in the `Host'
  15341.      field of either table.
  15342.  
  15343.    * A `'%'' or blank `Host' value in either table means "any host."
  15344.  
  15345.    * The `Db', `Table_name' and `Column_name' fields cannot contain
  15346.      wildcards or be blank in either table.
  15347.  
  15348. The `tables_priv' and `columns_priv' tables are sorted on the `Host',
  15349. `Db', and `User' fields.  This is similar to `db' table sorting,
  15350. although the sorting is simpler because only the `Host' field may
  15351. contain wildcards.
  15352.  
  15353. The request verification process is described here.  (If you are
  15354. familiar with the access-checking source code, you will notice that the
  15355. description here differs slightly from the algorithm used in the code.
  15356. The description is equivalent to what the code actually does; it
  15357. differs only to make the explanation simpler.)
  15358.  
  15359. For administrative requests (`SHUTDOWN', `RELOAD', etc.), the server
  15360. checks only the `user' table entry, because that is the only table that
  15361. specifies administrative privileges.  Access is granted if the entry
  15362. allows the requested operation and denied otherwise.  For example, if
  15363. you want to execute `mysqladmin shutdown' but your `user' table entry
  15364. doesn't grant the `SHUTDOWN' privilege to you, access is denied without
  15365. even checking the `db' or `host' tables.  (They contain no
  15366. `Shutdown_priv' column, so there is no need to do so.)
  15367.  
  15368. For database-related requests (`INSERT', `UPDATE', etc.), the server
  15369. first checks the user's global (superuser) privileges by looking in the
  15370. `user' table entry.  If the entry allows the requested operation,
  15371. access is granted.  If the global privileges in the `user' table are
  15372. insufficient, the server determines the user's database-specific
  15373. privileges by checking the `db' and `host' tables:
  15374.  
  15375.   1. The server looks in the `db' table for a match on the `Host',
  15376.      `Db', and `User' fields.  The `Host' and `User' fields are matched
  15377.      to the connecting user's hostname and MySQL user name.  The `Db'
  15378.      field is matched to the database the user wants to access.  If
  15379.      there is no entry for the `Host' and `User', access is denied.
  15380.  
  15381.   2. If there is a matching `db' table entry and its `Host' field is
  15382.      not blank, that entry defines the user's database-specific
  15383.      privileges.
  15384.  
  15385.   3. If the matching `db' table entry's `Host' field is blank, it
  15386.      signifies that the `host' table enumerates which hosts should be
  15387.      allowed access to the database.  In this case, a further lookup is
  15388.      done in the `host' table to find a match on the `Host' and `Db'
  15389.      fields.  If no `host' table entry matches, access is denied.  If
  15390.      there is a match, the user's database-specific privileges are
  15391.      computed as the intersection (*not* the union!) of the privileges
  15392.      in the `db' and `host' table entries, that is, the privileges that
  15393.      are `'Y'' in both entries.  (This way you can grant general
  15394.      privileges in the `db' table entry and then selectively restrict
  15395.      them on a host-by-host basis using the `host' table entries.)
  15396.  
  15397. After determining the database-specific privileges granted by the `db'
  15398. and `host' table entries, the server adds them to the global privileges
  15399. granted by the `user' table.  If the result allows the requested
  15400. operation, access is granted.  Otherwise, the server checks the user's
  15401. table and column privileges in the `tables_priv' and `columns_priv'
  15402. tables and adds those to the user's privileges.  Access is allowed or
  15403. denied based on the result.
  15404.  
  15405. Expressed in boolean terms, the preceding description of how a user's
  15406. privileges are calculated may be summarised like this:
  15407.  
  15408.      global privileges
  15409.      OR (database privileges AND host privileges)
  15410.      OR table privileges
  15411.      OR column privileges
  15412.  
  15413. It may not be apparent why, if the global `user' entry privileges are
  15414. initially found to be insufficient for the requested operation, the
  15415. server adds those privileges to the database-, table-, and
  15416. column-specific privileges later. The reason is that a request might
  15417. require more than one type of privilege.  For example, if you execute
  15418. an `INSERT ...  SELECT' statement, you need both `INSERT' and `SELECT'
  15419. privileges.  Your privileges might be such that the `user' table entry
  15420. grants one privilege and the `db' table entry grants the other.  In
  15421. this case, you have the necessary privileges to perform the request,
  15422. but the server cannot tell that from either table by itself; the
  15423. privileges granted by the entries in both tables must be combined.
  15424.  
  15425. The `host' table can be used to maintain a list of secure servers.
  15426.  
  15427. At TcX, the `host' table contains a list of all machines on the local
  15428. network. These are granted all privileges.
  15429.  
  15430. You can also use the `host' table to indicate hosts that are *not*
  15431. secure.  Suppose you have a machine `public.your.domain' that is located
  15432. in a public area that you do not consider secure.  You can allow access
  15433. to all hosts on your network except that machine by using `host' table
  15434. entries like this:
  15435.  
  15436.      +--------------------+----+-
  15437.      | Host               | Db | ...
  15438.      +--------------------+----+-
  15439.      | public.your.domain | %  | ... (all privileges set to 'N')
  15440.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  15441.      +--------------------+----+-
  15442.  
  15443. Naturally, you should always test your entries in the grant tables (for
  15444. example, using `mysqlaccess') to make sure your access privileges are
  15445. actually set up the way you think they are.
  15446.  
  15447. Password Hashing in MySQL 4.1
  15448. -----------------------------
  15449.  
  15450. MySQL user accounts are listed in the `user' table of the `mysql'
  15451. database. Each MySQL account is assigned a password, although what is
  15452. stored in the `Password' column of the `user' table is not the
  15453. plaintext version of the password, but a hash value computed from it.
  15454. Password hash values are computed by the `PASSWORD()' function.
  15455.  
  15456. MySQL uses passwords in two phases of client/server communication:
  15457.  
  15458.    * First, when a client attempts to connect to the server, there is an
  15459.      initial authentication step in which the client must present a
  15460.      password that matches the hash value stored in the user table for
  15461.      the account that the client wants to use.
  15462.  
  15463.    * Second, after the client connects, it may set or change the
  15464.      password hashes for accounts listed in the user table (if it has
  15465.      sufficient privileges). The client may do this by using the
  15466.      PASSWORD() function to generate a password hash, or by using the
  15467.      GRANT or SET PASSWORD statements.
  15468.  
  15469.  
  15470. In other words, the server _uses_ hash values during authentication when
  15471. a client first attempts to connect. The server _generates_ hash values
  15472. if a connected client invokes the `PASSWORD()' function or uses a
  15473. `GRANT' or `SET PASSWORD' statement to set or change a password.
  15474.  
  15475. The password hashing mechanism was updated in MySQL 4.1 to provide
  15476. better security and to reduce the risk of passwords being stolen.
  15477. However, this new mechanism is understood only by the 4.1 server and
  15478. 4.1 clients, which can result in some compatibility problems.  A 4.1
  15479. client can connect to a pre-4.1 server, because the client understands
  15480. both the old and new password hashing mechanisms. However, a pre-4.1
  15481. client that attempts to connect to a 4.1 server may run into
  15482. difficulties.  For example, a 4.0 `mysql' client that attempts to
  15483. connect to a 4.1 server may fail with the following error message:
  15484.  
  15485.      shell> mysql
  15486.      Client does not support authentication protocol requested
  15487.      by server; consider upgrading MySQL client
  15488.  
  15489. The following discussion describes the differences between the old and
  15490. new password mechanisms, and what you should do if you upgrade your
  15491. server to 4.1 but need to maintain backward compatibility with pre-4.1
  15492. clients.
  15493.  
  15494. *Note:* This discussion contrasts 4.1 behaviour with pre-4.1 behaviour,
  15495. but the 4.1 behaviour described here actually begins with 4.1.1. MySQL
  15496. 4.1.0 is an "odd" release because it has a slightly different mechanism
  15497. than that implemented in 4.1.1 and up.  Differences between 4.1.0 and
  15498. more recent versions are described later.
  15499.  
  15500. Prior to MySQL 4.1, password hashes computed by the `PASSWORD()'
  15501. function are 16 bytes long.  Such hashes look like this:
  15502.  
  15503.      mysql> SELECT PASSWORD('mypass');
  15504.      +--------------------+
  15505.      | PASSWORD('mypass') |
  15506.      +--------------------+
  15507.      | 6f8c114b58f2ce9e   |
  15508.      +--------------------+
  15509.  
  15510. The `Password' column of the `user' table (in which these hashes are
  15511. stored) also is 16 bytes long before MySQL 4.1.
  15512.  
  15513. As of MySQL 4.1, the `PASSWORD()' function has been modified to produce
  15514. a longer 41-byte hash value:
  15515.  
  15516.      mysql> SELECT PASSWORD('mypass');
  15517.      +-----------------------------------------------+
  15518.      | PASSWORD('mypass')                            |
  15519.      +-----------------------------------------------+
  15520.      | *43c8aa34cdc98eddd3de1fe9a9c2c2a9f92bb2098d75 |
  15521.      +-----------------------------------------------+
  15522.  
  15523. Accordingly, the `Password' column in the `user' table also must be 41
  15524. bytes long to store these values:
  15525.  
  15526.    * If you perform a new installation of MySQL 4.1, the `Password'
  15527.      column will be made 41 bytes long automatically.
  15528.  
  15529.    * If you upgrade an older installation to 4.1, you should run the
  15530.      `mysql_fix_privilege_tables' script to update the length of the
  15531.      `Password' column from 16 to 41 bytes. (The script does not change
  15532.      existing password values, which remain 16 bytes long.)
  15533.  
  15534.  
  15535. A widened `Password' column can store password hashes in both the old
  15536. and new formats. The format of any given password hash value can be
  15537. determined two ways:
  15538.  
  15539.    * The obvious difference is the length (16 bytes versus 41 bytes)
  15540.  
  15541.    * A second difference is that password hashes in the new format
  15542.      always begin with a `*' character, whereas passwords in the old
  15543.      format never do
  15544.  
  15545.  
  15546. The longer password hash format has better cryptographic properties, and
  15547. client authentication based on long hashes is more secure than that
  15548. based on the older short hashes.
  15549.  
  15550. The differences between short and long password hashes are relevant
  15551. both for how the server uses passwords during authentication and for
  15552. how it generates password hashes for connected clients that perform
  15553. password-changing operations.
  15554.  
  15555. The way in which the server uses password hashes during authentication
  15556. is affected by the width of the Password column:
  15557.  
  15558.    * If the column is narrow, only short-hash authentication is used.
  15559.  
  15560.    * If the column is wide, it can hold either short or long hashes, and
  15561.      the server can use either format:
  15562.  
  15563.         * Pre-4.1 clients can connect, though because they know only
  15564.           about the old hashing mechanism, they can authenticate only
  15565.           for accounts that have short hashes.
  15566.  
  15567.         * 4.1 clients can authenticate for accounts that have short or
  15568.           long hashes.
  15569.  
  15570.  
  15571.  
  15572. For short-hash accounts, the authentication process is actually a bit
  15573. more secure for 4.1 clients than for older clients.  In terms of
  15574. security, the gradient from least to most secure is:
  15575.  
  15576.    * Pre-4.1 client authenticating for account with short password hash
  15577.  
  15578.    * 4.1 client authenticating for account with short password hash
  15579.  
  15580.    * 4.1 client authenticating for account with long password hash
  15581.  
  15582.  
  15583. The way in which the server generates password hashes for connected
  15584. clients is affected by the width of the `Password' column and by the
  15585. `--old-passwords' option.  A 4.1 server generates long hashes only if
  15586. certain conditions are met: The `Password' column must be wide enough
  15587. to hold long values and the `--old-passwords' option must not be given.
  15588. These conditions apply as follows:
  15589.  
  15590.    * The `Password' column must be wide enough to hold long hashes (41
  15591.      bytes).  If the column has not been updated and still has the
  15592.      pre-4.1 width (16 bytes), the server notices that long hashes
  15593.      cannot fit into it and generates only short hashes when a client
  15594.      performs password-changing operations using `PASSWORD()', `GRANT',
  15595.      or `SET PASSWORD'.  (This behaviour occurs if you have upgraded to
  15596.      4.1 but have not run the `mysql_fix_privilege_tables' script to
  15597.      widen the `Password' column.)
  15598.  
  15599.    * If the `Password' column is wide, it can store either short or long
  15600.      password hashes. In this case, `PASSWORD()', `GRANT', and `SET
  15601.      PASSWORD' will generate long hashes unless the server was started
  15602.      with the `--old-passwords' option. This option forces the server
  15603.      to generate short passsword hashes instead.
  15604.  
  15605.  
  15606. The purpose of the `--old-passwords' option is to allow you to maintain
  15607. backward compatibility with pre-4.1 clients under circumstances where
  15608. the server would otherwise generate long password hashes. It doesn't
  15609. affect authentication (4.1 clients can still use accounts that have
  15610. long password hashes), but it does prevent creation of a long password
  15611. hash in the `user' table as the result of a password-changing
  15612. operation. Were that to occur, the account no longer could be used by
  15613. pre-4.1 clients. Without the `--old-passwords' option, the following
  15614. scenario is possible:
  15615.  
  15616.    * An old client connects to an account that has a short password
  15617.      hash.
  15618.  
  15619.    * The client changes the account's password. Without
  15620.      `--old-passwords', this results in the account having a long
  15621.      password hash.
  15622.  
  15623.    * The next time the old client attempts to connect to the account, it
  15624.      cannot, because the account now requires the new hashing mechanism
  15625.      during authentication. (Once an account has a long password hash in
  15626.      the user table, only 4.1 clients can authenticate for it, because
  15627.      pre-4.1 clients do not understand long hashes.)
  15628.  
  15629.  
  15630. This scenario illustrates that it is dangerous to run a 4.1 server
  15631. without using the `--old-passwords' option if you must support older
  15632. pre-4.1 clients. By running the server with `--old-passwords',
  15633. password-changing operations will not generate long password hashes and
  15634. thus do not cause accounts to become inaccessible to older clients.
  15635. (Those clients cannot inadvertently lock themselves out by changing
  15636. their password and ending up with a long password hash.)
  15637.  
  15638. The downside of the `--old-passwords' option is that any passwords you
  15639. create or change will use short hashes, even for 4.1 clients. Thus, you
  15640. lose the additional security provided by long password hashes. If you
  15641. want to create an account that has a long hash (for example, for use by
  15642. 4.1 clients), you must do so while running the server without
  15643. `--old-passwords'.
  15644.  
  15645. The following scenarios are possible for running a 4.1 server:
  15646.  
  15647. Scenario 1) Narrow `Password' column in user table
  15648.  
  15649.    * Only short hashes can be stored in the `Password' column.
  15650.  
  15651.    * The server uses only short hashes during client authentication.
  15652.  
  15653.    * For connected clients, password hash-generating operations
  15654.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  15655.      exclusively.  Any change to an account's password results in that
  15656.      account having a short password hash.
  15657.  
  15658.    * The `--old-passwords' option can be used but is superfluous because
  15659.      with a narrow `Password' column, the server will be generating
  15660.      short password hashes anyway.
  15661.  
  15662.  
  15663. Scenario 2) Long `Password' column; server not started with
  15664. `--old-passwords' option
  15665.  
  15666.    * Short or long hashes can be stored in the `Password' column.
  15667.  
  15668.    * 4.1 clients can authenticate for accounts that have short or long
  15669.      hashes.
  15670.  
  15671.    * Pre-4.1 clients can authenticate only for accounts that have short
  15672.      hashes.
  15673.  
  15674.    * For connected clients, password hash-generating operations
  15675.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use long hashes
  15676.      exclusively.  Any change to an account's password results in that
  15677.      account having a long password hash.
  15678.  
  15679.    * `OLD_PASSWORD()' may be used to explicitly generate a short hash.
  15680.      For example, to assign an account a short password, use `UPDATE'
  15681.      as follows:
  15682.  
  15683.           mysql> UPDATE user SET Password = OLD_PASSWORD('mypass')
  15684.               -> WHERE Host = 'some_host' AND User = 'some_user';
  15685.           mysql> FLUSH PRIVILEGES;
  15686.  
  15687.  
  15688. As indicated earlier, a danger in this scenario is that it is possible
  15689. for accounts that have a short password hash to become inaccessible to
  15690. pre-4.1 clients. Any change to such an account's password made via
  15691. `GRANT', `SET PASSWORD', or `PASSWORD()' results in the account being
  15692. given a long password hash, and from that point on, no pre-4.1 client
  15693. can authenticate to that account until the client upgrades to 4.1.
  15694.  
  15695. Scenario 3) Long `Password' column; server started with
  15696. `--old-passwords' option
  15697.  
  15698.    * Short or long hashes can be stored in the `Password' column.
  15699.  
  15700.    * 4.1 clients can authenticate for accounts that have short or long
  15701.      hashes (but note that it is possible to create long hashes only
  15702.      when the server is started without `--old-passwords').
  15703.  
  15704.    * Pre-4.1 clients can authenticate only for accounts that have short
  15705.      hashes.
  15706.  
  15707.    * For connected clients, password hash-generating operations
  15708.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  15709.      exclusively.  Any change to an account's password results in that
  15710.      account having a short password hash.
  15711.  
  15712.  
  15713. In this scenario, you cannot create accounts that have long password
  15714. hashes, because `--old-passwords' prevents generation of long hashes.
  15715. Also, if you create an account with a long hash before using the
  15716. `--old-passwords' option, changing the account's password while
  15717. `--old-passwords' is in effect results in the account being given a
  15718. short password, causing it to lose the security benefits of a longer
  15719. hash.
  15720.  
  15721. The disadvantages for these scenarios may be summarized as follows:
  15722.  
  15723. Scenario 1) You cannot take advantage of longer hashes that provide more
  15724. secure authentication.
  15725.  
  15726. Scenario 2) Accounts with short hashes become inaccessible to pre-4.1
  15727. clients if you change their passwords without explicitly using
  15728. `OLD_PASSWORD()'.
  15729.  
  15730. Scenario 3) `--old-passwords' prevents accounts with short hashes from
  15731. becoming inaccessible, but password-changing operations cause accounts
  15732. with long hashes to revert to short hashes, and you cannot change them
  15733. back to long hashes while `--old-passwords' is in effect.
  15734.  
  15735. Implications of Password Hashing Changes for Application Programs
  15736. -----------------------------------------------------------------
  15737.  
  15738. An upgrade to MySQL 4.1 can cause a compatibility issue for
  15739. applications that use `PASSWORD()' to generate passwords for their own
  15740. purposes. (Applications really should not do this, because `PASSWORD()'
  15741. should be used only to manage passwords for MySQL accounts. But some
  15742. applications use `PASSWORD()' for their own purposes anyway.)  If you
  15743. upgrade to 4.1 and run the server under conditions where it generates
  15744. long password hashes, an application that uses `PASSWORD()' for its own
  15745. passwords will break.  The recommended course of action is to modify
  15746. the application to use another function such as `SHA1()' or `MD5()' to
  15747. produce hashed values.  If that is not possible, you can use the
  15748. `OLD_PASSWORD()' function, which is provided to generate short hashes
  15749. in the old format. (But note that `OLD_PASSWORD()' may one day no
  15750. longer be supported.)
  15751.  
  15752. If the server is running under circumstances where it generates short
  15753. hashes, `OLD_PASSWORD()' is available but is equivalent to `PASSWORD()'.
  15754.  
  15755. Password hashing in MySQL 4.1.0 differs from hashing in 4.1.1 and up.
  15756. The 4.1.0 differences are:
  15757.  
  15758.    * Password hashes are 45 bytes long rather than 41 bytes.
  15759.  
  15760.    * The `PASSWORD()' function is non-repeatable.  That is, with a given
  15761.      argument `X', successive calls to `PASSWORD(X)' generate different
  15762.      results.
  15763.  
  15764.  
  15765. Causes of `Access denied' Errors
  15766. --------------------------------
  15767.  
  15768. If you encounter `Access denied' errors when you try to connect to the
  15769. MySQL server, the following list indicates some courses of action you
  15770. can take to correct the problem:
  15771.  
  15772.    * After installing MySQL, did you run the `mysql_install_db' script
  15773.      to set up the initial grant table contents?  If not, do so.  *Note
  15774.      Default privileges::.  Test the initial privileges by executing
  15775.      this command:
  15776.  
  15777.           shell> mysql -u root test
  15778.  
  15779.      The server should let you connect without error.  You should also
  15780.      make sure you have a file `user.MYD' in the MySQL database
  15781.      directory.  Ordinarily, this is `PATH/var/mysql/user.MYD', where
  15782.      `PATH' is the pathname to the MySQL installation root.
  15783.  
  15784.    * After a fresh installation, you should connect to the server and
  15785.      set up your users and their access permissions:
  15786.  
  15787.           shell> mysql -u root mysql
  15788.  
  15789.      The server should let you connect because the MySQL `root' user
  15790.      has no password initially.  That is also a security risk, so
  15791.      setting the `root' password is something you should do while
  15792.      you're setting up your other MySQL users.
  15793.  
  15794.      If you try to connect as `root' and get this error:
  15795.  
  15796.           Access denied for user: '@unknown' to database mysql
  15797.  
  15798.      this means that you don't have an entry in the `user' table with a
  15799.      `User' column value of `'root'' and that `mysqld' cannot resolve
  15800.      the hostname for your client.  In this case, you must restart the
  15801.      server with the `--skip-grant-tables' option and edit your
  15802.      `/etc/hosts' or `\windows\hosts' file to add an entry for your
  15803.      host.
  15804.  
  15805.    * If you get an error like the following:
  15806.  
  15807.           shell> mysqladmin -u root -pxxxx ver
  15808.           Access denied for user: 'root@localhost' (Using password: YES)
  15809.  
  15810.      It means that you are using an incorrect password. *Note
  15811.      Passwords::.
  15812.  
  15813.      If you have forgot the root password, you can restart `mysqld' with
  15814.      `--skip-grant-tables' to change the password.  *Note Resetting
  15815.      permissions::.
  15816.  
  15817.      If you get the above error even if you haven't specified a
  15818.      password, this means that you have an incorrect password in some
  15819.      `my.ini' file. *Note Option files::.  You can avoid using option
  15820.      files with the `--no-defaults' option, as follows:
  15821.  
  15822.           shell> mysqladmin --no-defaults -u root ver
  15823.  
  15824.    * If you updated an existing MySQL installation from a version
  15825.      earlier than Version 3.22.11 to Version 3.22.11 or later, did you
  15826.      run the `mysql_fix_privilege_tables' script?  If not, do so.  The
  15827.      structure of the grant tables changed with MySQL Version 3.22.11
  15828.      when the `GRANT' statement became functional.
  15829.  
  15830.    * If your privileges seem to have changed in the middle of a
  15831.      session, it may be that a superuser has changed them.  Reloading
  15832.      the grant tables affects new client connections, but it also
  15833.      affects existing connections as indicated in *Note Privilege
  15834.      changes::.
  15835.  
  15836.    * If you can't get your password to work, remember that you must use
  15837.      the `PASSWORD()' function if you set the password with the
  15838.      `INSERT', `UPDATE', or `SET PASSWORD' statements.  The
  15839.      `PASSWORD()' function is unnecessary if you specify the password
  15840.      using the `GRANT ... IDENTIFIED BY' statement or the `mysqladmin
  15841.      password' command.  *Note Passwords::.
  15842.  
  15843.    * `localhost' is a synonym for your local hostname, and is also the
  15844.      default host to which clients try to connect if you specify no host
  15845.      explicitly.  However, connections to `localhost' do not work if
  15846.      you are using a MySQL version prior to 3.23.27 that uses
  15847.      MIT-pthreads (`localhost' connections are made using Unix sockets,
  15848.      which were not supported by MIT-pthreads at that time).  To avoid
  15849.      this problem on such systems, you should use the `--host' option
  15850.      to name the server host explicitly.  This will make a TCP/IP
  15851.      connection to the `mysqld' server.  In this case, you must have
  15852.      your real hostname in `user' table entries on the server host.
  15853.      (This is true even if you are running a client program on the same
  15854.      host as the server.)
  15855.  
  15856.    * If you get an `Access denied' error when trying to connect to the
  15857.      database with `mysql -u user_name db_name', you may have a problem
  15858.      with the `user' table. Check this by executing `mysql -u root
  15859.      mysql' and issuing this SQL statement:
  15860.  
  15861.           mysql> SELECT * FROM user;
  15862.  
  15863.      The result should include an entry with the `Host' and `User'
  15864.      columns matching your computer's hostname and your MySQL user name.
  15865.  
  15866.    * The `Access denied' error message will tell you who you are trying
  15867.      to log in as, the host from which you are trying to connect, and
  15868.      whether or not you were using a password. Normally, you should
  15869.      have one entry in the `user' table that exactly matches the
  15870.      hostname and user name that were given in the error message. For
  15871.      example if you get an error message that contains `Using password:
  15872.      NO', this means that you tried to login without an password.
  15873.  
  15874.    * If you get the following error when you try to connect from a
  15875.      different host than the one on which the MySQL server is running,
  15876.      then there is no row in the `user' table that matches that host:
  15877.  
  15878.           Host ... is not allowed to connect to this MySQL server
  15879.  
  15880.      You can fix this by using the command-line tool `mysql' (on the
  15881.      server host!) to add a row to the `user', `db', or `host' table
  15882.      for the user/hostname combination from which you are trying to
  15883.      connect and then execute `mysqladmin flush-privileges'.  If you are
  15884.      not running MySQL Version 3.22 and you don't know the IP number or
  15885.      hostname of the machine from which you are connecting, you should
  15886.      put an entry with `'%'' as the `Host' column value in the `user'
  15887.      table and restart `mysqld' with the `--log' option on the server
  15888.      machine.  After trying to connect from the client machine, the
  15889.      information in the MySQL log will indicate how you really did
  15890.      connect.  (Then replace the `'%'' in the `user' table entry with
  15891.      the actual hostname that shows up in the log.  Otherwise, you'll
  15892.      have a system that is insecure.)
  15893.  
  15894.      Another reason for this error on Linux is that you are using a
  15895.      binary MySQL version that is compiled with a different glibc
  15896.      version than the one you are using.  In this case you should
  15897.      either upgrade your OS/glibc or download the source MySQL version
  15898.      and compile this yourself.  A source RPM is normally trivial to
  15899.      compile and install, so this isn't a big problem.
  15900.  
  15901.    * If you get an error message where the hostname is not shown or
  15902.      where the hostname is an IP, even if you try to connect with a
  15903.      hostname:
  15904.  
  15905.           shell> mysqladmin -u root -pxxxx -h some-hostname ver
  15906.           Access denied for user: 'root@' (Using password: YES)
  15907.  
  15908.      This means that MySQL got some error when trying to resolve the IP
  15909.      to a hostname.  In this case you can execute `mysqladmin
  15910.      flush-hosts' to reset the internal DNS cache. *Note DNS::.
  15911.  
  15912.      Some permanent solutions are:
  15913.  
  15914.         - Try to find out what is wrong with your DNS server and fix
  15915.           this.
  15916.  
  15917.         - Specify IPs instead of hostnames in the MySQL privilege
  15918.           tables.
  15919.  
  15920.         - Start `mysqld' with `--skip-name-resolve'.
  15921.  
  15922.         - Start `mysqld' with `--skip-host-cache'.
  15923.  
  15924.         - Connect to `localhost' if you are running the server and the
  15925.           client on the same machine.
  15926.  
  15927.         - Put the client machine names in `/etc/hosts'.
  15928.  
  15929.    * If `mysql -u root test' works but `mysql -h your_hostname -u root
  15930.      test' results in `Access denied', then you may not have the
  15931.      correct name for your host in the `user' table.  A common problem
  15932.      here is that the `Host' value in the user table entry specifies an
  15933.      unqualified hostname, but your system's name resolution routines
  15934.      return a fully qualified domain name (or vice-versa).  For
  15935.      example, if you have an entry with host `'tcx'' in the `user'
  15936.      table, but your DNS tells MySQL that your hostname is
  15937.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  15938.      the `user' table that contains the IP number of your host as the
  15939.      `Host' column value.  (Alternatively, you could add an entry to the
  15940.      `user' table with a `Host' value that contains a wildcard--for
  15941.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  15942.      *insecure* and is *not* recommended!)
  15943.  
  15944.    * If `mysql -u user_name test' works but `mysql -u user_name
  15945.      other_db_name' doesn't work, you don't have an entry for
  15946.      `other_db_name' listed in the `db' table.
  15947.  
  15948.    * If `mysql -u user_name db_name' works when executed on the server
  15949.      machine, but `mysql -h host_name -u user_name db_name' doesn't
  15950.      work when executed on another client machine, you don't have the
  15951.      client machine listed in the `user' table or the `db' table.
  15952.  
  15953.    * If you can't figure out why you get `Access denied', remove from
  15954.      the `user' table all entries that have `Host' values containing
  15955.      wildcards (entries that contain `%' or `_').  A very common error
  15956.      is to insert a new entry with `Host'=`'%'' and `User'=`'some
  15957.      user'', thinking that this will allow you to specify `localhost'
  15958.      to connect from the same machine.  The reason that this doesn't
  15959.      work is that the default privileges include an entry with
  15960.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  15961.      `Host' value `'localhost'' that is more specific than `'%'', it is
  15962.      used in preference to the new entry when connecting from
  15963.      `localhost'!  The correct procedure is to insert a second entry
  15964.      with `Host'=`'localhost'' and `User'=`'some_user'', or to remove
  15965.      the entry with `Host'=`'localhost'' and `User'=`'''.
  15966.  
  15967.    * If you get the following error, you may have a problem with the
  15968.      `db' or `host' table:
  15969.  
  15970.           Access to database denied
  15971.  
  15972.      If the entry selected from the `db' table has an empty value in the
  15973.      `Host' column, make sure there are one or more corresponding
  15974.      entries in the `host' table specifying which hosts the `db' table
  15975.      entry applies to.
  15976.  
  15977.      If you get the error when using the SQL commands `SELECT ...  INTO
  15978.      OUTFILE' or `LOAD DATA INFILE', your entry in the `user' table
  15979.      probably doesn't have the `FILE' privilege enabled.
  15980.  
  15981.    * Remember that client programs will use connection parameters
  15982.      specified in configuration files or environment variables.  *Note
  15983.      Environment variables::.  If a client seems to be sending the
  15984.      wrong default connection parameters when you don't specify them on
  15985.      the command-line, check your environment and the `.my.cnf' file in
  15986.      your home directory.  You might also check the system-wide MySQL
  15987.      configuration files, though it is far less likely that client
  15988.      connection parameters will be specified there. *Note Option
  15989.      files::.  If you get `Access denied' when you run a client without
  15990.      any options, make sure you haven't specified an old password in
  15991.      any of your option files!  *Note Option files::.
  15992.  
  15993.    * If you make changes to the grant tables directly (using an
  15994.      `INSERT' or `UPDATE' statement) and your changes seem to be
  15995.      ignored, remember that you must issue a `FLUSH PRIVILEGES'
  15996.      statement or execute a `mysqladmin flush-privileges' command to
  15997.      cause the server to re-read the privilege tables. Otherwise, your
  15998.      changes have no effect until the next time the server is
  15999.      restarted.  Remember that after you set the `root' password with
  16000.      an `UPDATE' command, you won't need to specify it until after you
  16001.      flush the privileges, because the server won't know you've changed
  16002.      the password yet!
  16003.  
  16004.    * If you have access problems with a Perl, PHP, Python, or ODBC
  16005.      program, try to connect to the server with `mysql -u user_name
  16006.      db_name' or `mysql -u user_name -pyour_pass db_name'.  If you are
  16007.      able to connect using the `mysql' client, there is a problem with
  16008.      your program and not with the access privileges.  (Note that there
  16009.      is no space between `-p' and the password; you can also use the
  16010.      `--password=your_pass' syntax to specify the password. If you use
  16011.      the `-p' option alone, MySQL will prompt you for the password.)
  16012.  
  16013.    * For testing, start the `mysqld' daemon with the
  16014.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  16015.      tables and use the `mysqlaccess' script to check whether your
  16016.      modifications have the desired effect.  When you are satisfied
  16017.      with your changes, execute `mysqladmin flush-privileges' to tell
  16018.      the `mysqld' server to start using the new grant tables.  *Note*:
  16019.      reloading the grant tables overrides the `--skip-grant-tables'
  16020.      option.  This allows you to tell the server to begin using the
  16021.      grant tables again without bringing it down and restarting it.
  16022.  
  16023.    * If everything else fails, start the `mysqld' daemon with a
  16024.      debugging option (for example, `--debug=d,general,query'). This
  16025.      will print host and user information about attempted connections,
  16026.      as well as information about each command issued. *Note Making
  16027.      trace files::.
  16028.  
  16029.    * If you have any other problems with the MySQL grant tables and
  16030.      feel you must post the problem to the mailing list, always provide
  16031.      a dump of the MySQL grant tables. You can dump the tables with the
  16032.      `mysqldump mysql' command. As always, post your problem using the
  16033.      `mysqlbug' script.  *Note Bug reports::.  In some cases you may
  16034.      need to restart `mysqld' with `--skip-grant-tables' to run
  16035.      `mysqldump'.
  16036.  
  16037. MySQL User Account Management
  16038. =============================
  16039.  
  16040. `GRANT' and `REVOKE' Syntax
  16041. ---------------------------
  16042.  
  16043.      GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
  16044.          ON {tbl_name | * | *.* | db_name.*}
  16045.          TO user_name [IDENTIFIED BY [PASSWORD] 'password']
  16046.              [, user_name [IDENTIFIED BY [PASSWORD] 'password'] ...]
  16047.          [REQUIRE
  16048.              NONE |
  16049.              [{SSL| X509}]
  16050.              [CIPHER cipher [AND]]
  16051.              [ISSUER issuer [AND]]
  16052.              [SUBJECT subject]]
  16053.          [WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR # |
  16054.                                MAX_UPDATES_PER_HOUR # |
  16055.                                MAX_CONNECTIONS_PER_HOUR #]]
  16056.      
  16057.      REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
  16058.          ON {tbl_name | * | *.* | db_name.*}
  16059.          FROM user_name [, user_name ...]
  16060.  
  16061. `GRANT' is implemented in MySQL Version 3.22.11 or later. For earlier
  16062. MySQL versions, the `GRANT' statement does nothing.
  16063.  
  16064. The `GRANT' and `REVOKE' commands allow system administrators to create
  16065. users and grant and revoke rights to MySQL users at four privilege
  16066. levels:
  16067.  
  16068. *Global level*
  16069.      Global privileges apply to all databases on a given server. These
  16070.      privileges are stored in the `mysql.user' table.  `REVOKE ALL ON
  16071.      *.*' will revoke only global privileges.
  16072.  
  16073. *Database level*
  16074.      Database privileges apply to all tables in a given database. These
  16075.      privileges are stored in the `mysql.db' and `mysql.host' tables.
  16076.      `REVOKE ALL ON db.*' will revoke only database privileges.
  16077.  
  16078. *Table level*
  16079.      Table privileges apply to all columns in a given table. These
  16080.      privileges are stored in the `mysql.tables_priv' table.  `REVOKE
  16081.      ALL ON db.table' will revoke only table privileges.
  16082.  
  16083. *Column level*
  16084.      Column privileges apply to single columns in a given table. These
  16085.      privileges are stored in the `mysql.columns_priv' table.  When
  16086.      using `REVOKE' you must specify the same columns that were granted.
  16087.  
  16088. For the `GRANT' and `REVOKE' statements, `priv_type' may be specified
  16089. as any of the following:
  16090.  
  16091. `ALL [PRIVILEGES]'     Sets all simple privileges except `WITH GRANT
  16092.                        OPTION'
  16093. `ALTER'                Allows usage of `ALTER TABLE'
  16094. `CREATE'               Allows usage of `CREATE TABLE'
  16095. `CREATE TEMPORARY      Allows usage of `CREATE TEMPORARY TABLE'
  16096. TABLES'                
  16097. `DELETE'               Allows usage of `DELETE'
  16098. `DROP'                 Allows usage of `DROP TABLE'.
  16099. `EXECUTE'              Allows the user to run stored procedures (MySQL
  16100.                        5.0)
  16101. `FILE'                 Allows usage of `SELECT ... INTO OUTFILE' and
  16102.                        `LOAD DATA INFILE'.
  16103. `INDEX'                Allows usage of `CREATE INDEX' and `DROP INDEX'
  16104. `INSERT'               Allows usage of `INSERT'
  16105. `LOCK TABLES'          Allows usage of `LOCK TABLES' on tables for which
  16106.                        one has the `SELECT' privilege.
  16107. `PROCESS'              Allows usage of `SHOW FULL PROCESSLIST'
  16108. `REFERENCES'           For the future
  16109. `RELOAD'               Allows usage of `FLUSH'
  16110. `REPLICATION CLIENT'   Gives the right to the user to ask where the
  16111.                        slaves/masters are.
  16112. `REPLICATION SLAVE'    Needed for the replication slaves (to read
  16113.                        binlogs from master).
  16114. `SELECT'               Allows usage of `SELECT'
  16115. `SHOW DATABASES'       `SHOW DATABASES' shows all databases.
  16116. `SHUTDOWN'             Allows usage of `mysqladmin shutdown'
  16117. `SUPER'                Allows one connect (once) even if max_connections
  16118.                        is reached and execute commands `CHANGE MASTER',
  16119.                        `KILL thread', `mysqladmin debug', `PURGE MASTER
  16120.                        LOGS' and `SET GLOBAL'
  16121. `UPDATE'               Allows usage of `UPDATE'
  16122. `USAGE'                Synonym for "no privileges."
  16123. `GRANT OPTION'         Synonym for `WITH GRANT OPTION'
  16124.  
  16125. `USAGE' can be used when you want to create a user that has no
  16126. privileges.
  16127.  
  16128. The privileges `CREATE TEMPORARY TABLES', `EXECUTE', `LOCK TABLES',
  16129. `REPLICATION ...', `SHOW DATABASES' and `SUPER' are new for in version
  16130. 4.0.2.  To use these new privileges after upgrading to 4.0.2, you have
  16131. to run the `mysql_fix_privilege_tables' script.
  16132.  
  16133. In older MySQL versions, the `PROCESS' privilege gives the same rights
  16134. as the new `SUPER' privilege.
  16135.  
  16136. To revoke the `GRANT' privilege from a user, use a `priv_type' value of
  16137. `GRANT OPTION':
  16138.  
  16139.      mysql> REVOKE GRANT OPTION ON ... FROM ...;
  16140.  
  16141. The only `priv_type' values you can specify for a table are `SELECT',
  16142. `INSERT', `UPDATE', `DELETE', `CREATE', `DROP', `GRANT OPTION',
  16143. `INDEX', and `ALTER'.
  16144.  
  16145. The only `priv_type' values you can specify for a column (that is, when
  16146. you use a `column_list' clause) are `SELECT', `INSERT', and `UPDATE'.
  16147.  
  16148. MySQL allows you to create database level privileges even if the
  16149. database doesn't exist, to make it easy to prepare for database usage.
  16150. Currently MySQL does however not allow one to create table level grants
  16151. if the table doesn't exist. MySQL will not automatically revoke any
  16152. privileges even if you drop a table or drop a database.
  16153.  
  16154. You can set global privileges by using `ON *.*' syntax.  You can set
  16155. database privileges by using `ON db_name.*' syntax. If you specify `ON
  16156. *' and you have a current database, you will set the privileges for
  16157. that database.  (*Warning*: if you specify `ON *' and you *don't* have
  16158. a current database, you will affect the global privileges!)
  16159.  
  16160. *Please note*: the `_' and `%' wildcards are allowed when specifying
  16161. database names in `GRANT' commands. This means that if you wish to use
  16162. for instance a `_' character as part of a database name, you should
  16163. specify it as `\_' in the `GRANT' command, to prevent the user from
  16164. being able to access additional databases matching the wildcard
  16165. pattern, for example, `GRANT ... ON `foo\_bar`.* TO ...'.
  16166.  
  16167. In order to accommodate granting rights to users from arbitrary hosts,
  16168. MySQL supports specifying the `user_name' value in the form
  16169. `user@host'.  If you want to specify a `user' string containing special
  16170. characters (such as `-'), or a `host' string containing special
  16171. characters or wildcard characters (such as `%'), you can quote the user
  16172. or host name (for example, `'test-user'@'test-hostname'').
  16173.  
  16174. You can specify wildcards in the hostname.  For example,
  16175. `user@'%.loc.gov'' applies to `user' for any host in the `loc.gov'
  16176. domain, and `user@'144.155.166.%'' applies to `user' for any host in
  16177. the `144.155.166' class C subnet.
  16178.  
  16179. The simple form `user' is a synonym for `user@"%"'.
  16180.  
  16181. MySQL doesn't support wildcards in user names.  Anonymous users are
  16182. defined by inserting entries with `User=''' into the `mysql.user' table
  16183. or creating an user with an empty name with the `GRANT' command.
  16184.  
  16185. *Note*: if you allow anonymous users to connect to the MySQL server,
  16186. you should also grant privileges to all local users as `user@localhost'
  16187. because otherwise the anonymous user entry for the local host in the
  16188. `mysql.user' table will be used when the user tries to log into the
  16189. MySQL server from the local machine!
  16190.  
  16191. You can verify if this applies to you by executing this query:
  16192.  
  16193.      mysql> SELECT Host,User FROM mysql.user WHERE User='';
  16194.  
  16195. For the moment, `GRANT' only supports host, table, database, and column
  16196. names up to 60 characters long. A user name can be up to 16 characters.
  16197.  
  16198. The privileges for a table or column are formed from the logical OR of
  16199. the privileges at each of the four privilege levels.  For example, if
  16200. the `mysql.user' table specifies that a user has a global `SELECT'
  16201. privilege, this can't be denied by an entry at the database, table, or
  16202. column level.
  16203.  
  16204. The privileges for a column can be calculated as follows:
  16205.  
  16206.      global privileges
  16207.      OR (database privileges AND host privileges)
  16208.      OR table privileges
  16209.      OR column privileges
  16210.  
  16211. In most cases, you grant rights to a user at only one of the privilege
  16212. levels, so life isn't normally as complicated as above. The details of
  16213. the privilege-checking procedure are presented in *Note Privilege
  16214. system::.
  16215.  
  16216. If you grant privileges for a user/hostname combination that does not
  16217. exist in the `mysql.user' table, an entry is added and remains there
  16218. until deleted with a `DELETE' command.  In other words, `GRANT' may
  16219. create `user' table entries, but `REVOKE' will not remove them; you
  16220. must do that explicitly using `DELETE'.
  16221.  
  16222. In MySQL Version 3.22.12 or later, if a new user is created or if you
  16223. have global grant privileges, the user's password will be set to the
  16224. password specified by the `IDENTIFIED BY' clause, if one is given.  If
  16225. the user already had a password, it is replaced by the new one.
  16226.  
  16227. If you don't want to send the password in clear text you can use the
  16228. `PASSWORD' option followed by a scrambled password from SQL function
  16229. `PASSWORD()' or the C API function `make_scrambled_password(char *to,
  16230. const char *password)'.
  16231.  
  16232. *Warning*: if you create a new user but do not specify an `IDENTIFIED
  16233. BY' clause, the user has no password.  This is insecure.
  16234.  
  16235. Passwords can also be set with the `SET PASSWORD' command.  *Note
  16236. `SET': SET OPTION.
  16237.  
  16238. If you grant privileges for a database, an entry in the `mysql.db'
  16239. table is created if needed. When all privileges for the database have
  16240. been removed with `REVOKE', this entry is deleted.
  16241.  
  16242. If a user doesn't have any privileges on a table, the table is not
  16243. displayed when the user requests a list of tables (for example, with a
  16244. `SHOW TABLES' statement). The same is true for `SHOW DATABASES'.
  16245.  
  16246. The `WITH GRANT OPTION' clause gives the user the ability to give to
  16247. other users any privileges the user has at the specified privilege
  16248. level.  You should be careful to whom you give the `GRANT' privilege,
  16249. as two users with different privileges may be able to join privileges!
  16250.  
  16251. `MAX_QUERIES_PER_HOUR #', `MAX_UPDATES_PER_HOUR #' and
  16252. `MAX_CONNECTIONS_PER_HOUR #' are new in MySQL version 4.0.2.  These
  16253. options limit the number of queries/updates and logins the user can do
  16254. during one hour. If `#' is 0 (default), then this means that there are
  16255. no limitations for that user. *Note User resources::.  Note: to specify
  16256. any of these options for an existing user without adding other
  16257. additional privileges, use `GRANT USAGE ON *.* ... WITH MAX_...'.
  16258.  
  16259. You cannot grant another user a privilege you don't have yourself; the
  16260. `GRANT' privilege allows you to give away only those privileges you
  16261. possess.
  16262.  
  16263. Be aware that when you grant a user the `GRANT' privilege at a
  16264. particular privilege level, any privileges the user already possesses
  16265. (or is given in the future!) at that level are also grantable by that
  16266. user.  Suppose you grant a user the `INSERT' privilege on a database.
  16267. If you then grant the `SELECT' privilege on the database and specify
  16268. `WITH GRANT OPTION', the user can give away not only the `SELECT'
  16269. privilege, but also `INSERT'.  If you then grant the `UPDATE' privilege
  16270. to the user on the database, the user can give away the `INSERT',
  16271. `SELECT' and `UPDATE'.
  16272.  
  16273. You should not grant `ALTER' privileges to a normal user.  If you do
  16274. that, the user can try to subvert the privilege system by renaming
  16275. tables!
  16276.  
  16277. Note that if you are using table or column privileges for even one
  16278. user, the server examines table and column privileges for all users and
  16279. this will slow down MySQL a bit.
  16280.  
  16281. When `mysqld' starts, all privileges are read into memory.  Database,
  16282. table, and column privileges take effect at once, and user-level
  16283. privileges take effect the next time the user connects.  Modifications
  16284. to the grant tables that you perform using `GRANT' or `REVOKE' are
  16285. noticed by the server immediately.  If you modify the grant tables
  16286. manually (using `INSERT', `UPDATE', etc.), you should execute a `FLUSH
  16287. PRIVILEGES' statement or run `mysqladmin flush-privileges' to tell the
  16288. server to reload the grant tables.  *Note Privilege changes::.
  16289.  
  16290. The biggest differences between the SQL standard and MySQL versions of
  16291. `GRANT' are:
  16292.  
  16293.    * In MySQL privileges are given for an username + hostname
  16294.      combination and not only for an username.
  16295.  
  16296.    * SQL-99 doesn't have global or database-level privileges, nor does
  16297.      it support all the privilege types that MySQL supports.  MySQL
  16298.      doesn't support the SQL-99 `TRIGGER' or `UNDER' privileges.
  16299.  
  16300.    * SQL-99 privileges are structured in a hierarchal manner. If you
  16301.      remove an user, all privileges the user has granted are revoked. In
  16302.      MySQL the granted privileges are not automatically revoked, but
  16303.      you have to revoke these yourself if needed.
  16304.  
  16305.    * In MySQL, if you have the `INSERT' privilege on only some of the
  16306.      columns in a table, you can execute `INSERT' statements on the
  16307.      table; the columns for which you don't have the `INSERT' privilege
  16308.      will be set to their default values. SQL-99 requires you to have
  16309.      the `INSERT' privilege on all columns.
  16310.  
  16311.    * With SQL99, when you drop a table, all privileges for the table
  16312.      are revoked.  With SQL-99, when you revoke a privilege, all
  16313.      privileges that were granted based on the privilege are also
  16314.      revoked. In MySQL, privileges can be dropped only with explicit
  16315.      `REVOKE' commands or by manipulating the MySQL grant tables.
  16316.  
  16317. For a description of using `REQUIRE', see *Note Secure connections::.
  16318.  
  16319. MySQL User Names and Passwords
  16320. ------------------------------
  16321.  
  16322. There are several distinctions between the way user names and passwords
  16323. are used by MySQL and the way they are used by Unix or Windows:
  16324.  
  16325.    * User names, as used by MySQL for authentication purposes, have
  16326.      nothing to do with Unix user names (login names) or Windows user
  16327.      names.  Most MySQL clients by default try to log in using the
  16328.      current Unix user name as the MySQL user name, but that is for
  16329.      convenience only.  Client programs allow a different name to be
  16330.      specified with the `-u' or `--user' options. This means that you
  16331.      can't make a database secure in any way unless all MySQL user
  16332.      names have passwords.  Anyone may attempt to connect to the server
  16333.      using any name, and they will succeed if they specify any name
  16334.      that doesn't have a password.
  16335.  
  16336.    * MySQL user names can be up to 16 characters long; Unix user names
  16337.      typically are limited to 8 characters.
  16338.  
  16339.    * MySQL passwords have nothing to do with Unix passwords.  There is
  16340.      no necessary connection between the password you use to log in to
  16341.      a Unix machine and the password you use to access a database on
  16342.      that machine.
  16343.  
  16344.    * MySQL encrypts passwords using a different algorithm than the one
  16345.      used during the Unix login process.  See the descriptions of the
  16346.      `PASSWORD()' and `ENCRYPT()' functions in *Note Miscellaneous
  16347.      functions::.  Note that even if the password is stored
  16348.      'scrambled', and knowing your 'scrambled' password is enough to be
  16349.      able to connect to the MySQL server!  From version 4.1, MySQL
  16350.      employs a different password and login mechanism that is secure
  16351.      even if TCP/IP packets are sniffed and/or the mysql database is
  16352.      captured.
  16353.  
  16354. MySQL users and their privileges are normally created with the `GRANT'
  16355. command. *Note GRANT::.
  16356.  
  16357. When you login to a MySQL server with a command-line client you should
  16358. specify the password with `--password=your-password'.  *Note
  16359. Connecting::.
  16360.  
  16361.      mysql --user=monty --password=guess database_name
  16362.  
  16363. If you want the client to prompt for a password, you should use
  16364. `--password' without any argument
  16365.  
  16366.      mysql --user=monty --password database_name
  16367.  
  16368. or the short form:
  16369.  
  16370.      mysql -u monty -p database_name
  16371.  
  16372. Note that in the last example the password is *not* 'database_name'.
  16373.  
  16374. If you want to use the `-p' option to supply a password you should do so
  16375. like this:
  16376.  
  16377.      mysql -u monty -pguess database_name
  16378.  
  16379. On some systems, the library call that MySQL uses to prompt for a
  16380. password will automatically cut the password to 8 characters. Internally
  16381. MySQL doesn't have any limit for the length of the password.
  16382.  
  16383. When Privilege Changes Take Effect
  16384. ----------------------------------
  16385.  
  16386. When `mysqld' starts, all grant table contents are read into memory and
  16387. become effective at that point.
  16388.  
  16389. Modifications to the grant tables that you perform using `GRANT',
  16390. `REVOKE', or `SET PASSWORD' are noticed by the server immediately.
  16391.  
  16392. If you modify the grant tables manually (using `INSERT', `UPDATE',
  16393. etc.), you should execute a `FLUSH PRIVILEGES' statement or run
  16394. `mysqladmin flush-privileges' or `mysqladmin reload' to tell the server
  16395. to reload the grant tables. Otherwise, your changes will have _no
  16396. effect_ until you restart the server. If you change the grant tables
  16397. manually but forget to reload the privileges, you will be wondering why
  16398. your changes don't seem to make any difference!
  16399.  
  16400. When the server notices that the grant tables have been changed,
  16401. existing client connections are affected as follows:
  16402.  
  16403.    * Table and column privilege changes take effect with the client's
  16404.      next request.
  16405.  
  16406.    * Database privilege changes take effect at the next `USE db_name'
  16407.      command.
  16408.  
  16409.    * Global privilege changes and password changes take effect the next
  16410.      time the client connects.
  16411.  
  16412. Setting Up the Initial MySQL Privileges
  16413. ---------------------------------------
  16414.  
  16415. After installing MySQL, you set up the initial access privileges by
  16416. running `scripts/mysql_install_db'.  *Note Quick install::.  The
  16417. `mysql_install_db' script starts up the `mysqld' server, then
  16418. initialises the grant tables to contain the following set of privileges:
  16419.  
  16420.    * The MySQL `root' user is created as a superuser who can do
  16421.      anything.  Connections must be made from the local host.
  16422.  
  16423.      *Note*: The initial `root' password is empty, so anyone can
  16424.      connect as `root' _without a password_ and be granted all
  16425.      privileges.
  16426.  
  16427.    * An anonymous user is created that can do anything with databases
  16428.      that have a name of `'test'' or starting with `'test_''.
  16429.      Connections must be made from the local host.  This means any
  16430.      local user can connect without a password and be treated as the
  16431.      anonymous user.
  16432.  
  16433.    * Other privileges are denied.  For example, normal users can't use
  16434.      `mysqladmin shutdown' or `mysqladmin processlist'.
  16435.  
  16436. *Note*: the default privileges are different for Windows.  *Note
  16437. Windows running::.
  16438.  
  16439. Because your installation is initially wide open, one of the first
  16440. things you should do is specify a password for the MySQL `root' user.
  16441. You can do this as follows (note that you specify the password using
  16442. the `PASSWORD()' function):
  16443.  
  16444.      shell> mysql -u root mysql
  16445.      mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
  16446.  
  16447. Replace `'new_password'' with the password that you want to use.
  16448.  
  16449. If you know what you are doing, you can also directly manipulate the
  16450. privilege tables:
  16451.  
  16452.      shell> mysql -u root mysql
  16453.      mysql> UPDATE user SET Password=PASSWORD('new_password')
  16454.          ->     WHERE user='root';
  16455.      mysql> FLUSH PRIVILEGES;
  16456.  
  16457. Another way to set the password is by using the `mysqladmin' command:
  16458.  
  16459.      shell> mysqladmin -u root password new_password
  16460.  
  16461. Only users with write/update access to the `mysql' database can change
  16462. the password for other users.  All normal users (not anonymous ones)
  16463. can only change their own password with either of the above commands or
  16464. with `SET PASSWORD=PASSWORD('new_password')'.
  16465.  
  16466. Note that if you update the password in the `user' table directly using
  16467. the first method, you must tell the server to re-read the grant tables
  16468. (with `FLUSH PRIVILEGES'), because the change will go unnoticed
  16469. otherwise.
  16470.  
  16471. Once the `root' password has been set, thereafter you must supply that
  16472. password when you connect to the server as `root'.
  16473.  
  16474. You may wish to leave the `root' password blank so that you don't need
  16475. to specify it while you perform additional setup or testing. However,
  16476. be sure to set it before using your installation for any real
  16477. production work.
  16478.  
  16479. See the `scripts/mysql_install_db' script to see how it sets up the
  16480. default privileges.  You can use this as a basis to see how to add
  16481. other users.
  16482.  
  16483. If you want the initial privileges to be different from those just
  16484. described above, you can modify `mysql_install_db' before you run it.
  16485.  
  16486. To re-create the grant tables completely, remove all the `.frm',
  16487. `.MYI', and `.MYD' files in the directory containing the `mysql'
  16488. database.  (This is the directory named `mysql' under the database
  16489. directory, which is listed when you run `mysqld --help'.) Then run the
  16490. `mysql_install_db' script, possibly after editing it first to have the
  16491. privileges you want.
  16492.  
  16493. *Note*: for MySQL versions older than Version 3.22.10, you should not
  16494. delete the `.frm' files.  If you accidentally do this, you should copy
  16495. them back from your MySQL distribution before running
  16496. `mysql_install_db'.
  16497.  
  16498. Adding New Users to MySQL
  16499. -------------------------
  16500.  
  16501. You can add users two different ways: by using `GRANT' statements or by
  16502. manipulating the MySQL grant tables directly.  The preferred method is
  16503. to use `GRANT' statements, because they are more concise and less
  16504. error-prone. *Note GRANT::.
  16505.  
  16506. There are also several contributed programs (such as `phpMyAdmin') that
  16507. can be used to create and administrate users.
  16508.  
  16509. The following examples show how to use the `mysql' client to set up new
  16510. users.  These examples assume that privileges are set up according to
  16511. the defaults described in the previous section.  This means that to
  16512. make changes, you must be on the same machine where `mysqld' is
  16513. running, you must connect as the MySQL `root' user, and the `root' user
  16514. must have the `INSERT' privilege for the `mysql' database and the
  16515. `RELOAD' administrative privilege.  Also, if you have changed the
  16516. `root' user password, you must specify it for the `mysql' commands here.
  16517.  
  16518. First, use the `mysql' program to connect to the server as the MySQL
  16519. `root' user:
  16520.  
  16521.      shell> mysql --user=root mysql
  16522.  
  16523. Then you can add new users by issuing `GRANT' statements:
  16524.  
  16525.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
  16526.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  16527.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@'%'
  16528.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  16529.      mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
  16530.      mysql> GRANT USAGE ON *.* TO dummy@localhost;
  16531.  
  16532. These `GRANT' statements set up three new users:
  16533.  
  16534. `monty'
  16535.      A full superuser who can connect to the server from anywhere, but
  16536.      who must use a password `'some_pass'' to do so.  Note that we must
  16537.      issue `GRANT' statements for both `monty@localhost' and
  16538.      `monty@"%"'.  If we don't add the entry with `localhost', the
  16539.      anonymous user entry for `localhost' that is created by
  16540.      `mysql_install_db' will take precedence when we connect from the
  16541.      local host, because it has a more specific `Host' field value and
  16542.      thus comes earlier in the `user' table sort order.
  16543.  
  16544. `admin'
  16545.      A user who can connect from `localhost' without a password and who
  16546.      is granted the `RELOAD' and `PROCESS' administrative privileges.
  16547.      This allows the user to execute the `mysqladmin reload',
  16548.      `mysqladmin refresh', and `mysqladmin flush-*' commands, as well as
  16549.      `mysqladmin processlist' .  No database-level privileges are
  16550.      granted.  (They can be granted later by issuing additional `GRANT'
  16551.      statements.)
  16552.  
  16553. `dummy'
  16554.      A user who can connect without a password, but only from the local
  16555.      host.  No privileges are granted--the `USAGE' privilege type
  16556.      allows you to create a user with no privileges. It has the effect
  16557.      of setting all the global privileges to `'N''.  It is assumed that
  16558.      you will grant specific privileges to the account later.
  16559.  
  16560. You can also add the same user access information directly by issuing
  16561. `INSERT' statements and then telling the server to reload the grant
  16562. tables:
  16563.  
  16564.      shell> mysql --user=root mysql
  16565.      mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
  16566.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  16567.      mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
  16568.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  16569.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  16570.          ->           Reload_priv='Y', Process_priv='Y';
  16571.      mysql> INSERT INTO user (Host,User,Password)
  16572.          ->                  VALUES('localhost','dummy','');
  16573.      mysql> FLUSH PRIVILEGES;
  16574.  
  16575. Depending on your MySQL version, you may have to use a different number
  16576. of `'Y'' values above. (Versions prior to Version 3.22.11 have fewer
  16577. privilege columns, and versions from 4.0.2 on have more.)  For the
  16578. `admin' user, the more readable extended `INSERT' syntax using `SET'
  16579. that is available starting with Version 3.22.11 is used.
  16580.  
  16581. Note that to set up a superuser, you need only create a `user' table
  16582. entry with the privilege fields set to `'Y''.  No `db' or `host' table
  16583. entries are necessary.
  16584.  
  16585. In the last `INSERT' statement (for the `dummy' user), only the `Host',
  16586. `User', and `Password' columns in the `user' table record are assigned
  16587. values. None of the privilege columns are set explicitly, so MySQL
  16588. assigns them all the default value of `'N''.  This is the same thing
  16589. that `GRANT USAGE' does.
  16590.  
  16591. The following example adds a user `custom' who can access the
  16592. `bankaccount' database only from the local host, the `expenses'
  16593. database only from the host `whitehouse.gov', and the `customer'
  16594. database only from the host `server.domain'.  He wants to use the
  16595. password `obscure' from all three hosts.
  16596.  
  16597. To set up this user's privileges using `GRANT' statements, run these
  16598. commands:
  16599.  
  16600.      shell> mysql --user=root mysql
  16601.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  16602.          ->     ON bankaccount.*
  16603.          ->     TO custom@localhost
  16604.          ->     IDENTIFIED BY 'obscure';
  16605.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  16606.          ->     ON expenses.*
  16607.          ->     TO custom@'whitehouse.gov'
  16608.          ->     IDENTIFIED BY 'obscure';
  16609.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  16610.          ->     ON customer.*
  16611.          ->     TO custom@'server.domain'
  16612.          ->     IDENTIFIED BY 'obscure';
  16613.  
  16614. To set up the user's privileges by modifying the grant tables directly,
  16615. run these commands (note the `FLUSH PRIVILEGES' at the end):
  16616.  
  16617.      shell> mysql --user=root mysql
  16618.      mysql> INSERT INTO user (Host,User,Password)
  16619.          -> VALUES('localhost','custom',PASSWORD('obscure'));
  16620.      mysql> INSERT INTO user (Host,User,Password)
  16621.          -> VALUES('whitehouse.gov','custom',PASSWORD('obscure'));
  16622.      mysql> INSERT INTO user (Host,User,Password)
  16623.          -> VALUES('server.domain','custom',PASSWORD('obscure'));
  16624.      mysql> INSERT INTO db
  16625.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  16626.          ->  Create_priv,Drop_priv)
  16627.          -> VALUES
  16628.          -> ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
  16629.      mysql> INSERT INTO db
  16630.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  16631.          ->  Create_priv,Drop_priv)
  16632.          -> VALUES
  16633.          -> ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
  16634.      mysql> INSERT INTO db
  16635.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  16636.          ->  Create_priv,Drop_priv)
  16637.          -> VALUES('server.domain','customer','custom','Y','Y','Y','Y','Y','Y');
  16638.      mysql> FLUSH PRIVILEGES;
  16639.  
  16640. As in the preceding example that used `INSERT' statements, you may need
  16641. to use a different number of `'Y'' values, depending on your version of
  16642. MySQL.
  16643.  
  16644. The first three `INSERT' statements add `user' table entries that allow
  16645. user `custom' to connect from the various hosts with the given
  16646. password, but grant no permissions to him (all privileges are set to the
  16647. default value of `'N'').  The next three `INSERT' statements add `db'
  16648. table entries that grant privileges to `custom' for the `bankaccount',
  16649. `expenses', and `customer' databases, but only when accessed from the
  16650. proper hosts.  As usual, after you modify the grant tables directly ,
  16651. you must tell the server to reload them (with `FLUSH PRIVILEGES') so
  16652. that the privilege changes take effect.
  16653.  
  16654. If you want to give a specific user access from any machine in a given
  16655. domain (for example, `mydomain.com'), you can issue a `GRANT' statement
  16656. like the following:
  16657.  
  16658.      mysql> GRANT ...
  16659.          ->     ON *.*
  16660.          ->     TO myusername@'%.mydomain.com'
  16661.          ->     IDENTIFIED BY 'mypassword';
  16662.  
  16663. To do the same thing by modifying the grant tables directly, do this:
  16664.  
  16665.      mysql> INSERT INTO user VALUES ('%.mydomain.com', 'myusername',
  16666.          ->             PASSWORD('mypassword'),...);
  16667.      mysql> FLUSH PRIVILEGES;
  16668.  
  16669. Limiting user resources
  16670. -----------------------
  16671.  
  16672. Starting from MySQL 4.0.2 one can limit certain resources per user.
  16673.  
  16674. So far, the only available method of limiting usage of MySQL server
  16675. resources has been setting the `max_user_connections' startup variable
  16676. to a non-zero value. But this method is strictly global and does not
  16677. allow for management of individual users, which could be of particular
  16678. interest to Internet Service Providers.
  16679.  
  16680. Therefore, management of three resources is introduced on the
  16681. individual user level:
  16682.  
  16683.    * Number of all queries per hour: All commands that could be run by
  16684.      a user.
  16685.  
  16686.    * Number of all updates per hour: Any command that changes any table
  16687.      or database.
  16688.  
  16689.    * Number of connections made per hour: New connections opened per
  16690.      hour.
  16691.  
  16692. A user in the aforementioned context is a single entry in the `user'
  16693. table, which is uniquely identified by its `user' and `host' columns.
  16694.  
  16695. All users are by default not limited in using the above resources,
  16696. unless the limits are granted to them. These limits can be granted
  16697. *only* via global `GRANT (*.*)', using this syntax:
  16698.  
  16699.      GRANT ... WITH MAX_QUERIES_PER_HOUR N1
  16700.                     MAX_UPDATES_PER_HOUR N2
  16701.                     MAX_CONNECTIONS_PER_HOUR N3;
  16702.  
  16703. One can specify any combination of the above resources.  `N1', `N2',
  16704. and `N3' are integers and represent counts per hour.
  16705.  
  16706. If a user reaches the limit on number of connections within one hour, no
  16707. further connections will be accepted until that hour is up. Similarly,
  16708. if the user reaches the limit on number of queries or updates, further
  16709. queries or updates will be rejected until the hour is up. In all cases,
  16710. an appropriate error message shall be issued.
  16711.  
  16712. Current usage values for a particular user can be flushed (set to zero)
  16713. by issuing a `GRANT' statement with any of the above clauses, including
  16714. a `GRANT' statement with the current values.
  16715.  
  16716. Also, current values for all users will be flushed if privileges are
  16717. reloaded (in the server or using `mysqladmin reload') or if the `FLUSH
  16718. USER_RESOURCES' command is issued.
  16719.  
  16720. The feature is enabled as soon as a single user is granted with any of
  16721. the limiting `GRANT' clauses.
  16722.  
  16723. As a prerequisite for enabling this feature, the `user' table in the
  16724. `mysql' database must contain the additional columns, as defined in the
  16725. table creation scripts `mysql_install_db' and `mysql_install_db.sh' in
  16726. `scripts' subdirectory.
  16727.  
  16728. Setting Up Passwords
  16729. --------------------
  16730.  
  16731. In most cases you should use `GRANT' to set up your users/passwords, so
  16732. the following only applies for advanced users. *Note `GRANT': GRANT.
  16733.  
  16734. The examples in the preceding sections illustrate an important
  16735. principle: when you store a non-empty password using `INSERT' or
  16736. `UPDATE' statements, you must use the `PASSWORD()' function to encrypt
  16737. it.  This is because the `user' table stores passwords in encrypted
  16738. form, not as plaintext.  If you forget that fact, you are likely to
  16739. attempt to set passwords like this:
  16740.  
  16741.      shell> mysql -u root mysql
  16742.      mysql> INSERT INTO user (Host,User,Password)
  16743.          -> VALUES('%','jeffrey','biscuit');
  16744.      mysql> FLUSH PRIVILEGES;
  16745.  
  16746. The result is that the plaintext value `'biscuit'' is stored as the
  16747. password in the `user' table.  When the user `jeffrey' attempts to
  16748. connect to the server using this password, the `mysql' client encrypts
  16749. it with `PASSWORD()', generates an authentification vector based on
  16750. *encrypted* password and a random number, obtained from server, and
  16751. sends the result to the server.  The server uses the `password' value
  16752. in the `user' table (that is *not encrypted* value `'biscuit'') to
  16753. perform the same calculations, and compares results.  The comparison
  16754. fails and the server rejects the connection:
  16755.  
  16756.      shell> mysql -u jeffrey -pbiscuit test
  16757.      Access denied
  16758.  
  16759. Passwords must be encrypted when they are inserted in the `user' table,
  16760. so the `INSERT' statement should have been specified like this instead:
  16761.  
  16762.      mysql> INSERT INTO user (Host,User,Password)
  16763.          -> VALUES('%','jeffrey',PASSWORD('biscuit'));
  16764.  
  16765. You must also use the `PASSWORD()' function when you use `SET PASSWORD'
  16766. statements:
  16767.  
  16768.      mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
  16769.  
  16770. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  16771. the `mysqladmin password' command, the `PASSWORD()' function is
  16772. unnecessary.  They both take care of encrypting the password for you,
  16773. so you would specify a password of `'biscuit'' like this:
  16774.  
  16775.      mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
  16776.  
  16777. or
  16778.  
  16779.      shell> mysqladmin -u jeffrey password biscuit
  16780.  
  16781. *Note*: `PASSWORD()' is different from Unix password encryption.  *Note
  16782. User names::.
  16783.  
  16784. Keeping Your Password Secure
  16785. ----------------------------
  16786.  
  16787. It is inadvisable to specify your password in a way that exposes it to
  16788. discovery by other users.  The methods you can use to specify your
  16789. password when you run client programs are listed here, along with an
  16790. assessment of the risks of each method:
  16791.  
  16792.    * Never give a normal user access to the `mysql.user' table. Knowing
  16793.      the encrypted password for a user makes it possible to login as
  16794.      this user.  The passwords are only scrambled so that one shouldn't
  16795.      be able to see the real password you used (if you happen to use a
  16796.      similar password with your other applications).
  16797.  
  16798.    * Use a `-pyour_pass' or `--password=your_pass' option on the command
  16799.      line.  This is convenient but insecure, because your password
  16800.      becomes visible to system status programs (such as `ps') that may
  16801.      be invoked by other users to display command-lines.  (MySQL
  16802.      clients typically overwrite the command-line argument with zeroes
  16803.      during their initialisation sequence, but there is still a brief
  16804.      interval during which the value is visible.)
  16805.  
  16806.    * Use a `-p' or `--password' option (with no `your_pass' value
  16807.      specified).  In this case, the client program solicits the
  16808.      password from the terminal:
  16809.  
  16810.           shell> mysql -u user_name -p
  16811.           Enter password: ********
  16812.  
  16813.      The `*' characters represent your password.
  16814.  
  16815.      It is more secure to enter your password this way than to specify
  16816.      it on the command-line because it is not visible to other users.
  16817.      However, this method of entering a password is suitable only for
  16818.      programs that you run interactively.  If you want to invoke a
  16819.      client from a script that runs non-interactively, there is no
  16820.      opportunity to enter the password from the terminal. On some
  16821.      systems, you may even find that the first line of your script is
  16822.      read and interpreted (incorrectly) as your password!
  16823.  
  16824.    * Store your password in a configuration file.  For example, you can
  16825.      list your password in the `[client]' section of the `.my.cnf' file
  16826.      in your home directory:
  16827.  
  16828.           [client]
  16829.           password=your_pass
  16830.  
  16831.      If you store your password in `.my.cnf', the file should not be
  16832.      group or world readable or writable.  Make sure the file's access
  16833.      mode is `400' or `600'.
  16834.  
  16835.      *Note Option files::.
  16836.  
  16837.    * You can store your password in the `MYSQL_PWD' environment
  16838.      variable, but this method must be considered extremely insecure
  16839.      and should not be used.  Some versions of `ps' include an option
  16840.      to display the environment of running processes; your password
  16841.      will be in plain sight for all to see if you set `MYSQL_PWD'.
  16842.      Even on systems without such a version of `ps', it is unwise to
  16843.      assume there is no other method to observe process environments.
  16844.      *Note Environment variables::.
  16845.  
  16846. All in all, the safest methods are to have the client program prompt
  16847. for the password or to specify the password in a properly protected
  16848. `.my.cnf' file.
  16849.  
  16850. Using Secure Connections
  16851. ------------------------
  16852.  
  16853. Basics
  16854. ......
  16855.  
  16856. Beginning with version 4.0.0, MySQL has support for SSL encrypted
  16857. connections. To understand how MySQL uses SSL, it's necessary to
  16858. explain some basic SSL and X509 concepts. People who are already
  16859. familiar with them can skip this part.
  16860.  
  16861. By default, MySQL uses unencrypted connections between the client and
  16862. the server. This means that someone could watch all your traffic and
  16863. look at the data being sent or received.  They could even change the
  16864. data while it is in transit between client and server. Sometimes you
  16865. need to move information over public networks in a secure fashion; in
  16866. such cases, using an unencrypted connection is unacceptable.
  16867.  
  16868. SSL is a protocol that uses different encryption algorithms to ensure
  16869. that data received over a public network can be trusted. It has
  16870. mechanisms to detect any change, loss or replay of data. SSL also
  16871. incorporates algorithms to recognise and provide identity verification
  16872. using the X509 standard.
  16873.  
  16874. Encryption is the way to make any kind of data unreadable. In fact,
  16875. today's practice requires many additional security elements from
  16876. encryption algorithms.  They should resist many kind of known attacks
  16877. like just messing with the order of encrypted messages or replaying data
  16878. twice.
  16879.  
  16880. X509 is a standard that makes it possible to identify someone on the
  16881. Internet.  It is most commonly used in e-commerce applications. In basic
  16882. terms, there should be some company (called a "Certificate Authority")
  16883. that assigns electronic certificates to anyone who needs them.
  16884. Certificates rely on asymmetric encryption algorithms that have two
  16885. encryption keys (a public key and a secret key). A certificate owner
  16886. can prove his identity by showing his certificate to other party. A
  16887. certificate consists of its owner's public key. Any data encrypted with
  16888. this public key can be decrypted only using the corresponding secret
  16889. key, which is held by the owner of the certificate.
  16890.  
  16891. MySQL doesn't use encrypted connections by default, because doing so
  16892. would make the client/server protocol much slower. Any kind of
  16893. additional functionality requires the computer to do additional work and
  16894. encrypting data is a CPU-intensive operation that requires time and can
  16895. delay MySQL main tasks. By default MySQL is tuned to be fast as
  16896. possible.
  16897.  
  16898. If you need more information about SSL, X509, or encryption, you should
  16899. use your favourite Internet search engine and search for keywords in
  16900. which you are interested.
  16901.  
  16902. Requirements
  16903. ............
  16904.  
  16905. To get secure connections to work with MySQL you must do the following:
  16906.  
  16907.   1. Install the OpenSSL library. We have tested MySQL with OpenSSL
  16908.      0.9.6.  `http://www.openssl.org/'.
  16909.  
  16910.   2. Configure MySQL with `--with-vio --with-openssl'.
  16911.  
  16912.   3. If you are using an old MySQL installation, you have to update your
  16913.      `mysql.user' table with some new SSL-related columns. You can do
  16914.      this by running the `mysql_fix_privilege_tables.sh' script.  This
  16915.      is necessary if your grant tables date from a version prior to
  16916.      MySQL 4.0.0.
  16917.  
  16918.   4. You can check if a running `mysqld' server supports OpenSSL by
  16919.      examining if `SHOW VARIABLES LIKE 'have_openssl'' returns `YES'.
  16920.  
  16921. Setting Up SSL Certificates for MySQL
  16922. .....................................
  16923.  
  16924. Here is an example for setting up SSL certificates for MySQL:
  16925.  
  16926.      DIR=`pwd`/openssl
  16927.      PRIV=$DIR/private
  16928.      
  16929.      mkdir $DIR $PRIV $DIR/newcerts
  16930.      cp /usr/share/ssl/openssl.cnf $DIR
  16931.      replace ./demoCA $DIR -- $DIR/openssl.cnf
  16932.      
  16933.      # Create necessary files: $database, $serial and $new_certs_dir
  16934.      # directory (optional)
  16935.      
  16936.      touch $DIR/index.txt
  16937.      echo "01" > $DIR/serial
  16938.      
  16939.      #
  16940.      # Generation of Certificate Authority(CA)
  16941.      #
  16942.      
  16943.      openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem \
  16944.          -config $DIR/openssl.cnf
  16945.      
  16946.      # Sample output:
  16947.      # Using configuration from /home/monty/openssl/openssl.cnf
  16948.      # Generating a 1024 bit RSA private key
  16949.      # ................++++++
  16950.      # .........++++++
  16951.      # writing new private key to '/home/monty/openssl/private/cakey.pem'
  16952.      # Enter PEM pass phrase:
  16953.      # Verifying password - Enter PEM pass phrase:
  16954.      # -----
  16955.      # You are about to be asked to enter information that will be incorporated
  16956.      # into your certificate request.
  16957.      # What you are about to enter is what is called a Distinguished Name or a DN.
  16958.      # There are quite a few fields but you can leave some blank
  16959.      # For some fields there will be a default value,
  16960.      # If you enter '.', the field will be left blank.
  16961.      # -----
  16962.      # Country Name (2 letter code) [AU]:FI
  16963.      # State or Province Name (full name) [Some-State]:.
  16964.      # Locality Name (eg, city) []:
  16965.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  16966.      # Organizational Unit Name (eg, section) []:
  16967.      # Common Name (eg, YOUR name) []:MySQL admin
  16968.      # Email Address []:
  16969.      
  16970.      #
  16971.      # Create server request and key
  16972.      #
  16973.      openssl req -new -keyout $DIR/server-key.pem -out \
  16974.          $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
  16975.      
  16976.      # Sample output:
  16977.      # Using configuration from /home/monty/openssl/openssl.cnf
  16978.      # Generating a 1024 bit RSA private key
  16979.      # ..++++++
  16980.      # ..........++++++
  16981.      # writing new private key to '/home/monty/openssl/server-key.pem'
  16982.      # Enter PEM pass phrase:
  16983.      # Verifying password - Enter PEM pass phrase:
  16984.      # -----
  16985.      # You are about to be asked to enter information that will be incorporated
  16986.      # into your certificate request.
  16987.      # What you are about to enter is what is called a Distinguished Name or a DN.
  16988.      # There are quite a few fields but you can leave some blank
  16989.      # For some fields there will be a default value,
  16990.      # If you enter '.', the field will be left blank.
  16991.      # -----
  16992.      # Country Name (2 letter code) [AU]:FI
  16993.      # State or Province Name (full name) [Some-State]:.
  16994.      # Locality Name (eg, city) []:
  16995.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  16996.      # Organizational Unit Name (eg, section) []:
  16997.      # Common Name (eg, YOUR name) []:MySQL server
  16998.      # Email Address []:
  16999.      #
  17000.      # Please enter the following 'extra' attributes
  17001.      # to be sent with your certificate request
  17002.      # A challenge password []:
  17003.      # An optional company name []:
  17004.      
  17005.      #
  17006.      # Remove the passphrase from the key (optional)
  17007.      #
  17008.      
  17009.      openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
  17010.      
  17011.      #
  17012.      # Sign server cert
  17013.      #
  17014.      openssl ca  -policy policy_anything -out $DIR/server-cert.pem \
  17015.          -config $DIR/openssl.cnf -infiles $DIR/server-req.pem
  17016.      
  17017.      # Sample output:
  17018.      # Using configuration from /home/monty/openssl/openssl.cnf
  17019.      # Enter PEM pass phrase:
  17020.      # Check that the request matches the signature
  17021.      # Signature ok
  17022.      # The Subjects Distinguished Name is as follows
  17023.      # countryName           :PRINTABLE:'FI'
  17024.      # organizationName      :PRINTABLE:'MySQL AB'
  17025.      # commonName            :PRINTABLE:'MySQL admin'
  17026.      # Certificate is to be certified until Sep 13 14:22:46 2003 GMT (365 days)
  17027.      # Sign the certificate? [y/n]:y
  17028.      #
  17029.      #
  17030.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  17031.      # Write out database with 1 new entries
  17032.      # Data Base Updated
  17033.      
  17034.      #
  17035.      # Create client request and key
  17036.      #
  17037.      openssl req -new -keyout $DIR/client-key.pem -out \
  17038.          $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
  17039.      
  17040.      # Sample output:
  17041.      # Using configuration from /home/monty/openssl/openssl.cnf
  17042.      # Generating a 1024 bit RSA private key
  17043.      # .....................................++++++
  17044.      # .............................................++++++
  17045.      # writing new private key to '/home/monty/openssl/client-key.pem'
  17046.      # Enter PEM pass phrase:
  17047.      # Verifying password - Enter PEM pass phrase:
  17048.      # -----
  17049.      # You are about to be asked to enter information that will be incorporated
  17050.      # into your certificate request.
  17051.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17052.      # There are quite a few fields but you can leave some blank
  17053.      # For some fields there will be a default value,
  17054.      # If you enter '.', the field will be left blank.
  17055.      # -----
  17056.      # Country Name (2 letter code) [AU]:FI
  17057.      # State or Province Name (full name) [Some-State]:.
  17058.      # Locality Name (eg, city) []:
  17059.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17060.      # Organizational Unit Name (eg, section) []:
  17061.      # Common Name (eg, YOUR name) []:MySQL user
  17062.      # Email Address []:
  17063.      #
  17064.      # Please enter the following 'extra' attributes
  17065.      # to be sent with your certificate request
  17066.      # A challenge password []:
  17067.      # An optional company name []:
  17068.      
  17069.      #
  17070.      # Remove a passphrase from the key (optional)
  17071.      #
  17072.      openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
  17073.      
  17074.      #
  17075.      # Sign client cert
  17076.      #
  17077.      
  17078.      openssl ca  -policy policy_anything -out $DIR/client-cert.pem \
  17079.          -config $DIR/openssl.cnf -infiles $DIR/client-req.pem
  17080.      
  17081.      # Sample output:
  17082.      # Using configuration from /home/monty/openssl/openssl.cnf
  17083.      # Enter PEM pass phrase:
  17084.      # Check that the request matches the signature
  17085.      # Signature ok
  17086.      # The Subjects Distinguished Name is as follows
  17087.      # countryName           :PRINTABLE:'FI'
  17088.      # organizationName      :PRINTABLE:'MySQL AB'
  17089.      # commonName            :PRINTABLE:'MySQL user'
  17090.      # Certificate is to be certified until Sep 13 16:45:17 2003 GMT (365 days)
  17091.      # Sign the certificate? [y/n]:y
  17092.      #
  17093.      #
  17094.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  17095.      # Write out database with 1 new entries
  17096.      # Data Base Updated
  17097.      
  17098.      #
  17099.      # Create a my.cnf file that you can use to test the certificates
  17100.      #
  17101.      
  17102.      cnf=""
  17103.      cnf="$cnf [client]"
  17104.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  17105.      cnf="$cnf ssl-cert=$DIR/client-cert.pem"
  17106.      cnf="$cnf ssl-key=$DIR/client-key.pem"
  17107.      cnf="$cnf [mysqld]"
  17108.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  17109.      cnf="$cnf ssl-cert=$DIR/server-cert.pem"
  17110.      cnf="$cnf ssl-key=$DIR/server-key.pem"
  17111.      echo $cnf | replace " " '
  17112.      ' > $DIR/my.cnf
  17113.      
  17114.      #
  17115.      # To test MySQL
  17116.      
  17117.      mysqld --defaults-file=$DIR/my.cnf &
  17118.      
  17119.      mysql --defaults-file=$DIR/my.cnf
  17120.  
  17121. You can also test your setup by modifying the above `my.cnf' file to
  17122. refer to the demo certificates in the mysql-source-dist/SSL direcory.
  17123.  
  17124. `GRANT' Options
  17125. ...............
  17126.  
  17127. MySQL can check X509 certificate attributes in addition to the normal
  17128. username/password scheme. All the usual options are still required
  17129. (username, password, IP address mask, database/table name).
  17130.  
  17131. There are different possibilities to limit connections:
  17132.  
  17133.    * Without any SSL or X509 options, all kind of encrypted/unencrypted
  17134.      connections are allowed if the username and password are valid.
  17135.  
  17136.    * `REQUIRE SSL' option limits the server to allow only SSL encrypted
  17137.      connections. Note that this option can be omitted if there are any
  17138.      ACL records which allow non-SSL connections.
  17139.  
  17140.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17141.               -> IDENTIFIED BY "goodsecret" REQUIRE SSL;
  17142.  
  17143.    * `REQUIRE X509' means that the client should have a valid
  17144.      certificate but we do not care about the exact certificate, issuer
  17145.      or subject.  The only restriction is that it should be possible to
  17146.      verify its signature with one of the CA certificates.
  17147.  
  17148.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17149.               -> IDENTIFIED BY "goodsecret" REQUIRE X509;
  17150.  
  17151.    * `REQUIRE ISSUER "issuer"' places a restriction on connection
  17152.      attempts: The client must present a valid X509 certificate issued
  17153.      by CA `"issuer"'.  Using X509 certificates always implies
  17154.      encryption, so the `SSL' option is unneccessary.
  17155.  
  17156.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17157.               -> IDENTIFIED BY "goodsecret"
  17158.               -> REQUIRE ISSUER "C=FI, ST=Some-State, L=Helsinki,
  17159.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com";
  17160.  
  17161.    * `REQUIRE SUBJECT "subject"' requires clients to have valid X509
  17162.      certificate with subject `"subject"' on it. If the client presents
  17163.      a certificate that is valid but has a different `"subject"', the
  17164.      connection is disallowed.
  17165.  
  17166.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17167.               -> IDENTIFIED BY "goodsecret"
  17168.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  17169.               "> O=MySQL demo client certificate,
  17170.               "> CN=Tonu Samuel/Email=tonu@mysql.com";
  17171.  
  17172.    * `REQUIRE CIPHER "cipher"' is needed to assure enough strong ciphers
  17173.      and keylengths will be used. SSL itself can be weak if old
  17174.      algorithms with short encryption keys are used. Using this option,
  17175.      we can ask for some exact cipher method to allow a connection.
  17176.  
  17177.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17178.               -> IDENTIFIED BY "goodsecret"
  17179.               -> REQUIRE CIPHER "EDH-RSA-DES-CBC3-SHA";
  17180.  
  17181.      The `SUBJECT', `ISSUER', and `CIPHER' options can be combined in
  17182.      the `REQUIRE' clause like this:
  17183.  
  17184.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17185.               -> IDENTIFIED BY "goodsecret"
  17186.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  17187.               "> O=MySQL demo client certificate,
  17188.               "> CN=Tonu Samuel/Email=tonu@mysql.com"
  17189.               -> AND ISSUER "C=FI, ST=Some-State, L=Helsinki,
  17190.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com"
  17191.               -> AND CIPHER "EDH-RSA-DES-CBC3-SHA";
  17192.  
  17193.      Starting from MySQL 4.0.4 the `AND' keyword is optional between
  17194.      `REQUIRE' options.
  17195.  
  17196.      The order of the options does not matter, but no option can be
  17197.      specified twice.
  17198.  
  17199. Disaster Prevention and Recovery
  17200. ================================
  17201.  
  17202. Database Backups
  17203. ----------------
  17204.  
  17205. Because MySQL tables are stored as files, it is easy to do a backup. To
  17206. get a consistent backup, do a `LOCK TABLES' on the relevant tables
  17207. followed by `FLUSH TABLES' for the tables.  *Note `LOCK TABLES': LOCK
  17208. TABLES.  *Note `FLUSH': FLUSH.  You only need a read lock; this allows
  17209. other threads to continue to query the tables while you are making a
  17210. copy of the files in the database directory.  The `FLUSH TABLE' is
  17211. needed to ensure that the all active index pages is written to disk
  17212. before you start the backup.
  17213.  
  17214. Starting from 3.23.56 and 4.0.12 `BACKUP TABLE' will not allow you to
  17215. overwrite existing files as this would be a security risk.
  17216.  
  17217. If you want to make an SQL level backup of a table, you can use `SELECT
  17218. INTO OUTFILE' or `BACKUP TABLE'. *Note SELECT::.  *Note BACKUP TABLE::.
  17219.  
  17220. Another way to back up a database is to use the `mysqldump' program or
  17221. the `mysqlhotcopy script'. *Note `mysqldump': mysqldump.  *Note
  17222. `mysqlhotcopy': mysqlhotcopy.
  17223.  
  17224.   1. Do a full backup of your database:
  17225.  
  17226.           shell> mysqldump --tab=/path/to/some/dir --opt db_name
  17227.           
  17228.           or
  17229.           
  17230.           shell> mysqlhotcopy db_name /path/to/some/dir
  17231.  
  17232.      You can also simply copy all table files (`*.frm', `*.MYD', and
  17233.      `*.MYI' files) as long as the server isn't updating anything.  The
  17234.      script `mysqlhotcopy' does use this method.  (But note that these
  17235.      methods will not work if your database contains `InnoDB' tables.
  17236.      `InnoDB' does not store table contents in database directories,
  17237.      and `mysqlhotcopy' works only for `MyISAM' and `ISAM' tables.)
  17238.  
  17239.   2. Stop `mysqld' if it's running, then start it with the
  17240.      `--log-bin[=file_name]' option.  *Note Binary log::. The binary
  17241.      log file(s) provide you with the information you need to replicate
  17242.      changes to the database that are made subsequent to the point at
  17243.      which you executed `mysqldump'.
  17244.  
  17245. If you have to restore something, try to recover your tables using
  17246. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  17247. all cases.  If `myisamchk' fails, try the following procedure (this
  17248. will only work if you have started MySQL with `--log-bin', see *Note
  17249. Binary log::):
  17250.  
  17251.   1. Restore the original `mysqldump' backup, or binary backup.
  17252.  
  17253.   2. Execute the following command to re-run the updates in the binary
  17254.      log:
  17255.  
  17256.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  17257.  
  17258.      In your case you may want to re-run only certain binlogs, from
  17259.      certain positions (usually you want to re-run all binlogs from the
  17260.      date of the restored backup, possibly excepted some wrong queries).
  17261.      See *Note mysqlbinlog:: for more information on the `mysqlbinlog'
  17262.      utility and how to use it.
  17263.  
  17264.      If you are using the update log (which will be removed in MySQL
  17265.      5.0) you can execute the content of the update log like this:
  17266.  
  17267.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  17268.  
  17269. `ls' is used to get all the update log files in the right order.
  17270.  
  17271. You can also do selective backups with `SELECT * INTO OUTFILE
  17272. 'file_name' FROM tbl_name' and restore with `LOAD DATA INFILE
  17273. 'file_name' REPLACE ...' To avoid duplicate records, you need a
  17274. `PRIMARY KEY' or a `UNIQUE' key in the table. The `REPLACE' keyword
  17275. causes old records to be replaced with new ones when a new record
  17276. duplicates an old record on a unique key value.
  17277.  
  17278. If you get performance problems in making backups on your system, you
  17279. can solve this by setting up replication and do the backups on the slave
  17280. instead of on the master. *Note Replication Intro::.
  17281.  
  17282. If you are using a Veritas filesystem, you can do:
  17283.  
  17284.   1. From a client (or Perl), execute: `FLUSH TABLES WITH READ LOCK'.
  17285.  
  17286.   2. From another shell, execute: `mount vxfs snapshot'.
  17287.  
  17288.   3. From the first client, execute: `UNLOCK TABLES'.
  17289.  
  17290.   4. Copy files from snapshot.
  17291.  
  17292.   5. Unmount snapshot.
  17293.  
  17294. `BACKUP TABLE' Syntax
  17295. ---------------------
  17296.  
  17297.      BACKUP TABLE tbl_name[,tbl_name...] TO '/path/to/backup/directory'
  17298.  
  17299. Copies to the backup directory the minimum number of table files needed
  17300. to restore the table, after flushing any buffered changes to disk.
  17301. Currently works only for `MyISAM' tables.  For `MyISAM' tables, copies
  17302. `.frm' (definition)  and `.MYD' (data) files. The index file can be
  17303. rebuilt from those two.
  17304.  
  17305. Before using this command, please see *Note Backup::.
  17306.  
  17307. During the backup, a read lock will be held for each table, one at time,
  17308. as they are being backed up. If you want to back up several tables as a
  17309. snapshot, you must first issue `LOCK TABLES' obtaining a read lock for
  17310. each table in the group.
  17311.  
  17312. The command returns a table with the following columns:
  17313.  
  17314. *Column*    *Value*
  17315. Table       Table name
  17316. Op          Always `backup'
  17317. Msg_type    One of `status', `error',
  17318.             `info', or `warning'
  17319. Msg_text    The message
  17320.  
  17321. Note that `BACKUP TABLE' is only available in MySQL version 3.23.25 and
  17322. later.
  17323.  
  17324. `RESTORE TABLE' Syntax
  17325. ----------------------
  17326.  
  17327.      RESTORE TABLE tbl_name[,tbl_name...] FROM '/path/to/backup/directory'
  17328.  
  17329. Restores the table(s) from the backup that was made with `BACKUP
  17330. TABLE'. Existing tables will not be overwritten; if you try to restore
  17331. over an existing table, you will get an error. Restoring will take
  17332. longer than backing up due to the need to rebuild the index. The more
  17333. keys you have, the longer it will take. Just as `BACKUP TABLE',
  17334. `RESTORE TABLE' currently works only for `MyISAM' tables.
  17335.  
  17336. The command returns a table with the following columns:
  17337.  
  17338. *Column*    *Value*
  17339. Table       Table name
  17340. Op          Always `restore'
  17341. Msg_type    One of `status', `error',
  17342.             `info', or `warning'
  17343. Msg_text    The message
  17344.  
  17345. `CHECK TABLE' Syntax
  17346. --------------------
  17347.  
  17348.      CHECK TABLE tbl_name[,tbl_name...] [option [option...]]
  17349.      
  17350.      option = QUICK | FAST | MEDIUM | EXTENDED | CHANGED
  17351.  
  17352. `CHECK TABLE' works only on `MyISAM' and `InnoDB' tables. On `MyISAM'
  17353. tables, it's the same thing as running `myisamchk --medium-check
  17354. table_name' on the table.
  17355.  
  17356. If you don't specify any option, `MEDIUM' is used.
  17357.  
  17358. Checks the table or tables for errors. For `MyISAM' tables, the key
  17359. statistics are updated. The command returns a table with the following
  17360. columns:
  17361.  
  17362. *Column*    *Value*
  17363. Table       Table name
  17364. Op          Always `check'
  17365. Msg_type    One of `status', `error',
  17366.             `info', or `warning'
  17367. Msg_text    The message
  17368.  
  17369. Note that the statement may produce many rows of information for each
  17370. checked table.  The last row will be of `Msg_type status' and should
  17371. normally be `OK'.  If you don't get `OK', or `Table is already up to
  17372. date' you should normally run a repair of the table. *Note Table
  17373. maintenance::. `Table is already up to date' means that the storage
  17374. manager for the table indicated that there was no need to check the
  17375. table.
  17376.  
  17377. The different check types are as follows:
  17378.  
  17379. *Type*      *Meaning*
  17380. `QUICK'     Don't scan the rows to check for incorrect links.
  17381. `FAST'      Only check tables that haven't been closed properly.
  17382. `CHANGED'   Only check tables that have been changed since the last
  17383.             check or haven't been closed properly.
  17384. `MEDIUM'    Scan rows to verify that deleted links are okay. This also
  17385.             calculates a key checksum for the rows and verifies this
  17386.             with a calculated checksum for the keys.
  17387. `EXTENDED'  Do a full key lookup for all keys for each row.  This
  17388.             ensures that the table is 100% consistent, but will take a
  17389.             long time!
  17390.  
  17391. For dynamically sized `MyISAM' tables, a started check will always do a
  17392. `MEDIUM' check. For statically sized rows, we skip the row scan for
  17393. `QUICK' and `FAST' as the rows are very seldom corrupted.
  17394.  
  17395. You can combine check options, as in the following example that does a
  17396. quick check on the table to see whether it was closed properly:
  17397.  
  17398.      CHECK TABLE test_table FAST QUICK;
  17399.  
  17400. *Note*: that in some cases `CHECK TABLE' will change the table!  This
  17401. happens if the table is marked as 'corrupted' or 'not closed properly'
  17402. but `CHECK TABLE' didn't find any problems in the table.  In this case,
  17403. `CHECK TABLE' will mark the table as okay.
  17404.  
  17405. If a table is corrupted, then it's most likely that the problem is in
  17406. the indexes and not in the data part.  All of the above check types
  17407. checks the indexes thoroughly and should thus find most errors.
  17408.  
  17409. If you just want to check a table that you assume is okay, you should
  17410. use no check options or the `QUICK' option. The latter should be used
  17411. when you are in a hurry and can take the very small risk that `QUICK'
  17412. didn't find an error in the datafile. (In most cases MySQL should find,
  17413. under normal usage, any error in the datafile.  If this happens then
  17414. the table will be marked as 'corrupted', in which case the table can't
  17415. be used until it's repaired.)
  17416.  
  17417. `FAST' and `CHANGED' are mostly intended to be used from a script (for
  17418. example to be executed from `cron') if you want to check your table
  17419. from time to time. In most cases, `FAST' is to be prefered over
  17420. `CHANGED'.  (The only case when it isn't is when you suspect that you
  17421. have found a bug in the `MyISAM' code.)
  17422.  
  17423. `EXTENDED' is only to be used after you have run a normal check but
  17424. still get strange errors from a table when MySQL tries to update a row
  17425. or find a row by key (this is very unlikely if a normal check has
  17426. succeeded!).
  17427.  
  17428. Some things reported by `CHECK TABLE' can't be corrected automatically:
  17429.  
  17430.    * `Found row where the auto_increment column has the value 0'.
  17431.  
  17432.      This means that you have a row in the table where the
  17433.      `AUTO_INCREMENT' index column contains the value 0.  (It's
  17434.      possible to create a row where the `AUTO_INCREMENT' column is 0 by
  17435.      explicitly setting the column to 0 with an `UPDATE' statement.)
  17436.  
  17437.      This isn't an error in itself, but could cause trouble if you
  17438.      decide to dump the table and restore it or do an `ALTER TABLE' on
  17439.      the table. In this case, the `AUTO_INCREMENT' column will change
  17440.      value, according to the rules of `AUTO_INCREMENT' columns, which
  17441.      could cause problems such as a duplicate key error.
  17442.  
  17443.      To get rid of the warning, just execute an `UPDATE' statement to
  17444.      set the column to some other value than 0.
  17445.  
  17446. `REPAIR TABLE' Syntax
  17447. ---------------------
  17448.  
  17449.      REPAIR [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED] [USE_FRM]
  17450.  
  17451. `REPAIR TABLE' works only on `MyISAM' tables and is the same as running
  17452. `myisamchk -r table_name' on the table.
  17453.  
  17454. Normally you should never have to run this command, but if disaster
  17455. strikes you are very likely to get back all your data from a MyISAM
  17456. table with `REPAIR TABLE'. If your tables get corrupted a lot, you
  17457. should try to find the reason for it, to eliminate the need to use
  17458. `REPAIR TABLE'.  *Note Crashing::. *Note MyISAM table problems::.
  17459.  
  17460. `REPAIR TABLE' repairs a possibly corrupted table. The command returns a
  17461. table with the following columns:
  17462.  
  17463. *Column*    *Value*
  17464. Table       Table name
  17465. Op          Always `repair'
  17466. Msg_type    One of `status', `error',
  17467.             `info', or `warning'
  17468. Msg_text    The message
  17469.  
  17470. Note that the statement may produce many rows of information for each
  17471. repaired table.  The last one row will be of `Msg_type status' and
  17472. should normally be `OK'.  If you don't get `OK', you should try
  17473. repairing the table with `myisamchk --safe-recover', as `REPAIR TABLE'
  17474. does not yet implement all the options of `myisamchk'. In the near
  17475. future, we will make it more flexible.
  17476.  
  17477. If `QUICK' is given, `REPAIR TABLE' tries to repair only the index tree.
  17478.  
  17479. If you use `EXTENDED', MySQL will create the index row by row instead
  17480. of creating one index at a time with sorting; this may be better than
  17481. sorting on fixed-length keys if you have long `CHAR' keys that compress
  17482. very well.  This type of repair is like that done by `myisamchk
  17483. --safe-recover'.
  17484.  
  17485. As of `MySQL' 4.0.2, there is a `USE_FRM' mode for `REPAIR'.  Use it if
  17486. the `.MYI' file is missing or if its header is corrupted.  In this mode
  17487. MySQL will recreate the table, using information from the `.frm' file.
  17488. This kind of repair cannot be done with `myisamchk'.
  17489.  
  17490. *Warning:* If `mysqld' dies during a `REPAIR TABLE', it's essential
  17491. that you do at once another `REPAIR' on the table before executing any
  17492. other commands on it. (It's of course always good to start with a
  17493. backup).  In the worst case you can have a new clean index file without
  17494. information about the datafile and when the next command you do may
  17495. overwrite the datafile.  This is not a likely, but possible scenario.
  17496.  
  17497. Strictly before MySQL 4.1.1, `REPAIR' commands are not written to the
  17498. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  17499. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  17500. used.
  17501.  
  17502. Using `myisamchk' for Table Maintenance and Crash Recovery
  17503. ----------------------------------------------------------
  17504.  
  17505. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  17506. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  17507. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  17508.  
  17509. To check/repair MyISAM tables (`.MYI' and `.MYD') you should use the
  17510. `myisamchk' utility. To check/repair ISAM tables (`.ISM' and `.ISD')
  17511. you should use the `isamchk' utility. *Note Table types::.
  17512.  
  17513. In the following text we will talk about `myisamchk', but everything
  17514. also applies to the old `isamchk'.
  17515.  
  17516. You can use the `myisamchk' utility to get information about your
  17517. database tables, check and repair them, or optimise them.  The following
  17518. sections describe how to invoke `myisamchk' (including a description of
  17519. its options), how to set up a table maintenance schedule, and how to
  17520. use `myisamchk' to perform its various functions.
  17521.  
  17522. You can, in most cases, also use the command `OPTIMIZE TABLES' to
  17523. optimise and repair tables, but this is not as fast or reliable (in case
  17524. of real fatal errors) as `myisamchk'.  On the other hand, `OPTIMIZE
  17525. TABLE' is easier to use and you don't have to worry about flushing
  17526. tables.  *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  17527.  
  17528. Even though the repair in `myisamchk' is quite secure, it's always a
  17529. good idea to make a backup _before_ doing a repair (or anything that
  17530. could make a lot of changes to a table)
  17531.  
  17532. `myisamchk' Invocation Syntax
  17533. .............................
  17534.  
  17535. `myisamchk' is invoked like this:
  17536.  
  17537.      shell> myisamchk [options] tbl_name
  17538.  
  17539. The `options' specify what you want `myisamchk' to do.  They are
  17540. described here.  (You can also get a list of options by invoking
  17541. `myisamchk --help'.)  With no options, `myisamchk' simply checks your
  17542. table.  To get more information or to tell `myisamchk' to take
  17543. corrective action, specify options as described here and in the
  17544. following sections.
  17545.  
  17546. `tbl_name' is the database table you want to check/repair.  If you run
  17547. `myisamchk' somewhere other than in the database directory, you must
  17548. specify the path to the file, because `myisamchk' has no idea where your
  17549. database is located.  Actually, `myisamchk' doesn't care whether the
  17550. files you are working on are located in a database directory; you can
  17551. copy the files that correspond to a database table into another
  17552. location and perform recovery operations on them there.
  17553.  
  17554. You can name several tables on the `myisamchk' command-line if you
  17555. wish.  You can also specify a name as an index file name (with the
  17556. `.MYI' suffix), which allows you to specify all tables in a directory
  17557. by using the pattern `*.MYI'.  For example, if you are in a database
  17558. directory, you can check all the tables in the directory like this:
  17559.  
  17560.      shell> myisamchk *.MYI
  17561.  
  17562. If you are not in the database directory, you can check all the tables
  17563. there by specifying the path to the directory:
  17564.  
  17565.      shell> myisamchk /path/to/database_dir/*.MYI
  17566.  
  17567. You can even check all tables in all databases by specifying a wildcard
  17568. with the path to the MySQL data directory:
  17569.  
  17570.      shell> myisamchk /path/to/datadir/*/*.MYI
  17571.  
  17572. The recommended way to quickly check all tables is:
  17573.  
  17574.      myisamchk --silent --fast /path/to/datadir/*/*.MYI
  17575.      isamchk --silent /path/to/datadir/*/*.ISM
  17576.  
  17577. If you want to check all tables and repair all tables that are
  17578. corrupted, you can use the following line:
  17579.  
  17580.      myisamchk --silent --force --fast --update-state -O key_buffer=64M \
  17581.                -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
  17582.                /path/to/datadir/*/*.MYI
  17583.      isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M \
  17584.              -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.ISM
  17585.  
  17586. The above assumes that you have more than 64 M free.
  17587.  
  17588. Note that if you get an error like:
  17589.  
  17590.      myisamchk: warning: 1 clients is using or hasn't closed the table properly
  17591.  
  17592. This means that you are trying to check a table that has been updated by
  17593. another program (like the `mysqld' server) that hasn't yet closed the
  17594. file or that has died without closing the file properly.
  17595.  
  17596. If `mysqld' is running, you must force a sync/close of all tables with
  17597. `FLUSH TABLES' and ensure that no one is using the tables while you are
  17598. running `myisamchk'.  In MySQL Version 3.23 the easiest way to avoid
  17599. this problem is to use `CHECK TABLE' instead of `myisamchk' to check
  17600. tables.
  17601.  
  17602. General Options for `myisamchk'
  17603. ...............................
  17604.  
  17605. `myisamchk' supports the following options.
  17606.  
  17607. `-# or --debug=debug_options'
  17608.      Output debug log. The `debug_options' string often is
  17609.      `'d:t:o,filename''.
  17610.  
  17611. `-? or --help'
  17612.      Display a help message and exit.
  17613.  
  17614. `-O var=option, --set-variable var=option'
  17615.      Set the value of a variable.  Please note that `--set-variable' is
  17616.      deprecated since MySQL 4.0, just use `--var=option' on its own.
  17617.      The possible variables and their default values for myisamchk can
  17618.      be examined with `myisamchk --help':
  17619.      *Variable*    *Value*
  17620.      key_buffer_size523264
  17621.      read_buffer_size262136
  17622.      write_buffer_size262136
  17623.      sort_buffer_size2097144
  17624.      sort_key_blocks16
  17625.      decode_bits   9
  17626.  
  17627.      `sort_buffer_size' is used when the keys are repaired by sorting
  17628.      keys, which is the normal case when you use `--recover'.
  17629.  
  17630.      `key_buffer_size' is used when you are checking the table with
  17631.      `--extended-check' or when the keys are repaired by inserting key
  17632.      row by row in to the table (like when doing normal inserts).
  17633.      Repairing through the key buffer is used in the following cases:
  17634.  
  17635.         * If you use `--safe-recover'.
  17636.  
  17637.         * If the temporary files needed to sort the keys would be more
  17638.           than twice as big as when creating the key file directly.
  17639.           This is often the case when you have big `CHAR', `VARCHAR' or
  17640.           `TEXT' keys as the sort needs to store the whole keys during
  17641.           sorting. If you have lots of temporary space and you can
  17642.           force `myisamchk' to repair by sorting you can use the
  17643.           `--sort-recover' option.
  17644.  
  17645.      Reparing through the key buffer takes much less disk space than
  17646.      using sorting, but is also much slower.
  17647.  
  17648.      If you want a faster repair, set the above variables to about 1/4
  17649.      of your available memory.  You can set both variables to big
  17650.      values, as only one of the above buffers will be used at a time.
  17651.  
  17652. `-s or --silent'
  17653.      Silent mode.  Write output only when errors occur. You can use `-s'
  17654.      twice (`-ss') to make `myisamchk' very silent.
  17655.  
  17656. `-v or --verbose'
  17657.      Verbose mode.  Print more information. This can be used with `-d'
  17658.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for more
  17659.      verbosity!
  17660.  
  17661. `-V or --version'
  17662.      Print the `myisamchk' version and exit.
  17663.  
  17664. `-w or, --wait'
  17665.      Instead of giving an error if the table is locked, wait until the
  17666.      table is unlocked before continuing.  Note that if you are running
  17667.      `mysqld' on the table with `--skip-external-locking', the table
  17668.      can only be locked by another `myisamchk' command.
  17669.  
  17670. Check Options for `myisamchk'
  17671. .............................
  17672.  
  17673. `-c or --check'
  17674.      Check table for errors. This is the default operation if you are
  17675.      not giving `myisamchk' any options that override this.
  17676.  
  17677. `-e or --extend-check'
  17678.      Check the table very thoroughly (which is quite slow if you have
  17679.      many indexes).  This option should only be used in extreme cases.
  17680.      Normally, `myisamchk' or `myisamchk --medium-check' should, in most
  17681.      cases, be able to find out if there are any errors in the table.
  17682.  
  17683.      If you are using `--extended-check' and have much memory, you
  17684.      should increase the value of `key_buffer_size' a lot!
  17685.  
  17686. `-F or --fast'
  17687.      Check only tables that haven't been closed properly.
  17688.  
  17689. `-C or --check-only-changed'
  17690.      Check only tables that have changed since the last check.
  17691.  
  17692. `-f or --force'
  17693.      Restart `myisamchk' with `-r' (repair) on the table, if
  17694.      `myisamchk' finds any errors in the table.
  17695.  
  17696. `-i or --information'
  17697.      Print informational statistics about the table that is checked.
  17698.  
  17699. `-m or --medium-check'
  17700.      Faster than extended-check, but only finds 99.99% of all errors.
  17701.      Should, however, be good enough for most cases.
  17702.  
  17703. `-U or --update-state'
  17704.      Store in the `.MYI' file when the table was checked and if the
  17705.      table crashed.  This should be used to get full benefit of the
  17706.      `--check-only-changed' option, but you shouldn't use this option
  17707.      if the `mysqld' server is using the table and you are running
  17708.      `mysqld' with `--skip-external-locking'.
  17709.  
  17710. `-T or --read-only'
  17711.      Don't mark table as checked. This is useful if you use `myisamchk'
  17712.      to check a table that is in use by some other application that
  17713.      doesn't use locking (like `mysqld --skip-external-locking').
  17714.  
  17715. Repair Options for myisamchk
  17716. ............................
  17717.  
  17718. The following options are used if you start `myisamchk' with `-r' or
  17719. `-o':
  17720.  
  17721. `-D # or --data-file-length=#'
  17722.      Max length of datafile (when re-creating datafile when it's
  17723.      'full').
  17724.  
  17725. `-e or --extend-check'
  17726.      Try to recover every possible row from the datafile.  Normally
  17727.      this will also find a lot of garbage rows. Don't use this option
  17728.      if you are not totally desperate.
  17729.  
  17730. `-f or --force'
  17731.      Overwrite old temporary files (`table_name.TMD') instead of
  17732.      aborting.
  17733.  
  17734. `-k # or keys-used=#'
  17735.      If you are using ISAM, tells the ISAM storage engine to update
  17736.      only the first `#' indexes.  If you are using `MyISAM', tells
  17737.      which keys to use, where each binary bit stands for one key (first
  17738.      key is bit 0).  This can be used to get faster inserts!
  17739.      Deactivated indexes can be reactivated by using `myisamchk -r'.
  17740.      keys.
  17741.  
  17742. `-l or --no-symlinks'
  17743.      Do not follow symbolic links. Normally `myisamchk' repairs the
  17744.      table a symlink points at.  This option doesn't exist in MySQL 4.0,
  17745.      as MySQL 4.0 will not remove symlinks during repair.
  17746.  
  17747. `-r or --recover'
  17748.      Can fix almost anything except unique keys that aren't unique
  17749.      (which is an extremely unlikely error with ISAM/MyISAM tables).
  17750.      If you want to recover a table, this is the option to try first.
  17751.      Only if myisamchk reports that the table can't be recovered by
  17752.      `-r', you should then try `-o'.  (Note that in the unlikely case
  17753.      that `-r' fails, the datafile is still intact.)  If you have lots
  17754.      of memory, you should increase the size of `sort_buffer_size'!
  17755.  
  17756. `-o or --safe-recover'
  17757.      Uses an old recovery method (reads through all rows in order and
  17758.      updates all index trees based on the found rows); this is an order
  17759.      of magnitude slower than `-r', but can handle a couple of very
  17760.      unlikely cases that `-r' cannot handle.  This recovery method also
  17761.      uses much less disk space than `-r'. Normally one should always
  17762.      first repair with `-r', and only if this fails use `-o'.
  17763.  
  17764.      If you have lots of memory, you should increase the size of
  17765.      `key_buffer_size'!
  17766.  
  17767. `-n or --sort-recover'
  17768.      Force `myisamchk' to use sorting to resolve the keys even if the
  17769.      temporary files should be very big.
  17770.  
  17771. `--character-sets-dir=...'
  17772.      Directory where character sets are stored.
  17773.  
  17774. `--set-character-set=name'
  17775.      Change the character set used by the index
  17776.  
  17777. `-t or --tmpdir=path'
  17778.      Path for storing temporary files. If this is not set, `myisamchk'
  17779.      will use the environment variable `TMPDIR' for this.  Starting
  17780.      from MySQL 4.1, `tmpdir' can be set to a list of paths separated
  17781.      by colon `:' (semicolon `;' on Windows). They will be used in
  17782.      round-robin fashion.
  17783.  
  17784. `-q or --quick'
  17785.      Faster repair by not modifying the datafile. One can give a second
  17786.      `-q' to force `myisamchk' to modify the original datafile in case
  17787.      of duplicate keys
  17788.  
  17789. `-u or --unpack'
  17790.      Unpack file packed with myisampack.
  17791.  
  17792. Other Options for `myisamchk'
  17793. .............................
  17794.  
  17795. Other actions that `myisamchk' can do, besides repair and check tables:
  17796.  
  17797. `-a or --analyze'
  17798.      Analyse the distribution of keys. This improves join performance by
  17799.      enabling the join optimiser to better choose in which order it
  17800.      should join the tables and which keys it should use: `myisamchk
  17801.      --describe --verbose table_name'' or using `SHOW KEYS' in MySQL.
  17802.  
  17803. `-d or --description'
  17804.      Prints some information about table.
  17805.  
  17806. `-A or --set-auto-increment[=value]'
  17807.      Force `AUTO_INCREMENT' to start at this or higher value. If no
  17808.      value is given, then sets the next `AUTO_INCREMENT' value to the
  17809.      highest used value for the auto key + 1.
  17810.  
  17811. `-S or --sort-index'
  17812.      Sort the index tree blocks in high-low order.  This will optimise
  17813.      seeks and will make table scanning by key faster.
  17814.  
  17815. `-R or --sort-records=#'
  17816.      Sorts records according to an index.  This makes your data much
  17817.      more localised and may speed up ranged `SELECT' and `ORDER BY'
  17818.      operations on this index. (It may be very slow to do a sort the
  17819.      first time!)  To find out a table's index numbers, use `SHOW
  17820.      INDEX', which shows a table's indexes in the same order that
  17821.      `myisamchk' sees them.  Indexes are numbered beginning with 1.
  17822.  
  17823. `myisamchk' Memory Usage
  17824. ........................
  17825.  
  17826. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  17827. uses no more memory than you specify with the `-O' options.  If you are
  17828. going to use `myisamchk' on very large files, you should first decide
  17829. how much memory you want it to use.  The default is to use only about
  17830. 3M to fix things.  By using larger values, you can get `myisamchk' to
  17831. operate faster.  For example, if you have more than 32M RAM, you could
  17832. use options such as these (in addition to any other options you might
  17833. specify):
  17834.  
  17835.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  17836.  
  17837. Using `-O sort=16M' should probably be enough for most cases.
  17838.  
  17839. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  17840. points to a memory filesystem, you may easily get out of memory errors.
  17841. If this happens, set `TMPDIR' to point at some directory with more
  17842. space and restart `myisamchk'.
  17843.  
  17844. When repairing, `myisamchk' will also need a lot of disk space:
  17845.  
  17846.    * Double the size of the record file (the original one and a copy).
  17847.      This space is not needed if one does a repair with `--quick', as
  17848.      in this case only the index file will be re-created.  This space
  17849.      is needed on the same disk as the original record file!
  17850.  
  17851.    * Space for the new index file that replaces the old one. The old
  17852.      index file is truncated at start, so one usually ignore this space.
  17853.      This space is needed on the same disk as the original index file!
  17854.  
  17855.    * When using `--recover' or `--sort-recover' (but not when using
  17856.      `--safe-recover'), you will need space for a sort buffer for:
  17857.      `(largest_key + row_pointer_length)*number_of_rows * 2'.  You can
  17858.      check the length of the keys and the row_pointer_length with
  17859.      `myisamchk -dv table'.  This space is allocated on the temporary
  17860.      disk (specified by `TMPDIR' or `--tmpdir=#').
  17861.  
  17862. If you have a problem with disk space during repair, you can try to use
  17863. `--safe-recover' instead of `--recover'.
  17864.  
  17865. Using `myisamchk' for Crash Recovery
  17866. ....................................
  17867.  
  17868. If you run `mysqld' with `--skip-external-locking' (which is the
  17869. default on some systems, like Linux), you can't reliably use `myisamchk'
  17870. to check a table when `mysqld' is using the same table.  If you can be
  17871. sure that no one is accessing the tables through `mysqld' while you run
  17872. `myisamchk', you only have to do `mysqladmin flush-tables' before you
  17873. start checking the tables.  If you can't guarantee the above, then you
  17874. must take down `mysqld' while you check the tables.  If you run
  17875. `myisamchk' while `mysqld' is updating the tables, you may get a
  17876. warning that a table is corrupt even if it isn't.
  17877.  
  17878. If you are not using `--skip-external-locking', you can use `myisamchk'
  17879. to check tables at any time.  While you do this, all clients that try
  17880. to update the table will wait until `myisamchk' is ready before
  17881. continuing.
  17882.  
  17883. If you use `myisamchk' to repair or optimise tables, you *must* always
  17884. ensure that the `mysqld' server is not using the table (this also
  17885. applies if you are using `--skip-external-locking').  If you don't take
  17886. down `mysqld' you should at least do a `mysqladmin flush-tables' before
  17887. you run `myisamchk'.  Your tables *may be corrupted* if the server and
  17888. `myisamchk' access the tables simultaneously.
  17889.  
  17890. This chapter describes how to check for and deal with data corruption
  17891. in MySQL databases.  If your tables get corrupted frequently you should
  17892. try to find the reason for this! *Note Crashing::.
  17893.  
  17894. The `MyISAM' table section contains reason for why a table could be
  17895. corrupted. *Note MyISAM table problems::.
  17896.  
  17897. When performing crash recovery, it is important to understand that each
  17898. table `tbl_name' in a database corresponds to three files in the
  17899. database directory:
  17900.  
  17901. *File*         *Purpose*
  17902. `tbl_name.frm' Table definition
  17903.                (form) file
  17904. `tbl_name.MYD' Datafile
  17905. `tbl_name.MYI' Index file
  17906.  
  17907. Each of these three file types is subject to corruption in various
  17908. ways, but problems occur most often in datafiles and index files.
  17909.  
  17910. `myisamchk' works by creating a copy of the `.MYD' (data) file row by
  17911. row. It ends the repair stage by removing the old `.MYD' file and
  17912. renaming the new file to the original file name.  If you use `--quick',
  17913. `myisamchk' does not create a temporary `.MYD' file, but instead
  17914. assumes that the `.MYD' file is correct and only generates a new index
  17915. file without touching the `.MYD' file. This is safe, because
  17916. `myisamchk' automatically detects if the `.MYD' file is corrupt and
  17917. aborts the repair in this case.  You can also give two `--quick'
  17918. options to `myisamchk'.  In this case, `myisamchk' does not abort on
  17919. some errors (like duplicate key) but instead tries to resolve them by
  17920. modifying the `.MYD' file. Normally the use of two `--quick' options is
  17921. useful only if you have too little free disk space to perform a normal
  17922. repair.  In this case you should at least make a backup before running
  17923. `myisamchk'.
  17924.  
  17925. How to Check Tables for Errors
  17926. ..............................
  17927.  
  17928. To check a MyISAM table, use the following commands:
  17929.  
  17930. `myisamchk tbl_name'
  17931.      This finds 99.99% of all errors. What it can't find is corruption
  17932.      that involves *only* the datafile (which is very unusual). If you
  17933.      want to check a table, you should normally run `myisamchk' without
  17934.      options or with either the `-s' or `--silent' option.
  17935.  
  17936. `myisamchk -m tbl_name'
  17937.      This finds 99.999% of all errors. It checks first all index
  17938.      entries for errors and then it reads through all rows. It
  17939.      calculates a checksum for all keys in the rows and verifies that
  17940.      they checksum matches the checksum for the keys in the index tree.
  17941.  
  17942. `myisamchk -e tbl_name'
  17943.      This does a complete and thorough check of all data (`-e' means
  17944.      "extended check"). It does a check-read of every key for each row
  17945.      to verify that they indeed point to the correct row.  This may
  17946.      take a long time on a big table with many keys.  `myisamchk' will
  17947.      normally stop after the first error it finds. If you want to
  17948.      obtain more information, you can add the `--verbose' (`-v')
  17949.      option.  This causes `myisamchk' to keep going, up through a
  17950.      maximum of 20 errors.  In normal usage, a simple `myisamchk' (with
  17951.      no arguments other than the table name) is sufficient.
  17952.  
  17953. `myisamchk -e -i tbl_name'
  17954.      Like the previous command, but the `-i' option tells `myisamchk' to
  17955.      print some informational statistics, too.
  17956.  
  17957. How to Repair Tables
  17958. ....................
  17959.  
  17960. In the following section we only talk about using `myisamchk' on
  17961. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  17962. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  17963. instead.
  17964.  
  17965. Starting with MySQL Version 3.23.14, you can repair MyISAM tables with
  17966. the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  17967.  
  17968. The symptoms of a corrupted table include queries that abort
  17969. unexpectedly and observable errors such as these:
  17970.  
  17971.    * `tbl_name.frm' is locked against change
  17972.  
  17973.    * Can't find file `tbl_name.MYI' (Errcode: ###)
  17974.  
  17975.    * Unexpected end of file
  17976.  
  17977.    * Record file is crashed
  17978.  
  17979.    * Got error ### from table handler
  17980.  
  17981.      To get more information about the error you can run `perror ###'.
  17982.      Here is the most common errors that indicates a problem with the
  17983.      table:
  17984.  
  17985.           shell> perror 126 127 132 134 135 136 141 144 145
  17986.           126 = Index file is crashed / Wrong file format
  17987.           127 = Record-file is crashed
  17988.           132 = Old database file
  17989.           134 = Record was already deleted (or record file crashed)
  17990.           135 = No more room in record file
  17991.           136 = No more room in index file
  17992.           141 = Duplicate unique key or constraint on write or update
  17993.           144 = Table is crashed and last repair failed
  17994.           145 = Table was marked as crashed and should be repaired
  17995.  
  17996.      Note that error 135, no more room in record file, is not an error
  17997.      that can be fixed by a simple repair. In this case you have to do:
  17998.  
  17999.           ALTER TABLE table MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;
  18000.  
  18001.  
  18002. In the other cases, you must repair your tables. `myisamchk' can
  18003. usually detect and fix most things that go wrong.
  18004.  
  18005. The repair process involves up to four stages, described here. Before
  18006. you begin, you should `cd' to the database directory and check the
  18007. permissions of the table files. Make sure they are readable by the Unix
  18008. user that `mysqld' runs as (and to you, because you need to access the
  18009. files you are checking).  If it turns out you need to modify files,
  18010. they must also be writable by you.
  18011.  
  18012. If you are using MySQL Version 3.23.16 and above, you can (and should)
  18013. use the `CHECK' and `REPAIR' commands to check and repair `MyISAM'
  18014. tables.  *Note CHECK TABLE::.  *Note REPAIR TABLE::.
  18015.  
  18016. The manual section about table maintenance includes the options to
  18017. `isamchk'/`myisamchk'.  *Note Table maintenance::.
  18018.  
  18019. The following section is for the cases where the above command fails or
  18020. if you want to use the extended features that `isamchk'/`myisamchk'
  18021. provides.
  18022.  
  18023. If you are going to repair a table from the command-line, you must first
  18024. take down the `mysqld' server. Note that when you do `mysqladmin
  18025. shutdown' on a remote server, the `mysqld' server will still be alive
  18026. for a while after `mysqladmin' returns, until all queries are stopped
  18027. and all keys have been flushed to disk.
  18028.  
  18029. *Stage 1: Checking your tables*
  18030.  
  18031. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  18032. Use the `-s' (silent) option to suppress unnecessary information.
  18033.  
  18034. If the `mysqld' server is done you should use the -update option to tell
  18035. `myisamchk' to mark the table as 'checked'.
  18036.  
  18037. You have to repair only those tables for which `myisamchk' announces an
  18038. error.  For such tables, proceed to Stage 2.
  18039.  
  18040. If you get weird errors when checking (such as `out of memory' errors),
  18041. or if `myisamchk' crashes, go to Stage 3.
  18042.  
  18043. *Stage 2: Easy safe repair*
  18044.  
  18045. Note: If you want repairing to go much faster, you should add: `-O
  18046. sort_buffer=# -O key_buffer=#' (where # is about 1/4 of the available
  18047. memory) to all `isamchk/myisamchk' commands.
  18048.  
  18049. First, try `myisamchk -r -q tbl_name' (`-r -q' means "quick recovery
  18050. mode"). This will attempt to repair the index file without touching the
  18051. datafile.  If the datafile contains everything that it should and the
  18052. delete links point at the correct locations within the datafile, this
  18053. should work, and the table is fixed. Start repairing the next table.
  18054. Otherwise, use the following procedure:
  18055.  
  18056.   1. Make a backup of the datafile before continuing.
  18057.  
  18058.   2. Use `myisamchk -r tbl_name' (`-r' means "recovery mode"). This will
  18059.      remove incorrect records and deleted records from the datafile and
  18060.      reconstruct the index file.
  18061.  
  18062.   3. If the preceding step fails, use `myisamchk --safe-recover
  18063.      tbl_name'.  Safe recovery mode uses an old recovery method that
  18064.      handles a few cases that regular recovery mode doesn't (but is
  18065.      slower).
  18066.  
  18067. If you get weird errors when repairing (such as `out of memory'
  18068. errors), or if `myisamchk' crashes, go to Stage 3.
  18069.  
  18070. *Stage 3: Difficult repair*
  18071.  
  18072. You should only reach this stage if the first 16K block in the index
  18073. file is destroyed or contains incorrect information, or if the index
  18074. file is missing.  In this case, it's necessary to create a new index
  18075. file. Do so as follows:
  18076.  
  18077.   1. Move the datafile to some safe place.
  18078.  
  18079.   2. Use the table description file to create new (empty) data and
  18080.      index files:
  18081.  
  18082.           shell> mysql db_name
  18083.           mysql> SET AUTOCOMMIT=1;
  18084.           mysql> TRUNCATE TABLE table_name;
  18085.           mysql> quit
  18086.  
  18087.      If your SQL version doesn't have `TRUNCATE TABLE', use `DELETE FROM
  18088.      table_name' instead.
  18089.  
  18090.   3. Copy the old datafile back onto the newly created datafile.
  18091.      (Don't just move the old file back onto the new file; you want to
  18092.      retain a copy in case something goes wrong.)
  18093.  
  18094. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  18095. be an endless loop.)
  18096.  
  18097. As of `MySQL' 4.0.2 you can also use `REPAIR ... USE_FRM' which
  18098. performs the whole procedure automatically.
  18099.  
  18100. *Stage 4: Very difficult repair*
  18101.  
  18102. You should reach this stage only if the description file has also
  18103. crashed. That should never happen, because the description file isn't
  18104. changed after the table is created:
  18105.  
  18106.   1. Restore the description file from a backup and go back to Stage 3.
  18107.      You can also restore the index file and go back to Stage 2.  In
  18108.      the latter case, you should start with `myisamchk -r'.
  18109.  
  18110.   2. If you don't have a backup but know exactly how the table was
  18111.      created, create a copy of the table in another database.  Remove
  18112.      the new datafile, then move the description and index files from
  18113.      the other database to your crashed database.  This gives you new
  18114.      description and index files, but leaves the datafile alone.  Go
  18115.      back to Stage 2 and attempt to reconstruct the index file.
  18116.  
  18117. Table Optimisation
  18118. ..................
  18119.  
  18120. To coalesce fragmented records and eliminate wasted space resulting from
  18121. deleting or updating records, run `myisamchk' in recovery mode:
  18122.  
  18123.      shell> myisamchk -r tbl_name
  18124.  
  18125. You can optimise a table in the same way using the SQL `OPTIMIZE TABLE'
  18126. statement.  `OPTIMIZE TABLE' does a repair of the table and a key
  18127. analysis, and also sorts the index tree to give faster key lookups.
  18128. There is also no possibility of unwanted interaction between a utility
  18129. and the server, because the server does all the work when you use
  18130. `OPTIMIZE TABLE'. *Note OPTIMIZE TABLE::.
  18131.  
  18132. `myisamchk' also has a number of other options you can use to improve
  18133. the performance of a table:
  18134.  
  18135.    * `-S', `--sort-index'
  18136.  
  18137.    * `-R index_num', `--sort-records=index_num'
  18138.  
  18139.    * `-a', `--analyze'
  18140.  
  18141. For a full description of the option. *Note myisamchk syntax::.
  18142.  
  18143. Setting Up a Table Maintenance Regimen
  18144. --------------------------------------
  18145.  
  18146. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  18147. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  18148. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18149.  
  18150. It is a good idea to perform table checks on a regular basis rather than
  18151. waiting for problems to occur.  For maintenance purposes, you can use
  18152. `myisamchk -s' to check tables.  The `-s' option (short for `--silent')
  18153. causes `myisamchk' to run in silent mode, printing messages only when
  18154. errors occur.
  18155.  
  18156. It's also a good idea to check tables when the server starts up.  For
  18157. example, whenever the machine has done a reboot in the middle of an
  18158. update, you usually need to check all the tables that could have been
  18159. affected. (This is an "expected crashed table".) You could add a test to
  18160. `mysqld_safe' that runs `myisamchk' to check all tables that have been
  18161. modified during the last 24 hours if there is an old `.pid' (process
  18162. ID) file left after a reboot.  (The `.pid' file is created by `mysqld'
  18163. when it starts up and removed when it terminates normally.  The
  18164. presence of a `.pid' file at system startup time indicates that
  18165. `mysqld' terminated abnormally.)
  18166.  
  18167. An even better test would be to check any table whose last-modified time
  18168. is more recent than that of the `.pid' file.
  18169.  
  18170. You should also check your tables regularly during normal system
  18171. operation.  At MySQL AB, we run a `cron' job to check all our important
  18172. tables once a week, using a line like this in a `crontab' file:
  18173.  
  18174.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  18175.  
  18176. This prints out information about crashed tables so we can examine and
  18177. repair them when needed.
  18178.  
  18179. As we haven't had any unexpectedly crashed tables (tables that become
  18180. corrupted for reasons other than hardware trouble) for a couple of
  18181. years now (this is really true), once a week is more than enough for us.
  18182.  
  18183. We recommend that to start with, you execute `myisamchk -s' each night
  18184. on all tables that have been updated during the last 24 hours, until
  18185. you come to trust MySQL as much as we do.
  18186.  
  18187. Normally you don't need to maintain MySQL tables that much.  If you are
  18188. changing tables with dynamic size rows (tables with `VARCHAR', `BLOB'
  18189. or `TEXT' columns) or have tables with many deleted rows you may want
  18190. to from time to time (once a month?) defragment/reclaim space from the
  18191. tables.
  18192.  
  18193. You can do this by using `OPTIMIZE TABLE' on the tables in question or
  18194. if you can take the `mysqld' server down for a while do:
  18195.  
  18196.      isamchk -r --silent --sort-index -O sort_buffer_size=16M */*.ISM
  18197.      myisamchk -r --silent --sort-index  -O sort_buffer_size=16M */*.MYI
  18198.  
  18199. Getting Information About a Table
  18200. ---------------------------------
  18201.  
  18202. To get a description of a table or statistics about it, use the
  18203. commands shown here. We explain some of the information in more detail
  18204. later:
  18205.  
  18206.    * myisamchk -d tbl_name Runs `myisamchk' in "describe mode" to
  18207.      produce a description of your table. If you start the MySQL server
  18208.      using the `--skip-external-locking' option, `myisamchk' may report
  18209.      an error for a table that is updated while it runs.  However,
  18210.      because `myisamchk' doesn't change the table in describe mode,
  18211.      there isn't any risk of destroying data.
  18212.  
  18213.    * myisamchk -d -v tbl_name To produce more information about what
  18214.      `myisamchk' is doing, add `-v' to tell it to run in verbose mode.
  18215.  
  18216.    * myisamchk -eis tbl_name Shows only the most important information
  18217.      from a table. It is slow because it must read the whole table.
  18218.  
  18219.    * myisamchk -eiv tbl_name This is like `-eis', but tells you what is
  18220.      being done.
  18221.  
  18222. Example of `myisamchk -d' output:
  18223.      MyISAM file:     company.MYI
  18224.      Record format:   Fixed length
  18225.      Data records:    1403698  Deleted blocks:         0
  18226.      Recordlength:    226
  18227.      
  18228.      table description:
  18229.      Key Start Len Index   Type
  18230.      1   2     8   unique  double
  18231.      2   15    10  multip. text packed stripped
  18232.      3   219   8   multip. double
  18233.      4   63    10  multip. text packed stripped
  18234.      5   167   2   multip. unsigned short
  18235.      6   177   4   multip. unsigned long
  18236.      7   155   4   multip. text
  18237.      8   138   4   multip. unsigned long
  18238.      9   177   4   multip. unsigned long
  18239.          193   1           text
  18240.  
  18241. Example of `myisamchk -d -v' output:
  18242.      MyISAM file:         company
  18243.      Record format:       Fixed length
  18244.      File-version:        1
  18245.      Creation time:       1999-10-30 12:12:51
  18246.      Recover time:        1999-10-31 19:13:01
  18247.      Status:              checked
  18248.      Data records:           1403698  Deleted blocks:              0
  18249.      Datafile parts:         1403698  Deleted data:                0
  18250.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     3
  18251.      Max datafile length: 3791650815  Max keyfile length: 4294967294
  18252.      Recordlength:               226
  18253.      
  18254.      table description:
  18255.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  18256.      1   2     8   unique  double                      1 15845376      1024
  18257.      2   15    10  multip. text packed stripped        2 25062400      1024
  18258.      3   219   8   multip. double                     73 40907776      1024
  18259.      4   63    10  multip. text packed stripped        5 48097280      1024
  18260.      5   167   2   multip. unsigned short           4840 55200768      1024
  18261.      6   177   4   multip. unsigned long            1346 65145856      1024
  18262.      7   155   4   multip. text                     4995 75090944      1024
  18263.      8   138   4   multip. unsigned long              87 85036032      1024
  18264.      9   177   4   multip. unsigned long             178 96481280      1024
  18265.          193   1           text
  18266.  
  18267. Example of `myisamchk -eis' output:
  18268.      Checking MyISAM file: company
  18269.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18270.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  18271.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18272.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  18273.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18274.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18275.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18276.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18277.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  18278.      Total:    Keyblocks used:  98%  Packed:   17%
  18279.      
  18280.      Records:          1403698    M.recordlength:     226
  18281.      Packed:             0%
  18282.      Recordspace used:     100%   Empty space:          0%
  18283.      Blocks/Record:   1.00
  18284.      Record blocks:    1403698    Delete blocks:        0
  18285.      Recorddata:     317235748    Deleted data:         0
  18286.      Lost space:             0    Linkdata:             0
  18287.      
  18288.      User time 1626.51, System time 232.36
  18289.      Maximum resident set size 0, Integral resident set size 0
  18290.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  18291.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  18292.      Voluntary context switches 639, Involuntary context switches 28966
  18293.  
  18294. Example of `myisamchk -eiv' output:
  18295.      Checking MyISAM file: company
  18296.      Data records: 1403698   Deleted blocks:       0
  18297.      - check file-size
  18298.      - check delete-chain
  18299.      block_size 1024:
  18300.      index  1:
  18301.      index  2:
  18302.      index  3:
  18303.      index  4:
  18304.      index  5:
  18305.      index  6:
  18306.      index  7:
  18307.      index  8:
  18308.      index  9:
  18309.      No recordlinks
  18310.      - check index reference
  18311.      - check data record references index: 1
  18312.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18313.      - check data record references index: 2
  18314.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  18315.      - check data record references index: 3
  18316.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18317.      - check data record references index: 4
  18318.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  18319.      - check data record references index: 5
  18320.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18321.      - check data record references index: 6
  18322.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18323.      - check data record references index: 7
  18324.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18325.      - check data record references index: 8
  18326.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18327.      - check data record references index: 9
  18328.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  18329.      Total:    Keyblocks used:   9%  Packed:   17%
  18330.      
  18331.      - check records and index references
  18332.      [LOTS OF ROW NUMBERS DELETED]
  18333.      
  18334.      Records:          1403698    M.recordlength:     226   Packed:             0%
  18335.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  18336.      Record blocks:    1403698    Delete blocks:        0
  18337.      Recorddata:     317235748    Deleted data:         0
  18338.      Lost space:             0    Linkdata:             0
  18339.      
  18340.      User time 1639.63, System time 251.61
  18341.      Maximum resident set size 0, Integral resident set size 0
  18342.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  18343.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  18344.      Voluntary context switches 10604, Involuntary context switches 122798
  18345.  
  18346. Here are the sizes of the data and index files for the table used in the
  18347. preceding examples:
  18348.  
  18349.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  18350.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  18351.  
  18352. Explanations for the types of information `myisamchk' produces are
  18353. given here.  The "keyfile" is the index file.  "Record" and "row" are
  18354. synonymous:
  18355.  
  18356.    * ISAM file Name of the ISAM (index) file.
  18357.  
  18358.    * Isam-version Version of ISAM format. Currently always 2.
  18359.  
  18360.    * Creation time When the datafile was created.
  18361.  
  18362.    * Recover time When the index/datafile was last reconstructed.
  18363.  
  18364.    * Data records How many records are in the table.
  18365.  
  18366.    * Deleted blocks How many deleted blocks still have reserved space.
  18367.      You can optimise your table to minimise this space.  *Note
  18368.      Optimisation::.
  18369.  
  18370.    * Data file: Parts For dynamic record format, this indicates how
  18371.      many data blocks there are. For an optimised table without
  18372.      fragmented records, this is the same as `Data records'.
  18373.  
  18374.    * Deleted data How many bytes of non-reclaimed deleted data there
  18375.      are.  You can optimise your table to minimise this space.  *Note
  18376.      Optimisation::.
  18377.  
  18378.    * Data file pointer The size of the datafile pointer, in bytes. It
  18379.      is usually 2, 3, 4, or 5 bytes. Most tables manage with 2 bytes,
  18380.      but this cannot be controlled from MySQL yet. For fixed tables,
  18381.      this is a record address. For dynamic tables, this is a byte
  18382.      address.
  18383.  
  18384.    * Keyfile pointer The size of the index file pointer, in bytes. It
  18385.      is usually 1, 2, or 3 bytes. Most tables manage with 2 bytes, but
  18386.      this is calculated automatically by MySQL. It is always a block
  18387.      address.
  18388.  
  18389.    * Max datafile length How long the table's datafile (`.MYD' file)
  18390.      can become, in bytes.
  18391.  
  18392.    * Max keyfile length How long the table's key file (`.MYI' file) can
  18393.      become, in bytes.
  18394.  
  18395.    * Recordlength How much space each record takes, in bytes.
  18396.  
  18397.    * Record format The format used to store table rows.  The examples
  18398.      shown above use `Fixed length'.  Other possible values are
  18399.      `Compressed' and `Packed'.
  18400.  
  18401.    * table description A list of all keys in the table. For each key,
  18402.      some low-level information is presented:
  18403.  
  18404.         - Key This key's number.
  18405.  
  18406.         - Start Where in the record this index part starts.
  18407.  
  18408.         - Len How long this index part is. For packed numbers, this
  18409.           should always be the full length of the column. For strings,
  18410.           it may be shorter than the full length of the indexed column,
  18411.           because you can index a prefix of a string column.
  18412.  
  18413.         - Index `unique' or `multip.' (multiple). Indicates whether one
  18414.           value can exist multiple times in this index.
  18415.  
  18416.         - Type What data-type this index part has. This is an ISAM
  18417.           data-type with the options `packed', `stripped' or `empty'.
  18418.  
  18419.         - Root Address of the root index block.
  18420.  
  18421.         - Blocksize The size of each index block. By default this is
  18422.           1024, but the value may be changed at compile time.
  18423.  
  18424.         - Rec/key This is a statistical value used by the optimiser. It
  18425.           tells how many records there are per value for this key. A
  18426.           unique key always has a value of 1. This may be updated after
  18427.           a table is loaded (or greatly changed) with `myisamchk -a'.
  18428.           If this is not updated at all, a default value of 30 is given.
  18429.  
  18430.    * In the first example above, the 9th key is a multi-part key with
  18431.      two parts.
  18432.  
  18433.    * Keyblocks used What percentage of the keyblocks are used. Because
  18434.      the table used in the examples had just been reorganised with
  18435.      `myisamchk', the values are very high (very near the theoretical
  18436.      maximum).
  18437.  
  18438.    * Packed MySQL tries to pack keys with a common suffix. This can
  18439.      only be used for `CHAR'/`VARCHAR'/`DECIMAL' keys. For long strings
  18440.      like names, this can significantly reduce the space used. In the
  18441.      third example above, the 4th key is 10 characters long and a 60%
  18442.      reduction in space is achieved.
  18443.  
  18444.    * Max levels How deep the B-tree for this key is. Large tables with
  18445.      long keys get high values.
  18446.  
  18447.    * Records How many rows are in the table.
  18448.  
  18449.    * M.recordlength The average record length. For tables with
  18450.      fixed-length records, this is the exact record length.
  18451.  
  18452.    * Packed MySQL strips spaces from the end of strings. The `Packed'
  18453.      value indicates the percentage of savings achieved by doing this.
  18454.  
  18455.    * Recordspace used What percentage of the datafile is used.
  18456.  
  18457.    * Empty space What percentage of the datafile is unused.
  18458.  
  18459.    * Blocks/Record Average number of blocks per record (that is, how
  18460.      many links a fragmented record is composed of). This is always 1.0
  18461.      for fixed-format tables. This value should stay as close to 1.0 as
  18462.      possible. If it gets too big, you can reorganise the table with
  18463.      `myisamchk'.  *Note Optimisation::.
  18464.  
  18465.    * Recordblocks How many blocks (links) are used. For fixed format,
  18466.      this is the same as the number of records.
  18467.  
  18468.    * Deleteblocks How many blocks (links) are deleted.
  18469.  
  18470.    * Recorddata How many bytes in the datafile are used.
  18471.  
  18472.    * Deleted data How many bytes in the datafile are deleted (unused).
  18473.  
  18474.    * Lost space If a record is updated to a shorter length, some space
  18475.      is lost. This is the sum of all such losses, in bytes.
  18476.  
  18477.    * Linkdata When the dynamic table format is used, record fragments
  18478.      are linked with pointers (4 to 7 bytes each). `Linkdata' is the
  18479.      sum of the amount of storage used by all such pointers.
  18480.  
  18481. If a table has been compressed with `myisampack', `myisamchk -d' prints
  18482. additional information about each table column.  See *Note
  18483. `myisampack': myisampack, for an example of this information and a
  18484. description of what it means.
  18485.  
  18486. Database Administration Language Reference
  18487. ==========================================
  18488.  
  18489. `OPTIMIZE TABLE' Syntax
  18490. -----------------------
  18491.  
  18492.      OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name]...
  18493.  
  18494. `OPTIMIZE TABLE' should be used if you have deleted a large part of a
  18495. table or if you have made many changes to a table with variable-length
  18496. rows (tables that have `VARCHAR', `BLOB', or `TEXT' columns).  Deleted
  18497. records are maintained in a linked list and subsequent `INSERT'
  18498. operations reuse old record positions. You can use `OPTIMIZE TABLE' to
  18499. reclaim the unused space and to defragment the datafile.
  18500.  
  18501. In most setups you don't have to run `OPTIMIZE TABLE' at all.  Even if
  18502. you do a lot of updates to variable length rows it's not likely that
  18503. you need to do this more than once a month/week and only on certain
  18504. tables.
  18505.  
  18506. For the moment, `OPTIMIZE TABLE' works only on `MyISAM' and `BDB'
  18507. tables. For `BDB' tables, `OPTIMIZE TABLE' is currently mapped to
  18508. `ANALYZE TABLE'.  *Note `ANALYZE TABLE': ANALYZE TABLE.
  18509.  
  18510. You can get `OPTIMIZE TABLE' to work on other table types by starting
  18511. `mysqld' with `--skip-new' or `--safe-mode', but in this case `OPTIMIZE
  18512. TABLE' is just mapped to `ALTER TABLE'.
  18513.  
  18514. `OPTIMIZE TABLE' works the following way:
  18515.    * If the table has deleted or split rows, repair the table.
  18516.  
  18517.    * If the index pages are not sorted, sort them.
  18518.  
  18519.    * If the statistics are not up to date (and the repair couldn't be
  18520.      done by sorting the index), update them.
  18521.  
  18522. Note that the table is locked during the time `OPTIMIZE TABLE' is
  18523. running!
  18524.  
  18525. Strictly before MySQL 4.1.1, `OPTIMIZE' commands are not written to the
  18526. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  18527. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  18528. used.
  18529.  
  18530. `ANALYZE TABLE' Syntax
  18531. ----------------------
  18532.  
  18533.      ANALYZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name...]
  18534.  
  18535. Analyse and store the key distribution for the table.  During the
  18536. analysis, the table is locked with a read lock.  This works on `MyISAM'
  18537. and `BDB' tables.
  18538.  
  18539. This is equivalent to running `myisamchk -a' on the table.
  18540.  
  18541. MySQL uses the stored key distribution to decide in which order tables
  18542. should be joined when one does a join on something else than a constant.
  18543.  
  18544. The command returns a table with the following columns:
  18545.  
  18546. *Column*    *Value*
  18547. Table       Table name
  18548. Op          Always `analyze'
  18549. Msg_type    One of `status', `error',
  18550.             `info', or `warning'
  18551. Msg_text    The message
  18552.  
  18553. You can check the stored key distribution with the `SHOW INDEX' command.
  18554. *Note SHOW DATABASE INFO::.
  18555.  
  18556. If the table hasn't changed since the last `ANALYZE TABLE' command, the
  18557. table will not be analysed again.
  18558.  
  18559. Strictly before MySQL 4.1.1, `ANALYZE' commands are not written to the
  18560. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  18561. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  18562. used.
  18563.  
  18564. `FLUSH' Syntax
  18565. --------------
  18566.  
  18567.      FLUSH [LOCAL | NO_WRITE_TO_BINLOG] flush_option [,flush_option] ...
  18568.  
  18569. You should use the `FLUSH' command if you want to clear some of the
  18570. internal caches MySQL uses.  To execute `FLUSH', you must have the
  18571. `RELOAD' privilege.
  18572.  
  18573. `flush_option' can be any of the following:
  18574.  
  18575. *Option*           *Description*
  18576. `HOSTS'            Empties the host cache tables.  You should flush the
  18577.                    host tables if some of your hosts change IP number or
  18578.                    if you get the error message `Host ... is blocked'.
  18579.                    When more than `max_connect_errors' errors occur in a
  18580.                    row for a given host while connection to the MySQL
  18581.                    server, MySQL assumes something is wrong and blocks
  18582.                    the host from further connection requests.  Flushing
  18583.                    the host tables allows the host to attempt to connect
  18584.                    again. *Note Blocked host::. You can start `mysqld'
  18585.                    with `-O max_connect_errors=999999999' to avoid this
  18586.                    error message.
  18587. `DES_KEY_FILE'     Reloads the DES keys from the file that was specified
  18588.                    with the `--des-key-file' option at server startup
  18589.                    time.
  18590. `LOGS'             Closes and reopens all log files.  If you have
  18591.                    specified an update log file or a binary log file
  18592.                    without an extension, the extension number of the log
  18593.                    file will be incremented by one relative to the
  18594.                    previous file. If you have used an extension in the
  18595.                    file name, MySQL will close and reopen the update log
  18596.                    file.  *Note Update log::. This is the same thing as
  18597.                    sending the `SIGHUP' signal to the `mysqld' server.
  18598. `PRIVILEGES'       Reloads the privileges from the grant tables in the
  18599.                    `mysql' database.
  18600. `QUERY CACHE'      Defragment the query cache to better utilise its
  18601.                    memory.  This command will not remove any queries
  18602.                    from the cache, unlike `RESET QUERY CACHE'.
  18603. `TABLES'           Closes all open tables and force all tables in use to
  18604.                    be closed. This also flushes the query cache.
  18605. `[TABLE | TABLES]  Flushes only the given tables.
  18606. tbl_name           
  18607. [,tbl_name...]'    
  18608. `TABLES WITH READ  Closes all open tables and locks all tables for all
  18609. LOCK'              databases with a read lock until you execute `UNLOCK
  18610.                    TABLES'. This is very convenient way to get backups
  18611.                    if you have a filesystem, like Veritas, that can take
  18612.                    snapshots in time.
  18613. `STATUS'           Resets most status variables to zero. This is
  18614.                    something one should only use when debugging a query.
  18615. `USER_RESOURCES'   Resets all user resources to zero. This will enable
  18616.                    blocked users to login again. *Note User resources::.
  18617.  
  18618. Strictly before MySQL 4.1.1, `FLUSH' commands are not written to the
  18619. binary log. Since MySQL 4.1.1 they are written to the binary log unless
  18620. the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was
  18621. used, or unless the command contained one of these arguments: `LOGS',
  18622. `MASTER', `SLAVE', `TABLES WITH READ LOCK', because any of these
  18623. arguments may cause problems if replicated to a slave.
  18624.  
  18625. You can also access some of the commands shown above with the
  18626. `mysqladmin' utility, using the `flush-hosts', `flush-logs',
  18627. `flush-privileges', `flush-status' or `flush-tables' commands.
  18628.  
  18629. Take also a look at the `RESET' command used with replication.  *Note
  18630. `RESET': RESET.
  18631.  
  18632. `RESET' Syntax
  18633. --------------
  18634.  
  18635.      RESET reset_option [,reset_option] ...
  18636.  
  18637. The `RESET' command is used to clear things. It also acts as an stronger
  18638. version of the `FLUSH' command.  *Note `FLUSH': FLUSH.
  18639.  
  18640. To execute `RESET', you must have the `RELOAD' privilege.
  18641.  
  18642. *Option*           *Description*
  18643. `MASTER'           Deletes all binary logs listed in the index file,
  18644.                    resetting the binlog index file to be empty.
  18645.                    Previously named `FLUSH MASTER'. *Note Replication
  18646.                    SQL::.
  18647. `SLAVE'            Makes the slave forget its replication position in
  18648.                    the master logs.  Previously named `FLUSH SLAVE'.
  18649.                    *Note Replication SQL::.
  18650. `QUERY CACHE'      Removes all query results from the query cache.
  18651.  
  18652. `PURGE MASTER LOGS' Syntax
  18653. --------------------------
  18654.  
  18655.      PURGE {MASTER|BINARY} LOGS TO binlog_name
  18656.      PURGE {MASTER|BINARY} LOGS BEFORE date
  18657.  
  18658. This command is used to delete all binary logs strictly prior to the
  18659. specified binlog or date. *Note Replication SQL::.
  18660.  
  18661. `PURGE BINARY LOGS' is available as a synonym for `PURGE MASTER LOGS'
  18662. as of MySQL 4.1.1.
  18663.  
  18664. `KILL' Syntax
  18665. -------------
  18666.  
  18667.      KILL thread_id
  18668.  
  18669. Each connection to `mysqld' runs in a separate thread.  You can see
  18670. which threads are running with the `SHOW PROCESSLIST' command and kill
  18671. a thread with the `KILL thread_id' command.
  18672.  
  18673. If you have the `PROCESS' privilege, you can see all threads.  If you
  18674. have the `SUPER' privilege, you can kill all threads.  Otherwise, you
  18675. can only see and kill your own threads.
  18676.  
  18677. You can also use the `mysqladmin processlist' and `mysqladmin kill'
  18678. commands to examine and kill threads.
  18679.  
  18680. _Note_: You currently cannot use `KILL' with the Embedded MySQL Server
  18681. library, because the embedded server merely runs inside the threads of
  18682. the host application, it does not create connection threads of its own.
  18683.  
  18684. When you do a `KILL', a thread-specific `kill flag' is set for the
  18685. thread.
  18686.  
  18687. In most cases it may take some time for the thread to die as the kill
  18688. flag is only checked at specific intervals.
  18689.  
  18690.    * In `SELECT', `ORDER BY' and `GROUP BY' loops, the flag is checked
  18691.      after reading a block of rows. If the kill flag is set, the
  18692.      statement is aborted.
  18693.  
  18694.    * When doing an `ALTER TABLE' the kill flag is checked before each
  18695.      block of rows are read from the original table. If the kill flag
  18696.      was set the command is aborted and the temporary table is deleted.
  18697.  
  18698.    * When doing an `UPDATE' or `DELETE', the kill flag is checked after
  18699.      each block read and after each updated or deleted row. If the kill
  18700.      flag is set, the statement is aborted.  Note that if you are not
  18701.      using transactions, the changes will not be rolled back!
  18702.  
  18703.    * `GET_LOCK()' will abort with `NULL'.
  18704.  
  18705.    * An `INSERT DELAYED' thread will quickly flush all rows it has in
  18706.      memory and die.
  18707.  
  18708.    * If the thread is in the table lock handler (state: `Locked'), the
  18709.      table lock will be quickly aborted.
  18710.  
  18711.    * If the thread is waiting for free disk space in a `write' call, the
  18712.      write is aborted with an disk full error message.
  18713.  
  18714. `SHOW' Syntax
  18715. -------------
  18716.  
  18717.         SHOW DATABASES [LIKE wild]
  18718.      or SHOW [OPEN] TABLES [FROM db_name] [LIKE wild]
  18719.      or SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
  18720.      or SHOW INDEX FROM tbl_name [FROM db_name]
  18721.      or SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  18722.      or SHOW STATUS [LIKE wild]
  18723.      or SHOW VARIABLES [LIKE wild]
  18724.      or SHOW [BDB] LOGS
  18725.      or SHOW [FULL] PROCESSLIST
  18726.      or SHOW GRANTS FOR user
  18727.      or SHOW CREATE TABLE table_name
  18728.      or SHOW MASTER STATUS
  18729.      or SHOW MASTER LOGS
  18730.      or SHOW SLAVE STATUS
  18731.      or SHOW WARNINGS [LIMIT row_count]
  18732.      or SHOW ERRORS [LIMIT row_count]
  18733.      or SHOW TABLE TYPES
  18734.  
  18735. `SHOW' provides information about databases, tables, columns, or status
  18736. information about the server. If the `LIKE wild' part is used, the
  18737. `wild' string can be a string that uses the SQL `%' and `_' wildcard
  18738. characters.
  18739.  
  18740. Retrieving information about Database, Tables, Columns, and Indexes
  18741. ...................................................................
  18742.  
  18743. You can use `db_name.tbl_name' as an alternative to the `tbl_name FROM
  18744. db_name' syntax.  These two statements are equivalent:
  18745.  
  18746.      mysql> SHOW INDEX FROM mytable FROM mydb;
  18747.      mysql> SHOW INDEX FROM mydb.mytable;
  18748.  
  18749. `SHOW DATABASES' lists the databases on the MySQL server host.  You can
  18750. also get this list using the `mysqlshow' command line tool.  In version
  18751. 4.0.2 you will only see those databases for which you have some kind of
  18752. privilege, if you don't have the global `SHOW DATABASES' privilege.
  18753.  
  18754. `SHOW TABLES' lists the tables in a given database.  You can also get
  18755. this list using the `mysqlshow db_name' command.
  18756.  
  18757. *Note*: if a user doesn't have any privileges for a table, the table
  18758. will not show up in the output from `SHOW TABLES' or `mysqlshow
  18759. db_name'.
  18760.  
  18761. `SHOW OPEN TABLES' lists the tables that are currently open in the
  18762. table cache. *Note Table cache::.  The `Comment' field tells how many
  18763. times the table is `cached' and `in_use'.
  18764.  
  18765. `SHOW COLUMNS' lists the columns in a given table.  If you specify the
  18766. `FULL' option, you will also get the privileges you have for each
  18767. column.  If the column types are different from what you expect them to
  18768. be based on a `CREATE TABLE' statement, note that MySQL sometimes
  18769. changes column types.  *Note Silent column changes::.  As of MySQL 4.1,
  18770. the `FULL' keyword also causes any per-column comments to be displayed.
  18771.  
  18772. The `DESCRIBE' statement provides information similar to `SHOW COLUMNS'.
  18773. *Note `DESCRIBE': DESCRIBE.
  18774.  
  18775. `SHOW FIELDS' is a synonym for `SHOW COLUMNS', and `SHOW KEYS' is a
  18776. synonym for `SHOW INDEX'.  You can also list a table's columns or
  18777. indexes with `mysqlshow db_name tbl_name' or `mysqlshow -k db_name
  18778. tbl_name'.
  18779.  
  18780. `SHOW INDEX' returns the index information in a format that closely
  18781. resembles the `SQLStatistics' call in ODBC. The following columns are
  18782. returned:
  18783.  
  18784. *Column*    *Meaning*
  18785. `Table'     Name of the table.
  18786. `Non_unique'0 if the index can't contain
  18787.             duplicates, 1 if it can.
  18788. `Key_name'  Name of the index.
  18789. `Seq_in_index'Column sequence number in index,
  18790.                                           starting
  18791.             with 1.
  18792. `Column_name'Column name.
  18793. `Collation' How the column is sorted in the index.
  18794.             In MySQL, this can have values
  18795.                                         `A'
  18796.             (Ascending) or `NULL' (Not
  18797.                                     sorted).
  18798. `Cardinality'Number of unique values in the index.
  18799.             This is updated by running
  18800.                                     `isamchk -a'.
  18801. `Sub_part'  Number of indexed characters if the
  18802.             column is only partly indexed.
  18803.                                          `NULL' if
  18804.             the entire key is indexed.
  18805. `Null'      Contains 'YES' if the column may
  18806.             contain `NULL'.
  18807. `Index_type'Index method used.
  18808. `Comment'   Various remarks.  For now, it tells in
  18809.             MySQL < 4.0.2 whether index is
  18810.             `FULLTEXT' or not.
  18811.  
  18812. Note that as the `Cardinality' is counted based on statistics stored as
  18813. integers, it's not necessarily accurate for small tables.
  18814.  
  18815. The `Null' and `Index_type' columns were added in MySQL 4.0.2.
  18816.  
  18817. `SHOW TABLE STATUS'
  18818. ...................
  18819.  
  18820.      SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  18821.  
  18822. `SHOW TABLE STATUS' (new in Version 3.23) works likes `SHOW STATUS',
  18823. but provides a lot of information about each table. You can also get
  18824. this list using the `mysqlshow --status db_name' command.  The
  18825. following columns are returned:
  18826.  
  18827. *Column*       *Meaning*
  18828. `Name'         Name of the table.
  18829. `Type'         Type of table. *Note Table types::.
  18830. `Row_format'   The row storage format (Fixed, Dynamic, or
  18831.                Compressed).
  18832. `Rows'         Number of rows.
  18833. `Avg_row_length'Average row length.
  18834. `Data_length'  Length of the datafile.
  18835. `Max_data_length'Max length of the datafile.  For fixed row
  18836.                formats, this is the max number of rows in the
  18837.                table.  For dynamic row formats, this is the
  18838.                total number of data bytes that can be stored in
  18839.                the table, given the data pointer size used.
  18840. `Index_length' Length of the index file.
  18841. `Data_free'    Number of allocated but not used bytes.
  18842. `Auto_increment'Next autoincrement value.
  18843. `Create_time'  When the table was created.
  18844. `Update_time'  When the datafile was last updated.
  18845. `Check_time'   When the table was last checked.
  18846. `Create_options'Extra options used with `CREATE TABLE'.
  18847. `Comment'      The comment used when creating the table (or some
  18848.                information why MySQL couldn't access the table
  18849.                information).
  18850.  
  18851. `InnoDB' tables will report the free space in the tablespace in the
  18852. table comment.
  18853.  
  18854. `SHOW STATUS'
  18855. .............
  18856.  
  18857. `SHOW STATUS' provides server status information (like `mysqladmin
  18858. extended-status'). The output resembles that shown here, though the
  18859. format and numbers probably differ:
  18860.  
  18861.      +--------------------------+------------+
  18862.      | Variable_name            | Value      |
  18863.      +--------------------------+------------+
  18864.      | Aborted_clients          | 0          |
  18865.      | Aborted_connects         | 0          |
  18866.      | Bytes_received           | 155372598  |
  18867.      | Bytes_sent               | 1176560426 |
  18868.      | Connections              | 30023      |
  18869.      | Created_tmp_disk_tables  | 0          |
  18870.      | Created_tmp_tables       | 8340       |
  18871.      | Created_tmp_files        | 60         |
  18872.      | Delayed_insert_threads   | 0          |
  18873.      | Delayed_writes           | 0          |
  18874.      | Delayed_errors           | 0          |
  18875.      | Flush_commands           | 1          |
  18876.      | Handler_delete           | 462604     |
  18877.      | Handler_read_first       | 105881     |
  18878.      | Handler_read_key         | 27820558   |
  18879.      | Handler_read_next        | 390681754  |
  18880.      | Handler_read_prev        | 6022500    |
  18881.      | Handler_read_rnd         | 30546748   |
  18882.      | Handler_read_rnd_next    | 246216530  |
  18883.      | Handler_update           | 16945404   |
  18884.      | Handler_write            | 60356676   |
  18885.      | Key_blocks_used          | 14955      |
  18886.      | Key_read_requests        | 96854827   |
  18887.      | Key_reads                | 162040     |
  18888.      | Key_write_requests       | 7589728    |
  18889.      | Key_writes               | 3813196    |
  18890.      | Max_used_connections     | 0          |
  18891.      | Not_flushed_key_blocks   | 0          |
  18892.      | Not_flushed_delayed_rows | 0          |
  18893.      | Open_tables              | 1          |
  18894.      | Open_files               | 2          |
  18895.      | Open_streams             | 0          |
  18896.      | Opened_tables            | 44600      |
  18897.      | Questions                | 2026873    |
  18898.      | Select_full_join         | 0          |
  18899.      | Select_full_range_join   | 0          |
  18900.      | Select_range             | 99646      |
  18901.      | Select_range_check       | 0          |
  18902.      | Select_scan              | 30802      |
  18903.      | Slave_running            | OFF        |
  18904.      | Slave_open_temp_tables   | 0          |
  18905.      | Slow_launch_threads      | 0          |
  18906.      | Slow_queries             | 0          |
  18907.      | Sort_merge_passes        | 30         |
  18908.      | Sort_range               | 500        |
  18909.      | Sort_rows                | 30296250   |
  18910.      | Sort_scan                | 4650       |
  18911.      | Table_locks_immediate    | 1920382    |
  18912.      | Table_locks_waited       | 0          |
  18913.      | Threads_cached           | 0          |
  18914.      | Threads_created          | 30022      |
  18915.      | Threads_connected        | 1          |
  18916.      | Threads_running          | 1          |
  18917.      | Uptime                   | 80380      |
  18918.      +--------------------------+------------+
  18919.  
  18920. The status variables listed above have the following meaning:
  18921.  
  18922. *Variable*             *Meaning*
  18923. `Aborted_clients'      Number of connections aborted because the client
  18924.                        died without closing the connection properly.
  18925.                        *Note Communication errors::.
  18926. `Aborted_connects'     Number of tries to connect to the MySQL server
  18927.                        that failed. *Note Communication errors::.
  18928. `Bytes_received'       Number of bytes received from all clients.
  18929. `Bytes_sent'           Number of bytes sent to all clients.
  18930. `Com_xxx'              Number of times each xxx command has been
  18931.                        executed.
  18932. `Connections'          Number of connection attempts to the MySQL server.
  18933. `Created_tmp_disk_tables'Number of implicit temporary tables on disk
  18934.                        created while executing statements.
  18935. `Created_tmp_tables'   Number of implicit temporary tables in memory
  18936.                        created while executing statements.
  18937. `Created_tmp_files'    How many temporary files `mysqld' has created.
  18938. `Delayed_insert_threads'Number of delayed insert handler threads in use.
  18939. `Delayed_writes'       Number of rows written with `INSERT DELAYED'.
  18940. `Delayed_errors'       Number of rows written with `INSERT DELAYED' for
  18941.                        which some error occurred (probably `duplicate
  18942.                        key').
  18943. `Flush_commands'       Number of executed `FLUSH' commands.
  18944. `Handler_commit'       Number of internal `COMMIT' commands.
  18945. `Handler_delete'       Number of times a row was deleted from a table.
  18946. `Handler_read_first'   Number of times the first entry was read from an
  18947.                        index.  If this is high, it suggests that the
  18948.                        server is doing a lot of full index scans, for
  18949.                        example, `SELECT col1 FROM foo', assuming that
  18950.                        col1 is indexed.
  18951. `Handler_read_key'     Number of requests to read a row based on a key.
  18952.                        If this is high, it is a good indication that
  18953.                        your queries and tables are properly indexed.
  18954. `Handler_read_next'    Number of requests to read next row in key order.
  18955.                        This will be incremented if you are querying an
  18956.                        index column with a range constraint. This also
  18957.                        will be incremented if you are doing an index
  18958.                        scan.
  18959. `Handler_read_prev'    Number of requests to read previous row in key
  18960.                        order.  This is mainly used to optimise `ORDER BY
  18961.                        ... DESC'.
  18962. `Handler_read_rnd'     Number of requests to read a row based on a fixed
  18963.                        position.  This will be high if you are doing a
  18964.                        lot of queries that require sorting of the result.
  18965. `Handler_read_rnd_next'Number of requests to read the next row in the
  18966.                        datafile.  This will be high if you are doing a
  18967.                        lot of table scans. Generally this suggests that
  18968.                        your tables are not properly indexed or that your
  18969.                        queries are not written to take advantage of the
  18970.                        indexes you have.
  18971. `Handler_rollback'     Number of internal `ROLLBACK' commands.
  18972. `Handler_update'       Number of requests to update a row in a table.
  18973. `Handler_write'        Number of requests to insert a row in a table.
  18974. `Key_blocks_used'      The number of used blocks in the key cache.
  18975. `Key_read_requests'    The number of requests to read a key block from
  18976.                        the cache.
  18977. `Key_reads'            The number of physical reads of a key block from
  18978.                        disk.
  18979. `Key_write_requests'   The number of requests to write a key block to
  18980.                        the cache.
  18981. `Key_writes'           The number of physical writes of a key block to
  18982.                        disk.
  18983. `Max_used_connections' The maximum number of connections in use
  18984.                        simultaneously.
  18985. `Not_flushed_key_blocks'Keys blocks in the key cache that has changed but
  18986.                        hasn't yet been flushed to disk.
  18987. `Not_flushed_delayed_rows'Number of rows waiting to be written in `INSERT
  18988.                        DELAY' queues.
  18989. `Open_tables'          Number of tables that are open.
  18990. `Open_files'           Number of files that are open.
  18991. `Open_streams'         Number of streams that are open (used mainly for
  18992.                        logging).
  18993. `Opened_tables'        Number of tables that have been opened.
  18994. `Rpl_status'           Status of failsafe replication. (Not yet in use).
  18995. `Select_full_join'     Number of joins without keys (If this is not 0,
  18996.                        you should carefully check the indexes of your
  18997.                        tables).
  18998. `Select_full_range_join'Number of joins where we used a range search on
  18999.                        reference table.
  19000. `Select_range'         Number of joins where we used ranges on the first
  19001.                        table. (It's normally not critical even if this
  19002.                        is big.)
  19003. `Select_scan'          Number of joins where we did a full scan of the
  19004.                        first table.
  19005. `Select_range_check'   Number of joins without keys where we check for
  19006.                        key usage after each row (If this is not 0, you
  19007.                        should carefully check the indexes of your
  19008.                        tables).
  19009. `Questions'            Number of queries sent to the server.
  19010. `Slave_open_temp_tables'Number of temporary tables currently open by the
  19011.                        slave thread
  19012. `Slave_running'        Is `ON' if this is a slave that is connected to a
  19013.                        master.
  19014. `Slow_launch_threads'  Number of threads that have taken more than
  19015.                        `slow_launch_time' to create.
  19016. `Slow_queries'         Number of queries that have taken more than
  19017.                        `long_query_time' seconds. *Note Slow query log::.
  19018. `Sort_merge_passes'    Number of merges passes the sort algoritm have
  19019.                        had to do. If this value is large you should
  19020.                        consider increasing `sort_buffer'.
  19021. `Sort_range'           Number of sorts that were done with ranges.
  19022. `Sort_rows'            Number of sorted rows.
  19023. `Sort_scan'            Number of sorts that were done by scanning the
  19024.                        table.
  19025. `ssl_xxx'              Variables used by SSL; Not yet implemented.
  19026. `Table_locks_immediate'Number of times a table lock was acquired
  19027.                        immediately. Available after 3.23.33.
  19028. `Table_locks_waited'   Number of times a table lock could not be
  19029.                        acquired immediately and a wait was needed. If
  19030.                        this is high, and you have performance problems,
  19031.                        you should first optimise your queries, and then
  19032.                        either split your table(s) or use replication.
  19033.                        Available after 3.23.33.
  19034. `Threads_cached'       Number of threads in the thread cache.
  19035. `Threads_connected'    Number of currently open connections.
  19036. `Threads_created'      Number of threads created to handle connections.
  19037. `Threads_running'      Number of threads that are not sleeping.
  19038. `Uptime'               How many seconds the server has been up.
  19039.  
  19040. Some comments about the above:
  19041.  
  19042.    * If `Opened_tables' is big, then your `table_cache' variable is
  19043.      probably too small.
  19044.  
  19045.    * If `Key_reads' is big, then your `key_buffer_size' variable is
  19046.      probably too small.  The *cache miss rate* can be calculated with
  19047.      `Key_reads'/`Key_read_requests'.
  19048.  
  19049.    * If `Handler_read_rnd' is big, then you probably have a lot of
  19050.      queries that require MySQL to scan whole tables or you have joins
  19051.      that don't use keys properly.
  19052.  
  19053.    * If `Threads_created' is big, you may want to increase the
  19054.      `thread_cache_size' variable.  The cache hit rate can be calculated
  19055.      with `Threads_created'/`Connections'.
  19056.  
  19057.    * If `Created_tmp_disk_tables' is big, you may want to increase the
  19058.      `tmp_table_size' variable to get the temporary tables memory-based
  19059.      instead of disk based.
  19060.  
  19061. `SHOW VARIABLES'
  19062. ................
  19063.  
  19064.      SHOW [GLOBAL | SESSION] VARIABLES [LIKE wild]
  19065.  
  19066. `SHOW VARIABLES' shows the values of some MySQL system variables.  The
  19067. options `GLOBAL' and `SESSION' are new in MySQL 4.0.3.  With `GLOBAL'
  19068. you will get the variables that will be used for new connections to
  19069. MySQL. With `SESSION' you will get the values that are in effect for
  19070. the current connection. If you are not using either option, `SESSION'
  19071. is used.
  19072.  
  19073. If the default values are unsuitable, you can set most of these
  19074. variables using command-line options when `mysqld' starts up.  *Note
  19075. Command-line options::. It is also possible to change most variables
  19076. with the `SET' statement.  *Note `SET': SET OPTION.
  19077.  
  19078. The output from `SHOW VARIABLES' resembles that shown in the following
  19079. list, though the format and numbers may differ somewhat.  You can also
  19080. get this information using the `mysqladmin variables' command.
  19081.  
  19082.      +---------------------------------+------------------------------+
  19083.      | Variable_name                   | Value                        |
  19084.      +---------------------------------+------------------------------|
  19085.      | back_log                        | 50                           |
  19086.      | basedir                         | /usr/local/mysql             |
  19087.      | bdb_cache_size                  | 8388572                      |
  19088.      | bdb_log_buffer_size             | 32768                        |
  19089.      | bdb_home                        | /usr/local/mysql             |
  19090.      | bdb_max_lock                    | 10000                        |
  19091.      | bdb_logdir                      |                              |
  19092.      | bdb_shared_data                 | OFF                          |
  19093.      | bdb_tmpdir                      | /tmp/                        |
  19094.      | bdb_version                     | Sleepycat Software: ...      |
  19095.      | binlog_cache_size               | 32768                        |
  19096.      | bulk_insert_buffer_size         | 8388608                      |
  19097.      | character_set                   | latin1                       |
  19098.      | character_sets                  | latin1 big5 czech euc_kr     |
  19099.      | concurrent_insert               | ON                           |
  19100.      | connect_timeout                 | 5                            |
  19101.      | convert_character_set           |                              |
  19102.      | datadir                         | /usr/local/mysql/data/       |
  19103.      | delay_key_write                 | ON                           |
  19104.      | delayed_insert_limit            | 100                          |
  19105.      | delayed_insert_timeout          | 300                          |
  19106.      | delayed_queue_size              | 1000                         |
  19107.      | flush                           | OFF                          |
  19108.      | flush_time                      | 0                            |
  19109.      | ft_boolean_syntax               | + -><()~*:""&|               |
  19110.      | ft_min_word_len                 | 4                            |
  19111.      | ft_max_word_len                 | 254                          |
  19112.      | ft_max_word_len_for_sort        | 20                           |
  19113.      | ft_stopword_file                | (built-in)                   |
  19114.      | have_bdb                        | YES                          |
  19115.      | have_innodb                     | YES                          |
  19116.      | have_isam                       | YES                          |
  19117.      | have_raid                       | NO                           |
  19118.      | have_symlink                    | DISABLED                     |
  19119.      | have_openssl                    | YES                          |
  19120.      | have_query_cache                | YES                          |
  19121.      | init_file                       |                              |
  19122.      | innodb_additional_mem_pool_size | 1048576                      |
  19123.      | innodb_buffer_pool_size         | 8388608                      |
  19124.      | innodb_data_file_path           | ibdata1:10M:autoextend       |
  19125.      | innodb_data_home_dir            |                              |
  19126.      | innodb_file_io_threads          | 4                            |
  19127.      | innodb_force_recovery           | 0                            |
  19128.      | innodb_thread_concurrency       | 8                            |
  19129.      | innodb_flush_log_at_trx_commit  | 1                            |
  19130.      | innodb_fast_shutdown            | ON                           |
  19131.      | innodb_flush_method             |                              |
  19132.      | innodb_lock_wait_timeout        | 50                           |
  19133.      | innodb_log_arch_dir             |                              |
  19134.      | innodb_log_archive              | OFF                          |
  19135.      | innodb_log_buffer_size          | 1048576                      |
  19136.      | innodb_log_file_size            | 5242880                      |
  19137.      | innodb_log_files_in_group       | 2                            |
  19138.      | innodb_log_group_home_dir       | ./                           |
  19139.      | innodb_mirrored_log_groups      | 1                            |
  19140.      | interactive_timeout             | 28800                        |
  19141.      | join_buffer_size                | 131072                       |
  19142.      | key_buffer_size                 | 16773120                     |
  19143.      | language                        | /usr/local/mysql/share/...   |
  19144.      | large_files_support             | ON                           |
  19145.      | local_infile                    | ON                           |
  19146.      | locked_in_memory                | OFF                          |
  19147.      | log                             | OFF                          |
  19148.      | log_update                      | OFF                          |
  19149.      | log_bin                         | OFF                          |
  19150.      | log_slave_updates               | OFF                          |
  19151.      | log_slow_queries                | OFF                          |
  19152.      | log_warnings                    | OFF                          |
  19153.      | long_query_time                 | 10                           |
  19154.      | low_priority_updates            | OFF                          |
  19155.      | lower_case_table_names          | OFF                          |
  19156.      | max_allowed_packet              | 1047552                      |
  19157.      | max_binlog_cache_size           | 4294967295                   |
  19158.      | max_binlog_size                 | 1073741824                   |
  19159.      | max_connections                 | 100                          |
  19160.      | max_connect_errors              | 10                           |
  19161.      | max_delayed_threads             | 20                           |
  19162.      | max_heap_table_size             | 16777216                     |
  19163.      | max_join_size                   | 4294967295                   |
  19164.      | max_relay_log_size              | 0                            |
  19165.      | max_sort_length                 | 1024                         |
  19166.      | max_user_connections            | 0                            |
  19167.      | max_tmp_tables                  | 32                           |
  19168.      | max_write_lock_count            | 4294967295                   |
  19169.      | myisam_max_extra_sort_file_size | 268435456                    |
  19170.      | myisam_repair_threads           | 1                            |
  19171.      | myisam_max_sort_file_size       | 2147483647                   |
  19172.      | myisam_recover_options          | force                        |
  19173.      | myisam_sort_buffer_size         | 8388608                      |
  19174.      | net_buffer_length               | 16384                        |
  19175.      | net_read_timeout                | 30                           |
  19176.      | net_retry_count                 | 10                           |
  19177.      | net_write_timeout               | 60                           |
  19178.      | open_files_limit                | 1024                         |
  19179.      | pid_file                        | /usr/local/mysql/name.pid    |
  19180.      | port                            | 3306                         |
  19181.      | protocol_version                | 10                           |
  19182.      | query_cache_limit               | 1048576                      |
  19183.      | query_cache_size                | 0                            |
  19184.      | query_cache_type                | ON                           |
  19185.      | read_buffer_size                | 131072                       |
  19186.      | read_rnd_buffer_size            | 262144                       |
  19187.      | rpl_recovery_rank               | 0                            |
  19188.      | safe_show_database              | OFF                          |
  19189.      | server_id                       | 0                            |
  19190.      | slave_net_timeout               | 3600                         |
  19191.      | skip_external_locking           | ON                           |
  19192.      | skip_networking                 | OFF                          |
  19193.      | skip_show_database              | OFF                          |
  19194.      | slow_launch_time                | 2                            |
  19195.      | socket                          | /tmp/mysql.sock              |
  19196.      | sort_buffer_size                | 2097116                      |
  19197.      | sql_mode                        |                              |
  19198.      | table_cache                     | 64                           |
  19199.      | table_type                      | MYISAM                       |
  19200.      | thread_cache_size               | 3                            |
  19201.      | thread_stack                    | 131072                       |
  19202.      | tx_isolation                    | READ-COMMITTED               |
  19203.      | timezone                        | EEST                         |
  19204.      | tmp_table_size                  | 33554432                     |
  19205.      | tmpdir                          | /tmp/:/mnt/hd2/tmp/          |
  19206.      | version                         | 4.0.4-beta                   |
  19207.      | wait_timeout                    | 28800                        |
  19208.      +---------------------------------+------------------------------+
  19209.  
  19210. Each option is described here. Values for buffer sizes, lengths, and
  19211. stack sizes are given in bytes.  You can specify values with a suffix
  19212. of `K' or `M' to indicate kilobytes or megabytes. For example, `16M'
  19213. indicates 16 megabytes.  The case of suffix letters does not matter;
  19214. `16M' and `16m' are equivalent:
  19215.  
  19216.    * `ansi_mode'.  Is `ON' if `mysqld' was started with `--ansi'.
  19217.      *Note ANSI mode::.
  19218.  
  19219.    * `back_log' The number of outstanding connection requests MySQL can
  19220.      have. This comes into play when the main MySQL thread gets *very*
  19221.      many connection requests in a very short time. It then takes some
  19222.      time (although very little) for the main thread to check the
  19223.      connection and start a new thread. The `back_log' value indicates
  19224.      how many requests can be stacked during this short time before
  19225.      MySQL momentarily stops answering new requests. You need to
  19226.      increase this only if you expect a large number of connections in
  19227.      a short period of time.
  19228.  
  19229.      In other words, this value is the size of the listen queue for
  19230.      incoming TCP/IP connections.  Your operating system has its own
  19231.      limit on the size of this queue.  The manual page for the Unix
  19232.      `listen(2)' system call should have more details.  Check your OS
  19233.      documentation for the maximum value for this variable.  Attempting
  19234.      to set `back_log' higher than your operating system limit will be
  19235.      ineffective.
  19236.  
  19237.    * `basedir' The value of the `--basedir' option.
  19238.  
  19239.    * `bdb_cache_size' The buffer that is allocated to cache index and
  19240.      rows for `BDB' tables.  If you don't use `BDB' tables, you should
  19241.      start `mysqld' with `--skip-bdb' to not waste memory for this
  19242.      cache.
  19243.  
  19244.    * `bdb_log_buffer_size' The buffer that is allocated to cache index
  19245.      and rows for `BDB' tables.  If you don't use `BDB' tables, you
  19246.      should set this to 0 or start `mysqld' with `--skip-bdb' to not
  19247.      waste memory for this cache.
  19248.  
  19249.    * `bdb_home' The value of the `--bdb-home' option.
  19250.  
  19251.    * `bdb_max_lock' The maximum number of locks (10,000 by default) you
  19252.      can have active on a BDB table. You should increase this if you
  19253.      get errors of type `bdb: Lock table is out of available locks' or
  19254.      `Got error 12 from ...' when you have do long transactions or when
  19255.      `mysqld' has to examine a lot of rows to calculate the query.
  19256.  
  19257.    * `bdb_logdir' The value of the `--bdb-logdir' option.
  19258.  
  19259.    * `bdb_shared_data' Is `ON' if you are using `--bdb-shared-data'.
  19260.  
  19261.    * `bdb_tmpdir' The value of the `--bdb-tmpdir' option.
  19262.  
  19263.    * `binlog_cache_size'.  The size of the cache to hold the SQL
  19264.      statements for the binary log during a transaction.  If you often
  19265.      use big, multi-statement transactions you can increase this to get
  19266.      more performance. *Note COMMIT::.
  19267.  
  19268.    * `bulk_insert_buffer_size' (was `myisam_bulk_insert_tree_size')
  19269.      MyISAM uses special tree-like cache to make bulk inserts (that is,
  19270.      `INSERT ... SELECT', `INSERT ... VALUES (...), (...), ...', and
  19271.      `LOAD DATA INFILE') faster. This variable limits the size of the
  19272.      cache tree in bytes per thread. Setting it to 0 will disable this
  19273.      optimisation.  *Note*: this cache is only used when adding data to
  19274.      non-empty table.  Default value is 8 MB.
  19275.  
  19276.    * `character_set' The default character set.
  19277.  
  19278.    * `character_sets' The supported character sets.
  19279.  
  19280.    * `concurrent_inserts' If `ON' (the default), MySQL will allow you
  19281.      to use `INSERT' on `MyISAM' tables at the same time as you run
  19282.      `SELECT' queries on them.  You can turn this option off by
  19283.      starting `mysqld' with `--safe' or `--skip-new'.
  19284.  
  19285.    * `connect_timeout' The number of seconds the `mysqld' server is
  19286.      waiting for a connect packet before responding with `Bad
  19287.      handshake'.
  19288.  
  19289.    * `datadir' The value of the `--datadir' option.
  19290.  
  19291.    * `delay_key_write' Option for MyISAM tables. Can have one of the
  19292.      following values:
  19293.  
  19294.      OFF                  All `CREATE TABLE ... DELAYED_KEY_WRITE' are
  19295.                           ignored.
  19296.      ON                   (default)  MySQL will honor the
  19297.                           `DELAY_KEY_WRITE' option for `CREATE TABLE'.
  19298.      ALL                  All new opened tables are treated as if they
  19299.                           were created with the `DELAY_KEY_WRITE' option.
  19300.  
  19301.      If `DELAY_KEY_WRITE' is enabled this means that the key buffer for
  19302.      tables with this option will not get flushed on every index
  19303.      update, but only when a table is closed.  This will speed up
  19304.      writes on keys a lot, but you should add automatic checking of all
  19305.      tables with `myisamchk --fast --force' if you use this.
  19306.  
  19307.    * `delayed_insert_limit' After inserting `delayed_insert_limit'
  19308.      rows, the `INSERT DELAYED' handler will check if there are any
  19309.      `SELECT' statements pending. If so, it allows these to execute
  19310.      before continuing.
  19311.  
  19312.    * `delayed_insert_timeout' How long a `INSERT DELAYED' thread should
  19313.      wait for `INSERT' statements before terminating.
  19314.  
  19315.    * `delayed_queue_size' What size queue (in rows) should be allocated
  19316.      for handling `INSERT DELAYED'.  If the queue becomes full, any
  19317.      client that does `INSERT DELAYED' will wait until there is room in
  19318.      the queue again.
  19319.  
  19320.    * `flush' This is `ON' if you have started MySQL with the `--flush'
  19321.      option.
  19322.  
  19323.    * `flush_time' If this is set to a non-zero value, then every
  19324.      `flush_time' seconds all tables will be closed (to free up
  19325.      resources and sync things to disk). We only recommend this option
  19326.      on Windows 9x/Me, or on systems where you have very little
  19327.      resources.
  19328.  
  19329.    * `ft_boolean_syntax' List of operators supported by `MATCH ...
  19330.      AGAINST(... IN BOOLEAN MODE)'.  *Note Fulltext Search::.
  19331.  
  19332.    * `ft_min_word_len' The minimum length of the word to be included in
  19333.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  19334.      after changing this variable.* (This option is new for MySQL 4.0.)
  19335.  
  19336.    * `ft_max_word_len' The maximum length of the word to be included in
  19337.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  19338.      after changing this variable.* (This option is new for MySQL 4.0.)
  19339.  
  19340.    * `ft_max_word_len_for_sort' The maximum length of the word in a
  19341.      `FULLTEXT' index to be used in fast index recreation method in
  19342.      `REPAIR', `CREATE INDEX',  or `ALTER TABLE'.  Longer words are
  19343.      inserted the slow way.  The rule of the thumb is as follows: with
  19344.      `ft_max_word_len_for_sort' increasing, *MySQL* will create bigger
  19345.      temporary files (thus slowing the process down, due to disk I/O),
  19346.      and will put fewer keys in one sort block (again, decreasing the
  19347.      efficiency).  When `ft_max_word_len_for_sort' is too small,
  19348.      instead, *MySQL* will insert a lot of words into index the slow
  19349.      way, but short words will be inserted very quickly.
  19350.  
  19351.    * `ft_stopword_file' The file from which to read the list of
  19352.      stopwords for full-text searches.  All the words from the file
  19353.      will be used; comments are *not* honored.  By default, built-in
  19354.      list of stopwords is used (as defined in `myisam/ft_static.c').
  19355.      Setting this parameter to an empty string (`""') will disable
  19356.      stopword filtering.  *Note: `FULLTEXT' indexes must be rebuilt
  19357.      after changing this variable.* (This option is new for MySQL
  19358.      4.0.10)
  19359.  
  19360.    * `have_innodb' `YES' if `mysqld' supports InnoDB tables. `DISABLED'
  19361.      if `--skip-innodb' is used.
  19362.  
  19363.    * `have_bdb' `YES' if `mysqld' supports Berkeley DB tables.
  19364.      `DISABLED' if `--skip-bdb' is used.
  19365.  
  19366.    * `have_raid' `YES' if `mysqld' supports the `RAID' option.
  19367.  
  19368.    * `have_openssl' `YES' if `mysqld' supports SSL (encryption) on the
  19369.      client/server protocol.
  19370.  
  19371.    * `init_file' The name of the file specified with the `--init-file'
  19372.      option when you start the server.  This is a file of SQL
  19373.      statements you want the server to execute when it starts.
  19374.  
  19375.    * `interactive_timeout' The number of seconds the server waits for
  19376.      activity on an interactive connection before closing it.  An
  19377.      interactive client is defined as a client that uses the
  19378.      `CLIENT_INTERACTIVE' option to `mysql_real_connect()'.  See also
  19379.      `wait_timeout'.
  19380.  
  19381.    * `join_buffer_size' The size of the buffer that is used for full
  19382.      joins (joins that do not use indexes).  The buffer is allocated
  19383.      one time for each full join between two tables. Increase this
  19384.      value to get a faster full join when adding indexes is not
  19385.      possible. (Normally the best way to get fast joins is to add
  19386.      indexes.)
  19387.  
  19388.    * `key_buffer_size' Index blocks are buffered and are shared by all
  19389.      threads.  `key_buffer_size' is the size of the buffer used for
  19390.      index blocks.
  19391.  
  19392.      Increase this to get better index handling (for all reads and
  19393.      multiple writes) to as much as you can afford; 64M on a 256M
  19394.      machine that mainly runs MySQL is quite common.  If you, however,
  19395.      make this too big (for instance more than 50% of your total
  19396.      memory) your system may start to page and become extremely slow.
  19397.      Remember that because MySQL does not cache data reads, you will
  19398.      have to leave some room for the OS filesystem cache.
  19399.  
  19400.      You can check the performance of the key buffer by doing `SHOW
  19401.      STATUS' and examine the variables `Key_read_requests',
  19402.      `Key_reads', `Key_write_requests', and `Key_writes'.  The
  19403.      `Key_reads/Key_read_request' ratio should normally be < 0.01.  The
  19404.      `Key_write/Key_write_requests' is usually near 1 if you are using
  19405.      mostly updates/deletes but may be much smaller if you tend to do
  19406.      updates that affect many at the same time or if you are using
  19407.      `DELAY_KEY_WRITE'. *Note `SHOW': SHOW.
  19408.  
  19409.      To get even more speed when writing many rows at the same time, use
  19410.      `LOCK TABLES'.  *Note `LOCK TABLES': LOCK TABLES.
  19411.  
  19412.    * `language' The language used for error messages.
  19413.  
  19414.    * `large_file_support' If `mysqld' was compiled with options for big
  19415.      file support.
  19416.  
  19417.    * `locked_in_memory' If `mysqld' was locked in memory with
  19418.      `--memlock'
  19419.  
  19420.    * `log' If logging of all queries is enabled.
  19421.  
  19422.    * `log_update' If the update log is enabled.
  19423.  
  19424.    * `log_bin' If the binary log is enabled.
  19425.  
  19426.    * `log_slave_updates' If the updates from the slave should be logged.
  19427.  
  19428.    * `long_query_time' If a query takes longer than this (in seconds),
  19429.      the `Slow_queries' counter will be incremented. If you are using
  19430.      `--log-slow-queries', the query will be logged to the slow query
  19431.      logfile. This value is measured in real time, not CPU time, so a
  19432.      query that may be under the threshold on a lightly loaded system
  19433.      may be above the threshold on a heavily loaded one.  *Note Slow
  19434.      query log::.
  19435.  
  19436.    * `lower_case_table_names' If set to 1 table names are stored in
  19437.      lowercase on disk and table name comparisons will be
  19438.      case-insensitive.  From version 4.0.2, this option also applies to
  19439.      database names.  From 4.1.1 this option also applies to table
  19440.      alias.  *Note Name case sensitivity::.
  19441.  
  19442.    * `max_allowed_packet' The maximum size of one packet. The message
  19443.      buffer is initialised to `net_buffer_length' bytes, but can grow
  19444.      up to `max_allowed_packet' bytes when needed.  This value by
  19445.      default is small, to catch big (possibly wrong) packets.  You must
  19446.      increase this value if you are using big `BLOB' columns. It should
  19447.      be as big as the biggest `BLOB' you want to use.  The protocol
  19448.      limits for `max_allowed_packet' is 16M in MySQL 3.23 and 1G in
  19449.      MySQL 4.0.
  19450.  
  19451.    * `max_binlog_cache_size' If a multi-statement transaction requires
  19452.      more than this amount of memory, one will get the error
  19453.      "Multi-statement transaction required more than
  19454.      'max_binlog_cache_size' bytes of storage".
  19455.  
  19456.    * `max_binlog_size' Available after 3.23.33. If a write to the
  19457.      binary (replication) log exceeds the given value, rotate the logs.
  19458.      You cannot set it to less than 4096 bytes (1024 in MySQL versions
  19459.      older than 4.0.14), or more than 1 GB. Default is 1 GB. Note if
  19460.      you are using transactions: a transaction is written in one chunk
  19461.      to the binary log, hence it is never split between several binary
  19462.      logs. Therefore, if you have big transactions, you may see binlogs
  19463.      bigger than `max_binlog_size'. If `max_relay_log_size' (available
  19464.      starting from MySQL 4.0.14) is 0, then `max_binlog_size' will
  19465.      apply to relay logs as well.
  19466.  
  19467.    * `max_connections' The number of simultaneous clients allowed.
  19468.      Increasing this value increases the number of file descriptors
  19469.      that `mysqld' requires.  See below for comments on file descriptor
  19470.      limits. *Note Too many connections::.
  19471.  
  19472.    * `max_connect_errors' If there is more than this number of
  19473.      interrupted connections from a host this host will be blocked from
  19474.      further connections.  You can unblock a host with the command
  19475.      `FLUSH HOSTS'.
  19476.  
  19477.    * `max_delayed_threads' Don't start more than this number of threads
  19478.      to handle `INSERT DELAYED' statements.  If you try to insert data
  19479.      into a new table after all `INSERT DELAYED' threads are in use,
  19480.      the row will be inserted as if the `DELAYED' attribute wasn't
  19481.      specified. If you set this to 0, MySQL will never create a
  19482.      max_delayed thread.
  19483.  
  19484.    * `max_heap_table_size' Don't allow creation of heap tables bigger
  19485.      than this.
  19486.  
  19487.    * `max_join_size' Joins that are probably going to read more than
  19488.      `max_join_size' records return an error. Set this value if your
  19489.      users tend to perform joins that lack a `WHERE' clause, that take
  19490.      a long time, and that return millions of rows.
  19491.  
  19492.    * `max_relay_log_size' Available starting from 4.0.14. If a write to
  19493.      the relay log (a kind of log used by replication slaves, *note
  19494.      Replication Implementation Details::) exceeds the given value,
  19495.      rotate the relay log.  This variable enables you to put different
  19496.      size constraints on relay logs and binary logs.  However, setting
  19497.      the variable to 0 will make MySQL use `max_binlog_size' for both
  19498.      binary logs and relay logs.  You have to set `max_relay_log_size'
  19499.      to 0 or more than 4096, and less than 1 GB. Default is 0.
  19500.  
  19501.    * `max_seeks_for_key' Limit assumed max number of seeks when looking
  19502.      up rows based on a key.  The MySQL optimiser will assume that when
  19503.      searching after matching rows in a table through scanning a key,
  19504.      we will not cause more than this number of key seeks independent
  19505.      of the cardinality of the key.  By setting this to a low value
  19506.      (100 ?) you can force MySQL to prefer keys instead of table scans.
  19507.  
  19508.    * `max_sort_length' The number of bytes to use when sorting `BLOB'
  19509.      or `TEXT' values (only the first `max_sort_length' bytes of each
  19510.      value are used; the rest are ignored).
  19511.  
  19512.    * `max_user_connections' The maximum number of active connections
  19513.      for a single user (0 = no limit).
  19514.  
  19515.    * `max_tmp_tables' (This option doesn't yet do anything.)  Maximum
  19516.      number of temporary tables a client can keep open at the same time.
  19517.  
  19518.    * `max_write_lock_count' After this many write locks, allow some
  19519.      read locks to run in between.
  19520.  
  19521.    * `myisam_recover_options' The value of the `--myisam-recover'
  19522.      option.
  19523.  
  19524.    * `myisam_sort_buffer_size' The buffer that is allocated when
  19525.      sorting the index when doing a `REPAIR' or when creating indexes
  19526.      with `CREATE INDEX' or `ALTER TABLE'.
  19527.  
  19528.    * `myisam_max_extra_sort_file_size'.  If the temporary file used for
  19529.      fast index creation would be bigger than using the key cache by
  19530.      the amount specified here, then prefer the key cache method.  This
  19531.      is mainly used to force long character keys in large tables to use
  19532.      the slower key cache method to create the index.  *Note* that this
  19533.      parameter is given in megabytes before 4.0.3 and in bytes
  19534.      beginning with this version.
  19535.  
  19536.    * `myisam_repair_threads'.  If this value is greater than one,
  19537.      MyISAM table indexes during `Repair by sorting' process will be
  19538.      created in parallel - each index in its own thread. *Note:*
  19539.      multi-threaded repair is still *alpha* quality code.
  19540.  
  19541.    * `myisam_max_sort_file_size' The maximum size of the temporary file
  19542.      MySQL is allowed to use while recreating the index (during
  19543.      `REPAIR', `ALTER TABLE' or `LOAD DATA INFILE'.  If the file-size
  19544.      would be bigger than this, the index will be created through the
  19545.      key cache (which is slower).  *Note* that this parameter is given
  19546.      in megabytes before 4.0.3 and in bytes beginning with this version.
  19547.  
  19548.    * `net_buffer_length' The communication buffer is reset to this size
  19549.      between queries. This should not normally be changed, but if you
  19550.      have very little memory, you can set it to the expected size of a
  19551.      query.  (That is, the expected length of SQL statements sent by
  19552.      clients.  If statements exceed this length, the buffer is
  19553.      automatically enlarged, up to `max_allowed_packet' bytes.)
  19554.  
  19555.    * `net_read_timeout' Number of seconds to wait for more data from a
  19556.      connection before aborting the read.  Note that when we don't
  19557.      expect data from a connection, the timeout is defined by
  19558.      `write_timeout'. See also `slave_net_timeout'.
  19559.  
  19560.    * `net_retry_count' If a read on a communication port is
  19561.      interrupted, retry this many times before giving up.  This value
  19562.      should be quite high on `FreeBSD' as internal interrupts are sent
  19563.      to all threads.
  19564.  
  19565.    * `net_write_timeout' Number of seconds to wait for a block to be
  19566.      written to a connection before aborting the write.
  19567.  
  19568.    * `open_files_limit' Number of files the system allows mysqld to
  19569.      open.  This is the real value given for the system and may be
  19570.      different from the value you gave mysqld as a startup parameter.
  19571.      This is 0 on systems where MySQL can't change the number of open
  19572.      files.
  19573.  
  19574.    * `pid_file' The value of the `--pid-file' option.
  19575.  
  19576.    * `port' The value of the `--port' option.
  19577.  
  19578.    * `protocol_version' The protocol version used by the MySQL server.
  19579.  
  19580.    * `read_buffer_size' (was `record_buffer') Each thread that does a
  19581.      sequential scan allocates a buffer of this size for each table it
  19582.      scans. If you do many sequential scans, you may want to increase
  19583.      this value.
  19584.  
  19585.    * `record_rnd_buffer_size' When reading rows in sorted order after a
  19586.      sort, the rows are read through this buffer to avoid a disk seeks.
  19587.      Can improve `ORDER BY' by a lot if set to a high value.  As this
  19588.      is a thread-specific variable, one should not set this big
  19589.      globally, but just change this when running some specific big
  19590.      queries.
  19591.  
  19592.    * `query_cache_limit' Don't cache results that are bigger than this.
  19593.      (Default 1M).
  19594.  
  19595.    * `query_cache_size' The memory allocated to store results from old
  19596.      queries.  If this is 0, the query cache is disabled (default).
  19597.  
  19598.    * `query_cache_type' This may be set (only numeric) to
  19599.      *Value**Alias*   *Comment*
  19600.      0      OFF       Don't cache or retrieve results.
  19601.      1      ON        Cache all results except `SELECT SQL_NO_CACHE
  19602.                       ...' queries.
  19603.      2      DEMAND    Cache only `SELECT SQL_CACHE ...' queries.
  19604.  
  19605.    * `safe_show_database' Don't show databases for which the user
  19606.      doesn't have any database or table privileges. This can improve
  19607.      security if you're concerned about people being able to see what
  19608.      databases other users have. See also `skip_show_database'.
  19609.  
  19610.    * `server_id' The value of the `--server-id' option.
  19611.  
  19612.    * `skip_locking' Is OFF if `mysqld' uses external locking.
  19613.  
  19614.    * `skip_networking' Is ON if we only allow local (socket)
  19615.      connections.
  19616.  
  19617.    * `skip_show_database' This prevents people from doing `SHOW
  19618.      DATABASES' if they don't have the `PROCESS' privilege. This can
  19619.      improve security if you're concerned about people being able to
  19620.      see what databases other users have. See also `safe_show_database'.
  19621.  
  19622.    * `slave_net_timeout' Number of seconds to wait for more data from a
  19623.      master/slave connection before aborting the read.
  19624.  
  19625.    * `slow_launch_time' If creating the thread takes longer than this
  19626.      value (in seconds), the `Slow_launch_threads' counter will be
  19627.      incremented.
  19628.  
  19629.    * `socket' The Unix socket used by the server.
  19630.  
  19631.    * `sort_buffer_size' Each thread that needs to do a sort allocates a
  19632.      buffer of this size. Increase this value for faster `ORDER BY' or
  19633.      `GROUP BY' operations.  *Note Temporary files::.
  19634.  
  19635.    * `table_cache' The number of open tables for all threads.
  19636.      Increasing this value increases the number of file descriptors
  19637.      that `mysqld' requires.  You can check if you need to increase the
  19638.      table cache by checking the `Opened_tables' variable.  *Note
  19639.      `Opened_tables': SHOW STATUS.  If this variable is big and you
  19640.      don't do `FLUSH TABLES' a lot (which just forces all tables to be
  19641.      closed and reopenend), then you should increase the value of this
  19642.      variable.
  19643.  
  19644.      For more information about the table cache, see *Note Table
  19645.      cache::.
  19646.  
  19647.    * `table_type' The default table type.
  19648.  
  19649.    * `thread_cache_size' How many threads we should keep in a cache for
  19650.      reuse.  When a client disconnects, the client's threads are put in
  19651.      the cache if there aren't more than `thread_cache_size' threads
  19652.      from before.  All new threads are first taken from the cache, and
  19653.      only when the cache is empty is a new thread created.  This
  19654.      variable can be increased to improve performance if you have a lot
  19655.      of new connections. (Normally this doesn't give a notable
  19656.      performance improvement if you have a good thread implementation.)
  19657.      By examing the difference between the `Connections' and
  19658.      `Threads_created' status variables (*note `SHOW STATUS': SHOW
  19659.      STATUS. for details) you can see how efficient thread cache is.
  19660.  
  19661.    * `thread_concurrency' On Solaris, `mysqld' will call
  19662.      `thr_setconcurrency()' with this value.  `thr_setconcurrency()'
  19663.      permits the application to give the threads system a hint for the
  19664.      desired number of threads that should be run at the same time.
  19665.  
  19666.    * `thread_stack' The stack size for each thread.  Many of the limits
  19667.      detected by the `crash-me' test are dependent on this value. The
  19668.      default is large enough for normal operation.  *Note MySQL
  19669.      Benchmarks::.
  19670.  
  19671.    * `timezone' The timezone for the server.
  19672.  
  19673.    * `tmp_table_size' If an in-memory temporary table exceeds this
  19674.      size, MySQL will automatically convert it to an on-disk `MyISAM'
  19675.      table.  Increase the value of `tmp_table_size' if you do many
  19676.      advanced `GROUP BY' queries and you have lots of memory.
  19677.  
  19678.    * `tmpdir' The directory used for temporary files and temporary
  19679.      tables.  Starting from MySQL 4.1, it can be set to a list of paths
  19680.      separated by colon `:' (semicolon `;' on Windows). They will be
  19681.      used in round-robin fashion. This feature can be used to spread
  19682.      load between several physical disks.
  19683.  
  19684.    * `version' The version number for the server.
  19685.  
  19686.    * `wait_timeout' The number of seconds the server waits for activity
  19687.      on a not interactive connection before closing it.
  19688.  
  19689.      On thread startup `SESSION.WAIT_TIMEOUT' is initialised from
  19690.      `GLOBAL.WAIT_TIMEOUT' or `GLOBAL.INTERACTIVE_TIMEOUT' depending on
  19691.      the type of client (as defined by the `CLIENT_INTERACTIVE' connect
  19692.      option). See also `interactive_timeout'.
  19693.  
  19694. The manual section that describes tuning MySQL contains some
  19695. information of how to tune the above variables. *Note Server
  19696. parameters::.
  19697.  
  19698. `SHOW [BDB] LOGS'
  19699. .................
  19700.  
  19701. `SHOW LOGS' shows you status information about existing log files.  It
  19702. currently only displays information about Berkeley DB log files, so an
  19703. alias for it (available as of MySQL 4.1.1) is `SHOW BDB LOGS'.
  19704.  
  19705.    * `File' shows the full path to the log file
  19706.  
  19707.    * `Type' shows the type of the log file (`BDB' for Berkeley DB log
  19708.      files)
  19709.  
  19710.    * `Status' shows the status of the log file (`FREE' if the file can
  19711.      be removed, or `IN USE' if the file is needed by the transaction
  19712.      subsystem)
  19713.  
  19714. `SHOW PROCESSLIST'
  19715. ..................
  19716.  
  19717. `SHOW [FULL] PROCESSLIST' shows you which threads are running.  You can
  19718. also get this information using the `mysqladmin processlist' command.
  19719. If you have the `SUPER' privilege, you can see all threads.  Otherwise,
  19720. you can see only your own threads.  *Note `KILL': KILL.  If you don't
  19721. use the `FULL' option, then only the first 100 characters of each query
  19722. will be shown.
  19723.  
  19724. Starting from 4.0.12, MySQL reports the hostname for TCP/IP connections
  19725. as `hostname:client_port' to make it easier to find out which client is
  19726. doing what.
  19727.  
  19728. This command is very useful if you get the 'too many connections' error
  19729. message and want to find out what's going on. MySQL reserves one extra
  19730. connection for a client with the `SUPER' privilege to ensure that you
  19731. should always be able to login and check the system (assuming you are
  19732. not giving this privilege to all your users).
  19733.  
  19734. Some states commonly seen in `mysqladmin processlist'
  19735.  
  19736.    * `Checking table' The thread is performing [automatic] checking of
  19737.      the table.
  19738.  
  19739.    * `Closing tables' Means that the thread is flushing the changed
  19740.      table data to disk and closing the used tables. This should be a
  19741.      fast operation.  If not, then you should check that you don't have
  19742.      a full disk or that the disk is not in very heavy use.
  19743.  
  19744.    * `Connect Out' Slave connecting to master.
  19745.  
  19746.    * `Copying to tmp table on disk' The temporary result set was larger
  19747.      than `tmp_table_size' and the thread is now changing the in
  19748.      memory-based temporary table to a disk based one to save memory.
  19749.  
  19750.    * `Creating tmp table' The thread is creating a temporary table to
  19751.      hold a part of the result for the query.
  19752.  
  19753.    * `deleting from main table' When executing the first part of a
  19754.      multi-table delete and we are only deleting from the first table.
  19755.  
  19756.    * `deleting from reference tables' When executing the second part of
  19757.      a multi-table delete and we are deleting the matched rows from the
  19758.      other tables.
  19759.  
  19760.    * `Flushing tables' The thread is executing `FLUSH TABLES' and is
  19761.      waiting for all threads to close their tables.
  19762.  
  19763.    * `Killed' Someone has sent a kill to the thread and it should abort
  19764.      next time it checks the kill flag.  The flag is checked in each
  19765.      major loop in MySQL, but in some cases it may still take a short
  19766.      time for the thread to die.  If the thread is locked by some other
  19767.      thread, the kill will take affect as soon as the other thread
  19768.      releases it's lock.
  19769.  
  19770.    * `Sending data' The thread is processing rows for a `SELECT'
  19771.      statement and is also sending data to the client.
  19772.  
  19773.    * `Sorting for group' The thread is doing a sort to satisfy a `GROUP
  19774.      BY'.
  19775.  
  19776.    * `Sorting for order' The thread is doing a sort to satisfy a `ORDER
  19777.      BY'.
  19778.  
  19779.    * `Opening tables' This simply means that the thread is trying to
  19780.      open a table. This is should be very fast procedure, unless
  19781.      something prevents opening. For example an `ALTER TABLE' or a
  19782.      `LOCK TABLE' can prevent opening a table until the command is
  19783.      finished.
  19784.  
  19785.    * `Removing duplicates' The query was using `SELECT DISTINCT' in
  19786.      such a way that MySQL couldn't optimise that distinct away at an
  19787.      early stage. Because of this MySQL has to do an extra stage to
  19788.      remove all duplicated rows before sending the result to the client.
  19789.  
  19790.    * `Reopen table' The thread got a lock for the table, but noticed
  19791.      after getting the lock that the underlying table structure
  19792.      changed. It has freed the lock, closed the table and is now trying
  19793.      to reopen it.
  19794.  
  19795.    * `Repair by sorting' The repair code is using sorting to create
  19796.      indexes.
  19797.  
  19798.    * `Repair with keycache' The repair code is using creating keys one
  19799.      by one through the key cache.  This is much slower than `Repair by
  19800.      sorting'.
  19801.  
  19802.    * `Searching rows for update' The thread is doing a first phase to
  19803.      find all matching rows before updating them.  This has to be done
  19804.      if the `UPDATE' is changing the index that is used to find the
  19805.      involved rows.
  19806.  
  19807.    * `Sleeping' The thread is wating for the client to send a new
  19808.      command to it.
  19809.  
  19810.    * `System lock' The thread is waiting for getting to get a external
  19811.      system lock for the table. If you are not using multiple mysqld
  19812.      servers that are accessing the same tables, you can disable system
  19813.      locks with the `--skip-external-locking' option.
  19814.  
  19815.    * `Upgrading lock' The `INSERT DELAYED' handler is trying to get a
  19816.      lock for the table to insert rows.
  19817.  
  19818.    * `Updating' The thread is searching for rows to update and updating
  19819.      them.
  19820.  
  19821.    * `User Lock' The thread is waiting on a `GET_LOCK()'.
  19822.  
  19823.    * `Waiting for tables' The thread got a notification that the
  19824.      underlying structure for a table has changed and it needs to
  19825.      reopen the table to get the new structure.  To be able to reopen
  19826.      the table it must however wait until all other threads have closed
  19827.      the table in question.
  19828.  
  19829.      This notification happens if another thread has used `FLUSH TABLES'
  19830.      or one of the following commands on the table in question: `FLUSH
  19831.      TABLES table_name', `ALTER TABLE', `RENAME TABLE', `REPAIR TABLE',
  19832.      `ANALYZE TABLE' or `OPTIMIZE TABLE'.
  19833.  
  19834.    * `waiting for handler insert' The `INSERT DELAYED' handler has
  19835.      processed all inserts and are waiting to get new ones.
  19836.  
  19837. Most states are very quick operations. If threads last in any of these
  19838. states for many seconds, there may be a problem around that needs to be
  19839. investigated.
  19840.  
  19841. There are some other states that are not mentioned previously, but most
  19842. of these are only useful to find bugs in `mysqld'.
  19843.  
  19844. `SHOW GRANTS'
  19845. .............
  19846.  
  19847. `SHOW GRANTS FOR user' lists the grant commands that must be issued to
  19848. duplicate the grants for a user.
  19849.  
  19850.      mysql> SHOW GRANTS FOR root@localhost;
  19851.      +---------------------------------------------------------------------+
  19852.      | Grants for root@localhost                                           |
  19853.      +---------------------------------------------------------------------+
  19854.      | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  19855.      +---------------------------------------------------------------------+
  19856.  
  19857. To list grants for the current session one may use `CURRENT_USER()'
  19858. function (new in version 4.0.6) to find out what user the session was
  19859. authenticated as.  *Note `CURRENT_USER()': Miscellaneous functions.
  19860.  
  19861. `SHOW CREATE TABLE'
  19862. ...................
  19863.  
  19864. Shows a `CREATE TABLE' statement that will create the given table:
  19865.  
  19866.      mysql> SHOW CREATE TABLE t\G
  19867.      *************************** 1. row ***************************
  19868.             Table: t
  19869.      Create Table: CREATE TABLE t (
  19870.        id INT(11) default NULL auto_increment,
  19871.        s char(60) default NULL,
  19872.        PRIMARY KEY (id)
  19873.      ) TYPE=MyISAM
  19874.  
  19875. `SHOW CREATE TABLE' will quote table and column names according to
  19876. `SQL_QUOTE_SHOW_CREATE' option.  *Note `SET SQL_QUOTE_SHOW_CREATE': SET
  19877. OPTION.
  19878.  
  19879. `SHOW WARNINGS | ERRORS'
  19880. ........................
  19881.  
  19882.      SHOW WARNINGS [LIMIT row_count]
  19883.      SHOW ERRORS [LIMIT row_count]
  19884.  
  19885. This command is implemented in MySQL 4.1.0.
  19886.  
  19887. It shows the errors, warnings and notes that one got for the last
  19888. command.  The errors/warnings are reset for each new command that uses
  19889. a table.
  19890.  
  19891. The MySQL server sends back the total number of warnings and errors you
  19892. got for the last commend; This can be retrieved by calling
  19893. `mysql_warning_count()'.
  19894.  
  19895. Up to `max_error_count' messages are stored (Global and thread specific
  19896. variable).
  19897.  
  19898. You can retrieve the number of errors from `@error_count' and warnings
  19899. from `@warning_count'.
  19900.  
  19901. `SHOW WARNINGS' shows all errors, warnings and notes you got for the
  19902. last command while `SHOW ERRORS' only shows you the errors.
  19903.  
  19904.      mysql> DROP TABLE IF EXISTS no_such_table;
  19905.      mysql> SHOW WARNINGS;
  19906.      
  19907.      +-------+------+-------------------------------+
  19908.      | Level | Code | Message                       |
  19909.      +-------+------+-------------------------------+
  19910.      | Note  | 1051 | Unknown table 'no_such_table' |
  19911.      +-------+------+-------------------------------+
  19912.  
  19913. Note that in MySQL 4.1.0 we have just added the frame work for warnings
  19914. and not many MySQL command do yet generate warnings.  4.1.1 supports all
  19915. kind of warnings for `LOAD DATA INFILE' and DML statements such as
  19916. `INSERT', `UPDATE' and `ALTER' commands.
  19917.  
  19918. For example, here is a simple case which produces conversion warnings
  19919. for a insert statement.
  19920.  
  19921.      mysql> create table t1(a tinyint NOT NULL, b char(4));
  19922.      Query OK, 0 rows affected (0.00 sec)
  19923.      
  19924.      mysql> insert into t1 values(10,'mysql'),(NULL,'test'),(300,'open source');
  19925.      Query OK, 3 rows affected, 4 warnings (0.15 sec)
  19926.      Records: 3  Duplicates: 0  Warnings: 4
  19927.      
  19928.      mysql> show warnings;
  19929.      +---------+------+---------------------------------------------------------------+
  19930.      | Level   | Code | Message                                                       |
  19931.      +---------+------+---------------------------------------------------------------+
  19932.      | Warning | 1263 | Data truncated for column 'b' at row 1                        |
  19933.      | Warning | 1261 | Data truncated, NULL supplied to NOT NULL column 'a' at row 2 |
  19934.      | Warning | 1262 | Data truncated, out of range for column 'a' at row 3          |
  19935.      | Warning | 1263 | Data truncated for column 'b' at row 3                        |
  19936.      +---------+------+---------------------------------------------------------------+
  19937.      4 rows in set (0.00 sec)
  19938.  
  19939. Maximum number of warnings can be specified using the server variable
  19940. `'max_error_count'', `SET max_error_count=[count]'; By default it is
  19941. 64. In case to disable warnings, simply reset this variable to '0'. In
  19942. case if `max_error_count' is 0, then still the warning count represents
  19943. how many warnings have occurred, but none of the messages are stored.
  19944.  
  19945. For example, consider the following `ALTER' table statement for the
  19946. above example, which returns only one warning message even though total
  19947. warnings occurred is 3 when you set max_error_count=1.
  19948.  
  19949.      mysql> show variables like 'max_error_count';
  19950.      +-----------------+-------+
  19951.      | Variable_name   | Value |
  19952.      +-----------------+-------+
  19953.      | max_error_count | 64    |
  19954.      +-----------------+-------+
  19955.      1 row in set (0.00 sec)
  19956.      
  19957.      mysql> set max_error_count=1;
  19958.      Query OK, 0 rows affected (0.00 sec)
  19959.      
  19960.      mysql> alter table t1 modify b char;
  19961.      Query OK, 3 rows affected, 3 warnings (0.00 sec)
  19962.      Records: 3  Duplicates: 0  Warnings: 3
  19963.      
  19964.      mysql> show warnings;
  19965.      +---------+------+----------------------------------------+
  19966.      | Level   | Code | Message                                |
  19967.      +---------+------+----------------------------------------+
  19968.      | Warning | 1263 | Data truncated for column 'b' at row 1 |
  19969.      +---------+------+----------------------------------------+
  19970.      1 row in set (0.00 sec)
  19971.      
  19972.      mysql>
  19973.  
  19974. `SHOW TABLE TYPES'
  19975. ..................
  19976.  
  19977.      SHOW TABLE TYPES
  19978.  
  19979. This command is implemented in MySQL 4.1.0.
  19980.  
  19981. `SHOW TABLE TYPES' shows you status information about the table types.
  19982. This is particulary useful for checking if a table type is supported;
  19983. or to see what is the default table type is.
  19984.  
  19985.      mysql> SHOW TABLE TYPES;
  19986.      
  19987.      +--------+---------+-----------------------------------------------------------+
  19988.      | Type   | Support | Comment                                                   |
  19989.      +--------+---------+-----------------------------------------------------------+
  19990.      | MyISAM | DEFAULT | Default type from 3.23 with great performance             |
  19991.      | HEAP   | YES     | Hash based, stored in memory, useful for temporary tables |
  19992.      | MERGE  | YES     | Collection of identical MyISAM tables                     |
  19993.      | ISAM   | YES     | Obsolete table type; Is replaced by MyISAM                |
  19994.      | InnoDB | YES     | Supports transactions, row-level locking and foreign keys |
  19995.      | BDB    | NO      | Supports transactions and page-level locking              |
  19996.      +--------+---------+-----------------------------------------------------------+
  19997.      6 rows in set (0.00 sec)
  19998.  
  19999. The 'Support' option `DEFAULT' indicates whether the particular table
  20000. type is supported, and which is the default type. If the server is
  20001. started with `--default-table-type=InnoDB', then the InnoDB 'Support'
  20002. field will have the value `DEFAULT'.
  20003.  
  20004. `SHOW PRIVILEGES'
  20005. .................
  20006.  
  20007.      SHOW PRIVILEGES
  20008.  
  20009. This command is implemented in MySQL 4.1.0.
  20010.  
  20011. `SHOW PRIVILEGES' shows the list of system privileges that the
  20012. underlying MySQL server supports.
  20013.  
  20014.      mysql> show privileges;
  20015.      +------------+--------------------------+-------------------------------------------------------+
  20016.      | Privilege  | Context                  | Comment                                               |
  20017.      +------------+--------------------------+-------------------------------------------------------+
  20018.      | Select     | Tables                   | To retrieve rows from table                           |
  20019.      | Insert     | Tables                   | To insert data into tables                            |
  20020.      | Update     | Tables                   | To update existing rows                               |
  20021.      | Delete     | Tables                   | To delete existing rows                               |
  20022.      | Index      | Tables                   | To create or drop indexes                             |
  20023.      | Alter      | Tables                   | To alter the table                                    |
  20024.      | Create     | Databases,Tables,Indexes | To create new databases and tables                    |
  20025.      | Drop       | Databases,Tables         | To drop databases and tables                          |
  20026.      | Grant      | Databases,Tables         | To give to other users those privileges you possess   |
  20027.      | References | Databases,Tables         | To have references on tables                          |
  20028.      | Reload     | Server Admin             | To reload or refresh tables, logs and privileges      |
  20029.      | Shutdown   | Server Admin             | To shutdown the server                                |
  20030.      | Process    | Server Admin             | To view the plain text of currently executing queries |
  20031.      | File       | File access on server    | To read and write files on the server                 |
  20032.      +------------+--------------------------+-------------------------------------------------------+
  20033.      14 rows in set (0.00 sec)
  20034.  
  20035. MySQL Localisation and International Usage
  20036. ==========================================
  20037.  
  20038. The Character Set Used for Data and Sorting
  20039. -------------------------------------------
  20040.  
  20041. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  20042. sorting according to Swedish/Finnish. This is the character set suitable
  20043. in the USA and western Europe.
  20044.  
  20045. All standard MySQL binaries are compiled with
  20046. `--with-extra-charsets=complex'.  This will add code to all standard
  20047. programs to be able to handle `latin1' and all multi-byte character
  20048. sets within the binary. Other character sets will be loaded from a
  20049. character-set definition file when needed.
  20050.  
  20051. The character set determines what characters are allowed in names and
  20052. how things are sorted by the `ORDER BY' and `GROUP BY' clauses of the
  20053. `SELECT' statement.
  20054.  
  20055. You can change the character set with the `--default-character-set'
  20056. option when you start the server.  The character sets available depend
  20057. on the `--with-charset=charset' and `--with-extra-charsets=
  20058. list-of-charset | complex | all | none' options to `configure', and the
  20059. character set configuration files listed in `SHAREDIR/charsets/Index'.
  20060. *Note configure options::.
  20061.  
  20062. If you change the character set when running MySQL (which may also
  20063. change the sort order), you must run `myisamchk -r -q
  20064. --set-character-set=charset' on all tables. Otherwise, your indexes may
  20065. not be ordered correctly.
  20066.  
  20067. When a client connects to a MySQL server, the server sends the default
  20068. character set in use to the client.  The client will switch to use this
  20069. character set for this connection.
  20070.  
  20071. One should use `mysql_real_escape_string()' when escaping strings for
  20072. an SQL query.  `mysql_real_escape_string()' is identical to the old
  20073. `mysql_escape_string()' function, except that it takes the `MYSQL'
  20074. connection handle as the first parameter.
  20075.  
  20076. If the client is compiled with different paths than where the server is
  20077. installed and the user who configured MySQL didn't include all
  20078. character sets in the MySQL binary, one must specify for the client
  20079. where it can find the additional character sets it will need if the
  20080. server runs with a different character set than the client.
  20081.  
  20082. One can specify this by putting in a MySQL option file:
  20083.  
  20084.      [client]
  20085.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  20086.  
  20087. where the path points to the directory in which the dynamic MySQL
  20088. character sets are stored.
  20089.  
  20090. One can force the client to use specific character set by specifying:
  20091.  
  20092.      [client]
  20093.      default-character-set=character-set-name
  20094.  
  20095. but normally this is never needed.
  20096.  
  20097. German character set
  20098. ....................
  20099.  
  20100. To get German sorting order, you should start `mysqld' with
  20101. `--default-character-set=latin1_de'.  This will give you the following
  20102. characteristics.
  20103.  
  20104. When sorting and comparing strings, the following mapping is done on the
  20105. strings before doing the comparison:
  20106.  
  20107.      a"  ->  ae
  20108.      o"  ->  oe
  20109.      u"  ->  ue
  20110.      ss  ->  ss
  20111.  
  20112. All accented characters, are converted to their un-accented uppercase
  20113. counterpart.  All letters are converted to uppercase.
  20114.  
  20115. When comparing strings with `LIKE' the one -> two character mapping is
  20116. not done. All letters are converted to uppercase. Accent are removed
  20117. from all letters except: `U"', `u"', `O"', `o"', `A"' and `a"'.
  20118.  
  20119. Non-English Error Messages
  20120. --------------------------
  20121.  
  20122. `mysqld' can issue error messages in the following languages: Czech,
  20123. Danish, Dutch, English (the default), Estonian, French, German, Greek,
  20124. Hungarian, Italian, Japanese, Korean, Norwegian, Norwegian-ny, Polish,
  20125. Portuguese, Romanian, Russian, Slovak, Spanish, and Swedish.
  20126.  
  20127. To start `mysqld' with a particular language, use either the
  20128. `--language=lang' or `-L lang' options. For example:
  20129.  
  20130.      shell> mysqld --language=swedish
  20131.  
  20132. or:
  20133.  
  20134.      shell> mysqld --language=/usr/local/share/swedish
  20135.  
  20136. Note that all language names are specified in lowercase.
  20137.  
  20138. The language files are located (by default) in
  20139. `MYSQL_BASE_DIR/share/LANGUAGE/'.
  20140.  
  20141. To update the error message file, you should edit the `errmsg.txt' file
  20142. and execute the following command to generate the `errmsg.sys' file:
  20143.  
  20144.      shell> comp_err errmsg.txt errmsg.sys
  20145.  
  20146. If you upgrade to a newer version of MySQL, remember to repeat your
  20147. changes with the new `errmsg.txt' file.
  20148.  
  20149. Adding a New Character Set
  20150. --------------------------
  20151.  
  20152. To add another character set to MySQL, use the following procedure.
  20153.  
  20154. Decide if the set is simple or complex.  If the character set does not
  20155. need to use special string collating routines for sorting and does not
  20156. need multi-byte character support, it is simple.  If it needs either of
  20157. those features, it is complex.
  20158.  
  20159. For example, `latin1' and `danish' are simple charactersets while
  20160. `big5' or `czech' are complex character sets.
  20161.  
  20162. In the following section, we have assumed that you name your character
  20163. set `MYSET'.
  20164.  
  20165. For a simple character set do the following:
  20166.  
  20167.   1. Add MYSET to the end of the `sql/share/charsets/Index' file Assign
  20168.      a unique number to it.
  20169.  
  20170.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use
  20171.      `sql/share/charsets/latin1.conf' as a base for this.)
  20172.  
  20173.      The syntax for the file is very simple:
  20174.  
  20175.         * Comments start with a '#' character and proceed to the end of
  20176.           the line.
  20177.  
  20178.         * Words are separated by arbitrary amounts of whitespace.
  20179.  
  20180.         * When defining the character set, every word must be a number
  20181.           in hexadecimal format
  20182.  
  20183.         * The `ctype' array takes up the first 257 words. The
  20184.           `to_lower[]', `to_upper[]' and `sort_order[]' arrays take up
  20185.           256 words each after that.
  20186.  
  20187.      *Note Character arrays::.
  20188.  
  20189.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  20190.      `COMPILED_CHARSETS' lists in `configure.in'.
  20191.  
  20192.   4. Reconfigure, recompile, and test.
  20193.  
  20194.  
  20195. For a complex character set do the following:
  20196.  
  20197.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  20198.      distribution.
  20199.  
  20200.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  20201.      Assign a unique number to it.
  20202.  
  20203.   3. Look at one of the existing `ctype-*.c' files to see what needs to
  20204.      be defined, for example `strings/ctype-big5.c'. Note that the
  20205.      arrays in your file must have names like `ctype_MYSET',
  20206.      `to_lower_MYSET', and so on.  This corresponds to the arrays in
  20207.      the simple character set. *Note Character arrays::.
  20208.  
  20209.   4. Near the top of the file, place a special comment like this:
  20210.  
  20211.           /*
  20212.            * This comment is parsed by configure to create ctype.c,
  20213.            * so don't change it unless you know what you are doing.
  20214.            *
  20215.            * .configure. number_MYSET=MYNUMBER
  20216.            * .configure. strxfrm_multiply_MYSET=N
  20217.            * .configure. mbmaxlen_MYSET=N
  20218.            */
  20219.  
  20220.      The `configure' program uses this comment to include the character
  20221.      set into the MySQL library automatically.
  20222.  
  20223.      The strxfrm_multiply and mbmaxlen lines will be explained in the
  20224.      following sections.  Only include these if you need the string
  20225.      collating functions or the multi-byte character set functions,
  20226.      respectively.
  20227.  
  20228.   5. You should then create some of the following functions:
  20229.  
  20230.         * `my_strncoll_MYSET()'
  20231.  
  20232.         * `my_strcoll_MYSET()'
  20233.  
  20234.         * `my_strxfrm_MYSET()'
  20235.  
  20236.         * `my_like_range_MYSET()'
  20237.  
  20238.      *Note String collating::.
  20239.  
  20240.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  20241.      `COMPILED_CHARSETS' lists in `configure.in'.
  20242.  
  20243.   7. Reconfigure, recompile, and test.
  20244.  
  20245. The file `sql/share/charsets/README' includes some more instructions.
  20246.  
  20247. If you want to have the character set included in the MySQL
  20248. distribution, mail a patch to the MySQL internals mailing list.  *Note
  20249. Mailing-list::.
  20250.  
  20251. The Character Definition Arrays
  20252. -------------------------------
  20253.  
  20254. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  20255. and uppercase characters corresponding to each member of the character
  20256. set.  For example:
  20257.  
  20258.      to_lower['A'] should contain 'a'
  20259.      to_upper['a'] should contain 'A'
  20260.  
  20261. `sort_order[]' is a map indicating how characters should be ordered for
  20262. comparison and sorting purposes. Quite often (but not for all character
  20263. sets) this is the same as `to_upper[]' (which means sorting will be
  20264. case-insensitive). MySQL will sort characters based on the value of
  20265. `sort_order[character]'.  For more complicated sorting rules, see the
  20266. discussion of string collating below. *Note String collating::.
  20267.  
  20268. `ctype[]' is an array of bit values, with one element for one character.
  20269. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  20270. by character value, but `ctype[]' is indexed by character value + 1.
  20271. This is an old legacy to be able to handle `EOF'.)
  20272.  
  20273. You can find the following bitmask definitions in `m_ctype.h':
  20274.  
  20275.      #define _U      01      /* Uppercase */
  20276.      #define _L      02      /* Lowercase */
  20277.      #define _N      04      /* Numeral (digit) */
  20278.      #define _S      010     /* Spacing character */
  20279.      #define _P      020     /* Punctuation */
  20280.      #define _C      040     /* Control character */
  20281.      #define _B      0100    /* Blank */
  20282.      #define _X      0200    /* heXadecimal digit */
  20283.  
  20284. The `ctype[]' entry for each character should be the union of the
  20285. applicable bitmask values that describe the character.  For example,
  20286. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  20287. (`_X'), so `ctype['A'+1]' should contain the value:
  20288.  
  20289.      _U + _X = 01 + 0200 = 0201
  20290.  
  20291. String Collating Support
  20292. ------------------------
  20293.  
  20294. If the sorting rules for your language are too complex to be handled
  20295. with the simple `sort_order[]' table, you need to use the string
  20296. collating functions.
  20297.  
  20298. Right now the best documentation on this is the character sets that are
  20299. already implemented.  Look at the `big5', `czech', `gbk', `sjis', and
  20300. `tis160' character sets for examples.
  20301.  
  20302. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  20303. comment at the top of the file.  `N' should be set to the maximum ratio
  20304. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  20305. integer).
  20306.  
  20307. Multi-byte Character Support
  20308. ----------------------------
  20309.  
  20310. If your want to add support for a new character set that includes
  20311. multi-byte characters, you need to use the multi-byte character
  20312. functions.
  20313.  
  20314. Right now the best documentation on this is the character sets that are
  20315. already implemented.  Look at the `euc_kr', `gb2312', `gbk', `sjis',
  20316. and `ujis' character sets for examples. These are implemented in the
  20317. `ctype-'charset'.c' files in the `strings' directory.
  20318.  
  20319. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  20320. the top of the source file.  `N' should be set to the size in bytes of
  20321. the largest character in the set.
  20322.  
  20323. Problems With Character Sets
  20324. ----------------------------
  20325.  
  20326. If you try to use a character set that is not compiled into your binary,
  20327. you can run into a couple of different problems:
  20328.  
  20329.    * Your program has a wrong path to where the character sets are
  20330.      stored.  (Default `/usr/local/mysql/share/mysql/charsets').  This
  20331.      can be fixed by using the `--character-sets-dir' option to the
  20332.      program in question.
  20333.  
  20334.    * The character set is a multi-byte character set that can't be
  20335.      loaded dynamically.  In this case you have to recompile the
  20336.      program with the support for the character set.
  20337.  
  20338.    * The character set is a dynamic character set, but you don't have a
  20339.      configure file for it.  In this case you should install the
  20340.      configure file for the character set from a new MySQL distribution.
  20341.  
  20342.    * Your `Index' file doesn't contain the name for the character set.
  20343.  
  20344.           ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf' not found
  20345.           (Errcode: 2)
  20346.  
  20347.      In this case you should either get a new `Index' file or add by
  20348.      hand the name of any missing character sets.
  20349.  
  20350. For `MyISAM' tables, you can check the character set name and number
  20351. for a table with `myisamchk -dvv table_name'.
  20352.  
  20353. MySQL Server-Side Scripts and Utilities
  20354. =======================================
  20355.  
  20356. Overview of the Server-Side Scripts and Utilities
  20357. -------------------------------------------------
  20358.  
  20359. All MySQL programs take many different options. However, every MySQL
  20360. program provides a `--help' option that you can use to get a full
  20361. description of the program's different options. For example, try `mysql
  20362. --help'.
  20363.  
  20364. You can override default options for all standard programs with an
  20365. option file. *Note Option files::.
  20366.  
  20367. The following list briefly describes the server-side MySQL programs:
  20368.  
  20369. `myisamchk'
  20370.      Utility to describe, check, optimise, and repair MySQL tables.
  20371.      Because `myisamchk' has many functions, it is described in its own
  20372.      chapter. *Note MySQL Database Administration::.
  20373.  
  20374. `make_binary_distribution'
  20375.      Makes a binary release of a compiled MySQL. This could be sent by
  20376.      FTP to `/pub/mysql/Incoming' on `support.mysql.com' for the
  20377.      convenience of other MySQL users.
  20378.  
  20379. `mysqlbug'
  20380.      The MySQL bug report script.  This script should always be used
  20381.      when filing a bug report to the MySQL list.
  20382.  
  20383. `mysqld'
  20384.      The SQL daemon. This should always be running.
  20385.  
  20386. `mysql_install_db'
  20387.      Creates the MySQL grant tables with default privileges. This is
  20388.      usually executed only once, when first installing MySQL on a
  20389.      system.
  20390.  
  20391. `mysqld_safe', The Wrapper Around `mysqld'
  20392. ------------------------------------------
  20393.  
  20394. `mysqld_safe' is the recommended way to start a `mysqld' daemon on
  20395. Unix.  `mysqld_safe' adds some safety features such as restarting the
  20396. server when an error occurs and logging run-time information to a log
  20397. file.
  20398.  
  20399. *Note:* Before MySQL 4.0, `mysqld_safe' is named `safe_mysqld'.  To
  20400. preserve backward compatibility, MySQL binary distributions for some
  20401. time will include `safe_mysqld' as a symbolic link to `mysqld_safe'.
  20402.  
  20403. If you don't use `--mysqld=#' or `--mysqld-version=#' `mysqld_safe'
  20404. will use an executable named `mysqld-max' if it exists. If not,
  20405. `mysqld_safe' will start `mysqld'.  This makes it very easy to test to
  20406. use `mysqld-max' instead of `mysqld'; just copy `mysqld-max' to where
  20407. you have `mysqld' and it will be used.
  20408.  
  20409. Normally one should never edit the `mysqld_safe' script, but instead
  20410. put the options to `mysqld_safe' in the `[mysqld_safe]' section in the
  20411. `my.cnf' file. `mysqld_safe' reads all options from the `[mysqld]',
  20412. `[server]' and `[mysqld_safe]' sections from the option files.  (For
  20413. backward compatibility, it also reads the `[safe_mysqld]' sections.)
  20414. *Note Option files::.
  20415.  
  20416. Note that all options on the command-line to `mysqld_safe' are passed
  20417. to `mysqld'.  If you wants to use any options in `mysqld_safe' that
  20418. `mysqld' doesn't support, you must specify these in the option file.
  20419.  
  20420. Most of the options to `mysqld_safe' are the same as the options to
  20421. `mysqld'. *Note Command-line options::.
  20422.  
  20423. `mysqld_safe' supports the following options:
  20424.  
  20425. `--basedir=path'
  20426.  
  20427. `--core-file-size=#'
  20428.      Size of the core file `mysqld' should be able to create. Passed to
  20429.      `ulimit -c'.
  20430.  
  20431. `--datadir=path'
  20432.  
  20433. `--defaults-extra-file=path'
  20434.  
  20435. `--defaults-file=path'
  20436.  
  20437. `--err-log=path (this is marked obsolete in 4.0; Use --log-error instead)'
  20438.  
  20439. `--log-error=path'
  20440.      Write the error log to the above file. *Note Error log::.
  20441.  
  20442. `--ledir=path'
  20443.      Path to `mysqld'
  20444.  
  20445. `--log=path'
  20446.  
  20447. `--mysqld=mysqld-version'
  20448.      Name of the `mysqld' version in the `ledir' directory you want to
  20449.      start.
  20450.  
  20451. `--mysqld-version=version'
  20452.      Similar to `--mysqld=' but here you only give the suffix for
  20453.      `mysqld'.  For example if you use `--mysqld-version=max',
  20454.      `mysqld_safe' will start the `ledir/mysqld-max' version.  If the
  20455.      argument to `--mysqld-version' is empty, `ledir/mysqld' will be
  20456.      used.
  20457.  
  20458. `--nice=# (added in MySQL 4.0.14)'
  20459.  
  20460. `--no-defaults'
  20461.  
  20462. `--open-files-limit=#'
  20463.      Number of files `mysqld' should be able to open. Passed to `ulimit
  20464.      -n'. Note that you need to start `mysqld_safe' as `root' for this
  20465.      to work properly!
  20466.  
  20467. `--pid-file=path'
  20468.  
  20469. `--port=#'
  20470.  
  20471. `--socket=path'
  20472.  
  20473. `--timezone=#'
  20474.      Set the timezone (the `TZ') variable to the value of this
  20475.      parameter.
  20476.  
  20477. `--user=#'
  20478. The `mysqld_safe' script is written so that it normally is able to start
  20479. a server that was installed from either a source or a binary version of
  20480. MySQL, even if these install the server in slightly different
  20481. locations.  `mysqld_safe' expects one of these conditions to be true:
  20482.  
  20483.    * The server and databases can be found relative to the directory
  20484.      from which `mysqld_safe' is invoked.  `mysqld_safe' looks under
  20485.      its working directory for `bin' and `data' directories (for binary
  20486.      distributions) or for `libexec' and `var' directories (for source
  20487.      distributions).  This condition should be met if you execute
  20488.      `mysqld_safe' from your MySQL installation directory (for example,
  20489.      `/usr/local/mysql' for a binary distribution).
  20490.  
  20491.    * If the server and databases cannot be found relative to the
  20492.      working directory, `mysqld_safe' attempts to locate them by
  20493.      absolute pathnames.  Typical locations are `/usr/local/libexec'
  20494.      and `/usr/local/var'.  The actual locations are determined when
  20495.      the distribution was built from which `mysqld_safe' comes.  They
  20496.      should be correct if MySQL was installed in a standard location.
  20497.  
  20498. Because `mysqld_safe' will try to find the server and databases relative
  20499. to its own working directory, you can install a binary distribution of
  20500. MySQL anywhere, as long as you start `mysqld_safe' from the MySQL
  20501. installation directory:
  20502.  
  20503.      shell> cd mysql_installation_directory
  20504.      shell> bin/mysqld_safe &
  20505.  
  20506. If `mysqld_safe' fails, even when invoked from the MySQL installation
  20507. directory, you can modify it to use the path to `mysqld' and the
  20508. pathname options that are correct for your system.  Note that if you
  20509. upgrade MySQL in the future, your modified version of `mysqld_safe'
  20510. will be overwritten, so you should make a copy of your edited version
  20511. that you can reinstall.
  20512.  
  20513. `mysqld_multi', A Program for Managing Multiple MySQL Servers
  20514. -------------------------------------------------------------
  20515.  
  20516. `mysqld_multi' is meant for managing several `mysqld' processes that
  20517. listen for connections on different Unix sockets and TCP/IP ports.
  20518.  
  20519. The program will search for group(s) named `[mysqld#]' from `my.cnf'
  20520. (or the file named by the `--config-file=...' option), where `#' can be
  20521. any positive number starting from 1.  This number is referred to in the
  20522. following discussion as the option group number, or GNR.  Group numbers
  20523. distinquish option groups from one another and are used as arguments to
  20524. `mysqld_multi' to specify which servers you want to start, stop, or
  20525. obtain status for.  Options listed in these groups should be the same
  20526. as you would use in the usual `[mysqld]' group used for starting
  20527. `mysqld'.  (See, for example, *Note Automatic start::.)  However, for
  20528. `mysqld_multi', be sure that each group includes options for values
  20529. such as the port, socket, etc., to be used for each individual `mysqld'
  20530. process.
  20531.  
  20532. `mysqld_multi' is invoked using the following syntax:
  20533.  
  20534.      Usage: mysqld_multi [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  20535.      or     mysqld_multi [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  20536.  
  20537. Each GNR represents an option group number. You can start, stop or
  20538. report any GNR, or several of them at the same time. For an example of
  20539. how you might set up an option file, use this command:
  20540.  
  20541.      shell> mysqld_multi --example
  20542.  
  20543. The GNR values in the list can be comma-separated or combined with a
  20544. dash; in the latter case, all the GNRs between GNR1-GNR2 will be
  20545. affected. With no GNR argument, all groups listed in the option file
  20546. will be either started, stopped, or reported. Note that you must not
  20547. have any white spaces in the GNR list. Anything after a white space is
  20548. ignored.
  20549.  
  20550. `mysqld_multi' supports the following options:
  20551.  
  20552. `--config-file=...'
  20553.      Alternative config file. Note: This will not affect this program's
  20554.      own options (group `[mysqld_multi]'), but only groups `[mysqld#]'.
  20555.      Without this option, everything will be searched from the ordinary
  20556.      `my.cnf' file.
  20557.  
  20558. `--example'
  20559.      Display an example option file.
  20560.  
  20561. `--help'
  20562.      Print this help and exit.
  20563.  
  20564. `--log=...'
  20565.      Log file. Full path to and the name for the log file. Note: If the
  20566.      file exists, everything will be appended.
  20567.  
  20568. `--mysqladmin=...'
  20569.      `mysqladmin' binary to be used for a server shutdown.
  20570.  
  20571. `--mysqld=...'
  20572.      `mysqld' binary to be used. Note that you can give `mysqld_safe'
  20573.      to this option also. The options are passed to `mysqld'. Just make
  20574.      sure you have `mysqld' in your environment variable `PATH' or fix
  20575.      `mysqld_safe'.
  20576.  
  20577. `--no-log'
  20578.      Print to stdout instead of the log file. By default the log file is
  20579.      turned on.
  20580.  
  20581. `--password=...'
  20582.      Password for user for `mysqladmin'.
  20583.  
  20584. `--tcp-ip'
  20585.      Connect to the MySQL server(s) via the TCP/IP port instead of the
  20586.      Unix socket. This affects stopping and reporting.  If a socket file
  20587.      is missing, the server may still be running, but can be accessed
  20588.      only via the TCP/IP port.  By default, connections are made using
  20589.      the Unix socket.
  20590.  
  20591. `--user=...'
  20592.      MySQL user for `mysqladmin'.
  20593.  
  20594. `--version'
  20595.      Print the version number and exit.
  20596.  
  20597. Some notes about `mysqld_multi':
  20598.  
  20599.    * Make sure that the MySQL user, who is stopping the `mysqld'
  20600.      services (e.g using the `mysqladmin' program) have the same
  20601.      password and username for all the data directories accessed (to the
  20602.      `mysql' database) And make sure that the user has the `SHUTDOWN'
  20603.      privilege! If you have many data directories and many different
  20604.      `mysql' databases with different passwords for the MySQL `root'
  20605.      user, you may want to create a common `multi_admin' user for each
  20606.      using the same password (see below). Example how to do it:
  20607.           shell> mysql -u root -S /tmp/mysql.sock -proot_password -e
  20608.           "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'multipass'"
  20609.      *Note Privileges::.  You will have to do the above for each
  20610.      `mysqld' running in each data directory, that you have (just
  20611.      change the socket, `-S=...').
  20612.  
  20613.    * `pid-file' is very important, if you are using `mysqld_safe' to
  20614.      start `mysqld' (for example, `--mysqld=mysqld_safe') Every
  20615.      `mysqld' should have its own `pid-file'. The advantage using
  20616.      `mysqld_safe' instead of `mysqld' directly here is, that
  20617.      `mysqld_safe' "guards" every `mysqld' process and will restart it,
  20618.      if a `mysqld' process terminates due to a signal sent using `kill
  20619.      -9', or for other reasons such as a segmentation fault (which
  20620.      MySQL should never do, of course ;). Please note that the
  20621.      `mysqld_safe' script may require that you start it from a certain
  20622.      place. This means that you may have to `cd' to a certain directory,
  20623.      before you start the `mysqld_multi'. If you have problems starting,
  20624.      please see the `mysqld_safe' script. Check especially the lines:
  20625.  
  20626.           --------------------------------------------------------------------------
  20627.           MY_PWD=`pwd` Check if we are starting this relative (for the binary
  20628.           release) if test -d /data/mysql -a -f ./share/mysql/english/errmsg.sys
  20629.           -a -x ./bin/mysqld
  20630.           --------------------------------------------------------------------------
  20631.  
  20632.      *Note `mysqld_safe': mysqld_safe.  The above test should be
  20633.      successful, or you may encounter problems.
  20634.  
  20635.    * Beware of the dangers starting multiple `mysqld's in the same data
  20636.      directory.  Use separate data directories, unless you *know* what
  20637.      you are doing!
  20638.  
  20639.    * The socket file and the TCP/IP port must be different for every
  20640.      `mysqld'.
  20641.  
  20642.    * The first and fifth `mysqld' group were intentionally left out from
  20643.      the example.  You may have 'gaps' in the config file. This gives
  20644.      you more flexibility.  The order in which the `mysqlds' are
  20645.      started or stopped depends on the order in which they appear in
  20646.      the config file.
  20647.  
  20648.    * When you want to refer to a certain group using GNR with this
  20649.      program, just use the number in the end of the group name.  For
  20650.      example, the GNR for a group named `[mysqld17]' is 17.
  20651.  
  20652.    * You may want to use option `--user' for `mysqld', but in order to
  20653.      do this you need to run the `mysqld_multi' script as the Unix
  20654.      `root' user. Having the option in the config file doesn't matter;
  20655.      you will just get a warning, if you are not the superuser and the
  20656.      `mysqlds' are started under *your* Unix account. *Important*: Make
  20657.      sure that the `pid-file' and the data directory are
  20658.      read+write(+execute for the latter one) accessible for *that* Unix
  20659.      user, who the specific `mysqld' process is started as. *Do not*
  20660.      use the Unix root account for this, unless you *know* what you are
  20661.      doing!
  20662.  
  20663.    * *Most important*: Make sure that you understand the meanings of
  20664.      the options that are passed to the `mysqld's and *why one would
  20665.      want* to have separate `mysqld' processes. Starting multiple
  20666.      `mysqld's in one data directory *will not* give you extra
  20667.      performance in a threaded system!
  20668.  
  20669. *Note Multiple servers::.
  20670.  
  20671. This is an example of the config file on behalf of `mysqld_multi'.
  20672.  
  20673.      # This file should probably be in your home dir (~/.my.cnf) or /etc/my.cnf
  20674.      # Version 2.1 by Jani Tolonen
  20675.      
  20676.      [mysqld_multi]
  20677.      mysqld     = /usr/local/bin/mysqld_safe
  20678.      mysqladmin = /usr/local/bin/mysqladmin
  20679.      user       = multi_admin
  20680.      password   = multipass
  20681.      
  20682.      [mysqld2]
  20683.      socket     = /tmp/mysql.sock2
  20684.      port       = 3307
  20685.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  20686.      datadir    = /usr/local/mysql/var2
  20687.      language   = /usr/local/share/mysql/english
  20688.      user       = john
  20689.      
  20690.      [mysqld3]
  20691.      socket     = /tmp/mysql.sock3
  20692.      port       = 3308
  20693.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  20694.      datadir    = /usr/local/mysql/var3
  20695.      language   = /usr/local/share/mysql/swedish
  20696.      user       = monty
  20697.      
  20698.      [mysqld4]
  20699.      socket     = /tmp/mysql.sock4
  20700.      port       = 3309
  20701.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  20702.      datadir    = /usr/local/mysql/var4
  20703.      language   = /usr/local/share/mysql/estonia
  20704.      user       = tonu
  20705.      
  20706.      [mysqld6]
  20707.      socket     = /tmp/mysql.sock6
  20708.      port       = 3311
  20709.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  20710.      datadir    = /usr/local/mysql/var6
  20711.      language   = /usr/local/share/mysql/japanese
  20712.      user       = jani
  20713.  
  20714. *Note Option files::.
  20715.  
  20716. `myisampack', The MySQL Compressed Read-only Table Generator
  20717. ------------------------------------------------------------
  20718.  
  20719. `myisampack' is used to compress MyISAM tables, and `pack_isam' is used
  20720. to compress ISAM tables. Because ISAM tables are deprecated, we will
  20721. only discuss `myisampack' here, but everything said about `myisampack'
  20722. should also be true for `pack_isam'.
  20723.  
  20724. `myisampack' works by compressing each column in the table separately.
  20725. The information needed to decompress columns is read into memory when
  20726. the table is opened. This results in much better performance when
  20727. accessing individual records, because you only have to uncompress
  20728. exactly one record, not a much larger disk block as when using Stacker
  20729. on MS-DOS.  Usually, `myisampack' packs the datafile 40%-70%.
  20730.  
  20731. MySQL uses memory mapping (`mmap()') on compressed tables and falls
  20732. back to normal read/write file usage if `mmap()' doesn't work.
  20733.  
  20734. Please note the following:
  20735.    * After packing, the table is read-only. This is generally intended
  20736.      (such as when accessing packed tables on a CD). Also allowing
  20737.      writes to a packed table is on our TODO list but with low priority.
  20738.  
  20739.    * `myisampack' can also pack `BLOB' or `TEXT' columns.  The older
  20740.      `pack_isam' (for `ISAM' tables) can not do this.
  20741.  
  20742. `myisampack' is invoked like this:
  20743.  
  20744.      shell> myisampack [options] filename ...
  20745.  
  20746. Each filename should be the name of an index (`.MYI') file.  If you are
  20747. not in the database directory, you should specify the pathname to the
  20748. file.  It is permissible to omit the `.MYI' extension.
  20749.  
  20750. `myisampack' supports the following options:
  20751.  
  20752. `-b, --backup'
  20753.      Make a backup of the table as `tbl_name.OLD'.
  20754.  
  20755. `-#, --debug=debug_options'
  20756.      Output debug log. The `debug_options' string often is
  20757.      `'d:t:o,filename''.
  20758.  
  20759. `-f, --force'
  20760.      Force packing of the table even if it becomes bigger or if the
  20761.      temporary file exists.  `myisampack' creates a temporary file
  20762.      named `tbl_name.TMD' while it compresses the table.  If you kill
  20763.      `myisampack', the `.TMD' file may not be deleted.  Normally,
  20764.      `myisampack' exits with an error if it finds that `tbl_name.TMD'
  20765.      exists.  With `--force', `myisampack' packs the table anyway.
  20766.  
  20767. `-?, --help'
  20768.      Display a help message and exit.
  20769.  
  20770. `-j big_tbl_name, --join=big_tbl_name'
  20771.      Join all tables named on the command-line into a single table
  20772.      `big_tbl_name'.  All tables that are to be combined *must* be
  20773.      identical (same column names and types, same indexes, etc.).
  20774.  
  20775. `-p #, --packlength=#'
  20776.      Specify the record length storage size, in bytes.  The value
  20777.      should be 1, 2, or 3.  (`myisampack' stores all rows with length
  20778.      pointers of 1, 2, or 3 bytes.  In most normal cases, `myisampack'
  20779.      can determine the right length value before it begins packing the
  20780.      file, but it may notice during the packing process that it could
  20781.      have used a shorter length. In this case, `myisampack' will print
  20782.      a note that the next time you pack the same file, you could use a
  20783.      shorter record length.)
  20784.  
  20785. `-s, --silent'
  20786.      Silent mode.  Write output only when errors occur.
  20787.  
  20788. `-t, --test'
  20789.      Don't actually pack table, just test packing it.
  20790.  
  20791. `-T dir_name, --tmp_dir=dir_name'
  20792.      Use the named directory as the location in which to write the
  20793.      temporary table.
  20794.  
  20795. `-v, --verbose'
  20796.      Verbose mode.  Write information about progress and packing result.
  20797.  
  20798. `-V, --version'
  20799.      Display version information and exit.
  20800.  
  20801. `-w, --wait'
  20802.      Wait and retry if table is in use.  If the `mysqld' server was
  20803.      invoked with the `--skip-external-locking' option, it is not a
  20804.      good idea to invoke `myisampack' if the table might be updated
  20805.      during the packing process.
  20806.  
  20807. The sequence of commands shown here illustrates a typical table
  20808. compression session:
  20809.  
  20810.      shell> ls -l station.*
  20811.      -rw-rw-r--   1 monty    my         994128 Apr 17 19:00 station.MYD
  20812.      -rw-rw-r--   1 monty    my          53248 Apr 17 19:00 station.MYI
  20813.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  20814.      
  20815.      shell> myisamchk -dvv station
  20816.      
  20817.      MyISAM file:     station
  20818.      Isam-version:  2
  20819.      Creation time: 1996-03-13 10:08:58
  20820.      Recover time:  1997-02-02  3:06:43
  20821.      Data records:              1192  Deleted blocks:              0
  20822.      Datafile: Parts:           1192  Deleted data:                0
  20823.      Datafile pointer (bytes):     2  Keyfile pointer (bytes):     2
  20824.      Max datafile length:   54657023  Max keyfile length:   33554431
  20825.      Recordlength:               834
  20826.      Record format: Fixed length
  20827.      
  20828.      table description:
  20829.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  20830.      1   2     4   unique  unsigned long              1024       1024          1
  20831.      2   32    30  multip. text                      10240       1024          1
  20832.      
  20833.      Field Start Length Type
  20834.      1     1     1
  20835.      2     2     4
  20836.      3     6     4
  20837.      4     10    1
  20838.      5     11    20
  20839.      6     31    1
  20840.      7     32    30
  20841.      8     62    35
  20842.      9     97    35
  20843.      10    132   35
  20844.      11    167   4
  20845.      12    171   16
  20846.      13    187   35
  20847.      14    222   4
  20848.      15    226   16
  20849.      16    242   20
  20850.      17    262   20
  20851.      18    282   20
  20852.      19    302   30
  20853.      20    332   4
  20854.      21    336   4
  20855.      22    340   1
  20856.      23    341   8
  20857.      24    349   8
  20858.      25    357   8
  20859.      26    365   2
  20860.      27    367   2
  20861.      28    369   4
  20862.      29    373   4
  20863.      30    377   1
  20864.      31    378   2
  20865.      32    380   8
  20866.      33    388   4
  20867.      34    392   4
  20868.      35    396   4
  20869.      36    400   4
  20870.      37    404   1
  20871.      38    405   4
  20872.      39    409   4
  20873.      40    413   4
  20874.      41    417   4
  20875.      42    421   4
  20876.      43    425   4
  20877.      44    429   20
  20878.      45    449   30
  20879.      46    479   1
  20880.      47    480   1
  20881.      48    481   79
  20882.      49    560   79
  20883.      50    639   79
  20884.      51    718   79
  20885.      52    797   8
  20886.      53    805   1
  20887.      54    806   1
  20888.      55    807   20
  20889.      56    827   4
  20890.      57    831   4
  20891.      
  20892.      shell> myisampack station.MYI
  20893.      Compressing station.MYI: (1192 records)
  20894.      - Calculating statistics
  20895.      
  20896.      normal:     20  empty-space:      16  empty-zero:        12  empty-fill:  11
  20897.      pre-space:   0  end-space:        12  table-lookups:      5  zero:         7
  20898.      Original trees:  57  After join: 17
  20899.      - Compressing file
  20900.      87.14%
  20901.      
  20902.      shell> ls -l station.*
  20903.      -rw-rw-r--   1 monty    my         127874 Apr 17 19:00 station.MYD
  20904.      -rw-rw-r--   1 monty    my          55296 Apr 17 19:04 station.MYI
  20905.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  20906.      
  20907.      shell> myisamchk -dvv station
  20908.      
  20909.      MyISAM file:     station
  20910.      Isam-version:  2
  20911.      Creation time: 1996-03-13 10:08:58
  20912.      Recover time:  1997-04-17 19:04:26
  20913.      Data records:              1192  Deleted blocks:              0
  20914.      Datafile: Parts:           1192  Deleted data:                0
  20915.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     1
  20916.      Max datafile length:   16777215  Max keyfile length:     131071
  20917.      Recordlength:               834
  20918.      Record format: Compressed
  20919.      
  20920.      table description:
  20921.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  20922.      1   2     4   unique  unsigned long             10240       1024          1
  20923.      2   32    30  multip. text                      54272       1024          1
  20924.      
  20925.      Field Start Length Type                         Huff tree  Bits
  20926.      1     1     1      constant                             1     0
  20927.      2     2     4      zerofill(1)                          2     9
  20928.      3     6     4      no zeros, zerofill(1)                2     9
  20929.      4     10    1                                           3     9
  20930.      5     11    20     table-lookup                         4     0
  20931.      6     31    1                                           3     9
  20932.      7     32    30     no endspace, not_always              5     9
  20933.      8     62    35     no endspace, not_always, no empty    6     9
  20934.      9     97    35     no empty                             7     9
  20935.      10    132   35     no endspace, not_always, no empty    6     9
  20936.      11    167   4      zerofill(1)                          2     9
  20937.      12    171   16     no endspace, not_always, no empty    5     9
  20938.      13    187   35     no endspace, not_always, no empty    6     9
  20939.      14    222   4      zerofill(1)                          2     9
  20940.      15    226   16     no endspace, not_always, no empty    5     9
  20941.      16    242   20     no endspace, not_always              8     9
  20942.      17    262   20     no endspace, no empty                8     9
  20943.      18    282   20     no endspace, no empty                5     9
  20944.      19    302   30     no endspace, no empty                6     9
  20945.      20    332   4      always zero                          2     9
  20946.      21    336   4      always zero                          2     9
  20947.      22    340   1                                           3     9
  20948.      23    341   8      table-lookup                         9     0
  20949.      24    349   8      table-lookup                        10     0
  20950.      25    357   8      always zero                          2     9
  20951.      26    365   2                                           2     9
  20952.      27    367   2      no zeros, zerofill(1)                2     9
  20953.      28    369   4      no zeros, zerofill(1)                2     9
  20954.      29    373   4      table-lookup                        11     0
  20955.      30    377   1                                           3     9
  20956.      31    378   2      no zeros, zerofill(1)                2     9
  20957.      32    380   8      no zeros                             2     9
  20958.      33    388   4      always zero                          2     9
  20959.      34    392   4      table-lookup                        12     0
  20960.      35    396   4      no zeros, zerofill(1)               13     9
  20961.      36    400   4      no zeros, zerofill(1)                2     9
  20962.      37    404   1                                           2     9
  20963.      38    405   4      no zeros                             2     9
  20964.      39    409   4      always zero                          2     9
  20965.      40    413   4      no zeros                             2     9
  20966.      41    417   4      always zero                          2     9
  20967.      42    421   4      no zeros                             2     9
  20968.      43    425   4      always zero                          2     9
  20969.      44    429   20     no empty                             3     9
  20970.      45    449   30     no empty                             3     9
  20971.      46    479   1                                          14     4
  20972.      47    480   1                                          14     4
  20973.      48    481   79     no endspace, no empty               15     9
  20974.      49    560   79     no empty                             2     9
  20975.      50    639   79     no empty                             2     9
  20976.      51    718   79     no endspace                         16     9
  20977.      52    797   8      no empty                             2     9
  20978.      53    805   1                                          17     1
  20979.      54    806   1                                           3     9
  20980.      55    807   20     no empty                             3     9
  20981.      56    827   4      no zeros, zerofill(2)                2     9
  20982.      57    831   4      no zeros, zerofill(1)                2     9
  20983.  
  20984. The information printed by `myisampack' is described here:
  20985.  
  20986. `normal'
  20987.      The number of columns for which no extra packing is used.
  20988.  
  20989. `empty-space'
  20990.      The number of columns containing values that are only spaces;
  20991.      these will occupy 1 bit.
  20992.  
  20993. `empty-zero'
  20994.      The number of columns containing values that are only binary 0's;
  20995.      these will occupy 1 bit.
  20996.  
  20997. `empty-fill'
  20998.      The number of integer columns that don't occupy the full byte
  20999.      range of their type; these are changed to a smaller type (for
  21000.      example, an `INTEGER' column may be changed to `MEDIUMINT').
  21001.  
  21002. `pre-space'
  21003.      The number of decimal columns that are stored with leading spaces.
  21004.      In this case, each value will contain a count for the number of
  21005.      leading spaces.
  21006.  
  21007. `end-space'
  21008.      The number of columns that have a lot of trailing spaces.  In this
  21009.      case, each value will contain a count for the number of trailing
  21010.      spaces.
  21011.  
  21012. `table-lookup'
  21013.      The column had only a small number of different values, which were
  21014.      converted to an `ENUM' before Huffman compression.
  21015.  
  21016. `zero'
  21017.      The number of columns for which all values are zero.
  21018.  
  21019. `Original trees'
  21020.      The initial number of Huffman trees.
  21021.  
  21022. `After join'
  21023.      The number of distinct Huffman trees left after joining trees to
  21024.      save some header space.
  21025.  
  21026. After a table has been compressed, `myisamchk -dvv' prints additional
  21027. information about each field:
  21028.  
  21029. `Type'
  21030.      The field type may contain the following descriptors:
  21031.  
  21032.     `constant'
  21033.           All rows have the same value.
  21034.  
  21035.     `no endspace'
  21036.           Don't store endspace.
  21037.  
  21038.     `no endspace, not_always'
  21039.           Don't store endspace and don't do end space compression for
  21040.           all values.
  21041.  
  21042.     `no endspace, no empty'
  21043.           Don't store endspace. Don't store empty values.
  21044.  
  21045.     `table-lookup'
  21046.           The column was converted to an `ENUM'.
  21047.  
  21048.     `zerofill(n)'
  21049.           The most significant `n' bytes in the value are always 0 and
  21050.           are not stored.
  21051.  
  21052.     `no zeros'
  21053.           Don't store zeros.
  21054.  
  21055.     `always zero'
  21056.           0 values are stored in 1 bit.
  21057.  
  21058. `Huff tree'
  21059.      The Huffman tree associated with the field.
  21060.  
  21061. `Bits'
  21062.      The number of bits used in the Huffman tree.
  21063.  
  21064. After you have run `pack_isam'/`myisampack' you must run
  21065. `isamchk'/`myisamchk' to re-create the index.  At this time you can
  21066. also sort the index blocks and create statistics needed for the MySQL
  21067. optimiser to work more efficiently:
  21068.  
  21069.      myisamchk -rq --analyze --sort-index table_name.MYI
  21070.      isamchk   -rq --analyze --sort-index table_name.ISM
  21071.  
  21072. After you have installed the packed table into the MySQL database
  21073. directory you should do `mysqladmin flush-tables' to force `mysqld' to
  21074. start using the new table.
  21075.  
  21076. If you want to unpack a packed table, you can do this with the
  21077. `--unpack' option to `isamchk' or `myisamchk'.
  21078.  
  21079. `mysqld-max', An Extended `mysqld' Server
  21080. -----------------------------------------
  21081.  
  21082. `mysqld-max' is the MySQL server (`mysqld') configured with the
  21083. following configure options:
  21084.  
  21085. *Option*               *Comment*
  21086. -with-server-suffix=-maxAdd a suffix to the `mysqld' version string
  21087. -with-innodb           Support for InnoDB tables (MySQL 3.23 only)
  21088. -with-bdb              Support for Berkeley DB (BDB) tables
  21089. CFLAGS=-DUSE_SYMDIR    Symbolic link support for Windows
  21090.  
  21091. The option for enabling InnoDB support is needed only in MySQL 3.23. In
  21092. MySQL 4 and up, InnoDB is included by default.
  21093.  
  21094. You can find the MySQL-Max binaries at
  21095. `http://www.mysql.com/downloads/mysql-max-4.0.html'.
  21096.  
  21097. The Windows MySQL binary distributions includes both the standard
  21098. `mysqld.exe' binary and the `mysqld-max.exe' binary.
  21099. `http://www.mysql.com/downloads/mysql-4.0.html'.  *Note Windows
  21100. installation::.
  21101.  
  21102. Note that as BerkeleyDB (BDB) is not available for all platforms, so
  21103. some of the `Max' binaries may not have support for it.  You can check
  21104. which table types are supported by doing the following query:
  21105.  
  21106.      mysql> SHOW VARIABLES LIKE "have_%";
  21107.      +------------------+----------+
  21108.      | Variable_name    | Value    |
  21109.      +------------------+----------+
  21110.      | have_bdb         | NO       |
  21111.      | have_crypt       | YES      |
  21112.      | have_innodb      | YES      |
  21113.      | have_isam        | YES      |
  21114.      | have_raid        | NO       |
  21115.      | have_symlink     | DISABLED |
  21116.      | have_openssl     | NO       |
  21117.      | have_query_cache | YES      |
  21118.      +------------------+----------+
  21119.  
  21120. The meanings of the values in the second column are:
  21121.  
  21122. *Value*     *Meaning*
  21123. `YES'       The option is activated and usable.
  21124. `NO'        MySQL is not compiled with support for this option.
  21125. `DISABLED'  The xxxx option is disabled because one started `mysqld'
  21126.             with `--skip-xxxx' or because one didn't start `mysqld' with
  21127.             all needed options to enable the option.  In this case the
  21128.             `hostname.err' file should contain a reason indicating why
  21129.             the option is disabled.
  21130.  
  21131. *Note*:  To be able to create InnoDB tables in MySQL version 3.23 you
  21132. *must* edit your startup options to include at least the
  21133. `innodb_data_file_path' option. *Note InnoDB in MySQL 3.23::.
  21134.  
  21135. To get better performance for BDB tables, you should add some
  21136. configuration options for these, too. *Note BDB start::.
  21137.  
  21138. `mysqld_safe' automatically tries to start any `mysqld' binary with the
  21139. `-max' suffix. This makes it very easy to test out another `mysqld'
  21140. binary in an existing installation.  Just run `configure' with the
  21141. options you want and then install the new `mysqld' binary as
  21142. `mysqld-max' in the same directory where your old `mysqld' binary is.
  21143. *Note `mysqld_safe': mysqld_safe.
  21144.  
  21145. On Linux, the `MySQL-Max' RPM uses the above mentioned `mysqld_safe'
  21146. feature. (It just installs the `mysqld-max' executable, so
  21147. `mysqld_safe' automatically uses this executable when `mysqld_safe' is
  21148. restarted.)
  21149.  
  21150. The following table shows which table types our MySQL-Max binaries
  21151. include:
  21152.  
  21153. *System*    `BDB'   `InnoDB'
  21154. Windows/NT  Y       Y
  21155. AIX 4.3     N       Y
  21156. HP-UX 11.0  N       Y
  21157. Linux-Alpha N       Y
  21158. Linux-Intel Y       Y
  21159. Linux-IA-64 N       Y
  21160. Solaris-IntelN       Y
  21161. Solaris-SPARCY       Y
  21162. SCO OSR5    Y       Y
  21163. UnixWare    Y       Y
  21164. Mac OS X    N       Y
  21165.  
  21166. Note that as of MySQL 4, you do not need a MySQL Max server for InnoDB,
  21167. because InnoDB is included by default.
  21168.  
  21169. MySQL Client-Side Scripts and Utilities
  21170. =======================================
  21171.  
  21172. Overview of the Client-Side Scripts and Utilities
  21173. -------------------------------------------------
  21174.  
  21175. All MySQL clients that communicate with the server using the
  21176. `mysqlclient' library use the following environment variables:
  21177.  
  21178. *Name*             *Description*
  21179. `MYSQL_UNIX_PORT'  The default socket; used for connections
  21180.                    to `localhost'
  21181. `MYSQL_TCP_PORT'   The default TCP/IP port
  21182. `MYSQL_PWD'        The default password
  21183. `MYSQL_DEBUG'      Debug-trace options when debugging
  21184. `TMPDIR'           The directory where temporary tables/files
  21185.                    are created
  21186.  
  21187. Use of `MYSQL_PWD' is insecure.  *Note Connecting::.
  21188.  
  21189. The `mysql' client uses the file named in the `MYSQL_HISTFILE'
  21190. environment variable to save the command-line history. The default
  21191. value for the history file is `$HOME/.mysql_history', where `$HOME' is
  21192. the value of the `HOME' environment variable. *Note Environment
  21193. variables::.
  21194.  
  21195. All MySQL programs take many different options. However, every MySQL
  21196. program provides a `--help' option that you can use to get a full
  21197. description of the program's different options. For example, try `mysql
  21198. --help'.
  21199.  
  21200. You can override default options for all standard client programs with
  21201. an option file. *Note Option files::.
  21202.  
  21203. The following list briefly describes the client-side MySQL programs:
  21204.  
  21205. `msql2mysql'
  21206.      A shell script that converts `mSQL' programs to MySQL. It doesn't
  21207.      handle all cases, but it gives a good start when converting.
  21208.  
  21209. `mysql'
  21210.      The command-line tool for interactively entering queries or
  21211.      executing queries from a file in batch mode.  *Note `mysql': mysql.
  21212.  
  21213. `mysqlaccess'
  21214.      A script that checks the access privileges for a host, user, and
  21215.      database combination.
  21216.  
  21217. `mysqladmin'
  21218.      Utility for performing administrative operations, such as creating
  21219.      or dropping databases, reloading the grant tables, flushing tables
  21220.      to disk, and reopening log files.  `mysqladmin' can also be used
  21221.      to retrieve version, process, and status information from the
  21222.      server.  *Note `mysqladmin': mysqladmin.
  21223.  
  21224. `mysqlbinlog'
  21225.      Utility for reading queries from a binary log. Can be used to
  21226.      recover from a crash with an old backup.  *Note `mysqlbinlog':
  21227.      mysqlbinlog.
  21228.  
  21229. `mysqldump'
  21230.      Dumps a MySQL database into a file as SQL statements or as
  21231.      tab-separated text files. Enhanced freeware originally by Igor
  21232.      Romanenko.  *Note `mysqldump': mysqldump.
  21233.  
  21234. `mysqlimport'
  21235.      Imports text files into their respective tables using `LOAD DATA
  21236.      INFILE'. *Note `mysqlimport': mysqlimport.
  21237.  
  21238. `mysqlshow'
  21239.      Displays information about databases, tables, columns, and indexes.
  21240.  
  21241. `replace'
  21242.      A utility program that is used by `msql2mysql', but that has more
  21243.      general applicability as well.  `replace' changes strings in place
  21244.      in files or on the standard input. Uses a finite state machine to
  21245.      match longer strings first. Can be used to swap strings. For
  21246.      example, this command swaps `a' and `b' in the given files:
  21247.  
  21248.           shell> replace a b b a -- file1 file2 ...
  21249.  
  21250. `mysql', The Command-line Tool
  21251. ------------------------------
  21252.  
  21253. `mysql' is a simple SQL shell (with GNU `readline' capabilities).  It
  21254. supports interactive and non-interactive use. When used interactively,
  21255. query results are presented in an ASCII-table format. When used
  21256. non-interactively (for example, as a filter), the result is presented in
  21257. tab-separated format.  (The output format can be changed using
  21258. command-line options.)  You can run scripts simply like this:
  21259.  
  21260.      shell> mysql database < script.sql > output.tab
  21261.  
  21262. If you have problems due to insufficient memory in the client, use the
  21263. `--quick' option!  This forces `mysql' to use `mysql_use_result()'
  21264. rather than `mysql_store_result()' to retrieve the result set.
  21265.  
  21266. Using `mysql' is very easy. Just start it as follows: `mysql database'
  21267. or `mysql --user=user_name --password=your_password database'. Type an
  21268. SQL statement, end it with `;', `\g', or `\G' and press Enter.
  21269.  
  21270. `mysql' supports the following options:
  21271.  
  21272. `-?, --help'
  21273.      Display this help and exit.
  21274.  
  21275. `-A, --no-auto-rehash'
  21276.      No automatic rehashing. One has to use 'rehash' to get table and
  21277.      field completion. This gives a quicker start of mysql.
  21278.  
  21279. `--prompt=...'
  21280.      Set the mysql prompt to specified format.
  21281.  
  21282. `-b, --no-beep'
  21283.      Turn off beep-on-error.
  21284.  
  21285. `-B, --batch'
  21286.      Print results with a tab as separator, each row on a new line.
  21287.      Doesn't use history file.
  21288.  
  21289. `--character-sets-dir=...'
  21290.      Directory where character sets are located.
  21291.  
  21292. `-C, --compress'
  21293.      Use compression in server/client protocol.
  21294.  
  21295. `-#, --debug[=...]'
  21296.      Debug log. Default is 'd:t:o,/tmp/mysql.trace'.
  21297.  
  21298. `-D, --database=...'
  21299.      Database to use. This is mainly useful in the `my.cnf' file.
  21300.  
  21301. `--default-character-set=...'
  21302.      Set the default character set.
  21303.  
  21304. `-e, --execute=...'
  21305.      Execute command and quit. (Output like with -batch)
  21306.  
  21307. `-E, --vertical'
  21308.      Print the output of a query (rows) vertically. Without this option
  21309.      you can also force this output by ending your statements with `\G'.
  21310.  
  21311. `-f, --force'
  21312.      Continue even if we get an SQL error.
  21313.  
  21314. `-g, --no-named-commands'
  21315.      Named commands are disabled. Use \* form only, or use named
  21316.      commands only in the beginning of a line ending with a semicolon
  21317.      (`;'). Since Version 10.9, the client now starts with this option
  21318.      *enabled* by default!  With the -g option, long format commands
  21319.      will still work from the first line, however.
  21320.  
  21321. `-G, --enable-named-commands'
  21322.      Named commands are *enabled*.  Long format commands are allowed as
  21323.      well as shortened \* commands.
  21324.  
  21325. `-i, --ignore-space'
  21326.      Ignore space after function names.
  21327.  
  21328. `-h, --host=...'
  21329.      Connect to the given host.
  21330.  
  21331. `-H, --html'
  21332.      Produce HTML output.
  21333.  
  21334. `-X, --xml'
  21335.      Produce XML output.
  21336.  
  21337. `-L, --skip-line-numbers'
  21338.      Don't write line number for errors. Useful when one wants to
  21339.      compare result files that includes error messages
  21340.  
  21341. `--no-pager'
  21342.      Disable pager and print to stdout. See interactive help (\h) also.
  21343.  
  21344. `--no-tee'
  21345.      Disable outfile. See interactive help (\h) also.
  21346.  
  21347. `-n, --unbuffered'
  21348.      Flush buffer after each query.
  21349.  
  21350. `-N, --skip-column-names'
  21351.      Don't write column names in results.
  21352.  
  21353. `-O, --set-variable var=option'
  21354.      Give a variable a value. `--help' lists variables.  Please note
  21355.      that `--set-variable' is deprecated since MySQL 4.0, just use
  21356.      `--var=option' on its own.
  21357.  
  21358. `-o, --one-database'
  21359.      Only update the default database. This is useful for skipping
  21360.      updates to other database in the binary log.
  21361.  
  21362. ``--pager[=...]''
  21363.      Output type. Default is your `ENV' variable `PAGER'. Valid pagers
  21364.      are less, more, cat [> filename], etc.  See interactive help (\h)
  21365.      also. This option does not work in batch mode. Pager works only in
  21366.      Unix.
  21367.  
  21368. `-p[password], --password[=...]'
  21369.      Password to use when connecting to server. If a password is not
  21370.      given on the command-line, you will be prompted for it.  Note that
  21371.      if you use the short form `-p' you can't have a space between the
  21372.      option and the password.
  21373.  
  21374. `-P port_num, --port=port_num'
  21375.      TCP/IP port number to use for connection.
  21376.  
  21377. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  21378.      To specify the connect protocol to use.  New in MySQL 4.1.
  21379.  
  21380. `-q, --quick'
  21381.      Don't cache result, print it row-by-row. This may slow down the
  21382.      server if the output is suspended. Doesn't use history file.
  21383.  
  21384. `-r, --raw'
  21385.      Write column values without escape conversion. Used with `--batch'
  21386.  
  21387. `--reconnect'
  21388.      If the connection is lost, automatically try to reconnect to the
  21389.      server (but only once).
  21390.  
  21391. `-s, --silent'
  21392.      Be more silent.
  21393.  
  21394. `-S  --socket=...'
  21395.      Socket file to use for connection.
  21396.  
  21397. `-t  --table'
  21398.      Output in table format. This is default in non-batch mode.
  21399.  
  21400. `-T, --debug-info'
  21401.      Print some debug information at exit.
  21402.  
  21403. `--tee=...'
  21404.      Append everything into outfile. See interactive help (\h) also.
  21405.      Does not work in batch mode.
  21406.  
  21407. `-u, --user=#'
  21408.      User for login if not current user.
  21409.  
  21410. `-U, --safe-updates[=#], --i-am-a-dummy[=#]'
  21411.      Only allow `UPDATE' and `DELETE' that uses keys. See below for
  21412.      more information about this option.  You can reset this option if
  21413.      you have it in your `my.cnf' file by using `--safe-updates=0'.
  21414.  
  21415. `-v, --verbose'
  21416.      More verbose output (-v -v -v gives the table output format).
  21417.  
  21418. `-V, --version'
  21419.      Output version information and exit.
  21420.  
  21421. `-w, --wait'
  21422.      Wait and retry if connection is down instead of aborting.
  21423.  
  21424. You can also set the following variables with `-O' or `--set-variable';
  21425. please note that `--set-variable' is deprecated since MySQL 4.0, just
  21426. use `--var=option' on its own:
  21427.  
  21428. *Variable Name*    *Default**Description*
  21429. connect_timeout    0       Number of seconds before timeout connection.
  21430. max_allowed_packet 16777216Max packetlength to send/receive from to server
  21431. net_buffer_length  16384   Buffer for TCP/IP and socket communication
  21432. select_limit       1000    Automatic limit for SELECT when using
  21433.                            -i-am-a-dummy
  21434. max_join_size      1000000 Automatic limit for rows in a join when using
  21435.                            -i-am-a-dummy.
  21436.  
  21437. If the `mysql' client loses connection to the server while sending it a
  21438. query, it will immediately and automatically try to reconnect once to
  21439. the server and send the query again.  Note that even if it succeeds in
  21440. reconnecting, as your first connection has ended, all your previous
  21441. session objects are lost : temporary tables, user and session
  21442. variables. Therefore, the above behaviour may be dangerous for you, as
  21443. in this example where the server was shut down and restarted without
  21444. you knowing it :
  21445.  
  21446.      mysql> set @a=1;
  21447.      Query OK, 0 rows affected (0.05 sec)
  21448.      
  21449.      mysql> insert into t values(@a);
  21450.      ERROR 2006: MySQL server has gone away
  21451.      No connection. Trying to reconnect...
  21452.      Connection id:    1
  21453.      Current database: test
  21454.      
  21455.      Query OK, 1 row affected (1.30 sec)
  21456.      
  21457.      mysql> select * from t;
  21458.      +------+
  21459.      | a    |
  21460.      +------+
  21461.      | NULL |
  21462.      +------+
  21463.      1 row in set (0.05 sec)
  21464.  
  21465. The `@a' user variable has been lost with the connection, and after the
  21466. reconnection it is undefined.  To protect from this risk, you can start
  21467. the `mysql' client with the `--disable-reconnect' option.
  21468.  
  21469. If you type 'help' on the command-line, `mysql' will print out the
  21470. commands that it supports:
  21471.  
  21472.      mysql> help
  21473.      
  21474.      MySQL commands:
  21475.      help    (\h)    Display this text.
  21476.      ?       (\h)    Synonym for `help'.
  21477.      clear   (\c)    Clear command.
  21478.      connect (\r)    Reconnect to the server.
  21479.                      Optional arguments are db and host.
  21480.      edit    (\e)    Edit command with $EDITOR.
  21481.      ego     (\G)    Send command to mysql server,
  21482.                      display result vertically.
  21483.      exit    (\q)    Exit mysql. Same as quit.
  21484.      go      (\g)    Send command to mysql server.
  21485.      nopager (\n)    Disable pager, print to stdout.
  21486.      notee   (\t)    Don't write into outfile.
  21487.      pager   (\P)    Set PAGER [to_pager].
  21488.                      Print the query results via PAGER.
  21489.      print   (\p)    Print current command.
  21490.      prompt  (\R)    Change your mysql prompt.
  21491.      quit    (\q)    Quit mysql.
  21492.      rehash  (\#)    Rebuild completion hash.
  21493.      source  (\.)    Execute an SQL script file.
  21494.                      Takes a file name as an argument.
  21495.      status  (\s)    Get status information from the server.
  21496.      system  (\!)    Execute a system shell command.
  21497.      tee     (\T)    Set outfile [to_outfile].
  21498.                      Append everything into given outfile.
  21499.      use     (\u)    Use another database.
  21500.                      Takes database name as argument.
  21501.  
  21502. The `edit', `nopager', `pager', and `system' commands work only in Unix.
  21503.  
  21504. The `status' command gives you some information about the connection
  21505. and the server you are using. If you are running in the
  21506. `--safe-updates' mode, `status' will also print the values for the
  21507. `mysql' variables that affect your queries.
  21508.  
  21509. A useful startup option for beginners (introduced in MySQL Version
  21510. 3.23.11) is `--safe-updates' (or `--i-am-a-dummy' for users that once
  21511. may have done a `DELETE FROM table_name' but forgot the `WHERE'
  21512. clause).  When using this option, `mysql' sends the following command
  21513. to the MySQL server when opening the connection:
  21514.  
  21515.      SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#,
  21516.          SQL_MAX_JOIN_SIZE=#max_join_size#"
  21517.  
  21518. where `#select_limit#' and `#max_join_size#' are variables that can be
  21519. set from the `mysql' command-line. *Note `SET': SET OPTION.
  21520.  
  21521. The effect of the above is:
  21522.  
  21523.    * You are not allowed to do an `UPDATE' or `DELETE' statement if you
  21524.      don't have a key constraint in the `WHERE' part. One can, however,
  21525.      force an `UPDATE/DELETE' by using `LIMIT':
  21526.           UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1;
  21527.  
  21528.    * All big results are automatically limited to `#select_limit#' rows.
  21529.  
  21530.    * `SELECT's that will probably need to examine more than
  21531.      `#max_join_size' row combinations will be aborted.
  21532.  
  21533. Some useful hints about the `mysql' client:
  21534.  
  21535. Some data is much more readable when displayed vertically, instead of
  21536. the usual horizontal box type output. For example longer text, which
  21537. includes new lines, is often much easier to be read with vertical
  21538. output.
  21539.  
  21540.      mysql> SELECT * FROM mails WHERE LENGTH(txt) < 300 lIMIT 300,1\G
  21541.      *************************** 1. row ***************************
  21542.        msg_nro: 3068
  21543.           date: 2000-03-01 23:29:50
  21544.      time_zone: +0200
  21545.      mail_from: Monty
  21546.          reply: monty@no.spam.com
  21547.        mail_to: "Thimble Smith" <tim@no.spam.com>
  21548.            sbj: UTF-8
  21549.            txt: >>>>> "Thimble" == Thimble Smith writes:
  21550.      
  21551.      Thimble> Hi.  I think this is a good idea.  Is anyone familiar with UTF-8
  21552.      Thimble> or Unicode? Otherwise, I'll put this on my TODO list and see what
  21553.      Thimble> happens.
  21554.      
  21555.      Yes, please do that.
  21556.      
  21557.      Regards,
  21558.      Monty
  21559.           file: inbox-jani-1
  21560.           hash: 190402944
  21561.      1 row in set (0.09 sec)
  21562.  
  21563. For logging, you can use the `tee' option. The `tee' can be started
  21564. with option `--tee=...', or from the command-line interactively with
  21565. command `tee'. All the data displayed on the screen will also be
  21566. appended into a given file. This can be very useful for debugging
  21567. purposes also. The `tee' can be disabled from the command-line with
  21568. command `notee'. Executing `tee' again starts logging again. Without a
  21569. parameter the previous file will be used. Note that `tee' will flush
  21570. the results into the file after each command, just before the
  21571. command-line appears again waiting for the next command.
  21572.  
  21573. Browsing, or searching the results in the interactive mode in Unix less,
  21574. more, or any other similar program, is now possible with option
  21575. `--pager[=...]'. Without argument, `mysql' client will look for the
  21576. `PAGER' environment variable and set `pager' to that.  `pager' can be
  21577. started from the interactive command-line with command `pager' and
  21578. disabled with command `nopager'.  The command takes an argument
  21579. optionally and the `pager' will be set to that. Command `pager' can be
  21580. called without an argument, but this requires that the option `--pager'
  21581. was used, or the `pager' will default to stdout. `pager' works only in
  21582. Unix, since it uses the `popen()' function, which doesn't exist in
  21583. Windows. In Windows, the `tee' option can be used instead, although it
  21584. may not be as handy as `pager' can be in some situations.
  21585.  
  21586. A few tips about `pager':
  21587.    * You can use it to write to a file:
  21588.           mysql> pager cat > /tmp/log.txt
  21589.      and the results will only go to a file. You can also pass any
  21590.      options for the programs that you want to use with the `pager':
  21591.           mysql> pager less -n -i -S
  21592.  
  21593.    * From the above do note the option `-S'. You may find it very
  21594.      useful when browsing the results; try the option with horizontal
  21595.      output (end commands with `\g', or `;') and with vertical output
  21596.      (end commands with `\G'). Sometimes a very wide result set is hard
  21597.      to be read from the screen, with option `-S' to `less' you can
  21598.      browse the results within the interactive `less' from left to
  21599.      right, preventing lines longer than your screen from being
  21600.      continued to the next line. This can make the result set much more
  21601.      readable. You can switch the mode between on and off within the
  21602.      interactive `less' with `-S'. See the 'h' for more help about
  21603.      `less'.
  21604.  
  21605.    * You can combine very complex ways to handle the results, for
  21606.      example the following would send the results to two files in two
  21607.      different directories, on two different hard-disks mounted on /dr1
  21608.      and /dr2, yet let the results still be seen on the screen via less:
  21609.           mysql> pager cat | tee /dr1/tmp/res.txt | \
  21610.           tee /dr2/tmp/res2.txt | less -n -i -S
  21611.  
  21612.  
  21613. You can also combine the two functions above; have the `tee' enabled,
  21614. `pager' set to 'less' and you will be able to browse the results in
  21615. Unix 'less' and still have everything appended into a file the same
  21616. time. The difference between Unix `tee' used with the `pager' and the
  21617. `mysql' client in-built `tee', is that the in-built `tee' works even if
  21618. you don't have the Unix `tee' available. The in-built `tee' also logs
  21619. everything that is printed on the screen, where the Unix `tee' used
  21620. with `pager' doesn't log quite that much. Last, but not least, the
  21621. interactive `tee' is more handy to switch on and off, when you want to
  21622. log something into a file, but want to be able to turn the feature off
  21623. sometimes.
  21624.  
  21625. From MySQL version 4.0.2 it is possible to change the prompt in the
  21626. `mysql' command-line client.
  21627.  
  21628. You can use the following prompt options:
  21629. *Option**Description*
  21630. \v      mysqld version
  21631. \d      database in use
  21632. \h      host connected to
  21633. \p      port connected on
  21634. \u      username
  21635. \U      full username@host
  21636. \\      `\'
  21637. \n      new line break
  21638. \t      tab
  21639. \       space
  21640. \_      space
  21641. \R      military hour time (0-23)
  21642. \r      standard hour time (1-12)
  21643. \m      minutes
  21644. \y      two digit year
  21645. \Y      four digit year
  21646. \D      full date format
  21647. \s      seconds
  21648. \w      day of the week in three letter
  21649.         format (Mon, Tue, ...)
  21650. \P      am/pm
  21651. \o      month in number format
  21652. \O      month in three letter format (Jan,
  21653.         Feb, ...)
  21654. \c      counter that counts up for each
  21655.         command you do
  21656.  
  21657. `\' followed by any other letter just becomes that letter.
  21658.  
  21659. You may set the prompt in the following places:
  21660.  
  21661. *Environment Variable*
  21662.      You may set the `MYSQL_PS1' environment variable to a prompt
  21663.      string.  For example:
  21664.  
  21665.           shell> export MYSQL_PS1="(\u@\h) [\d]> "
  21666.  
  21667. *`my.cnf'*
  21668.  
  21669. *`.my.cnf'*
  21670.      You may set the `prompt' option in any MySQL configuration file,
  21671.      in the `mysql' group.  For example:
  21672.  
  21673.           [mysql]
  21674.           prompt=(\u@\h) [\d]>\_
  21675.  
  21676. *Command Line*
  21677.      You may set the `--prompt' option on the command line to `mysql'.
  21678.      For example:
  21679.  
  21680.           shell> mysql --prompt="(\u@\h) [\d]> "
  21681.           
  21682.           (user@host) [database]>
  21683.  
  21684. *Interactively*
  21685.      You may also use the `prompt' (or `\R') command to change your
  21686.      prompt interactively.  For example:
  21687.  
  21688.           mysql> prompt (\u@\h) [\d]>\_
  21689.           PROMPT set to '(\u@\h) [\d]>\_'
  21690.           (user@host) [database]>
  21691.           (user@host) [database]> prompt
  21692.           Returning to default PROMPT of mysql>
  21693.           mysql>
  21694.  
  21695. `mysqladmin', Administrating a MySQL Server
  21696. -------------------------------------------
  21697.  
  21698. A utility for performing administrative operations. The syntax is:
  21699.  
  21700.      shell> mysqladmin [OPTIONS] command [command-option] command ...
  21701.  
  21702. You can get a list of the options your version of `mysqladmin' supports
  21703. by executing `mysqladmin --help'.
  21704.  
  21705. The current `mysqladmin' supports the following commands:
  21706.  
  21707. `create databasename'
  21708.      Create a new database.
  21709.  
  21710. `drop databasename'
  21711.      Delete a database and all its tables.
  21712.  
  21713. `extended-status'
  21714.      Gives an extended status message from the server.
  21715.  
  21716. `flush-hosts'
  21717.      Flush all cached hosts.
  21718.  
  21719. `flush-logs'
  21720.      Flush all logs.
  21721.  
  21722. `flush-tables'
  21723.      Flush all tables.
  21724.  
  21725. `flush-privileges'
  21726.      Reload grant tables (same as reload).
  21727.  
  21728. `kill id,id,...'
  21729.      Kill mysql threads.
  21730.  
  21731. `password'
  21732.      Set a new password. Change old password to new-password.
  21733.  
  21734. `ping'
  21735.      Check if mysqld is alive.
  21736.  
  21737. `processlist'
  21738.      Show list of active threads in server, as with the `SHOW
  21739.      PROCESSLIST' statement.  If the `--verbose' option is given, the
  21740.      output is like that of `SHOW FULL PROCESSLIST'.
  21741.  
  21742. `reload'
  21743.      Reload grant tables.
  21744.  
  21745. `refresh'
  21746.      Flush all tables and close and open logfiles.
  21747.  
  21748. `shutdown'
  21749.      Take server down.
  21750.  
  21751. `slave-start'
  21752.      Start slave replication thread.
  21753.  
  21754. `slave-stop'
  21755.      Stop slave replication thread.
  21756.  
  21757. `status'
  21758.      Gives a short status message from the server.
  21759.  
  21760. `variables'
  21761.      Prints variables available.
  21762.  
  21763. `version'
  21764.      Get version information from server.
  21765.  
  21766. All commands can be shortened to their unique prefix.  For example:
  21767.  
  21768.      shell> mysqladmin proc stat
  21769.      +----+-------+-----------+----+-------------+------+-------+------+
  21770.      | Id | User  | Host      | db | Command     | Time | State | Info |
  21771.      +----+-------+-----------+----+-------------+------+-------+------+
  21772.      | 6  | monty | localhost |    | Processlist | 0    |       |      |
  21773.      +----+-------+-----------+----+-------------+------+-------+------+
  21774.      Uptime: 10077  Threads: 1  Questions: 9  Slow queries: 0
  21775.      Opens: 6 Flush tables: 1  Open tables: 2
  21776.      Memory in use: 1092K  Max memory used: 1116K
  21777.  
  21778. The `mysqladmin status' command result has the following columns:
  21779.  
  21780. *Column*       *Description*
  21781. Uptime         Number of seconds the MySQL server has been up.
  21782. Threads        Number of active threads (clients).
  21783. Questions      Number of questions from clients since
  21784.                `mysqld' was started.
  21785. Slow queries   Queries that have taken more than
  21786.                `long_query_time' seconds. *Note Slow query
  21787.                log::.
  21788. Opens          How many tables `mysqld' has opened.
  21789. Flush tables   Number of `flush ...', `refresh', and `reload'
  21790.                commands.
  21791. Open tables    Number of tables that are open now.
  21792. Memory in use  Memory allocated directly by the `mysqld' code
  21793.                (only available when MySQL is compiled with
  21794.                -with-debug=full).
  21795. Max memory     Maximum memory allocated directly by the
  21796. used           `mysqld' code (only available when MySQL is
  21797.                compiled with -with-debug=full).
  21798.  
  21799. If you do `mysqladmin shutdown' on a socket (in other words, on a the
  21800. computer where `mysqld' is running), `mysqladmin' will wait until the
  21801. MySQL `pid-file' is removed to ensure that the `mysqld' server has
  21802. stopped properly.
  21803.  
  21804. `mysqlbinlog', Executing the queries from a binary log
  21805. ------------------------------------------------------
  21806.  
  21807. You can examine the binary log file (*note Binary log::) with the
  21808. `mysqlbinlog' utility.
  21809.  
  21810.      shell> mysqlbinlog hostname-bin.001
  21811.  
  21812. will print all queries contained in binlog `hostname-bin.001', together
  21813. with information (time the query took, id of the thread which issued
  21814. it, timestamp when it was issued etc).
  21815.  
  21816. You can pipe the output of `mysqlbinlog' into a `mysql' client; this is
  21817. used to recover from a crash when you have an old backup (*note
  21818. Backup::):
  21819.  
  21820.      shell> mysqlbinlog hostname-bin.001 | mysql
  21821.  
  21822. or
  21823.  
  21824.      shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  21825.  
  21826. You can also redirect the output of `mysqlbinlog' to a text file
  21827. instead, modify this text file (to cut queries you don't want to
  21828. execute for some reason), then execute the queries from the text file
  21829. into `mysql'.
  21830.  
  21831. `mysqlbinlog' has the `position=#' options which will print only
  21832. queries whose offset in the binlog is greater or equal to `#'.
  21833.  
  21834. If you have more than one binary log to execute on the MySQL server,
  21835. the safe method is to do it in one unique MySQL connection. Here is
  21836. what may be UNsafe:
  21837.  
  21838.      shell> mysqlbinlog hostname-bin.001 | mysql # DANGER!!
  21839.      shell> mysqlbinlog hostname-bin.002 | mysql # DANGER!!
  21840.  
  21841. It will cause problems if the first binlog contains a `CREATE TEMPORARY
  21842. TABLE' and the second one contains a query which uses this temporary
  21843. table: when the first `mysql' terminates, it will drop the temporary
  21844. table, so the second `mysql' will report "unknown table". This is why
  21845. you should run all binlogs you want in one unique connection,
  21846. especially if you use temporary tables. Here are two possible ways:
  21847.  
  21848.      shell> mysqlbinlog hostname-bin.001 hostname-bin.002 | mysql
  21849.  
  21850.      shell> mysqlbinlog hostname-bin.001 >  /tmp/queries.sql
  21851.      shell> mysqlbinlog hostname-bin.002 >> /tmp/queries.sql
  21852.      shell> mysql -e "source /tmp/queries.sql"
  21853.  
  21854. Starting from MySQL 4.0.14, `mysqlbinlog' can prepare suitable input
  21855. for `mysql' to execute a `LOAD DATA INFILE' from a binlog. As the binlog
  21856. contains the data to load (this is true for MySQL 4.0; MySQL 3.23 did
  21857. not write the loaded data into the binlog, so the original file was
  21858. needed when one wanted to execute the content of the binlog),
  21859. `mysqlbinlog' will copy this data to a temporary file and print a `LOAD
  21860. DATA INFILE' command for `mysql' to load this temporary file. The
  21861. location where the temporary file is created is by default the
  21862. temporary directory; it can be changed with the `local-load' option of
  21863. `mysqlbinlog'.
  21864.  
  21865. You can also use `mysqlbinlog' to read the binary log directly from a
  21866. remote MySQL server.
  21867.  
  21868. `mysqlbinlog --help' will give you more information.
  21869.  
  21870. Using `mysqlcheck' for Table Maintenance and Crash Recovery
  21871. -----------------------------------------------------------
  21872.  
  21873. Since MySQL version 3.23.38 you will be able to use a new checking and
  21874. repairing tool for `MyISAM' tables. The difference to `myisamchk' is
  21875. that `mysqlcheck' should be used when the `mysqld' server is running,
  21876. whereas `myisamchk' should be used when it is not. The benefit is that
  21877. you no longer have to take the server down for checking or repairing
  21878. your tables.
  21879.  
  21880. `mysqlcheck' uses MySQL server commands `CHECK', `REPAIR', `ANALYZE'
  21881. and `OPTIMIZE' in a convenient way for the user.
  21882.  
  21883. There are three alternative ways to invoke `mysqlcheck':
  21884.  
  21885.      shell> mysqlcheck [OPTIONS] database [tables]
  21886.      shell> mysqlcheck [OPTIONS] --databases DB1 [DB2 DB3...]
  21887.      shell> mysqlcheck [OPTIONS] --all-databases
  21888.  
  21889. So it can be used in a similar way as `mysqldump' when it comes to what
  21890. databases and tables you want to choose.
  21891.  
  21892. `mysqlcheck' does have a special feature compared to the other clients;
  21893. the default behaviour, checking tables (-c), can be changed by renaming
  21894. the binary. So if you want to have a tool that repairs tables by
  21895. default, you should just copy `mysqlcheck' to your harddrive with a new
  21896. name, `mysqlrepair', or alternatively make a symbolic link to
  21897. `mysqlrepair' and name the symbolic link as `mysqlrepair'. If you
  21898. invoke `mysqlrepair' now, it will repair tables by default.
  21899.  
  21900. The names that you can use to change `mysqlcheck' default behaviour are
  21901. here:
  21902.  
  21903.      mysqlrepair:   The default option will be -r
  21904.      mysqlanalyze:  The default option will be -a
  21905.      mysqloptimize: The default option will be -o
  21906.  
  21907. The options available for `mysqlcheck' are listed here, please check
  21908. what your version supports with `mysqlcheck --help'.
  21909.  
  21910. `-A, --all-databases'
  21911.      Check all the databases. This will be same as -databases with all
  21912.      databases selected
  21913.  
  21914. `-1, --all-in-1'
  21915.      Instead of making one query for each table, execute all queries in
  21916.      1 query separately for each database. Table names will be in a
  21917.      comma separated list.
  21918.  
  21919. `-a, --analyze'
  21920.      Analyse given tables.
  21921.  
  21922. `--auto-repair'
  21923.      If a checked table is corrupted, automatically fix it. Repairing
  21924.      will be done after all tables have been checked, if corrupted ones
  21925.      were found.
  21926.  
  21927. `-#, --debug=...'
  21928.      Output debug log. Often this is 'd:t:o,filename'
  21929.  
  21930. `--character-sets-dir=...'
  21931.      Directory where character sets are
  21932.  
  21933. `-c, --check'
  21934.      Check table for errors
  21935.  
  21936. `-C, --check-only-changed'
  21937.      Check only tables that have changed since last check or haven't
  21938.      been closed properly.
  21939.  
  21940. `--compress'
  21941.      Use compression in server/client protocol.
  21942.  
  21943. `-?, --help'
  21944.      Display this help message and exit.
  21945.  
  21946. `-B, --databases'
  21947.      To check several databases. Note the difference in usage; in this
  21948.      case no tables are given. All name arguments are regarded as
  21949.      database names.
  21950.  
  21951. `--default-character-set=...'
  21952.      Set the default character set
  21953.  
  21954. `-F, --fast'
  21955.      Check only tables that hasn't been closed properly
  21956.  
  21957. `-f, --force'
  21958.      Continue even if we get an sql-error.
  21959.  
  21960. `-e, --extended'
  21961.      If you are using this option with CHECK TABLE, it will ensure that
  21962.      the table is 100 percent consistent, but will take a long time.
  21963.  
  21964.      If you are using this option with REPAIR TABLE, it will run an
  21965.      extended repair on the table, which may not only take a long time
  21966.      to execute, but may produce a lot of garbage rows also!
  21967.  
  21968. `-h, --host=...'
  21969.      Connect to host.
  21970.  
  21971. `-m, --medium-check'
  21972.      Faster than extended-check, but only finds 99.99 percent of all
  21973.      errors. Should be good enough for most cases.
  21974.  
  21975. `-o, --optimize'
  21976.      Optimise table
  21977.  
  21978. `-p, --password[=...]'
  21979.      Password to use when connecting to server. If password is not given
  21980.      it's solicited on the tty.
  21981.  
  21982. `-P, --port=...'
  21983.      Port number to use for TCP/IP connections.
  21984.  
  21985. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  21986.      To specify the connect protocol to use.  New in MySQL 4.1.
  21987.  
  21988. `-q, --quick'
  21989.      If you are using this option with CHECK TABLE, it prevents the
  21990.      check from scanning the rows to check for wrong links. This is the
  21991.      fastest check.
  21992.  
  21993.      If you are using this option with REPAIR TABLE, it will try to
  21994.      repair only the index tree. This is the fastest repair method for
  21995.      a table.
  21996.  
  21997. `-r, --repair'
  21998.      Can fix almost anything except unique keys that aren't unique.
  21999.  
  22000. `-s, --silent'
  22001.      Print only error messages.
  22002.  
  22003. `-S, --socket=...'
  22004.      Socket file to use for connection.
  22005.  
  22006. `--tables'
  22007.      Overrides option -databases (-B).
  22008.  
  22009. `-u, --user=#'
  22010.      User for login if not current user.
  22011.  
  22012. `-v, --verbose'
  22013.      Print information about the various stages.
  22014.  
  22015. `-V, --version'
  22016.      Output version information and exit.
  22017.  
  22018. `mysqldump', Dumping Table Structure and Data
  22019. ---------------------------------------------
  22020.  
  22021. Utility to dump a database or a collection of database for backup or for
  22022. transferring the data to another SQL server (not necessarily a MySQL
  22023. server).  The dump will contain SQL statements to create the table
  22024. and/or populate the table.
  22025.  
  22026. If you are doing a backup on the server, you should consider using the
  22027. `mysqlhotcopy' instead. *Note `mysqlhotcopy': mysqlhotcopy.
  22028.  
  22029.      shell> mysqldump [OPTIONS] database [tables]
  22030.      OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
  22031.      OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
  22032.  
  22033. If you don't give any tables or use the `--databases' or
  22034. `--all-databases', the whole database(s) will be dumped.
  22035.  
  22036. You can get a list of the options your version of `mysqldump' supports
  22037. by executing `mysqldump --help'.
  22038.  
  22039. Note that if you run `mysqldump' without `--quick' or `--opt',
  22040. `mysqldump' will load the whole result set into memory before dumping
  22041. the result.  This will probably be a problem if you are dumping a big
  22042. database.
  22043.  
  22044. Note that if you are using a new copy of the `mysqldump' program and
  22045. you are going to do a dump that will be read into a very old MySQL
  22046. server, you should not use the `--opt' or `-e' options.
  22047.  
  22048. `mysqldump' supports the following options:
  22049.  
  22050. `--add-locks'
  22051.      Add `LOCK TABLES' before and `UNLOCK TABLE' after each table dump.
  22052.      (To get faster inserts into MySQL.)
  22053.  
  22054. `--add-drop-table'
  22055.      Add a `drop table' before each create statement.
  22056.  
  22057. `-A, --all-databases'
  22058.      Dump all the databases. This will be same as `--databases' with all
  22059.      databases selected.
  22060.  
  22061. `-a, --all'
  22062.      Include all MySQL-specific create options.
  22063.  
  22064. `--allow-keywords'
  22065.      Allow creation of column names that are keywords.  This works by
  22066.      prefixing each column name with the table name.
  22067.  
  22068. `-c, --complete-insert'
  22069.      Use complete insert statements (with column names).
  22070.  
  22071. `-C, --compress'
  22072.      Compress all information between the client and the server if both
  22073.      support compression.
  22074.  
  22075. `-B, --databases'
  22076.      To dump several databases. Note the difference in usage. In this
  22077.      case no tables are given. All name arguments are regarded as
  22078.      database names.  `USE db_name;' will be included in the output
  22079.      before each new database.
  22080.  
  22081. `--delayed'
  22082.      Insert rows with the `INSERT DELAYED' command.
  22083.  
  22084. `-e, --extended-insert'
  22085.      Use the new multiline `INSERT' syntax. (Gives more compact and
  22086.      faster inserts statements.)
  22087.  
  22088. `-#, --debug[=option_string]'
  22089.      Trace usage of the program (for debugging).
  22090.  
  22091. `--help'
  22092.      Display a help message and exit.
  22093.  
  22094. `--fields-terminated-by=...'
  22095. `--fields-enclosed-by=...'
  22096. `--fields-optionally-enclosed-by=...'
  22097. `--fields-escaped-by=...'
  22098. `--lines-terminated-by=...'
  22099.      These options are used with the `-T' option and have the same
  22100.      meaning as the corresponding clauses for `LOAD DATA INFILE'.
  22101.      *Note `LOAD DATA': LOAD DATA.
  22102.  
  22103. `-F, --flush-logs'
  22104.      Flush log file in the MySQL server before starting the dump.
  22105.  
  22106. `-f, --force,'
  22107.      Continue even if we get an SQL error during a table dump.
  22108.  
  22109. `-h, --host=..'
  22110.      Dump data from the MySQL server on the named host. The default host
  22111.      is `localhost'.
  22112.  
  22113. `-l, --lock-tables.'
  22114.      Lock all tables before starting the dump.  The tables are locked
  22115.      with `READ LOCAL' to allow concurrent inserts in the case of
  22116.      `MyISAM' tables.
  22117.  
  22118.      Please note that when dumping multiple databases, `--lock-tables'
  22119.      will lock tables for each database separately. So using this
  22120.      option will not guarantee your tables will be logically consistent
  22121.      between databases.  Tables in different databases may be dumped in
  22122.      completely different states.
  22123.  
  22124. `-K, --disable-keys'
  22125.      `/*!40000 ALTER TABLE tb_name DISABLE KEYS */;' and `/*!40000
  22126.      ALTER TABLE tb_name ENABLE KEYS */;' will be put in the output.
  22127.      This will make loading the data into a MySQL 4.0 server faster as
  22128.      the indexes are created after all data are inserted.
  22129.  
  22130. `-n, --no-create-db'
  22131.      `CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be
  22132.      put in the output. The above line will be added otherwise, if a
  22133.      `--databases' or `--all-databases' option was given.
  22134.  
  22135. `-t, --no-create-info'
  22136.      Don't write table creation information (the `CREATE TABLE'
  22137.      statement).
  22138.  
  22139. `-d, --no-data'
  22140.      Don't write any row information for the table.  This is very
  22141.      useful if you just want to get a dump of the structure for a table!
  22142.  
  22143. `--opt'
  22144.      Same as `--quick --add-drop-table --add-locks --extended-insert
  22145.      --lock-tables'.  Should give you the fastest possible dump for
  22146.      reading into a MySQL server.
  22147.  
  22148. `-pyour_pass, --password[=your_pass]'
  22149.      The password to use when connecting to the server. If you specify
  22150.      no `=your_pass' part, `mysqldump' you will be prompted for a
  22151.      password.
  22152.  
  22153. `-P, --port=...'
  22154.      Port number to use for TCP/IP connections.
  22155.  
  22156. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22157.      To specify the connect protocol to use.  New in MySQL 4.1.
  22158.  
  22159. `-q, --quick'
  22160.      Don't buffer query, dump directly to stdout. Uses
  22161.      `mysql_use_result()' to do this.
  22162.  
  22163. `-Q, --quote-names'
  22164.      Quote table and column names within ``' characters.
  22165.  
  22166. `-r, --result-file=...'
  22167.      Direct output to a given file. This option should be used in MSDOS,
  22168.      because it prevents new line `\n' from being converted to `\n\r'
  22169.      (new line + carriage return).
  22170.  
  22171. `--single-transaction'
  22172.      This option issues a `BEGIN' SQL command before dumping data from
  22173.      server. It is mostly useful with `InnoDB' tables and
  22174.      `READ_COMMITTED' transaction isolation level, as in this mode it
  22175.      will dump the consistent state of the database at the time then
  22176.      `BEGIN' was issued without blocking any applications.
  22177.  
  22178.      When using this option you should keep in mind that only
  22179.      transactional tables will be dumped in a consistent state, for
  22180.      example, any `MyISAM' or `HEAP' tables dumped while using this
  22181.      option may still change state.
  22182.  
  22183.      The `--single-transaction' option was added in version 4.0.2.
  22184.      This option is mutually exclusive with the `--lock-tables' option
  22185.      as `LOCK TABLES' already commits a previous transaction internally.
  22186.  
  22187. `-S /path/to/socket, --socket=/path/to/socket'
  22188.      The socket file to use when connecting to `localhost' (which is the
  22189.      default host).
  22190.  
  22191. `--tables'
  22192.      Overrides option -databases (-B).
  22193.  
  22194. `-T, --tab=path-to-some-directory'
  22195.      Creates a `table_name.sql' file, that contains the SQL CREATE
  22196.      commands, and a `table_name.txt' file, that contains the data, for
  22197.      each give table.  The format of the `.txt' file is made according
  22198.      to the `--fields-xxx' and `--lines--xxx' options.  *Note*: This
  22199.      option only works if `mysqldump' is run on the same machine as the
  22200.      `mysqld' daemon. You must use a MySQL account that has the `FILE'
  22201.      privilege, and the login user/group that `mysqld' is running as
  22202.      (normally user `mysql', group `mysql') must have permission to
  22203.      create/write a file at the location you specify.
  22204.  
  22205. `-u user_name, --user=user_name'
  22206.      The MySQL user name to use when connecting to the server. The
  22207.      default value is your Unix login name.
  22208.  
  22209. `-O var=option, --set-variable var=option'
  22210.      Set the value of a variable.  The possible variables are listed
  22211.      below.  Please note that `--set-variable' is deprecated since
  22212.      MySQL 4.0, just use `--var=option' on its own.
  22213.  
  22214. `-v, --verbose'
  22215.      Verbose mode.  Print out more information on what the program does.
  22216.  
  22217. `-V, --version'
  22218.      Print version information and exit.
  22219.  
  22220. `-w, --where='where-condition''
  22221.      Dump only selected records. Note that quotes are mandatory:
  22222.           "--where=user='jimf'" "-wuserid>1" "-wuserid<1"
  22223.  
  22224. `-X, --xml'
  22225.      Dumps a database as well formed XML
  22226.  
  22227. `-x, --first-slave'
  22228.      Locks all tables across all databases.
  22229.  
  22230. `--master-data'
  22231.      Like `--first-slave', but also prints some `CHANGE MASTER TO'
  22232.      commands which will later make your slave start from the right
  22233.      position in the master's binlogs, if you have set up your slave
  22234.      using this SQL dump of the master.
  22235.  
  22236. `-O net_buffer_length=#, where # < 16M'
  22237.      When creating multi-row-insert statements (as with option
  22238.      `--extended-insert' or `--opt'), `mysqldump' will create rows up
  22239.      to `net_buffer_length' length. If you increase this variable, you
  22240.      should also ensure that the `max_allowed_packet' variable in the
  22241.      MySQL server is bigger than the `net_buffer_length'.
  22242.  
  22243. The most normal use of `mysqldump' is probably for making a backup of
  22244. whole databases. *Note Backup::.
  22245.  
  22246.      mysqldump --opt database > backup-file.sql
  22247.  
  22248. You can read this back into MySQL with:
  22249.  
  22250.      mysql database < backup-file.sql
  22251.  
  22252. or
  22253.  
  22254.      mysql -e "source /patch-to-backup/backup-file.sql" database
  22255.  
  22256. However, it's also very useful to populate another MySQL server with
  22257. information from a database:
  22258.  
  22259.      mysqldump --opt database | mysql ---host=remote-host -C database
  22260.  
  22261. It is possible to dump several databases with one command:
  22262.  
  22263.      mysqldump --databases database1 [database2 ...] > my_databases.sql
  22264.  
  22265. If all the databases are wanted, one can use:
  22266.  
  22267.      mysqldump --all-databases > all_databases.sql
  22268.  
  22269. `mysqlhotcopy', Copying MySQL Databases and Tables
  22270. --------------------------------------------------
  22271.  
  22272. `mysqlhotcopy' is a Perl script that uses `LOCK TABLES', `FLUSH TABLES'
  22273. and `cp' or `scp' to quickly make a backup of a database.  It's the
  22274. fastest way to make a backup of the database or single tables, but it
  22275. can only be run on the same machine where the database directories are.
  22276. `mysqlhotcopy' works only on Unix, and it works only for `MyISAM' and
  22277. `ISAM' tables.
  22278.  
  22279.      mysqlhotcopy db_name [/path/to/new_directory]
  22280.      
  22281.      mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
  22282.      
  22283.      mysqlhotcopy db_name./regex/
  22284.  
  22285. `mysqlhotcopy' supports the following options:
  22286.  
  22287. `-?, --help'
  22288.      Display a help screen and exit
  22289.  
  22290. `-u, --user=#'
  22291.      User for database login
  22292.  
  22293. `-p, --password=#'
  22294.      Password to use when connecting to server
  22295.  
  22296. `-P, --port=#'
  22297.      Port to use when connecting to local server
  22298.  
  22299. `-S, --socket=#'
  22300.      Socket to use when connecting to local server
  22301.  
  22302. `--allowold'
  22303.      Don't abort if target already exists (rename it _old)
  22304.  
  22305. `--keepold'
  22306.      Don't delete previous (now renamed) target when done
  22307.  
  22308. `--noindices'
  22309.      Don't include full index files in copy to make the backup smaller
  22310.      and faster The indexes can later be reconstructed with `myisamchk
  22311.      -rq.'.
  22312.  
  22313. `--method=#'
  22314.      Method for copy (`cp' or `scp').
  22315.  
  22316. `-q, --quiet'
  22317.      Be silent except for errors
  22318.  
  22319. `--debug'
  22320.      Enable debug
  22321.  
  22322. `-n, --dryrun'
  22323.      Report actions without doing them
  22324.  
  22325. `--regexp=#'
  22326.      Copy all databases with names matching regexp
  22327.  
  22328. `--suffix=#'
  22329.      Suffix for names of copied databases
  22330.  
  22331. `--checkpoint=#'
  22332.      Insert checkpoint entry into specified db.table
  22333.  
  22334. `--flushlog'
  22335.      Flush logs once all tables are locked.
  22336.  
  22337. `--tmpdir=#'
  22338.      Temporary directory (instead of /tmp).
  22339.  
  22340. You can use `perldoc mysqlhotcopy' to get more complete documentation
  22341. for `mysqlhotcopy'.
  22342.  
  22343. `mysqlhotcopy' reads the groups `[client]' and  `[mysqlhotcopy]' from
  22344. the option files.
  22345.  
  22346. To be able to execute `mysqlhotcopy' you need write access to the
  22347. backup directory, the `SELECT' privilege for the tables you are about to
  22348. copy and the MySQL `RELOAD' privilege (to be able to execute `FLUSH
  22349. TABLES').
  22350.  
  22351. `mysqlimport', Importing Data from Text Files
  22352. ---------------------------------------------
  22353.  
  22354. `mysqlimport' provides a command-line interface to the `LOAD DATA
  22355. INFILE' SQL statement.  Most options to `mysqlimport' correspond
  22356. directly to the same options to `LOAD DATA INFILE'.  *Note `LOAD DATA':
  22357. LOAD DATA.
  22358.  
  22359. `mysqlimport' is invoked like this:
  22360.  
  22361.      shell> mysqlimport [options] database textfile1 [textfile2 ...]
  22362.  
  22363. For each text file named on the command-line, `mysqlimport' strips any
  22364. extension from the filename and uses the result to determine which
  22365. table to import the file's contents into.  For example, files named
  22366. `patient.txt', `patient.text', and `patient' would all be imported into
  22367. a table named `patient'.
  22368.  
  22369. `mysqlimport' supports the following options:
  22370.  
  22371. `-c, --columns=...'
  22372.      This option takes a comma-separated list of field names as an
  22373.      argument.  The field list is used to create a proper `LOAD DATA
  22374.      INFILE' command, which is then passed to MySQL. *Note `LOAD DATA':
  22375.      LOAD DATA.
  22376.  
  22377. `-C, --compress'
  22378.      Compress all information between the client and the server if both
  22379.      support compression.
  22380.  
  22381. `-#, --debug[=option_string]'
  22382.      Trace usage of the program (for debugging).
  22383.  
  22384. `-d, --delete'
  22385.      Empty the table before importing the text file.
  22386.  
  22387. `--fields-terminated-by=...'
  22388. `--fields-enclosed-by=...'
  22389. `--fields-optionally-enclosed-by=...'
  22390. `--fields-escaped-by=...'
  22391. `--lines-terminated-by=...'
  22392.      These options have the same meaning as the corresponding clauses
  22393.      for `LOAD DATA INFILE'. *Note `LOAD DATA': LOAD DATA.
  22394.  
  22395. `-f, --force'
  22396.      Ignore errors.  For example, if a table for a text file doesn't
  22397.      exist, continue processing any remaining files.  Without `--force',
  22398.      `mysqlimport' exits if a table doesn't exist.
  22399.  
  22400. `--help'
  22401.      Display a help message and exit.
  22402.  
  22403. `-h host_name, --host=host_name'
  22404.      Import data to the MySQL server on the named host. The default host
  22405.      is `localhost'.
  22406.  
  22407. `-i, --ignore'
  22408.      See the description for the `--replace' option.
  22409.  
  22410. `--ignore-lines=n'
  22411.      Ignore first `n' lines of the datafile.
  22412.  
  22413. `-l, --lock-tables'
  22414.      Lock *all* tables for writing before processing any text files.
  22415.      This ensures that all tables are synchronised on the server.
  22416.  
  22417. `-L, --local'
  22418.      Read input files from the client.  By default, text files are
  22419.      assumed to be on the server if you connect to `localhost' (which
  22420.      is the default host).
  22421.  
  22422. `-pyour_pass, --password[=your_pass]'
  22423.      The password to use when connecting to the server. If you specify
  22424.      no `=your_pass' part, `mysqlimport' you will be prompted for a
  22425.      password.
  22426.  
  22427. `-P port_num, --port=port_num'
  22428.      TCP/IP port number to use for connection.
  22429.  
  22430. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22431.      To specify the connect protocol to use.  New in MySQL 4.1.
  22432.  
  22433. `-r, --replace'
  22434.      The `--replace' and `--ignore' options control handling of input
  22435.      records that duplicate existing records on unique key values.  If
  22436.      you specify `--replace', new rows replace existing rows that have
  22437.      the same unique key value. If you specify `--ignore', input rows
  22438.      that duplicate an existing row on a unique key value are skipped.
  22439.      If you don't specify either option, an error occurs when a
  22440.      duplicate key value is found, and the rest of the text file is
  22441.      ignored.
  22442.  
  22443. `-s, --silent'
  22444.      Silent mode.  Write output only when errors occur.
  22445.  
  22446. `-S /path/to/socket, --socket=/path/to/socket'
  22447.      The socket file to use when connecting to `localhost' (which is the
  22448.      default host).
  22449.  
  22450. `-u user_name, --user=user_name'
  22451.      The MySQL user name to use when connecting to the server. The
  22452.      default value is your Unix login name.
  22453.  
  22454. `-v, --verbose'
  22455.      Verbose mode.  Print out more information what the program does.
  22456.  
  22457. `-V, --version'
  22458.      Print version information and exit.
  22459.  
  22460. Here is a sample run using `mysqlimport':
  22461.  
  22462.      $ mysql --version
  22463.      mysql  Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686)
  22464.      $ uname -a
  22465.      Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown
  22466.      $ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
  22467.      $ ed
  22468.      a
  22469.      100     Max Sydow
  22470.      101     Count Dracula
  22471.      .
  22472.      w imptest.txt
  22473.      32
  22474.      q
  22475.      $ od -c imptest.txt
  22476.      0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
  22477.      0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
  22478.      0000040
  22479.      $ mysqlimport --local test imptest.txt
  22480.      test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
  22481.      $ mysql -e 'SELECT * FROM imptest' test
  22482.      +------+---------------+
  22483.      | id   | n             |
  22484.      +------+---------------+
  22485.      |  100 | Max Sydow     |
  22486.      |  101 | Count Dracula |
  22487.      +------+---------------+
  22488.  
  22489. `mysqlshow', Showing Databases, Tables, and Columns
  22490. ---------------------------------------------------
  22491.  
  22492. `mysqlshow' can be used to quickly look at which databases exist, their
  22493. tables, and the table's columns.
  22494.  
  22495. With the `mysql' program you can get the same information with the
  22496. `SHOW' commands.  *Note SHOW::.
  22497.  
  22498. `mysqlshow' is invoked like this:
  22499.  
  22500.      shell> mysqlshow [OPTIONS] [database [table [column]]]
  22501.  
  22502.    * If no database is given, all matching databases are shown.
  22503.  
  22504.    * If no table is given, all matching tables in the database are
  22505.      shown.
  22506.  
  22507.    * If no column is given, all matching columns and column types in
  22508.      the table are shown.
  22509.  
  22510. Note that in newer MySQL versions, you only see those
  22511. database/tables/columns for which you have some privileges.
  22512.  
  22513. If the last argument contains a shell or SQL wildcard (`*', `?', `%' or
  22514. `_') then only what's matched by the wildcard is shown.  If a database
  22515. contains underscore(s), those should be escaped with backslash (some
  22516. Unix shells will require two), in order to get tables / columns
  22517. properly. '*' are converted into SQL '%' wildcard and '?' into SQL '_'
  22518. wildcard.  This may cause some confusion when you try to display the
  22519. columns for a table with a `_' as in this case `mysqlshow' only shows
  22520. you the table names that match the pattern.  This is easily fixed by
  22521. adding an extra `%' last on the command-line (as a separate argument).
  22522.  
  22523. `mysql_config', Get compile options for compiling clients
  22524. ---------------------------------------------------------
  22525.  
  22526. `mysql_config' provides you with useful information how to compile your
  22527. MySQL client and connect it to MySQL.
  22528.  
  22529. `mysql_config' supports the following options:
  22530.  
  22531. `--cflags'
  22532.      Compiler flags to find include files
  22533.  
  22534. `--libs'
  22535.      Libs and options required to link with the MySQL client library.
  22536.  
  22537. `--socket'
  22538.      The default socket name, defined when configuring MySQL.
  22539.  
  22540. `--port'
  22541.      The default port number, defined when configuring MySQL.
  22542.  
  22543. `--version'
  22544.      Version number and version for the MySQL distribution
  22545.  
  22546. `--libmysqld-libs'
  22547.      Libs and options required to link with the MySQL embedded server.
  22548.  
  22549. If you execute `mysql_config' without any options it will print all
  22550. options it supports plus the value of all options:
  22551.  
  22552.      shell> mysql_config
  22553.      sage: /usr/local/mysql/bin/mysql_config [OPTIONS]
  22554.      Options:
  22555.              --cflags         [-I'/usr/local/mysql/include/mysql']
  22556.              --libs           [-L'/usr/local/mysql/lib/mysql' -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto]
  22557.              --socket         [/tmp/mysql.sock]
  22558.              --port           [3306]
  22559.              --version        [4.0.8-gamma]
  22560.              --libmysqld-libs [ -L'/usr/local/mysql/lib/mysql' -lmysqld -lpthread -lz -lcrypt -lnsl -lm  -lpthread  -lrt]
  22561.  
  22562. You can use this to compile a MySQL client by as follows:
  22563.  
  22564.      CFG=/usr/local/mysql/bin/mysql_config
  22565.      sh -c "gcc -o progname `$CFG --cflags` progname.c `$CFG --libs`"
  22566.  
  22567. `perror', Explaining Error Codes
  22568. --------------------------------
  22569.  
  22570. For most system errors MySQL will, in addition to a internal text
  22571. message, also print the system error code in one of the following
  22572. styles: `message ... (errno: #)' or `message ... (Errcode: #)'.
  22573.  
  22574. You can find out what the error code means by either examining the
  22575. documentation for your system or use the `perror' utility.
  22576.  
  22577. `perror' prints a description for a system error code, or an MyISAM/ISAM
  22578. storage engine (table handler) error code.
  22579.  
  22580. `perror' is invoked like this:
  22581.  
  22582.      shell> perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  22583.      
  22584.      Example:
  22585.      
  22586.      shell> perror 13 64
  22587.      Error code  13:  Permission denied
  22588.      Error code  64:  Machine is not on the network
  22589.  
  22590. Note that the error messages are mostly system dependent!
  22591.  
  22592. How to Run SQL Commands from a Text File
  22593. ----------------------------------------
  22594.  
  22595. The `mysql' client typically is used interactively, like this:
  22596.  
  22597.      shell> mysql database
  22598.  
  22599. However, it's also possible to put your SQL commands in a file and tell
  22600. `mysql' to read its input from that file.  To do so, create a text file
  22601. `text_file' that contains the commands you wish to execute.  Then
  22602. invoke `mysql' as shown here:
  22603.  
  22604.      shell> mysql database < text_file
  22605.  
  22606. You can also start your text file with a `USE db_name' statement.  In
  22607. this case, it is unnecessary to specify the database name on the command
  22608. line:
  22609.  
  22610.      shell> mysql < text_file
  22611.  
  22612. If you are already running `mysql', you can execute an SQL script file
  22613. using the `source' command:
  22614.  
  22615.      mysql> source filename;
  22616.  
  22617. For more information about batch mode, *Note Batch mode::.
  22618.  
  22619. The MySQL Log Files
  22620. ===================
  22621.  
  22622. MySQL has several different log files that can help you find out what's
  22623. going on inside `mysqld':
  22624.  
  22625. *Log file*     *Description*
  22626. The error log  Problems encountering starting, running or stopping
  22627.                `mysqld'.
  22628. The isam log   Logs all changes to the ISAM tables. Used only for
  22629.                debugging the isam code.
  22630. The query log  Established connections and executed queries.
  22631. The update     Deprecated: Stores all statements that changes data
  22632. log            
  22633. The binary     Stores all statements that changes something. Used also
  22634. log            for replication
  22635. The slow log   Stores all queries that took more than `long_query_time'
  22636.                seconds to execute or didn't use indexes.
  22637.  
  22638. All logs can be found in the `mysqld' data directory.  You can force
  22639. `mysqld' to reopen the log files (or in some cases switch to a new log)
  22640. by executing `FLUSH LOGS'. *Note FLUSH::.
  22641.  
  22642. The Error Log
  22643. -------------
  22644.  
  22645. The error log file contains information indicating when `mysqld' was
  22646. started and stopped and also any critical errors found when running.
  22647.  
  22648. If `mysqld' dies unexpectedly and `mysqld_safe' needs to restart
  22649. `mysqld', `mysqld_safe' will write a `restarted mysqld' row in this
  22650. file.  This log also holds a warning if `mysqld' notices a table that
  22651. needs to be automatically checked or repaired.
  22652.  
  22653. On some operating systems, the error log will contain a stack trace for
  22654. where `mysqld' died. This can be used to find out where `mysqld' died.
  22655. *Note Using stack trace::.
  22656.  
  22657. Beginning with MySQL 4.0.10 you can specify where `mysqld' stores the
  22658. error log file with the option `--log-error[=filename]'. If no file
  22659. name is given `mysqld' will use `mysql-data-dir/'hostname'.err' on Unix
  22660. and `\mysql\data\mysql.err' on Windows.  If you execute `flush logs'
  22661. the old file will be prefixed with `--old' and `mysqld' will create a
  22662. new empty log file.
  22663.  
  22664. In older MySQL versions the error log handling was done by
  22665. `mysqld_safe' which redirected the error file to `'hostname'.err'.  One
  22666. could change this file name with the option `--err-log=filename'.
  22667.  
  22668. If you don't specify `--log-error' or if you use the `--console' option
  22669. the errors will be written to stderr (the terminal).
  22670.  
  22671. On Windows, the output is always written to the `.err' file if
  22672. `--console' is not given.
  22673.  
  22674. The General Query Log
  22675. ---------------------
  22676.  
  22677. If you want to know what happens within `mysqld', you should start it
  22678. with `--log[=file]'.  This will log all connections and queries to the
  22679. log file (by default named `'hostname'.log').  This log can be very
  22680. useful when you suspect an error in a client and want to know exactly
  22681. what `mysqld' thought the client sent to it.
  22682.  
  22683. Older versions of the `mysql.server' script (from MySQL 3.23.4 to
  22684. 3.23.8) pass `safe_mysqld' a `--log' option (enable general query log).
  22685. If you need better performance when you start using MySQL in a
  22686. production environment, you can remove the `--log' option from
  22687. `mysql.server' or change it to `--log-bin'. *Note Binary log::.
  22688.  
  22689. The entries in this log are written as `mysqld' receives the questions.
  22690. This may be different from the order in which the statements are
  22691. executed.  This is in contrast to the update log and the binary log
  22692. which are written after the query is executed, but before any locks are
  22693. released.
  22694.  
  22695. The Update Log
  22696. --------------
  22697.  
  22698. *Note*: the update log is replaced by the binary log. *Note Binary
  22699. log::.  With this you can do anything that you can do with the update
  22700. log. *The update log will be removed in MySQL 5.0*.
  22701.  
  22702. When started with the `--log-update[=file_name]' option, `mysqld'
  22703. writes a log file containing all SQL commands that update data. If no
  22704. filename is given, it defaults to the name of the host machine. If a
  22705. filename is given, but it doesn't contain a path, the file is written
  22706. in the data directory. If `file_name' doesn't have an extension,
  22707. `mysqld' will create log file names like so: `file_name.###', where
  22708. `###' is a number that is incremented each time you execute `mysqladmin
  22709. refresh', execute `mysqladmin flush-logs', execute the `FLUSH LOGS'
  22710. statement, or restart the server.
  22711.  
  22712. *Note*: for the above scheme to work, you must not create your own
  22713. files with the same filename as the update log + some extensions that
  22714. may be regarded as a number, in the directory used by the update log!
  22715.  
  22716. If you use the `--log' or `-l' options, `mysqld' writes a general log
  22717. with a filename of `hostname.log', and restarts and refreshes do not
  22718. cause a new log file to be generated (although it is closed and
  22719. reopened). In this case you can copy it (on Unix) by doing:
  22720.  
  22721.      mv hostname.log hostname-old.log
  22722.      mysqladmin flush-logs
  22723.      cp hostname-old.log to-backup-directory
  22724.      rm hostname-old.log
  22725.  
  22726. Update logging is smart because it logs only statements that really
  22727. update data. So an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  22728. rows is not written to the log. It even skips `UPDATE' statements that
  22729. set a column to the value it already has.
  22730.  
  22731. The update logging is done immediately after a query completes but
  22732. before any locks are released or any commit is done. This ensures that
  22733. the log will be logged in the execution order.
  22734.  
  22735. If you want to update a database from update log files, you could do the
  22736. following (assuming your update logs have names of the form
  22737. `file_name.###'):
  22738.  
  22739.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  22740.  
  22741. `ls' is used to get all the log files in the right order.
  22742.  
  22743. This can be useful if you have to revert to backup files after a crash
  22744. and you want to redo the updates that occurred between the time of the
  22745. backup and the crash.
  22746.  
  22747. The Binary Log
  22748. --------------
  22749.  
  22750. The intention is that the binary log should replace the update log, so
  22751. we recommend you to switch to this log format as soon as possible! The
  22752. update log will be removed in MySQL 5.0.
  22753.  
  22754. The binary log contains all information that is available in the update
  22755. log in a more efficient format. It also contains information about how
  22756. long each query took that updated the database.  It doesn't contain
  22757. queries that don't modify any data.  If you want to log all queries
  22758. (for example to find a problem query) you should use the general query
  22759. log. *Note Query log::.
  22760.  
  22761. The binary log is also used when you are replicating a slave from a
  22762. master.  *Note Replication::.
  22763.  
  22764. When started with the `--log-bin[=file_name]' option, `mysqld' writes a
  22765. log file containing all SQL commands that update data. If no file name
  22766. is given, it defaults to the name of the host machine followed by
  22767. `-bin'. If file name is given, but it doesn't contain a path, the file
  22768. is written in the data directory.
  22769.  
  22770. If you supply an extension to `--log-bin=filename.extension', the
  22771. extension will be silenty removed.
  22772.  
  22773. To the binary log filename `mysqld' will append an extension that is a
  22774. number that is incremented each time you execute `mysqladmin refresh',
  22775. execute `mysqladmin flush-logs', execute the `FLUSH LOGS' statement or
  22776. restart the server. A new binary log will also automatically be created
  22777. when the current one's size reaches `max_binlog_size'. Note if you are
  22778. using transactions: a transaction is written in one chunk to the binary
  22779. log, hence it is never split between several binary logs. Therefore, if
  22780. you have big transactions, you may see binlogs bigger than
  22781. `max_binlog_size'.
  22782.  
  22783. You can delete all binary log files with the `RESET MASTER' command
  22784. (*note `RESET': RESET.), or only some of them with `PURGE MASTER LOGS'
  22785. (*note Replication SQL::).
  22786.  
  22787. You can use the following options to `mysqld' to affect what is logged
  22788. to the binary log (please make sure to read the notes which follow this
  22789. table):
  22790.  
  22791. *Option*                    *Description*
  22792. `binlog-do-db=database_name' Tells the master that it should log updates
  22793.                             to the binary log if the current database
  22794.                             (that is, the one selected by `USE')
  22795.                             database is 'database_name'. All others
  22796.                             databases which are not explicitly mentioned
  22797.                             are ignored.  Note that if you use this you
  22798.                             should ensure that you only do updates in
  22799.                             the current database.  (Example:
  22800.                             `binlog-do-db=some_database')
  22801.                             
  22802.                             Example of what does not work as you could
  22803.                             expect it: if the server is started with
  22804.                             `binlog-do-db=sales', and you do `USE
  22805.                             prices; UPDATE sales.january SET
  22806.                             amount=amount+1000;', this query will not be
  22807.                             written into the binary log.
  22808. `binlog-ignore-db=database_name' Tells the master that updates where the
  22809.                             current database (that is, the one selected
  22810.                             by `USE') is 'database_name' should not be
  22811.                             stored in the binary log.  Note that if you
  22812.                             use this you should ensure that you only do
  22813.                             updates in the current database.  (Example:
  22814.                             `binlog-ignore-db=some_database')
  22815.                             
  22816.                             Example of what does not work as you could
  22817.                             expect it: if the server is started with
  22818.                             `binlog-ignore-db=sales', and you do `USE
  22819.                             prices; UPDATE sales.january SET
  22820.                             amount=amount+1000;', this query will be
  22821.                             written into the binary log.
  22822.  
  22823. The rules are evaluated in the following order, to decide if the query
  22824. should be written to the binary log or not:
  22825.   1. Are there `binlog-do-db' or `binlog-ignore-db' rules?
  22826.         * No: write the query to the binlog and exit.
  22827.  
  22828.         * Yes: go to step below.
  22829.  
  22830.   2. So there are some rules (`binlog-do-db' or `binlog-ignore-db' or
  22831.      both). Is there a current database (has any database been selected
  22832.      by `USE'?)?
  22833.         * No: do *NOT* write the query, and exit.
  22834.  
  22835.         * Yes: go to step below.
  22836.  
  22837.   3. There is a current database. Are there some `binlog-do-db' rules?
  22838.         * Yes: Does the current database match any of the `binlog-do-db'
  22839.           rules?
  22840.              * Yes: write the query and exit.
  22841.  
  22842.              * No: do *NOT* write the query, and exit.
  22843.  
  22844.         * No: go to step below.
  22845.  
  22846.   4. There are some `binlog-ignore-db' rules.  Does the current
  22847.      database match any of the `binlog-ignore-db' rules?
  22848.         * Yes: do not write the query, and exit.
  22849.  
  22850.         * No: write the query and exit.
  22851.  
  22852. So for example, a slave running with only `binlog-do-db=sales' will not
  22853. write to the binlog any query whose current database is different from
  22854. `sales' (in other words, `binlog-do-db' can sometimes mean "ignore
  22855. other databases").
  22856.  
  22857. To be able to know which different binary log files have been used,
  22858. `mysqld' will also create a binary log index file that contains the
  22859. name of all used binary log files. By default this has the same name as
  22860. the binary log file, with the extension `'.index''.  You can change the
  22861. name of the binary log index file with the `--log-bin-index=[filename]'
  22862. option.  You should not manually edit this file while `mysqld' is
  22863. running; doing this would confuse `mysqld'.
  22864.  
  22865. If you are using replication, you should not delete old binary log
  22866. files until you are sure that no slave will ever need to use them.  One
  22867. way to do this is to do `mysqladmin flush-logs' once a day and then
  22868. remove any logs that are more than 3 days old. You can remove them
  22869. manually, or preferably using `PURGE MASTER LOGS' (*note Replication
  22870. SQL::) which will also safely update the binary log index file for you
  22871. (and which can take a date argument since MySQL 4.1)
  22872.  
  22873. A connexion with the `SUPER' privilege can disable the binary logging
  22874. of its queries using `SET SQL_LOG_BIN=0'. *Note Replication SQL::.
  22875.  
  22876. You can examine the binary log file with the `mysqlbinlog' utility.
  22877. For example, you can update a MySQL server from the binary log as
  22878. follows:
  22879.  
  22880.      shell> mysqlbinlog log-file | mysql -h server_name
  22881.  
  22882. See *Note mysqlbinlog:: for more information on the `mysqlbinlog'
  22883. utility and how to use it.
  22884.  
  22885. If you are using `BEGIN [WORK]' or `SET AUTOCOMMIT=0', you must use the
  22886. MySQL binary log for backups instead of the old update log, which will
  22887. be removed in MySQL 5.0.
  22888.  
  22889. The binary logging is done immediately after a query completes but
  22890. before any locks are released or any commit is done. This ensures that
  22891. the log will be logged in the execution order.
  22892.  
  22893. Updates to non-transactional tables are stored in the binary log
  22894. immediately after execution.  For transactional tables such as `BDB' or
  22895. `InnoDB' tables, all updates (`UPDATE', `DELETE' or `INSERT') that
  22896. change tables are cached until a `COMMIT' command is sent to the
  22897. server. At this point `mysqld' writes the whole transaction to the
  22898. binary log before the `COMMIT' is executed.  Every thread will, on
  22899. start, allocate a buffer of `binlog_cache_size' to buffer queries.  If
  22900. a query is bigger than this, the thread will open a temporary file to
  22901. store the transaction.  The temporary file will be deleted when the
  22902. thread ends.
  22903.  
  22904. The `max_binlog_cache_size' (default 4G) can be used to restrict the
  22905. total size used to cache a multi-query transaction.  If a transaction is
  22906. bigger than this it will fail and roll back.
  22907.  
  22908. If you are using the update or binary log, concurrent inserts will be
  22909. converted to normal inserts when using `CREATE ... SELECT' or `INSERT
  22910. ... SELECT'.  This is to ensure that you can recreate an exact copy of
  22911. your tables by applying the log on a backup.
  22912.  
  22913. The Slow Query Log
  22914. ------------------
  22915.  
  22916. When started with the `--log-slow-queries[=file_name]' option, `mysqld'
  22917. writes a log file containing all SQL commands that took more than
  22918. `long_query_time' seconds to execute. The time to get the initial table
  22919. locks are not counted as execution time.
  22920.  
  22921. The slow query log is logged after the query is executed and after all
  22922. locks has been released. This may be different from the order in which
  22923. the statements are executed.
  22924.  
  22925. If no file name is given, it defaults to the name of the host machine
  22926. suffixed with `-slow.log'. If a filename is given, but doesn't contain
  22927. a path, the file is written in the data directory.
  22928.  
  22929. The slow query log can be used to find queries that take a long time to
  22930. execute and are thus candidates for optimisation. With a large log, that
  22931. can become a difficult task. You can pipe the slow query log through the
  22932. `mysqldumpslow' command to get a summary of the queries which appear in
  22933. the log.
  22934.  
  22935. You are using `--log-long-format' then also queries that are not using
  22936. indexes are printed. *Note Command-line options::.
  22937.  
  22938. Log File Maintenance
  22939. --------------------
  22940.  
  22941. The MySQL Server can create a number of different log files, which make
  22942. it easy to see what is going on. *Note Log Files::. One must however
  22943. regularly clean up these files, to ensure that the logs don't take up
  22944. too much disk space.
  22945.  
  22946. When using MySQL with log files, you will, from time to time, want to
  22947. remove/backup old log files and tell MySQL to start logging on new
  22948. files.  *Note Backup::.
  22949.  
  22950. On a Linux (`Red Hat') installation, you can use the `mysql-log-rotate'
  22951. script for this. If you installed MySQL from an RPM distribution, the
  22952. script should have been installed automatically.  Note that you should
  22953. be careful with this if you are using the log for replication!
  22954.  
  22955. On other systems you must install a short script yourself that you
  22956. start from `cron' to handle log files.
  22957.  
  22958. You can force MySQL to start using new log files by using `mysqladmin
  22959. flush-logs' or by using the SQL command `FLUSH LOGS'.  If you are using
  22960. MySQL Version 3.21 you must use `mysqladmin refresh'.
  22961.  
  22962. The above command does the following:
  22963.  
  22964.    * If standard logging (`--log') or slow query logging
  22965.      (`--log-slow-queries') is used, closes and reopens the log file
  22966.      (`mysql.log' and ``hostname`-slow.log' as default).
  22967.  
  22968.    * If update logging (`--log-update') is used, closes the update log
  22969.      and opens a new log file with a higher sequence number.
  22970.  
  22971. If you are using only an update log, you only have to flush the logs
  22972. and then move away the old update log files to a backup.  If you are
  22973. using the normal logging, you can do something like:
  22974.  
  22975.      shell> cd mysql-data-directory
  22976.      shell> mv mysql.log mysql.old
  22977.      shell> mysqladmin flush-logs
  22978.  
  22979. and then take a backup and remove `mysql.old'.
  22980.  
  22981. Replication in MySQL
  22982. ====================
  22983.  
  22984. This section describes the various replication features in MySQL.  It
  22985. serves as a reference to the options available with replication.  You
  22986. will be introduced to replication and learn how to implement it.
  22987. Toward the end, there are some frequently asked questions and
  22988. descriptions of problems and how to solve them.
  22989.  
  22990. We suggest that you visit our website at `http://www.mysql.com/' often
  22991. and read updates to this section. Replication is constantly being
  22992. improved, and we update the manual frequently with the most current
  22993. information.
  22994.  
  22995. Introduction
  22996. ------------
  22997.  
  22998. One-way replication can be used is to increase both robustness and
  22999. speed. For robustness you can have two systems and can switch to the
  23000. backup if you have problems with the master. The extra speed is
  23001. achieved by sending a part of the non-updating queries to the replica
  23002. server. Of course this only works if non-updating queries dominate, but
  23003. that is the normal case.
  23004.  
  23005. Starting in Version 3.23.15, MySQL supports one-way replication
  23006. internally. One server acts as the master, while the other acts as the
  23007. slave. Note that one server could play the roles of master in one pair
  23008. and slave in the other. The master server keeps a binary log of updates
  23009. (*note Binary log::) and an index file to binary logs to keep track of
  23010. log rotation.  The slave, upon connecting, informs the master where it
  23011. left off since the last successfully propagated update, catches up on
  23012. the updates, and then blocks and waits for the master to notify it of
  23013. the new updates.
  23014.  
  23015. Note that if you are using replication all updates to the tables you
  23016. replicate should be done through the master, unless you are always
  23017. careful of avoiding conflicts between updates which users issue on the
  23018. master and those which users issue on the slave.
  23019.  
  23020. Another benefit of using replication is that one can get non-disturbing
  23021. backups of the system by doing a backup on a slave instead of doing it
  23022. on the master. *Note Backup::.
  23023.  
  23024. Replication Implementation Overview
  23025. -----------------------------------
  23026.  
  23027. MySQL replication is based on the server keeping track of all changes
  23028. to your database (updates, deletes, etc) in the binary log (*note
  23029. Binary log::) and the slave server(s) reading the saved queries from
  23030. the master server's binary log so that the slave can execute the same
  23031. queries on its copy of the data.
  23032.  
  23033. It is *very important* to realise that the binary log is simply a
  23034. record starting from a fixed point in time (the moment you enable binary
  23035. logging). Any slaves which you set up will need copies of the data from
  23036. your master as it existed the moment that you enabled binary logging on
  23037. the master. If you start your slaves with data that doesn't agree with
  23038. what was on the master *when the binary log was started*, your slaves
  23039. may fail.
  23040.  
  23041. Please see the following table for an indication of master-slave
  23042. compatibility between different versions. With regard to version 4.0,
  23043. we recommend using same version on both sides.
  23044.  
  23045.                     *Master*    *Master**Master**Master*
  23046.                     *3.23.33    *4.0.0* *4.0.1* *4.0.3 and
  23047.                     and up*                     up*
  23048. *Slave* *3.23.33    yes         no      no      no
  23049.         and up*                                 
  23050. *Slave* *4.0.0*     no          yes     no      no
  23051. *Slave* *4.0.1*     yes         no      yes     no
  23052. *Slave* *4.0.3 and  yes         no      no      yes
  23053.         up*                                     
  23054.  
  23055. *Note*: MySQL Version 4.0.2 is not recommended for replication. As a
  23056. general rule, it's always recommended to use recent MySQL versions for
  23057. replication.
  23058.  
  23059. Note that when you upgrade a master from MySQL 3.23 to MySQL 4.0 (or
  23060. 4.1) you should not restart replication using old 3.23 binary logs,
  23061. because this will unfortunately confuse the 4.0 slave. The upgrade can
  23062. be safely done this way:
  23063.    * Block all updates on the master (`FLUSH TABLES WITH READ LOCK').
  23064.  
  23065.    * Wait until all the slaves have caught up all changes from the
  23066.      master (use `SHOW MASTER STATUS' on the master, and `SELECT
  23067.      MASTER_POS_WAIT()' on the slaves). Then run `SLAVE STOP' and
  23068.      `RESET SLAVE' on the slaves.
  23069.  
  23070.    * Shutdown MySQL on the master and slaves, upgrade the master and
  23071.      slaves to MySQL 4.0. Restart the master and slaves, and issue
  23072.      `CHANGE MASTER TO' commands on the slaves, unless the slaves
  23073.      already have the identification of the master in their `my.cnf'
  23074.      files.
  23075.  
  23076. Starting from 4.0.0, one can use `LOAD DATA FROM MASTER' to set up a
  23077. slave. Be aware that `LOAD DATA FROM MASTER' currently works only if
  23078. all the tables on the master are `MyISAM' type, and will acquire a
  23079. global read lock, so no writes are possible while the tables are being
  23080. transferred from the master. When we implement hot lock-free table
  23081. backup (in MySQL 5.0), this global read lock will no longer be
  23082. necessary.
  23083.  
  23084. Due to the above limitation, we recommend that at this point  you use
  23085. `LOAD DATA FROM MASTER' only if the dataset on the master is relatively
  23086. small, or if a prolonged read lock on the master is acceptable. While
  23087. the actual speed of `LOAD DATA FROM MASTER' may vary from system to
  23088. system, a good rule for a rough estimate of how long it is going to
  23089. take is 1 second per 1 MB of the datafile. You will get close to the
  23090. estimate if both master and slave are equivalent to 700 MHz Pentium,
  23091. are connected through 100 MBit/s network, and your index file is about
  23092. half the size of your datafile.  Of course, this is only a rough order
  23093. of magnitude estimate.
  23094.  
  23095. Once a slave is properly configured and running, it will simply connect
  23096. to the master and wait for updates to process. If the master goes away
  23097. or the slave loses connectivity with your master, it will keep trying to
  23098. connect every `master-connect-retry' seconds until it is able to
  23099. reconnect and resume listening for updates.
  23100.  
  23101. Each slave keeps track of where it left off. The master server has no
  23102. knowledge of how many slaves there are or which ones are up-to-date at
  23103. any given time.
  23104.  
  23105. Replication Implementation Details
  23106. ----------------------------------
  23107.  
  23108. Three threads are involved in replication : one on the master and two
  23109. on the slave.  When `START SLAVE' is issued, the I/O thread is created
  23110. on the slave. It connects to the master and asks it to send its
  23111. binlogs. Then one thread (named `Binlog_dump' in `SHOW PROCESSLIST' on
  23112. the master) is created on the master to send these binlogs. The I/O
  23113. thread reads what `Binlog_dump' sends and simply copies it to some local
  23114. files in the slave's data directory called relay logs.  The last
  23115. thread, the SQL thread, is created on the slave; it reads the relay
  23116. logs and executes the queries it contains.
  23117.  
  23118. Here is how the three threads show up in `SHOW PROCESSLIST'.  All `SHOW
  23119. PROCESSLIST' examples are taken from `MySQL' version 4.0.15; the
  23120. content of the `State' column was changed in that version to be more
  23121. meaningful.
  23122.  
  23123.      MASTER> show processlist\G
  23124.      *************************** 1. row ***************************
  23125.           Id: 2
  23126.         User: root
  23127.         Host: localhost:32931
  23128.           db: NULL
  23129.      Command: Binlog Dump
  23130.         Time: 94
  23131.        State: Has sent all binlog to slave; waiting for binlog to be updated
  23132.         Info: NULL
  23133.  
  23134.      SLAVE> show processlist\G
  23135.      *************************** 1. row ***************************
  23136.           Id: 10
  23137.         User: system user
  23138.         Host:
  23139.           db: NULL
  23140.      Command: Connect
  23141.         Time: 11
  23142.        State: Waiting for master to send event
  23143.         Info: NULL
  23144.      *************************** 2. row ***************************
  23145.           Id: 11
  23146.         User: system user
  23147.         Host:
  23148.           db: NULL
  23149.      Command: Connect
  23150.         Time: 11
  23151.        State: Has read all relay log; waiting for the I/O slave thread to update it
  23152.         Info: NULL
  23153.  
  23154. (`MASTER>' and `SLAVE>' prompts were obtained with option `--prompt' of
  23155. `mysql', *note mysql::.)  Here thread 2 is on the master. Thread 10 is
  23156. the I/O thread on the slave.  Thread 11 is the SQL thread on the slave;
  23157. note that the value in the `Time' column can tell how late the slave is
  23158. compared to the master (*note Replication FAQ::).
  23159.  
  23160. With `SHOW PROCESSLIST' you can know what is happening on the master
  23161. and on the slave as regards replication.
  23162.  
  23163. Here are the most common states you will see in the `State' column for
  23164. the `Binlog_dump' thread (if you don't see this thread, then
  23165. replication is not running, for sure):
  23166.  
  23167.    * `Sending binlog event to slave'.  Binlogs are made of events (an
  23168.      event is usually a query plus some information); the thread has
  23169.      read an event from the binlog and is sending it to the slave.
  23170.  
  23171.    * `Finished reading one binlog; switching to next binlog'
  23172.  
  23173.    * `Has sent all binlog to slave; waiting for binlog to be updated'.
  23174.      The thread has read all binary logs and is idle, waiting for
  23175.      connections on this master to write more data into binary logs if
  23176.      they want.
  23177.  
  23178.    * `Waiting to finalize termination'.  Very brief state - the thread
  23179.      is stopping.
  23180.  
  23181. Here are the most common states you will see in the `State' column for
  23182. the I/O thread:
  23183.  
  23184.    * `Connecting to master'.  Now attempting to connect to the master.
  23185.  
  23186.    * `Checking master version'.  Very brief state - happens just after
  23187.      connection is established.
  23188.  
  23189.    * `Registering slave on master'.  Very brief state - happens just
  23190.      after connection is established.
  23191.  
  23192.    * `Requesting binlog dump'.  Very brief state - happens just after
  23193.      connection is established; the thread sends to the master a
  23194.      request to send the content of its binlogs, starting from the
  23195.      requested binlog and position.
  23196.  
  23197.    * `Waiting to reconnect after a failed binlog dump request'.  If the
  23198.      above request failed (disconnection), this is showed while the
  23199.      thread is sleeping for `master-connect-retry' seconds before
  23200.      retrying.
  23201.  
  23202.    * `Reconnecting after a failed binlog dump request'.  Then the
  23203.      thread tries to reconnect to the master.
  23204.  
  23205.    * `Waiting for master to send event'.  The thread is now connected
  23206.      and waiting for binlog events to arrive. This can last for long if
  23207.      the master is idle. This wait will timeout after
  23208.      `slave_read_timeout' seconds, then the connection will be
  23209.      considered broken and reconnection will be attempted.
  23210.  
  23211.    * `Queueing master event to the relay log'.  The thread has read an
  23212.      event and is copying it to the relay log.
  23213.  
  23214.    * `Waiting to reconnect after a failed master event read'.  Got an
  23215.      error while reading (disconnection); sleeping for
  23216.      `master-connect-retry' seconds.
  23217.  
  23218.    * `Reconnecting after a failed master event read'.  Then the thread
  23219.      tries to reconnect. When connection is established again, state
  23220.      will be `Waiting for master to send event' again.
  23221.  
  23222.    * `Waiting for the SQL slave thread to free enough relay log space'.
  23223.      You are using a non-zero `relay_log_space_limit', and the relay
  23224.      log(s) has (have) grown so much that its (their) size exceeds the
  23225.      value of this variable. The (I/O) thread is so waiting until the
  23226.      SQL thread frees enough space by deleting some relay logs.
  23227.  
  23228.    * `Waiting for slave mutex on exit'.  Very brief state - happens
  23229.      when the thread is stopping.
  23230.  
  23231. Here are the most common states you will see in the `State' column for
  23232. the SQL thread:
  23233.  
  23234.    * `Reading event from the relay log'
  23235.  
  23236.    * `the-query-being-executed'.  The thread has read an event from the
  23237.      relay log, extracted the query from it and is executing the query,
  23238.      the `State' column shows this query.
  23239.  
  23240.    * `Has read all relay log; waiting for the I/O slave thread to
  23241.      update it'
  23242.  
  23243.    * `Waiting for slave mutex on exit'.  Very brief state - happens
  23244.      when the thread is stopping.
  23245.  
  23246. Before MySQL 4.0.2, the I/O and SQL threads were one. The advantage
  23247. brought by the two separate threads is that it makes the reading job
  23248. and the execution job independant, thus the reading job is not slowed
  23249. down by the execution job. As soon as the slave starts, even if it has
  23250. not been running for a while, the I/O thread can quickly fetch all the
  23251. binlogs, while the SQL thread lags far behind and may take hours to
  23252. catch. If the slave stops, though it has not executed everything yet,
  23253. at least it has fetched everything, so binlogs can be purged on the
  23254. master, as a safe copy is locally stored on the slave for future use.
  23255.  
  23256. Relay logs are by default named as the hostname followed by
  23257. `-relay-bin' plus a numeric extension. A `-relay-bin.index' file
  23258. contains the list of all relay logs currently in use.  By default these
  23259. files are in the slave's data directory.  Relay logs have the same
  23260. format than binary logs, so they can be read with `mysqlbinlog'.  A
  23261. relay log is automatically deleted by the SQL thread as soon as it no
  23262. longer needs it (that is, as soon as it has executed all its events).
  23263. The user has no command to delete relay logs as the SQL thread does the
  23264. job. However, from MySQL 4.0.14, `FLUSH LOGS' rotates relay logs, which
  23265. will influence deletion by the SQL thread.  A new relay log is created
  23266. when the I/O thread starts, or when the size of the current relay log
  23267. exceeds `max_relay_log_size' (or if this variable is 0 or the slave is
  23268. older than MySQL 4.0.14, when the size exceeds `max_binlog_size'), or
  23269. when `FLUSH LOGS' is issued (from version 4.0.14).
  23270.  
  23271. Replication also creates two small files in the data directory: these
  23272. files are the disk images of the output of `SHOW SLAVE STATUS' (*note
  23273. Replication SQL:: for a description of this command); but as disk
  23274. images they survive slave's shutdown; this way at restart time the slave
  23275. still knows his master and where the slave is in the master's binlogs,
  23276. and where it is in its own relay logs.
  23277.  
  23278.    * `master.info' is updated by the I/O thread.  Here is a
  23279.      correspondance between the file's rows and the columns displayed
  23280.      by `SHOW SLAVE STATUS':
  23281.  
  23282.      *Line#**Description*
  23283.      1   `Master_Log_File'
  23284.      2   `Read_Master_Log_Pos'
  23285.      3   `Master_Host'
  23286.      4   `Master_User'
  23287.      5   Password (not in `SHOW SLAVE STATUS')
  23288.      6   `Master_Port'
  23289.      7   `Connect_Retry'
  23290.  
  23291.    * `relay-log.info' is updated by the SQL thread.  Here is a
  23292.      correspondance between the file's rows and the columns displayed
  23293.      by `SHOW SLAVE STATUS':
  23294.  
  23295.      *Line#**Description*
  23296.      1   `Relay_Log_File'
  23297.      2   `Relay_Log_Pos'
  23298.      3   `Relay_Master_Log_File'
  23299.      4   `Exec_master_log_pos'
  23300.  
  23301.  
  23302. How To Set Up Replication
  23303. -------------------------
  23304.  
  23305. Here is a quick description of how to set up complete replication on
  23306. your current MySQL server. It assumes you want to replicate all your
  23307. databases and have not configured replication before. You will need to
  23308. shutdown your master server briefly to complete the steps outlined here.
  23309.  
  23310. While this method is the most straightforward way to set up a slave, it
  23311. is not the only one. For example, if you already have a snapshot of the
  23312. master, and the master already has server id set and binary logging
  23313. enabled, you can set up a slave without shutting the master down or
  23314. even blocking the updates.  For more details, please see *Note
  23315. Replication FAQ::.
  23316.  
  23317. If you want to be able to administrate a MySQL replication setup, we
  23318. suggest that you read this entire chapter through and try all commands
  23319. mentioned in *Note Replication SQL::. You should also familiarise
  23320. yourself with replication startup options in `my.cnf' in *Note
  23321. Replication Options::.
  23322.  
  23323.   1. Make sure you have a recent version of MySQL installed on the
  23324.      master and slave(s), and that these versions match with the above
  23325.      yes/no array.
  23326.  
  23327.      Please, do not report bugs until you have verified that the
  23328.      problem is present in the latest release.
  23329.  
  23330.   2. Set up a replication user on the master with the `FILE' (in MySQL
  23331.      versions older than 4.0.2) or `REPLICATION SLAVE' privilege in
  23332.      newer MySQL versions.  You must also have given this user
  23333.      permission to connect from all the slaves. If the user is only
  23334.      doing replication (which is recommended), you don't need to grant
  23335.      any additional privileges.
  23336.  
  23337.      For example, to create a user named `repl' which can access your
  23338.      master from any host, you might use this command:
  23339.  
  23340.           mysql> GRANT FILE ON *.* TO repl@"%" IDENTIFIED BY '<password>'; # master < 4.0.2
  23341.  
  23342.           mysql> GRANT REPLICATION SLAVE ON *.* TO repl@"%" IDENTIFIED BY '<password>'; # master >= 4.0.2
  23343.  
  23344.      If you plan to use the `LOAD TABLE FROM MASTER' or `LOAD DATA FROM
  23345.      MASTER' commands, you will also need to grant, on the master, to
  23346.      the above user, the `REPLICATION CLIENT' (or `SUPER' if the master
  23347.      is older than 4.0.13) privilege, the `RELOAD' privilege, and
  23348.      `SELECT' privileges on all tables you want to load. All master
  23349.      tables on which the user can't `SELECT' will be ignored by `LOAD
  23350.      DATA FROM MASTER'.
  23351.  
  23352.   3. If you are using MyISAM tables, flush all the tables and block
  23353.      write queries by executing `FLUSH TABLES WITH READ LOCK' command.
  23354.  
  23355.           mysql> FLUSH TABLES WITH READ LOCK;
  23356.  
  23357.      and then take a snapshot of the data on your master server.
  23358.  
  23359.      The easiest way to do this is to simply use an archiving program
  23360.      (`tar' on Unix, `PowerArchiver', `WinRAR', `WinZIP' or any similar
  23361.      software on Windows) to produce an archive of the databases in
  23362.      your master's data directory.  Include all the databases you want
  23363.      to replicate.
  23364.  
  23365.           tar -cvf /tmp/mysql-snapshot.tar /path/to/data-dir
  23366.  
  23367.      If you want to replicate only a database called `this_db', you can
  23368.      do just this:
  23369.  
  23370.           tar -cvf /tmp/mysql-snapshot.tar /path/to/data-dir/this_db
  23371.  
  23372.      You may not want to replicate the `mysql' database, then you can
  23373.      exclude it from the archive too. Into the archive you needn't copy
  23374.      the master's binary logs, error log, `master.info' /
  23375.      `relay-log.info' / relay logs (if the master is itself a slave of
  23376.      another machine). You can exclude all this from the archive.
  23377.  
  23378.      After or during the process of taking a snapshot, read the value
  23379.      of the current binary log name and the offset on the master:
  23380.  
  23381.           mysql > SHOW MASTER STATUS;
  23382.           +---------------+----------+--------------+-------------------------------+
  23383.           | File          | Position | Binlog_do_db | Binlog_ignore_db              |
  23384.           +---------------+----------+--------------+-------------------------------+
  23385.           | mysql-bin.003 | 73       | test,bar     | foo,manual,sasha_likes_to_run |
  23386.           +---------------+----------+--------------+-------------------------------+
  23387.           1 row in set (0.06 sec)
  23388.  
  23389.      The `File' column shows the name of the log,  while `Position'
  23390.      shows the offset. In the above example, the binary log value is
  23391.      `mysql-bin.003' and the offset is 73. Record the values - you will
  23392.      need to use them later when you are setting up the slave.
  23393.  
  23394.      Once you have taken the snapshot and recorded the log name and
  23395.      offset, you can re-enable write activity on the master:
  23396.  
  23397.           mysql> UNLOCK TABLES;
  23398.  
  23399.      If you are using InnoDB tables, ideally you should use the InnoDB
  23400.      Hot Backup tool that is available to those who purchase MySQL
  23401.      commercial licenses, support, or the backup tool itself. It will
  23402.      take a consistent snapshot without acquiring any locks on the
  23403.      master server, and record the log name and offset corresponding to
  23404.      the snapshot to be later used on the slave. More information about
  23405.      the tool is avalaible at `http://www.innodb.com/hotbackup.html'.
  23406.  
  23407.      Without the hot backup tool, the quickest way to take a snapshot
  23408.      of  InnoDB tables is to shut the master server down and copy the
  23409.      InnoDB datafiles and logs, and the table definition files
  23410.      (`.frm'). To record the current log file name and offset, you
  23411.      should do the following before you shut down the server:
  23412.  
  23413.           mysql> FLUSH TABLES WITH READ LOCK;
  23414.           mysql> SHOW MASTER STATUS;
  23415.  
  23416.      And then record the log name and the offset from the output of
  23417.      `SHOW MASTER STATUS' as was shown earlier. Once you have recorded
  23418.      the log name and the offset, shut the server down without
  23419.      unlocking the tables to make sure it goes down with the snapshot
  23420.      corresponding to the current log file and offset:
  23421.  
  23422.           shell> mysqladmin -uroot shutdown
  23423.  
  23424.      An alternative for both MyISAM and InnoDB tables is taking an SQL
  23425.      dump of the master instead of a binary copy like above; for this
  23426.      you can use `mysqldump --master-data' on your master and later run
  23427.      this SQL dump into your slave. This is however slower than doing a
  23428.      binary copy.
  23429.  
  23430.      If the master has been previously running without `log-bin'
  23431.      enabled, the values of log name and position displayed by `SHOW
  23432.      MASTER STATUS' or `mysqldump' will be empty. In that case, record
  23433.      empty string (") for the log name, and 4 for the offset.
  23434.  
  23435.   4. Make sure that `my.cnf' on the master has  `log-bin' if it is not
  23436.      there already and `server-id=unique number' in the `[mysqld]'
  23437.      section. If those options are not present, add them and restart
  23438.      the server.  It is very important that the id of the slave is
  23439.      different from the id of the master. Think of `server-id' as
  23440.      something similar to the IP address - it uniquely identifies the
  23441.      server instance in the community of replication partners.
  23442.  
  23443.           [mysqld]
  23444.           log-bin
  23445.           server-id=1
  23446.  
  23447.   5. Stop the slave server(s). Add the following to `my.cnf' on the
  23448.      slave(s):
  23449.  
  23450.           server-id=<some unique number between 1 and 2^32-1 that is different from
  23451.            that of the master>
  23452.  
  23453.      replacing the values in <> with what is relevant to your system.
  23454.  
  23455.      `server-id' must be different for each server participating in
  23456.      replication.  If you don't specify a server-id, it will be set to
  23457.      1 if you have not defined `master-host', else it will be set to 2.
  23458.      Note that in the case of `server-id' omission the master will
  23459.      refuse connections from all slaves, and the slave will refuse to
  23460.      connect to a master. Thus, omitting `server-id' is only good for
  23461.      backup with a binary log.
  23462.  
  23463.   6. Start the slave server(s). If it has been replicating previously,
  23464.      start the slave server with option `skip-slave-start'.  You may
  23465.      want to start the slave server with option `log-warnings', this
  23466.      way you will get more messages about network/connection problems
  23467.      for example.
  23468.  
  23469.   7. Copy the snapshot data into your data directory on your slave(s)
  23470.      (or execute the output of the above `mysqldump' into the `mysql').
  23471.      Make sure that the privileges on the files and directories are
  23472.      correct. The user which MySQL runs as needs to be able to read and
  23473.      write to them, just as on the master.
  23474.  
  23475.   8. Execute the following command on the slave(s):
  23476.  
  23477.           mysql> CHANGE MASTER TO MASTER_HOST='<master host name>',
  23478.            MASTER_USER='<replication user name>',
  23479.            MASTER_PASSWORD='<replication password>',
  23480.            MASTER_LOG_FILE='<recorded log file name>',
  23481.            MASTER_LOG_POS=<recorded log offset>;
  23482.  
  23483.      replacing the values in <> with the actual values relevant to your
  23484.      system.
  23485.  
  23486.      The maximum string length for the above variables are:
  23487.  
  23488.      MASTER_HOST                                            60
  23489.      MASTER_USER                                            16
  23490.      MASTER_PASSWORD                                        32
  23491.      MASTER_LOG_FILE                                        255
  23492.  
  23493.   9. Start the slave threads:
  23494.  
  23495.           mysql> START SLAVE;
  23496.  
  23497.  
  23498. After you have done the above, the slave(s) should connect to the master
  23499. and catch up on any updates which happened since the snapshot was taken.
  23500.  
  23501. If you have forgotten to set `server-id' for the slave you will get the
  23502. following error in the error log file:
  23503.  
  23504.      Warning: one should set server_id to a non-0 value if master_host is set.
  23505.      The server will not act as a slave.
  23506.  
  23507. If you have forgotten to do this for the master, the slaves will not be
  23508. able to connect to the master.
  23509.  
  23510. If a slave is not able to replicate for any reason, you will find error
  23511. messages in the error log on the slave.
  23512.  
  23513. Once a slave is replicating, you will find a file called `master.info'
  23514. and one called `relay-log.info' in the data directory. These two files
  23515. are used by the slave to keep track of how much of the master's binary
  23516. log it has processed. *Do not* remove or edit these files, unless you
  23517. really know what you are doing. Even in that case, it is preferred that
  23518. you use `CHANGE MASTER TO' command.  *NOTE*: the content of
  23519. `master.info' overrides some options specified on the command-line or
  23520. in `my.cnf' (*note Replication Options:: for more details).
  23521.  
  23522. Now that you have a snapshot, you can use it to set up other slaves. To
  23523. do so, follow the slave portion of the procedure described above. You
  23524. do not need to take another snapshot of the master.
  23525.  
  23526. Replication Features and Known Problems
  23527. ---------------------------------------
  23528.  
  23529. Here is an explanation of what is supported and what is not:
  23530.  
  23531.    * Replication will be done correctly with `AUTO_INCREMENT',
  23532.      `LAST_INSERT_ID()', and `TIMESTAMP' values.
  23533.  
  23534.    * `USER()' and `LOAD_FILE()' functions are replicated without
  23535.      changes and will thus not work reliably on the slave. This is also
  23536.      true for `CONNECTION_ID()' in slave versions strictly older than
  23537.      4.1.1.  The *new* `PASSWORD()' function in MySQL 4.1, is well
  23538.      replicated since 4.1.1 masters ; your slaves must be 4.1.0 or above
  23539.      to replicate it. If you have older slaves and need to replicate
  23540.      `PASSWORD()' from your 4.1.x master, you should start your master
  23541.      with option `--old-password'.
  23542.  
  23543.    * `sql_mode', `FOREIGN_KEY_CHECKS' and `table_type' variables are
  23544.      not replicated.
  23545.  
  23546.    * You have to use the same character set (`--default-character-set')
  23547.      on the master and the slave. If not, you may get duplicate key
  23548.      errors on the slave, because a key that is regarded as unique in
  23549.      the master character set may not be unique in the slave character
  23550.      set.
  23551.  
  23552.    * If you are using transactional tables on the master and
  23553.      non-transactional tables (for the same tables) on the slave, you
  23554.      will get problems if the slave is stopped in the middle of a
  23555.      `BEGIN/COMMIT' block, as the slave will later start at the
  23556.      beginning of the `BEGIN' block.  This issue is on our TODO and
  23557.      will be fixed in the near future.
  23558.  
  23559.    * Update queries that use user variables are badly replicated in
  23560.      3.23 and 4.0. This is fixed in 4.1. Note that user variables' names
  23561.      are case insensitive starting from version 5.0, so you should take
  23562.      this into account when setting up replication between 5.0 and a
  23563.      previous version.
  23564.  
  23565.    * The slave cannot connect to the master using SSL yet.
  23566.  
  23567.    * There is a theoretical chance (though we have never heard of it
  23568.      actually occurring) that the data on the master and slave become
  23569.      different if a query is designed in such a way that the data
  23570.      modification is non-deterministic, that is, left to the will of
  23571.      the query optimiser (which generally is not good practice!). For a
  23572.      detailed explanation, see *Note Open bugs::.
  23573.  
  23574.    * Strictly before MySQL 4.1.1, `FLUSH', `ANALYZE', `OPTIMIZE',
  23575.      `REPAIR' commands are not stored in the binary log and are because
  23576.      of this not replicated to the slaves. This is not normally a
  23577.      problem as these commands don't change anything. This does however
  23578.      mean that if you update the MySQL privilege tables directly
  23579.      without using the `GRANT' statement and you replicate the `mysql'
  23580.      privilege database, you must do a `FLUSH PRIVILEGES' on your
  23581.      slaves to put the new privileges into effect. Also if you use
  23582.      `FLUSH TABLES' when renaming a `MyISAM' table involved in a
  23583.      `MERGE' table, you will have to issue `FLUSH TABLES' manually on
  23584.      the slave.  Since MySQL 4.1.1, these commands are written to the
  23585.      binary log (except `FLUSH LOGS', `FLUSH MASTER', `FLUSH SLAVE',
  23586.      `FLUSH TABLES WITH READ LOCK') unless you specify
  23587.      `NO_WRITE_TO_BINLOG' (or its alias `LOCAL') (for a syntax example,
  23588.      *note `FLUSH': FLUSH.).
  23589.  
  23590.    * MySQL only supports one master and many slaves. Later we will add
  23591.      a voting algorithm to automatically change master if something goes
  23592.      wrong with the current master. We will also introduce 'agent'
  23593.      processes to help do load balancing by sending select queries to
  23594.      different slaves.
  23595.  
  23596.    * Temporary tables are replicated with the exception of the case
  23597.      when you shut down slave server (not just slave thread) when you
  23598.      have some replicated temporary tables and they are used in
  23599.      subsequent updates by the master. To deal with this problem
  23600.      shutting down the slave, do `STOP SLAVE', check
  23601.      `Slave_open_temp_tables' variable to see if it is 0, if so issue
  23602.      `mysqladmin shutdown'. If the number is not 0, restart the slave
  23603.      threads with `START SLAVE' and see if you have better luck next
  23604.      time. We have plans to fix this in the near future.
  23605.  
  23606.    * It is safe to connect servers in a circular master-slave
  23607.      relationship with `log-slave-updates' enabled.  Note, however,
  23608.      that many queries will not work right in this kind of setup unless
  23609.      your client code is written to take care of the potential problems
  23610.      that can happen from updates that occur in different sequence on
  23611.      different servers.
  23612.  
  23613.      This means that you can do a setup like the following:
  23614.  
  23615.           A -> B -> C -> A
  23616.  
  23617.      Thanks to server ids, which are encoded in the binary log events, A
  23618.      will know when the event it reads had originally been created by
  23619.      A, so A will not execute it and there will be no infinite loop.
  23620.      But this circular setup will only work if you only do non
  23621.      conflicting updates between the tables.  In other words, if you
  23622.      insert data in A and C, you should never insert a row in A that
  23623.      may have a conflicting key with a row insert in C.  You should
  23624.      also not update the same rows on two servers if the order in which
  23625.      the updates are applied matters.
  23626.  
  23627.    * If the query on the slave gets an error, the slave SQL thread will
  23628.      terminate, and a message will appear in the `.err' file. You should
  23629.      then connect to the slave manually, fix the cause of the error (for
  23630.      example, non-existent table), and then run `START SLAVE'.
  23631.  
  23632.    * If connection to the master is lost, the slave will retry
  23633.      immediately, and then in case of failure every
  23634.      `master-connect-retry' (default 60) seconds. Because of this, it
  23635.      is safe to shut down the master, and then restart it after a
  23636.      while. The slave will also be able to deal with network
  23637.      connectivity outages. However, the slave will notice the network
  23638.      outage only after receiving no data from the master for
  23639.      `slave_net_timeout' seconds. So if your outages are short, you may
  23640.      want to decrease `slave_net_timeout' ; see *Note SHOW VARIABLES::.
  23641.  
  23642.    * Shutting down the slave (cleanly) is also safe, as it keeps track
  23643.      of where it left off.  Unclean shutdowns might produce problems,
  23644.      especially if disk cache was not synced before the system died.
  23645.      Your system fault tolerance will be greatly increased if you have
  23646.      a good UPS.
  23647.  
  23648.    * Due to the non-transactional nature of MyISAM tables, it is
  23649.      possible to have a query that will only partially update a table
  23650.      and return an error code. This can happen, for example, on a
  23651.      multi-row insert that has one row violating a key constraint, or
  23652.      if a long update query is killed after updating some of the rows.
  23653.      If that happens on the master, the slave thread will exit and wait
  23654.      for the DBA to decide what to do about it unless the error code is
  23655.      legitimate and the query execution results in the same error code.
  23656.      If this error code validation behaviour is not desirable, some (
  23657.      or all) errors could be masked out with `slave-skip-errors' option
  23658.      starting in Version 3.23.47.
  23659.  
  23660.    * If you update transactional tables from non-transactional tables
  23661.      inside a `BEGIN/COMMIT' segment updates to the binary log may be
  23662.      out of sync if some thread changes the non-transactional table
  23663.      before the transaction commits.  This is because the transaction
  23664.      is written to the binary log only when it's commited.
  23665.  
  23666.    * Before version 4.0.15, any update to a non-transactional table is
  23667.      written to the binary log at once when the update is made while
  23668.      transactional updates are written on `COMMIT' or not written at
  23669.      all if you use `ROLLBACK'; you have to take this into account when
  23670.      updating both transactional tables and non-transactional tables in
  23671.      the same transaction if you are using binary logging for backups or
  23672.      replication. In version 4.0.15 we changed the behaviour of logging
  23673.      of transactions which mix updates to transactional and
  23674.      non-transactional tables, which solves the problems (order of
  23675.      queries is good in binlog, and all needed queries are written to
  23676.      the binlog even in case of `ROLLBACK'). The problem which remains
  23677.      is when a second connection updates the non-transactional table
  23678.      while the first connection's transaction is not finished yet
  23679.      (wrong order can still occur, because the second connection's
  23680.      update will be written immediately after it is done).
  23681.  
  23682. The following table is about problems in 3.23 that are fixed in 4.0:
  23683.  
  23684.    * `LOAD DATA INFILE' will be handled properly as long as the file
  23685.      still resides on the master server at the time of update
  23686.      propagation.
  23687.  
  23688.    * `LOAD LOCAL DATA INFILE' will be skipped.
  23689.  
  23690.    * In 3.23 `RAND()' in updates does not replicate properly.  Use
  23691.      `RAND(some_non_rand_expr)' if you are replicating updates with
  23692.      `RAND()'. You can, for example, use `UNIX_TIMESTAMP()' for the
  23693.      argument to `RAND()'. This is fixed in 4.0.
  23694.  
  23695. Replication Options in `my.cnf'
  23696. -------------------------------
  23697.  
  23698. On both master and slave you need to use the `server-id' option.  This
  23699. sets a unique replication id. You should pick a unique value in the
  23700. range between 1 to 2^32-1 for each master and slave.  Example:
  23701. `server-id=3'
  23702.  
  23703. The options you can use on the MASTER are all described there: see
  23704. *Note Binary log::.
  23705.  
  23706. The following table describes the options you can use on the SLAVE.  It
  23707. is recommended to read the following paragraph; these options can help
  23708. you customize replication to suit your needs.
  23709.  
  23710. *NOTE*: replication handles the following options :
  23711.    * master-host
  23712.  
  23713.    * master-user
  23714.  
  23715.    * master-password
  23716.  
  23717.    * master-port
  23718.  
  23719.    * master-connect-retry
  23720. in a special way. If no `master.info' file exists (replication is used
  23721. for the very first time or you have run `RESET SLAVE' and
  23722. shutdown/restarted the slave server), the slave uses values specified
  23723. on the command-line or in `my.cnf'.  But if `master.info' exists, the
  23724. slave *IGNORES* any values specified on the command-line or in `my.cnf',
  23725. and uses instead the values it reads from `master.info'.  For example,
  23726. if you have
  23727.  
  23728. `master-host=this_host'
  23729.  
  23730. in your `my.cnf', are using replication, then want to replicate from
  23731. another host, modifying the above line in `my.cnf' will have no effect.
  23732. You must use `CHANGE MASTER TO' instead. This holds true for
  23733. `master-host', `master-user', `master-password', `master-port',
  23734. `master-connect-retry'.  Therefore, you may decide to put no `master-*'
  23735. options in `my.cnf' and instead use only `CHANGE MASTER TO' (*note
  23736. Replication SQL::).
  23737.  
  23738. *Option*                    *Description*
  23739. `log-slave-updates'          Tells the slave to log the updates done by
  23740.                             the slave SQL thread to the slave's binary
  23741.                             log. Off by default.  Of course, it requires
  23742.                             that the slave be started with binary
  23743.                             logging enabled (`log-bin' option).  You
  23744.                             have to use `log-slave-updates' to chain
  23745.                             several slaves ; for example for the
  23746.                             following setup to work
  23747.                             
  23748.                                  A -> B ->C
  23749.                             (C is a slave of B which is a slave of A)
  23750.                             you need to start B with the
  23751.                             `log-slave-updates' option.
  23752. `log-warnings'               Makes the slave print more messages about
  23753.                             what it is doing. For example, it will warn
  23754.                             you that it succeeded in reconnecting after a
  23755.                             network/connection failure, and warn you
  23756.                             about how each slave thread started.
  23757. `max-relay-log-size=#'       To rotate the relay log automatically.
  23758.                             *Note SHOW VARIABLES::.
  23759. `master-host=host'           Master hostname or IP address for
  23760.                             replication. If not set, the slave thread
  23761.                             will not be started. Note that the setting
  23762.                             of `master-host' will be ignored if there
  23763.                             exists a valid `master.info' file. Probably a
  23764.                             better name for this options would have been
  23765.                             something like `bootstrap-master-host', but
  23766.                             it is too late to change now.
  23767.                             
  23768.                             Example:
  23769.                             `master-host=db-master.mycompany.com'
  23770. `master-user=username'       The username the slave thread will use for
  23771.                             authentication when connecting to the
  23772.                             master. The user must have the `FILE'
  23773.                             privilege. If the master user is not set,
  23774.                             user `test' is assumed. The value in
  23775.                             `master.info' will take precedence if it can
  23776.                             be read.
  23777.                             
  23778.                             Example: `master-user=scott'
  23779. `master-password=password'   The password the slave thread will
  23780.                             authenticate with when connecting to the
  23781.                             master. If not set, an empty password is
  23782.                             assumed.The value in `master.info' will take
  23783.                             precedence if it can be read.
  23784.                             
  23785.                             Example: `master-password=tiger'
  23786. `master-port=portnumber'     The port the master is listening on. If not
  23787.                             set, the compiled setting of `MYSQL_PORT' is
  23788.                             assumed. If you have not tinkered with
  23789.                             `configure' options, this should be 3306.
  23790.                             The value in `master.info' will take
  23791.                             precedence if it can be read.
  23792.                             
  23793.                             Example: `master-port=3306'
  23794. `master-connect-retry=seconds' The number of seconds the slave thread will
  23795.                             sleep before retrying to connect to the
  23796.                             master in case the master goes down or the
  23797.                             connection is lost.  Default is 60. The
  23798.                             value in `master.info' will take precedence
  23799.                             if it can be read.
  23800.                             
  23801.                             Example: `master-connect-retry=60'
  23802. `master-ssl'                 Planned to enable the slave to connect to
  23803.                             the master using SSL.  Does nothing yet!
  23804.                             
  23805.                             Example: `master-ssl'
  23806. `master-ssl-key=filename'    Master SSL keyfile name. Only applies if
  23807.                             you have enabled `master-ssl'. Does nothing
  23808.                             yet.
  23809.                             
  23810.                             Example: `master-ssl-key=SSL/master-key.pem'
  23811. `master-ssl-cert=filename'   Master SSL certificate file name. Only
  23812.                             applies if you have enabled `master-ssl'.
  23813.                             Does nothing yet.
  23814.                             
  23815.                             Example:
  23816.                             `master-ssl-cert=SSL/master-cert.pem'
  23817. `master-ssl-capath'          Master SSL CA path. Only applies if you
  23818.                             have enabled `master-ssl'. Does nothing yet.
  23819. `master-ssl-cipher'          Master SSL cipher. Only applies if you have
  23820.                             enabled `master-ssl'. Does nothing yet.
  23821. `master-info-file=filename'  To give `master.info' another name and/or
  23822.                             to put it in another directory than the data
  23823.                             directory.
  23824. `relay-log=filename'         To specify the location and name that
  23825.                             should be used for relay logs.  You can use
  23826.                             this to have hostname-independant relay log
  23827.                             names, or if your relay logs tend to be big
  23828.                             (and you don't want to decrease
  23829.                             `max_relay_log_size') and you need to put
  23830.                             them on some area different from the data
  23831.                             directory, or if you want to increase speed
  23832.                             by balancing load between disks.
  23833. `relay-log-index=filename'   To specify the location and name that
  23834.                             should be used for the relay logs index file.
  23835. `relay-log-info-file=filename' To give `relay-log.info' another name
  23836.                             and/or to put it in another directory than
  23837.                             the data directory.
  23838. `relay-log-purge=0|1'        Available since MySQL 4.1.1.
  23839.                             Disables/enables automatic purging of relay
  23840.                             logs as soon as they are not needed anymore.
  23841.                             This is a global variable which can be
  23842.                             dynamically changed with `SET GLOBAL
  23843.                             RELAY_LOG_PURGE=0|1'. The default value is 1.
  23844. `relay-log-space-limit=#'    To put an upper limit on the total size of
  23845.                             all relay logs on the slave (a value of 0
  23846.                             means "unlimited"). This is useful if you
  23847.                             have a small hard disk on your slave
  23848.                             machine. When the limit is reached, the I/O
  23849.                             thread pauses (does not read the master's
  23850.                             binlog) until the SQL thread has catched up
  23851.                             and deleted some now unused relay logs. Note
  23852.                             that this limit is not absolute: there are
  23853.                             cases where the SQL thread needs more events
  23854.                             to be able to delete; in that case the I/O
  23855.                             thread will overgo the limit until deletion
  23856.                             becomes possible. Not doing so would cause a
  23857.                             deadlock (which happens before MySQL 4.0.13).
  23858.                             Users should not set `relay-log-space-limit'
  23859.                             to less than twice the value of
  23860.                             `max-relay-log-size' (or `max-binlog-size' if
  23861.                             `max-relay-log-size' is 0) because in that
  23862.                             case there are chances that when the I/O
  23863.                             thread waits for free space because
  23864.                             `relay-log-space-limit' is exceeded, the SQL
  23865.                             thread has no relay log to purge and so
  23866.                             cannot satisfy the I/O thread, forcing the
  23867.                             I/O thread to temporarily ignore
  23868.                             `relay-log-space-limit'.
  23869. `replicate-do-table=db_name.table_name' Tells the slave thread to restrict
  23870.                             replication to the specified table.  To
  23871.                             specify more than one table, use the
  23872.                             directive multiple times, once for each
  23873.                             table.  This will work for cross-database
  23874.                             updates, in contrast to `replicate-do-db'.
  23875.                             Please read notes which follow this table.
  23876.                             
  23877.                             Example:
  23878.                             `replicate-do-table=some_db.some_table'
  23879. `replicate-ignore-table=db_name.table_name' Tells the slave thread to not replicate any
  23880.                             command that updates the specified table
  23881.                             (even if any other tables may be update by
  23882.                             the same command). To specify more than one
  23883.                             table to ignore, use the directive multiple
  23884.                             times, once for each table. This will work
  23885.                             for cross-database updates, in contrast to
  23886.                             `replicate-ignore-db'.  Please read notes
  23887.                             which follow this table.
  23888.                             
  23889.                             Example:
  23890.                             `replicate-ignore-table=db_name.some_table'
  23891. `replicate-wild-do-table=db_name.table_name' Tells the slave thread to restrict
  23892.                             replication to queries where any of the
  23893.                             updated tables match the specified wildcard
  23894.                             pattern.  To specify more than one table,
  23895.                             use the directive multiple times, once for
  23896.                             each table.  This will work for
  23897.                             cross-database updates.  Please read notes
  23898.                             which follow this table.
  23899.                             
  23900.                             Example: `replicate-wild-do-table=foo%.bar%'
  23901.                             will replicate only updates that uses a
  23902.                             table in any databases that start with `foo'
  23903.                             and whose table names start with `bar'.
  23904.                             
  23905.                             Note that if you do
  23906.                             `replicate-wild-do-table=foo%.%' then the
  23907.                             rule will be propagated to `CREATE DATABASE'
  23908.                             and `DROP DATABASE', that is, these two
  23909.                             statements will be replicated if the
  23910.                             database name matches the database pattern
  23911.                             ('foo%' here) (this magic is triggered by
  23912.                             '%' being the table pattern).
  23913. `replicate-wild-ignore-table=db_name.table_name' Tells the slave thread to not replicate a
  23914.                             query where any table matches the given
  23915.                             wildcard pattern. To specify more than one
  23916.                             table to ignore, use the directive multiple
  23917.                             times, once for each table. This will work
  23918.                             for cross-database updates.  Please read
  23919.                             notes which follow this table.
  23920.                             
  23921.                             Example:
  23922.                             `replicate-wild-ignore-table=foo%.bar%' will
  23923.                             not do updates to tables in databases that
  23924.                             start with `foo' and whose table names start
  23925.                             with `bar'.
  23926.                             
  23927.                             Note that if you do
  23928.                             `replicate-wild-ignore-table=foo%.%' then the
  23929.                             rule will be propagated to `CREATE DATABASE'
  23930.                             and `DROP DATABASE', that is, these two
  23931.                             statements will not be replicated if the
  23932.                             database name matches the database pattern
  23933.                             ('foo%' here) (this magic is triggered by
  23934.                             '%' being the table pattern).
  23935. `replicate-do-db=database_name' Tells the slave to restrict replication to
  23936.                             commands where the current database (that
  23937.                             is, the one selected by `USE') is
  23938.                             `database_name'.  To specify more than one
  23939.                             database, use the directive multiple times,
  23940.                             once for each database. Note that this will
  23941.                             not replicate cross-database queries such as
  23942.                             `UPDATE some_db.some_table SET foo='bar''
  23943.                             while having selected a different or no
  23944.                             database. If you need cross database updates
  23945.                             to work, make sure you have 3.23.28 or
  23946.                             later, and use
  23947.                             `replicate-wild-do-table=db_name.%'.  Please
  23948.                             read notes which follow this table.
  23949.                             
  23950.                             Example: `replicate-do-db=some_db'.
  23951.                             
  23952.                             Example of what does not work as you could
  23953.                             expect it: if the slave is started with
  23954.                             `replicate-do-db=sales', and you do `USE
  23955.                             prices; UPDATE sales.january SET
  23956.                             amount=amount+1000;', this query will not be
  23957.                             replicated.
  23958.                             
  23959.                             If you need cross database updates to work,
  23960.                             use `replicate-wild-do-table=db_name.%'
  23961.                             instead.
  23962.                             
  23963.                             The main reason for this
  23964.                             "just-check-the-current-database" behaviour
  23965.                             is that it's hard from the command alone to
  23966.                             know if a query should be replicated or not
  23967.                             ; for example if you are using
  23968.                             multi-table-delete or multi-table-update
  23969.                             commands that go across multiple databases.
  23970.                             It's also very fast to just check the
  23971.                             current database.
  23972. `replicate-ignore-db=database_name' Tells the slave to not replicate any
  23973.                             command where the current database (that is,
  23974.                             the one selected by `USE') is
  23975.                             `database_name'. To specify more than one
  23976.                             database to ignore, use the directive
  23977.                             multiple times, once for each database.  You
  23978.                             should not use this directive if you are
  23979.                             using cross table updates and you don't want
  23980.                             these update to be replicated.  Please read
  23981.                             notes which follow this table.
  23982.                             
  23983.                             Example: `replicate-ignore-db=some_db'.
  23984.                             
  23985.                             Example of what does not work as you could
  23986.                             expect it: if the slave is started with
  23987.                             `replicate-ignore-db=sales', and you do `USE
  23988.                             prices; UPDATE sales.january SET
  23989.                             amount=amount+1000;', this query will be
  23990.                             replicated.
  23991.                             
  23992.                             If you need cross database updates to work,
  23993.                             use `replicate-wild-ignore-table=db_name.%'
  23994.                             instead.
  23995. `replicate-rewrite-db=from_name->to_name' Tells the slave to translate the current
  23996.                             database (that is, the one selected by `USE')
  23997.                             to `to_name' if it was `from_name' on the
  23998.                             master.  Only statements involving tables
  23999.                             may be affected (`CREATE DATABASE', `DROP
  24000.                             DATABASE' won't), and only if `from_name'
  24001.                             was the current database on the master.
  24002.                             This will not work for cross-database
  24003.                             updates.  Note that the translation is done
  24004.                             before `replicate-*' rules are tested.
  24005.                             
  24006.                             Example:
  24007.                             `replicate-rewrite-db=master_db_name->slave_db_name'
  24008. `report-host=host'           Available after 4.0.0. Hostname or IP of
  24009.                             the slave to be reported to the master
  24010.                             during slave registration. Will appear in
  24011.                             the output of `SHOW SLAVE HOSTS'. Leave
  24012.                             unset if you do not want the slave to
  24013.                             register itself with the master. Note that
  24014.                             it is not sufficient for the master to
  24015.                             simply read the IP of the slave off the
  24016.                             socket once the slave connects. Due to `NAT'
  24017.                             and other routing issues, that IP may not be
  24018.                             valid for connecting to the slave from the
  24019.                             master or other hosts. For the moment this
  24020.                             option has no real interest ; it is meant
  24021.                             for failover replication which is not
  24022.                             implemented yet.
  24023.                             
  24024.                             Example: `report-host=slave1.mycompany.com'
  24025. `report-port=portnumber'     Available after 4.0.0. Port for connecting
  24026.                             to slave reported to the master during slave
  24027.                             registration.  Set it only if the slave is
  24028.                             listening on a non-default port or if you
  24029.                             have a special tunnel from the master or
  24030.                             other clients to the slave. If not sure,
  24031.                             leave this option unset.  For the moment
  24032.                             this option has no real interest ; it is
  24033.                             meant for failover replication which is not
  24034.                             implemented yet.
  24035. `skip-slave-start'           Tells the slave server not to start the
  24036.                             slave threads on server startup. The user
  24037.                             can start them later with `START SLAVE'.
  24038. `slave_compressed_protocol=#' If 1, then use compression on the
  24039.                             slave/client protocol if both slave and
  24040.                             master support this.
  24041. `slave-load-tmpdir=filename' This option is by default equal to `tmpdir'.
  24042.                             When the SQL slave replicates a `LOAD DATA
  24043.                             INFILE' command, it extracts the
  24044.                             to-be-loaded file from the relay log into
  24045.                             temporary files, then loads these into the
  24046.                             table. If the file loaded on the master was
  24047.                             huge, the temporary files on the slave will
  24048.                             be huge too; therefore you may wish/have to
  24049.                             tell the slave to put the temporary files on
  24050.                             some large disk different from `tmpdir',
  24051.                             using this option. In that case, you may
  24052.                             also use the `relay-log' option, as relay
  24053.                             logs will be huge too.
  24054. `slave-net-timeout=#'        Number of seconds to wait for more data
  24055.                             from the master before aborting the read,
  24056.                             considering the connection broken and
  24057.                             retrying to connect, first time immediately,
  24058.                             then every `master-connect-retry' seconds.
  24059. `slave-skip-errors=          Tells the slave SQL thread to continue
  24060. [err_code1,err_code2,... |  replication when a query returns an error
  24061. all]'                       from the provided list. Normally,
  24062.                             replication will discontinue when an error is
  24063.                             encountered, giving the user a chance to
  24064.                             resolve the inconsistency in the data
  24065.                             manually. Do not use this option unless you
  24066.                             fully understand why you are getting the
  24067.                             errors.  If there are no bugs in your
  24068.                             replication setup and client programs, and
  24069.                             no bugs in MySQL itself, you should never
  24070.                             get an abort with error. Indiscriminate use
  24071.                             of this option will result in slaves being
  24072.                             hopelessly out of sync with the master and
  24073.                             you having no idea how the problem happened.
  24074.                             
  24075.                             For error codes, you should use the numbers
  24076.                             provided by the error message in your slave
  24077.                             error log and in the output of `SHOW SLAVE
  24078.                             STATUS'. A full list of error messages can
  24079.                             be found in the source distribution in
  24080.                             `Docs/mysqld_error.txt'.
  24081.                             
  24082.                             You can (but should not) also use a very
  24083.                             non-recommended value of `all' which will
  24084.                             ignore all error messages and keep barging
  24085.                             along regardless.  Needless to say, if you
  24086.                             use it, we make no promises regarding your
  24087.                             data integrity. Please do not complain if
  24088.                             your data on the slave is not anywhere close
  24089.                             to what it is on the master in this case -
  24090.                             you have been warned.
  24091.                             
  24092.                             Example:
  24093.                             
  24094.                             `slave-skip-errors=1062,1053' or
  24095.                             `slave-skip-errors=all'
  24096.  
  24097. Some of these options, like all `replicate-*' options, can only be set
  24098. at the slave server's startup, not on-the-fly. We plan to fix this.
  24099.  
  24100. Here is the order of evaluation of the `replicate-*' rules, to decide
  24101. if the query is going to be executed by the slave or ignored by it:
  24102.   1. Are there some `replicate-do-db' or `replicate-ignore-db' rules?
  24103.         * Yes: test them like for `binlog-do-db' and `binlog-ignore-db'
  24104.           (*note Binary log::). What is the result of the test?
  24105.              * ignore the query: ignore it and exit.
  24106.  
  24107.              * execute the query: don't execute it immediately, defer
  24108.                the decision, go to step below.
  24109.  
  24110.         * No: go to step below.
  24111.  
  24112.   2. Are there some `replicate-*-table' rules?
  24113.         * No: execute the query and exit.
  24114.  
  24115.         * Yes: go to step below. Only tables which are to be updated
  24116.           will be compared to rules (`INSERT INTO sales SELECT * from
  24117.           prices': only `sales' will be compared to rules). If several
  24118.           tables are to be updated (multi-table statement), the first
  24119.           matching table (matching "do" or "ignore") wins (i.e. the
  24120.           first table is compared to rules, then if no decision could
  24121.           be taken the second table is compared to rules etc).
  24122.  
  24123.   3. Are there some `replicate-do-table' rules?
  24124.         * Yes: does the table match any of them?
  24125.              * Yes: execute the query and exit.
  24126.  
  24127.              * No: go to step below.
  24128.  
  24129.         * No: go to step below.
  24130.  
  24131.   4. Are there some `replicate-ignore-table' rules?
  24132.         * Yes: does the table match any of them?
  24133.              * Yes: ignore the query and exit.
  24134.  
  24135.              * No: go to step below.
  24136.  
  24137.         * No: go to step below.
  24138.  
  24139.   5. Are there some `replicate-wild-do-table' rules?
  24140.         * Yes: does the table match any of them?
  24141.              * Yes: execute the query and exit.
  24142.  
  24143.              * No: go to step below.
  24144.  
  24145.         * No: go to step below.
  24146.  
  24147.   6. Are there some `replicate-wild-ignore-table' rules?
  24148.         * Yes: does the table match any of them?
  24149.              * Yes: ignore the query and exit.
  24150.  
  24151.              * No: go to step below.
  24152.  
  24153.         * No: go to step below.
  24154.  
  24155.   7. No `replicate-*-table' rule was matched.  Is there another table
  24156.      to test against these rules?
  24157.         * Yes: loop.
  24158.  
  24159.         * No: we have tested all tables to be updated, could not match
  24160.           any rule.  Are there `replicate-do-table' or
  24161.           `replicate-wild-do-table' rules ?
  24162.              * Yes: ignore the query and exit.
  24163.  
  24164.              * No: execute the query and exit.
  24165.  
  24166. SQL Commands Related to Replication
  24167. -----------------------------------
  24168.  
  24169. Replication can be controlled through the SQL interface. Here is the
  24170. summary of commands. Near each command you will find "(Slave)", meaning
  24171. this command is issued on the slave, or "Master", meaning it is issued
  24172. on the master.
  24173.  
  24174. `START SLAVE' (slave)
  24175. .....................
  24176.  
  24177. Starts the slave threads. Was called `SLAVE START' in MySQL 3.23.  As
  24178. of MySQL 4.0.2, you can add `IO_THREAD' or `SQL_THREAD' options to the
  24179. statement to start only the I/O thread or the SQL thread.  The I/O
  24180. thread reads queries from the master server and stores them in the
  24181. relay log.  The SQL thread reads the relay log and executes the queries.
  24182. Note that if `START SLAVE' succeeds in starting the slave threads it
  24183. will return without any error. But even in that case it might be that
  24184. slave threads start and then later stop (because they don't manage to
  24185. connect to the master or read his binlogs or any other problem). `START
  24186. SLAVE' will not warn you about this, you have to check your slave's
  24187. `.err' file for error messages generated by the slave threads, or check
  24188. that these are running fine with `SHOW SLAVE STATUS'.
  24189.  
  24190. `STOP SLAVE' (slave)
  24191. ....................
  24192.  
  24193. Stops the slave threads. Was called `SLAVE STOP' in MySQL 3.23.  Like
  24194. `SLAVE START', this statement may be used with `IO_THREAD' and
  24195. `SQL_THREAD' options.
  24196.  
  24197. `SET SQL_LOG_BIN=0|1' (master)
  24198. ..............................
  24199.  
  24200. Disables/enables binary logging for the user's connection
  24201. (`SQL_LOG_BIN' is a session variable) if the user has the `SUPER'
  24202. privilege.  Ignored otherwise.
  24203.  
  24204. `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n' (slave)
  24205. .............................................
  24206.  
  24207. Skip the next `n' events from the master. Only valid when the slave
  24208. thread is not running, otherwise, gives an error. Useful for recovering
  24209. from replication stops caused by a statement.
  24210.  
  24211. `RESET MASTER' (master)
  24212. .......................
  24213.  
  24214. Deletes all binary logs listed in the index file, resetting the binlog
  24215. index file to be empty.  Previously named `FLUSH MASTER'.
  24216.  
  24217. `RESET SLAVE' (slave)
  24218. .....................
  24219.  
  24220. Makes the slave forget its replication position in the master's binlogs,
  24221. deletes the `master.info' and `relay-log.info' files, all relay logs,
  24222. starts a new relay log.  *Note:* relay logs which had not been totally
  24223. executed by the SQL slave thread (which are likely to exist if you
  24224. issued `STOP SLAVE' in an highly-loaded replication slave) are also
  24225. deleted.  Connection information (master host, master port, master
  24226. user, master password) is immediately reset to the values specified in
  24227. startup options (`master-host' etc) if there were some.  Previously
  24228. named `FLUSH SLAVE'.
  24229.  
  24230. `LOAD TABLE tblname FROM MASTER' (slave)
  24231. ........................................
  24232.  
  24233. Downloads a copy of the table from master to the slave. Implemented
  24234. mainly for debugging of `LOAD DATA FROM MASTER'.   Requires that the
  24235. replication user which is used to connect to the master has  `RELOAD'
  24236. and `SUPER' privileges on the master, and  `SELECT' on the master table
  24237. to load.  On the slave's side, the user which issues `LOAD TABLE FROM
  24238. MASTER' should have grants to drop and create the table.   Please read
  24239. the timeout notes in the description of `LOAD DATA  FROM MASTER' below,
  24240. they apply here too.
  24241.  
  24242. `LOAD DATA FROM MASTER' (slave)
  24243. ...............................
  24244.  
  24245. Takes a snapshot of the master and copies  it to the slave.   Updates
  24246. the values of `MASTER_LOG_FILE' and  `MASTER_LOG_POS' so that the slave
  24247. will start replicating from the  correct position. Will honor table and
  24248. database exclusion rules  specified with `replicate-*' options. So far
  24249. works only with  `MyISAM' tables and acquires a global read lock on the
  24250. master while  taking the snapshot. In the future it is planned to make
  24251. it work with  `InnoDB' tables and to remove the need for global read
  24252. lock using  the non-blocking online backup feature.
  24253.  
  24254. If you are loading big tables, you may have to increase the values  of
  24255. `net_read_timeout' and `net_write_timeout'  on both your master and
  24256. slave ; see *Note SHOW VARIABLES::.
  24257.  
  24258. Note that `LOAD DATA FROM MASTER' does *NOT* copy any  tables from the
  24259. `mysql' database.  This is to make it easy to have  different users and
  24260. privileges on the master and the slave.
  24261.  
  24262. Requires that the replication user which is used to connect to the
  24263. master has  `RELOAD' and `SUPER' privileges on the master,  `SELECT'
  24264. privileges on all master's tables you want to load. All  master's
  24265. tables on which the user has no `SELECT' privilege will  be ignored by
  24266. `LOAD DATA FROM MASTER'; this is because the  master will hide them to
  24267. the user: `LOAD DATA FROM MASTER' calls  `SHOW DATABASES' to know the
  24268. master databases to load, but  `SHOW DATABASES' returns only databases
  24269. on which the user has  some privilege, *note SHOW DATABASE INFO::.  On
  24270. the slave's side, the user which issues `LOAD DATA FROM MASTER' should
  24271. have grants to drop and create the involved databases and tables.
  24272.  
  24273. `CHANGE MASTER TO master_def_list' (slave)
  24274. ..........................................
  24275.  
  24276. `CHANGE MASTER' *is a "brutal" command, it is recommended to read this
  24277. whole description before using it in production.*
  24278.  
  24279. Changes the master parameters (connection and binlog information) to
  24280. the values specified in `master_def_list'. `master_def_list' is a
  24281. comma-separated list of `master_def' where `master_def' is one of the
  24282. following: `MASTER_HOST', `MASTER_USER', `MASTER_PASSWORD',
  24283. `MASTER_PORT', `MASTER_CONNECT_RETRY', `MASTER_LOG_FILE',
  24284. `MASTER_LOG_POS', `RELAY_LOG_FILE', `RELAY_LOG_POS' (these last two only
  24285. starting from MySQL 4.0).  For example:
  24286.  
  24287.  
  24288.      CHANGE MASTER TO
  24289.        MASTER_HOST='master2.mycompany.com',
  24290.        MASTER_USER='replication',
  24291.        MASTER_PASSWORD='bigs3cret',
  24292.        MASTER_PORT=3306,
  24293.        MASTER_LOG_FILE='master2-bin.001',
  24294.        MASTER_LOG_POS=4,
  24295.        MASTER_CONNECT_RETRY=10;
  24296.  
  24297.      CHANGE MASTER TO
  24298.        RELAY_LOG_FILE='slave-relay-bin.006',
  24299.        RELAY_LOG_POS=4025;
  24300.  
  24301. You only need to specify the values that need to be changed. The values
  24302. that you omit will stay the same with the exception of when you
  24303. *specify (not necessarily change)* the host or port.  In that case, the
  24304. slave will assume that the master is different from before. Therefore,
  24305. the old values of master's binlog name and position are considered no
  24306. longer applicable, thus if you didn't specify `MASTER_LOG_FILE' and
  24307. `MASTER_LOG_POS' in the command, `MASTER_LOG_FILE=''' and
  24308. `MASTER_LOG_POS=4' will silently be appended to it.
  24309.  
  24310. `MASTER_LOG_FILE' and `MASTER_LOG_POS' are the coordinates from which
  24311. the I/O slave thread will start reading from the master, next time this
  24312. thread is started. As `CHANGE MASTER' deletes relay logs (see below),
  24313. they are also the coordinates from which the SQL slave thread will
  24314. start executing next time it is started.
  24315.  
  24316. `CHANGE MASTER' *deletes all relay logs* (and starts a new one), unless
  24317. you specified `RELAY_LOG_FILE' or `RELAY_LOG_POS' (in that case relay
  24318. logs will be kept; since MySQL 4.1.1 the `RELAY_LOG_PURGE' global
  24319. variable will silently be set to 0).  `CHANGE MASTER' updates
  24320. `master.info' and `relay-log.info'.
  24321.  
  24322. *Note:* if, just before you issue `CHANGE MASTER', the SQL slave thread
  24323. is late by one or more queries compared to the I/O thread (a very
  24324. common case when replication is running in high-load environments),
  24325. then as `CHANGE MASTER' deletes relay logs containing these
  24326. non-executed queries, and so replication then restarts *from the
  24327. coordinates of the I/O thread*, *the SQL thread will have "lept" over
  24328. the non-executed queries*.  Therefore, unless these queries were not
  24329. important, you should, before issuing `CHANGE MASTER', either:
  24330.    * ensure that the SQL slave thread has read all existing relay logs;
  24331.      you can achive this by stopping only the I/O slave thread (`STOP
  24332.      SLAVE IO_THREAD'), then monitoring the progress of the running SQL
  24333.      slave thread with `SHOW SLAVE STATUS' and `SELECT
  24334.      MASTER_POS_WAIT()', until it has caught up. This way there will be
  24335.      no leap for the SQL slave thread.
  24336.  
  24337.    * run `STOP SLAVE', check where the SQL slave thread is in the
  24338.      master's binlog (using `SHOW SLAVE STATUS', columns
  24339.      `Relay_Master_Log_File' and `Exec_master_log_pos'), and add a
  24340.      specification of these coordinates to the `CHANGE MASTER' command
  24341.      (`MASTER_LOG_FILE=..., MASTER_LOG_POS=...').  This way, you will
  24342.      instruct the I/O slave thread to start replication from the former
  24343.      coordinates of the SQL slave thread, so there will be no leap for
  24344.      the SQL slave thread.
  24345. If you don't take care of this issue, even a simple `STOP SLAVE; CHANGE
  24346. MASTER TO MASTER_USER='repl'; START SLAVE;' run in the middle of an
  24347. highly-loaded replication could break this replication and spoil the
  24348. slave's data.
  24349.  
  24350. `CHANGE MASTER' is useful for setting up a slave when you have the
  24351. snapshot of the master and have recorded the log and the offset on the
  24352. master that the snapshot corresponds to. You can run  `CHANGE MASTER TO
  24353. MASTER_LOG_FILE='log_name_on_master',
  24354. MASTER_LOG_POS=log_offset_on_master' on the slave after restoring the
  24355. snapshot.
  24356.  
  24357. The first example above (`CHANGE MASTER TO
  24358. MASTER_HOST='master2.mycompany.com' etc') changes the master and
  24359. master's binlog coordinates. This is when you want the slave to
  24360. replicate the master.  The second example, less frequently used, is
  24361. when the slave has relay logs which, for some reason, you want the
  24362. slave to execute again; to do this the master needn't be reachable, you
  24363. just have to do `CHANGE MASTER TO' and start the SQL thread (`START
  24364. SLAVE SQL_THREAD').  You can even use this out of a replication setup,
  24365. on a standalone, slave-of-nobody server, to recover after a crash.
  24366. Suppose your server has crashed and you have restored a backup.  You
  24367. want to replay the server's own binlogs (not relay logs, but regular
  24368. binary logs), supposedly named `myhost-bin.*'. First make a backup copy
  24369. of these binlogs in some safe place, in case you don't exactly follow
  24370. the procedure below and accidentally have the server purge the binlogs.
  24371. If using MySQL 4.1.1 or newer, do `SET GLOBAL RELAY_LOG_PURGE=0' for
  24372. additional safety.  Then start the server without `log-bin', with a new
  24373. (different from before) server id, with `relay-log=myhost-bin' (to make
  24374. the server believe that these regular binlogs are relay logs) and
  24375. `skip-slave-start', then issue
  24376.  
  24377.      CHANGE MASTER TO RELAY_LOG_FILE='myhost-bin.153',RELAY_LOG_POS=410, MASTER_HOST='some_dummy_string';
  24378.      START SLAVE SQL_THREAD;
  24379.  
  24380. Then the server will read and execute its own binlogs, thus achieving
  24381. crash recovery.  Once the recovery is finished, run `STOP SLAVE',
  24382. shutdown the server, delete `master.info' and `relay-log.info', and
  24383. restart the server with its original options.  For the moment,
  24384. specifying `MASTER_HOST' (even with a dummy value) is compulsory to
  24385. make the server think he is a slave, and giving the server a new,
  24386. different from before, server id is also compulsory otherwise the
  24387. server will see events with its id and think it is in a circular
  24388. replication setup and skip the events, which is unwanted. In the future
  24389. we plan to add options to get rid of these small constraints.
  24390.  
  24391. `MASTER_POS_WAIT()' (slave)
  24392. ...........................
  24393.  
  24394. This is not a command but a function, used to ensure that the slave has
  24395. reached (read and executed up to) a given position in the master's
  24396. binlog; see *Note Miscellaneous functions:: for a full description.
  24397.  
  24398. `SHOW MASTER STATUS' (master)
  24399. .............................
  24400.  
  24401. Provides status information on the binlog of the master.
  24402.  
  24403. `SHOW SLAVE HOSTS' (master)
  24404. ...........................
  24405.  
  24406. Gives a listing of slaves currently registered with the master.
  24407.  
  24408. `SHOW SLAVE STATUS' (slave)
  24409. ...........................
  24410.  
  24411. Provides status information on essential parameters of the slave
  24412. threads (Slave). If you type it in the `mysql' client, you can put a
  24413. `\G' instead of a semicolon at the end, to get a vertical, more
  24414. readable layout:
  24415.  
  24416.      SLAVE> show slave status\G
  24417.      *************************** 1. row ***************************
  24418.                Master_Host: localhost
  24419.                Master_User: root
  24420.                Master_Port: 3306
  24421.              Connect_retry: 3
  24422.            Master_Log_File: gbichot-bin.005
  24423.        Read_Master_Log_Pos: 79
  24424.             Relay_Log_File: gbichot-relay-bin.005
  24425.              Relay_Log_Pos: 548
  24426.      Relay_Master_Log_File: gbichot-bin.005
  24427.           Slave_IO_Running: Yes
  24428.          Slave_SQL_Running: Yes
  24429.            Replicate_do_db:
  24430.        Replicate_ignore_db:
  24431.                 Last_errno: 0
  24432.                 Last_error:
  24433.               Skip_counter: 0
  24434.        Exec_master_log_pos: 79
  24435.            Relay_log_space: 552
  24436.      1 row in set (0.00 sec)
  24437.  
  24438.    * `Master_Host' the current master host.
  24439.  
  24440.    * `Master_User' the current user used to connect to the master.
  24441.  
  24442.    * `Master_Port' the current master port.
  24443.  
  24444.    * `Connect_Retry' the current value of `master-connect-retry'.
  24445.  
  24446.    * `Master_Log_File' the master's binlog in which the I/O thread is
  24447.      currently reading.
  24448.  
  24449.    * `Read_Master_Log_Pos' the position which the I/O thread has read
  24450.      up to in this master's binlog.
  24451.  
  24452.    * `Relay_Log_File' the relay log which the SQL thread is currently
  24453.      reading and executing.
  24454.  
  24455.    * `Relay_Log_Pos' the position which the SQL thread has read and
  24456.      executed up to in this relay log.
  24457.  
  24458.    * `Relay_Master_Log_File' the master's binlog which contains the
  24459.      last event executed by the SQL thread.
  24460.  
  24461.    * `Slave_IO_Running' tells whether the I/O thread is started or not.
  24462.  
  24463.    * `Slave_SQL_Running' tells whether the SQL thread is started or not.
  24464.  
  24465.    * `Replicate_do_db' / `Replicate_ignore_db' the lists of the
  24466.      databases which have been specified with option `replicate-do-db'
  24467.      / `replicate-ignore-db'; starting from version 4.1, options
  24468.      `replicate_*_table' are also displayed in four more columns.
  24469.  
  24470.    * `Last_errno' the error number returned by the lastly executed
  24471.      query (should be 0).
  24472.  
  24473.    * `Last_error' the error message returned by the lastly executed
  24474.      query (should be empty); if not empty, you will find this message
  24475.      in the slave's error log too. For example:
  24476.           Last_errno: 1051
  24477.           Last_error: error 'Unknown table 'z'' on query 'drop table z'
  24478.      Here the table 'z' existed on the master and was dropped there,
  24479.      but it did not exist on the slave (the user had forgotten to copy
  24480.      it to the slave when setting the slave up), so `DROP TABLE' failed
  24481.      on the slave.
  24482.  
  24483.    * `Skip_counter' the last used value for `SQL_SLAVE_SKIP_COUNTER'.
  24484.  
  24485.    * `Exec_master_log_pos' the position in the master's binlog
  24486.      (`Relay_Master_Log_File') of the last event executed by the SQL
  24487.      thread.  ((`Relay_Master_Log_File',`Exec_master_log_pos') in the
  24488.      master's binlog corresponds to (`Relay_Log_File',`Relay_Log_Pos')
  24489.      in the relay log).
  24490.  
  24491.    * `Relay_log_space' the total size of all existing relay logs.
  24492.  
  24493. `SHOW MASTER LOGS' (master)
  24494. ...........................
  24495.  
  24496. Lists the binary logs on the master. You should use this command prior
  24497. to `PURGE MASTER LOGS' to find out how far you should go.
  24498.  
  24499. `SHOW BINLOG EVENTS' (master)
  24500. .............................
  24501.  
  24502. `SHOW BINLOG EVENTS [ IN 'logname' ] [ FROM pos ] [ LIMIT [offset,]
  24503. rows ] '
  24504.  
  24505. Shows the events in the binary log.  If you do not specify `'logname'',
  24506. the first binary log will be displayed.
  24507.  
  24508. `PURGE MASTER LOGS' (master)
  24509. ............................
  24510.  
  24511. `PURGE MASTER|BINARY LOGS TO 'logname' ; PURGE MASTER|BINARY LOGS
  24512. BEFORE 'date''
  24513.  
  24514. The `BEFORE' variant is available in MySQL 4.1; its date argument can
  24515. be in format 'YYYY-MM-DD HH:MI:SS'.  `MASTER' and `BINARY' are here
  24516. synonyms.  Deletes all the binary logs that are listed in the log index
  24517. as being strictly prior to the specified log or date, and removes them
  24518. from the log index, so that the given log now becomes the first.
  24519. Example:
  24520.  
  24521.      PURGE MASTER LOGS TO 'mysql-bin.010' ;
  24522.      PURGE MASTER LOGS BEFORE '2003-04-02 22:46:26' ;
  24523.  
  24524. This command will do nothing and fail with an error if you have an
  24525. active slave that is currently reading one of the logs you are trying to
  24526. delete. However, if you have a dormant slave, and happen to purge one of
  24527. the logs it wants to read, the slave will be unable to replicate once it
  24528. comes up.  The command is safe to run while slaves are replicating - you
  24529. do not need to stop them.
  24530.  
  24531. You must first check all the slaves with `SHOW SLAVE STATUS' to see
  24532. which log they are on, then do a listing of the logs on the master with
  24533. `SHOW MASTER LOGS', find the earliest log among all the slaves (if all
  24534. the slaves are up to date, this will be the last log on the list),
  24535. backup all the logs you are about to delete (optional) and purge up to
  24536. the target log.
  24537.  
  24538. Replication FAQ
  24539. ---------------
  24540.  
  24541. *Q*: How do I configure a slave if the master is already running and I
  24542. do not want to stop it?
  24543.  
  24544. *A*: There are several options. If you have taken a backup of the
  24545. master at some point and recorded the binlog name and offset ( from the
  24546. output of `SHOW MASTER STATUS' ) corresponding to the snapshot, do the
  24547. following:
  24548.  
  24549.    * Make sure unique server id is assigned to the slave.
  24550.  
  24551.    * Execute `CHANGE MASTER TO MASTER_HOST='master-host-name',
  24552.      MASTER_USER='master-user-name', MASTER_PASSWORD='master-pass',
  24553.      MASTER_LOG_FILE='recorded-log-name',
  24554.      MASTER_LOG_POS=recorded_log_pos'
  24555.  
  24556.    * Execute `SLAVE START'
  24557.  
  24558. If you do not have a backup of the master already, here is a quick way
  24559. to do it consistently:
  24560.  
  24561.    * `FLUSH TABLES WITH READ LOCK'
  24562.  
  24563.    * `gtar zcf /tmp/backup.tar.gz /var/lib/mysql' ( or a variation of
  24564.      this)
  24565.  
  24566.    * `SHOW MASTER STATUS' - make sure to record the output - you will
  24567.      need it later
  24568.  
  24569.    * `UNLOCK TABLES'
  24570.  
  24571. An alternative is taking an SQL dump of the master instead of a binary
  24572. copy like above; for this you can use `mysqldump --master-data' on your
  24573. master and later run this SQL dump into your slave. This is however
  24574. slower than doing a binary copy.
  24575.  
  24576. No matter which of the two ways you used, afterwards follow the
  24577. instructions for the case when you have a snapshot and have recorded
  24578. the log name and offset. You can use the same snapshot to set up
  24579. several slaves. As long as the binary logs of the master are left
  24580. intact, you can wait as long as several days or in some cases maybe a
  24581. month to set up a slave once you have the snapshot of the master. In
  24582. theory the waiting gap can be infinite. The two practical limitations
  24583. is the diskspace of the master getting filled with old logs, and the
  24584. amount of time it will take the slave to catch up.
  24585.  
  24586. You can also use `LOAD DATA FROM MASTER'.  This is a convenient command
  24587. that will take a snapshot, restore it to the slave, and adjust the log
  24588. name and offset on the slave all at once. In the future, `LOAD DATA
  24589. FROM MASTER' will be the recommended way to set up a slave.  Be warned,
  24590. howerver, that the read lock may be held for a long time if you use
  24591. this command. It is not yet implemented as efficiently as we would like
  24592. to have it. If you have large tables, the preferred method at this time
  24593. is still with a local `tar' snapshot after executing `FLUSH TABLES WITH
  24594. READ LOCK'.
  24595.  
  24596. *Q*: Does the slave need to be connected to the master all the time?
  24597.  
  24598. *A*: No, it does not. You can have the slave go down or stay
  24599. disconnected for hours or even days, then reconnect, catch up on the
  24600. updates, and then disconnect or go down for a while again. So you can,
  24601. for example, use master-slave setup over a dial-up link that is up only
  24602. for short periods of time. The implications of that are that at any
  24603. given time the slave is not guaranteed to be in sync with the master
  24604. unless you take some special measures. In the future, we will have the
  24605. option to block the master until at least one slave is in sync.
  24606.  
  24607. *Q*: How do I know how late the slave is compared to the master? In
  24608. other words, how do I know the date of the last query replicated by the
  24609. slave?
  24610.  
  24611. *A*: This is possible only if the SQL slave thread exists (that is, if
  24612. it shows up in `SHOW PROCESSLIST', *note Replication Implementation
  24613. Details::) (in MySQL 3.23: if the slave thread exists, that is, shows
  24614. up in `SHOW PROCESSLIST'), and if it has executed at least one event
  24615. from the master. Indeed, when the SQL slave thread executes an event
  24616. read from the master, this thread modifies its own time to the event's
  24617. timestamp (this is why `TIMESTAMP' is well replicated). So in the
  24618. `Time' column in the output of `SHOW PROCESSLIST', the number of
  24619. seconds displayed for the SQL slave thread is the number of seconds
  24620. between the timestamp of the last replicated event and the real time of
  24621. the slave machine. You can use this to determine the date of the last
  24622. replicated event. Note that if your slave has been disconnected from
  24623. the master for one hour, then reconnects, you may immediately see
  24624. `Time' values like 3600 for the SQL slave thread in `SHOW
  24625. PROCESSLIST'... This would be because the slave is executing queries
  24626. that are one hour old.
  24627.  
  24628. *Q*: How do I force the master to block updates until the slave catches
  24629. up?
  24630.  
  24631. *A*: Execute the following commands:
  24632.  
  24633.    * Master: `FLUSH TABLES WITH READ LOCK'
  24634.  
  24635.    * Master: `SHOW MASTER STATUS' - record the log name and the offset
  24636.  
  24637.    * Slave: `SELECT MASTER_POS_WAIT('recorded_log_name',
  24638.      recorded_log_offset)' When the select returns, the slave is
  24639.      currently in sync with the master
  24640.  
  24641.    * Master: `UNLOCK TABLES' - now the master will continue updates.
  24642.  
  24643. *Q*: What issues should I be aware of when setting up two-way
  24644. replication?
  24645.  
  24646. *A*: MySQL replication currently does not support any locking protocol
  24647. between master and slave to guarantee the atomicity of a distributed
  24648. (cross-server) update. In other words, it is possible for client A to
  24649. make an update to  co-master 1, and in the meantime, before it
  24650. propagates to co-master 2, client B could make an update to co-master 2
  24651. that will make the update of client A work differently than it did on
  24652. co-master 1. Thus when the update of client A will make it to co-master
  24653. 2, it will produce  tables that will be different from what you have on
  24654. co-master 1, even after all the updates from co-master 2 have also
  24655. propagated. So you should not co-chain two servers in a two-way
  24656. replication relationship, unless you are sure that you updates can
  24657. safely happen in any order, or unless you take care of mis-ordered
  24658. updates somehow in the client code.
  24659.  
  24660. You must also realise that two-way replication actually does not improve
  24661. performance very much, if at all, as far as updates are concerned. Both
  24662. servers need to do the same amount of updates each, as you would have
  24663. one server do. The only difference is that there will be a little less
  24664. lock contention, because the updates originating on another server will
  24665. be serialised in one slave thread. This benefit, though, might be
  24666. offset by network delays.
  24667.  
  24668. *Q*: How can I use replication to improve performance of my system?
  24669.  
  24670. *A*: You should set up one server as the master, and direct all writes
  24671. to it, and configure as many slaves as you have the money and rackspace
  24672. for, distributing the reads among the master and the slaves.  You can
  24673. also start the slaves with `--skip-bdb', `--low-priority-updates' and
  24674. `--delay-key-write=ALL' to get speed improvements for the slave.  In
  24675. this case the slave will use non-transactional `MyISAM' tables instead
  24676. of `BDB' tables to get more speed.
  24677.  
  24678. *Q*: What should I do to prepare my client code to use
  24679. performance-enhancing replication?
  24680.  
  24681. *A*: If the part of your code that is responsible for database access
  24682. has been properly abstracted/modularised, converting it to run with the
  24683. replicated setup should be very smooth and easy - just change the
  24684. implementation of your database access to read from some slave or the
  24685. master, and to always write to the master. If your code does not have
  24686. this level of abstraction, setting up a replicated system will give you
  24687. an opportunity/motivation to it clean up.   You should start by
  24688. creating a wrapper library /module with the following functions:
  24689.  
  24690.    * `safe_writer_connect()'
  24691.  
  24692.    * `safe_reader_connect()'
  24693.  
  24694.    * `safe_reader_query()'
  24695.  
  24696.    * `safe_writer_query()'
  24697.  
  24698. `safe_' means that the function will take care of handling all the
  24699. error conditions.
  24700.  
  24701. You should then convert your client code to use the wrapper library.
  24702. It may be a painful and scary process at first, but it will pay off in
  24703. the long run. All applications that follow the above pattern will be
  24704. able to take advantage of one-master/many slaves solution.  The code
  24705. will be a lot easier to maintain, and adding troubleshooting options
  24706. will be trivial. You will ju