home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2004 January / INTERNET113.ISO / pc / software / windows / building / mysql / data1.cab / Documentation / Docs / manual.txt < prev   
Encoding:
Text File  |  2003-10-20  |  2.7 MB  |  69,813 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.     Contact Information
  26.   MySQL Support and Licensing
  27.     Support Offered by MySQL AB
  28.     Copyrights and Licenses Used by MySQL
  29.     MySQL Licenses
  30.       Using the MySQL Software Under a Commercial License
  31.       Using the MySQL Software for Free Under GPL
  32.     MySQL AB Logos and Trademarks
  33.       The Original MySQL Logo
  34.       MySQL Logos that may be Used Without Written Permission
  35.       When do you need a Written Permission to use MySQL Logos?
  36.       MySQL AB Partnership Logos
  37.       Using the word `MySQL' in Printed Text or Presentations
  38.       Using the word `MySQL' in Company and Product Names
  39.   MySQL Development Roadmap
  40.     MySQL 4.0 in a Nutshell
  41.       Features Available in MySQL 4.0
  42.       Embedded MySQL Server
  43.     MySQL 4.1 in a Nutshell
  44.       Features Available in MySQL 4.1
  45.       Stepwise Rollout
  46.       Ready for Immediate Development Use
  47.     MySQL 5.0, The Next Development Release
  48.   MySQL Information Sources
  49.     MySQL Mailing Lists
  50.       The MySQL Mailing Lists
  51.       Asking Questions or Reporting Bugs
  52.       How to Report Bugs or Problems
  53.       Guidelines for Answering Questions on the Mailing List
  54.     MySQL Community Support on IRC (Internet Relay Chat)
  55.   MySQL Standards Compliance
  56.     What Standards Does MySQL Follow?
  57.     Running MySQL in ANSI Mode
  58.     MySQL Extensions to the SQL-92 Standard
  59.     MySQL Differences Compared to SQL-92
  60.       Subqueries
  61.       `SELECT INTO TABLE'
  62.       Transactions and Atomic Operations
  63.       Stored Procedures and Triggers
  64.       Foreign Keys
  65.       Views
  66.       `--' as the Start of a Comment
  67.     How MySQL deals with constraints
  68.       Constraint PRIMARY KEY / UNIQUE
  69.       Constraint `NOT NULL' and `DEFAULT' values
  70.       Constraint `ENUM' and `SET'
  71.     Known Errors and Design Deficiencies in MySQL
  72.       Errors in 3.23 Fixed in a Later MySQL Version
  73.       Open Bugs / Design Deficiencies in MySQL
  74.   MySQL and the Future (The TODO)
  75.     New Features Planned For 4.1
  76.     New Features Planned For 5.0
  77.     New Features Planned For 5.1
  78.     New Features Planned for the Near Future
  79.     New Features Planned for the Mid-Term Future
  80.     New Features We Don't Plan to Do
  81.  
  82. Installing MySQL
  83.   Quick Standard Installation of MySQL
  84.     Installing MySQL on Windows
  85.       Installing the Binaries
  86.       Preparing the Windows MySQL Environment
  87.       Starting the Server for the First Time
  88.     Installing MySQL on Linux
  89.     Installing MySQL on Mac OS X
  90.     Installing MySQL on NetWare
  91.       Installing the MySQL for NetWare Binaries
  92.   General Installation Issues
  93.     How to Get MySQL
  94.     Verifying Package Integrity Using `MD5 Checksums' or `GnuPG'
  95.     Operating Systems Supported by MySQL
  96.     Which MySQL Version to Use
  97.     Installation Layouts
  98.     How and When Updates Are Released
  99.     Release Philosophy - No Known Bugs in Releases
  100.     MySQL Binaries Compiled by MySQL AB
  101.     Installing a MySQL Binary Distribution
  102.   Installing a MySQL Source Distribution
  103.     Quick Installation Overview
  104.     Applying Patches
  105.     Typical `configure' Options
  106.     Installing from the Development Source Tree
  107.     Problems Compiling MySQL?
  108.     MIT-pthreads Notes
  109.     Windows Source Distribution
  110.   Post-installation Setup and Testing
  111.     Problems Running `mysql_install_db'
  112.     Problems Starting the MySQL Server
  113.     Starting and Stopping MySQL Automatically
  114.   Upgrading/Downgrading MySQL
  115.     Upgrading From Version 4.0 to 4.1
  116.     Upgrading From Version 3.23 to 4.0
  117.     Upgrading From Version 3.22 to 3.23
  118.     Upgrading from Version 3.21 to 3.22
  119.     Upgrading from Version 3.20 to 3.21
  120.     Upgrading the Grant Tables
  121.     Upgrading to Another Architecture
  122.     Upgrading MySQL under Windows
  123.   Operating System Specific Notes
  124.     Windows Notes
  125.       Starting MySQL on Windows 95, 98, or Me
  126.       Starting MySQL on Windows NT, 2000, or XP
  127.       Running MySQL on Windows
  128.       Connecting to MySQL Remotely from Windows with SSH
  129.       Distributing Data Across Different Disks on Windows
  130.       Compiling MySQL Clients on Windows
  131.       MySQL for Windows Compared to Unix MySQL
  132.     Linux Notes (All Linux Versions)
  133.       Linux Notes for Binary Distributions
  134.       Linux x86 Notes
  135.       Linux SPARC Notes
  136.       Linux Alpha Notes
  137.       Linux PowerPC Notes
  138.       Linux MIPS Notes
  139.       Linux IA-64 Notes
  140.     Solaris Notes
  141.       Solaris 2.7/2.8 Notes
  142.       Solaris x86 Notes
  143.     BSD Notes
  144.       FreeBSD Notes
  145.       NetBSD Notes
  146.       OpenBSD 2.5 Notes
  147.       OpenBSD 2.8 Notes
  148.       BSD/OS Version 2.x Notes
  149.       BSD/OS Version 3.x Notes
  150.       BSD/OS Version 4.x Notes
  151.     Mac OS X Notes
  152.       Mac OS X 10.x
  153.       Mac OS X Server 1.2 (Rhapsody)
  154.     Other Unix Notes
  155.       HP-UX Notes for Binary Distributions
  156.       HP-UX Version 10.20 Notes
  157.       HP-UX Version 11.x Notes
  158.       IBM-AIX notes
  159.       SunOS 4 Notes
  160.       Alpha-DEC-UNIX Notes (Tru64)
  161.       Alpha-DEC-OSF/1 Notes
  162.       SGI Irix Notes
  163.       SCO Notes
  164.       SCO UnixWare Version 7.1.x Notes
  165.     OS/2 Notes
  166.     Novell NetWare Notes
  167.     BeOS Notes
  168.   Perl Installation Comments
  169.     Installing Perl on Unix
  170.     Installing ActiveState Perl on Windows
  171.     Problems Using the Perl `DBI'/`DBD' Interface
  172.  
  173. MySQL Tutorial
  174.   Connecting to and Disconnecting from the Server
  175.   Entering Queries
  176.   Creating and Using a Database
  177.     Creating and Selecting a Database
  178.     Creating a Table
  179.     Loading Data into a Table
  180.     Retrieving Information from a Table
  181.       Selecting All Data
  182.       Selecting Particular Rows
  183.       Selecting Particular Columns
  184.       Sorting Rows
  185.       Date Calculations
  186.       Working with `NULL' Values
  187.       Pattern Matching
  188.       Counting Rows
  189.       Using More Than one Table
  190.   Getting Information About Databases and Tables
  191.   Using `mysql' in Batch Mode
  192.   Examples of Common Queries
  193.     The Maximum Value for a Column
  194.     The Row Holding the Maximum of a Certain Column
  195.     Maximum of Column per Group
  196.     The Rows Holding the Group-wise Maximum of a Certain Field
  197.     Using User Variables
  198.     Using Foreign Keys
  199.     Searching on Two Keys
  200.     Calculating Visits Per Day
  201.     Using `AUTO_INCREMENT'
  202.   Queries from the Twin Project
  203.     Find All Non-distributed Twins
  204.     Show a Table of Twin Pair Status
  205.   Using MySQL with Apache
  206.  
  207. Database Administration
  208.   Configuring MySQL
  209.     `mysqld' Command-line Options
  210.     `my.cnf' Option Files
  211.     Running Multiple MySQL Servers on the Same Machine
  212.       Running Multiple Servers on Windows
  213.       Running Multiple Servers on Unix
  214.       Using Client Programs in a Multiple-Server Environment
  215.   General Security Issues and the MySQL Access Privilege System
  216.     General Security Guidelines
  217.     How to Make MySQL Secure Against Crackers
  218.     Startup Options for `mysqld' Concerning Security
  219.     Security issues with `LOAD DATA LOCAL'
  220.     What the Privilege System Does
  221.     How the Privilege System Works
  222.     Privileges Provided by MySQL
  223.     Connecting to the MySQL Server
  224.     Access Control, Stage 1: Connection Verification
  225.     Access Control, Stage 2: Request Verification
  226.     Password Hashing in MySQL 4.1
  227.     Causes of `Access denied' Errors
  228.   MySQL User Account Management
  229.     `GRANT' and `REVOKE' Syntax
  230.     MySQL User Names and Passwords
  231.     When Privilege Changes Take Effect
  232.     Setting Up the Initial MySQL Privileges
  233.     Adding New Users to MySQL
  234.     Deleting Users from MySQL
  235.     Limiting user resources
  236.     Setting Up Passwords
  237.     Keeping Your Password Secure
  238.     Using Secure Connections
  239.       Basics
  240.       Requirements
  241.       Setting Up SSL Certificates for MySQL
  242.       SSL `GRANT' Options
  243.       SSL Command-line 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 Startup Options
  324.     SQL Statements for Controlling Master Servers
  325.       `PURGE MASTER LOGS'
  326.       `RESET MASTER'
  327.       `SET SQL_LOG_BIN'
  328.       `SHOW BINLOG EVENTS'
  329.       `SHOW MASTER STATUS'
  330.       `SHOW MASTER LOGS'
  331.       `SHOW SLAVE HOSTS'
  332.     SQL Statements for Controlling Slave Servers
  333.       `CHANGE MASTER TO'
  334.       `LOAD DATA FROM MASTER'
  335.       `LOAD TABLE tbl_name FROM MASTER'
  336.       `MASTER_POS_WAIT()'
  337.       `RESET SLAVE'
  338.       `SET GLOBAL SQL_SLAVE_SKIP_COUNTER'
  339.       `SHOW SLAVE STATUS'
  340.       `START SLAVE'
  341.       `STOP SLAVE'
  342.     Replication FAQ
  343.     Troubleshooting Replication
  344.     Reporting Replication Bugs
  345.  
  346. MySQL Optimisation
  347.   Optimisation Overview
  348.     MySQL Design Limitations/Tradeoffs
  349.     Portability
  350.     What Have We Used MySQL For?
  351.     The MySQL Benchmark Suite
  352.     Using Your Own Benchmarks
  353.   Optimising `SELECT's and Other Queries
  354.     `EXPLAIN' Syntax (Get Information About a `SELECT')
  355.     Estimating Query Performance
  356.     Speed of `SELECT' Queries
  357.     How MySQL Optimises `WHERE' Clauses
  358.     How MySQL Optimises `IS NULL'
  359.     How MySQL Optimises `DISTINCT'
  360.     How MySQL Optimises `LEFT JOIN' and `RIGHT JOIN'
  361.     How MySQL Optimises `ORDER BY'
  362.     How MySQL Optimises `LIMIT'
  363.     Speed of `INSERT' Queries
  364.     Speed of `UPDATE' Queries
  365.     Speed of `DELETE' Queries
  366.     Other Optimisation Tips
  367.   Locking Issues
  368.     How MySQL Locks Tables
  369.     Table Locking Issues
  370.   Optimising Database Structure
  371.     Design Choices
  372.     Get Your Data as Small as Possible
  373.     How MySQL Uses Indexes
  374.     Column Indexes
  375.     Multiple-Column Indexes
  376.     Why So Many Open tables?
  377.     How MySQL Opens and Closes Tables
  378.     Drawbacks to Creating Large Numbers of Tables in the Same Database
  379.   Optimising the MySQL Server
  380.     System/Compile Time and Startup Parameter Tuning
  381.     Tuning Server Parameters
  382.     How Compiling and Linking Affects the Speed of MySQL
  383.     How MySQL Uses Memory
  384.     How MySQL uses DNS
  385.     `SET' Syntax
  386.   Disk Issues
  387.     Using Symbolic Links
  388.       Using Symbolic Links for Databases
  389.       Using Symbolic Links for Tables
  390.  
  391. MySQL Language Reference
  392.   Language Structure
  393.     Literals: How to Write Strings and Numbers
  394.       Strings
  395.       Numbers
  396.       Hexadecimal Values
  397.       `NULL' Values
  398.     Database, Table, Index, Column, and Alias Names
  399.     Case Sensitivity in Names
  400.     User Variables
  401.     System Variables
  402.     Comment Syntax
  403.     Is MySQL Picky About Reserved Words?
  404.   Column Types
  405.     Numeric Types
  406.     Date and Time Types
  407.       Y2K Issues and Date Types
  408.       The `DATETIME', `DATE', and `TIMESTAMP' Types
  409.       The `TIME' Type
  410.       The `YEAR' Type
  411.     String Types
  412.       The `CHAR' and `VARCHAR' Types
  413.       The `BLOB' and `TEXT' Types
  414.       The `ENUM' Type
  415.       The `SET' Type
  416.     Choosing the Right Type for a Column
  417.     Using Column Types from Other Database Engines
  418.     Column Type Storage Requirements
  419.   Functions for Use in `SELECT' and `WHERE' Clauses
  420.     Non-Type-Specific Operators and Functions
  421.       Parentheses
  422.       Comparison Operators
  423.       Logical Operators
  424.       Control Flow Functions
  425.     String Functions
  426.       String Comparison Functions
  427.       Case-Sensitivity
  428.     Numeric Functions
  429.       Arithmetic Operations
  430.       Mathematical Functions
  431.     Date and Time Functions
  432.     Cast Functions
  433.     Other Functions
  434.       Bit Functions
  435.       Miscellaneous Functions
  436.     Functions and Modifiers for Use with `GROUP BY' Clauses
  437.       `GROUP BY' Functions
  438.       `GROUP BY' Modifiers
  439.       `GROUP BY' with Hidden Fields
  440.   Data Manipulation: `SELECT', `INSERT', `UPDATE', `DELETE'
  441.     `SELECT' Syntax
  442.       `JOIN' Syntax
  443.       `UNION' Syntax
  444.     `HANDLER' Syntax
  445.     `INSERT' Syntax
  446.       `INSERT ... SELECT' Syntax
  447.       `INSERT DELAYED' Syntax
  448.     `UPDATE' Syntax
  449.     `DELETE' Syntax
  450.     `TRUNCATE' Syntax
  451.     `REPLACE' Syntax
  452.     `LOAD DATA INFILE' Syntax
  453.     `DO' Syntax
  454.   Data Definition: `CREATE', `DROP', `ALTER'
  455.     `CREATE DATABASE' Syntax
  456.     `DROP DATABASE' Syntax
  457.     `CREATE TABLE' Syntax
  458.       Silent Column Specification Changes
  459.     `ALTER TABLE' Syntax
  460.     `RENAME TABLE' Syntax
  461.     `DROP TABLE' Syntax
  462.     `CREATE INDEX' Syntax
  463.     `DROP INDEX' Syntax
  464.   Basic MySQL User Utility Commands
  465.     `USE' Syntax
  466.     `DESCRIBE' Syntax (Get Information About Columns)
  467.   MySQL Transactional and Locking Commands
  468.     `START TRANSACTION', `COMMIT', and `ROLLBACK' Syntax
  469.     Statements That Cannot Be Rolled Back
  470.     Statements That Cause an Implicit Commit
  471.     `SAVEPOINT' and `ROLLBACK TO SAVEPOINT' Syntax
  472.     `LOCK TABLES' and `UNLOCK TABLES' Syntax
  473.     `SET TRANSACTION' Syntax
  474.   MySQL Full-text Search
  475.     Full-text Restrictions
  476.     Fine-tuning MySQL Full-text Search
  477.     Full-text Search TODO
  478.   MySQL Query Cache
  479.     How the Query Cache Operates
  480.     Query Cache Configuration
  481.     Query Cache Options in `SELECT'
  482.     Query Cache Status and Maintenance
  483.  
  484. MySQL Table Types
  485.   `MyISAM' Tables
  486.     Space Needed for Keys
  487.     `MyISAM' Table Formats
  488.       Static (Fixed-length) Table Characteristics
  489.       Dynamic Table Characteristics
  490.       Compressed Table Characteristics
  491.     `MyISAM' Table Problems
  492.       Corrupted `MyISAM' Tables
  493.       Clients is using or hasn't closed the table properly
  494.   `MERGE' Tables
  495.     `MERGE' Table Problems
  496.   `ISAM' Tables
  497.   `HEAP' Tables
  498.   `InnoDB' Tables
  499.     InnoDB Tables Overview
  500.     InnoDB in MySQL Version 3.23
  501.     InnoDB Startup Options
  502.     Creating InnoDB Tablespace
  503.       If Something Goes Wrong in Database Creation
  504.     Creating InnoDB Tables
  505.       Converting MyISAM Tables to InnoDB
  506.       `FOREIGN KEY' Constraints
  507.     Adding and Removing InnoDB Data and Log Files
  508.     Backing up and Recovering an InnoDB Database
  509.       Forcing recovery
  510.       Checkpoints
  511.     Moving an InnoDB Database to Another Machine
  512.     InnoDB Transaction Model and Locking
  513.       InnoDB and `SET ... TRANSACTION ISOLATION LEVEL ...'
  514.       Consistent Non-Locking Read
  515.       Locking Reads `SELECT ... FOR UPDATE' and `SELECT ... LOCK IN SHARE MODE'
  516.       Next-key Locking: Avoiding the Phantom Problem
  517.       Locks Set by Different SQL Statements in `InnoDB'
  518.       Deadlock Detection and Rollback
  519.       An Example of How the Consistent Read Works in `InnoDB'
  520.       How to cope with deadlocks?
  521.     Performance Tuning Tips
  522.       `SHOW INNODB STATUS' and the `InnoDB' Monitors
  523.     Implementation of Multi-versioning
  524.     Table and Index Structures
  525.       Physical Structure of an Index
  526.       Insert Buffering
  527.       Adaptive Hash Indexes
  528.       Physical Record Structure
  529.       How an `AUTO_INCREMENT' Column Works in InnoDB
  530.     File Space Management and Disk I/O
  531.       Disk I/O
  532.       File Space Management
  533.       Defragmenting a Table
  534.     Error Handling
  535.     Restrictions on InnoDB Tables
  536.     InnoDB Change History
  537.       MySQL/InnoDB-4.0.14, July 22, 2003
  538.       MySQL/InnoDB-3.23.57, June 20, 2003
  539.       MySQL/InnoDB-4.0.13, May 20, 2003
  540.       MySQL/InnoDB-4.1.0, April 3, 2003
  541.       MySQL/InnoDB-3.23.56, March 17, 2003
  542.       MySQL/InnoDB-4.0.12, March 18, 2003
  543.       MySQL/InnoDB-4.0.11, February 25, 2003
  544.       MySQL/InnoDB-4.0.10, February 4, 2003
  545.       MySQL/InnoDB-3.23.55, January 24, 2003
  546.       MySQL/InnoDB-4.0.9, January 14, 2003
  547.       MySQL/InnoDB-4.0.8, January 7, 2003
  548.       MySQL/InnoDB-4.0.7, December 26, 2002
  549.       MySQL/InnoDB-4.0.6, December 19, 2002
  550.       MySQL/InnoDB-3.23.54, December 12, 2002
  551.       MySQL/InnoDB-4.0.5, November 18, 2002
  552.       MySQL/InnoDB-3.23.53, October 9, 2002
  553.       MySQL/InnoDB-4.0.4, October 2, 2002
  554.       MySQL/InnoDB-4.0.3, August 28, 2002
  555.       MySQL/InnoDB-3.23.52, August 16, 2002
  556.       MySQL/InnoDB-4.0.2, July 10, 2002
  557.       MySQL/InnoDB-3.23.51, June 12, 2002
  558.       MySQL/InnoDB-3.23.50, April 23, 2002
  559.       MySQL/InnoDB-3.23.49, February 17, 2002
  560.       MySQL/InnoDB-3.23.48, February 9, 2002
  561.       MySQL/InnoDB-3.23.47, December 28, 2001
  562.       MySQL/InnoDB-4.0.1, December 23, 2001
  563.       MySQL/InnoDB-3.23.46, November 30, 2001
  564.       MySQL/InnoDB-3.23.45, November 23, 2001
  565.       MySQL/InnoDB-3.23.44, November 2, 2001
  566.       MySQL/InnoDB-3.23.43, October 4, 2001
  567.       MySQL/InnoDB-3.23.42, September 9, 2001
  568.       MySQL/InnoDB-3.23.41, August 13, 2001
  569.       MySQL/InnoDB-3.23.40, July 16, 2001
  570.       MySQL/InnoDB-3.23.39, June 13, 2001
  571.       MySQL/InnoDB-3.23.38, May 12, 2001
  572.     `InnoDB' Contact Information
  573.   `BDB' or `BerkeleyDB' Tables
  574.     Overview of `BDB' Tables
  575.     Installing `BDB'
  576.     `BDB' startup options
  577.     Characteristics of `BDB' tables:
  578.     Things we need to fix for `BDB' in the near future:
  579.     Operating systems supported by `BDB'
  580.     Restrictions on `BDB' Tables
  581.     Errors That May Occur When Using `BDB' Tables
  582.  
  583. Introduction to MaxDB
  584.   History of MaxDB
  585.   Licensing and Support
  586.   Basic Concepts of MaxDB
  587.   Feature Differences between MaxDB and MySQL
  588.   Interoperability Features between MaxDB and MySQL
  589.   MaxDB-related Links
  590.   Reserved Words in MaxDB
  591.   Functions
  592.   Column Types
  593.  
  594. National Character Sets and Unicode
  595.   Character Sets and Collations in General
  596.   Character Sets and Collations in MySQL
  597.   Determining the Default Character Set and Collation
  598.     Server Character Set and Collation
  599.     Database Character Set and Collation
  600.     Table Character Set and Collation
  601.     Column Character Set and Collation
  602.     Examples of Character Set and Collation Assignment
  603.     Connection Character Sets and Collations
  604.     Character String Literal Character Set and Collation
  605.     `COLLATE' Clause in Various Parts of an SQL Query
  606.     `COLLATE' Clause Precedence
  607.     `BINARY' Operator
  608.     Some Special Cases Where the Collation Determination is Tricky
  609.     Collations Must Be for the Right Character Set
  610.     An example of the Effect of Collation
  611.   Operations Affected by Character Set Support
  612.     Result Strings
  613.     `CONVERT()'
  614.     `CAST()'
  615.     `SHOW CHARACTER SET'
  616.     `SHOW COLLATION'
  617.     `SHOW CREATE DATABASE'
  618.     `SHOW FULL COLUMNS'
  619.   Unicode Support
  620.   UTF8 for Metadata
  621.   Compatibility with Other DBMSs
  622.   New Character Set Configuration File format
  623.   National Character Set
  624.   Upgrading from MySQL 4.0
  625.     4.0 Character Sets and Corresponding 4.1 Character Set/Collation Pairs
  626.   The Character Sets and Collations that MySQL Supports
  627.     The Unicode Character Sets
  628.     Platform Specific Character Sets
  629.     Character Sets for South Europe and Middle East
  630.     The Asian Character Sets
  631.     The Baltic Character Sets
  632.     The Cyrillic Character Sets
  633.     The Central European Character Sets
  634.     The West European Character Sets
  635.  
  636. Spatial Extensions in MySQL
  637.   Introduction
  638.   The OpenGIS Geometry Model
  639.     The Geometry Class Hierarchy
  640.     Class `Geometry'
  641.     Class `Point'
  642.     Class `Curve'
  643.     Class `LineString'
  644.     Class `Surface'
  645.     Class `Polygon'
  646.     Class `GeometryCollection'
  647.     Class `MultiPoint'
  648.     Class `MultiCurve'
  649.     Class `MultiLineString'
  650.     Class `MultiSurface'
  651.     Class `MultiPolygon'
  652.   Supported Spatial Data Formats
  653.     Well-Known Text (WKT) Format
  654.     Well-Known Binary (WKB) Format
  655.   Creating a Spatially Enabled MySQL Database
  656.     MySQL Spatial Datatypes
  657.     Creating Spatial Values
  658.       Creating Geometry Values Using WKT Functions
  659.       Creating Geometry Values Using WKB Functions
  660.       Creating Geometry Values Using MySQL-Specific Functions
  661.     Creating Spatial Columns
  662.     Populating Spatial Columns
  663.     Fetching Spatial Data
  664.       Fetching Spatial Data in Internal Format
  665.       Fetching Spatial Data in WKT Format
  666.       Fetching Spatial Data in WKB Format
  667.   Analysing Spatial Information
  668.     Functions to Convert Geometries Between Formats
  669.     `Geometry' Property Analysis Functions
  670.       General Geometry Property Analysis Functions
  671.       `Point' Property Analysis Functions
  672.       `LineString' Property Analysis Functions
  673.       `MultiLineString' Property Analysis Functions
  674.       `Polygon' Property Analysis Functions
  675.       `MultiPolygon' Property Analysis Functions
  676.       `GeometryCollection' Property Analysis Functions
  677.     Functions That Create New Geometries From Existing Ones
  678.       Geometry Functions That Produce New Geometries
  679.       Spatial Operators
  680.     Functions For Testing Spatial Relations Between Geometric Objects
  681.     Relations On Geometry Minimal Bounding Rectangles (MBRs)
  682.     Functions That Test Spatial Relationships Between Geometries
  683.   Optimising Spatial Analysis
  684.     Creating Spatial Indexes
  685.     Using a Spatial Index
  686.   MySQL Conformance and Compatibility
  687.     GIS Features That Are Not Yet Implemented
  688.  
  689. MySQL APIs
  690.   MySQL C API
  691.     C API Datatypes
  692.     C API Function Overview
  693.     C API Function Descriptions
  694.       `mysql_affected_rows()'
  695.       `mysql_change_user()'
  696.       `mysql_character_set_name()'
  697.       `mysql_close()'
  698.       `mysql_connect()'
  699.       `mysql_create_db()'
  700.       `mysql_data_seek()'
  701.       `mysql_debug()'
  702.       `mysql_drop_db()'
  703.       `mysql_dump_debug_info()'
  704.       `mysql_eof()'
  705.       `mysql_errno()'
  706.       `mysql_error()'
  707.       `mysql_escape_string()'
  708.       `mysql_fetch_field()'
  709.       `mysql_fetch_fields()'
  710.       `mysql_fetch_field_direct()'
  711.       `mysql_fetch_lengths()'
  712.       `mysql_fetch_row()'
  713.       `mysql_field_count()'
  714.       `mysql_field_seek()'
  715.       `mysql_field_tell()'
  716.       `mysql_free_result()'
  717.       `mysql_get_client_info()'
  718.       `mysql_get_server_version()'
  719.       `mysql_get_host_info()'
  720.       `mysql_get_proto_info()'
  721.       `mysql_get_server_info()'
  722.       `mysql_info()'
  723.       `mysql_init()'
  724.       `mysql_insert_id()'
  725.       `mysql_kill()'
  726.       `mysql_list_dbs()'
  727.       `mysql_list_fields()'
  728.       `mysql_list_processes()'
  729.       `mysql_list_tables()'
  730.       `mysql_num_fields()'
  731.       `mysql_num_rows()'
  732.       `mysql_options()'
  733.       `mysql_ping()'
  734.       `mysql_query()'
  735.       `mysql_real_connect()'
  736.       `mysql_real_escape_string()'
  737.       `mysql_real_query()'
  738.       `mysql_reload()'
  739.       `mysql_row_seek()'
  740.       `mysql_row_tell()'
  741.       `mysql_select_db()'
  742.       `mysql_sqlstate()'
  743.       `mysql_shutdown()'
  744.       `mysql_stat()'
  745.       `mysql_store_result()'
  746.       `mysql_thread_id()'
  747.       `mysql_use_result()'
  748.       `mysql_commit()'
  749.       `mysql_rollback()'
  750.       `mysql_autocommit()'
  751.       `mysql_more_results()'
  752.       `mysql_next_result()'
  753.     C API Prepared Statements
  754.     C API Prepared Statement Datatypes
  755.     C API Prepared Statement Function Overview
  756.     C API Prepared Statement Function Descriptions
  757.       `mysql_prepare()'
  758.       `mysql_param_count()'
  759.       `mysql_get_metadata()'
  760.       `mysql_bind_param()'
  761.       `mysql_execute()'
  762.       `mysql_stmt_affected_rows()'
  763.       `mysql_bind_result()'
  764.       `mysql_stmt_store_result()'
  765.       `mysql_stmt_data_seek()'
  766.       `mysql_stmt_row_seek()'
  767.       `mysql_stmt_row_tell()'
  768.       `mysql_stmt_num_rows()'
  769.       `mysql_fetch()'
  770.       `mysql_send_long_data()'
  771.       `mysql_stmt_close()'
  772.       `mysql_stmt_errno()'
  773.       `mysql_stmt_error()'
  774.       `mysql_stmt_sqlstate()'
  775.     C API Handling of Multiple Query Execution
  776.     C API Handling of Date and Time Values
  777.     C API Threaded Function Descriptions
  778.       `my_init()'
  779.       `mysql_thread_init()'
  780.       `mysql_thread_end()'
  781.       `mysql_thread_safe()'
  782.     C API Embedded Server Function Descriptions
  783.       `mysql_server_init()'
  784.       `mysql_server_end()'
  785.     Common questions and problems when using the C API
  786.       Why Is It that After `mysql_query()' Returns Success, `mysql_store_result()' Sometimes Returns `NULL'?
  787.       What Results Can I Get From a Query?
  788.       How Can I Get the Unique ID for the Last Inserted Row?
  789.       Problems Linking with the C API
  790.     Building Client Programs
  791.     How to Make a Threaded Client
  792.     libmysqld, the Embedded MySQL Server Library
  793.       Overview of the Embedded MySQL Server Library
  794.       Compiling Programs with `libmysqld'
  795.       Restrictions when using the Embedded MySQL Server
  796.       Using Option Files with the Embedded Server
  797.       Things left to do in Embedded Server (TODO)
  798.       A Simple Embedded Server Example
  799.       Licensing the Embedded Server
  800.   MySQL ODBC Support
  801.     How to Install MyODBC
  802.     How to Fill in the Various Fields in the ODBC Administrator Program
  803.     Connect parameters for MyODBC
  804.     How to Report Problems with MyODBC
  805.     Programs Known to Work with MyODBC
  806.     How to Get the Value of an `AUTO_INCREMENT' Column in ODBC
  807.     Reporting Problems with MyODBC
  808.   MySQL Java Connectivity (JDBC)
  809.   MySQL PHP API
  810.     Common Problems with MySQL and PHP
  811.   MySQL Perl API
  812.     `DBI' with `DBD::mysql'
  813.     The `DBI' Interface
  814.     More `DBI'/`DBD' Information
  815.   MySQL C++ API
  816.     Borland C++
  817.   MySQL Python API
  818.   MySQL Tcl API
  819.   MySQL Eiffel Wrapper
  820.  
  821. Error Handling in MySQL
  822.   Error Returns
  823.  
  824. Extending MySQL
  825.   MySQL Internals
  826.     MySQL Threads
  827.     MySQL Test Suite
  828.       Running the MySQL Test Suite
  829.       Extending the MySQL Test Suite
  830.       Reporting Bugs in the MySQL Test Suite
  831.   Adding New Functions to MySQL
  832.     `CREATE FUNCTION/DROP FUNCTION' Syntax
  833.     Adding a New User-definable Function
  834.       UDF Calling Sequences for simple functions
  835.       UDF Calling Sequences for aggregate functions
  836.       Argument Processing
  837.       Return Values and Error Handling
  838.       Compiling and Installing User-definable Functions
  839.     Adding a New Native Function
  840.   Adding New Procedures to MySQL
  841.     Procedure Analyse
  842.     Writing a Procedure
  843.  
  844. Problems and Common Errors
  845.   How to Determine What Is Causing Problems
  846.   Common Errors When Using MySQL
  847.     `Access denied' Error
  848.     `MySQL server has gone away' Error
  849.     `Can't connect to [local] MySQL server' Error
  850.     `Client does not support authentication protocol' error
  851.     `Host '...' is blocked' Error
  852.     `Too many connections' Error
  853.     `Some non-transactional changed tables couldn't be rolled back' Error
  854.     `Out of memory' Error
  855.     `Packet too large' Error
  856.     Communication Errors / Aborted Connection
  857.     `The table is full' Error
  858.     `Can't create/write to file' Error
  859.     `Commands out of sync' Error in Client
  860.     `Ignoring user' Error
  861.     `Table 'xxx' doesn't exist' Error
  862.     `Can't initialize character set xxx' error
  863.     File Not Found
  864.   Installation Related Issues
  865.     Problems When Linking with the MySQL Client Library
  866.     How to Run MySQL As a Normal User
  867.     Problems with File Permissions
  868.   Administration Related Issues
  869.     What To Do If MySQL Keeps Crashing
  870.     How to Reset a Forgotten Root Password
  871.     How MySQL Handles a Full Disk
  872.     Where MySQL Stores Temporary Files
  873.     How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'
  874.     Time Zone Problems
  875.   Query Related Issues
  876.     Case-Sensitivity in Searches
  877.     Problems Using `DATE' Columns
  878.     Problems with `NULL' Values
  879.     Problems with `alias'
  880.     Deleting Rows from Related Tables
  881.     Solving Problems with No Matching Rows
  882.     Problems with Floating-Point Comparison
  883.   Optimiser Related Issues
  884.     How to avoid table scan,,,
  885.   Table Definition Related Issues
  886.     Problems with `ALTER TABLE'.
  887.     How To Change the Order of Columns in a Table
  888.     TEMPORARY TABLE problems
  889.  
  890. Contributed Programs
  891.   APIs
  892.   Converters
  893.   Utilities
  894.  
  895. Credits
  896.   Developers at MySQL AB
  897.   Contributors to MySQL
  898.   Supporters to MySQL
  899.  
  900. MySQL Change History
  901.   Changes in release 5.0.0 (Development)
  902.   Changes in release 4.1.x (Alpha)
  903.     Changes in release 4.1.1 (to be released soon)
  904.     Changes in release 4.1.0 (03 Apr 2003: Alpha)
  905.   Changes in release 4.0.x (Production)
  906.     Changes in release 4.0.17 (not released yet)
  907.     Changes in release 4.0.16 (to be released soon)
  908.     Changes in release 4.0.15 (03 Sep 2003)
  909.     Changes in release 4.0.14 (18 Jul 2003)
  910.     Changes in release 4.0.13 (16 May 2003)
  911.     Changes in release 4.0.12 (15 Mar 2003: Production)
  912.     Changes in release 4.0.11 (20 Feb 2003)
  913.     Changes in release 4.0.10 (29 Jan 2003)
  914.     Changes in release 4.0.9 (09 Jan 2003)
  915.     Changes in release 4.0.8 (07 Jan 2003)
  916.     Changes in release 4.0.7 (20 Dec 2002)
  917.     Changes in release 4.0.6 (14 Dec 2002: Gamma)
  918.     Changes in release 4.0.5 (13 Nov 2002)
  919.     Changes in release 4.0.4 (29 Sep 2002)
  920.     Changes in release 4.0.3 (26 Aug 2002: Beta)
  921.     Changes in release 4.0.2 (01 Jul 2002)
  922.     Changes in release 4.0.1 (23 Dec 2001)
  923.     Changes in release 4.0.0 (Oct 2001: Alpha)
  924.   Changes in release 3.23.x (Recent; still supported)
  925.     Changes in release 3.23.59 (not released yet)
  926.     Changes in release 3.23.58 (11 Sep 2003)
  927.     Changes in release 3.23.57 (06 Jun 2003)
  928.     Changes in release 3.23.56 (13 Mar 2003)
  929.     Changes in release 3.23.55 (23 Jan 2003)
  930.     Changes in release 3.23.54 (05 Dec 2002)
  931.     Changes in release 3.23.53 (09 Oct 2002)
  932.     Changes in release 3.23.52 (14 Aug 2002)
  933.     Changes in release 3.23.51 (31 May 2002)
  934.     Changes in release 3.23.50 (21 Apr 2002)
  935.     Changes in release 3.23.49
  936.     Changes in release 3.23.48 (07 Feb 2002)
  937.     Changes in release 3.23.47 (27 Dec 2001)
  938.     Changes in release 3.23.46 (29 Nov 2001)
  939.     Changes in release 3.23.45 (22 Nov 2001)
  940.     Changes in release 3.23.44 (31 Oct 2001)
  941.     Changes in release 3.23.43 (04 Oct 2001)
  942.     Changes in release 3.23.42 (08 Sep 2001)
  943.     Changes in release 3.23.41 (11 Aug 2001)
  944.     Changes in release 3.23.40
  945.     Changes in release 3.23.39 (12 Jun 2001)
  946.     Changes in release 3.23.38 (09 May 2001)
  947.     Changes in release 3.23.37 (17 Apr 2001)
  948.     Changes in release 3.23.36 (27 Mar 2001)
  949.     Changes in release 3.23.35 (15 Mar 2001)
  950.     Changes in release 3.23.34a
  951.     Changes in release 3.23.34 (10 Mar 2001)
  952.     Changes in release 3.23.33 (09 Feb 2001)
  953.     Changes in release 3.23.32 (22 Jan 2001: Production)
  954.     Changes in release 3.23.31 (17 Jan 2001)
  955.     Changes in release 3.23.30 (04 Jan 2001)
  956.     Changes in release 3.23.29 (16 Dec 2000)
  957.     Changes in release 3.23.28 (22 Nov 2000: Gamma)
  958.     Changes in release 3.23.27 (24 Oct 2000)
  959.     Changes in release 3.23.26 (18 Oct 2000)
  960.     Changes in release 3.23.25 (29 Sep 2000)
  961.     Changes in release 3.23.24 (08 Sep 2000)
  962.     Changes in release 3.23.23 (01 Sep 2000)
  963.     Changes in release 3.23.22 (31 Jul 2000)
  964.     Changes in release 3.23.21
  965.     Changes in release 3.23.20
  966.     Changes in release 3.23.19
  967.     Changes in release 3.23.18
  968.     Changes in release 3.23.17
  969.     Changes in release 3.23.16
  970.     Changes in release 3.23.15 (May 2000: Beta)
  971.     Changes in release 3.23.14
  972.     Changes in release 3.23.13
  973.     Changes in release 3.23.12 (07 Mar 2000)
  974.     Changes in release 3.23.11
  975.     Changes in release 3.23.10
  976.     Changes in release 3.23.9
  977.     Changes in release 3.23.8 (02 Jan 2000)
  978.     Changes in release 3.23.7 (10 Dec 1999)
  979.     Changes in release 3.23.6
  980.     Changes in release 3.23.5 (20 Oct 1999)
  981.     Changes in release 3.23.4 (28 Sep 1999)
  982.     Changes in release 3.23.3
  983.     Changes in release 3.23.2 (09 Aug 1999)
  984.     Changes in release 3.23.1
  985.     Changes in release 3.23.0 (05 Aug 1999: Alpha)
  986.   Changes in release 3.22.x (Old; discontinued)
  987.     Changes in release 3.22.35
  988.     Changes in release 3.22.34
  989.     Changes in release 3.22.33
  990.     Changes in release 3.22.32 (14 Feb 2000)
  991.     Changes in release 3.22.31
  992.     Changes in release 3.22.30
  993.     Changes in release 3.22.29 (02 Jan 2000)
  994.     Changes in release 3.22.28 (20 Oct 1999)
  995.     Changes in release 3.22.27
  996.     Changes in release 3.22.26 (16 Sep 1999)
  997.     Changes in release 3.22.25
  998.     Changes in release 3.22.24 (05 Jul 1999)
  999.     Changes in release 3.22.23 (08 Jun 1999)
  1000.     Changes in release 3.22.22 (30 Apr 1999)
  1001.     Changes in release 3.22.21
  1002.     Changes in release 3.22.20 (18 Mar 1999)
  1003.     Changes in release 3.22.19 (Mar 1999: Production)
  1004.     Changes in release 3.22.18
  1005.     Changes in release 3.22.17
  1006.     Changes in release 3.22.16 (Feb 1999: Gamma)
  1007.     Changes in release 3.22.15
  1008.     Changes in release 3.22.14
  1009.     Changes in release 3.22.13
  1010.     Changes in release 3.22.12
  1011.     Changes in release 3.22.11
  1012.     Changes in release 3.22.10
  1013.     Changes in release 3.22.9
  1014.     Changes in release 3.22.8
  1015.     Changes in release 3.22.7 (Sep 1998: Beta)
  1016.     Changes in release 3.22.6
  1017.     Changes in release 3.22.5
  1018.     Changes in release 3.22.4
  1019.     Changes in release 3.22.3
  1020.     Changes in release 3.22.2
  1021.     Changes in release 3.22.1 (Jun 1998: Alpha)
  1022.     Changes in release 3.22.0
  1023.   Changes in release 3.21.x
  1024.     Changes in release 3.21.33
  1025.     Changes in release 3.21.32
  1026.     Changes in release 3.21.31
  1027.     Changes in release 3.21.30
  1028.     Changes in release 3.21.29
  1029.     Changes in release 3.21.28
  1030.     Changes in release 3.21.27
  1031.     Changes in release 3.21.26
  1032.     Changes in release 3.21.25
  1033.     Changes in release 3.21.24
  1034.     Changes in release 3.21.23
  1035.     Changes in release 3.21.22
  1036.     Changes in release 3.21.21a
  1037.     Changes in release 3.21.21
  1038.     Changes in release 3.21.20
  1039.     Changes in release 3.21.19
  1040.     Changes in release 3.21.18
  1041.     Changes in release 3.21.17
  1042.     Changes in release 3.21.16
  1043.     Changes in release 3.21.15
  1044.     Changes in release 3.21.14b
  1045.     Changes in release 3.21.14a
  1046.     Changes in release 3.21.13
  1047.     Changes in release 3.21.12
  1048.     Changes in release 3.21.11
  1049.     Changes in release 3.21.10
  1050.     Changes in release 3.21.9
  1051.     Changes in release 3.21.8
  1052.     Changes in release 3.21.7
  1053.     Changes in release 3.21.6
  1054.     Changes in release 3.21.5
  1055.     Changes in release 3.21.4
  1056.     Changes in release 3.21.3
  1057.     Changes in release 3.21.2
  1058.     Changes in release 3.21.0
  1059.   Changes in release 3.20.x
  1060.     Changes in release 3.20.18
  1061.     Changes in release 3.20.17
  1062.     Changes in release 3.20.16
  1063.     Changes in release 3.20.15
  1064.     Changes in release 3.20.14
  1065.     Changes in release 3.20.13
  1066.     Changes in release 3.20.11
  1067.     Changes in release 3.20.10
  1068.     Changes in release 3.20.9
  1069.     Changes in release 3.20.8
  1070.     Changes in release 3.20.7
  1071.     Changes in release 3.20.6
  1072.     Changes in release 3.20.3
  1073.     Changes in release 3.20.0
  1074.   Changes in release 3.19.x
  1075.     Changes in release 3.19.5
  1076.     Changes in release 3.19.4
  1077.     Changes in release 3.19.3
  1078.  
  1079. Porting to Other Systems
  1080.   Debugging a MySQL server
  1081.     Compiling MYSQL for Debugging
  1082.     Creating Trace Files
  1083.     Debugging mysqld under gdb
  1084.     Using a Stack Trace
  1085.     Using Log Files to Find Cause of Errors in mysqld
  1086.     Making a Test Case If You Experience Table Corruption
  1087.   Debugging a MySQL client
  1088.   The DBUG Package
  1089.   Locking methods
  1090.   Comments about RTS threads
  1091.   Differences between different thread packages
  1092.  
  1093. Environment Variables
  1094.  
  1095. MySQL Regular Expressions
  1096.  
  1097. GNU General Public License
  1098.  
  1099. GNU Lesser General Public License
  1100.  
  1101. SQL command, type and function index
  1102.  
  1103. Concept Index
  1104.  
  1105.  
  1106. This is the Reference Manual for the `MySQL Database System'.  This
  1107. version refers to the 4.0.16 version of `MySQL Server' but it is also
  1108. applicable for any older version (such as 3.23 and 4.0-production) as
  1109. changes are always indicated. There are also references for version 5.0
  1110. (development).
  1111.  
  1112. General Information
  1113. *******************
  1114.  
  1115. The `MySQL' (R) software delivers a very fast, multi-threaded,
  1116. multi-user, and robust `SQL' (`Structured Query Language') database
  1117. server.  `MySQL Server' is intended for mission-critical, heavy-load
  1118. production systems as well as for embedding into mass-deployed software.
  1119. `MySQL' is a trademark of `MySQL AB'.
  1120.  
  1121. The `MySQL' software is `Dual Licensed'. Users can choose to use the
  1122. `MySQL' software as an `Open Source'/`Free Software' product under the
  1123. terms of the `GNU General Public License'
  1124. (`http://www.gnu.org/licenses/') or can purchase a standard commercial
  1125. license from `MySQL AB'.  *Note Licensing and Support::.
  1126.  
  1127. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1128. information about the `MySQL' software.
  1129.  
  1130. The following list describes some sections of particular interest in
  1131. this manual:
  1132.  
  1133.    * For information about the company behind the `MySQL Database
  1134.      Server', see *Note What is MySQL AB::.
  1135.  
  1136.    * For a discussion about the capabilities of the `MySQL Database
  1137.      Server', see *Note Features::.
  1138.  
  1139.    * For installation instructions, see *Note Installing::.
  1140.  
  1141.    * For tips on porting the `MySQL Database Software' to new
  1142.      architectures or operating systems, see *Note Porting::.
  1143.  
  1144.    * For information about upgrading from a Version 4.0 release, see
  1145.      *Note Upgrading-from-4.0::.
  1146.  
  1147.    * For information about upgrading from a Version 3.23 release, see
  1148.      *Note Upgrading-from-3.23::.
  1149.  
  1150.    * For information about upgrading from a Version 3.22 release, see
  1151.      *Note Upgrading-from-3.22::.
  1152.  
  1153.    * For a tutorial introduction to the `MySQL Database Server', see
  1154.      *Note Tutorial::.
  1155.  
  1156.    * For examples of `SQL' and benchmarking information, see the
  1157.      benchmarking directory (`sql-bench' in the distribution).
  1158.  
  1159.    * For a history of new features and bug fixes, see *Note News::.
  1160.  
  1161.    * For a list of currently known bugs and misfeatures, see *Note
  1162.      Bugs::.
  1163.  
  1164.    * For future plans, see *Note TODO::.
  1165.  
  1166.    * For a list of all the contributors to this project, see *Note
  1167.      Credits::.
  1168.  
  1169. *Important*:
  1170.  
  1171. Reports of errors (often called bugs), as well as questions and
  1172. comments, should be sent to the general MySQL mailing list.  *Note
  1173. Mailing-list::.  *Note Bug reports::.
  1174.  
  1175. The `mysqlbug' script should be used to generate bug reports on Unix.
  1176. (Windows distributions contain a file `mysqlbug.txt' in the base
  1177. directory that can be used as a template for a bug report.)
  1178.  
  1179. For source distributions, the `mysqlbug' script can be found in the
  1180. `scripts' directory. For binary distributions, `mysqlbug' can be found
  1181. in the `bin' directory (`/usr/bin' for the `MySQL-server' RPM package).
  1182.  
  1183. If you have found a sensitive security bug in `MySQL Server', you
  1184. should send an e-mail to <security@mysql.com>.
  1185.  
  1186. About This Manual
  1187. =================
  1188.  
  1189. This is the `MySQL' reference manual; it documents `MySQL' up to
  1190. Version 4.0.16. Functional changes are always indicated with reference
  1191. to the version, so this manual is also suitable if you are using an
  1192. older version of the `MySQL' software (such as 3.23 or 4.0-production).
  1193. There are also references for version 5.0 (development).
  1194.  
  1195. Being a reference manual, it does not provide general instruction on
  1196. `SQL' or relational database concepts.
  1197.  
  1198. As the `MySQL Database Software' is under constant development, the
  1199. manual is also updated frequently.  The most recent version of this
  1200. manual is available at `http://www.mysql.com/documentation/' in many
  1201. different formats, including HTML, PDF, and Windows HLP versions.
  1202.  
  1203. The primary document is the Texinfo file.  The HTML version is produced
  1204. automatically using a modified version of `texi2html'.  The plain text
  1205. and Info versions are produced with `makeinfo'.  The PostScript version
  1206. is produced using `texi2dvi' and `dvips'.  The PDF version is produced
  1207. with `pdftex'.
  1208.  
  1209. If you have a hard time finding information in the manual, you can try
  1210. our searchable version at `http://www.mysql.com/doc/'.
  1211.  
  1212. If you have any suggestions concerning additions or corrections to this
  1213. manual, please send them to the documentation team at <docs@mysql.com>.
  1214.  
  1215. This manual was initially written by David Axmark and Michael (Monty)
  1216. Widenius. It is now maintained by the MySQL Documentation Team,
  1217. consisting of Arjen Lentz, Paul DuBois and Stefan Hinz.  For the many
  1218. other contributors, see *Note Credits::.
  1219.  
  1220. The copyright (2003) to this manual is owned by the Swedish company
  1221. `MySQL AB'. *Note Copyright::.
  1222.  
  1223. Conventions Used in This Manual
  1224. -------------------------------
  1225.  
  1226. This manual uses certain typographical conventions:
  1227.  
  1228. `constant'
  1229.      Constant-width font is used for command names and options; SQL
  1230.      statements; database, table, and column names; C and Perl code;
  1231.      and environment variables.  Example: "To see how `mysqladmin'
  1232.      works, invoke it with the `--help' option."
  1233.  
  1234. `filename'
  1235.      Constant-width font with surrounding quotes is used for filenames
  1236.      and pathnames.  Example: "The distribution is installed under the
  1237.      `/usr/local/' directory."
  1238.  
  1239. `c'
  1240.      Constant-width font with surrounding quotes is also used to
  1241.      indicate character sequences.  Example: "To specify a wildcard,
  1242.      use the `%' character."
  1243.  
  1244. _italic_
  1245.      Italic font is used for emphasis, _like this_.
  1246.  
  1247. *boldface*
  1248.      Boldface font is used in table headings and to convey *especially
  1249.      strong emphasis*.
  1250.  
  1251. When commands are shown that are meant to be executed by a particular
  1252. program, the program is indicated by a prompt shown before the command.
  1253. For example, `shell>' indicates a command that you execute from your
  1254. login shell, and `mysql>' indicates a command that you execute from the
  1255. `mysql' client program:
  1256.  
  1257.      shell> type a shell command here
  1258.      mysql> type a mysql command here
  1259.  
  1260. Shell commands are shown using Bourne shell syntax.  If you are using a
  1261. `csh'-style shell, you may need to issue commands slightly differently.
  1262. For example, the sequence to set an environment variable and run a
  1263. command looks like this in Bourne shell syntax:
  1264.  
  1265.      shell> VARNAME=value some_command
  1266.  
  1267. For `csh', you would execute the sequence like this:
  1268.  
  1269.      shell> setenv VARNAME value
  1270.      shell> some_command
  1271.  
  1272. Database, table, and column names must often be substituted into
  1273. commands.  To indicate that such substitution is necessary, this manual
  1274. uses `db_name', `tbl_name', and `col_name'.  For example, you might see
  1275. a statement like this:
  1276.  
  1277.      mysql> SELECT col_name FROM db_name.tbl_name;
  1278.  
  1279. This means that if you were to enter a similar statement, you would
  1280. supply your own database, table, and column names, perhaps like this:
  1281.  
  1282.      mysql> SELECT author_name FROM biblio_db.author_list;
  1283.  
  1284. SQL keywords are not case-sensitive and may be written in uppercase or
  1285. lowercase.  This manual uses uppercase.
  1286.  
  1287. In syntax descriptions, square brackets (`[' and `]') are used to
  1288. indicate optional words or clauses.  For example, in the following
  1289. statement, `IF EXISTS' is optional:
  1290.  
  1291.      DROP TABLE [IF EXISTS] tbl_name
  1292.  
  1293. When a syntax element consists of a number of alternatives, the
  1294. alternatives are separated by vertical bars (`|').  When one member
  1295. from a set of choices *may* be chosen, the alternatives are listed
  1296. within square brackets (`[' and `]'):
  1297.  
  1298.      TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
  1299.  
  1300. When one member from a set of choices *must* be chosen, the
  1301. alternatives are listed within braces (`{' and `}'):
  1302.  
  1303.      {DESCRIBE | DESC} tbl_name {col_name | wild}
  1304.  
  1305. What Is MySQL?
  1306. ==============
  1307.  
  1308. `MySQL', the most popular `Open Source' SQL database, is developed,
  1309. distributed, and supported by `MySQL AB'.  `MySQL AB' is a commercial
  1310. company, founded by the MySQL developers, that builds its business
  1311. providing services around the `MySQL' database.  *Note What is MySQL
  1312. AB::.
  1313.  
  1314. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1315. information about `MySQL' software and `MySQL AB'.
  1316.  
  1317. `MySQL' is a database management system.
  1318.      A database is a structured collection of data.  It may be anything
  1319.      from a simple shopping list to a picture gallery or the vast
  1320.      amounts of information in a corporate network.  To add, access,
  1321.      and process data stored in a computer database, you need a
  1322.      database management system such as `MySQL' Server.  Since
  1323.      computers are very good at handling large amounts of data,
  1324.      database management systems play a central role in computing, as
  1325.      stand-alone utilities or as parts of other applications.
  1326.  
  1327. MySQL is a relational database management system.
  1328.      A relational database stores data in separate tables rather than
  1329.      putting all the data in one big storeroom.  This adds speed and
  1330.      flexibility.  The `SQL' part of "`MySQL'" stands for "`Structured
  1331.      Query Language'". SQL is the most common standardised language
  1332.      used to access databases and is defined by the ANSI/ISO SQL
  1333.      Standard.(The SQL standard has been evolving since 1986 and
  1334.      several versions exist. In this manual, "`SQL-92'" refers to the
  1335.      standard released in 1992, "`SQL-99'" refers to the standard
  1336.      released in 1999, and "`SQL:2003'" refers to the version of the
  1337.      standard that is expected to be released in mid-2003.We use the
  1338.      term "`the SQL standard'" to mean the current version of the SQL
  1339.      Standard at any time.)
  1340.  
  1341. MySQL software is `Open Source'.
  1342.      `Open Source' means that it is possible for anyone to use and
  1343.      modify the software.  Anybody can download the `MySQL' software
  1344.      from the Internet and use it without paying anything.  If you
  1345.      wish, you may study the source code and change it to suit your
  1346.      needs.  The `MySQL' software uses the `GPL' (`GNU General Public
  1347.      License'), `http://www.gnu.org/licenses/', to define what you may
  1348.      and may not do with the software in different situations.  If you
  1349.      feel uncomfortable with the `GPL' or need to embed `MySQL' code
  1350.      into a commercial application you can buy a commercially licensed
  1351.      version from us.  *Note MySQL licenses::.
  1352.  
  1353. Why use the MySQL Database Server?
  1354.      The `MySQL Database Server' is very fast, reliable, and easy to
  1355.      use.  If that is what you are looking for, you should give it a
  1356.      try.  `MySQL Server' also has a practical set of features
  1357.      developed in close cooperation with our users.  You can find a
  1358.      performance comparison of `MySQL Server' with other database
  1359.      managers on our benchmark page.  *Note MySQL Benchmarks::.
  1360.  
  1361.      `MySQL Server' was originally developed to handle large databases
  1362.      much faster than existing solutions and has been successfully used
  1363.      in highly demanding production environments for several years.
  1364.      Though under constant development, `MySQL Server' today offers a
  1365.      rich and useful set of functions.  Its connectivity, speed, and
  1366.      security make `MySQL Server' highly suited for accessing databases
  1367.      on the Internet.
  1368.  
  1369. The technical features of MySQL Server
  1370.      For advanced technical information, see *Note Reference::.  The
  1371.      `MySQL Database Software' is a client/server system that consists
  1372.      of a multi-threaded `SQL' server that supports different backends,
  1373.      several different client programs and libraries, administrative
  1374.      tools, and a wide range of programming interfaces (APIs).
  1375.  
  1376.      We also provide `MySQL Server' as a multi-threaded library which
  1377.      you can link into your application to get a smaller, faster,
  1378.      easier-to-manage product.
  1379.  
  1380. There is a large amount of contributed MySQL software available.
  1381.      It is very likely that you will find that your favorite
  1382.      application or language already supports the `MySQL Database
  1383.      Server'.
  1384.  
  1385. The official way to pronounce `MySQL' is "My Ess Que Ell" (not "my
  1386. sequel"), but we don't mind if you pronounce it as "my sequel" or in
  1387. some other localised way.
  1388.  
  1389. History of MySQL
  1390. ----------------
  1391.  
  1392. We started out with the intention of using `mSQL' to connect to our
  1393. tables using our own fast low-level (ISAM) routines. However, after some
  1394. testing we came to the conclusion that `mSQL' was not fast enough nor
  1395. flexible enough for our needs.  This resulted in a new SQL interface to
  1396. our database but with almost the same API interface as `mSQL'.  This
  1397. API was chosen to ease porting of third-party code.
  1398.  
  1399. The derivation of the name `MySQL' is not clear.  Our base directory
  1400. and a large number of our libraries and tools have had the prefix "my"
  1401. for well over 10 years.  However, co-founder Monty Widenius's daughter
  1402. (some years younger) is also named My.  Which of the two gave its name
  1403. to `MySQL' is still a mystery, even for us.
  1404.  
  1405. The name of the MySQL Dolphin (our logo) is `Sakila'. `Sakila' was
  1406. chosen by the founders of MySQL AB from a huge list of names suggested
  1407. by users in our "Name the Dolphin" contest. The winning name was
  1408. submitted by Ambrose Twebaze, an open source software developer from
  1409. Swaziland, Africa.  According to Ambrose, the name Sakila has its roots
  1410. in SiSwati, the local language of Swaziland. Sakila is also the name of
  1411. a town in Arusha, Tanzania, near Ambrose's country of origin, Uganda.
  1412.  
  1413. The Main Features of MySQL
  1414. --------------------------
  1415.  
  1416. The following list describes some of the important characteristics of
  1417. the `MySQL Database Software'. *Note MySQL 4.0 Nutshell::.
  1418.  
  1419. Internals and Portability
  1420.         * Written in C and C++.  Tested with a broad range of different
  1421.           compilers.
  1422.  
  1423.         * Works on many different platforms.  *Note Which OS::.
  1424.  
  1425.         * Uses GNU Automake, Autoconf, and Libtool for portability.
  1426.  
  1427.         * APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and
  1428.           Tcl.  *Note Clients::.
  1429.  
  1430.         * Fully multi-threaded using kernel threads.  This means it can
  1431.           easily use multiple CPUs if available.
  1432.  
  1433.         * Transactional and non-transactional storage engines.
  1434.  
  1435.         * Very fast B-tree disk tables (MyISAM) with index compression.
  1436.  
  1437.         * Relatively easy to add another storage engine. This is useful
  1438.           if you want to add an SQL interface to an in-house database.
  1439.  
  1440.         * A very fast thread-based memory allocation system.
  1441.  
  1442.         * Very fast joins using an optimised one-sweep multi-join.
  1443.  
  1444.         * In-memory hash tables which are used as temporary tables.
  1445.  
  1446.         * SQL functions are implemented through a highly optimised
  1447.           class library and should be as fast as possible.  Usually
  1448.           there isn't any memory allocation at all after query
  1449.           initialisation.
  1450.  
  1451.         * The `MySQL' code gets tested with Purify (a commercial memory
  1452.           leakage detector) as well as with Valgrind, a `GPL' tool
  1453.           (`http://developer.kde.org/~sewardj/').
  1454.  
  1455.         * Available as client/server or embedded (linked) version.
  1456.  
  1457. Column Types
  1458.         * Many column types: signed/unsigned integers 1, 2, 3, 4, and 8
  1459.           bytes long, `FLOAT', `DOUBLE', `CHAR', `VARCHAR', `TEXT',
  1460.           `BLOB', `DATE', `TIME', `DATETIME', `TIMESTAMP', `YEAR',
  1461.           `SET', and `ENUM' types.  *Note Column types::.
  1462.  
  1463.         * Fixed-length and variable-length records.
  1464.  
  1465. Commands and Functions
  1466.         * Full operator and function support in the `SELECT' and `WHERE'
  1467.           clauses of queries.  For example:
  1468.  
  1469.                mysql> SELECT CONCAT(first_name, " ", last_name)
  1470.                    -> FROM tbl_name
  1471.                    -> WHERE income/dependents > 10000 AND age > 30;
  1472.  
  1473.         * Full support for SQL `GROUP BY' and `ORDER BY' clauses.
  1474.           Support for group functions (`COUNT()', `COUNT(DISTINCT ...)',
  1475.           `AVG()', `STD()', `SUM()', `MAX()', `MIN()', and
  1476.           `GROUP_CONCAT()').
  1477.  
  1478.         * Support for `LEFT OUTER JOIN' and `RIGHT OUTER JOIN' with
  1479.           both standard SQL and ODBC syntax.
  1480.  
  1481.         * Support for aliases on tables and columns as required by
  1482.           SQL-92.
  1483.  
  1484.         * `DELETE', `INSERT', `REPLACE', and `UPDATE' return the number
  1485.           of rows that were changed (affected).  It is possible to
  1486.           return the number of rows matched instead by setting a flag
  1487.           when connecting to the server.
  1488.  
  1489.         * The `MySQL'-specific `SHOW' command can be used to retrieve
  1490.           information about databases, tables, and indexes.  The
  1491.           `EXPLAIN' command can be used to determine how the optimiser
  1492.           resolves a query.
  1493.  
  1494.         * Function names do not clash with table or column names.  For
  1495.           example, `ABS' is a valid column name.  The only restriction
  1496.           is that for a function call, no spaces are allowed between
  1497.           the function name and the `(' that follows it.  *Note
  1498.           Reserved words::.
  1499.  
  1500.         * You can mix tables from different databases in the same query
  1501.           (as of Version 3.22).
  1502.  
  1503. Security
  1504.         * A privilege and password system that is very flexible and
  1505.           secure, and allows host-based verification.  Passwords are
  1506.           secure because all password traffic is encrypted when you
  1507.           connect to a server.
  1508.  
  1509. Scalability and Limits
  1510.         * Handles large databases.  We use `MySQL Server' with
  1511.           databases that contain 50 million records. We also know of
  1512.           users that use `MySQL Server' with 60,000 tables and about
  1513.           5,000,000,000 rows.
  1514.  
  1515.         * Up to 32 indexes per table are allowed.  Each index may
  1516.           consist of 1 to 16 columns or parts of columns.  The maximum
  1517.           index width is 500 bytes (this may be changed when compiling
  1518.           `MySQL Server').  An index may use a prefix of a `CHAR' or
  1519.           `VARCHAR' field.
  1520.  
  1521. Connectivity
  1522.         * Clients may connect to the `MySQL' server using TCP/IP
  1523.           Sockets, Unix Sockets (Unix), or Named Pipes (NT).
  1524.  
  1525.         * ODBC (Open-DataBase-Connectivity) support for Win32 (with
  1526.           source).  All ODBC 2.5 functions are supported, as are many
  1527.           others.  For example, you can use MS Access to connect to
  1528.           your `MySQL' server.  *Note ODBC::.
  1529.  
  1530. Localisation
  1531.         * The server can provide error messages to clients in many
  1532.           languages.  *Note Languages::.
  1533.  
  1534.         * Full support for several different character sets, including
  1535.           ISO-8859-1 (Latin1), german, big5, ujis, and more.  For
  1536.           example, the Scandinavian characters `a^', `a"' and `o"' are
  1537.           allowed in table and column names.
  1538.  
  1539.         * All data is saved in the chosen character set.  All
  1540.           comparisons for normal string columns are case-insensitive.
  1541.  
  1542.         * Sorting is done according to the chosen character set (the
  1543.           Swedish way by default).  It is possible to change this when
  1544.           the `MySQL' server is started.  To see an example of very
  1545.           advanced sorting, look at the Czech sorting code.  `MySQL
  1546.           Server' supports many different character sets that can be
  1547.           specified at compile and runtime.
  1548.  
  1549. Clients and Tools
  1550.         * Includes `myisamchk', a very fast utility for table checking,
  1551.           optimisation, and repair.  All of the functionality of
  1552.           `myisamchk' is also available through the SQL interface.
  1553.           *Note MySQL Database Administration::.
  1554.  
  1555.         * All `MySQL' programs can be invoked with the `--help' or `-?'
  1556.           options to obtain online assistance.
  1557.  
  1558. How Stable Is MySQL?
  1559. --------------------
  1560.  
  1561. This section addresses the questions "_How stable is MySQL Server?_"
  1562. and "_Can I depend on MySQL Server in this project?_" We will try to
  1563. clarify these issues and answer some important questions that concern
  1564. many potential users. The information in this section is based on data
  1565. gathered from the mailing list, which is very active in identifying
  1566. problems as well as reporting types of use.
  1567.  
  1568. Original code stems back from the early '80s, providing a stable code
  1569. base, and the ISAM table format remains backward-compatible.  At TcX,
  1570. the predecessor of `MySQL AB', `MySQL' code has worked in projects
  1571. since mid-1996, without any problems.  When the `MySQL Database
  1572. Software' was released to a wider public, our new users quickly found
  1573. some pieces of "untested code". Each new release since then has had
  1574. fewer portability problems (even though each new release has also had
  1575. many new features).
  1576.  
  1577. Each release of the `MySQL Server' has been usable. Problems have
  1578. occurred only when users try code from the "gray zones."  Naturally,
  1579. new users don't know what the gray zones are; this section therefore
  1580. attempts to document those areas that are currently known.  The
  1581. descriptions mostly deal with Version 3.23 and 4.0 of `MySQL Server'.
  1582. All known and reported bugs are fixed in the latest version, with the
  1583. exception of those listed in the bugs section, which are things that
  1584. are design-related.  *Note Bugs::.
  1585.  
  1586. The `MySQL Server' design is multi-layered with independent modules.
  1587. Some of the newer modules are listed here with an indication of how
  1588. well-tested each of them is:
  1589.  
  1590. *Replication -- Gamma*
  1591.      Large server clusters using replication are in production use, with
  1592.      good results. Work on enhanced replication features is continuing
  1593.      in `MySQL' 4.x.
  1594.  
  1595. *`InnoDB' tables -- Stable (in 3.23 from 3.23.49)*
  1596.      The `InnoDB' transactional storage engine has been declared stable
  1597.      in the `MySQL' 3.23 tree, starting from version 3.23.49.  `InnoDB'
  1598.      is being used in large, heavy-load production systems.
  1599.  
  1600. *`BDB' tables -- Gamma*
  1601.      The `Berkeley DB' code is very stable, but we are still improving
  1602.      the `BDB' transactional storage engine interface in `MySQL
  1603.      Server', so it will take some time before this is as well tested
  1604.      as the other table types.
  1605.  
  1606. *`FULLTEXT' -- Beta*
  1607.      Full-text search works but is not yet widely used.  Important
  1608.      enhancements have been implemented in `MySQL' 4.0.
  1609.  
  1610. *`MyODBC 3.51' (uses ODBC SDK 3.51) -- Stable*
  1611.      In wide production use. Some issues brought up appear to be
  1612.      application-related and independent of the ODBC driver or
  1613.      underlying database server.
  1614.  
  1615. *Automatic recovery of `MyISAM' tables -- Gamma*
  1616.      This status applies only to the new code in the `MyISAM' storage
  1617.      engine that checks if the table was closed properly on open and
  1618.      executes an automatic check/repair of the table if it wasn't.
  1619.  
  1620. *Bulk-insert -- Alpha*
  1621.      New feature in `MyISAM' tables in `MySQL' 4.0 for faster insert of
  1622.      many rows.
  1623.  
  1624. *Locking -- Gamma*
  1625.      This is very system-dependent.  On some systems there are big
  1626.      problems using standard OS locking (`fcntl()').  In these cases,
  1627.      you should run `mysqld' with the `--skip-external-locking' flag.
  1628.      Problems are known to occur on some Linux systems, and on SunOS
  1629.      when using NFS-mounted filesystems.
  1630.  
  1631. `MySQL AB' provides high-quality support for paying customers, and the
  1632. `MySQL' mailing list usually provides answers to common questions. Bugs
  1633. are usually fixed right away with a patch; for serious bugs, there is
  1634. almost always a new release.
  1635.  
  1636. How Big Can MySQL Tables Be?
  1637. ----------------------------
  1638.  
  1639. `MySQL' Version 3.22 had a 4 GB (4 gigabyte) limit on table size. With
  1640. the `MyISAM' table type in `MySQL' Version 3.23, the maximum table size
  1641. was pushed up to 8 million terabytes (2 ^ 63 bytes).
  1642.  
  1643. In effect, then, the table size for `MySQL' databases is normally
  1644. limited by the operating system.
  1645.  
  1646. Note, however, that operating systems have their own file-size limits.
  1647. Here are some examples:
  1648.  
  1649. *Operating System*     *File-Size Limit*
  1650. Linux-Intel 32 bit     2 GB, much more when using LFS
  1651. Linux-Alpha            8 TB (?)
  1652. Solaris 2.5.1          2 GB (possible 4GB with patch)
  1653. Solaris 2.6            4 GB (can be changed with flag)
  1654. Solaris 2.7 Intel      4 GB
  1655. Solaris 2.7            512 GB
  1656. UltraSPARC             
  1657.  
  1658. On Linux 2.2 you can get tables larger than 2 GB in size by using the
  1659. LFS patch for the ext2 filesystem. On Linux 2.4 patches also exist for
  1660. ReiserFS to get support for big files. Most current distributions are
  1661. based on kernel 2.4 and already include all the required Large File
  1662. Support (LFS) patches. However, the maximum available file size still
  1663. depends on several factors, one of them being the file system used to
  1664. store MySQL tables.
  1665.  
  1666. For a very detailed overview about LFS in Linux, have a look at Andreas
  1667. Jaeger's "Large File Support in Linux" page at
  1668. <http://www.suse.de/~aj/linux_lfs.html>.
  1669.  
  1670. By default, `MySQL' tables have a maximum size of about 4 GB.  You can
  1671. check the maximum table size for a table with the `SHOW TABLE STATUS'
  1672. command or with the `myisamchk -dv table_name'.  *Note SHOW::.
  1673.  
  1674. If you need a table that will be larger than 4 GB in size (and your
  1675. operating system supports it), set the `AVG_ROW_LENGTH' and `MAX_ROWS'
  1676. parameters accordingly when you create your table.  *Note CREATE
  1677. TABLE::.  You can also set these parameters later, with `ALTER TABLE'.
  1678. *Note ALTER TABLE::.
  1679.  
  1680. If your big table is a read-only table, you could use `myisampack' to
  1681. merge and compress many tables into one.  `myisampack' usually
  1682. compresses a table by at least 50%, so you can have, in effect, much
  1683. bigger tables.  *Note `myisampack': myisampack.
  1684.  
  1685. You can get around the operating system file limit for `MyISAM'
  1686. datafiles using the `RAID' option. *Note CREATE TABLE::.
  1687.  
  1688. Another solution can be the included `MERGE' library, which allows you
  1689. to handle a collection of identical tables as one.  *Note `MERGE'
  1690. tables: MERGE.
  1691.  
  1692. Year 2000 Compliance
  1693. --------------------
  1694.  
  1695. The `MySQL Server' itself has no problems with Year 2000 (Y2K)
  1696. compliance:
  1697.  
  1698.    * `MySQL Server' uses Unix time functions and has no problems with
  1699.      dates until `2069'. All 2-digit years are considered to be in the
  1700.      range `1970' to `2069', which means that if you store `01' in a
  1701.      `YEAR' column, `MySQL Server' treats it as `2001'.
  1702.  
  1703.    * All `MySQL' date functions are stored in one file, `sql/time.cc',
  1704.      and are coded very carefully to be year 2000-safe.
  1705.  
  1706.    * In `MySQL' Version 3.22 and later, the `YEAR' column type can
  1707.      store years `0' and `1901' to `2155' in one byte and display them
  1708.      using two or four digits.
  1709.  
  1710. You may run into problems with applications that use `MySQL Server' in
  1711. a way that is not Y2K-safe.  For example, many old applications store
  1712. or manipulate years using 2-digit values (which are ambiguous) rather
  1713. than 4-digit values.  This problem may be compounded by applications
  1714. that use values such as `00' or `99' as "missing" value indicators.
  1715.  
  1716. Unfortunately, these problems may be difficult to fix because different
  1717. applications may be written by different programmers, each of whom may
  1718. use a different set of conventions and date-handling functions.
  1719.  
  1720. Here is a simple demonstration illustrating that `MySQL Server' doesn't
  1721. have any problems with dates until the year 2030:
  1722.  
  1723.      mysql> DROP TABLE IF EXISTS y2k;
  1724.      Query OK, 0 rows affected (0.01 sec)
  1725.      
  1726.      mysql> CREATE TABLE y2k (date DATE,
  1727.          ->                   date_time DATETIME,
  1728.          ->                   time_stamp TIMESTAMP);
  1729.      Query OK, 0 rows affected (0.00 sec)
  1730.      
  1731.      mysql> INSERT INTO y2k VALUES
  1732.          -> ("1998-12-31","1998-12-31 23:59:59",19981231235959),
  1733.          -> ("1999-01-01","1999-01-01 00:00:00",19990101000000),
  1734.          -> ("1999-09-09","1999-09-09 23:59:59",19990909235959),
  1735.          -> ("2000-01-01","2000-01-01 00:00:00",20000101000000),
  1736.          -> ("2000-02-28","2000-02-28 00:00:00",20000228000000),
  1737.          -> ("2000-02-29","2000-02-29 00:00:00",20000229000000),
  1738.          -> ("2000-03-01","2000-03-01 00:00:00",20000301000000),
  1739.          -> ("2000-12-31","2000-12-31 23:59:59",20001231235959),
  1740.          -> ("2001-01-01","2001-01-01 00:00:00",20010101000000),
  1741.          -> ("2004-12-31","2004-12-31 23:59:59",20041231235959),
  1742.          -> ("2005-01-01","2005-01-01 00:00:00",20050101000000),
  1743.          -> ("2030-01-01","2030-01-01 00:00:00",20300101000000),
  1744.          -> ("2050-01-01","2050-01-01 00:00:00",20500101000000);
  1745.      Query OK, 13 rows affected (0.01 sec)
  1746.      Records: 13  Duplicates: 0  Warnings: 0
  1747.      
  1748.      mysql> SELECT * FROM y2k;
  1749.      +------------+---------------------+----------------+
  1750.      | date       | date_time           | time_stamp     |
  1751.      +------------+---------------------+----------------+
  1752.      | 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
  1753.      | 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
  1754.      | 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
  1755.      | 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
  1756.      | 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
  1757.      | 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
  1758.      | 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
  1759.      | 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
  1760.      | 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
  1761.      | 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
  1762.      | 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
  1763.      | 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
  1764.      | 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
  1765.      +------------+---------------------+----------------+
  1766.      13 rows in set (0.00 sec)
  1767.  
  1768. This example shows that the `DATE' and `DATETIME' datatypes will not
  1769. give any problems with future dates (they handle dates until the year
  1770. 9999).
  1771.  
  1772. The `TIMESTAMP' datatype, which is used to store the current time,
  1773. supports values that range from `19700101000000' to `20300101000000' on
  1774. 32-bit machines (signed value).  On 64-bit machines, `TIMESTAMP'
  1775. handles values up to `2106' (unsigned value).
  1776.  
  1777. Even though `MySQL Server' is Y2K-compliant, it is your responsibility
  1778. to provide unambiguous input.  See *Note Y2K issues:: for `MySQL
  1779. Server''s rules for dealing with ambiguous date input data (data
  1780. containing 2-digit year values).
  1781.  
  1782. What Is MySQL AB?
  1783. =================
  1784.  
  1785. `MySQL AB' is the company of the `MySQL' founders and main developers.
  1786. `MySQL AB' was originally established in Sweden by David Axmark, Allan
  1787. Larsson, and Michael `Monty' Widenius.
  1788.  
  1789. The developers of the `MySQL' server are all employed by the company.
  1790. We are a virtual organisation with people in a dozen countries around
  1791. the world. We communicate extensively over the Net every day with one
  1792. another and with our users, supporters, and partners.
  1793.  
  1794. We are dedicated to developing the `MySQL' software and spreading our
  1795. database to new users. `MySQL AB' owns the copyright to the `MySQL'
  1796. source code, the `MySQL' logo and trademark, and this manual. *Note
  1797. What-is::.
  1798.  
  1799. The `MySQL' core values show our dedication to `MySQL' and `Open
  1800. Source'.
  1801.  
  1802. We want the `MySQL Database Software' to be:
  1803.    * The best and the most widely used database in the world.
  1804.  
  1805.    * Available to, and affordable by all.
  1806.  
  1807.    * Easy to use.
  1808.  
  1809.    * Continuously improving while remaining fast and safe.
  1810.  
  1811.    * Fun to use and improve.
  1812.  
  1813.    * Free from bugs.
  1814.  
  1815. `MySQL AB' and the people at `MySQL AB':
  1816.    * Promote `Open Source' philosophy and support the `Open Source'
  1817.      community.
  1818.  
  1819.    * Aim to be good citizens.
  1820.  
  1821.    * Prefer partners that share our values and mind-set.
  1822.  
  1823.    * Answer e-mail and provide support.
  1824.  
  1825.    * Are a virtual company, networking with others.
  1826.  
  1827.    * Work against software patents.
  1828.  
  1829. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1830. information about `MySQL' and `MySQL AB'.
  1831.  
  1832. By the way, the "AB" part of the company name is the acronym for the
  1833. Swedish "aktiebolag", or "stock company."  It translates to "MySQL,
  1834. Inc." In fact, MySQL Inc. and MySQL GmbH are examples of MySQL AB
  1835. subsidiaries. They are located in the US and Germany, respectively.
  1836.  
  1837. The Business Model and Services of MySQL AB
  1838. -------------------------------------------
  1839.  
  1840. One of the most common questions we encounter is: "_How can you make a
  1841. living from something you give away for free?_" This is how.
  1842.  
  1843. `MySQL AB' makes money on support, services, commercial licenses, and
  1844. royalties. We use these revenues to fund product development and to
  1845. expand the `MySQL' business.
  1846.  
  1847. The company has been profitable since its inception. In October 2001,
  1848. we accepted venture financing from leading Scandinavian investors and a
  1849. handful of business angels. This investment is used to solidify our
  1850. business model and build a basis for sustainable growth.
  1851.  
  1852. Support
  1853. .......
  1854.  
  1855. `MySQL AB' is run and owned by the founders and main developers of the
  1856. `MySQL' database. The developers are committed to giving support to
  1857. customers and other users in order to stay in touch with their needs
  1858. and problems. All our support is given by qualified developers. Really
  1859. tricky questions are answered by Michael `Monty' Widenius, principal
  1860. author of the `MySQL Server'.  *Note Support::.
  1861.  
  1862. For more information and ordering support at various levels, see
  1863. `http://www.mysql.com/support/' or contact our sales staff at
  1864. <sales@mysql.com>.
  1865.  
  1866. Training and Certification
  1867. ..........................
  1868.  
  1869. `MySQL AB' delivers `MySQL' and related training worldwide.  We offer
  1870. both open courses and in-house courses tailored to the specific needs
  1871. of your company. `MySQL Training' is also available through our
  1872. partners, the `Authorised MySQL Training Centers'.
  1873.  
  1874. Our training material uses the same example databases used in our
  1875. documentation and our sample applications, and is always updated to
  1876. reflect the latest `MySQL' version. Our trainers are backed by the
  1877. development team to guarantee the quality of the training and the
  1878. continuous development of the course material. This also ensures that
  1879. no questions raised during the courses remain unanswered.
  1880.  
  1881. Attending our training courses will enable you to achieve your `MySQL'
  1882. application goals. You will also:
  1883.    * Save time.
  1884.  
  1885.    * Improve the performance of your application(s).
  1886.  
  1887.    * Reduce or eliminate the need for additional hardware, decreasing
  1888.      cost.
  1889.  
  1890.    * Enhance security.
  1891.  
  1892.    * Increase customers' and co-workers' satisfaction.
  1893.  
  1894.    * Prepare yourself for `MySQL Certification'.
  1895.  
  1896. If you are interested in our training as a potential participant or as
  1897. a training partner, please visit the training section at
  1898. `http://www.mysql.com/training/' or contact us at: <training@mysql.com>.
  1899.  
  1900. For details about the `MySQL Certification Program', please see
  1901. `http://www.mysql.com/certification/'.
  1902.  
  1903. Consulting
  1904. ..........
  1905.  
  1906. `MySQL AB' and its `Authorised Partners' offer consulting services to
  1907. users of `MySQL Server' and to those who embed `MySQL Server' in their
  1908. own software, all over the world.
  1909.  
  1910. Our consultants can help you design and tune your databases, construct
  1911. efficient queries, tune your platform for optimal performance, resolve
  1912. migration issues, set up replication, build robust transactional
  1913. applications, and more.  We also help customers embed `MySQL Server' in
  1914. their products and applications for large-scale deployment.
  1915.  
  1916. Our consultants work in close collaboration with our development team,
  1917. which ensures the technical quality of our professional services.
  1918. Consulting assignments range from 2-day power-start sessions to
  1919. projects that span weeks and months. Our expertise not only covers
  1920. `MySQL Server'--it also extends into programming and scripting
  1921. languages such as PHP, Perl, and more.
  1922.  
  1923. If you are interested in our consulting services or want to become a
  1924. consulting partner, please visit the consulting section of our web site
  1925. at `http://www.mysql.com/consulting/' or contact our consulting staff
  1926. at <consulting@mysql.com>.
  1927.  
  1928. Commercial Licenses
  1929. ...................
  1930.  
  1931. The `MySQL' database is released under the `GNU General Public License'
  1932. (`GPL').  This means that the `MySQL' software can be used free of
  1933. charge under the `GPL'. If you do not want to be bound by the `GPL'
  1934. terms (such as the requirement that your application must also be `GPL',
  1935. you may purchase a commercial license for the same product from `MySQL
  1936. AB'; see `http://www.mysql.com/products/pricing.html'.  Since `MySQL
  1937. AB' owns the copyright to the `MySQL' source code, we are able to
  1938. employ `Dual Licensing', which means that the same product is available
  1939. under `GPL' and under a commercial license. This does not in any way
  1940. affect the `Open Source' commitment of `MySQL AB'. For details about
  1941. when a commercial license is required, please see *Note MySQL
  1942. licenses::.
  1943.  
  1944. We also sell commercial licenses of third-party `Open Source GPL'
  1945. software that adds value to `MySQL Server'. A good example is the
  1946. `InnoDB' transactional storage engine that offers `ACID' support,
  1947. row-level locking, crash recovery, multi-versioning, foreign key
  1948. support, and more. *Note InnoDB::.
  1949.  
  1950. Partnering
  1951. ..........
  1952.  
  1953. `MySQL AB' has a worldwide partner programme that covers training
  1954. courses, consulting and support, publications, plus reselling and
  1955. distributing `MySQL' and related products. `MySQL AB Partners' get
  1956. visibility on the `http://www.mysql.com/' web site and the right to use
  1957. special versions of the `MySQL' trademarks to identify their products
  1958. and promote their business.
  1959.  
  1960. If you are interested in becoming a `MySQL AB Partner', please e-mail
  1961. <partner@mysql.com>.
  1962.  
  1963. The word `MySQL' and the `MySQL' dolphin logo are trademarks of `MySQL
  1964. AB'. *Note MySQL AB Logos and Trademarks::.  These trademarks represent
  1965. a significant value that the `MySQL' founders have built over the years.
  1966.  
  1967. The `MySQL' web site (`http://www.mysql.com/') is popular among
  1968. developers and users. In October 2001, we served 10 million page views.
  1969. Our visitors represent a group that makes purchase decisions and
  1970. recommendations for both software and hardware. Twelve percent of our
  1971. visitors authorise purchase decisions, and only nine percent are not
  1972. involved in purchase decisions at all. More than 65% have made one or
  1973. more online business purchases within the last half-year, and 70% plan
  1974. to make one in the next few months.
  1975.  
  1976. Contact Information
  1977. -------------------
  1978.  
  1979. The `MySQL' web site (`http://www.mysql.com/') provides the latest
  1980. information about `MySQL' and `MySQL AB'.
  1981.  
  1982. For press services and inquiries not covered in our News releases
  1983. (`http://www.mysql.com/news/'), please send an e-mail to
  1984. <press@mysql.com>.
  1985.  
  1986. If you have a valid support contract with `MySQL AB', you will get
  1987. timely, precise answers to your technical questions about the `MySQL'
  1988. software. For more information, see *Note Support::.  On our web site,
  1989. see `http://www.mysql.com/support/', or send an e-mail to
  1990. <sales@mysql.com>.
  1991.  
  1992. For information about `MySQL' training, please visit the training
  1993. section at `http://www.mysql.com/training/'. If you have restricted
  1994. access to the Internet, please contact the `MySQL AB' training staff
  1995. via e-mail at <training@mysql.com>.  *Note Business Services Training::.
  1996.  
  1997. For information on the `MySQL Certification Program', please see
  1998. `http://www.mysql.com/certification/'.  *Note Business Services
  1999. Training::.
  2000.  
  2001. If you're interested in consulting, please visit the consulting section
  2002. of our web site at `http://www.mysql.com/consulting/'. If you have
  2003. restricted access to the Internet, please contact the `MySQL AB'
  2004. consulting staff via e-mail at <consulting@mysql.com>.  *Note Business
  2005. Services Consulting::.
  2006.  
  2007. Commercial licenses may be purchased online at
  2008. `https://order.mysql.com/'. There you will also find information on how
  2009. to fax your purchase order to `MySQL AB'. More information about
  2010. licensing can be found at `http://www.mysql.com/products/pricing.html'.
  2011. If you have questions regarding licensing or you want a quote for a
  2012. high-volume license deal, please fill in the contact form on our web
  2013. site (`http://www.mysql.com/') or send an e-mail message to
  2014. <licensing@mysql.com> (for licensing questions) or to <sales@mysql.com>
  2015. (for sales inquiries).  *Note MySQL licenses::.
  2016.  
  2017. If you represent a business that is interested in partnering with
  2018. `MySQL AB', please send an e-mail to <partner@mysql.com>.  *Note
  2019. Business Services Partnering::.
  2020.  
  2021. For more information on the `MySQL' trademark policy, refer to
  2022. `http://www.mysql.com/company/trademark.html' or send an e-mail to
  2023. <trademark@mysql.com>.  *Note MySQL AB Logos and Trademarks::.
  2024.  
  2025. If you are interested in any of the `MySQL AB' jobs listed in our jobs
  2026. section (`http://www.mysql.com/company/jobs/'), please send an e-mail
  2027. to <jobs@mysql.com>.  Please do not send your CV as an attachment, but
  2028. rather as plain text at the end of your e-mail message.
  2029.  
  2030. For general discussion among our many users, please direct your
  2031. attention to the appropriate mailing list.  *Note Questions::.
  2032.  
  2033. Reports of errors (often called bugs), as well as questions and
  2034. comments, should be sent to the general MySQL mailing list.  *Note
  2035. Mailing-list::.  If you have found a sensitive security bug in the
  2036. `MySQL Server', please send an e-mail to <security@mysql.com>.  *Note
  2037. Bug reports::.
  2038.  
  2039. If you have benchmark results that we can publish, please contact us
  2040. via e-mail at <benchmarks@mysql.com>.
  2041.  
  2042. If you have suggestions concerning additions or corrections to this
  2043. manual, please send them to the manual team via e-mail at
  2044. <docs@mysql.com>.
  2045.  
  2046. For questions or comments about the workings or content of the `MySQL'
  2047. web site (`http://www.mysql.com/'), please send an e-mail to
  2048. <webmaster@mysql.com>.
  2049.  
  2050. `MySQL AB' has a privacy policy, which can be read at
  2051. `http://www.mysql.com/company/privacy.html'.  For any queries regarding
  2052. this policy, please send an e-mail to <privacy@mysql.com>.
  2053.  
  2054. For all other inquires, please send an e-mail to <info@mysql.com>.
  2055.  
  2056. MySQL Support and Licensing
  2057. ===========================
  2058.  
  2059. This section describes `MySQL' support and licensing arrangements.
  2060.  
  2061. Support Offered by MySQL AB
  2062. ---------------------------
  2063.  
  2064. Technical support from `MySQL AB' means individualised answers to your
  2065. unique problems direct from the software engineers who code the `MySQL'
  2066. database engine.
  2067.  
  2068. We try to take a broad and inclusive view of technical support. Almost
  2069. any problem involving `MySQL' software is important to us if it's
  2070. important to you.  Typically customers seek help on how to get
  2071. different commands and utilities to work, remove performance
  2072. bottlenecks, restore crashed systems, understand operating system or
  2073. networking impacts on `MySQL', set up best practices for backup and
  2074. recovery, utilise APIs, and so on.  Our support covers only the `MySQL'
  2075. server and our own utilities, not third-party products that access the
  2076. `MySQL' server, though we try to help with these where we can.
  2077.  
  2078. Detailed information about our various support options is given at
  2079. `http://www.mysql.com/support/', where support contracts can also be
  2080. ordered online. If you have restricted access to the Internet, please
  2081. contact our sales staff via e-mail at <sales@mysql.com>.
  2082.  
  2083. Technical support is like life insurance. You can live happily without
  2084. it for years, but when your hour arrives it becomes critically
  2085. important, yet it's too late to buy it.  If you use `MySQL Server' for
  2086. important applications and encounter sudden difficulties, it may be too
  2087. time consuming to figure out all the answers yourself. You may need
  2088. immediate access to the most experienced `MySQL' troubleshooters
  2089. available, those employed by `MySQL AB'.
  2090.  
  2091. Copyrights and Licenses Used by MySQL
  2092. -------------------------------------
  2093.  
  2094. `MySQL AB' owns the copyright to the `MySQL' source code, the `MySQL'
  2095. logos and trademarks and this manual.  *Note What is MySQL AB::.
  2096. Several different licenses are relevant to the `MySQL' distribution:
  2097.  
  2098.   1. All the `MySQL'-specific source in the server, the `mysqlclient'
  2099.      library and the client, as well as the `GNU' `readline' library is
  2100.      covered by the `GNU General Public License'.  *Note GPL license::.
  2101.      The text of this license can be found as the file `COPYING' in the
  2102.      distribution.
  2103.  
  2104.   2. The `GNU' `getopt' library is covered by the `GNU Lesser General
  2105.      Public License'.  *Note LGPL license::.
  2106.  
  2107.   3. Some parts of the source (the `regexp' library) are covered by a
  2108.      Berkeley-style copyright.
  2109.  
  2110.   4. Older versions of `MySQL' (3.22 and earlier) are subject to a
  2111.      stricter license (`http://www.mysql.com/products/mypl.html').  See
  2112.      the documentation of the specific version for information.
  2113.  
  2114.   5. The `MySQL' reference manual is currently *not* distributed under
  2115.      a `GPL'-style license. Use of the manual is subject to the
  2116.      following terms:
  2117.         * Conversion to other formats is allowed, but the actual content
  2118.           may not be altered or edited in any way.
  2119.  
  2120.         * You may create a printed copy for your own personal use.
  2121.  
  2122.         * For all other uses, such as selling printed copies or using
  2123.           (parts of) the manual in another publication, prior written
  2124.           agreement from `MySQL AB' is required.
  2125.      Please send an e-mail to <docs@mysql.com> for more information or
  2126.      if you are interested in doing a translation.
  2127.  
  2128. For information about how the `MySQL' licenses work in practice, please
  2129. refer to *Note MySQL licenses::.  Also see *Note MySQL AB Logos and
  2130. Trademarks::.
  2131.  
  2132. MySQL Licenses
  2133. --------------
  2134.  
  2135. The `MySQL' software is released under the `GNU General Public License'
  2136. (`GPL'), which is probably the best known `Open Source' license.  The
  2137. formal terms of the `GPL' license can be found at
  2138. `http://www.gnu.org/licenses/'.  See also
  2139. `http://www.gnu.org/licenses/gpl-faq.html' and
  2140. `http://www.gnu.org/philosophy/enforcing-gpl.html'.
  2141.  
  2142. Since the `MySQL' software is released under the `GPL', it may often be
  2143. used for free, but for certain uses you may want or need to buy
  2144. commercial licenses from `MySQL AB' at `https://order.mysql.com/'.  See
  2145. `http://www.mysql.com/products/licensing.html' for more information.
  2146.  
  2147. Older versions of `MySQL' (3.22 and earlier) are subject to a stricter
  2148. license (`http://www.mysql.com/products/mypl.html').  See the
  2149. documentation of the specific version for information.
  2150.  
  2151. Please note that the use of the `MySQL' software under commercial
  2152. license, `GPL', or the old `MySQL' license does not automatically give
  2153. you the right to use `MySQL AB' trademarks.  *Note MySQL AB Logos and
  2154. Trademarks::.
  2155.  
  2156. Using the MySQL Software Under a Commercial License
  2157. ...................................................
  2158.  
  2159. The `GPL' license is contagious in the sense that when a program is
  2160. linked to a `GPL' program all the source code for all the parts of the
  2161. resulting product must also be released under the `GPL'.  If you do not
  2162. follow this `GPL' requirement, you break the license terms and forfeit
  2163. your right to use the `GPL' program altogether.  You also risk damages.
  2164.  
  2165. You need a commercial license:
  2166.  
  2167.    * When you link a program with any `GPL' code from the `MySQL'
  2168.      software and don't want the resulting product to be licensed under
  2169.      `GPL', perhaps because you want to build a commercial product or
  2170.      keep the added non-`GPL' code closed source for other reasons.
  2171.      When purchasing commercial licenses, you are not using the `MySQL'
  2172.      software under `GPL' even though it's the same code.
  2173.  
  2174.    * When you distribute a non-`GPL' application that *only* works with
  2175.      the `MySQL' software and ship it with the `MySQL' software. This
  2176.      type of solution is considered to be linking even if it's done
  2177.      over a network.
  2178.  
  2179.    * When you distribute copies of the `MySQL' software without
  2180.      providing the source code as required under the `GPL' license.
  2181.  
  2182.    * When you want to support the further development of the `MySQL'
  2183.      database even if you don't formally need a commercial license.
  2184.      Purchasing support directly from `MySQL AB' is another good way of
  2185.      contributing to the development of the `MySQL' software, with
  2186.      immediate advantages for you.  *Note Support::.
  2187.  
  2188. If you require a license, you will need one for each installation of the
  2189. `MySQL' software. This covers any number of CPUs on a machine, and there
  2190. is no artificial limit on the number of clients that connect to the
  2191. server in any way.
  2192.  
  2193. For commercial licenses, please visit our website at
  2194. `http://www.mysql.com/products/licensing.html'.  For support contracts,
  2195. see `http://www.mysql.com/support/'.  If you have special needs or you
  2196. have restricted access to the Internet, please contact our sales staff
  2197. via e-mail at <sales@mysql.com>.
  2198.  
  2199. Using the MySQL Software for Free Under GPL
  2200. ...........................................
  2201.  
  2202. You can use the `MySQL' software for free under the `GPL' if you adhere
  2203. to the conditions of the `GPL'.  For additional details, including
  2204. answers to common questions about the `GPL', see the generic FAQ from
  2205. the Free Software Foundation at
  2206. `http://www.gnu.org/licenses/gpl-faq.html'.  Common uses of the `GPL'
  2207. include:
  2208.  
  2209.    * When you distribute both your own application and the `MySQL'
  2210.      source code under the `GPL' with your product.
  2211.  
  2212.    * When you distribute the `MySQL' source code bundled with other
  2213.      programs that are not linked to or dependent on the `MySQL' system
  2214.      for their functionality even if you sell the distribution
  2215.      commercially.  This is called mere aggregation in the `GPL'
  2216.      license.
  2217.  
  2218.    * When you are not distributing *any* part of the `MySQL' system,
  2219.      you can use it for free.
  2220.  
  2221.    * When you are an Internet Service Provider (ISP), offering web
  2222.      hosting with `MySQL' servers for your customers.  We encourage
  2223.      people to use ISPs that have MySQL support, as this will give them
  2224.      the confidence that their ISP will, in fact, have the resources to
  2225.      solve any problems they may experience with the `MySQL'
  2226.      installation. Even if an ISP does not have a commercial license
  2227.      for `MySQL Server', their customers should at least be given read
  2228.      access to the source of the `MySQL' installation so that the
  2229.      customers can verify that it is correctly patched.
  2230.  
  2231.    * When you use the `MySQL' database software in conjunction with a
  2232.      web server, you do not need a commercial license (so long as it is
  2233.      not a product you distribute). This is true even if you run a
  2234.      commercial web server that uses `MySQL Server', because you are not
  2235.      distributing any part of the `MySQL' system. However, in this case
  2236.      we would like you to purchase `MySQL' support because the `MySQL'
  2237.      software is helping your enterprise.
  2238.  
  2239. If your use of `MySQL' database software does not require a commercial
  2240. license, we encourage you to purchase support from `MySQL AB' anyway.
  2241. This way you contribute toward `MySQL' development and also gain
  2242. immediate advantages for yourself. *Note Support::.
  2243.  
  2244. If you use the `MySQL' database software in a commercial context such
  2245. that you profit by its use, we ask that you further the development of
  2246. the `MySQL' software by purchasing some level of support.  We feel that
  2247. if the `MySQL' database helps your business, it is reasonable to ask
  2248. that you help `MySQL AB'.  (Otherwise, if you ask us support questions,
  2249. you are not only using for free something into which we've put a lot a
  2250. work, you're asking us to provide free support, too.)
  2251.  
  2252. MySQL AB Logos and Trademarks
  2253. -----------------------------
  2254.  
  2255. Many users of the `MySQL' database want to display the `MySQL AB'
  2256. dolphin logo on their web sites, books, or boxed products. We welcome
  2257. and encourage this, although it should be noted that the word `MySQL'
  2258. and the `MySQL' dolphin logo are trademarks of `MySQL AB' and may only
  2259. be used as stated in our trademark policy at
  2260. `http://www.mysql.com/company/trademark.html'.
  2261.  
  2262. The Original MySQL Logo
  2263. .......................
  2264.  
  2265. The `MySQL' dolphin logo was designed by the Finnish advertising agency
  2266. Priority in 2001.  The dolphin was chosen as a suitable symbol for the
  2267. `MySQL' database since it is a smart, fast, and lean animal,
  2268. effortlessly navigating oceans of data. We also happen to like dolphins.
  2269.  
  2270. The original `MySQL' logo may only be used by representatives of `MySQL
  2271. AB' and by those having a written agreement allowing them to do so.
  2272.  
  2273. MySQL Logos that may be Used Without Written Permission
  2274. .......................................................
  2275.  
  2276. We have designed a set of special _Conditional Use_ logos that may be
  2277. downloaded from our web site at `http://www.mysql.com/press/logos.html'
  2278. and used on third-party web sites without written permission from
  2279. `MySQL AB'.  The use of these logos is not entirely unrestricted but,
  2280. as the name implies, subject to our trademark policy that is also
  2281. available on our web site. You should read through the trademark policy
  2282. if you plan to use them. The requirements are basically as follows:
  2283.  
  2284.    * Use the logo you need as displayed on the `http://www.mysql.com/'
  2285.      site. You may scale it to fit your needs, but may not change
  2286.      colours or design, or alter the graphics in any way.
  2287.  
  2288.    * Make it evident that you, and not `MySQL AB', are the creator and
  2289.      owner of the site that displays the `MySQL' trademark.
  2290.  
  2291.    * Don't use the trademark in a way that is detrimental to `MySQL AB'
  2292.      or to the value of `MySQL AB' trademarks. We reserve the right to
  2293.      revoke the right to use the `MySQL AB' trademark.
  2294.  
  2295.    * If you use the trademark on a web site, make it clickable, leading
  2296.      directly to `http://www.mysql.com/'.
  2297.  
  2298.    * If you are use the `MySQL' database under `GPL' in an application,
  2299.      your application must be `Open Source' and must be able to connect
  2300.      to a `MySQL' server.
  2301.  
  2302. Contact us via e-mail at <trademark@mysql.com> to inquire about special
  2303. arrangements to fit your needs.
  2304.  
  2305. When do you need a Written Permission to use MySQL Logos?
  2306. .........................................................
  2307.  
  2308. You need written permission from `MySQL AB' before using `MySQL' logos
  2309. in the following cases:
  2310.  
  2311.    * When displaying any `MySQL AB' logo anywhere except on your web
  2312.      site.
  2313.  
  2314.    * When displaying any `MySQL AB' logo except the _Conditional Use_
  2315.      logos mentioned previously on web sites or elsewhere.
  2316.  
  2317. Due to legal and commercial reasons we monitor the use of MySQL
  2318. trademarks on products, books, and other items. We usually require a
  2319. fee for displaying `MySQL AB' logos on commercial products, since we
  2320. think it is reasonable that some of the revenue is returned to fund
  2321. further development of the `MySQL' database.
  2322.  
  2323. MySQL AB Partnership Logos
  2324. ..........................
  2325.  
  2326. `MySQL' partnership logos may be used only by companies and persons
  2327. having a written partnership agreement with `MySQL AB'. Partnerships
  2328. include certification as a `MySQL' trainer or consultant.  For more
  2329. information, please see *Note Partnering: Business Services Partnering.
  2330.  
  2331. Using the word `MySQL' in Printed Text or Presentations
  2332. .......................................................
  2333.  
  2334. `MySQL AB' welcomes references to the `MySQL' database, but it should
  2335. be noted that the word `MySQL' is a trademark of `MySQL AB'.  Because
  2336. of this, you must append the trademark symbol (`TM') to the first or
  2337. most prominent use of the word `MySQL' in a text and, where
  2338. appropriate, state that `MySQL' is a trademark of `MySQL AB'. For more
  2339. information, please refer to our trademark policy at
  2340. `http://www.mysql.com/company/trademark.html'.
  2341.  
  2342. Using the word `MySQL' in Company and Product Names
  2343. ...................................................
  2344.  
  2345. Use of the word `MySQL' in product or company names or in Internet
  2346. domain names is not allowed without written permission from `MySQL AB'.
  2347.  
  2348. MySQL Development Roadmap
  2349. =========================
  2350.  
  2351. This section provides a snapshot of the MySQL development roadmap,
  2352. including major features implemented or planned for MySQL 4.0, 4.1, and
  2353. 5.0.  The following sections provide information for each release.
  2354. Plans for some of the most requested features are summarized in the
  2355. following table.
  2356.  
  2357. *Feature*              *MySQL version*
  2358. Unions                 4.0
  2359. Subqueries             4.1
  2360. R-trees                4.1 (for MyISAM
  2361.                        tables)
  2362. Stored procedures      5.0
  2363. Cursors                5.0
  2364. Foreign keys           5.1 (3.23 with InnoDB)
  2365. Views                  5.1
  2366. Triggers               5.1
  2367. Full outer join        5.1
  2368. Constraints            5.1
  2369.  
  2370. MySQL 4.0 in a Nutshell
  2371. -----------------------
  2372.  
  2373. Long promised by `MySQL AB' and long awaited by our users, MySQL Server
  2374. 4.0 is now available in production version.
  2375.  
  2376. MySQL 4.0 is available for download from `http://www.mysql.com/' and
  2377. from our mirrors. MySQL 4.0 has been tested by a large number of users
  2378. and is in production use at many large sites.
  2379.  
  2380. The major new features of MySQL Server 4.0 are geared toward our
  2381. existing business and community users, enhancing the MySQL database
  2382. software as the solution for mission-critical, heavy-load database
  2383. systems.  Other new features target the users of embedded databases.
  2384.  
  2385. MySQL Version 4.0.12 was declared stable for production use in March
  2386. 2003. This means that, in future, only bug fixes will be done for the
  2387. 4.0 release series and only critical bug fixes will be done for the
  2388. older 3.23 series.  *Note Upgrading-from-3.23::.
  2389.  
  2390. New features to the `MySQL' software are being added to MySQL 4.1 which
  2391. is now also available (alpha version).  *Note MySQL 4.1 Nutshell::.
  2392.  
  2393. Features Available in MySQL 4.0
  2394. ...............................
  2395.  
  2396. Speed enhancements
  2397.         * MySQL 4.0 has a query cache that can give a huge speed boost
  2398.           to applications with repetitive queries. *Note Query Cache::.
  2399.  
  2400.         * Version 4.0 further increases the speed of MySQL Server in a
  2401.           number of areas, such as bulk `INSERT's, searching on packed
  2402.           indexes, creation of `FULLTEXT' indexes, and
  2403.           `COUNT(DISTINCT)'.
  2404.  
  2405. Embedded MySQL Server introduced
  2406.         * The new Embedded Server library (instead of client/server)
  2407.           can easily be used in standalone and embedded applications.
  2408.           *Note Nutshell Embedded MySQL::.
  2409.  
  2410. InnoDB storage engine as standard
  2411.         * The `InnoDB' storage engine is now offered as a standard
  2412.           feature of the `MySQL' server. This means full support for
  2413.           ACID _transactions_, _foreign keys_ with cascading
  2414.           UPDATE/DELETE, and _row-level locking_ are now standard
  2415.           features.  *Note InnoDB::.
  2416.  
  2417. New functionality
  2418.         * The enhanced `FULLTEXT' search properties of MySQL Server 4.0
  2419.           enables `FULLTEXT' indexing of large text masses with both
  2420.           binary and natural-language searching logic. You can
  2421.           customise minimal word length and define your own stop word
  2422.           lists in any human language, enabling a new set of
  2423.           applications to be built on MySQL Server.  *Note Fulltext
  2424.           Search::.
  2425.  
  2426. Standards compliance, portability, and migration
  2427.         * Features to simplify migration from other database systems to
  2428.           MySQL Server include `TRUNCATE TABLE' (as in Oracle).
  2429.  
  2430.         * Many users will also be happy to learn that MySQL Server now
  2431.           supports the `UNION' statement, a long-awaited standard SQL
  2432.           feature.
  2433.  
  2434.         * MySQL can now run natively on the Novell NetWare 6.0 platform.
  2435.           *Note Novell NetWare::.
  2436.  
  2437. Internationalisation
  2438.         * Our German, Austrian, and Swiss users will note that `MySQL'
  2439.           now supports a new character set, `latin1_de', which ensures
  2440.           that the _German sorting order_ sorts words with umlauts in
  2441.           the same order as do German telephone books.
  2442.  
  2443. Usability enhancements
  2444.      In the process of building features for new users, we have not
  2445.      forgotten requests from our community of loyal users.
  2446.  
  2447.         * Most `mysqld' parameters (startup options) can now be set
  2448.           without taking down the servers. This is a convenient feature
  2449.           for Database Administrators (DBAs).  *Note SET OPTION::.
  2450.  
  2451.         * Multi-table `DELETE' and `UPDATE' statements have been added..
  2452.  
  2453.         * Support has been added for `symbolic linking' to `MyISAM' at
  2454.           the table level (and not just the database level as before)
  2455.           and for enabling symlink handling by default on Windows.
  2456.  
  2457.         * `SQL_CALC_FOUND_ROWS' and `FOUND_ROWS()' are new functions
  2458.           that make it possible to find out the number of rows a
  2459.           `SELECT' query that includes a `LIMIT' clause would have
  2460.           returned without that clause.
  2461.  
  2462. The news section of this manual includes a more in-depth list of
  2463. features.  *Note News-4.0.x::.
  2464.  
  2465. Embedded MySQL Server
  2466. .....................
  2467.  
  2468. `libmysqld' makes MySQL Server suitable for a vastly expanded realm of
  2469. applications. Using the embedded MySQL server library, one can embed
  2470. MySQL Server into various applications and electronics devices, where
  2471. the end user has no knowledge of there actually being an underlying
  2472. database. Embedded MySQL Server is ideal for use behind the scenes in
  2473. Internet appliances, public kiosks, turnkey hardware/software
  2474. combination units, high performance Internet servers, self-contained
  2475. databases distributed on CD-ROM, and so on.
  2476.  
  2477. Many users of `libmysqld' will benefit from the MySQL _Dual Licensing_.
  2478. For those not wishing to be bound by the `GPL', the software is also
  2479. made available under a commercial license.  The embedded MySQL library
  2480. uses the same interface as the normal client library, so it is
  2481. convenient and easy to use. *Note libmysqld::.
  2482.  
  2483. MySQL 4.1 in a Nutshell
  2484. -----------------------
  2485.  
  2486. MySQL Server 4.0 laid the foundation for new features such as _nested
  2487. subqueries_ and _Unicode_ (implemented in version 4.1) and for the work
  2488. on SQL-99 _stored procedures_ being done for version 5.0. These
  2489. features come at the top of the wish list of many of our customers.
  2490.  
  2491. With these additions, critics of the MySQL Database Server have to be
  2492. more imaginative than ever in pointing out deficiencies in the MySQL
  2493. Database Management System. Already well-known for its stability,
  2494. speed, and ease of use, MySQL Server will be able to fulfill the
  2495. requirement checklists of very demanding buyers.
  2496.  
  2497. Features Available in MySQL 4.1
  2498. ...............................
  2499.  
  2500. The features listed in this section are implemented in MySQL 4.1. A few
  2501. other features are still planned for MySQL 4.1. *Note TODO MySQL 4.1::.
  2502.  
  2503. Most new features being coded, such as _stored procedures_, will be
  2504. available in MySQL 5.0. *Note TODO MySQL 5.0::.
  2505.  
  2506. Support for subqueries and derived tables
  2507.         * Subqueries are now supported. Here is an example:
  2508.                SELECT * FROM t1 WHERE t1.a=(SELECT t2.b FROM t2);
  2509.                
  2510.                SELECT * FROM t1 WHERE (1,2,3) IN (SELECT a,b,c FROM t2);
  2511.  
  2512.         * Derived tables (unnamed views) are now supported. Basically,
  2513.           a derived table is a subquery in the `FROM' clause of a
  2514.           `SELECT' statement. Here is an example:
  2515.                SELECT t1.a FROM t1, (SELECT * FROM t2) t3 WHERE t1.a=t3.a;
  2516.  
  2517. Speed enhancements
  2518.         * Faster binary protocol with prepared statements and parameter
  2519.           binding.  *Note C API Prepared statements::.
  2520.  
  2521.         * `BTREE' indexing is now supported for `HEAP' tables,
  2522.           significantly improving response time for non-exact searches.
  2523.  
  2524. New functionality
  2525.         * `CREATE TABLE table LIKE table' allows you to create a new
  2526.           table with the exact structure of an existing table, using a
  2527.           single command.
  2528.  
  2529.         * Support for OpenGIS spatial types (geographical data).  *Note
  2530.           Spatial extensions in MySQL::.
  2531.  
  2532.         * Replication can be done over SSL connections.
  2533.  
  2534. Standards compliance, portability, and migration
  2535.         * The new client/server protocol adds the ability to pass
  2536.           multiple warnings to the client, rather than only a single
  2537.           result. This makes jobs such as bulk loading of data much
  2538.           easier to track.  `SHOW WARNINGS' shows warnings for the last
  2539.           command.  *Note SHOW WARNINGS::.
  2540.  
  2541. Internationalisation
  2542.         * To support our ever expanding user base using local languages
  2543.           in applications, the MySQL software now offers extensive
  2544.           Unicode (UTF8) support.
  2545.  
  2546.         * Character sets can now be defined per column, table, and
  2547.           database.  This allows for a high degree of flexibility in
  2548.           application design, particularly for multi-language web sites.
  2549.  
  2550.         * For documentation for this improved character set support,
  2551.           see *Note Charset::.
  2552.  
  2553. Usability enhancements
  2554.         * In response to popular demand, we have added a server-based
  2555.           `HELP command' that can be used in the `mysql' command line
  2556.           client (and other clients) to get help for SQL commands.  The
  2557.           advantage of having this information on the server side is
  2558.           that the information is always applicable for that particular
  2559.           server version.
  2560.  
  2561.         * In the new client/server protocol, multi-line queries can now
  2562.           be enabled.  This allows you to issue several queries in a
  2563.           single call and then read all the results in one go.  *Note C
  2564.           API multiple queries::.
  2565.  
  2566.         * A new `INSERT ... ON DUPLICATE KEY UPDATE ...' syntax has been
  2567.           implemented. This allows you to `UPDATE' an existing row if
  2568.           the `INSERT' would have caused a duplicate in a `PRIMARY' or
  2569.           `UNIQUE' key (index).  *Note INSERT::.
  2570.  
  2571.         * We have designed a new aggregate function `GROUP_CONCAT()',
  2572.           adding the extremely useful capability of concatenating
  2573.           columns from grouped rows into a single result string.  *Note
  2574.           Group by functions::.
  2575.  
  2576.         * The new client/server protocol supports multiple result sets.
  2577.  
  2578. The news section in this manual includes a more in-depth list of
  2579. features.  *Note News-4.1.x::.
  2580.  
  2581. Stepwise Rollout
  2582. ................
  2583.  
  2584. New features are being added to MySQL 4.1, which is already available
  2585. for download (alpha version). *Note Nutshell Ready for Immediate Use::.
  2586.  
  2587. The set of features that are being added to version 4.1 is mostly
  2588. fixed. Additional development is already ongoing for version 5.0.
  2589. MySQL 4.1 will go through the steps of _Alpha_ (during which time new
  2590. features might still be added/changed), _Beta_ (when we have feature
  2591. freeze and only bug corrections will be done), and _Gamma_ (indicating
  2592. that a production release is just weeks ahead).  At the end of this
  2593. process, MySQL 4.1 will become the new production release.
  2594.  
  2595. Ready for Immediate Development Use
  2596. ...................................
  2597.  
  2598. MySQL 4.1 is currently in the alpha stage, and binaries are available
  2599. for download at `http://www.mysql.com/downloads/mysql-4.1.html'.  All
  2600. binary releases pass our extensive test suite without any errors on the
  2601. platforms on which we test.  *Note News-4.1.x::.
  2602.  
  2603. For those wishing to use the most recent development source for MySQL
  2604. 4.1, we have made our 4.1 BitKeeper repository publicly available.
  2605. *Note Installing source tree::.
  2606.  
  2607. MySQL 5.0, The Next Development Release
  2608. ---------------------------------------
  2609.  
  2610. New development for MySQL is focused on the 5.0 release, featuring
  2611. Stored Procedures and other new features.  *Note TODO MySQL 5.0::.
  2612.  
  2613. For those wishing to take a look at the bleeding edge of MySQL
  2614. development, we have made our BitKeeper repository for MySQL version
  2615. 5.0 publicly available.  *Note Installing source tree::.
  2616.  
  2617. MySQL Information Sources
  2618. =========================
  2619.  
  2620. MySQL Mailing Lists
  2621. -------------------
  2622.  
  2623. This section introduces you to the MySQL mailing lists and gives some
  2624. guidelines as to how the lists should be used. When you subscribe to a
  2625. mailing list, you will receive, as e-mail messages, all postings to the
  2626. list. You will also be able to send your own questions and answers to
  2627. the list.
  2628.  
  2629. The MySQL Mailing Lists
  2630. .......................
  2631.  
  2632. To subscribe to or unsubscribe from any of the mailing lists described
  2633. in this section, visit `http://lists.mysql.com/'.  Please *do not* send
  2634. messages about subscribing or unsubscribing to any of the mailing
  2635. lists, because such messages are distributed automatically to thousands
  2636. of other users.
  2637.  
  2638. Your local site may have many subscribers to a MySQL mailing list.  If
  2639. so, the site may have a local mailing list, so that messages sent from
  2640. `lists.mysql.com' to your site are propagated to the local list.  In
  2641. such cases, please contact your system administrator to be added to or
  2642. dropped from the local MySQL list.
  2643.  
  2644. If you wish to have traffic for a mailing list go to a separate mailbox
  2645. in your mail program, set up a filter based on the message headers.
  2646. You can use either the `List-ID:' or `Delivered-To:' headers to identify
  2647. list messages.
  2648.  
  2649. The MySQL mailing lists are as follows:
  2650.  
  2651. ``announce''
  2652.      This list is for announcements of new versions of MySQL and related
  2653.      programs.  This is a low-volume list to which all MySQL users
  2654.      should subscribe.
  2655.  
  2656. ``mysql''
  2657.      This is the main list for general MySQL discussion.  Please note
  2658.      that some topics are better discussed on the more-specialised
  2659.      lists.  If you post to the wrong list, you may not get an answer.
  2660.  
  2661. ``mysql-digest''
  2662.      This is the `mysql' list in digest form.  Subscribing to this list
  2663.      means you will get all list messages, sent as one large mail
  2664.      message once a day.
  2665.  
  2666. ``bugs''
  2667.      This list will be of interest to you if you want to stay informed
  2668.      about issues reported since the last release of `MySQL' or if you
  2669.      want to be actively involved in the process of bug hunting and
  2670.      fixing.  *Note Bug reports::.
  2671.  
  2672. ``bugs-digest''
  2673.      This is the `bugs' list in digest form.
  2674.  
  2675. ``internals''
  2676.      This list is for people who work on the MySQL code.  This is also
  2677.      the forum for discussions on MySQL development and post patches.
  2678.  
  2679. ``internals-digest''
  2680.      This is the `internals' list in digest form.
  2681.  
  2682. ``mysqldoc''
  2683.      This list is for people who work on the MySQL documentation:
  2684.      people from MySQL AB, translators, and other community members.
  2685.  
  2686. ``mysqldoc-digest''
  2687.      This is the `mysqldoc' list in digest form.
  2688.  
  2689. ``benchmarks''
  2690.      This list is for anyone interested in performance issues.
  2691.      Discussions concentrate on database performance (not limited to
  2692.      MySQL) but also include broader categories such as performance of
  2693.      the kernel, file system, disk system, and so on.
  2694.  
  2695. ``benchmarks-digest''
  2696.      This is the `benchmarks' list in digest form.
  2697.  
  2698. ``packagers''
  2699.      This list is for discussions on packaging and distributing MySQL.
  2700.      This is the forum used by distribution maintainers to exchange
  2701.      ideas on packaging MySQL and on ensuring that MySQL looks and
  2702.      feels as similar as possible on all supported platforms and
  2703.      operating systems.
  2704.  
  2705. ``packagers-digest''
  2706.      This is the `packagers' list in digest form.
  2707.  
  2708. ``java''
  2709.      This list is for discussions about the MySQL server and Java.It is
  2710.      mostly used to discuss JDBC drivers, including MySQL Connector/J.
  2711.  
  2712. ``java-digest''
  2713.      This is the `java' list in digest form.
  2714.  
  2715. ``win32''
  2716.      This list is for all things concerning the MySQL software on
  2717.      Microsoft operating systems, such as Windows 9x/Me/NT/2000/XP.
  2718.  
  2719. ``win32-digest''
  2720.      This is the `win32' list in digest form.
  2721.  
  2722. ``myodbc''
  2723.      This list is for all things concerning connecting to the MySQL
  2724.      server with ODBC.
  2725.  
  2726. ``myodbc-digest''
  2727.      This is the `myodbc' list in digest form.
  2728.  
  2729. ``mysqlcc''
  2730.      This list is for all things concerning the `MySQL Control Center'
  2731.      graphical client.
  2732.  
  2733. ``mysqlcc-digest''
  2734.      This is the `mysqlcc' list in digest form.
  2735.  
  2736. ``plusplus''
  2737.      This list is for all things concerning programming with the C++
  2738.      API to MySQL.
  2739.  
  2740. ``plusplus-digest''
  2741.      This is the `plusplus' list in digest form.
  2742.  
  2743. ``msql-mysql-modules''
  2744.      This list is for all things concerning the Perl support for MySQL
  2745.      with `msql-mysql-modules', which is now named `DBD-mysql'.
  2746.  
  2747. ``msql-mysql-modules-digest''
  2748.      This is the `msql-mysql-modules' list in digest form.
  2749.  
  2750. If you're unable to get an answer to your question(s) from a `MySQL'
  2751. mailing list, one option is to pay for support from MySQL AB. This will
  2752. put you in direct contact with MySQL developers. *Note Support::.
  2753.  
  2754. The following table shows some MySQL mailing lists in languages other
  2755. than English.  These lists are not operated by MySQL AB, so we can't
  2756. guarantee their quality.
  2757.  
  2758. `<mysql-france-subscribe@yahoogroups.com> A French mailing list'
  2759.  
  2760. `<list@tinc.net> A Korean mailing list'
  2761.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2762.  
  2763. `<mysql-de-request@lists.4t2.com> A German mailing list'
  2764.      E-mail `subscribe mysql-de your@e-mail.address' to this list.  You
  2765.      can find information about this mailing list at
  2766.      `http://www.4t2.com/mysql/'.
  2767.  
  2768. `<mysql-br-request@listas.linkway.com.br> A Portuguese mailing list'
  2769.      E-mail `subscribe mysql-br your@e-mail.address' to this list.
  2770.  
  2771. `<mysql-alta@elistas.net> A Spanish mailing list'
  2772.      E-mail `subscribe mysql your@e-mail.address' to this list.
  2773.  
  2774. Asking Questions or Reporting Bugs
  2775. ..................................
  2776.  
  2777. Before posting a bug report or question, please do the following:
  2778.  
  2779.    * Start by searching the MySQL online manual at:
  2780.      `http://www.mysql.com/doc/'
  2781.      We try to keep the manual up to date by updating it frequently with
  2782.      solutions to newly found problems. The change history appendix
  2783.      (`http://www.mysql.com/doc/en/News.html') can be particularly
  2784.      useful since it is quite possible that a newer version already
  2785.      contains a solution to your problem.
  2786.  
  2787.    * Search in the bugs database at `http://bugs.mysql.com/' to see
  2788.      whether the bug has already been reported/solved.
  2789.  
  2790.    * Search the MySQL mailing list archives:
  2791.      `http://lists.mysql.com/'
  2792.    * You can also use `http://www.mysql.com/search/' to search all the
  2793.      web pages (including the manual) that are located at
  2794.      `http://www.mysql.com/'.
  2795.  
  2796. If you can't find an answer in the manual or the archives, check with
  2797. your local MySQL expert.  If you still can't find an answer to your
  2798. question, please follow the guidelines on sending mail to a MySQL
  2799. mailing list, outlined in the next section, before contacting us.
  2800.  
  2801. How to Report Bugs or Problems
  2802. ..............................
  2803.  
  2804. Our bugs database is public, and can be browsed and searched by anyone
  2805. at `http://bugs.mysql.com/'.  If you log into the system, you will also
  2806. be able to enter new reports.
  2807.  
  2808. Writing a good bug report takes patience, but doing it right the first
  2809. time saves time both for us and for yourself.  A good bug report,
  2810. containing a full test case for the bug, makes it very likely that we
  2811. will fix the bug in the next release.  This section will help you write
  2812. your report correctly so that you don't waste your time doing things
  2813. that may not help us much or at all.
  2814.  
  2815. We encourage everyone to use the `mysqlbug' script to generate a bug
  2816. report (or a report about any problem).  `mysqlbug' can be found in the
  2817. `scripts' directory (source distribution) and in the `bin' directory
  2818. under your MySQL installation directory (binary distribution).  If you
  2819. are unable to use `mysqlbug' (for instance, if you are running on
  2820. Windows), it is still vital that you include all the necessary
  2821. information noted in this section (most importantly a description of
  2822. the operating system and the MySQL version).
  2823.  
  2824. The `mysqlbug' script helps you generate a report by determining much
  2825. of the following information automatically, but if something important
  2826. is missing, please include it with your message.  Please read this
  2827. section carefully and make sure that all the information described here
  2828. is included in your report.
  2829.  
  2830. Preferably, you should test the problem using the latest production or
  2831. development version of MySQL Server before posting.  Anyone should be
  2832. able to repeat the bug by just using '`mysql test < script'' on the
  2833. included test case or run the shell or Perl script that is included in
  2834. the bug report.
  2835.  
  2836. All bugs posted in the bugs database at `http://bugs.mysql.com/' will
  2837. be corrected or documented in the next MySQL release. If only minor
  2838. code changes are needed to correct a problem, we will also post a patch
  2839. that fixes the problem.
  2840.  
  2841. The normal place to report bugs is `http://bugs.mysql.com/'.
  2842.  
  2843. If you have found a sensitive security bug in MySQL, please send an
  2844. e-mail to <security@mysql.com>.
  2845.  
  2846. If you have a repeatable bug report, please report this into the bugs
  2847. database at `http://bugs.mysql.com/'.  Note that even in this case it's
  2848. good to run the `mysqlbug' script first to find information about your
  2849. system.  Any bug that we are able to repeat has a high chance of being
  2850. fixed in the next MySQL release.
  2851.  
  2852. To report other problems, you can use one of the MySQL mailing lists.
  2853.  
  2854. Remember that it is possible for us to respond to a message containing
  2855. too much information, but not to one containing too little.  People
  2856. often omit facts because they think they know the cause of a problem
  2857. and assume that some details don't matter.  A good principle is: if you
  2858. are in doubt about stating something, state it.  It is a thousand times
  2859. faster and less troublesome to write a couple of lines more in your
  2860. report than to be forced to ask again and wait for the answer because
  2861. you didn't include enough information the first time.
  2862.  
  2863. The most common errors made in bug reports are (a) not including the
  2864. version number of the MySQL distribution used and (b) not fully
  2865. describing the platform on which the MySQL server is installed
  2866. (including the platform type and version number).  This is highly
  2867. relevant information, and in 99 cases out of 100 the bug report is
  2868. useless without it.  Very often we get questions like, "Why doesn't
  2869. this work for me?" Then we find that the feature requested wasn't
  2870. implemented in that MySQL version, or that a bug described in a report
  2871. has already been fixed in newer MySQL versions.  Sometimes the error is
  2872. platform-dependent; in such cases, it is next to impossible for us to
  2873. fix anything without knowing the operating system and the version
  2874. number of the platform.
  2875.  
  2876. Remember also to provide information about your compiler, if it is
  2877. related to the problem.  Often people find bugs in compilers and think
  2878. the problem is MySQL-related.  Most compilers are under development all
  2879. the time and become better version by version.  To determine whether
  2880. your problem depends on your compiler, we need to know what compiler
  2881. you use.  Note that every compiling problem should be regarded as a bug
  2882. and reported accordingly.
  2883.  
  2884. It is most helpful when a good description of the problem is included
  2885. in the bug report.  That is, give a good example of all the things you
  2886. did that led to the problem and describe, in exact detail, the problem
  2887. itself.  The best reports are those that include a full example showing
  2888. how to reproduce the bug or problem.  *Note Reproduceable test case::.
  2889.  
  2890. If a program produces an error message, it is very important to include
  2891. the message in your report.  If we try to search for something from the
  2892. archives using programs, it is better that the error message reported
  2893. exactly matches the one that the program produces.  (Even the case
  2894. should be observed.)  You should never try to remember what the error
  2895. message was; instead, copy and paste the entire message into your
  2896. report.
  2897.  
  2898. If you have a problem with MyODBC, please try to generate a MyODBC
  2899. trace file and send it with your report.  *Note MyODBC bug report::.
  2900.  
  2901. Please remember that many of the people who will read your report will
  2902. do so using an 80-column display.  When generating reports or examples
  2903. using the `mysql' command-line tool, you should therefore use the
  2904. `--vertical' option (or the `\G' statement terminator) for output that
  2905. would exceed the available width for such a display (for example, with
  2906. the `EXPLAIN SELECT' statement; see the example later in this section).
  2907.  
  2908. Please include the following information in your report:
  2909.  
  2910.    * The version number of the MySQL distribution you are using (for
  2911.      example, MySQL Version 4.0.12). You can find out which version you
  2912.      are running by executing `mysqladmin version'.  `mysqladmin' can be
  2913.      found in the `bin' directory under your MySQL installation
  2914.      directory.
  2915.  
  2916.    * The manufacturer and model of the machine on which you experience
  2917.      the problem.
  2918.  
  2919.    * The operating system name and version.  For most operating
  2920.      systems, you can get this information by executing the Unix
  2921.      command `uname -a'.  If you work with Windows, you can usually get
  2922.      the name and version number by double-clicking your "My Computer"
  2923.      icon and pulling down the "Help/About Windows" menu.
  2924.  
  2925.    * Sometimes the amount of memory (real and virtual) is relevant. If
  2926.      in doubt, include these values.
  2927.  
  2928.    * If you are using a source distribution of the MySQL software, the
  2929.      name and version number of the compiler used is needed.  If you
  2930.      have a binary distribution, the distribution name is needed.
  2931.  
  2932.    * If the problem occurs during compilation, include the exact error
  2933.      message(s) and also a few lines of context around the offending
  2934.      code in the file where the error occurrs.
  2935.  
  2936.    * If `mysqld' died, you should also report the query that crashed
  2937.      `mysqld'.  You can usually find this out by running `mysqld' with
  2938.      logging enabled.  *Note Using log files::.
  2939.  
  2940.    * If a database table is related to the problem, include the output
  2941.      from `mysqldump --no-data db_name tbl_name1 tbl_name2 ...'.  This
  2942.      is very easy to do and is a powerful way to get information about
  2943.      any table in a database.  The information will help us create a
  2944.      situation matching the one you have.
  2945.  
  2946.    * For speed-related bugs or problems with `SELECT' statements, you
  2947.      should always include the output of `EXPLAIN SELECT ...', and at
  2948.      least the number of rows that the `SELECT' statement produces.  You
  2949.      should also include the output from `SHOW CREATE TABLE tbl_name'
  2950.      for each involved table. The more information you give about your
  2951.      situation, the more likely it is that someone can help you.  The
  2952.      following is an example of a very good bug report (it should of
  2953.      course be posted with the `mysqlbug' script).
  2954.  
  2955.      Example run using the `mysql' command-line tool (note the use of
  2956.      the `\G' statement terminator for statements whose output width
  2957.      would otherwise exceed that of an 80-column display device):
  2958.  
  2959.           mysql> SHOW VARIABLES;
  2960.           mysql> SHOW COLUMNS FROM ...\G
  2961.                  <output from SHOW COLUMNS>
  2962.           mysql> EXPLAIN SELECT ...\G
  2963.                  <output from EXPLAIN>
  2964.           mysql> FLUSH STATUS;
  2965.           mysql> SELECT ...;
  2966.                  <A short version of the output from SELECT,
  2967.                  including the time taken to run the query>
  2968.           mysql> SHOW STATUS;
  2969.                  <output from SHOW STATUS>
  2970.  
  2971.    * If a bug or problem occurs while running `mysqld', try to provide
  2972.      an input script that will reproduce the anomaly.  This script
  2973.      should include any necessary source files.  The more closely the
  2974.      script can reproduce your situation, the better.  If you can make
  2975.      a reproducible test case, you should post it on
  2976.      `http://bugs.mysql.com/' for high-priority treatment.
  2977.  
  2978.      If you can't provide a script, you should at least include the
  2979.      output from `mysqladmin variables extended-status processlist' in
  2980.      your mail to provide some information on how your system is
  2981.      performing.
  2982.  
  2983.    * If you can't produce a test case with only a few rows, or if the
  2984.      test table is too big to be mailed to the mailing list (more than
  2985.      10 rows), you should dump your tables using `mysqldump' and create
  2986.      a `README' file that describes your problem.
  2987.  
  2988.      Create a compressed archive of your files using `tar' and `gzip'
  2989.      or `zip', and use `ftp' to transfer the archive to
  2990.      `ftp://support.mysql.com/pub/mysql/secret/'.  Then enter the
  2991.      problem into our bugs database at `http://bugs.mysql.com/'.
  2992.  
  2993.    * If you think that the MySQL server produces a strange result from
  2994.      a query, include not only the result, but also your opinion of
  2995.      what the result should be, and an account describing the basis for
  2996.      your opinion.
  2997.  
  2998.    * When giving an example of the problem, it's better to use the
  2999.      variable names, table names, etc., that exist in your actual
  3000.      situation than to come up with new names.  The problem could be
  3001.      related to the name of a variable or table.  These cases are rare,
  3002.      perhaps, but it is better to be safe than sorry.  After all, it
  3003.      should be easier for you to provide an example that uses your
  3004.      actual situation, and it is by all means better for us.  In case
  3005.      you have data you don't want to show to others, you can use `ftp'
  3006.      to transfer it to `ftp://support.mysql.com/pub/mysql/secret/'.  If
  3007.      the data is really top secret and you don't want to show it even
  3008.      to us, then go ahead and provide an example using other names, but
  3009.      please regard this as the last choice.
  3010.  
  3011.    * Include all the options given to the relevant programs, if
  3012.      possible.  For example, indicate the options that you use when you
  3013.      start the `mysqld' daemon as well as the options that you use to
  3014.      run any MySQL client programs.  The options to programs like
  3015.      `mysqld' and `mysql', and to the `configure' script, are often
  3016.      keys to answers and are very relevant.  It is never a bad idea to
  3017.      include them.  If you use any modules, such as Perl or PHP, please
  3018.      include the version number(s) of those as well.
  3019.  
  3020.    * If your question is related to the privilege system, please
  3021.      include the output of `mysqlaccess', the output of `mysqladmin
  3022.      reload', and all the error messages you get when trying to
  3023.      connect.  When you test your privileges, you should first run
  3024.      `mysqlaccess'.  After this, execute `mysqladmin reload version'
  3025.      and try to connect with the program that gives you trouble.
  3026.      `mysqlaccess' can be found in the `bin' directory under your MySQL
  3027.      installation directory.
  3028.  
  3029.    * If you have a patch for a bug, do include it.  But don't assume
  3030.      the patch is all we need, or that we will use it, if you don't
  3031.      provide some necessary information such as test cases showing the
  3032.      bug that your patch fixes.  We might find problems with your patch
  3033.      or we might not understand it at all; if so, we can't use it.
  3034.  
  3035.      If we can't verify exactly what the patch is meant for, we won't
  3036.      use it.  Test cases will help us here.  Show that the patch will
  3037.      handle all the situations that may occur.  If we find a borderline
  3038.      case (even a rare one) where the patch won't work, it may be
  3039.      useless.
  3040.  
  3041.    * Guesses about what the bug is, why it occurs, or what it depends on
  3042.      are usually wrong.  Even the MySQL team can't guess such things
  3043.      without first using a debugger to determine the real cause of a
  3044.      bug.
  3045.  
  3046.    * Indicate in your bug report that you have checked the reference
  3047.      manual and mail archive so that others know you have tried to
  3048.      solve the problem yourself.
  3049.  
  3050.    * If you get a `parse error', please check your syntax closely.  If
  3051.      you can't find something wrong with it, it's extremely likely that
  3052.      your current version of MySQL Server doesn't support the syntax
  3053.      you are using.  If you are using the current version and the
  3054.      manual at `http://www.mysql.com/doc/' doesn't cover the syntax you
  3055.      are using, MySQL Server doesn't support your query.  In this case,
  3056.      your only options are to implement the syntax yourself or e-mail
  3057.      <licensing@mysql.com> and ask for an offer to implement it.
  3058.  
  3059.      If the manual covers the syntax you are using, but you have an
  3060.      older version of MySQL Server, you should check the MySQL change
  3061.      history to see when the syntax was implemented.  In this case, you
  3062.      have the option of upgrading to a newer version of MySQL Server.
  3063.      *Note News::.
  3064.  
  3065.    * If your problem is that your data appears corrupt or you get
  3066.      errors when you access a particular table, you should first check
  3067.      and then try repairing your tables with `myisamchk' or `CHECK
  3068.      TABLE' and `REPAIR TABLE'.  *Note MySQL Database Administration::.
  3069.  
  3070.    * If you often get corrupted tables you should try to find out when
  3071.      and why this happens.  In this case, the
  3072.      `mysql-data-directory/'hostname'.err' file may contain some
  3073.      information about what happened.  *Note Error log::.  Please
  3074.      include any relevant information from this file in your bug
  3075.      report.  Normally `mysqld' should *never* crash a table if nothing
  3076.      killed it in the middle of an update.  If you can find the cause
  3077.      of `mysqld' dying, it's much easier for us to provide you with a
  3078.      fix for the problem.  *Note What is crashing::.
  3079.  
  3080.    * If possible, download and install the most recent version of MySQL
  3081.      Server and check whether it solves your problem.  All versions of
  3082.      the MySQL software are thoroughly tested and should work without
  3083.      problems.  We believe in making everything as backward-compatible
  3084.      as possible, and you should be able to switch MySQL versions
  3085.      without difficulty.  *Note Which version::.
  3086.  
  3087. If you are a support customer, please cross-post the bug report to
  3088. <mysql-support@mysql.com> for higher-priority treatment, as well as to
  3089. the appropriate mailing list to see if someone else has experienced (and
  3090. perhaps solved) the problem.
  3091.  
  3092. For information on reporting bugs in `MyODBC', see *Note ODBC
  3093. Problems::.
  3094.  
  3095. For solutions to some common problems, see *Note Problems::.
  3096.  
  3097. When answers are sent to you individually and not to the mailing list,
  3098. it is considered good etiquette to summarise the answers and send the
  3099. summary to the mailing list so that others may have the benefit of
  3100. responses you received that helped you solve your problem.
  3101.  
  3102. Guidelines for Answering Questions on the Mailing List
  3103. ......................................................
  3104.  
  3105. If you consider your answer to have broad interest, you may want to
  3106. post it to the mailing list instead of replying directly to the
  3107. individual who asked.  Try to make your answer general enough that
  3108. people other than the original poster may benefit from it.  When you
  3109. post to the list, please make sure that your answer is not a
  3110. duplication of a previous answer.
  3111.  
  3112. Try to summarise the essential part of the question in your reply;
  3113. don't feel obliged to quote the entire original message.
  3114.  
  3115. Please don't post mail messages from your browser with HTML mode turned
  3116. on.  Many users don't read mail with a browser.
  3117.  
  3118. MySQL Community Support on IRC (Internet Relay Chat)
  3119. ----------------------------------------------------
  3120.  
  3121. In addition to the various MySQL mailing lists, you can find experienced
  3122. community people on `IRC' (`Internet Relay Chat').  These are the best
  3123. networks/channels currently known to us:
  3124.  
  3125.    * *freenode* (see `http://www.freenode.net/' for servers)
  3126.         * `#mysql' Primarily MySQL questions but other database and SQL
  3127.           questions welcome.
  3128.  
  3129.         * `#mysqlphp' Questions about MySQL+PHP, a popular combination.
  3130.  
  3131.         * `#mysqlperl' Questions about MySQL+Perl, another popular
  3132.           combination.
  3133.  
  3134.    * *EFnet* (see `http://www.efnet.org/' for servers)
  3135.         * `#mysql' MySQL questions.
  3136.  
  3137. If you are looking for IRC client software to connect to an IRC network,
  3138. take a look at `X-Chat' (`http://www.xchat.org/').  X-Chat (GPL
  3139. licensed) is available for Unix as well as for Windows platforms.
  3140.  
  3141. MySQL Standards Compliance
  3142. ==========================
  3143.  
  3144. This section describes how MySQL relates to the ANSI/ISO SQL standards.
  3145. MySQL Server has many extensions to the SQL standard, and here you will
  3146. find out what they are and how to use them.  You will also find
  3147. information about functionality missing from MySQL Server, and how to
  3148. work around some differences.
  3149.  
  3150. Our goal is to not, without a very good reason, restrict MySQL Server
  3151. usability for any usage.  Even if we don't have the resources to do
  3152. development for every possible use, we are always willing to help and
  3153. offer suggestions to people who are trying to use MySQL Server in new
  3154. territories.
  3155.  
  3156. One of our main goals with the product is to continue to work toward
  3157. compliance with the SQL-99 standard, but without sacrificing speed or
  3158. reliability.  We are not afraid to add extensions to SQL or support for
  3159. non-SQL features if this greatly increases the usability of MySQL
  3160. Server for a big part of our users.  (The new `HANDLER' interface in
  3161. MySQL Server 4.0 is an example of this strategy. *Note `HANDLER':
  3162. HANDLER.)
  3163.  
  3164. We will continue to support transactional and non-transactional
  3165. databases to satisfy both heavy web/logging usage and mission-critical
  3166. 24/7 usage.
  3167.  
  3168. MySQL Server was designed from the start to work with medium size
  3169. databases (10-100 million rows, or about 100 MB per table) on small
  3170. computer systems.  We will continue to extend MySQL Server to work even
  3171. better with terabyte-size databases, as well as to make it possible to
  3172. compile a reduced MySQL version that is more suitable for hand-held
  3173. devices and embedded usage.  The compact design of the MySQL server
  3174. makes both of these directions possible without any conflicts in the
  3175. source tree.
  3176.  
  3177. We are currently not targeting realtime support or clustered databases
  3178. (even if you can already do a lot of things with our replication
  3179. services).
  3180.  
  3181. We are looking at providing XML support in the database server.
  3182.  
  3183. What Standards Does MySQL Follow?
  3184. ---------------------------------
  3185.  
  3186. Entry-level SQL-92. ODBC levels 0-3.51.
  3187.  
  3188. We are aiming toward supporting the full SQL-99 standard, but without
  3189. concessions to speed and quality of the code.
  3190.  
  3191. Running MySQL in ANSI Mode
  3192. --------------------------
  3193.  
  3194. If you start `mysqld' with the `--ansi' or `--sql-mode=ANSI' option,
  3195. the following behaviours of MySQL Server change:
  3196.  
  3197.    * `||' is a string concatenation operator rather than a synonym for
  3198.      `OR'.
  3199.  
  3200.    * `"' is treated as an identifier quote character (like the MySQL
  3201.      Server ``' quote character) and not as a string quote character.
  3202.      You can still use ``' to quote identifers in ANSI mode. An
  3203.      implication of this is that you cannot use double quotes to quote
  3204.      a literal string, because it will be intepreted as an identifier.
  3205.  
  3206.    * You can have any number of spaces between a function name and the
  3207.      `(' character.  This forces all function names to be treated as
  3208.      reserved words. As a result, if you want to access any database,
  3209.      table, or column name that is a reserved word, you must quote it.
  3210.      For example, because there is a `USER()' function, the name of the
  3211.      `user' table in the `mysql' database and the `User' column in that
  3212.      table become reserved, so you must quote them:
  3213.  
  3214.           SELECT "User" FROM mysql."user";
  3215.  
  3216.    * `REAL' is a synonym for `FLOAT' instead of a synonym for `DOUBLE'.
  3217.  
  3218.    * The default transaction isolation level is `SERIALIZABLE'.  *Note
  3219.      `SET TRANSACTION': SET TRANSACTION.
  3220.  
  3221.    * You can use a field/expression in `GROUP BY' that is not in the
  3222.      field list.
  3223.  
  3224. Running the server in ANSI mode is the same as starting it with these
  3225. options:
  3226.  
  3227.      --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  3228.      --transaction-isolation=SERIALIZABLE
  3229.  
  3230. In MySQL 4.1, you can achieve the same effect with these two statements:
  3231.  
  3232.      SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3233.      SET GLOBAL sql_mode =
  3234.        "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY";
  3235.  
  3236. In MySQL 4.1.1, the `sql_mode' options shown can be also be set with:
  3237.  
  3238.      SET GLOBAL sql_mode="ansi";
  3239.  
  3240. In this case, the value of the `sql_mode' variable will be set to all
  3241. options that are relevant for ANSI mode. You can check the result by
  3242. doing:
  3243.  
  3244.      mysql> SET GLOBAL sql_mode="ansi";
  3245.      mysql> SELECT @@GLOBAL.sql_mode;
  3246.               -> "REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI"
  3247.  
  3248. MySQL Extensions to the SQL-92 Standard
  3249. ---------------------------------------
  3250.  
  3251. MySQL Server includes some extensions that you probably will not find in
  3252. other SQL databases.  Be warned that if you use them, your code will
  3253. not be portable to other SQL servers.  In some cases, you can write
  3254. code that includes MySQL extensions, but is still portable, by using
  3255. comments of the form `/*! ... */'.  In this case, MySQL Server will
  3256. parse and execute the code within the comment as it would any other
  3257. MySQL statement, but other SQL servers will ignore the extensions.  For
  3258. example:
  3259.  
  3260.      SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  3261.  
  3262. If you add a version number after the `'!'', the syntax will be
  3263. executed only if the MySQL version is equal to or newer than the used
  3264. version number:
  3265.  
  3266.      CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
  3267.  
  3268. This means that if you have Version 3.23.02 or newer, MySQL Server will
  3269. use the `TEMPORARY' keyword.
  3270.  
  3271. The following is a list of MySQL extensions:
  3272.  
  3273.    * The field types `MEDIUMINT', `SET', `ENUM', and the different
  3274.      `BLOB' and `TEXT' types.
  3275.  
  3276.    * The field attributes `AUTO_INCREMENT', `BINARY', `NULL',
  3277.      `UNSIGNED', and `ZEROFILL'.
  3278.  
  3279.    * All string comparisons are case-insensitive by default, with sort
  3280.      ordering determined by the current character set (ISO-8859-1
  3281.      Latin1 by default).  If you don't like this, you should declare
  3282.      your columns with the `BINARY' attribute or use the `BINARY' cast,
  3283.      which causes comparisons to be done according to the ASCII order
  3284.      used on the MySQL server host.
  3285.  
  3286.    * MySQL Server maps each database to a directory under the MySQL
  3287.      data directory, and tables within a database to filenames in the
  3288.      database directory.
  3289.  
  3290.      This has a few implications:
  3291.  
  3292.         - Database names and table names are case-sensitive in MySQL
  3293.           Server on operating systems that have case-sensitive
  3294.           filenames (like most Unix systems). *Note Name case
  3295.           sensitivity::.
  3296.  
  3297.         - Database, table, index, column, or alias names may begin with
  3298.           a digit (but may not consist solely of digits).
  3299.  
  3300.         - You can use standard system commands to back up, rename,
  3301.           move, delete, and copy tables.  For example, to rename a
  3302.           table, rename the `.MYD', `.MYI', and `.frm' files to which
  3303.           the table corresponds.
  3304.  
  3305.    * In SQL statements, you can access tables from different databases
  3306.      with the `db_name.tbl_name' syntax.  Some SQL servers provide the
  3307.      same functionality but call this `User space'.  MySQL Server
  3308.      doesn't support tablespaces as in: `create table
  3309.      ralph.my_table...IN my_tablespace'.
  3310.  
  3311.    * `LIKE' is allowed on numeric columns.
  3312.  
  3313.    * Use of `INTO OUTFILE' and `STRAIGHT_JOIN' in a `SELECT' statement.
  3314.      *Note `SELECT': SELECT.
  3315.  
  3316.    * The `SQL_SMALL_RESULT' option in a `SELECT' statement.
  3317.  
  3318.    * `EXPLAIN SELECT' to get a description of how tables are joined.
  3319.  
  3320.    * Use of index names, indexes on a prefix of a field, and use of
  3321.      `INDEX' or `KEY' in a `CREATE TABLE' statement. *Note `CREATE
  3322.      TABLE': CREATE TABLE.
  3323.  
  3324.    * Use of `TEMPORARY' or `IF NOT EXISTS' with `CREATE TABLE'.
  3325.  
  3326.    * Use of `COUNT(DISTINCT list)' where `list' has more than one
  3327.      element.
  3328.  
  3329.    * Use of `CHANGE col_name', `DROP col_name', or `DROP INDEX',
  3330.      `IGNORE' or `RENAME' in an `ALTER TABLE' statement. *Note `ALTER
  3331.      TABLE': ALTER TABLE.
  3332.  
  3333.    * Use of `RENAME TABLE'. *Note `RENAME TABLE': RENAME TABLE.
  3334.  
  3335.    * Use of multiple `ADD', `ALTER', `DROP', or `CHANGE' clauses in an
  3336.      `ALTER TABLE' statement.
  3337.  
  3338.    * Use of `DROP TABLE' with the keywords `IF EXISTS'.
  3339.  
  3340.    * You can drop multiple tables with a single `DROP TABLE' statement.
  3341.  
  3342.    * The `ORDER BY' and `LIMIT' clauses of the `UPDATE' and `DELETE'
  3343.      statements.
  3344.  
  3345.    * `INSERT INTO ... SET col_name = ...' syntax.
  3346.  
  3347.    * The `DELAYED' clause of the `INSERT' and `REPLACE' statements.
  3348.  
  3349.    * The `LOW_PRIORITY' clause of the `INSERT', `REPLACE', `DELETE',
  3350.      and `UPDATE' statements.
  3351.  
  3352.    * Use of `LOAD DATA INFILE'. In many cases, this syntax is
  3353.      compatible with Oracle's `LOAD DATA INFILE'. *Note `LOAD DATA':
  3354.      LOAD DATA.
  3355.  
  3356.    * The `ANALYZE TABLE', `CHECK TABLE', `OPTIMIZE TABLE', and `REPAIR
  3357.      TABLE' statements.
  3358.  
  3359.    * The `SHOW' statement.  *Note `SHOW': SHOW.
  3360.  
  3361.    * Strings may be enclosed by either `"' or `'', not just by `''.
  3362.  
  3363.    * Use of the escape `\' character.
  3364.  
  3365.    * The `SET' statement. *Note `SET': SET OPTION.
  3366.  
  3367.    * You don't need to name all selected columns in the `GROUP BY' part.
  3368.      This gives better performance for some very specific, but quite
  3369.      normal queries.  *Note Group by functions::.
  3370.  
  3371.    * One can specify `ASC' and `DESC' with `GROUP BY'.
  3372.  
  3373.    * To make it easier for users who come from other SQL environments,
  3374.      MySQL Server supports aliases for many functions. For example, all
  3375.      string functions support both standard SQL syntax and ODBC syntax.
  3376.  
  3377.    * MySQL Server understands the `||' and `&&' operators to mean
  3378.      logical OR and AND, as in the C programming language.  In MySQL
  3379.      Server, `||' and `OR' are synonyms, as are `&&' and `AND'.
  3380.      Because of this nice syntax, MySQL Server doesn't support the
  3381.      standard SQL-99 `||' operator for string concatenation; use
  3382.      `CONCAT()' instead. Because `CONCAT()' takes any number of
  3383.      arguments, it's easy to convert use of the `||' operator to MySQL
  3384.      Server.
  3385.  
  3386.    * `CREATE DATABASE' or `DROP DATABASE'.  *Note `CREATE DATABASE':
  3387.      CREATE DATABASE.
  3388.  
  3389.    * The `%' operator is a synonym for `MOD()'.  That is, `N % M' is
  3390.      equivalent to `MOD(N,M)'.  `%' is supported for C programmers and
  3391.      for compatibility with PostgreSQL.
  3392.  
  3393.    * The `=', `<>', `<=' ,`<', `>=',`>', `<<', `>>', `<=>', `AND',
  3394.      `OR', or `LIKE' operators may be used in column comparisons to the
  3395.      left of the `FROM' in `SELECT' statements.  For example:
  3396.  
  3397.           mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  3398.  
  3399.    * The `LAST_INSERT_ID()' function.  *Note `mysql_insert_id()':
  3400.      mysql_insert_id.
  3401.  
  3402.    * The `REGEXP' and `NOT REGEXP' extended regular expression
  3403.      operators.
  3404.  
  3405.    * `CONCAT()' or `CHAR()' with one argument or more than two
  3406.      arguments.  (In MySQL Server, these functions can take any number
  3407.      of arguments.)
  3408.  
  3409.    * The `BIT_COUNT()', `CASE', `ELT()', `FROM_DAYS()', `FORMAT()',
  3410.      `IF()', `PASSWORD()', `ENCRYPT()', `MD5()', `ENCODE()', `DECODE()',
  3411.      `PERIOD_ADD()', `PERIOD_DIFF()', `TO_DAYS()', or `WEEKDAY()'
  3412.      functions.
  3413.  
  3414.    * Use of `TRIM()' to trim substrings.  SQL-99 supports removal of
  3415.      single characters only.
  3416.  
  3417.    * The `GROUP BY' functions `STD()', `BIT_OR()', `BIT_AND()',
  3418.      `BIT_XOR()', and `GROUP_CONCAT()'.  *Note Group by functions::.
  3419.  
  3420.    * Use of `REPLACE' instead of `DELETE' + `INSERT'.  *Note `REPLACE':
  3421.      REPLACE.
  3422.  
  3423.    * The `FLUSH', `RESET' and `DO' statements.
  3424.  
  3425.    * The ability to set variables in a statement with `:=':
  3426.           SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg FROM test_table;
  3427.           SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  3428.  
  3429.  
  3430. MySQL Differences Compared to SQL-92
  3431. ------------------------------------
  3432.  
  3433. We try to make MySQL Server follow the ANSI SQL standard
  3434. (SQL-92/SQL-99) and the ODBC SQL standard, but in some cases MySQL
  3435. Server does things differently:
  3436.  
  3437.    * For `VARCHAR' columns, trailing spaces are removed when the value
  3438.      is stored. *Note Bugs::.
  3439.  
  3440.    * In some cases, `CHAR' columns are silently changed to `VARCHAR'
  3441.      columns. *Note Silent column changes::.
  3442.  
  3443.    * Privileges for a table are not automatically revoked when you
  3444.      delete a table. You must explicitly issue a `REVOKE' to revoke
  3445.      privileges for a table. *Note `GRANT': GRANT.
  3446.  
  3447. For a prioritised list indicating when new extensions will be added to
  3448. MySQL Server, you should consult the online MySQL TODO list at
  3449. `http://www.mysql.com/doc/en/TODO.html'.  That is the latest version of
  3450. the TODO list in this manual. *Note TODO::.
  3451.  
  3452. Subqueries
  3453. ..........
  3454.  
  3455. Subqueries are supported in MySQL version 4.1.  *Note Nutshell 4.1
  3456. features::.
  3457.  
  3458. Up to version 4.0, only nested queries of the form `INSERT ... SELECT
  3459. ...' and `REPLACE ... SELECT ...' are supported.  You can, however, use
  3460. the function `IN()' in other contexts.
  3461.  
  3462. You can often rewrite the query without a subquery:
  3463.  
  3464.      SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
  3465.  
  3466. This can be rewritten as:
  3467.  
  3468.      SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
  3469.  
  3470. The queries:
  3471.      SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
  3472.      SELECT * FROM table1 WHERE NOT EXISTS (SELECT id FROM table2
  3473.                                             WHERE table1.id=table2.id);
  3474.  
  3475. Can be rewritten as:
  3476.  
  3477.      SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id
  3478.                                             WHERE table2.id IS NULL;
  3479.  
  3480. Using a `LEFT [OUTER] JOIN' is generally much faster than an equivalent
  3481. subquery because the server can optimise it better, a fact that is not
  3482. specific to MySQL Server alone.  Prior to SQL-92, outer joins did not
  3483. exist, so subqueries were the only way to do certain things in those
  3484. bygone days. But that is no longer the case, MySQL Server and many
  3485. other modern database systems offer a whole range of outer joins types.
  3486.  
  3487. For more complicated subqueries you can often create temporary tables
  3488. to hold the subquery.  In some cases, however, this option will not
  3489. work. The most frequently encountered of these cases arises with
  3490. `DELETE' statements, for which standard SQL does not support joins
  3491. (except in subqueries).  For this situation there are three options
  3492. available:
  3493.  
  3494.    * The first option is to upgrade to MySQL version 4.1.
  3495.  
  3496.    * The second option is to use a procedural programming language
  3497.      (such as Perl or PHP) to submit a `SELECT' query to obtain the
  3498.      primary keys for the records to be deleted, and then use these
  3499.      values to construct the `DELETE' statement (`DELETE FROM ... WHERE
  3500.      ... IN (key1, key2, ...)').
  3501.  
  3502.    * The third option is to use interactive SQL to construct a set of
  3503.      `DELETE' statements automatically, using the MySQL extension
  3504.      `CONCAT()' (in lieu of the standard `||' operator).  For example:
  3505.  
  3506.           SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', "'", tab1.pkid, "'", ';')
  3507.             FROM tab1, tab2
  3508.            WHERE tab1.col1 = tab2.col2;
  3509.  
  3510.      You can place this query in a script file and redirect input from
  3511.      it to the `mysql' command-line interpreter, piping its output back
  3512.      to a second instance of the interpreter:
  3513.  
  3514.           shell> mysql --skip-column-names mydb < myscript.sql | mysql mydb
  3515.  
  3516. MySQL Server 4.0 supports multi-table `DELETE's that can be used to
  3517. efficiently delete rows based on information from one table or even
  3518. from many tables at the same time.
  3519.  
  3520. `SELECT INTO TABLE'
  3521. ...................
  3522.  
  3523. MySQL Server doesn't yet support the Oracle SQL extension: `SELECT ...
  3524. INTO TABLE ...'.  Instead, MySQL Server supports the SQL-99 syntax
  3525. `INSERT INTO ... SELECT ...', which is basically the same thing. *Note
  3526. INSERT SELECT::.
  3527.  
  3528.      INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID
  3529.             FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;
  3530.  
  3531. Alternatively, you can use `SELECT INTO OUTFILE...' or `CREATE TABLE
  3532. ... SELECT'.
  3533.  
  3534. Transactions and Atomic Operations
  3535. ..................................
  3536.  
  3537. MySQL Server (version 3.23-max and all versions 4.0 and above) supports
  3538. transactions with the `InnoDB' and `BDB' `Transactional storage
  3539. engines'.  `InnoDB' provides _full_ `ACID' compliance.  *Note Table
  3540. types::.
  3541.  
  3542. The other non-transactional table types (such as `MyISAM') in MySQL
  3543. Server follow a different paradigm for data integrity called "`Atomic
  3544. Operations'." In transactional terms, `MyISAM' tables effectively
  3545. always operate in `AUTOCOMMIT=1' mode.  Atomic operations often offer
  3546. comparable integrity with higher performance.
  3547.  
  3548. With MySQL Server supporting both paradigms, the user is able to decide
  3549. if he needs the speed of atomic operations or if he needs to use
  3550. transactional features in his applications. This choice can be made on
  3551. a per-table basis.
  3552.  
  3553. As noted, the trade off for transactional vs. non-transactional table
  3554. types lies mostly in performance. Transactional tables have
  3555. significantly higher memory and diskspace requirements, and more CPU
  3556. overhead.  That said, transactional table types such as `InnoDB' do of
  3557. course offer many unique features. MySQL Server's modular design allows
  3558. the concurrent use of all these different storage engines to suit
  3559. different requirements and deliver optimum performance in all
  3560. situations.
  3561.  
  3562. But how does one use the features of MySQL Server to maintain rigorous
  3563. integrity even with the non-transactional `MyISAM' tables, and how do
  3564. these features compare with the transactional table types?
  3565.  
  3566.   1. In the transactional paradigm, if your applications are written in
  3567.      a way that is dependent on the calling of `ROLLBACK' instead of
  3568.      `COMMIT' in critical situations, transactions are more convenient.
  3569.      Transactions also ensure that unfinished updates or corrupting
  3570.      activities are not committed to the database; the server is given
  3571.      the opportunity to do an automatic rollback and your database is
  3572.      saved.
  3573.  
  3574.      MySQL Server, in almost all cases, allows you to resolve potential
  3575.      problems by including simple checks before updates and by running
  3576.      simple scripts that check the databases for inconsistencies and
  3577.      automatically repair or warn if such an inconsistency occurs. Note
  3578.      that just by using the MySQL log or even adding one extra log, one
  3579.      can normally fix tables perfectly with no data integrity loss.
  3580.  
  3581.   2. More often than not, critical transactional updates can be
  3582.      rewritten to be atomic. Generally speaking, all integrity problems
  3583.      that transactions solve can be done with `LOCK TABLES' or atomic
  3584.      updates, ensuring that you never will get an automatic abort from
  3585.      the server, which is a common problem with transactional database
  3586.      systems.
  3587.  
  3588.   3. Even a transactional system can lose data if the server goes down.
  3589.      The difference between different systems lies in just how small the
  3590.      time-lap is where they could lose data. No system is 100% secure,
  3591.      only "secure enough." Even Oracle, reputed to be the safest of
  3592.      transactional database systems, is reported to sometimes lose data
  3593.      in such situations.
  3594.  
  3595.      To be safe with MySQL Server, whether using transactional tables
  3596.      or not, you only need to have backups and have the binary logging
  3597.      turned on. With this you can recover from any situation that you
  3598.      could with any other transactional database system.  It is, of
  3599.      course, always good to have backups, independent of which database
  3600.      system you use.
  3601.  
  3602. The transactional paradigm has its benefits and its drawbacks. Many
  3603. users and application developers depend on the ease with which they can
  3604. code around problems where an abort appears to be, or is necessary.
  3605. However, even if you are new to the atomic operations paradigm, or more
  3606. familiar with transactions, do consider the speed benefit that
  3607. non-transactional tables can offer on the order of three to five times
  3608. the speed of the fastest and most optimally tuned transactional tables.
  3609.  
  3610. In situations where integrity is of highest importance, MySQL Server
  3611. offers transaction-level reliability and integrity even for
  3612. non-transactional tables.  If you lock tables with `LOCK TABLES', all
  3613. updates will stall until any integrity checks are made. If you only
  3614. obtain a read lock (as opposed to a write lock), reads and inserts are
  3615. still allowed to happen. The new inserted records will not be seen by
  3616. any of the clients that have a read lock until they release their read
  3617. locks. With `INSERT DELAYED' you can queue inserts into a local queue,
  3618. until the locks are released, without having the client wait for the
  3619. insert to complete. *Note INSERT DELAYED::.
  3620.  
  3621. "Atomic," in the sense that we mean it, is nothing magical. It only
  3622. means that you can be sure that while each specific update is running,
  3623. no other user can interfere with it, and there will never be an
  3624. automatic rollback (which can happen with transactional tables if you
  3625. are not very careful).  MySQL Server also guarantees that there will
  3626. not be any dirty reads.
  3627.  
  3628. Following are some techniques for working with non-transactional tables:
  3629.  
  3630.    * Loops that need transactions normally can be coded with the help of
  3631.      `LOCK TABLES', and you don't need cursors when you can update
  3632.      records on the fly.
  3633.  
  3634.    * To avoid using `ROLLBACK', you can use the following strategy:
  3635.  
  3636.        1. Use `LOCK TABLES ...' to lock all the tables you want to
  3637.           access.
  3638.  
  3639.        2. Test conditions.
  3640.  
  3641.        3. Update if everything is okay.
  3642.  
  3643.        4. Use `UNLOCK TABLES' to release your locks.
  3644.  
  3645.      This is usually a much faster method than using transactions with
  3646.      possible `ROLLBACK's, although not always. The only situation this
  3647.      solution doesn't handle is when someone kills the threads in the
  3648.      middle of an update. In this case, all locks will be released but
  3649.      some of the updates may not have been executed.
  3650.  
  3651.    * You can also use functions to update records in a single operation.
  3652.      You can get a very efficient application by using the following
  3653.      techniques:
  3654.  
  3655.         * Modify fields relative to their current value.
  3656.  
  3657.         * Update only those fields that actually have changed.
  3658.  
  3659.      For example, when we are doing updates to some customer
  3660.      information, we update only the customer data that has changed and
  3661.      test only that none of the changed data, or data that depends on
  3662.      the changed data, has changed compared to the original row. The
  3663.      test for changed data is done with the `WHERE' clause in the
  3664.      `UPDATE' statement. If the record wasn't updated, we give the
  3665.      client a message: "Some of the data you have changed has been
  3666.      changed by another user." Then we show the old row versus the new
  3667.      row in a window, so the user can decide which version of the
  3668.      customer record he should use.
  3669.  
  3670.      This gives us something that is similar to column locking but is
  3671.      actually even better because we only update some of the columns,
  3672.      using values that are relative to their current values.  This
  3673.      means that typical `UPDATE' statements look something like these:
  3674.  
  3675.           UPDATE tablename SET pay_back=pay_back+125;
  3676.           
  3677.           UPDATE customer
  3678.             SET
  3679.               customer_date='current_date',
  3680.               address='new address',
  3681.               phone='new phone',
  3682.               money_he_owes_us=money_he_owes_us-125
  3683.             WHERE
  3684.               customer_id=id AND address='old address' AND phone='old phone';
  3685.  
  3686.      As you can see, this is very efficient and works even if another
  3687.      client has changed the values in the `pay_back' or
  3688.      `money_he_owes_us' columns.
  3689.  
  3690.    * In many cases, users have wanted `ROLLBACK' and/or `LOCK TABLES'
  3691.      for the purpose of managing unique identifiers for some tables.
  3692.      This can be handled much more efficiently by using an
  3693.      `AUTO_INCREMENT' column and either the SQL function
  3694.      `LAST_INSERT_ID()' or the C API function `mysql_insert_id()'.
  3695.      *Note `mysql_insert_id()': mysql_insert_id.
  3696.  
  3697.      You can generally code around row-level locking. Some situations
  3698.      really need it, but they are very few. `InnoDB' tables support
  3699.      row-level locking. With MyISAM, you can use a flag column in the
  3700.      table and do something like the following:
  3701.  
  3702.           UPDATE tbl_name SET row_flag=1 WHERE id=ID;
  3703.  
  3704.      MySQL returns 1 for the number of affected rows if the row was
  3705.      found and `row_flag' wasn't already 1 in the original row.
  3706.  
  3707.      You can think of it as though MySQL Server changed the preceding
  3708.      query to:
  3709.  
  3710.           UPDATE tbl_name SET row_flag=1 WHERE id=ID AND row_flag <> 1;
  3711.  
  3712. Stored Procedures and Triggers
  3713. ..............................
  3714.  
  3715. Stored procedures are being implemented in our version 5.0 development
  3716. tree.  *Note Installing source tree::.
  3717.  
  3718. This effort is based on SQL-99, which has a basic syntax similar (but
  3719. not identical) to Oracle PL/SQL. In addition to this, we are
  3720. implementing the SQL-99 framework to hook in external languages.
  3721.  
  3722. A stored procedure is a set of SQL commands that can be compiled and
  3723. stored in the server. Once this has been done, clients don't need to
  3724. keep re-issuing the entire query but can refer to the stored procedure.
  3725. This provides better overall performance because the query has to be
  3726. parsed only once, and less information needs to be sent between the
  3727. server and the client. You can also raise the conceptual level by
  3728. having libraries of functions in the server.  However, stored
  3729. procedures of course do increase the load on the database server
  3730. system, as more of the work is done on the server side and less on the
  3731. client (application) side.
  3732.  
  3733. Triggers will also be implemented. A trigger is effectively a type of
  3734. stored procedure, one that is invoked when a particular event occurs.
  3735. For example, you can install a stored procedure that is triggered each
  3736. time a record is deleted from a transactional table and that stored
  3737. procedure automatically deletes the corresponding customer from a
  3738. customer table when all his transactions are deleted.
  3739.  
  3740. Foreign Keys
  3741. ............
  3742.  
  3743. In MySQL Server 3.23.44 and up, `InnoDB' tables support checking of
  3744. foreign key constraints, including `CASCADE', `ON DELETE', and `ON
  3745. UPDATE'. *Note InnoDB foreign key constraints::.
  3746.  
  3747. For other table types, MySQL Server only parses the `FOREIGN KEY'
  3748. syntax in `CREATE TABLE' commands, but does not use/store this info.
  3749.  
  3750. Note that foreign keys in SQL are not used to join tables, but are used
  3751. mostly for checking referential integrity (foreign key constraints).  If
  3752. you want to get results from multiple tables from a `SELECT' statement,
  3753. you do this by joining tables:
  3754.  
  3755.      SELECT * FROM table1,table2 WHERE table1.id = table2.id;
  3756.  
  3757. *Note `JOIN': JOIN. *Note example-Foreign keys::.
  3758.  
  3759. When used as a constraint, `FOREIGN KEY's don't need to be used if the
  3760. application inserts rows into `MyISAM' tables in the proper order.
  3761.  
  3762. For `MyISAM' tables, you can work around the lack of `ON DELETE' by
  3763. adding the appropriate `DELETE' statement to an application when you
  3764. delete records from a table that has a foreign key. In practice this is
  3765. as quick (in some cases quicker) and much more portable than using
  3766. foreign keys.
  3767.  
  3768. In MySQL Server 4.0 you can use multi-table delete to delete rows from
  3769. many tables with one command. *Note DELETE::.
  3770.  
  3771. The `FOREIGN KEY' syntax without `ON DELETE ...' is often used by ODBC
  3772. applications to produce automatic `WHERE' clauses.
  3773.  
  3774. In the near future we will extend the `FOREIGN KEY' implementation so
  3775. that the information is stored in the table specification file and may
  3776. be retrieved by `mysqldump' and ODBC. At a later stage we will
  3777. implement foreign key constraints for `MyISAM' tables as well.
  3778.  
  3779. Do keep in mind that foreign keys are often misused, which can cause
  3780. severe problems. Even when used properly, it is not a magic solution for
  3781. the referential integrity problem, although it can make things easier.
  3782.  
  3783. Some advantages of foreign key enforcement:
  3784.  
  3785.    * Assuming proper design of the relations, foreign key constraints
  3786.      will make it more difficult for a programmer to introduce an
  3787.      inconsistency into the database.
  3788.  
  3789.    * Using cascading updates and deletes can simplify the client code.
  3790.  
  3791.    * Properly designed foreign key rules aid in documenting relations
  3792.      between tables.
  3793.  
  3794. Disadvantages:
  3795.  
  3796.    * Mistakes, which are easy to make in designing key relations, can
  3797.      cause severe problems--for example, circular rules, or the wrong
  3798.      combination of cascading deletes.
  3799.  
  3800.    * Additional checking on the database level affects performance, for
  3801.      this reason some major commercial applications have coded this
  3802.      logic on the application level.
  3803.  
  3804.    * It is not uncommon for a DBA to make such a complex topology of
  3805.      relations that it becomes very difficult, and in some cases
  3806.      impossible, to back up or restore individual tables.
  3807.  
  3808. Views
  3809. .....
  3810.  
  3811. We plan to implement views in MySQL Server in version 5.1
  3812.  
  3813. Historically, MySQL Server has been most used in applications and on web
  3814. systems where the application writer has full control over database
  3815. usage. Of course, usage has shifted over time, and so we find that an
  3816. increasing number of users now regard views as an important aspect.
  3817.  
  3818. Views are useful for allowing users to access a set of relations as if
  3819. it were a single table, and limiting their access to just that.  Many
  3820. DBMS don't allow updates to a view, instead you have to perform the
  3821. updates on the individual tables.
  3822.  
  3823. Views can also be used to restrict access to rows (a subset of a
  3824. particular table).  One does not need views to restrict access to
  3825. columns, as MySQL Server has a sophisticated privilege system.  *Note
  3826. Privilege system::.
  3827.  
  3828. In designing our implementation of views, we aim toward (as fully as
  3829. possible within the confines of SQL) compliance with "*Codd's Rule #6*"
  3830. for relational database systems: all views that are theoretically
  3831. updatable, should in practice also be updatable.  This is a complex
  3832. issue, and we are taking the time to make sure we get it right.
  3833.  
  3834. The implementation itself will be done in stages.  Unnamed views
  3835. (_derived tables_, a subquery in the `FROM' clause of a `SELECT') are
  3836. already implemented in version 4.1.
  3837.  
  3838. *Note*: If you are an enterprise level user with an urgent need for
  3839. views, please contact <sales@mysql.com> to discuss sponsoring options.
  3840. Targeted financing of this particular effort by one or more companies
  3841. would allow us to allocate additional resources to it.  One example of
  3842. a feature sponsored in the past is replication.
  3843.  
  3844. `--' as the Start of a Comment
  3845. ..............................
  3846.  
  3847. Some other SQL databases use `--' to start comments.  MySQL Server has
  3848. `#' as the start comment character. You can also use the C comment
  3849. style `/* this is a comment */' with MySQL Server.  *Note Comments::.
  3850.  
  3851. MySQL Server Version 3.23.3 and above support the `--' comment style,
  3852. provided the comment is followed by a space (or by a control character
  3853. such as a newline).  This is because this comment style has caused many
  3854. problems with automatically generated SQL queries that have used
  3855. something like the following code, where we automatically insert the
  3856. value of the payment for `!payment!':
  3857.  
  3858.      UPDATE tbl_name SET credit=credit-!payment!
  3859.  
  3860. Think about what happens if the value of `payment' is negative.
  3861. Because `1--1' is legal in SQL, the consequences of allowing comments
  3862. to start with `--' are terrible.
  3863.  
  3864. Using our implementation of this method of commenting in MySQL Server
  3865. Version 3.23.3 and up, `1-- This is a comment' is actually safe.
  3866.  
  3867. Another safe feature is that the `mysql' command-line client removes
  3868. all lines that start with `--'.
  3869.  
  3870. The following information is relevant only if you are running a MySQL
  3871. version earlier than 3.23.3:
  3872.  
  3873. If you have an SQL program in a text file that contains `--' comments
  3874. you should use:
  3875.  
  3876.      shell> replace " --" " #" < text-file-with-funny-comments.sql \
  3877.               | mysql database
  3878.  
  3879. instead of the usual:
  3880.  
  3881.      shell> mysql database < text-file-with-funny-comments.sql
  3882.  
  3883. You can also edit the command file "in place" to change the `--'
  3884. comments to `#' comments:
  3885.  
  3886.      shell> replace " --" " #" -- text-file-with-funny-comments.sql
  3887.  
  3888. Change them back with this command:
  3889.  
  3890.      shell> replace " #" " --" -- text-file-with-funny-comments.sql
  3891.  
  3892. How MySQL deals with constraints
  3893. --------------------------------
  3894.  
  3895. As MySQL allows you to work with both transactional and
  3896. non-transactional tables (which don't allow rollback), constraint
  3897. handling is a bit different in MySQL than in other databases.
  3898.  
  3899. We have to handle the case when you have updated a lot of rows with a
  3900. non-transactional table which can't rollback on errors.
  3901.  
  3902. The basic philosophy is to try to give an error for anything that we can
  3903. detect on compile time but try to recover from any errors we get run
  3904. time.  We do this in most cases, but not yet for all. *Note TODO
  3905. future::.
  3906.  
  3907. The basic options MySQL has is to stop the statement in the middle or do
  3908. it's best to recover from the problem and continue.
  3909.  
  3910. Here follows what happens with the different types of constraints.
  3911.  
  3912. Constraint PRIMARY KEY / UNIQUE
  3913. ...............................
  3914.  
  3915. Normally you will get an error when you try to `INSERT' / `UPDATE' a
  3916. row that causes a primary key, unique key or foreign key violation.  If
  3917. you are using a transactional storage engine, like InnoDB, MySQL will
  3918. automatically roll back the transaction.  If you are using a
  3919. non-transactional storage engine MySQL will stop at the wrong row and
  3920. leave the rest of the rows unprocessed.
  3921.  
  3922. To make life easier MySQL has added support for the `IGNORE' directive
  3923. to most commands that can cause a key violation (like `INSERT IGNORE
  3924. ...'). In this case MySQL will ignore any key violation and continue
  3925. with processing the next row.  You can get information of what MySQL
  3926. did with the `mysql_info()' API function and in later MySQL 4.1 version
  3927. with the `SHOW WARNINGS' command. *Note mysql_info::. *Note SHOW
  3928. WARNINGS::.
  3929.  
  3930. Note that for the moment only `InnoDB' tables support foreign keys.
  3931. *Note InnoDB foreign key constraints::.  Foreign key support in
  3932. `MyISAM' tables is scheduled for inclusion in the MySQL 5.0 source tree.
  3933.  
  3934. Constraint `NOT NULL' and `DEFAULT' values
  3935. ..........................................
  3936.  
  3937. To be able to support easy handling of non-transactional tables all
  3938. fields in MySQL have default values.
  3939.  
  3940. If you insert a 'wrong' value in a column like a `NULL' in a `NOT NULL'
  3941. column or a too big numerical value in a numerical column, MySQL will
  3942. instead of giving an error instead set the column to the 'best possible
  3943. value'.  For numerical values this is 0, the smallest possible values
  3944. or the largest possible value. For strings this is either the empty
  3945. string or the longest possible string that can be in the column.
  3946.  
  3947. This means that if you try to store `NULL' into a column that doesn't
  3948. take `NULL' values, MySQL Server will store 0 or `''' (empty string) in
  3949. it instead. This last behaviour can, for single row inserts, be changed
  3950. with the `-DDONT_USE_DEFAULT_FIELDS' compile option.) *Note configure
  3951. options::.  This causes `INSERT' statements to generate an error unless
  3952. you explicitly specify values for all columns that require a non-`NULL'
  3953. value.
  3954.  
  3955. The reason for the above rules is that we can't check these conditions
  3956. before the query starts to execute.  If we encounter a problem after
  3957. updating a few rows, we can't just rollback as the table type may not
  3958. support this.  The option to stop is not that good as in this case the
  3959. update would be 'half done' which is probably the worst possible
  3960. scenario.  In this case it's better to 'do the best you can' and then
  3961. continue as if nothing happened.  In MySQL 5.0 we plan to improve this
  3962. by providing warnings for automatic field conversions, plus an option
  3963. to let you roll back statements that only use transactional tables in
  3964. case one such statement does a field assignment that is not allowed.
  3965.  
  3966. The above means that one should generally not use MySQL to check field
  3967. content, but instead handle this in the application.
  3968.  
  3969. Constraint `ENUM' and `SET'
  3970. ...........................
  3971.  
  3972. In MySQL 4.x `ENUM' is not a real constrain but a more efficient way to
  3973. store fields that can only contain a given set of values.  This is
  3974. because of the same reasons `NOT NULL' is not honoured.  *Note
  3975. constraint NOT NULL::.
  3976.  
  3977. If you insert an wrong value in an `ENUM' field, it will be set to the
  3978. reserved enum number `0', which will be displayed as an empty string in
  3979. string context. *Note ENUM::.
  3980.  
  3981. If you insert an wrong option in a `SET' field, the wrong value will be
  3982. ignored. *Note SET::.
  3983.  
  3984. Known Errors and Design Deficiencies in MySQL
  3985. ---------------------------------------------
  3986.  
  3987. Errors in 3.23 Fixed in a Later MySQL Version
  3988. .............................................
  3989.  
  3990. The following known errors/bugs are not fixed in MySQL 3.23 because
  3991. fixing them would involves changing a lot of code which could introduce
  3992. other even worse bugs. The bugs are also classified as 'not fatal' or
  3993. 'bearable'.
  3994.  
  3995.    * One can get a deadlock when doing `LOCK TABLE' on multiple tables
  3996.      and then in the same connection doing a `DROP TABLE' on one of
  3997.      them while another thread is trying to lock the table.  One can
  3998.      however do a `KILL' on any of the involved threads to resolve this.
  3999.      Fixed in 4.0.12.
  4000.  
  4001.    * `SELECT MAX(key_column) FROM t1,t2,t3...' where one of the tables
  4002.      are empty doesn't return `NULL' but instead the maximum value for
  4003.      the column.  Fixed in 4.0.11.
  4004.  
  4005.    * `DELETE FROM heap_table' without a `WHERE' doesn't work on a locked
  4006.      HEAP table.
  4007.  
  4008. Open Bugs / Design Deficiencies in MySQL
  4009. ........................................
  4010.  
  4011. The following problems are known and fixing them is a high priority:
  4012.  
  4013.    * `FLUSH TABLES WITH READ LOCK' does not block `CREATE TABLE' or
  4014.      `COMMIT', which make cause a problem with the binary log position
  4015.      when doing a full backup of tables and the binary log.
  4016.  
  4017.    * `ANALYZE TABLE' on a BDB table may in some cases make the table
  4018.      unusable until one has restarted `mysqld'.  When this happens you
  4019.      will see errors like the following in the MySQL error file:
  4020.  
  4021.           001207 22:07:56  bdb:  log_flush: LSN past current end-of-log
  4022.  
  4023.    * MySQL accepts parentheses in the `FROM' part, but silently ignores
  4024.      them.  The reason for not giving an error is that many clients
  4025.      that automatically generate queries add parentheses in the `FROM'
  4026.      part even where they are not needed.
  4027.  
  4028.    * Concatenating many `RIGHT JOINS' or combining `LEFT' and `RIGHT'
  4029.      join in the same query may not give a correct answer as MySQL only
  4030.      generates `NULL' rows for the table preceding a `LEFT' or before a
  4031.      `RIGHT' join.  This will be fixed in 5.0 at the same time we add
  4032.      support for parentheses in the `FROM' part.
  4033.  
  4034.    * Don't execute `ALTER TABLE' on a `BDB' table on which you are
  4035.      running multi-statement transactions until all those transactions
  4036.      complete.  (The transaction will probably be ignored.)
  4037.  
  4038.    * `ANALYZE TABLE', `OPTIMIZE TABLE', and `REPAIR TABLE' may cause
  4039.      problems on tables for which you are using `INSERT DELAYED'.
  4040.  
  4041.    * Doing a `LOCK TABLE ...' and `FLUSH TABLES ...' doesn't guarantee
  4042.      that there isn't a half-finished transaction in progress on the
  4043.      table.
  4044.  
  4045.    * BDB tables are a bit slow to open. If you have many BDB tables in a
  4046.      database, it will take a long time to use the `mysql' client on the
  4047.      database if you are not using the `-A' option or if you are using
  4048.      `rehash'. This is especially notable when you have a big table
  4049.      cache.
  4050.  
  4051.    * Replication uses query-level logging: the master writes the
  4052.      executed queries to the binary log. This is a very fast, compact,
  4053.      and efficient logging method that works perfectly in most cases.
  4054.      Though we have never heard of it actually occurring, it is
  4055.      theoretically possible for the data on the master and slave to
  4056.      become different if a query is designed in such a way that the
  4057.      data modification is non-deterministic, that is, left to the will
  4058.      of the query optimiser (which generally is not a good practice,
  4059.      even outside of replication!).  For example:
  4060.  
  4061.         - `CREATE ... SELECT' or `INSERT ... SELECT' which feeds zeros
  4062.           or `NULL's into an `auto_increment' column.
  4063.  
  4064.         - `DELETE' if you are deleting rows from a table which has
  4065.           foreign keys with `ON DELETE CASCADE' properties.
  4066.  
  4067.         - `REPLACE ... SELECT', `INSERT IGNORE ... SELECT' if you have
  4068.           duplicate key values in the inserted data.
  4069.      *IF and only if all these queries have NO `ORDER BY' clause
  4070.      guaranteeing a deterministic order*.
  4071.  
  4072.      Indeed, for example for `INSERT ... SELECT' with no `ORDER BY',
  4073.      the `SELECT' may return rows in a different order (which will
  4074.      result in a row having different ranks, hence getting a different
  4075.      number in the `auto_increment' column), depending on the choices
  4076.      made by the optimisers on the master and slave. A query will be
  4077.      optimised differently on the master and slave only if:
  4078.  
  4079.         - The files used by the two queries are not exactly the same;
  4080.           for example `OPTIMIZE TABLE' was run on the master tables and
  4081.           not on the slave tables (to fix this, since MySQL 4.1.1,
  4082.           `OPTIMIZE', `ANALYZE' and `REPAIR' are written to the binary
  4083.           log).
  4084.  
  4085.         - The table is stored in a different storage engine on the
  4086.           master than on the slave (one can run with different storage
  4087.           engines on the slave and master: for example InnoDB on the
  4088.           master and MyISAM on the slave, if the slave has less
  4089.           available disk space).
  4090.  
  4091.         - The MySQL buffers' sizes (`key_buffer_size' etc) are
  4092.           different on the master and slave.
  4093.  
  4094.         - The master and slave run different MySQL versions, and the
  4095.           optimiser code is different between these versions.
  4096.  
  4097.      This problem may also affect database restoration using
  4098.      `mysqlbinlog|mysql'.
  4099.  
  4100.      The easiest way to avoid this problem in all cases is add an
  4101.      `ORDER BY' clause to such non-deterministic queries to ensure that
  4102.      the rows are always stored/modified in the same order.  In future
  4103.      MySQL versions we will automatically add an `ORDER BY' clause when
  4104.      needed.
  4105.  
  4106.  
  4107. The following problems are known and will be fixed in due time:
  4108.  
  4109.    * `LIKE' is not `multi-byte character' safe. Comparison is done
  4110.      character by character.
  4111.  
  4112.    *  When using `RPAD' function, or any other string function that ends
  4113.      up adding blanks to the right, in a query that has to use temporary
  4114.      table to be resolved, then all resulting strings will be RTRIM'ed.
  4115.      This is an example of the query:
  4116.  
  4117.      `SELECT    RPAD(t1.field1, 50, ' ') AS f2,    RPAD(t2.field2, 50, '
  4118.      ') AS f1  FROM    table1 as t1     LEFT JOIN table2 AS t2 ON
  4119.      t1.record=t2.joinID ORDER BY t2.record;'
  4120.  
  4121.      Final result of this bug is that use will not be able to get
  4122.      blanks on the right side of the resulting field.
  4123.  
  4124.      The above behaviour exists in all versions of MySQL.
  4125.  
  4126.      The reason for this is due to the fact that HEAP tables, which are
  4127.      used first for temporary tables, are not capable of handling
  4128.      VARCHAR columns.
  4129.  
  4130.      This behaviour will be fixed in one of the 4.1 series releases.
  4131.  
  4132.    * Because of how table definitions files are stored one can't use
  4133.      character 255 (`CHAR(255)') in table names, column names or enums.
  4134.      This is scheduled to be fixed in version 5.1 when we have new table
  4135.      definition format files.
  4136.  
  4137.    * When using `SET CHARACTER SET', one can't use translated
  4138.      characters in database, table, and column names.
  4139.  
  4140.    * One can't use `_' or `%' with `ESCAPE' in `LIKE ... ESCAPE'.
  4141.  
  4142.    * If you have a `DECIMAL' column with a  number stored in different
  4143.      formats (+01.00, 1.00, 01.00), `GROUP BY' may regard each value as
  4144.      a different value.
  4145.  
  4146.    * `DELETE FROM merge_table' used without a `WHERE' will only clear
  4147.      the mapping for the table, not delete everything in the mapped
  4148.      tables.
  4149.  
  4150.    * You cannot build the server in another directory when using
  4151.      MIT-pthreads. Because this requires changes to MIT-pthreads, we
  4152.      are not likely to fix this. *Note MIT-pthreads::.
  4153.  
  4154.    * `BLOB' values can't "reliably" be used in `GROUP BY' or `ORDER BY'
  4155.      or `DISTINCT'. Only the first `max_sort_length' bytes (default
  4156.      1024) are used when comparing `BLOB's in these cases.  This can be
  4157.      changed with the `-O max_sort_length' option to `mysqld'. A
  4158.      workaround for most cases is to use a substring: `SELECT DISTINCT
  4159.      LEFT(blob,2048) FROM tbl_name'.
  4160.  
  4161.    * Calculation is done with `BIGINT' or `DOUBLE' (both are normally
  4162.      64 bits long). It depends on the function which precision one
  4163.      gets. The general rule is that bit functions are done with `BIGINT'
  4164.      precision, `IF', and `ELT()' with `BIGINT' or `DOUBLE' precision
  4165.      and the rest with `DOUBLE' precision.  One should try to avoid
  4166.      using unsigned long long values if they resolve to be bigger than
  4167.      63 bits (9223372036854775807) for anything else than bit fields.
  4168.      MySQL Server 4.0 has better `BIGINT' handling than 3.23.
  4169.  
  4170.    * All string columns, except `BLOB' and `TEXT' columns, automatically
  4171.      have all trailing spaces removed when retrieved. For `CHAR' types
  4172.      this is okay, and may be regarded as a feature according to
  4173.      SQL-92. The bug is that in MySQL Server, `VARCHAR' columns are
  4174.      treated the same way.
  4175.  
  4176.    * You can only have up to 255 `ENUM' and `SET' columns in one table.
  4177.  
  4178.    * In `MIN()', `MAX()' and other aggregate functions, MySQL currently
  4179.      compares `ENUM' and `SET' columns by their string value rather
  4180.      than by the string's relative position in the set.
  4181.  
  4182.    * `mysqld_safe' redirects all messages from `mysqld' to the `mysqld'
  4183.      log.  One problem with this is that if you execute `mysqladmin
  4184.      refresh' to close and reopen the log, `stdout' and `stderr' are
  4185.      still redirected to the old log.  If you use `--log' extensively,
  4186.      you should edit `mysqld_safe' to log to `'hostname'.err' instead
  4187.      of `'hostname'.log' so you can easily reclaim the space for the
  4188.      old log by deleting the old one and executing `mysqladmin refresh'.
  4189.  
  4190.    * In the `UPDATE' statement, columns are updated from left to right.
  4191.      If you refer to an updated column, you will get the updated value
  4192.      instead of the original value. For example:
  4193.  
  4194.           mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1;
  4195.  
  4196.      This will update `KEY' with `2' instead of with `1'.
  4197.  
  4198.    * You can refer to multiple temporary tables in the same query, but
  4199.      you cannot refer to any given temporary table more than once.  For
  4200.      example, the following doesn't work:
  4201.  
  4202.           mysql> SELECT * FROM temporary_table, temporary_table AS t2;
  4203.  
  4204.    * `RENAME' doesn't work with `TEMPORARY' tables or tables used in a
  4205.      `MERGE' table.
  4206.  
  4207.    * The optimiser may handle `DISTINCT' differently if you are using
  4208.      'hidden' columns in a join or not.  In a join, hidden columns are
  4209.      counted as part of the result (even if they are not shown) while in
  4210.      normal queries hidden columns don't participate in the `DISTINCT'
  4211.      comparison.  We will probably change this in the future to never
  4212.      compare the hidden columns when executing `DISTINCT'.
  4213.  
  4214.      An example of this is:
  4215.  
  4216.           SELECT DISTINCT mp3id FROM band_downloads
  4217.                  WHERE userid = 9 ORDER BY id DESC;
  4218.  
  4219.      and
  4220.  
  4221.           SELECT DISTINCT band_downloads.mp3id
  4222.                  FROM band_downloads,band_mp3
  4223.                  WHERE band_downloads.userid = 9
  4224.                  AND band_mp3.id = band_downloads.mp3id
  4225.                  ORDER BY band_downloads.id DESC;
  4226.  
  4227.      In the second case you may in MySQL Server 3.23.x get two
  4228.      identical rows in the result set (because the hidden `id' column
  4229.      may differ).
  4230.  
  4231.      Note that this happens only for queries where you don't have the
  4232.      ORDER BY columns in the result, something that you are not allowed
  4233.      to do in SQL-92.
  4234.  
  4235.    * Because MySQL Server allows you to work with table types that don't
  4236.      support transactions, and thus can't `rollback' data, some things
  4237.      behave a little differently in MySQL Server than in other SQL
  4238.      servers.  This is just to ensure that MySQL Server never needs to
  4239.      do a rollback for an SQL command.  This may be a little awkward at
  4240.      times as column values must be checked in the application, but
  4241.      this will actually give you a nice speed increase as it allows
  4242.      MySQL Server to do some optimisations that otherwise would be very
  4243.      hard to do.
  4244.  
  4245.      If you set a column to an incorrect value, MySQL Server will,
  4246.      instead of doing a rollback, store the `best possible value' in
  4247.      the column:
  4248.  
  4249.         - If you try to store a value outside the range in a numerical
  4250.           column, MySQL Server will instead store the smallest or
  4251.           biggest possible value in the column.
  4252.  
  4253.         - If you try to store a string that doesn't start with a number
  4254.           into a numerical column, MySQL Server will store 0 into it.
  4255.  
  4256.         - If you try to store `NULL' into a column that doesn't take
  4257.           `NULL' values, MySQL Server will store 0 or `''' (empty
  4258.           string) in it instead. (This behaviour can, however, be
  4259.           changed with the -DDONT_USE_DEFAULT_FIELDS compile option.)
  4260.  
  4261.         - MySQL allows you to store some wrong date values into `DATE'
  4262.           and `DATETIME' columns (like 2000-02-31 or 2000-02-00).  The
  4263.           idea is that it's not the SQL server job to validate date.
  4264.           If MySQL can store a date and retrieve exactly the same date,
  4265.           then MySQL will store the date. If the date is totally wrong
  4266.           (outside the server's ability to store it), then the special
  4267.           date value 0000-00-00 will be stored in the column.
  4268.  
  4269.         - If you set an `ENUM' column to an unsupported value, it will
  4270.           be set to the error value `empty string', with numeric value
  4271.           0.
  4272.  
  4273.         - If you set a `SET' column to an unsupported value, the value
  4274.           will be ignored.
  4275.  
  4276.  
  4277.    * If you execute a `PROCEDURE' on a query that returns an empty set,
  4278.      in some cases the `PROCEDURE' will not transform the columns.
  4279.  
  4280.    * Creation of a table of type `MERGE' doesn't check if the underlying
  4281.      tables are of compatible types.
  4282.  
  4283.    * MySQL Server can't yet handle `NaN', `-Inf', and `Inf' values in
  4284.      double. Using these will cause problems when trying to export and
  4285.      import data. We should as an intermediate solution change `NaN' to
  4286.      `NULL' (if possible) and `-Inf' and `Inf' to the minimum
  4287.      respective maximum possible `double' value.
  4288.  
  4289.    * `LIMIT' on negative numbers are treated as big positive numbers.
  4290.  
  4291.    * If you use `ALTER TABLE' to first add a `UNIQUE' index to a table
  4292.      used in a `MERGE' table and then use `ALTER TABLE' to add a normal
  4293.      index on the `MERGE' table, the key order will be different for
  4294.      the tables if there was an old key that was not unique in the
  4295.      table. This is because `ALTER TABLE' puts `UNIQUE' keys before
  4296.      normal keys to be able to detect duplicate keys as early as
  4297.      possible.
  4298.  
  4299. The following are known bugs in earlier versions of MySQL:
  4300.  
  4301.    * You can get a hung thread if you do a `DROP TABLE' on a table that
  4302.      is one among many tables that is locked with `LOCK TABLES'.
  4303.  
  4304.    * In the following case you can get a core dump:
  4305.  
  4306.         - Delayed insert handler has pending inserts to a table.
  4307.  
  4308.         - `LOCK table' with `WRITE'.
  4309.  
  4310.         - `FLUSH TABLES'.
  4311.  
  4312.    * Before MySQL Server Version 3.23.2 an `UPDATE' that updated a key
  4313.      with a `WHERE' on the same key may have failed because the key was
  4314.      used to search for records and the same row may have been found
  4315.      multiple times:
  4316.  
  4317.           UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
  4318.  
  4319.      A workaround is to use:
  4320.  
  4321.           mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
  4322.  
  4323.      This will work because MySQL Server will not use an index on
  4324.      expressions in the `WHERE' clause.
  4325.  
  4326.    * Before MySQL Server Version 3.23, all numeric types were treated as
  4327.      fixed-point fields. That means you had to specify how many decimals
  4328.      a floating-point field shall have. All results were returned with
  4329.      the correct number of decimals.
  4330.  
  4331. For platform-specific bugs, see the sections about compiling and
  4332. porting.
  4333.  
  4334. MySQL and the Future (The TODO)
  4335. ===============================
  4336.  
  4337. This section summarises the features that we plan to implement in
  4338. `MySQL Server'. The lists are broken up per version, and the items are
  4339. approximately in the order they will be done.
  4340.  
  4341. *Note*: If you are an enterprise level user with an urgent need for a
  4342. particular feature, please contact <sales@mysql.com> to discuss
  4343. sponsoring options. Targeted financing by one or more companies allows
  4344. us to allocate additional resources for that specific purpose.  One
  4345. example of a feature sponsored in the past is replication.
  4346.  
  4347. New Features Planned For 4.1
  4348. ----------------------------
  4349.  
  4350. The features below are not yet implemented in MySQL 4.1, but are planned
  4351. for implementation before MySQL 4.1 moves into its beta phase.  For a
  4352. list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  4353. features::.
  4354.  
  4355.    * Stable OpenSSL support (MySQL 4.0 supports rudimentary, not 100%
  4356.      tested, support for OpenSSL).
  4357.  
  4358.    * Character set casts and syntax for handling multiple character
  4359.      sets.
  4360.  
  4361.    * More testing of prepared statements and multiple characters sets
  4362.      for one table.
  4363.  
  4364. Development of other things has already shifted to the 5.0 tree.
  4365.  
  4366. New Features Planned For 5.0
  4367. ----------------------------
  4368.  
  4369. The following features are planned for inclusion into MySQL 5.0.  Note
  4370. that because we have many developers that are working on different
  4371. projects, there will also be many additional features. There is also a
  4372. small chance that some of these features will be added to MySQL 4.1.
  4373. For a list what is already done in MySQL 4.1, see *Note Nutshell 4.1
  4374. features::.
  4375.  
  4376. For those wishing to take a look at the bleeding edge of MySQL
  4377. development, we have made our BitKeeper repository for MySQL version
  4378. 5.0 publicly available.  *Note Installing source tree::.
  4379.  
  4380. Stored Procedures
  4381.         * Stored procedures are currently being implemented.  This
  4382.           effort is based on SQL-99, which has a basic syntax similar
  4383.           (but not identical) to Oracle PL/SQL. We will also implement
  4384.           the SQL-99 framework to hook in external languages, and
  4385.           (where possible) compatibility with, for example, PL/SQL and
  4386.           T-SQL.
  4387.  
  4388. New functionality
  4389.         * Elementary cursor support.
  4390.  
  4391.         * Visible `RTREE' index for MyISAM tables.  In 4.1 RTREE
  4392.           indexes are used internally for geometrical data, but not
  4393.           directly usable.
  4394.  
  4395.         * Dynamic length rows for HEAP tables.
  4396.  
  4397. Standards compliance, portability and migration
  4398.         * Add true `VARCHAR' support (there is already support for this
  4399.           in `MyISAM').
  4400.  
  4401. Speed enhancements
  4402.         * `SHOW COLUMNS FROM table_name' (used by `mysql' client to
  4403.           allow expansions of column names) should not open the table,
  4404.           only the definition file. This will require less memory and
  4405.           be much faster.
  4406.  
  4407.         * Allow `DELETE' on `MyISAM' tables to use the record cache.
  4408.           To do this, we need to update the threads record cache when
  4409.           we update the `.MYD' file.
  4410.  
  4411.         * Better in-memory (`HEAP') tables:
  4412.              * Dynamic size rows.
  4413.  
  4414.              * Faster row handling (less copying).
  4415.  
  4416. Internationalisation
  4417.         * When using `SET CHARACTER SET' we should translate the whole
  4418.           query at once and not only strings. This will enable users to
  4419.           use the translated characters in database, table, and column
  4420.           names.
  4421.  
  4422. Usability enhancements
  4423.         * Resolving the issue of `RENAME TABLE' on a table used in an
  4424.           active `MERGE' table possibly corrupting the table.
  4425.  
  4426. New Features Planned For 5.1
  4427. ----------------------------
  4428.  
  4429. New functionality
  4430.         * `FOREIGN KEY' support for all table types.
  4431.  
  4432.         * Column-level constraints.
  4433.  
  4434.         * Fail-safe replication.
  4435.  
  4436.         * Online backup with very low performance penalty.  The online
  4437.           backup will make it easy to add a new replication slave
  4438.           without taking down the master.
  4439.  
  4440. Speed enhancements
  4441.         * New text based table definition file format (`.frm' files)
  4442.           and a table cache for table definitions.  This will enable us
  4443.           to do faster queries of table structures and do more
  4444.           efficient foreign key support.
  4445.  
  4446.         * Optimise `BIT' type to take 1 bit (now `BIT' takes 1 char).
  4447.  
  4448. Usability enhancements
  4449.         * Add options to the client/server protocol to get progress
  4450.           notes for long running commands.
  4451.  
  4452.         * Implement `RENAME DATABASE'. To make this safe for all
  4453.           storage engines, it should work as follows:
  4454.              * Create the new database.
  4455.  
  4456.              * For every table do a rename of the table to another
  4457.                database, as we do with the `RENAME' command.
  4458.  
  4459.              * Drop the old database.
  4460.  
  4461.         * New internal file interface change.  This will make all file
  4462.           handling much more general and make it easier to add
  4463.           extensions like RAID.  (The current implementation is a hack.)
  4464.  
  4465. New Features Planned for the Near Future
  4466. ----------------------------------------
  4467.  
  4468. New functionality
  4469.         * Oracle-like `CONNECT BY PRIOR ...' to search tree-like
  4470.           (hierarchical) structures.
  4471.  
  4472.         * Add all missing SQL-92 and ODBC 3.0 types.
  4473.  
  4474.         * Add `SUM(DISTINCT)'.
  4475.  
  4476.         * `INSERT SQL_CONCURRENT' and `mysqld --concurrent-insert' to do
  4477.           a concurrent insert at the end of the file if the file is
  4478.           read-locked.
  4479.  
  4480.         * Allow update of variables in `UPDATE' statements. For example:
  4481.           `UPDATE TABLE foo SET @a=a+b,a=@a, b=@a+c'.
  4482.  
  4483.         * Change when user variables are updated so that one can use
  4484.           them with `GROUP BY', as in the following example: `SELECT
  4485.           id, @a:=COUNT(*), SUM(sum_col)/@a FROM table_name GROUP BY
  4486.           id'.
  4487.  
  4488.         * Add an `IMAGE' option to `LOAD DATA INFILE' to not update
  4489.           `TIMESTAMP' and `AUTO_INCREMENT' fields.
  4490.  
  4491.         * Added `LOAD DATA INFILE ... UPDATE' syntax.
  4492.              * For tables with primary keys, if the data contains the
  4493.                primary key, entries matching that primary key are
  4494.                updated from the remainder of the columns. However,
  4495.                columns *missing* from the incoming data feed are not
  4496.                touched.
  4497.  
  4498.              * For tables with primary keys that are missing some part
  4499.                of the key in the incoming data stream, or that have no
  4500.                primary key, the feed is treated as a `LOAD DATA INFILE
  4501.                ... REPLACE INTO' now.
  4502.  
  4503.         * Make `LOAD DATA INFILE' understand syntax like:
  4504.                LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
  4505.                     TEXT_FIELDS (text_field1, text_field2, text_field3)
  4506.                     SET table_field1=CONCAT(text_field1, text_field2),
  4507.                         table_field3=23
  4508.                     IGNORE text_field3
  4509.           This can be used to skip over extra columns in the text file,
  4510.           or update columns based on expressions of the read data.
  4511.  
  4512.         * New functions for working with `SET' type columns:
  4513.              * `ADD_TO_SET(value,set)'
  4514.  
  4515.              * `REMOVE_FROM_SET(value,set)'
  4516.  
  4517.         * If you abort `mysql' in the middle of a query, you should open
  4518.           another connection and kill the old running query.
  4519.           Alternatively, an attempt should be made to detect this in
  4520.           the server.
  4521.  
  4522.         * Add a storage engine interface for table information so that
  4523.           you can use it as a system table. This would be a bit slow if
  4524.           you requested information about all tables, but very
  4525.           flexible.  `SHOW INFO FROM tbl_name' for basic table
  4526.           information should be implemented.
  4527.  
  4528.         * Allow `SELECT a FROM crash_me LEFT JOIN crash_me2 USING (a)';
  4529.           in this case `a' is assumed to come from the `crash_me' table.
  4530.  
  4531.         * `DELETE' and `REPLACE' options to the `UPDATE' statement
  4532.           (this will delete rows when one gets a duplicate key error
  4533.           while updating).
  4534.  
  4535.         * Change the format of `DATETIME' to store fractions of seconds.
  4536.  
  4537.         * Make it possible to use the new GNU regexp library instead of
  4538.           the current one (the GNU library should be much faster than
  4539.           the old one).
  4540.  
  4541. Standards compliance, portability and migration
  4542.         * Don't add automatic `DEFAULT' values to columns.  Give an
  4543.           error when using an `INSERT' that doesn't contain a column
  4544.           that doesn't have a `DEFAULT'.
  4545.  
  4546.         * Add `ANY()', `EVERY()', and `SOME()' group functions. In
  4547.           standard SQL these work only on boolean columns, but we can
  4548.           extend these to work on any columns/expressions by applying:
  4549.           value == 0 -> FALSE and value <> 0 -> TRUE.
  4550.  
  4551.         * Fix that the type for `MAX(column)' is the same as the column
  4552.           type:
  4553.                mysql> CREATE TABLE t1 (a DATE);
  4554.                mysql> INSERT INTO t1 VALUES (NOW());
  4555.                mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
  4556.                mysql> SHOW COLUMNS FROM t2;
  4557.  
  4558. Speed enhancements
  4559.         * Don't allow more than a defined number of threads to run
  4560.           MyISAM recover at the same time.
  4561.  
  4562.         * Change `INSERT ... SELECT' to optionally use concurrent
  4563.           inserts.
  4564.  
  4565.         * Add an option to periodically flush key pages for tables with
  4566.           delayed keys if they haven't been used in a while.
  4567.  
  4568.         * Allow join on key parts (optimisation issue).
  4569.  
  4570.         * Add simulation of `pread()'/`pwrite()' on Windows to enable
  4571.           concurrent inserts.
  4572.  
  4573.         * A logfile analyser that could parse out information about
  4574.           which tables are hit most often, how often multi-table joins
  4575.           are executed, etc.  It should help users identify areas or
  4576.           table design that could be optimised to execute much more
  4577.           efficient queries.
  4578.  
  4579. Internationalisation
  4580.  
  4581. Usability enhancements
  4582.         * Return the original field types() when doing `SELECT
  4583.           MIN(column) ... GROUP BY'.
  4584.  
  4585.         * Make it possible to specify `long_query_time' with a
  4586.           granularity in microseconds.
  4587.  
  4588.         * Link the `myisampack' code into the server, enabling a PACK or
  4589.           COMPRESS command on the server.
  4590.  
  4591.         * Add a temporary key buffer cache during
  4592.           `INSERT/DELETE/UPDATE' so that we can gracefully recover if
  4593.           the index file gets full.
  4594.  
  4595.         * If you perform an `ALTER TABLE' on a table that is symlinked
  4596.           to another disk, create temporary tables on this disk.
  4597.  
  4598.         * Implement a `DATE/DATETIME' type that handles time zone
  4599.           information properly so that dealing with dates in different
  4600.           time zones is easier.
  4601.  
  4602.         * Fix configure so that one can compile all libraries (like
  4603.           `MyISAM') without threads.
  4604.  
  4605.         * Allow SQL variables in `LIMIT', like in `LIMIT @a,@b'.
  4606.  
  4607.         * Automatic output from `mysql' to a web browser.
  4608.  
  4609.         * `LOCK DATABASES' (with various options).
  4610.  
  4611.         * Many more variables for `SHOW STATUS'.  Records reads and
  4612.           updates.  Selects on 1 table and selects with joins.  Mean
  4613.           number of tables in select. Number of `ORDER BY' and `GROUP
  4614.           BY' queries.
  4615.  
  4616.         * `mysqladmin copy database new-database'; requires `COPY'
  4617.           command to be added to `mysqld'.
  4618.  
  4619.         * Processlist should show number of queries/threads.
  4620.  
  4621.         * `SHOW HOSTS' for printing information about the hostname
  4622.           cache.
  4623.  
  4624.         * Change table names from empty strings to `NULL' for
  4625.           calculated columns.
  4626.  
  4627.         * Don't use `Item_copy_string' on numerical values to avoid
  4628.           number->string->number conversion in case of: `SELECT
  4629.           COUNT(*)*(id+0) FROM table_name GROUP BY id'
  4630.  
  4631.         * Change so that `ALTER TABLE' doesn't abort clients that
  4632.           execute `INSERT DELAYED'.
  4633.  
  4634.         * Fix so that when columns are referenced in an `UPDATE' clause,
  4635.           they contain the old values from before the update started.
  4636.  
  4637. New operating systems
  4638.         * Port of the MySQL clients to LynxOS.
  4639.  
  4640. New Features Planned for the Mid-Term Future
  4641. --------------------------------------------
  4642.  
  4643.    * Implement function:
  4644.      `get_changed_tables(timeout,table1,table2,...)'.
  4645.  
  4646.    * Change reading through tables to use memmap when possible. Now only
  4647.      compressed tables use memmap.
  4648.  
  4649.    * Make the automatic timestamp code nicer.  Add timestamps to the
  4650.      update log with `SET TIMESTAMP=#;'.
  4651.  
  4652.    * Use read/write mutex in some places to get more speed.
  4653.  
  4654.    * Simple views (stepwise implementation up to full functionality).
  4655.      *Note ANSI diff Views::.
  4656.  
  4657.    * Automatically close some tables if a table, temporary table, or
  4658.      temporary files gets error 23 (not enough open files).
  4659.  
  4660.    * When one finds a field=#, change all occurrences of field to #.
  4661.      Now this is only done for some simple cases.
  4662.  
  4663.    * Change all const expressions with calculated expressions if
  4664.      possible.
  4665.  
  4666.    * Optimise key = expression. At the moment only key = field or key =
  4667.      constant are optimised.
  4668.  
  4669.    * Join some of the copy functions for nicer code.
  4670.  
  4671.    * Change `sql_yacc.yy' to an inline parser to reduce its size and get
  4672.      better error messages (5 days).
  4673.  
  4674.    * Change the parser to use only one rule per different number of
  4675.      arguments in function.
  4676.  
  4677.    * Use of full calculation names in the order part (for ACCESS97).
  4678.  
  4679.    * `MINUS', `INTERSECT', and `FULL OUTER JOIN'.  (Currently `UNION'
  4680.      [in 4.0] and `LEFT|RIGHT OUTER JOIN' are supported.)
  4681.  
  4682.    * `SQL_OPTION MAX_SELECT_TIME=#' to put a time limit on a query.
  4683.  
  4684.    * Make the update log write to a database.
  4685.  
  4686.    * Enhance `LIMIT' to allow retrieval of data from the end of a
  4687.      result set.
  4688.  
  4689.    * Alarm around client connect/read/write functions.
  4690.  
  4691.    * Please note the changes to `mysqld_safe': according to FSSTND
  4692.      (which Debian tries to follow) PID files should go into
  4693.      `/var/run/<progname>.pid' and log files into `/var/log'. It would
  4694.      be nice if you could put the "DATADIR" in the first declaration of
  4695.      "pidfile" and "log", so the placement of these files can be
  4696.      changed with a single statement.
  4697.  
  4698.    * Allow a client to request logging.
  4699.  
  4700.    * Add use of `zlib()' for `gzip'-ed files to `LOAD DATA INFILE'.
  4701.  
  4702.    * Fix sorting and grouping of `BLOB' columns (partly solved now).
  4703.  
  4704.    * Change to use semaphores when counting threads.  One should first
  4705.      implement a semaphore library to MIT-pthreads.
  4706.  
  4707.    * Don't assign a new `AUTO_INCREMENT' value when one sets a column
  4708.      to 0.  Use `NULL' instead.
  4709.  
  4710.    * Add full support for `JOIN' with parentheses.
  4711.  
  4712.    * As an alternative for one thread/connection manage a pool of
  4713.      threads to handle the queries.
  4714.  
  4715.    * Allow one to get more than one lock with `GET_LOCK'.  When doing
  4716.      this, one must also handle the possible deadlocks this change will
  4717.      introduce.
  4718.  
  4719. Time is given according to amount of work, not real time.
  4720.  
  4721. New Features We Don't Plan to Do
  4722. --------------------------------
  4723.  
  4724.    * Nothing; we aim toward full compliance with SQL-92/SQL-99.
  4725.  
  4726. Installing MySQL
  4727. ****************
  4728.  
  4729. This chapter describes how to obtain and install MySQL:
  4730.  
  4731.    * For a list of sites from which you can obtain MySQL, see *Note
  4732.      Getting MySQL: Getting MySQL.
  4733.  
  4734.    * To see which platforms are supported, see *Note Which OS::. Please
  4735.      note that not all supported systems are equally good for running
  4736.      MySQL on them.  On some it is much more robust and efficient than
  4737.      others--see *Note Which OS:: for details.
  4738.  
  4739.    * Several versions of MySQL are available in both binary and source
  4740.      distributions.  We also provide public access to our current
  4741.      source tree for those who want to see our most recent developments
  4742.      and help us test new code.  To determine which version and type of
  4743.      distribution you should use, see *Note Which version::. When in
  4744.      doubt, use a binary distribution.
  4745.  
  4746.    * Installation instructions for binary and source distributions are
  4747.      described in *Note Installing binary::, and *Note Installing
  4748.      source::.  Each set of instructions includes a section on
  4749.      system-specific problems you may run into.
  4750.  
  4751.    * For post-installation procedures, see *Note Post-installation::.
  4752.      These procedures apply whether you install MySQL using a binary or
  4753.      source distribution.
  4754.  
  4755. Quick Standard Installation of MySQL
  4756. ====================================
  4757.  
  4758. This chapter covers the installation of MySQL on platforms where we
  4759. offer packages using the native packaging format of the respective
  4760. platform. However, binary distributions of MySQL are available for many
  4761. other platforms as well, see *Note Installing binary:: for generic
  4762. installation instructions for these packages that apply to all
  4763. platforms.
  4764.  
  4765. See *Note General Installation Issues:: for more information on what
  4766. other binary distributions are available on how to obtain them.
  4767.  
  4768. Installing MySQL on Windows
  4769. ---------------------------
  4770.  
  4771. The MySQL server for Windows is available in two distribution formats:
  4772.  
  4773.    * The binary distribution contains a setup program that installs
  4774.      everything you need so that you can start the server immediately.
  4775.  
  4776.    * The source distribution contains all the code and support files
  4777.      for building the executables using the VC++ 6.0 compiler.  *Note
  4778.      Windows source build::.
  4779.  
  4780.  
  4781. Generally speaking, you should use the binary distribution. It's
  4782. simpler, and you need no additional tools to get MySQL up and running.
  4783.  
  4784. You will need the following:
  4785.  
  4786.    * A 32-bit Windows Operating System such as 9x, Me, NT, 2000, or XP.
  4787.      The NT family (Windows NT, 2000, and XP) permits you to run the
  4788.      MySQL server as a service. *Note NT start::.
  4789.  
  4790.      If you need tables with a size larger than 4 GB, install MySQL on
  4791.      an NTFS or newer filesystem. Don't forget to use `MAX_ROWS' and
  4792.      `AVG_ROW_LENGTH' when you create tables.  *Note `CREATE TABLE':
  4793.      CREATE TABLE.
  4794.  
  4795.    * TCP/IP protocol support.
  4796.  
  4797.    * A copy of the MySQL binary distribution for Windows, which can be
  4798.      downloaded from `http://www.mysql.com/downloads/'.
  4799.  
  4800.      Note: The distribution files are supplied with a zipped format and
  4801.      we recommend the use of an adequate FTP client with resume feature
  4802.      to avoid corruption of files during the download process.
  4803.  
  4804.    * A `ZIP' program to unpack the distribution file.
  4805.  
  4806.    * Enough space on the hard drive to unpack, install, and create the
  4807.      databases in accordance with your requirements.
  4808.  
  4809.    * If you plan to connect to the MySQL server via ODBC, you will also
  4810.      need the `MyODBC' driver. *Note ODBC::.
  4811.  
  4812.  
  4813. Installing the Binaries
  4814. .......................
  4815.  
  4816.   1. If you are working on an NT/2000/XP server, log on as a user with
  4817.      administrator privileges.
  4818.  
  4819.   2. If you are doing an upgrade of an earlier MySQL installation, it
  4820.      is necessary to stop the current server. If you are running the
  4821.      server as a service, stop it using this command:
  4822.  
  4823.           C:\> NET STOP MySQL
  4824.  
  4825.      Otherwise, stop the server like this:
  4826.  
  4827.           C:\mysql\bin> mysqladmin -u root shutdown
  4828.  
  4829.   3. On NT/2000/XP machines, if you want to change the server executable
  4830.      (for example, `-max' or `-nt'), it is also necessary to remove the
  4831.      service:
  4832.  
  4833.           C:\mysql\bin> mysqld --remove
  4834.  
  4835.   4. Exit the `WinMySQLadmin' program if it is running.
  4836.  
  4837.   5. Unzip the distribution file to a temporary directory.
  4838.  
  4839.   6. Run the `setup.exe' program to begin the installation process.  If
  4840.      you want to install into another directory than the default
  4841.      (`C:\mysql'), use the `Browse' button to specify your preferred
  4842.      directory.
  4843.  
  4844.   7. Finish the install process.
  4845.  
  4846.  
  4847. Preparing the Windows MySQL Environment
  4848. .......................................
  4849.  
  4850. Starting with MySQL 3.23.38, the Windows distribution includes both the
  4851. normal and the MySQL-Max server binaries.  Here is a list of the
  4852. different MySQL servers from which you can choose:
  4853.  
  4854. *Binary*       *Description*
  4855. `mysqld'       Compiled with full debugging and automatic memory
  4856.                allocation checking, symbolic links, `InnoDB', and `BDB'
  4857.                tables.
  4858. `mysqld-opt'   Optimised binary with no support for transactional tables
  4859.                in version 3.23. For version 4.0, `InnoDB' is enabled.
  4860. `mysqld-nt'    Optimised binary for NT/2000/XP with support for named
  4861.                pipes.
  4862. `mysqld-max'   Optimised binary with support for symbolic links,
  4863.                `InnoDB' and `BDB' tables.
  4864. `mysqld-max-nt'Like `mysqld-max', but compiled with support for named
  4865.                pipes.
  4866.  
  4867. All of the preceding binaries are optimised for modern Intel processors
  4868. but should work on any Intel processor >= i386.
  4869.  
  4870. When run on a version of Windows that supports named pipes (NT, 2000,
  4871. XP), the `mysqld-nt' and `mysqld-max-nt' servers support named pipe
  4872. connections.  However, starting from 3.23.50, named pipes are enabled
  4873. only if you start these servers with the `--enable-named-pipe' option.
  4874. (The servers can be run on Windows 98 or Me, but TCP/IP must be
  4875. installed, and named pipe connections cannot be used. On Windows 95,
  4876. these servers cannot be used.)
  4877.  
  4878. You will find it helpful to use an option file to specify your MySQL
  4879. configuration under the following circumstances:
  4880.  
  4881.    * The installation or data directories are different from the default
  4882.      locations (`C:\mysql' and `C:\mysql\data').
  4883.  
  4884.    * You need to tune the server settings.  For example, if you want to
  4885.      use the `InnoDB' transactional tables in MySQL version 3.23, you
  4886.      need to manually create two new directories to hold the `InnoDB'
  4887.      data and log files--such as, `C:\ibdata' and `C:\iblogs'.  You
  4888.      will also need to add some extra lines to the option file, as
  4889.      described in *Note `InnoDB' start: InnoDB start.  (As of MySQL
  4890.      4.0, InnoDB will create its datafiles and log files in the data
  4891.      directory by default. This means you need not configure InnoDB
  4892.      explicitly, though you may still wish to do so.)
  4893.  
  4894.  
  4895. On Windows, the MySQL installer places the data directory directly under
  4896. the directory where you install MySQL.  If you would like to use a data
  4897. directory in a different location, you should copy the entire contents
  4898. of the `data' directory to the new location. For example, the default
  4899. installation places MySQL in `C:\mysql' and the data directory in
  4900. `C:\mysql\data'. If you want to use a data directory of `E:\mydata',
  4901. you must copy `C:\mysql\data' there. You will also need to use a
  4902. `--datadir' option to specify the location of the new data directory.
  4903.  
  4904. Normally you can use the `WinMySQLAdmin' tool to edit the option file
  4905. `my.ini'.  In this case you don't have to worry about the following
  4906. discussion.
  4907.  
  4908. There are two option files with the same function: `C:\my.cnf', and the
  4909. `my.ini' file in the Windows directory.  (This directory typically is
  4910. named something like `C:\WINDOWS' or `C:\WinNT'.  You can determine its
  4911. exact location from the value of the `WINDIR' environment variable.)
  4912. MySQL looks first for the `my.ini' file, then for the `my.cnf' file.
  4913. However, to avoid confusion, it's best if you use only one of these
  4914. files. Both files are plain text.
  4915.  
  4916. If your PC uses a boot loader where the `C:' drive isn't the boot drive,
  4917. your only option is to use the `my.ini' file.  Also note that if you
  4918. use the `WinMySQLAdmin' tool, it uses only the `my.ini' file.  The
  4919. `\mysql\bin' directory contains a help file with instructions for using
  4920. this tool.
  4921.  
  4922. Using the `notepad' program, create the option file and edit the
  4923. `[mysqld]' section to specify values for the `basedir' and `datadir'
  4924. parameters:
  4925.  
  4926.      [mysqld]
  4927.      # set basedir to your installation path, for example, C:/mysql
  4928.      basedir=the_install_path
  4929.      # set datadir to the location of your data directory,
  4930.      # for example, C:/mysql/data or D:/mydata/data
  4931.      datadir=the_data_path
  4932.  
  4933. Note that Windows pathnames should be specified in option files using
  4934. forward slashes rather than backslashes.  If you do use backslashes, you
  4935. must double them.
  4936.  
  4937. Now you are ready to test starting the server.
  4938.  
  4939. Starting the Server for the First Time
  4940. ......................................
  4941.  
  4942. Testing is best done from a command prompt in a console window (a "DOS
  4943. window"). This way you can have the server display status messages in
  4944. the window where they are easy to see.  If something is wrong with your
  4945. configuration, these messages will make it easier for you to identify
  4946. and fix any problems.
  4947.  
  4948. Make sure you are in the directory where the server is located, then
  4949. enter this command:
  4950.  
  4951.      shell> mysqld --console
  4952.  
  4953. For servers that include `InnoDB' support, you should see the following
  4954. messages as the server starts up:
  4955.  
  4956.      InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist:
  4957.      InnoDB: a new database to be created!
  4958.      InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200
  4959.      InnoDB: Database physically writes the file full: wait...
  4960.      InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created
  4961.      InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280
  4962.      InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created
  4963.      InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280
  4964.      InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created
  4965.      InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280
  4966.      InnoDB: Doublewrite buffer not found: creating new
  4967.      InnoDB: Doublewrite buffer created
  4968.      InnoDB: creating foreign key constraint system tables
  4969.      InnoDB: foreign key constraint system tables created
  4970.      011024 10:58:25  InnoDB: Started
  4971.  
  4972. When the server finishes its startup sequence, you should see something
  4973. like this, which indicates that the server is ready to service client
  4974. connections::
  4975.  
  4976.      mysqld: ready for connections
  4977.      Version: '4.0.14-log'  socket: ''  port: 3306
  4978.  
  4979. The server will continue to write to the console any further diagnostic
  4980. output it produces.  You can open a new console window in which to run
  4981. client programs.
  4982.  
  4983. If you omit the `--console' option, the server writes diagnostic output
  4984. to the error log in the data directory. The error log is the file with
  4985. the `.err' extension.
  4986.  
  4987. For further information about running MySQL on Windows, see *Note
  4988. Windows::.
  4989.  
  4990. Installing MySQL on Linux
  4991. -------------------------
  4992.  
  4993. The recommended way to install MySQL on Linux is by using the RPM
  4994. packages. The MySQL RPMs are currently built on a SuSE Linux 7.3 system
  4995. but should work on most versions of Linux that support `rpm' and use
  4996. `glibc'.
  4997.  
  4998. If you have problems with an RPM file (for example, if you receive the
  4999. error "`Sorry, the host 'xxxx' could not be looked up'"), see *Note
  5000. Binary notes-Linux::.
  5001.  
  5002. In most cases, you only need to install the `MySQL-server' and
  5003. `MySQL-client' packages to get a functional MySQL installation. The
  5004. other packages are not required for a standard installation.  If you
  5005. want to run a MySQL Max server that has additional capabilities, you
  5006. should install the `MySQL-Max' RPM after installing the `MySQL-server'
  5007. RPM.  *Note `mysqld-max': mysqld-max.
  5008.  
  5009. If you get a dependency failure when trying to install the MySQL 4.0
  5010. packages (for example, "`error: removing these packages would break
  5011. dependencies: libmysqlclient.so.10 is needed by ...'"), you should also
  5012. install the package `MySQL-shared-compat', which includes both the
  5013. shared libraries for backward compatibility (`libmysqlclient.so.12' for
  5014. MySQL 4.0 and `libmysqlclient.so.10' for MySQL 3.23).
  5015.  
  5016. Many Linux distributions still ship with MySQL 3.23 and they usually
  5017. link applications dynamically to save disk space. If these shared
  5018. libraries are in a separate package (for example, `MySQL-shared'), it is
  5019. sufficient to simply leave this package installed and just upgrade the
  5020. MySQL server and client packages (which are statically linked and do
  5021. not depend on the shared libraries). For distributions that include the
  5022. shared libraries in the same package as the MySQL server (for example,
  5023. Red Hat Linux), you could either install our 3.23 `MySQL-shared' RPM,
  5024. or use the `MySQL-shared-compat' package instead.
  5025.  
  5026. The following RPM packages are available:
  5027.  
  5028.    * `MySQL-server-VERSION.i386.rpm'
  5029.  
  5030.      The MySQL server.  You will need this unless you only want to
  5031.      connect to a MySQL server running on another machine. Please note
  5032.      that this package was called `MySQL-VERSION.i386.rpm' before MySQL
  5033.      4.0.10.
  5034.  
  5035.    * `MySQL-Max-VERSION.i386.rpm'
  5036.  
  5037.      The MySQL Max server. This server has additional capabilities that
  5038.      the one in the `MySQL-server' RPM does not.  You must install the
  5039.      `MySQL-server' RPM first, because the `MySQL-Max' RPM depends on
  5040.      it.
  5041.  
  5042.    * `MySQL-client-VERSION.i386.rpm'
  5043.  
  5044.      The standard MySQL client programs. You probably always want to
  5045.      install this package.
  5046.  
  5047.    * `MySQL-bench-VERSION.i386.rpm'
  5048.  
  5049.      Tests and benchmarks. Requires Perl and the `DBD-mysql' module.
  5050.  
  5051.    * `MySQL-devel-VERSION.i386.rpm'
  5052.  
  5053.      The libraries and include files that are needed if you want to
  5054.      compile other MySQL clients, such as the Perl modules.
  5055.  
  5056.    * `MySQL-shared-VERSION.i386.rpm'
  5057.  
  5058.      This package contains the shared libraries (`libmysqlclient.so*')
  5059.      that certain languages and applications need to dynamically load
  5060.      and use MySQL.
  5061.  
  5062.    * `MySQL-shared-compat-VERSION.i386.rpm'
  5063.  
  5064.      This package includes the shared libraries for both MySQL 3.23 and
  5065.      MySQL 4.0. Install this package instead of `MySQL-shared', if you
  5066.      have applications installed that are dynamically linked against
  5067.      MySQL 3.23 but you want to upgrade to MySQL 4.0 without breaking
  5068.      the library dependencies. This package is available since MySQL
  5069.      4.0.13.
  5070.  
  5071.    * `MySQL-embedded-VERSION.i386.rpm'
  5072.  
  5073.      The embedded MySQL server library (from MySQL 4.0).
  5074.  
  5075.    * `MySQL-VERSION.src.rpm'
  5076.  
  5077.      This contains the source code for all of the previous packages. It
  5078.      can also be used to rebuild the RPMs on other architectures (for
  5079.      example, Alpha or SPARC).
  5080.  
  5081. To see all files in an RPM package (for example, a `MySQL-server' RPM),
  5082. run:
  5083.  
  5084.      shell> rpm -qpl MySQL-server-VERSION.i386.rpm
  5085.  
  5086. To perform a standard minimal installation, run:
  5087.  
  5088.      shell> rpm -i MySQL-server-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
  5089.  
  5090. To install just the client package, run:
  5091.  
  5092.      shell> rpm -i MySQL-client-VERSION.i386.rpm
  5093.  
  5094. The server RPM places data under the `/var/lib/mysql' directory. The
  5095. RPM also creates the appropriate entries in `/etc/init.d/' to start the
  5096. server automatically at boot time. (This means that if you have
  5097. performed a previous installation and have made changes to its startup
  5098. script, you may want to make a copy of the script so you don't lose it
  5099. when you install a newer RPM.) See *Note Automatic start:: for more
  5100. information on how MySQL can be started automatically on system startup.
  5101.  
  5102. If you want to install the MySQL RPM on older Linux distributions that
  5103. do not support initialisation scripts in `/etc/init.d' (directly or via
  5104. a symlink), you should create a symbolic link that points to the
  5105. location where your initialisation scripts actually are installed. For
  5106. example, if that location is `/etc/rc.d/init.d', use these commands
  5107. before installing the RPM to create `/etc/init.d' as a symbolic link
  5108. that points there:
  5109.  
  5110.      shell> cd /etc; ln -s rc.d/init.d .
  5111.  
  5112. However, all current major Linux distributions should already support
  5113. the new directory layout that uses `/etc/init.d', because it is
  5114. required for LSB (Linux Standard Base) compliance.
  5115.  
  5116. If the RPM files that you install include `MySQL-server', the `mysqld'
  5117. daemon should be up and running after installation.  You should now be
  5118. able to start using MySQL.  *Note Post-installation::.
  5119.  
  5120. If something goes wrong, you can find more information in the binary
  5121. installation chapter. *Note Installing binary::.
  5122.  
  5123. Installing MySQL on Mac OS X
  5124. ----------------------------
  5125.  
  5126. Beginning with MySQL 4.0.11, you can install MySQL on Mac OS X 10.2
  5127. ("Jaguar") using a Mac OS X `PKG' binary package instead of the binary
  5128. tarball distribution. Please note that older versions of Mac OS X (for
  5129. example, 10.1.x) are not supported by this package.
  5130.  
  5131. The package is located inside a disk image (`.dmg') file, that you
  5132. first need to mount by double-clicking its icon in the Finder. It should
  5133. then mount the image and display its contents.
  5134.  
  5135. *NOTE*: Before proceeding with the installation, be sure to shut down
  5136. all running MySQL server instances by either using the MySQL Manager
  5137. Application (on Mac OS X Server) or via `mysqladmin shutdown' on the
  5138. command line.
  5139.  
  5140. To actually install the MySQL PKG, double click on the package icon.
  5141. This launches the Mac OS Package Installer, which will guide you through
  5142. the installation of MySQL.
  5143.  
  5144. The Mac OS X PKG of MySQL will install itself into
  5145. `/usr/local/mysql-<version>' and will also install a symbolic link
  5146. `/usr/local/mysql', pointing to the new location. If a directory named
  5147. `/usr/local/mysql' already exists, it will be renamed to
  5148. `/usr/local/mysql.bak' first. Additionally, it will install the grant
  5149. tables in the `mysql' database by executing `mysql_install_db' after
  5150. the installation.
  5151.  
  5152. The installation layout is similar to the one of the binary
  5153. distribution; all MySQL binaries are located in the directory
  5154. `/usr/local/mysql/bin'.  The MySQL socket file is created as
  5155. `/tmp/mysql.sock' by default.  *Note Installation layouts::.
  5156.  
  5157. MySQL installation requires a Mac OS X user account named `mysql' (a
  5158. user account with this name should exist by default on Mac OS X 10.2
  5159. and up).
  5160.  
  5161. If you are running Mac OS X Server, you already have a version of MySQL
  5162. installed:
  5163.  
  5164.    * Mac OS X Server 10.2-10.2.2 come with MySQL 3.23.51 installed
  5165.  
  5166.    * Mac OS X Server 10.2.3-10.2.6 ship with MySQL 3.23.53
  5167.  
  5168. This manual section covers the installation of the official MySQL Mac
  5169. OS X PKG only.  Make sure to read Apple's help about installing MySQL
  5170. (Run the "Help View" application, select "Mac OS X Server" help, and do
  5171. a search for "MySQL" and read the item entitled "Installing MySQL").
  5172.  
  5173. Especially note that the pre-installed version of MySQL on Mac OS X
  5174. Server is started with the command `safe_mysqld' instead of
  5175. `mysqld_safe'.
  5176.  
  5177. If you previously used Marc Liyanage's MySQL packages for Mac OS X from
  5178. `http://www.entropy.ch', you can simply follow the update instructions
  5179. for packages using the binary installation layout as given on his pages.
  5180.  
  5181. If you are upgrading from Marc's 3.23.xx versions or from the Mac OS X
  5182. Server version of MySQL to the official MySQL PKG, you also need to
  5183. convert the existing MySQL privilege tables to the current format,
  5184. because some new security privileges have been added.  *Note
  5185. Upgrading-grant-tables::.
  5186.  
  5187. If you would like to automatically start up MySQL during system bootup,
  5188. you also need to install the MySQL Startup Item. Starting with MySQL
  5189. 4.0.15, it is part of the Mac OS X installation disk images as a
  5190. separate installation package. Simply double-click the
  5191. `MySQLStartupItem.pkg' icon and follow the instructions to install it.
  5192.  
  5193. Note that this only has to be done once! There is no need to install the
  5194. Startup Item every time you upgrade the MySQL package.
  5195.  
  5196. The Startup Item will be installed into `/Library/StartupItems/MySQL'.
  5197. It adds a variable `MYSQLCOM=-YES-' to the system configuration file
  5198. `/etc/hostconfig'. If you would like to disable the automatic startup
  5199. of MySQL, simply change this variable to `MYSQLCOM=-NO-'.
  5200.  
  5201. On Mac OS X Server, the Startup Item installation script will
  5202. automatically disable the startup of the default MySQL installation by
  5203. changing the variable `MYSQL' in `/etc/hostconfig' to `MYSQL=-NO-'. This
  5204. is to avoid conflicts on bootup. However, it does not shut down an
  5205. already running MySQL server.
  5206.  
  5207. After the installation, you can start up MySQL by running the following
  5208. commands in a terminal window. Please note that you need to have
  5209. administrator privileges to perform this task.
  5210.  
  5211. If you have installed the Startup Item:
  5212.  
  5213.      shell> sudo /Library/StartupItems/MySQL/MySQL start
  5214.      (Enter your password, if necessary)
  5215.      (Press Control-D or enter "exit" to exit the shell)
  5216.  
  5217. If you don't use the Startup Item, enter the following command sequence:
  5218.  
  5219.      shell> cd /usr/local/mysql
  5220.      shell> sudo ./bin/mysqld_safe
  5221.      (Enter your password, if necessary)
  5222.      (Press Control-Z)
  5223.      shell> bg
  5224.      (Press Control-D or enter "exit" to exit the shell)
  5225.  
  5226. You should now be able to connect to the MySQL server, for example, by
  5227. running `/usr/local/mysql/bin/mysql'.
  5228.  
  5229. If you installed MySQL for the first time, *please remember to set a
  5230. password for the MySQL `root' user!*
  5231.  
  5232. This is done with the following two commands:
  5233.  
  5234.      /usr/local/mysql/bin/mysqladmin -u root password <password>
  5235.      /usr/local/mysql/bin/mysqladmin -u root -h `hostname` password <password>
  5236.  
  5237. Please make sure that the `hostname' command in the second line is
  5238. enclosed by *backticks* (`), so the shell can replace it with the
  5239. output of this command (the host name of this system)!
  5240.  
  5241. You might want to also add aliases to your shell's resource file to
  5242. access `mysql' and `mysqladmin' from the command line:
  5243.  
  5244.      alias mysql '/usr/local/mysql/bin/mysql'
  5245.      alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
  5246.  
  5247. Alternatively, you could simply add `/usr/local/mysql/bin' to your
  5248. `PATH' environment variable, for example, by adding the following to
  5249. `$HOME/.tcshrc':
  5250.  
  5251.      setenv PATH ${PATH}:/usr/local/mysql/bin
  5252.  
  5253. Please note that installing a new MySQL PKG does not remove the
  5254. directory of an older installation. Unfortunately, the Mac OS X
  5255. Installer does not yet offer the functionality required to properly
  5256. upgrade previously installed packages.
  5257.  
  5258. After you have copied over the MySQL database files from the previous
  5259. version and have successfully started the new version, you should
  5260. consider removing the old installation files to save disk space.
  5261. Additionally, you should also remove older versions of the Package
  5262. Receipt directories located in `/Library/Receipts/mysql-<version>.pkg'.
  5263.  
  5264. Installing MySQL on NetWare
  5265. ---------------------------
  5266.  
  5267. As of version 4.0.11, the MySQL server is available for Novell NetWare
  5268. in binary package form. In order to host MySQL, the NetWare server must
  5269. meet these requirements:
  5270.  
  5271.    * NetWare version 6.5, or NetWare 6.0 with Support Pack 3 installed
  5272.      (You can obtain this at
  5273.      `http://support.novell.com/filefinder/13659/index.html').  The
  5274.      system must meet Novell's minimum requirements to run the
  5275.      respective version of NetWare.
  5276.  
  5277.    * MySQL data, as well as the binaries themselves, must be installed
  5278.      on an NSS volume; traditional volumes are not supported.
  5279.  
  5280. The binary package for NetWare can be obtained at
  5281. `http://www.mysql.com/downloads/'.
  5282.  
  5283. If you are running MySQL on NetWare 6.0, we strongly suggest that you
  5284. use the `--skip-external-locking' option on the command line. It will
  5285. also be neccesary to use `CHECK TABLE' and `REPAIR TABLE' instead of
  5286. `myisamchk', because `myisamchk' makes use of external locking.
  5287. External locking is known to have problems on NetWare 6.0; the problem
  5288. has been eliminated in NetWare 6.5.
  5289.  
  5290. Installing the MySQL for NetWare Binaries
  5291. .........................................
  5292.  
  5293.   1. If you are upgrading from a prior installation, stop the MySQL
  5294.      server.  This is done from the server console, using:
  5295.  
  5296.           SERVER:  mysqladmin -u root shutdown
  5297.  
  5298.   2. Log on to the target server from a client machine with access to
  5299.      the location where you will install MySQL.
  5300.  
  5301.   3. Extract the binary package zip file onto the server. Be sure to
  5302.      allow the paths in the zip file to be used. It is safe to simply
  5303.      extract the file to `SYS:\'.
  5304.  
  5305.      If you are upgrading from a prior installation, you may need to
  5306.      copy the data directory (for example, `SYS:MYSQL\DATA') now, as
  5307.      well as `my.cnf' if you have customised it. You can then delete
  5308.      the old copy of MySQL.
  5309.  
  5310.   4. You may wish to rename the directory to something more consistent
  5311.      and easy to use. We recommend using `SYS:MYSQL'; examples in the
  5312.      manual will use this to refer to the installation directory in
  5313.      general.
  5314.  
  5315.   5. At the server console, add a search path for the directory
  5316.      containing the MySQL NLMs. For example:
  5317.  
  5318.           SERVER:  SEARCH ADD SYS:MYSQL\BIN
  5319.  
  5320.   6. Install the initial database, if needed, by executing
  5321.      `mysql_install_db' at the server console.
  5322.  
  5323.   7. Start the MySQL server using `mysqld_safe' at the server console.
  5324.  
  5325.   8. To finish the installation, you should also add the following
  5326.      commands to `autoexec.ncf'. For example, if your MySQL
  5327.      installation is in `SYS:MYSQL' and you want MySQL to start
  5328.      automatically, you could add these lines:
  5329.  
  5330.           #Starts the MySQL 4.0.x database server
  5331.           SEARCH ADD SYS:MYSQL\BIN
  5332.           MYSQLD_SAFE
  5333.  
  5334.      If you are using NetWare 6.0, you should add the
  5335.      `--skip-external-locking' flag:
  5336.  
  5337.           #Starts the MySQL 4.0.x database server
  5338.           SEARCH ADD SYS:MYSQL\BIN
  5339.           MYSQLD_SAFE --skip-external-locking
  5340.  
  5341.  
  5342. If there was an existing installation of MySQL on the server, be sure
  5343. to check for existing MySQL startup commands in `autoexec.ncf', and
  5344. edit or delete them as necessary.
  5345.  
  5346. General Installation Issues
  5347. ===========================
  5348.  
  5349. How to Get MySQL
  5350. ----------------
  5351.  
  5352. Check the MySQL homepage (`http://www.mysql.com/') for information
  5353. about the current version and for downloading instructions.
  5354.  
  5355. Our main mirror is located at `http://mirrors.sunsite.dk/mysql/'.
  5356.  
  5357. For a complete up-to-date list of MySQL web/download mirrors, see
  5358. `http://www.mysql.com/downloads/mirrors.html'.  There you will also
  5359. find information about becoming a MySQL mirror site and how to report a
  5360. bad or out-of-date mirror.
  5361.  
  5362. Verifying Package Integrity Using `MD5 Checksums' or `GnuPG'
  5363. ------------------------------------------------------------
  5364.  
  5365. After you have downloaded the MySQL package that suits your needs and
  5366. before you attempt to install it, you should make sure it is intact and
  5367. has not been tampered with.
  5368.  
  5369. MySQL AB offers two means of integrity checking: `MD5 checksums' and
  5370. cryptographic signatures using `GnuPG', the `GNU Privacy Guard'.
  5371.  
  5372. Verifying the `MD5 Checksum'
  5373. ----------------------------
  5374.  
  5375. After you have downloaded the package, you should check, if the MD5
  5376. checksum matches the one provided on the MySQL download pages. Each
  5377. package has an individual checksum, that you can verify with the
  5378. following command:
  5379.  
  5380.      shell> md5sum <package>
  5381.  
  5382. Note, that not all operating systems support the `md5sum' command - on
  5383. some it is simply called `md5', others do not ship it at all. On Linux,
  5384. it is part of the `GNU Text Utilities' package, which is available for
  5385. a wide range of platforms. You can download the source code from
  5386. `http://www.gnu.org/software/textutils/' as well. If you have `OpenSSL'
  5387. installed, you can also use the command `openssl md5 <package>'
  5388. instead. A DOS/Windows implementation of the `md5' command is available
  5389. from `http://www.fourmilab.ch/md5/'.
  5390.  
  5391. Example:
  5392.      shell> md5sum mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz
  5393.      155836a7ed8c93aee6728a827a6aa153
  5394.                      mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz
  5395.  
  5396. You should check, if the resulting checksum matches the one printed on
  5397. the download page right below the respective package.
  5398.  
  5399. Signature Checking Using `GnuPG'
  5400. --------------------------------
  5401.  
  5402. A more reliable method of verifying the integrity of a package is using
  5403. cryptographic signatures. MySQL AB uses the `GNU Privacy Guard'
  5404. (`GnuPG'), an `Open Source' alternative to the very well-known `Pretty
  5405. Good Privacy' (`PGP') by Phil Zimmermann.  See `http://www.gnupg.org/'
  5406. and `http://www.openpgp.org/' for more information about
  5407. `OpenPGP'/`GnuPG' and how to obtain and install `GnuPG' on your system.
  5408. Most Linux distributions already ship with `GnuPG' installed by default.
  5409.  
  5410. Beginning with MySQL 4.0.10 (February 2003), MySQL AB has started
  5411. signing their downloadable packages with `GnuPG'. Cryptographic
  5412. signatures are a much more reliable method of verifying the integrity
  5413. and authenticity of a file.
  5414.  
  5415. To verify the signature for a specific package, you first need to
  5416. obtain a copy of MySQL AB's public GPG build key <build@mysql.com>. You
  5417. can either cut and paste it directly from here, or obtain it from
  5418. `http://www.keyserver.net/'.
  5419.  
  5420.      Key ID:
  5421.      pub  1024D/5072E1F5 2003-02-03
  5422.           MySQL Package signing key (www.mysql.com) <build@mysql.com>
  5423.      Fingerprint: A4A9 4068 76FC BD3C 4567  70C8 8C71 8D3B 5072 E1F5
  5424.      
  5425.      Public Key (ASCII-armored):
  5426.      
  5427.      -----BEGIN PGP PUBLIC KEY BLOCK-----
  5428.      Version: GnuPG v1.0.6 (GNU/Linux)
  5429.      Comment: For info see http://www.gnupg.org
  5430.      
  5431.      mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3
  5432.      RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ
  5433.      fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3
  5434.      BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW
  5435.      hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV
  5436.      K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE
  5437.      kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI
  5438.      QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep
  5439.      rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFj
  5440.      a2FnZSBzaWduaW5nIGtleSAod3d3Lm15c3FsLmNvbSkgPGJ1aWxkQG15c3FsLmNv
  5441.      bT6IXQQTEQIAHQUCPj6jDAUJCWYBgAULBwoDBAMVAwIDFgIBAheAAAoJEIxxjTtQ
  5442.      cuH1cY4AnilUwTXn8MatQOiG0a/bPxrvK/gCAJ4oinSNZRYTnblChwFaazt7PF3q
  5443.      zIhMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAn1mxHijft00bKXvu
  5444.      cSo/pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJ
  5445.      YiKJAAoJELb1zU3GuiQ/lpEAoIhpp6BozKI8p6eaabzF5MlJH58pAKCu/ROofK8J
  5446.      Eg2aLos+5zEYrB/LsrkCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/l
  5447.      xaZoJYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRi
  5448.      Rjd1DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE
  5449.      7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fm
  5450.      Le11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p
  5451.      /1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqq
  5452.      a8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSaf
  5453.      anFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOW
  5454.      I39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42Lmu
  5455.      QT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt92
  5456.      6s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZ
  5457.      Whe70YGNPw1yjWJT1IhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4A
  5458.      n3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uUq/SlsQ==
  5459.      =YJkx
  5460.      -----END PGP PUBLIC KEY BLOCK-----
  5461.  
  5462. You can import this key into your public `GPG' keyring by using `gpg
  5463. --import'. See the `GPG' documentation for more info on how to work
  5464. with public keys.
  5465.  
  5466. After you have downloaded and imported the public build key, now
  5467. download your desired MySQL package and the corresponding signature,
  5468. which is also available from the download page.  The signature has the
  5469. file name extension `.asc'. For example, the signature for
  5470. `mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz' would be
  5471. `mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz.asc'.  Make sure that
  5472. both files are stored in the same directory and then run the following
  5473. command to verify the signature for this file:
  5474.  
  5475.      shell> gpg --verify <package>.asc
  5476.      
  5477.      Example:
  5478.      
  5479.      shell> gpg --verify mysql-standard-4.0.10-gamma-pc-linux-i686.tar.gz.asc
  5480.      gpg: Warning: using insecure memory!
  5481.      gpg: Signature made Mon 03 Feb 2003 08:50:39 PM MET using DSA key ID 5072E1F5
  5482.      gpg: Good signature from
  5483.           "MySQL Package signing key (www.mysql.com) <build@mysql.com>"
  5484.  
  5485. The "Good signature" message indicates that everything is all right.
  5486.  
  5487. For `RPM' packages, there is no separate signature - `RPM' packages
  5488. actually have a built-in `GPG' signature and `MD5 checksum'. You can
  5489. verify them by running the following command:
  5490.  
  5491.      shell> rpm --checksig <package>.rpm
  5492.      
  5493.      Example:
  5494.      
  5495.      shell> rpm --checksig MySQL-server-4.0.10-0.i386.rpm
  5496.      MySQL-server-4.0.10-0.i386.rpm: md5 gpg OK
  5497.  
  5498. *Note:* If you are using RPM 4.1 and it complains about `(GPG) NOT OK
  5499. (MISSING KEYS: GPG#5072e1f5)' (even though you have imported it into
  5500. your GPG public keyring), you need to import the key into the RPM
  5501. keyring first. RPM 4.1 no longer uses your GPG keyring (and GPG
  5502. itself), but rather maintains its own keyring (because it's a system
  5503. wide application and the GPG public keyring is user-specific file). To
  5504. import the MySQL public key into the RPM keyring, please use the
  5505. following command:
  5506.  
  5507.      shell> rpm --import <pubkey>
  5508.      
  5509.      Example:
  5510.      
  5511.      shell> rpm --import mysql_pubkey.asc
  5512.  
  5513. In case you notice that the `MD5 checksum' or `GPG' signatures do not
  5514. match, first try to download the respective package one more time,
  5515. maybe from another mirror site. If you repeatedly can not successfully
  5516. verify the integrity of the package, please notify us about such
  5517. incidents including the full package name and the download site you
  5518. have been using at <webmaster@mysql.com> or <build@mysql.com>.
  5519.  
  5520. Operating Systems Supported by MySQL
  5521. ------------------------------------
  5522.  
  5523. We use GNU Autoconf, so it is possible to port MySQL to all modern
  5524. systems with working Posix threads and a C++ compiler.  (To compile
  5525. only the client code, a C++ compiler is required but not threads.)  We
  5526. use and develop the software ourselves primarily on Linux (SuSE and Red
  5527. Hat), FreeBSD and Sun Solaris (Versions 8 and 9).
  5528.  
  5529. Note that for many operating systems, the native thread support works
  5530. only in the latest versions. MySQL has been reported to compile
  5531. successfully on the following operating system/thread package
  5532. combinations:
  5533.  
  5534.    * AIX 4.x, 5.x with native threads.  *Note IBM-AIX::.
  5535.  
  5536.    * Amiga.
  5537.  
  5538.    * BSDI 2.x with the MIT-pthreads package.  *Note BSDI::.
  5539.  
  5540.    * BSDI 3.0, 3.1 and 4.x with native threads.  *Note BSDI::.
  5541.  
  5542.    * SCO OpenServer with a recent port of the FSU Pthreads package.
  5543.      *Note SCO::.
  5544.  
  5545.    * SCO UnixWare 7.1.x.  *Note SCO UnixWare::.
  5546.  
  5547.    * DEC Unix 4.x with native threads.  *Note Alpha-DEC-UNIX::.
  5548.  
  5549.    * FreeBSD 2.x with the MIT-pthreads package.  *Note FreeBSD::.
  5550.  
  5551.    * FreeBSD 3.x and 4.x with native threads.  *Note FreeBSD::.
  5552.  
  5553.    * FreeBSD 4.x with Linuxthreads.  *Note FreeBSD::.
  5554.  
  5555.    * HP-UX 10.20 with the DCE threads or the MIT-pthreads package.
  5556.      *Note HP-UX 10.20::.
  5557.  
  5558.    * HP-UX 11.x with the native threads.  *Note HP-UX 11.x::.
  5559.  
  5560.    * Linux 2.0+ with LinuxThreads 0.7.1+ or `glibc' 2.0.7+.  *Note
  5561.      Linux::.
  5562.  
  5563.    * Mac OS X.  *Note Mac OS X::.
  5564.  
  5565.    * NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make).
  5566.      *Note NetBSD::.
  5567.  
  5568.    * Novell NetWare 6.0.  *Note Novell NetWare::.
  5569.  
  5570.    * OpenBSD > 2.5 with native threads. OpenBSD < 2.5 with the
  5571.      MIT-pthreads package.  *Note OpenBSD::.
  5572.  
  5573.    * OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4.  *Note OS/2::.
  5574.  
  5575.    * SGI Irix 6.x with native threads.  *Note SGI-Irix::.
  5576.  
  5577.    * Solaris 2.5 and above with native threads on SPARC and x86.  *Note
  5578.      Solaris::.
  5579.  
  5580.    * SunOS 4.x with the MIT-pthreads package.  *Note Solaris::.
  5581.  
  5582.    * Tru64 Unix
  5583.  
  5584.    * Windows 9x, Me, NT, 2000 and XP.  *Note Windows::.
  5585.  
  5586. Note that not all platforms are suited equally well for running MySQL.
  5587. How well a certain platform is suited for a high-load mission-critical
  5588. MySQL server is determined by the following factors:
  5589.  
  5590.    * General stability of the thread library. A platform may have
  5591.      excellent reputation otherwise, but if the thread library is
  5592.      unstable in the code that is called by MySQL, even if everything
  5593.      else is perfect, MySQL will be only as stable as the thread
  5594.      library.
  5595.  
  5596.    * The ability of the kernel and/or thread library to take advantage
  5597.      of *SMP* on multi-processor systems. In other words, when a process
  5598.      creates a thread, it should be possible for that thread to run on
  5599.      a different CPU than the original process.
  5600.  
  5601.    * The ability of the kernel and/or the thread library to run many
  5602.      threads which acquire/release a mutex over a short critical region
  5603.      frequently without excessive context switches. In other words, if
  5604.      the implementation of `pthread_mutex_lock()' is too anxious to
  5605.      yield CPU time, this will hurt MySQL tremendously. If this issue
  5606.      is not taken care of, adding extra CPUs will actually make MySQL
  5607.      slower.
  5608.  
  5609.    * General filesystem stability/performance.
  5610.  
  5611.    * Ability of the filesystem to deal with large files at all and deal
  5612.      with them efficiently, if your tables are big.
  5613.  
  5614.    * Our level of expertise here at MySQL AB with the platform. If we
  5615.      know a platform well, we introduce platform-specific
  5616.      optimisations/fixes enabled at compile time. We can also provide
  5617.      advice on configuring your system optimally for MySQL.
  5618.  
  5619.    * The amount of testing of similar configurations we have done
  5620.      internally.
  5621.  
  5622.    * The number of users that have successfully run MySQL on that
  5623.      platform in similar configurations. If this number is high, the
  5624.      chances of hitting some platform-specific surprises are much
  5625.      smaller.
  5626.  
  5627. Based on the preceding criteria, the best platforms for running MySQL
  5628. at this point are x86 with SuSE Linux 8.2, 2.4 kernel, and ReiserFS (or
  5629. any similar Linux distribution) and SPARC with Solaris (2.7-9). FreeBSD
  5630. comes third, but we really hope it will join the top club once the
  5631. thread library is improved. We also hope that at some point we will be
  5632. able to include all other platforms on which MySQL compiles, runs okay,
  5633. but not quite with the same level of stability and performance, into
  5634. the top category. This will require some effort on our part in
  5635. cooperation with the developers of the OS/library components MySQL
  5636. depends upon. If you are interested in making one of those components
  5637. better, are in a position to influence their development, and need more
  5638. detailed instructions on what MySQL needs to run better, send an e-mail
  5639. to the MySQL internals mailing list.  *Note Mailing-list::.
  5640.  
  5641. Please note that the preceding comparison is not to say that one OS is
  5642. better or worse than the other in general. We are talking about
  5643. choosing a particular OS for a dedicated purpose--running MySQL, and
  5644. compare platforms in that regard only. With this in mind, the result of
  5645. this comparison would be different if we included more issues into it.
  5646. And in some cases, the reason one OS is better than the other could
  5647. simply be that we have put forth more effort into testing on and
  5648. optimising for that particular platform.  We are just stating our
  5649. observations to help you decide on which platform to use MySQL on in
  5650. your setup.
  5651.  
  5652. Which MySQL Version to Use
  5653. --------------------------
  5654.  
  5655. The first decision to make is whether you want to use the latest
  5656. development release or the last production (stable) release:
  5657.  
  5658.    * Normally, if you are beginning to use MySQL for the first time or
  5659.      trying to port it to some system for which there is no binary
  5660.      distribution, we recommend going with the production release
  5661.      (currently version 4.0).  Note that all MySQL releases are checked
  5662.      with the MySQL benchmarks and an extensive test suite before each
  5663.      release (even the development releases).
  5664.  
  5665.    * Otherwise, if you are running an old system and want to upgrade,
  5666.      but don't want to take chances with a non-seamless upgrade, you
  5667.      should upgrade to the latest in the same branch you are using
  5668.      (where only the last version number is newer than yours).  We have
  5669.      tried to fix only fatal bugs and make small, relatively safe
  5670.      changes to that version.
  5671.  
  5672. The second decision to make is whether you want to use a source
  5673. distribution or a binary distribution.  In most cases you should
  5674. probably use a binary distribution, if one exists for your platform, as
  5675. this generally will be easier to install than a source distribution.
  5676.  
  5677. In the following cases you probably will be better off with a source
  5678. installation:
  5679.  
  5680.    * If you want to install MySQL at some explicit location.  (The
  5681.      standard binary distributions are "ready to run" at any place, but
  5682.      you may want to get even more flexibility).
  5683.  
  5684.    * To be able to satisfy different user requirements, we are
  5685.      providing two different binary versions: one compiled with the
  5686.      non-transactional storage engines (a small, fast binary), and one
  5687.      configured with the most important extended options like
  5688.      transaction-safe tables.  Both versions are compiled from the same
  5689.      source distribution.  All native `MySQL' clients can connect to
  5690.      both MySQL versions.
  5691.  
  5692.      The extended MySQL binary distribution is marked with the `-max'
  5693.      suffix and is configured with the same options as `mysqld-max'.
  5694.      *Note `mysqld-max': mysqld-max.
  5695.  
  5696.      If you want to use the `MySQL-Max' RPM, you must first install the
  5697.      standard `MySQL-server' RPM.
  5698.  
  5699.    * If you want to configure `mysqld' with some extra features that are
  5700.      not in the standard binary distributions.  Here is a list of the
  5701.      most common extra options that you may want to use:
  5702.  
  5703.         * `--with-innodb' (default for MySQL 4.0 and onwards)
  5704.  
  5705.         * `--with-berkeley-db' (not available on all platforms)
  5706.  
  5707.         * `--with-raid'
  5708.  
  5709.         * `--with-libwrap'
  5710.  
  5711.         * `--with-named-z-libs' (This is done for some of the binaries)
  5712.  
  5713.         * `--with-debug[=full]'
  5714.  
  5715.    * The default binary distribution is normally compiled with support
  5716.      for all character sets and should work on a variety of processors
  5717.      from the same processor family.
  5718.  
  5719.      If you want a faster MySQL server you may want to recompile it
  5720.      with support for only the character sets you need, use a better
  5721.      compiler (like `pgcc'), or use compiler options that are better
  5722.      optimised for your processor.
  5723.  
  5724.    * If you have found a bug and reported it to the MySQL development
  5725.      team you will probably receive a patch that you need to apply to
  5726.      the source distribution to get the bug fixed.
  5727.  
  5728.    * If you want to read (and/or modify) the C and C++ code that makes
  5729.      up MySQL, you should get a source distribution.  The source code is
  5730.      always the ultimate manual.  Source distributions also contain more
  5731.      tests and examples than binary distributions.
  5732.  
  5733. The MySQL naming scheme uses release numbers that consist of three
  5734. numbers and a suffix.  For example, a release name like
  5735. `mysql-4.1.0-alpha' is interpreted like this:
  5736.  
  5737.    * The first number (`4') is the major version and also describes the
  5738.      file format.  All Version 4 releases have the same file format.
  5739.  
  5740.    * The second number (`1') is the release level.
  5741.  
  5742.    * The third number (`0') is the version number within the release
  5743.      level.  This is incremented for each new distribution.  Usually you
  5744.      want the latest version for the release level you have chosen.
  5745.  
  5746.    * The suffix (`alpha') indicates the stability level of the release.
  5747.      The possible suffixes are:
  5748.  
  5749.         - `alpha' indicates that the release contains some large
  5750.           section of new code that hasn't been 100% tested.  Known bugs
  5751.           (usually there are none) should be documented in the News
  5752.           section.  *Note News::.  There are also new commands and
  5753.           extensions in most alpha releases.  Active development that
  5754.           may involve major code changes can occur on an alpha release,
  5755.           but everything will be tested before doing a release.  There
  5756.           should be no known bugs in any MySQL release.
  5757.  
  5758.         - `beta' means that all new code has been tested.  No major new
  5759.           features that could cause corruption on old code are added.
  5760.           There should be no known bugs.  A version changes from alpha
  5761.           to beta when there haven't been any reported fatal bugs
  5762.           within an alpha version for at least a month and we don't
  5763.           plan to add any features that could make any old command more
  5764.           unreliable.
  5765.  
  5766.         - `gamma' is a beta that has been around a while and seems to
  5767.           work fine.  Only minor fixes are added.  This is what many
  5768.           other companies call a release.
  5769.  
  5770.         - If there is no suffix, it means that the version has been run
  5771.           for a while at many different sites with no reports of bugs
  5772.           other than platform-specific bugs.  Only critical bug fixes
  5773.           are applied to the release. This is what we call a production
  5774.           (stable) release.
  5775.  
  5776. In the MySQL development process, multiple versions co-exist and are at
  5777. a different stage. Naturally, relevant bugfixes from an earlier series
  5778. also propagate upward.
  5779.    * For the old stable/production series `3.23', new versions are only
  5780.      released for critical bugs.
  5781.  
  5782.    * The current series `4.0') is stable/production quality, with new
  5783.      versions released for bugfixes. No new features are added that
  5784.      could influence the code stability.
  5785.  
  5786.    * In the alpha branch `4.1' major new features are added. Sources
  5787.      and binaries are available for use and testing on development
  5788.      systems.
  5789.  
  5790.    * The development branch `5.0' is only available from the BitKeeper
  5791.      tree.
  5792.  
  5793. All versions of MySQL are run through our standard tests and benchmarks
  5794. to ensure that they are relatively safe to use.  Because the standard
  5795. tests are extended over time to check for all previously found bugs,
  5796. the test suite keeps getting better.
  5797.  
  5798. Note that all releases have been tested at least with:
  5799.  
  5800. An internal test suite
  5801.      This is part of a production system for a customer.  It has many
  5802.      tables with hundreds of megabytes of data.
  5803.  
  5804. The MySQL benchmark suite
  5805.      This runs a range of common queries.  It is also a test to see
  5806.      whether the latest batch of optimisations actually made the code
  5807.      faster.  *Note MySQL Benchmarks::.
  5808.  
  5809. The `crash-me' test
  5810.      This tries to determine what features the database supports and
  5811.      what its capabilities and limitations are.  *Note MySQL
  5812.      Benchmarks::.
  5813.  
  5814. Another test is that we use the newest MySQL version in our internal
  5815. production environment, on at least one machine.  We have more than 100
  5816. gigabytes of data to work with.
  5817.  
  5818. Installation Layouts
  5819. --------------------
  5820.  
  5821. This section describes the default layout of the directories created by
  5822. installing binary and source distributions.
  5823.  
  5824. A binary distribution is installed by unpacking it at the installation
  5825. location you choose (typically `/usr/local/mysql') and creates the
  5826. following directories in that location:
  5827.  
  5828. *Directory* *Contents of directory*
  5829. `bin'       Client programs and the
  5830.             `mysqld' server
  5831. `data'      Log files, databases
  5832. `docs'      Documentation, ChangeLog
  5833. `include'   Include (header) files
  5834. `lib'       Libraries
  5835. `scripts'   `mysql_install_db'
  5836. `share/mysql'Error message files
  5837. `sql-bench' Benchmarks
  5838.  
  5839. A source distribution is installed after you configure and compile it.
  5840. By default, the installation step installs files under `/usr/local', in
  5841. the following subdirectories:
  5842.  
  5843. *Directory* *Contents of directory*
  5844. `bin'       Client programs and scripts
  5845. `include/mysql'Include (header) files
  5846. `info'      Documentation in Info format
  5847. `lib/mysql' Libraries
  5848. `libexec'   The `mysqld' server
  5849. `share/mysql'Error message files
  5850. `sql-bench' Benchmarks and `crash-me' test
  5851. `var'       Databases and log files
  5852.  
  5853. Within an installation directory, the layout of a source installation
  5854. differs from that of a binary installation in the following ways:
  5855.  
  5856.    * The `mysqld' server is installed in the `libexec' directory rather
  5857.      than in the `bin' directory.
  5858.  
  5859.    * The data directory is `var' rather than `data'.
  5860.  
  5861.    * `mysql_install_db' is installed in the `/usr/local/bin' directory
  5862.      rather than in `/usr/local/mysql/scripts'.
  5863.  
  5864.    * The header file and library directories are `include/mysql' and
  5865.      `lib/mysql' rather than `include' and `lib'.
  5866.  
  5867. You can create your own binary installation from a compiled source
  5868. distribution by executing the script `scripts/make_binary_distribution'.
  5869.  
  5870. How and When Updates Are Released
  5871. ---------------------------------
  5872.  
  5873. MySQL is evolving quite rapidly here at MySQL AB and we want to share
  5874. this with other MySQL users.  We try to make a release when we have
  5875. very useful features that others seem to have a need for.
  5876.  
  5877. We also try to help out users who request features that are easy to
  5878. implement.  We take note of what our licensed users want to have, and
  5879. we especially take note of what our extended e-mail supported customers
  5880. want and try to help them out.
  5881.  
  5882. No one has to download a new release.  The News section will tell you if
  5883. the new release has something you really want.  *Note News::.
  5884.  
  5885. We use the following policy when updating MySQL:
  5886.  
  5887.    * For each minor update, the last number in the version string is
  5888.      incremented.  When there are major new features or minor
  5889.      incompatibilities with previous versions, the second number in the
  5890.      version string is incremented.  When the file format changes, the
  5891.      first number is increased.
  5892.  
  5893.    * Production (stable-tested) releases are meant to appear about 1-2
  5894.      times a year, but if small bugs are found, a release with only bug
  5895.      fixes will be released.
  5896.  
  5897.    * Working releases/bug fixes to old releases are meant to appear
  5898.      about every 1-8 weeks.
  5899.  
  5900.    * Binary distributions for some platforms will be made by us for
  5901.      major releases.  Other people may make binary distributions for
  5902.      other systems but probably less frequently.
  5903.  
  5904.    * We usually make patches available as soon as we have located and
  5905.      fixed small bugs. They usually are immediately available from our
  5906.      public BitKeeper repositories. They will also be included in the
  5907.      next release.
  5908.  
  5909.    * Non-critical but annoying bugs will be added to the MySQL source
  5910.      repository and they will be fixed in the next release.
  5911.  
  5912.    * If there is, by any chance, a fatal bug in a release we will make
  5913.      a new release as soon as possible.  We would like other companies
  5914.      to do this, too.
  5915.  
  5916. The current production release is Version 4.0; we have already moved
  5917. active development to Version 4.1 and 5.0.  Bugs will still be fixed in
  5918. the 4.0 version, and critical bugs also in the 3.23 series.  We don't
  5919. believe in a complete freeze, as this also leaves out bug fixes and
  5920. things that "must be done."  "Somewhat frozen" means that we may add
  5921. small things that "almost surely will not affect anything that's
  5922. already working."
  5923.  
  5924. MySQL uses a slightly different naming scheme from most other products.
  5925. In general it's relatively safe to use any version that has been out for
  5926. a couple of weeks without being replaced with a new version.  *Note
  5927. Which version::.
  5928.  
  5929. Release Philosophy - No Known Bugs in Releases
  5930. ----------------------------------------------
  5931.  
  5932. We put a lot of time and effort into making our releases bug free.  To
  5933. our knowledge, we have not released a single MySQL version with any
  5934. _known_ 'fatal' repeatable bugs.
  5935.  
  5936. A fatal bug is something that crashes MySQL under normal usage, gives
  5937. wrong answers for normal queries, or has a security problem.
  5938.  
  5939. We have documented all open problems, bugs and things that are
  5940. dependent on design decisions.  *Note Bugs::.
  5941.  
  5942. Our aim is to fix everything that is fixable, but without risking
  5943. making a stable MySQL version less stable. In certain cases, this means
  5944. we can fix an issue in the development version(s), but not in the
  5945. stable (production) version. Naturally, we document such issues so that
  5946. users are aware.
  5947.  
  5948. Here is a description of how our build process works:
  5949.    * We monitor bugs from our customer support list, the MySQL external
  5950.      mailing lists and the bugs database at `http://bugs.mysql.com/'.
  5951.  
  5952.    * All reported bugs for live versions are entered into the bugs
  5953.      database.
  5954.  
  5955.    * When we fix a bug, we always try to make a test case of it and
  5956.      include this into our test system to ensure that the bug will never
  5957.      come back. (About 90% of all fixed bugs have a test case.)
  5958.  
  5959.    * We also create test cases for all new features we add to MySQL.
  5960.  
  5961.    * Before we start to build a new MySQL release, we ensure that all
  5962.      reported repeatable bugs for the MySQL version (3.23.x, 4.0.x, etc)
  5963.      are fixed.  If something is impossible to fix (because some
  5964.      internal design decision in MySQL) we document this in the manual.
  5965.      *Note Bugs::.
  5966.  
  5967.    * We do a build on all platforms for which we support binaries (15+
  5968.      platforms) and run our test suite and benchmark suite on all of
  5969.      them.
  5970.  
  5971.    * We will not publish a binary for a platform for which the test or
  5972.      benchmark suite fails.  If it's a general error in the source, we
  5973.      fix this and do the build plus tests on all systems again, from
  5974.      scratch.
  5975.  
  5976.    * If we, during the build and test process (which takes 2-3 days),
  5977.      receive a report regarding a fatal bug (for example, one that
  5978.      causes a core dump), we fix this and restart the build process.
  5979.  
  5980.    * After publishing the binaries on `http://www.mysql.com/', we send
  5981.      out an announce email on the `mysql' and `announce' mailing lists.
  5982.      *Note Mailing-list::.  The announcement message contains a list of
  5983.      all changes to the release and any known problems with the release.
  5984.      (The 'known problems' section in the release notes has only been
  5985.      needed in a handful of releases.)
  5986.  
  5987.    * To quickly give our users access to the latest MySQL features, we
  5988.      do a new MySQL release every 4-5 weeks.
  5989.  
  5990.    * If we, after the release is done, get any bug reports that there
  5991.      was (after all) anything critically wrong with the build on a
  5992.      specific platform, we will fix this at once and build a new `'a''
  5993.      release for that platform. Thanks to our large user base, problems
  5994.      are found quickly.
  5995.  
  5996.    * Our track record for making good releases is quite good.  In the
  5997.      last 150 releases, we had to do a new build for less than 10
  5998.      releases (in 3 of these cases, the bug was a faulty glibc library
  5999.      on one of our build machines that took us a long time to track
  6000.      down).
  6001.  
  6002. MySQL Binaries Compiled by MySQL AB
  6003. -----------------------------------
  6004.  
  6005. As a service, we at MySQL AB provide a set of binary distributions of
  6006. MySQL that are compiled at our site or at sites where customers kindly
  6007. have given us access to their machines.
  6008.  
  6009. In addition to the binaries provided in platform-specific package
  6010. formats (see *Note Quick Standard Installation::), we do offer binary
  6011. distributions for a number of platforms by means of compressed tar
  6012. archives (`.tar.gz').
  6013.  
  6014. These distributions are generated using the script
  6015. `Build-tools/Do-compile' which compiles the source code and creates the
  6016. binary `tar.gz' archive using `scripts/make_binary_distribution' These
  6017. binaries are configured and built with the following compilers and
  6018. options.
  6019.  
  6020. Binaries built on MySQL AB development systems:
  6021.  
  6022. Linux 2.4.xx x86 with `gcc' 2.95.3
  6023.      `CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2
  6024.      -mcpu=pentiumpro -felide-constructors" ./configure
  6025.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6026.      --enable-thread-safe-client --enable-local-infile
  6027.      --enable-assembler --disable-shared
  6028.      --with-client-ldflags=-all-static
  6029.      --with-mysqld-ldflags=-all-static'
  6030.  
  6031. Linux 2.4.xx Intel Itanium 2 with `ecc' (Intel C++ Itanium Compiler 7.0)
  6032.      `CC=ecc CFLAGS="-O2 -tpp2 -ip -nolib_inline" CXX=ecc CXXFLAGS="-O2
  6033.      -tpp2 -ip -nolib_inline" ./configure --prefix=/usr/local/mysql
  6034.      --with-extra-charsets=complex --enable-thread-safe-client
  6035.      --enable-local-infile'
  6036.  
  6037. Linux 2.4.xx Intel Itanium with `ecc' (Intel C++ Itanium Compiler 7.0)
  6038.      `CC=ecc CFLAGS=-tpp1 CXX=ecc CXXFLAGS=-tpp1 ./configure
  6039.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6040.      --enable-thread-safe-client --enable-local-infile'
  6041.  
  6042. Linux 2.4.xx alpha with `ccc' (Compaq C V6.2-505 / Compaq C++ V6.3-006)
  6043.      `CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
  6044.      generic -noexceptions -nortti" ./configure
  6045.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6046.      --enable-thread-safe-client --enable-local-infile
  6047.      --with-mysqld-ldflags=-non_shared
  6048.      --with-client-ldflags=-non_shared --disable-shared'
  6049.  
  6050. Linux 2.4.xx s390 with `gcc' 2.95.3
  6051.      `CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors"
  6052.      ./configure --prefix=/usr/local/mysql
  6053.      --with-extra-charsets=complex --enable-thread-safe-client
  6054.      --enable-local-infile --disable-shared
  6055.      --with-client-ldflags=-all-static
  6056.      --with-mysqld-ldflags=-all-static'
  6057.  
  6058. Linux 2.4.xx x86_64 (AMD64) with `gcc' 3.2.1
  6059.      `CXX=gcc ./configure --prefix=/usr/local/mysql
  6060.      --with-extra-charsets=complex --enable-thread-safe-client
  6061.      --enable-local-infile  --disable-shared'
  6062.  
  6063. Sun Solaris 8 x86 with `gcc' 3.2.3
  6064.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6065.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6066.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6067.      --localstatedir=/usr/local/mysql/data
  6068.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6069.      --enable-thread-safe-client --enable-local-infile
  6070.      --disable-shared --with-innodb'
  6071.  
  6072. Sun Solaris 8 sparc with `gcc' 3.2
  6073.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6074.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6075.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6076.      --with-extra-charsets=complex --enable-thread-safe-client
  6077.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6078.      --with-named-curses-libs=-lcurses --disable-shared'
  6079.  
  6080. Sun Solaris 8 sparc 64bit with `gcc' 3.2
  6081.      `CC=gcc CFLAGS="-O3 -m64 -fno-omit-frame-pointer" CXX=gcc
  6082.      CXXFLAGS="-O3 -m64 -fno-omit-frame-pointer -felide-constructors
  6083.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6084.      --with-extra-charsets=complex --enable-thread-safe-client
  6085.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6086.      --with-named-curses-libs=-lcurses --disable-shared'
  6087.  
  6088. Sun Solaris 9 sparc with `gcc' 2.95.3
  6089.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6090.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6091.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6092.      --with-extra-charsets=complex --enable-thread-safe-client
  6093.      --enable-local-infile --enable-assembler
  6094.      --with-named-curses-libs=-lcurses --disable-shared'
  6095.  
  6096. Sun Solaris 9 sparc with `cc-5.0' (Sun Forte 5.0)
  6097.      `CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
  6098.      -D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
  6099.      ./configure --prefix=/usr/local/mysql
  6100.      --with-extra-charsets=complex --enable-thread-safe-client
  6101.      --enable-local-infile --enable-assembler --with-named-z-libs=no
  6102.      --enable-thread-safe-client --disable-shared'
  6103.  
  6104. IBM AIX 4.3.2 ppc with `gcc' 3.2.3
  6105.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2
  6106.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  6107.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6108.      --with-extra-charsets=complex --enable-thread-safe-client
  6109.      --enable-local-infile --with-named-z-libs=no --disable-shared'
  6110.  
  6111. IBM AIX 4.3.3 ppc with `xlC_r' (IBM Visual Age C/C++ 6.0)
  6112.      `CC=xlc_r CFLAGS="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  6113.      CXX=xlC_r CXXFLAGS ="-ma -O2 -qstrict -qoptimize=2 -qmaxmem=8192"
  6114.      ./configure --prefix=/usr/local/mysql
  6115.      --localstatedir=/usr/local/mysql/data
  6116.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6117.      --enable-thread-safe-client --enable-local-infile
  6118.      --with-named-z-libs=no --disable-shared --with-innodb'
  6119.  
  6120. IBM AIX 5.1.0 ppc with `gcc' 3.3
  6121.      `CFLAGS="-O2 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-O2
  6122.      -mcpu=powerpc -Wa,-many  -felide-constructors -fno-exceptions
  6123.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6124.      --with-extra-charsets=complex --with-server-suffix="-pro"
  6125.      --enable-thread-safe-client --enable-local-infile
  6126.      --with-named-z-libs=no --disable-shared'
  6127.  
  6128. HP-UX 10.20 pa-risc1.1 with `gcc' 3.1
  6129.      `CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc
  6130.      CXXFLAGS="-DHPUX -I/opt/dce /include -felide-constructors
  6131.      -fno-exceptions -fno-rtti -O3 -fPIC" ./configure
  6132.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6133.      --enable-thread-safe-client --enable-local-infile  --with-pthread
  6134.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  6135.      --disable-shared'
  6136.  
  6137. HP-UX 11.11 pa-risc2.0 64bit with `aCC' (HP ANSI C++ B3910B A.03.33)
  6138.      `CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
  6139.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6140.      --enable-thread-safe-client --enable-local-infile --disable-shared'
  6141.  
  6142. HP-UX 11.11 pa-risc2.0 32bit with `aCC' (HP ANSI C++ B3910B A.03.33)
  6143.      `CC=cc CXX=aCC CFLAGS="+DAportable" CXXFLAGS="+DAportable"
  6144.      ./configure --prefix=/usr/local/mysql
  6145.      --localstatedir=/usr/local/mysql/data
  6146.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6147.      --enable-thread-safe-client --enable-local-infile
  6148.      --disable-shared --with-innodb'
  6149.  
  6150. Apple Mac OS X 10.2 powerpc with `gcc' 3.1
  6151.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6152.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6153.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6154.      --with-extra-charsets=complex --enable-thread-safe-client
  6155.      --enable-local-infile  --disable-shared'
  6156.  
  6157. FreeBSD 4.7 i386 with `gcc' 2.95.4
  6158.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  6159.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6160.      --enable-thread-safe-client --enable-local-infile
  6161.      --enable-assembler --with-named-z-libs=not-used --disable-shared'
  6162.  
  6163. QNX Neutrino 6.2.1 i386 with `gcc' 2.95.3qnx-nto 20010315
  6164.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6165.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6166.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6167.      --with-extra-charsets=complex --enable-thread-safe-client
  6168.      --enable-local-infile  --disable-shared'
  6169.  
  6170. The following binaries are built on third-party systems kindly provided
  6171. to MySQL AB by other users. Please note that these are only provided as
  6172. a courtesy. Since MySQL AB does not have full control over these
  6173. systems, we can only provide limited support for the binaries built on
  6174. these systems.
  6175.  
  6176. SCO Unix 3.2v5.0.6 i386 with `gcc' 2.95.3
  6177.      `CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3
  6178.      -mpentium -felide-constructors" ./configure
  6179.      --prefix=/usr/local/mysql --with-extra-charsets=complex
  6180.      --enable-thread-safe-client --enable-local-infile
  6181.      --with-named-z-libs=no --enable-thread-safe-client
  6182.      --disable-shared'
  6183.  
  6184. SCO OpenUnix 8.0.0 i386 with `CC' 3.2
  6185.      `CC=cc CFLAGS="-O" CXX=CC ./configure --prefix=/usr/local/mysql
  6186.      --with-extra-charsets=complex --enable-thread-safe-client
  6187.      --enable-local-infile --with-named-z-libs=no
  6188.      --enable-thread-safe-client --disable-shared'
  6189.  
  6190. Compaq Tru64 OSF/1 V5.1 732 alpha with `cc/cxx' (Compaq C V6.3-029i / DIGITAL C++ V6.1-027)
  6191.      `CC="cc -pthread" CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline
  6192.      speed -speculate all" CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias
  6193.      -fast -inline speed -speculate all -noexceptions -nortti"
  6194.      ./configure --prefix=/usr/local/mysql
  6195.      --with-extra-charsets=complex --enable-thread-safe-client
  6196.      --enable-local-infile --with-prefix=/usr/local/mysql
  6197.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  6198.      --disable-shared --with-mysqld-ldflags=-all-static'
  6199.  
  6200. SGI Irix 6.5 IP32 with `gcc' 3.0.1
  6201.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
  6202.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6203.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6204.      --with-extra-charsets=complex --enable-thread-safe-client
  6205.      --enable-local-infile  --disable-shared'
  6206.  
  6207. FreeBSD 5.0 sparc64 with `gcc' 3.2.1
  6208.      `CFLAGS=-DHAVE_BROKEN_REALPATH ./configure
  6209.      --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
  6210.      --libexecdir=/usr/local/mysql/bin --with-extra-charsets=complex
  6211.      --enable-thread-safe-client --enable-local-infile --disable-shared
  6212.      --with-innodb'
  6213.  
  6214. The following compile options have been used for binary packages MySQL
  6215. AB used to provide in the past. These binaries are no longer being
  6216. updated, but the compile options are kept here for reference purposes.
  6217.  
  6218. Linux 2.2.xx sparc with `egcs' 1.1.2
  6219.      `CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
  6220.      -fno-omit-frame-pointer -felide-constructors -fno-exceptions
  6221.      -fno-rtti" ./configure --prefix=/usr/local/mysql
  6222.      --with-extra-charsets=complex --enable-thread-safe-client
  6223.      --enable-local-infile --enable-assembler --disable-shared'
  6224.  
  6225. Linux 2.2.x with x686 with `gcc' 2.95.2
  6226.      `CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro
  6227.      -felide-constructors -fno-exceptions -fno-rtti" ./configure
  6228.      --prefix=/usr/local/mysql --enable-assembler
  6229.      --with-mysqld-ldflags=-all-static --disable-shared
  6230.      --with-extra-charsets=complex'
  6231.  
  6232. SunOS 4.1.4 2 sun4c with `gcc' 2.7.2.1
  6233.      `CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors" ./configure
  6234.      --prefix=/usr/local/mysql --disable-shared
  6235.      --with-extra-charsets=complex --enable-assembler'
  6236.  
  6237. SunOS 5.5.1 (and above) sun4u with `egcs' 1.0.3a or 2.90.27 or gcc 2.95.2 and newer
  6238.      `CC=gcc CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6239.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql
  6240.      --with-low-memory --with-extra-charsets=complex --enable-assembler'
  6241.  
  6242. SunOS 5.6 i86pc with `gcc' 2.8.1
  6243.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6244.      --with-low-memory --with-extra-charsets=complex'
  6245.  
  6246. BSDI BSD/OS 3.1 i386 with `gcc' 2.7.2.1
  6247.      `CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql
  6248.      --with-extra-charsets=complex'
  6249.  
  6250. BSDI BSD/OS 2.1 i386 with `gcc' 2.7.2
  6251.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6252.      --with-extra-charsets=complex'
  6253.  
  6254. AIX 2 4 with `gcc' 2.7.2.2
  6255.      `CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  6256.      --with-extra-charsets=complex'
  6257.  
  6258. Anyone who has more optimal options for any of the preceding
  6259. configurations listed can always mail them to the MySQL internals s
  6260. mailing list.  *Note Mailing-list::.
  6261.  
  6262. RPM distributions prior to MySQL Version 3.22 are user-contributed.
  6263. Beginning with Version 3.22, the RPMs are generated by us at MySQL AB.
  6264.  
  6265. If you want to compile a debug version of MySQL, you should add
  6266. `--with-debug' or `--with-debug=full' to the preceding configure lines
  6267. and remove any `-fomit-frame-pointer' options.
  6268.  
  6269. For the Windows distribution, please see *Note Windows installation::.
  6270.  
  6271. Installing a MySQL Binary Distribution
  6272. --------------------------------------
  6273.  
  6274. This chapter covers the installation of MySQL binary distributions
  6275. (`.tar.gz' Archives) for various platforms (see *Note MySQL binaries::
  6276. for a detailed list).
  6277.  
  6278. In addition to these generic packages, we also offer binaries in
  6279. platform-specific package formats for selected platforms.  See *Note
  6280. Quick Standard Installation:: for more information on how to install
  6281. these.
  6282.  
  6283. The generic MySQL binary distributions are packaged as gzip-compressed
  6284. GNU tar archives (`.tar.gz'). You need the following tools to install a
  6285. MySQL binary distribution:
  6286.  
  6287.    * GNU `gunzip' to uncompress the distribution.
  6288.  
  6289.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  6290.      to work. Some `tar' implementations that come pre-installed with
  6291.      the operating system (e.g. Sun `tar') are known to have problems
  6292.      (with long file names, for example). In that case, you should
  6293.      install GNU `tar' first.
  6294.  
  6295. If you run into problems, *please always use `mysqlbug'* when posting
  6296. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  6297. `mysqlbug' gathers system information that will help others solve your
  6298. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  6299. a solution to your problem.  You will find `mysqlbug' in the `bin'
  6300. directory after you unpack the distribution.  *Note Bug reports::.
  6301.  
  6302. The basic commands you must execute to install and use a MySQL binary
  6303. distribution are:
  6304.  
  6305.      shell> groupadd mysql
  6306.      shell> useradd -g mysql mysql
  6307.      shell> cd /usr/local
  6308.      shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  6309.      shell> ln -s full-path-to-mysql-VERSION-OS mysql
  6310.      shell> cd mysql
  6311.      shell> scripts/mysql_install_db
  6312.      shell> chown -R root  .
  6313.      shell> chown -R mysql data
  6314.      shell> chgrp -R mysql .
  6315.      shell> bin/mysqld_safe --user=mysql &
  6316.  
  6317. If your version of MySQL is older than 4.0, substitute `bin/safe_mysqld'
  6318. for `bin/mysqld_safe' in the final command.
  6319.  
  6320. You can add new users using the `bin/mysql_setpermission' script if you
  6321. install the `DBI' and `DBD-mysql' Perl modules.
  6322.  
  6323. A more detailed description follows.
  6324.  
  6325. To install a binary distribution, follow these steps, then proceed to
  6326. *Note Post-installation::, for post-installation setup and testing:
  6327.  
  6328.   1. Pick the directory under which you want to unpack the
  6329.      distribution, and move into it. In the following example, we
  6330.      unpack the distribution under `/usr/local' (The following
  6331.      instructions, therefore, assume you have permission to create
  6332.      files and directories in `/usr/local'.  If that directory is
  6333.      protected, you will need to perform the installation as `root'.)
  6334.  
  6335.   2. Obtain a distribution file from one of the sites listed in *Note
  6336.      Getting MySQL: Getting MySQL.
  6337.  
  6338.      MySQL binary distributions are provided as compressed `tar'
  6339.      archives and have names like `mysql-VERSION-OS.tar.gz', where
  6340.      `VERSION' is a number (for example, `3.21.15'), and `OS' indicates
  6341.      the type of operating system for which the distribution is intended
  6342.      (for example, `pc-linux-gnu-i586').  Note that all binaries are
  6343.      built from the same MySQL source distribution.
  6344.  
  6345.   3. Add a user and group for `mysqld' to run as:
  6346.  
  6347.           shell> groupadd mysql
  6348.           shell> useradd -g mysql mysql
  6349.  
  6350.      These commands add the `mysql' group and the `mysql' user.  The
  6351.      syntax for `useradd' and `groupadd' may differ slightly on
  6352.      different versions of Unix.  They may also be called `adduser' and
  6353.      `addgroup'.  You may wish to call the user and group something
  6354.      else instead of `mysql'.
  6355.  
  6356.   4. Change into the intended installation directory:
  6357.  
  6358.           shell> cd /usr/local
  6359.  
  6360.   5. Unpack the distribution, which will create the installation
  6361.      directory.  Then create a symbolic link to that directory:
  6362.  
  6363.           shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  6364.           shell> ln -s full-path-to-mysql-VERSION-OS mysql
  6365.  
  6366.      Using GNU tar, you can also replace the first line with the
  6367.      following alternative command to decompress and extract the
  6368.      distribution in one go:
  6369.  
  6370.           shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
  6371.  
  6372.      The first command creates a directory named `mysql-VERSION-OS'.
  6373.      The second command makes a symbolic link to that directory.  This
  6374.      lets you refer more easily to the installation directory as
  6375.      `/usr/local/mysql'.
  6376.  
  6377.   6. Change into the installation directory:
  6378.  
  6379.           shell> cd mysql
  6380.  
  6381.      You will find several files and subdirectories in the `mysql'
  6382.      directory.  The most important for installation purposes are the
  6383.      `bin' and `scripts' subdirectories.
  6384.  
  6385.     `bin'
  6386.           This directory contains client programs and the server You
  6387.           should add the full pathname of this directory to your `PATH'
  6388.           environment variable so that your shell finds the MySQL
  6389.           programs properly. *Note Environment variables::.
  6390.  
  6391.     `scripts'
  6392.           This directory contains the `mysql_install_db' script used to
  6393.           initialise the `mysql' database containing the grant tables
  6394.           that store the server access permissions.
  6395.  
  6396.   7. If you would like to use `mysqlaccess' and have the MySQL
  6397.      distribution in some non-standard place, you must change the
  6398.      location where `mysqlaccess' expects to find the `mysql' client.
  6399.      Edit the `bin/mysqlaccess' script at approximately line 18.
  6400.      Search for a line that looks like this:
  6401.  
  6402.           $MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
  6403.  
  6404.      Change the path to reflect the location where `mysql' actually is
  6405.      stored on your system.  If you do not do this, you will get a
  6406.      `Broken pipe' error when you run `mysqlaccess'.
  6407.  
  6408.   8. Create the MySQL grant tables (necessary only if you haven't
  6409.      installed MySQL before):
  6410.           shell> scripts/mysql_install_db
  6411.  
  6412.      Note that MySQL versions older than Version 3.22.10 started the
  6413.      MySQL server when you run `mysql_install_db'.  This is no longer
  6414.      true.
  6415.  
  6416.   9. Change ownership of binaries to `root' and ownership of the data
  6417.      directory to the user that you will run `mysqld' as:
  6418.  
  6419.           shell> chown -R root  /usr/local/mysql/.
  6420.           shell> chown -R mysql /usr/local/mysql/data
  6421.           shell> chgrp -R mysql /usr/local/mysql/.
  6422.  
  6423.      The first command changes the `owner' attribute of the files to the
  6424.      `root' user, the second one changes the `owner' attribute of the
  6425.      data directory to the `mysql' user, and the third one changes the
  6426.      `group' attribute to the `mysql' group.
  6427.  
  6428.  10. If you want to install support for the Perl `DBI'/`DBD' interface,
  6429.      see *Note Perl support::.
  6430.  
  6431.  11. If you would like MySQL to start automatically when you boot your
  6432.      machine, you can copy `support-files/mysql.server' to the location
  6433.      where your system has its startup files.  More information can be
  6434.      found in the `support-files/mysql.server' script itself and in
  6435.      *Note Automatic start::.
  6436.  
  6437.  
  6438. After everything has been unpacked and installed, you should initialise
  6439. and test your distribution.
  6440.  
  6441. You can start the MySQL server with the following command:
  6442.  
  6443.      shell> bin/mysqld_safe --user=mysql &
  6444.  
  6445. Now proceed to *Note `mysqld_safe': mysqld_safe, and *Note
  6446. Post-installation::.
  6447.  
  6448. Installing a MySQL Source Distribution
  6449. ======================================
  6450.  
  6451. Before you proceed with the source installation, check first to see if
  6452. our binary is available for your platform and if it will work for you.
  6453. We put a lot of effort into making sure that our binaries are built
  6454. with the best possible options.
  6455.  
  6456. You need the following tools to build and install MySQL from source:
  6457.  
  6458.    * GNU `gunzip' to uncompress the distribution.
  6459.  
  6460.    * A reasonable `tar' to unpack the distribution. GNU `tar' is known
  6461.      to work. Some `tar' implementations that come pre-installed with
  6462.      the operating system (e.g. Sun `tar') are known to have problems
  6463.      (with long file names, for example). In that case, you should
  6464.      install GNU `tar' first.
  6465.  
  6466.    * A working ANSI C++ compiler.  `gcc' >= 2.95.2, `egcs' >= 1.0.2 or
  6467.      `egcs 2.91.66', SGI C++, and SunPro C++ are some of the compilers
  6468.      that are known to work.  `libg++' is not needed when using `gcc'.
  6469.      `gcc' 2.7.x has a bug that makes it impossible to compile some
  6470.      perfectly legal C++ files, such as `sql/sql_base.cc'.  If you only
  6471.      have `gcc' 2.7.x, you must upgrade your `gcc' to be able to
  6472.      compile MySQL. `gcc' 2.8.1 is also known to have problems on some
  6473.      platforms, so it should be avoided if a new compiler exists for
  6474.      the platform.
  6475.  
  6476.      `gcc' >= 2.95.2 is recommended when compiling MySQL Version 3.23.x.
  6477.  
  6478.    * A good `make' program.  GNU `make' is always recommended and is
  6479.      sometimes required.  If you have problems, we recommend trying GNU
  6480.      `make' 3.75 or newer.
  6481.  
  6482. If you are using a recent version of `gcc', recent enough to understand
  6483. the `-fno-exceptions' option, it is *very important* that you use it.
  6484. Otherwise, you may compile a binary that crashes randomly. We also
  6485. recommend that you use `-felide-constructors' and `-fno-rtti' along
  6486. with `-fno-exceptions'. When in doubt, do the following:
  6487.  
  6488.  
  6489.      CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions \
  6490.             -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler \
  6491.             --with-mysqld-ldflags=-all-static
  6492.  
  6493. On most systems this will give you a fast and stable binary.
  6494.  
  6495. If you run into problems, *please always use `mysqlbug'* when posting
  6496. questions to a MySQL mailing list.  Even if the problem isn't a bug,
  6497. `mysqlbug' gathers system information that will help others solve your
  6498. problem.  By not using `mysqlbug', you lessen the likelihood of getting
  6499. a solution to your problem.  You will find `mysqlbug' in the `scripts'
  6500. directory after you unpack the distribution.  *Note Bug reports::.
  6501.  
  6502. Quick Installation Overview
  6503. ---------------------------
  6504.  
  6505. The basic commands you must execute to install a MySQL source
  6506. distribution are:
  6507.  
  6508.      shell> groupadd mysql
  6509.      shell> useradd -g mysql mysql
  6510.      shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
  6511.      shell> cd mysql-VERSION
  6512.      shell> ./configure --prefix=/usr/local/mysql
  6513.      shell> make
  6514.      shell> make install
  6515.      shell> scripts/mysql_install_db
  6516.      shell> chown -R root  /usr/local/mysql
  6517.      shell> chown -R mysql /usr/local/mysql/var
  6518.      shell> chgrp -R mysql /usr/local/mysql
  6519.      shell> cp support-files/my-medium.cnf /etc/my.cnf
  6520.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  6521.  
  6522. If your version of MySQL is older than 4.0, substitute `bin/safe_mysqld'
  6523. for `bin/mysqld_safe' in the final command.
  6524.  
  6525. If you want to have support for InnoDB tables, you should edit the
  6526. `/etc/my.cnf' file and remove the `#' character before the parameter
  6527. that starts with `innodb_...'.  *Note Option files::, and *Note InnoDB
  6528. start::.
  6529.  
  6530. If you start from a source RPM, do the following:
  6531.  
  6532.      shell> rpm --rebuild --clean MySQL-VERSION.src.rpm
  6533.  
  6534. This will make a binary RPM that you can install.
  6535.  
  6536. You can add new users using the `bin/mysql_setpermission' script if you
  6537. install the `DBI' and `DBD-mysql' Perl modules.
  6538.  
  6539. A more detailed description follows.
  6540.  
  6541. To install a source distribution, follow these steps, then proceed to
  6542. *Note Post-installation::, for post-installation initialisation and
  6543. testing:
  6544.  
  6545.   1. Pick the directory under which you want to unpack the
  6546.      distribution, and move into it.
  6547.  
  6548.   2. Obtain a distribution file from one of the sites listed in *Note
  6549.      Getting MySQL: Getting MySQL.
  6550.  
  6551.   3. If you are interested in using Berkeley DB tables with MySQL, you
  6552.      will need to obtain a patched version of the Berkeley DB source
  6553.      code.  Please read the chapter on Berkeley DB tables before
  6554.      proceeding.  *Note BDB::.
  6555.  
  6556.      MySQL source distributions are provided as compressed `tar'
  6557.      archives and have names like `mysql-VERSION.tar.gz', where
  6558.      `VERSION' is a number like 4.0.16.
  6559.  
  6560.   4. Add a user and group for `mysqld' to run as:
  6561.  
  6562.           shell> groupadd mysql
  6563.           shell> useradd -g mysql mysql
  6564.  
  6565.      These commands add the `mysql' group and the `mysql' user.  The
  6566.      syntax for `useradd' and `groupadd' may differ slightly on
  6567.      different versions of Unix.  They may also be called `adduser' and
  6568.      `addgroup'.  You may wish to call the user and group something
  6569.      else instead of `mysql'.
  6570.  
  6571.   5. Unpack the distribution into the current directory:
  6572.           shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
  6573.  
  6574.      This command creates a directory named `mysql-VERSION'.
  6575.  
  6576.   6. Change into the top-level directory of the unpacked distribution:
  6577.  
  6578.           shell> cd mysql-VERSION
  6579.  
  6580.      Note that currently you must configure and build MySQL from this
  6581.      top-level directory.  You cannot build it in a different directory.
  6582.  
  6583.   7. Configure the release and compile everything:
  6584.  
  6585.           shell> ./configure --prefix=/usr/local/mysql
  6586.           shell> make
  6587.  
  6588.      When you run `configure', you might want to specify some options.
  6589.      Run `./configure --help' for a list of options.  *Note `configure'
  6590.      options: configure options, discusses some of the more useful
  6591.      options.
  6592.  
  6593.      If `configure' fails, and you are going to send mail to a MySQL
  6594.      mailing list to ask for assistance, please include any lines from
  6595.      `config.log' that you think can help solve the problem.  Also
  6596.      include the last couple of lines of output from `configure' if
  6597.      `configure' aborts.  Post the bug report using the `mysqlbug'
  6598.      script.  *Note Bug reports::.
  6599.  
  6600.      If the compile fails, see *Note Compilation problems::, for help
  6601.      with a number of common problems.
  6602.  
  6603.   8. Install everything:
  6604.  
  6605.           shell> make install
  6606.  
  6607.      You might need to run this command as `root'.
  6608.  
  6609.   9. Create the MySQL grant tables (necessary only if you haven't
  6610.      installed MySQL before):
  6611.  
  6612.           shell> scripts/mysql_install_db
  6613.  
  6614.      Note that MySQL versions older than Version 3.22.10 started the
  6615.      MySQL server when you run `mysql_install_db'.  This is no longer
  6616.      true.
  6617.  
  6618.  10. Change ownership of binaries to `root' and ownership of the data
  6619.      directory to the user that you will run `mysqld' as:
  6620.  
  6621.           shell> chown -R root  /usr/local/mysql
  6622.           shell> chown -R mysql /usr/local/mysql/var
  6623.           shell> chgrp -R mysql /usr/local/mysql
  6624.  
  6625.      The first command changes the `owner' attribute of the files to the
  6626.      `root' user, the second one changes the `owner' attribute of the
  6627.      data directory to the `mysql' user, and the third one changes the
  6628.      `group' attribute to the `mysql' group.
  6629.  
  6630.  11. If you want to install support for the Perl `DBI'/`DBD' interface,
  6631.      see *Note Perl support::.
  6632.  
  6633.  12. If you would like MySQL to start automatically when you boot your
  6634.      machine, you can copy `support-files/mysql.server' to the location
  6635.      where your system has its startup files.  More information can be
  6636.      found in the `support-files/mysql.server' script itself and in
  6637.      *Note Automatic start::.
  6638.  
  6639. After everything has been installed, you should initialise and test your
  6640. distribution:
  6641.  
  6642.      shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
  6643.  
  6644. If that command fails immediately with `mysqld daemon ended', you can
  6645. find some information in the file `mysql-data-directory/'hostname'.err'.
  6646. The likely reason is that you already have another `mysqld' server
  6647. running.  *Note Multiple servers::.
  6648.  
  6649. Now proceed to *Note Post-installation::.
  6650.  
  6651. Applying Patches
  6652. ----------------
  6653.  
  6654. Sometimes patches appear on the mailing list or are placed in the
  6655. patches area of the MySQL web site
  6656. (`http://www.mysql.com/downloads/patches.html').
  6657.  
  6658. To apply a patch from the mailing list, save the message in which the
  6659. patch appears in a file, change into the top-level directory of your
  6660. MySQL source tree, and run these commands:
  6661.  
  6662.      shell> patch -p1 < patch-file-name
  6663.      shell> rm config.cache
  6664.      shell> make clean
  6665.  
  6666. Patches from the FTP site are distributed as plain text files or as
  6667. files compressed with `gzip'.  Apply a plain patch as shown previously
  6668. for mailing list patches.  To apply a compressed patch, change into the
  6669. top-level directory of your MySQL source tree and run these commands:
  6670.  
  6671.      shell> gunzip < patch-file-name.gz | patch -p1
  6672.      shell> rm config.cache
  6673.      shell> make clean
  6674.  
  6675. After applying a patch, follow the instructions for a normal source
  6676. install, beginning with the `./configure' step.  After running the `make
  6677. install' step, restart your MySQL server.
  6678.  
  6679. You may need to bring down any currently running server before you run
  6680. `make install'.  (Use `mysqladmin shutdown' to do this.)  Some systems
  6681. do not allow you to install a new version of a program if it replaces
  6682. the version that is currently executing.
  6683.  
  6684. Typical `configure' Options
  6685. ---------------------------
  6686.  
  6687. The `configure' script gives you a great deal of control over how you
  6688. configure your MySQL distribution.  Typically you do this using options
  6689. on the `configure' command-line.  You can also affect `configure' using
  6690. certain environment variables.  *Note Environment variables::.  For a
  6691. list of options supported by `configure', run this command:
  6692.  
  6693.      shell> ./configure --help
  6694.  
  6695. Some of the more commonly-used `configure' options are described here:
  6696.  
  6697.    * To compile just the MySQL client libraries and client programs and
  6698.      not the server, use the `--without-server' option:
  6699.  
  6700.           shell> ./configure --without-server
  6701.  
  6702.      If you don't have a C++ compiler, `mysql' will not compile (it is
  6703.      the one client program that requires C++).  In this case, you can
  6704.      remove the code in `configure' that tests for the C++ compiler and
  6705.      then run `./configure' with the `--without-server' option. The
  6706.      compile step will still try to build `mysql', but you can ignore
  6707.      any warnings about `mysql.cc'.  (If `make' stops, try `make -k' to
  6708.      tell it to continue with the rest of the build even if errors
  6709.      occur.)
  6710.  
  6711.    * If you want to get an embedded MySQL library (`libmysqld.a') you
  6712.      should use the `--with-embedded-server' option.
  6713.  
  6714.    * If you don't want your log files and database directories located
  6715.      under `/usr/local/var', use a `configure' command, something like
  6716.      one of these:
  6717.  
  6718.           shell> ./configure --prefix=/usr/local/mysql
  6719.           shell> ./configure --prefix=/usr/local \
  6720.                      --localstatedir=/usr/local/mysql/data
  6721.  
  6722.      The first command changes the installation prefix so that
  6723.      everything is installed under `/usr/local/mysql' rather than the
  6724.      default of `/usr/local'.  The second command preserves the default
  6725.      installation prefix, but overrides the default location for
  6726.      database directories (normally `/usr/local/var') and changes it to
  6727.      `/usr/local/mysql/data'.  After you have compiled MySQL, you can
  6728.      change these options with option files. *Note Option files::.
  6729.  
  6730.    * If you are using Unix and you want the MySQL socket located
  6731.      somewhere other than the default location (normally in the
  6732.      directory `/tmp' or `/var/run') use a `configure' command like
  6733.      this:
  6734.  
  6735.           shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
  6736.  
  6737.      Note that the given file must be an absolute pathname.  You can
  6738.      also later change the location `mysql.sock' by using the MySQL
  6739.      option files. *Note Problems with mysql.sock::.
  6740.  
  6741.    * If you want to compile statically linked programs (for example, to
  6742.      make a binary distribution, to get more speed, or to work around
  6743.      problems with some Red Hat Linux distributions), run `configure'
  6744.      like this:
  6745.  
  6746.           shell> ./configure --with-client-ldflags=-all-static \
  6747.                      --with-mysqld-ldflags=-all-static
  6748.  
  6749.    * If you are using `gcc' and don't have `libg++' or `libstdc++'
  6750.      installed, you can tell `configure' to use `gcc' as your C++
  6751.      compiler:
  6752.  
  6753.           shell> CC=gcc CXX=gcc ./configure
  6754.  
  6755.      When you use `gcc' as your C++ compiler, it will not attempt to
  6756.      link in `libg++' or `libstdc++'.  This may be a good idea to do
  6757.      even if you have the above libraries installed, as some versions
  6758.      of these libraries have caused strange problems for MySQL users in
  6759.      the past.
  6760.  
  6761.      Here are some common environment variables to set depending on the
  6762.      compiler you are using:
  6763.  
  6764.      *Compiler*    *Recommended options*
  6765.      gcc 2.7.2.1    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
  6766.      egcs 1.0.3a    CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors
  6767.                    -fno-exceptions -fno-rtti"
  6768.      gcc 2.95.2     CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3
  6769.                    -mpentiumpro \ -felide-constructors -fno-exceptions
  6770.                    -fno-rtti"
  6771.      pgcc 2.90.29   CFLAGS="-O3 -mpentiumpro -mstack-align-double"
  6772.      or newer      CXX=gcc \ CXXFLAGS="-O3 -mpentiumpro
  6773.                    -mstack-align-double -felide-constructors \
  6774.                    -fno-exceptions -fno-rtti"
  6775.  
  6776.      In most cases you can get a reasonably optimal MySQL binary by
  6777.      using the options from the preceding table and adding the
  6778.      following options to the configure line:
  6779.  
  6780.           --prefix=/usr/local/mysql --enable-assembler \
  6781.           --with-mysqld-ldflags=-all-static
  6782.  
  6783.      The full configure line would, in other words, be something like
  6784.      the following for all recent gcc versions:
  6785.  
  6786.           CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
  6787.           -felide-constructors -fno-exceptions -fno-rtti" ./configure \
  6788.           --prefix=/usr/local/mysql --enable-assembler \
  6789.           --with-mysqld-ldflags=-all-static
  6790.  
  6791.      The binaries we provide on the MySQL web site at
  6792.      `http://www.mysql.com/' are all compiled with full optimisation and
  6793.      should be perfect for most users.  *Note MySQL binaries::.  There
  6794.      are some things you can tweak to make an even faster binary, but
  6795.      this is only for advanced users.  *Note Compile and link options::.
  6796.  
  6797.      If the build fails and produces errors about your compiler or
  6798.      linker not being able to create the shared library
  6799.      `libmysqlclient.so.#' (`#' is a version number), you can work
  6800.      around this problem by giving the `--disable-shared' option to
  6801.      `configure'.  In this case, `configure' will not build a shared
  6802.      `libmysqlclient.so.#' library.
  6803.  
  6804.    * You can configure MySQL not to use `DEFAULT' column values for
  6805.      non-`NULL' columns (that is, columns that are not allowed to be
  6806.      `NULL'). *Note constraint NOT NULL::.
  6807.  
  6808.           shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
  6809.  
  6810.    * By default, MySQL uses the ISO-8859-1 (Latin1) character set. To
  6811.      change the default set, use the `--with-charset' option:
  6812.           shell> ./configure --with-charset=CHARSET
  6813.      `CHARSET' may be one of `big5', `cp1251', `cp1257', `czech',
  6814.      `danish', `dec8', `dos', `euc_kr', `gb2312', `gbk', `german1',
  6815.      `hebrew', `hp8', `hungarian', `koi8_ru', `koi8_ukr', `latin1',
  6816.      `latin2', `sjis', `swe7', `tis620', `ujis', `usa7', or
  6817.      `win1251ukr'.  *Note Character sets::.
  6818.  
  6819.      If you want to convert characters between the server and the
  6820.      client, you should take a look at the `SET CHARACTER SET' command.
  6821.      *Note `SET': SET OPTION.
  6822.  
  6823.      *Warning*: If you change character sets after having created any
  6824.      tables, you will have to run `myisamchk -r -q
  6825.      --set-character-set=charset' on every table. Your indexes may be
  6826.      sorted incorrectly otherwise.  (This can happen if you install
  6827.      MySQL, create some tables, then reconfigure MySQL to use a
  6828.      different character set and reinstall it.)
  6829.  
  6830.      With the option `--with-extra-charsets=LIST' you can define which
  6831.      additional character sets should be compiled into the server.
  6832.  
  6833.      Here `LIST' is either a list of character sets separated with
  6834.      spaces, `complex' to include all characters that can't be
  6835.      dynamically loaded, or `all' to include all character sets into
  6836.      the binaries.
  6837.  
  6838.    * To configure MySQL with debugging code, use the `--with-debug'
  6839.      option:
  6840.           shell> ./configure --with-debug
  6841.      This causes a safe memory allocator to be included that can find
  6842.      some errors and that provides output about what is happening.
  6843.      *Note Debugging server::.
  6844.  
  6845.    * If your client programs are using threads, you need to also
  6846.      compile a thread-safe version of the MySQL client library with the
  6847.      `--enable-thread-safe-client' configure options. This will create a
  6848.      `libmysqlclient_r' library with which you should link your threaded
  6849.      applications.  *Note Threaded clients::.
  6850.  
  6851.    * Options that pertain to particular systems can be found in the
  6852.      system-specific section of this manual.  *Note Operating System
  6853.      Specific Notes::.
  6854.  
  6855. Installing from the Development Source Tree
  6856. -------------------------------------------
  6857.  
  6858. *Caution*: You should read this section only if you are interested in
  6859. helping us test our new code. If you just want to get MySQL up and
  6860. running on your system, you should use a standard release distribution
  6861. (either a source or binary distribution will do).
  6862.  
  6863. To obtain our most recent development source tree, use these
  6864. instructions:
  6865.  
  6866.   1. Download `BitKeeper' from
  6867.      `http://www.bitmover.com/cgi-bin/download.cgi'.  You will need
  6868.      `Bitkeeper' 3.0 or newer to access our repository.
  6869.  
  6870.   2. Follow the instructions to install it.
  6871.  
  6872.   3. After `BitKeeper' is installed, first go to the directory you want
  6873.      to work from, and then use one of the following commands to clone
  6874.      the MySQL version branch of your choice:
  6875.  
  6876.      To clone the 3.23 (old) branch, use this command:
  6877.  
  6878.           shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
  6879.  
  6880.      To clone the 4.0 (stable/production) branch, use this command:
  6881.  
  6882.           shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
  6883.  
  6884.      To clone the 4.1 alpha branch, use this command:
  6885.  
  6886.           shell> bk clone bk://mysql.bkbits.net/mysql-4.1 mysql-4.1
  6887.  
  6888.      To clone the 5.0 development branch, use this command:
  6889.  
  6890.           shell> bk clone bk://mysql.bkbits.net/mysql-5.0 mysql-5.0
  6891.  
  6892.      In the preceding examples the source tree will be set up in the
  6893.      `mysql-3.23/', `mysql-4.0/', `mysql-4.1/', or `mysql-5.0/'
  6894.      subdirectory of your current directory.
  6895.  
  6896.      If you are behind a firewall and can only initiate HTTP
  6897.      connections, you can also use `BitKeeper' via HTTP.
  6898.  
  6899.      If you are required to use a proxy server, simply set the
  6900.      environment variable `http_proxy' to point to your proxy:
  6901.  
  6902.           shell> export http_proxy="http://your.proxy.server:8080/"
  6903.  
  6904.      Now, simply replace the `bk://' with `http://' when doing a clone.
  6905.      Example:
  6906.  
  6907.           shell> bk clone http://mysql.bkbits.net/mysql-4.1 mysql-4.1
  6908.  
  6909.      The initial download of the source tree may take a while,
  6910.      depending on the speed of your connection - please be patient.
  6911.  
  6912.   4. You will need *GNU* `make', `autoconf 2.53 (or newer)', `automake
  6913.      1.5', `libtool 1.4', and `m4' to run the next set of commands.
  6914.      Even though many operating system already come with their own
  6915.      implementation of `make', chances are high that the compilation
  6916.      fails with strange error messages. Therefore it is highly
  6917.      recommended to use GNU `make' (sometimes also named `gmake') by
  6918.      all means.
  6919.  
  6920.      Fortunately, a large number of operating systems already ship with
  6921.      the GNU toolchain preinstalled or supply installable packages of
  6922.      these. In any case, they can also be downloaded from the following
  6923.      locations:
  6924.  
  6925.         * <http://www.gnu.org/software/autoconf/>
  6926.  
  6927.         * <http://www.gnu.org/software/automake/>
  6928.  
  6929.         * <http://www.gnu.org/software/libtool/>
  6930.  
  6931.         * <http://www.gnu.org/software/make/>
  6932.  
  6933.      If you are trying to configure MySQL 4.1, you will also need GNU
  6934.      `bison 1.75'.  Older versions of `bison' may report this error:
  6935.      `sql_yacc.yy:#####: fatal error: maximum table size (32767)
  6936.      exceeded'. Note: the maximum table size is not actually exceeded,
  6937.      the error is caused by bugs in these earlier `bison' versions.
  6938.  
  6939.      Versions of MySQL before version 4.1 may also compile with other
  6940.      `yacc' implementations (e.g. BSD `yacc' 91.7.30). For later
  6941.      versions, GNU `bison' is a requirement.
  6942.  
  6943.      The typical command to do in a shell is:
  6944.  
  6945.           cd mysql-4.0
  6946.           bk -r edit
  6947.           aclocal; autoheader; autoconf; automake
  6948.           (cd innobase; aclocal; autoheader; autoconf; automake) # for InnoDB
  6949.           (cd bdb/dist; sh s_all ) # for Berkeley DB
  6950.           ./configure  # Add your favorite options here
  6951.           make
  6952.  
  6953.      If you get some strange error during this stage, check that you
  6954.      really have `libtool' installed.
  6955.  
  6956.      A collection of our standard configure scripts is located in the
  6957.      `BUILD/' subdirectory.  If you are lazy, you can use
  6958.      `BUILD/compile-pentium-debug'. To compile on a different
  6959.      architecture, modify the script by removing flags that are
  6960.      Pentium-specific.
  6961.  
  6962.   5. When the build is done, run `make install'.  Be careful with this
  6963.      on a production machine; the command may overwrite your live
  6964.      release installation.  If you have another installation of MySQL,
  6965.      we recommend that you run `./configure' with different values for
  6966.      the `prefix', `with-tcp-port', and `unix-socket-path' options than
  6967.      those used for your production server.
  6968.  
  6969.   6. Play hard with your new installation and try to make the new
  6970.      features crash.  Start by running `make test'.  *Note MySQL test
  6971.      suite::.
  6972.  
  6973.   7. If you have gotten to the `make' stage and the distribution does
  6974.      not compile, please report it in our bugs database at
  6975.      `http://bugs.mysql.com/'.  If you have installed the latest
  6976.      versions of the required GNU tools, and they crash trying to
  6977.      process our configuration files, please report that also.
  6978.      However, if you execute `aclocal' and get a `command not found'
  6979.      error or a similar problem, do not report it.  Instead, make sure
  6980.      all the necessary tools are installed and that your `PATH'
  6981.      variable is set correctly so that your shell can find them.
  6982.  
  6983.   8. After the initial `bk clone' operation to get the source tree, you
  6984.      should run `bk pull' periodically to get the updates.
  6985.  
  6986.   9. You can examine the change history for the tree with all the diffs
  6987.      by using `bk sccstool'.  If you see some funny diffs or code that
  6988.      you have a question about, do not hesitate to send e-mail to the
  6989.      MySQL internals mailing list.  *Note Mailing-list::.  Also, if you
  6990.      think you have a better idea on how to do something, send an
  6991.      e-mail to the same address with a patch.  `bk diffs' will produce
  6992.      a patch for you after you have made changes to the source. If you
  6993.      do not have the time to code your idea, just send a description.
  6994.  
  6995.  10. `BitKeeper' has a nice help utility that you can access via `bk
  6996.      helptool'.
  6997.  
  6998.  11. Please note that any commits (`bk ci' or `bk citool') will trigger
  6999.      the posting of a message with the changeset to our internals
  7000.      mailing list, as well as the usual openlogging.org submission with
  7001.      just the changeset comments.  Generally, you wouldn't need to use
  7002.      commit (since the public tree will not allow `bk push'), but
  7003.      rather use the `bk diffs' method described previously.
  7004.  
  7005.  
  7006. You can also browse changesets, comments and sourcecode online by
  7007. browsing to for example, `http://mysql.bkbits.net:8080/mysql-4.1' For
  7008. MySQL 4.1.
  7009.  
  7010. The manual is in a separate tree which can be cloned with:
  7011.  
  7012.      shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
  7013.  
  7014. There are also public BitKeeper trees for MySQL Control Center and
  7015. Connector/ODBC. They can be cloned respectively as follows.
  7016.  
  7017. To clone MySQL Control center, use this command:
  7018.  
  7019.      shell> bk clone http://mysql.bkbits.net/mysqlcc mysqlcc
  7020.  
  7021. To clone Connector/ODBC, use this command:
  7022.  
  7023.      shell> bk clone http://mysql.bkbits.net/myodbc3 myodbc3
  7024.  
  7025. Problems Compiling MySQL?
  7026. -------------------------
  7027.  
  7028. All MySQL programs compile cleanly for us with no warnings on Solaris
  7029. or Linux using `gcc'.  On other systems, warnings may occur due to
  7030. differences in system include files.  See *Note MIT-pthreads:: for
  7031. warnings that may occur when using MIT-pthreads.  For other problems,
  7032. check the following list.
  7033.  
  7034. The solution to many problems involves reconfiguring.  If you do need to
  7035. reconfigure, take note of the following:
  7036.  
  7037.    * If `configure' is run after it already has been run, it may use
  7038.      information that was gathered during its previous invocation.  This
  7039.      information is stored in `config.cache'.  When `configure' starts
  7040.      up, it looks for that file and reads its contents if it exists, on
  7041.      the assumption that the information is still correct.  That
  7042.      assumption is invalid when you reconfigure.
  7043.  
  7044.    * Each time you run `configure', you must run `make' again to
  7045.      recompile.  However, you may want to remove old object files from
  7046.      previous builds first because they were compiled using different
  7047.      configuration options.
  7048.  
  7049. To prevent old configuration information or object files from being
  7050. used, run these commands before rerunning `configure':
  7051.  
  7052.      shell> rm config.cache
  7053.      shell> make clean
  7054.  
  7055. Alternatively, you can run `make distclean'.
  7056.  
  7057. The following list describes some of the problems when compiling MySQL
  7058. that have been found to occur most often:
  7059.  
  7060.    * If you get errors when compiling `sql_yacc.cc', such as the ones
  7061.      shown here, you have probably run out of memory or swap space:
  7062.  
  7063.           Internal compiler error: program cc1plus got fatal signal 11
  7064.             or
  7065.           Out of virtual memory
  7066.             or
  7067.           Virtual memory exhausted
  7068.  
  7069.      The problem is that `gcc' requires huge amounts of memory to
  7070.      compile `sql_yacc.cc' with inline functions.  Try running
  7071.      `configure' with the `--with-low-memory' option:
  7072.  
  7073.           shell> ./configure --with-low-memory
  7074.  
  7075.      This option causes `-fno-inline' to be added to the compile line
  7076.      if you are using `gcc' and `-O0' if you are using something else.
  7077.      You should try the `--with-low-memory' option even if you have so
  7078.      much memory and swap space that you think you can't possibly have
  7079.      run out.  This problem has been observed to occur even on systems
  7080.      with generous hardware configurations, and the `--with-low-memory'
  7081.      option usually fixes it.
  7082.  
  7083.    * By default, `configure' picks `c++' as the compiler name and GNU
  7084.      `c++' links with `-lg++'.  If you are using `gcc', that behaviour
  7085.      can cause problems during configuration such as this:
  7086.  
  7087.           configure: error: installation or configuration problem:
  7088.           C++ compiler cannot create executables.
  7089.  
  7090.      You might also observe problems during compilation related to
  7091.      `g++', `libg++', or `libstdc++'.
  7092.  
  7093.      One cause of these problems is that you may not have `g++', or you
  7094.      may have `g++' but not `libg++', or `libstdc++'.  Take a look at
  7095.      the `config.log' file.  It should contain the exact reason why
  7096.      your C++ compiler didn't work.  To work around these problems, you
  7097.      can use `gcc' as your C++ compiler.  Try setting the environment
  7098.      variable `CXX' to `"gcc -O3"'.  For example:
  7099.  
  7100.           shell> CXX="gcc -O3" ./configure
  7101.  
  7102.      This works because `gcc' compiles C++ sources as well as `g++'
  7103.      does, but does not link in `libg++' or `libstdc++' by default.
  7104.  
  7105.      Another way to fix these problems, of course, is to install `g++',
  7106.      `libg++', and `libstdc++'.  We would however like to recommend you
  7107.      to not use `libg++' or `libstdc++' with MySQL as this will only
  7108.      increase the binary size of mysqld without giving you any benefits.
  7109.      Some versions of these libraries have also caused strange problems
  7110.      for MySQL users in the past.
  7111.  
  7112.      Using `gcc' as the C++ compiler is also required, if you want to
  7113.      compile MySQL with RAID functionality (see *Note CREATE TABLE::
  7114.      for more info on RAID table type) and you are using GNU `gcc'
  7115.      version 3 and above. If you get errors like the ones below during
  7116.      the linking stage when you configure MySQL to compile with the
  7117.      option `--with-raid', try to use `gcc' as your C++ compiler by
  7118.      defining the above mentioned environment variable `CXX':
  7119.  
  7120.           gcc -O3 -DDBUG_OFF -rdynamic -o isamchk isamchk.o sort.o  libnisam.a
  7121.           ../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a -lpthread
  7122.           -lz -lcrypt -lnsl -lm -lpthread
  7123.           ../mysys/libmysys.a(raid.o)(.text+0x79): In function `my_raid_create':
  7124.           : undefined reference to `operator new(unsigned)'
  7125.           ../mysys/libmysys.a(raid.o)(.text+0xdd): In function `my_raid_create':
  7126.           : undefined reference to `operator delete(void*)'
  7127.           ../mysys/libmysys.a(raid.o)(.text+0x129): In function `my_raid_open':
  7128.           : undefined reference to `operator new(unsigned)'
  7129.           ../mysys/libmysys.a(raid.o)(.text+0x189): In function `my_raid_open':
  7130.           : undefined reference to `operator delete(void*)'
  7131.           ../mysys/libmysys.a(raid.o)(.text+0x64b): In function `my_raid_close':
  7132.           : undefined reference to `operator delete(void*)'
  7133.           collect2: ld returned 1 exit status
  7134.  
  7135.    * If your compile fails with errors, such as any of the following,
  7136.      you must upgrade your version of `make' to GNU `make':
  7137.  
  7138.           making all in mit-pthreads
  7139.           make: Fatal error in reader: Makefile, line 18:
  7140.           Badly formed macro assignment
  7141.             or
  7142.           make: file `Makefile' line 18: Must be a separator (:
  7143.             or
  7144.           pthread.h: No such file or directory
  7145.  
  7146.      Solaris and FreeBSD are known to have troublesome `make' programs.
  7147.  
  7148.      GNU `make' Version 3.75 is known to work.
  7149.  
  7150.    * If you want to define flags to be used by your C or C++ compilers,
  7151.      do so by adding the flags to the `CFLAGS' and `CXXFLAGS'
  7152.      environment variables.  You can also specify the compiler names
  7153.      this way using `CC' and `CXX'.  For example:
  7154.  
  7155.           shell> CC=gcc
  7156.           shell> CFLAGS=-O3
  7157.           shell> CXX=gcc
  7158.           shell> CXXFLAGS=-O3
  7159.           shell> export CC CFLAGS CXX CXXFLAGS
  7160.  
  7161.      See *Note MySQL binaries::, for a list of flag definitions that
  7162.      have been found to be useful on various systems.
  7163.  
  7164.    * If you get an error message like this, you need to upgrade your
  7165.      `gcc' compiler:
  7166.  
  7167.           client/libmysql.c:273: parse error before `__attribute__'
  7168.  
  7169.      `gcc' 2.8.1 is known to work, but we recommend using `gcc' 2.95.2
  7170.      or `egcs' 1.0.3a instead.
  7171.  
  7172.    * If you get errors such as those shown here when compiling `mysqld',
  7173.      `configure' didn't correctly detect the type of the last argument
  7174.      to `accept()', `getsockname()', or `getpeername()':
  7175.  
  7176.           cxx: Error: mysqld.cc, line 645: In this statement, the referenced
  7177.                type of the pointer value ''length'' is ''unsigned long'', which
  7178.                is not compatible with ''int''.
  7179.           new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
  7180.  
  7181.      To fix this, edit the `config.h' file (which is generated by
  7182.      `configure').  Look for these lines:
  7183.  
  7184.           /* Define as the base type of the last arg to accept */
  7185.           #define SOCKET_SIZE_TYPE XXX
  7186.  
  7187.      Change `XXX' to `size_t' or `int', depending on your operating
  7188.      system.  (Note that you will have to do this each time you run
  7189.      `configure' because `configure' regenerates `config.h'.)
  7190.  
  7191.    * The `sql_yacc.cc' file is generated from `sql_yacc.yy'.  Normally
  7192.      the build process doesn't need to create `sql_yacc.cc', because
  7193.      MySQL comes with an already generated copy.  However, if you do
  7194.      need to re-create it, you might encounter this error:
  7195.  
  7196.           "sql_yacc.yy", line xxx fatal: default action causes potential...
  7197.  
  7198.      This is a sign that your version of `yacc' is deficient.  You
  7199.      probably need to install `bison' (the GNU version of `yacc') and
  7200.      use that instead.
  7201.  
  7202.    * If you need to debug `mysqld' or a MySQL client, run `configure'
  7203.      with the `--with-debug' option, then recompile and link your
  7204.      clients with the new client library.  *Note Debugging client::.
  7205.  
  7206.    * If you get a compilation error on Linux (e.g. SuSE Linux 8.1 or
  7207.      Red Hat Linux 7.3) similar to the following one:
  7208.  
  7209.           libmysql.c:1329: warning: passing arg 5 of `gethostbyname_r' from incompatible pointer type
  7210.           libmysql.c:1329: too few arguments to function `gethostbyname_r'
  7211.           libmysql.c:1329: warning: assignment makes pointer from integer without a cast
  7212.           make[2]: *** [libmysql.lo] Error 1
  7213.  
  7214.      By default, the `configure' script attempts to determine the
  7215.      correct number of arguments by using `g++' the GNU C++ compiler.
  7216.      This test yields wrong results, if `g++' is not installed. There
  7217.      are two ways to work around this problem:
  7218.  
  7219.         * Make sure that the GNU C++ `g++' is installed. On some Linux
  7220.           distributions, the required package is called `gpp', on
  7221.           others it is named `gcc-c++'.
  7222.  
  7223.         * Use `gcc' as your C++ compiler by setting the `CXX'
  7224.           environment variable to `gcc':
  7225.                export CXX="gcc"
  7226.  
  7227.      Please note that you need to run `configure' again afterwards.
  7228.  
  7229.  
  7230. MIT-pthreads Notes
  7231. ------------------
  7232.  
  7233. This section describes some of the issues involved in using
  7234. MIT-pthreads.
  7235.  
  7236. Note that on Linux you should *not* use MIT-pthreads but use the
  7237. installed LinuxThreads implementation instead.  *Note Linux::.
  7238.  
  7239. If your system does not provide native thread support, you will need to
  7240. build MySQL using the MIT-pthreads package.  This includes older
  7241. FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
  7242. *Note Which OS::.
  7243.  
  7244. Note, that beginning with MySQL 4.0.2 MIT-pthreads are no longer part of
  7245. the source distribution. If you require this package, you need to
  7246. download it separately from
  7247. <http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz>
  7248.  
  7249. After downloading, extract this source archive into the top level of the
  7250. MySQL source directory. It will create a new subdirectory
  7251. `mit-pthreads'.
  7252.  
  7253.    * On most systems, you can force MIT-pthreads to be used by running
  7254.      `configure' with the `--with-mit-threads' option:
  7255.  
  7256.           shell> ./configure --with-mit-threads
  7257.  
  7258.      Building in a non-source directory is not supported when using
  7259.      MIT-pthreads because we want to minimise our changes to this code.
  7260.  
  7261.    * The checks that determine whether to use MIT-pthreads occur only
  7262.      during the part of the configuration process that deals with the
  7263.      server code.  If you have configured the distribution using
  7264.      `--without-server' to build only the client code, clients will not
  7265.      know whether MIT-pthreads is being used and will use Unix socket
  7266.      connections by default.  Because Unix sockets do not work under
  7267.      MIT-pthreads on some platforms, this means you will need to use
  7268.      `-h' or `--host' when you run client programs.
  7269.  
  7270.    * When MySQL is compiled using MIT-pthreads, system locking is
  7271.      disabled by default for performance reasons.  You can tell the
  7272.      server to use system locking with the `--external-locking' option.
  7273.      This is only needed if you want to be able to run two MySQL
  7274.      servers against the same datafiles (not recommended).
  7275.  
  7276.    * Sometimes the pthread `bind()' command fails to bind to a socket
  7277.      without any error message (at least on Solaris).  The result is
  7278.      that all connections to the server fail.  For example:
  7279.  
  7280.           shell> mysqladmin version
  7281.           mysqladmin: connect to server at '' failed;
  7282.           error: 'Can't connect to mysql server on localhost (146)'
  7283.  
  7284.      The solution to this is to kill the `mysqld' server and restart it.
  7285.      This has only happened to us when we have forced down the server
  7286.      and done a restart immediately.
  7287.  
  7288.    * With MIT-pthreads, the `sleep()' system call isn't interruptible
  7289.      with `SIGINT' (break).  This is only noticeable when you run
  7290.      `mysqladmin --sleep'.  You must wait for the `sleep()' call to
  7291.      terminate before the interrupt is served and the process stops.
  7292.  
  7293.    * When linking, you may receive warning messages like these (at
  7294.      least on Solaris); they can be ignored:
  7295.  
  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.           ld: warning: symbol `__iob' has differing sizes:
  7301.               (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
  7302.           file /usr/lib/libc.so value=0x140);
  7303.               /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
  7304.  
  7305.    * Some other warnings also can be ignored:
  7306.  
  7307.           implicit declaration of function `int strtoll(...)'
  7308.           implicit declaration of function `int strtoul(...)'
  7309.  
  7310.    * We haven't gotten `readline' to work with MIT-pthreads.  (This
  7311.      isn't needed, but may be interesting for someone.)
  7312.  
  7313. Windows Source Distribution
  7314. ---------------------------
  7315.  
  7316. You will need the following:
  7317.  
  7318.    * VC++ 6.0 compiler (updated with 4 or 5 SP and Pre-processor
  7319.      package) The Pre-processor package is necessary for the macro
  7320.      assembler.  More details at:
  7321.      `http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/faq.aspx'.
  7322.  
  7323.    * The MySQL source distribution for Windows, which can be downloaded
  7324.      from `http://www.mysql.com/downloads/'.
  7325.  
  7326. Building MySQL:
  7327.  
  7328.   1. Create a work directory (for example, `workdir').
  7329.  
  7330.   2. Unpack the source distribution in the aforementioned directory.
  7331.  
  7332.   3. Start the VC++ 6.0 compiler.
  7333.  
  7334.   4. In the `File' menu, select `Open Workspace'.
  7335.  
  7336.   5. Open the `mysql.dsw' workspace you find on the work directory.
  7337.  
  7338.   6. From the `Build' menu, select the `Set Active Configuration' menu.
  7339.  
  7340.   7. Click over the screen selecting `mysqld - Win32 Debug' and click
  7341.      OK.
  7342.  
  7343.   8. Press `F7' to begin the build of the debug server, libraries, and
  7344.      some client applications.
  7345.  
  7346.   9. When the compilation finishes, copy the libraries and the
  7347.      executables to a separate directory.
  7348.  
  7349.  10. Compile the release versions that you want, in the same way.
  7350.  
  7351.  11. Create the directory into which to install the MySQL stuff (for
  7352.      example, `c:\mysql').
  7353.  
  7354.  12. From the `workdir' directory copy into the `c:\mysql' directory the
  7355.      following directories:
  7356.  
  7357.         * `Data'
  7358.  
  7359.         * `Docs'
  7360.  
  7361.         * `Share'
  7362.  
  7363.  13. Create the directory `c:\mysql\bin' and copy into it all the
  7364.      servers and clients that you just compiled.
  7365.  
  7366.  14. If you want, also create the `c:\mysql\lib' directory and copy the
  7367.      libraries that you just compiled.
  7368.  
  7369.  15. Do a clean using Visual Studio.
  7370.  
  7371. Set up and start the server in the same way as for the binary Windows
  7372. distribution. *Note Windows prepare environment::.
  7373.  
  7374. Post-installation Setup and Testing
  7375. ===================================
  7376.  
  7377. Once you've installed MySQL (from either a binary or source
  7378. distribution), you need to initialise the grant tables, start the
  7379. server, and make sure that the server works okay.  You may also wish to
  7380. arrange for the server to be started and stopped automatically when
  7381. your system starts up and shuts down.
  7382.  
  7383. Normally you install the grant tables and start the server like this
  7384. for installation from a source distribution:
  7385.  
  7386.      shell> ./scripts/mysql_install_db
  7387.      shell> cd mysql_installation_directory
  7388.      shell> ./bin/mysqld_safe --user=mysql &
  7389.  
  7390. For a binary distribution (not RPM or pkg packages), do this:
  7391.  
  7392.      shell> cd mysql_installation_directory
  7393.      shell> ./scripts/mysql_install_db
  7394.      shell> ./bin/mysqld_safe --user=mysql &
  7395.  
  7396. The `mysql_install_db' script creates the `mysql' database which will
  7397. hold all database privileges, the `test' database which you can use to
  7398. test MySQL, and also privilege entries for the user that runs
  7399. `mysql_install_db' and a `root' user.  The entries are created without
  7400. passwords.  The `mysqld_safe' script starts the `mysqld' server.  (If
  7401. your version of MySQL is older than 4.0, use `safe_mysqld' rather than
  7402. `mysqld_safe'.)
  7403.  
  7404. `mysql_install_db' will not overwrite any old privilege tables, so it
  7405. should be safe to run in any circumstances.  If you don't want to have
  7406. the `test' database you can remove it with `mysqladmin -u root drop
  7407. test' after starting the server.
  7408.  
  7409. Testing is most easily done from the top-level directory of the MySQL
  7410. distribution.  For a binary distribution, this is your installation
  7411. directory (typically something like `/usr/local/mysql').  For a source
  7412. distribution, this is the main directory of your MySQL source tree.
  7413.  
  7414. In the commands shown in this section and in the following subsections,
  7415. `BINDIR' is the path to the location in which programs like
  7416. `mysqladmin' and `mysqld_safe' are installed.  For a binary
  7417. distribution, this is the `bin' directory within the distribution.  For
  7418. a source distribution, `BINDIR' is probably `/usr/local/bin', unless
  7419. you specified an installation directory other than `/usr/local' when
  7420. you ran `configure'.  `EXECDIR' is the location in which the `mysqld'
  7421. server is installed.  For a binary distribution, this is the same as
  7422. `BINDIR'.  For a source distribution, `EXECDIR' is probably
  7423. `/usr/local/libexec'.
  7424.  
  7425. Testing is described in detail:
  7426.  
  7427.   1. If necessary, start the `mysqld' server and set up the initial
  7428.      MySQL grant tables containing the privileges that determine how
  7429.      users are allowed to connect to the server.  This is normally done
  7430.      with the `mysql_install_db' script:
  7431.  
  7432.           shell> scripts/mysql_install_db
  7433.  
  7434.      Typically, `mysql_install_db' needs to be run only the first time
  7435.      you install MySQL.  Therefore, if you are upgrading an existing
  7436.      installation, you can skip this step.  (However,
  7437.      `mysql_install_db' is quite safe to use and will not update any
  7438.      tables that already exist, so if you are unsure of what to do, you
  7439.      can always run `mysql_install_db'.)
  7440.  
  7441.      `mysql_install_db' creates six tables (`user', `db', `host',
  7442.      `tables_priv', `columns_priv', and `func') in the `mysql'
  7443.      database.  A description of the initial privileges is given in
  7444.      *Note Default privileges::.  Briefly, these privileges allow the
  7445.      MySQL `root' user to do anything, and allow anybody to create or
  7446.      use databases with a name of `test' or starting with `test_'.
  7447.  
  7448.      If you don't set up the grant tables, the following error will
  7449.      appear in the log file when you start the server:
  7450.  
  7451.           mysqld: Can't find file: 'host.frm'
  7452.  
  7453.      This may also happen with a binary MySQL distribution if you don't
  7454.      start MySQL by executing exactly `./bin/mysqld_safe'.  *Note
  7455.      `mysqld_safe': mysqld_safe.
  7456.  
  7457.      You might need to run `mysql_install_db' as `root'.  However, if
  7458.      you prefer, you can run the MySQL server as an unprivileged
  7459.      (non-`root') user, provided that the user can read and write files
  7460.      in the database directory.  Instructions for running MySQL as an
  7461.      unprivileged user are given in *Note Changing MySQL user: Changing
  7462.      MySQL user.
  7463.  
  7464.      If you have problems with `mysql_install_db', see *Note
  7465.      `mysql_install_db': mysql_install_db.
  7466.  
  7467.      There are some alternatives to running the `mysql_install_db'
  7468.      script as it is provided in the MySQL distribution:
  7469.  
  7470.         * You may want to edit `mysql_install_db' before running it, to
  7471.           change the initial privileges that are installed into the
  7472.           grant tables.  This is useful if you want to install MySQL on
  7473.           a lot of machines with the same privileges.  In this case you
  7474.           probably should need only to add a few extra `INSERT'
  7475.           statements to the `mysql.user' and `mysql.db' tables.
  7476.  
  7477.         * If you want to change things in the grant tables after
  7478.           installing them, you can run `mysql_install_db', then use
  7479.           `mysql -u root mysql' to connect to the grant tables as the
  7480.           MySQL `root' user and issue SQL statements to modify the
  7481.           grant tables directly.
  7482.  
  7483.         * It is possible to re-create the grant tables completely after
  7484.           they have already been created.  You might want to do this if
  7485.           you've already installed the tables but then want to
  7486.           re-create them after editing `mysql_install_db'.
  7487.  
  7488.      For more information about these alternatives, see *Note Default
  7489.      privileges::.
  7490.  
  7491.   2. Start the MySQL server like this:
  7492.  
  7493.           shell> cd mysql_installation_directory
  7494.           shell> bin/mysqld_safe &
  7495.  
  7496.      If you have problems starting the server, see *Note Starting
  7497.      server::.
  7498.  
  7499.   3. Use `mysqladmin' to verify that the server is running.  The
  7500.      following commands provide a simple test to check that the server
  7501.      is up and responding to connections:
  7502.  
  7503.           shell> BINDIR/mysqladmin version
  7504.           shell> BINDIR/mysqladmin variables
  7505.  
  7506.      The output from `mysqladmin version' varies slightly depending on
  7507.      your platform and version of MySQL, but should be similar to that
  7508.      shown here:
  7509.  
  7510.           shell> BINDIR/mysqladmin version
  7511.           mysqladmin  Ver 8.14 Distrib 3.23.32, for linux on i586
  7512.           Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  7513.           This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  7514.           and you are welcome to modify and redistribute it under the GPL license.
  7515.           
  7516.           Server version          3.23.32-debug
  7517.           Protocol version        10
  7518.           Connection              Localhost via Unix socket
  7519.           TCP port                3306
  7520.           UNIX socket             /tmp/mysql.sock
  7521.           Uptime:                 16 sec
  7522.           
  7523.           Threads: 1  Questions: 9  Slow queries: 0
  7524.           Opens: 7  Flush tables: 2  Open tables: 0
  7525.           Queries per second avg: 0.000
  7526.           Memory in use: 132K  Max memory used: 16773K
  7527.  
  7528.      To get a feeling for what else you can do with `BINDIR/mysqladmin',
  7529.      invoke it with the `--help' option.
  7530.  
  7531.   4. Verify that you can shut down the server:
  7532.  
  7533.           shell> BINDIR/mysqladmin -u root shutdown
  7534.  
  7535.   5. Verify that you can restart the server.  Do this using
  7536.      `mysqld_safe' or by invoking `mysqld' directly.  For example:
  7537.  
  7538.           shell> BINDIR/mysqld_safe --log &
  7539.  
  7540.      If `mysqld_safe' fails, try running it from the MySQL installation
  7541.      directory (if you are not already there).  If that doesn't work,
  7542.      see *Note Starting server::.
  7543.  
  7544.   6. Run some simple tests to verify that the server is working.  The
  7545.      output should be similar to what is shown here:
  7546.  
  7547.           shell> BINDIR/mysqlshow
  7548.           +-----------+
  7549.           | Databases |
  7550.           +-----------+
  7551.           | mysql     |
  7552.           +-----------+
  7553.           
  7554.           shell> BINDIR/mysqlshow mysql
  7555.           Database: mysql
  7556.           +--------------+
  7557.           |    Tables    |
  7558.           +--------------+
  7559.           | columns_priv |
  7560.           | db           |
  7561.           | func         |
  7562.           | host         |
  7563.           | tables_priv  |
  7564.           | user         |
  7565.           +--------------+
  7566.           
  7567.           shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql
  7568.           +------+--------+------+
  7569.           | host | db     | user |
  7570.           +------+--------+------+
  7571.           | %    | test   |      |
  7572.           | %    | test_% |      |
  7573.           +------+--------+------+
  7574.  
  7575.      There is also a benchmark suite in the `sql-bench' directory
  7576.      (under the MySQL installation directory) that you can use to
  7577.      compare how MySQL performs on different platforms. The benchmark
  7578.      suite is written in Perl, using the Perl DBI module to provide a
  7579.      database-independent interface to the various databases. The
  7580.      following additional Perl modules are required to run the
  7581.      benchmark suite:
  7582.  
  7583.           DBI
  7584.           DBD-mysql
  7585.           Data-Dumper
  7586.           Data-ShowTable
  7587.  
  7588.      These modules can be obtained from CPAN `http://www.cpan.org/'.
  7589.      *Note Perl installation::.
  7590.  
  7591.      The `sql-bench/Results' directory contains the results from many
  7592.      runs against different databases and platforms.  To run all tests,
  7593.      execute these commands:
  7594.  
  7595.           shell> cd sql-bench
  7596.           shell> run-all-tests
  7597.  
  7598.      If you don't have the `sql-bench' directory, you are probably
  7599.      using an RPM for a binary distribution.  (Source distribution RPMs
  7600.      include the benchmark directory.)  In this case, you must first
  7601.      install the benchmark suite before you can use it.  Beginning with
  7602.      MySQL Version 3.22, there are benchmark RPM files named
  7603.      `mysql-bench-VERSION-i386.rpm' that contain benchmark code and
  7604.      data.
  7605.  
  7606.      If you have a source distribution, you can also run the tests in
  7607.      the `tests' subdirectory. For example, to run
  7608.      `auto_increment.tst', do this:
  7609.  
  7610.           shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
  7611.  
  7612.      The expected results are shown in the `./tests/auto_increment.res'
  7613.      file.
  7614.  
  7615. Problems Running `mysql_install_db'
  7616. -----------------------------------
  7617.  
  7618. The purpose of the `mysql_install_db' script is to generate new MySQL
  7619. privilege tables.  It will not affect any other data.  It will also not
  7620. do anything if you already have MySQL privilege tables installed.
  7621.  
  7622. If you want to re-create your privilege tables, you should take down
  7623. the `mysqld' server, if it's running, and then do something like:
  7624.  
  7625.      mv mysql-data-directory/mysql mysql-data-directory/mysql-old
  7626.      mysql_install_db
  7627.  
  7628. This section lists problems you might encounter when you run
  7629. `mysql_install_db':
  7630.  
  7631. *`mysql_install_db' doesn't install the grant tables*
  7632.      You may find that `mysql_install_db' fails to install the grant
  7633.      tables and terminates after displaying the following messages:
  7634.  
  7635.           starting mysqld daemon with databases from XXXXXX
  7636.           mysql daemon ended
  7637.  
  7638.      In this case, you should examine the log file very carefully.  The
  7639.      log should be located in the directory `XXXXXX' named by the error
  7640.      message, and should indicate why `mysqld' didn't start.  If you
  7641.      don't understand what happened, include the log when you post a
  7642.      bug report using `mysqlbug'.  *Note Bug reports::.
  7643.  
  7644. *There is already a `mysqld' daemon running*
  7645.      In this case, you probably don't have to run `mysql_install_db' at
  7646.      all.  You have to run `mysql_install_db' only once, when you
  7647.      install MySQL the first time.
  7648.  
  7649. *Installing a second `mysqld' daemon doesn't work when one daemon is running*
  7650.      This can happen when you already have an existing MySQL
  7651.      installation, but want to put a new installation in a different
  7652.      place (for example, for testing, or perhaps you simply want to run
  7653.      two installations at the same time).  Generally the problem that
  7654.      occurs when you try to run the second server is that it tries to
  7655.      use the same socket and port as the old one.  In this case you
  7656.      will get the error message: `Can't start server: Bind on TCP/IP
  7657.      port: Address already in use' or `Can't start server: Bind on unix
  7658.      socket...'. *Note Multiple servers::.
  7659.  
  7660. *You don't have write access to `/tmp'*
  7661.      If you don't have write access to create a socket file at the
  7662.      default place (in `/tmp') or permission to create temporary files
  7663.      in `/tmp,' you will get an error when running `mysql_install_db'
  7664.      or when starting or using `mysqld'.
  7665.  
  7666.      You can specify a different socket and temporary directory as
  7667.      follows:
  7668.  
  7669.           shell> TMPDIR=/some_tmp_dir/
  7670.           shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
  7671.           shell> export TMPDIR MYSQL_UNIX_PORT
  7672.  
  7673.      See *Note Problems with mysql.sock::.
  7674.  
  7675.      `some_tmp_dir' should be the path to some directory for which you
  7676.      have write permission. *Note Environment variables::.
  7677.  
  7678.      After this you should be able to run `mysql_install_db' and start
  7679.      the server with these commands:
  7680.  
  7681.           shell> scripts/mysql_install_db
  7682.           shell> BINDIR/mysqld_safe &
  7683.  
  7684. *`mysqld' crashes immediately*
  7685.      If you are running Red Hat Version 5.0 with a version of `glibc'
  7686.      older than 2.0.7-5, you should make sure you have installed all
  7687.      `glibc' patches.  There is a lot of information about this in the
  7688.      MySQL mail archives.  Links to the mail archives are available
  7689.      online at `http://lists.mysql.com/'.  Also, see *Note Linux::.
  7690.  
  7691.      You can also start `mysqld' manually using the
  7692.      `--skip-grant-tables' option and add the privilege information
  7693.      yourself using `mysql':
  7694.  
  7695.           shell> BINDIR/mysqld_safe --skip-grant-tables &
  7696.           shell> BINDIR/mysql -u root mysql
  7697.  
  7698.      From `mysql', manually execute the SQL commands in
  7699.      `mysql_install_db'.  Make sure you run `mysqladmin
  7700.      flush-privileges' or `mysqladmin reload' afterward to tell the
  7701.      server to reload the grant tables.
  7702.  
  7703. Problems Starting the MySQL Server
  7704. ----------------------------------
  7705.  
  7706. If you are going to use tables that support transactions (InnoDB, BDB),
  7707. you should first create a `my.cnf' file and set startup options for the
  7708. table types you plan to use. *Note Table types::.
  7709.  
  7710. Generally, you start the `mysqld' server in one of these ways:
  7711.  
  7712.    * By invoking `mysql.server'.  This script is used primarily at
  7713.      system startup and shutdown, and is described more fully in *Note
  7714.      Automatic start::.
  7715.  
  7716.    * By invoking `mysqld_safe', which tries to determine the proper
  7717.      options for `mysqld' and then runs it with those options. *Note
  7718.      `mysqld_safe': mysqld_safe.
  7719.  
  7720.    * For Windows NT/2000/XP, please see *Note NT start::.
  7721.  
  7722.    * By invoking `mysqld' directly.
  7723.  
  7724. When the `mysqld' daemon starts up, it changes the directory to the
  7725. data directory.  This is where it expects to write log files and the pid
  7726. (process ID) file, and where it expects to find databases.
  7727.  
  7728. The data directory location is hardwired in when the distribution is
  7729. compiled.  However, if `mysqld' expects to find the data directory
  7730. somewhere other than where it really is on your system, it will not work
  7731. properly.  If you have problems with incorrect paths, you can find out
  7732. what options `mysqld' allows and what the default path settings are by
  7733. invoking `mysqld' with the `--help' option.  You can override the
  7734. defaults by specifying the correct pathnames as command-line arguments
  7735. to `mysqld'.  (These options can be used with `mysqld_safe' as well.)
  7736.  
  7737. Normally you should need to tell `mysqld' only the base directory under
  7738. which MySQL is installed.  You can do this with the `--basedir' option.
  7739. You can also use `--help' to check the effect of changing path options
  7740. (note that `--help' *must* be the final option of the `mysqld'
  7741. command).  For example:
  7742.  
  7743.      shell> EXECDIR/mysqld --basedir=/usr/local --help
  7744.  
  7745. Once you determine the path settings you want, start the server without
  7746. the `--help' option.
  7747.  
  7748. Whichever method you use to start the server, if it fails to start up
  7749. correctly, check the log file to see if you can find out why.  Log files
  7750. are located in the data directory (typically `/usr/local/mysql/data'
  7751. for a binary distribution, `/usr/local/var' for a source distribution,
  7752. and `\mysql\data\mysql.err' on Windows).  Look in the data directory for
  7753. files with names of the form `host_name.err' and `host_name.log' where
  7754. `host_name' is the name of your server host.  Then check the last few
  7755. lines of these files:
  7756.  
  7757.      shell> tail host_name.err
  7758.      shell> tail host_name.log
  7759.  
  7760. Look for something like the following in the log file:
  7761.      000729 14:50:10  bdb:  Recovery function for LSN 1 27595 failed
  7762.      000729 14:50:10  bdb:  warning: ./test/t1.db: No such file or directory
  7763.      000729 14:50:10  Can't init databases
  7764.  
  7765. This means that you didn't start `mysqld' with `--bdb-no-recover' and
  7766. Berkeley DB found something wrong with its log files when it tried to
  7767. recover your databases.  To be able to continue, you should move away
  7768. the old Berkeley DB log file from the database directory to some other
  7769. place, where you can later examine it.  The log files are named
  7770. `log.0000000001', where the number will increase over time.
  7771.  
  7772. If you are running `mysqld' with BDB table support and `mysqld' core
  7773. dumps at start this could be because of some problems with the BDB
  7774. recover log.  In this case you can try starting `mysqld' with
  7775. `--bdb-no-recover'.  If this helps, then you should remove all `log.*'
  7776. files from the data directory and try starting `mysqld' again.
  7777.  
  7778. If you get the following error, it means that some other program (or
  7779. another `mysqld' server) is already using the TCP/IP port or socket
  7780. `mysqld' is trying to use:
  7781.  
  7782.      Can't start server: Bind on TCP/IP port: Address already in use
  7783.        or
  7784.      Can't start server: Bind on unix socket...
  7785.  
  7786. Use `ps' to make sure that you don't have another `mysqld' server
  7787. running.  If you can't find another server running, you can try to
  7788. execute the command `telnet your-host-name tcp-ip-port-number' and press
  7789. Enter a couple of times.  If you don't get an error message like
  7790. `telnet: Unable to connect to remote host: Connection refused',
  7791. something is using the TCP/IP port `mysqld' is trying to use.  See
  7792. *Note mysql_install_db:: and *Note Multiple servers::.
  7793.  
  7794. If `mysqld' is currently running, you can find out what path settings
  7795. it is using by executing this command:
  7796.  
  7797.      shell> mysqladmin variables
  7798.  
  7799. or
  7800.  
  7801.      shell> mysqladmin -h 'your-host-name' variables
  7802.  
  7803. If you get `Errcode 13', which means `Permission denied', when starting
  7804. `mysqld' this means that you didn't have the right to read/create files
  7805. in the MySQL database or log directory. In this case you should either
  7806. start `mysqld' as the `root' user or change the permissions for the
  7807. involved files and directories so that you have the right to use them.
  7808.  
  7809. If `mysqld_safe' starts the server but you can't connect to it, you
  7810. should make sure you have an entry in `/etc/hosts' that looks like this:
  7811.  
  7812.      127.0.0.1       localhost
  7813.  
  7814. This problem occurs only on systems that don't have a working thread
  7815. library and for which MySQL must be configured to use MIT-pthreads.
  7816.  
  7817. If you can't get `mysqld' to start you can try to make a trace file to
  7818. find the problem. *Note Making trace files::.
  7819.  
  7820. If you are using InnoDB tables, refer to the InnoDB-specific startup
  7821. options.  *Note InnoDB start::.
  7822.  
  7823. If you are using BDB (Berkeley DB) tables, you should familiarise
  7824. yourself with the different BDB-specific startup options.  *Note BDB
  7825. start::.
  7826.  
  7827. Starting and Stopping MySQL Automatically
  7828. -----------------------------------------
  7829.  
  7830. The `mysql.server' and `mysqld_safe' scripts can be used to start the
  7831. server automatically at system startup time. `mysql.server' can also be
  7832. used to stop the server.
  7833.  
  7834. The `mysql.server' script can be used to start or stop the server by
  7835. invoking it with `start' or `stop' arguments:
  7836.  
  7837.      shell> mysql.server start
  7838.      shell> mysql.server stop
  7839.  
  7840. `mysql.server' can be found in the `share/mysql' directory under the
  7841. MySQL installation directory or in the `support-files' directory of the
  7842. MySQL source tree.
  7843.  
  7844. Note that if you use the Linux RPM package
  7845. (`MySQL-server-VERSION.rpm'), the `mysql.server' script has already
  7846. been installed as `/etc/init.d/mysql' - you don't have to install it
  7847. manually. See *Note Linux-RPM:: for more information on the Linux RPM
  7848. packages.
  7849.  
  7850. On Mac OS X, you can install a separate MySQL Startup Item package to
  7851. enable the automatic startup of MySQL on system bootup.  See *Note Mac
  7852. OS X installation:: for details.
  7853.  
  7854. Before `mysql.server' starts the server, it changes the directory to
  7855. the MySQL installation directory, then invokes `mysqld_safe'.  You
  7856. might need to edit `mysql.server' if you have a binary distribution
  7857. that you've installed in a non-standard location.  Modify it to `cd'
  7858. into the proper directory before it runs `mysqld_safe'. If you want the
  7859. server to run as some specific user, add an appropriate `user' line to
  7860. the `/etc/my.cnf' file, as shown later in this section.
  7861.  
  7862. `mysql.server stop' brings down the server by sending a signal to it.
  7863. You can also take down the server manually by executing `mysqladmin
  7864. shutdown'.
  7865.  
  7866. You need to add these start and stop commands to the appropriate places
  7867. in your `/etc/rc*' files when you want to start up MySQL automatically
  7868. on your server.
  7869.  
  7870. On most current Linux distributions, it is sufficient to copy the file
  7871. `mysql.server' into the `/etc/init.d' directory (or `/etc/rc.d/init.d'
  7872. on older Red Hat systems). Afterwards, run the following command to
  7873. enable the startup of MySQL on system bootup:
  7874.  
  7875.      shell> chkconfig --add mysql.server
  7876.  
  7877. On FreeBSD startup scripts generally should go in
  7878. `/usr/local/etc/rc.d/'. The `rc(8)' manual page also states that
  7879. scripts in this directory are only executed, if their basename matches
  7880. the shell globbing pattern `*.sh'. Any other files or directories
  7881. present within the directory are silently ignored. In other words, on
  7882. FreeBSD you should install the file `mysql.server' as
  7883. `/usr/local/etc/rc.d/mysql.server.sh' to enable automatic startup.
  7884.  
  7885. As an alternative to the above, some operating systems also use
  7886. `/etc/rc.local' or `/etc/init.d/boot.local' to start additional
  7887. services on bootup. To start up MySQL using this method, you could
  7888. append something like the following to it:
  7889.  
  7890.      /bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
  7891.  
  7892. You can also add options for `mysql.server' in a global `/etc/my.cnf'
  7893. file.  A typical `/etc/my.cnf' file might look like this:
  7894.  
  7895.      [mysqld]
  7896.      datadir=/usr/local/mysql/var
  7897.      socket=/var/tmp/mysql.sock
  7898.      port=3306
  7899.      user=mysql
  7900.      
  7901.      [mysql.server]
  7902.      basedir=/usr/local/mysql
  7903.  
  7904. The `mysql.server' script understands the following options: `datadir',
  7905. `basedir', and `pid-file'.
  7906.  
  7907. The following table shows which option groups each startup script reads
  7908. from option files:
  7909.  
  7910. *Script*    *Option groups*
  7911. `mysqld'    `[mysqld]' and `[server]'
  7912. `mysql.server'`[mysql.server]', `[mysqld]', and `[server]'
  7913. `mysqld_safe'`[mysqld]', `[server]', and `[mysqld_safe]'
  7914.  
  7915. For backward compatibility, `mysql.server' also reads the
  7916. `[mysql_server]' group and `mysqld_safe' also reads the `[safe_mysqld]'
  7917. group. However, you should update your option files to use the
  7918. `[mysql.server]' and `[mysqld_safe]' groups instead.
  7919.  
  7920. *Note Option files::.
  7921.  
  7922. Upgrading/Downgrading MySQL
  7923. ===========================
  7924.  
  7925. Before you do an upgrade, you should back up your old databases.
  7926.  
  7927. You can always move the MySQL format files and datafiles between
  7928. different versions on the same architecture as long as you have the
  7929. same base version of MySQL. The current base version is 4. If you
  7930. change the character set when running MySQL, you must run `myisamchk -r
  7931. -q --set-character-set=charset' on all tables.  Otherwise, your indexes
  7932. may not be ordered correctly, because changing the character set may
  7933. also change the sort order.
  7934.  
  7935. If you are afraid of new versions, you can always rename your old
  7936. `mysqld' to something like `mysqld-old-version-number'.  If your new
  7937. `mysqld' then does something unexpected, you can simply shut it down
  7938. and restart with your old `mysqld'.
  7939.  
  7940. If, after an upgrade, you experience problems with recompiled client
  7941. programs, such as `Commands out of sync' or unexpected core dumps, you
  7942. probably have used an old header or library file when compiling your
  7943. programs.  In this case you should check the date for your `mysql.h'
  7944. file and `libmysqlclient.a' library to verify that they are from the new
  7945. MySQL distribution.  If not, please recompile your programs.
  7946.  
  7947. If problems occur, such as that the new `mysqld' server doesn't want to
  7948. start or that you can't connect without a password, check that you don't
  7949. have some old `my.cnf' file from your old installation.  You can check
  7950. this with: `program-name --print-defaults'.  If this outputs anything
  7951. other than the program name, you have an active `my.cnf' file that will
  7952. affect things.
  7953.  
  7954. It is a good idea to rebuild and reinstall the Perl `DBD-mysql' module
  7955. whenever you install a new release of MySQL. The same applies to other
  7956. MySQL interfaces as well, such as the Python `MySQLdb' module.
  7957.  
  7958. Upgrading From Version 4.0 to 4.1
  7959. ---------------------------------
  7960.  
  7961. Several visible things have changed between MySQL 4.0 and MySQL 4.1 to
  7962. fix some critical bugs and make MySQL more compatible with the ANSI SQL
  7963. standard. These changes may affect your applications.
  7964.  
  7965. Some of the 4.1 behaviours can be tested in 4.0 before performing a
  7966. full upgrade to 4.1. We have added to later MySQL 4.0 releases (from
  7967. 4.0.12 on) a `--new' startup option for `mysqld'.  This option gives
  7968. you the 4.1 behaviour for the most critical changes.  You can also
  7969. enable these behaviours for a given client connection with the `SET
  7970. @@new=1' command, or turn them off if they are on with `SET @@new=0'.
  7971.  
  7972. If you believe that some of the 4.1 changes will affect you, we
  7973. recommend that before upgrading to 4.1, you download the latest MySQL
  7974. 4.0 version and run it with the `--new' option.  That way you can test
  7975. the new behaviors in 4.0 to make sure that your applications work with
  7976. them. This will help you have a smooth painless transition when you
  7977. perform a full upgrade to 4.1 later.
  7978.  
  7979. The following list describes changes that may affect applications and
  7980. that you should watch out for when upgrading to version 4.1:
  7981.  
  7982.    * `TIMESTAMP' is now returned as a string in `'YYYY-MM-DD HH:MM:SS''
  7983.      format.  (The `--new' option can be used from 4.0.12 on to make a
  7984.      4.0 server behave as 4.1 in this respect.)  If you want to have
  7985.      the value returned as a number (like Version 4.0 does) you should
  7986.      add +0 to `TIMESTAMP' columns when you retrieve them:
  7987.  
  7988.           mysql> SELECT ts_col + 0 FROM tbl_name;
  7989.  
  7990.      Display widths for `TIMESTAMP' columns are no longer supported.
  7991.      For example, if you declare a column as `TIMESTAMP(10)', the `(10)'
  7992.      is ignored.
  7993.  
  7994.      These changes were necessary for SQL standards compliance. In a
  7995.      future version, a further change will be made (backward compatible
  7996.      with this change), allowing the timestamp length to indicate the
  7997.      desired number of digits for fractions of a second.
  7998.  
  7999.    * Binary values such as `0xFFDF' now are assumed to be strings
  8000.      instead of numbers.  This fixes some problems with character sets
  8001.      where it's convenient to input a string as a binary value.  With
  8002.      this change, you should use `CAST()' if you want to compare binary
  8003.      values numerically as integers:
  8004.  
  8005.           mysql> SELECT CAST(0xFEFF AS UNSIGNED INTEGER) < CAST(0xFF AS UNSIGNED INTEGER);
  8006.                   -> 0
  8007.  
  8008.      If you don't use `CAST()', a lexical string comparison will be
  8009.      done:
  8010.  
  8011.           mysql> SELECT 0xFEFF < 0xFF;
  8012.                   -> 1
  8013.  
  8014.      Using binary items in a numeric context or comparing them using the
  8015.      `=' operator should work as before.  (The `--new' option can be
  8016.      used from 4.0.13 on to make a 4.0 server behave as 4.1 in this
  8017.      respect.)
  8018.  
  8019.    * For functions that produce a `DATE', `DATETIME', or `TIME' value,
  8020.      the result returned to the client now is fixed up to have a
  8021.      temporal type. For example, in MySQL 4.1, you get this result:
  8022.  
  8023.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  8024.               -> '2001-01-01 00:00:00'
  8025.  
  8026.      In MySQL 4.0, the result is different:
  8027.  
  8028.           mysql> SELECT CAST("2001-1-1" as DATETIME);
  8029.               -> '2001-01-01'
  8030.  
  8031.    * `DEFAULT' values no longer can be specified for `AUTO_INCREMENT'
  8032.      columns. (In 4.0, a `DEFAULT' value is silently ignored; in 4.1,
  8033.      an error occurs).
  8034.  
  8035.    * `SERIALIZE' is no longer a valid option value for the `sql_mode'
  8036.      variable.  You should use `SET TRANSACTION ISOLATION LEVEL
  8037.      SERIALIZABLE' instead. `SERIALIZE' is no longer valid for the
  8038.      `--sql-mode' option for `mysqld', either. Use
  8039.      `--transaction-isolation=SERIALIZABLE' instead.
  8040.  
  8041.    * All tables and string columns now have a character set.  *Note
  8042.      Charset::.  Character set information is displayed by `SHOW CREATE
  8043.      TABLE' and `mysqldump'.  (MySQL versions 4.0.6 and above can read
  8044.      the new dump files; older versions cannot.)
  8045.  
  8046.    * The table definition format used in `.frm' files has changed
  8047.      slightly in 4.1.  MySQL 4.0 versions from 4.0.11 on can read the
  8048.      new `.frm' format directly, but older versions cannot.  If you
  8049.      need to move tables from 4.1 to a version earlier than 4.0.11, you
  8050.      should use `mysqldump'.  *Note `mysqldump': mysqldump.
  8051.  
  8052.    * If you are running multiple servers on the same Windows machine,
  8053.      you should use a different `--shared_memory_base_name' option on
  8054.      all machines.
  8055.  
  8056.    * The interface to aggregated UDF functions has changed a bit. You
  8057.      must now declare a `clear()' function for each aggregate function.
  8058.  
  8059.  
  8060. In general, upgrading to 4.1 from an earlier MySQL version involves the
  8061. following steps:
  8062.  
  8063.    * Check the changes listed earlier in this section to see if there
  8064.      are any that may affect your applications.
  8065.  
  8066.    * Read the 4.1 news items to see what significant new features you
  8067.      can use in 4.1.  *Note News-4.1.x::.
  8068.  
  8069.    * If you are running MySQL Server on Windows, please also see *Note
  8070.      Windows upgrading::.
  8071.  
  8072.    * After upgrading, update the grant tables to generate the new
  8073.      longer `Password' column that is needed for secure handling of
  8074.      passwords.  The procedure uses `mysql_fix_privilege_tables' and is
  8075.      described in *Note Upgrading-grant-tables::.
  8076.  
  8077.  
  8078. The password hashing mechanism has changed in 4.1 to provide better
  8079. security, but this may cause compatibility problems if you still have
  8080. clients that use the client library from 4.0 or earlier.  (It is very
  8081. likely that you will have 4.0 clients in situations where clients
  8082. connect from remote hosts that have not yet upgraded to 4.1).  The
  8083. following list indicates some possible upgrade strategies.  They
  8084. represent various tradeoffs between the goal of compatibility with old
  8085. clients and the goal of security.
  8086.  
  8087.    * Don't upgrade to 4.1. No behaviour will change, but of course you
  8088.      cannot use any of the new features provided by the 4.1
  8089.      client/server protocol, either.  (MySQL 4.1 has an extended
  8090.      client/server protocol that offers such features as prepared
  8091.      statements and multiple result sets.)  *Note C API Prepared
  8092.      statements::.
  8093.  
  8094.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  8095.      widen the `Password' column in the `user' table so that it can
  8096.      hold long password hashes.  But run the server with the
  8097.      `--old-passwords' option to provide backward compatibility that
  8098.      allows pre-4.1 clients to continue to connect to their short-hash
  8099.      accounts.  Eventually, when all your clients are upgraded to 4.1,
  8100.      you can stop using the `--old-passwords' server option. You can
  8101.      also change the passwords for your MySQL accounts to use the new
  8102.      more secure format.
  8103.  
  8104.    * Upgrade to 4.1 and run the `mysql_fix_privilege_tables' script to
  8105.      widen the `Password' column in the `user' table.  If you know that
  8106.      all clients also have been upgraded to 4.1, don't run the server
  8107.      with the `--old-passwords' option.  Instead, change the passwords
  8108.      on all existing accounts so that they have the new format.  A
  8109.      pure-4.1 installation is the most secure.
  8110.  
  8111.  
  8112. Further background on password hashing with respect to client
  8113. authentication and password-changing operations may be found in *Note
  8114. Password hashing::.
  8115.  
  8116. Upgrading From Version 3.23 to 4.0
  8117. ----------------------------------
  8118.  
  8119. In general, you should do the following when upgrading to 4.0 from an
  8120. earlier MySQL version:
  8121.  
  8122.    * After upgrading, update the grant tables to add new privileges and
  8123.      features.  The procedure uses the `mysql_fix_privilege_tables'
  8124.      script and is described in *Note Upgrading-grant-tables::.
  8125.  
  8126.    * Edit any MySQL startup scripts or configure files to not use any
  8127.      of the deprecated options described later in this section.
  8128.  
  8129.    * Convert your old `ISAM' files to `MyISAM' files with the
  8130.      `mysql_convert_table_format database' script. (This is a Perl
  8131.      script; it requires that DBI be installed.) To convert the tables
  8132.      in a given database, use this command:
  8133.  
  8134.           shell> mysql_convert_table_format database db_name
  8135.  
  8136.      Note that this should only be used if all tables in the given
  8137.      database are `ISAM' or `MyISAM' tables. To avoid converting tables
  8138.      of other types to `MyISAM', you can explicitly list the names of
  8139.      your `ISAM' tables after the database name on the command line.
  8140.      You can also issue a `ALTER TABLE table_name TYPE=MyISAM'
  8141.      statement for each `ISAM' table to convert it to `MyISAM'.
  8142.  
  8143.      To find out the table type for a given table, use this statement:
  8144.  
  8145.           mysql> SHOW TABLE STATUS LIKE 'tbl_name';
  8146.  
  8147.    * Ensure that you don't have any MySQL clients that use shared
  8148.      libraries (like the Perl `DBD-mysql' mode). If you do, you should
  8149.      recompile them, because the data structures used in
  8150.      `libmysqlclient.so' have changed.  The same applies to other MySQL
  8151.      interfaces as well, such as the Python `MySQLdb' module.
  8152.  
  8153.  
  8154. MySQL 4.0 will work even if you don't do the above, but you will not be
  8155. able to use the new security privileges that MySQL 4.0 and you may run
  8156. into problems when upgrading later to MySQL 4.1 or newer.  The `ISAM'
  8157. file format still works in MySQL 4.0 but it's deprecated and will be
  8158. disabled (not compiled in by default) in MySQL 4.1. `MyISAM' tables
  8159. should be used instead.
  8160.  
  8161. Old clients should work with a Version 4.0 server without any problems.
  8162.  
  8163. Even if you do the above, you can still downgrade to MySQL 3.23.52 or
  8164. newer if you run into problems with the MySQL 4.0 series.  In this
  8165. case, you must use `mysqldump' to dump any tables that use full-text
  8166. indexes and reload the dump file into the 3.23 server.  This is
  8167. necessary because 4.0 uses a new format for full-text indexing.
  8168.  
  8169. The following is a more complete list that tells what you must watch out
  8170. for when upgrading to version 4.0:
  8171.  
  8172.    * MySQL 4.0 has a lot of new privileges in the `mysql.user' table.
  8173.      *Note `GRANT': GRANT.
  8174.  
  8175.      To get these new privileges to work, you must update the grant
  8176.      tables.  The procedure is described in *Note
  8177.      Upgrading-grant-tables::.  Until you do this, all users have the
  8178.      `SHOW DATABASES', `CREATE TEMPORARY TABLES', and `LOCK TABLES'
  8179.      privileges. `SUPER' and `EXECUTE' privileges take their value from
  8180.      `PROCESS'.  `REPLICATION SLAVE' and `REPLICATION CLIENT' take their
  8181.      values from `FILE'.
  8182.  
  8183.      If you have any scripts that create new users, you may want to
  8184.      change them to use the new privileges.  If you are not using
  8185.      `GRANT' commands in the scripts, this is a good time to change
  8186.      your scripts to use `GRANT' instead of modifying the grant tables
  8187.      directly..
  8188.  
  8189.      From version 4.0.2 on, the option `--safe-show-database' is
  8190.      deprecated (and no longer does anything). *Note Privileges
  8191.      options::.
  8192.  
  8193.      If you get `Access denied' errors for new users in version 4.0.2
  8194.      and up, you should check if you need some of the new grants that
  8195.      you didn't need before.  In particular, you will need `REPLICATION
  8196.      SLAVE' (instead of `FILE') for new slaves.
  8197.  
  8198.    * `safe_mysqld' is renamed to `mysqld_safe'.  For backward
  8199.      compatibility, binary distributions will for some time include
  8200.      `safe_mysqld' as a symlink to `mysqld_safe'.
  8201.  
  8202.    * InnoDB support is now included by default in binary distributions.
  8203.      If you build MySQL from source, InnoDB is configured in by default.
  8204.      If you do not use InnoDB and want to save memory when running a
  8205.      server that has InnoDB support enabled, use the `--skip-innodb'
  8206.      server startop option. To compile MySQL without InnoDB support,
  8207.      run `configure' with the `--without-innodb' option.
  8208.  
  8209.    * The startup parameters `myisam_max_extra_sort_file_size' and
  8210.      `myisam_max_extra_sort_file_size' are now given in bytes (they
  8211.      were given in megabytes before 4.0.3).
  8212.  
  8213.    * External system locking of `MyISAM'/`ISAM' files is now turned off
  8214.      by default.  Your can turn this on by doing `--external-locking'.
  8215.      (However, this is never needed for most users.)
  8216.  
  8217.    * The following startup variables/options have been renamed:
  8218.  
  8219.      *Old Name*                         *New Name*
  8220.      `myisam_bulk_insert_tree_size'     `bulk_insert_buffer_size'
  8221.      `query_cache_startup_type'         `query_cache_type'
  8222.      `record_buffer'                    `read_buffer_size'
  8223.      `record_rnd_buffer'                `read_rnd_buffer_size'
  8224.      `sort_buffer'                      `sort_buffer_size'
  8225.      `warnings'                         `log-warnings'
  8226.      `--err-log'                        `--log-error' (for `mysqld_safe')
  8227.  
  8228.      The startup options `record_buffer', `sort_buffer' and `warnings'
  8229.      will still work in MySQL 4.0 but are deprecated.
  8230.  
  8231.    * The following SQL variables have changed name.
  8232.  
  8233.      *Old Name*                         *New Name*
  8234.      `SQL_BIG_TABLES'                   `BIG_TABLES'
  8235.      `SQL_LOW_PRIORITY_UPDATES'         `LOW_PRIORITY_UPDATES'
  8236.      `SQL_MAX_JOIN_SIZE'                `MAX_JOIN_SIZE'
  8237.      `SQL_QUERY_CACHE_TYPE'             `QUERY_CACHE_TYPE'
  8238.      The old names still work in MySQL 4.0 but are deprecated.
  8239.  
  8240.    * You have to use `SET GLOBAL SQL_SLAVE_SKIP_COUNTER=#' instead of
  8241.      `SET SQL_SLAVE_SKIP_COUNTER=#'.
  8242.  
  8243.    * The `mysqld' startup options `--skip-locking' and
  8244.      `--enable-locking' were renamed to `--skip-external-locking' and
  8245.      `--external-locking'.
  8246.  
  8247.    * `SHOW MASTER STATUS' now returns an empty set if binary logging is
  8248.      not enabled.
  8249.  
  8250.    * `SHOW SLAVE STATUS' now returns an empty set if slave is not
  8251.      initialised.
  8252.  
  8253.    * `mysqld' now has the option `--temp-pool' enabled by default as
  8254.      this gives better performance with some operating systems (most
  8255.      notably Linux).
  8256.  
  8257.    * `DOUBLE' and `FLOAT' columns now honour the `UNSIGNED' flag on
  8258.      storage (before, `UNSIGNED' was ignored for these columns).
  8259.  
  8260.    * `ORDER BY col_name DESC' sorts `NULL' values last, as of MySQL
  8261.      4.0.11. In 3.23 and in earlier 4.0 versions, this was not always
  8262.      consistent.
  8263.  
  8264.    * `SHOW INDEX' has two more columns (`Null' and `Index_type') than
  8265.      it had in 3.23.
  8266.  
  8267.    * `CHECK', `SIGNED', `LOCALTIME' and `LOCALTIMESTAMP' are now
  8268.      reserved words.
  8269.  
  8270.    * The result of all bitwise operators (`|', `&', `<<', `>>', and
  8271.      `~')) is now unsigned.  This may cause problems if you are using
  8272.      them in a context where you want a signed result.  *Note Cast
  8273.      Functions::.
  8274.  
  8275.    * *Note*: when you use subtraction between integer values where one
  8276.      is of type `UNSIGNED', the result will be unsigned.  In other
  8277.      words, before upgrading to MySQL 4.0, you should check your
  8278.      application for cases where you are subtracting a value from an
  8279.      unsigned entity and want a negative answer or subtracting an
  8280.      unsigned value from an integer column. You can disable this
  8281.      behaviour by using the `--sql-mode=NO_UNSIGNED_SUBTRACTION' option
  8282.      when starting `mysqld'.  *Note Cast Functions::.
  8283.  
  8284.    * To use `MATCH ... AGAINST (... IN BOOLEAN MODE)' with your tables,
  8285.      you need to rebuild them with `REPAIR TABLE table_name USE_FRM'.
  8286.  
  8287.    * `LOCATE()' and `INSTR()' are case-sensitive if one of the
  8288.      arguments is a binary string. Otherwise they are case-insensitive.
  8289.  
  8290.    * `STRCMP()' now uses the current character set when doing
  8291.      comparisons, which means that the default comparison behaviour now
  8292.      is case-insensitive.
  8293.  
  8294.    * `HEX(string)' now returns the characters in `string' converted to
  8295.      hexadecimal.  If you want to convert a number to hexadecimal, you
  8296.      should ensure that you call `HEX()' with a numeric argument.
  8297.  
  8298.    * In 3.23, `INSERT INTO ... SELECT' always had `IGNORE' enabled.  In
  8299.      4.0.1, MySQL will stop (and possibly roll back) by default in case
  8300.      of an error unless you specify `IGNORE'.
  8301.  
  8302.    * The old C API functions `mysql_drop_db()', `mysql_create_db()', and
  8303.      `mysql_connect()' are no longer supported unless you compile MySQL
  8304.      with `CFLAGS=-DUSE_OLD_FUNCTIONS'.  However, it is preferable to
  8305.      change client programs to use the new 4.0 API instead.
  8306.  
  8307.    * In the `MYSQL_FIELD' structure, `length' and `max_length' have
  8308.      changed from `unsigned int' to `unsigned long'. This should not
  8309.      cause any problems, except that they may generate warning messages
  8310.      when used as arguments in the `printf()' class of functions.
  8311.  
  8312.    * You should use `TRUNCATE TABLE' when you want to delete all rows
  8313.      from a table and you don't need to obtain a count of the number of
  8314.      rows that were deleted.  (`DELETE FROM table_name' returns a row
  8315.      count in 4.0, and `TRUNCATE TABLE' is faster.)
  8316.  
  8317.    * You will get an error if you have an active `LOCK TABLES' or
  8318.      transaction when trying to execute `TRUNCATE TABLE' or `DROP
  8319.      DATABASE'.
  8320.  
  8321.    * You should use integers to store values in `BIGINT' columns
  8322.      (instead of using strings, as you did in MySQL 3.23).  Using
  8323.      strings will still work, but using integers is more efficient.
  8324.  
  8325.    * The format of `SHOW OPEN TABLES' has changed.
  8326.  
  8327.    * Multi-threaded clients should use `mysql_thread_init()' and
  8328.      `mysql_thread_end()'. *Note Threaded clients::.
  8329.  
  8330.    * If you want to recompile the Perl `DBD::mysql' module, you must get
  8331.      `DBD-mysql' version 1.2218 or newer because older DBD modules used
  8332.      the deprecated `mysql_drop_db()' call.  Version 2.1022 or newer is
  8333.      recommended.
  8334.  
  8335.    * `RAND(seed)' returns a different random number series in 4.0 than
  8336.      in 3.23; this was done to further differentiate `RAND(seed)' and
  8337.      `RAND(seed+1)'.
  8338.  
  8339.    * The default type returned by `IFNULL(A,B)' is now set to be the
  8340.      more 'general' of the types of `A' and `B'. (The
  8341.      general-to-specific order is string, `REAL' or `INTEGER').
  8342.  
  8343.  
  8344. If you are running MySQL Server on Windows, please also see *Note
  8345. Windows upgrading::. If you are using replication, please also see
  8346. *Note Replication Implementation::.
  8347.  
  8348. Upgrading From Version 3.22 to 3.23
  8349. -----------------------------------
  8350.  
  8351. MySQL Version 3.23 supports tables of the new `MyISAM' type and the old
  8352. `ISAM' type.  You don't have to convert your old tables to use these
  8353. with Version 3.23.  By default, all new tables will be created with
  8354. type `MyISAM' (unless you start `mysqld' with the
  8355. `--default-table-type=isam' option). You can convert an `ISAM' table to
  8356. `MyISAM' format with `ALTER TABLE table_name TYPE=MyISAM' or the Perl
  8357. script `mysql_convert_table_format'.
  8358.  
  8359. Version 3.22 and 3.21 clients will work without any problems with a
  8360. Version 3.23 server.
  8361.  
  8362. The following list tells what you have to watch out for when upgrading
  8363. to Version 3.23:
  8364.  
  8365.    * All tables that use the `tis620' character set must be fixed with
  8366.      `myisamchk -r' or `REPAIR TABLE'.
  8367.  
  8368.    * If you do a `DROP DATABASE' on a symbolically-linked database,
  8369.      both the link and the original database are deleted.  (This didn't
  8370.      happen in 3.22 because `configure' didn't detect the availability
  8371.      of the `readlink()' system call.)
  8372.  
  8373.    * `OPTIMIZE TABLE' now works only for `MyISAM' tables.  For other
  8374.      table types, you can use `ALTER TABLE' to optimise the table.
  8375.      During `OPTIMIZE TABLE', the table is now locked to prevent it
  8376.      from being used by other threads.
  8377.  
  8378.    * The MySQL client `mysql' is now by default started with the option
  8379.      `--no-named-commands (-g)'. This option can be disabled with
  8380.      `--enable-named-commands (-G)'. This may cause incompatibility
  8381.      problems in some cases--for example, in SQL scripts that use named
  8382.      commands without a semicolon.  Long format commands still work
  8383.      from the first line.
  8384.  
  8385.    * Date functions that work on parts of dates (like `MONTH()') will
  8386.      now return 0 for `0000-00-00' dates. (In MySQL 3.22, these
  8387.      functions returned `NULL'.)
  8388.  
  8389.    * If you are using the `german' character sort order for `ISAM'
  8390.      tables, you must repair them with `isamchk -r', because we have
  8391.      made some changes in the sort order.
  8392.  
  8393.    * The default return type of `IF()' now depends on both arguments
  8394.      and not only the first argument.
  8395.  
  8396.    * `AUTO_INCREMENT' columns should not be used to store negative
  8397.      numbers. The reason for this is that negative numbers caused
  8398.      problems when wrapping from -1 to 0.  You should not store 0 in
  8399.      `AUTO_INCREMENT' columns, either; `CHECK TABLE' will complain
  8400.      about 0 values because they may change if you dump and restore the
  8401.      table.  `AUTO_INCREMENT' for `MyISAM' tables is now handled at a
  8402.      lower level and is much faster than before. In addition, for
  8403.      `MyISAM' tables, old numbers are no longer reused, even if you
  8404.      delete rows from the table.
  8405.  
  8406.    * `CASE', `DELAYED', `ELSE', `END', `FULLTEXT', `INNER', `RIGHT',
  8407.      `THEN', and `WHEN' are now reserved words.
  8408.  
  8409.    * `FLOAT(X)' is now a true floating-point type and not a value with a
  8410.      fixed number of decimals.
  8411.  
  8412.    * When declaring columns using a `DECIMAL(length,dec)' type, the
  8413.      `length' argument no longer includes a place for the sign or the
  8414.      decimal point.
  8415.  
  8416.    * A `TIME' string must now be of one of the following formats:
  8417.      `[[[DAYS] [H]H:]MM:]SS[.fraction]' or
  8418.      `[[[[[H]H]H]H]MM]SS[.fraction]'.
  8419.  
  8420.    * `LIKE' now compares strings using the same character comparison
  8421.      rules as for the `=' operator.  If you require the old behaviour,
  8422.      you can compile MySQL with the `CXXFLAGS=-DLIKE_CMP_TOUPPER' flag.
  8423.  
  8424.    * `REGEXP' is now case-insensitive if neither of the strings are
  8425.      binary strings.
  8426.  
  8427.    * When you check or repair `MyISAM' (`.MYI') tables, you should use
  8428.      the `CHECK TABLE' statement or the `myisamchk' command. For `ISAM'
  8429.      (`.ISM') tables, use the `isamchk' command.
  8430.  
  8431.    * If you want your `mysqldump' files to be compatible between MySQL
  8432.      Version 3.22 and Version 3.23, you should not use the `--opt' or
  8433.      `--all' option to `mysqldump'.
  8434.  
  8435.    * Check all your calls to `DATE_FORMAT()' to make sure there is a
  8436.      `%' before each format character.  (MySQL Version 3.22 and later
  8437.      already allowed this syntax.)
  8438.  
  8439.    * `mysql_fetch_fields_direct()' is now a function (it used to be a
  8440.      macro) and it returns a pointer to a `MYSQL_FIELD' instead of a
  8441.      `MYSQL_FIELD'.
  8442.  
  8443.    * `mysql_num_fields()' can no longer be used on a `MYSQL*' object
  8444.      (it's now a function that takes a `MYSQL_RES*' value as an
  8445.      argument). With a `MYSQL*' object, you should now use
  8446.      `mysql_field_count()' instead.
  8447.  
  8448.    * In MySQL Version 3.22, the output of `SELECT DISTINCT ...' was
  8449.      almost always sorted.  In Version 3.23, you must use `GROUP BY' or
  8450.      `ORDER BY' to obtain sorted output.
  8451.  
  8452.    * `SUM()' now returns `NULL' instead of 0 if there are no matching
  8453.      rows. This is required by SQL-99.
  8454.  
  8455.    * An `AND' or `OR' with `NULL' values will now return `NULL' instead
  8456.      of 0. This mostly affects queries that use `NOT' on an `AND/OR'
  8457.      expression as `NOT NULL' = `NULL'.
  8458.  
  8459.    * `LPAD()' and `RPAD()' now shorten the result string if it's longer
  8460.      than the length argument.
  8461.  
  8462. Upgrading from Version 3.21 to 3.22
  8463. -----------------------------------
  8464.  
  8465. Nothing that affects compatibility has changed between versions 3.21
  8466. and 3.22.  The only pitfall is that new tables that are created with
  8467. `DATE' type columns will use the new way to store the date. You can't
  8468. access these new columns from an old version of `mysqld'.
  8469.  
  8470. After installing MySQL Version 3.22, you should start the new server
  8471. and then run the `mysql_fix_privilege_tables' script. This will add the
  8472. new privileges that you need to use the `GRANT' command.  If you forget
  8473. this, you will get `Access denied' when you try to use `ALTER TABLE',
  8474. `CREATE INDEX', or `DROP INDEX'. The procedure for updating the grant
  8475. tables is described in *Note Upgrading-grant-tables::.
  8476.  
  8477. The C API interface to `mysql_real_connect()' has changed.  If you have
  8478. an old client program that calls this function, you must place a `0' for
  8479. the new `db' argument (or recode the client to send the `db' element
  8480. for faster connections).  You must also call `mysql_init()' before
  8481. calling `mysql_real_connect()'.  This change was done to allow the new
  8482. `mysql_options()' function to save options in the `MYSQL' handler
  8483. structure.
  8484.  
  8485. The `mysqld' variable `key_buffer' has been renamed to
  8486. `key_buffer_size', but you can still use the old name in your startup
  8487. files.
  8488.  
  8489. Upgrading from Version 3.20 to 3.21
  8490. -----------------------------------
  8491.  
  8492. If you are running a version older than Version 3.20.28 and want to
  8493. switch to Version 3.21, you need to do the following:
  8494.  
  8495. You can start the `mysqld' Version 3.21 server with the
  8496. `--old-protocol' option to use it with clients from a Version 3.20
  8497. distribution.  In this case, the new client function `mysql_errno()'
  8498. will not return any server error, only `CR_UNKNOWN_ERROR' (but it works
  8499. for client errors), and the server uses the old pre-3.21 `password()'
  8500. checking rather than the new method.
  8501.  
  8502. If you are *not* using the `--old-protocol' option to `mysqld', you
  8503. will need to make the following changes:
  8504.  
  8505.    * All client code must be recompiled. If you are using ODBC, you
  8506.      must get the new `MyODBC' 2.x driver.
  8507.  
  8508.    * The script `scripts/add_long_password' must be run to convert the
  8509.      `Password' field in the `mysql.user' table to `CHAR(16)'.
  8510.  
  8511.    * All passwords must be reassigned in the `mysql.user' table (to get
  8512.      62-bit rather than 31-bit passwords).
  8513.  
  8514.    * The table format hasn't changed, so you don't have to convert any
  8515.      tables.
  8516.  
  8517.  
  8518. MySQL Version 3.20.28 and above can handle the new `user' table format
  8519. without affecting clients. If you have a MySQL version earlier than
  8520. Version 3.20.28, passwords will no longer work with it if you convert
  8521. the `user' table. So to be safe, you should first upgrade to at least
  8522. Version 3.20.28 and then upgrade to Version 3.21.
  8523.  
  8524. The new client code works with a 3.20.x `mysqld' server, so if you
  8525. experience problems with 3.21.x, you can use the old 3.20.x server
  8526. without having to recompile the clients again.
  8527.  
  8528. If you are not using the `--old-protocol' option to `mysqld', old
  8529. clients will be unable to connect and will issue the following error
  8530. message:
  8531.  
  8532.      ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
  8533.  
  8534. The new Perl `DBI'/`DBD' interface also supports the old `mysqlperl'
  8535. interface.  The only change you have to make if you use `mysqlperl' is
  8536. to change the arguments to the `connect()' function.  The new arguments
  8537. are: `host', `database', `user', and `password' (note that the `user'
  8538. and `password' arguments have changed places).  *Note Perl `DBI' Class:
  8539. Perl DBI Class.
  8540.  
  8541. The following changes may affect queries in old applications:
  8542.  
  8543.    * `HAVING' must now be specified before any `ORDER BY' clause.
  8544.  
  8545.    * The parameters to `LOCATE()' have been swapped.
  8546.  
  8547.    * There are some new reserved words. The most notable are `DATE',
  8548.      `TIME', and `TIMESTAMP'.
  8549.  
  8550.  
  8551. Upgrading the Grant Tables
  8552. --------------------------
  8553.  
  8554. Some releases introduce changes to the structure of the grant tables
  8555. (the tables in the `mysql' database) to add new  privileges or
  8556. features. To make sure that your grant tables are current when you
  8557. update to a new version of MySQL, you should update your grant tables
  8558. as well.
  8559.  
  8560. On Unix or Unix-like systems, update the grant tables by running the
  8561. `mysql_fix_privilege_tables' script:
  8562.  
  8563.      shell> mysql_fix_privilege_tables
  8564.  
  8565. You must run this script while the server is running. It attempts to
  8566. connect to the server running on the local host as `root'.  If your
  8567. `root' account requires a password, indicate the password on the
  8568. command line.  For MySQL 4.1 and up, specify the password like this:
  8569.  
  8570.      shell> mysql_fix_privilege_tables --password=root_password
  8571.  
  8572. Prior to MySQL 4.1, specify the password like this:
  8573.  
  8574.      shell> mysql_fix_privilege_tables root_password
  8575.  
  8576. The `mysql_fix_privilege_tables' script performs any actions necessary
  8577. to convert your grant tables to the current format. You may see some
  8578. `Duplicate column name' warnings as it runs; they can be ignored.
  8579.  
  8580. After running the script, stop the server and restart it.
  8581.  
  8582. On Windows systems, there isn't an easy way to update the grant tables
  8583. until MySQL 4.0.15.  From version 4.0.15 on, MySQL distributions
  8584. include a `mysql_fix_privilege_tables.sql' SQL script that you can run
  8585. using the `mysql' client.  If your MySQL installation is located at
  8586. `C:\mysql', the command looks like this (enter it all on one line):
  8587.  
  8588.      shell> C:\mysql\bin\mysql -f -u root -p mysql
  8589.                 < C:\mysql\scripts\mysql_fix_privilege_tables.sql
  8590.  
  8591. If your installation is located in some other directory, adjust the
  8592. pathnames appropriately.
  8593.  
  8594. The command will prompt you for the `root' password; enter it when
  8595. prompted.
  8596.  
  8597. As with the Unix procedure, you may see some `Duplicate column name'
  8598. warnings as `mysql' processes the statements in the
  8599. `mysql_fix_privilege_tables.sql' script; they can be ignored.
  8600.  
  8601. After running the script, stop the server and restart it.
  8602.  
  8603. Upgrading to Another Architecture
  8604. ---------------------------------
  8605.  
  8606. If you are using MySQL Version 3.23, you can copy the `.frm', `.MYI',
  8607. and `.MYD' files for `MyISAM' tables between different architectures
  8608. that support the same floating-point format.  (MySQL takes care of any
  8609. byte-swapping issues.)  *Note `MyISAM' Tables: MyISAM.
  8610.  
  8611. The MySQL `ISAM' data and index files (`.ISD' and `*.ISM',
  8612. respectively) are architecture-dependent and in some cases
  8613. OS-dependent.  If you want to move your applications to another machine
  8614. that has a different architecture or OS than your current machine, you
  8615. should not try to move a database by simply copying the files to the
  8616. other machine. Use `mysqldump' instead.
  8617.  
  8618. By default, `mysqldump' will create a file containing SQL statements.
  8619. You can then transfer the file to the other machine and feed it as input
  8620. to the `mysql' client.
  8621.  
  8622. Try `mysqldump --help' to see what options are available.  If you are
  8623. moving the data to a newer version of MySQL, you should use `mysqldump
  8624. --opt' with the newer version to get a fast, compact dump.
  8625.  
  8626. The easiest (although not the fastest) way to move a database between
  8627. two machines is to run the following commands on the machine on which
  8628. the database is located:
  8629.  
  8630.      shell> mysqladmin -h 'other hostname' create db_name
  8631.      shell> mysqldump --opt db_name \
  8632.              | mysql -h 'other hostname' db_name
  8633.  
  8634. If you want to copy a database from a remote machine over a slow
  8635. network, you can use:
  8636.  
  8637.      shell> mysqladmin create db_name
  8638.      shell> mysqldump -h 'other hostname' --opt --compress db_name \
  8639.              | mysql db_name
  8640.  
  8641. You can also store the result in a file, then transfer the file to the
  8642. target machine and load the file into the database there.  For example,
  8643. you can dump a database to a file on the source machine like this:
  8644.  
  8645.      shell> mysqldump --quick db_name | gzip > db_name.contents.gz
  8646.  
  8647. (The file created in this example is compressed.) Transfer the file
  8648. containing the database contents to the target machine and run these
  8649. commands there:
  8650.  
  8651.      shell> mysqladmin create db_name
  8652.      shell> gunzip < db_name.contents.gz | mysql db_name
  8653.  
  8654. You can also use `mysqldump' and `mysqlimport' to transfer the database.
  8655. For big tables, this is much faster than simply using `mysqldump'.  In
  8656. the following commands, `DUMPDIR' represents the full pathname of the
  8657. directory you use to store the output from `mysqldump'.
  8658.  
  8659. First, create the directory for the output files and dump the database:
  8660.  
  8661.      shell> mkdir DUMPDIR
  8662.      shell> mysqldump --tab=DUMPDIR db_name
  8663.  
  8664. Then transfer the files in the `DUMPDIR' directory to some corresponding
  8665. directory on the target machine and load the files into MySQL there:
  8666.  
  8667.      shell> mysqladmin create db_name           # create database
  8668.      shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
  8669.      shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables
  8670.  
  8671. Also, don't forget to copy the `mysql' database because that's where the
  8672. grant tables (`user', `db', `host') are stored.  You may have to run
  8673. commands as the MySQL `root' user on the new machine until you have the
  8674. `mysql' database in place.
  8675.  
  8676. After you import the `mysql' database on the new machine, execute
  8677. `mysqladmin flush-privileges' so that the server reloads the grant table
  8678. information.
  8679.  
  8680. Upgrading MySQL under Windows
  8681. -----------------------------
  8682.  
  8683. When upgrading MySQL under Windows, please follow these steps:
  8684.  
  8685.   1. Download the latest Windows distribution of MySQL.
  8686.  
  8687.   2. Choose a time of day with low usage, where a maintenance break is
  8688.      acceptable.
  8689.  
  8690.   3. Alert the users that still are active about the maintenance break.
  8691.  
  8692.   4. Stop the running MySQL Server (for example, with `NET STOP mysql'
  8693.      if you are running MySQL as a service, or with `mysqladmin
  8694.      shutdown' otherwise).
  8695.  
  8696.   5. Exit the `WinMySQLadmin' program if it is running.
  8697.  
  8698.   6. Run the installation script of the Windows distribution, by
  8699.      clicking the "Install" button in WinZip and following the
  8700.      installation steps of the script.
  8701.  
  8702.   7. You may either overwrite your old MySQL installation (usually
  8703.      located at `C:\mysql'), or install it into a different directory,
  8704.      such as `C:\mysql4'. Overwriting the old installation is
  8705.      recommended.
  8706.  
  8707.   8. The version of MySQL that is started as a service is determined by
  8708.      the `basedir' parameter in the `my.ini' file of your Windows
  8709.      directory (for example, `C:\WINNT').
  8710.  
  8711.   9. Restart the server (for example, with `NET START mysql' if you run
  8712.      MYSQL as a service, or by invoking `mysqld' directly otherwise).
  8713.  
  8714.  10. Update the grant tables. The procedure is described in *Note
  8715.      Upgrading-grant-tables::.
  8716.  
  8717.  
  8718. Possible error situations:
  8719.      A system error has occurred.
  8720.      System error 1067 has occurred.
  8721.      The process terminated unexpectedly.
  8722.  
  8723. This cryptic error means that your `my.cnf' file (by default
  8724. `C:\my.cnf') contains an option that cannot be recognised by MySQL. You
  8725. can verify that this is the case by trying to restart MySQL with the
  8726. `my.cnf' file renamed, for example, to `my.cnf.old' to prevent the
  8727. server from using it.  Once you have verified it, you need to identify
  8728. which option is the culprit. Create a new `my.cnf' file and move parts
  8729. of the old file to it (restarting the server after you move each part)
  8730. until you determine which part causes server startup to fail.
  8731.  
  8732. Operating System Specific Notes
  8733. ===============================
  8734.  
  8735. Windows Notes
  8736. -------------
  8737.  
  8738. This section describes using MySQL on Windows. This information is also
  8739. provided in the `README' file that comes with the MySQL Windows
  8740. distribution. *Note Windows installation::.
  8741.  
  8742. On Windows 95, 98, or Me, MySQL clients always connect to the server
  8743. using TCP/IP. On NT-based systems such as Windows NT, 2000, or XP,
  8744. clients have two options. They can use TCP/IP, or they can use a named
  8745. pipe if the server supports named pipe connections.
  8746.  
  8747. For information about which server binary to run, see *Note Windows
  8748. prepare environment::.
  8749.  
  8750. The examples in this section assume that MySQL is installed under the
  8751. default location of `C:\mysql'. Adjust the pathnames shown in the
  8752. examples if you have MySQL installed in a different location.
  8753.  
  8754. Starting MySQL on Windows 95, 98, or Me
  8755. .......................................
  8756.  
  8757. On these versions of Windows, MySQL uses TCP/IP to connect a client to
  8758. a server. (This will allow any machine on your network to connect to
  8759. your MySQL server.)  Because of this, you must make sure that TCP/IP
  8760. support is installed on your machine before starting MySQL.  You can
  8761. find TCP/IP on your Windows CD-ROM.
  8762.  
  8763. Note that if you are using an old Windows 95 release (for example,
  8764. OSR2), it's likely that you have an old Winsock package; MySQL requires
  8765. Winsock 2! You can get the newest Winsock from
  8766. `http://www.microsoft.com/'.  Windows 98 has the new Winsock 2 library,
  8767. so it is unnecessary to update the library.
  8768.  
  8769. To start the `mysqld' server, you should start a console window (a
  8770. "DOS" window) and enter this command:
  8771.  
  8772.      shell> C:\mysql\bin\mysqld
  8773.  
  8774. This will start `mysqld' in the background. That is, after the server
  8775. starts up, you should see another command prompt. (Note that if you
  8776. start the server this way on Windows NT, 2000, or XP, the server will
  8777. run in the foreground and the next command prompt will not appear until
  8778. the server exits.  To run client programs while the server is running,
  8779. you should open another console window.)
  8780.  
  8781. You can stop the MySQL server by executing this command:
  8782.  
  8783.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  8784.  
  8785. This invokes the MySQL administrative utility `mysqladmin' to connect
  8786. to the server as `root', which is the default administrative account in
  8787. the MySQL grant system. Please note that users in the MySQL grant
  8788. system are wholly independent from any login users under Windows.
  8789.  
  8790. If `mysqld' doesn't start, please check the error log to see if the
  8791. server wrote any messages there to indicate the cause of the problem.
  8792. The error log is located in the `C:\mysql\data' directory. It is the
  8793. file with a suffix of `.err'. You can also try to start the server as
  8794. `mysqld --console'; in this case, you may get some useful information
  8795. on the screen that may help solve the problem.
  8796.  
  8797. The last option is to start `mysqld' with `--standalone --debug'.  In
  8798. this case `mysqld' will write a log file `C:\mysqld.trace' that should
  8799. contain the reason why `mysqld' doesn't start. *Note Making trace
  8800. files::.
  8801.  
  8802. Use `mysqld --help' to display all the options that `mysqld'
  8803. understands!
  8804.  
  8805. Starting MySQL on Windows NT, 2000, or XP
  8806. .........................................
  8807.  
  8808. To get MySQL to work with TCP/IP on Windows NT 4, you must install
  8809. service pack 3 (or newer)!
  8810.  
  8811. Normally you should install MySQL as a service on Windows NT/2000/XP.
  8812. In case the server was already running, first stop it using the
  8813. following command:
  8814.  
  8815.      shell> C:\mysql\bin\mysqladmin -u root shutdown
  8816.  
  8817. This invokes the MySQL administrative utility `mysqladmin' to connect
  8818. to the server as `root', which is the default administrative account in
  8819. the MySQL grant system. Please note that users in the MySQL grant
  8820. system are wholly independent from any login users under Windows.
  8821.  
  8822. Now install the server as a service:
  8823.  
  8824.      shell> C:\mysql\bin\mysqld --install
  8825.  
  8826. The service is installed with the name `MySql'. Once installed, it can
  8827. be immediately started from the `Services' utility, or by using the
  8828. command `NET START MySql'.
  8829.  
  8830. Once running, `mysqld' can be stopped by using the Services utility,
  8831. the command `NET STOP MySql', or the command `mysqladmin shutdown'.
  8832.  
  8833. If any startup options are required, you can place them in the
  8834. `[mysqld]' group of any of the standard option files. As of MySQL
  8835. 4.0.3, you can place options in the `[mysqld]' group of any option file
  8836. and use a `--defaults-file' option to tell the server the name of the
  8837. file when you install the service. For example:
  8838.  
  8839.      shell> C:\mysql\bin\mysqld --install MySql --defaults-file=C:\my-opts.cnf
  8840.  
  8841. You can also specify options as "`Start parameters'" in the Windows
  8842. `Services' utility before you start the MySQL service.
  8843.  
  8844. The `Services' utility (`Windows Service Control Manager') can be found
  8845. in the `Windows Control Panel' (under `Administrative Tools' on Windows
  8846. 2000). It is advisable to close the Services utility while performing
  8847. the `--install' or `--remove' operations, this prevents some odd errors.
  8848.  
  8849. Please note that from MySQL version 3.23.44, you have the choice of
  8850. setting up the service as `Manual' instead (if you don't wish the
  8851. service to be started automatically during the boot process):
  8852.  
  8853.      shell> C:\mysql\bin\mysqld --install-manual
  8854.  
  8855. When MySQL is running as a service, the operating system will
  8856. automatically stop the server on computer shutdown. In MySQL versions
  8857. older than 3.23.47, Windows waited only for a few seconds for the
  8858. shutdown to complete, and killed the database server process if the
  8859. time limit was exceeded. This had the potential to cause problems.
  8860. (For example, at the next startup the `InnoDB' storage engine had to do
  8861. crash recovery.) Starting from MySQL version 3.23.48, Windows waits
  8862. longer for the MySQL server shutdown to complete. If you notice this
  8863. still is not enough for your installation, it is safest not to run the
  8864. MySQL server as a service. Instead, run it from the command-line
  8865. prompt, and shut it down with `mysqladmin shutdown'.
  8866.  
  8867. There is a problem that Windows NT (but not Windows 2000/XP) by default
  8868. only waits 20 seconds for a service to shut down, and after that kills
  8869. the service process. You can increase this default by opening the
  8870. Registry Editor `\winnt\system32\regedt32.exe' and editing the value of
  8871. `WaitToKillServiceTimeout' at
  8872. `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' in the Registry
  8873. tree. Specify the new larger value in milliseconds (for example, 120000
  8874. to have Windows NT wait up to 120 seconds).
  8875.  
  8876. Please note that when run as a service, `mysqld' has no access to a
  8877. console and so no messages can be seen.  Errors can be checked in the
  8878. error log, which is located in the `C:\mysql\data' directory. It is the
  8879. file with a suffix of `.err'.
  8880.  
  8881. If you have problems installing `mysqld' as a service using just the
  8882. server name, try installing it using its full pathname:
  8883.  
  8884.      shell> C:\mysql\bin\mysqld --install
  8885.  
  8886. If that doesn't work, you can get `mysqld' to start properly by fixing
  8887. the path in the registry!
  8888.  
  8889. If you don't want to start `mysqld' as a service, you can start it from
  8890. the command line the same way as for Windows 95, 98, or Me. For
  8891. instructions, see *Note Win95 start::.
  8892.  
  8893. Running MySQL on Windows
  8894. ........................
  8895.  
  8896. MySQL supports TCP/IP on all Windows platforms. The `mysqld-nt' and
  8897. `mysql-max-nt' servers support named pipes on NT, 2000, and XP.  The
  8898. default is to use TCP/IP regardless of the platform, because named
  8899. pipes are actually slower than TCP/IP, and because some users have
  8900. experienced problems shutting down the MySQL server when named pipes
  8901. are used. Starting from 3.23.50, named pipes are only enabled for
  8902. `mysqld-nt' and `mysql-max-nt' if they are started with the
  8903. `--enable-named-pipe' option.
  8904.  
  8905. You can force a MySQL client to use named pipes by specifying the
  8906. `--pipe' option or by specifying `.' as the host name.  Use the
  8907. `--socket' option to specify the name of the pipe.  In MySQL 4.1, you
  8908. should use the `--protocol=PIPE' option.
  8909.  
  8910. You can test whether the MySQL server is working by executing any of the
  8911. following commands:
  8912.  
  8913.      C:\> C:\mysql\bin\mysqlshow
  8914.      C:\> C:\mysql\bin\mysqlshow -u root mysql
  8915.      C:\> C:\mysql\bin\mysqladmin version status proc
  8916.      C:\> C:\mysql\bin\mysql test
  8917.  
  8918. If `mysqld' is slow to answer to connections on Windows 9x/Me, there is
  8919. probably a problem with your DNS.  In this case, start `mysqld' with the
  8920. `--skip-name-resolve' option and use only `localhost' and IP numbers in
  8921. the `Host' column of the MySQL grant tables.
  8922.  
  8923. There are two versions of the MySQL command-line tool:
  8924. *Binary**Description*
  8925. `mysql' Compiled on native Windows, offering
  8926.         limited text editing capabilities.
  8927. `mysqlc'Compiled with the Cygnus GNU compiler and
  8928.         libraries, which offers `readline' editing.
  8929.  
  8930. If you want to use `mysqlc', you must have a copy of the
  8931. `cygwinb19.dll' library installed somewhere that `mysqlc' can find it.
  8932. If your distribution of MySQL doesn't have this library installed in the
  8933. same directory as `mysqlc' (the `bin' directory under the base
  8934. directory of your MySQL installation, look in the `lib' directory to
  8935. find it and copy it to your Windows system directory (`\windows\system'
  8936. or similar place).
  8937.  
  8938. The default privileges on Windows give all local users full privileges
  8939. to all databases without specifying a password.  To make MySQL more
  8940. secure, you should set a password for all users and remove the row in
  8941. the `mysql.user' table that has `Host='localhost'' and `User='''.
  8942.  
  8943. You should also add a password for the `root' user. The following
  8944. example starts by removing the anonymous user that has all privileges,
  8945. then sets a `root' user password:
  8946.  
  8947.      C:\> C:\mysql\bin\mysql mysql
  8948.      mysql> DELETE FROM user WHERE Host='localhost' AND User='';
  8949.      mysql> QUIT
  8950.      C:\> C:\mysql\bin\mysqladmin reload
  8951.      C:\> C:\mysql\bin\mysqladmin -u root password your_password
  8952.  
  8953. After you've set the password, if you want to shut down the `mysqld'
  8954. server, you can do so using this command:
  8955.  
  8956.      C:\> mysqladmin --user=root --password=your_password shutdown
  8957.  
  8958. If you are using the old shareware version of MySQL Version 3.21 under
  8959. Windows, the above command will fail with an error: `parse error near
  8960. 'SET password''.  The solution to this problem is to upgrade to a newer
  8961. version of MySQL.
  8962.  
  8963. With the current MySQL versions you can easily add new users and change
  8964. privileges with `GRANT' and `REVOKE' commands.  *Note `GRANT': GRANT.
  8965.  
  8966. Connecting to MySQL Remotely from Windows with SSH
  8967. ..................................................
  8968.  
  8969. Here is a note about how to connect to get a secure connection to remote
  8970. MySQL server with SSH (by David Carlson <dcarlson@mplcomm.com>):
  8971.  
  8972.   1. Install an SSH client on your Windows machine.  As a user, the
  8973.      best non-free one I've found is from `SecureCRT' from
  8974.      `http://www.vandyke.com/'.  Another option is `f-secure' from
  8975.      `http://www.f-secure.com/'. You can also find some free ones on
  8976.      `Google' at
  8977.      `http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cryptography/SSH/Clients/Windows/'.
  8978.  
  8979.   2. Start your Windows SSH client.  Set `Host_Name =
  8980.      yourmysqlserver_URL_or_IP'.  Set `userid=your_userid' to log in to
  8981.      your server (probably not the same as your MySQL login/password.
  8982.  
  8983.   3. Set up port forwarding. Either do a remote forward (Set
  8984.      `local_port: 3306', `remote_host: yourmysqlservername_or_ip',
  8985.      `remote_port: 3306' ) or a local forward (Set `port: 3306',
  8986.      `host: localhost', `remote port: 3306').
  8987.  
  8988.   4. Save everything, otherwise you'll have to redo it the next time.
  8989.  
  8990.   5. Log in to your server with SSH session you just created.
  8991.  
  8992.   6. On your Windows machine, start some ODBC application (such as
  8993.      Access).
  8994.  
  8995.   7. Create a new file in Windows and link to MySQL using the ODBC
  8996.      driver the same way you normally do, except type in `localhost'
  8997.      for the MySQL host server--not `yourmysqlservername'.
  8998.  
  8999. You should now have an ODBC connection to MySQL, encrypted using SSH.
  9000.  
  9001. Distributing Data Across Different Disks on Windows
  9002. ...................................................
  9003.  
  9004. Beginning with MySQL Version 3.23.16, the `mysqld-max' and
  9005. `mysql-max-nt' servers in the MySQL distribution are compiled with the
  9006. `-DUSE_SYMDIR' option.  This allows you to put a database on a
  9007. different disk by setting up a symbolic link to it (in a manner similar
  9008. to the way that symbolic links work on Unix).
  9009.  
  9010. On Windows, you make a symbolic link to a database by creating a file
  9011. that contains the path to the destination directory and saving this in
  9012. the data directory using the filename `db_name.sym', where `db_name' is
  9013. the database name.  Note that the symbolic link will not be used if a
  9014. directory with the database name exists.
  9015.  
  9016. For example, if the MySQL data directory is `C:\mysql\data' and you
  9017. want to have database `foo' located at `D:\data\foo', you should create
  9018. the file `C:\mysql\data\foo.sym' that contains the text `D:\data\foo\'.
  9019. After that, all tables created in the database `foo' will be created
  9020. in `D:\data\foo'.
  9021.  
  9022. Note that because of the speed penalty you get when opening every table,
  9023. we have not enabled this by default even if you have compiled MySQL
  9024. with support for this. To enable symlinks you should put in your
  9025. `my.cnf' or `my.ini' file the following entry:
  9026.  
  9027.      [mysqld]
  9028.      symbolic-links
  9029.  
  9030. In MySQL 4.0, symbolic links are enabled by default. If you don't need
  9031. them, you can disable them with the `skip-symbolic-links' option.
  9032.  
  9033. Compiling MySQL Clients on Windows
  9034. ..................................
  9035.  
  9036. In your source files, you should include `my_global.h' before `mysql.h':
  9037.  
  9038.      #include <my_global.h>
  9039.      #include <mysql.h>
  9040.  
  9041. `my_global.h' includes any other files needed for Windows compatibility
  9042. (such as `windows.h') if you compile your program on Windows.
  9043.  
  9044. You can either link your code with the dynamic `libmysql.lib' library,
  9045. which is just a wrapper to load in `libmysql.dll' on demand, or link
  9046. with the static `mysqlclient.lib' library.
  9047.  
  9048. Note that because the MySQL client libraries are compiled as threaded
  9049. libraries, you should also compile your code to be multi-threaded!
  9050.  
  9051. MySQL for Windows Compared to Unix MySQL
  9052. ........................................
  9053.  
  9054. MySQL for Windows has by now proven itself to be very stable. The
  9055. Windows version of MySQL has the same features as the corresponding
  9056. Unix version, with the following exceptions:
  9057.  
  9058. *Windows 95 and threads*
  9059.      Windows 95 leaks about 200 bytes of main memory for each thread
  9060.      creation.  Each connection in MySQL creates a new thread, so you
  9061.      shouldn't run `mysqld' for an extended time on Windows 95 if your
  9062.      server handles many connections!  Other versions of Windows don't
  9063.      suffer from this bug.
  9064.  
  9065. *Concurrent reads*
  9066.      MySQL depends on the `pread()' and `pwrite()' calls to be able to
  9067.      mix `INSERT' and `SELECT'.  Currently we use mutexes to emulate
  9068.      `pread()'/`pwrite()'.  We will, in the long run, replace the file
  9069.      level interface with a virtual interface so that we can use the
  9070.      `readfile()'/`writefile()' interface on NT/2000/XP to get more
  9071.      speed.  The current implementation limits the number of open files
  9072.      MySQL can use to 1024, which means that you will not be able to
  9073.      run as many concurrent threads on NT/2000/XP as on Unix.
  9074.  
  9075. *Blocking read*
  9076.      MySQL uses a blocking read for each connection, which has the
  9077.      following implications:
  9078.  
  9079.         * A connection will not be disconnected automatically after 8
  9080.           hours, as happens with the Unix version of MySQL.
  9081.  
  9082.         * If a connection hangs, it's impossible to break it without
  9083.           killing MySQL.
  9084.  
  9085.         * `mysqladmin kill' will not work on a sleeping connection.
  9086.  
  9087.         * `mysqladmin shutdown' can't abort as long as there are
  9088.           sleeping connections.
  9089.  
  9090.      We plan to fix this problem when our Windows developers have
  9091.      figured out a nice workaround.
  9092.  
  9093. *`DROP DATABASE'*
  9094.      You can't drop a database that is in use by some thread.
  9095.  
  9096. *Killing MySQL from the task manager*
  9097.      You can't kill MySQL from the task manager or with the shutdown
  9098.      utility in Windows 95.  You must take it down with `mysqladmin
  9099.      shutdown'.
  9100.  
  9101. *Case-insensitive names*
  9102.      Filenames are case-insensitive on Windows, so database and table
  9103.      names are also case-insensitive in MySQL for Windows.  The only
  9104.      restriction is that database and table names must be specified
  9105.      using the same case throughout a given statement.  *Note Name case
  9106.      sensitivity::.
  9107.  
  9108. *The `\' directory character*
  9109.      Pathname components in Windows 95 are separated by the `\'
  9110.      character, which is also the escape character in MySQL.  If you
  9111.      are using `LOAD DATA INFILE' or `SELECT ... INTO OUTFILE', you
  9112.      must double the `\' character:
  9113.  
  9114.           mysql> LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
  9115.           mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
  9116.  
  9117.      Alternatively, use Unix style filenames with `/' characters:
  9118.  
  9119.           mysql> LOAD DATA INFILE "C:/tmp/skr.txt" INTO TABLE skr;
  9120.           mysql> SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
  9121.  
  9122. *Problems with pipes.*
  9123.      Pipes doesn't work reliably in the Windows command-line prompt.
  9124.      If the pipe includes the character `^Z' / `CHAR(24)', Windows will
  9125.      think it has encountered end-of-file and abort the program.
  9126.  
  9127.      This is mainly a problem when you try to apply a binary log as
  9128.      follows:
  9129.  
  9130.           mysqlbinlog binary-log-name | mysql --user=root
  9131.  
  9132.      If you get a problem applying the log and suspect it's because of
  9133.      an `^Z' / `CHAR(24)' character you can use the following
  9134.      workaround:
  9135.  
  9136.           mysqlbinlog binary-log-file --result-file=/tmp/bin.sql
  9137.           mysql --user=root --execute "source /tmp/bin.sql"
  9138.  
  9139.      The latter command also can be used to reliably read in any SQL
  9140.      file that may contain binary data.
  9141.  
  9142. *`Can't open named pipe' error*
  9143.      If you use a MySQL 3.22 version on NT with the newest mysql-clients
  9144.      you will get the following error:
  9145.  
  9146.           error 2017: can't open named pipe to host: . pipe...
  9147.  
  9148.      This is because the release version of MySQL uses named pipes on NT
  9149.      by default.  You can avoid this error by using the
  9150.      `--host=localhost' option to the new MySQL clients or create an
  9151.      option file `C:\my.cnf' that contains the following information:
  9152.  
  9153.           [client]
  9154.           host = localhost
  9155.  
  9156.      Starting from 3.23.50, named pipes are enabled only if `mysqld-nt'
  9157.      or `mysqld-max-nt' is started with `--enable-named-pipe'.
  9158.  
  9159. *`Access denied for user' error*
  9160.      If you get the error `Access denied for user: 'some-user@unknown'
  9161.      to database 'mysql'' when accessing a MySQL server on the same
  9162.      machine, this means that MySQL can't resolve your host name
  9163.      properly.
  9164.  
  9165.      To fix this, you should create a file `\windows\hosts' with the
  9166.      following information:
  9167.  
  9168.           127.0.0.1       localhost
  9169.  
  9170. *`ALTER TABLE'*
  9171.      While you are executing an `ALTER TABLE' statement, the table is
  9172.      locked from usage by other threads.  This has to do with the fact
  9173.      that on Windows, you can't delete a file that is in use by another
  9174.      threads.  (In the future, we may find some way to work around this
  9175.      problem.)
  9176.  
  9177. *`DROP TABLE'*
  9178.      `DROP TABLE' on a table that is in use by a `MERGE' table will not
  9179.      work on Windows because the `MERGE' handler does the table mapping
  9180.      hidden from the upper layer of MySQL.  Because Windows doesn't
  9181.      allow you to drop files that are open, you first must flush all
  9182.      `MERGE' tables (with `FLUSH TABLES') or drop the `MERGE' table
  9183.      before dropping the table.  We will fix this at the same time we
  9184.      introduce `VIEW's.
  9185.  
  9186. *`DATA DIRECTORY' and `INDEX DIRECTORY'*
  9187.      The `DATA DIRECTORY' and `INDEX DIRECTORY' options for `CREATE
  9188.      TABLE' are ignored on Windows, because Windows doesn't support
  9189.      symbolic links.
  9190.  
  9191. Here are some open issues for anyone who might want to help us with the
  9192. Windows release:
  9193.  
  9194.    * Add some nice start and shutdown icons to the MySQL installation.
  9195.  
  9196.    * It would be really nice to be able to kill `mysqld' from the task
  9197.      manager.  For the moment, you must use `mysqladmin shutdown'.
  9198.  
  9199.    * Port `readline' to Windows for use in the `mysql' command-line
  9200.      tool.
  9201.  
  9202.    * GUI versions of the standard MySQL clients (`mysql', `mysqlshow',
  9203.      `mysqladmin', and `mysqldump') would be nice.
  9204.  
  9205.    * It would be nice if the socket read and write functions in `net.c'
  9206.      were interruptible. This would make it possible to kill open
  9207.      threads with `mysqladmin kill' on Windows.
  9208.  
  9209.    * Add macros to use the faster thread-safe increment/decrement
  9210.      methods provided by Windows.
  9211.  
  9212. Other Windows-specific issues are described in the `README' file that
  9213. comes with the Windows distribution of MySQL.
  9214.  
  9215. Linux Notes (All Linux Versions)
  9216. --------------------------------
  9217.  
  9218. The following notes regarding `glibc' apply only to the situation when
  9219. you build MySQL yourself. If you are running Linux on an x86 machine,
  9220. in most cases it is much better for you to just use our binary. We link
  9221. our binaries against the best patched version of `glibc' we can come up
  9222. with and with the best compiler options, in an attempt to make it
  9223. suitable for a high-load server. So if you read the following text, and
  9224. are in doubt about what you should do, try our binary first to see if
  9225. it meets your needs, and worry about your own build only after you have
  9226. discovered that our binary is not good enough. In that case, we would
  9227. appreciate a note about it, so we can build a better binary next time.
  9228. For a typical user, even for setups with a lot of concurrent
  9229. connections and/or tables exceeding the 2G limit, our binary in most
  9230. cases is the best choice.
  9231.  
  9232. MySQL uses LinuxThreads on Linux.  If you are using an old Linux
  9233. version that doesn't have `glibc2', you must install LinuxThreads
  9234. before trying to compile MySQL.   You can get LinuxThreads at
  9235. `http://www.mysql.com/downloads/os-linux.html'.
  9236.  
  9237. *Note*: we have seen some strange problems with Linux 2.2.14 and MySQL
  9238. on SMP systems. If you have a SMP system, we recommend you upgrade to
  9239. Linux 2.4 as soon as possible.  Your system will be faster and more
  9240. stable by doing this.
  9241.  
  9242. Note that `glibc' versions before and including Version 2.1.1 have a
  9243. fatal bug in `pthread_mutex_timedwait' handling, which is used when you
  9244. do `INSERT DELAYED'.  We recommend that you not use `INSERT DELAYED'
  9245. before upgrading glibc.
  9246.  
  9247. If you plan to have 1000+ concurrent connections, you will need to make
  9248. some changes to LinuxThreads, recompile it, and relink MySQL against
  9249. the new `libpthread.a'.  Increase `PTHREAD_THREADS_MAX' in
  9250. `sysdeps/unix/sysv/linux/bits/local_lim.h' to 4096 and decrease
  9251. `STACK_SIZE' in `linuxthreads/internals.h' to 256 KB. The paths are
  9252. relative to the root of `glibc' Note that MySQL will not be stable with
  9253. around 600-1000 connections if `STACK_SIZE' is the default of 2 MB.
  9254.  
  9255. If MySQL can't open enough files, or connections, it may be that you
  9256. haven't configured Linux to handle enough files.
  9257.  
  9258. In Linux 2.2 and onward, you can check the number of allocated file
  9259. handles by doing:
  9260.  
  9261.      cat /proc/sys/fs/file-max
  9262.      cat /proc/sys/fs/dquot-max
  9263.      cat /proc/sys/fs/super-max
  9264.  
  9265. If you have more than 16 MB of memory, you should add something like the
  9266. following to your init scripts (for example, `/etc/init.d/boot.local'
  9267. on SuSE Linux):
  9268.  
  9269.      echo 65536 > /proc/sys/fs/file-max
  9270.      echo 8192 > /proc/sys/fs/dquot-max
  9271.      echo 1024 > /proc/sys/fs/super-max
  9272.  
  9273. You can also run the preceding commands from the command-line as root,
  9274. but these settings will be lost the next time your computer reboots.
  9275.  
  9276. Alternatively, you can set these parameters on bootup by using the
  9277. `sysctl' tool, which is used by many Linux distributions (SuSE has
  9278. added it as well, beginning with SuSE Linux 8.0). Just put the following
  9279. values into a file named `/etc/sysctl.conf':
  9280.  
  9281.      # Increase some values for MySQL
  9282.      fs.file-max = 65536
  9283.      fs.dquot-max = 8192
  9284.      fs.super-max = 1024
  9285.  
  9286. You should also add the following to `/etc/my.cnf':
  9287.  
  9288.      [mysqld_safe]
  9289.      open-files-limit=8192
  9290.  
  9291. This should allow MySQL to create up to 8192 connections + files.
  9292.  
  9293. The `STACK_SIZE' constant in LinuxThreads controls the spacing of thread
  9294. stacks in the address space.  It needs to be large enough so that there
  9295. will be plenty of room for the stack of each individual thread, but
  9296. small enough to keep the stack of some threads from running into the
  9297. global `mysqld' data.  Unfortunately, the Linux implementation of
  9298. `mmap()', as we have experimentally discovered, will successfully unmap
  9299. an already mapped region if you ask it to map out an address already in
  9300. use, zeroing out the data on the entire page, instead of returning an
  9301. error.  So, the safety of `mysqld' or any other threaded application
  9302. depends on the "gentleman" behaviour of the code that creates threads.
  9303. The user must take measures to make sure the number of running threads
  9304. at any time is sufficiently low for thread stacks to stay away from the
  9305. global heap.  With `mysqld', you should enforce this "gentleman"
  9306. behaviour by setting a reasonable value for the `max_connections'
  9307. variable.
  9308.  
  9309. If you build MySQL yourself and do not want to mess with patching
  9310. LinuxThreads, you should set `max_connections' to a value no higher
  9311. than 500.  It should be even less if you have a large key buffer,  large
  9312. heap tables, or some other things that make `mysqld' allocate a lot of
  9313. memory, or if you are running a 2.2 kernel with a 2G patch. If you are
  9314. using our binary or RPM version 3.23.25 or later, you can safely set
  9315. `max_connections' at 1500, assuming no large key buffer or heap tables
  9316. with lots of data.  The more you reduce `STACK_SIZE' in LinuxThreads
  9317. the more threads you can safely create.  We recommend the values between
  9318. 128K and 256K.
  9319.  
  9320. If you use a lot of concurrent connections, you may suffer from a
  9321. "feature" in the 2.2 kernel that penalises a process for forking or
  9322. cloning a child in an attempt to prevent a fork bomb attack.  This will
  9323. cause MySQL not to scale well as you increase the number of concurrent
  9324. clients.  On single-CPU systems, we have seen this manifested in a very
  9325. slow thread creation, which means it may take a long time to connect to
  9326. MySQL (as long as 1 minute), and it may take just as long to shut it
  9327. down.  On multiple-CPU systems, we have observed a gradual drop in
  9328. query speed as the number of clients increases.  In the process of
  9329. trying to find a solution, we have received a kernel patch from one of
  9330. our users, who claimed it made a lot of difference for his site.  The
  9331. patch is available at
  9332. `http://www.mysql.com/Downloads/Patches/linux-fork.patch'. We have now
  9333. done rather extensive testing of this patch on both development and
  9334. production systems.  It has significantly improved `MySQL' performance
  9335. without causing any problems and we now recommend it to our users who
  9336. are still running high-load servers on 2.2 kernels.  This issue has
  9337. been fixed in the 2.4 kernel, so if you are not satisfied with the
  9338. current performance of your system, rather than patching your 2.2
  9339. kernel, it might be easier to just upgrade to 2.4, which will also give
  9340. you a nice SMP boost in addition to fixing this fairness bug.
  9341.  
  9342. We have tested MySQL on the 2.4 kernel on a 2-CPU machine and found
  9343. MySQL scales *much* better--there was virtually no slowdown on queries
  9344. throughput all the way up to 1000 clients, and the MySQL scaling factor
  9345. (computed as the ratio of maximum throughput to the throughput with one
  9346. client) was 180%.  We have observed similar results on a 4-CPU
  9347. system--virtually no slowdown as the number of clients was increased up
  9348. to 1000, and 300% scaling factor. So for a high-load SMP server we
  9349. would definitely recommend the 2.4 kernel at this point. We have
  9350. discovered that it is essential to run `mysqld' process with the
  9351. highest possible priority on the 2.4 kernel to achieve maximum
  9352. performance.  This can be done by adding `renice -20 $$' command to
  9353. `mysqld_safe'. In our testing on a 4-CPU machine, increasing the
  9354. priority gave 60% increase in throughput with 400 clients.
  9355.  
  9356. We are currently also trying to collect more information on how well
  9357. `MySQL' performs on 2.4 kernel on 4-way and 8-way systems. If you have
  9358. access such a system and have done some benchmarks, please send a mail
  9359. to <docs@mysql.com> with the results - we will include them in the
  9360. manual.
  9361.  
  9362. There is another issue that greatly hurts MySQL performance, especially
  9363. on SMP systems.  The implementation of mutex in LinuxThreads in
  9364. `glibc-2.1' is very bad for programs with many threads that only hold
  9365. the mutex for a short time. On an SMP system, ironic as it is, if you
  9366. link MySQL against unmodified `LinuxThreads', removing processors from
  9367. the machine improves MySQL performance in many cases.  We have made a
  9368. patch available for `glibc 2.1.3' to correct this behaviour
  9369. (`http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch').
  9370.  
  9371. With `glibc-2.2.2' MySQL version 3.23.36 will use the adaptive mutex,
  9372. which is much better than even the patched one in `glibc-2.1.3'. Be
  9373. warned, however, that under some conditions, the current mutex code in
  9374. `glibc-2.2.2' overspins, which hurts MySQL performance. The chance of
  9375. this condition can be reduced by renicing `mysqld' process to the
  9376. highest priority. We have also been able to correct the overspin
  9377. behaviour with a patch, available at
  9378. `http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch'.  It
  9379. combines the correction of overspin, maximum number of threads, and
  9380. stack spacing all in one. You will need to apply it in the
  9381. `linuxthreads' directory with `patch -p0
  9382. </tmp/linuxthreads-2.2.2.patch'.  We hope it will be included in some
  9383. form in to the future releases of `glibc-2.2'. In any case, if you link
  9384. against `glibc-2.2.2' you still need to correct `STACK_SIZE' and
  9385. `PTHREAD_THREADS_MAX'. We hope that the defaults will be corrected to
  9386. some more acceptable values for high-load MySQL setup in the future, so
  9387. that your own build can be reduced to `./configure; make; make install'.
  9388.  
  9389. We recommend that you use the above patches to build a special static
  9390. version of `libpthread.a' and use it only for statically linking
  9391. against `MySQL'. We know that the patches are safe for `MySQL' and
  9392. significantly improve its performance, but we cannot say anything about
  9393. other applications. If you link other applications against the patched
  9394. version of the library, or build a patched shared version and install
  9395. it on your system, you are doing it at your own risk with regard to
  9396. other applications that depend on `LinuxThreads'.
  9397.  
  9398. If you experience any strange problems during the installation of
  9399. MySQL, or with some common utilities hanging, it is very likely that
  9400. they are either library or compiler related. If this is the case, using
  9401. our binary will resolve them.
  9402.  
  9403. One known problem with the binary distribution is that with older Linux
  9404. systems that use `libc' (like Red Hat 4.x or Slackware), you will get
  9405. some non-fatal problems with hostname resolution.  *Note Binary
  9406. notes-Linux::.
  9407.  
  9408. When using LinuxThreads you will see a minimum of three processes
  9409. running.  These are in fact threads.  There will be one thread for the
  9410. LinuxThreads manager, one thread to handle connections, and one thread
  9411. to handle alarms and signals.
  9412.  
  9413. Note that the Linux kernel and the LinuxThread library can by default
  9414. only have 1024 threads.  This means that you can only have up to 1021
  9415. connections to MySQL on an unpatched system.  The page
  9416. `http://www.volano.com/linuxnotes.html' contains information how to go
  9417. around this limit.
  9418.  
  9419. If you see a dead `mysqld' daemon process with `ps', this usually means
  9420. that you have found a bug in MySQL or you have a corrupted table. *Note
  9421. Crashing::.
  9422.  
  9423. To get a core dump on Linux if `mysqld' dies with a `SIGSEGV' signal,
  9424. you can start `mysqld' with the `--core-file' option.  Note that you
  9425. also probably need to raise the `core file size' by adding `ulimit -c
  9426. 1000000' to `mysqld_safe' or starting `mysqld_safe' with
  9427. `--core-file-size=1000000'.  *Note `mysqld_safe': mysqld_safe.
  9428.  
  9429. If you are linking your own MySQL client and get the error:
  9430.  
  9431.      ld.so.1: ./my: fatal: libmysqlclient.so.4:
  9432.      open failed: No such file or directory
  9433.  
  9434. When executing them, the problem can be avoided by one of the following
  9435. methods:
  9436.  
  9437.    * Link the client with the following flag (instead of `-Lpath'):
  9438.      `-Wl,r/path-libmysqlclient.so'.
  9439.  
  9440.    * Copy `libmysqclient.so' to `/usr/lib'.
  9441.  
  9442.    * Add the pathname of the directory where `libmysqlclient.so' is
  9443.      located to the `LD_RUN_PATH' environment variable before running
  9444.      your client.
  9445.  
  9446. If you are using the Fujitsu compiler `(fcc / FCC)' you will have some
  9447. problems compiling MySQL because the Linux header files are very `gcc'
  9448. oriented.
  9449.  
  9450. The following `configure' line should work with `fcc/FCC':
  9451.  
  9452.      CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE \
  9453.      -DCONST=const -DNO_STRTOLL_PROTO" CXX=FCC CXXFLAGS="-O -K fast -K lib \
  9454.      -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE -DCONST=const \
  9455.      -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO \
  9456.      '-D_EXTERN_INLINE=static __inline'" ./configure --prefix=/usr/local/mysql \
  9457.      --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared \
  9458.      --with-low-memory
  9459.  
  9460. Linux Notes for Binary Distributions
  9461. ....................................
  9462.  
  9463. MySQL needs at least Linux Version 2.0.
  9464.  
  9465. *Warning*: We have reports from some MySQL users that they have got
  9466. serious stability problems with MySQL with Linux kernel 2.2.14.  If you
  9467. are using this kernel you should upgrade to 2.2.19 (or newer) or to a
  9468. 2.4 kernel.  If you have a multi-cpu box, then you should seriously
  9469. consider using 2.4 as this will give you a significant speed boost.
  9470.  
  9471. The binary release is linked with `-static', which means you do not
  9472. normally need to worry about which version of the system libraries you
  9473. have. You need not install LinuxThreads, either.  A program linked with
  9474. `-static' is slightly bigger than a dynamically linked program but also
  9475. slightly faster (3-5%).  One problem, however, is that you can't use
  9476. user-definable functions (UDFs) with a statically linked program.  If
  9477. you are going to write or use UDFs (this is something for C or C++
  9478. programmers only), you must compile MySQL yourself, using dynamic
  9479. linking.
  9480.  
  9481. If you are using a `libc'-based system (instead of a `glibc2' system),
  9482. you will probably get some problems with hostname resolving and
  9483. `getpwnam()' with the binary release. (This is because `glibc'
  9484. unfortunately depends on some external libraries to resolve hostnames
  9485. and `getpwent()', even when compiled with `-static'). In this case you
  9486. probably get the following error message when you run
  9487. `mysql_install_db':
  9488.  
  9489.      Sorry, the host 'xxxx' could not be looked up
  9490.  
  9491. or the following error when you try to run `mysqld' with the `--user'
  9492. option:
  9493.  
  9494.      getpwnam: No such file or directory
  9495.  
  9496. You can solve this problem in one of the following ways:
  9497.  
  9498.    * Get a MySQL source distribution (an RPM or the `tar.gz'
  9499.      distribution) and install this instead.
  9500.  
  9501.    * Execute `mysql_install_db --force'; this will not execute the
  9502.      `resolveip' test in `mysql_install_db'.  The downside is that you
  9503.      can't use host names in the grant tables; you must use IP numbers
  9504.      instead (except for `localhost').  If you are using an old MySQL
  9505.      release that doesn't support `--force', you have to remove the
  9506.      `resolveip' test in `mysql_install' with an editor.
  9507.  
  9508.    * Start `mysqld' with `su' instead of using `--user'.
  9509.  
  9510. The Linux-Intel binary and RPM releases of MySQL are configured for the
  9511. highest possible speed.  We are always trying to use the fastest stable
  9512. compiler available.
  9513.  
  9514. MySQL Perl support requires Version Perl 5.004_03 or newer.
  9515.  
  9516. On some Linux 2.2 versions, you may get the error `Resource temporarily
  9517. unavailable' when you do a lot of new connections to a `mysqld' server
  9518. over TCP/IP.
  9519.  
  9520. The problem is that Linux has a delay between when you close a TCP/IP
  9521. socket and until this is actually freed by the system.  As there is only
  9522. room for a finite number of TCP/IP slots, you will get the above error
  9523. if you try to do too many new TCP/IP connections during a small time,
  9524. like when you run the MySQL `test-connect' benchmark over TCP/IP.
  9525.  
  9526. We have mailed about this problem a couple of times to different Linux
  9527. mailing lists but have never been able to resolve this properly.
  9528.  
  9529. The only known 'fix' to this problem is to use persistent connections in
  9530. your clients or use sockets, if you are running the database server and
  9531. clients on the same machine.  We hope that the `Linux 2.4' kernel will
  9532. fix this problem in the future.
  9533.  
  9534. Linux x86 Notes
  9535. ...............
  9536.  
  9537. MySQL requires `libc' Version 5.4.12 or newer. It's known to work with
  9538. `libc' 5.4.46.  `glibc' Version 2.0.6 and later should also work. There
  9539. have been some problems with the `glibc' RPMs from Red Hat, so if you
  9540. have problems, check whether there are any updates.  The `glibc'
  9541. 2.0.7-19 and 2.0.7-29 RPMs are known to work.
  9542.  
  9543. If you are using Red Hat 8.0 or a new `glibc' 2.2.x library, you should
  9544. start `mysqld' with the option `--thread-stack=192K'.  (Use `-O
  9545. thread_stack=192K' before MySQL 4.) If you don't do this, `mysqld' will
  9546. die in `gethostbyaddr()' because the new `glibc' library requires a
  9547. stack size greater than 128K for this call. This stack size is now the
  9548. default on MySQL 4.0.10 and above.
  9549.  
  9550. If you are using `gcc' 3.0 and above to compile MySQL, you must install
  9551. the `libstdc++v3' library before compiling MySQL; if you don't do this,
  9552. you will get an error about a missing `__cxa_pure_virtual' symbol
  9553. during linking.
  9554.  
  9555. On some older Linux distributions, `configure' may produce an error
  9556. like this:
  9557.  
  9558.      Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file.
  9559.      See the Installation chapter in the Reference Manual.
  9560.  
  9561. Just do what the error message says and add an extra underscore to the
  9562. `_P' macro that has only one underscore, then try again.
  9563.  
  9564. You may get some warnings when compiling; those shown here can be
  9565. ignored:
  9566.  
  9567.      mysqld.cc -o objs-thread/mysqld.o
  9568.      mysqld.cc: In function `void init_signals()':
  9569.      mysqld.cc:315: warning: assignment of negative value `-1' to
  9570.      `long unsigned int'
  9571.      mysqld.cc: In function `void * signal_hand(void *)':
  9572.      mysqld.cc:346: warning: assignment of negative value `-1' to
  9573.      `long unsigned int'
  9574.  
  9575. `mysql.server' can be found in the `share/mysql' directory under the
  9576. MySQL installation directory or in the `support-files' directory of the
  9577. MySQL source tree.
  9578.  
  9579. If `mysqld' always core dumps when it starts up, the problem may be that
  9580. you have an old `/lib/libc.a'.  Try renaming it, then remove
  9581. `sql/mysqld' and do a new `make install' and try again.  This problem
  9582. has been reported on some Slackware installations.
  9583.  
  9584. If you get the following error when linking `mysqld', it means that
  9585. your `libg++.a' is not installed correctly:
  9586.  
  9587.      /usr/lib/libc.a(putc.o): In function `_IO_putc':
  9588.      putc.o(.text+0x0): multiple definition of `_IO_putc'
  9589.  
  9590. You can avoid using `libg++.a' by running `configure' like this:
  9591.  
  9592.      shell> CXX=gcc ./configure
  9593.  
  9594. Linux SPARC Notes
  9595. .................
  9596.  
  9597. In some implementations, `readdir_r()' is broken.  The symptom is that
  9598. `SHOW DATABASES' always returns an empty set.  This can be fixed by
  9599. removing `HAVE_READDIR_R' from `config.h' after configuring and before
  9600. compiling.
  9601.  
  9602. Linux Alpha Notes
  9603. .................
  9604.  
  9605. MySQL Version 3.23.12 is the first MySQL version that is tested on
  9606. Linux-Alpha.  If you plan to use MySQL on Linux-Alpha, you should
  9607. ensure that you have this version or newer.
  9608.  
  9609. We have tested MySQL on Alpha with our benchmarks and test suite, and
  9610. it appears to work nicely.
  9611.  
  9612. We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP,
  9613. kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler
  9614. (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.
  9615.  
  9616. You can find the above compilers at
  9617. `http://www.support.compaq.com/alpha-tools/'.  By using these compilers,
  9618. instead of gcc, we get about 9-14% better performance with MySQL.
  9619.  
  9620. Note that until MySQL version 3.23.52 and 4.0.2 we optimised the binary
  9621. for the current CPU only (by using the `-fast' compile option); this
  9622. meant that you could only use our binaries if you had an Alpha EV6
  9623. processor.
  9624.  
  9625. Starting with all following releases we added the `-arch generic' flag
  9626. to our compile options, which makes sure the binary runs on all Alpha
  9627. processors. We also compile statically to avoid library problems.
  9628.  
  9629.      CC=ccc CFLAGS="-fast -arch generic" CXX=cxx \
  9630.      CXXFLAGS="-fast -arch generic -noexceptions -nortti" \
  9631.      ./configure --prefix=/usr/local/mysql --disable-shared \
  9632.      --with-extra-charsets=complex --enable-thread-safe-client \
  9633.      --with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared
  9634.  
  9635. If you want to use egcs the following configure line worked for us:
  9636.  
  9637.      CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
  9638.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
  9639.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  9640.      --disable-shared
  9641.  
  9642. Some known problems when running MySQL on Linux-Alpha:
  9643.  
  9644.    * Debugging threaded applications like MySQL will not work with `gdb
  9645.      4.18'.  You should download and use gdb 5.1 instead!
  9646.  
  9647.    * If you try linking `mysqld' statically when using `gcc', the
  9648.      resulting image will core dump at start.  In other words, *don't*
  9649.      use `--with-mysqld-ldflags=-all-static' with `gcc'.
  9650.  
  9651. Linux PowerPC Notes
  9652. ...................
  9653.  
  9654. MySQL should work on MkLinux with the newest `glibc' package (tested
  9655. with `glibc' 2.0.7).
  9656.  
  9657. Linux MIPS Notes
  9658. ................
  9659.  
  9660. To get MySQL to work on Qube2, (Linux Mips), you need the newest
  9661. `glibc' libraries (`glibc-2.0.7-29C2' is known to work).  You must also
  9662. use the `egcs' C++ compiler (`egcs-1.0.2-9', `gcc 2.95.2' or newer).
  9663.  
  9664. Linux IA-64 Notes
  9665. .................
  9666.  
  9667. To get MySQL to compile on Linux IA-64, we use the following compile
  9668. line: Using `gcc-2.96':
  9669.  
  9670.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  9671.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  9672.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  9673.      "--with-comment=Official MySQL binary" --with-extra-charsets=complex
  9674.  
  9675. On IA-64, the MySQL client binaries use shared libraries. This means
  9676. that if you install our binary distribution in some other place than
  9677. `/usr/local/mysql' you need to add the path of the directory where you
  9678. have `libmysqlclient.so' installed either to the `/etc/ld.so.conf' file
  9679. or to the value of your `LD_LIBRARY_PATH' environment variable.
  9680.  
  9681. *Note Link errors::.
  9682.  
  9683. Solaris Notes
  9684. -------------
  9685.  
  9686. On Solaris, you may run into trouble even before you get the MySQL
  9687. distribution unpacked!  Solaris `tar' can't handle long file names, so
  9688. you may see an error like this when you unpack MySQL:
  9689.  
  9690.      x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,\
  9691.      informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
  9692.      tar: directory checksum error
  9693.  
  9694. In this case, you must use GNU `tar' (`gtar') to unpack the
  9695. distribution.  You can find a precompiled copy for Solaris at
  9696. `http://www.mysql.com/downloads/os-solaris.html'.
  9697.  
  9698. Sun native threads only work on Solaris 2.5 and higher.  For Version
  9699. 2.4 and earlier, MySQL will automatically use MIT-pthreads.  *Note
  9700. MIT-pthreads::.
  9701.  
  9702. If you get the following error from configure:
  9703.  
  9704.      checking for restartable system calls... configure: error can not run test
  9705.      programs while cross compiling
  9706.  
  9707. This means that you have something wrong with your compiler
  9708. installation!  In this case you should upgrade your compiler to a newer
  9709. version.  You may also be able to solve this problem by inserting the
  9710. following row into the `config.cache' file:
  9711.  
  9712.      ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
  9713.  
  9714. If you are using Solaris on a SPARC, the recommended compiler is `gcc'
  9715. 2.95.2 or 3.2. You can find this at `http://gcc.gnu.org/'.  Note that
  9716. `egcs' 1.1.1 and `gcc' 2.8.1 don't work reliably on SPARC!
  9717.  
  9718. The recommended `configure' line when using `gcc' 2.95.2 is:
  9719.  
  9720.      CC=gcc CFLAGS="-O3" \
  9721.      CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
  9722.      ./configure --prefix=/usr/local/mysql --with-low-memory --enable-assembler
  9723.  
  9724. If you have an UltraSPARC, you can get 4% more performance by adding
  9725. "-mcpu=v8 -Wa,-xarch=v8plusa" to CFLAGS and CXXFLAGS.
  9726.  
  9727. If you have Sun's Forte 5.0 (or newer) compiler, you can run
  9728. `configure' like this:
  9729.  
  9730.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt" \
  9731.      CXX=CC CXXFLAGS="-noex -mt" \
  9732.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9733.  
  9734. You can create a 64 bit binary using Sun's Forte compiler with the
  9735. following compile flags:
  9736.  
  9737.      CC=cc CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
  9738.      CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS="-xarch=v9" \
  9739.      ./configure --prefix=/usr/local/mysql --enable-assembler
  9740.  
  9741. To create a 64bit Solaris binary using `gcc', add `-m64' to `CFLAGS'
  9742. and `CXXFLAGS'. Note that this only works with MySQL 4.0 and up - MySQL
  9743. 3.23 does not include the required modifications to support this.
  9744.  
  9745. In the MySQL benchmarks, we got a 4% speedup on an UltraSPARC when using
  9746. Forte 5.0 in 32 bit mode compared to using gcc 3.2 with -mcpu flags.
  9747.  
  9748. If you create a 64 bit binary, it's 4 % slower than the 32 bit binary,
  9749. but `mysqld' can instead handle more treads and memory.
  9750.  
  9751. If you get a problem with `fdatasync' or `sched_yield', you can fix
  9752. this by adding `LIBS=-lrt' to the configure line
  9753.  
  9754. The following paragraph is only relevant for older compilers than
  9755. WorkShop 5.3:
  9756.  
  9757. You may also have to edit the `configure' script to change this line:
  9758.  
  9759.      #if !defined(__STDC__) || __STDC__ != 1
  9760.  
  9761. to this:
  9762.  
  9763.      #if !defined(__STDC__)
  9764.  
  9765. If you turn on `__STDC__' with the `-Xc' option, the Sun compiler can't
  9766. compile with the Solaris `pthread.h' header file.  This is a Sun bug
  9767. (broken compiler or broken include file).
  9768.  
  9769. If `mysqld' issues the error message shown here when you run it, you
  9770. have tried to compile MySQL with the Sun compiler without enabling the
  9771. multi-thread option (`-mt'):
  9772.  
  9773.      libc internal error: _rmutex_unlock: rmutex not held
  9774.  
  9775. Add `-mt' to `CFLAGS' and `CXXFLAGS' and try again.
  9776.  
  9777. If you are using the SFW version of gcc (which comes with Solaris 8),
  9778. you must add `/opt/sfw/lib' to the environment variable
  9779. `LD_LIBRARY_PATH' before running configure.
  9780.  
  9781. If you are using the gcc available from `sunfreeware.com', you may have
  9782. many problems.  You should recompile gcc and GNU binutils on the
  9783. machine you will be running them from to avoid any problems.
  9784.  
  9785. If you get the following error when compiling MySQL with `gcc', it
  9786. means that your `gcc' is not configured for your version of Solaris:
  9787.  
  9788.      shell> gcc -O3 -g -O2 -DDBUG_OFF  -o thr_alarm ...
  9789.      ./thr_alarm.c: In function `signal_hand':
  9790.      ./thr_alarm.c:556: too many arguments to function `sigwait'
  9791.  
  9792. The proper thing to do in this case is to get the newest version of
  9793. `gcc' and compile it with your current `gcc' compiler!  At least for
  9794. Solaris 2.5, almost all binary versions of `gcc' have old, unusable
  9795. include files that will break all programs that use threads (and
  9796. possibly other programs)!
  9797.  
  9798. Solaris doesn't provide static versions of all system libraries
  9799. (`libpthreads' and `libdl'), so you can't compile MySQL with
  9800. `--static'.  If you try to do so, you will get the error:
  9801.  
  9802.      ld: fatal: library -ldl: not found
  9803.      
  9804.      or
  9805.      
  9806.      undefined reference to `dlopen'
  9807.      
  9808.      or
  9809.      
  9810.      cannot find -lrt
  9811.  
  9812. If too many processes try to connect very rapidly to `mysqld', you will
  9813. see this error in the MySQL log:
  9814.  
  9815.      Error in accept: Protocol error
  9816.  
  9817. You might try starting the server with the `--set-variable back_log=50'
  9818. option as a workaround for this. Please note that `--set-variable' is
  9819. deprecated since MySQL 4.0, just use `--back_log=50' on its own.  *Note
  9820. Command-line options::.
  9821.  
  9822. If you are linking your own MySQL client, you might get the following
  9823. error when you try to execute it:
  9824.  
  9825.      ld.so.1: ./my: fatal: libmysqlclient.so.#:
  9826.      open failed: No such file or directory
  9827.  
  9828. The problem can be avoided by one of the following methods:
  9829.  
  9830.    * Link the client with the following flag (instead of `-Lpath'):
  9831.      `-Wl,r/full-path-to-libmysqlclient.so'.
  9832.  
  9833.    * Copy `libmysqclient.so' to `/usr/lib'.
  9834.  
  9835.    * Add the pathname of the directory where `libmysqlclient.so' is
  9836.      located to the `LD_RUN_PATH' environment variable before running
  9837.      your client.
  9838.  
  9839. If you have problems with configure trying to link with `-lz' and you
  9840. don't have `zlib' installed, you have two options:
  9841.  
  9842.    * If you want to be able to use the compressed communication
  9843.      protocol, you need to get and install zlib from ftp.gnu.org.
  9844.  
  9845.    * Configure with `--with-named-z-libs=no'.
  9846.  
  9847. If you are using gcc and have problems with loading user defined
  9848. functions (`UDF's) into MySQL, try adding `-lgcc' to the link line for
  9849. the `UDF'.
  9850.  
  9851. If you would like MySQL to start automatically, you can copy
  9852. `support-files/mysql.server' to `/etc/init.d' and create a symbolic
  9853. link to it named `/etc/rc3.d/S99mysql.server'.
  9854.  
  9855. As Solaris doesn't support core files for `setuid()' applications, you
  9856. can't get a core file from `mysqld' if you are using the `--user'
  9857. option.
  9858.  
  9859. Solaris 2.7/2.8 Notes
  9860. .....................
  9861.  
  9862. You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8.  Most
  9863. of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
  9864.  
  9865. Note that MySQL Version 3.23.4 and above should be able to autodetect
  9866. new versions of Solaris and enable workarounds for the following
  9867. problems!
  9868.  
  9869. Solaris 2.7 / 2.8 has some bugs in the include files.  You may see the
  9870. following error when you use `gcc':
  9871.  
  9872.      /usr/include/widec.h:42: warning: `getwc' redefined
  9873.      /usr/include/wchar.h:326: warning: this is the location of the previous
  9874.      definition
  9875.  
  9876. If this occurs, you can do the following to fix the problem:
  9877.  
  9878. Copy `/usr/include/widec.h' to `.../lib/gcc-lib/os/gcc-version/include'
  9879. and change line 41 from:
  9880.  
  9881.      #if     !defined(lint) && !defined(__lint)
  9882.      
  9883.      to
  9884.      
  9885.      #if     !defined(lint) && !defined(__lint) && !defined(getwc)
  9886.  
  9887. Alternatively, you can edit `/usr/include/widec.h' directly.  Either
  9888. way, after you make the fix, you should remove `config.cache' and run
  9889. `configure' again!
  9890.  
  9891. If you get errors like this when you run `make', it's because
  9892. `configure' didn't detect the `curses.h' file (probably because of the
  9893. error in `/usr/include/widec.h'):
  9894.  
  9895.      In file included from mysql.cc:50:
  9896.      /usr/include/term.h:1060: syntax error before `,'
  9897.      /usr/include/term.h:1081: syntax error before `;'
  9898.  
  9899. The solution to this is to do one of the following:
  9900.  
  9901.    * Configure with `CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H
  9902.      ./configure'.
  9903.  
  9904.    * Edit `/usr/include/widec.h' as indicted above and rerun configure.
  9905.  
  9906.    * Remove the `#define HAVE_TERM' line from `config.h' file and run
  9907.      `make' again.
  9908.  
  9909. If you get a problem that your linker can't find `-lz' when linking
  9910. your client program, the problem is probably that your `libz.so' file is
  9911. installed in `/usr/local/lib'.  You can fix this by one of the
  9912. following methods:
  9913.  
  9914.    * Add `/usr/local/lib' to `LD_LIBRARY_PATH'.
  9915.  
  9916.    * Add a link to `libz.so' from `/lib'.
  9917.  
  9918.    * If you are using Solaris 8, you can install the optional zlib from
  9919.      your Solaris 8 CD distribution.
  9920.  
  9921.    * Configure MySQL with the `--with-named-z-libs=no' option.
  9922.  
  9923. Solaris x86 Notes
  9924. .................
  9925.  
  9926. On Solaris 8 on x86, `mysqld' will dump core if you remove the debug
  9927. symbols using `strip'.
  9928.  
  9929. If you are using `gcc' or `egcs' on Solaris x86 and you experience
  9930. problems with core dumps under load, you should use the following
  9931. `configure' command:
  9932.  
  9933.      CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
  9934.      CXX=gcc \
  9935.      CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors -fno-exceptions \
  9936.      -fno-rtti -DHAVE_CURSES_H" \
  9937.      ./configure --prefix=/usr/local/mysql
  9938.  
  9939. This will avoid problems with the `libstdc++' library and with C++
  9940. exceptions.
  9941.  
  9942. If this doesn't help, you should compile a debug version and run it
  9943. with a trace file or under `gdb'.  *Note Using gdb on mysqld::.
  9944.  
  9945. BSD Notes
  9946. ---------
  9947.  
  9948. This section provides information for the various BSD flavours, as well
  9949. as specific versions within those.
  9950.  
  9951. FreeBSD Notes
  9952. .............
  9953.  
  9954. FreeBSD 4.x or newer is recommended for running MySQL since the thread
  9955. package is much more integrated.
  9956.  
  9957. The easiest and therefore the preferred way to install is to use the
  9958. mysql-server and mysql-client ports available on
  9959. `http://www.freebsd.org/'.
  9960.  
  9961. Using these gives you:
  9962.    * A working MySQL with all optimisations known to work on your
  9963.      version of FreeBSD enabled.
  9964.  
  9965.    * Automatic configuration and build.
  9966.  
  9967.    * Startup scripts installed in /usr/local/etc/rc.d.
  9968.  
  9969.    * Ability to see which files that are installed with pkg_info -L.
  9970.      And to remove them all with pkg_delete if you no longer want MySQL
  9971.      on that machine.
  9972.  
  9973. It is recommended you use MIT-pthreads on FreeBSD 2.x and native
  9974. threads on Versions 3 and up. It is possible to run with native threads
  9975. on some late 2.2.x versions but you may encounter problems shutting
  9976. down `mysqld'.
  9977.  
  9978. Unfortunately, certain function calls on FreeBSD are not yet fully
  9979. thread-safe, most notably the `gethostbyname()' function, which is used
  9980. by MySQL to convert host names into IP addresses. Under certain
  9981. circumstances, the `mysqld' process will suddenly cause 100% CPU load
  9982. and will be unresponsive. If you encounter this, try to start up MySQL
  9983. using the `--skip-name-resolve' option.
  9984.  
  9985. Alternatively, you can link MySQL on FreeBSD 4.x against the
  9986. LinuxThreads library, which avoids a few of the problems that the
  9987. native FreeBSD thread implementation has. For a very good comparison of
  9988. LinuxThreads vs. native threads have a look at Jeremy Zawodny's article
  9989. "FreeBSD or Linux for your MySQL Server?" at
  9990. `http://jeremy.zawodny.com/blog/archives/000697.html'
  9991.  
  9992. The known problems when using LinuxThreads on FreeBSD are:
  9993.  
  9994.    * `wait_timeout' is not working (probably signal handling problem in
  9995.      FreeBSD/LinuxThreads).  This is supposed to get fixed in FreeBSD
  9996.      5.0.  The symptom is that persistent connections can hang for *a
  9997.      long* time without getting closed done.
  9998.  
  9999. The MySQL `Makefile's require GNU make (`gmake') to work.  If you want
  10000. to compile MySQL you need to install GNU `make' first.
  10001.  
  10002. Be sure to have your name resolver setup correct.  Otherwise, you may
  10003. experience resolver delays or failures when connecting to `mysqld'.
  10004.  
  10005. Make sure that the `localhost' entry in the `/etc/hosts' file is
  10006. correct (otherwise, you will have problems connecting to the database).
  10007. The `/etc/hosts' file should start with a line:
  10008.  
  10009.      127.0.0.1       localhost localhost.your.domain
  10010.  
  10011. The recommended way to compile and install MySQL on FreeBSD with gcc
  10012. (2.95.2 and up) is:
  10013.  
  10014.      CC=gcc CFLAGS="-O2 -fno-strength-reduce" \
  10015.      CXX=gcc CXXFLAGS="-O2 -fno-rtti -fno-exceptions -felide-constructors \
  10016.      -fno-strength-reduce" \
  10017.      ./configure --prefix=/usr/local/mysql --enable-assembler
  10018.      gmake
  10019.      gmake install
  10020.      ./scripts/mysql_install_db
  10021.      cd /usr/local/mysql
  10022.      ./bin/mysqld_safe &
  10023.  
  10024. If you notice that `configure' will use MIT-pthreads, you should read
  10025. the MIT-pthreads notes.  *Note MIT-pthreads::.
  10026.  
  10027. If you get an error from `make install' that it can't find
  10028. `/usr/include/pthreads', `configure' didn't detect that you need
  10029. MIT-pthreads.  This is fixed by executing these commands:
  10030.  
  10031.      shell> rm config.cache
  10032.      shell> ./configure --with-mit-threads
  10033.  
  10034. FreeBSD is also known to have a very low default file handle limit.
  10035. *Note Not enough file handles::.  Uncomment the `ulimit -n' section in
  10036. `mysqld_safe' or raise the limits for the `mysqld' user in
  10037. /etc/login.conf (and rebuild it with cap_mkdb /etc/login.conf).  Also
  10038. be sure you set the appropriate class for this user in the password
  10039. file if you are not using the default (use: chpass mysqld-user-name).
  10040. *Note `mysqld_safe': mysqld_safe.
  10041.  
  10042. If you have a lot of memory you should consider rebuilding the kernel
  10043. to allow MySQL to take more than 512M of RAM.  Take a look at `option
  10044. MAXDSIZ' in the LINT config file for more info.
  10045.  
  10046. If you get problems with the current date in MySQL, setting the `TZ'
  10047. variable will probably help.  *Note Environment variables::.
  10048.  
  10049. To get a secure and stable system you should only use FreeBSD kernels
  10050. that are marked `-RELEASE'.
  10051.  
  10052. NetBSD Notes
  10053. ............
  10054.  
  10055. To compile on NetBSD you need GNU `make'. Otherwise, the compile will
  10056. crash when `make' tries to run `lint' on C++ files.
  10057.  
  10058. OpenBSD 2.5 Notes
  10059. .................
  10060.  
  10061. On OpenBSD Version 2.5, you can compile MySQL with native threads with
  10062. the following options:
  10063.  
  10064.      CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
  10065.  
  10066. OpenBSD 2.8 Notes
  10067. .................
  10068.  
  10069. Our users have reported that OpenBSD 2.8 has a threading bug which
  10070. causes problems with MySQL.  The OpenBSD Developers have fixed the
  10071. problem, but as of January 25th, 2001, it's only available in the
  10072. "-current" branch.  The symptoms of this threading bug are: slow
  10073. response, high load, high CPU usage, and crashes.
  10074.  
  10075. If you get an error like `Error in accept:: Bad file descriptor' or
  10076. error 9 when trying to open tables or directories, the problem is
  10077. probably that you haven't allocated enough file descriptors for MySQL.
  10078.  
  10079. In this case, try starting `mysqld_safe' as `root' with the following
  10080. options:
  10081.  
  10082.      shell> mysqld_safe --user=mysql --open-files-limit=2048 &
  10083.  
  10084. BSD/OS Version 2.x Notes
  10085. ........................
  10086.  
  10087. If you get the following error when compiling MySQL, your `ulimit'
  10088. value for virtual memory is too low:
  10089.  
  10090.      item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
  10091.      item_func.h:28: virtual memory exhausted
  10092.      make[2]: *** [item_func.o] Error 1
  10093.  
  10094. Try using `ulimit -v 80000' and run `make' again.  If this doesn't work
  10095. and you are using `bash', try switching to `csh' or `sh'; some BSDI
  10096. users have reported problems with `bash' and `ulimit'.
  10097.  
  10098. If you are using `gcc', you may also use have to use the
  10099. `--with-low-memory' flag for `configure' to be able to compile
  10100. `sql_yacc.cc'.
  10101.  
  10102. If you get problems with the current date in MySQL, setting the `TZ'
  10103. variable will probably help.  *Note Environment variables::.
  10104.  
  10105. BSD/OS Version 3.x Notes
  10106. ........................
  10107.  
  10108. Upgrade to BSD/OS Version 3.1.  If that is not possible, install
  10109. BSDIpatch M300-038.
  10110.  
  10111. Use the following command when configuring MySQL:
  10112.  
  10113.      shell> env CXX=shlicc++ CC=shlicc2 \
  10114.             ./configure \
  10115.                 --prefix=/usr/local/mysql \
  10116.                 --localstatedir=/var/mysql \
  10117.                 --without-perl \
  10118.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10119.  
  10120. The following is also known to work:
  10121.  
  10122.      shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
  10123.             ./configure \
  10124.                 --prefix=/usr/local/mysql \
  10125.                 --with-unix-socket-path=/var/mysql/mysql.sock
  10126.  
  10127. You can change the directory locations if you wish, or just use the
  10128. defaults by not specifying any locations.
  10129.  
  10130. If you have problems with performance under heavy load, try using the
  10131. `--skip-thread-priority' option to `mysqld'!  This will run all threads
  10132. with the same priority; on BSDI Version 3.1, this gives better
  10133. performance (at least until BSDI fixes their thread scheduler).
  10134.  
  10135. If you get the error `virtual memory exhausted' while compiling, you
  10136. should try using `ulimit -v 80000' and run `make' again.  If this
  10137. doesn't work and you are using `bash', try switching to `csh' or `sh';
  10138. some BSDI users have reported problems with `bash' and `ulimit'.
  10139.  
  10140. BSD/OS Version 4.x Notes
  10141. ........................
  10142.  
  10143. BSDI Version 4.x has some thread-related bugs.  If you want to use
  10144. MySQL on this, you should install all thread-related patches.  At least
  10145. M400-023 should be installed.
  10146.  
  10147. On some BSDI Version 4.x systems, you may get problems with shared
  10148. libraries.  The symptom is that you can't execute any client programs,
  10149. for example, `mysqladmin'.  In this case you need to reconfigure not to
  10150. use shared libraries with the `--disable-shared' option to configure.
  10151.  
  10152. Some customers have had problems on BSDI 4.0.1 that the `mysqld' binary
  10153. after a while can't open tables.  This is because some library/system
  10154. related bug causes `mysqld' to change current directory without asking
  10155. for this!
  10156.  
  10157. The fix is to either upgrade to 3.23.34 or after running `configure'
  10158. remove the line `#define HAVE_REALPATH' from `config.h' before running
  10159. make.
  10160.  
  10161. Note that the above means that you can't symbolic link a database
  10162. directories to another database directory or symbolic link a table to
  10163. another database on BSDI!  (Making a symbolic link to another disk is
  10164. okay).
  10165.  
  10166. Mac OS X Notes
  10167. --------------
  10168.  
  10169. Mac OS X 10.x
  10170. .............
  10171.  
  10172. MySQL should work without any problems on Mac OS X 10.x (Darwin). You
  10173. don't need the pthread patches for this OS!
  10174.  
  10175. This also applies to Mac OS X 10.x Server. Compiling for the Server
  10176. platform is the same as for the client version of Mac OS X. However
  10177. please note that MySQL comes preinstalled on the Server!
  10178.  
  10179. Our binary for Mac OS X is compiled on Darwin 6.3 with the following
  10180. configure line:
  10181.  
  10182.      CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
  10183.      CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
  10184.      -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
  10185.      --with-extra-charsets=complex --enable-thread-safe-client \
  10186.      --enable-local-infile --disable-shared
  10187.  
  10188. *Note Mac OS X installation::.
  10189.  
  10190. Mac OS X Server 1.2 (Rhapsody)
  10191. ..............................
  10192.  
  10193. Before trying to configure MySQL on Mac OS X Server 1.2 (aka Rhapsody)
  10194. you must first install the pthread package from
  10195. `http://www.prnet.de/RegEx/mysql.html'.
  10196.  
  10197. *Note Mac OS X installation::.
  10198.  
  10199. Other Unix Notes
  10200. ----------------
  10201.  
  10202. HP-UX Notes for Binary Distributions
  10203. ....................................
  10204.  
  10205. Some of the binary distributions of MySQL for HP-UX are distributed as
  10206. an HP depot file and as a tar file.  To use the depot file you must be
  10207. running at least HP-UX 10.x to have access to HP's software depot tools.
  10208.  
  10209. The HP version of MySQL was compiled on an HP 9000/8xx server under
  10210. HP-UX 10.20, and uses MIT-pthreads.  It is known to work well under
  10211. this configuration.  MySQL Version 3.22.26 and newer can also be built
  10212. with HP's native thread package.
  10213.  
  10214. Other configurations that may work:
  10215.  
  10216.    * HP 9000/7xx running HP-UX 10.20+
  10217.  
  10218.    * HP 9000/8xx running HP-UX 10.30
  10219.  
  10220. The following configurations almost definitely won't work:
  10221.  
  10222.    * HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
  10223.  
  10224.    * HP 9000/7xx or 8xx running HP-UX 9.x
  10225.  
  10226. To install the distribution, use one of the commands here, where
  10227. `/path/to/depot' is the full pathname of the depot file:
  10228.  
  10229.    * To install everything, including the server, client and
  10230.      development tools:
  10231.  
  10232.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
  10233.  
  10234.    * To install only the server:
  10235.  
  10236.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
  10237.  
  10238.    * To install only the client package:
  10239.  
  10240.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
  10241.  
  10242.    * To install only the development tools:
  10243.  
  10244.           shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
  10245.  
  10246. The depot places binaries and libraries in `/opt/mysql' and data in
  10247. `/var/opt/mysql'. The depot also creates the appropriate entries in
  10248. `/etc/init.d' and `/etc/rc2.d' to start the server automatically at
  10249. boot time.  Obviously, this entails being `root' to install.
  10250.  
  10251. To install the HP-UX tar.gz distribution, you must have a copy of GNU
  10252. `tar'.
  10253.  
  10254. HP-UX Version 10.20 Notes
  10255. .........................
  10256.  
  10257. There are a couple of small problems when compiling MySQL on HP-UX.  We
  10258. recommend that you use `gcc' instead of the HP-UX native compiler,
  10259. because `gcc' produces better code!
  10260.  
  10261. We recommend using `gcc' 2.95 on HP-UX.  Don't use high optimisation
  10262. flags (like -O6) as this may not be safe on HP-UX.
  10263.  
  10264. The following `configure' line should work with `gcc' 2.95:
  10265.  
  10266.      CFLAGS="-I/opt/dce/include -fpic" \
  10267.      CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
  10268.      -fno-rtti" CXX=gcc ./configure --with-pthread \
  10269.      --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
  10270.  
  10271. The following `configure' line should work with `gcc' 3.1:
  10272.  
  10273.      CFLAGS="-DHPUX -I/opt/dce/include -O3 -fPIC" CXX=gcc \
  10274.      CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions \
  10275.      -fno-rtti -O3 -fPIC" ./configure --prefix=/usr/local/mysql \
  10276.      --with-extra-charsets=complex --enable-thread-safe-client \
  10277.      --enable-local-infile  --with-pthread \
  10278.      --with-named-thread-libs=-ldce --with-lib-ccflags=-fPIC
  10279.      --disable-shared
  10280.  
  10281. HP-UX Version 11.x Notes
  10282. ........................
  10283.  
  10284. For HP-UX Version 11.x, we recommend MySQL Version 3.23.15 or later.
  10285.  
  10286. Because of some critical bugs in the standard HP-UX libraries, you
  10287. should install the following patches before trying to run MySQL on
  10288. HP-UX 11.0:
  10289.  
  10290.      PHKL_22840 Streams cumulative
  10291.      PHNE_22397 ARPA cumulative
  10292.  
  10293. This will solve the problem of getting `EWOULDBLOCK' from `recv()' and
  10294. `EBADF' from `accept()' in threaded applications.
  10295.  
  10296. If you are using `gcc' 2.95.1 on an unpatched HP-UX 11.x system, you
  10297. will get the error:
  10298.  
  10299.      In file included from /usr/include/unistd.h:11,
  10300.                       from ../include/global.h:125,
  10301.                       from mysql_priv.h:15,
  10302.                       from item.cc:19:
  10303.      /usr/include/sys/unistd.h:184: declaration of C function ...
  10304.      /usr/include/sys/pthread.h:440: previous declaration ...
  10305.      In file included from item.h:306,
  10306.                       from mysql_priv.h:158,
  10307.                       from item.cc:19:
  10308.  
  10309. The problem is that HP-UX doesn't define `pthreads_atfork()'
  10310. consistently.  It has conflicting prototypes in
  10311. `/usr/include/sys/unistd.h':184 and `/usr/include/sys/pthread.h':440
  10312. (details below).
  10313.  
  10314. One solution is to copy `/usr/include/sys/unistd.h' into
  10315. `mysql/include' and edit `unistd.h' and change it to match the
  10316. definition in `pthread.h'.  Here's the diff:
  10317.  
  10318.      183,184c183,184
  10319.      <      extern int pthread_atfork(void (*prepare)(), void (*parent)(),
  10320.      <                                                void (*child)());
  10321.      ---
  10322.      >      extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
  10323.      >                                                void (*child)(void));
  10324.  
  10325. After this, the following configure line should work:
  10326.  
  10327.      CFLAGS="-fomit-frame-pointer -O3 -fpic" CXX=gcc \
  10328.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O3" \
  10329.      ./configure --prefix=/usr/local/mysql --disable-shared
  10330.  
  10331. If you are using MySQL 4.0.5 with the HP-UX compiler you can use:
  10332. (tested with cc B.11.11.04):
  10333.  
  10334.      CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure --with-extra-character-set=complex
  10335.  
  10336. You can ignore any errors of the following type:
  10337.  
  10338.      aCC: warning 901: unknown option: `-3': use +help for online documentation
  10339.  
  10340. If you get the following error from `configure'
  10341.  
  10342.      checking for cc option to accept ANSI C... no
  10343.      configure: error: MySQL requires a ANSI C compiler (and a C++ compiler).
  10344.      Try gcc. See the Installation chapter in the Reference Manual.
  10345.  
  10346. Check that you don't have the path to the K&R compiler before the path
  10347. to the HP-UX C and C++ compiler.
  10348.  
  10349. Another reason for not beeing able to compile is that you didn't define
  10350. the `+DD64' flags above.
  10351.  
  10352. Another possibility for HP-UX 11 is to use MySQL binaries for HP-UX
  10353. 10.20.  We have received reports from some users that these binaries
  10354. work fine on HP-UX 11.00. If you encounter problems, be sure to check
  10355. your HP-UX patch level.
  10356.  
  10357. IBM-AIX notes
  10358. .............
  10359.  
  10360. Automatic detection of `xlC' is missing from Autoconf, so a `configure'
  10361. command something like this is needed when compiling MySQL (This
  10362. example uses the IBM compiler):
  10363.  
  10364.      export CC="xlc_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192 "
  10365.      export CXX="xlC_r -ma -O3 -qstrict -qoptimize=3 -qmaxmem=8192"
  10366.      export CFLAGS="-I /usr/local/include"
  10367.      export LDFLAGS="-L /usr/local/lib"
  10368.      export CPPFLAGS=$CFLAGS
  10369.      export CXXFLAGS=$CFLAGS
  10370.      
  10371.      ./configure --prefix=/usr/local \
  10372.                      --localstatedir=/var/mysql \
  10373.                      --sysconfdir=/etc/mysql \
  10374.                      --sbindir='/usr/local/bin' \
  10375.                      --libexecdir='/usr/local/bin' \
  10376.                      --enable-thread-safe-client \
  10377.                      --enable-large-files
  10378.  
  10379. Above are the options used to compile the MySQL distribution that can
  10380. be found at `http://www-frec.bull.com/'.
  10381.  
  10382. If you change the `-O3' to `-O2' in the above configure line, you must
  10383. also remove the `-qstrict' option (this is a limitation in the IBM C
  10384. compiler).
  10385.  
  10386. If you are using `gcc' or `egcs' to compile MySQL, you *must* use the
  10387. `-fno-exceptions' flag, as the exception handling in `gcc'/`egcs' is
  10388. not thread-safe!  (This is tested with `egcs' 1.1.)  There are also
  10389. some known problems with IBM's assembler, which may cause it to
  10390. generate bad code when used with gcc.
  10391.  
  10392. We recommend the following `configure' line with `egcs' and `gcc 2.95'
  10393. on AIX:
  10394.  
  10395.      CC="gcc -pipe -mcpu=power -Wa,-many" \
  10396.      CXX="gcc -pipe -mcpu=power -Wa,-many" \
  10397.      CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \
  10398.      ./configure --prefix=/usr/local/mysql --with-low-memory
  10399.  
  10400. The `-Wa,-many' is necessary for the compile to be successful.  IBM is
  10401. aware of this problem but is in to hurry to fix it because of the
  10402. workaround available.  We don't know if the `-fno-exceptions' is
  10403. required with `gcc 2.95', but as MySQL doesn't use exceptions and the
  10404. above option generates faster code, we recommend that you should always
  10405. use this option with `egcs / gcc'.
  10406.  
  10407. If you get a problem with assembler code try changing the -mcpu=xxx to
  10408. match your CPU. Typically power2, power, or powerpc may need to be used,
  10409. alternatively you might need to use 604 or 604e. I'm not positive but I
  10410. would think using "power" would likely be safe most of the time, even on
  10411. a power2 machine.
  10412.  
  10413. If you don't know what your CPU is then do a "uname -m", this will give
  10414. you back a string that looks like "000514676700", with a format of
  10415. xxyyyyyymmss where xx and ss are always 0's, yyyyyy is a unique system
  10416. ID and mm is the ID of the CPU Planar. A chart of these values can be
  10417. found at
  10418. `http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm'.
  10419. This will give you a machine type and a machine model you can use to
  10420. determine what type of CPU you have.
  10421.  
  10422. If you have problems with signals (MySQL dies unexpectedly under high
  10423. load) you may have found an OS bug with threads and signals.  In this
  10424. case you can tell MySQL not to use signals by configuring with:
  10425.  
  10426.      shell> CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
  10427.             CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
  10428.             -DDONT_USE_THR_ALARM" \
  10429.             ./configure --prefix=/usr/local/mysql --with-debug --with-low-memory
  10430.  
  10431. This doesn't affect the performance of MySQL, but has the side effect
  10432. that you can't kill clients that are "sleeping" on a connection with
  10433. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  10434. die when it issues its next command.
  10435.  
  10436. On some versions of AIX, linking with `libbind.a' makes `getservbyname'
  10437. core dump.  This is an AIX bug and should be reported to IBM.
  10438.  
  10439. For AIX 4.2.1 and gcc you have to do the following changes.
  10440.  
  10441. After configuring, edit `config.h' and `include/my_config.h' and change
  10442. the line that says
  10443.  
  10444.      #define HAVE_SNPRINTF 1
  10445.  
  10446. to
  10447.  
  10448.      #undef HAVE_SNPRINTF
  10449.  
  10450. And finally, in `mysqld.cc' you need to add a prototype for initgoups.
  10451.  
  10452.      #ifdef _AIX41
  10453.      extern "C" int initgroups(const char *,int);
  10454.      #endif
  10455.  
  10456. If you need to allocate a lot of memory to the mysqld process, it's not
  10457. enough to just set 'ulimit -d unlimited'. You may also have to set in
  10458. `mysqld_safe' something like:
  10459.  
  10460.      export LDR_CNTRL='MAXDATA=0x80000000'
  10461.  
  10462. You can find more about using a lot of memory at:
  10463. `http://publib16.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/lrg_prg_support.htm'.
  10464.  
  10465. SunOS 4 Notes
  10466. .............
  10467.  
  10468. On SunOS 4, MIT-pthreads is needed to compile MySQL, which in turn
  10469. means you will need GNU `make'.
  10470.  
  10471. Some SunOS 4 systems have problems with dynamic libraries and `libtool'.
  10472. You can use the following `configure' line to avoid this problem:
  10473.  
  10474.      shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
  10475.  
  10476. When compiling `readline', you may get warnings about duplicate defines.
  10477. These may be ignored.
  10478.  
  10479. When compiling `mysqld', there will be some `implicit declaration of
  10480. function' warnings. These may be ignored.
  10481.  
  10482. Alpha-DEC-UNIX Notes (Tru64)
  10483. ............................
  10484.  
  10485. If you are using egcs 1.1.2 on Digital Unix, you should upgrade to gcc
  10486. 2.95.2, as egcs on DEC has some serious bugs!
  10487.  
  10488. When compiling threaded programs under Digital Unix, the documentation
  10489. recommends using the `-pthread' option for `cc' and `cxx' and the
  10490. libraries `-lmach -lexc' (in addition to `-lpthread').  You should run
  10491. `configure' something like this:
  10492.  
  10493.      CC="cc -pthread" CXX="cxx -pthread -O" \
  10494.      ./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  10495.  
  10496. When compiling `mysqld', you may see a couple of warnings like this:
  10497.  
  10498.      mysqld.cc: In function void handle_connections()':
  10499.      mysqld.cc:626: passing long unsigned int *' as argument 3 of
  10500.      accept(int,sockadddr *, int *)'
  10501.  
  10502. You can safely ignore these warnings.  They occur because `configure'
  10503. can detect only errors, not warnings.
  10504.  
  10505. If you start the server directly from the command-line, you may have
  10506. problems with it dying when you log out.  (When you log out, your
  10507. outstanding processes receive a `SIGHUP' signal.)  If so, try starting
  10508. the server like this:
  10509.  
  10510.      shell> nohup mysqld [options] &
  10511.  
  10512. `nohup' causes the command following it to ignore any `SIGHUP' signal
  10513. sent from the terminal.  Alternatively, start the server by running
  10514. `mysqld_safe', which invokes `mysqld' using `nohup' for you.  *Note
  10515. `mysqld_safe': mysqld_safe.
  10516.  
  10517. If you get a problem when compiling mysys/get_opt.c, just remove the
  10518. line #define _NO_PROTO from the start of that file!
  10519.  
  10520. If you are using Compaq's CC compiler, the following configure line
  10521. should work:
  10522.  
  10523.      CC="cc -pthread"
  10524.      CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
  10525.      CXX="cxx -pthread"
  10526.      CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host \
  10527.      -noexceptions -nortti"
  10528.      export CC CFLAGS CXX CXXFLAGS
  10529.      ./configure \
  10530.      --prefix=/usr/local/mysql \
  10531.      --with-low-memory \
  10532.      --enable-large-files \
  10533.      --enable-shared=yes \
  10534.      --with-named-thread-libs="-lpthread -lmach -lexc -lc"
  10535.      gnumake
  10536.  
  10537. If you get a problem with libtool, when compiling with shared libraries
  10538. as above, when linking `mysql', you should be able to get around this
  10539. by issuing:
  10540.  
  10541.      cd mysql
  10542.      /bin/sh ../libtool --mode=link cxx -pthread  -O3 -DDBUG_OFF \
  10543.      -O4 -ansi_alias -ansi_args -fast -inline speed \
  10544.      -speculate all \ -arch host  -DUNDEF_HAVE_GETHOSTBYNAME_R \
  10545.      -o mysql  mysql.o readline.o sql_string.o completion_hash.o \
  10546.      ../readline/libreadline.a -lcurses \
  10547.      ../libmysql/.libs/libmysqlclient.so  -lm
  10548.      cd ..
  10549.      gnumake
  10550.      gnumake install
  10551.      scripts/mysql_install_db
  10552.  
  10553. Alpha-DEC-OSF/1 Notes
  10554. .....................
  10555.  
  10556. If you have problems compiling and have DEC `CC' and `gcc' installed,
  10557. try running `configure' like this:
  10558.  
  10559.      CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
  10560.      ./configure --prefix=/usr/local/mysql
  10561.  
  10562. If you get problems with the `c_asm.h' file, you can create and use a
  10563. 'dummy' `c_asm.h' file with:
  10564.  
  10565.      touch include/c_asm.h
  10566.      CC=gcc CFLAGS=-I./include \
  10567.      CXX=gcc CXXFLAGS=-O3 \
  10568.      ./configure --prefix=/usr/local/mysql
  10569.  
  10570. Note that the following problems with the `ld' program can be fixed by
  10571. downloading the latest DEC (Compaq) patch kit from:
  10572. `http://ftp.support.compaq.com/public/unix/'.
  10573.  
  10574. On OSF/1 V4.0D and compiler "DEC C V5.6-071 on Digital Unix V4.0 (Rev.
  10575. 878)" the compiler had some strange behaviour (undefined `asm' symbols).
  10576. `/bin/ld' also appears to be broken (problems with `_exit undefined'
  10577. errors occurring while linking `mysqld').  On this system, we have
  10578. managed to compile MySQL with the following `configure' line, after
  10579. replacing `/bin/ld' with the version from OSF 4.0C:
  10580.  
  10581.      CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
  10582.  
  10583. With the Digital compiler "C++ V6.1-029", the following should work:
  10584.  
  10585.      CC=cc -pthread
  10586.      CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  10587.             -arch host
  10588.      CXX=cxx -pthread
  10589.      CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all \
  10590.                -arch host -noexceptions -nortti
  10591.      export CC CFLAGS CXX CXXFLAGS
  10592.      ./configure --prefix=/usr/mysql/mysql --with-mysqld-ldflags=-all-static \
  10593.                  --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
  10594.  
  10595. In some versions of OSF/1, the `alloca()' function is broken. Fix this
  10596. by removing the line in `config.h' that defines `'HAVE_ALLOCA''.
  10597.  
  10598. The `alloca()' function also may have an incorrect prototype in
  10599. `/usr/include/alloca.h'.  This warning resulting from this can be
  10600. ignored.
  10601.  
  10602. `configure' will use the following thread libraries automatically:
  10603. `--with-named-thread-libs="-lpthread -lmach -lexc -lc"'.
  10604.  
  10605. When using `gcc', you can also try running `configure' like this:
  10606.  
  10607.      shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ...
  10608.  
  10609. If you have problems with signals (MySQL dies unexpectedly under high
  10610. load), you may have found an OS bug with threads and signals. In this
  10611. case you can tell MySQL not to use signals by configuring with:
  10612.  
  10613.      shell> CFLAGS=-DDONT_USE_THR_ALARM \
  10614.             CXXFLAGS=-DDONT_USE_THR_ALARM \
  10615.             ./configure ...
  10616.  
  10617. This doesn't affect the performance of MySQL, but has the side effect
  10618. that you can't kill clients that are "sleeping" on a connection with
  10619. `mysqladmin kill' or `mysqladmin shutdown'.  Instead, the client will
  10620. die when it issues its next command.
  10621.  
  10622. With `gcc' 2.95.2, you will probably run into the following compile
  10623. error:
  10624.  
  10625.      sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
  10626.      Please submit a full bug report.
  10627.  
  10628. To fix this you should change to the `sql' directory and do a "cut and
  10629. paste" of the last `gcc' line, but change `-O3' to `-O0' (or add `-O0'
  10630. immediately after `gcc' if you don't have any `-O' option on your
  10631. compile line).  After this is done you can just change back to the
  10632. top-level directly and run `make' again.
  10633.  
  10634. SGI Irix Notes
  10635. ..............
  10636.  
  10637. If you are using Irix Version 6.5.3 or newer `mysqld' will only be able
  10638. to create threads if you run it as a user with `CAP_SCHED_MGT'
  10639. privileges (like `root') or give the `mysqld' server this privilege
  10640. with the following shell command:
  10641.  
  10642.      shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
  10643.  
  10644. You may have to undefine some things in `config.h' after running
  10645. `configure' and before compiling.
  10646.  
  10647. In some Irix implementations, the `alloca()' function is broken.  If the
  10648. `mysqld' server dies on some `SELECT' statements, remove the lines from
  10649. `config.h' that define `HAVE_ALLOC' and `HAVE_ALLOCA_H'.  If
  10650. `mysqladmin create' doesn't work, remove the line from `config.h' that
  10651. defines `HAVE_READDIR_R'.  You may have to remove the `HAVE_TERM_H'
  10652. line as well.
  10653.  
  10654. SGI recommends that you install all of the patches on this page as a
  10655. set:
  10656. `http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html'
  10657.  
  10658. At the very minimum, you should install the latest kernel rollup, the
  10659. latest `rld' rollup, and the latest `libc' rollup.
  10660.  
  10661. You definitely need all the POSIX patches on this page, for pthreads
  10662. support:
  10663.  
  10664. `http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html'
  10665.  
  10666. If you get the something like the following error when compiling
  10667. `mysql.cc':
  10668.  
  10669.      "/usr/include/curses.h", line 82: error(1084): invalid combination of type
  10670.  
  10671. Type the following in the top-level directory of your MySQL source tree:
  10672.  
  10673.      shell> extra/replace bool curses_bool < /usr/include/curses.h \
  10674.      > include/curses.h
  10675.      shell> make
  10676.  
  10677. There have also been reports of scheduling problems.  If only one
  10678. thread is running, things go slow.  Avoid this by starting another
  10679. client.  This may lead to a 2-to-10-fold increase in execution speed
  10680. thereafter for the other thread.  This is a poorly understood problem
  10681. with Irix threads; you may have to improvise to find solutions until
  10682. this can be fixed.
  10683.  
  10684. If you are compiling with `gcc', you can use the following `configure'
  10685. command:
  10686.  
  10687.      CC=gcc CXX=gcc CXXFLAGS=-O3 \
  10688.      ./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
  10689.      --with-named-thread-libs=-lpthread
  10690.  
  10691. On Irix 6.5.11 with native Irix C and C++ compilers ver. 7.3.1.2, the
  10692. following is reported to work
  10693.  
  10694.      CC=cc CXX=CC CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
  10695.      -L/usr/local/lib' CXXFLAGS='-O3 -n32 -TARG:platform=IP22 \
  10696.      -I/usr/local/include -L/usr/local/lib' ./configure \
  10697.      --prefix=/usr/local/mysql --with-innodb --with-berkeley-db \
  10698.      --with-libwrap=/usr/local \
  10699.      --with-named-curses-libs=/usr/local/lib/libncurses.a
  10700.  
  10701. SCO Notes
  10702. .........
  10703.  
  10704. The current port is tested only on "sco3.2v5.0.5", "sco3.2v5.0.6" and
  10705. "sco3.2v5.0.7" systems.  There has also been a lot of progress on a
  10706. port to "sco 3.2v4.2".
  10707.  
  10708. For the moment the recommended compiler on OpenServer is gcc 2.95.2.
  10709. With this you should be able to compile MySQL with just:
  10710.  
  10711.      CC=gcc CXX=gcc ./configure ... (options)
  10712.  
  10713.   1. For OpenServer 5.0.x you need to use gcc-2.95.2p1 or newer from the
  10714.      Skunkware.  `http://www.sco.com/skunkware/' and choose browser
  10715.      OpenServer packages or by ftp to ftp2.caldera.com in the
  10716.      pub/skunkware/osr5/devtools/gcc directory.
  10717.  
  10718.   2. You need the port of GCC 2.5.x for this product and the Development
  10719.      system.  They are required on this version of SCO Unix.  You cannot
  10720.      just use the GCC Dev system.
  10721.  
  10722.   3. You should get the FSU Pthreads package and install it first.
  10723.      This can be found at
  10724.      `http://moss.csc.ncsu.edu/~mueller/ftp/pub/PART/pthreads.tar.gz'.
  10725.      You can also get a precompiled package from
  10726.      `http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz'.
  10727.  
  10728.   4. FSU Pthreads can be compiled with SCO Unix 4.2 with tcpip.  Or
  10729.      OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0), with the SCO
  10730.      Development System installed using a good port of GCC 2.5.x ODT or
  10731.      OS 3.0 you will need a good port of GCC 2.5.x There are a lot of
  10732.      problems without a good port.  The port for this product requires
  10733.      the SCO Unix Development system.  Without it, you are missing the
  10734.      libraries and the linker that is needed.
  10735.  
  10736.   5. To build FSU Pthreads on your system, do the following:
  10737.  
  10738.        1. Run `./configure' in the `threads/src' directory and select
  10739.           the SCO OpenServer option. This command copies
  10740.           `Makefile.SCO5' to `Makefile'.
  10741.  
  10742.        2. Run `make'.
  10743.  
  10744.        3. To install in the default `/usr/include' directory, login as
  10745.           root, then `cd' to the `thread/src' directory, and run `make
  10746.           install'.
  10747.  
  10748.   6. Remember to use GNU `make' when making MySQL.
  10749.  
  10750.   7. If you don't start `mysqld_safe' as `root', you probably will get
  10751.      only the default 110 open files per process.  `mysqld' will write
  10752.      a note about this in the log file.
  10753.  
  10754.   8. With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or
  10755.      newer.  You should also use gcc 2.95.2 or newer!
  10756.  
  10757.      The following `configure' command should work:
  10758.  
  10759.           shell> ./configure --prefix=/usr/local/mysql --disable-shared
  10760.  
  10761.   9. With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or
  10762.      newer.  The following `configure' command should work:
  10763.  
  10764.           shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
  10765.                  ./configure \
  10766.                      --prefix=/usr/local/mysql \
  10767.                      --with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
  10768.                      --with-named-curses-libs="-lcurses"
  10769.  
  10770.      You may get some problems with some include files. In this case,
  10771.      you can find new SCO-specific include files at
  10772.      `http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz'.
  10773.      You should unpack this file in the `include' directory of your
  10774.      MySQL source tree.
  10775.  
  10776. SCO development notes:
  10777.  
  10778.    * MySQL should automatically detect FSU Pthreads and link `mysqld'
  10779.      with `-lgthreads -lsocket -lgthreads'.
  10780.  
  10781.    * The SCO development libraries are re-entrant in FSU Pthreads.  SCO
  10782.      claim's that its libraries' functions are re-entrant, so they must
  10783.      be reentrant with FSU Pthreads.  FSU Pthreads on OpenServer tries
  10784.      to use the SCO scheme to make re-entrant libraries.
  10785.  
  10786.    * FSU Pthreads (at least the version at `http://www.mysql.com/')
  10787.      comes linked with GNU `malloc'.  If you encounter problems with
  10788.      memory usage, make sure that `gmalloc.o' is included in
  10789.      `libgthreads.a' and `libgthreads.so'.
  10790.  
  10791.    * In FSU Pthreads, the following system calls are pthreads-aware:
  10792.      `read()', `write()', `getmsg()', `connect()', `accept()',
  10793.      `select()', and `wait()'.
  10794.  
  10795.    * The CSSA-2001-SCO.35.2 (the patch is listed in custom as
  10796.      erg711905-dscr_remap security patch (version 2.0.0) breaks FSU
  10797.      threads and makes mysqld unstable.  You have to remove this one if
  10798.      you want to run mysqld on an OpenServer 5.0.6 machine.
  10799.  
  10800.    * SCO provides Operating Systems Patches at
  10801.      `ftp://ftp.sco.com/pub/openserver5' for OpenServer 5.0.x
  10802.  
  10803.    * SCO provides secruity fixes and libsocket.so.2 at
  10804.      `ftp://ftp.sco.com/pub/security/OpenServer' and
  10805.      `ftp://ftp.sco.com/pub/security/sse' for OpenServer 5.0.x
  10806.  
  10807.    * pre-OSR506 security fixes. Also, the telnetd fix at
  10808.      `ftp://stage.caldera.com/pub/security/openserver/' or
  10809.      `ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/'
  10810.      as both libsocket.so.2 and libresolv.so.1 with instructions for
  10811.      installing on pre-OSR506 systems.
  10812.  
  10813.      It's probably a good idea to install the above patches before
  10814.      trying to compile/use MySQL.
  10815.  
  10816. If you want to install DBI on SCO, you have to edit the `Makefile' in
  10817. DBI-xxx and each subdirectory.
  10818.  
  10819. Note that the following assumes gcc 2.95.2 or newer:
  10820.  
  10821.      OLD:                                  NEW:
  10822.      CC = cc                               CC = gcc
  10823.      CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
  10824.      CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =
  10825.      
  10826.      LD = ld                               LD = gcc -G -fpic
  10827.      LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
  10828.      LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib
  10829.      
  10830.      LD = ld                               LD = gcc -G -fpic
  10831.      OPTIMISE = -Od                        OPTIMISE = -O1
  10832.      
  10833.      OLD:
  10834.      CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10835.      
  10836.      NEW:
  10837.      CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
  10838.  
  10839. This is because the Perl dynaloader will not load the `DBI' modules if
  10840. they were compiled with `icc' or `cc'.
  10841.  
  10842. Perl works best when compiled with `cc'.
  10843.  
  10844. SCO UnixWare Version 7.1.x Notes
  10845. ................................
  10846.  
  10847. You must use a version of MySQL at least as recent as Version 3.22.13
  10848. and of UnixWare 7.1.0 because these version fixes some portability and
  10849. OS problems under UnixWare.
  10850.  
  10851. We have been able to compile MySQL with the following `configure'
  10852. command on UnixWare Version 7.1.x:
  10853.  
  10854.      CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
  10855.  
  10856. If you want to use `gcc', you must use `gcc' 2.95.2 or newer.
  10857.  
  10858.      CC=gcc CXX=g++ ./configure --prefix=/usr/local/mysql
  10859.  
  10860.   1. SCO provides Operating Systems Patches at
  10861.      `ftp://ftp.sco.com/pub/unixware7' for UnixWare 7.1.1 and 7.1.3
  10862.      `ftp://ftp.sco.com/pub/openunix8' for OpenUNIX 8.0.0
  10863.  
  10864.   2. SCO provides information about Security Fixes at
  10865.      `ftp://ftp.sco.com/pub/security/OpenUNIX' for OpenUNIX
  10866.      `ftp://ftp.sco.com/pub/security/UnixWare' for UnixWare
  10867.  
  10868. OS/2 Notes
  10869. ----------
  10870.  
  10871. MySQL uses quite a few open files. Because of this, you should add
  10872. something like the following to your `CONFIG.SYS' file:
  10873.  
  10874.      SET EMXOPT=-c -n -h1024
  10875.  
  10876. If you don't do this, you will probably run into the following error:
  10877.  
  10878.      File 'xxxx' not found (Errcode: 24)
  10879.  
  10880. When using MySQL with OS/2 Warp 3, FixPack 29 or above is required.
  10881. With OS/2 Warp 4, FixPack 4 or above is required. This is a requirement
  10882. of the Pthreads library.  MySQL must be installed in a partition that
  10883. supports long filenames such as HPFS, FAT32, etc.
  10884.  
  10885. The `INSTALL.CMD' script must be run from OS/2's own `CMD.EXE' and may
  10886. not work with replacement shells such as `4OS2.EXE'.
  10887.  
  10888. The `scripts/mysql-install-db' script has been renamed.  It is now
  10889. called `install.cmd' and is a REXX script, which will set up the default
  10890. MySQL security settings and create the WorkPlace Shell icons for MySQL.
  10891.  
  10892. Dynamic module support is compiled in but not fully tested. Dynamic
  10893. modules should be compiled using the Pthreads run-time library.
  10894.  
  10895.      gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
  10896.          -o example udf_example.cc -L../lib -lmysqlclient udf_example.def
  10897.      mv example.dll example.udf
  10898.  
  10899. *Note*: Due to limitations in OS/2, UDF module name stems must not
  10900. exceed 8 characters. Modules are stored in the `/mysql2/udf' directory;
  10901. the `safe-mysqld.cmd' script will put this directory in the
  10902. `BEGINLIBPATH' environment variable. When using UDF modules, specified
  10903. extensions are ignored--it is assumed to be `.udf'.  For example, in
  10904. Unix, the shared module might be named `example.so' and you would load
  10905. a function from it like this:
  10906.  
  10907.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
  10908.  
  10909. In OS/2, the module would be named `example.udf', but you would not
  10910. specify the module extension:
  10911.  
  10912.      mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
  10913.  
  10914. Novell NetWare Notes
  10915. --------------------
  10916.  
  10917. Porting `MySQL' to `NetWare' was an effort spearheaded by `Novell'.
  10918. Novell customers will be pleased to note that NetWare 6.5 will ship
  10919. with bundled MySQL binaries, complete with an automatic commercial use
  10920. license for all servers running that version of NetWare.
  10921.  
  10922. *Note NetWare installation::.
  10923.  
  10924. MySQL for NetWare is compiled using a combination of `Metrowerks
  10925. Codewarrior for NetWare' and special cross-compilation versions of the
  10926. GNU autotools. Check back here in the future for more information on
  10927. building and optimising MySQL for NetWare.
  10928.  
  10929. BeOS Notes
  10930. ----------
  10931.  
  10932. We have in the past talked with some BeOS developers that have said that
  10933. MySQL is 80% ported to BeOS, but we haven't heard from them in a while.
  10934.  
  10935. Perl Installation Comments
  10936. ==========================
  10937.  
  10938. Installing Perl on Unix
  10939. -----------------------
  10940.  
  10941. Perl support for MySQL is provided by means of the `DBI'/`DBD' client
  10942. interface.  *Note Perl::.  The Perl `DBD'/`DBI' client code requires
  10943. Perl Version 5.004 or later.  The interface *will not work* if you have
  10944. an older version of Perl.
  10945.  
  10946. MySQL Perl support also requires that you've installed MySQL client
  10947. programming support.  If you installed MySQL from RPM files, client
  10948. programs are in the client RPM, but client programming support is in
  10949. the developer RPM.  Make sure you've installed the latter RPM.
  10950.  
  10951. As of Version 3.22.8, Perl support is distributed separately from the
  10952. main MySQL distribution.  If you want to install Perl support, the files
  10953. you will need can be obtained from
  10954. `http://www.mysql.com/downloads/api-dbi.html'.
  10955.  
  10956. The Perl distributions are provided as compressed `tar' archives and
  10957. have names like `MODULE-VERSION.tar.gz', where `MODULE' is the module
  10958. name and `VERSION' is the version number.  You should get the
  10959. `Data-Dumper', `DBI', and `DBD-mysql' distributions and install them in
  10960. that order.  The installation procedure is shown here.  The example
  10961. shown is for the `Data-Dumper' module, but the procedure is the same
  10962. for all three distributions:
  10963.  
  10964.   1. Unpack the distribution into the current directory:
  10965.           shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf -
  10966.      This command creates a directory named `Data-Dumper-VERSION'.
  10967.  
  10968.   2. Change into the top-level directory of the unpacked distribution:
  10969.           shell> cd Data-Dumper-VERSION
  10970.  
  10971.   3. Build the distribution and compile everything:
  10972.           shell> perl Makefile.PL
  10973.           shell> make
  10974.           shell> make test
  10975.           shell> make install
  10976.  
  10977. The `make test' command is important because it verifies that the
  10978. module is working.  Note that when you run that command during the
  10979. `DBD-mysql' installation to exercise the interface code, the MySQL
  10980. server must be running or the test will fail.
  10981.  
  10982. It is a good idea to rebuild and reinstall the `DBD-mysql' distribution
  10983. whenever you install a new release of MySQL, particularly if you notice
  10984. symptoms such as all your `DBI' scripts dumping core after you upgrade
  10985. MySQL.
  10986.  
  10987. If you don't have the right to install Perl modules in the system
  10988. directory or if you to install local Perl modules, the following
  10989. reference may help you:
  10990.  
  10991.      `http://www.iserver.com/support/contrib/perl5/modules.html'
  10992.  
  10993. Look under the heading `Installing New Modules that Require Locally
  10994. Installed Modules'.
  10995.  
  10996. Installing ActiveState Perl on Windows
  10997. --------------------------------------
  10998.  
  10999. To install the MySQL `DBD' module with ActiveState Perl on Windows, you
  11000. should do the following:
  11001.  
  11002.    * Get ActiveState Perl from
  11003.      `http://www.activestate.com/Products/ActivePerl/' and install it.
  11004.  
  11005.    * Open a DOS shell.
  11006.  
  11007.    * If required, set the HTTP_proxy variable. For example, you might
  11008.      try:
  11009.  
  11010.           set HTTP_proxy=my.proxy.com:3128
  11011.  
  11012.    * Start the PPM program:
  11013.  
  11014.           C:\> c:\perl\bin\ppm.pl
  11015.  
  11016.    * If you have not already done so, install `DBI':
  11017.  
  11018.           ppm> install DBI
  11019.  
  11020.    * If this succeeds, run the following command:
  11021.  
  11022.           install \
  11023.           ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
  11024.  
  11025. The above should work at least with ActiveState Perl Version 5.6.
  11026.  
  11027. If you can't get the above to work, you should instead install the
  11028. `MyODBC' driver and connect to MySQL server through ODBC:
  11029.  
  11030.      use DBI;
  11031.      $dbh= DBI->connect("DBI:ODBC:$dsn","$user","$password") ||
  11032.        die "Got error $DBI::errstr when connecting to $dsn\n";
  11033.  
  11034. Problems Using the Perl `DBI'/`DBD' Interface
  11035. ---------------------------------------------
  11036.  
  11037. If Perl reports that it can't find the `../mysql/mysql.so' module, then
  11038. the problem is probably that Perl can't locate the shared library
  11039. `libmysqlclient.so'.
  11040.  
  11041. You can fix this by any of the following methods:
  11042.  
  11043.    * Compile the `DBD-mysql' distribution with `perl Makefile.PL
  11044.      -static -config' rather than `perl Makefile.PL'.
  11045.  
  11046.    * Copy `libmysqlclient.so' to the directory where your other shared
  11047.      libraries are located (probably `/usr/lib' or `/lib').
  11048.  
  11049.    * On Linux you can add the pathname of the directory where
  11050.      `libmysqlclient.so' is located to the `/etc/ld.so.conf' file.
  11051.  
  11052.    * Add the pathname of the directory where `libmysqlclient.so' is
  11053.      located to the `LD_RUN_PATH' environment variable.
  11054.  
  11055. If you get the following errors from `DBD-mysql', you are probably
  11056. using `gcc' (or using an old binary compiled with `gcc'):
  11057.  
  11058.      /usr/bin/perl: can't resolve symbol '__moddi3'
  11059.      /usr/bin/perl: can't resolve symbol '__divdi3'
  11060.  
  11061. Add `-L/usr/lib/gcc-lib/... -lgcc' to the link command when the
  11062. `mysql.so' library gets built (check the output from `make' for
  11063. `mysql.so' when you compile the Perl client).  The `-L' option should
  11064. specify the pathname of the directory where `libgcc.a' is located on
  11065. your system.
  11066.  
  11067. Another cause of this problem may be that Perl and MySQL aren't both
  11068. compiled with `gcc'.  In this case, you can solve the mismatch by
  11069. compiling both with `gcc'.
  11070.  
  11071. If you get the following error from `DBD-mysql' when you run the tests:
  11072.  
  11073.      t/00base............install_driver(mysql) failed:
  11074.      Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
  11075.      ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
  11076.      uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
  11077.  
  11078. it means that you need to include the compression library, -lz, to the
  11079. link line. This can be doing the following change in the file
  11080. `lib/DBD/mysql/Install.pm':
  11081.  
  11082.      $sysliblist .= " -lm";
  11083.      
  11084.      to
  11085.      
  11086.      $sysliblist .= " -lm -lz";
  11087.  
  11088. After this, you *must* run 'make realclean' and then proceed with the
  11089. installation from the beginning.
  11090.  
  11091. If you want to use the Perl module on a system that doesn't support
  11092. dynamic linking (like SCO) you can generate a static version of Perl
  11093. that includes `DBI' and `DBD-mysql'.  The way this works is that you
  11094. generate a version of Perl with the `DBI' code linked in and install it
  11095. on top of your current Perl.  Then you use that to build a version of
  11096. Perl that additionally has the `DBD' code linked in, and install that.
  11097.  
  11098. On SCO, you must have the following environment variables set:
  11099.  
  11100.      shell> LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
  11101.      or
  11102.      shell> LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11103.      /usr/progressive/lib:/usr/skunk/lib
  11104.      shell> LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
  11105.      /usr/progressive/lib:/usr/skunk/lib
  11106.      shell> MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
  11107.      /usr/skunk/man:
  11108.  
  11109. First, create a Perl that includes a statically linked `DBI' by running
  11110. these commands in the directory where your `DBI' distribution is
  11111. located:
  11112.  
  11113.      shell> perl Makefile.PL -static -config
  11114.      shell> make
  11115.      shell> make install
  11116.      shell> make perl
  11117.  
  11118. Then you must install the new Perl. The output of `make perl' will
  11119. indicate the exact `make' command you will need to execute to perform
  11120. the installation.  On SCO, this is `make -f Makefile.aperl inst_perl
  11121. MAP_TARGET=perl'.
  11122.  
  11123. Next, use the just-created Perl to create another Perl that also
  11124. includes a statically-linked `DBD::mysql' by running these commands in
  11125. the directory where your `DBD-mysql' distribution is located:
  11126.  
  11127.      shell> perl Makefile.PL -static -config
  11128.      shell> make
  11129.      shell> make install
  11130.      shell> make perl
  11131.  
  11132. Finally, you should install this new Perl.  Again, the output of `make
  11133. perl' indicates the command to use.
  11134.  
  11135. MySQL Tutorial
  11136. **************
  11137.  
  11138. This chapter provides a tutorial introduction to MySQL by showing how
  11139. to use the `mysql' client program to create and use a simple database.
  11140. `mysql' (sometimes referred to as the "terminal monitor" or just
  11141. "monitor") is an interactive program that allows you to connect to a
  11142. MySQL server, run queries, and view the results.  `mysql' may also be
  11143. used in batch mode: you place your queries in a file beforehand, then
  11144. tell `mysql' to execute the contents of the file.  Both ways of using
  11145. `mysql' are covered here.
  11146.  
  11147. To see a list of options provided by `mysql', invoke it with the
  11148. `--help' option:
  11149.  
  11150.      shell> mysql --help
  11151.  
  11152. This chapter assumes that `mysql' is installed on your machine and that
  11153. a MySQL server is available to which you can connect.  If this is not
  11154. true, contact your MySQL administrator.  (If *you* are the
  11155. administrator, you will need to consult other sections of this manual.)
  11156.  
  11157. This chapter describes the entire process of setting up and using a
  11158. database.  If you are interested only in accessing an already-existing
  11159. database, you may want to skip over the sections that describe how to
  11160. create the database and the tables it contains.
  11161.  
  11162. Because this chapter is tutorial in nature, many details are necessarily
  11163. omitted.  Consult the relevant sections of the manual for more
  11164. information on the topics covered here.
  11165.  
  11166. Connecting to and Disconnecting from the Server
  11167. ===============================================
  11168.  
  11169. To connect to the server, you'll usually need to provide a MySQL user
  11170. name when you invoke `mysql' and, most likely, a password.  If the
  11171. server runs on a machine other than the one where you log in, you'll
  11172. also need to specify a hostname.  Contact your administrator to find
  11173. out what connection parameters you should use to connect (that is, what
  11174. host, user name, and password to use).  Once you know the proper
  11175. parameters, you should be able to connect like this:
  11176.  
  11177.      shell> mysql -h host -u user -p
  11178.      Enter password: ********
  11179.  
  11180. The `********' represents your password; enter it when `mysql' displays
  11181. the `Enter password:' prompt.
  11182.  
  11183. If that works, you should see some introductory information followed by
  11184. a `mysql>' prompt:
  11185.  
  11186.      shell> mysql -h host -u user -p
  11187.      Enter password: ********
  11188.      Welcome to the MySQL monitor.  Commands end with ; or \g.
  11189.      Your MySQL connection id is 25338 to server version: 4.0.14-log
  11190.      
  11191.      Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  11192.      
  11193.      mysql>
  11194.  
  11195. The prompt tells you that `mysql' is ready for you to enter commands.
  11196.  
  11197. Some MySQL installations allow users to connect as the anonymous
  11198. (unnamed) user to the server running on the local host.  If this is the
  11199. case on your machine, you should be able to connect to that server by
  11200. invoking `mysql' without any options:
  11201.  
  11202.      shell> mysql
  11203.  
  11204. After you have connected successfully, you can disconnect any time by
  11205. typing `QUIT' (or `\q') at the `mysql>' prompt:
  11206.  
  11207.      mysql> QUIT
  11208.      Bye
  11209.  
  11210. On Unix, you can also disconnect by pressing Control-D.
  11211.  
  11212. Most examples in the following sections assume you are connected to the
  11213. server.  They indicate this by the `mysql>' prompt.
  11214.  
  11215. Entering Queries
  11216. ================
  11217.  
  11218. Make sure you are connected to the server, as discussed in the previous
  11219. section.  Doing so will not in itself select any database to work with,
  11220. but that's okay.  At this point, it's more important to find out a
  11221. little about how to issue queries than to jump right in creating
  11222. tables, loading data into them, and retrieving data from them.  This
  11223. section describes the basic principles of entering commands, using
  11224. several queries you can try out to familiarise yourself with how
  11225. `mysql' works.
  11226.  
  11227. Here's a simple command that asks the server to tell you its version
  11228. number and the current date.  Type it in as shown here following the
  11229. `mysql>' prompt and press Enter:
  11230.  
  11231.      mysql> SELECT VERSION(), CURRENT_DATE;
  11232.      +--------------+--------------+
  11233.      | VERSION()    | CURRENT_DATE |
  11234.      +--------------+--------------+
  11235.      | 3.22.20a-log | 1999-03-19   |
  11236.      +--------------+--------------+
  11237.      1 row in set (0.01 sec)
  11238.      mysql>
  11239.  
  11240. This query illustrates several things about `mysql':
  11241.  
  11242.    * A command normally consists of an SQL statement followed by a
  11243.      semicolon.  (There are some exceptions where a semicolon may be
  11244.      omitted.  `QUIT', mentioned earlier, is one of them.  We'll get to
  11245.      others later.)
  11246.  
  11247.    * When you issue a command, `mysql' sends it to the server for
  11248.      execution and displays the results, then prints another `mysql>'
  11249.      prompt to indicate that it is ready for another command.
  11250.  
  11251.    * `mysql' displays query output in tabular form (rows and columns).
  11252.      The first row contains labels for the columns.  The rows following
  11253.      are the query results.  Normally, column labels are the names of
  11254.      the columns you fetch from database tables.  If you're retrieving
  11255.      the value of an expression rather than a table column (as in the
  11256.      example just shown), `mysql' labels the column using the
  11257.      expression itself.
  11258.  
  11259.    * `mysql' shows how many rows were returned and how long the query
  11260.      took to execute, which gives you a rough idea of server
  11261.      performance.  These values are imprecise because they represent
  11262.      wall clock time (not CPU or machine time), and because they are
  11263.      affected by factors such as server load and network latency.  (For
  11264.      brevity, the "rows in set" line is not shown in the remaining
  11265.      examples in this chapter.)
  11266.  
  11267. Keywords may be entered in any lettercase.  The following queries are
  11268. equivalent:
  11269.  
  11270.      mysql> SELECT VERSION(), CURRENT_DATE;
  11271.      mysql> select version(), current_date;
  11272.      mysql> SeLeCt vErSiOn(), current_DATE;
  11273.  
  11274. Here's another query.  It demonstrates that you can use `mysql' as a
  11275. simple calculator:
  11276.  
  11277.      mysql> SELECT SIN(PI()/4), (4+1)*5;
  11278.      +-------------+---------+
  11279.      | SIN(PI()/4) | (4+1)*5 |
  11280.      +-------------+---------+
  11281.      |    0.707107 |      25 |
  11282.      +-------------+---------+
  11283.  
  11284. The queries shown thus far have been relatively short, single-line
  11285. statements.  You can even enter multiple statements on a single line.
  11286. Just end each one with a semicolon:
  11287.  
  11288.      mysql> SELECT VERSION(); SELECT NOW();
  11289.      +--------------+
  11290.      | VERSION()    |
  11291.      +--------------+
  11292.      | 3.22.20a-log |
  11293.      +--------------+
  11294.      
  11295.      +---------------------+
  11296.      | NOW()               |
  11297.      +---------------------+
  11298.      | 1999-03-19 00:15:33 |
  11299.      +---------------------+
  11300.  
  11301. A command need not be given all on a single line, so lengthy commands
  11302. that require several lines are not a problem.  `mysql' determines where
  11303. your statement ends by looking for the terminating semicolon, not by
  11304. looking for the end of the input line.  (In other words, `mysql'
  11305. accepts free-format input:  it collects input lines but does not
  11306. execute them until it sees the semicolon.)
  11307.  
  11308. Here's a simple multiple-line statement:
  11309.  
  11310.      mysql> SELECT
  11311.          -> USER()
  11312.          -> ,
  11313.          -> CURRENT_DATE;
  11314.      +--------------------+--------------+
  11315.      | USER()             | CURRENT_DATE |
  11316.      +--------------------+--------------+
  11317.      | joesmith@localhost | 1999-03-18   |
  11318.      +--------------------+--------------+
  11319.  
  11320. In this example, notice how the prompt changes from `mysql>' to `->'
  11321. after you enter the first line of a multiple-line query.  This is how
  11322. `mysql' indicates that it hasn't seen a complete statement and is
  11323. waiting for the rest.  The prompt is your friend, because it provides
  11324. valuable feedback.  If you use that feedback, you will always be aware
  11325. of what `mysql' is waiting for.
  11326.  
  11327. If you decide you don't want to execute a command that you are in the
  11328. process of entering, cancel it by typing `\c':
  11329.  
  11330.      mysql> SELECT
  11331.          -> USER()
  11332.          -> \c
  11333.      mysql>
  11334.  
  11335. Here, too, notice the prompt.  It switches back to `mysql>' after you
  11336. type `\c', providing feedback to indicate that `mysql' is ready for a
  11337. new command.
  11338.  
  11339. The following table shows each of the prompts you may see and
  11340. summarises what they mean about the state that `mysql' is in:
  11341.  
  11342. *Prompt**Meaning*
  11343. `mysql>'Ready for new command.
  11344. `       Waiting for next line of multiple-line command.
  11345. ->'     
  11346. `       Waiting for next line, collecting a string that begins
  11347. '>'     with a single quote (`'').
  11348. `       Waiting for next line, collecting a string that begins
  11349. ">'     with a double quote (`"').
  11350. `       Waiting for next line, collecting an identifier that
  11351. `>'     begins with a backtick (``').
  11352.  
  11353. Multiple-line statements commonly occur by accident when you intend to
  11354. issue a command on a single line, but forget the terminating semicolon.
  11355. In this case, `mysql' waits for more input:
  11356.  
  11357.      mysql> SELECT USER()
  11358.          ->
  11359.  
  11360. If this happens to you (you think you've entered a statement but the
  11361. only response is a `->' prompt), most likely `mysql' is waiting for the
  11362. semicolon.  If you don't notice what the prompt is telling you, you
  11363. might sit there for a while before realising what you need to do.
  11364. Enter a semicolon to complete the statement, and `mysql' will execute
  11365. it:
  11366.  
  11367.      mysql> SELECT USER()
  11368.          -> ;
  11369.      +--------------------+
  11370.      | USER()             |
  11371.      +--------------------+
  11372.      | joesmith@localhost |
  11373.      +--------------------+
  11374.  
  11375. The `'>' and `">' prompts occur during string collection.  In MySQL,
  11376. you can write strings surrounded by either `'' or `"' characters (for
  11377. example, `'hello'' or `"goodbye"'), and `mysql' lets you enter strings
  11378. that span multiple lines.  When you see a `'>' or `">' prompt, it means
  11379. that you've entered a line containing a string that begins with a `''
  11380. or `"' quote character, but have not yet entered the matching quote
  11381. that terminates the string.  That's fine if you really are entering a
  11382. multiple-line string, but how likely is that?  Not very.  More often,
  11383. the `'>' and `">' prompts indicate that you've inadvertantly left out a
  11384. quote character.  For example:
  11385.  
  11386.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  11387.          ">
  11388.  
  11389. If you enter this `SELECT' statement, then press Enter and wait for the
  11390. result, nothing will happen.  Instead of wondering why this query takes
  11391. so long, notice the clue provided by the `">' prompt.  It tells you
  11392. that `mysql' expects to see the rest of an unterminated string.  (Do
  11393. you see the error in the statement?  The string `"Smith' is missing the
  11394. second quote.)
  11395.  
  11396. At this point, what do you do?  The simplest thing is to cancel the
  11397. command.  However, you cannot just type `\c' in this case, because
  11398. `mysql' interprets it as part of the string that it is collecting!
  11399. Instead, enter the closing quote character (so `mysql' knows you've
  11400. finished the string), then type `\c':
  11401.  
  11402.      mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
  11403.          "> "\c
  11404.      mysql>
  11405.  
  11406. The prompt changes back to `mysql>', indicating that `mysql' is ready
  11407. for a new command.
  11408.  
  11409. The ``>' prompt is similar to th `'>' and `">' prompts, but indicates
  11410. that you have begun but not completed a backtick-quoted identifier.
  11411.  
  11412. It's important to know what the `'>', `">', and ``>' prompts signify,
  11413. because if you mistakenly enter an unterminated string, any further
  11414. lines you type will appear to be ignored by `mysql'--including a line
  11415. containing `QUIT'!  This can be quite confusing, especially if you
  11416. don't know that you need to supply the terminating quote before you can
  11417. cancel the current command.
  11418.  
  11419. Creating and Using a Database
  11420. =============================
  11421.  
  11422. Now that you know how to enter commands, it's time to access a database.
  11423.  
  11424. Suppose you have several pets in your home (your menagerie) and you'd
  11425. like to keep track of various types of information about them.  You can
  11426. do so by creating tables to hold your data and loading them with the
  11427. desired information.  Then you can answer different sorts of questions
  11428. about your animals by retrieving data from the tables.  This section
  11429. shows you how to:
  11430.  
  11431.    * Create a database
  11432.  
  11433.    * Create a table
  11434.  
  11435.    * Load data into the table
  11436.  
  11437.    * Retrieve data from the table in various ways
  11438.  
  11439.    * Use multiple tables
  11440.  
  11441. The menagerie database will be simple (deliberately), but it is not
  11442. difficult to think of real-world situations in which a similar type of
  11443. database might be used.  For example, a database like this could be
  11444. used by a farmer to keep track of livestock, or by a veterinarian to
  11445. keep track of patient records.  A menagerie distribution containing
  11446. some of the queries and sample data used in the following sections can
  11447. be obtained from the MySQL web site.  It's available in either
  11448. compressed `tar' format
  11449. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.tar.gz') or
  11450. Zip format
  11451. (`http://www.mysql.com/Downloads/Contrib/Examples/menagerie.zip').
  11452.  
  11453. Use the `SHOW' statement to find out what databases currently exist on
  11454. the server:
  11455.  
  11456.      mysql> SHOW DATABASES;
  11457.      +----------+
  11458.      | Database |
  11459.      +----------+
  11460.      | mysql    |
  11461.      | test     |
  11462.      | tmp      |
  11463.      +----------+
  11464.  
  11465. The list of databases is probably different on your machine, but the
  11466. `mysql' and `test' databases are likely to be among them.  The `mysql'
  11467. database is required because it describes user access privileges.  The
  11468. `test' database is often provided as a workspace for users to try
  11469. things out.
  11470.  
  11471. Note that you may not see all databases if you don't have the `SHOW
  11472. DATABASES' privilege. *Note `GRANT': GRANT.
  11473.  
  11474. If the `test' database exists, try to access it:
  11475.  
  11476.      mysql> USE test
  11477.      Database changed
  11478.  
  11479. Note that `USE', like `QUIT', does not require a semicolon.  (You can
  11480. terminate such statements with a semicolon if you like; it does no
  11481. harm.)  The `USE' statement is special in another way, too:  it must be
  11482. given on a single line.
  11483.  
  11484. You can use the `test' database (if you have access to it) for the
  11485. examples that follow, but anything you create in that database can be
  11486. removed by anyone else with access to it.  For this reason, you should
  11487. probably ask your MySQL administrator for permission to use a database
  11488. of your own.  Suppose you want to call yours `menagerie'.  The
  11489. administrator needs to execute a command like this:
  11490.  
  11491.      mysql> GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';
  11492.  
  11493. where `your_mysql_name' is the MySQL user name assigned to you and
  11494. `your_client_host' is the host from which you connect to the server.
  11495.  
  11496. Creating and Selecting a Database
  11497. ---------------------------------
  11498.  
  11499. If the administrator creates your database for you when setting up your
  11500. permissions, you can begin using it.  Otherwise, you need to create it
  11501. yourself:
  11502.  
  11503.      mysql> CREATE DATABASE menagerie;
  11504.  
  11505. Under Unix, database names are case-sensitive (unlike SQL keywords), so
  11506. you must always refer to your database as `menagerie', not as
  11507. `Menagerie', `MENAGERIE', or some other variant.  This is also true for
  11508. table names.  (Under Windows, this restriction does not apply, although
  11509. you must refer to databases and tables using the same lettercase
  11510. throughout a given query.)
  11511.  
  11512. Creating a database does not select it for use; you must do that
  11513. explicitly.  To make `menagerie' the current database, use this command:
  11514.  
  11515.      mysql> USE menagerie
  11516.      Database changed
  11517.  
  11518. Your database needs to be created only once, but you must select it for
  11519. use each time you begin a `mysql' session.  You can do this by issuing a
  11520. `USE' statement as shown in the example.  Alternatively, you can select
  11521. the database on the command-line when you invoke `mysql'.  Just specify
  11522. its name after any connection parameters that you might need to
  11523. provide.  For example:
  11524.  
  11525.      shell> mysql -h host -u user -p menagerie
  11526.      Enter password: ********
  11527.  
  11528. Note that `menagerie' is not your password on the command just shown.
  11529. If you want to supply your password on the command-line after the `-p'
  11530. option, you must do so with no intervening space (for example, as
  11531. `-pmypassword', not as `-p mypassword').  However, putting your
  11532. password on the command-line is not recommended, because doing so
  11533. exposes it to snooping by other users logged in on your machine.
  11534.  
  11535. Creating a Table
  11536. ----------------
  11537.  
  11538. Creating the database is the easy part, but at this point it's empty, as
  11539. `SHOW TABLES' will tell you:
  11540.  
  11541.      mysql> SHOW TABLES;
  11542.      Empty set (0.00 sec)
  11543.  
  11544. The harder part is deciding what the structure of your database should
  11545. be: what tables you will need and what columns will be in each of them.
  11546.  
  11547. You'll want a table that contains a record for each of your pets.  This
  11548. can be called the `pet' table, and it should contain, as a bare minimum,
  11549. each animal's name.  Because the name by itself is not very
  11550. interesting, the table should contain other information.  For example,
  11551. if more than one person in your family keeps pets, you might want to
  11552. list each animal's owner.  You might also want to record some basic
  11553. descriptive information such as species and sex.
  11554.  
  11555. How about age?  That might be of interest, but it's not a good thing to
  11556. store in a database.  Age changes as time passes, which means you'd
  11557. have to update your records often.  Instead, it's better to store a
  11558. fixed value such as date of birth.  Then, whenever you need age, you
  11559. can calculate it as the difference between the current date and the
  11560. birth date.  MySQL provides functions for doing date arithmetic, so
  11561. this is not difficult.  Storing birth date rather than age has other
  11562. advantages, too:
  11563.  
  11564.    * You can use the database for tasks such as generating reminders
  11565.      for upcoming pet birthdays.  (If you think this type of query is
  11566.      somewhat silly, note that it is the same question you might ask in
  11567.      the context of a business database to identify clients to whom
  11568.      you'll soon need to send out birthday greetings, for that
  11569.      computer-assisted personal touch.)
  11570.  
  11571.    * You can calculate age in relation to dates other than the current
  11572.      date.  For example, if you store death date in the database, you
  11573.      can easily calculate how old a pet was when it died.
  11574.  
  11575. You can probably think of other types of information that would be
  11576. useful in the `pet' table, but the ones identified so far are
  11577. sufficient for now: name, owner, species, sex, birth, and death.
  11578.  
  11579. Use a `CREATE TABLE' statement to specify the layout of your table:
  11580.  
  11581.      mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
  11582.          -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
  11583.  
  11584. `VARCHAR' is a good choice for the `name', `owner', and `species'
  11585. columns because the column values will vary in length.  The lengths of
  11586. those columns need not all be the same, and need not be `20'.  You can
  11587. pick any length from `1' to `255', whatever seems most reasonable to
  11588. you.  (If you make a poor choice and it turns out later that you need a
  11589. longer field, MySQL provides an `ALTER TABLE' statement.)
  11590.  
  11591. Several types of values can be chosen to represent sex in animal
  11592. records, such as `"m"' and `"f"', or perhaps `"male"' and `"female"'.
  11593. It's simplest to use the single characters `"m"' and `"f"'.
  11594.  
  11595. The use of the `DATE' datatype for the `birth' and `death' columns is a
  11596. fairly obvious choice.
  11597.  
  11598. Now that you have created a table, `SHOW TABLES' should produce some
  11599. output:
  11600.  
  11601.      mysql> SHOW TABLES;
  11602.      +---------------------+
  11603.      | Tables in menagerie |
  11604.      +---------------------+
  11605.      | pet                 |
  11606.      +---------------------+
  11607.  
  11608. To verify that your table was created the way you expected, use a
  11609. `DESCRIBE' statement:
  11610.  
  11611.      mysql> DESCRIBE pet;
  11612.      +---------+-------------+------+-----+---------+-------+
  11613.      | Field   | Type        | Null | Key | Default | Extra |
  11614.      +---------+-------------+------+-----+---------+-------+
  11615.      | name    | varchar(20) | YES  |     | NULL    |       |
  11616.      | owner   | varchar(20) | YES  |     | NULL    |       |
  11617.      | species | varchar(20) | YES  |     | NULL    |       |
  11618.      | sex     | char(1)     | YES  |     | NULL    |       |
  11619.      | birth   | date        | YES  |     | NULL    |       |
  11620.      | death   | date        | YES  |     | NULL    |       |
  11621.      +---------+-------------+------+-----+---------+-------+
  11622.  
  11623. You can use `DESCRIBE' any time, for example, if you forget the names of
  11624. the columns in your table or what types they have.
  11625.  
  11626. Loading Data into a Table
  11627. -------------------------
  11628.  
  11629. After creating your table, you need to populate it.  The `LOAD DATA' and
  11630. `INSERT' statements are useful for this.
  11631.  
  11632. Suppose your pet records can be described as shown here.  (Observe that
  11633. MySQL expects dates in `'YYYY-MM-DD'' format; this may be different
  11634. from what you are used to.)
  11635.  
  11636. *name*  *owner* *species**sex**birth*        *death*
  11637. Fluffy  Harold  cat     f    1993-02-04     
  11638. Claws   Gwen    cat     m    1994-03-17     
  11639. Buffy   Harold  dog     f    1989-05-13     
  11640. Fang    Benny   dog     m    1990-08-27     
  11641. Bowser  Diane   dog     m    1979-08-31     1995-07-29
  11642. Chirpy  Gwen    bird    f    1998-09-11     
  11643. WhistlerGwen    bird         1997-12-09     
  11644. Slim    Benny   snake   m    1996-04-29     
  11645.  
  11646. Because you are beginning with an empty table, an easy way to populate
  11647. it is to create a text file containing a row for each of your animals,
  11648. then load the contents of the file into the table with a single
  11649. statement.
  11650.  
  11651. You could create a text file `pet.txt' containing one record per line,
  11652. with values separated by tabs, and given in the order in which the
  11653. columns were listed in the `CREATE TABLE' statement.  For missing
  11654. values (such as unknown sexes or death dates for animals that are still
  11655. living), you can use `NULL' values.  To represent these in your text
  11656. file, use `\N' (backslash, capital-N).  For example, the record for
  11657. Whistler the bird would look like this (where the whitespace between
  11658. values is a single tab character):
  11659.  
  11660. *name*  *owner* *species**sex**birth*        *death*
  11661. `Whistler'`Gwen'  `bird'  `\N' `1997-12-09'   `\N'
  11662.  
  11663. To load the text file `pet.txt' into the `pet' table, use this command:
  11664.  
  11665.      mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  11666.  
  11667. You can specify the column value separator and end of line marker
  11668. explicitly in the `LOAD DATA' statement if you wish, but the defaults
  11669. are tab and linefeed.  These are sufficient for the statement to read
  11670. the file `pet.txt' properly.
  11671.  
  11672. If the statement fails, it is likely that your MySQL installation does
  11673. not have local file capability enabled by default.  See *Note `LOAD
  11674. DATA LOCAL': LOAD DATA LOCAL for information on how to change this.
  11675.  
  11676. When you want to add new records one at a time, the `INSERT' statement
  11677. is useful.  In its simplest form, you supply values for each column, in
  11678. the order in which the columns were listed in the `CREATE TABLE'
  11679. statement.  Suppose Diane gets a new hamster named Puffball.  You could
  11680. add a new record using an `INSERT' statement like this:
  11681.  
  11682.      mysql> INSERT INTO pet
  11683.          -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
  11684.  
  11685. Note that string and date values are specified as quoted strings here.
  11686. Also, with `INSERT', you can insert `NULL' directly to represent a
  11687. missing value.  You do not use `\N' like you do with `LOAD DATA'.
  11688.  
  11689. From this example, you should be able to see that there would be a lot
  11690. more typing involved to load your records initially using several
  11691. `INSERT' statements rather than a single `LOAD DATA' statement.
  11692.  
  11693. Retrieving Information from a Table
  11694. -----------------------------------
  11695.  
  11696. The `SELECT' statement is used to pull information from a table.  The
  11697. general form of the statement is:
  11698.  
  11699.      SELECT what_to_select
  11700.      FROM which_table
  11701.      WHERE conditions_to_satisfy;
  11702.  
  11703. `what_to_select' indicates what you want to see.  This can be a list of
  11704. columns, or `*' to indicate "all columns." `which_table' indicates the
  11705. table from which you want to retrieve data.  The `WHERE' clause is
  11706. optional.  If it's present, `conditions_to_satisfy' specifies
  11707. conditions that rows must satisfy to qualify for retrieval.
  11708.  
  11709. Selecting All Data
  11710. ..................
  11711.  
  11712. The simplest form of `SELECT' retrieves everything from a table:
  11713.  
  11714.      mysql> SELECT * FROM pet;
  11715.      +----------+--------+---------+------+------------+------------+
  11716.      | name     | owner  | species | sex  | birth      | death      |
  11717.      +----------+--------+---------+------+------------+------------+
  11718.      | Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |
  11719.      | Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |
  11720.      | Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |
  11721.      | Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |
  11722.      | Bowser   | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |
  11723.      | Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |
  11724.      | Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |
  11725.      | Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |
  11726.      | Puffball | Diane  | hamster | f    | 1999-03-30 | NULL       |
  11727.      +----------+--------+---------+------+------------+------------+
  11728.  
  11729. This form of `SELECT' is useful if you want to review your entire table,
  11730. for instance, after you've just loaded it with your initial dataset.
  11731. For example, you may happen to think that the birth date for Bowser
  11732. doesn't seem quite right.  Consulting your original pedigree papers,
  11733. you find that the correct birth year should be 1989, not 1979.
  11734.  
  11735. There are least a couple of ways to fix this:
  11736.  
  11737.    * Edit the file `pet.txt' to correct the error, then empty the table
  11738.      and reload it using `DELETE' and `LOAD DATA':
  11739.  
  11740.           mysql> DELETE FROM pet;
  11741.           mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
  11742.  
  11743.      However, if you do this, you must also re-enter the record for
  11744.      Puffball.
  11745.  
  11746.    * Fix only the erroneous record with an `UPDATE' statement:
  11747.  
  11748.           mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
  11749.  
  11750.      The `UPDATE' changes only the record in question and does not
  11751.      require you to reload the table.
  11752.  
  11753. Selecting Particular Rows
  11754. .........................
  11755.  
  11756. As shown in the preceding section, it is easy to retrieve an entire
  11757. table.  Just omit the `WHERE' clause from the `SELECT' statement.  But
  11758. typically you don't want to see the entire table, particularly when it
  11759. becomes large.  Instead, you're usually more interested in answering a
  11760. particular question, in which case you specify some constraints on the
  11761. information you want.  Let's look at some selection queries in terms of
  11762. questions about your pets that they answer.
  11763.  
  11764. You can select only particular rows from your table.  For example, if
  11765. you want to verify the change that you made to Bowser's birth date,
  11766. select Bowser's record like this:
  11767.  
  11768.      mysql> SELECT * FROM pet WHERE name = "Bowser";
  11769.      +--------+-------+---------+------+------------+------------+
  11770.      | name   | owner | species | sex  | birth      | death      |
  11771.      +--------+-------+---------+------+------------+------------+
  11772.      | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  11773.      +--------+-------+---------+------+------------+------------+
  11774.  
  11775. The output confirms that the year is correctly recorded now as 1989,
  11776. not 1979.
  11777.  
  11778. String comparisons normally are case-insensitive, so you can specify the
  11779. name as `"bowser"', `"BOWSER"', etc.  The query result will be the same.
  11780.  
  11781. You can specify conditions on any column, not just `name'.  For example,
  11782. if you want to know which animals were born after 1998, test the `birth'
  11783. column:
  11784.  
  11785.      mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
  11786.      +----------+-------+---------+------+------------+-------+
  11787.      | name     | owner | species | sex  | birth      | death |
  11788.      +----------+-------+---------+------+------------+-------+
  11789.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  11790.      | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  11791.      +----------+-------+---------+------+------------+-------+
  11792.  
  11793. You can combine conditions, for example, to locate female dogs:
  11794.  
  11795.      mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
  11796.      +-------+--------+---------+------+------------+-------+
  11797.      | name  | owner  | species | sex  | birth      | death |
  11798.      +-------+--------+---------+------+------------+-------+
  11799.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11800.      +-------+--------+---------+------+------------+-------+
  11801.  
  11802. The preceding query uses the `AND' logical operator.  There is also an
  11803. `OR' operator:
  11804.  
  11805.      mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
  11806.      +----------+-------+---------+------+------------+-------+
  11807.      | name     | owner | species | sex  | birth      | death |
  11808.      +----------+-------+---------+------+------------+-------+
  11809.      | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  11810.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  11811.      | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  11812.      +----------+-------+---------+------+------------+-------+
  11813.  
  11814. `AND' and `OR' may be intermixed, though `AND' has higher precedence
  11815. than `OR'.  If you use both operators, it's a good idea to use
  11816. parentheses to indicate explicitly how conditions should be grouped:
  11817.  
  11818.      mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
  11819.          -> OR (species = "dog" AND sex = "f");
  11820.      +-------+--------+---------+------+------------+-------+
  11821.      | name  | owner  | species | sex  | birth      | death |
  11822.      +-------+--------+---------+------+------------+-------+
  11823.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  11824.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  11825.      +-------+--------+---------+------+------------+-------+
  11826.  
  11827. Selecting Particular Columns
  11828. ............................
  11829.  
  11830. If you don't want to see entire rows from your table, just name the
  11831. columns in which you're interested, separated by commas.  For example,
  11832. if you want to know when your animals were born, select the `name' and
  11833. `birth' columns:
  11834.  
  11835.      mysql> SELECT name, birth FROM pet;
  11836.      +----------+------------+
  11837.      | name     | birth      |
  11838.      +----------+------------+
  11839.      | Fluffy   | 1993-02-04 |
  11840.      | Claws    | 1994-03-17 |
  11841.      | Buffy    | 1989-05-13 |
  11842.      | Fang     | 1990-08-27 |
  11843.      | Bowser   | 1989-08-31 |
  11844.      | Chirpy   | 1998-09-11 |
  11845.      | Whistler | 1997-12-09 |
  11846.      | Slim     | 1996-04-29 |
  11847.      | Puffball | 1999-03-30 |
  11848.      +----------+------------+
  11849.  
  11850. To find out who owns pets, use this query:
  11851.  
  11852.      mysql> SELECT owner FROM pet;
  11853.      +--------+
  11854.      | owner  |
  11855.      +--------+
  11856.      | Harold |
  11857.      | Gwen   |
  11858.      | Harold |
  11859.      | Benny  |
  11860.      | Diane  |
  11861.      | Gwen   |
  11862.      | Gwen   |
  11863.      | Benny  |
  11864.      | Diane  |
  11865.      +--------+
  11866.  
  11867. However, notice that the query simply retrieves the `owner' field from
  11868. each record, and some of them appear more than once.  To minimise the
  11869. output, retrieve each unique output record just once by adding the
  11870. keyword `DISTINCT':
  11871.  
  11872.      mysql> SELECT DISTINCT owner FROM pet;
  11873.      +--------+
  11874.      | owner  |
  11875.      +--------+
  11876.      | Benny  |
  11877.      | Diane  |
  11878.      | Gwen   |
  11879.      | Harold |
  11880.      +--------+
  11881.  
  11882. You can use a `WHERE' clause to combine row selection with column
  11883. selection.  For example, to get birth dates for dogs and cats only, use
  11884. this query:
  11885.  
  11886.      mysql> SELECT name, species, birth FROM pet
  11887.          -> WHERE species = "dog" OR species = "cat";
  11888.      +--------+---------+------------+
  11889.      | name   | species | birth      |
  11890.      +--------+---------+------------+
  11891.      | Fluffy | cat     | 1993-02-04 |
  11892.      | Claws  | cat     | 1994-03-17 |
  11893.      | Buffy  | dog     | 1989-05-13 |
  11894.      | Fang   | dog     | 1990-08-27 |
  11895.      | Bowser | dog     | 1989-08-31 |
  11896.      +--------+---------+------------+
  11897.  
  11898. Sorting Rows
  11899. ............
  11900.  
  11901. You may have noticed in the preceding examples that the result rows are
  11902. displayed in no particular order.  It's often easier to examine query
  11903. output when the rows are sorted in some meaningful way.  To sort a
  11904. result, use an `ORDER BY' clause.
  11905.  
  11906. Here are animal birthdays, sorted by date:
  11907.  
  11908.      mysql> SELECT name, birth FROM pet ORDER BY birth;
  11909.      +----------+------------+
  11910.      | name     | birth      |
  11911.      +----------+------------+
  11912.      | Buffy    | 1989-05-13 |
  11913.      | Bowser   | 1989-08-31 |
  11914.      | Fang     | 1990-08-27 |
  11915.      | Fluffy   | 1993-02-04 |
  11916.      | Claws    | 1994-03-17 |
  11917.      | Slim     | 1996-04-29 |
  11918.      | Whistler | 1997-12-09 |
  11919.      | Chirpy   | 1998-09-11 |
  11920.      | Puffball | 1999-03-30 |
  11921.      +----------+------------+
  11922.  
  11923. On character type columns, sorting--like all other comparison
  11924. operations--is normally performed in a case-insensitive fashion.  This
  11925. means that the order will be undefined for columns that are identical
  11926. except for their case. You can force a case-sensitive sort for a column
  11927. by using the `BINARY' cast: `ORDER BY BINARY col_name'.
  11928.  
  11929. The default sort order is ascending, with smallest values first.  To
  11930. sort in reverse (descending) order, add the `DESC' keyword to the name
  11931. of the column you are sorting by:
  11932.  
  11933.      mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
  11934.      +----------+------------+
  11935.      | name     | birth      |
  11936.      +----------+------------+
  11937.      | Puffball | 1999-03-30 |
  11938.      | Chirpy   | 1998-09-11 |
  11939.      | Whistler | 1997-12-09 |
  11940.      | Slim     | 1996-04-29 |
  11941.      | Claws    | 1994-03-17 |
  11942.      | Fluffy   | 1993-02-04 |
  11943.      | Fang     | 1990-08-27 |
  11944.      | Bowser   | 1989-08-31 |
  11945.      | Buffy    | 1989-05-13 |
  11946.      +----------+------------+
  11947.  
  11948. You can sort on multiple columns, and you can sort columns in different
  11949. directions.  For example, to sort by type of animal in ascending order,
  11950. then by birth date within animal type in descending order (youngest
  11951. animals first), use the following query:
  11952.  
  11953.      mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
  11954.      +----------+---------+------------+
  11955.      | name     | species | birth      |
  11956.      +----------+---------+------------+
  11957.      | Chirpy   | bird    | 1998-09-11 |
  11958.      | Whistler | bird    | 1997-12-09 |
  11959.      | Claws    | cat     | 1994-03-17 |
  11960.      | Fluffy   | cat     | 1993-02-04 |
  11961.      | Fang     | dog     | 1990-08-27 |
  11962.      | Bowser   | dog     | 1989-08-31 |
  11963.      | Buffy    | dog     | 1989-05-13 |
  11964.      | Puffball | hamster | 1999-03-30 |
  11965.      | Slim     | snake   | 1996-04-29 |
  11966.      +----------+---------+------------+
  11967.  
  11968. Note that the `DESC' keyword applies only to the column name immediately
  11969. preceding it (`birth'); it does not affect the `species' column sort
  11970. order.
  11971.  
  11972. Date Calculations
  11973. .................
  11974.  
  11975. MySQL provides several functions that you can use to perform
  11976. calculations on dates, for example, to calculate ages or extract parts
  11977. of dates.
  11978.  
  11979. To determine how many years old each of your pets is, compute the
  11980. difference in the year part of the current date and the birth date, then
  11981. subtract one if the current date occurs earlier in the calendar year
  11982. than the birth date.  The following query shows, for each pet, the
  11983. birth date, the current date, and the age in years.
  11984.  
  11985.      mysql> SELECT name, birth, CURDATE(),
  11986.          -> (YEAR(CURDATE())-YEAR(birth))
  11987.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  11988.          -> AS age
  11989.          -> FROM pet;
  11990.      +----------+------------+------------+------+
  11991.      | name     | birth      | CURDATE()  | age  |
  11992.      +----------+------------+------------+------+
  11993.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  11994.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  11995.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  11996.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  11997.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  11998.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  11999.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  12000.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  12001.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  12002.      +----------+------------+------------+------+
  12003.  
  12004. Here, `YEAR()' pulls out the year part of a date and `RIGHT()' pulls
  12005. off the rightmost five characters that represent the `MM-DD' (calendar
  12006. year) part of the date.  The part of the expression that compares the
  12007. `MM-DD' values evaluates to 1 or 0, which adjusts the year difference
  12008. down a year if `CURDATE()' occurs earlier in the year than `birth'.
  12009. The full expression is somewhat ungainly, so an alias (`age') is used
  12010. to make the output column label more meaningful.
  12011.  
  12012. The query works, but the result could be scanned more easily if the rows
  12013. were presented in some order.  This can be done by adding an `ORDER BY
  12014. name' clause to sort the output by name:
  12015.  
  12016.      mysql> SELECT name, birth, CURDATE(),
  12017.          -> (YEAR(CURDATE())-YEAR(birth))
  12018.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  12019.          -> AS age
  12020.          -> FROM pet ORDER BY name;
  12021.      +----------+------------+------------+------+
  12022.      | name     | birth      | CURDATE()  | age  |
  12023.      +----------+------------+------------+------+
  12024.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  12025.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  12026.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  12027.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  12028.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  12029.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  12030.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  12031.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  12032.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  12033.      +----------+------------+------------+------+
  12034.  
  12035. To sort the output by `age' rather than `name', just use a different
  12036. `ORDER BY' clause:
  12037.  
  12038.      mysql> SELECT name, birth, CURDATE(),
  12039.          -> (YEAR(CURDATE())-YEAR(birth))
  12040.          -> - (RIGHT(CURDATE(),5)<RIGHT(birth,5))
  12041.          -> AS age
  12042.          -> FROM pet ORDER BY age;
  12043.      +----------+------------+------------+------+
  12044.      | name     | birth      | CURDATE()  | age  |
  12045.      +----------+------------+------------+------+
  12046.      | Chirpy   | 1998-09-11 | 2003-08-19 |    4 |
  12047.      | Puffball | 1999-03-30 | 2003-08-19 |    4 |
  12048.      | Whistler | 1997-12-09 | 2003-08-19 |    5 |
  12049.      | Slim     | 1996-04-29 | 2003-08-19 |    7 |
  12050.      | Claws    | 1994-03-17 | 2003-08-19 |    9 |
  12051.      | Fluffy   | 1993-02-04 | 2003-08-19 |   10 |
  12052.      | Fang     | 1990-08-27 | 2003-08-19 |   12 |
  12053.      | Bowser   | 1989-08-31 | 2003-08-19 |   13 |
  12054.      | Buffy    | 1989-05-13 | 2003-08-19 |   14 |
  12055.      +----------+------------+------------+------+
  12056.  
  12057. A similar query can be used to determine age at death for animals that
  12058. have died.  You determine which animals these are by checking whether
  12059. the `death' value is `NULL'.  Then, for those with non-`NULL' values,
  12060. compute the difference between the `death' and `birth' values:
  12061.  
  12062.      mysql> SELECT name, birth, death,
  12063.          -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
  12064.          -> AS age
  12065.          -> FROM pet WHERE death IS NOT NULL ORDER BY age;
  12066.      +--------+------------+------------+------+
  12067.      | name   | birth      | death      | age  |
  12068.      +--------+------------+------------+------+
  12069.      | Bowser | 1989-08-31 | 1995-07-29 |    5 |
  12070.      +--------+------------+------------+------+
  12071.  
  12072. The query uses `death IS NOT NULL' rather than `death <> NULL' because
  12073. `NULL' is a special value that cannot be compared using the usual
  12074. comparison operators.  This is discussed later.  *Note Working with
  12075. `NULL': Working with NULL.
  12076.  
  12077. What if you want to know which animals have birthdays next month?  For
  12078. this type of calculation, year and day are irrelevant; you simply want
  12079. to extract the month part of the `birth' column.  MySQL provides several
  12080. date-part extraction functions, such as `YEAR()', `MONTH()', and
  12081. `DAYOFMONTH()'.  `MONTH()' is the appropriate function here.  To see
  12082. how it works, run a simple query that displays the value of both
  12083. `birth' and `MONTH(birth)':
  12084.  
  12085.      mysql> SELECT name, birth, MONTH(birth) FROM pet;
  12086.      +----------+------------+--------------+
  12087.      | name     | birth      | MONTH(birth) |
  12088.      +----------+------------+--------------+
  12089.      | Fluffy   | 1993-02-04 |            2 |
  12090.      | Claws    | 1994-03-17 |            3 |
  12091.      | Buffy    | 1989-05-13 |            5 |
  12092.      | Fang     | 1990-08-27 |            8 |
  12093.      | Bowser   | 1989-08-31 |            8 |
  12094.      | Chirpy   | 1998-09-11 |            9 |
  12095.      | Whistler | 1997-12-09 |           12 |
  12096.      | Slim     | 1996-04-29 |            4 |
  12097.      | Puffball | 1999-03-30 |            3 |
  12098.      +----------+------------+--------------+
  12099.  
  12100. Finding animals with birthdays in the upcoming month is easy, too.
  12101. Suppose the current month is April.  Then the month value is `4' and
  12102. you look for animals born in May (month `5') like this:
  12103.  
  12104.      mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
  12105.      +-------+------------+
  12106.      | name  | birth      |
  12107.      +-------+------------+
  12108.      | Buffy | 1989-05-13 |
  12109.      +-------+------------+
  12110.  
  12111. There is a small complication if the current month is December, of
  12112. course.  You don't just add one to the month number (`12') and look for
  12113. animals born in month `13', because there is no such month.  Instead,
  12114. you look for animals born in January (month `1').
  12115.  
  12116. You can even write the query so that it works no matter what the current
  12117. month is.  That way you don't have to use a particular month number in
  12118. the query.  `DATE_ADD()' allows you to add a time interval to a given
  12119. date.  If you add a month to the value of `CURDATE()', then extract the
  12120. month part with `MONTH()', the result produces the month in which to
  12121. look for birthdays:
  12122.  
  12123.      mysql> SELECT name, birth FROM pet
  12124.          -> WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(), INTERVAL 1 MONTH));
  12125.  
  12126. A different way to accomplish the same task is to add `1' to get the
  12127. next month after the current one (after using the modulo function
  12128. (`MOD') to wrap around the month value to `0' if it is currently `12'):
  12129.  
  12130.      mysql> SELECT name, birth FROM pet
  12131.          -> WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1;
  12132.  
  12133. Note that `MONTH' returns a number between `1' and `12'. And
  12134. `MOD(something,12)' returns a number between `0' and `11'. So the
  12135. addition has to be after the `MOD()', otherwise we would go from
  12136. November (`11') to January (`1').
  12137.  
  12138. Working with `NULL' Values
  12139. ..........................
  12140.  
  12141. The `NULL' value can be surprising until you get used to it.
  12142. Conceptually, `NULL' means missing value or unknown value and it is
  12143. treated somewhat differently than other values.  To test for `NULL',
  12144. you cannot use the arithmetic comparison operators such as `=', `<', or
  12145. `<>'.  To demonstrate this for yourself, try the following query:
  12146.  
  12147.      mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;
  12148.      +----------+-----------+----------+----------+
  12149.      | 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |
  12150.      +----------+-----------+----------+----------+
  12151.      |     NULL |      NULL |     NULL |     NULL |
  12152.      +----------+-----------+----------+----------+
  12153.  
  12154. Clearly you get no meaningful results from these comparisons.  Use the
  12155. `IS NULL' and `IS NOT NULL' operators instead:
  12156.  
  12157.      mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
  12158.      +-----------+---------------+
  12159.      | 1 IS NULL | 1 IS NOT NULL |
  12160.      +-----------+---------------+
  12161.      |         0 |             1 |
  12162.      +-----------+---------------+
  12163.  
  12164. Note that in MySQL, `0' or `NULL' means false and anything else means
  12165. true. The default truth value from a boolean operation is `1'.
  12166.  
  12167. This special treatment of `NULL' is why, in the previous section, it
  12168. was necessary to determine which animals are no longer alive using
  12169. `death IS NOT NULL' instead of `death <> NULL'.
  12170.  
  12171. Two `NULL' values are regarded as equal in a `GROUP BY'.
  12172.  
  12173. When doing an `ORDER BY', `NULL' values are presented first if you do
  12174. `ORDER BY ... ASC' and last if you do `ORDER BY ... DESC'.
  12175.  
  12176. Note that MySQL 4.0.2 to 4.0.10 incorrectly always sorts `NULL' values
  12177. first regardless of the sort direction.
  12178.  
  12179. Pattern Matching
  12180. ................
  12181.  
  12182. MySQL provides standard SQL pattern matching as well as a form of
  12183. pattern matching based on extended regular expressions similar to those
  12184. used by Unix utilities such as `vi', `grep', and `sed'.
  12185.  
  12186. SQL pattern matching allows you to use `_' to match any single
  12187. character and `%' to match an arbitrary number of characters (including
  12188. zero characters).  In MySQL, SQL patterns are case-insensitive by
  12189. default.  Some examples are shown here.  Note that you do not use `='
  12190. or `<>' when you use SQL patterns; use the `LIKE' or `NOT LIKE'
  12191. comparison operators instead.
  12192.  
  12193. To find names beginning with `b':
  12194.  
  12195.      mysql> SELECT * FROM pet WHERE name LIKE "b%";
  12196.      +--------+--------+---------+------+------------+------------+
  12197.      | name   | owner  | species | sex  | birth      | death      |
  12198.      +--------+--------+---------+------+------------+------------+
  12199.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  12200.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  12201.      +--------+--------+---------+------+------------+------------+
  12202.  
  12203. To find names ending with `fy':
  12204.  
  12205.      mysql> SELECT * FROM pet WHERE name LIKE "%fy";
  12206.      +--------+--------+---------+------+------------+-------+
  12207.      | name   | owner  | species | sex  | birth      | death |
  12208.      +--------+--------+---------+------+------------+-------+
  12209.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  12210.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  12211.      +--------+--------+---------+------+------------+-------+
  12212.  
  12213. To find names containing a `w':
  12214.  
  12215.      mysql> SELECT * FROM pet WHERE name LIKE "%w%";
  12216.      +----------+-------+---------+------+------------+------------+
  12217.      | name     | owner | species | sex  | birth      | death      |
  12218.      +----------+-------+---------+------+------------+------------+
  12219.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  12220.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12221.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  12222.      +----------+-------+---------+------+------------+------------+
  12223.  
  12224. To find names containing exactly five characters, use fives instances of
  12225. the `_' pattern character:
  12226.  
  12227.      mysql> SELECT * FROM pet WHERE name LIKE "_____";
  12228.      +-------+--------+---------+------+------------+-------+
  12229.      | name  | owner  | species | sex  | birth      | death |
  12230.      +-------+--------+---------+------+------------+-------+
  12231.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12232.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12233.      +-------+--------+---------+------+------------+-------+
  12234.  
  12235. The other type of pattern matching provided by MySQL uses extended
  12236. regular expressions.  When you test for a match for this type of
  12237. pattern, use the `REGEXP' and `NOT REGEXP' operators (or `RLIKE' and
  12238. `NOT RLIKE', which are synonyms).
  12239.  
  12240. Some characteristics of extended regular expressions are:
  12241.  
  12242.    * `.' matches any single character.
  12243.  
  12244.    * A character class `[...]' matches any character within the
  12245.      brackets.  For example, `[abc]' matches `a', `b', or `c'.  To name
  12246.      a range of characters, use a dash.  `[a-z]' matches any letter,
  12247.      whereas `[0-9]' matches any digit.
  12248.  
  12249.    * `*' matches zero or more instances of the thing preceding it.  For
  12250.      example, `x*' matches any number of `x' characters, `[0-9]*'
  12251.      matches any number of digits, and `.*' matches any number of
  12252.      anything.
  12253.  
  12254.    * A `REGEXP' pattern match succeed if the pattern matches anywhere
  12255.      in the value being tested.  (This differs from a `LIKE' pattern
  12256.      match, which succeeds only if the pattern matches the entire
  12257.      value.)
  12258.  
  12259.    * To anchor a pattern so that it must match the beginning or end of
  12260.      the value being tested, use `^' at the beginning or `$' at the end
  12261.      of the pattern.
  12262.  
  12263. To demonstrate how extended regular expressions work, the `LIKE' queries
  12264. shown previously are rewritten here to use `REGEXP'.
  12265.  
  12266. To find names beginning with `b', use `^' to match the beginning of the
  12267. name:
  12268.  
  12269.      mysql> SELECT * FROM pet WHERE name REGEXP "^b";
  12270.      +--------+--------+---------+------+------------+------------+
  12271.      | name   | owner  | species | sex  | birth      | death      |
  12272.      +--------+--------+---------+------+------------+------------+
  12273.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
  12274.      | Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
  12275.      +--------+--------+---------+------+------------+------------+
  12276.  
  12277. Prior to MySQL Version 3.23.4, `REGEXP' is case-sensitive, and the
  12278. previous query will return no rows. In this case, to match either
  12279. lowercase or uppercase `b', use this query instead:
  12280.  
  12281.      mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
  12282.  
  12283. From MySQL 3.23.4 on, if you really want to force a `REGEXP' comparison
  12284. to be case-sensitive, use the `BINARY' keyword to make one of the
  12285. strings a binary string. This query will match only lowercase `b' at
  12286. the beginning of a name:
  12287.  
  12288.      mysql> SELECT * FROM pet WHERE name REGEXP BINARY "^b";
  12289.  
  12290. To find names ending with `fy', use `$' to match the end of the name:
  12291.  
  12292.      mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
  12293.      +--------+--------+---------+------+------------+-------+
  12294.      | name   | owner  | species | sex  | birth      | death |
  12295.      +--------+--------+---------+------+------------+-------+
  12296.      | Fluffy | Harold | cat     | f    | 1993-02-04 | NULL  |
  12297.      | Buffy  | Harold | dog     | f    | 1989-05-13 | NULL  |
  12298.      +--------+--------+---------+------+------------+-------+
  12299.  
  12300. To find names containing a `w', use this query:
  12301.  
  12302.      mysql> SELECT * FROM pet WHERE name REGEXP "w";
  12303.      +----------+-------+---------+------+------------+------------+
  12304.      | name     | owner | species | sex  | birth      | death      |
  12305.      +----------+-------+---------+------+------------+------------+
  12306.      | Claws    | Gwen  | cat     | m    | 1994-03-17 | NULL       |
  12307.      | Bowser   | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  12308.      | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL       |
  12309.      +----------+-------+---------+------+------------+------------+
  12310.  
  12311. Because a regular expression pattern matches if it occurs anywhere in
  12312. the value, it is not necessary in the previous query to put a wildcard
  12313. on either side of the pattern to get it to match the entire value like
  12314. it would be if you used an SQL pattern.
  12315.  
  12316. To find names containing exactly five characters, use `^' and `$' to
  12317. match the beginning and end of the name, and five instances of `.' in
  12318. between:
  12319.  
  12320.      mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
  12321.      +-------+--------+---------+------+------------+-------+
  12322.      | name  | owner  | species | sex  | birth      | death |
  12323.      +-------+--------+---------+------+------------+-------+
  12324.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12325.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12326.      +-------+--------+---------+------+------------+-------+
  12327.  
  12328. You could also write the previous query using the `{n}'
  12329. "repeat-`n'-times" operator:
  12330.  
  12331.      mysql> SELECT * FROM pet WHERE name REGEXP "^.{5}$";
  12332.      +-------+--------+---------+------+------------+-------+
  12333.      | name  | owner  | species | sex  | birth      | death |
  12334.      +-------+--------+---------+------+------------+-------+
  12335.      | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  12336.      | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  12337.      +-------+--------+---------+------+------------+-------+
  12338.  
  12339. Counting Rows
  12340. .............
  12341.  
  12342. Databases are often used to answer the question, "How often does a
  12343. certain type of data occur in a table?"  For example, you might want to
  12344. know how many pets you have, or how many pets each owner has, or you
  12345. might want to perform various kinds of census operations on your
  12346. animals.
  12347.  
  12348. Counting the total number of animals you have is the same question as
  12349. "How many rows are in the `pet' table?" because there is one record per
  12350. pet.  `COUNT(*)' counts the number of rows, so the query to count your
  12351. animals looks like this:
  12352.  
  12353.      mysql> SELECT COUNT(*) FROM pet;
  12354.      +----------+
  12355.      | COUNT(*) |
  12356.      +----------+
  12357.      |        9 |
  12358.      +----------+
  12359.  
  12360. Earlier, you retrieved the names of the people who owned pets.  You can
  12361. use `COUNT()' if you want to find out how many pets each owner has:
  12362.  
  12363.      mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
  12364.      +--------+----------+
  12365.      | owner  | COUNT(*) |
  12366.      +--------+----------+
  12367.      | Benny  |        2 |
  12368.      | Diane  |        2 |
  12369.      | Gwen   |        3 |
  12370.      | Harold |        2 |
  12371.      +--------+----------+
  12372.  
  12373. Note the use of `GROUP BY' to group together all records for each
  12374. `owner'.  Without it, all you get is an error message:
  12375.  
  12376.      mysql> SELECT owner, COUNT(*) FROM pet;
  12377.      ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
  12378.      with no GROUP columns is illegal if there is no GROUP BY clause
  12379.  
  12380. `COUNT()' and `GROUP BY' are useful for characterising your data in
  12381. various ways.  The following examples show different ways to perform
  12382. animal census operations.
  12383.  
  12384. Number of animals per species:
  12385.  
  12386.      mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
  12387.      +---------+----------+
  12388.      | species | COUNT(*) |
  12389.      +---------+----------+
  12390.      | bird    |        2 |
  12391.      | cat     |        2 |
  12392.      | dog     |        3 |
  12393.      | hamster |        1 |
  12394.      | snake   |        1 |
  12395.      +---------+----------+
  12396.  
  12397. Number of animals per sex:
  12398.  
  12399.      mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
  12400.      +------+----------+
  12401.      | sex  | COUNT(*) |
  12402.      +------+----------+
  12403.      | NULL |        1 |
  12404.      | f    |        4 |
  12405.      | m    |        4 |
  12406.      +------+----------+
  12407.  
  12408. (In this output, `NULL' indicates that the sex is unknown.)
  12409.  
  12410. Number of animals per combination of species and sex:
  12411.  
  12412.      mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
  12413.      +---------+------+----------+
  12414.      | species | sex  | COUNT(*) |
  12415.      +---------+------+----------+
  12416.      | bird    | NULL |        1 |
  12417.      | bird    | f    |        1 |
  12418.      | cat     | f    |        1 |
  12419.      | cat     | m    |        1 |
  12420.      | dog     | f    |        1 |
  12421.      | dog     | m    |        2 |
  12422.      | hamster | f    |        1 |
  12423.      | snake   | m    |        1 |
  12424.      +---------+------+----------+
  12425.  
  12426. You need not retrieve an entire table when you use `COUNT()'.  For
  12427. example, the previous query, when performed just on dogs and cats,
  12428. looks like this:
  12429.  
  12430.      mysql> SELECT species, sex, COUNT(*) FROM pet
  12431.          -> WHERE species = "dog" OR species = "cat"
  12432.          -> GROUP BY species, sex;
  12433.      +---------+------+----------+
  12434.      | species | sex  | COUNT(*) |
  12435.      +---------+------+----------+
  12436.      | cat     | f    |        1 |
  12437.      | cat     | m    |        1 |
  12438.      | dog     | f    |        1 |
  12439.      | dog     | m    |        2 |
  12440.      +---------+------+----------+
  12441.  
  12442. Or, if you wanted the number of animals per sex only for known-sex
  12443. animals:
  12444.  
  12445.      mysql> SELECT species, sex, COUNT(*) FROM pet
  12446.          -> WHERE sex IS NOT NULL
  12447.          -> GROUP BY species, sex;
  12448.      +---------+------+----------+
  12449.      | species | sex  | COUNT(*) |
  12450.      +---------+------+----------+
  12451.      | bird    | f    |        1 |
  12452.      | cat     | f    |        1 |
  12453.      | cat     | m    |        1 |
  12454.      | dog     | f    |        1 |
  12455.      | dog     | m    |        2 |
  12456.      | hamster | f    |        1 |
  12457.      | snake   | m    |        1 |
  12458.      +---------+------+----------+
  12459.  
  12460. Using More Than one Table
  12461. .........................
  12462.  
  12463. The `pet' table keeps track of which pets you have.  If you want to
  12464. record other information about them, such as events in their lives like
  12465. visits to the vet or when litters are born, you need another table.
  12466. What should this table look like? It needs:
  12467.  
  12468.    * To contain the pet name so you know which animal each event
  12469.      pertains to.
  12470.  
  12471.    * A date so you know when the event occurred.
  12472.  
  12473.    * A field to describe the event.
  12474.  
  12475.    * An event type field, if you want to be able to categorise events.
  12476.  
  12477. Given these considerations, the `CREATE TABLE' statement for the
  12478. `event' table might look like this:
  12479.  
  12480.      mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
  12481.          -> type VARCHAR(15), remark VARCHAR(255));
  12482.  
  12483. As with the `pet' table, it's easiest to load the initial records by
  12484. creating a tab-delimited text file containing the information:
  12485.  
  12486. *name*      *date*      *type*      *remark*
  12487. Fluffy      1995-05-15  litter      4 kittens, 3 female, 1
  12488.                                     male
  12489. Buffy       1993-06-23  litter      5 puppies, 2 female, 3
  12490.                                     male
  12491. Buffy       1994-06-19  litter      3 puppies, 3 female
  12492. Chirpy      1999-03-21  vet         needed beak straightened
  12493. Slim        1997-08-03  vet         broken rib
  12494. Bowser      1991-10-12  kennel      
  12495. Fang        1991-10-12  kennel      
  12496. Fang        1998-08-28  birthday    Gave him a new chew toy
  12497. Claws       1998-03-17  birthday    Gave him a new flea
  12498.                                     collar
  12499. Whistler    1998-12-09  birthday    First birthday
  12500.  
  12501. Load the records like this:
  12502.  
  12503.      mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
  12504.  
  12505. Based on what you've learned from the queries you've run on the `pet'
  12506. table, you should be able to perform retrievals on the records in the
  12507. `event' table; the principles are the same.  But when is the `event'
  12508. table by itself insufficient to answer questions you might ask?
  12509.  
  12510. Suppose you want to find out the ages at which each pet had its
  12511. litters. We saw earlier how to calculate ages from two dates.  The
  12512. litter date of the mother is in the `event' table, but to calculate her
  12513. age on that date you need her birth date, which is stored in the `pet'
  12514. table.  This means the query requires both tables:
  12515.  
  12516.      mysql> SELECT pet.name,
  12517.          -> (YEAR(date)-YEAR(birth)) - (RIGHT(date,5)<RIGHT(birth,5)) AS age,
  12518.          -> remark
  12519.          -> FROM pet, event
  12520.          -> WHERE pet.name = event.name AND type = "litter";
  12521.      +--------+------+-----------------------------+
  12522.      | name   | age  | remark                      |
  12523.      +--------+------+-----------------------------+
  12524.      | Fluffy |    2 | 4 kittens, 3 female, 1 male |
  12525.      | Buffy  |    4 | 5 puppies, 2 female, 3 male |
  12526.      | Buffy  |    5 | 3 puppies, 3 female         |
  12527.      +--------+------+-----------------------------+
  12528.  
  12529. There are several things to note about this query:
  12530.  
  12531.    * The `FROM' clause lists two tables because the query needs to pull
  12532.      information from both of them.
  12533.  
  12534.    * When combining (joining) information from multiple tables, you
  12535.      need to specify how records in one table can be matched to records
  12536.      in the other.  This is easy because they both have a `name'
  12537.      column.  The query uses `WHERE' clause to match up records in the
  12538.      two tables based on the `name' values.
  12539.  
  12540.    * Because the `name' column occurs in both tables, you must be
  12541.      specific about which table you mean when referring to the column.
  12542.      This is done by prepending the table name to the column name.
  12543.  
  12544. You need not have two different tables to perform a join.  Sometimes it
  12545. is useful to join a table to itself, if you want to compare records in
  12546. a table to other records in that same table.  For example, to find
  12547. breeding pairs among your pets, you can join the `pet' table with
  12548. itself to produce candidate pairs of males and females of like species:
  12549.  
  12550.      mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
  12551.          -> FROM pet AS p1, pet AS p2
  12552.          -> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
  12553.      +--------+------+--------+------+---------+
  12554.      | name   | sex  | name   | sex  | species |
  12555.      +--------+------+--------+------+---------+
  12556.      | Fluffy | f    | Claws  | m    | cat     |
  12557.      | Buffy  | f    | Fang   | m    | dog     |
  12558.      | Buffy  | f    | Bowser | m    | dog     |
  12559.      +--------+------+--------+------+---------+
  12560.  
  12561. In this query, we specify aliases for the table name in order to refer
  12562. to the columns and keep straight which instance of the table each
  12563. column reference is associated with.
  12564.  
  12565. Getting Information About Databases and Tables
  12566. ==============================================
  12567.  
  12568. What if you forget the name of a database or table, or what the
  12569. structure of a given table is (for example, what its columns are
  12570. called)?  MySQL addresses this problem through several statements that
  12571. provide information about the databases and tables it supports.
  12572.  
  12573. You have already seen `SHOW DATABASES', which lists the databases
  12574. managed by the server.  To find out which database is currently
  12575. selected, use the `DATABASE()' function:
  12576.  
  12577.      mysql> SELECT DATABASE();
  12578.      +------------+
  12579.      | DATABASE() |
  12580.      +------------+
  12581.      | menagerie  |
  12582.      +------------+
  12583.  
  12584. If you haven't selected any database yet, the result is `NULL' (or the
  12585. empty string before MySQL 4.1.1).
  12586.  
  12587. To find out what tables the current database contains (for example, when
  12588. you're not sure about the name of a table), use this command:
  12589.  
  12590.      mysql> SHOW TABLES;
  12591.      +---------------------+
  12592.      | Tables in menagerie |
  12593.      +---------------------+
  12594.      | event               |
  12595.      | pet                 |
  12596.      +---------------------+
  12597.  
  12598. If you want to find out about the structure of a table, the `DESCRIBE'
  12599. command is useful; it displays information about each of a table's
  12600. columns:
  12601.  
  12602.      mysql> DESCRIBE pet;
  12603.      +---------+-------------+------+-----+---------+-------+
  12604.      | Field   | Type        | Null | Key | Default | Extra |
  12605.      +---------+-------------+------+-----+---------+-------+
  12606.      | name    | varchar(20) | YES  |     | NULL    |       |
  12607.      | owner   | varchar(20) | YES  |     | NULL    |       |
  12608.      | species | varchar(20) | YES  |     | NULL    |       |
  12609.      | sex     | char(1)     | YES  |     | NULL    |       |
  12610.      | birth   | date        | YES  |     | NULL    |       |
  12611.      | death   | date        | YES  |     | NULL    |       |
  12612.      +---------+-------------+------+-----+---------+-------+
  12613.  
  12614. `Field' indicates the column name, `Type' is the datatype for the
  12615. column, `NULL' indicates whether the column can contain `NULL' values,
  12616. `Key' indicates whether the column is indexed, and `Default' specifies
  12617. the column's default value.
  12618.  
  12619. If you have indexes on a table, `SHOW INDEX FROM tbl_name' produces
  12620. information about them.
  12621.  
  12622. Using `mysql' in Batch Mode
  12623. ===========================
  12624.  
  12625. In the previous sections, you used `mysql' interactively to enter
  12626. queries and view the results.  You can also run `mysql' in batch mode.
  12627. To do this, put the commands you want to run in a file, then tell
  12628. `mysql' to read its input from the file:
  12629.  
  12630.      shell> mysql < batch-file
  12631.  
  12632. If you are running `mysql' under Windows and have some special
  12633. characters in the file that cause problems, you can do this:
  12634.  
  12635.      dos> mysql -e "source batch-file"
  12636.  
  12637. If you need to specify connection parameters on the command line, the
  12638. command might look like this:
  12639.  
  12640.      shell> mysql -h host -u user -p < batch-file
  12641.      Enter password: ********
  12642.  
  12643. When you use `mysql' this way, you are creating a script file, then
  12644. executing the script.
  12645.  
  12646. If you want the script to continue even if some of the statements in it
  12647. produce errors, you should use the `--force' command-line option.
  12648.  
  12649. Why use a script?  Here are a few reasons:
  12650.  
  12651.    * If you run a query repeatedly (say, every day or every week),
  12652.      making it a script allows you to avoid retyping it each time you
  12653.      execute it.
  12654.  
  12655.    * You can generate new queries from existing ones that are similar
  12656.      by copying and editing script files.
  12657.  
  12658.    * Batch mode can also be useful while you're developing a query,
  12659.      particularly for multiple-line commands or multiple-statement
  12660.      sequences of commands.  If you make a mistake, you don't have to
  12661.      retype everything.  Just edit your script to correct the error,
  12662.      then tell `mysql' to execute it again.
  12663.  
  12664.    * If you have a query that produces a lot of output, you can run the
  12665.      output through a pager rather than watching it scroll off the top
  12666.      of your screen:
  12667.  
  12668.           shell> mysql < batch-file | more
  12669.  
  12670.    * You can catch the output in a file for further processing:
  12671.  
  12672.           shell> mysql < batch-file > mysql.out
  12673.  
  12674.    * You can distribute your script to other people so they can run the
  12675.      commands, too.
  12676.  
  12677.    * Some situations do not allow for interactive use, for example,
  12678.      when you run a query from a `cron' job.  In this case, you must
  12679.      use batch mode.
  12680.  
  12681. The default output format is different (more concise) when you run
  12682. `mysql' in batch mode than when you use it interactively.  For example,
  12683. the output of `SELECT DISTINCT species FROM pet' looks like this when
  12684. `mysql' is run interactively:
  12685.  
  12686.      +---------+
  12687.      | species |
  12688.      +---------+
  12689.      | bird    |
  12690.      | cat     |
  12691.      | dog     |
  12692.      | hamster |
  12693.      | snake   |
  12694.      +---------+
  12695.  
  12696. In batch mode, the output looks like this instead:
  12697.  
  12698.      species
  12699.      bird
  12700.      cat
  12701.      dog
  12702.      hamster
  12703.      snake
  12704.  
  12705. If you want to get the interactive output format in batch mode, use
  12706. `mysql -t'.  To echo to the output the commands that are executed, use
  12707. `mysql -vvv'.
  12708.  
  12709. You can also use scripts from the `mysql' prompt by using the `source'
  12710. command:
  12711.  
  12712.      mysql> source filename;
  12713.  
  12714. Examples of Common Queries
  12715. ==========================
  12716.  
  12717. Here are examples of how to solve some common problems with MySQL.
  12718.  
  12719. Some of the examples use the table `shop' to hold the price of each
  12720. article (item number) for certain traders (dealers).  Supposing that
  12721. each trader has a single fixed price per article, then (`article',
  12722. `dealer') is a primary key for the records.
  12723.  
  12724. Start the command-line tool `mysql' and select a database:
  12725.  
  12726.      shell> mysql your-database-name
  12727.  
  12728. (In most MySQL installations, you can use the database name `test').
  12729.  
  12730. You can create and populate the example table with these statements:
  12731.  
  12732.      mysql> CREATE TABLE shop (
  12733.          -> article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  12734.          -> dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
  12735.          -> price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
  12736.          -> PRIMARY KEY(article, dealer));
  12737.      mysql> INSERT INTO shop VALUES
  12738.          -> (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
  12739.          -> (3,'D',1.25),(4,'D',19.95);
  12740.  
  12741. After issuing the statements, the table should have the following
  12742. contents:
  12743.  
  12744.      mysql> SELECT * FROM shop;
  12745.      +---------+--------+-------+
  12746.      | article | dealer | price |
  12747.      +---------+--------+-------+
  12748.      |    0001 | A      |  3.45 |
  12749.      |    0001 | B      |  3.99 |
  12750.      |    0002 | A      | 10.99 |
  12751.      |    0003 | B      |  1.45 |
  12752.      |    0003 | C      |  1.69 |
  12753.      |    0003 | D      |  1.25 |
  12754.      |    0004 | D      | 19.95 |
  12755.      +---------+--------+-------+
  12756.  
  12757. The Maximum Value for a Column
  12758. ------------------------------
  12759.  
  12760. "What's the highest item number?"
  12761.  
  12762.      SELECT MAX(article) AS article FROM shop;
  12763.      
  12764.      +---------+
  12765.      | article |
  12766.      +---------+
  12767.      |       4 |
  12768.      +---------+
  12769.  
  12770. The Row Holding the Maximum of a Certain Column
  12771. -----------------------------------------------
  12772.  
  12773. "Find number, dealer, and price of the most expensive article."
  12774.  
  12775. In SQL-99 (and MySQL Version 4.1) this is easily done with a subquery:
  12776.  
  12777.      SELECT article, dealer, price
  12778.      FROM   shop
  12779.      WHERE  price=(SELECT MAX(price) FROM shop);
  12780.  
  12781. In MySQL versions prior to 4.1, just do it in two steps:
  12782.  
  12783.   1. Get the maximum price value from the table with a `SELECT'
  12784.      statement.
  12785.           mysql> SELECT MAX(price) FROM shop;
  12786.           +------------+
  12787.           | MAX(price) |
  12788.           +------------+
  12789.           |      19.95 |
  12790.           +------------+
  12791.  
  12792.   2. Using the value 19.95 shown by the previous query to be the maximum
  12793.      article price, write a query to locate and display the
  12794.      corresponding record:
  12795.           mysql> SELECT article, dealer, price
  12796.               -> FROM   shop
  12797.               -> WHERE  price=19.95;
  12798.           +---------+--------+-------+
  12799.           | article | dealer | price |
  12800.           +---------+--------+-------+
  12801.           |    0004 | D      | 19.95 |
  12802.           +---------+--------+-------+
  12803.  
  12804. Another solution is to sort all rows descending by price and only get
  12805. the first row using the MySQL-specific `LIMIT' clause:
  12806.  
  12807.      SELECT article, dealer, price
  12808.      FROM   shop
  12809.      ORDER BY price DESC
  12810.      LIMIT 1;
  12811.  
  12812. *NOTE*:  If there were several most expensive articles, each with a
  12813. price of 19.95, the `LIMIT' solution would show only one of them!
  12814.  
  12815. Maximum of Column per Group
  12816. ---------------------------
  12817.  
  12818. "What's the highest price per article?"
  12819.  
  12820.      SELECT article, MAX(price) AS price
  12821.      FROM   shop
  12822.      GROUP BY article
  12823.      
  12824.      +---------+-------+
  12825.      | article | price |
  12826.      +---------+-------+
  12827.      |    0001 |  3.99 |
  12828.      |    0002 | 10.99 |
  12829.      |    0003 |  1.69 |
  12830.      |    0004 | 19.95 |
  12831.      +---------+-------+
  12832.  
  12833. The Rows Holding the Group-wise Maximum of a Certain Field
  12834. ----------------------------------------------------------
  12835.  
  12836. "For each article, find the dealer(s) with the most expensive price."
  12837.  
  12838. In SQL-99 (and MySQL Version 4.1 or greater), the problem can be solved
  12839. with a subquery like this:
  12840.  
  12841.      SELECT article, dealer, price
  12842.      FROM   shop s1
  12843.      WHERE  price=(SELECT MAX(s2.price)
  12844.                    FROM shop s2
  12845.                    WHERE s1.article = s2.article);
  12846.  
  12847. In MySQL versions prior to 4.1, it's best do it in several steps:
  12848.  
  12849.   1. Get the list of (article,maxprice) pairs.
  12850.  
  12851.   2. For each article, get the corresponding rows that have the stored
  12852.      maximum price.
  12853.  
  12854. This can easily be done with a temporary table and a join:
  12855.  
  12856.      CREATE TEMPORARY TABLE tmp (
  12857.              article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
  12858.              price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL);
  12859.      
  12860.      LOCK TABLES shop READ;
  12861.      
  12862.      INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
  12863.      
  12864.      SELECT shop.article, dealer, shop.price FROM shop, tmp
  12865.      WHERE shop.article=tmp.article AND shop.price=tmp.price;
  12866.      
  12867.      UNLOCK TABLES;
  12868.      
  12869.      DROP TABLE tmp;
  12870.  
  12871. If you don't use a `TEMPORARY' table, you must also lock the `tmp'
  12872. table.
  12873.  
  12874. "Can it be done with a single query?"
  12875.  
  12876. Yes, but only by using a quite inefficient trick called the "MAX-CONCAT
  12877. trick":
  12878.  
  12879.      SELECT article,
  12880.             SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
  12881.        0.00+LEFT(      MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
  12882.      FROM   shop
  12883.      GROUP BY article;
  12884.      
  12885.      +---------+--------+-------+
  12886.      | article | dealer | price |
  12887.      +---------+--------+-------+
  12888.      |    0001 | B      |  3.99 |
  12889.      |    0002 | A      | 10.99 |
  12890.      |    0003 | C      |  1.69 |
  12891.      |    0004 | D      | 19.95 |
  12892.      +---------+--------+-------+
  12893.  
  12894. The last example can, of course, be made a bit more efficient by doing
  12895. the splitting of the concatenated column in the client.
  12896.  
  12897. Using User Variables
  12898. --------------------
  12899.  
  12900. You can use MySQL user variables to remember results without having to
  12901. store them in temporary variables in the client.  *Note Variables::.
  12902.  
  12903. For example, to find the articles with the highest and lowest price you
  12904. can do this:
  12905.  
  12906.      mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
  12907.      mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
  12908.      +---------+--------+-------+
  12909.      | article | dealer | price |
  12910.      +---------+--------+-------+
  12911.      |    0003 | D      |  1.25 |
  12912.      |    0004 | D      | 19.95 |
  12913.      +---------+--------+-------+
  12914.  
  12915. Using Foreign Keys
  12916. ------------------
  12917.  
  12918. In MySQL 3.23.44 and up, `InnoDB' tables support checking of foreign
  12919. key constraints. *Note `InnoDB': InnoDB.  See also *Note ANSI diff
  12920. Foreign Keys::.
  12921.  
  12922. You don't actually need foreign keys to join 2 tables.  For table types
  12923. other than `InnoDB'), the only things MySQL currently doesn't do are 1)
  12924. `CHECK' to make sure that the keys you use really exist in the table(s)
  12925. you're referencing and 2) automatically delete rows from a table with a
  12926. foreign key definition. Using your keys to join tables will work just
  12927. fine:
  12928.  
  12929.      CREATE TABLE person (
  12930.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  12931.          name CHAR(60) NOT NULL,
  12932.          PRIMARY KEY (id)
  12933.      );
  12934.      
  12935.      CREATE TABLE shirt (
  12936.          id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  12937.          style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
  12938.          colour ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
  12939.          owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id),
  12940.          PRIMARY KEY (id)
  12941.      );
  12942.      
  12943.      
  12944.      INSERT INTO person VALUES (NULL, 'Antonio Paz');
  12945.      
  12946.      INSERT INTO shirt VALUES
  12947.      (NULL, 'polo', 'blue', LAST_INSERT_ID()),
  12948.      (NULL, 'dress', 'white', LAST_INSERT_ID()),
  12949.      (NULL, 't-shirt', 'blue', LAST_INSERT_ID());
  12950.      
  12951.      
  12952.      INSERT INTO person VALUES (NULL, 'Lilliana Angelovska');
  12953.      
  12954.      INSERT INTO shirt VALUES
  12955.      (NULL, 'dress', 'orange', LAST_INSERT_ID()),
  12956.      (NULL, 'polo', 'red', LAST_INSERT_ID()),
  12957.      (NULL, 'dress', 'blue', LAST_INSERT_ID()),
  12958.      (NULL, 't-shirt', 'white', LAST_INSERT_ID());
  12959.      
  12960.      
  12961.      SELECT * FROM person;
  12962.      +----+---------------------+
  12963.      | id | name                |
  12964.      +----+---------------------+
  12965.      |  1 | Antonio Paz         |
  12966.      |  2 | Lilliana Angelovska |
  12967.      +----+---------------------+
  12968.      
  12969.      SELECT * FROM shirt;
  12970.      +----+---------+--------+-------+
  12971.      | id | style   | colour | owner |
  12972.      +----+---------+--------+-------+
  12973.      |  1 | polo    | blue   |     1 |
  12974.      |  2 | dress   | white  |     1 |
  12975.      |  3 | t-shirt | blue   |     1 |
  12976.      |  4 | dress   | orange |     2 |
  12977.      |  5 | polo    | red    |     2 |
  12978.      |  6 | dress   | blue   |     2 |
  12979.      |  7 | t-shirt | white  |     2 |
  12980.      +----+---------+--------+-------+
  12981.      
  12982.      
  12983.      SELECT s.* FROM person p, shirt s
  12984.       WHERE p.name LIKE 'Lilliana%'
  12985.         AND s.owner = p.id
  12986.         AND s.colour <> 'white';
  12987.      
  12988.      +----+-------+--------+-------+
  12989.      | id | style | colour | owner |
  12990.      +----+-------+--------+-------+
  12991.      |  4 | dress | orange |     2 |
  12992.      |  5 | polo  | red    |     2 |
  12993.      |  6 | dress | blue   |     2 |
  12994.      +----+-------+--------+-------+
  12995.  
  12996. Searching on Two Keys
  12997. ---------------------
  12998.  
  12999. MySQL doesn't yet optimise when you search on two different keys
  13000. combined with `OR' (searching on one key with different `OR' parts is
  13001. optimised quite well):
  13002.  
  13003.      SELECT field1_index, field2_index FROM test_table
  13004.      WHERE field1_index = '1' OR  field2_index = '1'
  13005.  
  13006. The reason is that we haven't yet had time to come up with an efficient
  13007. way to handle this in the general case. (The `AND' handling is, in
  13008. comparison, now completely general and works very well.)
  13009.  
  13010. In MySQL 4.0 and up, you can solve this problem efficiently by using a
  13011. `UNION' that combines the output of two separate `SELECT' statements.
  13012. *Note UNION::.  Each `SELECT' searches only one key and can be
  13013. optimised:
  13014.  
  13015.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
  13016.      UNION
  13017.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  13018.  
  13019. Prior to MySQL 4.0, you can achieve the same effect by using a
  13020. `TEMPORARY' table and separate `SELECT' statements.  This type of
  13021. optimisation is also very good if you are using very complicated
  13022. queries where the SQL server does the optimisations in the wrong order.
  13023.  
  13024.      CREATE TEMPORARY TABLE tmp
  13025.      SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
  13026.      INSERT INTO tmp
  13027.      SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
  13028.      SELECT * from tmp;
  13029.      DROP TABLE tmp;
  13030.  
  13031. The above way to solve this query is in effect a `UNION' of two queries.
  13032.  
  13033. Calculating Visits Per Day
  13034. --------------------------
  13035.  
  13036. The following example shows how you can use the bit group functions to
  13037. calculate the number of days per month a user has visited a web page.
  13038.  
  13039.      CREATE TABLE t1 (year YEAR(4), month INT(2) UNSIGNED ZEROFILL,
  13040.                   day INT(2) UNSIGNED ZEROFILL);
  13041.      INSERT INTO t1 VALUES(2000,1,1),(2000,1,20),(2000,1,30),(2000,2,2),
  13042.                  (2000,2,23),(2000,2,23);
  13043.  
  13044. The example table contains year-month-day values representing visits by
  13045. users to the page. To determine how many different days in each month
  13046. these visits occur, use this query:
  13047.  
  13048.      SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM t1
  13049.             GROUP BY year,month;
  13050.  
  13051. Which returns:
  13052.  
  13053.      +------+-------+------+
  13054.      | year | month | days |
  13055.      +------+-------+------+
  13056.      | 2000 |    01 |    3 |
  13057.      | 2000 |    02 |    2 |
  13058.      +------+-------+------+
  13059.  
  13060. The query calculates how many different days appear in the table for
  13061. each year/month combination, with automatic removal of duplicate
  13062. entries.
  13063.  
  13064. Using `AUTO_INCREMENT'
  13065. ----------------------
  13066.  
  13067. The `AUTO_INCREMENT' attribute can be used to generate a unique
  13068. identity for new rows:
  13069.  
  13070.      CREATE TABLE animals (
  13071.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13072.                   name CHAR(30) NOT NULL,
  13073.                   PRIMARY KEY (id)
  13074.                   );
  13075.      INSERT INTO animals (name) VALUES ("dog"),("cat"),("penguin"),
  13076.                                        ("lax"),("whale"),("ostrich");
  13077.      SELECT * FROM animals;
  13078.  
  13079. Which returns:
  13080.  
  13081.      +----+---------+
  13082.      | id | name    |
  13083.      +----+---------+
  13084.      |  1 | dog     |
  13085.      |  2 | cat     |
  13086.      |  3 | penguin |
  13087.      |  4 | lax     |
  13088.      |  5 | whale   |
  13089.      |  6 | ostrich |
  13090.      +----+---------+
  13091.  
  13092. You can retrieve the most recent `AUTO_INCREMENT' value with the
  13093. `LAST_INSERT_ID()' SQL function or the `mysql_insert_id()' C API
  13094. function.  Note: For a multiple-row insert,
  13095. `LAST_INSERT_ID()'/`mysql_insert_id()' will actually return the
  13096. `AUTO_INCREMENT' key from the *first* of the inserted rows.  This
  13097. allows multiple-row inserts to be reproduced correctly on other servers
  13098. in a replication setup.
  13099.  
  13100. For `MyISAM' and `BDB' tables you can specify `AUTO_INCREMENT' on a
  13101. secondary column in a multiple-column index.  In this case, the
  13102. generated value for the `AUTO_INCREMENT' column is calculated as
  13103. `MAX(auto_increment_column)+1) WHERE prefix=given-prefix'.  This is
  13104. useful when you want to put data into ordered groups.
  13105.  
  13106.      CREATE TABLE animals (
  13107.                   grp ENUM('fish','mammal','bird') NOT NULL,
  13108.                   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  13109.                   name CHAR(30) NOT NULL,
  13110.                   PRIMARY KEY (grp,id)
  13111.                   );
  13112.      INSERT INTO animals (grp,name) VALUES("mammal","dog"),("mammal","cat"),
  13113.                        ("bird","penguin"),("fish","lax"),("mammal","whale"),
  13114.                        ("bird","ostrich");
  13115.      SELECT * FROM animals ORDER BY grp,id;
  13116.  
  13117. Which returns:
  13118.  
  13119.      +--------+----+---------+
  13120.      | grp    | id | name    |
  13121.      +--------+----+---------+
  13122.      | fish   |  1 | lax     |
  13123.      | mammal |  1 | dog     |
  13124.      | mammal |  2 | cat     |
  13125.      | mammal |  3 | whale   |
  13126.      | bird   |  1 | penguin |
  13127.      | bird   |  2 | ostrich |
  13128.      +--------+----+---------+
  13129.  
  13130. Note that in this case (when the `AUTO_INCREMENT' column is part of a
  13131. multiple-column index), `AUTO_INCREMENT' values will be reused if you
  13132. delete the row with the biggest `AUTO_INCREMENT' value in any group.
  13133. This happens even for `MyISAM' tables, for which `AUTO_INCREMENT'
  13134. values normally are not reused.)
  13135.  
  13136. Queries from the Twin Project
  13137. =============================
  13138.  
  13139. At Analytikerna and Lentus, we have been doing the systems and field
  13140. work for a big research project. This project is a collaboration
  13141. between the Institute of Environmental Medicine at Karolinska
  13142. Institutet Stockholm and the Section on Clinical Research in Aging and
  13143. Psychology at the University of Southern California.
  13144.  
  13145. The project involves a screening part where all twins in Sweden older
  13146. than 65 years are interviewed by telephone. Twins who meet certain
  13147. criteria are passed on to the next stage. In this latter stage, twins
  13148. who want to participate are visited by a doctor/nurse team. Some of the
  13149. examinations include physical and neuropsychological examination,
  13150. laboratory testing, neuroimaging, psychological status assessment, and
  13151. family history collection. In addition, data are collected on medical
  13152. and environmental risk factors.
  13153.  
  13154. More information about Twin studies can be found at:
  13155. `http://www.mep.ki.se/twinreg/index_en.html'
  13156.  
  13157. The latter part of the project is administered with a web interface
  13158. written using Perl and MySQL.
  13159.  
  13160. Each night all data from the interviews is moved into a MySQL database.
  13161.  
  13162. Find All Non-distributed Twins
  13163. ------------------------------
  13164.  
  13165. The following query is used to determine who goes into the second part
  13166. of the project:
  13167.  
  13168.      SELECT
  13169.              CONCAT(p1.id, p1.tvab) + 0 AS tvid,
  13170.              CONCAT(p1.christian_name, " ", p1.surname) AS Name,
  13171.              p1.postal_code AS Code,
  13172.              p1.city AS City,
  13173.              pg.abrev AS Area,
  13174.              IF(td.participation = "Aborted", "A", " ") AS A,
  13175.              p1.dead AS dead1,
  13176.              l.event AS event1,
  13177.              td.suspect AS tsuspect1,
  13178.              id.suspect AS isuspect1,
  13179.              td.severe AS tsevere1,
  13180.              id.severe AS isevere1,
  13181.              p2.dead AS dead2,
  13182.              l2.event AS event2,
  13183.              h2.nurse AS nurse2,
  13184.              h2.doctor AS doctor2,
  13185.              td2.suspect AS tsuspect2,
  13186.              id2.suspect AS isuspect2,
  13187.              td2.severe AS tsevere2,
  13188.              id2.severe AS isevere2,
  13189.              l.finish_date
  13190.      FROM
  13191.              twin_project AS tp
  13192.              /* For Twin 1 */
  13193.              LEFT JOIN twin_data AS td ON tp.id = td.id
  13194.                        AND tp.tvab = td.tvab
  13195.              LEFT JOIN informant_data AS id ON tp.id = id.id
  13196.                        AND tp.tvab = id.tvab
  13197.              LEFT JOIN harmony AS h ON tp.id = h.id
  13198.                        AND tp.tvab = h.tvab
  13199.              LEFT JOIN lentus AS l ON tp.id = l.id
  13200.                        AND tp.tvab = l.tvab
  13201.              /* For Twin 2 */
  13202.              LEFT JOIN twin_data AS td2 ON p2.id = td2.id
  13203.                        AND p2.tvab = td2.tvab
  13204.              LEFT JOIN informant_data AS id2 ON p2.id = id2.id
  13205.                        AND p2.tvab = id2.tvab
  13206.              LEFT JOIN harmony AS h2 ON p2.id = h2.id
  13207.                        AND p2.tvab = h2.tvab
  13208.              LEFT JOIN lentus AS l2 ON p2.id = l2.id
  13209.                        AND p2.tvab = l2.tvab,
  13210.              person_data AS p1,
  13211.              person_data AS p2,
  13212.              postal_groups AS pg
  13213.      WHERE
  13214.              /* p1 gets main twin and p2 gets his/her twin. */
  13215.              /* ptvab is a field inverted from tvab */
  13216.              p1.id = tp.id AND p1.tvab = tp.tvab AND
  13217.              p2.id = p1.id AND p2.ptvab = p1.tvab AND
  13218.              /* Just the sceening survey */
  13219.              tp.survey_no = 5 AND
  13220.              /* Skip if partner died before 65 but allow emigration (dead=9) */
  13221.              (p2.dead = 0 OR p2.dead = 9 OR
  13222.               (p2.dead = 1 AND
  13223.                (p2.death_date = 0 OR
  13224.                 (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
  13225.                  >= 65))))
  13226.              AND
  13227.              (
  13228.              /* Twin is suspect */
  13229.              (td.future_contact = 'Yes' AND td.suspect = 2) OR
  13230.              /* Twin is suspect - Informant is Blessed */
  13231.              (td.future_contact = 'Yes' AND td.suspect = 1
  13232.                                         AND id.suspect = 1) OR
  13233.              /* No twin - Informant is Blessed */
  13234.              (ISNULL(td.suspect) AND id.suspect = 1
  13235.                                  AND id.future_contact = 'Yes') OR
  13236.              /* Twin broken off - Informant is Blessed */
  13237.              (td.participation = 'Aborted'
  13238.               AND id.suspect = 1 AND id.future_contact = 'Yes') OR
  13239.              /* Twin broken off - No inform - Have partner */
  13240.              (td.participation = 'Aborted' AND ISNULL(id.suspect)
  13241.                                            AND p2.dead = 0))
  13242.              AND
  13243.              l.event = 'Finished'
  13244.              /* Get at area code */
  13245.              AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
  13246.              /* Not already distributed */
  13247.              AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
  13248.              /* Has not refused or been aborted */
  13249.              AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
  13250.              OR h.status = 'Died' OR h.status = 'Other')
  13251.      ORDER BY
  13252.              tvid;
  13253.  
  13254. Some explanations:
  13255. `CONCAT(p1.id, p1.tvab) + 0 AS tvid'
  13256.      We want to sort on the concatenated `id' and `tvab' in numerical
  13257.      order. Adding `0' to the result causes MySQL to treat the result
  13258.      as a number.
  13259.  
  13260. column `id'
  13261.      This identifies a pair of twins. It is a key in all tables.
  13262.  
  13263. column `tvab'
  13264.      This identifies a twin in a pair. It has a value of `1' or `2'.
  13265.  
  13266. column `ptvab'
  13267.      This is an inverse of `tvab'. When `tvab' is `1' this is `2', and
  13268.      vice versa. It exists to save typing and to make it easier for
  13269.      MySQL to optimise the query.
  13270.  
  13271. This query demonstrates, among other things, how to do lookups on a
  13272. table from the same table with a join (`p1' and `p2'). In the example,
  13273. this is used to check whether a twin's partner died before the age of
  13274. 65. If so, the row is not returned.
  13275.  
  13276. All of the above exist in all tables with twin-related information. We
  13277. have a key on both `id,tvab' (all tables), and `id,ptvab'
  13278. (`person_data') to make queries faster.
  13279.  
  13280. On our production machine (A 200MHz UltraSPARC), this query returns
  13281. about 150-200 rows and takes less than one second.
  13282.  
  13283. The current number of records in the tables used above:
  13284. *Table*            *Rows*
  13285. `person_data'      71074
  13286. `lentus'           5291
  13287. `twin_project'     5286
  13288. `twin_data'        2012
  13289. `informant_data'   663
  13290. `harmony'          381
  13291. `postal_groups'    100
  13292.  
  13293. Show a Table of Twin Pair Status
  13294. --------------------------------
  13295.  
  13296. Each interview ends with a status code called `event'. The query shown
  13297. here is used to display a table over all twin pairs combined by event.
  13298. This indicates in how many pairs both twins are finished, in how many
  13299. pairs one twin is finished and the other refused, and so on.
  13300.  
  13301.      SELECT
  13302.              t1.event,
  13303.              t2.event,
  13304.              COUNT(*)
  13305.      FROM
  13306.              lentus AS t1,
  13307.              lentus AS t2,
  13308.              twin_project AS tp
  13309.      WHERE
  13310.              /* We are looking at one pair at a time */
  13311.              t1.id = tp.id
  13312.              AND t1.tvab=tp.tvab
  13313.              AND t1.id = t2.id
  13314.              /* Just the sceening survey */
  13315.              AND tp.survey_no = 5
  13316.              /* This makes each pair only appear once */
  13317.              AND t1.tvab='1' AND t2.tvab='2'
  13318.      GROUP BY
  13319.              t1.event, t2.event;
  13320.  
  13321. Using MySQL with Apache
  13322. =======================
  13323.  
  13324. There are programs that let you authenticate your users from a MySQL
  13325. database and also let you write your log files into a MySQL table.
  13326.  
  13327. You can change the Apache logging format to be easily readable by MySQL
  13328. by putting the following into the Apache configuration file:
  13329.  
  13330.      LogFormat \
  13331.              "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \
  13332.              \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""
  13333.  
  13334. To load a log file in that format into MySQL, you can use a statement
  13335. something like this:
  13336.  
  13337.      LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
  13338.      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
  13339.  
  13340. The named table should be created to have columns that correspond to
  13341. those that the `LogFormat' line writes to the log file.
  13342.  
  13343. Database Administration
  13344. ***********************
  13345.  
  13346. Configuring MySQL
  13347. =================
  13348.  
  13349. `mysqld' Command-line Options
  13350. -----------------------------
  13351.  
  13352. In most cases you should manage `mysqld' options through option files.
  13353. *Note Option files::.
  13354.  
  13355. `mysqld' and `mysqld.server' read options from the `mysqld' and
  13356. `server' groups. `mysqld_safe' read options from the `mysqld',
  13357. `server', `mysqld_safe' and `safe_mysqld' groups.  An embedded MySQL
  13358. server usually reads options from the `server', `embedded' and
  13359. `xxxxx_SERVER', where `xxxxx' is the name of the application.
  13360.  
  13361. `mysqld' accepts a lot of command-line options. Here follows some of
  13362. the most common ones. For a full list execute `mysqld --help'.  Options
  13363. used for replication are listed in a separate section, see *Note
  13364. Replication Options::.
  13365.  
  13366. `--ansi'
  13367.      Use SQL-99 syntax instead of MySQL syntax.  *Note ANSI mode::.
  13368.  
  13369. `-b, --basedir=path'
  13370.      Path to installation directory. All paths are usually resolved
  13371.      relative to this.
  13372.  
  13373. `--big-tables'
  13374.      Allow big result sets by saving all temporary sets on file.  It
  13375.      solves most 'table full' errors, but also slows down the queries
  13376.      where in-memory tables would suffice.  Since Version 3.23.2, MySQL
  13377.      is able to solve it automatically by using memory for small
  13378.      temporary tables and switching to disk tables where necessary.
  13379.  
  13380. `--bind-address=IP'
  13381.      IP address to bind to.
  13382.  
  13383. `--console'
  13384.      Write the error log messages to stderr/stdout even if `--log-error'
  13385.      is specified.  On Windows, `mysqld' will not close the console
  13386.      screen if this option is used.
  13387.  
  13388. `--character-sets-dir=path'
  13389.      Directory where character sets are.  *Note Character sets::.
  13390.  
  13391. `--chroot=path'
  13392.      Put `mysqld' daemon in chroot environment at startup. Recommended
  13393.      security measure since MySQL 4.0 (MySQL 3.23 is not able to provide
  13394.      100% closed chroot jail).  It somewhat limits `LOAD DATA INFILE'
  13395.      and `SELECT ... INTO OUTFILE' though.
  13396.  
  13397. `--core-file'
  13398.      Write a core file if `mysqld' dies.  For some systems you must also
  13399.      specify `--core-file-size' to `mysqld_safe'.  *Note `mysqld_safe':
  13400.      mysqld_safe.  Note that on some systems, like Solaris, you will
  13401.      not get a core file if you are also using the `--user' option.
  13402.  
  13403. `-h, --datadir=path'
  13404.      Path to the database root.
  13405.  
  13406. `--debug[...]='
  13407.      If MySQL is configured with `--with-debug', you can use this
  13408.      option to get a trace file of what `mysqld' is doing.  *Note
  13409.      Making trace files::.
  13410.  
  13411. `--default-character-set=charset'
  13412.      Set the default character set.  *Note Character sets::.
  13413.  
  13414. `--default-table-type=type'
  13415.      Set the default table type for tables.  *Note Table types::.
  13416.  
  13417. `--delay-key-write[= OFF | ON | ALL]'
  13418.      How MyISAM `DELAYED KEYS' should be used. *Note Server
  13419.      parameters::.
  13420.  
  13421. `--delay-key-write-for-all-tables;  In MySQL 4.0.3 you should use --delay-key-write=ALL instead.'
  13422.      Don't flush key buffers between writes for any `MyISAM' table.
  13423.      *Note Server parameters::.
  13424.  
  13425. `--des-key-file=filename'
  13426.      Read the default keys used by `DES_ENCRYPT()' and `DES_DECRYPT()'
  13427.      from this file.
  13428.  
  13429. `--enable-external-locking (was --enable-locking)'
  13430.      Enable system locking.  Note that if you use this option on a
  13431.      system on which `lockd' does not fully work (as on Linux), you
  13432.      will easily get mysqld to deadlock.
  13433.  
  13434. `--enable-named-pipe'
  13435.      Enable support for named pipes (only on NT/Win2000/XP).
  13436.  
  13437. `-T, --exit-info'
  13438.      This is a bit mask of different flags one can use for debugging the
  13439.      mysqld server; one should not use this option if one doesn't know
  13440.      exactly what it does!
  13441.  
  13442. `--flush'
  13443.      Flush all changes to disk after each SQL command.  Normally MySQL
  13444.      only does a write of all changes to disk after each SQL command
  13445.      and lets the operating system handle the syncing to disk.  *Note
  13446.      Crashing::.
  13447.  
  13448. `-?, --help'
  13449.      Display short help and exit.
  13450.  
  13451. `--init-file=file'
  13452.      Read SQL commands from this file at startup.
  13453.  
  13454. `-L, --language=...'
  13455.      Client error messages in given language.  May be given as a full
  13456.      path.  *Note Languages::.
  13457.  
  13458. `-l, --log[=file]'
  13459.      Log connections and queries to file. *Note Query log::.
  13460.  
  13461. `--log-bin=[file]'
  13462.      Log all queries that change data to the file. Used for backup and
  13463.      replication.  *Note Binary log::.
  13464.  
  13465. `--log-bin-index[=file]'
  13466.      Index file for binary log file names. *Note Binary log::.
  13467.  
  13468. `--log-error[=file]'
  13469.      Log errors and startup messages to this file. *Note Error log::.
  13470.  
  13471. `--log-isam[=file]'
  13472.      Log all ISAM/MyISAM changes to file (only used when debugging
  13473.      ISAM/MyISAM).
  13474.  
  13475. `--log-long-format'
  13476.      Log some extra information to the logfiles (update log, binary
  13477.      update log, and slow queries log, whatever log has been
  13478.      activated). For example, username and timestamp are logged for
  13479.      queries. If you are using `--log-slow-queries' and
  13480.      `--log-long-format', then also  queries that are not using indexes
  13481.      are logged to the slow query log.  Note that `--log-long-format'
  13482.      is deprecated as of MySQL version  4.1, when `--log-short-format'
  13483.      was introduced (the long log format is the default setting since
  13484.      version 4.1). Also note that starting with MySQL 4.1 the
  13485.      `--log-queries-not-using-indexes' option is available for the
  13486.      purpose of logging queries that do not use indexes to the slow
  13487.      queries log.
  13488.  
  13489. `--log-queries-not-using-indexes'
  13490.      If you are using this option with `--log-slow-queries', then also
  13491.      queries that are not using indexes are logged to the slow query
  13492.      log. This option is available as of MySQL 4.1. *Note Slow query
  13493.      log::.
  13494.  
  13495. `--log-short-format'
  13496.      Log less information to the logfiles (update log, binary update
  13497.      log, and slow queries log, whatever log has been activated). For
  13498.      example, username and timestamp are not logged for queries. This
  13499.      options was introduced in MySQL 4.1.
  13500.  
  13501. `--log-slow-queries[=file]'
  13502.      Log all queries that have taken more than `long_query_time'
  13503.      seconds to execute to file. Note that the default for the amount
  13504.      of information logged has changed in MySQL 4.1. See the
  13505.      `--log-long-format' and `--log-long-format' options for details.
  13506.      *Note Slow query log::.
  13507.  
  13508. `--log-update[=file]'
  13509.      Log updates to `file.#' where `#' is a unique number if not given.
  13510.      *Note Update log::. The update log is deprecated and will be
  13511.      removed in MySQL 5.0; you should use the binary log instead
  13512.      (`--log-bin'). *Note Binary log::. Starting from version 5.0,
  13513.      using `--log-update' will just turn on the binlog instead.
  13514.  
  13515. `--low-priority-updates'
  13516.      Table-modifying operations (`INSERT'/`DELETE'/`UPDATE') will have
  13517.      lower priority than selects.  It can also be done via `{INSERT |
  13518.      REPLACE | UPDATE | DELETE} LOW_PRIORITY ...' to lower the priority
  13519.      of only one query, or by `SET LOW_PRIORITY_UPDATES=1' to change
  13520.      the priority in one thread.  *Note Table locking::.
  13521.  
  13522. `--memlock'
  13523.      Lock the `mysqld' process in memory.  This works only if your
  13524.      system supports the `mlockall()' system call (like Solaris).  This
  13525.      may help if you have a problem where the operating system is
  13526.      causing `mysqld' to swap on disk.  Note that use of this option
  13527.      requires that you run the server as `root', which is normally not
  13528.      a good idea for security reasons.
  13529.  
  13530. `--myisam-recover [=option[,option...]]]'
  13531.      Option is any combination of `DEFAULT', `BACKUP', `FORCE' or
  13532.      `QUICK'.  You can also set this explicitly to `""' if you want to
  13533.      disable this option. If this option is used, `mysqld' will on open
  13534.      check if the table is marked as crashed or if the table wasn't
  13535.      closed properly.  (The last option only works if you are running
  13536.      with `--skip-external-locking'.)  If this is the case `mysqld'
  13537.      will run check on the table. If the table was corrupted, `mysqld'
  13538.      will attempt to repair it.
  13539.  
  13540.      The following options affects how the repair works.
  13541.  
  13542.      *Option*   *Description*
  13543.      DEFAULT    The same as not giving any option to
  13544.                          `--myisam-recover'.
  13545.      BACKUP     If the data table was changed during recover,
  13546.                 save a                     backup of the
  13547.                 `table_name.MYD' datafile as
  13548.                  `table_name-datetime.BAK'.
  13549.      FORCE      Run recover even if we will lose more than one
  13550.                 row                     from the .MYD file.
  13551.      QUICK      Don't check the rows in the table if there
  13552.                 aren't any                     delete blocks.
  13553.  
  13554.      Before a table is automatically repaired, MySQL will add a note
  13555.      about this in the error log.  If you want to be able to recover
  13556.      from most things without user intervention, you should use the
  13557.      options `BACKUP,FORCE'.  This will force a repair of a table even
  13558.      if some rows would be deleted, but it will keep the old datafile
  13559.      as a backup so that you can later examine what happened.
  13560.  
  13561. `--new'
  13562.      From version 4.0.12, the `--new' option can be used to make the
  13563.      server behave as 4.1 in certain aspects, easing a 4.0 to 4.1
  13564.      upgrade:
  13565.         * `TIMESTAMP' is returned as a string with the format
  13566.           `'YYYY-MM-DD HH:MM:SS''.  *Note Column types::.
  13567.  
  13568. `--pid-file=path'
  13569.      Path to pid file used by `mysqld_safe'.
  13570.  
  13571. `-P, --port=...'
  13572.      Port number to listen for TCP/IP connections.
  13573.  
  13574. `-o, --old-protocol'
  13575.      Use the 3.20 protocol for compatibility with some very old clients.
  13576.      *Note Upgrading-from-3.20::.
  13577.  
  13578. `--one-thread'
  13579.      Only use one thread (for debugging under Linux).  *Note Debugging
  13580.      server::.
  13581.  
  13582. `--open-files-limit='
  13583.      To change the number of file descriptors available to `mysqld'.
  13584.      If this is not set or set to 0, then `mysqld' will use this value
  13585.      to reserve file descriptors to use with `setrlimit()'.  If this
  13586.      value is 0 then `mysqld' will reserve `max_connections*5' or
  13587.      `max_connections + table_cache*2' (whichever is larger) number of
  13588.      files.  You should try increasing this if `mysqld' gives you the
  13589.      error 'Too many open files'.
  13590.  
  13591. `-O, --set-variable var=option'
  13592.      Give a variable a value. `--help' lists variables.  You can find a
  13593.      full description for all variables in the `SHOW VARIABLES' section
  13594.      in this manual.  *Note SHOW VARIABLES::.  The tuning server
  13595.      parameters section includes information of how to optimise these.
  13596.      Please note that `--set-variable' is deprecated since MySQL 4.0,
  13597.      just use `--var=option' on its own.  *Note Server parameters::.
  13598.  
  13599.      In MySQL 4.0.2 one can set a variable directly with
  13600.      `--variable-name=option' and `set-variable' is no longer needed in
  13601.      option files.
  13602.  
  13603.      If you want to restrict the maximum value a startup option can be
  13604.      set to with `SET', you can define this by using the
  13605.      `--maximum-variable-name' command line option. *Note SET OPTION::.
  13606.  
  13607.      Note that when setting a variable to a value, MySQL may
  13608.      automatically correct it to stay within a given range and also
  13609.      adjusts the value a little to fix for the used algorithm.
  13610.  
  13611. `--safe-mode'
  13612.      Skip some optimise stages.
  13613.  
  13614. `--safe-show-database'
  13615.      With this option, the `SHOW DATABASES' command returns only those
  13616.      databases for which the user has some kind of privilege.  From
  13617.      version 4.0.2 this option is deprecated and doesn't do anything
  13618.      (the option is enabled by default) as we now have the `SHOW
  13619.      DATABASES' privilege. *Note GRANT::.
  13620.  
  13621. `--safe-user-create'
  13622.      If this is enabled, a user can't create new users with the GRANT
  13623.      command, if the user doesn't have `INSERT' privilege to the
  13624.      `mysql.user' table or any column in this table.
  13625.  
  13626. `--skip-bdb'
  13627.      Disable usage of BDB tables. This will save memory and may speed
  13628.      up some things.
  13629.  
  13630. `--skip-concurrent-insert'
  13631.      Turn off the ability to select and insert at the same time on
  13632.      `MyISAM' tables. (This is only to be used if you think you have
  13633.      found a bug in this feature.)
  13634.  
  13635. `--skip-delay-key-write'
  13636.      In MySQL 4.0.3 you should use -delay-key-write=OFF instead.
  13637.      Ignore the `DELAY_KEY_WRITE' option for all tables.  *Note Server
  13638.      parameters::.
  13639.  
  13640. `--skip-grant-tables'
  13641.      This option causes the server not to use the privilege system at
  13642.      all.  This gives everyone *full access* to all databases!  (You
  13643.      can tell a running server to start using the grant tables again by
  13644.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  13645.  
  13646. `--skip-host-cache'
  13647.      Never use host name cache for faster name-ip resolution, but query
  13648.      DNS server on every connect instead.  *Note DNS::.
  13649.  
  13650. `--skip-innodb'
  13651.      Disable usage of Innodb tables.  This will save memory and disk
  13652.      space and speed up some things.
  13653.  
  13654. `--skip-external-locking (was --skip-locking)'
  13655.      Don't use system locking.  To use `isamchk' or `myisamchk' you must
  13656.      shut down the server.  *Note Stability::.  Note that in MySQL
  13657.      Version 3.23 you can use `REPAIR' and `CHECK' to repair/check
  13658.      `MyISAM' tables.
  13659.  
  13660. `--skip-name-resolve'
  13661.      Hostnames are not resolved.  All `Host' column values in the grant
  13662.      tables must be IP numbers or `localhost'.  *Note DNS::.
  13663.  
  13664. `--skip-networking'
  13665.      Don't listen for TCP/IP connections at all.  All interaction with
  13666.      `mysqld' must be made via named pipes or Unix sockets.  This
  13667.      option is highly recommended for systems where only local requests
  13668.      are allowed.  *Note DNS::.
  13669.  
  13670. `--skip-new'
  13671.      Don't use new, possibly wrong routines.
  13672.  
  13673. `--skip-symlink'
  13674.      Deprecated option in 4.0.13;  use `--skip-symbolic-links' instead.
  13675.  
  13676. `--symbolic-links, --skip-symbolic-links'
  13677.      Enable or disable symbolic link support. This option has different
  13678.      effects on Windows and Unix.
  13679.  
  13680.      On Windows, enabling symbolic links allows you to establish a
  13681.      symbolic link to a database directory by creating a
  13682.      `directory.sym' file that contains the path to the real directory.
  13683.      *Note Windows symbolic links::.
  13684.  
  13685.      On Unix, enabling symbolic links means that you can link a
  13686.      `MyISAM' index file or datafile to another directory with the
  13687.      `INDEX DIRECTORY' or `DATA DIRECTORY' options of the `CREATE
  13688.      TABLE' statement.  If you delete or rename the table, the files
  13689.      that its symbolic links point to also will be deleted or renamed.
  13690.  
  13691. `--skip-safemalloc'
  13692.      If MySQL is configured with `--with-debug=full', all programs
  13693.      check memory for overruns for every memory allocation and memory
  13694.      freeing operations.  This checking is very slow, so for the server
  13695.      you can avoid it when you don't need it by using the
  13696.      `--skip-safemalloc' option.
  13697.  
  13698. `--skip-show-database'
  13699.      Don't allow the `SHOW DATABASES' command, unless the user has the
  13700.      `SHOW DATABASES' privilege.
  13701.  
  13702. `--skip-stack-trace'
  13703.      Don't write stack traces.  This option is useful when you are
  13704.      running `mysqld' under a debugger. On some systems, you also must
  13705.      use this option to get a core file. *Note Debugging server::.
  13706.  
  13707. `--skip-thread-priority'
  13708.      Disable using thread priorities for faster response time.
  13709.  
  13710. `--socket=path'
  13711.      On Unix, the socket file to use for local connections (default
  13712.      `/tmp/mysql.sock').  On Windows, the pipe name to use for local
  13713.      connections that use a named pipe (default `MySql').
  13714.  
  13715. `--sql-mode=value[,value[,value...]]'
  13716.      The option values can be any combination of: `REAL_AS_FLOAT',
  13717.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  13718.      `ONLY_FULL_GROUP_BY', `NO_UNSIGNED_SUBTRACTION',
  13719.      `NO_AUTO_VALUE_ON_ZERO', `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS',
  13720.      `NO_KEY_OPTIONS', `NO_DIR_IN_CREATE', `MYSQL323', `MYSQL40', `DB2',
  13721.      `MAXDB', `MSSQL', `ORACLE', `POSTGRESQL', or `ANSI'.  The value
  13722.      also can be empty (`--sql-mode=""') if you want to reset it.
  13723.  
  13724.      `NO_AUTO_VALUE_ON_ZERO' affects handling of `AUTO_INCREMENT'
  13725.      columns. Normally, you generate the next sequence number for the
  13726.      column by inserting either `NULL' or `0' into it.
  13727.      `NO_AUTO_VALUE_ON_ZERO' suppresses this behaviour for `0' so that
  13728.      only `NULL' generates the next sequence number. This mode can be
  13729.      useful if `0' has been stored in a table's `AUTO_INCREMENT' column
  13730.      (this is not recommended, by the way).  For example, if you dump
  13731.      the table with `mysqldump' and then reload it, normally MySQL will
  13732.      generate new sequence numbers when it encounters the `0' values,
  13733.      resulting in a table with different contents than the one that was
  13734.      dumped. Enabling `NO_AUTO_VALUE_ON_ZERO' before reloading the dump
  13735.      file solves this problem. (As of MySQL 4.1.1, when this option
  13736.      value became available, `mysqldump' automatically includes dump
  13737.      output to enable `NO_AUTO_VALUE_ON_ZERO'.)
  13738.  
  13739.      Several of the option values are used for compatibility with other
  13740.      servers.  If specified, they cause the server to omit from the
  13741.      output of `SHOW CREATE TABLE' those parts of the statement that
  13742.      are not understood by earlier versions of MySQL or other database
  13743.      servers.  Using these option values results in `CREATE TABLE'
  13744.      statements that are more portable for use with other servers:
  13745.  
  13746.         * The `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS',
  13747.           `NO_DIR_IN_CREATE', and `NO_KEY_OPTIONS' values cause
  13748.           omission of table options, or options pertaining to column or
  13749.           index definitions.
  13750.  
  13751.         * The values `MYSQL323' and `MYSQL40' are for compatibility with
  13752.           MySQL 3.23 and MySQL 4.0.
  13753.  
  13754.         * The values used for compatibility with other servers are
  13755.           `DB2', `MAXDB', `MSSQL', `ORACLE', and `POSTGRESQL'.
  13756.  
  13757.  
  13758.      These options also affect the output of `mysqldump', because that
  13759.      program uses `SHOW CREATE TABLE' to obtain the table-creation
  13760.      statements that it includes in its own output.
  13761.  
  13762.      Several of the option values have a complex effect because they
  13763.      are shorthand for a group or set of values.  For example, you can
  13764.      tell the server to run in ANSI mode by using the `--sql-mode=ANSI'
  13765.      (or `--ansi') option, which is equivalent to specifying both of
  13766.      the following command-line options:
  13767.  
  13768.           --sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY
  13769.           --transaction-isolation=SERIALIZABLE
  13770.  
  13771.      Note that specifying ANSI mode in this way also has the effect of
  13772.      setting the transaction isolation level.  For more information
  13773.      about running the server in ANSI mode, see *Note ANSI mode::.
  13774.  
  13775.      Other "group" values are `DB2', `MAXDB', `MSSQL', `ORACLE', and
  13776.      `POSTGRESQL'.  Specifying any of them turns on the
  13777.      `PIPES_AS_CONCAT', `ANSI_QUOTES', `IGNORE_SPACE',
  13778.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', and `NO_KEY_OPTIONS'
  13779.      values.
  13780.  
  13781.      The `--sql-mode' option was added in MySQL 3.23.41.  The
  13782.      `NO_UNSIGNED_SUBTRACTION' value was added in 4.0.0.
  13783.      `NO_DIR_IN_CREATE' was added in 4.0.15.  `NO_AUTO_VALUE_ON_ZERO',
  13784.      `NO_TABLE_OPTIONS', `NO_FIELD_OPTIONS', `NO_KEY_OPTIONS',
  13785.      `MYSQL323', `MYSQL40', `DB2', `MAXDB', `MSSQL', `ORACLE',
  13786.      `POSTGRESQL', and `ANSI' were added in 4.1.1.
  13787.  
  13788. `--temp-pool'
  13789.      Using this option will cause most temporary files created by the
  13790.      server to use a small set of names, rather than a unique name for
  13791.      each new file. This is to work around a problem in the Linux kernel
  13792.      dealing with creating many new files with different names. With
  13793.      the old behaviour, Linux seems to "leak" memory, as it's being
  13794.      allocated to the directory entry cache rather than to the disk
  13795.      cache.
  13796.  
  13797. `--transaction-isolation={ READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE }'
  13798.      Sets the default transaction isolation level.  *Note `SET
  13799.      TRANSACTION': SET TRANSACTION.
  13800.  
  13801. `-t, --tmpdir=path'
  13802.      Path of the directory to use for creating temporary files. It may
  13803.      be useful if your default `/tmp' directory resides on a partition
  13804.      that is too small to hold temporary tables.  Starting from MySQL
  13805.      4.1, this option accepts several paths that are used in
  13806.      round-robin fashion. Paths should be separated by colon characters
  13807.      (`:') on Unix and semicolon characters (`;') on Windows.  It is
  13808.      possible to set `tmpdir' to point to a memory-based filesystem,
  13809.      except if the MySQL server is a slave. If it is a slave, it needs
  13810.      some of its temporary files (for replication of temporary tables
  13811.      or of `LOAD DATA INFILE') to survive a machine's reboot, so a
  13812.      memory-based `tmpdir' which is cleared when the machine reboots is
  13813.      not suitable; a disk-based `tmpdir' is necessary.
  13814.  
  13815. `-u, --user={user_name | user_id}'
  13816.      Run the `mysqld' server as the user having the name `user_name' or
  13817.      numeric user ID `user_id'.  ("User" in this context refers to a
  13818.      system login account, not a MySQL user listed in the grant tables.)
  13819.  
  13820.      This option is *mandatory* when starting `mysqld' as `root'.  The
  13821.      server will change its user ID during its startup sequence,
  13822.      causing it to run as that particular user rather than as `root'.
  13823.      *Note Security::.
  13824.  
  13825.      Starting from MySQL 3.23.56 and 4.0.12: To avoid a possible
  13826.      security hole where a user adds a `--user=root' option to some
  13827.      `my.cnf' file (thus causing the server to run as `root'), `mysqld'
  13828.      uses only the first `--user' option specified and produces a
  13829.      warning if there are multiple `--user' options. Options in
  13830.      `/etc/my.cnf' and `datadir/my.cnf' are processed before
  13831.      command-line options, so it is recommended that you put a `--user'
  13832.      option in `/etc/my.cnf' and specify a value other than `root'. The
  13833.      option in `/etc/my.cnf' will be found before any other `--user'
  13834.      options, which ensures that the server runs as a user other than
  13835.      `root', and that a warning results if any other `--user' option is
  13836.      found.
  13837.  
  13838. `-V, --version'
  13839.      Display version information and exit.
  13840.  
  13841. `-W, --log-warnings'
  13842.      Print out warnings like `Aborted connection...' to the `.err'
  13843.      file. Enabling this option is recommended, for example, if you use
  13844.      replication (you will get more information about what is happening,
  13845.      such as messages about network failures and reconnections). *Note
  13846.      Communication errors::.
  13847.  
  13848.      This option used to be called `--warnings'.
  13849.  
  13850. You can change most values for a running server with the `SET' command.
  13851. *Note `SET OPTION': SET OPTION.
  13852.  
  13853. `my.cnf' Option Files
  13854. ---------------------
  13855.  
  13856. MySQL can, since Version 3.22, read default startup options for the
  13857. server and for clients from option files.
  13858.  
  13859. On Windows, MySQL reads default options from the following files:
  13860.  
  13861. *Filename*                *Purpose*
  13862. `windows-directory\my.ini'Global options
  13863. `C:\my.cnf'               Global options
  13864.  
  13865. `windows-directory' is the location of your Windows directory.
  13866.  
  13867. On Unix, MySQL reads default options from the following files:
  13868.  
  13869. *Filename*                *Purpose*
  13870. `/etc/my.cnf'             Global options
  13871. `DATADIR/my.cnf'          Server-specific options
  13872. `defaults-extra-file'     The file specified with
  13873.                           `--defaults-extra-file=path'
  13874. `~/.my.cnf'               User-specific options
  13875.  
  13876. `DATADIR' is the MySQL data directory (typically
  13877. `/usr/local/mysql/data' for a binary installation or `/usr/local/var'
  13878. for a source installation).  Note that this is the directory that was
  13879. specified at configuration time, not the one specified with `--datadir'
  13880. when `mysqld' starts up!  (`--datadir' has no effect on where the
  13881. server looks for option files, because the server looks for files
  13882. before it processes any command-line arguments.)
  13883.  
  13884. Note that on Windows you should specify all paths in option files with
  13885. `/' instead of `\'. If you use `\', you need to specify it twice,
  13886. because `\' is the escape character in MySQL.
  13887.  
  13888. MySQL tries to read option files in the order listed above.  If
  13889. multiple option files exist, an option specified in a file read later
  13890. takes precedence over the same option specified in a file read earlier.
  13891. Options specified on the command-line take precedence over options
  13892. specified in any option file.  Some options can be specified using
  13893. environment variables.  Options specified on the command-line or in
  13894. option files take precedence over environment variable values. *Note
  13895. Environment variables::.
  13896.  
  13897. The following programs support option files:  `mysql', `mysqladmin',
  13898. `mysqld', `mysqld_safe', `mysql.server', `mysqldump', `mysqlimport',
  13899. `mysqlshow', `mysqlcheck', `myisamchk', and `myisampack'.
  13900.  
  13901. Since Version 4.0.2, you can use the `loose' prefix for command-line
  13902. options (or options in my.cnf). If an option is prefixed by `loose', the
  13903. program reading it will not exit with an error if an option is unknown,
  13904. but will rather only issue a warning:
  13905.  
  13906.      shell> mysql --loose-no-such-option
  13907.  
  13908. Any long option that may be given on the command-line when running a
  13909. MySQL program can be given in an option file as well (without the
  13910. leading double dash).  Run the program with the `--help' option to get
  13911. a list of available options.
  13912.  
  13913. An option file can contain lines of the following forms:
  13914.  
  13915. `#comment'
  13916.      Comment lines start with `#' or `;'. Empty lines are ignored.
  13917.  
  13918. `[group]'
  13919.      `group' is the name of the program or group for which you want to
  13920.      set options.  After a group line, any `option' or `set-variable'
  13921.      lines apply to the named group until the end of the option file or
  13922.      another group line is given.
  13923.  
  13924. `option'
  13925.      This is equivalent to `--option' on the command-line.
  13926.  
  13927. `option=value'
  13928.      This is equivalent to `--option=value' on the command-line.
  13929.  
  13930. `set-variable = variable=value'
  13931.      This is equivalent to `--set-variable variable=value' on the
  13932.      command-line.  Please note that `--set-variable' is deprecated
  13933.      since MySQL 4.0; as of that version, program variable names can be
  13934.      used as option names.  On the command line, just use
  13935.      `--variable=value'. In an option file, use `variable=value'.
  13936.  
  13937. The `[client]' group allows you to specify options that apply to all
  13938. MySQL clients (not `mysqld'). This is the perfect group to use to
  13939. specify the password that you use to connect to the server.  (But make
  13940. sure the option file is readable and writable only by yourself.)
  13941.  
  13942. Note that for options and values, all leading and trailing blanks are
  13943. automatically deleted.  You may use the escape sequences `\b', `\t',
  13944. `\n', `\r', `\\', and `\s' in your value string (`\s' == blank).
  13945.  
  13946. Here is a typical global option file:
  13947.  
  13948.      [client]
  13949.      port=3306
  13950.      socket=/tmp/mysql.sock
  13951.      
  13952.      [mysqld]
  13953.      port=3306
  13954.      socket=/tmp/mysql.sock
  13955.      set-variable = key_buffer_size=16M
  13956.      set-variable = max_allowed_packet=1M
  13957.      
  13958.      [mysqldump]
  13959.      quick
  13960.  
  13961. Here is typical user option file:
  13962.  
  13963.      [client]
  13964.      # The following password will be sent to all standard MySQL clients
  13965.      password=my_password
  13966.      
  13967.      [mysql]
  13968.      no-auto-rehash
  13969.      set-variable = connect_timeout=2
  13970.      
  13971.      [mysqlhotcopy]
  13972.      interactive-timeout
  13973.  
  13974. If you have a source distribution, you will find sample configuration
  13975. files named `my-xxxx.cnf' in the `support-files' directory.  If you
  13976. have a binary distribution, look in the `DIR/support-files' directory,
  13977. where `DIR' is the pathname to the MySQL installation directory
  13978. (typically `C:\mysql' or `/usr/local/mysql').  Currently there are
  13979. sample configuration files for small, medium, large, and very large
  13980. systems.  You can copy `my-xxxx.cnf' to your home directory (rename the
  13981. copy to `.my.cnf') to experiment with this.
  13982.  
  13983. All MySQL programs that support option files support the following
  13984. options:
  13985.  
  13986. *Option*                         *Description*
  13987. `--no-defaults'                  Don't read any option files.
  13988. `--print-defaults'               Print the program name and all options
  13989.                                  that it will get.
  13990. `--defaults-file=full-path-to-default-file'Only use the given configuration file.
  13991. `--defaults-extra-file=full-path-to-default-file'Read this configuration file after the
  13992.                                  global configuration file but before
  13993.                                  the user configuration file.
  13994.  
  13995. Note that the options just shown must be first on the command line to
  13996. work, with the exception that `--print-defaults' may be used
  13997. immediately after `--defaults-file' or `--defaults-extra-file'.
  13998.  
  13999. Note for developers:  Option file handling is implemented simply by
  14000. processing all matching options (that is, options in the appropriate
  14001. group) before any command-line arguments. This works nicely for
  14002. programs that use the last instance of an option that is specified
  14003. multiple times. If you have an old program that handles multiply
  14004. specified options this way but doesn't read option files, you need add
  14005. only two lines to give it that capability.  Check the source code of
  14006. any of the standard MySQL clients to see how to do this.
  14007.  
  14008. In shell scripts, you can use the `my_print_defaults' command to parse
  14009. the option files. The following example shows the output that
  14010. `my_print_defaults' might produce when asked to show the options found
  14011. in the `[client]' and `[mysql]' groups:
  14012.  
  14013.  
  14014.      shell> my_print_defaults client mysql
  14015.      --port=3306
  14016.      --socket=/tmp/mysql.sock
  14017.      --no-auto-rehash
  14018.  
  14019. Running Multiple MySQL Servers on the Same Machine
  14020. --------------------------------------------------
  14021.  
  14022. In some cases you might want to run multiple `mysqld' servers on the
  14023. same machine.  For example, you might want to test a new MySQL release
  14024. while leaving your existing production setup undisturbed.  Or you may
  14025. want to give different users access to different `mysqld' servers that
  14026. they manage themselves.  (For example, you might be an Internet service
  14027. provider that wants to provide independent MySQL installations for
  14028. different customers.)
  14029.  
  14030. When you run multiple servers on a single machine, each server must have
  14031. unique values for several operating parameters. At least the following
  14032. options must be different for each server:
  14033.  
  14034.    * `--port=port_num'
  14035.  
  14036.    * `--socket=path'
  14037.  
  14038.    * `--shared-memory-base-name=name' (Windows only; new in MySQL 4.1)
  14039.  
  14040.    * `--pid-file=path' (Unix only)
  14041.  
  14042. `--port' controls the port number for TCP/IP connections.  `--socket'
  14043. controls the socket file path on Unix and the name of the named pipe on
  14044. Windows. (It's necessary to specify distinct pipe names on Windows only
  14045. for those servers that support named pipe connections.)
  14046. `--shared-memory-base-name' designates the shared memory name used by a
  14047. Windows server to allow clients to connect via shared memory.
  14048. `--pid-file' indicates the name of the file in which a Unix server
  14049. writes its process ID.
  14050.  
  14051. If you use the following options, they must be different for each
  14052. server:
  14053.  
  14054.    * `--log=path'
  14055.  
  14056.    * `--log-bin=path'
  14057.  
  14058.    * `--log-update=path'
  14059.  
  14060.    * `--log-error=path'
  14061.  
  14062.    * `--log-isam=path'
  14063.  
  14064.    * `--bdb-logdir=path'
  14065.  
  14066. If you want more performance, you can also specify the following options
  14067. differently for each server, to spread load between several physical
  14068. disks:
  14069.  
  14070.    * `--tmpdir=path'
  14071.  
  14072.    * `--bdb-tmpdir=path'
  14073.  
  14074. *Note Command-line options::.
  14075.  
  14076. Having different temporary directories like above is also recommended
  14077. because it will be easier for you in case you want to know to which
  14078. MySQL server a certain temporary file belongs.
  14079.  
  14080. Generally, each server should also use a different data directory,
  14081. which is specified using the `--datadir=path' option.
  14082.  
  14083. If you have multiple MySQL installations in different locations,
  14084. normally you can specify the base installation directory for each
  14085. server with the `--basedir=path' option to cause each server to use a
  14086. different data directory, log files, and PID file. (The defaults for
  14087. all these values are determined relative to the base directory.) In
  14088. that case, the only other options you need to specify are the
  14089. `--socket' and `--port' options.  For example, suppose you install
  14090. binary MySQL versions (`.tar' files) in different locations and start
  14091. them using the command `./bin/mysqld_safe' under the corresponding base
  14092. directory of each installation.  `mysqld_safe' will determine the proper
  14093. `--basedir' option to pass to `mysqld', and you need specify only the
  14094. `--socket' and `--port' options to `mysqld_safe'.
  14095.  
  14096. As discussed in the following sections, it is possible to start
  14097. additional servers by setting environment variables or by specifying
  14098. appropriate command-line options.  However, if you need to run multiple
  14099. servers on a more permanent basis, it will be more convenient to use
  14100. option files to specify for each server those option values that must
  14101. be unique to it.  *Note Option files::.
  14102.  
  14103. *Warning*: Normally you should never have two servers that update data
  14104. in the same databases!  If your OS doesn't support fault-free system
  14105. locking, this may lead to unpleasant surprises!  If (despite this
  14106. warning) you run multiple servers using the same data directory and
  14107. they have logging enabled, you must specify the names of the log files
  14108. using the appropriate options.  Otherwise, the servers may try to log
  14109. to the same files.
  14110.  
  14111. This warning against sharing a data directory among servers also applies
  14112. in an NFS environment.  Allowing several MySQL servers to access a
  14113. common data directory over NFS is a *bad idea*!
  14114.  
  14115.    * The primary problem is that NFS will become the speed bottleneck.
  14116.      It is not meant for such use.
  14117.  
  14118.    * You also will have to come up with a solution how to make sure
  14119.      that two or more servers do not interfere with each other. At the
  14120.      moment there is no platform that will 100% reliably do the file
  14121.      locking in every situation (usually this is handled by the `lockd'
  14122.      daemon).  Yet there would be one more possible risk with NFS; it
  14123.      would make the work even more complicated for `lockd' daemon to
  14124.      handle.
  14125.  
  14126.  
  14127. Make it easy for yourself: Forget about sharing a data directory among
  14128. servers over NFS. A better solution is to have one computer with an
  14129. operating system that efficiently handles threads and have several CPUs
  14130. in it.
  14131.  
  14132. Running Multiple Servers on Windows
  14133. ...................................
  14134.  
  14135. You can run multiple servers on Windows by starting them manually from
  14136. the command line, each with appropriate operating parameters. On
  14137. Windows NT-based systems, you also have the option of installing
  14138. several servers as services and running them that way. General
  14139. instructions for running MySQL servers from the command line or as
  14140. services are given in *Note Windows::. This section describes how to
  14141. make sure you start each server with different values for those startup
  14142. options that must be unique per server, such as the data directory.
  14143. (These options are described in *Note Multiple servers::.)
  14144.  
  14145. Starting Multiple Windows Servers at the Command Line
  14146. .....................................................
  14147.  
  14148. To start multiple servers manually from the command line, you can
  14149. specify the appropriate options on the command line or in an option
  14150. file. It's more convenient to place the options in an option file, but
  14151. it's necessary to make sure that each server gets its own set of
  14152. options. To do this, create an option file for each server and tell the
  14153. server the filename with a `--defaults-file' option when you run it.
  14154.  
  14155. Suppose you want to run `mysqld' on port 3307 with a data directory of
  14156. `C:\mydata1', and `mysqld-max' on port 3308 with a data directory of
  14157. `C:\mydata2'. To accomplish this, create two option files. For example,
  14158. create one file `C:\my-opts1.cnf' that looks like this:
  14159.  
  14160.      [mysqld]
  14161.      datadir = C:/mydata1
  14162.      port = 3307
  14163.  
  14164. Create a second file `C:\my-opts2.cnf' that looks like this:
  14165.  
  14166.      [mysqld]
  14167.      datadir = C:/mydata2
  14168.      port = 3308
  14169.  
  14170. Then start each server with its own option file:
  14171.  
  14172.      shell> mysqld --defaults-file=C:\my-opts1.cnf
  14173.      shell> mysqld-max --defaults-file=C:\my-opts2.cnf
  14174.  
  14175. (On NT, the servers will start in the foreground, so you'll need to
  14176. issue those two commands in separate console windows.)
  14177.  
  14178. To shut down the servers, you must connect to the appropriate port
  14179. number:
  14180.  
  14181.      shell> mysqladmin --port=3307 shutdown
  14182.      shell> mysqladmin --port=3308 shutdown
  14183.  
  14184. If you want to allow named pipe connections in addition to TCP/IP
  14185. connections, use the `mysqld-nt' or `mysqld-max-nt' servers and specify
  14186. options that enable the named pipe and specify its name. (Each server
  14187. must have a unique pipe name.)  For example, the `C:\my-opts1.cnf' file
  14188. might be written like this:
  14189.  
  14190.      [mysqld]
  14191.      datadir = C:/mydata1
  14192.      port = 3307
  14193.      enable-named-pipe
  14194.      socket = mypipe1
  14195.  
  14196. Then start the server this way:
  14197.  
  14198.      shell> mysqld-nt --defaults-file=C:\my-opts1.cnf
  14199.  
  14200. `C:\my-opts2.cnf' would be modified similarly.
  14201.  
  14202. Starting Multiple Windows Servers as Services
  14203. .............................................
  14204.  
  14205. On NT-based systems, you can install multiple servers as services.
  14206. (This is possible as of MySQL 4.0.2.) In this case, you must make sure
  14207. that each server uses a different service name in addition to all the
  14208. other parameters that must be unique per server.
  14209.  
  14210. For the following instructions, assume that you want to run `mysqld-nt'
  14211. servers from two different versions of MySQL that are installed at
  14212. `C:\mysql-4.0.8' and `C:\mysql-4.0.14', respectively. (This might be
  14213. the case if you're running 4.0.8 as your production server, but want to
  14214. test 4.0.14 before upgrading to it.)
  14215.  
  14216. The following principles are relevant when installing a MySQL service
  14217. with the `--install' (or `--install-manual') option:
  14218.  
  14219.    * If you specify no service name, the server uses the default
  14220.      service name of `MySql' and the server reads options from the
  14221.      `[mysqld]' group in the standard option files.
  14222.  
  14223.    * If you specify a service name after the `--install' option, the
  14224.      server ignores the `[mysqld]' option group and instead reads
  14225.      options from the group that has the same name as the service.
  14226.  
  14227.    * If you specify a `--defaults-file' option after the service name,
  14228.      the server ignores the standard option files and reads options
  14229.      only from the `[mysqld]' group of the named file.
  14230.  
  14231. These principles give you several ways to set up multiple services.
  14232. The following instructions describe some examples. Before trying any of
  14233. them, be sure you shut down and remove any existing MySQL services
  14234. first.
  14235.  
  14236.    * Specify the options for all services in one of the standard option
  14237.      files.  To do this, use the `[mysqld]' group for the server that
  14238.      is installed under the default service name (`MySql'). For other
  14239.      servers, use a group name that is the same as the service name.
  14240.      Suppose you want to run the 4.0.8 `mysqld-nt' using the default
  14241.      service name and the 4.0.14 `mysqld-nt' using the service name
  14242.      `mysqld2'.  In this case, you can use the `[mysqld]' group for
  14243.      4.0.8 and the `[mysqld2]' group for 4.0.14.  For example, you can
  14244.      set up `C:\my.cnf' like this:
  14245.  
  14246.           # options for default service (MySql)
  14247.           [mysqld]
  14248.           basedir = C:/mysql-4.0.8
  14249.           port = 3307
  14250.           enable-named-pipe
  14251.           socket = mypipe1
  14252.           
  14253.           # options for mysqld2 service
  14254.           [mysqld2]
  14255.           basedir = C:/mysql-4.0.14
  14256.           port = 3308
  14257.           enable-named-pipe
  14258.           socket = mypipe2
  14259.  
  14260.      Install the services like this:
  14261.  
  14262.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install
  14263.           shell> C:\mysql-4.0.14\bin\mysqld-nt --install mysqld2
  14264.  
  14265.      To start the services, use the services manager, or use `NET START'
  14266.      with the appropriate service names:
  14267.  
  14268.           shell> NET START MySql
  14269.           shell> NET START mysqld2
  14270.  
  14271.      To stop the services, use the services manager, or use `NET STOP'
  14272.      with the same service names.
  14273.  
  14274.    * Specify options for each server in separate files and use
  14275.      `--defaults-file' when you install the services to tell each server
  14276.      what file to use.  In this case, each file should list options
  14277.      using a `[mysqld]' group.
  14278.  
  14279.      With this approach, to specify options for the 4.0.8 `mysqld-nt',
  14280.      create a file `C:\my-opts1.cnf' that looks like this:
  14281.  
  14282.           [mysqld]
  14283.           basedir = C:/mysql-4.0.8
  14284.           port = 3307
  14285.           enable-named-pipe
  14286.           socket = mypipe1
  14287.  
  14288.      For the 4.0.14 `mysqld-nt', create a file `C:\my-opts2.cnf' that
  14289.      looks like this:
  14290.  
  14291.           [mysqld]
  14292.           basedir = C:/mysql-4.0.14
  14293.           port = 3308
  14294.           enable-named-pipe
  14295.           socket = mypipe2
  14296.  
  14297.      Install the services as follows (enter each command on a single
  14298.      line):
  14299.  
  14300.           shell> C:\mysql-4.0.8\bin\mysqld-nt --install MySql
  14301.                      --defaults-file=C:\my-opts1.cnf
  14302.           shell> C:\mysql-4.0.14\bin\mysqld-nt --install mysqld2
  14303.                      --defaults-file=C:\my-opts2.cnf
  14304.  
  14305.      To use a `--defaults-file' option when you install a MySQL server
  14306.      as a service, you must precede the option with the service name.
  14307.      That is why the first command names the `MySql' service
  14308.      explicitly, even though that is the default service name.
  14309.  
  14310.      Start and stop the services the same way as in the preceding
  14311.      example.
  14312.  
  14313.  
  14314. To remove multiple services, use `mysqld --remove' for each one,
  14315. specifying a service name following the `--remove' option if the
  14316. service to remove has a name different than the default.
  14317.  
  14318. Running Multiple Servers on Unix
  14319. ................................
  14320.  
  14321. The easiest way is to run multiple servers on Unix is to compile them
  14322. with different TCP/IP ports and socket files so that each one is
  14323. listening on different network interfaces. Also, by compiling in
  14324. different base directories for each installation, that automatically
  14325. results in different compiled-in data directory, log file, and PID file
  14326. locations for each of your servers.
  14327.  
  14328. Assume an existing server is configured for the default port number and
  14329. socket file.  To configure a new server to have different operating
  14330. parameters, use a `configure' command something like this:
  14331.  
  14332.      shell> ./configure --with-tcp-port=port_number \
  14333.                   --with-unix-socket-path=file_name \
  14334.                   --prefix=/usr/local/mysql-4.0.14
  14335.  
  14336. Here `port_number' and `file_name' should be different from the default
  14337. port number and socket file pathname, and the `--prefix' value should
  14338. specify an installation directory different than the one under which
  14339. the existing MySQL installation is located.
  14340.  
  14341. If you have a MySQL server listening on a given port number, you can
  14342. use the following command to find out what operating parameters it is
  14343. using for several important configurable variables, including the base
  14344. directory and socket name:
  14345.  
  14346.      shell> mysqladmin --host=host_name --port=port_number variables
  14347.  
  14348. With the information displayed by that command, you can tell what option
  14349. values *not* to use when configuring an additional server.
  14350.  
  14351. Note that if you specify "`localhost'" as a hostname, `mysqladmin' will
  14352. default to using a Unix socket connection rather than TCP/IP.  In MySQL
  14353. 4.1, you can explicitly specify the connection protocol to use by using
  14354. the `--protocol={TCP | SOCKET | PIPE | MEMORY}' option.
  14355.  
  14356. You don't have to compile a new MySQL server just to start with a
  14357. different socket file and TCP/IP port number.  It is also possible to
  14358. specify those values at runtime. One way to do so is by using
  14359. command-line options:
  14360.  
  14361.      shell> /path/to/mysqld_safe --socket=file_name --port=port_number
  14362.  
  14363. To use another database directory for the second server, pass a
  14364. `--datadir=path' option to `mysqld_safe'.
  14365.  
  14366. Another way to achieve a similar effect is to use environment variables
  14367. to set the socket name and port number:
  14368.  
  14369.      shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
  14370.      shell> MYSQL_TCP_PORT=3307
  14371.      shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
  14372.      shell> scripts/mysql_install_db
  14373.      shell> bin/mysqld_safe &
  14374.  
  14375. This is a quick and dirty method for starting a second server to use
  14376. for testing.  The nice thing about this method is that the environment
  14377. variable settings will apply to any client programs that you invoke from
  14378. the above shell. Thus, connections for those clients automatically will
  14379. be directed to the second server!
  14380.  
  14381. *Note Environment variables:: includes a list of other environment
  14382. variables you can use to affect `mysqld'.
  14383.  
  14384. For automatic server execution, your startup script that is executed at
  14385. boot time should execute the following command once for each server
  14386. with an appropriate option file path for each command:
  14387.  
  14388.      mysqld_safe --defaults-file=path-to-option-file
  14389.  
  14390. Each option file should contain option values specific to a given
  14391. server.
  14392.  
  14393. On Unix, the `mysqld_multi' script is another way to start multiple
  14394. servers.  *Note `mysqld_multi': mysqld_multi.
  14395.  
  14396. Using Client Programs in a Multiple-Server Environment
  14397. ......................................................
  14398.  
  14399. When you want to connect with a client program to a MySQL server that is
  14400. listening to different network interfaces than those compiled into your
  14401. client, you can use one of the following methods:
  14402.  
  14403.    * Start the client with `--host=host_name --port=port_number' to
  14404.      connect via TCP/IP to a remote host, or with `--host=localhost
  14405.      --socket=file_name' to connect to a local host via a Unix socket
  14406.      or a Windows named pipe.
  14407.  
  14408.    * As of MySQL 4.1, start the client with `--protocol=tcp' to connect
  14409.      via TCP/IP, `--protocol=socket' to connect via a Unix socket,
  14410.      `--protocol=pipe' to connect via a named pipe, or
  14411.      `--protocol=memory' to connect via shared memory.  For TCP/IP
  14412.      connections, you may also need to specify `--host' and `--port'
  14413.      options.  For the other types of connections, you may need to
  14414.      specify a `--socket' option to specify a socket or named pipe
  14415.      name, or a `--shared-memory-base-name' option to specify the
  14416.      shared memory name.
  14417.  
  14418.    * On Unix, set the `MYSQL_UNIX_PORT' and `MYSQL_TCP_PORT'
  14419.      environment variables to point to the Unix socket and TCP/IP port
  14420.      before you start your clients.  If you normally use a specific
  14421.      socket or port, you can place commands to set these environment
  14422.      variables in your `.login' file so that they apply each time you
  14423.      log in.  *Note Environment variables::.
  14424.  
  14425.    * Specify the default socket and TCP/IP port in the `[client]' group
  14426.      of an option file. Foe example, you can use `C:\my.cnf' on
  14427.      Windows, or the `.my.cnf' file in your home directory on Unix.
  14428.      *Note Option files::.
  14429.  
  14430.    * In a C program, you can specify the port or socket arguments in the
  14431.      `mysql_real_connect()' call.  You can also have the program read
  14432.      option files by calling `mysql_options()'.  *Note C API
  14433.      functions::.
  14434.  
  14435.    * If you are using the Perl `DBD::mysql' module, you can read the
  14436.      options from the MySQL option files. For example:
  14437.  
  14438.           $dsn = "DBI:mysql:test;mysql_read_default_group=client;"
  14439.                   . "mysql_read_default_file=/usr/local/mysql/data/my.cnf";
  14440.           $dbh = DBI->connect($dsn, $user, $password);
  14441.  
  14442.      *Note Perl DBI Class::.
  14443.  
  14444.  
  14445. General Security Issues and the MySQL Access Privilege System
  14446. =============================================================
  14447.  
  14448. MySQL has an advanced but non-standard security/privilege system.  This
  14449. section describes how it works.
  14450.  
  14451. General Security Guidelines
  14452. ---------------------------
  14453.  
  14454. Anyone using MySQL on a computer connected to the Internet should read
  14455. this section to avoid the most common security mistakes.
  14456.  
  14457. In discussing security, we emphasise the necessity of fully protecting
  14458. the entire server host (not simply the MySQL server) against all types
  14459. of applicable attacks: eavesdropping, altering, playback, and denial of
  14460. service. We do not cover all aspects of availability and fault tolerance
  14461. here.
  14462.  
  14463. MySQL uses security based on Access Control Lists (ACLs) for all
  14464. connections, queries, and other operations that a user may attempt to
  14465. perform. There is also some support for SSL-encrypted connections
  14466. between MySQL clients and servers. Many of the concepts discussed here
  14467. are not specific to MySQL at all; the same general ideas apply to
  14468. almost all applications.
  14469.  
  14470. When running MySQL, follow these guidelines whenever possible:
  14471.  
  14472.    * *Do not ever give anyone (except the mysql `root' user) access to
  14473.      the `user' table in the `mysql' database!*  This is critical.
  14474.      *The encrypted password is the real password in MySQL.* Anyone who
  14475.      knows the password which is listed in the `user' table and has
  14476.      access to the host listed for the account *can easily log in as
  14477.      that user*.
  14478.  
  14479.    * Learn the MySQL access privilege system. The `GRANT' and `REVOKE'
  14480.      commands are used for controlling access to MySQL. Do not grant
  14481.      any more privileges than necessary. Never grant privileges to all
  14482.      hosts.
  14483.  
  14484.      Checklist:
  14485.         - Try `mysql -u root'. If you are able to connect successfully
  14486.           to the server without being asked for a password, you have
  14487.           problems. Anyone can connect to your MySQL server as the MySQL
  14488.           `root' user with full privileges!  Review the MySQL
  14489.           installation instructions, paying particular attention to the
  14490.           item about setting a `root' password.
  14491.  
  14492.         - Use the command `SHOW GRANTS' and check to see who has access
  14493.           to what. Remove those privileges that are not necessary using
  14494.           the `REVOKE' command.
  14495.  
  14496.    * Do not keep any plain-text passwords in your database. When your
  14497.      computer becomes compromised, the intruder can take the full list
  14498.      of passwords and use them. Instead use `MD5()', `SHA1()' or
  14499.      another one-way hashing function.
  14500.  
  14501.    * Do not choose passwords from dictionaries. There are special
  14502.      programs to break them. Even passwords like "xfish98" are very
  14503.      bad.  Much better is "duag98" which contains the same word "fish"
  14504.      but typed one key to the left on a standard QWERTY keyboard.
  14505.      Another method is to use "Mhall" which is taken from the first
  14506.      characters of each word in the sentence "Mary had a little lamb."
  14507.      This is easy to remember and type, but difficult to guess for
  14508.      someone who does not know it.
  14509.  
  14510.    * Invest in a firewall. This protects you from at least 50% of all
  14511.      types of exploits in any software. Put MySQL behind the firewall
  14512.      or in a demilitarised zone (DMZ).
  14513.  
  14514.      Checklist:
  14515.         - Try to scan your ports from the Internet using a tool such as
  14516.           `nmap'. MySQL uses port 3306 by default. This port should be
  14517.           inaccessible from untrusted hosts. Another simple way to
  14518.           check whether or not your MySQL port is open is to try the
  14519.           following command from some remote machine, where
  14520.           `server_host' is the hostname of your MySQL server:
  14521.  
  14522.                shell> telnet server_host 3306
  14523.  
  14524.           If you get a connection and some garbage characters, the port
  14525.           is open, and should be closed on your firewall or router,
  14526.           unless you really have a good reason to keep it open. If
  14527.           `telnet' just hangs or the connection is refused, everything
  14528.           is OK; the port is blocked.
  14529.  
  14530.    * Do not trust any data entered by your users. They can try to trick
  14531.      your code by entering special or escaped character sequences in
  14532.      web forms, URLs, or whatever application you have built. Be sure
  14533.      that your application remains secure if a user enters something
  14534.      like "`; DROP DATABASE mysql;'". This is an extreme example, but
  14535.      large security leaks and data loss may occur as a result of
  14536.      hackers using similar techniques, if you do not prepare for them.
  14537.  
  14538.      Also remember to check numeric data. A common mistake is to
  14539.      protect only strings. Sometimes people think that if a database
  14540.      contains only publicly available data that it need not be
  14541.      protected. This is incorrect. At least denial-of-service type
  14542.      attacks can be performed on such databases. The simplest way to
  14543.      protect from this type of attack is to use apostrophes around the
  14544.      numeric constants: `SELECT * FROM table WHERE ID='234'' rather
  14545.      than `SELECT * FROM table WHERE ID=234'.  MySQL automatically
  14546.      converts this string to a number and strips all non-numeric
  14547.      symbols from it.
  14548.  
  14549.      Checklist:
  14550.         - All web applications:
  14551.              * Try to enter `'' and `"' in all your web forms. If you
  14552.                get any kind of MySQL error, investigate the problem
  14553.                right away.
  14554.  
  14555.              * Try to modify any dynamic URLs by adding `%22' (`"'),
  14556.                `%23' (`#'), and `%27' (`'') in the URL.
  14557.  
  14558.              * Try to modify datatypes in dynamic URLs from numeric
  14559.                ones to character ones containing characters from
  14560.                previous examples. Your application should be safe
  14561.                against this and similar attacks.
  14562.  
  14563.              * Try to enter characters, spaces, and special symbols
  14564.                instead of numbers in numeric fields. Your application
  14565.                should remove them before passing them to MySQL or your
  14566.                application should generate an error. Passing unchecked
  14567.                values to MySQL is very dangerous!
  14568.  
  14569.              * Check data sizes before passing them to MySQL.
  14570.  
  14571.              * Consider having your application connect to the database
  14572.                using a different user name than the one you use for
  14573.                administrative purposes. Do not give your applications
  14574.                any more access privileges than they need.
  14575.  
  14576.         - Users of PHP:
  14577.              * Check out the `addslashes()' function.  As of PHP 4.0.3,
  14578.                a `mysql_escape_string()' function is available that is
  14579.                based on the function of the same name in the MySQL C
  14580.                API.
  14581.  
  14582.         - Users of MySQL C API:
  14583.              * Check out the `mysql_real_escape_string()' API call.
  14584.  
  14585.         - Users of MySQL++:
  14586.              * Check out the `escape' and `quote' modifiers for query
  14587.                streams.
  14588.  
  14589.         - Users of Perl DBI:
  14590.              * Check out the `quote()' method or use placeholders.
  14591.  
  14592.         - Users of Java JDBC:
  14593.              * Use a `PreparedStatement' object and placeholders.
  14594.  
  14595.    * Do not transmit plain (unencrypted) data over the Internet. These
  14596.      data are accessible to everyone who has the time and ability to
  14597.      intercept it and use it for their own purposes. Instead, use an
  14598.      encrypted protocol such as SSL or SSH. MySQL supports internal SSL
  14599.      connections as of Version 4.0.0.  SSH port-forwarding can be used
  14600.      to create an encrypted (and compressed) tunnel for the
  14601.      communication.
  14602.  
  14603.    * Learn to use the `tcpdump' and `strings' utilities. For most cases,
  14604.      you can check whether MySQL data streams are unencrypted by
  14605.      issuing a command like the following:
  14606.  
  14607.           shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
  14608.  
  14609.      (This works under Linux and should work with small modifications
  14610.      under other systems.)  Warning: If you do not see data this
  14611.      doesn't always actually mean that it is encrypted. If you need
  14612.      high security, you should consult with a security expert.
  14613.  
  14614. How to Make MySQL Secure Against Crackers
  14615. -----------------------------------------
  14616.  
  14617. When you connect to a MySQL server, you normally should use a password.
  14618. The password is not transmitted in clear text over the connection,
  14619. however the encryption algorithm is not very strong, and with some
  14620. effort a clever attacker can crack the password if he is able to sniff
  14621. the traffic between the client and the server. If the connection
  14622. between the client and the server goes through an untrusted network,
  14623. you should use an SSH tunnel to encrypt the communication.
  14624.  
  14625. All other information is transferred as text that can be read by anyone
  14626. who is able to watch the connection.  If you are concerned about this,
  14627. you can use the compressed protocol (in MySQL Version 3.22 and above)
  14628. to make things much harder.  To make things even more secure you should
  14629. use `ssh'.  You can find an `Open Source' `ssh' client at
  14630. `http://www.openssh.org/', and a commercial `ssh' client at
  14631. `http://www.ssh.com/'.  With this, you can get an encrypted TCP/IP
  14632. connection between a MySQL server and a MySQL client.
  14633.  
  14634. If you are using MySQL 4.0, you can also use internal OpenSSL support.
  14635. *Note Secure connections::.
  14636.  
  14637. To make a MySQL system secure, you should strongly consider the
  14638. following suggestions:
  14639.  
  14640.    * Use passwords for all MySQL users. Remember that anyone can log in
  14641.      as any other person as simply as `mysql -u other_user db_name' if
  14642.      `other_user' has no password.  It is common behaviour with
  14643.      client/server applications that the client may specify any user
  14644.      name.  You can change the password of all users by editing the
  14645.      `mysql_install_db' script before you run it, or only the password
  14646.      for the MySQL `root' user like this:
  14647.  
  14648.           shell> mysql -u root mysql
  14649.           mysql> UPDATE user SET Password=PASSWORD('new_password')
  14650.               ->             WHERE user='root';
  14651.           mysql> FLUSH PRIVILEGES;
  14652.  
  14653.    * Don't run the MySQL daemon as the Unix `root' user.  This is very
  14654.      dangerous, because any user with the `FILE' privilege will be able
  14655.      to create files as `root' (for example, `~root/.bashrc'). To
  14656.      prevent this, `mysqld' will refuse to run as `root' unless it is
  14657.      specified directly using a `--user=root' option.
  14658.  
  14659.      `mysqld' can be run as an ordinary unprivileged user instead.  You
  14660.      can also create a new Unix user `mysql' to make everything even
  14661.      more secure.  If you run `mysqld' as another Unix user, you don't
  14662.      need to change the `root' user name in the `user' table, because
  14663.      MySQL user names have nothing to do with Unix user names.  To
  14664.      start `mysqld' as another Unix user, add a `user' line that
  14665.      specifies the user name to the `[mysqld]' group of the
  14666.      `/etc/my.cnf' option file or the `my.cnf' option file in the
  14667.      server's data directory. For example:
  14668.  
  14669.           [mysqld]
  14670.           user=mysql
  14671.  
  14672.      This will cause the server to start as the designated user whether
  14673.      you start it manually or by using `mysqld_safe' or `mysql.server'.
  14674.      For more details, see *Note Changing MySQL user::.
  14675.  
  14676.    * Don't support symlinks to tables (this can be disabled with the
  14677.      `--skip-symlink' option). This is especially important if you run
  14678.      `mysqld' as root as anyone that has write access to the mysqld data
  14679.      directories could then delete any file in the system!  *Note
  14680.      Symbolic links to tables::.
  14681.  
  14682.    * Check that the Unix user that `mysqld' runs as is the only user
  14683.      with read/write privileges in the database directories.
  14684.  
  14685.    * Don't give the `PROCESS' privilege to all users.  The output of
  14686.      `mysqladmin processlist' shows the text of the currently executing
  14687.      queries, so any user who is allowed to execute that command might
  14688.      be able to see if another user issues an `UPDATE user SET
  14689.      password=PASSWORD('not_secure')' query.
  14690.  
  14691.      `mysqld' reserves an extra connection for users who have the
  14692.      `PROCESS' privilege, so that a MySQL `root' user can log in and
  14693.      check things even if all normal connections are in use.
  14694.  
  14695.    * Don't give the `FILE' privilege to all users.  Any user that has
  14696.      this privilege can write a file anywhere in the filesystem with
  14697.      the privileges of the `mysqld' daemon!  To make this a bit safer,
  14698.      all files generated with `SELECT ... INTO OUTFILE' are writeable
  14699.      by everyone, and you cannot overwrite existing files.
  14700.  
  14701.      The `FILE' privilege may also be used to read any world readable
  14702.      file that is accessible to the Unix user that the server runs as.
  14703.      One can also read any file to the current database (which the user
  14704.      need some privilege for).  This could be abused, for example, by
  14705.      using `LOAD DATA' to load `/etc/passwd' into a table, which can
  14706.      then be read with `SELECT'.
  14707.  
  14708.    * If you don't trust your DNS, you should use IP numbers instead of
  14709.      hostnames in the grant tables. In any case, you should be very
  14710.      careful about creating grant table entries using hostname values
  14711.      that contain wildcards!
  14712.  
  14713.    * If you want to restrict the number of connections for a single
  14714.      user, you can do this by setting the `max_user_connections'
  14715.      variable in `mysqld'.
  14716.  
  14717. Startup Options for `mysqld' Concerning Security
  14718. ------------------------------------------------
  14719.  
  14720. The following `mysqld' options affect security:
  14721.  
  14722. `--local-infile[=(0|1)]'
  14723.      If one uses `--local-infile=0' then one can't use `LOAD DATA LOCAL
  14724.      INFILE'.
  14725.  
  14726. `--safe-show-database'
  14727.      With this option, the `SHOW DATABASES' command returns only those
  14728.      databases for which the user has some kind of privilege.  From
  14729.      version 4.0.2 this option is deprecated and doesn't do anything
  14730.      (the option is enabled by default) as we now have the `SHOW
  14731.      DATABASES' privilege. *Note GRANT::.
  14732.  
  14733. `--safe-user-create'
  14734.      If this is enabled, an user can't create new users with the `GRANT'
  14735.      command, if the user doesn't have the `INSERT' privilege for the
  14736.      `mysql.user' table.  If you want to give a user access to just
  14737.      create new users with those privileges that the user has right to
  14738.      grant, you should give the user the following privilege:
  14739.  
  14740.           mysql> GRANT INSERT(user) ON mysql.user TO 'user'@'hostname';
  14741.  
  14742.      This will ensure that the user can't change any privilege columns
  14743.      directly, but has to use the `GRANT' command to give privileges to
  14744.      other users.
  14745.  
  14746. `--skip-grant-tables'
  14747.      This option causes the server not to use the privilege system at
  14748.      all. This gives everyone *full access* to all databases!  (You can
  14749.      tell a running server to start using the grant tables again by
  14750.      executing `mysqladmin flush-privileges' or `mysqladmin reload'.)
  14751.  
  14752. `--skip-name-resolve'
  14753.      Hostnames are not resolved.  All `Host' column values in the grant
  14754.      tables must be IP numbers or `localhost'.
  14755.  
  14756. `--skip-networking'
  14757.      Don't allow TCP/IP connections over the network.  All connections
  14758.      to `mysqld' must be made via Unix sockets.  This option is
  14759.      unsuitable when using a MySQL version prior to 3.23.27 with the
  14760.      MIT-pthreads package, because Unix sockets were not supported by
  14761.      MIT-pthreads at that time.
  14762.  
  14763. `--skip-show-database'
  14764.      Don't allow `SHOW DATABASES' command, unless the user has the
  14765.      `SHOW DATABASES' privilege. From version 4.0.2 you should no longer
  14766.      need this option, since access can now be granted specifically
  14767.      with the `SHOW DATABASES' privilege.
  14768.  
  14769. Security issues with `LOAD DATA LOCAL'
  14770. --------------------------------------
  14771.  
  14772. In MySQL 3.23.49 and MySQL 4.0.2, we added some new options to deal with
  14773. possible security issues when it comes to `LOAD DATA LOCAL'.
  14774.  
  14775. There are two possible problems with supporting this command:
  14776.  
  14777. As the reading of the file is initiated from the server, one could
  14778. theoretically create a patched MySQL server that could read any file on
  14779. the client machine that the current user has read access to, when the
  14780. client issues a query against the table.
  14781.  
  14782. In a web environment where the clients are connecting from a web
  14783. server, a user could use `LOAD DATA LOCAL' to read any files that the
  14784. web server process has read access to (assuming a user could run any
  14785. command against the SQL server).
  14786.  
  14787. There are two separate fixes for this:
  14788.  
  14789. If you don't configure MySQL with `--enable-local-infile', then `LOAD
  14790. DATA LOCAL' will be disabled by all clients, unless one calls
  14791. `mysql_options(... MYSQL_OPT_LOCAL_INFILE, 0)' in the client.  *Note
  14792. `mysql_options()': mysql_options.
  14793.  
  14794. For the `mysql' command-line client, `LOAD DATA LOCAL' can be enabled
  14795. by specifying the option `--local-infile[=1]', or disabled with
  14796. `--local-infile=0'.
  14797.  
  14798. By default, all MySQL clients and libraries are compiled with
  14799. `--enable-local-infile', to be compatible with MySQL 3.23.48 and before.
  14800.  
  14801. One can disable all `LOAD DATA LOCAL' commands in the MySQL server by
  14802. starting `mysqld' with `--local-infile=0'.
  14803.  
  14804. In the case that `LOAD DATA LOCAL INFILE' is disabled in the server or
  14805. the client, you will get the error message (1148):
  14806.  
  14807.      The used command is not allowed with this MySQL version
  14808.  
  14809. What the Privilege System Does
  14810. ------------------------------
  14811.  
  14812. The primary function of the MySQL privilege system is to authenticate a
  14813. user connecting from a given host, and to associate that user with
  14814. privileges on a database such as `SELECT', `INSERT', `UPDATE' and
  14815. `DELETE'.
  14816.  
  14817. Additional functionality includes the ability to have an anonymous user
  14818. and to grant privileges for MySQL-specific functions such as `LOAD DATA
  14819. INFILE' and administrative operations.
  14820.  
  14821. How the Privilege System Works
  14822. ------------------------------
  14823.  
  14824. The MySQL privilege system ensures that all users may do exactly the
  14825. things that they are supposed to be allowed to do.  When you connect to
  14826. a MySQL server, your identity is determined by *the host from which you
  14827. connect* and *the user name you specify*.  The system grants privileges
  14828. according to your identity and *what you want to do*.
  14829.  
  14830. MySQL considers both your hostname and user name in identifying you
  14831. because there is little reason to assume that a given user name belongs
  14832. to the same person everywhere on the Internet.  For example, the user
  14833. `joe' who connects from `office.com' need not be the same person as the
  14834. user `joe' who connects from `elsewhere.com'.  MySQL handles this by
  14835. allowing you to distinguish users on different hosts that happen to
  14836. have the same name:  you can grant `joe' one set of privileges for
  14837. connections from `office.com', and a different set of privileges for
  14838. connections from `elsewhere.com'.
  14839.  
  14840. MySQL access control involves two stages:
  14841.  
  14842.    * Stage 1: The server checks whether you are even allowed to connect.
  14843.  
  14844.    * Stage 2: Assuming you can connect, the server checks each request
  14845.      you issue to see whether you have sufficient privileges to perform
  14846.      it.  For example, if you try to select rows from a table in a
  14847.      database or drop a table from the database, the server makes sure
  14848.      you have the `SELECT' privilege for the table or the `DROP'
  14849.      privilege for the database.
  14850.  
  14851. Note that if your privileges are changed (either by yourself or someone
  14852. else) while you are connected, those changes will not necessarily take
  14853. effect with your next query or queries. See *Note Privilege changes::
  14854. for details.
  14855.  
  14856. The server uses the `user', `db', and `host' tables in the `mysql'
  14857. database at both stages of access control.  The fields in these grant
  14858. tables are shown here:
  14859.  
  14860. *Table name*   *user*         *db*           *host*
  14861. *Scope fields* `Host'         `Host'         `Host'
  14862.                `User'         `Db'           `Db'
  14863.                `Password'     `User'         
  14864. *Privilege     `Select_priv'  `Select_priv'  `Select_priv'
  14865. fields*                                      
  14866.                `Insert_priv'  `Insert_priv'  `Insert_priv'
  14867.                `Update_priv'  `Update_priv'  `Update_priv'
  14868.                `Delete_priv'  `Delete_priv'  `Delete_priv'
  14869.                `Index_priv'   `Index_priv'   `Index_priv'
  14870.                `Alter_priv'   `Alter_priv'   `Alter_priv'
  14871.                `Create_priv'  `Create_priv'  `Create_priv'
  14872.                `Drop_priv'    `Drop_priv'    `Drop_priv'
  14873.                `Grant_priv'   `Grant_priv'   `Grant_priv'
  14874.                `References_priv'`References_priv'`References_priv'
  14875.                `Reload_priv'                 
  14876.                `Shutdown_priv'               
  14877.                `Process_priv'                
  14878.                `File_priv'                   
  14879.                `Show_db_priv'                
  14880.                `Super_priv'                  
  14881.                `Create_tmp_table_priv'`Create_tmp_table_priv'`Create_tmp_table_priv'
  14882.                `Lock_tables_priv'`Lock_tables_priv'`Lock_tables_priv'
  14883.                `Execute_priv'                
  14884.                `Repl_slave_priv'               
  14885.                `Repl_client_priv'               
  14886.                `ssl_type'                    
  14887.                `ssl_cypher'                  
  14888.                `x509_issuer'                 
  14889.                `x509_cubject'                
  14890.                `max_questions'               
  14891.                `max_updates'                 
  14892.                `max_connections'               
  14893.  
  14894. For the second stage of access control (request verification), the
  14895. server may, if the request involves tables, additionally consult the
  14896. `tables_priv' and `columns_priv' tables.  The fields in these tables
  14897. are shown here:
  14898.  
  14899. *Table name*   *tables_priv*  *columns_priv*
  14900. *Scope         `Host'         `Host'
  14901. fields*                       
  14902.                `Db'           `Db'
  14903.                `User'         `User'
  14904.                `Table_name'   `Table_name'
  14905.                               `Column_name'
  14906. *Privilege     `Table_priv'   `Column_priv'
  14907. fields*                       
  14908.                `Column_priv'  
  14909. *Other         `Timestamp'    `Timestamp'
  14910. fields*                       
  14911.                `Grantor'      
  14912.  
  14913. Each grant table contains scope fields and privilege fields.
  14914.  
  14915. Scope fields determine the scope of each entry in the tables, that is,
  14916. the context in which the entry applies.  For example, a `user' table
  14917. entry with `Host' and `User' values of `'thomas.loc.gov'' and `'bob''
  14918. would be used for authenticating connections made to the server by
  14919. `bob' from the host `thomas.loc.gov'.  Similarly, a `db' table entry
  14920. with `Host', `User', and `Db' fields of `'thomas.loc.gov'', `'bob'' and
  14921. `'reports'' would be used when `bob' connects from the host
  14922. `thomas.loc.gov' to access the `reports' database.  The `tables_priv'
  14923. and `columns_priv' tables contain scope fields indicating tables or
  14924. table/column combinations to which each entry applies.
  14925.  
  14926. For access-checking purposes, comparisons of `Host' values are
  14927. case-insensitive.  `User', `Password', `Db', and `Table_name' values
  14928. are case-sensitive.  `Column_name' values are case-insensitive in MySQL
  14929. Version 3.22.12 or later.
  14930.  
  14931. Privilege fields indicate the privileges granted by a table entry, that
  14932. is, what operations can be performed.  The server combines the
  14933. information in the various grant tables to form a complete description
  14934. of a user's privileges.  The rules used to do this are described in
  14935. *Note Request access::.
  14936.  
  14937. Scope fields are strings, declared as shown here; the default value for
  14938. each is the empty string:
  14939.  
  14940. *Field name*   *Type*      *Notes*
  14941. `Host'         `CHAR(60)'  
  14942. `User'         `CHAR(16)'  
  14943. `Password'     `CHAR(16)'  
  14944. `Db'           `CHAR(64)'  (`CHAR(60)' for the `tables_priv' and
  14945.                            `columns_priv' tables)
  14946. `Table_name'   `CHAR(60)'  
  14947. `Column_name'  `CHAR(60)'  
  14948.  
  14949. In the `user', `db' and `host' tables, all privilege fields are
  14950. declared as `ENUM('N','Y')'--each can have a value of `'N'' or `'Y'',
  14951. and the default value is `'N''.
  14952.  
  14953. In the `tables_priv' and `columns_priv' tables, the privilege fields
  14954. are declared as `SET' fields:
  14955.  
  14956. *Table      *Field      *Possible set elements*
  14957. name*       name*       
  14958. `tables_priv'`Table_priv'`'Select', 'Insert', 'Update',
  14959.                         'Delete', 'Create', 'Drop', 'Grant',
  14960.                         'References', 'Index', 'Alter''
  14961. `tables_priv'`Column_priv'`'Select', 'Insert', 'Update',
  14962.                         'References''
  14963. `columns_priv'`Column_priv'`'Select', 'Insert', 'Update',
  14964.                         'References''
  14965.  
  14966. Briefly, the server uses the grant tables like this:
  14967.  
  14968.    * The `user' table scope fields determine whether to allow or reject
  14969.      incoming connections.  For allowed connections, any privileges
  14970.      granted in the `user' table indicate the user's global (superuser)
  14971.      privileges.  These privileges apply to *all* databases on the
  14972.      server.
  14973.  
  14974.    * The `db' and `host' tables are used together:
  14975.  
  14976.         - The `db' table scope fields determine which users can access
  14977.           which databases from which hosts.  The privilege fields
  14978.           determine which operations are allowed.
  14979.  
  14980.         - The `host' table is used as an extension of the `db' table
  14981.           when you want a given `db' table entry to apply to several
  14982.           hosts.  For example, if you want a user to be able to use a
  14983.           database from several hosts in your network, leave the `Host'
  14984.           value empty in the user's `db' table entry, then populate the
  14985.           `host' table with an entry for each of those hosts.  This
  14986.           mechanism is described more detail in *Note Request access::.
  14987.  
  14988.    * The `tables_priv' and `columns_priv' tables are similar to the
  14989.      `db' table, but are more fine-grained: they apply at the table and
  14990.      column levels rather than at the database level.
  14991.  
  14992. Note that administrative privileges (`RELOAD', `SHUTDOWN', etc.) are
  14993. specified only in the `user' table.  This is because administrative
  14994. operations are operations on the server itself and are not
  14995. database-specific, so there is no reason to list such privileges in the
  14996. other grant tables.  In fact, only the `user' table need be consulted
  14997. to determine whether you can perform an administrative operation.
  14998.  
  14999. The `FILE' privilege is specified only in the `user' table, too.  It is
  15000. not an administrative privilege as such, but your ability to read or
  15001. write files on the server host is independent of the database you are
  15002. accessing.
  15003.  
  15004. The `mysqld' server reads the contents of the grant tables once, when it
  15005. starts up.  Changes to the grant tables take effect as indicated in
  15006. *Note Privilege changes::.
  15007.  
  15008. When you modify the contents of the grant tables, it is a good idea to
  15009. make sure that your changes set up privileges the way you want.  For
  15010. help in diagnosing problems, see *Note Access denied::.  For advice on
  15011. security issues, see *Note Security::.
  15012.  
  15013. A useful diagnostic tool is the `mysqlaccess' script, which Yves
  15014. Carlier has provided for the MySQL distribution.  Invoke `mysqlaccess'
  15015. with the `--help' option to find out how it works.  Note that
  15016. `mysqlaccess' checks access using only the `user', `db' and `host'
  15017. tables.  It does not check table- or column-level privileges.
  15018.  
  15019. Privileges Provided by MySQL
  15020. ----------------------------
  15021.  
  15022. Information about user privileges is stored in the `user', `db',
  15023. `host', `tables_priv', and `columns_priv' tables in the `mysql'
  15024. database (that is, in the database named `mysql').  The MySQL server
  15025. reads the contents of these tables when it starts up and under the
  15026. circumstances indicated in *Note Privilege changes::.
  15027.  
  15028. The names used in this manual to refer to the privileges provided by
  15029. MySQL version 4.0.2 are shown here, along with the table column name
  15030. associated with each privilege in the grant tables and the context in
  15031. which the privilege applies. Further information about the meaning of
  15032. each privilege may be found at *Note `GRANT': GRANT.
  15033.  
  15034. *Privilege* *Column*       *Context*
  15035. `ALTER'     `Alter_priv'   tables
  15036. `DELETE'    `Delete_priv'  tables
  15037. `INDEX'     `Index_priv'   tables
  15038. `INSERT'    `Insert_priv'  tables
  15039. `SELECT'    `Select_priv'  tables
  15040. `UPDATE'    `Update_priv'  tables
  15041. `CREATE'    `Create_priv'  databases, tables, or
  15042.                            indexes
  15043. `DROP'      `Drop_priv'    databases or tables
  15044. `GRANT'     `Grant_priv'   databases or tables
  15045. `REFERENCES'`References_priv'databases or tables
  15046. `CREATE     `Create_tmp_table_priv'server administration
  15047. TEMPORARY                  
  15048. TABLES'                    
  15049. `EXECUTE'   `Execute_priv' server administration
  15050. `FILE'      `File_priv'    file access on server
  15051. `LOCK       `Lock_tables_priv'server administration
  15052. TABLES'                    
  15053. `PROCESS'   `Process_priv' server administration
  15054. `RELOAD'    `Reload_priv'  server administration
  15055. `REPLICATION`Repl_client_priv'server administration
  15056. CLIENT'                    
  15057. `REPLICATION`Repl_slave_priv'server administration
  15058. SLAVE'                     
  15059. `SHOW       `Show_db_priv' server administration
  15060. DATABASES'                 
  15061. `SHUTDOWN'  `Shutdown_priv'server administration
  15062. `SUPER'     `Super_priv'   server administration
  15063.  
  15064. The `SELECT', `INSERT', `UPDATE', and `DELETE' privileges allow you to
  15065. perform operations on rows in existing tables in a database.
  15066.  
  15067. `SELECT' statements require the `SELECT' privilege only if they
  15068. actually retrieve rows from a table.  You can execute certain `SELECT'
  15069. statements even without permission to access any of the databases on the
  15070. server.  For example, you could use the `mysql' client as a simple
  15071. calculator:
  15072.  
  15073.      mysql> SELECT 1+1;
  15074.      mysql> SELECT PI()*2;
  15075.  
  15076. The `INDEX' privilege allows you to create or drop (remove) indexes.
  15077.  
  15078. The `ALTER' privilege allows you to use `ALTER TABLE'.
  15079.  
  15080. The `CREATE' and `DROP' privileges allow you to create new databases
  15081. and tables, or to drop (remove) existing databases and tables.
  15082.  
  15083. Note that if you grant the `DROP' privilege for the `mysql' database to
  15084. a user, that user can drop the database in which the MySQL access
  15085. privileges are stored!
  15086.  
  15087. The `GRANT' privilege allows you to give to other users those
  15088. privileges you yourself possess.
  15089.  
  15090. The `FILE' privilege gives you permission to read and write files on
  15091. the server using the `LOAD DATA INFILE' and `SELECT ... INTO OUTFILE'
  15092. statements.  Any user to whom this privilege is granted can read any
  15093. world readable file accessable by the MySQL server and create a new
  15094. world readable file in any directory where the MySQL server can write.
  15095. The user can also read any file in the current database directory.  The
  15096. user can however not change any existing file.
  15097.  
  15098. The remaining privileges are used for administrative operations, which
  15099. are performed using the `mysqladmin' program.  The table here shows
  15100. which `mysqladmin' commands each administrative privilege allows you to
  15101. execute:
  15102.  
  15103. *Privilege* *Commands permitted to privilege holders*
  15104. `RELOAD'    `reload', `refresh', `flush-privileges',
  15105.             `flush-hosts', `flush-logs', and `flush-tables'
  15106. `SHUTDOWN'  `shutdown'
  15107. `PROCESS'   `processlist'
  15108. `SUPER'     `kill'
  15109.  
  15110. The `reload' command tells the server to re-read the grant tables.  The
  15111. `refresh' command flushes all tables and opens and closes the log
  15112. files.  `flush-privileges' is a synonym for `reload'.  The other
  15113. `flush-*' commands perform functions similar to `refresh' but are more
  15114. limited in scope, and may be preferable in some instances.  For example,
  15115. if you want to flush just the log files, `flush-logs' is a better choice
  15116. than `refresh'.
  15117.  
  15118. The `shutdown' command shuts down the server.
  15119.  
  15120. The `processlist' command displays information about the threads
  15121. executing within the server.  The `kill' command kills server threads.
  15122. You can always display or kill your own threads, but you need the
  15123. `PROCESS' privilege to display and `SUPER' privilege to kill threads
  15124. initiated by other users. *Note KILL::.
  15125.  
  15126. It is a good idea in general to grant privileges only to those users
  15127. who need them, but you should exercise particular caution in granting
  15128. certain privileges:
  15129.  
  15130.    * The `GRANT' privilege allows users to give away their privileges to
  15131.      other users.  Two users with different privileges and with the
  15132.      `GRANT' privilege are able to combine privileges.
  15133.  
  15134.    * The `ALTER' privilege may be used to subvert the privilege system
  15135.      by renaming tables.
  15136.  
  15137.    * The `FILE' privilege can be abused to read any world-readable file
  15138.      on the server or any file in the current database directory on the
  15139.      server into a database table, the contents of which can then be
  15140.      accessed using `SELECT'.
  15141.  
  15142.    * The `SHUTDOWN' privilege can be abused to deny service to other
  15143.      users entirely, by terminating the server.
  15144.  
  15145.    * The `PROCESS' privilege can be used to view the plain text of
  15146.      currently executing queries, including queries that set or change
  15147.      passwords.
  15148.  
  15149.    * Privileges on the `mysql' database can be used to change passwords
  15150.      and other access privilege information.  (Passwords are stored
  15151.      encrypted, so a malicious user cannot simply read them to know the
  15152.      plain text password.)  If they can access the `mysql.user' password
  15153.      column, they can use it to log into the MySQL server for the given
  15154.      user.  (With sufficient privileges, the same user can replace a
  15155.      password with a different one.)
  15156.  
  15157. There are some things that you cannot do with the MySQL privilege
  15158. system:
  15159.  
  15160.    * You cannot explicitly specify that a given user should be denied
  15161.      access.  That is, you cannot explicitly match a user and then
  15162.      refuse the connection.
  15163.  
  15164.    * You cannot specify that a user has privileges to create or drop
  15165.      tables in a database but not to create or drop the database itself.
  15166.  
  15167. Connecting to the MySQL Server
  15168. ------------------------------
  15169.  
  15170. MySQL client programs generally require that you specify connection
  15171. parameters when you want to access a MySQL server: the host you want to
  15172. connect to, your user name, and your password.  For example, the
  15173. `mysql' client can be started like this (optional arguments are enclosed
  15174. between `[' and `]'):
  15175.  
  15176.      shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
  15177.  
  15178. Alternate forms of the `-h', `-u', and `-p' options are
  15179. `--host=host_name', `--user=user_name', and `--password=your_pass'.
  15180. Note that there is _no space_ between `-p' or `--password=' and the
  15181. password following it.
  15182.  
  15183. *Note*: Specifying a password on the command-line is not secure!  Any
  15184. user on your system may then find out your password by typing a command
  15185. like: `ps auxww'.  *Note Option files::.
  15186.  
  15187. `mysql' uses default values for connection parameters that are missing
  15188. from the command-line:
  15189.  
  15190.    * The default hostname is `localhost'.
  15191.  
  15192.    * The default user name is your Unix login name.
  15193.  
  15194.    * No password is supplied if `-p' is missing.
  15195.  
  15196. Thus, for a Unix user `joe', the following commands are equivalent:
  15197.  
  15198.      shell> mysql -h localhost -u joe
  15199.      shell> mysql -h localhost
  15200.      shell> mysql -u joe
  15201.      shell> mysql
  15202.  
  15203. Other MySQL clients behave similarly.
  15204.  
  15205. On Unix systems, you can specify different default values to be used
  15206. when you make a connection, so that you need not enter them on the
  15207. command-line each time you invoke a client program.  This can be done
  15208. in a couple of ways:
  15209.  
  15210.    * You can specify connection parameters in the `[client]' section of
  15211.      the `.my.cnf' configuration file in your home directory.  The
  15212.      relevant section of the file might look like this:
  15213.  
  15214.           [client]
  15215.           host=host_name
  15216.           user=user_name
  15217.           password=your_pass
  15218.  
  15219.      *Note Option files::.
  15220.  
  15221.    * You can specify connection parameters using environment variables.
  15222.      The host can be specified for `mysql' using `MYSQL_HOST'.  The
  15223.      MySQL user name can be specified using `USER' (this is for Windows
  15224.      only).  The password can be specified using `MYSQL_PWD' (but this
  15225.      is insecure; see the next section).  *Note Environment variables::.
  15226.  
  15227. Access Control, Stage 1: Connection Verification
  15228. ------------------------------------------------
  15229.  
  15230. When you attempt to connect to a MySQL server, the server accepts or
  15231. rejects the connection based on your identity and whether you can
  15232. verify your identity by supplying the correct password.  If not, the
  15233. server denies access to you completely.  Otherwise, the server accepts
  15234. the connection, then enters Stage 2 and waits for requests.
  15235.  
  15236. Your identity is based on two pieces of information:
  15237.  
  15238.    * The host from which you connect
  15239.  
  15240.    * Your MySQL user name
  15241.  
  15242. Identity checking is performed using the three `user' table scope fields
  15243. (`Host', `User', and `Password').  The server accepts the connection
  15244. only if a `user' table entry matches your hostname and user name, and
  15245. you supply the correct password.
  15246.  
  15247. Values in the `user' table scope fields may be specified as follows:
  15248.  
  15249.    * A `Host' value may be a hostname or an IP number, or `'localhost''
  15250.      to indicate the local host.
  15251.  
  15252.    * You can use the wildcard characters `%' and `_' in the `Host'
  15253.      field.
  15254.  
  15255.    * A `Host' value of `'%'' matches any hostname.
  15256.  
  15257.    * A blank `Host' value means that the privilege should be anded with
  15258.      the entry in the `host' table that matches the given host name.
  15259.      You can find more information about this in the next chapter.
  15260.  
  15261.    * As of MySQL Version 3.23, for `Host' values specified as IP
  15262.      numbers, you can specify a netmask indicating how many address
  15263.      bits to use for the network number. For example:
  15264.  
  15265.           mysql> GRANT ALL PRIVILEGES ON db.*
  15266.               -> TO david@'192.58.197.0/255.255.255.0';
  15267.  
  15268.      This will allow everyone to connect from an IP where the following
  15269.      is true:
  15270.  
  15271.           user_ip & netmask = host_ip.
  15272.  
  15273.      In the above example all IP:s in the interval 192.58.197.0 -
  15274.      192.58.197.255 can connect to the MySQL server.
  15275.  
  15276.    * Wildcard characters are not allowed in the `User' field, but you
  15277.      can specify a blank value, which matches any name.  If the `user'
  15278.      table entry that matches an incoming connection has a blank user
  15279.      name, the user is considered to be the anonymous user (the user
  15280.      with no name), rather than the name that the client actually
  15281.      specified.  This means that a blank user name is used for all
  15282.      further access checking for the duration of the connection (that
  15283.      is, during Stage 2).
  15284.  
  15285.    * The `Password' field can be blank.  This does not mean that any
  15286.      password matches, it means the user must connect without
  15287.      specifying a password.
  15288.  
  15289. Non-blank `Password' values represent encrypted passwords.  MySQL does
  15290. not store passwords in plaintext form for anyone to see.  Rather, the
  15291. password supplied by a user who is attempting to connect is encrypted
  15292. (using the `PASSWORD()' function). The encrypted password is then used
  15293. when the client/server is checking if the password is correct. (This is
  15294. done without the encrypted password ever traveling over the
  15295. connection.)  Note that from MySQL's point of view the encrypted
  15296. password is the REAL password, so you should not give anyone access to
  15297. it!  In particular, don't give normal users read access to the tables
  15298. in the `mysql' database!  From version 4.1, MySQL employs a different
  15299. password and login mechanism that is secure even if TCP/IP packets are
  15300. sniffed and/or the mysql database is captured.
  15301.  
  15302. The examples here show how various combinations of `Host' and `User'
  15303. values in `user' table entries apply to incoming connections:
  15304.  
  15305. `Host' *value*            `User'      *Connections matched by entry*
  15306.                           *value*     
  15307. `'thomas.loc.gov''        `'fred''    `fred', connecting from
  15308.                                       `thomas.loc.gov'
  15309. `'thomas.loc.gov''        `'''        Any user, connecting from
  15310.                                       `thomas.loc.gov'
  15311. `'%''                     `'fred''    `fred', connecting from any host
  15312. `'%''                     `'''        Any user, connecting from any host
  15313. `'%.loc.gov''             `'fred''    `fred', connecting from any host in
  15314.                                       the `loc.gov' domain
  15315. `'x.y.%''                 `'fred''    `fred', connecting from `x.y.net',
  15316.                                       `x.y.com',`x.y.edu', etc. (this is
  15317.                                       probably not useful)
  15318. `'144.155.166.177''       `'fred''    `fred', connecting from the host
  15319.                                       with IP address `144.155.166.177'
  15320. `'144.155.166.%''         `'fred''    `fred', connecting from any host in
  15321.                                       the `144.155.166' class C subnet
  15322. `'144.155.166.0/255.255.255.0''`'fred''    Same as previous example
  15323.  
  15324. Because you can use IP wildcard values in the `Host' field (for example,
  15325. `'144.155.166.%'' to match every host on a subnet), there is the
  15326. possibility that someone might try to exploit this capability by naming
  15327. a host `144.155.166.somewhere.com'.  To foil such attempts, MySQL
  15328. disallows matching on hostnames that start with digits and a dot. Thus,
  15329. if you have a host named something like `1.2.foo.com', its name will
  15330. never match the `Host' column of the grant tables.  Only an IP number
  15331. can match an IP wildcard value.
  15332.  
  15333. An incoming connection may be matched by more than one entry in the
  15334. `user' table.  For example, a connection from `thomas.loc.gov' by
  15335. `fred' would be matched by several of the entries shown in the preceding
  15336. table.  How does the server choose which entry to use if more than one
  15337. matches?  The server resolves this question by sorting the `user' table
  15338. after reading it at startup time, then looking through the entries in
  15339. sorted order when a user attempts to connect.  The first matching entry
  15340. is the one that is used.
  15341.  
  15342. `user' table sorting works as follows.  Suppose the `user' table looks
  15343. like this:
  15344.  
  15345.      +-----------+----------+-
  15346.      | Host      | User     | ...
  15347.      +-----------+----------+-
  15348.      | %         | root     | ...
  15349.      | %         | jeffrey  | ...
  15350.      | localhost | root     | ...
  15351.      | localhost |          | ...
  15352.      +-----------+----------+-
  15353.  
  15354. When the server reads in the table, it orders the entries with the
  15355. most-specific `Host' values first (`'%'' in the `Host' column means
  15356. "any host" and is least specific).  Entries with the same `Host' value
  15357. are ordered with the most-specific `User' values first (a blank `User'
  15358. value means "any user" and is least specific).  The resulting sorted
  15359. `user' table looks like this:
  15360.  
  15361.      +-----------+----------+-
  15362.      | Host      | User     | ...
  15363.      +-----------+----------+-
  15364.      | localhost | root     | ...
  15365.      | localhost |          | ...
  15366.      | %         | jeffrey  | ...
  15367.      | %         | root     | ...
  15368.      +-----------+----------+-
  15369.  
  15370. When a connection is attempted, the server looks through the sorted
  15371. entries and uses the first match found.  For a connection from
  15372. `localhost' by `jeffrey', the entries with `'localhost'' in the `Host'
  15373. column match first.  Of those, the entry with the blank user name
  15374. matches both the connecting hostname and user name.  (The
  15375. `'%'/'jeffrey'' entry would have matched, too, but it is not the first
  15376. match in the table.)
  15377.  
  15378. Here is another example.  Suppose the `user' table looks like this:
  15379.  
  15380.      +----------------+----------+-
  15381.      | Host           | User     | ...
  15382.      +----------------+----------+-
  15383.      | %              | jeffrey  | ...
  15384.      | thomas.loc.gov |          | ...
  15385.      +----------------+----------+-
  15386.  
  15387. The sorted table looks like this:
  15388.  
  15389.      +----------------+----------+-
  15390.      | Host           | User     | ...
  15391.      +----------------+----------+-
  15392.      | thomas.loc.gov |          | ...
  15393.      | %              | jeffrey  | ...
  15394.      +----------------+----------+-
  15395.  
  15396. A connection from `thomas.loc.gov' by `jeffrey' is matched by the first
  15397. entry, whereas a connection from `whitehouse.gov' by `jeffrey' is
  15398. matched by the second.
  15399.  
  15400. A common misconception is to think that for a given user name, all
  15401. entries that explicitly name that user will be used first when the
  15402. server attempts to find a match for the connection.  This is simply not
  15403. true.  The previous example illustrates this, where a connection from
  15404. `thomas.loc.gov' by `jeffrey' is first matched not by the entry
  15405. containing `'jeffrey'' as the `User' field value, but by the entry with
  15406. no user name!
  15407.  
  15408. If you have problems connecting to the server, print out the `user'
  15409. table and sort it by hand to see where the first match is being made.
  15410. If connection was successful, but your privileges are not what you
  15411. expected you may use `CURRENT_USER()' function (new in version 4.0.6)
  15412. to see what user/host combination your connection actually matched.
  15413. *Note `CURRENT_USER()': Miscellaneous functions.
  15414.  
  15415. Access Control, Stage 2: Request Verification
  15416. ---------------------------------------------
  15417.  
  15418. Once you establish a connection, the server enters Stage 2.  For each
  15419. request that comes in on the connection, the server checks whether you
  15420. have sufficient privileges to perform it, based on the type of
  15421. operation you wish to perform.  This is where the privilege fields in
  15422. the grant tables come into play.  These privileges can come from any of
  15423. the `user', `db', `host', `tables_priv', or `columns_priv' tables.  The
  15424. grant tables are manipulated with `GRANT' and `REVOKE' commands.  *Note
  15425. `GRANT': GRANT.  (You may find it helpful to refer to *Note
  15426. Privileges::, which lists the fields present in each of the grant
  15427. tables.)
  15428.  
  15429. The `user' table grants privileges that are assigned to you on a global
  15430. basis and that apply no matter what the current database is.  For
  15431. example, if the `user' table grants you the `DELETE' privilege, you can
  15432. delete rows from any database on the server host!  In other words,
  15433. `user' table privileges are superuser privileges.  It is wise to grant
  15434. privileges in the `user' table only to superusers such as server or
  15435. database administrators.  For other users, you should leave the
  15436. privileges in the `user' table set to `'N'' and grant privileges on a
  15437. database-specific basis only, using the `db' and `host' tables.
  15438.  
  15439. The `db' and `host' tables grant database-specific privileges.  Values
  15440. in the scope fields may be specified as follows:
  15441.  
  15442.    * The wildcard characters `%' and `_' can be used in the `Host' and
  15443.      `Db' fields of either table. If you wish to use for instance a `_'
  15444.      character as part of a database name, specify it as `\_' in the
  15445.      `GRANT' command.
  15446.  
  15447.    * A `'%'' `Host' value in the `db' table means "any host." A blank
  15448.      `Host' value in the `db' table means "consult the `host' table for
  15449.      further information."
  15450.  
  15451.    * A `'%'' or blank `Host' value in the `host' table means "any host."
  15452.  
  15453.    * A `'%'' or blank `Db' value in either table means "any database."
  15454.  
  15455.    * A blank `User' value in either table matches the anonymous user.
  15456.  
  15457. The `db' and `host' tables are read in and sorted when the server
  15458. starts up (at the same time that it reads the `user' table).  The `db'
  15459. table is sorted on the `Host', `Db', and `User' scope fields, and the
  15460. `host' table is sorted on the `Host' and `Db' scope fields.  As with
  15461. the `user' table, sorting puts the most-specific values first and
  15462. least-specific values last, and when the server looks for matching
  15463. entries, it uses the first match that it finds.
  15464.  
  15465. The `tables_priv' and `columns_priv' tables grant table- and
  15466. column-specific privileges.  Values in the scope fields may be
  15467. specified as follows:
  15468.  
  15469.    * The wildcard characters `%' and `_' can be used in the `Host'
  15470.      field of either table.
  15471.  
  15472.    * A `'%'' or blank `Host' value in either table means "any host."
  15473.  
  15474.    * The `Db', `Table_name' and `Column_name' fields cannot contain
  15475.      wildcards or be blank in either table.
  15476.  
  15477. The `tables_priv' and `columns_priv' tables are sorted on the `Host',
  15478. `Db', and `User' fields.  This is similar to `db' table sorting,
  15479. although the sorting is simpler because only the `Host' field may
  15480. contain wildcards.
  15481.  
  15482. The request verification process is described here.  (If you are
  15483. familiar with the access-checking source code, you will notice that the
  15484. description here differs slightly from the algorithm used in the code.
  15485. The description is equivalent to what the code actually does; it
  15486. differs only to make the explanation simpler.)
  15487.  
  15488. For administrative requests (`SHUTDOWN', `RELOAD', etc.), the server
  15489. checks only the `user' table entry, because that is the only table that
  15490. specifies administrative privileges.  Access is granted if the entry
  15491. allows the requested operation and denied otherwise.  For example, if
  15492. you want to execute `mysqladmin shutdown' but your `user' table entry
  15493. doesn't grant the `SHUTDOWN' privilege to you, access is denied without
  15494. even checking the `db' or `host' tables.  (They contain no
  15495. `Shutdown_priv' column, so there is no need to do so.)
  15496.  
  15497. For database-related requests (`INSERT', `UPDATE', etc.), the server
  15498. first checks the user's global (superuser) privileges by looking in the
  15499. `user' table entry.  If the entry allows the requested operation,
  15500. access is granted.  If the global privileges in the `user' table are
  15501. insufficient, the server determines the user's database-specific
  15502. privileges by checking the `db' and `host' tables:
  15503.  
  15504.   1. The server looks in the `db' table for a match on the `Host',
  15505.      `Db', and `User' fields.  The `Host' and `User' fields are matched
  15506.      to the connecting user's hostname and MySQL user name.  The `Db'
  15507.      field is matched to the database the user wants to access.  If
  15508.      there is no entry for the `Host' and `User', access is denied.
  15509.  
  15510.   2. If there is a matching `db' table entry and its `Host' field is
  15511.      not blank, that entry defines the user's database-specific
  15512.      privileges.
  15513.  
  15514.   3. If the matching `db' table entry's `Host' field is blank, it
  15515.      signifies that the `host' table enumerates which hosts should be
  15516.      allowed access to the database.  In this case, a further lookup is
  15517.      done in the `host' table to find a match on the `Host' and `Db'
  15518.      fields.  If no `host' table entry matches, access is denied.  If
  15519.      there is a match, the user's database-specific privileges are
  15520.      computed as the intersection (*not* the union!) of the privileges
  15521.      in the `db' and `host' table entries, that is, the privileges that
  15522.      are `'Y'' in both entries.  (This way you can grant general
  15523.      privileges in the `db' table entry and then selectively restrict
  15524.      them on a host-by-host basis using the `host' table entries.)
  15525.  
  15526. After determining the database-specific privileges granted by the `db'
  15527. and `host' table entries, the server adds them to the global privileges
  15528. granted by the `user' table.  If the result allows the requested
  15529. operation, access is granted.  Otherwise, the server checks the user's
  15530. table and column privileges in the `tables_priv' and `columns_priv'
  15531. tables and adds those to the user's privileges.  Access is allowed or
  15532. denied based on the result.
  15533.  
  15534. Expressed in boolean terms, the preceding description of how a user's
  15535. privileges are calculated may be summarised like this:
  15536.  
  15537.      global privileges
  15538.      OR (database privileges AND host privileges)
  15539.      OR table privileges
  15540.      OR column privileges
  15541.  
  15542. It may not be apparent why, if the global `user' entry privileges are
  15543. initially found to be insufficient for the requested operation, the
  15544. server adds those privileges to the database-, table-, and
  15545. column-specific privileges later. The reason is that a request might
  15546. require more than one type of privilege.  For example, if you execute
  15547. an `INSERT ...  SELECT' statement, you need both `INSERT' and `SELECT'
  15548. privileges.  Your privileges might be such that the `user' table entry
  15549. grants one privilege and the `db' table entry grants the other.  In
  15550. this case, you have the necessary privileges to perform the request,
  15551. but the server cannot tell that from either table by itself; the
  15552. privileges granted by the entries in both tables must be combined.
  15553.  
  15554. The `host' table can be used to maintain a list of secure servers.
  15555.  
  15556. At TcX, the `host' table contains a list of all machines on the local
  15557. network. These are granted all privileges.
  15558.  
  15559. You can also use the `host' table to indicate hosts that are *not*
  15560. secure.  Suppose you have a machine `public.your.domain' that is located
  15561. in a public area that you do not consider secure.  You can allow access
  15562. to all hosts on your network except that machine by using `host' table
  15563. entries like this:
  15564.  
  15565.      +--------------------+----+-
  15566.      | Host               | Db | ...
  15567.      +--------------------+----+-
  15568.      | public.your.domain | %  | ... (all privileges set to 'N')
  15569.      | %.your.domain      | %  | ... (all privileges set to 'Y')
  15570.      +--------------------+----+-
  15571.  
  15572. Naturally, you should always test your entries in the grant tables (for
  15573. example, using `mysqlaccess') to make sure your access privileges are
  15574. actually set up the way you think they are.
  15575.  
  15576. Password Hashing in MySQL 4.1
  15577. -----------------------------
  15578.  
  15579. MySQL user accounts are listed in the `user' table of the `mysql'
  15580. database. Each MySQL account is assigned a password, although what is
  15581. stored in the `Password' column of the `user' table is not the
  15582. plaintext version of the password, but a hash value computed from it.
  15583. Password hash values are computed by the `PASSWORD()' function.
  15584.  
  15585. MySQL uses passwords in two phases of client/server communication:
  15586.  
  15587.    * First, when a client attempts to connect to the server, there is an
  15588.      initial authentication step in which the client must present a
  15589.      password that matches the hash value stored in the user table for
  15590.      the account that the client wants to use.
  15591.  
  15592.    * Second, after the client connects, it may set or change the
  15593.      password hashes for accounts listed in the user table (if it has
  15594.      sufficient privileges). The client may do this by using the
  15595.      PASSWORD() function to generate a password hash, or by using the
  15596.      GRANT or SET PASSWORD statements.
  15597.  
  15598.  
  15599. In other words, the server _uses_ hash values during authentication when
  15600. a client first attempts to connect. The server _generates_ hash values
  15601. if a connected client invokes the `PASSWORD()' function or uses a
  15602. `GRANT' or `SET PASSWORD' statement to set or change a password.
  15603.  
  15604. The password hashing mechanism was updated in MySQL 4.1 to provide
  15605. better security and to reduce the risk of passwords being stolen.
  15606. However, this new mechanism is understood only by the 4.1 server and
  15607. 4.1 clients, which can result in some compatibility problems.  A 4.1
  15608. client can connect to a pre-4.1 server, because the client understands
  15609. both the old and new password hashing mechanisms. However, a pre-4.1
  15610. client that attempts to connect to a 4.1 server may run into
  15611. difficulties.  For example, a 4.0 `mysql' client that attempts to
  15612. connect to a 4.1 server may fail with the following error message:
  15613.  
  15614.      shell> mysql
  15615.      Client does not support authentication protocol requested
  15616.      by server; consider upgrading MySQL client
  15617.  
  15618. The following discussion describes the differences between the old and
  15619. new password mechanisms, and what you should do if you upgrade your
  15620. server to 4.1 but need to maintain backward compatibility with pre-4.1
  15621. clients.
  15622.  
  15623. *Note:* This discussion contrasts 4.1 behaviour with pre-4.1 behaviour,
  15624. but the 4.1 behaviour described here actually begins with 4.1.1. MySQL
  15625. 4.1.0 is an "odd" release because it has a slightly different mechanism
  15626. than that implemented in 4.1.1 and up.  Differences between 4.1.0 and
  15627. more recent versions are described later.
  15628.  
  15629. Prior to MySQL 4.1, password hashes computed by the `PASSWORD()'
  15630. function are 16 bytes long.  Such hashes look like this:
  15631.  
  15632.      mysql> SELECT PASSWORD('mypass');
  15633.      +--------------------+
  15634.      | PASSWORD('mypass') |
  15635.      +--------------------+
  15636.      | 6f8c114b58f2ce9e   |
  15637.      +--------------------+
  15638.  
  15639. The `Password' column of the `user' table (in which these hashes are
  15640. stored) also is 16 bytes long before MySQL 4.1.
  15641.  
  15642. As of MySQL 4.1, the `PASSWORD()' function has been modified to produce
  15643. a longer 41-byte hash value:
  15644.  
  15645.      mysql> SELECT PASSWORD('mypass');
  15646.      +-----------------------------------------------+
  15647.      | PASSWORD('mypass')                            |
  15648.      +-----------------------------------------------+
  15649.      | *43c8aa34cdc98eddd3de1fe9a9c2c2a9f92bb2098d75 |
  15650.      +-----------------------------------------------+
  15651.  
  15652. Accordingly, the `Password' column in the `user' table also must be 41
  15653. bytes long to store these values:
  15654.  
  15655.    * If you perform a new installation of MySQL 4.1, the `Password'
  15656.      column will be made 41 bytes long automatically.
  15657.  
  15658.    * If you upgrade an older installation to 4.1, you should run the
  15659.      `mysql_fix_privilege_tables' script to update the length of the
  15660.      `Password' column from 16 to 41 bytes. (The script does not change
  15661.      existing password values, which remain 16 bytes long.)
  15662.  
  15663.  
  15664. A widened `Password' column can store password hashes in both the old
  15665. and new formats. The format of any given password hash value can be
  15666. determined two ways:
  15667.  
  15668.    * The obvious difference is the length (16 bytes versus 41 bytes)
  15669.  
  15670.    * A second difference is that password hashes in the new format
  15671.      always begin with a `*' character, whereas passwords in the old
  15672.      format never do
  15673.  
  15674.  
  15675. The longer password hash format has better cryptographic properties, and
  15676. client authentication based on long hashes is more secure than that
  15677. based on the older short hashes.
  15678.  
  15679. The differences between short and long password hashes are relevant
  15680. both for how the server uses passwords during authentication and for
  15681. how it generates password hashes for connected clients that perform
  15682. password-changing operations.
  15683.  
  15684. The way in which the server uses password hashes during authentication
  15685. is affected by the width of the Password column:
  15686.  
  15687.    * If the column is narrow, only short-hash authentication is used.
  15688.  
  15689.    * If the column is wide, it can hold either short or long hashes, and
  15690.      the server can use either format:
  15691.  
  15692.         * Pre-4.1 clients can connect, though because they know only
  15693.           about the old hashing mechanism, they can authenticate only
  15694.           for accounts that have short hashes.
  15695.  
  15696.         * 4.1 clients can authenticate for accounts that have short or
  15697.           long hashes.
  15698.  
  15699.  
  15700.  
  15701. For short-hash accounts, the authentication process is actually a bit
  15702. more secure for 4.1 clients than for older clients.  In terms of
  15703. security, the gradient from least to most secure is:
  15704.  
  15705.    * Pre-4.1 client authenticating for account with short password hash
  15706.  
  15707.    * 4.1 client authenticating for account with short password hash
  15708.  
  15709.    * 4.1 client authenticating for account with long password hash
  15710.  
  15711.  
  15712. The way in which the server generates password hashes for connected
  15713. clients is affected by the width of the `Password' column and by the
  15714. `--old-passwords' option.  A 4.1 server generates long hashes only if
  15715. certain conditions are met: The `Password' column must be wide enough
  15716. to hold long values and the `--old-passwords' option must not be given.
  15717. These conditions apply as follows:
  15718.  
  15719.    * The `Password' column must be wide enough to hold long hashes (41
  15720.      bytes).  If the column has not been updated and still has the
  15721.      pre-4.1 width (16 bytes), the server notices that long hashes
  15722.      cannot fit into it and generates only short hashes when a client
  15723.      performs password-changing operations using `PASSWORD()', `GRANT',
  15724.      or `SET PASSWORD'.  (This behaviour occurs if you have upgraded to
  15725.      4.1 but have not run the `mysql_fix_privilege_tables' script to
  15726.      widen the `Password' column.)
  15727.  
  15728.    * If the `Password' column is wide, it can store either short or long
  15729.      password hashes. In this case, `PASSWORD()', `GRANT', and `SET
  15730.      PASSWORD' will generate long hashes unless the server was started
  15731.      with the `--old-passwords' option. This option forces the server
  15732.      to generate short passsword hashes instead.
  15733.  
  15734.  
  15735. The purpose of the `--old-passwords' option is to allow you to maintain
  15736. backward compatibility with pre-4.1 clients under circumstances where
  15737. the server would otherwise generate long password hashes. It doesn't
  15738. affect authentication (4.1 clients can still use accounts that have
  15739. long password hashes), but it does prevent creation of a long password
  15740. hash in the `user' table as the result of a password-changing
  15741. operation. Were that to occur, the account no longer could be used by
  15742. pre-4.1 clients. Without the `--old-passwords' option, the following
  15743. scenario is possible:
  15744.  
  15745.    * An old client connects to an account that has a short password
  15746.      hash.
  15747.  
  15748.    * The client changes the account's password. Without
  15749.      `--old-passwords', this results in the account having a long
  15750.      password hash.
  15751.  
  15752.    * The next time the old client attempts to connect to the account, it
  15753.      cannot, because the account now requires the new hashing mechanism
  15754.      during authentication. (Once an account has a long password hash in
  15755.      the user table, only 4.1 clients can authenticate for it, because
  15756.      pre-4.1 clients do not understand long hashes.)
  15757.  
  15758.  
  15759. This scenario illustrates that it is dangerous to run a 4.1 server
  15760. without using the `--old-passwords' option if you must support older
  15761. pre-4.1 clients. By running the server with `--old-passwords',
  15762. password-changing operations will not generate long password hashes and
  15763. thus do not cause accounts to become inaccessible to older clients.
  15764. (Those clients cannot inadvertently lock themselves out by changing
  15765. their password and ending up with a long password hash.)
  15766.  
  15767. The downside of the `--old-passwords' option is that any passwords you
  15768. create or change will use short hashes, even for 4.1 clients. Thus, you
  15769. lose the additional security provided by long password hashes. If you
  15770. want to create an account that has a long hash (for example, for use by
  15771. 4.1 clients), you must do so while running the server without
  15772. `--old-passwords'.
  15773.  
  15774. The following scenarios are possible for running a 4.1 server:
  15775.  
  15776. Scenario 1) Narrow `Password' column in user table
  15777.  
  15778.    * Only short hashes can be stored in the `Password' column.
  15779.  
  15780.    * The server uses only short hashes during client authentication.
  15781.  
  15782.    * For connected clients, password hash-generating operations
  15783.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  15784.      exclusively.  Any change to an account's password results in that
  15785.      account having a short password hash.
  15786.  
  15787.    * The `--old-passwords' option can be used but is superfluous because
  15788.      with a narrow `Password' column, the server will be generating
  15789.      short password hashes anyway.
  15790.  
  15791.  
  15792. Scenario 2) Long `Password' column; server not started with
  15793. `--old-passwords' option
  15794.  
  15795.    * Short or long hashes can be stored in the `Password' column.
  15796.  
  15797.    * 4.1 clients can authenticate for accounts that have short or long
  15798.      hashes.
  15799.  
  15800.    * Pre-4.1 clients can authenticate only for accounts that have short
  15801.      hashes.
  15802.  
  15803.    * For connected clients, password hash-generating operations
  15804.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use long hashes
  15805.      exclusively.  Any change to an account's password results in that
  15806.      account having a long password hash.
  15807.  
  15808.    * `OLD_PASSWORD()' may be used to explicitly generate a short hash.
  15809.      For example, to assign an account a short password, use `UPDATE'
  15810.      as follows:
  15811.  
  15812.           mysql> UPDATE user SET Password = OLD_PASSWORD('mypass')
  15813.               -> WHERE Host = 'some_host' AND User = 'some_user';
  15814.           mysql> FLUSH PRIVILEGES;
  15815.  
  15816.  
  15817. As indicated earlier, a danger in this scenario is that it is possible
  15818. for accounts that have a short password hash to become inaccessible to
  15819. pre-4.1 clients. Any change to such an account's password made via
  15820. `GRANT', `SET PASSWORD', or `PASSWORD()' results in the account being
  15821. given a long password hash, and from that point on, no pre-4.1 client
  15822. can authenticate to that account until the client upgrades to 4.1.
  15823.  
  15824. Scenario 3) Long `Password' column; server started with
  15825. `--old-passwords' option
  15826.  
  15827.    * Short or long hashes can be stored in the `Password' column.
  15828.  
  15829.    * 4.1 clients can authenticate for accounts that have short or long
  15830.      hashes (but note that it is possible to create long hashes only
  15831.      when the server is started without `--old-passwords').
  15832.  
  15833.    * Pre-4.1 clients can authenticate only for accounts that have short
  15834.      hashes.
  15835.  
  15836.    * For connected clients, password hash-generating operations
  15837.      involving `PASSWORD()', `GRANT', or `SET PASSWORD' use short hashes
  15838.      exclusively.  Any change to an account's password results in that
  15839.      account having a short password hash.
  15840.  
  15841.  
  15842. In this scenario, you cannot create accounts that have long password
  15843. hashes, because `--old-passwords' prevents generation of long hashes.
  15844. Also, if you create an account with a long hash before using the
  15845. `--old-passwords' option, changing the account's password while
  15846. `--old-passwords' is in effect results in the account being given a
  15847. short password, causing it to lose the security benefits of a longer
  15848. hash.
  15849.  
  15850. The disadvantages for these scenarios may be summarized as follows:
  15851.  
  15852. Scenario 1) You cannot take advantage of longer hashes that provide more
  15853. secure authentication.
  15854.  
  15855. Scenario 2) Accounts with short hashes become inaccessible to pre-4.1
  15856. clients if you change their passwords without explicitly using
  15857. `OLD_PASSWORD()'.
  15858.  
  15859. Scenario 3) `--old-passwords' prevents accounts with short hashes from
  15860. becoming inaccessible, but password-changing operations cause accounts
  15861. with long hashes to revert to short hashes, and you cannot change them
  15862. back to long hashes while `--old-passwords' is in effect.
  15863.  
  15864. Implications of Password Hashing Changes for Application Programs
  15865. -----------------------------------------------------------------
  15866.  
  15867. An upgrade to MySQL 4.1 can cause a compatibility issue for
  15868. applications that use `PASSWORD()' to generate passwords for their own
  15869. purposes. (Applications really should not do this, because `PASSWORD()'
  15870. should be used only to manage passwords for MySQL accounts. But some
  15871. applications use `PASSWORD()' for their own purposes anyway.)  If you
  15872. upgrade to 4.1 and run the server under conditions where it generates
  15873. long password hashes, an application that uses `PASSWORD()' for its own
  15874. passwords will break.  The recommended course of action is to modify
  15875. the application to use another function such as `SHA1()' or `MD5()' to
  15876. produce hashed values.  If that is not possible, you can use the
  15877. `OLD_PASSWORD()' function, which is provided to generate short hashes
  15878. in the old format. (But note that `OLD_PASSWORD()' may one day no
  15879. longer be supported.)
  15880.  
  15881. If the server is running under circumstances where it generates short
  15882. hashes, `OLD_PASSWORD()' is available but is equivalent to `PASSWORD()'.
  15883.  
  15884. Password hashing in MySQL 4.1.0 differs from hashing in 4.1.1 and up.
  15885. The 4.1.0 differences are:
  15886.  
  15887.    * Password hashes are 45 bytes long rather than 41 bytes.
  15888.  
  15889.    * The `PASSWORD()' function is non-repeatable.  That is, with a given
  15890.      argument `X', successive calls to `PASSWORD(X)' generate different
  15891.      results.
  15892.  
  15893.  
  15894. Causes of `Access denied' Errors
  15895. --------------------------------
  15896.  
  15897. If you encounter `Access denied' errors when you try to connect to the
  15898. MySQL server, the following list indicates some courses of action you
  15899. can take to correct the problem:
  15900.  
  15901.    * After installing MySQL, did you run the `mysql_install_db' script
  15902.      to set up the initial grant table contents?  If not, do so.  *Note
  15903.      Default privileges::.  Test the initial privileges by executing
  15904.      this command:
  15905.  
  15906.           shell> mysql -u root test
  15907.  
  15908.      The server should let you connect without error.  You should also
  15909.      make sure you have a file `user.MYD' in the MySQL database
  15910.      directory.  Ordinarily, this is `PATH/var/mysql/user.MYD', where
  15911.      `PATH' is the pathname to the MySQL installation root.
  15912.  
  15913.    * After a fresh installation, you should connect to the server and
  15914.      set up your users and their access permissions:
  15915.  
  15916.           shell> mysql -u root mysql
  15917.  
  15918.      The server should let you connect because the MySQL `root' user
  15919.      has no password initially.  That is also a security risk, so
  15920.      setting the `root' password is something you should do while
  15921.      you're setting up your other MySQL users.
  15922.  
  15923.      If you try to connect as `root' and get this error:
  15924.  
  15925.           Access denied for user: '@unknown' to database mysql
  15926.  
  15927.      this means that you don't have an entry in the `user' table with a
  15928.      `User' column value of `'root'' and that `mysqld' cannot resolve
  15929.      the hostname for your client.  In this case, you must restart the
  15930.      server with the `--skip-grant-tables' option and edit your
  15931.      `/etc/hosts' or `\windows\hosts' file to add an entry for your
  15932.      host.
  15933.  
  15934.    * If you get an error like the following:
  15935.  
  15936.           shell> mysqladmin -u root -pxxxx ver
  15937.           Access denied for user: 'root@localhost' (Using password: YES)
  15938.  
  15939.      It means that you are using an incorrect password. *Note
  15940.      Passwords::.
  15941.  
  15942.      If you have forgot the root password, you can restart `mysqld' with
  15943.      `--skip-grant-tables' to change the password.  *Note Resetting
  15944.      permissions::.
  15945.  
  15946.      If you get the above error even if you haven't specified a
  15947.      password, this means that you have an incorrect password in some
  15948.      `my.ini' file. *Note Option files::.  You can avoid using option
  15949.      files with the `--no-defaults' option, as follows:
  15950.  
  15951.           shell> mysqladmin --no-defaults -u root ver
  15952.  
  15953.    * If you updated an existing MySQL installation from a version
  15954.      earlier than Version 3.22.11 to Version 3.22.11 or later, did you
  15955.      run the `mysql_fix_privilege_tables' script?  If not, do so.  The
  15956.      structure of the grant tables changed with MySQL Version 3.22.11
  15957.      when the `GRANT' statement became functional.  *Note
  15958.      Upgrading-grant-tables::.
  15959.  
  15960.    * If your privileges seem to have changed in the middle of a
  15961.      session, it may be that a superuser has changed them.  Reloading
  15962.      the grant tables affects new client connections, but it also
  15963.      affects existing connections as indicated in *Note Privilege
  15964.      changes::.
  15965.  
  15966.    * If you can't get your password to work, remember that you must use
  15967.      the `PASSWORD()' function if you set the password with the
  15968.      `INSERT', `UPDATE', or `SET PASSWORD' statements.  The
  15969.      `PASSWORD()' function is unnecessary if you specify the password
  15970.      using the `GRANT ... IDENTIFIED BY' statement or the `mysqladmin
  15971.      password' command.  *Note Passwords::.
  15972.  
  15973.    * `localhost' is a synonym for your local hostname, and is also the
  15974.      default host to which clients try to connect if you specify no host
  15975.      explicitly.  However, connections to `localhost' do not work if
  15976.      you are using a MySQL version prior to 3.23.27 that uses
  15977.      MIT-pthreads (`localhost' connections are made using Unix sockets,
  15978.      which were not supported by MIT-pthreads at that time).  To avoid
  15979.      this problem on such systems, you should use the `--host' option
  15980.      to name the server host explicitly.  This will make a TCP/IP
  15981.      connection to the `mysqld' server.  In this case, you must have
  15982.      your real hostname in `user' table entries on the server host.
  15983.      (This is true even if you are running a client program on the same
  15984.      host as the server.)
  15985.  
  15986.    * If you get an `Access denied' error when trying to connect to the
  15987.      database with `mysql -u user_name db_name', you may have a problem
  15988.      with the `user' table. Check this by executing `mysql -u root
  15989.      mysql' and issuing this SQL statement:
  15990.  
  15991.           mysql> SELECT * FROM user;
  15992.  
  15993.      The result should include an entry with the `Host' and `User'
  15994.      columns matching your computer's hostname and your MySQL user name.
  15995.  
  15996.    * The `Access denied' error message will tell you who you are trying
  15997.      to log in as, the host from which you are trying to connect, and
  15998.      whether or not you were using a password. Normally, you should
  15999.      have one entry in the `user' table that exactly matches the
  16000.      hostname and user name that were given in the error message. For
  16001.      example if you get an error message that contains `Using password:
  16002.      NO', this means that you tried to login without an password.
  16003.  
  16004.    * If you get the following error when you try to connect from a
  16005.      different host than the one on which the MySQL server is running,
  16006.      then there is no row in the `user' table that matches that host:
  16007.  
  16008.           Host ... is not allowed to connect to this MySQL server
  16009.  
  16010.      You can fix this by using the command-line tool `mysql' (on the
  16011.      server host!) to add a row to the `user', `db', or `host' table
  16012.      for the user/hostname combination from which you are trying to
  16013.      connect and then execute `mysqladmin flush-privileges'.  If you are
  16014.      not running MySQL Version 3.22 and you don't know the IP number or
  16015.      hostname of the machine from which you are connecting, you should
  16016.      put an entry with `'%'' as the `Host' column value in the `user'
  16017.      table and restart `mysqld' with the `--log' option on the server
  16018.      machine.  After trying to connect from the client machine, the
  16019.      information in the MySQL log will indicate how you really did
  16020.      connect.  (Then replace the `'%'' in the `user' table entry with
  16021.      the actual hostname that shows up in the log.  Otherwise, you'll
  16022.      have a system that is insecure.)
  16023.  
  16024.      Another reason for this error on Linux is that you are using a
  16025.      binary MySQL version that is compiled with a different glibc
  16026.      version than the one you are using.  In this case you should
  16027.      either upgrade your OS/glibc or download the source MySQL version
  16028.      and compile this yourself.  A source RPM is normally trivial to
  16029.      compile and install, so this isn't a big problem.
  16030.  
  16031.    * If you get an error message where the hostname is not shown or
  16032.      where the hostname is an IP, even if you try to connect with a
  16033.      hostname:
  16034.  
  16035.           shell> mysqladmin -u root -pxxxx -h some-hostname ver
  16036.           Access denied for user: 'root@' (Using password: YES)
  16037.  
  16038.      This means that MySQL got some error when trying to resolve the IP
  16039.      to a hostname.  In this case you can execute `mysqladmin
  16040.      flush-hosts' to reset the internal DNS cache. *Note DNS::.
  16041.  
  16042.      Some permanent solutions are:
  16043.  
  16044.         - Try to find out what is wrong with your DNS server and fix
  16045.           this.
  16046.  
  16047.         - Specify IPs instead of hostnames in the MySQL privilege
  16048.           tables.
  16049.  
  16050.         - Start `mysqld' with `--skip-name-resolve'.
  16051.  
  16052.         - Start `mysqld' with `--skip-host-cache'.
  16053.  
  16054.         - Connect to `localhost' if you are running the server and the
  16055.           client on the same machine.
  16056.  
  16057.         - Put the client machine names in `/etc/hosts'.
  16058.  
  16059.    * If `mysql -u root test' works but `mysql -h your_hostname -u root
  16060.      test' results in `Access denied', then you may not have the
  16061.      correct name for your host in the `user' table.  A common problem
  16062.      here is that the `Host' value in the user table entry specifies an
  16063.      unqualified hostname, but your system's name resolution routines
  16064.      return a fully qualified domain name (or vice-versa).  For
  16065.      example, if you have an entry with host `'tcx'' in the `user'
  16066.      table, but your DNS tells MySQL that your hostname is
  16067.      `'tcx.subnet.se'', the entry will not work. Try adding an entry to
  16068.      the `user' table that contains the IP number of your host as the
  16069.      `Host' column value.  (Alternatively, you could add an entry to the
  16070.      `user' table with a `Host' value that contains a wildcard--for
  16071.      example, `'tcx.%''.  However, use of hostnames ending with `%' is
  16072.      *insecure* and is *not* recommended!)
  16073.  
  16074.    * If `mysql -u user_name test' works but `mysql -u user_name
  16075.      other_db_name' doesn't work, you don't have an entry for
  16076.      `other_db_name' listed in the `db' table.
  16077.  
  16078.    * If `mysql -u user_name db_name' works when executed on the server
  16079.      machine, but `mysql -h host_name -u user_name db_name' doesn't
  16080.      work when executed on another client machine, you don't have the
  16081.      client machine listed in the `user' table or the `db' table.
  16082.  
  16083.    * If you can't figure out why you get `Access denied', remove from
  16084.      the `user' table all entries that have `Host' values containing
  16085.      wildcards (entries that contain `%' or `_').  A very common error
  16086.      is to insert a new entry with `Host'=`'%'' and `User'=`'some
  16087.      user'', thinking that this will allow you to specify `localhost'
  16088.      to connect from the same machine.  The reason that this doesn't
  16089.      work is that the default privileges include an entry with
  16090.      `Host'=`'localhost'' and `User'=`'''.  Because that entry has a
  16091.      `Host' value `'localhost'' that is more specific than `'%'', it is
  16092.      used in preference to the new entry when connecting from
  16093.      `localhost'!  The correct procedure is to insert a second entry
  16094.      with `Host'=`'localhost'' and `User'=`'some_user'', or to remove
  16095.      the entry with `Host'=`'localhost'' and `User'=`'''.
  16096.  
  16097.    * If you get the following error, you may have a problem with the
  16098.      `db' or `host' table:
  16099.  
  16100.           Access to database denied
  16101.  
  16102.      If the entry selected from the `db' table has an empty value in the
  16103.      `Host' column, make sure there are one or more corresponding
  16104.      entries in the `host' table specifying which hosts the `db' table
  16105.      entry applies to.
  16106.  
  16107.      If you get the error when using the SQL commands `SELECT ...  INTO
  16108.      OUTFILE' or `LOAD DATA INFILE', your entry in the `user' table
  16109.      probably doesn't have the `FILE' privilege enabled.
  16110.  
  16111.    * Remember that client programs will use connection parameters
  16112.      specified in configuration files or environment variables.  *Note
  16113.      Environment variables::.  If a client seems to be sending the
  16114.      wrong default connection parameters when you don't specify them on
  16115.      the command-line, check your environment and the `.my.cnf' file in
  16116.      your home directory.  You might also check the system-wide MySQL
  16117.      configuration files, though it is far less likely that client
  16118.      connection parameters will be specified there. *Note Option
  16119.      files::.  If you get `Access denied' when you run a client without
  16120.      any options, make sure you haven't specified an old password in
  16121.      any of your option files!  *Note Option files::.
  16122.  
  16123.    * If you make changes to the grant tables directly (using an
  16124.      `INSERT' or `UPDATE' statement) and your changes seem to be
  16125.      ignored, remember that you must issue a `FLUSH PRIVILEGES'
  16126.      statement or execute a `mysqladmin flush-privileges' command to
  16127.      cause the server to re-read the privilege tables. Otherwise, your
  16128.      changes have no effect until the next time the server is
  16129.      restarted.  Remember that after you set the `root' password with
  16130.      an `UPDATE' command, you won't need to specify it until after you
  16131.      flush the privileges, because the server won't know you've changed
  16132.      the password yet!
  16133.  
  16134.    * If you have access problems with a Perl, PHP, Python, or ODBC
  16135.      program, try to connect to the server with `mysql -u user_name
  16136.      db_name' or `mysql -u user_name -pyour_pass db_name'.  If you are
  16137.      able to connect using the `mysql' client, there is a problem with
  16138.      your program and not with the access privileges.  (Note that there
  16139.      is no space between `-p' and the password; you can also use the
  16140.      `--password=your_pass' syntax to specify the password. If you use
  16141.      the `-p' option alone, MySQL will prompt you for the password.)
  16142.  
  16143.    * For testing, start the `mysqld' daemon with the
  16144.      `--skip-grant-tables' option.  Then you can change the MySQL grant
  16145.      tables and use the `mysqlaccess' script to check whether your
  16146.      modifications have the desired effect.  When you are satisfied
  16147.      with your changes, execute `mysqladmin flush-privileges' to tell
  16148.      the `mysqld' server to start using the new grant tables.  *Note*:
  16149.      reloading the grant tables overrides the `--skip-grant-tables'
  16150.      option.  This allows you to tell the server to begin using the
  16151.      grant tables again without bringing it down and restarting it.
  16152.  
  16153.    * If everything else fails, start the `mysqld' daemon with a
  16154.      debugging option (for example, `--debug=d,general,query'). This
  16155.      will print host and user information about attempted connections,
  16156.      as well as information about each command issued. *Note Making
  16157.      trace files::.
  16158.  
  16159.    * If you have any other problems with the MySQL grant tables and
  16160.      feel you must post the problem to the mailing list, always provide
  16161.      a dump of the MySQL grant tables. You can dump the tables with the
  16162.      `mysqldump mysql' command. As always, post your problem using the
  16163.      `mysqlbug' script.  *Note Bug reports::.  In some cases you may
  16164.      need to restart `mysqld' with `--skip-grant-tables' to run
  16165.      `mysqldump'.
  16166.  
  16167. MySQL User Account Management
  16168. =============================
  16169.  
  16170. `GRANT' and `REVOKE' Syntax
  16171. ---------------------------
  16172.  
  16173.      GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
  16174.          ON {tbl_name | * | *.* | db_name.*}
  16175.          TO user_name [IDENTIFIED BY [PASSWORD] 'password']
  16176.              [, user_name [IDENTIFIED BY [PASSWORD] 'password'] ...]
  16177.          [REQUIRE
  16178.              NONE |
  16179.              [{SSL| X509}]
  16180.              [CIPHER cipher [AND]]
  16181.              [ISSUER issuer [AND]]
  16182.              [SUBJECT subject]]
  16183.          [WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR # |
  16184.                                MAX_UPDATES_PER_HOUR # |
  16185.                                MAX_CONNECTIONS_PER_HOUR #]]
  16186.      
  16187.      REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
  16188.          ON {tbl_name | * | *.* | db_name.*}
  16189.          FROM user_name [, user_name ...]
  16190.  
  16191. `GRANT' is implemented in MySQL Version 3.22.11 or later. For earlier
  16192. MySQL versions, the `GRANT' statement does nothing.
  16193.  
  16194. The `GRANT' and `REVOKE' commands allow system administrators to create
  16195. users and grant and revoke rights to MySQL users at four privilege
  16196. levels:
  16197.  
  16198. *Global level*
  16199.      Global privileges apply to all databases on a given server. These
  16200.      privileges are stored in the `mysql.user' table.  `GRANT ALL ON
  16201.      *.*' and `REVOKE ALL ON *.*' will grant and revoke only global
  16202.      privileges.
  16203.  
  16204. *Database level*
  16205.      Database privileges apply to all tables in a given database. These
  16206.      privileges are stored in the `mysql.db' and `mysql.host' tables.
  16207.      `GRANT ALL ON db.*' and `REVOKE ALL ON db.*' will grant and revoke
  16208.      only database privileges.
  16209.  
  16210. *Table level*
  16211.      Table privileges apply to all columns in a given table. These
  16212.      privileges are stored in the `mysql.tables_priv' table.  `GRANT
  16213.      ALL ON db.table' and `REVOKE ALL ON db.table' will grant and
  16214.      revoke only table privileges.
  16215.  
  16216. *Column level*
  16217.      Column privileges apply to single columns in a given table. These
  16218.      privileges are stored in the `mysql.columns_priv' table.  When
  16219.      using `REVOKE' you must specify the same columns that were granted.
  16220.  
  16221. For the `GRANT' and `REVOKE' statements, `priv_type' may be specified
  16222. as any of the following:
  16223.  
  16224. `ALL [PRIVILEGES]'     Sets all simple privileges except `WITH GRANT
  16225.                        OPTION'
  16226. `ALTER'                Allows usage of `ALTER TABLE'
  16227. `CREATE'               Allows usage of `CREATE TABLE'
  16228. `CREATE TEMPORARY      Allows usage of `CREATE TEMPORARY TABLE'
  16229. TABLES'                
  16230. `DELETE'               Allows usage of `DELETE'
  16231. `DROP'                 Allows usage of `DROP TABLE'.
  16232. `EXECUTE'              Allows the user to run stored procedures (MySQL
  16233.                        5.0)
  16234. `FILE'                 Allows usage of `SELECT ... INTO OUTFILE' and
  16235.                        `LOAD DATA INFILE'.
  16236. `INDEX'                Allows usage of `CREATE INDEX' and `DROP INDEX'
  16237. `INSERT'               Allows usage of `INSERT'
  16238. `LOCK TABLES'          Allows usage of `LOCK TABLES' on tables for which
  16239.                        one has the `SELECT' privilege.
  16240. `PROCESS'              Allows usage of `SHOW FULL PROCESSLIST'
  16241. `REFERENCES'           For the future
  16242. `RELOAD'               Allows usage of `FLUSH'
  16243. `REPLICATION CLIENT'   Gives the right to the user to ask where the
  16244.                        slaves/masters are.
  16245. `REPLICATION SLAVE'    Needed for the replication slaves (to read
  16246.                        binlogs from master).
  16247. `SELECT'               Allows usage of `SELECT'
  16248. `SHOW DATABASES'       `SHOW DATABASES' shows all databases.
  16249. `SHUTDOWN'             Allows usage of `mysqladmin shutdown'
  16250. `SUPER'                Allows one connect (once) even if max_connections
  16251.                        is reached and execute commands `CHANGE MASTER',
  16252.                        `KILL thread', `mysqladmin debug', `PURGE MASTER
  16253.                        LOGS' and `SET GLOBAL'
  16254. `UPDATE'               Allows usage of `UPDATE'
  16255. `USAGE'                Synonym for "no privileges."
  16256. `GRANT OPTION'         Synonym for `WITH GRANT OPTION'
  16257.  
  16258. `USAGE' can be used when you want to create a user that has no
  16259. privileges.
  16260.  
  16261. The privileges `CREATE TEMPORARY TABLES', `EXECUTE', `LOCK TABLES',
  16262. `REPLICATION ...', `SHOW DATABASES' and `SUPER' are new for in version
  16263. 4.0.2.  To use these new privileges after upgrading to 4.0.2, you have
  16264. to run the `mysql_fix_privilege_tables' script.  *Note
  16265. Upgrading-grant-tables::.
  16266.  
  16267. In older MySQL versions, the `PROCESS' privilege gives the same rights
  16268. as the new `SUPER' privilege.
  16269.  
  16270. To revoke the `GRANT' privilege from a user, use a `priv_type' value of
  16271. `GRANT OPTION':
  16272.  
  16273.      mysql> REVOKE GRANT OPTION ON ... FROM ...;
  16274.  
  16275. The only `priv_type' values you can specify for a table are `SELECT',
  16276. `INSERT', `UPDATE', `DELETE', `CREATE', `DROP', `GRANT OPTION',
  16277. `INDEX', and `ALTER'.
  16278.  
  16279. The only `priv_type' values you can specify for a column (that is, when
  16280. you use a `column_list' clause) are `SELECT', `INSERT', and `UPDATE'.
  16281.  
  16282. MySQL allows you to create database level privileges even if the
  16283. database doesn't exist, to make it easy to prepare for database usage.
  16284. Currently MySQL does however not allow one to create table level grants
  16285. if the table doesn't exist. MySQL will not automatically revoke any
  16286. privileges even if you drop a table or drop a database.
  16287.  
  16288. You can set global privileges by using `ON *.*' syntax.  You can set
  16289. database privileges by using `ON db_name.*' syntax. If you specify `ON
  16290. *' and you have a current database, you will set the privileges for
  16291. that database.  (*Warning*: if you specify `ON *' and you *don't* have
  16292. a current database, you will affect the global privileges!)
  16293.  
  16294. *Please note*: the `_' and `%' wildcards are allowed when specifying
  16295. database names in `GRANT' commands. This means that if you wish to use
  16296. for instance a `_' character as part of a database name, you should
  16297. specify it as `\_' in the `GRANT' command, to prevent the user from
  16298. being able to access additional databases matching the wildcard
  16299. pattern, for example, `GRANT ... ON `foo\_bar`.* TO ...'.
  16300.  
  16301. In order to accommodate granting rights to users from arbitrary hosts,
  16302. MySQL supports specifying the `user_name' value in the form
  16303. `user@host'.  If you want to specify a `user' string containing special
  16304. characters (such as `-'), or a `host' string containing special
  16305. characters or wildcard characters (such as `%'), you can quote the user
  16306. or host name (for example, `'test-user'@'test-hostname'').
  16307.  
  16308. You can specify wildcards in the hostname.  For example,
  16309. `user@'%.loc.gov'' applies to `user' for any host in the `loc.gov'
  16310. domain, and `user@'144.155.166.%'' applies to `user' for any host in
  16311. the `144.155.166' class C subnet.
  16312.  
  16313. The simple form `user' is a synonym for `user@"%"'.
  16314.  
  16315. MySQL doesn't support wildcards in user names.  Anonymous users are
  16316. defined by inserting entries with `User=''' into the `mysql.user' table
  16317. or creating an user with an empty name with the `GRANT' command.
  16318.  
  16319. *Note*: if you allow anonymous users to connect to the MySQL server,
  16320. you should also grant privileges to all local users as `user@localhost'
  16321. because otherwise the anonymous user entry for the local host in the
  16322. `mysql.user' table will be used when the user tries to log into the
  16323. MySQL server from the local machine!
  16324.  
  16325. You can verify if this applies to you by executing this query:
  16326.  
  16327.      mysql> SELECT Host,User FROM mysql.user WHERE User='';
  16328.  
  16329. For the moment, `GRANT' only supports host, table, database, and column
  16330. names up to 60 characters long. A user name can be up to 16 characters.
  16331.  
  16332. The privileges for a table or column are formed from the logical OR of
  16333. the privileges at each of the four privilege levels.  For example, if
  16334. the `mysql.user' table specifies that a user has a global `SELECT'
  16335. privilege, this can't be denied by an entry at the database, table, or
  16336. column level.
  16337.  
  16338. The privileges for a column can be calculated as follows:
  16339.  
  16340.      global privileges
  16341.      OR (database privileges AND host privileges)
  16342.      OR table privileges
  16343.      OR column privileges
  16344.  
  16345. In most cases, you grant rights to a user at only one of the privilege
  16346. levels, so life isn't normally as complicated as above. The details of
  16347. the privilege-checking procedure are presented in *Note Privilege
  16348. system::.
  16349.  
  16350. If you grant privileges for a user/hostname combination that does not
  16351. exist in the `mysql.user' table, an entry is added and remains there
  16352. until deleted with a `DELETE' command.  In other words, `GRANT' may
  16353. create `user' table entries, but `REVOKE' will not remove them; you
  16354. must do that explicitly using `DELETE'.
  16355.  
  16356. In MySQL Version 3.22.12 or later, if a new user is created or if you
  16357. have global grant privileges, the user's password will be set to the
  16358. password specified by the `IDENTIFIED BY' clause, if one is given.  If
  16359. the user already had a password, it is replaced by the new one.
  16360.  
  16361. If you don't want to send the password in clear text you can use the
  16362. `PASSWORD' option followed by a scrambled password from SQL function
  16363. `PASSWORD()' or the C API function `make_scrambled_password(char *to,
  16364. const char *password)'.
  16365.  
  16366. *Warning*: if you create a new user but do not specify an `IDENTIFIED
  16367. BY' clause, the user has no password.  This is insecure.
  16368.  
  16369. Passwords can also be set with the `SET PASSWORD' command.  *Note
  16370. `SET': SET OPTION.
  16371.  
  16372. If you grant privileges for a database, an entry in the `mysql.db'
  16373. table is created if needed. When all privileges for the database have
  16374. been removed with `REVOKE', this entry is deleted.
  16375.  
  16376. If a user doesn't have any privileges on a table, the table is not
  16377. displayed when the user requests a list of tables (for example, with a
  16378. `SHOW TABLES' statement). The same is true for `SHOW DATABASES'.
  16379.  
  16380. The `WITH GRANT OPTION' clause gives the user the ability to give to
  16381. other users any privileges the user has at the specified privilege
  16382. level.  You should be careful to whom you give the `GRANT' privilege,
  16383. as two users with different privileges may be able to join privileges!
  16384.  
  16385. `MAX_QUERIES_PER_HOUR #', `MAX_UPDATES_PER_HOUR #' and
  16386. `MAX_CONNECTIONS_PER_HOUR #' are new in MySQL version 4.0.2.  These
  16387. options limit the number of queries/updates and logins the user can do
  16388. during one hour. If `#' is 0 (default), then this means that there are
  16389. no limitations for that user. *Note User resources::.  Note: to specify
  16390. any of these options for an existing user without adding other
  16391. additional privileges, use `GRANT USAGE ON *.* ... WITH MAX_...'.
  16392.  
  16393. You cannot grant another user a privilege you don't have yourself; the
  16394. `GRANT' privilege allows you to give away only those privileges you
  16395. possess.
  16396.  
  16397. Be aware that when you grant a user the `GRANT' privilege at a
  16398. particular privilege level, any privileges the user already possesses
  16399. (or is given in the future!) at that level are also grantable by that
  16400. user.  Suppose you grant a user the `INSERT' privilege on a database.
  16401. If you then grant the `SELECT' privilege on the database and specify
  16402. `WITH GRANT OPTION', the user can give away not only the `SELECT'
  16403. privilege, but also `INSERT'.  If you then grant the `UPDATE' privilege
  16404. to the user on the database, the user can give away the `INSERT',
  16405. `SELECT' and `UPDATE'.
  16406.  
  16407. You should not grant `ALTER' privileges to a normal user.  If you do
  16408. that, the user can try to subvert the privilege system by renaming
  16409. tables!
  16410.  
  16411. Note that if you are using table or column privileges for even one
  16412. user, the server examines table and column privileges for all users and
  16413. this will slow down MySQL a bit.
  16414.  
  16415. When `mysqld' starts, all privileges are read into memory.  Database,
  16416. table, and column privileges take effect at once, and user-level
  16417. privileges take effect the next time the user connects.  Modifications
  16418. to the grant tables that you perform using `GRANT' or `REVOKE' are
  16419. noticed by the server immediately.  If you modify the grant tables
  16420. manually (using `INSERT', `UPDATE', etc.), you should execute a `FLUSH
  16421. PRIVILEGES' statement or run `mysqladmin flush-privileges' to tell the
  16422. server to reload the grant tables.  *Note Privilege changes::.
  16423.  
  16424. The biggest differences between the SQL standard and MySQL versions of
  16425. `GRANT' are:
  16426.  
  16427.    * In MySQL privileges are given for an username + hostname
  16428.      combination and not only for an username.
  16429.  
  16430.    * SQL-99 doesn't have global or database-level privileges, nor does
  16431.      it support all the privilege types that MySQL supports.  MySQL
  16432.      doesn't support the SQL-99 `TRIGGER' or `UNDER' privileges.
  16433.  
  16434.    * SQL-99 privileges are structured in a hierarchal manner. If you
  16435.      remove an user, all privileges the user has granted are revoked. In
  16436.      MySQL the granted privileges are not automatically revoked, but
  16437.      you have to revoke these yourself if needed.
  16438.  
  16439.    * In MySQL, if you have the `INSERT' privilege on only some of the
  16440.      columns in a table, you can execute `INSERT' statements on the
  16441.      table; the columns for which you don't have the `INSERT' privilege
  16442.      will be set to their default values. SQL-99 requires you to have
  16443.      the `INSERT' privilege on all columns.
  16444.  
  16445.    * With SQL99, when you drop a table, all privileges for the table
  16446.      are revoked.  With SQL-99, when you revoke a privilege, all
  16447.      privileges that were granted based on the privilege are also
  16448.      revoked. In MySQL, privileges can be dropped only with explicit
  16449.      `REVOKE' commands or by manipulating the MySQL grant tables.
  16450.  
  16451. For a description of using `REQUIRE', see *Note Secure connections::.
  16452.  
  16453. MySQL User Names and Passwords
  16454. ------------------------------
  16455.  
  16456. There are several distinctions between the way user names and passwords
  16457. are used by MySQL and the way they are used by Unix or Windows:
  16458.  
  16459.    * User names, as used by MySQL for authentication purposes, have
  16460.      nothing to do with Unix user names (login names) or Windows user
  16461.      names.  Most MySQL clients by default try to log in using the
  16462.      current Unix user name as the MySQL user name, but that is for
  16463.      convenience only.  Client programs allow a different name to be
  16464.      specified with the `-u' or `--user' options. This means that you
  16465.      can't make a database secure in any way unless all MySQL user
  16466.      names have passwords.  Anyone may attempt to connect to the server
  16467.      using any name, and they will succeed if they specify any name
  16468.      that doesn't have a password.
  16469.  
  16470.    * MySQL user names can be up to 16 characters long; Unix user names
  16471.      typically are limited to 8 characters.
  16472.  
  16473.    * MySQL passwords have nothing to do with Unix passwords.  There is
  16474.      no necessary connection between the password you use to log in to
  16475.      a Unix machine and the password you use to access a database on
  16476.      that machine.
  16477.  
  16478.    * MySQL encrypts passwords using a different algorithm than the one
  16479.      used during the Unix login process.  See the descriptions of the
  16480.      `PASSWORD()' and `ENCRYPT()' functions in *Note Miscellaneous
  16481.      functions::.  Note that even if the password is stored
  16482.      'scrambled', and knowing your 'scrambled' password is enough to be
  16483.      able to connect to the MySQL server!  From version 4.1, MySQL
  16484.      employs a different password and login mechanism that is secure
  16485.      even if TCP/IP packets are sniffed and/or the mysql database is
  16486.      captured.
  16487.  
  16488. MySQL users and their privileges are normally created with the `GRANT'
  16489. command. *Note GRANT::.
  16490.  
  16491. When you login to a MySQL server with a command-line client you should
  16492. specify the password with `--password=your-password'.  *Note
  16493. Connecting::.
  16494.  
  16495.      mysql --user=monty --password=guess database_name
  16496.  
  16497. If you want the client to prompt for a password, you should use
  16498. `--password' without any argument
  16499.  
  16500.      mysql --user=monty --password database_name
  16501.  
  16502. or the short form:
  16503.  
  16504.      mysql -u monty -p database_name
  16505.  
  16506. Note that in the last example the password is *not* 'database_name'.
  16507.  
  16508. If you want to use the `-p' option to supply a password you should do so
  16509. like this:
  16510.  
  16511.      mysql -u monty -pguess database_name
  16512.  
  16513. On some systems, the library call that MySQL uses to prompt for a
  16514. password will automatically cut the password to 8 characters. Internally
  16515. MySQL doesn't have any limit for the length of the password.
  16516.  
  16517. When Privilege Changes Take Effect
  16518. ----------------------------------
  16519.  
  16520. When `mysqld' starts, all grant table contents are read into memory and
  16521. become effective at that point.
  16522.  
  16523. Modifications to the grant tables that you perform using `GRANT',
  16524. `REVOKE', or `SET PASSWORD' are noticed by the server immediately.
  16525.  
  16526. If you modify the grant tables manually (using `INSERT', `UPDATE',
  16527. etc.), you should execute a `FLUSH PRIVILEGES' statement or run
  16528. `mysqladmin flush-privileges' or `mysqladmin reload' to tell the server
  16529. to reload the grant tables. Otherwise, your changes will have _no
  16530. effect_ until you restart the server. If you change the grant tables
  16531. manually but forget to reload the privileges, you will be wondering why
  16532. your changes don't seem to make any difference!
  16533.  
  16534. When the server notices that the grant tables have been changed,
  16535. existing client connections are affected as follows:
  16536.  
  16537.    * Table and column privilege changes take effect with the client's
  16538.      next request.
  16539.  
  16540.    * Database privilege changes take effect at the next `USE db_name'
  16541.      command.
  16542.  
  16543.    * Global privilege changes and password changes take effect the next
  16544.      time the client connects.
  16545.  
  16546. Setting Up the Initial MySQL Privileges
  16547. ---------------------------------------
  16548.  
  16549. After installing MySQL, you set up the initial access privileges by
  16550. running `scripts/mysql_install_db'.  *Note Quick install::.  The
  16551. `mysql_install_db' script starts up the `mysqld' server, then
  16552. initialises the grant tables to contain the following set of privileges:
  16553.  
  16554.    * The MySQL `root' user is created as a superuser who can do
  16555.      anything.  Connections must be made from the local host.
  16556.  
  16557.      *Note*: The initial `root' password is empty, so anyone can
  16558.      connect as `root' _without a password_ and be granted all
  16559.      privileges.
  16560.  
  16561.    * An anonymous user is created that can do anything with databases
  16562.      that have a name of `'test'' or starting with `'test_''.
  16563.      Connections must be made from the local host.  This means any
  16564.      local user can connect without a password and be treated as the
  16565.      anonymous user.
  16566.  
  16567.    * Other privileges are denied.  For example, normal users can't use
  16568.      `mysqladmin shutdown' or `mysqladmin processlist'.
  16569.  
  16570. *Note*: the default privileges are different for Windows.  *Note
  16571. Windows running::.
  16572.  
  16573. Because your installation is initially wide open, one of the first
  16574. things you should do is specify a password for the MySQL `root' user.
  16575. You can do this as follows (note that you specify the password using
  16576. the `PASSWORD()' function):
  16577.  
  16578.      shell> mysql -u root mysql
  16579.      mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
  16580.  
  16581. Replace `'new_password'' with the password that you want to use.
  16582.  
  16583. If you know what you are doing, you can also directly manipulate the
  16584. privilege tables:
  16585.  
  16586.      shell> mysql -u root mysql
  16587.      mysql> UPDATE user SET Password=PASSWORD('new_password')
  16588.          ->     WHERE user='root';
  16589.      mysql> FLUSH PRIVILEGES;
  16590.  
  16591. Another way to set the password is by using the `mysqladmin' command:
  16592.  
  16593.      shell> mysqladmin -u root password new_password
  16594.  
  16595. Only users with write/update access to the `mysql' database can change
  16596. the password for other users.  All normal users (not anonymous ones)
  16597. can only change their own password with either of the above commands or
  16598. with `SET PASSWORD=PASSWORD('new_password')'.
  16599.  
  16600. Note that if you update the password in the `user' table directly using
  16601. `UPDATE', you must tell the server to re-read the grant tables (with
  16602. `FLUSH PRIVILEGES'), because the change will go unnoticed otherwise.
  16603.  
  16604. Once the `root' password has been set, thereafter you must supply that
  16605. password when you connect to the server as `root'.
  16606.  
  16607. You may wish to leave the `root' password blank so that you don't need
  16608. to specify it while you perform additional setup or testing. However,
  16609. be sure to set it before using your installation for any real
  16610. production work.
  16611.  
  16612. See the `scripts/mysql_install_db' script to see how it sets up the
  16613. default privileges.  You can use this as a basis to see how to add
  16614. other users.
  16615.  
  16616. If you want the initial privileges to be different from those just
  16617. described above, you can modify `mysql_install_db' before you run it.
  16618.  
  16619. To re-create the grant tables completely, remove all the `.frm',
  16620. `.MYI', and `.MYD' files in the directory containing the `mysql'
  16621. database.  (This is the directory named `mysql' under the database
  16622. directory, which is listed when you run `mysqld --help'.) Then run the
  16623. `mysql_install_db' script, possibly after editing it first to have the
  16624. privileges you want.
  16625.  
  16626. *Note*: for MySQL versions older than Version 3.22.10, you should not
  16627. delete the `.frm' files.  If you accidentally do this, you should copy
  16628. them back from your MySQL distribution before running
  16629. `mysql_install_db'.
  16630.  
  16631. Adding New Users to MySQL
  16632. -------------------------
  16633.  
  16634. You can add users two different ways: by using `GRANT' statements or by
  16635. manipulating the MySQL grant tables directly.  The preferred method is
  16636. to use `GRANT' statements, because they are more concise and less
  16637. error-prone. *Note GRANT::.
  16638.  
  16639. There are also several contributed programs (such as `phpMyAdmin') that
  16640. can be used to create and administrate users.
  16641.  
  16642. The following examples show how to use the `mysql' client to set up new
  16643. users.  These examples assume that privileges are set up according to
  16644. the defaults described in the previous section.  This means that to
  16645. make changes, you must be on the same machine where `mysqld' is
  16646. running, you must connect as the MySQL `root' user, and the `root' user
  16647. must have the `INSERT' privilege for the `mysql' database and the
  16648. `RELOAD' administrative privilege.  Also, if you have changed the
  16649. `root' user password, you must specify it for the `mysql' commands here.
  16650.  
  16651. First, use the `mysql' program to connect to the server as the MySQL
  16652. `root' user:
  16653.  
  16654.      shell> mysql --user=root mysql
  16655.  
  16656. Then you can add new users by issuing `GRANT' statements:
  16657.  
  16658.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
  16659.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  16660.      mysql> GRANT ALL PRIVILEGES ON *.* TO monty@'%'
  16661.          ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
  16662.      mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
  16663.      mysql> GRANT USAGE ON *.* TO dummy@localhost;
  16664.  
  16665. These `GRANT' statements set up three new users:
  16666.  
  16667. `monty'
  16668.      A full superuser who can connect to the server from anywhere, but
  16669.      who must use a password `'some_pass'' to do so.  Note that we must
  16670.      issue `GRANT' statements for both `monty@localhost' and
  16671.      `monty@"%"'.  If we don't add the entry with `localhost', the
  16672.      anonymous user entry for `localhost' that is created by
  16673.      `mysql_install_db' takes precedence when we connect from the local
  16674.      host, because it has a more specific `Host' field value and thus
  16675.      comes earlier in the `user' table sort order.
  16676.  
  16677. `admin'
  16678.      A user who can connect from `localhost' without a password and who
  16679.      is granted the `RELOAD' and `PROCESS' administrative privileges.
  16680.      This allows the user to execute the `mysqladmin reload',
  16681.      `mysqladmin refresh', and `mysqladmin flush-*' commands, as well as
  16682.      `mysqladmin processlist' .  No database-level privileges are
  16683.      granted.  (They can be granted later by issuing additional `GRANT'
  16684.      statements.)
  16685.  
  16686. `dummy'
  16687.      A user who can connect without a password, but only from the local
  16688.      host.  No privileges are granted--the `USAGE' privilege type
  16689.      allows you to create a user with no privileges. It has the effect
  16690.      of setting all the global privileges to `'N''.  It is assumed that
  16691.      you will grant specific privileges to the account later.
  16692.  
  16693. You can also add the same user access information directly by issuing
  16694. `INSERT' statements and then telling the server to reload the grant
  16695. tables:
  16696.  
  16697.      shell> mysql --user=root mysql
  16698.      mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
  16699.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  16700.      mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
  16701.          ->          'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  16702.      mysql> INSERT INTO user SET Host='localhost',User='admin',
  16703.          ->           Reload_priv='Y', Process_priv='Y';
  16704.      mysql> INSERT INTO user (Host,User,Password)
  16705.          ->                  VALUES('localhost','dummy','');
  16706.      mysql> FLUSH PRIVILEGES;
  16707.  
  16708. Depending on your MySQL version, you may have to use a different number
  16709. of `'Y'' values above. (Versions prior to Version 3.22.11 have fewer
  16710. privilege columns, and versions from 4.0.2 on have more.)  For the
  16711. `admin' user, the more readable extended `INSERT' syntax using `SET'
  16712. that is available starting with Version 3.22.11 is used.
  16713.  
  16714. Note that to set up a superuser, you need only create a `user' table
  16715. entry with the privilege fields set to `'Y''.  No `db' or `host' table
  16716. entries are necessary.
  16717.  
  16718. In the last `INSERT' statement (for the `dummy' user), only the `Host',
  16719. `User', and `Password' columns in the `user' table record are assigned
  16720. values. None of the privilege columns are set explicitly, so MySQL
  16721. assigns them all the default value of `'N''.  This is the same thing
  16722. that `GRANT USAGE' does.
  16723.  
  16724. The following example adds a user `custom' who can access the
  16725. `bankaccount' database only from the local host, the `expenses'
  16726. database only from the host `whitehouse.gov', and the `customer'
  16727. database only from the host `server.domain'.  He wants to use the
  16728. password `obscure' from all three hosts.
  16729.  
  16730. To set up this user's privileges using `GRANT' statements, run these
  16731. commands:
  16732.  
  16733.      shell> mysql --user=root mysql
  16734.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  16735.          ->     ON bankaccount.*
  16736.          ->     TO custom@localhost
  16737.          ->     IDENTIFIED BY 'obscure';
  16738.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  16739.          ->     ON expenses.*
  16740.          ->     TO custom@'whitehouse.gov'
  16741.          ->     IDENTIFIED BY 'obscure';
  16742.      mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
  16743.          ->     ON customer.*
  16744.          ->     TO custom@'server.domain'
  16745.          ->     IDENTIFIED BY 'obscure';
  16746.  
  16747. To set up the user's privileges by modifying the grant tables directly,
  16748. run these commands (note the `FLUSH PRIVILEGES' at the end):
  16749.  
  16750.      shell> mysql --user=root mysql
  16751.      mysql> INSERT INTO user (Host,User,Password)
  16752.          -> VALUES('localhost','custom',PASSWORD('obscure'));
  16753.      mysql> INSERT INTO user (Host,User,Password)
  16754.          -> VALUES('whitehouse.gov','custom',PASSWORD('obscure'));
  16755.      mysql> INSERT INTO user (Host,User,Password)
  16756.          -> VALUES('server.domain','custom',PASSWORD('obscure'));
  16757.      mysql> INSERT INTO db
  16758.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  16759.          ->  Create_priv,Drop_priv)
  16760.          -> VALUES
  16761.          -> ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
  16762.      mysql> INSERT INTO db
  16763.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  16764.          ->  Create_priv,Drop_priv)
  16765.          -> VALUES
  16766.          -> ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
  16767.      mysql> INSERT INTO db
  16768.          -> (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
  16769.          ->  Create_priv,Drop_priv)
  16770.          -> VALUES('server.domain','customer','custom','Y','Y','Y','Y','Y','Y');
  16771.      mysql> FLUSH PRIVILEGES;
  16772.  
  16773. As in the preceding example that used `INSERT' statements, you may need
  16774. to use a different number of `'Y'' values, depending on your version of
  16775. MySQL.
  16776.  
  16777. The first three `INSERT' statements add `user' table entries that allow
  16778. user `custom' to connect from the various hosts with the given
  16779. password, but grant no permissions to him (all privileges are set to the
  16780. default value of `'N'').  The next three `INSERT' statements add `db'
  16781. table entries that grant privileges to `custom' for the `bankaccount',
  16782. `expenses', and `customer' databases, but only when accessed from the
  16783. proper hosts.  As usual, after you modify the grant tables directly ,
  16784. you must tell the server to reload them (with `FLUSH PRIVILEGES') so
  16785. that the privilege changes take effect.
  16786.  
  16787. If you want to give a specific user access from any machine in a given
  16788. domain (for example, `mydomain.com'), you can issue a `GRANT' statement
  16789. like the following:
  16790.  
  16791.      mysql> GRANT ...
  16792.          ->     ON *.*
  16793.          ->     TO myusername@'%.mydomain.com'
  16794.          ->     IDENTIFIED BY 'mypassword';
  16795.  
  16796. To do the same thing by modifying the grant tables directly, do this:
  16797.  
  16798.      mysql> INSERT INTO user VALUES ('%.mydomain.com', 'myusername',
  16799.          ->             PASSWORD('mypassword'),...);
  16800.      mysql> FLUSH PRIVILEGES;
  16801.  
  16802. Deleting Users from MySQL
  16803. -------------------------
  16804.  
  16805.      DROP USER user_name
  16806.  
  16807. This command was added to MySQL 4.1.1.
  16808.  
  16809. It deletes a user that doesn't have any privileges.
  16810.  
  16811. To delete a user from MySQL you should do things in the following order:
  16812.  
  16813.   1. Check which privileges the user has with `SHOW PRIVILEGES'.  *Note
  16814.      SHOW PRIVILEGES::.
  16815.  
  16816.   2. Delete all privileges from the user with `REVOKE'. *Note GRANT::.
  16817.  
  16818.   3. Delete the user with `DROP USER'.
  16819.  
  16820. If you are using and older MySQL version you should first revoke the
  16821. privileges and then delete the user with:
  16822.  
  16823.      DELETE FROM mysql.user WHERE user='username' and host='hostname';
  16824.      FLUSH PRIVILEGES;
  16825.  
  16826. Limiting user resources
  16827. -----------------------
  16828.  
  16829. Starting from MySQL 4.0.2 one can limit certain resources per user.
  16830.  
  16831. So far, the only available method of limiting usage of MySQL server
  16832. resources has been setting the `max_user_connections' startup variable
  16833. to a non-zero value. But this method is strictly global and does not
  16834. allow for management of individual users, which could be of particular
  16835. interest to Internet Service Providers.
  16836.  
  16837. Therefore, management of three resources is introduced on the
  16838. individual user level:
  16839.  
  16840.    * Number of all queries per hour: All commands that could be run by
  16841.      a user.
  16842.  
  16843.    * Number of all updates per hour: Any command that changes any table
  16844.      or database.
  16845.  
  16846.    * Number of connections made per hour: New connections opened per
  16847.      hour.
  16848.  
  16849. A user in the aforementioned context is a single entry in the `user'
  16850. table, which is uniquely identified by its `user' and `host' columns.
  16851.  
  16852. All users are by default not limited in using the above resources,
  16853. unless the limits are granted to them. These limits can be granted
  16854. *only* via global `GRANT (*.*)', using this syntax:
  16855.  
  16856.      GRANT ... WITH MAX_QUERIES_PER_HOUR N1
  16857.                     MAX_UPDATES_PER_HOUR N2
  16858.                     MAX_CONNECTIONS_PER_HOUR N3;
  16859.  
  16860. One can specify any combination of the above resources.  `N1', `N2',
  16861. and `N3' are integers and represent counts per hour.
  16862.  
  16863. If a user reaches the limit on number of connections within one hour, no
  16864. further connections will be accepted until that hour is up. Similarly,
  16865. if the user reaches the limit on number of queries or updates, further
  16866. queries or updates will be rejected until the hour is up. In all cases,
  16867. an appropriate error message shall be issued.
  16868.  
  16869. Current usage values for a particular user can be flushed (set to zero)
  16870. by issuing a `GRANT' statement with any of the above clauses, including
  16871. a `GRANT' statement with the current values.
  16872.  
  16873. Also, current values for all users will be flushed if privileges are
  16874. reloaded (in the server or using `mysqladmin reload') or if the `FLUSH
  16875. USER_RESOURCES' command is issued.
  16876.  
  16877. The feature is enabled as soon as a single user is granted with any of
  16878. the limiting `GRANT' clauses.
  16879.  
  16880. As a prerequisite for enabling this feature, the `user' table in the
  16881. `mysql' database must contain the additional columns, as defined in the
  16882. table creation scripts `mysql_install_db' and `mysql_install_db.sh' in
  16883. `scripts' subdirectory.
  16884.  
  16885. Setting Up Passwords
  16886. --------------------
  16887.  
  16888. In most cases you should use `GRANT' to set up your users/passwords, so
  16889. the following only applies for advanced users. *Note `GRANT': GRANT.
  16890.  
  16891. The examples in the preceding sections illustrate an important
  16892. principle: when you store a non-empty password using `INSERT' or
  16893. `UPDATE' statements, you must use the `PASSWORD()' function to encrypt
  16894. it.  This is because the `user' table stores passwords in encrypted
  16895. form, not as plaintext.  If you forget that fact, you are likely to
  16896. attempt to set passwords like this:
  16897.  
  16898.      shell> mysql -u root mysql
  16899.      mysql> INSERT INTO user (Host,User,Password)
  16900.          -> VALUES('%','jeffrey','biscuit');
  16901.      mysql> FLUSH PRIVILEGES;
  16902.  
  16903. The result is that the plaintext value `'biscuit'' is stored as the
  16904. password in the `user' table.  When the user `jeffrey' attempts to
  16905. connect to the server using this password, the `mysql' client encrypts
  16906. it with `PASSWORD()', generates an authentification vector based on
  16907. *encrypted* password and a random number, obtained from server, and
  16908. sends the result to the server.  The server uses the `password' value
  16909. in the `user' table (that is *not encrypted* value `'biscuit'') to
  16910. perform the same calculations, and compares results.  The comparison
  16911. fails and the server rejects the connection:
  16912.  
  16913.      shell> mysql -u jeffrey -pbiscuit test
  16914.      Access denied
  16915.  
  16916. Passwords must be encrypted when they are inserted in the `user' table,
  16917. so the `INSERT' statement should have been specified like this instead:
  16918.  
  16919.      mysql> INSERT INTO user (Host,User,Password)
  16920.          -> VALUES('%','jeffrey',PASSWORD('biscuit'));
  16921.  
  16922. You must also use the `PASSWORD()' function when you use `SET PASSWORD'
  16923. statements:
  16924.  
  16925.      mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
  16926.  
  16927. If you set passwords using the `GRANT ... IDENTIFIED BY' statement or
  16928. the `mysqladmin password' command, the `PASSWORD()' function is
  16929. unnecessary.  They both take care of encrypting the password for you,
  16930. so you would specify a password of `'biscuit'' like this:
  16931.  
  16932.      mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
  16933.  
  16934. or
  16935.  
  16936.      shell> mysqladmin -u jeffrey password biscuit
  16937.  
  16938. *Note*: `PASSWORD()' is different from Unix password encryption.  *Note
  16939. User names::.
  16940.  
  16941. Keeping Your Password Secure
  16942. ----------------------------
  16943.  
  16944. It is inadvisable to specify your password in a way that exposes it to
  16945. discovery by other users.  The methods you can use to specify your
  16946. password when you run client programs are listed here, along with an
  16947. assessment of the risks of each method:
  16948.  
  16949.    * Never give a normal user access to the `mysql.user' table. Knowing
  16950.      the encrypted password for a user makes it possible to login as
  16951.      this user.  The passwords are only scrambled so that one shouldn't
  16952.      be able to see the real password you used (if you happen to use a
  16953.      similar password with your other applications).
  16954.  
  16955.    * Use a `-pyour_pass' or `--password=your_pass' option on the command
  16956.      line.  This is convenient but insecure, because your password
  16957.      becomes visible to system status programs (such as `ps') that may
  16958.      be invoked by other users to display command-lines.  (MySQL
  16959.      clients typically overwrite the command-line argument with zeroes
  16960.      during their initialisation sequence, but there is still a brief
  16961.      interval during which the value is visible.)
  16962.  
  16963.    * Use a `-p' or `--password' option (with no `your_pass' value
  16964.      specified).  In this case, the client program solicits the
  16965.      password from the terminal:
  16966.  
  16967.           shell> mysql -u user_name -p
  16968.           Enter password: ********
  16969.  
  16970.      The `*' characters represent your password.
  16971.  
  16972.      It is more secure to enter your password this way than to specify
  16973.      it on the command-line because it is not visible to other users.
  16974.      However, this method of entering a password is suitable only for
  16975.      programs that you run interactively.  If you want to invoke a
  16976.      client from a script that runs non-interactively, there is no
  16977.      opportunity to enter the password from the terminal. On some
  16978.      systems, you may even find that the first line of your script is
  16979.      read and interpreted (incorrectly) as your password!
  16980.  
  16981.    * Store your password in a configuration file.  For example, you can
  16982.      list your password in the `[client]' section of the `.my.cnf' file
  16983.      in your home directory:
  16984.  
  16985.           [client]
  16986.           password=your_pass
  16987.  
  16988.      If you store your password in `.my.cnf', the file should not be
  16989.      group or world readable or writable.  Make sure the file's access
  16990.      mode is `400' or `600'.
  16991.  
  16992.      *Note Option files::.
  16993.  
  16994.    * You can store your password in the `MYSQL_PWD' environment
  16995.      variable, but this method must be considered extremely insecure
  16996.      and should not be used.  Some versions of `ps' include an option
  16997.      to display the environment of running processes; your password
  16998.      will be in plain sight for all to see if you set `MYSQL_PWD'.
  16999.      Even on systems without such a version of `ps', it is unwise to
  17000.      assume there is no other method to observe process environments.
  17001.      *Note Environment variables::.
  17002.  
  17003. All in all, the safest methods are to have the client program prompt
  17004. for the password or to specify the password in a properly protected
  17005. `.my.cnf' file.
  17006.  
  17007. Using Secure Connections
  17008. ------------------------
  17009.  
  17010. Basics
  17011. ......
  17012.  
  17013. Beginning with version 4.0.0, MySQL has support for SSL encrypted
  17014. connections. To understand how MySQL uses SSL, it's necessary to
  17015. explain some basic SSL and X509 concepts. People who are already
  17016. familiar with them can skip this part.
  17017.  
  17018. By default, MySQL uses unencrypted connections between the client and
  17019. the server. This means that someone could watch all your traffic and
  17020. look at the data being sent or received.  They could even change the
  17021. data while it is in transit between client and server. Sometimes you
  17022. need to move information over public networks in a secure fashion; in
  17023. such cases, using an unencrypted connection is unacceptable.
  17024.  
  17025. SSL is a protocol that uses different encryption algorithms to ensure
  17026. that data received over a public network can be trusted. It has
  17027. mechanisms to detect any change, loss or replay of data. SSL also
  17028. incorporates algorithms to recognise and provide identity verification
  17029. using the X509 standard.
  17030.  
  17031. Encryption is the way to make any kind of data unreadable. In fact,
  17032. today's practice requires many additional security elements from
  17033. encryption algorithms.  They should resist many kind of known attacks
  17034. like just messing with the order of encrypted messages or replaying data
  17035. twice.
  17036.  
  17037. X509 is a standard that makes it possible to identify someone on the
  17038. Internet.  It is most commonly used in e-commerce applications. In basic
  17039. terms, there should be some company (called a "Certificate Authority")
  17040. that assigns electronic certificates to anyone who needs them.
  17041. Certificates rely on asymmetric encryption algorithms that have two
  17042. encryption keys (a public key and a secret key). A certificate owner
  17043. can prove his identity by showing his certificate to other party. A
  17044. certificate consists of its owner's public key. Any data encrypted with
  17045. this public key can be decrypted only using the corresponding secret
  17046. key, which is held by the owner of the certificate.
  17047.  
  17048. MySQL doesn't use encrypted connections by default, because doing so
  17049. would make the client/server protocol much slower. Any kind of
  17050. additional functionality requires the computer to do additional work and
  17051. encrypting data is a CPU-intensive operation that requires time and can
  17052. delay MySQL main tasks. By default MySQL is tuned to be fast as
  17053. possible.
  17054.  
  17055. If you need more information about SSL, X509, or encryption, you should
  17056. use your favourite Internet search engine and search for keywords in
  17057. which you are interested.
  17058.  
  17059. Requirements
  17060. ............
  17061.  
  17062. To get secure connections to work with MySQL you must do the following:
  17063.  
  17064.   1. Install the OpenSSL library. We have tested MySQL with OpenSSL
  17065.      0.9.6.  `http://www.openssl.org/'.
  17066.  
  17067.   2. Configure MySQL with `--with-vio --with-openssl'.
  17068.  
  17069.   3. If you are using an old MySQL installation, you have to update your
  17070.      `mysql.user' table with some new SSL-related columns.  This is
  17071.      necessary if your grant tables date from a version prior to MySQL
  17072.      4.0.0.  The procedure is described in *Note
  17073.      Upgrading-grant-tables::.
  17074.  
  17075.   4. You can check if a running `mysqld' server supports OpenSSL by
  17076.      examining if `SHOW VARIABLES LIKE 'have_openssl'' returns `YES'.
  17077.  
  17078. Setting Up SSL Certificates for MySQL
  17079. .....................................
  17080.  
  17081. Here is an example for setting up SSL certificates for MySQL:
  17082.  
  17083.      DIR=`pwd`/openssl
  17084.      PRIV=$DIR/private
  17085.      
  17086.      mkdir $DIR $PRIV $DIR/newcerts
  17087.      cp /usr/share/ssl/openssl.cnf $DIR
  17088.      replace ./demoCA $DIR -- $DIR/openssl.cnf
  17089.      
  17090.      # Create necessary files: $database, $serial and $new_certs_dir
  17091.      # directory (optional)
  17092.      
  17093.      touch $DIR/index.txt
  17094.      echo "01" > $DIR/serial
  17095.      
  17096.      #
  17097.      # Generation of Certificate Authority(CA)
  17098.      #
  17099.      
  17100.      openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem \
  17101.          -config $DIR/openssl.cnf
  17102.      
  17103.      # Sample output:
  17104.      # Using configuration from /home/monty/openssl/openssl.cnf
  17105.      # Generating a 1024 bit RSA private key
  17106.      # ................++++++
  17107.      # .........++++++
  17108.      # writing new private key to '/home/monty/openssl/private/cakey.pem'
  17109.      # Enter PEM pass phrase:
  17110.      # Verifying password - Enter PEM pass phrase:
  17111.      # -----
  17112.      # You are about to be asked to enter information that will be incorporated
  17113.      # into your certificate request.
  17114.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17115.      # There are quite a few fields but you can leave some blank
  17116.      # For some fields there will be a default value,
  17117.      # If you enter '.', the field will be left blank.
  17118.      # -----
  17119.      # Country Name (2 letter code) [AU]:FI
  17120.      # State or Province Name (full name) [Some-State]:.
  17121.      # Locality Name (eg, city) []:
  17122.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17123.      # Organizational Unit Name (eg, section) []:
  17124.      # Common Name (eg, YOUR name) []:MySQL admin
  17125.      # Email Address []:
  17126.      
  17127.      #
  17128.      # Create server request and key
  17129.      #
  17130.      openssl req -new -keyout $DIR/server-key.pem -out \
  17131.          $DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
  17132.      
  17133.      # Sample output:
  17134.      # Using configuration from /home/monty/openssl/openssl.cnf
  17135.      # Generating a 1024 bit RSA private key
  17136.      # ..++++++
  17137.      # ..........++++++
  17138.      # writing new private key to '/home/monty/openssl/server-key.pem'
  17139.      # Enter PEM pass phrase:
  17140.      # Verifying password - Enter PEM pass phrase:
  17141.      # -----
  17142.      # You are about to be asked to enter information that will be incorporated
  17143.      # into your certificate request.
  17144.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17145.      # There are quite a few fields but you can leave some blank
  17146.      # For some fields there will be a default value,
  17147.      # If you enter '.', the field will be left blank.
  17148.      # -----
  17149.      # Country Name (2 letter code) [AU]:FI
  17150.      # State or Province Name (full name) [Some-State]:.
  17151.      # Locality Name (eg, city) []:
  17152.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17153.      # Organizational Unit Name (eg, section) []:
  17154.      # Common Name (eg, YOUR name) []:MySQL server
  17155.      # Email Address []:
  17156.      #
  17157.      # Please enter the following 'extra' attributes
  17158.      # to be sent with your certificate request
  17159.      # A challenge password []:
  17160.      # An optional company name []:
  17161.      
  17162.      #
  17163.      # Remove the passphrase from the key (optional)
  17164.      #
  17165.      
  17166.      openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
  17167.      
  17168.      #
  17169.      # Sign server cert
  17170.      #
  17171.      openssl ca  -policy policy_anything -out $DIR/server-cert.pem \
  17172.          -config $DIR/openssl.cnf -infiles $DIR/server-req.pem
  17173.      
  17174.      # Sample output:
  17175.      # Using configuration from /home/monty/openssl/openssl.cnf
  17176.      # Enter PEM pass phrase:
  17177.      # Check that the request matches the signature
  17178.      # Signature ok
  17179.      # The Subjects Distinguished Name is as follows
  17180.      # countryName           :PRINTABLE:'FI'
  17181.      # organizationName      :PRINTABLE:'MySQL AB'
  17182.      # commonName            :PRINTABLE:'MySQL admin'
  17183.      # Certificate is to be certified until Sep 13 14:22:46 2003 GMT (365 days)
  17184.      # Sign the certificate? [y/n]:y
  17185.      #
  17186.      #
  17187.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  17188.      # Write out database with 1 new entries
  17189.      # Data Base Updated
  17190.      
  17191.      #
  17192.      # Create client request and key
  17193.      #
  17194.      openssl req -new -keyout $DIR/client-key.pem -out \
  17195.          $DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
  17196.      
  17197.      # Sample output:
  17198.      # Using configuration from /home/monty/openssl/openssl.cnf
  17199.      # Generating a 1024 bit RSA private key
  17200.      # .....................................++++++
  17201.      # .............................................++++++
  17202.      # writing new private key to '/home/monty/openssl/client-key.pem'
  17203.      # Enter PEM pass phrase:
  17204.      # Verifying password - Enter PEM pass phrase:
  17205.      # -----
  17206.      # You are about to be asked to enter information that will be incorporated
  17207.      # into your certificate request.
  17208.      # What you are about to enter is what is called a Distinguished Name or a DN.
  17209.      # There are quite a few fields but you can leave some blank
  17210.      # For some fields there will be a default value,
  17211.      # If you enter '.', the field will be left blank.
  17212.      # -----
  17213.      # Country Name (2 letter code) [AU]:FI
  17214.      # State or Province Name (full name) [Some-State]:.
  17215.      # Locality Name (eg, city) []:
  17216.      # Organization Name (eg, company) [Internet Widgits Pty Ltd]:MySQL AB
  17217.      # Organizational Unit Name (eg, section) []:
  17218.      # Common Name (eg, YOUR name) []:MySQL user
  17219.      # Email Address []:
  17220.      #
  17221.      # Please enter the following 'extra' attributes
  17222.      # to be sent with your certificate request
  17223.      # A challenge password []:
  17224.      # An optional company name []:
  17225.      
  17226.      #
  17227.      # Remove a passphrase from the key (optional)
  17228.      #
  17229.      openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
  17230.      
  17231.      #
  17232.      # Sign client cert
  17233.      #
  17234.      
  17235.      openssl ca  -policy policy_anything -out $DIR/client-cert.pem \
  17236.          -config $DIR/openssl.cnf -infiles $DIR/client-req.pem
  17237.      
  17238.      # Sample output:
  17239.      # Using configuration from /home/monty/openssl/openssl.cnf
  17240.      # Enter PEM pass phrase:
  17241.      # Check that the request matches the signature
  17242.      # Signature ok
  17243.      # The Subjects Distinguished Name is as follows
  17244.      # countryName           :PRINTABLE:'FI'
  17245.      # organizationName      :PRINTABLE:'MySQL AB'
  17246.      # commonName            :PRINTABLE:'MySQL user'
  17247.      # Certificate is to be certified until Sep 13 16:45:17 2003 GMT (365 days)
  17248.      # Sign the certificate? [y/n]:y
  17249.      #
  17250.      #
  17251.      # 1 out of 1 certificate requests certified, commit? [y/n]y
  17252.      # Write out database with 1 new entries
  17253.      # Data Base Updated
  17254.      
  17255.      #
  17256.      # Create a my.cnf file that you can use to test the certificates
  17257.      #
  17258.      
  17259.      cnf=""
  17260.      cnf="$cnf [client]"
  17261.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  17262.      cnf="$cnf ssl-cert=$DIR/client-cert.pem"
  17263.      cnf="$cnf ssl-key=$DIR/client-key.pem"
  17264.      cnf="$cnf [mysqld]"
  17265.      cnf="$cnf ssl-ca=$DIR/cacert.pem"
  17266.      cnf="$cnf ssl-cert=$DIR/server-cert.pem"
  17267.      cnf="$cnf ssl-key=$DIR/server-key.pem"
  17268.      echo $cnf | replace " " '
  17269.      ' > $DIR/my.cnf
  17270.      
  17271.      #
  17272.      # To test MySQL
  17273.      
  17274.      mysqld --defaults-file=$DIR/my.cnf &
  17275.      
  17276.      mysql --defaults-file=$DIR/my.cnf
  17277.  
  17278. You can also test your setup by modifying the above `my.cnf' file to
  17279. refer to the demo certificates in the mysql-source-dist/SSL direcory.
  17280.  
  17281. SSL `GRANT' Options
  17282. ...................
  17283.  
  17284. MySQL can check X509 certificate attributes in addition to the normal
  17285. username/password scheme. All the usual options are still required
  17286. (username, password, IP address mask, database/table name).
  17287.  
  17288. There are different possibilities to limit connections:
  17289.  
  17290.    * Without any SSL or X509 options, all kind of encrypted/unencrypted
  17291.      connections are allowed if the username and password are valid.
  17292.  
  17293.    * `REQUIRE SSL' option limits the server to allow only SSL encrypted
  17294.      connections. Note that this option can be omitted if there are any
  17295.      ACL records which allow non-SSL connections.
  17296.  
  17297.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17298.               -> IDENTIFIED BY "goodsecret" REQUIRE SSL;
  17299.  
  17300.    * `REQUIRE X509' means that the client should have a valid
  17301.      certificate but we do not care about the exact certificate, issuer
  17302.      or subject.  The only restriction is that it should be possible to
  17303.      verify its signature with one of the CA certificates.
  17304.  
  17305.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17306.               -> IDENTIFIED BY "goodsecret" REQUIRE X509;
  17307.  
  17308.    * `REQUIRE ISSUER "issuer"' places a restriction on connection
  17309.      attempts: The client must present a valid X509 certificate issued
  17310.      by CA `"issuer"'.  Using X509 certificates always implies
  17311.      encryption, so the `SSL' option is unneccessary.
  17312.  
  17313.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17314.               -> IDENTIFIED BY "goodsecret"
  17315.               -> REQUIRE ISSUER "C=FI, ST=Some-State, L=Helsinki,
  17316.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com";
  17317.  
  17318.    * `REQUIRE SUBJECT "subject"' requires clients to have valid X509
  17319.      certificate with subject `"subject"' on it. If the client presents
  17320.      a certificate that is valid but has a different `"subject"', the
  17321.      connection is disallowed.
  17322.  
  17323.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17324.               -> IDENTIFIED BY "goodsecret"
  17325.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  17326.               "> O=MySQL demo client certificate,
  17327.               "> CN=Tonu Samuel/Email=tonu@mysql.com";
  17328.  
  17329.    * `REQUIRE CIPHER "cipher"' is needed to assure enough strong ciphers
  17330.      and keylengths will be used. SSL itself can be weak if old
  17331.      algorithms with short encryption keys are used. Using this option,
  17332.      we can ask for some exact cipher method to allow a connection.
  17333.  
  17334.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17335.               -> IDENTIFIED BY "goodsecret"
  17336.               -> REQUIRE CIPHER "EDH-RSA-DES-CBC3-SHA";
  17337.  
  17338.      The `SUBJECT', `ISSUER', and `CIPHER' options can be combined in
  17339.      the `REQUIRE' clause like this:
  17340.  
  17341.           mysql> GRANT ALL PRIVILEGES ON test.* TO root@localhost
  17342.               -> IDENTIFIED BY "goodsecret"
  17343.               -> REQUIRE SUBJECT "C=EE, ST=Some-State, L=Tallinn,
  17344.               "> O=MySQL demo client certificate,
  17345.               "> CN=Tonu Samuel/Email=tonu@mysql.com"
  17346.               -> AND ISSUER "C=FI, ST=Some-State, L=Helsinki,
  17347.               "> O=MySQL Finland AB, CN=Tonu Samuel/Email=tonu@mysql.com"
  17348.               -> AND CIPHER "EDH-RSA-DES-CBC3-SHA";
  17349.  
  17350.      Starting from MySQL 4.0.4 the `AND' keyword is optional between
  17351.      `REQUIRE' options.
  17352.  
  17353.      The order of the options does not matter, but no option can be
  17354.      specified twice.
  17355.  
  17356. SSL Command-line Options
  17357. ........................
  17358.  
  17359. The following table lists options that are used for specifying the use
  17360. of SSL, certificate files, and key files.  These options are available
  17361. beginning with MySQL 4.0. They may be given on the command line or in
  17362. option files.
  17363.  
  17364. `--ssl'
  17365.      For the server, specifies that the server allows SSL connections.
  17366.      For a client program, allows the client to connect to the server
  17367.      using SSL.  This option itself is not sufficient to cause an SSL
  17368.      connection to be used.  You must also specify the `--ssl-ca',
  17369.      `--ssl-cert', and `--ssl-key' options.
  17370.  
  17371.      Note that this option doesn't *require* an SSL connection.  For
  17372.      example, if the server or client are compiled without SSL support,
  17373.      a normal unencrypted connection will be used.
  17374.  
  17375.      The secure way to ensure that a SSL connection will be used is to
  17376.      create an account on the server that includes a `REQUIRE SSL'
  17377.      clause in the `GRANT' statement.  Then use this account to connect
  17378.      to the server, with both a server and client that have SSL support
  17379.      enabled.
  17380.  
  17381.      You can use this option to indicate that the connection should not
  17382.      use SSL.  Do this by specifying the option as `--skip-ssl' or
  17383.      `--ssl=0'.
  17384.  
  17385. `--ssl-ca=file_name'
  17386.      The path to a file with a list of trusted SSL CAs.
  17387.  
  17388. `--ssl-capath=directory_name'
  17389.      The path to a directory which contains trusted SSL CA certificates
  17390.      in pem format.
  17391.  
  17392. `--ssl-cert=file_name'
  17393.      The name of the SSL certificate file to use used for establishing
  17394.      a secure connection.
  17395.  
  17396. `--ssl-cipher=cipher_list'
  17397.      A list of allowable ciphers to use for SSL encryption.
  17398.      `cipher_list' has the same format as the `openssl ciphers' command.
  17399.  
  17400.      Example: `--ssl-cipher=ALL:-AES:-EXP'
  17401.  
  17402. `--ssl-key=file_name'
  17403.      The name of the SSL key file to use used for establishing a secure
  17404.      connection.
  17405.  
  17406. Disaster Prevention and Recovery
  17407. ================================
  17408.  
  17409. Database Backups
  17410. ----------------
  17411.  
  17412. Because MySQL tables are stored as files, it is easy to do a backup. To
  17413. get a consistent backup, do a `LOCK TABLES' on the relevant tables
  17414. followed by `FLUSH TABLES' for the tables.  *Note `LOCK TABLES': LOCK
  17415. TABLES.  *Note `FLUSH': FLUSH.  You only need a read lock; this allows
  17416. other threads to continue to query the tables while you are making a
  17417. copy of the files in the database directory.  The `FLUSH TABLE' is
  17418. needed to ensure that the all active index pages is written to disk
  17419. before you start the backup.
  17420.  
  17421. Starting from 3.23.56 and 4.0.12 `BACKUP TABLE' will not allow you to
  17422. overwrite existing files as this would be a security risk.
  17423.  
  17424. If you want to make an SQL level backup of a table, you can use `SELECT
  17425. INTO OUTFILE' or `BACKUP TABLE'. *Note SELECT::.  *Note BACKUP TABLE::.
  17426.  
  17427. Another way to back up a database is to use the `mysqldump' program or
  17428. the `mysqlhotcopy script'. *Note `mysqldump': mysqldump.  *Note
  17429. `mysqlhotcopy': mysqlhotcopy.
  17430.  
  17431.   1. Do a full backup of your database:
  17432.  
  17433.           shell> mysqldump --tab=/path/to/some/dir --opt db_name
  17434.           
  17435.           or
  17436.           
  17437.           shell> mysqlhotcopy db_name /path/to/some/dir
  17438.  
  17439.      You can also simply copy all table files (`*.frm', `*.MYD', and
  17440.      `*.MYI' files) as long as the server isn't updating anything.  The
  17441.      script `mysqlhotcopy' does use this method.  (But note that these
  17442.      methods will not work if your database contains `InnoDB' tables.
  17443.      `InnoDB' does not store table contents in database directories,
  17444.      and `mysqlhotcopy' works only for `MyISAM' and `ISAM' tables.)
  17445.  
  17446.   2. Stop `mysqld' if it's running, then start it with the
  17447.      `--log-bin[=file_name]' option.  *Note Binary log::. The binary
  17448.      log file(s) provide you with the information you need to replicate
  17449.      changes to the database that are made subsequent to the point at
  17450.      which you executed `mysqldump'.
  17451.  
  17452. If your MySQL server is a slave, whatever backup method you choose,
  17453. when you backup your slave's data, you should also backup the
  17454. `master.info' and `relay-log.info' files which are always needed to
  17455. resume replication after you restore the slave's data. If your slave is
  17456. subject to replicating `LOAD DATA INFILE' commands, you should also
  17457. backup the `SQL-LOAD*' files which may exist in the `slave-load-tmpdir'
  17458. (which is `tmpdir' by default) directory. The slave will need these
  17459. files to resume replication of any interrupted `LOAD DATA INFILE'.
  17460.  
  17461. If you have to restore something, try to recover your tables using
  17462. `REPAIR TABLE' or `myisamchk -r' first.  That should work in 99.9% of
  17463. all cases.  If `myisamchk' fails, try the following procedure (this
  17464. will only work if you have started MySQL with `--log-bin', see *Note
  17465. Binary log::):
  17466.  
  17467.   1. Restore the original `mysqldump' backup, or binary backup.
  17468.  
  17469.   2. Execute the following command to re-run the updates in the binary
  17470.      log:
  17471.  
  17472.           shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  17473.  
  17474.      In your case you may want to re-run only certain binlogs, from
  17475.      certain positions (usually you want to re-run all binlogs from the
  17476.      date of the restored backup, possibly excepted some wrong queries).
  17477.      See *Note mysqlbinlog:: for more information on the `mysqlbinlog'
  17478.      utility and how to use it.
  17479.  
  17480.      If you are using the update log (which will be removed in MySQL
  17481.      5.0) you can execute the content of the update log like this:
  17482.  
  17483.           shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
  17484.  
  17485. `ls' is used to get all the update log files in the right order.
  17486.  
  17487. You can also do selective backups with `SELECT * INTO OUTFILE
  17488. 'file_name' FROM tbl_name' and restore with `LOAD DATA INFILE
  17489. 'file_name' REPLACE ...' To avoid duplicate records, you need a
  17490. `PRIMARY KEY' or a `UNIQUE' key in the table. The `REPLACE' keyword
  17491. causes old records to be replaced with new ones when a new record
  17492. duplicates an old record on a unique key value.
  17493.  
  17494. If you get performance problems in making backups on your system, you
  17495. can solve this by setting up replication and do the backups on the slave
  17496. instead of on the master. *Note Replication Intro::.
  17497.  
  17498. If you are using a Veritas filesystem, you can do:
  17499.  
  17500.   1. From a client (or Perl), execute: `FLUSH TABLES WITH READ LOCK'.
  17501.  
  17502.   2. From another shell, execute: `mount vxfs snapshot'.
  17503.  
  17504.   3. From the first client, execute: `UNLOCK TABLES'.
  17505.  
  17506.   4. Copy files from snapshot.
  17507.  
  17508.   5. Unmount snapshot.
  17509.  
  17510. `BACKUP TABLE' Syntax
  17511. ---------------------
  17512.  
  17513.      BACKUP TABLE tbl_name[,tbl_name...] TO '/path/to/backup/directory'
  17514.  
  17515. Copies to the backup directory the minimum number of table files needed
  17516. to restore the table, after flushing any buffered changes to disk.
  17517. Currently works only for `MyISAM' tables.  For `MyISAM' tables, copies
  17518. `.frm' (definition)  and `.MYD' (data) files. The index file can be
  17519. rebuilt from those two.
  17520.  
  17521. Before using this command, please see *Note Backup::.
  17522.  
  17523. During the backup, a read lock will be held for each table, one at time,
  17524. as they are being backed up. If you want to back up several tables as a
  17525. snapshot, you must first issue `LOCK TABLES' obtaining a read lock for
  17526. each table in the group.
  17527.  
  17528. The command returns a table with the following columns:
  17529.  
  17530. *Column*    *Value*
  17531. Table       Table name
  17532. Op          Always `backup'
  17533. Msg_type    One of `status', `error',
  17534.             `info', or `warning'
  17535. Msg_text    The message
  17536.  
  17537. Note that `BACKUP TABLE' is only available in MySQL version 3.23.25 and
  17538. later.
  17539.  
  17540. `RESTORE TABLE' Syntax
  17541. ----------------------
  17542.  
  17543.      RESTORE TABLE tbl_name[,tbl_name...] FROM '/path/to/backup/directory'
  17544.  
  17545. Restores the table(s) from the backup that was made with `BACKUP
  17546. TABLE'. Existing tables will not be overwritten; if you try to restore
  17547. over an existing table, you will get an error. Restoring will take
  17548. longer than backing up due to the need to rebuild the index. The more
  17549. keys you have, the longer it will take. Just as `BACKUP TABLE',
  17550. `RESTORE TABLE' currently works only for `MyISAM' tables.
  17551.  
  17552. The command returns a table with the following columns:
  17553.  
  17554. *Column*    *Value*
  17555. Table       Table name
  17556. Op          Always `restore'
  17557. Msg_type    One of `status', `error',
  17558.             `info', or `warning'
  17559. Msg_text    The message
  17560.  
  17561. `CHECK TABLE' Syntax
  17562. --------------------
  17563.  
  17564.      CHECK TABLE tbl_name[,tbl_name...] [option [option...]]
  17565.      
  17566.      option = QUICK | FAST | MEDIUM | EXTENDED | CHANGED
  17567.  
  17568. `CHECK TABLE' works only on `MyISAM' and `InnoDB' tables. On `MyISAM'
  17569. tables, it's the same thing as running `myisamchk --medium-check
  17570. table_name' on the table.
  17571.  
  17572. If you don't specify any option, `MEDIUM' is used.
  17573.  
  17574. Checks the table or tables for errors. For `MyISAM' tables, the key
  17575. statistics are updated. The command returns a table with the following
  17576. columns:
  17577.  
  17578. *Column*    *Value*
  17579. Table       Table name
  17580. Op          Always `check'
  17581. Msg_type    One of `status', `error',
  17582.             `info', or `warning'
  17583. Msg_text    The message
  17584.  
  17585. Note that the statement may produce many rows of information for each
  17586. checked table.  The last row will be of `Msg_type status' and should
  17587. normally be `OK'.  If you don't get `OK', or `Table is already up to
  17588. date' you should normally run a repair of the table. *Note Table
  17589. maintenance::. `Table is already up to date' means that the storage
  17590. manager for the table indicated that there was no need to check the
  17591. table.
  17592.  
  17593. The different check types are as follows:
  17594.  
  17595. *Type*      *Meaning*
  17596. `QUICK'     Don't scan the rows to check for incorrect links.
  17597. `FAST'      Only check tables that haven't been closed properly.
  17598. `CHANGED'   Only check tables that have been changed since the last
  17599.             check or haven't been closed properly.
  17600. `MEDIUM'    Scan rows to verify that deleted links are okay. This also
  17601.             calculates a key checksum for the rows and verifies this
  17602.             with a calculated checksum for the keys.
  17603. `EXTENDED'  Do a full key lookup for all keys for each row.  This
  17604.             ensures that the table is 100% consistent, but will take a
  17605.             long time!
  17606.  
  17607. For dynamically sized `MyISAM' tables, a started check will always do a
  17608. `MEDIUM' check. For statically sized rows, we skip the row scan for
  17609. `QUICK' and `FAST' as the rows are very seldom corrupted.
  17610.  
  17611. You can combine check options, as in the following example that does a
  17612. quick check on the table to see whether it was closed properly:
  17613.  
  17614.      CHECK TABLE test_table FAST QUICK;
  17615.  
  17616. *Note*: that in some cases `CHECK TABLE' will change the table!  This
  17617. happens if the table is marked as 'corrupted' or 'not closed properly'
  17618. but `CHECK TABLE' didn't find any problems in the table.  In this case,
  17619. `CHECK TABLE' will mark the table as okay.
  17620.  
  17621. If a table is corrupted, then it's most likely that the problem is in
  17622. the indexes and not in the data part.  All of the above check types
  17623. checks the indexes thoroughly and should thus find most errors.
  17624.  
  17625. If you just want to check a table that you assume is okay, you should
  17626. use no check options or the `QUICK' option. The latter should be used
  17627. when you are in a hurry and can take the very small risk that `QUICK'
  17628. didn't find an error in the datafile. (In most cases MySQL should find,
  17629. under normal usage, any error in the datafile.  If this happens then
  17630. the table will be marked as 'corrupted', in which case the table can't
  17631. be used until it's repaired.)
  17632.  
  17633. `FAST' and `CHANGED' are mostly intended to be used from a script (for
  17634. example to be executed from `cron') if you want to check your table
  17635. from time to time. In most cases, `FAST' is to be prefered over
  17636. `CHANGED'.  (The only case when it isn't is when you suspect that you
  17637. have found a bug in the `MyISAM' code.)
  17638.  
  17639. `EXTENDED' is only to be used after you have run a normal check but
  17640. still get strange errors from a table when MySQL tries to update a row
  17641. or find a row by key (this is very unlikely if a normal check has
  17642. succeeded!).
  17643.  
  17644. Some things reported by `CHECK TABLE' can't be corrected automatically:
  17645.  
  17646.    * `Found row where the auto_increment column has the value 0'.
  17647.  
  17648.      This means that you have a row in the table where the
  17649.      `AUTO_INCREMENT' index column contains the value 0.  (It's
  17650.      possible to create a row where the `AUTO_INCREMENT' column is 0 by
  17651.      explicitly setting the column to 0 with an `UPDATE' statement.)
  17652.  
  17653.      This isn't an error in itself, but could cause trouble if you
  17654.      decide to dump the table and restore it or do an `ALTER TABLE' on
  17655.      the table. In this case, the `AUTO_INCREMENT' column will change
  17656.      value, according to the rules of `AUTO_INCREMENT' columns, which
  17657.      could cause problems such as a duplicate key error.
  17658.  
  17659.      To get rid of the warning, just execute an `UPDATE' statement to
  17660.      set the column to some other value than 0.
  17661.  
  17662. `REPAIR TABLE' Syntax
  17663. ---------------------
  17664.  
  17665.      REPAIR [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED] [USE_FRM]
  17666.  
  17667. `REPAIR TABLE' works only on `MyISAM' tables and is the same as running
  17668. `myisamchk -r table_name' on the table.
  17669.  
  17670. Normally you should never have to run this command, but if disaster
  17671. strikes you are very likely to get back all your data from a MyISAM
  17672. table with `REPAIR TABLE'. If your tables get corrupted a lot, you
  17673. should try to find the reason for it, to eliminate the need to use
  17674. `REPAIR TABLE'.  *Note Crashing::. *Note MyISAM table problems::.
  17675.  
  17676. `REPAIR TABLE' repairs a possibly corrupted table. The command returns a
  17677. table with the following columns:
  17678.  
  17679. *Column*    *Value*
  17680. Table       Table name
  17681. Op          Always `repair'
  17682. Msg_type    One of `status', `error',
  17683.             `info', or `warning'
  17684. Msg_text    The message
  17685.  
  17686. Note that the statement may produce many rows of information for each
  17687. repaired table.  The last one row will be of `Msg_type status' and
  17688. should normally be `OK'.  If you don't get `OK', you should try
  17689. repairing the table with `myisamchk --safe-recover', as `REPAIR TABLE'
  17690. does not yet implement all the options of `myisamchk'. In the near
  17691. future, we will make it more flexible.
  17692.  
  17693. If `QUICK' is given, `REPAIR TABLE' tries to repair only the index tree.
  17694.  
  17695. If you use `EXTENDED', MySQL will create the index row by row instead
  17696. of creating one index at a time with sorting; this may be better than
  17697. sorting on fixed-length keys if you have long `CHAR' keys that compress
  17698. very well.  This type of repair is like that done by `myisamchk
  17699. --safe-recover'.
  17700.  
  17701. As of `MySQL' 4.0.2, there is a `USE_FRM' mode for `REPAIR'.  Use it if
  17702. the `.MYI' file is missing or if its header is corrupted.  In this mode
  17703. MySQL will recreate the table, using information from the `.frm' file.
  17704. This kind of repair cannot be done with `myisamchk'.
  17705.  
  17706. *Warning:* If `mysqld' dies during a `REPAIR TABLE', it's essential
  17707. that you do at once another `REPAIR' on the table before executing any
  17708. other commands on it. (It's of course always good to start with a
  17709. backup).  In the worst case you can have a new clean index file without
  17710. information about the datafile and when the next command you do may
  17711. overwrite the datafile.  This is not a likely, but possible scenario.
  17712.  
  17713. Before MySQL 4.1.1, `REPAIR' commands are not written to the binary
  17714. log. Since MySQL 4.1.1 they are written to the binary log unless the
  17715. optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was used.
  17716.  
  17717. Using `myisamchk' for Table Maintenance and Crash Recovery
  17718. ----------------------------------------------------------
  17719.  
  17720. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  17721. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  17722. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  17723.  
  17724. To check/repair MyISAM tables (`.MYI' and `.MYD') you should use the
  17725. `myisamchk' utility. To check/repair ISAM tables (`.ISM' and `.ISD')
  17726. you should use the `isamchk' utility. *Note Table types::.
  17727.  
  17728. In the following text we will talk about `myisamchk', but everything
  17729. also applies to the old `isamchk'.
  17730.  
  17731. You can use the `myisamchk' utility to get information about your
  17732. database tables, check and repair them, or optimise them.  The following
  17733. sections describe how to invoke `myisamchk' (including a description of
  17734. its options), how to set up a table maintenance schedule, and how to
  17735. use `myisamchk' to perform its various functions.
  17736.  
  17737. You can, in most cases, also use the command `OPTIMIZE TABLES' to
  17738. optimise and repair tables, but this is not as fast or reliable (in case
  17739. of real fatal errors) as `myisamchk'.  On the other hand, `OPTIMIZE
  17740. TABLE' is easier to use and you don't have to worry about flushing
  17741. tables.  *Note `OPTIMIZE TABLE': OPTIMIZE TABLE.
  17742.  
  17743. Even though the repair in `myisamchk' is quite secure, it's always a
  17744. good idea to make a backup _before_ doing a repair (or anything that
  17745. could make a lot of changes to a table)
  17746.  
  17747. `myisamchk' Invocation Syntax
  17748. .............................
  17749.  
  17750. `myisamchk' is invoked like this:
  17751.  
  17752.      shell> myisamchk [options] tbl_name
  17753.  
  17754. The `options' specify what you want `myisamchk' to do.  They are
  17755. described here.  (You can also get a list of options by invoking
  17756. `myisamchk --help'.)  With no options, `myisamchk' simply checks your
  17757. table.  To get more information or to tell `myisamchk' to take
  17758. corrective action, specify options as described here and in the
  17759. following sections.
  17760.  
  17761. `tbl_name' is the database table you want to check/repair.  If you run
  17762. `myisamchk' somewhere other than in the database directory, you must
  17763. specify the path to the file, because `myisamchk' has no idea where your
  17764. database is located.  Actually, `myisamchk' doesn't care whether the
  17765. files you are working on are located in a database directory; you can
  17766. copy the files that correspond to a database table into another
  17767. location and perform recovery operations on them there.
  17768.  
  17769. You can name several tables on the `myisamchk' command-line if you
  17770. wish.  You can also specify a name as an index file name (with the
  17771. `.MYI' suffix), which allows you to specify all tables in a directory
  17772. by using the pattern `*.MYI'.  For example, if you are in a database
  17773. directory, you can check all the tables in the directory like this:
  17774.  
  17775.      shell> myisamchk *.MYI
  17776.  
  17777. If you are not in the database directory, you can check all the tables
  17778. there by specifying the path to the directory:
  17779.  
  17780.      shell> myisamchk /path/to/database_dir/*.MYI
  17781.  
  17782. You can even check all tables in all databases by specifying a wildcard
  17783. with the path to the MySQL data directory:
  17784.  
  17785.      shell> myisamchk /path/to/datadir/*/*.MYI
  17786.  
  17787. The recommended way to quickly check all tables is:
  17788.  
  17789.      myisamchk --silent --fast /path/to/datadir/*/*.MYI
  17790.      isamchk --silent /path/to/datadir/*/*.ISM
  17791.  
  17792. If you want to check all tables and repair all tables that are
  17793. corrupted, you can use the following line:
  17794.  
  17795.      myisamchk --silent --force --fast --update-state -O key_buffer=64M \
  17796.                -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
  17797.                /path/to/datadir/*/*.MYI
  17798.      isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M \
  17799.              -O read_buffer=1M -O write_buffer=1M /path/to/datadir/*/*.ISM
  17800.  
  17801. The above assumes that you have more than 64 M free.
  17802.  
  17803. Note that if you get an error like:
  17804.  
  17805.      myisamchk: warning: 1 clients is using or hasn't closed the table properly
  17806.  
  17807. This means that you are trying to check a table that has been updated by
  17808. another program (like the `mysqld' server) that hasn't yet closed the
  17809. file or that has died without closing the file properly.
  17810.  
  17811. If `mysqld' is running, you must force a sync/close of all tables with
  17812. `FLUSH TABLES' and ensure that no one is using the tables while you are
  17813. running `myisamchk'.  In MySQL Version 3.23 the easiest way to avoid
  17814. this problem is to use `CHECK TABLE' instead of `myisamchk' to check
  17815. tables.
  17816.  
  17817. General Options for `myisamchk'
  17818. ...............................
  17819.  
  17820. `myisamchk' supports the following options.
  17821.  
  17822. `-# or --debug=debug_options'
  17823.      Output debug log. The `debug_options' string often is
  17824.      `'d:t:o,filename''.
  17825.  
  17826. `-? or --help'
  17827.      Display a help message and exit.
  17828.  
  17829. `-O var=option, --set-variable var=option'
  17830.      Set the value of a variable.  Please note that `--set-variable' is
  17831.      deprecated since MySQL 4.0, just use `--var=option' on its own.
  17832.      The possible variables and their default values for myisamchk can
  17833.      be examined with `myisamchk --help':
  17834.      *Variable*    *Value*
  17835.      key_buffer_size523264
  17836.      read_buffer_size262136
  17837.      write_buffer_size262136
  17838.      sort_buffer_size2097144
  17839.      sort_key_blocks16
  17840.      decode_bits   9
  17841.  
  17842.      `sort_buffer_size' is used when the keys are repaired by sorting
  17843.      keys, which is the normal case when you use `--recover'.
  17844.  
  17845.      `key_buffer_size' is used when you are checking the table with
  17846.      `--extended-check' or when the keys are repaired by inserting key
  17847.      row by row in to the table (like when doing normal inserts).
  17848.      Repairing through the key buffer is used in the following cases:
  17849.  
  17850.         * If you use `--safe-recover'.
  17851.  
  17852.         * If the temporary files needed to sort the keys would be more
  17853.           than twice as big as when creating the key file directly.
  17854.           This is often the case when you have big `CHAR', `VARCHAR' or
  17855.           `TEXT' keys as the sort needs to store the whole keys during
  17856.           sorting. If you have lots of temporary space and you can
  17857.           force `myisamchk' to repair by sorting you can use the
  17858.           `--sort-recover' option.
  17859.  
  17860.      Reparing through the key buffer takes much less disk space than
  17861.      using sorting, but is also much slower.
  17862.  
  17863.      If you want a faster repair, set the above variables to about 1/4
  17864.      of your available memory.  You can set both variables to big
  17865.      values, as only one of the above buffers will be used at a time.
  17866.  
  17867. `-s or --silent'
  17868.      Silent mode.  Write output only when errors occur. You can use `-s'
  17869.      twice (`-ss') to make `myisamchk' very silent.
  17870.  
  17871. `-v or --verbose'
  17872.      Verbose mode.  Print more information. This can be used with `-d'
  17873.      and `-e'. Use `-v' multiple times (`-vv', `-vvv') for more
  17874.      verbosity!
  17875.  
  17876. `-V or --version'
  17877.      Print the `myisamchk' version and exit.
  17878.  
  17879. `-w or, --wait'
  17880.      Instead of giving an error if the table is locked, wait until the
  17881.      table is unlocked before continuing.  Note that if you are running
  17882.      `mysqld' on the table with `--skip-external-locking', the table
  17883.      can only be locked by another `myisamchk' command.
  17884.  
  17885. Check Options for `myisamchk'
  17886. .............................
  17887.  
  17888. `-c or --check'
  17889.      Check table for errors. This is the default operation if you are
  17890.      not giving `myisamchk' any options that override this.
  17891.  
  17892. `-e or --extend-check'
  17893.      Check the table very thoroughly (which is quite slow if you have
  17894.      many indexes).  This option should only be used in extreme cases.
  17895.      Normally, `myisamchk' or `myisamchk --medium-check' should, in most
  17896.      cases, be able to find out if there are any errors in the table.
  17897.  
  17898.      If you are using `--extended-check' and have much memory, you
  17899.      should increase the value of `key_buffer_size' a lot!
  17900.  
  17901. `-F or --fast'
  17902.      Check only tables that haven't been closed properly.
  17903.  
  17904. `-C or --check-only-changed'
  17905.      Check only tables that have changed since the last check.
  17906.  
  17907. `-f or --force'
  17908.      Restart `myisamchk' with `-r' (repair) on the table, if
  17909.      `myisamchk' finds any errors in the table.
  17910.  
  17911. `-i or --information'
  17912.      Print informational statistics about the table that is checked.
  17913.  
  17914. `-m or --medium-check'
  17915.      Faster than extended-check, but only finds 99.99% of all errors.
  17916.      Should, however, be good enough for most cases.
  17917.  
  17918. `-U or --update-state'
  17919.      Store in the `.MYI' file when the table was checked and if the
  17920.      table crashed.  This should be used to get full benefit of the
  17921.      `--check-only-changed' option, but you shouldn't use this option
  17922.      if the `mysqld' server is using the table and you are running
  17923.      `mysqld' with `--skip-external-locking'.
  17924.  
  17925. `-T or --read-only'
  17926.      Don't mark table as checked. This is useful if you use `myisamchk'
  17927.      to check a table that is in use by some other application that
  17928.      doesn't use locking (like `mysqld --skip-external-locking').
  17929.  
  17930. Repair Options for myisamchk
  17931. ............................
  17932.  
  17933. The following options are used if you start `myisamchk' with `-r' or
  17934. `-o':
  17935.  
  17936. `-B or --backup'
  17937.      Make a backup of the `.MYD' file as `filename-time.BAK'
  17938.  
  17939. `--correct-checksum'
  17940.      Correct checksum information for table.
  17941.  
  17942. `-D # or --data-file-length=#'
  17943.      Max length of datafile (when re-creating datafile when it's
  17944.      'full').
  17945.  
  17946. `-e or --extend-check'
  17947.      Try to recover every possible row from the datafile.  Normally
  17948.      this will also find a lot of garbage rows. Don't use this option
  17949.      if you are not totally desperate.
  17950.  
  17951. `-f or --force'
  17952.      Overwrite old temporary files (`table_name.TMD') instead of
  17953.      aborting.
  17954.  
  17955. `-k # or --keys-used=#'
  17956.      If you are using `ISAM', tells the `ISAM' storage engine to update
  17957.      only the first `#' indexes.  If you are using `MyISAM', tells
  17958.      which keys to use, where each binary bit stands for one key (first
  17959.      key is bit 0).  This can be used to get faster inserts!
  17960.      Deactivated indexes can be reactivated by using `myisamchk -r'.
  17961.  
  17962. `-l or --no-symlinks'
  17963.      Do not follow symbolic links. Normally `myisamchk' repairs the
  17964.      table a symlink points at.  This option doesn't exist in MySQL 4.0,
  17965.      as MySQL 4.0 will not remove symlinks during repair.
  17966.  
  17967. `-p or --parallel-recover'
  17968.      Uses the same technique as `-r' and `-n', but creates all the keys
  17969.      in parallel, in different threads.  This option was added in MySQL
  17970.      4.0.2.  *This is alpha code. Use at your own risk!*
  17971.  
  17972. `-r or --recover'
  17973.      Can fix almost anything except unique keys that aren't unique
  17974.      (which is an extremely unlikely error with `ISAM'/`MyISAM' tables).
  17975.      If you want to recover a table, this is the option to try first.
  17976.      Only if `myisamchk' reports that the table can't be recovered by
  17977.      `-r', you should then try `-o'.  (Note that in the unlikely case
  17978.      that `-r' fails, the datafile is still intact.)  If you have lots
  17979.      of memory, you should increase the size of `sort_buffer_size'!
  17980.  
  17981. `-o or --safe-recover'
  17982.      Uses an old recovery method (reads through all rows in order and
  17983.      updates all index trees based on the found rows); this is an order
  17984.      of magnitude slower than `-r', but can handle a couple of very
  17985.      unlikely cases that `-r' cannot handle.  This recovery method also
  17986.      uses much less disk space than `-r'. Normally one should always
  17987.      first repair with `-r', and only if this fails use `-o'.
  17988.  
  17989.      If you have lots of memory, you should increase the size of
  17990.      `key_buffer_size'!
  17991.  
  17992. `-n or --sort-recover'
  17993.      Force `myisamchk' to use sorting to resolve the keys even if the
  17994.      temporary files should be very big.
  17995.  
  17996. `--character-sets-dir=...'
  17997.      Directory where character sets are stored.
  17998.  
  17999. `--set-character-set=name'
  18000.      Change the character set used by the index
  18001.  
  18002. `-t or --tmpdir=path'
  18003.      Path for storing temporary files. If this is not set, `myisamchk'
  18004.      will use the environment variable `TMPDIR' for this.  Starting
  18005.      from MySQL 4.1, `tmpdir' can be set to a list of paths separated
  18006.      by colon `:' (semicolon `;' on Windows). They will be used in
  18007.      round-robin fashion.
  18008.  
  18009. `-q or --quick'
  18010.      Faster repair by not modifying the datafile. One can give a second
  18011.      `-q' to force `myisamchk' to modify the original datafile in case
  18012.      of duplicate keys
  18013.  
  18014. `-u or --unpack'
  18015.      Unpack file packed with myisampack.
  18016.  
  18017. Other Options for `myisamchk'
  18018. .............................
  18019.  
  18020. Other actions that `myisamchk' can do, besides repair and check tables:
  18021.  
  18022. `-a or --analyze'
  18023.      Analyse the distribution of keys. This improves join performance by
  18024.      enabling the join optimiser to better choose in which order it
  18025.      should join the tables and which keys it should use: `myisamchk
  18026.      --describe --verbose table_name'' or using `SHOW KEYS' in MySQL.
  18027.  
  18028. `-d or --description'
  18029.      Prints some information about table.
  18030.  
  18031. `-A or --set-auto-increment[=value]'
  18032.      Force `AUTO_INCREMENT' to start at this or higher value. If no
  18033.      value is given, then sets the next `AUTO_INCREMENT' value to the
  18034.      highest used value for the auto key + 1.
  18035.  
  18036. `-S or --sort-index'
  18037.      Sort the index tree blocks in high-low order.  This will optimise
  18038.      seeks and will make table scanning by key faster.
  18039.  
  18040. `-R or --sort-records=#'
  18041.      Sorts records according to an index.  This makes your data much
  18042.      more localised and may speed up ranged `SELECT' and `ORDER BY'
  18043.      operations on this index. (It may be very slow to do a sort the
  18044.      first time!)  To find out a table's index numbers, use `SHOW
  18045.      INDEX', which shows a table's indexes in the same order that
  18046.      `myisamchk' sees them.  Indexes are numbered beginning with 1.
  18047.  
  18048. `myisamchk' Memory Usage
  18049. ........................
  18050.  
  18051. Memory allocation is important when you run `myisamchk'.  `myisamchk'
  18052. uses no more memory than you specify with the `-O' options.  If you are
  18053. going to use `myisamchk' on very large files, you should first decide
  18054. how much memory you want it to use.  The default is to use only about
  18055. 3M to fix things.  By using larger values, you can get `myisamchk' to
  18056. operate faster.  For example, if you have more than 32M RAM, you could
  18057. use options such as these (in addition to any other options you might
  18058. specify):
  18059.  
  18060.      shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
  18061.  
  18062. Using `-O sort=16M' should probably be enough for most cases.
  18063.  
  18064. Be aware that `myisamchk' uses temporary files in `TMPDIR'. If `TMPDIR'
  18065. points to a memory filesystem, you may easily get out of memory errors.
  18066. If this happens, set `TMPDIR' to point at some directory with more
  18067. space and restart `myisamchk'.
  18068.  
  18069. When repairing, `myisamchk' will also need a lot of disk space:
  18070.  
  18071.    * Double the size of the record file (the original one and a copy).
  18072.      This space is not needed if one does a repair with `--quick', as
  18073.      in this case only the index file will be re-created.  This space
  18074.      is needed on the same disk as the original record file!
  18075.  
  18076.    * Space for the new index file that replaces the old one. The old
  18077.      index file is truncated at start, so one usually ignore this space.
  18078.      This space is needed on the same disk as the original index file!
  18079.  
  18080.    * When using `--recover' or `--sort-recover' (but not when using
  18081.      `--safe-recover'), you will need space for a sort buffer for:
  18082.      `(largest_key + row_pointer_length)*number_of_rows * 2'.  You can
  18083.      check the length of the keys and the row_pointer_length with
  18084.      `myisamchk -dv table'.  This space is allocated on the temporary
  18085.      disk (specified by `TMPDIR' or `--tmpdir=#').
  18086.  
  18087. If you have a problem with disk space during repair, you can try to use
  18088. `--safe-recover' instead of `--recover'.
  18089.  
  18090. Using `myisamchk' for Crash Recovery
  18091. ....................................
  18092.  
  18093. If you run `mysqld' with `--skip-external-locking' (which is the
  18094. default on some systems, like Linux), you can't reliably use `myisamchk'
  18095. to check a table when `mysqld' is using the same table.  If you can be
  18096. sure that no one is accessing the tables through `mysqld' while you run
  18097. `myisamchk', you only have to do `mysqladmin flush-tables' before you
  18098. start checking the tables.  If you can't guarantee the above, then you
  18099. must take down `mysqld' while you check the tables.  If you run
  18100. `myisamchk' while `mysqld' is updating the tables, you may get a
  18101. warning that a table is corrupt even if it isn't.
  18102.  
  18103. If you are not using `--skip-external-locking', you can use `myisamchk'
  18104. to check tables at any time.  While you do this, all clients that try
  18105. to update the table will wait until `myisamchk' is ready before
  18106. continuing.
  18107.  
  18108. If you use `myisamchk' to repair or optimise tables, you *must* always
  18109. ensure that the `mysqld' server is not using the table (this also
  18110. applies if you are using `--skip-external-locking').  If you don't take
  18111. down `mysqld' you should at least do a `mysqladmin flush-tables' before
  18112. you run `myisamchk'.  Your tables *may be corrupted* if the server and
  18113. `myisamchk' access the tables simultaneously.
  18114.  
  18115. This chapter describes how to check for and deal with data corruption
  18116. in MySQL databases.  If your tables get corrupted frequently you should
  18117. try to find the reason for this! *Note Crashing::.
  18118.  
  18119. The `MyISAM' table section contains reason for why a table could be
  18120. corrupted. *Note MyISAM table problems::.
  18121.  
  18122. When performing crash recovery, it is important to understand that each
  18123. table `tbl_name' in a database corresponds to three files in the
  18124. database directory:
  18125.  
  18126. *File*         *Purpose*
  18127. `tbl_name.frm' Table definition
  18128.                (form) file
  18129. `tbl_name.MYD' Datafile
  18130. `tbl_name.MYI' Index file
  18131.  
  18132. Each of these three file types is subject to corruption in various
  18133. ways, but problems occur most often in datafiles and index files.
  18134.  
  18135. `myisamchk' works by creating a copy of the `.MYD' (data) file row by
  18136. row. It ends the repair stage by removing the old `.MYD' file and
  18137. renaming the new file to the original file name.  If you use `--quick',
  18138. `myisamchk' does not create a temporary `.MYD' file, but instead
  18139. assumes that the `.MYD' file is correct and only generates a new index
  18140. file without touching the `.MYD' file. This is safe, because
  18141. `myisamchk' automatically detects if the `.MYD' file is corrupt and
  18142. aborts the repair in this case.  You can also give two `--quick'
  18143. options to `myisamchk'.  In this case, `myisamchk' does not abort on
  18144. some errors (like duplicate key) but instead tries to resolve them by
  18145. modifying the `.MYD' file. Normally the use of two `--quick' options is
  18146. useful only if you have too little free disk space to perform a normal
  18147. repair.  In this case you should at least make a backup before running
  18148. `myisamchk'.
  18149.  
  18150. How to Check Tables for Errors
  18151. ..............................
  18152.  
  18153. To check a MyISAM table, use the following commands:
  18154.  
  18155. `myisamchk tbl_name'
  18156.      This finds 99.99% of all errors. What it can't find is corruption
  18157.      that involves *only* the datafile (which is very unusual). If you
  18158.      want to check a table, you should normally run `myisamchk' without
  18159.      options or with either the `-s' or `--silent' option.
  18160.  
  18161. `myisamchk -m tbl_name'
  18162.      This finds 99.999% of all errors. It checks first all index
  18163.      entries for errors and then it reads through all rows. It
  18164.      calculates a checksum for all keys in the rows and verifies that
  18165.      they checksum matches the checksum for the keys in the index tree.
  18166.  
  18167. `myisamchk -e tbl_name'
  18168.      This does a complete and thorough check of all data (`-e' means
  18169.      "extended check"). It does a check-read of every key for each row
  18170.      to verify that they indeed point to the correct row.  This may
  18171.      take a long time on a big table with many keys.  `myisamchk' will
  18172.      normally stop after the first error it finds. If you want to
  18173.      obtain more information, you can add the `--verbose' (`-v')
  18174.      option.  This causes `myisamchk' to keep going, up through a
  18175.      maximum of 20 errors.  In normal usage, a simple `myisamchk' (with
  18176.      no arguments other than the table name) is sufficient.
  18177.  
  18178. `myisamchk -e -i tbl_name'
  18179.      Like the previous command, but the `-i' option tells `myisamchk' to
  18180.      print some informational statistics, too.
  18181.  
  18182. How to Repair Tables
  18183. ....................
  18184.  
  18185. In the following section we only talk about using `myisamchk' on
  18186. `MyISAM' tables (extensions `.MYI' and `.MYD').  If you are using
  18187. `ISAM' tables (extensions `.ISM' and `.ISD'), you should use `isamchk'
  18188. instead.
  18189.  
  18190. Starting with MySQL Version 3.23.14, you can repair MyISAM tables with
  18191. the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18192.  
  18193. The symptoms of a corrupted table include queries that abort
  18194. unexpectedly and observable errors such as these:
  18195.  
  18196.    * `tbl_name.frm' is locked against change
  18197.  
  18198.    * Can't find file `tbl_name.MYI' (Errcode: ###)
  18199.  
  18200.    * Unexpected end of file
  18201.  
  18202.    * Record file is crashed
  18203.  
  18204.    * Got error ### from table handler
  18205.  
  18206.      To get more information about the error you can run `perror ###'.
  18207.      Here is the most common errors that indicates a problem with the
  18208.      table:
  18209.  
  18210.           shell> perror 126 127 132 134 135 136 141 144 145
  18211.           126 = Index file is crashed / Wrong file format
  18212.           127 = Record-file is crashed
  18213.           132 = Old database file
  18214.           134 = Record was already deleted (or record file crashed)
  18215.           135 = No more room in record file
  18216.           136 = No more room in index file
  18217.           141 = Duplicate unique key or constraint on write or update
  18218.           144 = Table is crashed and last repair failed
  18219.           145 = Table was marked as crashed and should be repaired
  18220.  
  18221.      Note that error 135 (no more room in record file), is not an error
  18222.      that can be fixed by a simple repair. In this case you have to do:
  18223.  
  18224.           ALTER TABLE table MAX_ROWS=xxx AVG_ROW_LENGTH=yyy;
  18225.  
  18226.      You can also use this technique for error 136 (no more room in
  18227.      index file).
  18228.  
  18229.  
  18230. In the other cases, you must repair your tables. `myisamchk' can
  18231. usually detect and fix most things that go wrong.
  18232.  
  18233. The repair process involves up to four stages, described here. Before
  18234. you begin, you should `cd' to the database directory and check the
  18235. permissions of the table files. Make sure they are readable by the Unix
  18236. user that `mysqld' runs as (and to you, because you need to access the
  18237. files you are checking).  If it turns out you need to modify files,
  18238. they must also be writable by you.
  18239.  
  18240. If you are using MySQL Version 3.23.16 and above, you can (and should)
  18241. use the `CHECK' and `REPAIR' commands to check and repair `MyISAM'
  18242. tables.  *Note CHECK TABLE::.  *Note REPAIR TABLE::.
  18243.  
  18244. The manual section about table maintenance includes the options to
  18245. `isamchk'/`myisamchk'.  *Note Table maintenance::.
  18246.  
  18247. The following section is for the cases where the above command fails or
  18248. if you want to use the extended features that `isamchk'/`myisamchk'
  18249. provides.
  18250.  
  18251. If you are going to repair a table from the command-line, you must first
  18252. take down the `mysqld' server. Note that when you do `mysqladmin
  18253. shutdown' on a remote server, the `mysqld' server will still be alive
  18254. for a while after `mysqladmin' returns, until all queries are stopped
  18255. and all keys have been flushed to disk.
  18256.  
  18257. *Stage 1: Checking your tables*
  18258.  
  18259. Run `myisamchk *.MYI' or `myisamchk -e *.MYI' if you have more time.
  18260. Use the `-s' (silent) option to suppress unnecessary information.
  18261.  
  18262. If the `mysqld' server is done you should use the -update option to tell
  18263. `myisamchk' to mark the table as 'checked'.
  18264.  
  18265. You have to repair only those tables for which `myisamchk' announces an
  18266. error.  For such tables, proceed to Stage 2.
  18267.  
  18268. If you get weird errors when checking (such as `out of memory' errors),
  18269. or if `myisamchk' crashes, go to Stage 3.
  18270.  
  18271. *Stage 2: Easy safe repair*
  18272.  
  18273. Note: If you want repairing to go much faster, you should add: `-O
  18274. sort_buffer=# -O key_buffer=#' (where # is about 1/4 of the available
  18275. memory) to all `isamchk/myisamchk' commands.
  18276.  
  18277. First, try `myisamchk -r -q tbl_name' (`-r -q' means "quick recovery
  18278. mode"). This will attempt to repair the index file without touching the
  18279. datafile.  If the datafile contains everything that it should and the
  18280. delete links point at the correct locations within the datafile, this
  18281. should work, and the table is fixed. Start repairing the next table.
  18282. Otherwise, use the following procedure:
  18283.  
  18284.   1. Make a backup of the datafile before continuing.
  18285.  
  18286.   2. Use `myisamchk -r tbl_name' (`-r' means "recovery mode"). This will
  18287.      remove incorrect records and deleted records from the datafile and
  18288.      reconstruct the index file.
  18289.  
  18290.   3. If the preceding step fails, use `myisamchk --safe-recover
  18291.      tbl_name'.  Safe recovery mode uses an old recovery method that
  18292.      handles a few cases that regular recovery mode doesn't (but is
  18293.      slower).
  18294.  
  18295. If you get weird errors when repairing (such as `out of memory'
  18296. errors), or if `myisamchk' crashes, go to Stage 3.
  18297.  
  18298. *Stage 3: Difficult repair*
  18299.  
  18300. You should only reach this stage if the first 16K block in the index
  18301. file is destroyed or contains incorrect information, or if the index
  18302. file is missing.  In this case, it's necessary to create a new index
  18303. file. Do so as follows:
  18304.  
  18305.   1. Move the datafile to some safe place.
  18306.  
  18307.   2. Use the table description file to create new (empty) data and
  18308.      index files:
  18309.  
  18310.           shell> mysql db_name
  18311.           mysql> SET AUTOCOMMIT=1;
  18312.           mysql> TRUNCATE TABLE table_name;
  18313.           mysql> quit
  18314.  
  18315.      If your SQL version doesn't have `TRUNCATE TABLE', use `DELETE FROM
  18316.      table_name' instead.
  18317.  
  18318.   3. Copy the old datafile back onto the newly created datafile.
  18319.      (Don't just move the old file back onto the new file; you want to
  18320.      retain a copy in case something goes wrong.)
  18321.  
  18322. Go back to Stage 2.  `myisamchk -r -q' should work now.  (This shouldn't
  18323. be an endless loop.)
  18324.  
  18325. As of `MySQL' 4.0.2 you can also use `REPAIR ... USE_FRM' which
  18326. performs the whole procedure automatically.
  18327.  
  18328. *Stage 4: Very difficult repair*
  18329.  
  18330. You should reach this stage only if the description file has also
  18331. crashed. That should never happen, because the description file isn't
  18332. changed after the table is created:
  18333.  
  18334.   1. Restore the description file from a backup and go back to Stage 3.
  18335.      You can also restore the index file and go back to Stage 2.  In
  18336.      the latter case, you should start with `myisamchk -r'.
  18337.  
  18338.   2. If you don't have a backup but know exactly how the table was
  18339.      created, create a copy of the table in another database.  Remove
  18340.      the new datafile, then move the description and index files from
  18341.      the other database to your crashed database.  This gives you new
  18342.      description and index files, but leaves the datafile alone.  Go
  18343.      back to Stage 2 and attempt to reconstruct the index file.
  18344.  
  18345. Table Optimisation
  18346. ..................
  18347.  
  18348. To coalesce fragmented records and eliminate wasted space resulting from
  18349. deleting or updating records, run `myisamchk' in recovery mode:
  18350.  
  18351.      shell> myisamchk -r tbl_name
  18352.  
  18353. You can optimise a table in the same way using the SQL `OPTIMIZE TABLE'
  18354. statement.  `OPTIMIZE TABLE' does a repair of the table and a key
  18355. analysis, and also sorts the index tree to give faster key lookups.
  18356. There is also no possibility of unwanted interaction between a utility
  18357. and the server, because the server does all the work when you use
  18358. `OPTIMIZE TABLE'. *Note OPTIMIZE TABLE::.
  18359.  
  18360. `myisamchk' also has a number of other options you can use to improve
  18361. the performance of a table:
  18362.  
  18363.    * `-S', `--sort-index'
  18364.  
  18365.    * `-R index_num', `--sort-records=index_num'
  18366.  
  18367.    * `-a', `--analyze'
  18368.  
  18369. For a full description of the option. *Note myisamchk syntax::.
  18370.  
  18371. Setting Up a Table Maintenance Regimen
  18372. --------------------------------------
  18373.  
  18374. Starting with MySQL Version 3.23.13, you can check MyISAM tables with
  18375. the `CHECK TABLE' command. *Note CHECK TABLE::.  You can repair tables
  18376. with the `REPAIR TABLE' command. *Note REPAIR TABLE::.
  18377.  
  18378. It is a good idea to perform table checks on a regular basis rather than
  18379. waiting for problems to occur.  For maintenance purposes, you can use
  18380. `myisamchk -s' to check tables.  The `-s' option (short for `--silent')
  18381. causes `myisamchk' to run in silent mode, printing messages only when
  18382. errors occur.
  18383.  
  18384. It's also a good idea to check tables when the server starts up.  For
  18385. example, whenever the machine has done a reboot in the middle of an
  18386. update, you usually need to check all the tables that could have been
  18387. affected. (This is an "expected crashed table".) You could add a test to
  18388. `mysqld_safe' that runs `myisamchk' to check all tables that have been
  18389. modified during the last 24 hours if there is an old `.pid' (process
  18390. ID) file left after a reboot.  (The `.pid' file is created by `mysqld'
  18391. when it starts up and removed when it terminates normally.  The
  18392. presence of a `.pid' file at system startup time indicates that
  18393. `mysqld' terminated abnormally.)
  18394.  
  18395. An even better test would be to check any table whose last-modified time
  18396. is more recent than that of the `.pid' file.
  18397.  
  18398. You should also check your tables regularly during normal system
  18399. operation.  At MySQL AB, we run a `cron' job to check all our important
  18400. tables once a week, using a line like this in a `crontab' file:
  18401.  
  18402.      35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI
  18403.  
  18404. This prints out information about crashed tables so we can examine and
  18405. repair them when needed.
  18406.  
  18407. As we haven't had any unexpectedly crashed tables (tables that become
  18408. corrupted for reasons other than hardware trouble) for a couple of
  18409. years now (this is really true), once a week is more than enough for us.
  18410.  
  18411. We recommend that to start with, you execute `myisamchk -s' each night
  18412. on all tables that have been updated during the last 24 hours, until
  18413. you come to trust MySQL as much as we do.
  18414.  
  18415. Normally you don't need to maintain MySQL tables that much.  If you are
  18416. changing tables with dynamic size rows (tables with `VARCHAR', `BLOB'
  18417. or `TEXT' columns) or have tables with many deleted rows you may want
  18418. to from time to time (once a month?) defragment/reclaim space from the
  18419. tables.
  18420.  
  18421. You can do this by using `OPTIMIZE TABLE' on the tables in question or
  18422. if you can take down the `mysqld' server for a while do:
  18423.  
  18424.      isamchk -r --silent --sort-index -O sort_buffer_size=16M */*.ISM
  18425.      myisamchk -r --silent --sort-index  -O sort_buffer_size=16M */*.MYI
  18426.  
  18427. Getting Information About a Table
  18428. ---------------------------------
  18429.  
  18430. To get a description of a table or statistics about it, use the
  18431. commands shown here. We explain some of the information in more detail
  18432. later:
  18433.  
  18434.    * myisamchk -d tbl_name Runs `myisamchk' in "describe mode" to
  18435.      produce a description of your table. If you start the MySQL server
  18436.      using the `--skip-external-locking' option, `myisamchk' may report
  18437.      an error for a table that is updated while it runs.  However,
  18438.      because `myisamchk' doesn't change the table in describe mode,
  18439.      there isn't any risk of destroying data.
  18440.  
  18441.    * myisamchk -d -v tbl_name To produce more information about what
  18442.      `myisamchk' is doing, add `-v' to tell it to run in verbose mode.
  18443.  
  18444.    * myisamchk -eis tbl_name Shows only the most important information
  18445.      from a table. It is slow because it must read the whole table.
  18446.  
  18447.    * myisamchk -eiv tbl_name This is like `-eis', but tells you what is
  18448.      being done.
  18449.  
  18450. Example of `myisamchk -d' output:
  18451.      MyISAM file:     company.MYI
  18452.      Record format:   Fixed length
  18453.      Data records:    1403698  Deleted blocks:         0
  18454.      Recordlength:    226
  18455.      
  18456.      table description:
  18457.      Key Start Len Index   Type
  18458.      1   2     8   unique  double
  18459.      2   15    10  multip. text packed stripped
  18460.      3   219   8   multip. double
  18461.      4   63    10  multip. text packed stripped
  18462.      5   167   2   multip. unsigned short
  18463.      6   177   4   multip. unsigned long
  18464.      7   155   4   multip. text
  18465.      8   138   4   multip. unsigned long
  18466.      9   177   4   multip. unsigned long
  18467.          193   1           text
  18468.  
  18469. Example of `myisamchk -d -v' output:
  18470.      MyISAM file:         company
  18471.      Record format:       Fixed length
  18472.      File-version:        1
  18473.      Creation time:       1999-10-30 12:12:51
  18474.      Recover time:        1999-10-31 19:13:01
  18475.      Status:              checked
  18476.      Data records:           1403698  Deleted blocks:              0
  18477.      Datafile parts:         1403698  Deleted data:                0
  18478.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     3
  18479.      Max datafile length: 3791650815  Max keyfile length: 4294967294
  18480.      Recordlength:               226
  18481.      
  18482.      table description:
  18483.      Key Start Len Index   Type                  Rec/key     Root Blocksize
  18484.      1   2     8   unique  double                      1 15845376      1024
  18485.      2   15    10  multip. text packed stripped        2 25062400      1024
  18486.      3   219   8   multip. double                     73 40907776      1024
  18487.      4   63    10  multip. text packed stripped        5 48097280      1024
  18488.      5   167   2   multip. unsigned short           4840 55200768      1024
  18489.      6   177   4   multip. unsigned long            1346 65145856      1024
  18490.      7   155   4   multip. text                     4995 75090944      1024
  18491.      8   138   4   multip. unsigned long              87 85036032      1024
  18492.      9   177   4   multip. unsigned long             178 96481280      1024
  18493.          193   1           text
  18494.  
  18495. Example of `myisamchk -eis' output:
  18496.      Checking MyISAM file: company
  18497.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18498.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  18499.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18500.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  18501.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18502.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18503.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18504.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18505.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  18506.      Total:    Keyblocks used:  98%  Packed:   17%
  18507.      
  18508.      Records:          1403698    M.recordlength:     226
  18509.      Packed:             0%
  18510.      Recordspace used:     100%   Empty space:          0%
  18511.      Blocks/Record:   1.00
  18512.      Record blocks:    1403698    Delete blocks:        0
  18513.      Recorddata:     317235748    Deleted data:         0
  18514.      Lost space:             0    Linkdata:             0
  18515.      
  18516.      User time 1626.51, System time 232.36
  18517.      Maximum resident set size 0, Integral resident set size 0
  18518.      Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
  18519.      Blocks in 0 out 0, Messages in 0 out 0, Signals 0
  18520.      Voluntary context switches 639, Involuntary context switches 28966
  18521.  
  18522. Example of `myisamchk -eiv' output:
  18523.      Checking MyISAM file: company
  18524.      Data records: 1403698   Deleted blocks:       0
  18525.      - check file-size
  18526.      - check delete-chain
  18527.      block_size 1024:
  18528.      index  1:
  18529.      index  2:
  18530.      index  3:
  18531.      index  4:
  18532.      index  5:
  18533.      index  6:
  18534.      index  7:
  18535.      index  8:
  18536.      index  9:
  18537.      No recordlinks
  18538.      - check index reference
  18539.      - check data record references index: 1
  18540.      Key:  1:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18541.      - check data record references index: 2
  18542.      Key:  2:  Keyblocks used:  98%  Packed:   50%  Max levels:  4
  18543.      - check data record references index: 3
  18544.      Key:  3:  Keyblocks used:  97%  Packed:    0%  Max levels:  4
  18545.      - check data record references index: 4
  18546.      Key:  4:  Keyblocks used:  99%  Packed:   60%  Max levels:  3
  18547.      - check data record references index: 5
  18548.      Key:  5:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18549.      - check data record references index: 6
  18550.      Key:  6:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18551.      - check data record references index: 7
  18552.      Key:  7:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18553.      - check data record references index: 8
  18554.      Key:  8:  Keyblocks used:  99%  Packed:    0%  Max levels:  3
  18555.      - check data record references index: 9
  18556.      Key:  9:  Keyblocks used:  98%  Packed:    0%  Max levels:  4
  18557.      Total:    Keyblocks used:   9%  Packed:   17%
  18558.      
  18559.      - check records and index references
  18560.      [LOTS OF ROW NUMBERS DELETED]
  18561.      
  18562.      Records:          1403698    M.recordlength:     226   Packed:             0%
  18563.      Recordspace used:     100%   Empty space:          0%  Blocks/Record:   1.00
  18564.      Record blocks:    1403698    Delete blocks:        0
  18565.      Recorddata:     317235748    Deleted data:         0
  18566.      Lost space:             0    Linkdata:             0
  18567.      
  18568.      User time 1639.63, System time 251.61
  18569.      Maximum resident set size 0, Integral resident set size 0
  18570.      Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
  18571.      Blocks in 4 out 0, Messages in 0 out 0, Signals 0
  18572.      Voluntary context switches 10604, Involuntary context switches 122798
  18573.  
  18574. Here are the sizes of the data and index files for the table used in the
  18575. preceding examples:
  18576.  
  18577.      -rw-rw-r--   1 monty    tcx     317235748 Jan 12 17:30 company.MYD
  18578.      -rw-rw-r--   1 davida   tcx      96482304 Jan 12 18:35 company.MYM
  18579.  
  18580. Explanations for the types of information `myisamchk' produces are
  18581. given here.  The "keyfile" is the index file.  "Record" and "row" are
  18582. synonymous:
  18583.  
  18584.    * ISAM file Name of the ISAM (index) file.
  18585.  
  18586.    * Isam-version Version of ISAM format. Currently always 2.
  18587.  
  18588.    * Creation time When the datafile was created.
  18589.  
  18590.    * Recover time When the index/datafile was last reconstructed.
  18591.  
  18592.    * Data records How many records are in the table.
  18593.  
  18594.    * Deleted blocks How many deleted blocks still have reserved space.
  18595.      You can optimise your table to minimise this space.  *Note
  18596.      Optimisation::.
  18597.  
  18598.    * Data file: Parts For dynamic record format, this indicates how
  18599.      many data blocks there are. For an optimised table without
  18600.      fragmented records, this is the same as `Data records'.
  18601.  
  18602.    * Deleted data How many bytes of non-reclaimed deleted data there
  18603.      are.  You can optimise your table to minimise this space.  *Note
  18604.      Optimisation::.
  18605.  
  18606.    * Data file pointer The size of the datafile pointer, in bytes. It
  18607.      is usually 2, 3, 4, or 5 bytes. Most tables manage with 2 bytes,
  18608.      but this cannot be controlled from MySQL yet. For fixed tables,
  18609.      this is a record address. For dynamic tables, this is a byte
  18610.      address.
  18611.  
  18612.    * Keyfile pointer The size of the index file pointer, in bytes. It
  18613.      is usually 1, 2, or 3 bytes. Most tables manage with 2 bytes, but
  18614.      this is calculated automatically by MySQL. It is always a block
  18615.      address.
  18616.  
  18617.    * Max datafile length How long the table's datafile (`.MYD' file)
  18618.      can become, in bytes.
  18619.  
  18620.    * Max keyfile length How long the table's key file (`.MYI' file) can
  18621.      become, in bytes.
  18622.  
  18623.    * Recordlength How much space each record takes, in bytes.
  18624.  
  18625.    * Record format The format used to store table rows.  The preceding
  18626.      examples use `Fixed length'.  Other possible values are
  18627.      `Compressed' and `Packed'.
  18628.  
  18629.    * table description A list of all keys in the table. For each key,
  18630.      some low-level information is presented:
  18631.  
  18632.         - Key This key's number.
  18633.  
  18634.         - Start Where in the record this index part starts.
  18635.  
  18636.         - Len How long this index part is. For packed numbers, this
  18637.           should always be the full length of the column. For strings,
  18638.           it may be shorter than the full length of the indexed column,
  18639.           because you can index a prefix of a string column.
  18640.  
  18641.         - Index `unique' or `multip.' (multiple). Indicates whether one
  18642.           value can exist multiple times in this index.
  18643.  
  18644.         - Type What data-type this index part has. This is an ISAM
  18645.           data-type with the options `packed', `stripped' or `empty'.
  18646.  
  18647.         - Root Address of the root index block.
  18648.  
  18649.         - Blocksize The size of each index block. By default this is
  18650.           1024, but the value may be changed at compile time.
  18651.  
  18652.         - Rec/key This is a statistical value used by the optimiser. It
  18653.           tells how many records there are per value for this key. A
  18654.           unique key always has a value of 1. This may be updated after
  18655.           a table is loaded (or greatly changed) with `myisamchk -a'.
  18656.           If this is not updated at all, a default value of 30 is given.
  18657.  
  18658.    * In the first example above, the 9th key is a multi-part key with
  18659.      two parts.
  18660.  
  18661.    * Keyblocks used What percentage of the keyblocks are used. Because
  18662.      the table used in the examples had just been reorganised with
  18663.      `myisamchk', the values are very high (very near the theoretical
  18664.      maximum).
  18665.  
  18666.    * Packed MySQL tries to pack keys with a common suffix. This can
  18667.      only be used for `CHAR'/`VARCHAR'/`DECIMAL' keys. For long strings
  18668.      like names, this can significantly reduce the space used. In the
  18669.      third example above, the 4th key is 10 characters long and a 60%
  18670.      reduction in space is achieved.
  18671.  
  18672.    * Max levels How deep the B-tree for this key is. Large tables with
  18673.      long keys get high values.
  18674.  
  18675.    * Records How many rows are in the table.
  18676.  
  18677.    * M.recordlength The average record length. For tables with
  18678.      fixed-length records, this is the exact record length.
  18679.  
  18680.    * Packed MySQL strips spaces from the end of strings. The `Packed'
  18681.      value indicates the percentage of savings achieved by doing this.
  18682.  
  18683.    * Recordspace used What percentage of the datafile is used.
  18684.  
  18685.    * Empty space What percentage of the datafile is unused.
  18686.  
  18687.    * Blocks/Record Average number of blocks per record (that is, how
  18688.      many links a fragmented record is composed of). This is always 1.0
  18689.      for fixed-format tables. This value should stay as close to 1.0 as
  18690.      possible. If it gets too big, you can reorganise the table with
  18691.      `myisamchk'.  *Note Optimisation::.
  18692.  
  18693.    * Recordblocks How many blocks (links) are used. For fixed format,
  18694.      this is the same as the number of records.
  18695.  
  18696.    * Deleteblocks How many blocks (links) are deleted.
  18697.  
  18698.    * Recorddata How many bytes in the datafile are used.
  18699.  
  18700.    * Deleted data How many bytes in the datafile are deleted (unused).
  18701.  
  18702.    * Lost space If a record is updated to a shorter length, some space
  18703.      is lost. This is the sum of all such losses, in bytes.
  18704.  
  18705.    * Linkdata When the dynamic table format is used, record fragments
  18706.      are linked with pointers (4 to 7 bytes each). `Linkdata' is the
  18707.      sum of the amount of storage used by all such pointers.
  18708.  
  18709. If a table has been compressed with `myisampack', `myisamchk -d' prints
  18710. additional information about each table column.  See *Note
  18711. `myisampack': myisampack, for an example of this information and a
  18712. description of what it means.
  18713.  
  18714. Database Administration Language Reference
  18715. ==========================================
  18716.  
  18717. `OPTIMIZE TABLE' Syntax
  18718. -----------------------
  18719.  
  18720.      OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name]...
  18721.  
  18722. `OPTIMIZE TABLE' should be used if you have deleted a large part of a
  18723. table or if you have made many changes to a table with variable-length
  18724. rows (tables that have `VARCHAR', `BLOB', or `TEXT' columns).  Deleted
  18725. records are maintained in a linked list and subsequent `INSERT'
  18726. operations reuse old record positions. You can use `OPTIMIZE TABLE' to
  18727. reclaim the unused space and to defragment the datafile.
  18728.  
  18729. In most setups you don't have to run `OPTIMIZE TABLE' at all.  Even if
  18730. you do a lot of updates to variable length rows it's not likely that
  18731. you need to do this more than once a month/week and only on certain
  18732. tables.
  18733.  
  18734. For the moment, `OPTIMIZE TABLE' works only on `MyISAM' and `BDB'
  18735. tables. For `BDB' tables, `OPTIMIZE TABLE' is currently mapped to
  18736. `ANALYZE TABLE'.  *Note `ANALYZE TABLE': ANALYZE TABLE.
  18737.  
  18738. You can get `OPTIMIZE TABLE' to work on other table types by starting
  18739. `mysqld' with `--skip-new' or `--safe-mode', but in this case `OPTIMIZE
  18740. TABLE' is just mapped to `ALTER TABLE'.
  18741.  
  18742. `OPTIMIZE TABLE' works the following way:
  18743.    * If the table has deleted or split rows, repair the table.
  18744.  
  18745.    * If the index pages are not sorted, sort them.
  18746.  
  18747.    * If the statistics are not up to date (and the repair couldn't be
  18748.      done by sorting the index), update them.
  18749.  
  18750. Note that the table is locked during the time `OPTIMIZE TABLE' is
  18751. running!
  18752.  
  18753. Before MySQL 4.1.1, `OPTIMIZE' commands are not written to the binary
  18754. log. Since MySQL 4.1.1 they are written to the binary log unless the
  18755. optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was used.
  18756.  
  18757. `ANALYZE TABLE' Syntax
  18758. ----------------------
  18759.  
  18760.      ANALYZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name[,tbl_name...]
  18761.  
  18762. Analyse and store the key distribution for the table.  During the
  18763. analysis, the table is locked with a read lock.  This works on `MyISAM'
  18764. and `BDB' tables.
  18765.  
  18766. This is equivalent to running `myisamchk -a' on the table.
  18767.  
  18768. MySQL uses the stored key distribution to decide in which order tables
  18769. should be joined when one does a join on something else than a constant.
  18770.  
  18771. The command returns a table with the following columns:
  18772.  
  18773. *Column*    *Value*
  18774. Table       Table name
  18775. Op          Always `analyze'
  18776. Msg_type    One of `status', `error',
  18777.             `info', or `warning'
  18778. Msg_text    The message
  18779.  
  18780. You can check the stored key distribution with the `SHOW INDEX' command.
  18781. *Note Show database info::.
  18782.  
  18783. If the table hasn't changed since the last `ANALYZE TABLE' command, the
  18784. table will not be analysed again.
  18785.  
  18786. Before MySQL 4.1.1, `ANALYZE' commands are not written to the binary
  18787. log. Since MySQL 4.1.1 they are written to the binary log unless the
  18788. optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was used.
  18789.  
  18790. `FLUSH' Syntax
  18791. --------------
  18792.  
  18793.      FLUSH [LOCAL | NO_WRITE_TO_BINLOG] flush_option [,flush_option] ...
  18794.  
  18795. You should use the `FLUSH' command if you want to clear some of the
  18796. internal caches MySQL uses.  To execute `FLUSH', you must have the
  18797. `RELOAD' privilege.
  18798.  
  18799. `flush_option' can be any of the following:
  18800.  
  18801. *Option*           *Description*
  18802. `HOSTS'            Empties the host cache tables.  You should flush the
  18803.                    host tables if some of your hosts change IP number or
  18804.                    if you get the error message `Host ... is blocked'.
  18805.                    When more than `max_connect_errors' errors occur in a
  18806.                    row for a given host while connection to the MySQL
  18807.                    server, MySQL assumes something is wrong and blocks
  18808.                    the host from further connection requests.  Flushing
  18809.                    the host tables allows the host to attempt to connect
  18810.                    again. *Note Blocked host::. You can start `mysqld'
  18811.                    with `-O max_connect_errors=999999999' to avoid this
  18812.                    error message.
  18813. `DES_KEY_FILE'     Reloads the DES keys from the file that was specified
  18814.                    with the `--des-key-file' option at server startup
  18815.                    time.
  18816. `LOGS'             Closes and reopens all log files.  If you have
  18817.                    specified an update log file or a binary log file
  18818.                    without an extension, the extension number of the log
  18819.                    file will be incremented by one relative to the
  18820.                    previous file. If you have used an extension in the
  18821.                    file name, MySQL will close and reopen the update log
  18822.                    file.  *Note Update log::. This is the same thing as
  18823.                    sending the `SIGHUP' signal to the `mysqld' server.
  18824. `PRIVILEGES'       Reloads the privileges from the grant tables in the
  18825.                    `mysql' database.
  18826. `QUERY CACHE'      Defragment the query cache to better utilise its
  18827.                    memory.  This command will not remove any queries
  18828.                    from the cache, unlike `RESET QUERY CACHE'.
  18829. `TABLES'           Closes all open tables and force all tables in use to
  18830.                    be closed. This also flushes the query cache.
  18831. `[TABLE | TABLES]  Flushes only the given tables.
  18832. tbl_name           
  18833. [,tbl_name...]'    
  18834. `TABLES WITH READ  Closes all open tables and locks all tables for all
  18835. LOCK'              databases with a read lock until you execute `UNLOCK
  18836.                    TABLES'. This is very convenient way to get backups
  18837.                    if you have a filesystem, like Veritas, that can take
  18838.                    snapshots in time.
  18839. `STATUS'           Resets most status variables to zero. This is
  18840.                    something one should only use when debugging a query.
  18841. `USER_RESOURCES'   Resets all user resources to zero. This will enable
  18842.                    blocked users to login again. *Note User resources::.
  18843.  
  18844. Before MySQL 4.1.1, `FLUSH' commands are not written to the binary log.
  18845. Since MySQL 4.1.1 they are written to the binary log unless the
  18846. optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL') was used,
  18847. or unless the command contained one of these arguments: `LOGS',
  18848. `MASTER', `SLAVE', `TABLES WITH READ LOCK', because any of these
  18849. arguments may cause problems if replicated to a slave.
  18850.  
  18851. You can also access some of the commands shown above with the
  18852. `mysqladmin' utility, using the `flush-hosts', `flush-logs',
  18853. `flush-privileges', `flush-status' or `flush-tables' commands.
  18854.  
  18855. Take also a look at the `RESET' command used with replication.  *Note
  18856. `RESET': RESET.
  18857.  
  18858. `RESET' Syntax
  18859. --------------
  18860.  
  18861.      RESET reset_option [,reset_option] ...
  18862.  
  18863. The `RESET' command is used to clear things. It also acts as an stronger
  18864. version of the `FLUSH' command.  *Note `FLUSH': FLUSH.
  18865.  
  18866. To execute `RESET', you must have the `RELOAD' privilege.
  18867.  
  18868. *Option*           *Description*
  18869. `MASTER'           Deletes all binary logs listed in the index file,
  18870.                    resetting the binlog index file to be empty.
  18871.                    Previously named `FLUSH MASTER'.  *Note Replication
  18872.                    Master SQL::.
  18873. `SLAVE'            Makes the slave forget its replication position in
  18874.                    the master binlogs.  Previously named `FLUSH SLAVE'.
  18875.                    *Note Replication Slave SQL::.
  18876. `QUERY CACHE'      Removes all query results from the query cache.
  18877.  
  18878. `PURGE MASTER LOGS' Syntax
  18879. --------------------------
  18880.  
  18881.      PURGE {MASTER|BINARY} LOGS TO binlog_name
  18882.      PURGE {MASTER|BINARY} LOGS BEFORE date
  18883.  
  18884. This command is used to delete all binary logs strictly prior to the
  18885. specified binlog or date. *Note Replication Master SQL::.
  18886.  
  18887. `PURGE BINARY LOGS' is available as a synonym for `PURGE MASTER LOGS'
  18888. as of MySQL 4.1.1.
  18889.  
  18890. `KILL' Syntax
  18891. -------------
  18892.  
  18893.      KILL thread_id
  18894.  
  18895. Each connection to `mysqld' runs in a separate thread.  You can see
  18896. which threads are running with the `SHOW PROCESSLIST' command and kill
  18897. a thread with the `KILL thread_id' command.
  18898.  
  18899. If you have the `PROCESS' privilege, you can see all threads.  If you
  18900. have the `SUPER' privilege, you can kill all threads.  Otherwise, you
  18901. can only see and kill your own threads.
  18902.  
  18903. You can also use the `mysqladmin processlist' and `mysqladmin kill'
  18904. commands to examine and kill threads.
  18905.  
  18906. _Note_: You currently cannot use `KILL' with the Embedded MySQL Server
  18907. library, because the embedded server merely runs inside the threads of
  18908. the host application, it does not create connection threads of its own.
  18909.  
  18910. When you do a `KILL', a thread-specific `kill flag' is set for the
  18911. thread.
  18912.  
  18913. In most cases it may take some time for the thread to die as the kill
  18914. flag is only checked at specific intervals.
  18915.  
  18916.    * In `SELECT', `ORDER BY' and `GROUP BY' loops, the flag is checked
  18917.      after reading a block of rows. If the kill flag is set, the
  18918.      statement is aborted.
  18919.  
  18920.    * When doing an `ALTER TABLE' the kill flag is checked before each
  18921.      block of rows are read from the original table. If the kill flag
  18922.      was set the command is aborted and the temporary table is deleted.
  18923.  
  18924.    * When doing an `UPDATE' or `DELETE', the kill flag is checked after
  18925.      each block read and after each updated or deleted row. If the kill
  18926.      flag is set, the statement is aborted.  Note that if you are not
  18927.      using transactions, the changes will not be rolled back!
  18928.  
  18929.    * `GET_LOCK()' will abort with `NULL'.
  18930.  
  18931.    * An `INSERT DELAYED' thread will quickly flush all rows it has in
  18932.      memory and die.
  18933.  
  18934.    * If the thread is in the table lock handler (state: `Locked'), the
  18935.      table lock will be quickly aborted.
  18936.  
  18937.    * If the thread is waiting for free disk space in a `write' call, the
  18938.      write is aborted with an disk full error message.
  18939.  
  18940. `SHOW' Syntax
  18941. -------------
  18942.  
  18943.         SHOW DATABASES [LIKE wild]
  18944.      or SHOW [OPEN] TABLES [FROM db_name] [LIKE wild]
  18945.      or SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
  18946.      or SHOW INDEX FROM tbl_name [FROM db_name]
  18947.      or SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  18948.      or SHOW STATUS [LIKE wild]
  18949.      or SHOW VARIABLES [LIKE wild]
  18950.      or SHOW [BDB] LOGS
  18951.      or SHOW [FULL] PROCESSLIST
  18952.      or SHOW GRANTS FOR user
  18953.      or SHOW CREATE TABLE table_name
  18954.      or SHOW MASTER STATUS
  18955.      or SHOW MASTER LOGS
  18956.      or SHOW SLAVE STATUS
  18957.      or SHOW WARNINGS [LIMIT row_count]
  18958.      or SHOW ERRORS [LIMIT row_count]
  18959.      or SHOW TABLE TYPES
  18960.  
  18961. `SHOW' provides information about databases, tables, columns, or status
  18962. information about the server. If the `LIKE wild' part is used, the
  18963. `wild' string can be a string that uses the SQL `%' and `_' wildcard
  18964. characters.
  18965.  
  18966. Retrieving information about Database, Tables, Columns, and Indexes
  18967. ...................................................................
  18968.  
  18969. You can use `db_name.tbl_name' as an alternative to the `tbl_name FROM
  18970. db_name' syntax.  These two statements are equivalent:
  18971.  
  18972.      mysql> SHOW INDEX FROM mytable FROM mydb;
  18973.      mysql> SHOW INDEX FROM mydb.mytable;
  18974.  
  18975. `SHOW DATABASES' lists the databases on the MySQL server host.  You can
  18976. also get this list using the `mysqlshow' command line tool.  In version
  18977. 4.0.2 you will only see those databases for which you have some kind of
  18978. privilege, if you don't have the global `SHOW DATABASES' privilege.
  18979.  
  18980. `SHOW TABLES' lists the tables in a given database.  You can also get
  18981. this list using the `mysqlshow db_name' command.
  18982.  
  18983. *Note*: if a user doesn't have any privileges for a table, the table
  18984. will not show up in the output from `SHOW TABLES' or `mysqlshow
  18985. db_name'.
  18986.  
  18987. `SHOW OPEN TABLES' lists the tables that are currently open in the
  18988. table cache. *Note Table cache::.  The `Comment' field tells how many
  18989. times the table is `cached' and `in_use'.
  18990.  
  18991. `SHOW COLUMNS' lists the columns in a given table.  If you specify the
  18992. `FULL' option, you will also get the privileges you have for each
  18993. column.  If the column types are different from what you expect them to
  18994. be based on a `CREATE TABLE' statement, note that MySQL sometimes
  18995. changes column types.  *Note Silent column changes::.  As of MySQL 4.1,
  18996. the `FULL' keyword also causes any per-column comments to be displayed.
  18997.  
  18998. The `DESCRIBE' statement provides information similar to `SHOW COLUMNS'.
  18999. *Note `DESCRIBE': DESCRIBE.
  19000.  
  19001. `SHOW FIELDS' is a synonym for `SHOW COLUMNS', and `SHOW KEYS' is a
  19002. synonym for `SHOW INDEX'.  You can also list a table's columns or
  19003. indexes with `mysqlshow db_name tbl_name' or `mysqlshow -k db_name
  19004. tbl_name'.
  19005.  
  19006. `SHOW INDEX' returns the index information in a format that closely
  19007. resembles the `SQLStatistics' call in ODBC. The following columns are
  19008. returned:
  19009.  
  19010. *Column*    *Meaning*
  19011. `Table'     Name of the table.
  19012. `Non_unique'0 if the index can't contain
  19013.             duplicates, 1 if it can.
  19014. `Key_name'  Name of the index.
  19015. `Seq_in_index'Column sequence number in index,
  19016.                                           starting
  19017.             with 1.
  19018. `Column_name'Column name.
  19019. `Collation' How the column is sorted in the index.
  19020.             In MySQL, this can have values
  19021.                                         `A'
  19022.             (Ascending) or `NULL' (Not
  19023.                                     sorted).
  19024. `Cardinality'Number of unique values in the index.
  19025.             This is updated by running
  19026.                                     `isamchk -a'.
  19027. `Sub_part'  Number of indexed characters if the
  19028.             column is only partly indexed.
  19029.                                          `NULL' if
  19030.             the entire key is indexed.
  19031. `Null'      Contains 'YES' if the column may
  19032.             contain `NULL'.
  19033. `Index_type'Index method used.
  19034. `Comment'   Various remarks.  For now, it tells in
  19035.             MySQL < 4.0.2 whether index is
  19036.             `FULLTEXT' or not.
  19037.  
  19038. Note that as the `Cardinality' is counted based on statistics stored as
  19039. integers, it's not necessarily accurate for small tables.
  19040.  
  19041. The `Null' and `Index_type' columns were added in MySQL 4.0.2.
  19042.  
  19043. `SHOW TABLE STATUS'
  19044. ...................
  19045.  
  19046.      SHOW TABLE STATUS [FROM db_name] [LIKE wild]
  19047.  
  19048. `SHOW TABLE STATUS' (new in Version 3.23) works likes `SHOW STATUS',
  19049. but provides a lot of information about each table. You can also get
  19050. this list using the `mysqlshow --status db_name' command.  The
  19051. following columns are returned:
  19052.  
  19053. *Column*       *Meaning*
  19054. `Name'         Name of the table.
  19055. `Type'         Type of table. *Note Table types::.
  19056. `Row_format'   The row storage format (Fixed, Dynamic, or
  19057.                Compressed).
  19058. `Rows'         Number of rows.
  19059. `Avg_row_length'Average row length.
  19060. `Data_length'  Length of the datafile.
  19061. `Max_data_length'Max length of the datafile.  For fixed row
  19062.                formats, this is the max number of rows in the
  19063.                table.  For dynamic row formats, this is the
  19064.                total number of data bytes that can be stored in
  19065.                the table, given the data pointer size used.
  19066. `Index_length' Length of the index file.
  19067. `Data_free'    Number of allocated but not used bytes.
  19068. `Auto_increment'Next autoincrement value.
  19069. `Create_time'  When the table was created.
  19070. `Update_time'  When the datafile was last updated.
  19071. `Check_time'   When the table was last checked.
  19072. `Create_options'Extra options used with `CREATE TABLE'.
  19073. `Comment'      The comment used when creating the table (or some
  19074.                information why MySQL couldn't access the table
  19075.                information).
  19076.  
  19077. `InnoDB' tables will report the free space in the tablespace in the
  19078. table comment.
  19079.  
  19080. `SHOW STATUS'
  19081. .............
  19082.  
  19083. `SHOW STATUS' provides server status information (like `mysqladmin
  19084. extended-status'). The output resembles that shown here, though the
  19085. format and numbers probably differ:
  19086.  
  19087.      +--------------------------+------------+
  19088.      | Variable_name            | Value      |
  19089.      +--------------------------+------------+
  19090.      | Aborted_clients          | 0          |
  19091.      | Aborted_connects         | 0          |
  19092.      | Bytes_received           | 155372598  |
  19093.      | Bytes_sent               | 1176560426 |
  19094.      | Connections              | 30023      |
  19095.      | Created_tmp_disk_tables  | 0          |
  19096.      | Created_tmp_tables       | 8340       |
  19097.      | Created_tmp_files        | 60         |
  19098.      | Delayed_insert_threads   | 0          |
  19099.      | Delayed_writes           | 0          |
  19100.      | Delayed_errors           | 0          |
  19101.      | Flush_commands           | 1          |
  19102.      | Handler_delete           | 462604     |
  19103.      | Handler_read_first       | 105881     |
  19104.      | Handler_read_key         | 27820558   |
  19105.      | Handler_read_next        | 390681754  |
  19106.      | Handler_read_prev        | 6022500    |
  19107.      | Handler_read_rnd         | 30546748   |
  19108.      | Handler_read_rnd_next    | 246216530  |
  19109.      | Handler_update           | 16945404   |
  19110.      | Handler_write            | 60356676   |
  19111.      | Key_blocks_used          | 14955      |
  19112.      | Key_read_requests        | 96854827   |
  19113.      | Key_reads                | 162040     |
  19114.      | Key_write_requests       | 7589728    |
  19115.      | Key_writes               | 3813196    |
  19116.      | Max_used_connections     | 0          |
  19117.      | Not_flushed_key_blocks   | 0          |
  19118.      | Not_flushed_delayed_rows | 0          |
  19119.      | Open_tables              | 1          |
  19120.      | Open_files               | 2          |
  19121.      | Open_streams             | 0          |
  19122.      | Opened_tables            | 44600      |
  19123.      | Questions                | 2026873    |
  19124.      | Select_full_join         | 0          |
  19125.      | Select_full_range_join   | 0          |
  19126.      | Select_range             | 99646      |
  19127.      | Select_range_check       | 0          |
  19128.      | Select_scan              | 30802      |
  19129.      | Slave_running            | OFF        |
  19130.      | Slave_open_temp_tables   | 0          |
  19131.      | Slow_launch_threads      | 0          |
  19132.      | Slow_queries             | 0          |
  19133.      | Sort_merge_passes        | 30         |
  19134.      | Sort_range               | 500        |
  19135.      | Sort_rows                | 30296250   |
  19136.      | Sort_scan                | 4650       |
  19137.      | Table_locks_immediate    | 1920382    |
  19138.      | Table_locks_waited       | 0          |
  19139.      | Threads_cached           | 0          |
  19140.      | Threads_created          | 30022      |
  19141.      | Threads_connected        | 1          |
  19142.      | Threads_running          | 1          |
  19143.      | Uptime                   | 80380      |
  19144.      +--------------------------+------------+
  19145.  
  19146. The status variables listed above have the following meaning:
  19147.  
  19148. *Variable*             *Meaning*
  19149. `Aborted_clients'      Number of connections aborted because the client
  19150.                        died without closing the connection properly.
  19151.                        *Note Communication errors::.
  19152. `Aborted_connects'     Number of tries to connect to the MySQL server
  19153.                        that failed. *Note Communication errors::.
  19154. `Bytes_received'       Number of bytes received from all clients.
  19155. `Bytes_sent'           Number of bytes sent to all clients.
  19156. `Com_xxx'              Number of times each xxx command has been
  19157.                        executed.
  19158. `Connections'          Number of connection attempts to the MySQL server.
  19159. `Created_tmp_disk_tables'Number of implicit temporary tables on disk
  19160.                        created while executing statements.
  19161. `Created_tmp_tables'   Number of implicit temporary tables in memory
  19162.                        created while executing statements.
  19163. `Created_tmp_files'    How many temporary files `mysqld' has created.
  19164. `Delayed_insert_threads'Number of delayed insert handler threads in use.
  19165. `Delayed_writes'       Number of rows written with `INSERT DELAYED'.
  19166. `Delayed_errors'       Number of rows written with `INSERT DELAYED' for
  19167.                        which some error occurred (probably `duplicate
  19168.                        key').
  19169. `Flush_commands'       Number of executed `FLUSH' commands.
  19170. `Handler_commit'       Number of internal `COMMIT' commands.
  19171. `Handler_delete'       Number of times a row was deleted from a table.
  19172. `Handler_read_first'   Number of times the first entry was read from an
  19173.                        index.  If this is high, it suggests that the
  19174.                        server is doing a lot of full index scans, for
  19175.                        example, `SELECT col1 FROM foo', assuming that
  19176.                        col1 is indexed.
  19177. `Handler_read_key'     Number of requests to read a row based on a key.
  19178.                        If this is high, it is a good indication that
  19179.                        your queries and tables are properly indexed.
  19180. `Handler_read_next'    Number of requests to read next row in key order.
  19181.                        This will be incremented if you are querying an
  19182.                        index column with a range constraint. This also
  19183.                        will be incremented if you are doing an index
  19184.                        scan.
  19185. `Handler_read_prev'    Number of requests to read previous row in key
  19186.                        order.  This is mainly used to optimise `ORDER BY
  19187.                        ... DESC'.
  19188. `Handler_read_rnd'     Number of requests to read a row based on a fixed
  19189.                        position.  This will be high if you are doing a
  19190.                        lot of queries that require sorting of the result.
  19191. `Handler_read_rnd_next'Number of requests to read the next row in the
  19192.                        datafile.  This will be high if you are doing a
  19193.                        lot of table scans. Generally this suggests that
  19194.                        your tables are not properly indexed or that your
  19195.                        queries are not written to take advantage of the
  19196.                        indexes you have.
  19197. `Handler_rollback'     Number of internal `ROLLBACK' commands.
  19198. `Handler_update'       Number of requests to update a row in a table.
  19199. `Handler_write'        Number of requests to insert a row in a table.
  19200. `Key_blocks_used'      The number of used blocks in the key cache.
  19201. `Key_read_requests'    The number of requests to read a key block from
  19202.                        the cache.
  19203. `Key_reads'            The number of physical reads of a key block from
  19204.                        disk.
  19205. `Key_write_requests'   The number of requests to write a key block to
  19206.                        the cache.
  19207. `Key_writes'           The number of physical writes of a key block to
  19208.                        disk.
  19209. `Max_used_connections' The maximum number of connections in use
  19210.                        simultaneously.
  19211. `Not_flushed_key_blocks'Keys blocks in the key cache that has changed but
  19212.                        hasn't yet been flushed to disk.
  19213. `Not_flushed_delayed_rows'Number of rows waiting to be written in `INSERT
  19214.                        DELAY' queues.
  19215. `Open_tables'          Number of tables that are open.
  19216. `Open_files'           Number of files that are open.
  19217. `Open_streams'         Number of streams that are open (used mainly for
  19218.                        logging).
  19219. `Opened_tables'        Number of tables that have been opened.
  19220. `Rpl_status'           Status of failsafe replication. (Not yet in use).
  19221. `Select_full_join'     Number of joins without keys (If this is not 0,
  19222.                        you should carefully check the indexes of your
  19223.                        tables).
  19224. `Select_full_range_join'Number of joins where we used a range search on
  19225.                        reference table.
  19226. `Select_range'         Number of joins where we used ranges on the first
  19227.                        table. (It's normally not critical even if this
  19228.                        is big.)
  19229. `Select_scan'          Number of joins where we did a full scan of the
  19230.                        first table.
  19231. `Select_range_check'   Number of joins without keys where we check for
  19232.                        key usage after each row (If this is not 0, you
  19233.                        should carefully check the indexes of your
  19234.                        tables).
  19235. `Questions'            Number of queries sent to the server.
  19236. `Slave_open_temp_tables'Number of temporary tables currently open by the
  19237.                        slave thread
  19238. `Slave_running'        Is `ON' if this is a slave that is connected to a
  19239.                        master.
  19240. `Slow_launch_threads'  Number of threads that have taken more than
  19241.                        `slow_launch_time' to create.
  19242. `Slow_queries'         Number of queries that have taken more than
  19243.                        `long_query_time' seconds. *Note Slow query log::.
  19244. `Sort_merge_passes'    Number of merges passes the sort algoritm have
  19245.                        had to do. If this value is large you should
  19246.                        consider increasing `sort_buffer'.
  19247. `Sort_range'           Number of sorts that were done with ranges.
  19248. `Sort_rows'            Number of sorted rows.
  19249. `Sort_scan'            Number of sorts that were done by scanning the
  19250.                        table.
  19251. `ssl_xxx'              Variables used by SSL; Not yet implemented.
  19252. `Table_locks_immediate'Number of times a table lock was acquired
  19253.                        immediately. Available after 3.23.33.
  19254. `Table_locks_waited'   Number of times a table lock could not be
  19255.                        acquired immediately and a wait was needed. If
  19256.                        this is high, and you have performance problems,
  19257.                        you should first optimise your queries, and then
  19258.                        either split your table(s) or use replication.
  19259.                        Available after 3.23.33.
  19260. `Threads_cached'       Number of threads in the thread cache.
  19261. `Threads_connected'    Number of currently open connections.
  19262. `Threads_created'      Number of threads created to handle connections.
  19263. `Threads_running'      Number of threads that are not sleeping.
  19264. `Uptime'               How many seconds the server has been up.
  19265.  
  19266. Some comments about the above:
  19267.  
  19268.    * If `Opened_tables' is big, then your `table_cache' variable is
  19269.      probably too small.
  19270.  
  19271.    * If `Key_reads' is big, then your `key_buffer_size' variable is
  19272.      probably too small.  The *cache miss rate* can be calculated with
  19273.      `Key_reads'/`Key_read_requests'.
  19274.  
  19275.    * If `Handler_read_rnd' is big, then you probably have a lot of
  19276.      queries that require MySQL to scan whole tables or you have joins
  19277.      that don't use keys properly.
  19278.  
  19279.    * If `Threads_created' is big, you may want to increase the
  19280.      `thread_cache_size' variable.  The cache hit rate can be calculated
  19281.      with `Threads_created'/`Connections'.
  19282.  
  19283.    * If `Created_tmp_disk_tables' is big, you may want to increase the
  19284.      `tmp_table_size' variable to get the temporary tables memory-based
  19285.      instead of disk based.
  19286.  
  19287. `SHOW VARIABLES'
  19288. ................
  19289.  
  19290.      SHOW [GLOBAL | SESSION] VARIABLES [LIKE wild]
  19291.  
  19292. `SHOW VARIABLES' shows the values of some MySQL system variables.  The
  19293. options `GLOBAL' and `SESSION' are new in MySQL 4.0.3.  With `GLOBAL'
  19294. you will get the variables that will be used for new connections to
  19295. MySQL. With `SESSION' you will get the values that are in effect for
  19296. the current connection. If you are not using either option, `SESSION'
  19297. is used.
  19298.  
  19299. If the default values are unsuitable, you can set most of these
  19300. variables using command-line options when `mysqld' starts up.  *Note
  19301. Command-line options::. It is also possible to change most variables
  19302. with the `SET' statement.  *Note `SET': SET OPTION.
  19303.  
  19304. The output from `SHOW VARIABLES' resembles that shown in the following
  19305. list, though the format and numbers may differ somewhat.  You can also
  19306. get this information using the `mysqladmin variables' command.
  19307.  
  19308.      +---------------------------------+------------------------------+
  19309.      | Variable_name                   | Value                        |
  19310.      +---------------------------------+------------------------------|
  19311.      | back_log                        | 50                           |
  19312.      | basedir                         | /usr/local/mysql             |
  19313.      | bdb_cache_size                  | 8388572                      |
  19314.      | bdb_log_buffer_size             | 32768                        |
  19315.      | bdb_home                        | /usr/local/mysql             |
  19316.      | bdb_max_lock                    | 10000                        |
  19317.      | bdb_logdir                      |                              |
  19318.      | bdb_shared_data                 | OFF                          |
  19319.      | bdb_tmpdir                      | /tmp/                        |
  19320.      | bdb_version                     | Sleepycat Software: ...      |
  19321.      | binlog_cache_size               | 32768                        |
  19322.      | bulk_insert_buffer_size         | 8388608                      |
  19323.      | character_set                   | latin1                       |
  19324.      | character_sets                  | latin1 big5 czech euc_kr     |
  19325.      | concurrent_insert               | ON                           |
  19326.      | connect_timeout                 | 5                            |
  19327.      | convert_character_set           |                              |
  19328.      | datadir                         | /usr/local/mysql/data/       |
  19329.      | delay_key_write                 | ON                           |
  19330.      | delayed_insert_limit            | 100                          |
  19331.      | delayed_insert_timeout          | 300                          |
  19332.      | delayed_queue_size              | 1000                         |
  19333.      | flush                           | OFF                          |
  19334.      | flush_time                      | 0                            |
  19335.      | ft_boolean_syntax               | + -><()~*:""&|               |
  19336.      | ft_min_word_len                 | 4                            |
  19337.      | ft_max_word_len                 | 254                          |
  19338.      | ft_max_word_len_for_sort        | 20                           |
  19339.      | ft_stopword_file                | (built-in)                   |
  19340.      | have_bdb                        | YES                          |
  19341.      | have_innodb                     | YES                          |
  19342.      | have_isam                       | YES                          |
  19343.      | have_raid                       | NO                           |
  19344.      | have_symlink                    | DISABLED                     |
  19345.      | have_openssl                    | YES                          |
  19346.      | have_query_cache                | YES                          |
  19347.      | init_file                       |                              |
  19348.      | innodb_additional_mem_pool_size | 1048576                      |
  19349.      | innodb_buffer_pool_size         | 8388608                      |
  19350.      | innodb_data_file_path           | ibdata1:10M:autoextend       |
  19351.      | innodb_data_home_dir            |                              |
  19352.      | innodb_file_io_threads          | 4                            |
  19353.      | innodb_force_recovery           | 0                            |
  19354.      | innodb_thread_concurrency       | 8                            |
  19355.      | innodb_flush_log_at_trx_commit  | 1                            |
  19356.      | innodb_fast_shutdown            | ON                           |
  19357.      | innodb_flush_method             |                              |
  19358.      | innodb_lock_wait_timeout        | 50                           |
  19359.      | innodb_log_arch_dir             |                              |
  19360.      | innodb_log_archive              | OFF                          |
  19361.      | innodb_log_buffer_size          | 1048576                      |
  19362.      | innodb_log_file_size            | 5242880                      |
  19363.      | innodb_log_files_in_group       | 2                            |
  19364.      | innodb_log_group_home_dir       | ./                           |
  19365.      | innodb_mirrored_log_groups      | 1                            |
  19366.      | interactive_timeout             | 28800                        |
  19367.      | join_buffer_size                | 131072                       |
  19368.      | key_buffer_size                 | 16773120                     |
  19369.      | language                        | /usr/local/mysql/share/...   |
  19370.      | large_files_support             | ON                           |
  19371.      | local_infile                    | ON                           |
  19372.      | locked_in_memory                | OFF                          |
  19373.      | log                             | OFF                          |
  19374.      | log_update                      | OFF                          |
  19375.      | log_bin                         | OFF                          |
  19376.      | log_slave_updates               | OFF                          |
  19377.      | log_slow_queries                | OFF                          |
  19378.      | log_warnings                    | OFF                          |
  19379.      | long_query_time                 | 10                           |
  19380.      | low_priority_updates            | OFF                          |
  19381.      | lower_case_table_names          | OFF                          |
  19382.      | max_allowed_packet              | 1047552                      |
  19383.      | max_binlog_cache_size           | 4294967295                   |
  19384.      | max_binlog_size                 | 1073741824                   |
  19385.      | max_connections                 | 100                          |
  19386.      | max_connect_errors              | 10                           |
  19387.      | max_delayed_threads             | 20                           |
  19388.      | max_heap_table_size             | 16777216                     |
  19389.      | max_join_size                   | 4294967295                   |
  19390.      | max_relay_log_size              | 0                            |
  19391.      | max_sort_length                 | 1024                         |
  19392.      | max_user_connections            | 0                            |
  19393.      | max_tmp_tables                  | 32                           |
  19394.      | max_write_lock_count            | 4294967295                   |
  19395.      | myisam_max_extra_sort_file_size | 268435456                    |
  19396.      | myisam_repair_threads           | 1                            |
  19397.      | myisam_max_sort_file_size       | 2147483647                   |
  19398.      | myisam_recover_options          | force                        |
  19399.      | myisam_sort_buffer_size         | 8388608                      |
  19400.      | net_buffer_length               | 16384                        |
  19401.      | net_read_timeout                | 30                           |
  19402.      | net_retry_count                 | 10                           |
  19403.      | net_write_timeout               | 60                           |
  19404.      | open_files_limit                | 1024                         |
  19405.      | pid_file                        | /usr/local/mysql/name.pid    |
  19406.      | port                            | 3306                         |
  19407.      | protocol_version                | 10                           |
  19408.      | query_cache_limit               | 1048576                      |
  19409.      | query_cache_size                | 0                            |
  19410.      | query_cache_type                | ON                           |
  19411.      | read_buffer_size                | 131072                       |
  19412.      | read_rnd_buffer_size            | 262144                       |
  19413.      | rpl_recovery_rank               | 0                            |
  19414.      | safe_show_database              | OFF                          |
  19415.      | server_id                       | 0                            |
  19416.      | slave_net_timeout               | 3600                         |
  19417.      | skip_external_locking           | ON                           |
  19418.      | skip_networking                 | OFF                          |
  19419.      | skip_show_database              | OFF                          |
  19420.      | slow_launch_time                | 2                            |
  19421.      | socket                          | /tmp/mysql.sock              |
  19422.      | sort_buffer_size                | 2097116                      |
  19423.      | sql_mode                        |                              |
  19424.      | table_cache                     | 64                           |
  19425.      | table_type                      | MYISAM                       |
  19426.      | thread_cache_size               | 3                            |
  19427.      | thread_stack                    | 131072                       |
  19428.      | tx_isolation                    | READ-COMMITTED               |
  19429.      | timezone                        | EEST                         |
  19430.      | tmp_table_size                  | 33554432                     |
  19431.      | tmpdir                          | /tmp/:/mnt/hd2/tmp/          |
  19432.      | version                         | 4.0.4-beta                   |
  19433.      | wait_timeout                    | 28800                        |
  19434.      +---------------------------------+------------------------------+
  19435.  
  19436. Each option is described here. Values for buffer sizes, lengths, and
  19437. stack sizes are given in bytes.  You can specify values with a suffix
  19438. of `K' or `M' to indicate kilobytes or megabytes. For example, `16M'
  19439. indicates 16 megabytes.  The case of suffix letters does not matter;
  19440. `16M' and `16m' are equivalent:
  19441.  
  19442.    * `ansi_mode'.  Is `ON' if `mysqld' was started with `--ansi'.
  19443.      *Note ANSI mode::.
  19444.  
  19445.    * `back_log' The number of outstanding connection requests MySQL can
  19446.      have. This comes into play when the main MySQL thread gets *very*
  19447.      many connection requests in a very short time. It then takes some
  19448.      time (although very little) for the main thread to check the
  19449.      connection and start a new thread. The `back_log' value indicates
  19450.      how many requests can be stacked during this short time before
  19451.      MySQL momentarily stops answering new requests. You need to
  19452.      increase this only if you expect a large number of connections in
  19453.      a short period of time.
  19454.  
  19455.      In other words, this value is the size of the listen queue for
  19456.      incoming TCP/IP connections.  Your operating system has its own
  19457.      limit on the size of this queue.  The manual page for the Unix
  19458.      `listen(2)' system call should have more details.  Check your OS
  19459.      documentation for the maximum value for this variable.  Attempting
  19460.      to set `back_log' higher than your operating system limit will be
  19461.      ineffective.
  19462.  
  19463.    * `basedir' The value of the `--basedir' option.
  19464.  
  19465.    * `bdb_cache_size' The buffer that is allocated to cache index and
  19466.      rows for `BDB' tables.  If you don't use `BDB' tables, you should
  19467.      start `mysqld' with `--skip-bdb' to not waste memory for this
  19468.      cache.
  19469.  
  19470.    * `bdb_log_buffer_size' The buffer that is allocated to cache index
  19471.      and rows for `BDB' tables.  If you don't use `BDB' tables, you
  19472.      should set this to 0 or start `mysqld' with `--skip-bdb' to not
  19473.      waste memory for this cache.
  19474.  
  19475.    * `bdb_home' The value of the `--bdb-home' option.
  19476.  
  19477.    * `bdb_max_lock' The maximum number of locks (10,000 by default) you
  19478.      can have active on a BDB table. You should increase this if you
  19479.      get errors of type `bdb: Lock table is out of available locks' or
  19480.      `Got error 12 from ...' when you have do long transactions or when
  19481.      `mysqld' has to examine a lot of rows to calculate the query.
  19482.  
  19483.    * `bdb_logdir' The value of the `--bdb-logdir' option.
  19484.  
  19485.    * `bdb_shared_data' Is `ON' if you are using `--bdb-shared-data'.
  19486.  
  19487.    * `bdb_tmpdir' The value of the `--bdb-tmpdir' option.
  19488.  
  19489.    * `binlog_cache_size'.  The size of the cache to hold the SQL
  19490.      statements for the binary log during a transaction.  If you often
  19491.      use big, multi-statement transactions you can increase this to get
  19492.      more performance. *Note COMMIT::.
  19493.  
  19494.    * `bulk_insert_buffer_size' (was `myisam_bulk_insert_tree_size')
  19495.      MyISAM uses special tree-like cache to make bulk inserts (that is,
  19496.      `INSERT ... SELECT', `INSERT ... VALUES (...), (...), ...', and
  19497.      `LOAD DATA INFILE') faster. This variable limits the size of the
  19498.      cache tree in bytes per thread. Setting it to 0 will disable this
  19499.      optimisation.  *Note*: this cache is only used when adding data to
  19500.      non-empty table.  Default value is 8 MB.
  19501.  
  19502.    * `character_set' The default character set.
  19503.  
  19504.    * `character_sets' The supported character sets.
  19505.  
  19506.    * `concurrent_inserts' If `ON' (the default), MySQL will allow you
  19507.      to use `INSERT' on `MyISAM' tables at the same time as you run
  19508.      `SELECT' queries on them.  You can turn this option off by
  19509.      starting `mysqld' with `--safe' or `--skip-new'.
  19510.  
  19511.    * `connect_timeout' The number of seconds the `mysqld' server is
  19512.      waiting for a connect packet before responding with `Bad
  19513.      handshake'.
  19514.  
  19515.    * `datadir' The value of the `--datadir' option.
  19516.  
  19517.    * `delay_key_write' Option for MyISAM tables. Can have one of the
  19518.      following values:
  19519.  
  19520.      OFF                  All `CREATE TABLE ... DELAYED_KEY_WRITE' are
  19521.                           ignored.
  19522.      ON                   (default)  MySQL will honor the
  19523.                           `DELAY_KEY_WRITE' option for `CREATE TABLE'.
  19524.      ALL                  All new opened tables are treated as if they
  19525.                           were created with the `DELAY_KEY_WRITE' option.
  19526.  
  19527.      If `DELAY_KEY_WRITE' is enabled this means that the key buffer for
  19528.      tables with this option will not get flushed on every index
  19529.      update, but only when a table is closed.  This will speed up
  19530.      writes on keys a lot, but you should add automatic checking of all
  19531.      tables with `myisamchk --fast --force' if you use this.
  19532.  
  19533.    * `delayed_insert_limit' After inserting `delayed_insert_limit'
  19534.      rows, the `INSERT DELAYED' handler will check if there are any
  19535.      `SELECT' statements pending. If so, it allows these to execute
  19536.      before continuing.
  19537.  
  19538.    * `delayed_insert_timeout' How long a `INSERT DELAYED' thread should
  19539.      wait for `INSERT' statements before terminating.
  19540.  
  19541.    * `delayed_queue_size' What size queue (in rows) should be allocated
  19542.      for handling `INSERT DELAYED'.  If the queue becomes full, any
  19543.      client that does `INSERT DELAYED' will wait until there is room in
  19544.      the queue again.
  19545.  
  19546.    * `flush' This is `ON' if you have started MySQL with the `--flush'
  19547.      option.
  19548.  
  19549.    * `flush_time' If this is set to a non-zero value, then every
  19550.      `flush_time' seconds all tables will be closed (to free up
  19551.      resources and sync things to disk). We only recommend this option
  19552.      on Windows 9x/Me, or on systems where you have very little
  19553.      resources.
  19554.  
  19555.    * `ft_boolean_syntax' List of operators supported by `MATCH ...
  19556.      AGAINST(... IN BOOLEAN MODE)'.  *Note Fulltext Search::.
  19557.  
  19558.    * `ft_min_word_len' The minimum length of the word to be included in
  19559.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  19560.      after changing this variable.* (This option is new for MySQL 4.0.)
  19561.  
  19562.    * `ft_max_word_len' The maximum length of the word to be included in
  19563.      a `FULLTEXT' index.  *Note: `FULLTEXT' indexes must be rebuilt
  19564.      after changing this variable.* (This option is new for MySQL 4.0.)
  19565.  
  19566.    * `ft_max_word_len_for_sort' The maximum length of the word in a
  19567.      `FULLTEXT' index to be used in fast index recreation method in
  19568.      `REPAIR', `CREATE INDEX',  or `ALTER TABLE'.  Longer words are
  19569.      inserted the slow way.  The rule of the thumb is as follows: with
  19570.      `ft_max_word_len_for_sort' increasing, *MySQL* will create bigger
  19571.      temporary files (thus slowing the process down, due to disk I/O),
  19572.      and will put fewer keys in one sort block (again, decreasing the
  19573.      efficiency).  When `ft_max_word_len_for_sort' is too small,
  19574.      instead, *MySQL* will insert a lot of words into index the slow
  19575.      way, but short words will be inserted very quickly.
  19576.  
  19577.    * `ft_stopword_file' The file from which to read the list of
  19578.      stopwords for full-text searches.  All the words from the file
  19579.      will be used; comments are *not* honored.  By default, built-in
  19580.      list of stopwords is used (as defined in `myisam/ft_static.c').
  19581.      Setting this parameter to an empty string (`""') will disable
  19582.      stopword filtering.  *Note: `FULLTEXT' indexes must be rebuilt
  19583.      after changing this variable.* (This option is new for MySQL
  19584.      4.0.10)
  19585.  
  19586.    * `have_innodb' `YES' if `mysqld' supports InnoDB tables. `DISABLED'
  19587.      if `--skip-innodb' is used.
  19588.  
  19589.    * `have_bdb' `YES' if `mysqld' supports Berkeley DB tables.
  19590.      `DISABLED' if `--skip-bdb' is used.
  19591.  
  19592.    * `have_raid' `YES' if `mysqld' supports the `RAID' option.
  19593.  
  19594.    * `have_openssl' `YES' if `mysqld' supports SSL (encryption) on the
  19595.      client/server protocol.
  19596.  
  19597.    * `init_file' The name of the file specified with the `--init-file'
  19598.      option when you start the server.  This is a file of SQL
  19599.      statements you want the server to execute when it starts.
  19600.  
  19601.    * `interactive_timeout' The number of seconds the server waits for
  19602.      activity on an interactive connection before closing it.  An
  19603.      interactive client is defined as a client that uses the
  19604.      `CLIENT_INTERACTIVE' option to `mysql_real_connect()'.  See also
  19605.      `wait_timeout'.
  19606.  
  19607.    * `join_buffer_size' The size of the buffer that is used for full
  19608.      joins (joins that do not use indexes).  The buffer is allocated
  19609.      one time for each full join between two tables. Increase this
  19610.      value to get a faster full join when adding indexes is not
  19611.      possible. (Normally the best way to get fast joins is to add
  19612.      indexes.)
  19613.  
  19614.    * `key_buffer_size' Index blocks are buffered and are shared by all
  19615.      threads.  `key_buffer_size' is the size of the buffer used for
  19616.      index blocks.
  19617.  
  19618.      Increase this to get better index handling (for all reads and
  19619.      multiple writes) to as much as you can afford; 64M on a 256M
  19620.      machine that mainly runs MySQL is quite common.  If you, however,
  19621.      make this too big (for instance more than 50% of your total
  19622.      memory) your system may start to page and become extremely slow.
  19623.      Remember that because MySQL does not cache data reads, you will
  19624.      have to leave some room for the OS filesystem cache.
  19625.  
  19626.      You can check the performance of the key buffer by doing `SHOW
  19627.      STATUS' and examine the variables `Key_read_requests',
  19628.      `Key_reads', `Key_write_requests', and `Key_writes'.  The
  19629.      `Key_reads/Key_read_request' ratio should normally be < 0.01.  The
  19630.      `Key_write/Key_write_requests' is usually near 1 if you are using
  19631.      mostly updates/deletes but may be much smaller if you tend to do
  19632.      updates that affect many at the same time or if you are using
  19633.      `DELAY_KEY_WRITE'. *Note `SHOW': SHOW.
  19634.  
  19635.      To get even more speed when writing many rows at the same time, use
  19636.      `LOCK TABLES'.  *Note `LOCK TABLES': LOCK TABLES.
  19637.  
  19638.    * `language' The language used for error messages.
  19639.  
  19640.    * `large_file_support' If `mysqld' was compiled with options for big
  19641.      file support.
  19642.  
  19643.    * `locked_in_memory' If `mysqld' was locked in memory with
  19644.      `--memlock'
  19645.  
  19646.    * `log' If logging of all queries is enabled.
  19647.  
  19648.    * `log_update' If the update log is enabled.
  19649.  
  19650.    * `log_bin' If the binary log is enabled.
  19651.  
  19652.    * `log_slave_updates' If the updates from the slave should be logged.
  19653.  
  19654.    * `long_query_time' If a query takes longer than this (in seconds),
  19655.      the `Slow_queries' counter will be incremented. If you are using
  19656.      `--log-slow-queries', the query will be logged to the slow query
  19657.      logfile. This value is measured in real time, not CPU time, so a
  19658.      query that may be under the threshold on a lightly loaded system
  19659.      may be above the threshold on a heavily loaded one.  *Note Slow
  19660.      query log::.
  19661.  
  19662.    * `lower_case_table_names' If set to 1 table names are stored in
  19663.      lowercase on disk and table name comparisons will be
  19664.      case-insensitive.  From version 4.0.2, this option also applies to
  19665.      database names.  From 4.1.1 this option also applies to table
  19666.      alias.  *Note Name case sensitivity::.
  19667.  
  19668.    * `max_allowed_packet' The maximum size of one packet. The message
  19669.      buffer is initialised to `net_buffer_length' bytes, but can grow
  19670.      up to `max_allowed_packet' bytes when needed.  This value by
  19671.      default is small, to catch big (possibly wrong) packets.  You must
  19672.      increase this value if you are using big `BLOB' columns. It should
  19673.      be as big as the biggest `BLOB' you want to use.  The protocol
  19674.      limits for `max_allowed_packet' is 16M in MySQL 3.23 and 1G in
  19675.      MySQL 4.0.
  19676.  
  19677.    * `max_binlog_cache_size' If a multi-statement transaction requires
  19678.      more than this amount of memory, one will get the error
  19679.      "Multi-statement transaction required more than
  19680.      'max_binlog_cache_size' bytes of storage".
  19681.  
  19682.    * `max_binlog_size' Available after 3.23.33. If a write to the
  19683.      binary (replication) log exceeds the given value, rotate the logs.
  19684.      You cannot set it to less than 4096 bytes (1024 in MySQL versions
  19685.      older than 4.0.14), or more than 1 GB. Default is 1 GB. Note if
  19686.      you are using transactions: a transaction is written in one chunk
  19687.      to the binary log, hence it is never split between several binary
  19688.      logs. Therefore, if you have big transactions, you may see binlogs
  19689.      bigger than `max_binlog_size'. If `max_relay_log_size' (available
  19690.      starting from MySQL 4.0.14) is 0, then `max_binlog_size' will
  19691.      apply to relay logs as well.
  19692.  
  19693.    * `max_connections' The number of simultaneous clients allowed.
  19694.      Increasing this value increases the number of file descriptors
  19695.      that `mysqld' requires.  See below for comments on file descriptor
  19696.      limits. *Note Too many connections::.
  19697.  
  19698.    * `max_connect_errors' If there is more than this number of
  19699.      interrupted connections from a host this host will be blocked from
  19700.      further connections.  You can unblock a host with the command
  19701.      `FLUSH HOSTS'.
  19702.  
  19703.    * `max_delayed_threads' Don't start more than this number of threads
  19704.      to handle `INSERT DELAYED' statements.  If you try to insert data
  19705.      into a new table after all `INSERT DELAYED' threads are in use,
  19706.      the row will be inserted as if the `DELAYED' attribute wasn't
  19707.      specified. If you set this to 0, MySQL will never create a
  19708.      max_delayed thread.
  19709.  
  19710.    * `max_heap_table_size' Don't allow creation of heap tables bigger
  19711.      than this.
  19712.  
  19713.    * `max_join_size' Joins that are probably going to read more than
  19714.      `max_join_size' records return an error. Set this value if your
  19715.      users tend to perform joins that lack a `WHERE' clause, that take
  19716.      a long time, and that return millions of rows.
  19717.  
  19718.    * `max_relay_log_size' Available starting from 4.0.14. If a write to
  19719.      the relay log (a kind of log used by replication slaves, *note
  19720.      Replication Implementation Details::) exceeds the given value,
  19721.      rotate the relay log.  This variable enables you to put different
  19722.      size constraints on relay logs and binary logs.  However, setting
  19723.      the variable to 0 will make MySQL use `max_binlog_size' for both
  19724.      binary logs and relay logs.  You have to set `max_relay_log_size'
  19725.      to 0 or more than 4096, and less than 1 GB. Default is 0.
  19726.  
  19727.    * `max_seeks_for_key' Limit assumed max number of seeks when looking
  19728.      up rows based on a key.  The MySQL optimiser will assume that when
  19729.      searching after matching rows in a table through scanning a key,
  19730.      we will not cause more than this number of key seeks independent
  19731.      of the cardinality of the key.  By setting this to a low value
  19732.      (100 ?) you can force MySQL to prefer keys instead of table scans.
  19733.  
  19734.    * `max_sort_length' The number of bytes to use when sorting `BLOB'
  19735.      or `TEXT' values (only the first `max_sort_length' bytes of each
  19736.      value are used; the rest are ignored).
  19737.  
  19738.    * `max_user_connections' The maximum number of active connections
  19739.      for a single user (0 = no limit).
  19740.  
  19741.    * `max_tmp_tables' (This option doesn't yet do anything.)  Maximum
  19742.      number of temporary tables a client can keep open at the same time.
  19743.  
  19744.    * `max_write_lock_count' After this many write locks, allow some
  19745.      read locks to run in between.
  19746.  
  19747.    * `myisam_recover_options' The value of the `--myisam-recover'
  19748.      option.
  19749.  
  19750.    * `myisam_sort_buffer_size' The buffer that is allocated when
  19751.      sorting the index when doing a `REPAIR' or when creating indexes
  19752.      with `CREATE INDEX' or `ALTER TABLE'.
  19753.  
  19754.    * `myisam_max_extra_sort_file_size'.  If the temporary file used for
  19755.      fast index creation would be bigger than using the key cache by
  19756.      the amount specified here, then prefer the key cache method.  This
  19757.      is mainly used to force long character keys in large tables to use
  19758.      the slower key cache method to create the index.  *Note* that this
  19759.      parameter is given in megabytes before 4.0.3 and in bytes
  19760.      beginning with this version.
  19761.  
  19762.    * `myisam_repair_threads'.  If this value is greater than one,
  19763.      MyISAM table indexes during `Repair by sorting' process will be
  19764.      created in parallel - each index in its own thread. *Note:*
  19765.      multi-threaded repair is still *alpha* quality code.
  19766.  
  19767.    * `myisam_max_sort_file_size' The maximum size of the temporary file
  19768.      MySQL is allowed to use while recreating the index (during
  19769.      `REPAIR', `ALTER TABLE' or `LOAD DATA INFILE'.  If the file-size
  19770.      would be bigger than this, the index will be created through the
  19771.      key cache (which is slower).  *Note* that this parameter is given
  19772.      in megabytes before 4.0.3 and in bytes beginning with this version.
  19773.  
  19774.    * `net_buffer_length' The communication buffer is reset to this size
  19775.      between queries. This should not normally be changed, but if you
  19776.      have very little memory, you can set it to the expected size of a
  19777.      query.  (That is, the expected length of SQL statements sent by
  19778.      clients.  If statements exceed this length, the buffer is
  19779.      automatically enlarged, up to `max_allowed_packet' bytes.)
  19780.  
  19781.    * `net_read_timeout' Number of seconds to wait for more data from a
  19782.      connection before aborting the read.  Note that when we don't
  19783.      expect data from a connection, the timeout is defined by
  19784.      `write_timeout'. See also `slave_net_timeout'.
  19785.  
  19786.    * `net_retry_count' If a read on a communication port is
  19787.      interrupted, retry this many times before giving up.  This value
  19788.      should be quite high on `FreeBSD' as internal interrupts are sent
  19789.      to all threads.
  19790.  
  19791.    * `net_write_timeout' Number of seconds to wait for a block to be
  19792.      written to a connection before aborting the write.
  19793.  
  19794.    * `open_files_limit' Number of files the system allows mysqld to
  19795.      open.  This is the real value given for the system and may be
  19796.      different from the value you gave mysqld as a startup parameter.
  19797.      This is 0 on systems where MySQL can't change the number of open
  19798.      files.
  19799.  
  19800.    * `pid_file' The value of the `--pid-file' option.
  19801.  
  19802.    * `port' The value of the `--port' option.
  19803.  
  19804.    * `protocol_version' The protocol version used by the MySQL server.
  19805.  
  19806.    * `range_alloc_block_size' Size of blocks that are allocated when
  19807.      doing range optimization.
  19808.  
  19809.    * `read_buffer_size' (was `record_buffer') Each thread that does a
  19810.      sequential scan allocates a buffer of this size for each table it
  19811.      scans. If you do many sequential scans, you may want to increase
  19812.      this value.
  19813.  
  19814.    * `read_rnd_buffer_size' (was `record_rnd_buffer') When reading rows
  19815.      in sorted order after a sort, the rows are read through this
  19816.      buffer to avoid a disk seeks.  Can improve `ORDER BY' by a lot if
  19817.      set to a high value.  As this is a thread-specific variable, one
  19818.      should not set this big globally, but just change this when running
  19819.      some specific big queries.
  19820.  
  19821.    * `query_alloc_block_size' Size of memory allocation blocks that are
  19822.      allocated for objects created during query parsing and execution.
  19823.      If you have problem with memory fragmentation it may help
  19824.      increasing this a bit.
  19825.  
  19826.    * `query_cache_limit' Don't cache results that are bigger than this.
  19827.      (Default 1M).
  19828.  
  19829.    * `query_cache_size' The memory allocated to store results from old
  19830.      queries.  If this is 0, the query cache is disabled (default).
  19831.  
  19832.    * `query_cache_type' This may be set (only numeric) to
  19833.      *Value**Alias*   *Comment*
  19834.      0      OFF       Don't cache or retrieve results.
  19835.      1      ON        Cache all results except `SELECT SQL_NO_CACHE
  19836.                       ...' queries.
  19837.      2      DEMAND    Cache only `SELECT SQL_CACHE ...' queries.
  19838.  
  19839.    * `query_prealloc_size' Persistent buffer for query parsing and
  19840.      execution.  This one is not freed between queries.  In theory, by
  19841.      making this "big enough", make MySQL run queries without having to
  19842.      do a single `malloc()' call.
  19843.  
  19844.    * `safe_show_database' Don't show databases for which the user
  19845.      doesn't have any database or table privileges. This can improve
  19846.      security if you're concerned about people being able to see what
  19847.      databases other users have. See also `skip_show_database'.
  19848.  
  19849.    * `server_id' The value of the `--server-id' option.
  19850.  
  19851.    * `skip_locking' Is OFF if `mysqld' uses external locking.
  19852.  
  19853.    * `skip_networking' Is ON if we only allow local (socket)
  19854.      connections.
  19855.  
  19856.    * `skip_show_database' This prevents people from doing `SHOW
  19857.      DATABASES' if they don't have the `PROCESS' privilege. This can
  19858.      improve security if you're concerned about people being able to
  19859.      see what databases other users have. See also `safe_show_database'.
  19860.  
  19861.    * `slave_net_timeout' Number of seconds to wait for more data from a
  19862.      master/slave connection before aborting the read.
  19863.  
  19864.    * `slow_launch_time' If creating the thread takes longer than this
  19865.      value (in seconds), the `Slow_launch_threads' counter will be
  19866.      incremented.
  19867.  
  19868.    * `socket' The Unix socket used by the server.
  19869.  
  19870.    * `sort_buffer_size' Each thread that needs to do a sort allocates a
  19871.      buffer of this size. Increase this value for faster `ORDER BY' or
  19872.      `GROUP BY' operations.  *Note Temporary files::.
  19873.  
  19874.    * `table_cache' The number of open tables for all threads.
  19875.      Increasing this value increases the number of file descriptors
  19876.      that `mysqld' requires.  You can check if you need to increase the
  19877.      table cache by checking the `Opened_tables' variable.  *Note
  19878.      `Opened_tables': SHOW STATUS.  If this variable is big and you
  19879.      don't do `FLUSH TABLES' a lot (which just forces all tables to be
  19880.      closed and reopenend), then you should increase the value of this
  19881.      variable.
  19882.  
  19883.      For more information about the table cache, see *Note Table
  19884.      cache::.
  19885.  
  19886.    * `table_type' The default table type.
  19887.  
  19888.    * `thread_cache_size' How many threads we should keep in a cache for
  19889.      reuse.  When a client disconnects, the client's threads are put in
  19890.      the cache if there aren't more than `thread_cache_size' threads
  19891.      from before.  All new threads are first taken from the cache, and
  19892.      only when the cache is empty is a new thread created.  This
  19893.      variable can be increased to improve performance if you have a lot
  19894.      of new connections. (Normally this doesn't give a notable
  19895.      performance improvement if you have a good thread implementation.)
  19896.      By examing the difference between the `Connections' and
  19897.      `Threads_created' status variables (*note `SHOW STATUS': SHOW
  19898.      STATUS. for details) you can see how efficient thread cache is.
  19899.  
  19900.    * `thread_concurrency' On Solaris, `mysqld' will call
  19901.      `thr_setconcurrency()' with this value.  `thr_setconcurrency()'
  19902.      permits the application to give the threads system a hint for the
  19903.      desired number of threads that should be run at the same time.
  19904.  
  19905.    * `thread_stack' The stack size for each thread.  Many of the limits
  19906.      detected by the `crash-me' test are dependent on this value. The
  19907.      default is large enough for normal operation.  *Note MySQL
  19908.      Benchmarks::.
  19909.  
  19910.    * `timezone' The timezone for the server.
  19911.  
  19912.    * `tmp_table_size' If an in-memory temporary table exceeds this
  19913.      size, MySQL will automatically convert it to an on-disk `MyISAM'
  19914.      table.  Increase the value of `tmp_table_size' if you do many
  19915.      advanced `GROUP BY' queries and you have lots of memory.
  19916.  
  19917.    * `tmpdir' The directory used for temporary files and temporary
  19918.      tables.  Starting from MySQL 4.1, it can be set to a list of paths
  19919.      separated by colon `:' (semicolon `;' on Windows). They will be
  19920.      used in round-robin fashion. This feature can be used to spread
  19921.      load between several physical disks.  It is possible to set
  19922.      `tmpdir' to point to a memory-based filesystem, except if the
  19923.      MySQL server is a slave. If it is a slave, it needs some of its
  19924.      temporary files (for replication of temporary tables or of `LOAD
  19925.      DATA INFILE') to survive a machine's reboot, so a memory-based
  19926.      `tmpdir' which is cleared when the machine reboots is not
  19927.      suitable; a disk-based `tmpdir' is necessary.
  19928.  
  19929.    * `transaction_alloc_block_size' Size of memory allocation blocks
  19930.      that are allocated for storing queries that are part of a
  19931.      transaction that are to be stored in the binary log when doing a
  19932.      commit.
  19933.  
  19934.    * `transaction_prealloc_block_size' Persistent buffer for
  19935.      `transaction_alloc_blocks'. that are not freed between queries. By
  19936.      making this "big enough" to fit all queries in a common
  19937.      transaction you can avoid a lot of `malloc()' calls.
  19938.  
  19939.    * `version' The version number for the server.
  19940.  
  19941.    * `wait_timeout' The number of seconds the server waits for activity
  19942.      on a not interactive connection before closing it.
  19943.  
  19944.      On thread startup `SESSION.WAIT_TIMEOUT' is initialised from
  19945.      `GLOBAL.WAIT_TIMEOUT' or `GLOBAL.INTERACTIVE_TIMEOUT' depending on
  19946.      the type of client (as defined by the `CLIENT_INTERACTIVE' connect
  19947.      option). See also `interactive_timeout'.
  19948.  
  19949. The manual section that describes tuning MySQL contains some
  19950. information of how to tune the above variables. *Note Server
  19951. parameters::.
  19952.  
  19953. `SHOW [BDB] LOGS'
  19954. .................
  19955.  
  19956. `SHOW LOGS' shows you status information about existing log files.  It
  19957. currently only displays information about Berkeley DB log files, so an
  19958. alias for it (available as of MySQL 4.1.1) is `SHOW BDB LOGS'.
  19959.  
  19960.    * `File' shows the full path to the log file
  19961.  
  19962.    * `Type' shows the type of the log file (`BDB' for Berkeley DB log
  19963.      files)
  19964.  
  19965.    * `Status' shows the status of the log file (`FREE' if the file can
  19966.      be removed, or `IN USE' if the file is needed by the transaction
  19967.      subsystem)
  19968.  
  19969. `SHOW PROCESSLIST'
  19970. ..................
  19971.  
  19972. `SHOW [FULL] PROCESSLIST' shows you which threads are running.  You can
  19973. also get this information using the `mysqladmin processlist' command.
  19974. If you have the `SUPER' privilege, you can see all threads.  Otherwise,
  19975. you can see only your own threads.  *Note `KILL': KILL.  If you don't
  19976. use the `FULL' option, then only the first 100 characters of each query
  19977. will be shown.
  19978.  
  19979. Starting from 4.0.12, MySQL reports the hostname for TCP/IP connections
  19980. as `hostname:client_port' to make it easier to find out which client is
  19981. doing what.
  19982.  
  19983. This command is very useful if you get the 'too many connections' error
  19984. message and want to find out what's going on. MySQL reserves one extra
  19985. connection for a client with the `SUPER' privilege to ensure that you
  19986. should always be able to login and check the system (assuming you are
  19987. not giving this privilege to all your users).
  19988.  
  19989. Some states commonly seen in `mysqladmin processlist'
  19990.  
  19991.    * `Checking table' The thread is performing [automatic] checking of
  19992.      the table.
  19993.  
  19994.    * `Closing tables' Means that the thread is flushing the changed
  19995.      table data to disk and closing the used tables. This should be a
  19996.      fast operation.  If not, then you should check that you don't have
  19997.      a full disk or that the disk is not in very heavy use.
  19998.  
  19999.    * `Connect Out' Slave connecting to master.
  20000.  
  20001.    * `Copying to tmp table on disk' The temporary result set was larger
  20002.      than `tmp_table_size' and the thread is now changing the in
  20003.      memory-based temporary table to a disk based one to save memory.
  20004.  
  20005.    * `Creating tmp table' The thread is creating a temporary table to
  20006.      hold a part of the result for the query.
  20007.  
  20008.    * `deleting from main table' When executing the first part of a
  20009.      multi-table delete and we are only deleting from the first table.
  20010.  
  20011.    * `deleting from reference tables' When executing the second part of
  20012.      a multi-table delete and we are deleting the matched rows from the
  20013.      other tables.
  20014.  
  20015.    * `Flushing tables' The thread is executing `FLUSH TABLES' and is
  20016.      waiting for all threads to close their tables.
  20017.  
  20018.    * `Killed' Someone has sent a kill to the thread and it should abort
  20019.      next time it checks the kill flag.  The flag is checked in each
  20020.      major loop in MySQL, but in some cases it may still take a short
  20021.      time for the thread to die.  If the thread is locked by some other
  20022.      thread, the kill will take effect as soon as the other thread
  20023.      releases its lock.
  20024.  
  20025.    * `Sending data' The thread is processing rows for a `SELECT'
  20026.      statement and is also sending data to the client.
  20027.  
  20028.    * `Sorting for group' The thread is doing a sort to satisfy a `GROUP
  20029.      BY'.
  20030.  
  20031.    * `Sorting for order' The thread is doing a sort to satisfy a `ORDER
  20032.      BY'.
  20033.  
  20034.    * `Opening tables' This simply means that the thread is trying to
  20035.      open a table. This is should be very fast procedure, unless
  20036.      something prevents opening. For example an `ALTER TABLE' or a
  20037.      `LOCK TABLE' can prevent opening a table until the command is
  20038.      finished.
  20039.  
  20040.    * `Removing duplicates' The query was using `SELECT DISTINCT' in
  20041.      such a way that MySQL couldn't optimise that distinct away at an
  20042.      early stage. Because of this MySQL has to do an extra stage to
  20043.      remove all duplicated rows before sending the result to the client.
  20044.  
  20045.    * `Reopen table' The thread got a lock for the table, but noticed
  20046.      after getting the lock that the underlying table structure
  20047.      changed. It has freed the lock, closed the table and is now trying
  20048.      to reopen it.
  20049.  
  20050.    * `Repair by sorting' The repair code is using sorting to create
  20051.      indexes.
  20052.  
  20053.    * `Repair with keycache' The repair code is using creating keys one
  20054.      by one through the key cache.  This is much slower than `Repair by
  20055.      sorting'.
  20056.  
  20057.    * `Searching rows for update' The thread is doing a first phase to
  20058.      find all matching rows before updating them.  This has to be done
  20059.      if the `UPDATE' is changing the index that is used to find the
  20060.      involved rows.
  20061.  
  20062.    * `Sleeping' The thread is wating for the client to send a new
  20063.      command to it.
  20064.  
  20065.    * `System lock' The thread is waiting for getting to get a external
  20066.      system lock for the table. If you are not using multiple mysqld
  20067.      servers that are accessing the same tables, you can disable system
  20068.      locks with the `--skip-external-locking' option.
  20069.  
  20070.    * `Upgrading lock' The `INSERT DELAYED' handler is trying to get a
  20071.      lock for the table to insert rows.
  20072.  
  20073.    * `Updating' The thread is searching for rows to update and updating
  20074.      them.
  20075.  
  20076.    * `User Lock' The thread is waiting on a `GET_LOCK()'.
  20077.  
  20078.    * `Waiting for tables' The thread got a notification that the
  20079.      underlying structure for a table has changed and it needs to
  20080.      reopen the table to get the new structure.  To be able to reopen
  20081.      the table it must however wait until all other threads have closed
  20082.      the table in question.
  20083.  
  20084.      This notification happens if another thread has used `FLUSH TABLES'
  20085.      or one of the following commands on the table in question: `FLUSH
  20086.      TABLES table_name', `ALTER TABLE', `RENAME TABLE', `REPAIR TABLE',
  20087.      `ANALYZE TABLE' or `OPTIMIZE TABLE'.
  20088.  
  20089.    * `waiting for handler insert' The `INSERT DELAYED' handler has
  20090.      processed all inserts and are waiting to get new ones.
  20091.  
  20092. Most states are very quick operations. If threads last in any of these
  20093. states for many seconds, there may be a problem around that needs to be
  20094. investigated.
  20095.  
  20096. There are some other states that are not mentioned previously, but most
  20097. of these are only useful to find bugs in `mysqld'.
  20098.  
  20099. `SHOW GRANTS'
  20100. .............
  20101.  
  20102. `SHOW GRANTS FOR user' lists the grant commands that must be issued to
  20103. duplicate the grants for a user.
  20104.  
  20105.      mysql> SHOW GRANTS FOR root@localhost;
  20106.      +---------------------------------------------------------------------+
  20107.      | Grants for root@localhost                                           |
  20108.      +---------------------------------------------------------------------+
  20109.      | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  20110.      +---------------------------------------------------------------------+
  20111.  
  20112. To list grants for the current session one may use `CURRENT_USER()'
  20113. function (new in version 4.0.6) to find out what user the session was
  20114. authenticated as.  *Note `CURRENT_USER()': Miscellaneous functions.
  20115.  
  20116. `SHOW CREATE TABLE'
  20117. ...................
  20118.  
  20119. Shows a `CREATE TABLE' statement that will create the given table:
  20120.  
  20121.      mysql> SHOW CREATE TABLE t\G
  20122.      *************************** 1. row ***************************
  20123.             Table: t
  20124.      Create Table: CREATE TABLE t (
  20125.        id INT(11) default NULL auto_increment,
  20126.        s char(60) default NULL,
  20127.        PRIMARY KEY (id)
  20128.      ) TYPE=MyISAM
  20129.  
  20130. `SHOW CREATE TABLE' will quote table and column names according to
  20131. `SQL_QUOTE_SHOW_CREATE' option.  *Note `SET SQL_QUOTE_SHOW_CREATE': SET
  20132. OPTION.
  20133.  
  20134. `SHOW WARNINGS | ERRORS'
  20135. ........................
  20136.  
  20137.      SHOW WARNINGS [LIMIT row_count]
  20138.      SHOW ERRORS [LIMIT row_count]
  20139.  
  20140. This command is implemented in MySQL 4.1.0.
  20141.  
  20142. It shows the errors, warnings and notes that one got for the last
  20143. command.  The errors/warnings are reset for each new command that uses
  20144. a table.
  20145.  
  20146. The MySQL server sends back the total number of warnings and errors you
  20147. got for the last commend; This can be retrieved by calling
  20148. `mysql_warning_count()'.
  20149.  
  20150. Up to `max_error_count' messages are stored (Global and thread specific
  20151. variable).
  20152.  
  20153. You can retrieve the number of errors from `@error_count' and warnings
  20154. from `@warning_count'.
  20155.  
  20156. `SHOW WARNINGS' shows all errors, warnings and notes you got for the
  20157. last command while `SHOW ERRORS' only shows you the errors.
  20158.  
  20159.      mysql> DROP TABLE IF EXISTS no_such_table;
  20160.      mysql> SHOW WARNINGS;
  20161.      
  20162.      +-------+------+-------------------------------+
  20163.      | Level | Code | Message                       |
  20164.      +-------+------+-------------------------------+
  20165.      | Note  | 1051 | Unknown table 'no_such_table' |
  20166.      +-------+------+-------------------------------+
  20167.  
  20168. Note that in MySQL 4.1.0 we have just added the frame work for warnings
  20169. and not many MySQL command do yet generate warnings.  4.1.1 supports all
  20170. kind of warnings for `LOAD DATA INFILE' and DML statements such as
  20171. `INSERT', `UPDATE' and `ALTER' commands.
  20172.  
  20173. For example, here is a simple case which produces conversion warnings
  20174. for a insert statement.
  20175.  
  20176.      mysql> create table t1(a tinyint NOT NULL, b char(4));
  20177.      Query OK, 0 rows affected (0.00 sec)
  20178.      
  20179.      mysql> insert into t1 values(10,'mysql'),(NULL,'test'),(300,'open source');
  20180.      Query OK, 3 rows affected, 4 warnings (0.15 sec)
  20181.      Records: 3  Duplicates: 0  Warnings: 4
  20182.      
  20183.      mysql> show warnings;
  20184.      +---------+------+---------------------------------------------------------------+
  20185.      | Level   | Code | Message                                                       |
  20186.      +---------+------+---------------------------------------------------------------+
  20187.      | Warning | 1263 | Data truncated for column 'b' at row 1                        |
  20188.      | Warning | 1261 | Data truncated, NULL supplied to NOT NULL column 'a' at row 2 |
  20189.      | Warning | 1262 | Data truncated, out of range for column 'a' at row 3          |
  20190.      | Warning | 1263 | Data truncated for column 'b' at row 3                        |
  20191.      +---------+------+---------------------------------------------------------------+
  20192.      4 rows in set (0.00 sec)
  20193.  
  20194. Maximum number of warnings can be specified using the server variable
  20195. `'max_error_count'', `SET max_error_count=[count]'; By default it is
  20196. 64. In case to disable warnings, simply reset this variable to '0'. In
  20197. case if `max_error_count' is 0, then still the warning count represents
  20198. how many warnings have occurred, but none of the messages are stored.
  20199.  
  20200. For example, consider the following `ALTER' table statement for the
  20201. above example, which returns only one warning message even though total
  20202. warnings occurred is 3 when you set max_error_count=1.
  20203.  
  20204.      mysql> show variables like 'max_error_count';
  20205.      +-----------------+-------+
  20206.      | Variable_name   | Value |
  20207.      +-----------------+-------+
  20208.      | max_error_count | 64    |
  20209.      +-----------------+-------+
  20210.      1 row in set (0.00 sec)
  20211.      
  20212.      mysql> set max_error_count=1;
  20213.      Query OK, 0 rows affected (0.00 sec)
  20214.      
  20215.      mysql> alter table t1 modify b char;
  20216.      Query OK, 3 rows affected, 3 warnings (0.00 sec)
  20217.      Records: 3  Duplicates: 0  Warnings: 3
  20218.      
  20219.      mysql> show warnings;
  20220.      +---------+------+----------------------------------------+
  20221.      | Level   | Code | Message                                |
  20222.      +---------+------+----------------------------------------+
  20223.      | Warning | 1263 | Data truncated for column 'b' at row 1 |
  20224.      +---------+------+----------------------------------------+
  20225.      1 row in set (0.00 sec)
  20226.      
  20227.      mysql>
  20228.  
  20229. `SHOW TABLE TYPES'
  20230. ..................
  20231.  
  20232.      SHOW TABLE TYPES
  20233.  
  20234. This command is implemented in MySQL 4.1.0.
  20235.  
  20236. `SHOW TABLE TYPES' shows you status information about the table types.
  20237. This is particulary useful for checking if a table type is supported;
  20238. or to see what is the default table type is.
  20239.  
  20240.      mysql> SHOW TABLE TYPES;
  20241.      
  20242.      +--------+---------+-----------------------------------------------------------+
  20243.      | Type   | Support | Comment                                                   |
  20244.      +--------+---------+-----------------------------------------------------------+
  20245.      | MyISAM | DEFAULT | Default type from 3.23 with great performance             |
  20246.      | HEAP   | YES     | Hash based, stored in memory, useful for temporary tables |
  20247.      | MERGE  | YES     | Collection of identical MyISAM tables                     |
  20248.      | ISAM   | YES     | Obsolete table type; Is replaced by MyISAM                |
  20249.      | InnoDB | YES     | Supports transactions, row-level locking and foreign keys |
  20250.      | BDB    | NO      | Supports transactions and page-level locking              |
  20251.      +--------+---------+-----------------------------------------------------------+
  20252.      6 rows in set (0.00 sec)
  20253.  
  20254. The 'Support' option `DEFAULT' indicates whether the particular table
  20255. type is supported, and which is the default type. If the server is
  20256. started with `--default-table-type=InnoDB', then the InnoDB 'Support'
  20257. field will have the value `DEFAULT'.
  20258.  
  20259. `SHOW PRIVILEGES'
  20260. .................
  20261.  
  20262.      SHOW PRIVILEGES
  20263.  
  20264. This command is implemented in MySQL 4.1.0.
  20265.  
  20266. `SHOW PRIVILEGES' shows the list of system privileges that the
  20267. underlying MySQL server supports.
  20268.  
  20269.      mysql> show privileges;
  20270.      +------------+--------------------------+-------------------------------------------------------+
  20271.      | Privilege  | Context                  | Comment                                               |
  20272.      +------------+--------------------------+-------------------------------------------------------+
  20273.      | Select     | Tables                   | To retrieve rows from table                           |
  20274.      | Insert     | Tables                   | To insert data into tables                            |
  20275.      | Update     | Tables                   | To update existing rows                               |
  20276.      | Delete     | Tables                   | To delete existing rows                               |
  20277.      | Index      | Tables                   | To create or drop indexes                             |
  20278.      | Alter      | Tables                   | To alter the table                                    |
  20279.      | Create     | Databases,Tables,Indexes | To create new databases and tables                    |
  20280.      | Drop       | Databases,Tables         | To drop databases and tables                          |
  20281.      | Grant      | Databases,Tables         | To give to other users those privileges you possess   |
  20282.      | References | Databases,Tables         | To have references on tables                          |
  20283.      | Reload     | Server Admin             | To reload or refresh tables, logs and privileges      |
  20284.      | Shutdown   | Server Admin             | To shutdown the server                                |
  20285.      | Process    | Server Admin             | To view the plain text of currently executing queries |
  20286.      | File       | File access on server    | To read and write files on the server                 |
  20287.      +------------+--------------------------+-------------------------------------------------------+
  20288.      14 rows in set (0.00 sec)
  20289.  
  20290. MySQL Localisation and International Usage
  20291. ==========================================
  20292.  
  20293. The Character Set Used for Data and Sorting
  20294. -------------------------------------------
  20295.  
  20296. By default, MySQL uses the ISO-8859-1 (Latin1) character set with
  20297. sorting according to Swedish/Finnish. This is the character set suitable
  20298. in the USA and western Europe.
  20299.  
  20300. All standard MySQL binaries are compiled with
  20301. `--with-extra-charsets=complex'.  This will add code to all standard
  20302. programs to be able to handle `latin1' and all multi-byte character
  20303. sets within the binary. Other character sets will be loaded from a
  20304. character-set definition file when needed.
  20305.  
  20306. The character set determines what characters are allowed in names and
  20307. how things are sorted by the `ORDER BY' and `GROUP BY' clauses of the
  20308. `SELECT' statement.
  20309.  
  20310. You can change the character set with the `--default-character-set'
  20311. option when you start the server.  The character sets available depend
  20312. on the `--with-charset=charset' and `--with-extra-charsets=
  20313. list-of-charset | complex | all | none' options to `configure', and the
  20314. character set configuration files listed in `SHAREDIR/charsets/Index'.
  20315. *Note configure options::.
  20316.  
  20317. If you change the character set when running MySQL (which may also
  20318. change the sort order), you must run `myisamchk -r -q
  20319. --set-character-set=charset' on all tables. Otherwise, your indexes may
  20320. not be ordered correctly.
  20321.  
  20322. When a client connects to a MySQL server, the server sends the default
  20323. character set in use to the client.  The client will switch to use this
  20324. character set for this connection.
  20325.  
  20326. One should use `mysql_real_escape_string()' when escaping strings for
  20327. an SQL query.  `mysql_real_escape_string()' is identical to the old
  20328. `mysql_escape_string()' function, except that it takes the `MYSQL'
  20329. connection handle as the first parameter.
  20330.  
  20331. If the client is compiled with different paths than where the server is
  20332. installed and the user who configured MySQL didn't include all
  20333. character sets in the MySQL binary, one must specify for the client
  20334. where it can find the additional character sets it will need if the
  20335. server runs with a different character set than the client.
  20336.  
  20337. One can specify this by putting in a MySQL option file:
  20338.  
  20339.      [client]
  20340.      character-sets-dir=/usr/local/mysql/share/mysql/charsets
  20341.  
  20342. where the path points to the directory in which the dynamic MySQL
  20343. character sets are stored.
  20344.  
  20345. One can force the client to use specific character set by specifying:
  20346.  
  20347.      [client]
  20348.      default-character-set=character-set-name
  20349.  
  20350. but normally this is never needed.
  20351.  
  20352. German character set
  20353. ....................
  20354.  
  20355. To get German sorting order, you should start `mysqld' with
  20356. `--default-character-set=latin1_de'.  This will give you the following
  20357. characteristics.
  20358.  
  20359. When sorting and comparing strings, the following mapping is done on the
  20360. strings before doing the comparison:
  20361.  
  20362.      a"  ->  ae
  20363.      o"  ->  oe
  20364.      u"  ->  ue
  20365.      ss  ->  ss
  20366.  
  20367. All accented characters, are converted to their un-accented uppercase
  20368. counterpart.  All letters are converted to uppercase.
  20369.  
  20370. When comparing strings with `LIKE' the one -> two character mapping is
  20371. not done. All letters are converted to uppercase. Accent are removed
  20372. from all letters except: `U"', `u"', `O"', `o"', `A"' and `a"'.
  20373.  
  20374. Non-English Error Messages
  20375. --------------------------
  20376.  
  20377. `mysqld' can issue error messages in the following languages: Czech,
  20378. Danish, Dutch, English (the default), Estonian, French, German, Greek,
  20379. Hungarian, Italian, Japanese, Korean, Norwegian, Norwegian-ny, Polish,
  20380. Portuguese, Romanian, Russian, Slovak, Spanish, and Swedish.
  20381.  
  20382. To start `mysqld' with a particular language, use either the
  20383. `--language=lang' or `-L lang' options. For example:
  20384.  
  20385.      shell> mysqld --language=swedish
  20386.  
  20387. or:
  20388.  
  20389.      shell> mysqld --language=/usr/local/share/swedish
  20390.  
  20391. Note that all language names are specified in lowercase.
  20392.  
  20393. The language files are located (by default) in
  20394. `MYSQL_BASE_DIR/share/LANGUAGE/'.
  20395.  
  20396. To update the error message file, you should edit the `errmsg.txt' file
  20397. and execute the following command to generate the `errmsg.sys' file:
  20398.  
  20399.      shell> comp_err errmsg.txt errmsg.sys
  20400.  
  20401. If you upgrade to a newer version of MySQL, remember to repeat your
  20402. changes with the new `errmsg.txt' file.
  20403.  
  20404. Adding a New Character Set
  20405. --------------------------
  20406.  
  20407. To add another character set to MySQL, use the following procedure.
  20408.  
  20409. Decide if the set is simple or complex.  If the character set does not
  20410. need to use special string collating routines for sorting and does not
  20411. need multi-byte character support, it is simple.  If it needs either of
  20412. those features, it is complex.
  20413.  
  20414. For example, `latin1' and `danish' are simple charactersets while
  20415. `big5' or `czech' are complex character sets.
  20416.  
  20417. In the following section, we have assumed that you name your character
  20418. set `MYSET'.
  20419.  
  20420. For a simple character set do the following:
  20421.  
  20422.   1. Add MYSET to the end of the `sql/share/charsets/Index' file Assign
  20423.      a unique number to it.
  20424.  
  20425.   2. Create the file `sql/share/charsets/MYSET.conf'.  (You can use
  20426.      `sql/share/charsets/latin1.conf' as a base for this.)
  20427.  
  20428.      The syntax for the file is very simple:
  20429.  
  20430.         * Comments start with a '#' character and proceed to the end of
  20431.           the line.
  20432.  
  20433.         * Words are separated by arbitrary amounts of whitespace.
  20434.  
  20435.         * When defining the character set, every word must be a number
  20436.           in hexadecimal format
  20437.  
  20438.         * The `ctype' array takes up the first 257 words. The
  20439.           `to_lower[]', `to_upper[]' and `sort_order[]' arrays take up
  20440.           256 words each after that.
  20441.  
  20442.      *Note Character arrays::.
  20443.  
  20444.   3. Add the character set name to the `CHARSETS_AVAILABLE' and
  20445.      `COMPILED_CHARSETS' lists in `configure.in'.
  20446.  
  20447.   4. Reconfigure, recompile, and test.
  20448.  
  20449.  
  20450. For a complex character set do the following:
  20451.  
  20452.   1. Create the file `strings/ctype-MYSET.c' in the MySQL source
  20453.      distribution.
  20454.  
  20455.   2. Add MYSET to the end of the `sql/share/charsets/Index' file.
  20456.      Assign a unique number to it.
  20457.  
  20458.   3. Look at one of the existing `ctype-*.c' files to see what needs to
  20459.      be defined, for example `strings/ctype-big5.c'. Note that the
  20460.      arrays in your file must have names like `ctype_MYSET',
  20461.      `to_lower_MYSET', and so on.  This corresponds to the arrays in
  20462.      the simple character set. *Note Character arrays::.
  20463.  
  20464.   4. Near the top of the file, place a special comment like this:
  20465.  
  20466.           /*
  20467.            * This comment is parsed by configure to create ctype.c,
  20468.            * so don't change it unless you know what you are doing.
  20469.            *
  20470.            * .configure. number_MYSET=MYNUMBER
  20471.            * .configure. strxfrm_multiply_MYSET=N
  20472.            * .configure. mbmaxlen_MYSET=N
  20473.            */
  20474.  
  20475.      The `configure' program uses this comment to include the character
  20476.      set into the MySQL library automatically.
  20477.  
  20478.      The strxfrm_multiply and mbmaxlen lines will be explained in the
  20479.      following sections.  Only include these if you need the string
  20480.      collating functions or the multi-byte character set functions,
  20481.      respectively.
  20482.  
  20483.   5. You should then create some of the following functions:
  20484.  
  20485.         * `my_strncoll_MYSET()'
  20486.  
  20487.         * `my_strcoll_MYSET()'
  20488.  
  20489.         * `my_strxfrm_MYSET()'
  20490.  
  20491.         * `my_like_range_MYSET()'
  20492.  
  20493.      *Note String collating::.
  20494.  
  20495.   6. Add the character set name to the `CHARSETS_AVAILABLE' and
  20496.      `COMPILED_CHARSETS' lists in `configure.in'.
  20497.  
  20498.   7. Reconfigure, recompile, and test.
  20499.  
  20500. The file `sql/share/charsets/README' includes some more instructions.
  20501.  
  20502. If you want to have the character set included in the MySQL
  20503. distribution, mail a patch to the MySQL internals mailing list.  *Note
  20504. Mailing-list::.
  20505.  
  20506. The Character Definition Arrays
  20507. -------------------------------
  20508.  
  20509. `to_lower[]' and `to_upper[]' are simple arrays that hold the lowercase
  20510. and uppercase characters corresponding to each member of the character
  20511. set.  For example:
  20512.  
  20513.      to_lower['A'] should contain 'a'
  20514.      to_upper['a'] should contain 'A'
  20515.  
  20516. `sort_order[]' is a map indicating how characters should be ordered for
  20517. comparison and sorting purposes. Quite often (but not for all character
  20518. sets) this is the same as `to_upper[]' (which means sorting will be
  20519. case-insensitive). MySQL will sort characters based on the value of
  20520. `sort_order[character]'.  For more complicated sorting rules, see the
  20521. discussion of string collating below. *Note String collating::.
  20522.  
  20523. `ctype[]' is an array of bit values, with one element for one character.
  20524. (Note that `to_lower[]', `to_upper[]', and `sort_order[]' are indexed
  20525. by character value, but `ctype[]' is indexed by character value + 1.
  20526. This is an old legacy to be able to handle `EOF'.)
  20527.  
  20528. You can find the following bitmask definitions in `m_ctype.h':
  20529.  
  20530.      #define _U      01      /* Uppercase */
  20531.      #define _L      02      /* Lowercase */
  20532.      #define _N      04      /* Numeral (digit) */
  20533.      #define _S      010     /* Spacing character */
  20534.      #define _P      020     /* Punctuation */
  20535.      #define _C      040     /* Control character */
  20536.      #define _B      0100    /* Blank */
  20537.      #define _X      0200    /* heXadecimal digit */
  20538.  
  20539. The `ctype[]' entry for each character should be the union of the
  20540. applicable bitmask values that describe the character.  For example,
  20541. `'A'' is an uppercase character (`_U') as well as a hexadecimal digit
  20542. (`_X'), so `ctype['A'+1]' should contain the value:
  20543.  
  20544.      _U + _X = 01 + 0200 = 0201
  20545.  
  20546. String Collating Support
  20547. ------------------------
  20548.  
  20549. If the sorting rules for your language are too complex to be handled
  20550. with the simple `sort_order[]' table, you need to use the string
  20551. collating functions.
  20552.  
  20553. Right now the best documentation on this is the character sets that are
  20554. already implemented.  Look at the `big5', `czech', `gbk', `sjis', and
  20555. `tis160' character sets for examples.
  20556.  
  20557. You must specify the `strxfrm_multiply_MYSET=N' value in the special
  20558. comment at the top of the file.  `N' should be set to the maximum ratio
  20559. the strings may grow during `my_strxfrm_MYSET' (it must be a positive
  20560. integer).
  20561.  
  20562. Multi-byte Character Support
  20563. ----------------------------
  20564.  
  20565. If your want to add support for a new character set that includes
  20566. multi-byte characters, you need to use the multi-byte character
  20567. functions.
  20568.  
  20569. Right now the best documentation on this is the character sets that are
  20570. already implemented.  Look at the `euc_kr', `gb2312', `gbk', `sjis',
  20571. and `ujis' character sets for examples. These are implemented in the
  20572. `ctype-'charset'.c' files in the `strings' directory.
  20573.  
  20574. You must specify the `mbmaxlen_MYSET=N' value in the special comment at
  20575. the top of the source file.  `N' should be set to the size in bytes of
  20576. the largest character in the set.
  20577.  
  20578. Problems With Character Sets
  20579. ----------------------------
  20580.  
  20581. If you try to use a character set that is not compiled into your binary,
  20582. you can run into a couple of different problems:
  20583.  
  20584.    * Your program has a wrong path to where the character sets are
  20585.      stored.  (Default `/usr/local/mysql/share/mysql/charsets').  This
  20586.      can be fixed by using the `--character-sets-dir' option to the
  20587.      program in question.
  20588.  
  20589.    * The character set is a multi-byte character set that can't be
  20590.      loaded dynamically.  In this case you have to recompile the
  20591.      program with the support for the character set.
  20592.  
  20593.    * The character set is a dynamic character set, but you don't have a
  20594.      configure file for it.  In this case you should install the
  20595.      configure file for the character set from a new MySQL distribution.
  20596.  
  20597.    * Your `Index' file doesn't contain the name for the character set.
  20598.  
  20599.           ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf' not found
  20600.           (Errcode: 2)
  20601.  
  20602.      In this case you should either get a new `Index' file or add by
  20603.      hand the name of any missing character sets.
  20604.  
  20605. For `MyISAM' tables, you can check the character set name and number
  20606. for a table with `myisamchk -dvv table_name'.
  20607.  
  20608. MySQL Server-Side Scripts and Utilities
  20609. =======================================
  20610.  
  20611. Overview of the Server-Side Scripts and Utilities
  20612. -------------------------------------------------
  20613.  
  20614. All MySQL programs take many different options. However, every MySQL
  20615. program provides a `--help' option that you can use to get a full
  20616. description of the program's different options. For example, try `mysql
  20617. --help'.
  20618.  
  20619. You can override default options for all standard programs with an
  20620. option file. *Note Option files::.
  20621.  
  20622. The following list briefly describes the server-side MySQL programs:
  20623.  
  20624. `myisamchk'
  20625.      Utility to describe, check, optimise, and repair MySQL tables.
  20626.      Because `myisamchk' has many functions, it is described in its own
  20627.      chapter. *Note MySQL Database Administration::.
  20628.  
  20629. `make_binary_distribution'
  20630.      Makes a binary release of a compiled MySQL. This could be sent by
  20631.      FTP to `/pub/mysql/Incoming' on `support.mysql.com' for the
  20632.      convenience of other MySQL users.
  20633.  
  20634. `mysqlbug'
  20635.      The MySQL bug report script.  This script should always be used
  20636.      when filing a bug report to the MySQL list.
  20637.  
  20638. `mysqld'
  20639.      The SQL daemon. This should always be running.
  20640.  
  20641. `mysql_install_db'
  20642.      Creates the MySQL grant tables with default privileges. This is
  20643.      usually executed only once, when first installing MySQL on a
  20644.      system.
  20645.  
  20646. `mysqld_safe', The Wrapper Around `mysqld'
  20647. ------------------------------------------
  20648.  
  20649. `mysqld_safe' is the recommended way to start a `mysqld' daemon on
  20650. Unix.  `mysqld_safe' adds some safety features such as restarting the
  20651. server when an error occurs and logging run-time information to a log
  20652. file.
  20653.  
  20654. *Note:* Before MySQL 4.0, `mysqld_safe' is named `safe_mysqld'.  To
  20655. preserve backward compatibility, MySQL binary distributions for some
  20656. time will include `safe_mysqld' as a symbolic link to `mysqld_safe'.
  20657.  
  20658. If you don't use `--mysqld=#' or `--mysqld-version=#' `mysqld_safe'
  20659. will use an executable named `mysqld-max' if it exists. If not,
  20660. `mysqld_safe' will start `mysqld'.  This makes it very easy to test to
  20661. use `mysqld-max' instead of `mysqld'; just copy `mysqld-max' to where
  20662. you have `mysqld' and it will be used.
  20663.  
  20664. Normally one should never edit the `mysqld_safe' script, but instead
  20665. put the options to `mysqld_safe' in the `[mysqld_safe]' section in the
  20666. `my.cnf' file. `mysqld_safe' reads all options from the `[mysqld]',
  20667. `[server]' and `[mysqld_safe]' sections from the option files.  (For
  20668. backward compatibility, it also reads the `[safe_mysqld]' sections.)
  20669. *Note Option files::.
  20670.  
  20671. Note that all options on the command-line to `mysqld_safe' are passed
  20672. to `mysqld'.  If you wants to use any options in `mysqld_safe' that
  20673. `mysqld' doesn't support, you must specify these in the option file.
  20674.  
  20675. Most of the options to `mysqld_safe' are the same as the options to
  20676. `mysqld'. *Note Command-line options::.
  20677.  
  20678. `mysqld_safe' supports the following options:
  20679.  
  20680. `--basedir=path'
  20681.  
  20682. `--core-file-size=#'
  20683.      Size of the core file `mysqld' should be able to create. Passed to
  20684.      `ulimit -c'.
  20685.  
  20686. `--datadir=path'
  20687.  
  20688. `--defaults-extra-file=path'
  20689.  
  20690. `--defaults-file=path'
  20691.  
  20692. `--err-log=path (this is marked obsolete in 4.0; Use --log-error instead)'
  20693.  
  20694. `--log-error=path'
  20695.      Write the error log to the above file. *Note Error log::.
  20696.  
  20697. `--ledir=path'
  20698.      Path to `mysqld'
  20699.  
  20700. `--log=path'
  20701.  
  20702. `--mysqld=mysqld-version'
  20703.      Name of the `mysqld' version in the `ledir' directory you want to
  20704.      start.
  20705.  
  20706. `--mysqld-version=version'
  20707.      Similar to `--mysqld=' but here you only give the suffix for
  20708.      `mysqld'.  For example if you use `--mysqld-version=max',
  20709.      `mysqld_safe' will start the `ledir/mysqld-max' version.  If the
  20710.      argument to `--mysqld-version' is empty, `ledir/mysqld' will be
  20711.      used.
  20712.  
  20713. `--nice=# (added in MySQL 4.0.14)'
  20714.  
  20715. `--no-defaults'
  20716.  
  20717. `--open-files-limit=#'
  20718.      Number of files `mysqld' should be able to open. Passed to `ulimit
  20719.      -n'. Note that you need to start `mysqld_safe' as `root' for this
  20720.      to work properly!
  20721.  
  20722. `--pid-file=path'
  20723.  
  20724. `--port=#'
  20725.  
  20726. `--socket=path'
  20727.  
  20728. `--timezone=#'
  20729.      Set the timezone (the `TZ') variable to the value of this
  20730.      parameter.
  20731.  
  20732. `--user=#'
  20733. The `mysqld_safe' script is written so that it normally is able to start
  20734. a server that was installed from either a source or a binary version of
  20735. MySQL, even if these install the server in slightly different
  20736. locations.  `mysqld_safe' expects one of these conditions to be true:
  20737.  
  20738.    * The server and databases can be found relative to the directory
  20739.      from which `mysqld_safe' is invoked.  `mysqld_safe' looks under
  20740.      its working directory for `bin' and `data' directories (for binary
  20741.      distributions) or for `libexec' and `var' directories (for source
  20742.      distributions).  This condition should be met if you execute
  20743.      `mysqld_safe' from your MySQL installation directory (for example,
  20744.      `/usr/local/mysql' for a binary distribution).
  20745.  
  20746.    * If the server and databases cannot be found relative to the
  20747.      working directory, `mysqld_safe' attempts to locate them by
  20748.      absolute pathnames.  Typical locations are `/usr/local/libexec'
  20749.      and `/usr/local/var'.  The actual locations are determined when
  20750.      the distribution was built from which `mysqld_safe' comes.  They
  20751.      should be correct if MySQL was installed in a standard location.
  20752.  
  20753. Because `mysqld_safe' will try to find the server and databases relative
  20754. to its own working directory, you can install a binary distribution of
  20755. MySQL anywhere, as long as you start `mysqld_safe' from the MySQL
  20756. installation directory:
  20757.  
  20758.      shell> cd mysql_installation_directory
  20759.      shell> bin/mysqld_safe &
  20760.  
  20761. If `mysqld_safe' fails, even when invoked from the MySQL installation
  20762. directory, you can modify it to use the path to `mysqld' and the
  20763. pathname options that are correct for your system.  Note that if you
  20764. upgrade MySQL in the future, your modified version of `mysqld_safe'
  20765. will be overwritten, so you should make a copy of your edited version
  20766. that you can reinstall.
  20767.  
  20768. `mysqld_multi', A Program for Managing Multiple MySQL Servers
  20769. -------------------------------------------------------------
  20770.  
  20771. `mysqld_multi' is meant for managing several `mysqld' processes that
  20772. listen for connections on different Unix sockets and TCP/IP ports.
  20773.  
  20774. The program will search for group(s) named `[mysqld#]' from `my.cnf'
  20775. (or the file named by the `--config-file=...' option), where `#' can be
  20776. any positive number starting from 1.  This number is referred to in the
  20777. following discussion as the option group number, or GNR.  Group numbers
  20778. distinquish option groups from one another and are used as arguments to
  20779. `mysqld_multi' to specify which servers you want to start, stop, or
  20780. obtain status for.  Options listed in these groups should be the same
  20781. as you would use in the usual `[mysqld]' group used for starting
  20782. `mysqld'.  (See, for example, *Note Automatic start::.)  However, for
  20783. `mysqld_multi', be sure that each group includes options for values
  20784. such as the port, socket, etc., to be used for each individual `mysqld'
  20785. process.
  20786.  
  20787. `mysqld_multi' is invoked using the following syntax:
  20788.  
  20789.      Usage: mysqld_multi [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  20790.      or     mysqld_multi [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  20791.  
  20792. Each GNR represents an option group number. You can start, stop or
  20793. report any GNR, or several of them at the same time. For an example of
  20794. how you might set up an option file, use this command:
  20795.  
  20796.      shell> mysqld_multi --example
  20797.  
  20798. The GNR values in the list can be comma-separated or combined with a
  20799. dash; in the latter case, all the GNRs between GNR1-GNR2 will be
  20800. affected. With no GNR argument, all groups listed in the option file
  20801. will be either started, stopped, or reported. Note that you must not
  20802. have any white spaces in the GNR list. Anything after a white space is
  20803. ignored.
  20804.  
  20805. `mysqld_multi' supports the following options:
  20806.  
  20807. `--config-file=...'
  20808.      Alternative config file. Note: This will not affect this program's
  20809.      own options (group `[mysqld_multi]'), but only groups `[mysqld#]'.
  20810.      Without this option, everything will be searched from the ordinary
  20811.      `my.cnf' file.
  20812.  
  20813. `--example'
  20814.      Display an example option file.
  20815.  
  20816. `--help'
  20817.      Print this help and exit.
  20818.  
  20819. `--log=...'
  20820.      Log file. Full path to and the name for the log file. Note: If the
  20821.      file exists, everything will be appended.
  20822.  
  20823. `--mysqladmin=...'
  20824.      `mysqladmin' binary to be used for a server shutdown.
  20825.  
  20826. `--mysqld=...'
  20827.      `mysqld' binary to be used. Note that you can give `mysqld_safe'
  20828.      to this option also. The options are passed to `mysqld'. Just make
  20829.      sure you have `mysqld' in your environment variable `PATH' or fix
  20830.      `mysqld_safe'.
  20831.  
  20832. `--no-log'
  20833.      Print to stdout instead of the log file. By default the log file is
  20834.      turned on.
  20835.  
  20836. `--password=...'
  20837.      Password for user for `mysqladmin'.
  20838.  
  20839. `--tcp-ip'
  20840.      Connect to the MySQL server(s) via the TCP/IP port instead of the
  20841.      Unix socket. This affects stopping and reporting.  If a socket file
  20842.      is missing, the server may still be running, but can be accessed
  20843.      only via the TCP/IP port.  By default, connections are made using
  20844.      the Unix socket.
  20845.  
  20846. `--user=...'
  20847.      MySQL user for `mysqladmin'.
  20848.  
  20849. `--version'
  20850.      Print the version number and exit.
  20851.  
  20852. Some notes about `mysqld_multi':
  20853.  
  20854.    * Make sure that the MySQL user, who is stopping the `mysqld'
  20855.      services (e.g using the `mysqladmin' program) have the same
  20856.      password and username for all the data directories accessed (to the
  20857.      `mysql' database) And make sure that the user has the `SHUTDOWN'
  20858.      privilege! If you have many data directories and many different
  20859.      `mysql' databases with different passwords for the MySQL `root'
  20860.      user, you may want to create a common `multi_admin' user for each
  20861.      using the same password (see below). Example how to do it:
  20862.           shell> mysql -u root -S /tmp/mysql.sock -proot_password -e
  20863.           "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'multipass'"
  20864.      *Note Privileges::.  You will have to do the above for each
  20865.      `mysqld' running in each data directory, that you have (just
  20866.      change the socket, `-S=...').
  20867.  
  20868.    * `pid-file' is very important, if you are using `mysqld_safe' to
  20869.      start `mysqld' (for example, `--mysqld=mysqld_safe') Every
  20870.      `mysqld' should have its own `pid-file'. The advantage using
  20871.      `mysqld_safe' instead of `mysqld' directly here is, that
  20872.      `mysqld_safe' "guards" every `mysqld' process and will restart it,
  20873.      if a `mysqld' process terminates due to a signal sent using `kill
  20874.      -9', or for other reasons such as a segmentation fault (which
  20875.      MySQL should never do, of course;). Please note that the
  20876.      `mysqld_safe' script may require that you start it from a certain
  20877.      place. This means that you may have to `cd' to a certain directory,
  20878.      before you start the `mysqld_multi'. If you have problems starting,
  20879.      please see the `mysqld_safe' script. Check especially the lines:
  20880.  
  20881.           --------------------------------------------------------------------------
  20882.           MY_PWD=`pwd` Check if we are starting this relative (for the binary
  20883.           release) if test -d /data/mysql -a -f ./share/mysql/english/errmsg.sys
  20884.           -a -x ./bin/mysqld
  20885.           --------------------------------------------------------------------------
  20886.  
  20887.      *Note `mysqld_safe': mysqld_safe.  The above test should be
  20888.      successful, or you may encounter problems.
  20889.  
  20890.    * Beware of the dangers starting multiple `mysqld's in the same data
  20891.      directory.  Use separate data directories, unless you *know* what
  20892.      you are doing!
  20893.  
  20894.    * The socket file and the TCP/IP port must be different for every
  20895.      `mysqld'.
  20896.  
  20897.    * The first and fifth `mysqld' group were intentionally left out from
  20898.      the example.  You may have 'gaps' in the config file. This gives
  20899.      you more flexibility.  The order in which the `mysqlds' are
  20900.      started or stopped depends on the order in which they appear in
  20901.      the config file.
  20902.  
  20903.    * When you want to refer to a certain group using GNR with this
  20904.      program, just use the number in the end of the group name.  For
  20905.      example, the GNR for a group named `[mysqld17]' is 17.
  20906.  
  20907.    * You may want to use option `--user' for `mysqld', but in order to
  20908.      do this you need to run the `mysqld_multi' script as the Unix
  20909.      `root' user. Having the option in the config file doesn't matter;
  20910.      you will just get a warning, if you are not the superuser and the
  20911.      `mysqlds' are started under *your* Unix account. *Important*: Make
  20912.      sure that the `pid-file' and the data directory are
  20913.      read+write(+execute for the latter one) accessible for *that* Unix
  20914.      user, who the specific `mysqld' process is started as. *Do not*
  20915.      use the Unix root account for this, unless you *know* what you are
  20916.      doing!
  20917.  
  20918.    * *Most important*: Make sure that you understand the meanings of
  20919.      the options that are passed to the `mysqld's and *why one would
  20920.      want* to have separate `mysqld' processes. Starting multiple
  20921.      `mysqld's in one data directory *will not* give you extra
  20922.      performance in a threaded system!
  20923.  
  20924. *Note Multiple servers::.
  20925.  
  20926. This is an example of the config file on behalf of `mysqld_multi'.
  20927.  
  20928.      # This file should probably be in your home dir (~/.my.cnf) or /etc/my.cnf
  20929.      # Version 2.1 by Jani Tolonen
  20930.      
  20931.      [mysqld_multi]
  20932.      mysqld     = /usr/local/bin/mysqld_safe
  20933.      mysqladmin = /usr/local/bin/mysqladmin
  20934.      user       = multi_admin
  20935.      password   = multipass
  20936.      
  20937.      [mysqld2]
  20938.      socket     = /tmp/mysql.sock2
  20939.      port       = 3307
  20940.      pid-file   = /usr/local/mysql/var2/hostname.pid2
  20941.      datadir    = /usr/local/mysql/var2
  20942.      language   = /usr/local/share/mysql/english
  20943.      user       = john
  20944.      
  20945.      [mysqld3]
  20946.      socket     = /tmp/mysql.sock3
  20947.      port       = 3308
  20948.      pid-file   = /usr/local/mysql/var3/hostname.pid3
  20949.      datadir    = /usr/local/mysql/var3
  20950.      language   = /usr/local/share/mysql/swedish
  20951.      user       = monty
  20952.      
  20953.      [mysqld4]
  20954.      socket     = /tmp/mysql.sock4
  20955.      port       = 3309
  20956.      pid-file   = /usr/local/mysql/var4/hostname.pid4
  20957.      datadir    = /usr/local/mysql/var4
  20958.      language   = /usr/local/share/mysql/estonia
  20959.      user       = tonu
  20960.      
  20961.      [mysqld6]
  20962.      socket     = /tmp/mysql.sock6
  20963.      port       = 3311
  20964.      pid-file   = /usr/local/mysql/var6/hostname.pid6
  20965.      datadir    = /usr/local/mysql/var6
  20966.      language   = /usr/local/share/mysql/japanese
  20967.      user       = jani
  20968.  
  20969. *Note Option files::.
  20970.  
  20971. `myisampack', The MySQL Compressed Read-only Table Generator
  20972. ------------------------------------------------------------
  20973.  
  20974. `myisampack' is used to compress MyISAM tables, and `pack_isam' is used
  20975. to compress ISAM tables. Because ISAM tables are deprecated, we will
  20976. only discuss `myisampack' here, but everything said about `myisampack'
  20977. should also be true for `pack_isam'.
  20978.  
  20979. `myisampack' works by compressing each column in the table separately.
  20980. The information needed to decompress columns is read into memory when
  20981. the table is opened. This results in much better performance when
  20982. accessing individual records, because you only have to uncompress
  20983. exactly one record, not a much larger disk block as when using Stacker
  20984. on MS-DOS.  Usually, `myisampack' packs the datafile 40%-70%.
  20985.  
  20986. MySQL uses memory mapping (`mmap()') on compressed tables and falls
  20987. back to normal read/write file usage if `mmap()' doesn't work.
  20988.  
  20989. Please note the following:
  20990.    * After packing, the table is read-only. This is generally intended
  20991.      (such as when accessing packed tables on a CD). Also allowing
  20992.      writes to a packed table is on our TODO list but with low priority.
  20993.  
  20994.    * `myisampack' can also pack `BLOB' or `TEXT' columns.  The older
  20995.      `pack_isam' (for `ISAM' tables) can not do this.
  20996.  
  20997. `myisampack' is invoked like this:
  20998.  
  20999.      shell> myisampack [options] filename ...
  21000.  
  21001. Each filename should be the name of an index (`.MYI') file.  If you are
  21002. not in the database directory, you should specify the pathname to the
  21003. file.  It is permissible to omit the `.MYI' extension.
  21004.  
  21005. `myisampack' supports the following options:
  21006.  
  21007. `-b, --backup'
  21008.      Make a backup of the table as `tbl_name.OLD'.
  21009.  
  21010. `-#, --debug=debug_options'
  21011.      Output debug log. The `debug_options' string often is
  21012.      `'d:t:o,filename''.
  21013.  
  21014. `-f, --force'
  21015.      Force packing of the table even if it becomes bigger or if the
  21016.      temporary file exists.  `myisampack' creates a temporary file
  21017.      named `tbl_name.TMD' while it compresses the table.  If you kill
  21018.      `myisampack', the `.TMD' file may not be deleted.  Normally,
  21019.      `myisampack' exits with an error if it finds that `tbl_name.TMD'
  21020.      exists.  With `--force', `myisampack' packs the table anyway.
  21021.  
  21022. `-?, --help'
  21023.      Display a help message and exit.
  21024.  
  21025. `-j big_tbl_name, --join=big_tbl_name'
  21026.      Join all tables named on the command-line into a single table
  21027.      `big_tbl_name'.  All tables that are to be combined *must* be
  21028.      identical (same column names and types, same indexes, etc.).
  21029.  
  21030. `-p #, --packlength=#'
  21031.      Specify the record length storage size, in bytes.  The value
  21032.      should be 1, 2, or 3.  (`myisampack' stores all rows with length
  21033.      pointers of 1, 2, or 3 bytes.  In most normal cases, `myisampack'
  21034.      can determine the right length value before it begins packing the
  21035.      file, but it may notice during the packing process that it could
  21036.      have used a shorter length. In this case, `myisampack' will print
  21037.      a note that the next time you pack the same file, you could use a
  21038.      shorter record length.)
  21039.  
  21040. `-s, --silent'
  21041.      Silent mode.  Write output only when errors occur.
  21042.  
  21043. `-t, --test'
  21044.      Don't actually pack table, just test packing it.
  21045.  
  21046. `-T dir_name, --tmp_dir=dir_name'
  21047.      Use the named directory as the location in which to write the
  21048.      temporary table.
  21049.  
  21050. `-v, --verbose'
  21051.      Verbose mode.  Write information about progress and packing result.
  21052.  
  21053. `-V, --version'
  21054.      Display version information and exit.
  21055.  
  21056. `-w, --wait'
  21057.      Wait and retry if table is in use.  If the `mysqld' server was
  21058.      invoked with the `--skip-external-locking' option, it is not a
  21059.      good idea to invoke `myisampack' if the table might be updated
  21060.      during the packing process.
  21061.  
  21062. The sequence of commands shown here illustrates a typical table
  21063. compression session:
  21064.  
  21065.      shell> ls -l station.*
  21066.      -rw-rw-r--   1 monty    my         994128 Apr 17 19:00 station.MYD
  21067.      -rw-rw-r--   1 monty    my          53248 Apr 17 19:00 station.MYI
  21068.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  21069.      
  21070.      shell> myisamchk -dvv station
  21071.      
  21072.      MyISAM file:     station
  21073.      Isam-version:  2
  21074.      Creation time: 1996-03-13 10:08:58
  21075.      Recover time:  1997-02-02  3:06:43
  21076.      Data records:              1192  Deleted blocks:              0
  21077.      Datafile: Parts:           1192  Deleted data:                0
  21078.      Datafile pointer (bytes):     2  Keyfile pointer (bytes):     2
  21079.      Max datafile length:   54657023  Max keyfile length:   33554431
  21080.      Recordlength:               834
  21081.      Record format: Fixed length
  21082.      
  21083.      table description:
  21084.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  21085.      1   2     4   unique  unsigned long              1024       1024          1
  21086.      2   32    30  multip. text                      10240       1024          1
  21087.      
  21088.      Field Start Length Type
  21089.      1     1     1
  21090.      2     2     4
  21091.      3     6     4
  21092.      4     10    1
  21093.      5     11    20
  21094.      6     31    1
  21095.      7     32    30
  21096.      8     62    35
  21097.      9     97    35
  21098.      10    132   35
  21099.      11    167   4
  21100.      12    171   16
  21101.      13    187   35
  21102.      14    222   4
  21103.      15    226   16
  21104.      16    242   20
  21105.      17    262   20
  21106.      18    282   20
  21107.      19    302   30
  21108.      20    332   4
  21109.      21    336   4
  21110.      22    340   1
  21111.      23    341   8
  21112.      24    349   8
  21113.      25    357   8
  21114.      26    365   2
  21115.      27    367   2
  21116.      28    369   4
  21117.      29    373   4
  21118.      30    377   1
  21119.      31    378   2
  21120.      32    380   8
  21121.      33    388   4
  21122.      34    392   4
  21123.      35    396   4
  21124.      36    400   4
  21125.      37    404   1
  21126.      38    405   4
  21127.      39    409   4
  21128.      40    413   4
  21129.      41    417   4
  21130.      42    421   4
  21131.      43    425   4
  21132.      44    429   20
  21133.      45    449   30
  21134.      46    479   1
  21135.      47    480   1
  21136.      48    481   79
  21137.      49    560   79
  21138.      50    639   79
  21139.      51    718   79
  21140.      52    797   8
  21141.      53    805   1
  21142.      54    806   1
  21143.      55    807   20
  21144.      56    827   4
  21145.      57    831   4
  21146.      
  21147.      shell> myisampack station.MYI
  21148.      Compressing station.MYI: (1192 records)
  21149.      - Calculating statistics
  21150.      
  21151.      normal:     20  empty-space:      16  empty-zero:        12  empty-fill:  11
  21152.      pre-space:   0  end-space:        12  table-lookups:      5  zero:         7
  21153.      Original trees:  57  After join: 17
  21154.      - Compressing file
  21155.      87.14%
  21156.      
  21157.      shell> ls -l station.*
  21158.      -rw-rw-r--   1 monty    my         127874 Apr 17 19:00 station.MYD
  21159.      -rw-rw-r--   1 monty    my          55296 Apr 17 19:04 station.MYI
  21160.      -rw-rw-r--   1 monty    my           5767 Apr 17 19:00 station.frm
  21161.      
  21162.      shell> myisamchk -dvv station
  21163.      
  21164.      MyISAM file:     station
  21165.      Isam-version:  2
  21166.      Creation time: 1996-03-13 10:08:58
  21167.      Recover time:  1997-04-17 19:04:26
  21168.      Data records:              1192  Deleted blocks:              0
  21169.      Datafile: Parts:           1192  Deleted data:                0
  21170.      Datafilepointer (bytes):      3  Keyfile pointer (bytes):     1
  21171.      Max datafile length:   16777215  Max keyfile length:     131071
  21172.      Recordlength:               834
  21173.      Record format: Compressed
  21174.      
  21175.      table description:
  21176.      Key Start Len Index   Type                       Root  Blocksize    Rec/key
  21177.      1   2     4   unique  unsigned long             10240       1024          1
  21178.      2   32    30  multip. text                      54272       1024          1
  21179.      
  21180.      Field Start Length Type                         Huff tree  Bits
  21181.      1     1     1      constant                             1     0
  21182.      2     2     4      zerofill(1)                          2     9
  21183.      3     6     4      no zeros, zerofill(1)                2     9
  21184.      4     10    1                                           3     9
  21185.      5     11    20     table-lookup                         4     0
  21186.      6     31    1                                           3     9
  21187.      7     32    30     no endspace, not_always              5     9
  21188.      8     62    35     no endspace, not_always, no empty    6     9
  21189.      9     97    35     no empty                             7     9
  21190.      10    132   35     no endspace, not_always, no empty    6     9
  21191.      11    167   4      zerofill(1)                          2     9
  21192.      12    171   16     no endspace, not_always, no empty    5     9
  21193.      13    187   35     no endspace, not_always, no empty    6     9
  21194.      14    222   4      zerofill(1)                          2     9
  21195.      15    226   16     no endspace, not_always, no empty    5     9
  21196.      16    242   20     no endspace, not_always              8     9
  21197.      17    262   20     no endspace, no empty                8     9
  21198.      18    282   20     no endspace, no empty                5     9
  21199.      19    302   30     no endspace, no empty                6     9
  21200.      20    332   4      always zero                          2     9
  21201.      21    336   4      always zero                          2     9
  21202.      22    340   1                                           3     9
  21203.      23    341   8      table-lookup                         9     0
  21204.      24    349   8      table-lookup                        10     0
  21205.      25    357   8      always zero                          2     9
  21206.      26    365   2                                           2     9
  21207.      27    367   2      no zeros, zerofill(1)                2     9
  21208.      28    369   4      no zeros, zerofill(1)                2     9
  21209.      29    373   4      table-lookup                        11     0
  21210.      30    377   1                                           3     9
  21211.      31    378   2      no zeros, zerofill(1)                2     9
  21212.      32    380   8      no zeros                             2     9
  21213.      33    388   4      always zero                          2     9
  21214.      34    392   4      table-lookup                        12     0
  21215.      35    396   4      no zeros, zerofill(1)               13     9
  21216.      36    400   4      no zeros, zerofill(1)                2     9
  21217.      37    404   1                                           2     9
  21218.      38    405   4      no zeros                             2     9
  21219.      39    409   4      always zero                          2     9
  21220.      40    413   4      no zeros                             2     9
  21221.      41    417   4      always zero                          2     9
  21222.      42    421   4      no zeros                             2     9
  21223.      43    425   4      always zero                          2     9
  21224.      44    429   20     no empty                             3     9
  21225.      45    449   30     no empty                             3     9
  21226.      46    479   1                                          14     4
  21227.      47    480   1                                          14     4
  21228.      48    481   79     no endspace, no empty               15     9
  21229.      49    560   79     no empty                             2     9
  21230.      50    639   79     no empty                             2     9
  21231.      51    718   79     no endspace                         16     9
  21232.      52    797   8      no empty                             2     9
  21233.      53    805   1                                          17     1
  21234.      54    806   1                                           3     9
  21235.      55    807   20     no empty                             3     9
  21236.      56    827   4      no zeros, zerofill(2)                2     9
  21237.      57    831   4      no zeros, zerofill(1)                2     9
  21238.  
  21239. The information printed by `myisampack' is described here:
  21240.  
  21241. `normal'
  21242.      The number of columns for which no extra packing is used.
  21243.  
  21244. `empty-space'
  21245.      The number of columns containing values that are only spaces;
  21246.      these will occupy 1 bit.
  21247.  
  21248. `empty-zero'
  21249.      The number of columns containing values that are only binary 0's;
  21250.      these will occupy 1 bit.
  21251.  
  21252. `empty-fill'
  21253.      The number of integer columns that don't occupy the full byte
  21254.      range of their type; these are changed to a smaller type (for
  21255.      example, an `INTEGER' column may be changed to `MEDIUMINT').
  21256.  
  21257. `pre-space'
  21258.      The number of decimal columns that are stored with leading spaces.
  21259.      In this case, each value will contain a count for the number of
  21260.      leading spaces.
  21261.  
  21262. `end-space'
  21263.      The number of columns that have a lot of trailing spaces.  In this
  21264.      case, each value will contain a count for the number of trailing
  21265.      spaces.
  21266.  
  21267. `table-lookup'
  21268.      The column had only a small number of different values, which were
  21269.      converted to an `ENUM' before Huffman compression.
  21270.  
  21271. `zero'
  21272.      The number of columns for which all values are zero.
  21273.  
  21274. `Original trees'
  21275.      The initial number of Huffman trees.
  21276.  
  21277. `After join'
  21278.      The number of distinct Huffman trees left after joining trees to
  21279.      save some header space.
  21280.  
  21281. After a table has been compressed, `myisamchk -dvv' prints additional
  21282. information about each field:
  21283.  
  21284. `Type'
  21285.      The field type may contain the following descriptors:
  21286.  
  21287.     `constant'
  21288.           All rows have the same value.
  21289.  
  21290.     `no endspace'
  21291.           Don't store endspace.
  21292.  
  21293.     `no endspace, not_always'
  21294.           Don't store endspace and don't do end space compression for
  21295.           all values.
  21296.  
  21297.     `no endspace, no empty'
  21298.           Don't store endspace. Don't store empty values.
  21299.  
  21300.     `table-lookup'
  21301.           The column was converted to an `ENUM'.
  21302.  
  21303.     `zerofill(n)'
  21304.           The most significant `n' bytes in the value are always 0 and
  21305.           are not stored.
  21306.  
  21307.     `no zeros'
  21308.           Don't store zeros.
  21309.  
  21310.     `always zero'
  21311.           0 values are stored in 1 bit.
  21312.  
  21313. `Huff tree'
  21314.      The Huffman tree associated with the field.
  21315.  
  21316. `Bits'
  21317.      The number of bits used in the Huffman tree.
  21318.  
  21319. After you have run `pack_isam'/`myisampack' you must run
  21320. `isamchk'/`myisamchk' to re-create the index.  At this time you can
  21321. also sort the index blocks and create statistics needed for the MySQL
  21322. optimiser to work more efficiently:
  21323.  
  21324.      myisamchk -rq --analyze --sort-index table_name.MYI
  21325.      isamchk   -rq --analyze --sort-index table_name.ISM
  21326.  
  21327. After you have installed the packed table into the MySQL database
  21328. directory you should do `mysqladmin flush-tables' to force `mysqld' to
  21329. start using the new table.
  21330.  
  21331. If you want to unpack a packed table, you can do this with the
  21332. `--unpack' option to `isamchk' or `myisamchk'.
  21333.  
  21334. `mysqld-max', An Extended `mysqld' Server
  21335. -----------------------------------------
  21336.  
  21337. `mysqld-max' is the MySQL server (`mysqld') configured with the
  21338. following configure options:
  21339.  
  21340. *Option*               *Comment*
  21341. -with-server-suffix=-maxAdd a suffix to the `mysqld' version string
  21342. -with-innodb           Support for InnoDB tables (MySQL 3.23 only)
  21343. -with-bdb              Support for Berkeley DB (BDB) tables
  21344. CFLAGS=-DUSE_SYMDIR    Symbolic link support for Windows
  21345.  
  21346. The option for enabling InnoDB support is needed only in MySQL 3.23. In
  21347. MySQL 4 and up, InnoDB is included by default.
  21348.  
  21349. You can find the MySQL-Max binaries at
  21350. `http://www.mysql.com/downloads/mysql-max-4.0.html'.
  21351.  
  21352. The Windows MySQL binary distributions includes both the standard
  21353. `mysqld.exe' binary and the `mysqld-max.exe' binary.
  21354. `http://www.mysql.com/downloads/mysql-4.0.html'.  *Note Windows
  21355. installation::.
  21356.  
  21357. Note that as BerkeleyDB (BDB) is not available for all platforms, so
  21358. some of the `Max' binaries may not have support for it.  You can check
  21359. which table types are supported by doing the following query:
  21360.  
  21361.      mysql> SHOW VARIABLES LIKE "have_%";
  21362.      +------------------+----------+
  21363.      | Variable_name    | Value    |
  21364.      +------------------+----------+
  21365.      | have_bdb         | NO       |
  21366.      | have_crypt       | YES      |
  21367.      | have_innodb      | YES      |
  21368.      | have_isam        | YES      |
  21369.      | have_raid        | NO       |
  21370.      | have_symlink     | DISABLED |
  21371.      | have_openssl     | NO       |
  21372.      | have_query_cache | YES      |
  21373.      +------------------+----------+
  21374.  
  21375. The meanings of the values in the second column are:
  21376.  
  21377. *Value*     *Meaning*
  21378. `YES'       The option is activated and usable.
  21379. `NO'        MySQL is not compiled with support for this option.
  21380. `DISABLED'  The xxxx option is disabled because one started `mysqld'
  21381.             with `--skip-xxxx' or because one didn't start `mysqld' with
  21382.             all needed options to enable the option.  In this case the
  21383.             `hostname.err' file should contain a reason indicating why
  21384.             the option is disabled.
  21385.  
  21386. *Note*:  To be able to create InnoDB tables in MySQL version 3.23 you
  21387. *must* edit your startup options to include at least the
  21388. `innodb_data_file_path' option. *Note InnoDB in MySQL 3.23::.
  21389.  
  21390. To get better performance for BDB tables, you should add some
  21391. configuration options for these, too. *Note BDB start::.
  21392.  
  21393. `mysqld_safe' automatically tries to start any `mysqld' binary with the
  21394. `-max' suffix. This makes it very easy to test out another `mysqld'
  21395. binary in an existing installation.  Just run `configure' with the
  21396. options you want and then install the new `mysqld' binary as
  21397. `mysqld-max' in the same directory where your old `mysqld' binary is.
  21398. *Note `mysqld_safe': mysqld_safe.
  21399.  
  21400. On Linux, the `MySQL-Max' RPM uses the above mentioned `mysqld_safe'
  21401. feature. (It just installs the `mysqld-max' executable, so
  21402. `mysqld_safe' automatically uses this executable when `mysqld_safe' is
  21403. restarted.)
  21404.  
  21405. The following table shows which table types our MySQL-Max binaries
  21406. include:
  21407.  
  21408. *System*    `BDB'   `InnoDB'
  21409. Windows/NT  Y       Y
  21410. AIX 4.3     N       Y
  21411. HP-UX 11.0  N       Y
  21412. Linux-Alpha N       Y
  21413. Linux-Intel Y       Y
  21414. Linux-IA-64 N       Y
  21415. Solaris-IntelN       Y
  21416. Solaris-SPARCY       Y
  21417. SCO OSR5    Y       Y
  21418. UnixWare    Y       Y
  21419. Mac OS X    N       Y
  21420.  
  21421. Note that as of MySQL 4, you do not need a MySQL Max server for InnoDB,
  21422. because InnoDB is included by default.
  21423.  
  21424. MySQL Client-Side Scripts and Utilities
  21425. =======================================
  21426.  
  21427. Overview of the Client-Side Scripts and Utilities
  21428. -------------------------------------------------
  21429.  
  21430. All MySQL clients that communicate with the server using the
  21431. `mysqlclient' library use the following environment variables:
  21432.  
  21433. *Name*             *Description*
  21434. `MYSQL_UNIX_PORT'  The default socket; used for connections
  21435.                    to `localhost'
  21436. `MYSQL_TCP_PORT'   The default TCP/IP port
  21437. `MYSQL_PWD'        The default password
  21438. `MYSQL_DEBUG'      Debug-trace options when debugging
  21439. `TMPDIR'           The directory where temporary tables/files
  21440.                    are created
  21441.  
  21442. Use of `MYSQL_PWD' is insecure.  *Note Connecting::.
  21443.  
  21444. On Unix, the `mysql' client uses the file named in the `MYSQL_HISTFILE'
  21445. environment variable to save the command-line history. The default
  21446. value for the history file is `$HOME/.mysql_history', where `$HOME' is
  21447. the value of the `HOME' environment variable. *Note Environment
  21448. variables::.
  21449.  
  21450. If you do not want to maintain a file that contains a record of your
  21451. queries, first remove `.mysql_history' if it exists, then use either of
  21452. the following techniques:
  21453.  
  21454.    * Set the `MYSQL_HISTFILE' variable to `/dev/null'. To cause this
  21455.      setting to take effect each time you log in, put the setting in
  21456.      one of your shell's startup files.
  21457.  
  21458.    * Create `.mysql_histfile' as a symbolic link to `/dev/null':
  21459.  
  21460.           shell> ln -s /dev/null $HOME/.mysql_history
  21461.  
  21462.      You need do this only once.
  21463.  
  21464.  
  21465. All MySQL programs take many different options. However, every MySQL
  21466. program provides a `--help' option that you can use to get a full
  21467. description of the program's different options. For example, try `mysql
  21468. --help'.
  21469.  
  21470. You can override default options for all standard client programs with
  21471. an option file. *Note Option files::.
  21472.  
  21473. The following list briefly describes the client-side MySQL programs:
  21474.  
  21475. `msql2mysql'
  21476.      A shell script that converts `mSQL' programs to MySQL. It doesn't
  21477.      handle all cases, but it gives a good start when converting.
  21478.  
  21479. `mysql'
  21480.      The command-line tool for interactively entering queries or
  21481.      executing queries from a file in batch mode.  *Note `mysql': mysql.
  21482.  
  21483. `mysqlaccess'
  21484.      A script that checks the access privileges for a host, user, and
  21485.      database combination.
  21486.  
  21487. `mysqladmin'
  21488.      Utility for performing administrative operations, such as creating
  21489.      or dropping databases, reloading the grant tables, flushing tables
  21490.      to disk, and reopening log files.  `mysqladmin' can also be used
  21491.      to retrieve version, process, and status information from the
  21492.      server.  *Note `mysqladmin': mysqladmin.
  21493.  
  21494. `mysqlbinlog'
  21495.      Utility for reading queries from a binary log. Can be used to
  21496.      recover from a crash with an old backup.  *Note `mysqlbinlog':
  21497.      mysqlbinlog.
  21498.  
  21499. `mysqldump'
  21500.      Dumps a MySQL database into a file as SQL statements or as
  21501.      tab-separated text files. Enhanced freeware originally by Igor
  21502.      Romanenko.  *Note `mysqldump': mysqldump.
  21503.  
  21504. `mysqlimport'
  21505.      Imports text files into their respective tables using `LOAD DATA
  21506.      INFILE'. *Note `mysqlimport': mysqlimport.
  21507.  
  21508. `mysqlshow'
  21509.      Displays information about databases, tables, columns, and indexes.
  21510.  
  21511. `replace'
  21512.      A utility program that is used by `msql2mysql', but that has more
  21513.      general applicability as well.  `replace' changes strings in place
  21514.      in files or on the standard input. Uses a finite state machine to
  21515.      match longer strings first. Can be used to swap strings. For
  21516.      example, this command swaps `a' and `b' in the given files:
  21517.  
  21518.           shell> replace a b b a -- file1 file2 ...
  21519.  
  21520. `mysql', The Command-line Tool
  21521. ------------------------------
  21522.  
  21523. `mysql' is a simple SQL shell (with GNU `readline' capabilities).  It
  21524. supports interactive and non-interactive use. When used interactively,
  21525. query results are presented in an ASCII-table format. When used
  21526. non-interactively (for example, as a filter), the result is presented in
  21527. tab-separated format.  (The output format can be changed using
  21528. command-line options.)  You can run scripts simply like this:
  21529.  
  21530.      shell> mysql database < script.sql > output.tab
  21531.  
  21532. If you have problems due to insufficient memory in the client, use the
  21533. `--quick' option!  This forces `mysql' to use `mysql_use_result()'
  21534. rather than `mysql_store_result()' to retrieve the result set.
  21535.  
  21536. Using `mysql' is very easy. Just start it as follows: `mysql database'
  21537. or `mysql --user=user_name --password=your_password database'. Type an
  21538. SQL statement, end it with `;', `\g', or `\G' and press Enter.
  21539.  
  21540. `mysql' supports the following options:
  21541.  
  21542. `-?, --help'
  21543.      Display this help and exit.
  21544.  
  21545. `-A, --no-auto-rehash'
  21546.      No automatic rehashing. One has to use 'rehash' to get table and
  21547.      field completion. This gives a quicker start of mysql.
  21548.  
  21549. `--prompt=...'
  21550.      Set the mysql prompt to specified format.
  21551.  
  21552. `-b, --no-beep'
  21553.      Turn off beep-on-error.
  21554.  
  21555. `-B, --batch'
  21556.      Print results with a tab as separator, each row on a new line.
  21557.      Doesn't use history file.
  21558.  
  21559. `--character-sets-dir=...'
  21560.      Directory where character sets are located.
  21561.  
  21562. `-C, --compress'
  21563.      Use compression in server/client protocol.
  21564.  
  21565. `-#, --debug[=...]'
  21566.      Debug log. Default is 'd:t:o,/tmp/mysql.trace'.
  21567.  
  21568. `-D, --database=...'
  21569.      Database to use. This is mainly useful in the `my.cnf' file.
  21570.  
  21571. `--default-character-set=...'
  21572.      Set the default character set.
  21573.  
  21574. `-e, --execute=...'
  21575.      Execute command and quit. (Output like with -batch)
  21576.  
  21577. `-E, --vertical'
  21578.      Print the output of a query (rows) vertically. Without this option
  21579.      you can also force this output by ending your statements with `\G'.
  21580.  
  21581. `-f, --force'
  21582.      Continue even if we get an SQL error.
  21583.  
  21584. `-g, --no-named-commands'
  21585.      Named commands are disabled. Use \* form only, or use named
  21586.      commands only in the beginning of a line ending with a semicolon
  21587.      (`;'). Since Version 10.9, the client now starts with this option
  21588.      *enabled* by default!  With the -g option, long format commands
  21589.      will still work from the first line, however.
  21590.  
  21591. `-G, --enable-named-commands'
  21592.      Named commands are *enabled*.  Long format commands are allowed as
  21593.      well as shortened \* commands.
  21594.  
  21595. `-i, --ignore-space'
  21596.      Ignore space after function names.
  21597.  
  21598. `-h, --host=...'
  21599.      Connect to the given host.
  21600.  
  21601. `-H, --html'
  21602.      Produce HTML output.
  21603.  
  21604. `-X, --xml'
  21605.      Produce XML output.
  21606.  
  21607. `-L, --skip-line-numbers'
  21608.      Don't write line number for errors. Useful when one wants to
  21609.      compare result files that includes error messages
  21610.  
  21611. `--no-pager'
  21612.      Disable pager and print to stdout. See interactive help (\h) also.
  21613.  
  21614. `--no-tee'
  21615.      Disable outfile. See interactive help (\h) also.
  21616.  
  21617. `-n, --unbuffered'
  21618.      Flush buffer after each query.
  21619.  
  21620. `-N, --skip-column-names'
  21621.      Don't write column names in results.
  21622.  
  21623. `-O, --set-variable var=option'
  21624.      Give a variable a value. `--help' lists variables.  Please note
  21625.      that `--set-variable' is deprecated since MySQL 4.0, just use
  21626.      `--var=option' on its own.
  21627.  
  21628. `-o, --one-database'
  21629.      Only update the default database. This is useful for skipping
  21630.      updates to other database in the binary log.
  21631.  
  21632. ``--pager[=...]''
  21633.      Output type. Default is your `ENV' variable `PAGER'. Valid pagers
  21634.      are less, more, cat [> filename], etc.  See interactive help (\h)
  21635.      also. This option does not work in batch mode. Pager works only in
  21636.      Unix.
  21637.  
  21638. `-p[password], --password[=...]'
  21639.      Password to use when connecting to server. If a password is not
  21640.      given on the command-line, you will be prompted for it.  Note that
  21641.      if you use the short form `-p' you can't have a space between the
  21642.      option and the password.
  21643.  
  21644. `-P port_num, --port=port_num'
  21645.      TCP/IP port number to use for connection.
  21646.  
  21647. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  21648.      To specify the connect protocol to use.  New in MySQL 4.1.
  21649.  
  21650. `-q, --quick'
  21651.      Don't cache result, print it row-by-row. This may slow down the
  21652.      server if the output is suspended. Doesn't use history file.
  21653.  
  21654. `-r, --raw'
  21655.      Write column values without escape conversion. Used with `--batch'
  21656.  
  21657. `--reconnect'
  21658.      If the connection is lost, automatically try to reconnect to the
  21659.      server (but only once).
  21660.  
  21661. `-s, --silent'
  21662.      Be more silent.
  21663.  
  21664. `-S  --socket=...'
  21665.      Socket file to use for connection.
  21666.  
  21667. `-t  --table'
  21668.      Output in table format. This is default in non-batch mode.
  21669.  
  21670. `-T, --debug-info'
  21671.      Print some debug information at exit.
  21672.  
  21673. `--tee=...'
  21674.      Append everything into outfile. See interactive help (\h) also.
  21675.      Does not work in batch mode.
  21676.  
  21677. `-u, --user=#'
  21678.      User for login if not current user.
  21679.  
  21680. `-U, --safe-updates[=#], --i-am-a-dummy[=#]'
  21681.      Only allow `UPDATE' and `DELETE' that uses keys. See below for
  21682.      more information about this option.  You can reset this option if
  21683.      you have it in your `my.cnf' file by using `--safe-updates=0'.
  21684.  
  21685. `-v, --verbose'
  21686.      More verbose output (-v -v -v gives the table output format).
  21687.  
  21688. `-V, --version'
  21689.      Output version information and exit.
  21690.  
  21691. `-w, --wait'
  21692.      Wait and retry if connection is down instead of aborting.
  21693.  
  21694. You can also set the following variables with `-O' or `--set-variable';
  21695. please note that `--set-variable' is deprecated since MySQL 4.0, just
  21696. use `--var=option' on its own:
  21697.  
  21698. *Variable Name*    *Default**Description*
  21699. connect_timeout    0       Number of seconds before timeout connection.
  21700. max_allowed_packet 16777216Max packetlength to send/receive from to server
  21701. net_buffer_length  16384   Buffer for TCP/IP and socket communication
  21702. select_limit       1000    Automatic limit for SELECT when using
  21703.                            -i-am-a-dummy
  21704. max_join_size      1000000 Automatic limit for rows in a join when using
  21705.                            -i-am-a-dummy.
  21706.  
  21707. If the `mysql' client loses connection to the server while sending it a
  21708. query, it will immediately and automatically try to reconnect once to
  21709. the server and send the query again.  Note that even if it succeeds in
  21710. reconnecting, as your first connection has ended, all your previous
  21711. session objects are lost: temporary tables, user and session variables.
  21712. Therefore, the above behaviour may be dangerous for you, as in this
  21713. example where the server was shut down and restarted without you
  21714. knowing it:
  21715.  
  21716.      mysql> set @a=1;
  21717.      Query OK, 0 rows affected (0.05 sec)
  21718.      
  21719.      mysql> insert into t values(@a);
  21720.      ERROR 2006: MySQL server has gone away
  21721.      No connection. Trying to reconnect...
  21722.      Connection id:    1
  21723.      Current database: test
  21724.      
  21725.      Query OK, 1 row affected (1.30 sec)
  21726.      
  21727.      mysql> select * from t;
  21728.      +------+
  21729.      | a    |
  21730.      +------+
  21731.      | NULL |
  21732.      +------+
  21733.      1 row in set (0.05 sec)
  21734.  
  21735. The `@a' user variable has been lost with the connection, and after the
  21736. reconnection it is undefined.  To protect from this risk, you can start
  21737. the `mysql' client with the `--disable-reconnect' option.
  21738.  
  21739. If you type 'help' on the command-line, `mysql' will print out the
  21740. commands that it supports:
  21741.  
  21742.      mysql> help
  21743.      
  21744.      MySQL commands:
  21745.      help      (\h)    Display this text.
  21746.      ?         (\h)    Synonym for `help'.
  21747.      clear     (\c)    Clear command.
  21748.      connect   (\r)    Reconnect to the server.
  21749.                        Optional arguments are db and host.
  21750.      delimiter (\d)    Set query delimiter.
  21751.      edit      (\e)    Edit command with $EDITOR.
  21752.      ego       (\G)    Send command to mysql server,
  21753.                        display result vertically.
  21754.      exit      (\q)    Exit mysql. Same as quit.
  21755.      go        (\g)    Send command to mysql server.
  21756.      nopager   (\n)    Disable pager, print to stdout.
  21757.      notee     (\t)    Don't write into outfile.
  21758.      pager     (\P)    Set PAGER [to_pager].
  21759.                        Print the query results via PAGER.
  21760.      print     (\p)    Print current command.
  21761.      prompt    (\R)    Change your mysql prompt.
  21762.      quit      (\q)    Quit mysql.
  21763.      rehash    (\#)    Rebuild completion hash.
  21764.      source    (\.)    Execute an SQL script file.
  21765.                        Takes a file name as an argument.
  21766.      status    (\s)    Get status information from the server.
  21767.      system    (\!)    Execute a system shell command.
  21768.      tee       (\T)    Set outfile [to_outfile].
  21769.                        Append everything into given outfile.
  21770.      use       (\u)    Use another database.
  21771.                        Takes database name as argument.
  21772.  
  21773. The `edit', `nopager', `pager', and `system' commands work only in Unix.
  21774.  
  21775. The `status' command gives you some information about the connection
  21776. and the server you are using. If you are running in the
  21777. `--safe-updates' mode, `status' will also print the values for the
  21778. `mysql' variables that affect your queries.
  21779.  
  21780. A useful startup option for beginners (introduced in MySQL Version
  21781. 3.23.11) is `--safe-updates' (or `--i-am-a-dummy' for users that once
  21782. may have done a `DELETE FROM table_name' but forgot the `WHERE'
  21783. clause).  When using this option, `mysql' sends the following command
  21784. to the MySQL server when opening the connection:
  21785.  
  21786.      SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#,
  21787.          SQL_MAX_JOIN_SIZE=#max_join_size#"
  21788.  
  21789. where `#select_limit#' and `#max_join_size#' are variables that can be
  21790. set from the `mysql' command-line. *Note `SET': SET OPTION.
  21791.  
  21792. The effect of the above is:
  21793.  
  21794.    * You are not allowed to do an `UPDATE' or `DELETE' statement if you
  21795.      don't have a key constraint in the `WHERE' part. One can, however,
  21796.      force an `UPDATE/DELETE' by using `LIMIT':
  21797.           UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1;
  21798.  
  21799.    * All big results are automatically limited to `#select_limit#' rows.
  21800.  
  21801.    * `SELECT's that will probably need to examine more than
  21802.      `#max_join_size' row combinations will be aborted.
  21803.  
  21804. Some useful hints about the `mysql' client:
  21805.  
  21806. Some data is much more readable when displayed vertically, instead of
  21807. the usual horizontal box type output. For example longer text, which
  21808. includes new lines, is often much easier to be read with vertical
  21809. output.
  21810.  
  21811.      mysql> SELECT * FROM mails WHERE LENGTH(txt) < 300 lIMIT 300,1\G
  21812.      *************************** 1. row ***************************
  21813.        msg_nro: 3068
  21814.           date: 2000-03-01 23:29:50
  21815.      time_zone: +0200
  21816.      mail_from: Monty
  21817.          reply: monty@no.spam.com
  21818.        mail_to: "Thimble Smith" <tim@no.spam.com>
  21819.            sbj: UTF-8
  21820.            txt: >>>>> "Thimble" == Thimble Smith writes:
  21821.      
  21822.      Thimble> Hi.  I think this is a good idea.  Is anyone familiar with UTF-8
  21823.      Thimble> or Unicode? Otherwise, I'll put this on my TODO list and see what
  21824.      Thimble> happens.
  21825.      
  21826.      Yes, please do that.
  21827.      
  21828.      Regards,
  21829.      Monty
  21830.           file: inbox-jani-1
  21831.           hash: 190402944
  21832.      1 row in set (0.09 sec)
  21833.  
  21834. For logging, you can use the `tee' option. The `tee' can be started
  21835. with option `--tee=...', or from the command-line interactively with
  21836. command `tee'. All the data displayed on the screen will also be
  21837. appended into a given file. This can be very useful for debugging
  21838. purposes also. The `tee' can be disabled from the command-line with
  21839. command `notee'. Executing `tee' again starts logging again. Without a
  21840. parameter the previous file will be used. Note that `tee' will flush
  21841. the results into the file after each command, just before the
  21842. command-line appears again waiting for the next command.
  21843.  
  21844. Browsing, or searching the results in the interactive mode in Unix less,
  21845. more, or any other similar program, is now possible with option
  21846. `--pager[=...]'. Without argument, `mysql' client will look for the
  21847. `PAGER' environment variable and set `pager' to that.  `pager' can be
  21848. started from the interactive command-line with command `pager' and
  21849. disabled with command `nopager'.  The command takes an argument
  21850. optionally and the `pager' will be set to that. Command `pager' can be
  21851. called without an argument, but this requires that the option `--pager'
  21852. was used, or the `pager' will default to stdout. `pager' works only in
  21853. Unix, since it uses the `popen()' function, which doesn't exist in
  21854. Windows. In Windows, the `tee' option can be used instead, although it
  21855. may not be as handy as `pager' can be in some situations.
  21856.  
  21857. A few tips about `pager':
  21858.    * You can use it to write to a file:
  21859.           mysql> pager cat > /tmp/log.txt
  21860.      and the results will only go to a file. You can also pass any
  21861.      options for the programs that you want to use with the `pager':
  21862.           mysql> pager less -n -i -S
  21863.  
  21864.    * From the above do note the option `-S'. You may find it very
  21865.      useful when browsing the results; try the option with horizontal
  21866.      output (end commands with `\g', or `;') and with vertical output
  21867.      (end commands with `\G'). Sometimes a very wide result set is hard
  21868.      to be read from the screen, with option `-S' to `less' you can
  21869.      browse the results within the interactive `less' from left to
  21870.      right, preventing lines longer than your screen from being
  21871.      continued to the next line. This can make the result set much more
  21872.      readable. You can switch the mode between on and off within the
  21873.      interactive `less' with `-S'. See the 'h' for more help about
  21874.      `less'.
  21875.  
  21876.    * You can combine very complex ways to handle the results, for
  21877.      example the following would send the results to two files in two
  21878.      different directories, on two different hard-disks mounted on /dr1
  21879.      and /dr2, yet let the results still be seen on the screen via less:
  21880.           mysql> pager cat | tee /dr1/tmp/res.txt | \
  21881.           tee /dr2/tmp/res2.txt | less -n -i -S
  21882.  
  21883.  
  21884. You can also combine the two functions above; have the `tee' enabled,
  21885. `pager' set to 'less' and you will be able to browse the results in
  21886. Unix 'less' and still have everything appended into a file the same
  21887. time. The difference between Unix `tee' used with the `pager' and the
  21888. `mysql' client in-built `tee', is that the in-built `tee' works even if
  21889. you don't have the Unix `tee' available. The in-built `tee' also logs
  21890. everything that is printed on the screen, where the Unix `tee' used
  21891. with `pager' doesn't log quite that much. Last, but not least, the
  21892. interactive `tee' is more handy to switch on and off, when you want to
  21893. log something into a file, but want to be able to turn the feature off
  21894. sometimes.
  21895.  
  21896. From MySQL version 4.0.2 it is possible to change the prompt in the
  21897. `mysql' command-line client.
  21898.  
  21899. You can use the following prompt options:
  21900. *Option**Description*
  21901. \v      mysqld version
  21902. \d      database in use
  21903. \h      host connected to
  21904. \p      port connected on
  21905. \u      username
  21906. \U      full username@host
  21907. \\      `\'
  21908. \n      new line break
  21909. \t      tab
  21910. \       space
  21911. \_      space
  21912. \R      military hour time (0-23)
  21913. \r      standard hour time (1-12)
  21914. \m      minutes
  21915. \y      two digit year
  21916. \Y      four digit year
  21917. \D      full date format
  21918. \s      seconds
  21919. \w      day of the week in three letter
  21920.         format (Mon, Tue, ...)
  21921. \P      am/pm
  21922. \o      month in number format
  21923. \O      month in three letter format (Jan,
  21924.         Feb, ...)
  21925. \c      counter that counts up for each
  21926.         command you do
  21927.  
  21928. `\' followed by any other letter just becomes that letter.
  21929.  
  21930. You may set the prompt in the following places:
  21931.  
  21932. *Environment Variable*
  21933.      You may set the `MYSQL_PS1' environment variable to a prompt
  21934.      string.  For example:
  21935.  
  21936.           shell> export MYSQL_PS1="(\u@\h) [\d]> "
  21937.  
  21938. *`my.cnf'*
  21939.  
  21940. *`.my.cnf'*
  21941.      You may set the `prompt' option in any MySQL configuration file,
  21942.      in the `mysql' group.  For example:
  21943.  
  21944.           [mysql]
  21945.           prompt=(\u@\h) [\d]>\_
  21946.  
  21947. *Command Line*
  21948.      You may set the `--prompt' option on the command line to `mysql'.
  21949.      For example:
  21950.  
  21951.           shell> mysql --prompt="(\u@\h) [\d]> "
  21952.           
  21953.           (user@host) [database]>
  21954.  
  21955. *Interactively*
  21956.      You may also use the `prompt' (or `\R') command to change your
  21957.      prompt interactively.  For example:
  21958.  
  21959.           mysql> prompt (\u@\h) [\d]>\_
  21960.           PROMPT set to '(\u@\h) [\d]>\_'
  21961.           (user@host) [database]>
  21962.           (user@host) [database]> prompt
  21963.           Returning to default PROMPT of mysql>
  21964.           mysql>
  21965.  
  21966. `mysqladmin', Administrating a MySQL Server
  21967. -------------------------------------------
  21968.  
  21969. A utility for performing administrative operations. The syntax is:
  21970.  
  21971.      shell> mysqladmin [OPTIONS] command [command-option] command ...
  21972.  
  21973. You can get a list of the options your version of `mysqladmin' supports
  21974. by executing `mysqladmin --help'.
  21975.  
  21976. The current `mysqladmin' supports the following commands:
  21977.  
  21978. `create databasename'
  21979.      Create a new database.
  21980.  
  21981. `drop databasename'
  21982.      Delete a database and all its tables.
  21983.  
  21984. `extended-status'
  21985.      Gives an extended status message from the server.
  21986.  
  21987. `flush-hosts'
  21988.      Flush all cached hosts.
  21989.  
  21990. `flush-logs'
  21991.      Flush all logs.
  21992.  
  21993. `flush-tables'
  21994.      Flush all tables.
  21995.  
  21996. `flush-privileges'
  21997.      Reload grant tables (same as reload).
  21998.  
  21999. `kill id,id,...'
  22000.      Kill mysql threads.
  22001.  
  22002. `password'
  22003.      Set a new password. Change old password to new-password.
  22004.  
  22005. `ping'
  22006.      Check if mysqld is alive.
  22007.  
  22008. `processlist'
  22009.      Show list of active threads in server, as with the `SHOW
  22010.      PROCESSLIST' statement.  If the `--verbose' option is given, the
  22011.      output is like that of `SHOW FULL PROCESSLIST'.
  22012.  
  22013. `reload'
  22014.      Reload grant tables.
  22015.  
  22016. `refresh'
  22017.      Flush all tables and close and open logfiles.
  22018.  
  22019. `shutdown'
  22020.      Take down the server.
  22021.  
  22022. `slave-start'
  22023.      Start slave replication thread.
  22024.  
  22025. `slave-stop'
  22026.      Stop slave replication thread.
  22027.  
  22028. `status'
  22029.      Gives a short status message from the server.
  22030.  
  22031. `variables'
  22032.      Prints variables available.
  22033.  
  22034. `version'
  22035.      Get version information from server.
  22036.  
  22037. All commands can be shortened to their unique prefix.  For example:
  22038.  
  22039.      shell> mysqladmin proc stat
  22040.      +----+-------+-----------+----+-------------+------+-------+------+
  22041.      | Id | User  | Host      | db | Command     | Time | State | Info |
  22042.      +----+-------+-----------+----+-------------+------+-------+------+
  22043.      | 6  | monty | localhost |    | Processlist | 0    |       |      |
  22044.      +----+-------+-----------+----+-------------+------+-------+------+
  22045.      Uptime: 10077  Threads: 1  Questions: 9  Slow queries: 0
  22046.      Opens: 6 Flush tables: 1  Open tables: 2
  22047.      Memory in use: 1092K  Max memory used: 1116K
  22048.  
  22049. The `mysqladmin status' command result has the following columns:
  22050.  
  22051. *Column*       *Description*
  22052. Uptime         Number of seconds the MySQL server has been up.
  22053. Threads        Number of active threads (clients).
  22054. Questions      Number of questions from clients since
  22055.                `mysqld' was started.
  22056. Slow queries   Queries that have taken more than
  22057.                `long_query_time' seconds. *Note Slow query
  22058.                log::.
  22059. Opens          How many tables `mysqld' has opened.
  22060. Flush tables   Number of `flush ...', `refresh', and `reload'
  22061.                commands.
  22062. Open tables    Number of tables that are open now.
  22063. Memory in use  Memory allocated directly by the `mysqld' code
  22064.                (only available when MySQL is compiled with
  22065.                -with-debug=full).
  22066. Max memory     Maximum memory allocated directly by the
  22067. used           `mysqld' code (only available when MySQL is
  22068.                compiled with -with-debug=full).
  22069.  
  22070. If you do `mysqladmin shutdown' on a socket (in other words, on a the
  22071. computer where `mysqld' is running), `mysqladmin' will wait until the
  22072. MySQL `pid-file' is removed to ensure that the `mysqld' server has
  22073. stopped properly.
  22074.  
  22075. `mysqlbinlog', Executing the queries from a binary log
  22076. ------------------------------------------------------
  22077.  
  22078. You can examine the binary log file (*note Binary log::) with the
  22079. `mysqlbinlog' utility.
  22080.  
  22081.      shell> mysqlbinlog hostname-bin.001
  22082.  
  22083. will print all queries contained in binlog `hostname-bin.001', together
  22084. with information (time the query took, ID of the thread which issued
  22085. it, timestamp when it was issued etc).
  22086.  
  22087. You can pipe the output of `mysqlbinlog' into a `mysql' client; this is
  22088. used to recover from a crash when you have an old backup (*note
  22089. Backup::):
  22090.  
  22091.      shell> mysqlbinlog hostname-bin.001 | mysql
  22092.  
  22093. or
  22094.  
  22095.      shell> mysqlbinlog hostname-bin.[0-9]* | mysql
  22096.  
  22097. You can also redirect the output of `mysqlbinlog' to a text file
  22098. instead, modify this text file (to cut queries you don't want to
  22099. execute for some reason), then execute the queries from the text file
  22100. into `mysql'.
  22101.  
  22102. `mysqlbinlog' has the `position=#' options which will print only
  22103. queries whose offset in the binlog is greater or equal to `#'.
  22104.  
  22105. If you have more than one binary log to execute on the MySQL server,
  22106. the safe method is to do it in one unique MySQL connection. Here is
  22107. what may be UNsafe:
  22108.  
  22109.      shell> mysqlbinlog hostname-bin.001 | mysql # DANGER!!
  22110.      shell> mysqlbinlog hostname-bin.002 | mysql # DANGER!!
  22111.  
  22112. It will cause problems if the first binlog contains a `CREATE TEMPORARY
  22113. TABLE' and the second one contains a query which uses this temporary
  22114. table: when the first `mysql' terminates, it will drop the temporary
  22115. table, so the second `mysql' will report "unknown table". This is why
  22116. you should run all binlogs you want in one unique connection,
  22117. especially if you use temporary tables. Here are two possible ways:
  22118.  
  22119.      shell> mysqlbinlog hostname-bin.001 hostname-bin.002 | mysql
  22120.  
  22121.      shell> mysqlbinlog hostname-bin.001 >  /tmp/queries.sql
  22122.      shell> mysqlbinlog hostname-bin.002 >> /tmp/queries.sql
  22123.      shell> mysql -e "source /tmp/queries.sql"
  22124.  
  22125. Starting from MySQL 4.0.14, `mysqlbinlog' can prepare suitable input
  22126. for `mysql' to execute a `LOAD DATA INFILE' from a binlog. As the binlog
  22127. contains the data to load (this is true for MySQL 4.0; MySQL 3.23 did
  22128. not write the loaded data into the binlog, so the original file was
  22129. needed when one wanted to execute the content of the binlog),
  22130. `mysqlbinlog' will copy this data to a temporary file and print a `LOAD
  22131. DATA INFILE' command for `mysql' to load this temporary file. The
  22132. location where the temporary file is created is by default the
  22133. temporary directory; it can be changed with the `local-load' option of
  22134. `mysqlbinlog'.
  22135.  
  22136. Before MySQL 4.1, `mysqlbinlog' could not prepare suitable output for
  22137. `mysql' when the binary log contained queries from different threads
  22138. using temporary tables of the same name, if these queries were
  22139. interlaced. This is solved in MySQL 4.1.
  22140.  
  22141. You can also use `mysqlbinlog --read-from-remote-server' to read the
  22142. binary log directly from a remote MySQL server.  However, this is
  22143. something that is deprecated as we instead want to make it easy to to
  22144. apply binary logs to a running MySQL server.
  22145.  
  22146. `mysqlbinlog --help' will give you more information.
  22147.  
  22148. Using `mysqlcheck' for Table Maintenance and Crash Recovery
  22149. -----------------------------------------------------------
  22150.  
  22151. Since MySQL version 3.23.38 you will be able to use a new checking and
  22152. repairing tool for `MyISAM' tables. The difference to `myisamchk' is
  22153. that `mysqlcheck' should be used when the `mysqld' server is running,
  22154. whereas `myisamchk' should be used when it is not. The benefit is that
  22155. you no longer have to take down the server for checking or repairing
  22156. your tables.
  22157.  
  22158. `mysqlcheck' uses MySQL server commands `CHECK', `REPAIR', `ANALYZE'
  22159. and `OPTIMIZE' in a convenient way for the user.
  22160.  
  22161. There are three alternative ways to invoke `mysqlcheck':
  22162.  
  22163.      shell> mysqlcheck [OPTIONS] database [tables]
  22164.      shell> mysqlcheck [OPTIONS] --databases DB1 [DB2 DB3...]
  22165.      shell> mysqlcheck [OPTIONS] --all-databases
  22166.  
  22167. So it can be used in a similar way as `mysqldump' when it comes to what
  22168. databases and tables you want to choose.
  22169.  
  22170. `mysqlcheck' does have a special feature compared to the other clients;
  22171. the default behaviour, checking tables (-c), can be changed by renaming
  22172. the binary. So if you want to have a tool that repairs tables by
  22173. default, you should just copy `mysqlcheck' to your harddrive with a new
  22174. name, `mysqlrepair', or alternatively make a symbolic link to
  22175. `mysqlrepair' and name the symbolic link as `mysqlrepair'. If you
  22176. invoke `mysqlrepair' now, it will repair tables by default.
  22177.  
  22178. The names that you can use to change `mysqlcheck' default behaviour are
  22179. here:
  22180.  
  22181.      mysqlrepair:   The default option will be -r
  22182.      mysqlanalyze:  The default option will be -a
  22183.      mysqloptimize: The default option will be -o
  22184.  
  22185. The options available for `mysqlcheck' are listed here, please check
  22186. what your version supports with `mysqlcheck --help'.
  22187.  
  22188. `-A, --all-databases'
  22189.      Check all the databases. This will be same as -databases with all
  22190.      databases selected
  22191.  
  22192. `-1, --all-in-1'
  22193.      Instead of making one query for each table, execute all queries in
  22194.      1 query separately for each database. Table names will be in a
  22195.      comma separated list.
  22196.  
  22197. `-a, --analyze'
  22198.      Analyse given tables.
  22199.  
  22200. `--auto-repair'
  22201.      If a checked table is corrupted, automatically fix it. Repairing
  22202.      will be done after all tables have been checked, if corrupted ones
  22203.      were found.
  22204.  
  22205. `-#, --debug=...'
  22206.      Output debug log. Often this is 'd:t:o,filename'
  22207.  
  22208. `--character-sets-dir=...'
  22209.      Directory where character sets are
  22210.  
  22211. `-c, --check'
  22212.      Check table for errors
  22213.  
  22214. `-C, --check-only-changed'
  22215.      Check only tables that have changed since last check or haven't
  22216.      been closed properly.
  22217.  
  22218. `--compress'
  22219.      Use compression in server/client protocol.
  22220.  
  22221. `-?, --help'
  22222.      Display this help message and exit.
  22223.  
  22224. `-B, --databases'
  22225.      To check several databases. Note the difference in usage; in this
  22226.      case no tables are given. All name arguments are regarded as
  22227.      database names.
  22228.  
  22229. `--default-character-set=...'
  22230.      Set the default character set
  22231.  
  22232. `-F, --fast'
  22233.      Check only tables that hasn't been closed properly
  22234.  
  22235. `-f, --force'
  22236.      Continue even if we get an sql-error.
  22237.  
  22238. `-e, --extended'
  22239.      If you are using this option with CHECK TABLE, it will ensure that
  22240.      the table is 100 percent consistent, but will take a long time.
  22241.  
  22242.      If you are using this option with REPAIR TABLE, it will run an
  22243.      extended repair on the table, which may not only take a long time
  22244.      to execute, but may produce a lot of garbage rows also!
  22245.  
  22246. `-h, --host=...'
  22247.      Connect to host.
  22248.  
  22249. `-m, --medium-check'
  22250.      Faster than extended-check, but only finds 99.99 percent of all
  22251.      errors. Should be good enough for most cases.
  22252.  
  22253. `-o, --optimize'
  22254.      Optimise table
  22255.  
  22256. `-p, --password[=...]'
  22257.      Password to use when connecting to server. If password is not given
  22258.      it's solicited on the tty.
  22259.  
  22260. `-P, --port=...'
  22261.      Port number to use for TCP/IP connections.
  22262.  
  22263. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22264.      To specify the connect protocol to use.  New in MySQL 4.1.
  22265.  
  22266. `-q, --quick'
  22267.      If you are using this option with CHECK TABLE, it prevents the
  22268.      check from scanning the rows to check for wrong links. This is the
  22269.      fastest check.
  22270.  
  22271.      If you are using this option with REPAIR TABLE, it will try to
  22272.      repair only the index tree. This is the fastest repair method for
  22273.      a table.
  22274.  
  22275. `-r, --repair'
  22276.      Can fix almost anything except unique keys that aren't unique.
  22277.  
  22278. `-s, --silent'
  22279.      Print only error messages.
  22280.  
  22281. `-S, --socket=...'
  22282.      Socket file to use for connection.
  22283.  
  22284. `--tables'
  22285.      Overrides option -databases (-B).
  22286.  
  22287. `-u, --user=#'
  22288.      User for login if not current user.
  22289.  
  22290. `-v, --verbose'
  22291.      Print information about the various stages.
  22292.  
  22293. `-V, --version'
  22294.      Output version information and exit.
  22295.  
  22296. `mysqldump', Dumping Table Structure and Data
  22297. ---------------------------------------------
  22298.  
  22299. Utility to dump a database or a collection of database for backup or for
  22300. transferring the data to another SQL server (not necessarily a MySQL
  22301. server).  The dump will contain SQL statements to create the table
  22302. and/or populate the table.
  22303.  
  22304. If you are doing a backup on the server, you should consider using the
  22305. `mysqlhotcopy' instead. *Note `mysqlhotcopy': mysqlhotcopy.
  22306.  
  22307.      shell> mysqldump [OPTIONS] database [tables]
  22308.      OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
  22309.      OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
  22310.  
  22311. If you don't give any tables or use the `--databases' or
  22312. `--all-databases', the whole database(s) will be dumped.
  22313.  
  22314. You can get a list of the options your version of `mysqldump' supports
  22315. by executing `mysqldump --help'.
  22316.  
  22317. Note that if you run `mysqldump' without `--quick' or `--opt',
  22318. `mysqldump' will load the whole result set into memory before dumping
  22319. the result.  This will probably be a problem if you are dumping a big
  22320. database.
  22321.  
  22322. Note that if you are using a new copy of the `mysqldump' program and
  22323. you are going to do a dump that will be read into a very old MySQL
  22324. server, you should not use the `--opt' or `-e' options.
  22325.  
  22326. `mysqldump' supports the following options:
  22327.  
  22328. `--add-locks'
  22329.      Add `LOCK TABLES' before and `UNLOCK TABLE' after each table dump.
  22330.      (To get faster inserts into MySQL.)
  22331.  
  22332. `--add-drop-table'
  22333.      Add a `drop table' before each create statement.
  22334.  
  22335. `-A, --all-databases'
  22336.      Dump all the databases. This will be same as `--databases' with all
  22337.      databases selected.
  22338.  
  22339. `-a, --all'
  22340.      Include all MySQL-specific create options.
  22341.  
  22342. `--allow-keywords'
  22343.      Allow creation of column names that are keywords.  This works by
  22344.      prefixing each column name with the table name.
  22345.  
  22346. `-c, --complete-insert'
  22347.      Use complete insert statements (with column names).
  22348.  
  22349. `-C, --compress'
  22350.      Compress all information between the client and the server if both
  22351.      support compression.
  22352.  
  22353. `-B, --databases'
  22354.      To dump several databases. Note the difference in usage. In this
  22355.      case no tables are given. All name arguments are regarded as
  22356.      database names.  `USE db_name;' will be included in the output
  22357.      before each new database.
  22358.  
  22359. `--delayed'
  22360.      Insert rows with the `INSERT DELAYED' command.
  22361.  
  22362. `-e, --extended-insert'
  22363.      Use the new multiline `INSERT' syntax. (Gives more compact and
  22364.      faster inserts statements.)
  22365.  
  22366. `-#, --debug[=option_string]'
  22367.      Trace usage of the program (for debugging).
  22368.  
  22369. `--help'
  22370.      Display a help message and exit.
  22371.  
  22372. `--fields-terminated-by=...'
  22373. `--fields-enclosed-by=...'
  22374. `--fields-optionally-enclosed-by=...'
  22375. `--fields-escaped-by=...'
  22376. `--lines-terminated-by=...'
  22377.      These options are used with the `-T' option and have the same
  22378.      meaning as the corresponding clauses for `LOAD DATA INFILE'.
  22379.      *Note `LOAD DATA': LOAD DATA.
  22380.  
  22381. `-F, --flush-logs'
  22382.      Flush log file in the MySQL server before starting the dump.
  22383.  
  22384. `-f, --force,'
  22385.      Continue even if we get an SQL error during a table dump.
  22386.  
  22387. `-h, --host=..'
  22388.      Dump data from the MySQL server on the named host. The default host
  22389.      is `localhost'.
  22390.  
  22391. `-l, --lock-tables.'
  22392.      Lock all tables before starting the dump.  The tables are locked
  22393.      with `READ LOCAL' to allow concurrent inserts in the case of
  22394.      `MyISAM' tables.
  22395.  
  22396.      Please note that when dumping multiple databases, `--lock-tables'
  22397.      will lock tables for each database separately. So using this
  22398.      option will not guarantee your tables will be logically consistent
  22399.      between databases.  Tables in different databases may be dumped in
  22400.      completely different states.
  22401.  
  22402. `-K, --disable-keys'
  22403.      `/*!40000 ALTER TABLE tb_name DISABLE KEYS */;' and `/*!40000
  22404.      ALTER TABLE tb_name ENABLE KEYS */;' will be put in the output.
  22405.      This will make loading the data into a MySQL 4.0 server faster as
  22406.      the indexes are created after all data are inserted.
  22407.  
  22408. `-n, --no-create-db'
  22409.      `CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be
  22410.      put in the output. The above line will be added otherwise, if a
  22411.      `--databases' or `--all-databases' option was given.
  22412.  
  22413. `-t, --no-create-info'
  22414.      Don't write table creation information (the `CREATE TABLE'
  22415.      statement).
  22416.  
  22417. `-d, --no-data'
  22418.      Don't write any row information for the table.  This is very
  22419.      useful if you just want to get a dump of the structure for a table!
  22420.  
  22421. `--opt'
  22422.      Same as `--quick --add-drop-table --add-locks --extended-insert
  22423.      --lock-tables'.  Should give you the fastest possible dump for
  22424.      reading into a MySQL server.
  22425.  
  22426. `-pyour_pass, --password[=your_pass]'
  22427.      The password to use when connecting to the server. If you specify
  22428.      no `=your_pass' part, `mysqldump' you will be prompted for a
  22429.      password.
  22430.  
  22431. `-P, --port=...'
  22432.      Port number to use for TCP/IP connections.
  22433.  
  22434. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22435.      To specify the connect protocol to use.  New in MySQL 4.1.
  22436.  
  22437. `-q, --quick'
  22438.      Don't buffer query, dump directly to stdout. Uses
  22439.      `mysql_use_result()' to do this.
  22440.  
  22441. `-Q, --quote-names'
  22442.      Quote table and column names within ``' characters.
  22443.  
  22444. `-r, --result-file=...'
  22445.      Direct output to a given file. This option should be used in MSDOS,
  22446.      because it prevents new line `\n' from being converted to `\n\r'
  22447.      (new line + carriage return).
  22448.  
  22449. `--single-transaction'
  22450.      This option issues a `BEGIN' SQL command before dumping data from
  22451.      server. It is mostly useful with `InnoDB' tables and
  22452.      `READ_COMMITTED' transaction isolation level, as in this mode it
  22453.      will dump the consistent state of the database at the time then
  22454.      `BEGIN' was issued without blocking any applications.
  22455.  
  22456.      When using this option you should keep in mind that only
  22457.      transactional tables will be dumped in a consistent state, for
  22458.      example, any `MyISAM' or `HEAP' tables dumped while using this
  22459.      option may still change state.
  22460.  
  22461.      The `--single-transaction' option was added in version 4.0.2.
  22462.      This option is mutually exclusive with the `--lock-tables' option
  22463.      as `LOCK TABLES' already commits a previous transaction internally.
  22464.  
  22465. `-S /path/to/socket, --socket=/path/to/socket'
  22466.      The socket file to use when connecting to `localhost' (which is the
  22467.      default host).
  22468.  
  22469. `--tables'
  22470.      Overrides option -databases (-B).
  22471.  
  22472. `-T, --tab=path-to-some-directory'
  22473.      Creates a `table_name.sql' file, that contains the SQL CREATE
  22474.      commands, and a `table_name.txt' file, that contains the data, for
  22475.      each give table.  The format of the `.txt' file is made according
  22476.      to the `--fields-xxx' and `--lines--xxx' options.  *Note*: This
  22477.      option only works if `mysqldump' is run on the same machine as the
  22478.      `mysqld' daemon. You must use a MySQL account that has the `FILE'
  22479.      privilege, and the login user/group that `mysqld' is running as
  22480.      (normally user `mysql', group `mysql') must have permission to
  22481.      create/write a file at the location you specify.
  22482.  
  22483. `-u user_name, --user=user_name'
  22484.      The MySQL user name to use when connecting to the server. The
  22485.      default value is your Unix login name.
  22486.  
  22487. `-O var=option, --set-variable var=option'
  22488.      Set the value of a variable.  The possible variables are listed
  22489.      below.  Please note that `--set-variable' is deprecated since
  22490.      MySQL 4.0, just use `--var=option' on its own.
  22491.  
  22492. `-v, --verbose'
  22493.      Verbose mode.  Print out more information on what the program does.
  22494.  
  22495. `-V, --version'
  22496.      Print version information and exit.
  22497.  
  22498. `-w, --where='where-condition''
  22499.      Dump only selected records. Note that quotes are mandatory:
  22500.           "--where=user='jimf'" "-wuserid>1" "-wuserid<1"
  22501.  
  22502. `-X, --xml'
  22503.      Dumps a database as well formed XML
  22504.  
  22505. `-x, --first-slave'
  22506.      Locks all tables across all databases.
  22507.  
  22508. `--master-data'
  22509.      Like `--first-slave', but also prints some `CHANGE MASTER TO'
  22510.      commands which will later make your slave start from the right
  22511.      position in the master's binlogs, if you have set up your slave
  22512.      using this SQL dump of the master.
  22513.  
  22514. `-O net_buffer_length=#, where # < 16M'
  22515.      When creating multi-row-insert statements (as with option
  22516.      `--extended-insert' or `--opt'), `mysqldump' will create rows up
  22517.      to `net_buffer_length' length. If you increase this variable, you
  22518.      should also ensure that the `max_allowed_packet' variable in the
  22519.      MySQL server is bigger than the `net_buffer_length'.
  22520.  
  22521. The most normal use of `mysqldump' is probably for making a backup of
  22522. whole databases. *Note Backup::.
  22523.  
  22524.      mysqldump --opt database > backup-file.sql
  22525.  
  22526. You can read this back into MySQL with:
  22527.  
  22528.      mysql database < backup-file.sql
  22529.  
  22530. or
  22531.  
  22532.      mysql -e "source /patch-to-backup/backup-file.sql" database
  22533.  
  22534. However, it's also very useful to populate another MySQL server with
  22535. information from a database:
  22536.  
  22537.      mysqldump --opt database | mysql ---host=remote-host -C database
  22538.  
  22539. It is possible to dump several databases with one command:
  22540.  
  22541.      mysqldump --databases database1 [database2 ...] > my_databases.sql
  22542.  
  22543. If all the databases are wanted, one can use:
  22544.  
  22545.      mysqldump --all-databases > all_databases.sql
  22546.  
  22547. `mysqlhotcopy', Copying MySQL Databases and Tables
  22548. --------------------------------------------------
  22549.  
  22550. `mysqlhotcopy' is a Perl script that uses `LOCK TABLES', `FLUSH TABLES'
  22551. and `cp' or `scp' to quickly make a backup of a database.  It's the
  22552. fastest way to make a backup of the database or single tables, but it
  22553. can only be run on the same machine where the database directories are.
  22554. `mysqlhotcopy' works only on Unix, and it works only for `MyISAM' and
  22555. `ISAM' tables.
  22556.  
  22557.      mysqlhotcopy db_name [/path/to/new_directory]
  22558.      
  22559.      mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
  22560.      
  22561.      mysqlhotcopy db_name./regex/
  22562.  
  22563. `mysqlhotcopy' supports the following options:
  22564.  
  22565. `-?, --help'
  22566.      Display a help screen and exit
  22567.  
  22568. `-u, --user=#'
  22569.      User for database login
  22570.  
  22571. `-p, --password=#'
  22572.      Password to use when connecting to server
  22573.  
  22574. `-P, --port=#'
  22575.      Port to use when connecting to local server
  22576.  
  22577. `-S, --socket=#'
  22578.      Socket to use when connecting to local server
  22579.  
  22580. `--allowold'
  22581.      Don't abort if target already exists (rename it _old)
  22582.  
  22583. `--keepold'
  22584.      Don't delete previous (now renamed) target when done
  22585.  
  22586. `--noindices'
  22587.      Don't include full index files in copy to make the backup smaller
  22588.      and faster The indexes can later be reconstructed with `myisamchk
  22589.      -rq.'.
  22590.  
  22591. `--method=#'
  22592.      Method for copy (`cp' or `scp').
  22593.  
  22594. `-q, --quiet'
  22595.      Be silent except for errors
  22596.  
  22597. `--debug'
  22598.      Enable debug
  22599.  
  22600. `-n, --dryrun'
  22601.      Report actions without doing them
  22602.  
  22603. `--regexp=#'
  22604.      Copy all databases with names matching regexp
  22605.  
  22606. `--suffix=#'
  22607.      Suffix for names of copied databases
  22608.  
  22609. `--checkpoint=#'
  22610.      Insert checkpoint entry into specified db.table
  22611.  
  22612. `--flushlog'
  22613.      Flush logs once all tables are locked.
  22614.  
  22615. `--tmpdir=#'
  22616.      Temporary directory (instead of /tmp).
  22617.  
  22618. You can use `perldoc mysqlhotcopy' to get more complete documentation
  22619. for `mysqlhotcopy'.
  22620.  
  22621. `mysqlhotcopy' reads the groups `[client]' and  `[mysqlhotcopy]' from
  22622. the option files.
  22623.  
  22624. To be able to execute `mysqlhotcopy' you need write access to the
  22625. backup directory, the `SELECT' privilege for the tables you are about to
  22626. copy and the MySQL `RELOAD' privilege (to be able to execute `FLUSH
  22627. TABLES').
  22628.  
  22629. `mysqlimport', Importing Data from Text Files
  22630. ---------------------------------------------
  22631.  
  22632. `mysqlimport' provides a command-line interface to the `LOAD DATA
  22633. INFILE' SQL statement.  Most options to `mysqlimport' correspond
  22634. directly to the same options to `LOAD DATA INFILE'.  *Note `LOAD DATA':
  22635. LOAD DATA.
  22636.  
  22637. `mysqlimport' is invoked like this:
  22638.  
  22639.      shell> mysqlimport [options] database textfile1 [textfile2 ...]
  22640.  
  22641. For each text file named on the command-line, `mysqlimport' strips any
  22642. extension from the filename and uses the result to determine which
  22643. table to import the file's contents into.  For example, files named
  22644. `patient.txt', `patient.text', and `patient' would all be imported into
  22645. a table named `patient'.
  22646.  
  22647. `mysqlimport' supports the following options:
  22648.  
  22649. `-c, --columns=...'
  22650.      This option takes a comma-separated list of field names as an
  22651.      argument.  The field list is used to create a proper `LOAD DATA
  22652.      INFILE' command, which is then passed to MySQL. *Note `LOAD DATA':
  22653.      LOAD DATA.
  22654.  
  22655. `-C, --compress'
  22656.      Compress all information between the client and the server if both
  22657.      support compression.
  22658.  
  22659. `-#, --debug[=option_string]'
  22660.      Trace usage of the program (for debugging).
  22661.  
  22662. `-d, --delete'
  22663.      Empty the table before importing the text file.
  22664.  
  22665. `--fields-terminated-by=...'
  22666. `--fields-enclosed-by=...'
  22667. `--fields-optionally-enclosed-by=...'
  22668. `--fields-escaped-by=...'
  22669. `--lines-terminated-by=...'
  22670.      These options have the same meaning as the corresponding clauses
  22671.      for `LOAD DATA INFILE'. *Note `LOAD DATA': LOAD DATA.
  22672.  
  22673. `-f, --force'
  22674.      Ignore errors.  For example, if a table for a text file doesn't
  22675.      exist, continue processing any remaining files.  Without `--force',
  22676.      `mysqlimport' exits if a table doesn't exist.
  22677.  
  22678. `--help'
  22679.      Display a help message and exit.
  22680.  
  22681. `-h host_name, --host=host_name'
  22682.      Import data to the MySQL server on the named host. The default host
  22683.      is `localhost'.
  22684.  
  22685. `-i, --ignore'
  22686.      See the description for the `--replace' option.
  22687.  
  22688. `--ignore-lines=n'
  22689.      Ignore first `n' lines of the datafile.
  22690.  
  22691. `-l, --lock-tables'
  22692.      Lock *all* tables for writing before processing any text files.
  22693.      This ensures that all tables are synchronised on the server.
  22694.  
  22695. `-L, --local'
  22696.      Read input files from the client.  By default, text files are
  22697.      assumed to be on the server if you connect to `localhost' (which
  22698.      is the default host).
  22699.  
  22700. `-pyour_pass, --password[=your_pass]'
  22701.      The password to use when connecting to the server. If you specify
  22702.      no `=your_pass' part, `mysqlimport' you will be prompted for a
  22703.      password.
  22704.  
  22705. `-P port_num, --port=port_num'
  22706.      TCP/IP port number to use for connection.
  22707.  
  22708. ``--protocol=(TCP | SOCKET | PIPE | MEMORY)''
  22709.      To specify the connect protocol to use.  New in MySQL 4.1.
  22710.  
  22711. `-r, --replace'
  22712.      The `--replace' and `--ignore' options control handling of input
  22713.      records that duplicate existing records on unique key values.  If
  22714.      you specify `--replace', new rows replace existing rows that have
  22715.      the same unique key value. If you specify `--ignore', input rows
  22716.      that duplicate an existing row on a unique key value are skipped.
  22717.      If you don't specify either option, an error occurs when a
  22718.      duplicate key value is found, and the rest of the text file is
  22719.      ignored.
  22720.  
  22721. `-s, --silent'
  22722.      Silent mode.  Write output only when errors occur.
  22723.  
  22724. `-S /path/to/socket, --socket=/path/to/socket'
  22725.      The socket file to use when connecting to `localhost' (which is the
  22726.      default host).
  22727.  
  22728. `-u user_name, --user=user_name'
  22729.      The MySQL user name to use when connecting to the server. The
  22730.      default value is your Unix login name.
  22731.  
  22732. `-v, --verbose'
  22733.      Verbose mode.  Print out more information what the program does.
  22734.  
  22735. `-V, --version'
  22736.      Print version information and exit.
  22737.  
  22738. Here is a sample run using `mysqlimport':
  22739.  
  22740.      $ mysql --version
  22741.      mysql  Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686)
  22742.      $ uname -a
  22743.      Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown
  22744.      $ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
  22745.      $ ed
  22746.      a
  22747.      100     Max Sydow
  22748.      101     Count Dracula
  22749.      .
  22750.      w imptest.txt
  22751.      32
  22752.      q
  22753.      $ od -c imptest.txt
  22754.      0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
  22755.      0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
  22756.      0000040
  22757.      $ mysqlimport --local test imptest.txt
  22758.      test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
  22759.      $ mysql -e 'SELECT * FROM imptest' test
  22760.      +------+---------------+
  22761.      | id   | n             |
  22762.      +------+---------------+
  22763.      |  100 | Max Sydow     |
  22764.      |  101 | Count Dracula |
  22765.      +------+---------------+
  22766.  
  22767. `mysqlshow', Showing Databases, Tables, and Columns
  22768. ---------------------------------------------------
  22769.  
  22770. `mysqlshow' can be used to quickly look at which databases exist, their
  22771. tables, and the table's columns.
  22772.  
  22773. With the `mysql' program you can get the same information with the
  22774. `SHOW' commands.  *Note SHOW::.
  22775.  
  22776. `mysqlshow' is invoked like this:
  22777.  
  22778.      shell> mysqlshow [OPTIONS] [database [table [column]]]
  22779.  
  22780.    * If no database is given, all matching databases are shown.
  22781.  
  22782.    * If no table is given, all matching tables in the database are
  22783.      shown.
  22784.  
  22785.    * If no column is given, all matching columns and column types in
  22786.      the table are shown.
  22787.  
  22788. Note that in newer MySQL versions, you only see those
  22789. database/tables/columns for which you have some privileges.
  22790.  
  22791. If the last argument contains a shell or SQL wildcard (`*', `?', `%' or
  22792. `_') then only what's matched by the wildcard is shown.  If a database
  22793. contains underscore(s), those should be escaped with backslash (some
  22794. Unix shells will require two), in order to get tables / columns
  22795. properly. '*' are converted into SQL '%' wildcard and '?' into SQL '_'
  22796. wildcard.  This may cause some confusion when you try to display the
  22797. columns for a table with a `_' as in this case `mysqlshow' only shows
  22798. you the table names that match the pattern.  This is easily fixed by
  22799. adding an extra `%' last on the command-line (as a separate argument).
  22800.  
  22801. `mysql_config', Get compile options for compiling clients
  22802. ---------------------------------------------------------
  22803.  
  22804. `mysql_config' provides you with useful information how to compile your
  22805. MySQL client and connect it to MySQL.
  22806.  
  22807. `mysql_config' supports the following options:
  22808.  
  22809. `--cflags'
  22810.      Compiler flags to find include files and critical ccompiler flags
  22811.      and defines used when compiling the `libmysqlclient' library.
  22812.  
  22813. `--include'
  22814.      Compiler options to find MySQL include files. (Normally one would
  22815.      use `--cflags' instead of this)
  22816.  
  22817. `--libs'
  22818.      Libraries and options required to link with the MySQL client
  22819.      library.
  22820.  
  22821. `--libs_r'
  22822.      Libraries and options required to link with the thread-safe MySQL
  22823.      client library.
  22824.  
  22825. `--socket'
  22826.      The default socket name, defined when configuring MySQL.
  22827.  
  22828. `--port'
  22829.      The default port number, defined when configuring MySQL.
  22830.  
  22831. `--version'
  22832.      Version number and version for the MySQL distribution.
  22833.  
  22834. `--libmysqld-libs or --embedded'
  22835.      Libraries and options required to link with the MySQL embedded
  22836.      server.
  22837.  
  22838. If you execute `mysql_config' without any options it will print all
  22839. options it supports plus the value of all options:
  22840.  
  22841.      shell> mysql_config
  22842.      Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
  22843.      Options:
  22844.              --cflags         [-I/usr/local/mysql/include/mysql -mcpu=pentiumpro]
  22845.              --include        [-I/usr/local/mysql/include/mysql]
  22846.              --libs           [-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto]
  22847.              --libs_r         [-L/usr/local/mysql/lib/mysql -lmysqlclient_r -lpthread -lz -lcrypt -lnsl -lm -lpthread]
  22848.              --socket         [/tmp/mysql.sock]
  22849.              --port           [3306]
  22850.              --version        [4.0.16]
  22851.              --libmysqld-libs [-L/usr/local/mysql/lib/mysql -lmysqld -lpthread -lz -lcrypt -lnsl -lm -lpthread -lrt]
  22852.  
  22853. You can use this to compile a MySQL client by as follows:
  22854.  
  22855.      CFG=/usr/local/mysql/bin/mysql_config
  22856.      sh -c "gcc -o progname `$CFG --cflags` progname.c `$CFG --libs`"
  22857.  
  22858. `perror', Explaining Error Codes
  22859. --------------------------------
  22860.  
  22861. For most system errors MySQL will, in addition to a internal text
  22862. message, also print the system error code in one of the following
  22863. styles: `message ... (errno: #)' or `message ... (Errcode: #)'.
  22864.  
  22865. You can find out what the error code means by either examining the
  22866. documentation for your system or use the `perror' utility.
  22867.  
  22868. `perror' prints a description for a system error code, or an MyISAM/ISAM
  22869. storage engine (table handler) error code.
  22870.  
  22871. `perror' is invoked like this:
  22872.  
  22873.      shell> perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  22874.      
  22875.      Example:
  22876.      
  22877.      shell> perror 13 64
  22878.      Error code  13:  Permission denied
  22879.      Error code  64:  Machine is not on the network
  22880.  
  22881. Note that the error messages are mostly system dependent!
  22882.  
  22883. How to Run SQL Commands from a Text File
  22884. ----------------------------------------
  22885.  
  22886. The `mysql' client typically is used interactively, like this:
  22887.  
  22888.      shell> mysql database
  22889.  
  22890. However, it's also possible to put your SQL commands in a file and tell
  22891. `mysql' to read its input from that file.  To do so, create a text file
  22892. `text_file' that contains the commands you wish to execute.  Then
  22893. invoke `mysql' as shown here:
  22894.  
  22895.      shell> mysql database < text_file
  22896.  
  22897. You can also start your text file with a `USE db_name' statement.  In
  22898. this case, it is unnecessary to specify the database name on the command
  22899. line:
  22900.  
  22901.      shell> mysql < text_file
  22902.  
  22903. If you are already running `mysql', you can execute an SQL script file
  22904. using the `source' command:
  22905.  
  22906.      mysql> source filename;
  22907.  
  22908. For more information about batch mode, *Note Batch mode::.
  22909.  
  22910. The MySQL Log Files
  22911. ===================
  22912.  
  22913. MySQL has several different log files that can help you find out what's
  22914. going on inside `mysqld':
  22915.  
  22916. *Log file*     *Description*
  22917. The error log  Problems encountering starting, running or stopping
  22918.                `mysqld'.
  22919. The isam log   Logs all changes to the ISAM tables. Used only for
  22920.                debugging the isam code.
  22921. The query log  Established connections and executed queries.
  22922. The update     Deprecated: Stores all statements that changes data
  22923. log            
  22924. The binary     Stores all statements that changes something. Used also
  22925. log            for replication
  22926. The slow log   Stores all queries that took more than `long_query_time'
  22927.                seconds to execute or didn't use indexes.
  22928.  
  22929. All logs can be found in the `mysqld' data directory.  You can force
  22930. `mysqld' to reopen the log files (or in some cases switch to a new log)
  22931. by executing `FLUSH LOGS'. *Note FLUSH::.
  22932.  
  22933. The Error Log
  22934. -------------
  22935.  
  22936. The error log file contains information indicating when `mysqld' was
  22937. started and stopped and also any critical errors found when running.
  22938.  
  22939. If `mysqld' dies unexpectedly and `mysqld_safe' needs to restart
  22940. `mysqld', `mysqld_safe' will write a `restarted mysqld' row in this
  22941. file.  This log also holds a warning if `mysqld' notices a table that
  22942. needs to be automatically checked or repaired.
  22943.  
  22944. On some operating systems, the error log will contain a stack trace for
  22945. where `mysqld' died. This can be used to find out where `mysqld' died.
  22946. *Note Using stack trace::.
  22947.  
  22948. Beginning with MySQL 4.0.10 you can specify where `mysqld' stores the
  22949. error log file with the option `--log-error[=filename]'. If no file
  22950. name is given `mysqld' will use `mysql-data-dir/'hostname'.err' on Unix
  22951. and `\mysql\data\mysql.err' on Windows.  If you execute `flush logs'
  22952. the old file will be prefixed with `--old' and `mysqld' will create a
  22953. new empty log file.
  22954.  
  22955. In older MySQL versions the error log handling was done by
  22956. `mysqld_safe' which redirected the error file to `'hostname'.err'.  One
  22957. could change this file name with the option `--err-log=filename'.
  22958.  
  22959. If you don't specify `--log-error' or if you use the `--console' option
  22960. the errors will be written to stderr (the terminal).
  22961.  
  22962. On Windows, the output is always written to the `.err' file if
  22963. `--console' is not given.
  22964.  
  22965. The General Query Log
  22966. ---------------------
  22967.  
  22968. If you want to know what happens within `mysqld', you should start it
  22969. with `--log[=file]'.  This will log all connections and queries to the
  22970. log file (by default named `'hostname'.log').  This log can be very
  22971. useful when you suspect an error in a client and want to know exactly
  22972. what `mysqld' thought the client sent to it.
  22973.  
  22974. Older versions of the `mysql.server' script (from MySQL 3.23.4 to
  22975. 3.23.8) pass `safe_mysqld' a `--log' option (enable general query log).
  22976. If you need better performance when you start using MySQL in a
  22977. production environment, you can remove the `--log' option from
  22978. `mysql.server' or change it to `--log-bin'. *Note Binary log::.
  22979.  
  22980. The entries in this log are written as `mysqld' receives the questions.
  22981. This may be different from the order in which the statements are
  22982. executed.  This is in contrast to the update log and the binary log
  22983. which are written after the query is executed, but before any locks are
  22984. released.
  22985.  
  22986. The Update Log
  22987. --------------
  22988.  
  22989. *Note*: the update log is replaced by the binary log. *Note Binary
  22990. log::.  With this you can do anything that you can do with the update
  22991. log. *The update log will be removed in MySQL 5.0*.
  22992.  
  22993. When started with the `--log-update[=file_name]' option, `mysqld'
  22994. writes a log file containing all SQL commands that update data. If no
  22995. filename is given, it defaults to the name of the host machine. If a
  22996. filename is given, but it doesn't contain a path, the file is written
  22997. in the data directory. If `file_name' doesn't have an extension,
  22998. `mysqld' will create log file names like so: `file_name.###', where
  22999. `###' is a number that is incremented each time you execute `mysqladmin
  23000. refresh', execute `mysqladmin flush-logs', execute the `FLUSH LOGS'
  23001. statement, or restart the server.
  23002.  
  23003. *Note*: for the above scheme to work, you must not create your own
  23004. files with the same filename as the update log + some extensions that
  23005. may be regarded as a number, in the directory used by the update log!
  23006.  
  23007. If you use the `--log' or `-l' options, `mysqld' writes a general log
  23008. with a filename of `hostname.log', and restarts and refreshes do not
  23009. cause a new log file to be generated (although it is closed and
  23010. reopened). In this case you can copy it (on Unix) by doing:
  23011.  
  23012.      mv hostname.log hostname-old.log
  23013.      mysqladmin flush-logs
  23014.      cp hostname-old.log to-backup-directory
  23015.      rm hostname-old.log
  23016.  
  23017. Update logging is smart because it logs only statements that really
  23018. update data. So an `UPDATE' or a `DELETE' with a `WHERE' that finds no
  23019. rows is not written to the log. It even skips `UPDATE' statements that
  23020. set a column to the value it already has.
  23021.  
  23022. The update logging is done immediately after a query completes but
  23023. before any locks are released or any commit is done. This ensures that
  23024. the log will be logged in the execution order.
  23025.  
  23026. If you want to update a database from update log files, you could do the
  23027. following (assuming your update logs have names of the form
  23028. `file_name.###'):
  23029.  
  23030.      shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
  23031.  
  23032. `ls' is used to get all the log files in the right order.
  23033.  
  23034. This can be useful if you have to revert to backup files after a crash
  23035. and you want to redo the updates that occurred between the time of the
  23036. backup and the crash.
  23037.  
  23038. The Binary Log
  23039. --------------
  23040.  
  23041. The intention is that the binary log should replace the update log, so
  23042. we recommend you to switch to this log format as soon as possible! The
  23043. update log will be removed in MySQL 5.0.
  23044.  
  23045. The binary log contains all information that is available in the update
  23046. log in a more efficient format. It also contains information about how
  23047. long each query took that updated the database.  It doesn't contain
  23048. queries that don't modify any data.  If you want to log all queries
  23049. (for example to find a problem query) you should use the general query
  23050. log. *Note Query log::.
  23051.  
  23052. The binary log is also used when you are replicating a slave from a
  23053. master.  *Note Replication::.
  23054.  
  23055. When started with the `--log-bin[=file_name]' option, `mysqld' writes a
  23056. log file containing all SQL commands that update data. If no file name
  23057. is given, it defaults to the name of the host machine followed by
  23058. `-bin'. If file name is given, but it doesn't contain a path, the file
  23059. is written in the data directory.
  23060.  
  23061. If you supply an extension to `--log-bin=filename.extension', the
  23062. extension will be silenty removed.
  23063.  
  23064. To the binary log filename `mysqld' will append an extension that is a
  23065. number that is incremented each time you execute `mysqladmin refresh',
  23066. execute `mysqladmin flush-logs', execute the `FLUSH LOGS' statement or
  23067. restart the server. A new binary log will also automatically be created
  23068. when the current one's size reaches `max_binlog_size'. Note if you are
  23069. using transactions: a transaction is written in one chunk to the binary
  23070. log, hence it is never split between several binary logs. Therefore, if
  23071. you have big transactions, you may see binlogs bigger than
  23072. `max_binlog_size'.
  23073.  
  23074. You can delete all binary log files with the `RESET MASTER' command
  23075. (*note `RESET': RESET.), or only some of them with `PURGE MASTER LOGS'
  23076. (*note Replication Master SQL::).
  23077.  
  23078. You can use the following options to `mysqld' to affect what is logged
  23079. to the binary log (please make sure to read the notes which follow this
  23080. table):
  23081.  
  23082. *Option*                    *Description*
  23083. `binlog-do-db=database_name' Tells the master that it should log updates
  23084.                             to the binary log if the current database
  23085.                             (that is, the one selected by `USE')
  23086.                             database is 'database_name'. All others
  23087.                             databases which are not explicitly mentioned
  23088.                             are ignored.  Note that if you use this you
  23089.                             should ensure that you only do updates in
  23090.                             the current database.  (Example:
  23091.                             `binlog-do-db=some_database')
  23092.                             
  23093.                             Example of what does not work as you could
  23094.                             expect it: if the server is started with
  23095.                             `binlog-do-db=sales', and you do `USE
  23096.                             prices; UPDATE sales.january SET
  23097.                             amount=amount+1000;', this query will not be
  23098.                             written into the binary log.
  23099. `binlog-ignore-db=database_name' Tells the master that updates where the
  23100.                             current database (that is, the one selected
  23101.                             by `USE') is 'database_name' should not be
  23102.                             stored in the binary log.  Note that if you
  23103.                             use this you should ensure that you only do
  23104.                             updates in the current database.  (Example:
  23105.                             `binlog-ignore-db=some_database')
  23106.                             
  23107.                             Example of what does not work as you could
  23108.                             expect it: if the server is started with
  23109.                             `binlog-ignore-db=sales', and you do `USE
  23110.                             prices; UPDATE sales.january SET
  23111.                             amount=amount+1000;', this query will be
  23112.                             written into the binary log.
  23113.  
  23114. The rules are evaluated in the following order, to decide if the query
  23115. should be written to the binary log or not:
  23116.   1. Are there `binlog-do-db' or `binlog-ignore-db' rules?
  23117.         * No: write the query to the binlog and exit.
  23118.  
  23119.         * Yes: go to step below.
  23120.  
  23121.   2. So there are some rules (`binlog-do-db' or `binlog-ignore-db' or
  23122.      both). Is there a current database (has any database been selected
  23123.      by `USE'?)?
  23124.         * No: do *NOT* write the query, and exit.
  23125.  
  23126.         * Yes: go to step below.
  23127.  
  23128.   3. There is a current database. Are there some `binlog-do-db' rules?
  23129.         * Yes: Does the current database match any of the `binlog-do-db'
  23130.           rules?
  23131.              * Yes: write the query and exit.
  23132.  
  23133.              * No: do *NOT* write the query, and exit.
  23134.  
  23135.         * No: go to step below.
  23136.  
  23137.   4. There are some `binlog-ignore-db' rules.  Does the current
  23138.      database match any of the `binlog-ignore-db' rules?
  23139.         * Yes: do not write the query, and exit.
  23140.  
  23141.         * No: write the query and exit.
  23142.  
  23143. So for example, a slave running with only `binlog-do-db=sales' will not
  23144. write to the binlog any query whose current database is different from
  23145. `sales' (in other words, `binlog-do-db' can sometimes mean "ignore
  23146. other databases").
  23147.  
  23148. To be able to know which different binary log files have been used,
  23149. `mysqld' will also create a binary log index file that contains the
  23150. name of all used binary log files. By default this has the same name as
  23151. the binary log file, with the extension `'.index''.  You can change the
  23152. name of the binary log index file with the `--log-bin-index=[filename]'
  23153. option.  You should not manually edit this file while `mysqld' is
  23154. running; doing this would confuse `mysqld'.
  23155.  
  23156. If you are using replication, you should not delete old binary log
  23157. files until you are sure that no slave will ever need to use them.  One
  23158. way to do this is to do `mysqladmin flush-logs' once a day and then
  23159. remove any logs that are more than 3 days old. You can remove them
  23160. manually, or preferably using `PURGE MASTER LOGS' (*note Replication
  23161. Master SQL::) which will also safely update the binary log index file
  23162. for you  (and which can take a date argument since MySQL 4.1)
  23163.  
  23164. A connection with the `SUPER' privilege can disable the binary logging
  23165. of its queries using `SET SQL_LOG_BIN=0'. *Note Replication Master
  23166. SQL::.
  23167.  
  23168. You can examine the binary log file with the `mysqlbinlog' utility.
  23169. For example, you can update a MySQL server from the binary log as
  23170. follows:
  23171.  
  23172.      shell> mysqlbinlog log-file | mysql -h server_name
  23173.  
  23174. See *Note mysqlbinlog:: for more information on the `mysqlbinlog'
  23175. utility and how to use it.
  23176.  
  23177. If you are using `BEGIN [WORK]' or `SET AUTOCOMMIT=0', you must use the
  23178. MySQL binary log for backups instead of the old update log, which will
  23179. be removed in MySQL 5.0.
  23180.  
  23181. The binary logging is done immediately after a query completes but
  23182. before any locks are released or any commit is done. This ensures that
  23183. the log will be logged in the execution order.
  23184.  
  23185. Updates to non-transactional tables are stored in the binary log
  23186. immediately after execution.  For transactional tables such as `BDB' or
  23187. `InnoDB' tables, all updates (`UPDATE', `DELETE' or `INSERT') that
  23188. change tables are cached until a `COMMIT' command is sent to the
  23189. server. At this point `mysqld' writes the whole transaction to the
  23190. binary log before the `COMMIT' is executed.  Every thread will, on
  23191. start, allocate a buffer of `binlog_cache_size' to buffer queries.  If
  23192. a query is bigger than this, the thread will open a temporary file to
  23193. store the transaction.  The temporary file will be deleted when the
  23194. thread ends.
  23195.  
  23196. The `max_binlog_cache_size' (default 4G) can be used to restrict the
  23197. total size used to cache a multi-query transaction.  If a transaction is
  23198. bigger than this it will fail and roll back.
  23199.  
  23200. If you are using the update or binary log, concurrent inserts will be
  23201. converted to normal inserts when using `CREATE ... SELECT' or `INSERT
  23202. ... SELECT'.  This is to ensure that you can recreate an exact copy of
  23203. your tables by applying the log on a backup.
  23204.  
  23205. The Slow Query Log
  23206. ------------------
  23207.  
  23208. When started with the `--log-slow-queries[=file_name]' option, `mysqld'
  23209. writes a log file containing all SQL commands that took more than
  23210. `long_query_time' seconds to execute. The time to get the initial table
  23211. locks are not counted as execution time.
  23212.  
  23213. The slow query log is logged after the query is executed and after all
  23214. locks has been released. This may be different from the order in which
  23215. the statements are executed.
  23216.  
  23217. If no file name is given, it defaults to the name of the host machine
  23218. suffixed with `-slow.log'. If a filename is given, but doesn't contain
  23219. a path, the file is written in the data directory.
  23220.  
  23221. The slow query log can be used to find queries that take a long time to
  23222. execute and are thus candidates for optimisation. With a large log, that
  23223. can become a difficult task. You can pipe the slow query log through the
  23224. `mysqldumpslow' command to get a summary of the queries which appear in
  23225. the log.
  23226.  
  23227. You are using `--log-long-format' then also queries that are not using
  23228. indexes are printed. *Note Command-line options::.
  23229.  
  23230. Log File Maintenance
  23231. --------------------
  23232.  
  23233. The MySQL Server can create a number of different log files, which make
  23234. it easy to see what is going on. *Note Log Files::. However, you must
  23235. clean up these files regularly, to ensure that the logs don't take up
  23236. too much disk space.
  23237.  
  23238. When using MySQL with log files, you will want to remove/backup old log
  23239. files from time to time and tell MySQL to start logging to new files.
  23240. *Note Backup::.
  23241.  
  23242. On a Linux (`Red Hat') installation, you can use the `mysql-log-rotate'
  23243. script for this. If you installed MySQL from an RPM distribution, the
  23244. script should have been installed automatically.  Note that you should
  23245. be careful with this script if you are using the binary log for
  23246. replication!
  23247.  
  23248. On other systems you must install a short script yourself that you
  23249. start from `cron' to handle log files.
  23250.  
  23251. You can force MySQL to start using new log files by using `mysqladmin
  23252. flush-logs' or by using the SQL command `FLUSH LOGS'.  If you are using
  23253. MySQL Version 3.21, you must use `mysqladmin refresh'.
  23254.  
  23255. The above command does the following:
  23256.  
  23257.    * If standard logging (`--log') or slow query logging
  23258.      (`--log-slow-queries') is used, closes and reopens the log file
  23259.      (`mysql.log' and ``hostname`-slow.log' as default).
  23260.  
  23261.    * If update logging (`--log-update') is used, closes the update log
  23262.      and opens a new log file with a higher sequence number.
  23263.  
  23264. If you are using only an update log, you only have to flush the logs
  23265. and then move away the old update log files to a backup.  If you are
  23266. using the normal logging, you can do something like:
  23267.  
  23268.      shell> cd mysql-data-directory
  23269.      shell> mv mysql.log mysql.old
  23270.      shell> mysqladmin flush-logs
  23271.  
  23272. and then take a backup and remove `mysql.old'.
  23273.  
  23274. Replication in MySQL
  23275. ====================
  23276.  
  23277. Replication capabilities allowing the databases on one MySQL server to
  23278. be duplicated on another were introduced in MySQL version 3.23.15.
  23279. This section describes the various replication features in MySQL.  It
  23280. serves as a reference to the options available with replication.  You
  23281. will be introduced to replication and learn how to implement it.
  23282. Toward that end, there are some frequently asked questions, descriptions
  23283. of problems, and how to solve them.
  23284.  
  23285. We suggest that you visit our website at `http://www.mysql.com/' often
  23286. and read updates to this section. Replication is constantly being
  23287. improved, and we update the manual frequently with the most current
  23288. information.
  23289.  
  23290. Introduction
  23291. ------------
  23292.  
  23293. Starting in Version 3.23.15, MySQL supports one-way replication
  23294. internally. One server acts as the master, while one or more other
  23295. servers act as slaves.  The master server keeps a binary log of updates
  23296. (*note Binary log::).  It also maintains an index file of the binary
  23297. logs to keep track of log rotation.  Each slave, upon connecting,
  23298. informs the master where it left off since the last successfully
  23299. propagated update, catches up any updates that have occurred since
  23300. then, and then blocks and waits for the master to notify it of new
  23301. updates.
  23302.  
  23303. A slave can also serve as a master if you set up chained replication
  23304. servers.
  23305.  
  23306. Note that when you are using replication, all updates to the tables
  23307. that are replicated should be performed on the master server.
  23308. Otherwise, you must always be careful to avoid conflicts between
  23309. updates that users make to tables on the master and updates that they
  23310. make to tables on the slave.
  23311.  
  23312. One-way replication has benefits for robustness, speed, and system
  23313. administration:
  23314.  
  23315.    * Robustness is increased with a master/slave setup.  In the event
  23316.      of problems with the master, you can switch to the slave as a
  23317.      backup.
  23318.  
  23319.    * The extra speed is achieved by splitting the load for processing
  23320.      client queries between the master and slave servers, resulting in
  23321.      better client response time.  `SELECT' queries may be sent to the
  23322.      slave to reduce query processing load of the master. Queries that
  23323.      modify data should still be sent to the master so that the master
  23324.      and slave to not get out of sync.  This load-balancing strategy if
  23325.      effective if non-updating queries dominate, but that is the normal
  23326.      case.
  23327.  
  23328.    * Another benefit of using replication is that one can get
  23329.      non-disturbing backups of the system by doing a backup on a slave
  23330.      instead of doing it on the master. *Note Backup::.
  23331.  
  23332.  
  23333. Replication Implementation Overview
  23334. -----------------------------------
  23335.  
  23336. MySQL replication is based on the master server keeping track of all
  23337. changes to your database (updates, deletes, etc) in the binary log
  23338. (*note Binary log::).  Each slave server receives from the master the
  23339. saved queries that the master has recorded in its binary log, so that
  23340. the slave can execute the same queries on its copy of the data.
  23341.  
  23342. It is *very important* to realise that the binary log is simply a
  23343. record starting from a fixed point in time (the moment you enable binary
  23344. logging). Any slaves that you set up will need copies of the databases
  23345. on your master as they existed at the moment you enabled binary logging
  23346. on the master. If you start your slaves with data that is not the same
  23347. as what was on the master *when the binary log was started*, your
  23348. slaves may fail.
  23349.  
  23350. The following table indicates master/slave replication compatibility
  23351. between different versions of MySQL.
  23352.  
  23353.                     *Master*    *Master**Master**Master*
  23354.                     *3.23.33    *4.0.0* *4.0.1* *4.0.3 and
  23355.                     and up*                     up*
  23356. *Slave* *3.23.33    yes         no      no      no
  23357.         and up*                                 
  23358. *Slave* *4.0.0*     no          yes     no      no
  23359. *Slave* *4.0.1*     yes         no      yes     no
  23360. *Slave* *4.0.3 and  yes         no      no      yes
  23361.         up*                                     
  23362.  
  23363. As a general rule, it's always recommended to use recent MySQL versions,
  23364. because replication capabilities are continually being improved.  With
  23365. regard to version 4.0, we recommend using same version for both the
  23366. master and the slave, with the exception that MySQL 4.0.2 is not
  23367. recommended for replication.
  23368.  
  23369. Note that when you upgrade a master from MySQL 3.23 to MySQL 4.0 (or
  23370. 4.1) you should not restart replication using old 3.23 binary logs,
  23371. because this will unfortunately confuse the 4.0 slave. The upgrade can
  23372. safely be done this way, assuming you have a 3.23 master to upgrade and
  23373. you have 4.0 slaves:
  23374.  
  23375.   1. Block all updates on the master (`FLUSH TABLES WITH READ LOCK').
  23376.  
  23377.   2. Wait until all the slaves have caught up all changes from the
  23378.      master (use `SHOW MASTER STATUS' on the master, and `SELECT
  23379.      MASTER_POS_WAIT()' on the slaves). Then run `STOP SLAVE' on the
  23380.      slaves.
  23381.  
  23382.   3. Shut down MySQL on the master and upgrade the master to MySQL 4.0.
  23383.  
  23384.   4. Restart MySQL on the master. Record the name `<name>' of the
  23385.      master's newly created binary log. You can obtain the name of the
  23386.      file by issuing `SHOW MASTER STATUS' on the master. Then issue
  23387.      these commands on each slave:
  23388.           mysql> CHANGE MASTER TO MASTER_LOG_FILE='<name>', MASTER_LOG_POS=4;
  23389.           mysql> START SLAVE;
  23390.  
  23391.  
  23392. If you also must upgrade your slaves from 3.23 to 4.0, you should first
  23393. upgrade your slaves: Shut down each one, upgrade it, and restart it.
  23394. Then upgrade the master as just described.
  23395.  
  23396. Starting from 4.0.0, you can use `LOAD DATA FROM MASTER' to set up a
  23397. slave. Be aware that `LOAD DATA FROM MASTER' currently works only if
  23398. all the tables on the master are `MyISAM' type. Also, this statement
  23399. acquires a global read lock, so no writes are possible while the tables
  23400. are being transferred from the master. When we implement lock-free hot
  23401. table backup (in MySQL 5.0), this global read lock will no longer be
  23402. necessary.
  23403.  
  23404. Due to these limitations, we recommend that at this point  you use
  23405. `LOAD DATA FROM MASTER' only if the dataset on the master is relatively
  23406. small, or if a prolonged read lock on the master is acceptable. While
  23407. the actual speed of `LOAD DATA FROM MASTER' may vary from system to
  23408. system, a good rule of thumb for how long it is going to take is 1
  23409. second per 1 MB of the datafile. You will get close to the estimate if
  23410. both master and slave are equivalent to 700 MHz Pentium and are
  23411. connected through a 100 MBit/s network.  Of course, this is only a
  23412. rough estimate.
  23413.  
  23414. Once a slave is properly configured and running, it will simply connect
  23415. to the master and wait for updates to process. If the master goes away
  23416. or the slave loses connectivity with your master, it will keep trying to
  23417. connect periodically until it is able to reconnect and resume listening
  23418. for updates. The retry interval is controlled by the
  23419. `--master-connect-retry' option. The default is 60 seconds.
  23420.  
  23421. Each slave keeps track of where it left off. The master server has no
  23422. knowledge of how many slaves there are or which ones are up-to-date at
  23423. any given time.
  23424.  
  23425. Replication Implementation Details
  23426. ----------------------------------
  23427.  
  23428. Three threads are involved in replication: one on the master and two on
  23429. the slave.  When `START SLAVE' is issued, the I/O thread is created on
  23430. the slave. It connects to the master and asks it to send the queries
  23431. recorded in its binlogs. Then one thread is created on the master to
  23432. send these binlogs.  This thread is identified by `Binlog Dump' in
  23433. `SHOW PROCESSLIST' output on the master.  The I/O thread reads what the
  23434. master `Binlog Dump' thread sends and simply copies it to some local
  23435. files in the slave's data directory called relay logs.  The last
  23436. thread, the SQL thread, is created on the slave; it reads the relay
  23437. logs and executes the queries it contains.
  23438.  
  23439. Note that the master has one thread for each currently connected slave
  23440. server.
  23441.  
  23442. With `SHOW PROCESSLIST' you can know what is happening on the master
  23443. and on the slave as regards replication.
  23444.  
  23445. The following example illustrates how the three threads show up in
  23446. `SHOW PROCESSLIST'.  The output format is that used by `SHOW
  23447. PROCESSLIST' as of MySQL version 4.0.15, when the content of the
  23448. `State' column was changed to be more meaningful compared to earlier
  23449. versions.
  23450.  
  23451. On the master server, the output looks like this:
  23452.  
  23453.      mysql> SHOW PROCESSLIST\G
  23454.      *************************** 1. row ***************************
  23455.           Id: 2
  23456.         User: root
  23457.         Host: localhost:32931
  23458.           db: NULL
  23459.      Command: Binlog Dump
  23460.         Time: 94
  23461.        State: Has sent all binlog to slave; waiting for binlog to be updated
  23462.         Info: NULL
  23463.  
  23464. On the slave server, the output looks like this:
  23465.  
  23466.      mysql> SHOW PROCESSLIST\G
  23467.      *************************** 1. row ***************************
  23468.           Id: 10
  23469.         User: system user
  23470.         Host:
  23471.           db: NULL
  23472.      Command: Connect
  23473.         Time: 11
  23474.        State: Waiting for master to send event
  23475.         Info: NULL
  23476.      *************************** 2. row ***************************
  23477.           Id: 11
  23478.         User: system user
  23479.         Host:
  23480.           db: NULL
  23481.      Command: Connect
  23482.         Time: 11
  23483.        State: Has read all relay log; waiting for the I/O slave thread to update it
  23484.         Info: NULL
  23485.  
  23486. Here thread 2 is on the master. Thread 10 is the I/O thread on the
  23487. slave.  Thread 11 is the SQL thread on the slave; note that the value
  23488. in the `Time' column can tell how late the slave is compared to the
  23489. master (*note Replication FAQ::).
  23490.  
  23491. The following list shows the most common states you will see in the
  23492. `State' column for the master's `Binlog Dump' thread. If you don't see
  23493. this thread on a master server, replication is not running.
  23494.  
  23495. `Sending binlog event to slave'
  23496.      Binlogs consist of events, where an event is usually a query plus
  23497.      some other information. The thread has read an event from the
  23498.      binlog and is sending it to the slave.
  23499.  
  23500. `Finished reading one binlog; switching to next binlog'
  23501.      The thread has finished reading a binlog file and is opening the
  23502.      next one to send to the slave.
  23503.  
  23504. `Has sent all binlog to slave; waiting for binlog to be updated'
  23505.      The thread has read all binary log files and is idle. It is
  23506.      waiting for new events to appear in the binary log as a result of
  23507.      new update queries being executed on the master.
  23508.  
  23509. `Waiting to finalize termination'
  23510.      A very brief state that happens as the thread is stopping.
  23511.  
  23512. Here are the most common states you will see in the `State' column for
  23513. the I/O thread of a slave server. Beginning with MySQL 4.1.1, this
  23514. state also appears in the `Slave_IO_State' column of `SHOW SLAVE
  23515. STATUS' output. This means that you can get a good view of what is
  23516. happening by using only `SHOW SLAVE STATUS'.
  23517.  
  23518. `Connecting to master'
  23519.      The thread is attempting to connect to the master.
  23520.  
  23521. `Checking master version'
  23522.      A very brief state that happens just after the connection to the
  23523.      master is established.
  23524.  
  23525. `Registering slave on master'
  23526.      A very brief state that happens just after the connection to the
  23527.      master is established.
  23528.  
  23529. `Requesting binlog dump'
  23530.      A very brief state that happens just after the connection to the
  23531.      master is established.  The thread sends to the master a request
  23532.      for the contents of its binlogs, starting from the requested
  23533.      binlog filename and position.
  23534.  
  23535. `Waiting to reconnect after a failed binlog dump request'
  23536.      If the binlog dump request failed (due to disconnection), the
  23537.      thread goes into this state while it sleeps. The thread sleeps for
  23538.      `master-connect-retry' seconds before retrying.
  23539.  
  23540. `Reconnecting after a failed binlog dump request'
  23541.      Then the thread tries to reconnect to the master.
  23542.  
  23543. `Waiting for master to send event'
  23544.      The thread has connected and is waiting for binlog events to
  23545.      arrive. This can last for a long time if the master is idle. If the
  23546.      wait lasts for `slave_read_timeout' seconds, a timeout will occur.
  23547.      At that point, the thread will consider the connection to be
  23548.      broken and make an attempt to reconnect.
  23549.  
  23550. `Queueing master event to the relay log'
  23551.      The thread has read an event and is copying it to the relay log so
  23552.      the SQL thread can process it.
  23553.  
  23554. `Waiting to reconnect after a failed master event read'
  23555.      An error occurred while reading (due to disconnection). The thread
  23556.      is sleeping for `master-connect-retry' seconds before attempting
  23557.      to reconnect.
  23558.  
  23559. `Reconnecting after a failed master event read'
  23560.      Then the thread tries to reconnect. When connection is established
  23561.      again, the state will become `Waiting for master to send event'.
  23562.  
  23563. `Waiting for the SQL slave thread to free enough relay log space'
  23564.      You are using a non-zero `relay_log_space_limit' value, and the
  23565.      relay logs have grown so much that their combined size exceeds
  23566.      this value.  The I/O thread is waiting until the SQL thread frees
  23567.      enough space by processing relay log contents so that it can
  23568.      delete some relay log files.
  23569.  
  23570. `Waiting for slave mutex on exit'
  23571.      A very brief state that happens as the thread is stopping.
  23572.  
  23573. Here are the most common states you will see in the `State' column for
  23574. the SQL thread of a slave server:
  23575.  
  23576. `Reading event from the relay log'
  23577.      The thread has read an event from the relay log so that it can
  23578.      process it.
  23579.  
  23580. `Has read all relay log; waiting for the I/O slave thread to update it'
  23581.      The thread has processed all events in the relay log files and is
  23582.      waiting for the I/O thread to write new events to the relay log.
  23583.  
  23584. `Waiting for slave mutex on exit'
  23585.      A very brief state that happens as the thread is stopping.
  23586.  
  23587. The `State' column for the I/O thread may also show a query string.
  23588. This indicates that the thread has read an event from the relay log,
  23589. extracted the query from it and is executing the query.
  23590.  
  23591. Before MySQL 4.0.2, the slave I/O and SQL threads were combined as a
  23592. single thread, and no relay log files were used.  The advantage of
  23593. using two threads is that it separates query reading and query
  23594. execution into two independent tasks, so the task of reading queries is
  23595. not slowed down if query execution is slow.  For example, if the slave
  23596. server has not been running for a while, its I/O thread can quickly
  23597. fetch all the binlog contents from the master when the slave starts,
  23598. even if the SQL thread lags far behind and may take hours to catch up.
  23599. If the slave stops before the SQL thread has executed all the fetched
  23600. queries, the I/O thread has at least fetched everything so that a safe
  23601. copy of the queries is locally stored in the slave's relay logs for
  23602. execution when next the slave starts. This allows the binlogs to be
  23603. purged on the master, because it no longer need wait for the slave to
  23604. fetch their contents.
  23605.  
  23606. By default, relay logs are named using filenames of the form
  23607. `host_name-relay-bin.nnn', where `host_name' is the name of the slave
  23608. server host, and `nnn' is a sequence number.  Successive relay log
  23609. files are created using successive sequence numbers, beginning with
  23610. `001'.  The slave keeps track of relay logs currently in use in an
  23611. index file.  The default relay log index filename is
  23612. `host_name-relay-bin.index'.  By default these files are created in the
  23613. slave's data directory.  The default filenames may be overridden with
  23614. the `--relay-log' and `--relay-log-index' server options.
  23615.  
  23616. Relay logs have the same format as binary logs, so they can be read
  23617. with `mysqlbinlog'.  A relay log is automatically deleted by the SQL
  23618. thread as soon as it no longer needs it (that is, as soon as it has
  23619. executed all its events). There is no command to delete relay logs,
  23620. because the SQL thread takes care of doing so. However, from MySQL
  23621. 4.0.14, `FLUSH LOGS' rotates relay logs, which will influence when the
  23622. SQL thread deletes them.
  23623.  
  23624. A new relay log is created under the following conditions:
  23625.  
  23626.    * The first time the I/O thread starts after the slave server starts.
  23627.      (In MySQL 5.0, a new relay log will be created each time the I/O
  23628.      thread starts, not just the first time.)
  23629.  
  23630.    * A `FLUSH LOGS' statement is issued (4.0.14 and up only).
  23631.  
  23632.    * The size of the current relay log file becomes too big. The
  23633.      meaning of "too big" is determined as follows:
  23634.         - `max_relay_log_size', if `max_relay_log_size' > 0
  23635.  
  23636.         - `max_binlog_size', if `max_relay_log_size' = 0 or MySQL is
  23637.           older than 4.0.14
  23638.  
  23639.  
  23640. A slave replication server creates additional two small files in the
  23641. data directory.  These files are named `master.info' and
  23642. `relay-log.info' by default.  They contain information like that shown
  23643. in the output of the `SHOW SLAVE STATUS' statement (*note Replication
  23644. Slave SQL:: for a description of this command).  As disk files they
  23645. survive slave's shutdown. The next time the slave starts up, it can
  23646. read these files to know how far it has proceeded in reading binlogs
  23647. from the master and in processing its own relay logs.
  23648.  
  23649. The `master.info' file is updated by the I/O thread.  The
  23650. correspondance between the lines in the file and the columns displayed
  23651. by `SHOW SLAVE STATUS' is as follows:
  23652.  
  23653. *Line**Description*
  23654. 1    `Master_Log_File'
  23655. 2    `Read_Master_Log_Pos'
  23656. 3    `Master_Host'
  23657. 4    `Master_User'
  23658. 5    Password (not shown by `SHOW SLAVE STATUS')
  23659. 6    `Master_Port'
  23660. 7    `Connect_Retry'
  23661.  
  23662. The `relay-log.info' file is updated by the SQL thread.  The
  23663. correspondance between the lines in the file and the columns displayed
  23664. by `SHOW SLAVE STATUS' is as follows:
  23665.  
  23666. *Line**Description*
  23667. 1    `Relay_Log_File'
  23668. 2    `Relay_Log_Pos'
  23669. 3    `Relay_Master_Log_File'
  23670. 4    `Exec_master_log_pos'
  23671.  
  23672. When you back up your slave's data, you should back up these 2 small
  23673. files as well, along with the relay log files. because they are needed
  23674. to resume replication after you restore the slave's data.  If you lose
  23675. the relay logs but still have the `relay-log.info' file, you can check
  23676. it to determine how far the SQL thread has executed in the master
  23677. binlogs. Then you can use `CHANGE MASTER TO' with the
  23678. `MASTER_RELAY_LOG' and `MASTER_RELAY_POS' options to tell the slave to
  23679. re-read the binlogs from that point.  This requires that the binlogs
  23680. still exist on the master server, of course.
  23681.  
  23682. If your slave is subject to replicating `LOAD DATA INFILE' statements,
  23683. you should also backup the `SQL-LOAD*' files that may exist in the
  23684. directory that the slave uses for this purpose.  The slave needs these
  23685. files to resume replication of any interrupted `LOAD DATA INFILE'
  23686. statements.  (The directory location is specified using the
  23687. `--slave-load-tmpdir' option.  Its default value if not specified is
  23688. the value of the `tmpdir' variable.)
  23689.  
  23690. How to Set Up Replication
  23691. -------------------------
  23692.  
  23693. Here is a quick description of how to set up complete replication on
  23694. your current MySQL server. It assumes you want to replicate all your
  23695. databases and have not configured replication before. You will need to
  23696. shut down your master server briefly to complete the steps outlined
  23697. here.
  23698.  
  23699. The procedure is written in terms of setting up a single slave, but you
  23700. can use it to set up multiple slaves.
  23701.  
  23702. While this method is the most straightforward way to set up a slave, it
  23703. is not the only one. For example, if you already have a snapshot of the
  23704. master's data, and the master already has its server ID set and binary
  23705. logging enabled, you can set up a slave without shutting down the
  23706. master or even blocking updates to it.  For more details, please see
  23707. *Note Replication FAQ::.
  23708.  
  23709. If you want to administer a MySQL replication setup, we suggest that you
  23710. read this entire chapter through and try all commands mentioned in
  23711. *Note Replication Master SQL:: ans *Note Replication Slave SQL::.  You
  23712. should also familiarise yourself with replication startup options in
  23713. `my.cnf' in *Note Replication Options::.
  23714.  
  23715. Note that this procedure and some of the replication SQL statements in
  23716. later sections refer to the `SUPER' privilege. Prior to MySQL 4.0.2,
  23717. use the `PROCESS' privilege instead.
  23718.  
  23719.   1. Make sure you have a recent version of MySQL installed on the
  23720.      master and slave(s), and that these versions are compatible
  23721.      according to the table shown in *Note Replication Implementation::.
  23722.  
  23723.      Please do not report bugs until you have verified that the problem
  23724.      is present in the latest release.
  23725.  
  23726.   2. Set up an account on the master server that the slave server can
  23727.      use to connnect. This account must be given the `REPLICATION
  23728.      SLAVE' privilege.  (If MySQL versions older than 4.0.2, give the
  23729.      account the `FILE' privilege instead.)  If the account is only for
  23730.      replication (which is recommended), you don't need to grant any
  23731.      additional privileges.
  23732.  
  23733.      The hostname in the account name should be such that each of the
  23734.      slave servers can use the account to connect to the master.  For
  23735.      example, to create a user named `repl' which can access your
  23736.      master from any host, you might use this command:
  23737.  
  23738.           mysql> GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY '<password>';
  23739.  
  23740.      For MySQL versions older than 4.0.2, use this command instead:
  23741.  
  23742.           mysql> GRANT FILE ON *.* TO repl@'%' IDENTIFIED BY '<password>';
  23743.  
  23744.      If you plan to use the `LOAD TABLE FROM MASTER' or `LOAD DATA FROM
  23745.      MASTER' statements from the slave host, you will need to grant this
  23746.      account additional privileges:
  23747.  
  23748.         * Grant to the account the `SUPER' and `RELOAD' global
  23749.           privileges.
  23750.  
  23751.         * Grant the `SELECT' privilege for all tables that you want to
  23752.           load. Any master tables from which the account cannot
  23753.           `SELECT' will be ignored by `LOAD DATA FROM MASTER'.
  23754.  
  23755.   3. If you are using MyISAM tables, flush all the tables and block
  23756.      write queries by executing `FLUSH TABLES WITH READ LOCK' command.
  23757.  
  23758.           mysql> FLUSH TABLES WITH READ LOCK;
  23759.  
  23760.      and then take a snapshot of the data on your master server.
  23761.  
  23762.      The easiest way to create a snapshot is to simply use an archiving
  23763.      program (`tar' on Unix, `PowerArchiver', `WinRAR', `WinZIP' or any
  23764.      similar software on Windows) to produce an archive of the
  23765.      databases in your master's data directory.  For example, to use
  23766.      `tar' to create an archive that includes all databases, change
  23767.      location into the master server's data directory, then execute
  23768.      this command:
  23769.  
  23770.           shell> tar -cvf /tmp/mysql-snapshot.tar .
  23771.  
  23772.      If you want the archive to include only a database called
  23773.      `this_db', use this command instead:
  23774.  
  23775.           shell> tar -cvf /tmp/mysql-snapshot.tar ./this_db
  23776.  
  23777.      Then copy the archive file to the `/tmp' directory on the slave
  23778.      server host. On that machine, change location into the slave's
  23779.      data directory, and unpack the archive file using this command:
  23780.  
  23781.           shell> tar -xvf /tmp/mysql-snapshot.tar
  23782.  
  23783.      You may not want to replicate the `mysql' database. If not, you can
  23784.      exclude it from the archive. You also need not include any log
  23785.      files in the archive, or the `master.info' or `relay-log.info'
  23786.      files.
  23787.  
  23788.      While the read lock placed by `FLUSH TABLES WITH READ LOCK' is in
  23789.      effect, read the value of the current binary log name and offset
  23790.      on the master:
  23791.  
  23792.           mysql > SHOW MASTER STATUS;
  23793.           +---------------+----------+--------------+------------------+
  23794.           | File          | Position | Binlog_do_db | Binlog_ignore_db |
  23795.           +---------------+----------+--------------+------------------+
  23796.           | mysql-bin.003 | 73       | test,bar     | foo,manual,mysql |
  23797.           +---------------+----------+--------------+------------------+
  23798.           1 row in set (0.06 sec)
  23799.  
  23800.      The `File' column shows the name of the log,  while `Position'
  23801.      shows the offset. In the above example, the binary log value is
  23802.      `mysql-bin.003' and the offset is 73. Record the values. You will
  23803.      need to use them later when you are setting up the slave.
  23804.  
  23805.      Once you have taken the snapshot and recorded the log name and
  23806.      offset, you can re-enable write activity on the master:
  23807.  
  23808.           mysql> UNLOCK TABLES;
  23809.  
  23810.      If you are using InnoDB tables, ideally you should use the InnoDB
  23811.      Hot Backup tool that is available to those who purchase MySQL
  23812.      commercial licenses, support, or the backup tool itself. It takes
  23813.      a consistent snapshot without acquiring any locks on the master
  23814.      server, and records the log name and offset corresponding to the
  23815.      snapshot to be later used on the slave. More information about the
  23816.      tool is avalaible at `http://www.innodb.com/hotbackup.html'.
  23817.  
  23818.      Without the Hot Backup tool, the quickest way to take a snapshot
  23819.      of  InnoDB tables is to shut down the master server and copy the
  23820.      InnoDB datafiles and logs, and the table definition files
  23821.      (`.frm'). To record the current log file name and offset, you
  23822.      should do the following before you shut down the server:
  23823.  
  23824.           mysql> FLUSH TABLES WITH READ LOCK;
  23825.           mysql> SHOW MASTER STATUS;
  23826.  
  23827.      And then record the log name and the offset from the output of
  23828.      `SHOW MASTER STATUS' as was shown earlier. Once you have recorded
  23829.      the log name and the offset, shut down the server without
  23830.      unlocking the tables to make sure it goes down with the snapshot
  23831.      corresponding to the current log file and offset:
  23832.  
  23833.           shell> mysqladmin -uroot shutdown
  23834.  
  23835.      An alternative for both MyISAM and InnoDB tables is to take an SQL
  23836.      dump of the master instead of a binary copy like above; for this
  23837.      you can use `mysqldump --master-data' on your master and later run
  23838.      this SQL dump into your slave. However, this is slower than doing
  23839.      a binary copy.
  23840.  
  23841.      If the master has been previously running without `--log-bin'
  23842.      enabled, the log name and position values displayed by `SHOW MASTER
  23843.      STATUS' or `mysqldump' will be empty. In that case, record empty
  23844.      string (") for the log name, and 4 for the offset.
  23845.  
  23846.   4. Make sure the `[mysqld]' section of the `my.cnf' file on the
  23847.      master host includes a `log-bin' option. The section should also
  23848.      have a `server-id=master_id' option, where `master_id' must be an
  23849.      integer value from 1 to 2^32 - 1. For example:
  23850.  
  23851.           [mysqld]
  23852.           log-bin
  23853.           server-id=1
  23854.  
  23855.      If those options are not present, add them and restart the server.
  23856.  
  23857.   5. Stop the server that is to be used as a slave server and add the
  23858.      following to its `my.cnf' file:
  23859.  
  23860.           [mysqld]
  23861.           server-id=slave_id
  23862.  
  23863.      The `slave_id' value, like the `master_id' value, must be an
  23864.      integer value from 1 to 2^32 - 1. In addition, it is very
  23865.      important that the ID of the slave be different than the ID of the
  23866.      master. For example:
  23867.  
  23868.           [mysqld]
  23869.           server-id=2
  23870.  
  23871.      If you are setting up multiple slaves, each one must have a
  23872.      `server-id' value that differs from that of the master and from
  23873.      each of the other slaves.  Think of `server-id' values as
  23874.      something similar to IP addresses: These IDs uniquely identify
  23875.      each server instance in the community of replication partners.
  23876.  
  23877.      If you don't specify a `server-id' value, it will be set to 1 if
  23878.      you have not defined `master-host', else it will be set to 2. Note
  23879.      that in the case of `server-id' omission, a master will refuse
  23880.      connections from all slaves, and a slave will refuse to connect to
  23881.      a master. Thus, omitting `server-id' is only good for backup with a
  23882.      binary log.
  23883.  
  23884.   6. If you made a binary backup of the master server's data, copy it
  23885.      to the slave server's data directory before starting the slave.
  23886.      Make sure that the privileges on the files and directories are
  23887.      correct. The user which MySQL runs as needs to be able to read
  23888.      from and write to them, just as on the master.
  23889.  
  23890.      If you made a backup using `mysqldump', start the slave first (see
  23891.      next step).
  23892.  
  23893.   7. Start the slave server. If it has been replicating previously,
  23894.      start the slave server with the `--skip-slave-start' option.  You
  23895.      also may want to start the slave server with the `--log-warnings'
  23896.      option. That way, you will get more messages about problems (for
  23897.      example, network or connection problems).
  23898.  
  23899.   8. If you made a backup of the master server's data using
  23900.      `mysqldump', load the dump file into the slave server:
  23901.  
  23902.           shell> mysql -u root -p < dump_file.sql
  23903.  
  23904.   9. Execute the following command on the slave, replacing the values
  23905.      within `<>' with the actual values relevant to your system:
  23906.  
  23907.           mysql> CHANGE MASTER TO
  23908.               ->     MASTER_HOST='<master host name>',
  23909.               ->     MASTER_USER='<replication user name>',
  23910.               ->     MASTER_PASSWORD='<replication password>',
  23911.               ->     MASTER_LOG_FILE='<recorded log file name>',
  23912.               ->     MASTER_LOG_POS=<recorded log offset>;
  23913.  
  23914.      The following table lists the maximum string length for these
  23915.      variables:
  23916.  
  23917.      `MASTER_HOST'               60
  23918.      `MASTER_USER'               16
  23919.      `MASTER_PASSWORD'           32
  23920.      `MASTER_LOG_FILE'           255
  23921.  
  23922.  10. Start the slave threads:
  23923.  
  23924.           mysql> START SLAVE;
  23925.  
  23926.  
  23927. After you have performed this procedure, the slave should connect to
  23928. the master and catch up on any updates that have occurred since the
  23929. snapshot was taken.
  23930.  
  23931. If you have forgotten to set `server-id' for the master, slaves will
  23932. not be able to connect to it.
  23933.  
  23934. If you have forgotten to set `server-id' for the slave, you will get
  23935. the following error in its error log:
  23936.  
  23937.      Warning: one should set server_id to a non-0 value if master_host is set.
  23938.      The server will not act as a slave.
  23939.  
  23940. You will also find error messages in the slave's error log if it is not
  23941. able to replicate for any other reason.
  23942.  
  23943. Once a slave is replicating, you will find in its data directory one
  23944. file called `master.info' and another called `relay-log.info'.  The
  23945. slave uses these two files to keep track of how much of the master's
  23946. binary log it has processed. *Do not* remove or edit these files,
  23947. unless you really know what you are doing and understand the
  23948. implications. Even in that case, it is preferred that you use `CHANGE
  23949. MASTER TO' command.
  23950.  
  23951. *NOTE*: The content of `master.info' overrides some options specified
  23952. on the command-line or in `my.cnf' See *Note Replication Options:: for
  23953. more details.
  23954.  
  23955. Once you have a snapshot, you can use it to set up other slaves by
  23956. following the slave portion of the procedure just described. You do not
  23957. need to take another snapshot of the master.
  23958.  
  23959. Replication Features and Known Problems
  23960. ---------------------------------------
  23961.  
  23962. Here is an explanation of what is supported and what is not:
  23963.  
  23964.    * Replication will be done correctly with `AUTO_INCREMENT',
  23965.      `LAST_INSERT_ID()', and `TIMESTAMP' values.
  23966.  
  23967.    * The `USER()' and `LOAD_FILE()' functions are replicated without
  23968.      changes and will thus not work reliably on the slave. This is also
  23969.      true for `CONNECTION_ID()' in slave versions older than 4.1.1.
  23970.      The *new* `PASSWORD()' function in MySQL 4.1, is well replicated
  23971.      since 4.1.1 masters; your slaves must be 4.1.0 or above to
  23972.      replicate it. If you have older slaves and need to replicate
  23973.      `PASSWORD()' from your 4.1.x master, you must start your master
  23974.      with option `--old-password'.
  23975.  
  23976.    * The `sql_mode', `FOREIGN_KEY_CHECKS', and `table_type' variables
  23977.      are not replicated.
  23978.  
  23979.    * You must use the same character set (`--default-character-set') on
  23980.      the master and the slave. Otherwise, you may get duplicate key
  23981.      errors on the slave, because a key that is regarded as unique in
  23982.      the master character set may not be unique in the slave character
  23983.      set.
  23984.  
  23985.    * If you are using transactional tables on the master and
  23986.      non-transactional tables (for the same tables) on the slave, you
  23987.      will get problems if the slave is stopped in the middle of a
  23988.      `BEGIN/COMMIT' block, as the slave will later start at the
  23989.      beginning of the `BEGIN' block.  This issue is on our TODO and
  23990.      will be fixed in the near future.
  23991.  
  23992.    * Update queries that use user variables are badly replicated in
  23993.      3.23 and 4.0. This is fixed in 4.1. Note that user variable names
  23994.      are case insensitive starting from version 5.0, so you should take
  23995.      this into account when setting up replication between 5.0 and a
  23996.      previous version.
  23997.  
  23998.    * The slave can connect to the master using SSL, if the master and
  23999.      slave are both 4.1.1 or newer.
  24000.  
  24001.    * Though we have never heard of it actually occurring, it is
  24002.      theoretically possible for the data on the master and slave to
  24003.      become different if a query is designed in such a way that the
  24004.      data modification is non-deterministic, that is, left to the will
  24005.      of the query optimiser (which generally is not a good practice,
  24006.      even outside of replication!).  For a detailed explanation, see
  24007.      *Note Open bugs::.
  24008.  
  24009.    * Before MySQL 4.1.1, `FLUSH', `ANALYZE', `OPTIMIZE', `REPAIR'
  24010.      commands are not stored in the binary log and thus are not
  24011.      replicated to the slaves. This is not normally a problem as these
  24012.      commands don't change anything. However, it does mean that if you
  24013.      update the MySQL privilege tables directly without using the
  24014.      `GRANT' statement and you replicate the `mysql' privilege
  24015.      database, you must do a `FLUSH PRIVILEGES' on your slaves to put
  24016.      the new privileges into effect. Also if you use `FLUSH TABLES'
  24017.      when renaming a `MyISAM' table involved in a `MERGE' table, you
  24018.      will have to issue `FLUSH TABLES' manually on the slave.  Since
  24019.      MySQL 4.1.1, these commands are written to the binary log (except
  24020.      `FLUSH LOGS', `FLUSH MASTER', `FLUSH SLAVE', `FLUSH TABLES WITH
  24021.      READ LOCK') unless you specify `NO_WRITE_TO_BINLOG' (or its alias
  24022.      `LOCAL').  For a syntax example, see *Note `FLUSH': FLUSH.
  24023.  
  24024.    * MySQL only supports one master and many slaves. Later we will add
  24025.      a voting algorithm to automatically change master if something goes
  24026.      wrong with the current master. We will also introduce "agent"
  24027.      processes to help do load balancing by sending `SELECT' queries to
  24028.      different slaves.
  24029.  
  24030.    * Temporary tables are replicated with the exception of the case
  24031.      that you shut down slave server (not just slave thread) and you
  24032.      have some replicated temporary tables that are used in update
  24033.      statements that have not yet been executed on the slave.  (If you
  24034.      shut down the slave, the temporary tables needed by those updates
  24035.      no longer are available when the slave starts again.)  To avoid
  24036.      this problem, do not shut down the slave while it has temporary
  24037.      tables open. Instead, use this procedure:
  24038.  
  24039.        1. Issue a `STOP SLAVE' statement.
  24040.  
  24041.        2. Use `SHOW STATUS' to check the value of the
  24042.           `Slave_open_temp_tables' variable.
  24043.  
  24044.        3. If the value is 0, issue a `mysqladmin shutdown' command to
  24045.           shut down the slave.
  24046.  
  24047.        4. If the value is not 0, restart the slave threads with `START
  24048.           SLAVE'.
  24049.  
  24050.        5. Repeat the procedure later to see if you have better luck
  24051.           next time.
  24052.  
  24053.  
  24054.      We have plans to fix this problem in the near future.
  24055.  
  24056.    * It is safe to connect servers in a circular master/slave
  24057.      relationship with `log-slave-updates' enabled.  Note, however,
  24058.      that many queries will not work correctly in this kind of setup
  24059.      unless your client code is written to take care of the potential
  24060.      problems that can happen from updates that occur in different
  24061.      sequence on different servers.
  24062.  
  24063.      This means that you can do a setup like the following:
  24064.  
  24065.           A -> B -> C -> A
  24066.  
  24067.      Server IDs are encoded in the binary log events.  A will know when
  24068.      an event it reads had originally been created by A, so A will not
  24069.      execute it and there will be no infinite loop.  But this circular
  24070.      setup will work only if you only if you perform no conflicting
  24071.      updates between the tables.  In other words, if you insert data in
  24072.      A and C, you should never insert a row in A that may have a
  24073.      conflicting key with a row insert in C.  You should also not update
  24074.      the same rows on two servers if the order in which the updates are
  24075.      applied matters.
  24076.  
  24077.    * If a query on the slave gets an error, the slave SQL thread will
  24078.      terminate, and a message will appear in the slave error log. You
  24079.      should then connect to the slave manually, fix the cause of the
  24080.      error (for example, non-existent table), and then run `START
  24081.      SLAVE'.
  24082.  
  24083.    * If the connection to the master is lost, the slave will try to
  24084.      reconnect immediately. If that fails, the slave will retry every
  24085.      `master-connect-retry' seconds (default 60). Because of this, it
  24086.      is safe to shut down the master, and then restart it after a
  24087.      while. The slave will also be able to deal with network
  24088.      connectivity outages. However, the slave will notice the network
  24089.      outage only after receiving no data from the master for
  24090.      `slave_net_timeout' seconds. So if your outages are short, you may
  24091.      want to decrease `slave_net_timeout'.  *Note `SHOW VARIABLES':
  24092.      SHOW VARIABLES.
  24093.  
  24094.    * Shutting down the slave (cleanly) is also safe, as it keeps track
  24095.      of where it left off.  Unclean shutdowns might produce problems,
  24096.      especially if disk cache was not synced before the system died.
  24097.      Your system fault tolerance will be greatly increased if you have
  24098.      a good UPS.
  24099.  
  24100.    * Due to the non-transactional nature of MyISAM tables, it is
  24101.      possible to have a query that will only partially update a table
  24102.      and return an error code. This can happen, for example, on a
  24103.      multi-row insert that has one row violating a key constraint, or
  24104.      if a long update query is killed after updating some of the rows.
  24105.      If that happens on the master, the slave thread will exit and wait
  24106.      for the DBA to decide what to do about it unless the error code is
  24107.      legitimate and the query execution results in the same error code.
  24108.      If this error code validation behaviour is not desirable, some (or
  24109.      all) errors can be masked out (ignored) with the
  24110.      `--slave-skip-errors' option.  This option is available starting
  24111.      with MySQL Version 3.23.47.
  24112.  
  24113.    * If you update transactional tables from non-transactional tables
  24114.      inside a `BEGIN/COMMIT' segment, updates to the binary log may be
  24115.      out of sync if some thread changes the non-transactional table
  24116.      before the transaction commits.  This is because the transaction
  24117.      is written to the binary log only when it's commited.
  24118.  
  24119.    * Before version 4.0.15, any update to a non-transactional table is
  24120.      written to the binary log at once when the update is made while
  24121.      transactional updates are written on `COMMIT' or not written at
  24122.      all if you use `ROLLBACK'; you have to take this into account when
  24123.      updating both transactional tables and non-transactional tables in
  24124.      the same transaction if you are using binary logging for backups or
  24125.      replication. In version 4.0.15, we changed the logging behaviour
  24126.      for transactions that mix updates to transactional and
  24127.      non-transactional tables, which solves the problems (order of
  24128.      queries is good in binlog, and all needed queries are written to
  24129.      the binlog even in case of `ROLLBACK'). The problem which remains
  24130.      is when a second connection updates the non-transactional table
  24131.      while the first connection's transaction is not finished yet
  24132.      (wrong order can still occur, because the second connection's
  24133.      update will be written immediately after it is done).
  24134.  
  24135. The following table lists problems in MySQL 3.23 that are fixed in
  24136. MySQL 4.0:
  24137.  
  24138.    * `LOAD DATA INFILE' is handled properly, as long as the data file
  24139.      still resides on the master server at the time of update
  24140.      propagation.
  24141.  
  24142.    * `LOAD LOCAL DATA INFILE' will be skipped.
  24143.  
  24144.    * In 3.23 `RAND()' in updates does not replicate properly.  Use
  24145.      `RAND(some_non_rand_expr)' if you are replicating updates with
  24146.      `RAND()'. You can, for example, use `UNIX_TIMESTAMP()' for the
  24147.      argument to `RAND()'. This is fixed in 4.0.
  24148.  
  24149. Replication Startup Options
  24150. ---------------------------
  24151.  
  24152. On both the master and the slave you need to use the `server-id' option
  24153. to establish a unique replication ID for each server. You should pick a
  24154. unique integer in the range from 1 to 2^32 - 1 for each master and
  24155. slave.  Example: `server-id=3'
  24156.  
  24157. The options that you can use on the master server for controlling binary
  24158. logging are all described in *Note Binary log::.
  24159.  
  24160. The following table describes the options you can use on slave servers.
  24161. You can specify them on the command line or in an option file.
  24162.  
  24163. *NOTE*: Replication handles the following options in a special way:
  24164.  
  24165.    * `--master-host'
  24166.  
  24167.    * `--master-user'
  24168.  
  24169.    * `--master-password'
  24170.  
  24171.    * `--master-port'
  24172.  
  24173.    * `--master-connect-retry'
  24174.  
  24175. If no `master.info' file exists when the slave server starts, it uses
  24176. values for those options that are specified in option files or on the
  24177. command line.  This will occur when you start the server as a
  24178. replication slave for the very first time, or you have run `RESET
  24179. SLAVE' and shut down and restarted the slave server.
  24180.  
  24181. However, if the `master.info' file exists when the slave server starts,
  24182. it uses the values in the file and *IGNORES* any values specified for
  24183. those options in option files or on the command line.
  24184.  
  24185. Suppose you specify this option in your `my.cnf' file:
  24186.  
  24187.      [mysqld]
  24188.      master-host=this_host
  24189.  
  24190. The first time you start the server as a replication slave, it will
  24191. read and use that option from the `my.cnf' file.  The server will then
  24192. record that value in the `master.info' file.  The next time you start
  24193. the server, it will read the master host value from the `master.info'
  24194. file only.  If you modify the `my.cnf' file to specify a different
  24195. master host, it will have no effect.  You must use `CHANGE MASTER TO'
  24196. instead.
  24197.  
  24198. As of MySQL 4.1.1, the following options also are handled specially:
  24199.  
  24200.    * `--master-ssl'
  24201.  
  24202.    * `--master-ssl-ca'
  24203.  
  24204.    * `--master-ssl-capath'
  24205.  
  24206.    * `--master-ssl-cert'
  24207.  
  24208.    * `--master-ssl-cipher'
  24209.  
  24210.    * `--master-ssl-key'
  24211.  
  24212. The `master.info' file includes the values corresponding to those
  24213. options. In addition, the 4.1.1 file format includes as its first line
  24214. the number of lines in the file. If you upgrade an older server to
  24215. 4.1.1, the `master.info' will be upgraded to the new format
  24216. automatically when the new server starts. (If you downgrade a 4.1.1 or
  24217. newer server to a version older than 4.1.1, you should manually remove
  24218. the first line before starting the older server for the first time.)
  24219.  
  24220. Because the server gives an existing `master.info' file precedence over
  24221. the startup options just described, you might prefer not to use startup
  24222. options for these values at all, and instead specify them by using the
  24223. `CHANGE MASTER TO' statement.  See *Note `CHANGE MASTER TO': CHANGE
  24224. MASTER TO.
  24225.  
  24226. This example shows a more extensive use of startup options to configure
  24227. a slave server:
  24228.  
  24229.      [mysqld]
  24230.      server-id=2
  24231.      master-host=db-master.mycompany.com
  24232.      master-port=3306
  24233.      master-user=pertinax
  24234.      master-password=freitag
  24235.      master-connect-retry=60
  24236.      report-host=db-slave.mycompany.com
  24237.  
  24238. The following list describes startup options for controlling
  24239. replication:
  24240.  
  24241. `--log-slave-updates'
  24242.      Tells the slave to log the updates performed by its SQL thread to
  24243.      the slave's own binary log. Off by default.  Of course, for this
  24244.      option to have any effect, the slave must be started with binary
  24245.      logging enabled (`--log-bin' option).  `--log-slave-updates' is
  24246.      used when you want to chain replication servers.  For example, you
  24247.      might want a setup like this:
  24248.  
  24249.           A -> B -> C
  24250.  
  24251.      That is, A serves as the master for the slave B, and B serves as
  24252.      the master for the slave C. For this to work, where B is both a
  24253.      master and a slave, you must start B with the
  24254.      `--log-slave-updates' option.  A and B must both be started with
  24255.      binary logging enabled.
  24256.  
  24257. `--log-warnings'
  24258.      Makes the slave print more messages about what it is doing. For
  24259.      example, it will warn you that it succeeded in reconnecting after a
  24260.      network/connection failure, and warn you about how each slave
  24261.      thread started.
  24262.  
  24263.      This option is not limited to replication use only. It produces
  24264.      warnings across a spectrum of server activities.
  24265.  
  24266. `--master-host=host'
  24267.      Specify the hostname or IP address of the master replication
  24268.      server.  If this option is not given, the slave thread will not be
  24269.      started.  The value in `master.info' takes precedence if it can be
  24270.      read.  Probably a better name for this options would have been
  24271.      something like `--bootstrap-master-host', but it is too late to
  24272.      change now.
  24273.  
  24274. `--master-user=username'
  24275.      The username of the account that the slave thread uses for
  24276.      authentication when connecting to the master. The account must
  24277.      have the `REPLICATION SLAVE' privilege (prior to MySQL 4.0.2, it
  24278.      must have the `FILE' privilege instead). If the master user is not
  24279.      set, user `test' is assumed. The value in `master.info' takes
  24280.      precedence if it can be read.
  24281.  
  24282. `--master-password=password'
  24283.      The password of the account that the slave thread uses for
  24284.      authentication when connecting to the master.  If not set, an
  24285.      empty password is assumed. The value in `master.info' takes
  24286.      precedence if it can be read.
  24287.  
  24288. `--master-port=port_number'
  24289.      The port the master is listening on. If not set, the compiled
  24290.      setting of `MYSQL_PORT' is assumed. If you have not tinkered with
  24291.      `configure' options, this should be 3306. The value in
  24292.      `master.info' takes precedence if it can be read.
  24293.  
  24294. `--master-connect-retry=seconds'
  24295.      The number of seconds the slave thread sleeps before retrying to
  24296.      connect to the master in case the master goes down or the
  24297.      connection is lost.  Default is 60. The value in `master.info'
  24298.      takes precedence if it can be read.
  24299.  
  24300. `--master-info-file=filename'
  24301.      Specifies the name to use for the file in which the slave records
  24302.      information about the master.  The default name is `mysql.info' in
  24303.      the data directory.
  24304.  
  24305. `--master-ssl'
  24306. `--master-ssl-ca=file_name'
  24307. `--master-ssl-capath=directory_name'
  24308. `--master-ssl-cert=file_name'
  24309. `--master-ssl-cipher=cipher_list'
  24310. `--master-ssl-key=file_name'
  24311.      These options are used for setting up a secure replication
  24312.      connection to the master server using SSL.  Their meanings are the
  24313.      same as the corresponding `--ssl', `--ssl-ca', `--ssl-capath',
  24314.      `--ssl-cert', `--ssl-cipher', `--ssl-key' options described in
  24315.      *Note SSL options::.
  24316.  
  24317.      These options are operational as of MySQL 4.1.1.
  24318.  
  24319. `--max-relay-log-size=#'
  24320.      To rotate the relay log automatically.  *Note `SHOW VARIABLES':
  24321.      SHOW VARIABLES.
  24322.  
  24323. `--relay-log=filename'
  24324.      To specify the location and name that should be used for relay
  24325.      logs.  You can use this to have hostname-independant relay log
  24326.      names, or if your relay logs tend to be big (and you don't want to
  24327.      decrease `max_relay_log_size') and you need to put them on some
  24328.      area different from the data directory, or if you want to increase
  24329.      speed by balancing load between disks.
  24330.  
  24331. `--relay-log-index=filename'
  24332.      To specify the location and name that should be used for the relay
  24333.      logs index file.
  24334.  
  24335. `--relay-log-info-file=filename'
  24336.      To give `relay-log.info' another name and/or to put it in another
  24337.      directory than the data directory.
  24338.  
  24339. `--relay-log-purge=0|1'
  24340.      Disables/enables automatic purging of relay logs as soon as they
  24341.      are not needed any more. This is a global variable that can be
  24342.      dynamically changed with `SET GLOBAL RELAY_LOG_PURGE=0|1'. The
  24343.      default value is 1.
  24344.  
  24345.      This option is available as of MySQL 4.1.1.
  24346.  
  24347. `--relay-log-space-limit=#'
  24348.      To put an upper limit on the total size of all relay logs on the
  24349.      slave (a value of 0 means "unlimited"). This is useful if you have
  24350.      a small hard disk on your slave machine. When the limit is
  24351.      reached, the I/O thread pauses (does not read the master's binlog)
  24352.      until the SQL thread has caught up and deleted some now unused
  24353.      relay logs. Note that this limit is not absolute: there are cases
  24354.      where the SQL thread needs more events to be able to delete; in
  24355.      that case the I/O thread will overgo the limit until deletion
  24356.      becomes possible. Not doing so would cause a deadlock (which
  24357.      happens before MySQL 4.0.13).  Users should not set
  24358.      `--relay-log-space-limit' to less than twice the value of
  24359.      `--max-relay-log-size' (or `--max-binlog-size' if
  24360.      `--max-relay-log-size' is 0) because in that case there are
  24361.      chances that when the I/O thread waits for free space because
  24362.      `--relay-log-space-limit' is exceeded, the SQL thread has no relay
  24363.      log to purge and so cannot satisfy the I/O thread, forcing the I/O
  24364.      thread to temporarily ignore `--relay-log-space-limit'.
  24365.  
  24366. `--replicate-do-table=db_name.table_name'
  24367.      Tells the slave thread to restrict replication to the specified
  24368.      table.  To specify more than one table, use the directive multiple
  24369.      times, once for each table.  This will work for cross-database
  24370.      updates, in contrast to `--replicate-do-db'.  Please read the
  24371.      notes that follow this option list.
  24372.  
  24373. `--replicate-ignore-table=db_name.table_name'
  24374.      Tells the slave thread to not replicate any command that updates
  24375.      the specified table (even if any other tables may be update by the
  24376.      same command). To specify more than one table to ignore, use the
  24377.      directive multiple times, once for each table. This will work for
  24378.      cross-database updates, in contrast to `--replicate-ignore-db'.
  24379.      Please read the notes that follow this option list.
  24380.  
  24381. `--replicate-wild-do-table=db_name.table_name'
  24382.      Tells the slave thread to restrict replication to queries where
  24383.      any of the updated tables match the specified wildcard pattern.
  24384.      To specify more than one table, use the directive multiple times,
  24385.      once for each table.  This will work for cross-database updates.
  24386.      Please read the notes that follow this option list.
  24387.  
  24388.      Example: `--replicate-wild-do-table=foo%.bar%' will replicate only
  24389.      updates that uses a table in any databases that start with `foo'
  24390.      and whose table names start with `bar'.
  24391.  
  24392.      Note that if you do `--replicate-wild-do-table=foo%.%' then the
  24393.      rule will be propagated to `CREATE DATABASE' and `DROP DATABASE',
  24394.      that is, these two statements will be replicated if the database
  24395.      name matches the database pattern (`foo%' here) (this magic is
  24396.      triggered by `%' being the table pattern).
  24397.  
  24398. `--replicate-wild-ignore-table=db_name.table_name'
  24399.      Tells the slave thread to not replicate a query where any table
  24400.      matches the given wildcard pattern. To specify more than one table
  24401.      to ignore, use the directive multiple times, once for each table.
  24402.      This will work for cross-database updates.  Please read the notes
  24403.      that follow this option list.
  24404.  
  24405.      Example: `--replicate-wild-ignore-table=foo%.bar%' will not do
  24406.      updates to tables in databases that start with `foo' and whose
  24407.      table names start with `bar'.
  24408.  
  24409.      Note that if you do `--replicate-wild-ignore-table=foo%.%' then the
  24410.      rule will be propagated to `CREATE DATABASE' and `DROP DATABASE',
  24411.      that is, these two statements will not be replicated if the
  24412.      database name matches the database pattern (`foo%' here) (this
  24413.      magic is triggered by `%' being the table pattern).
  24414.  
  24415. `--replicate-do-db=database_name'
  24416.      Tells the slave to restrict replication to commands where the
  24417.      current database (that is, the one selected by `USE') is
  24418.      `database_name'.  To specify more than one database, use the
  24419.      directive multiple times, once for each database. Note that this
  24420.      will not replicate cross-database queries such as `UPDATE
  24421.      some_db.some_table SET foo='bar'' while having selected a
  24422.      different or no database. If you need cross database updates to
  24423.      work, make sure you have 3.23.28 or later, and use
  24424.      `--replicate-wild-do-table=db_name.%'.  Please read the notes that
  24425.      follow this option list.
  24426.  
  24427.      Example of what does not work as you could expect it: if the slave
  24428.      is started with `--replicate-do-db=sales', and you do `USE prices;
  24429.      UPDATE sales.january SET amount=amount+1000;', this query will not
  24430.      be replicated.
  24431.  
  24432.      If you need cross database updates to work, use
  24433.      `--replicate-wild-do-table=db_name.%' instead.
  24434.  
  24435.      The main reason for this "just-check-the-current-database"
  24436.      behaviour is that it's hard from the command alone to know if a
  24437.      query should be replicated or not; for example if you are using
  24438.      multi-table-delete or multi-table-update commands that go across
  24439.      multiple databases.  It's also very fast to just check the current
  24440.      database.
  24441.  
  24442. `--replicate-ignore-db=database_name'
  24443.      Tells the slave to not replicate any command where the current
  24444.      database (that is, the one selected by `USE') is `database_name'.
  24445.      To specify more than one database to ignore, use the directive
  24446.      multiple times, once for each database.  You should not use this
  24447.      directive if you are using cross table updates and you don't want
  24448.      these update to be replicated.  Please read the notes that follow
  24449.      this option list.
  24450.  
  24451.      Example of what does not work as you could expect it: if the slave
  24452.      is started with `--replicate-ignore-db=sales', and you do `USE
  24453.      prices; UPDATE sales.january SET amount=amount+1000;', this query
  24454.      will be replicated.
  24455.  
  24456.      If you need cross database updates to work, use
  24457.      `--replicate-wild-ignore-table=db_name.%' instead.
  24458.  
  24459. `--replicate-rewrite-db=from_name->to_name'
  24460.      Tells the slave to translate the current database (that is, the
  24461.      one selected by `USE') to `to_name' if it was `from_name' on the
  24462.      master.  Only statements involving tables may be affected (`CREATE
  24463.      DATABASE', `DROP DATABASE' won't), and only if `from_name' was the
  24464.      current database on the master.  This will not work for
  24465.      cross-database updates.  Note that the translation is done before
  24466.      `--replicate-*' rules are tested.
  24467.  
  24468.      Example: `replicate-rewrite-db=master_db_name->slave_db_name'
  24469.  
  24470. `--report-host=host'
  24471.      The hostname or IP number of the slave to be reported to the
  24472.      master during slave registration. Will appear in the output of
  24473.      `SHOW SLAVE HOSTS'. Leave unset if you do not want the slave to
  24474.      register itself with the master. Note that it is not sufficient
  24475.      for the master to simply read the IP number of the slave from the
  24476.      TCP/IP socket once the slave connects. Due to `NAT' and other
  24477.      routing issues, that IP may not be valid for connecting to the
  24478.      slave from the master or other hosts.
  24479.  
  24480.      This option is available as of MySQL 4.0.0.
  24481.  
  24482. `--report-port=port_number'
  24483.      Port for connecting to slave reported to the master during slave
  24484.      registration.  Set it only if the slave is listening on a
  24485.      non-default port or if you have a special tunnel from the master or
  24486.      other clients to the slave. If not sure, leave this option unset.
  24487.  
  24488.      This option is available as of MySQL 4.0.0.
  24489.  
  24490. `--skip-slave-start'
  24491.      Tells the slave server not to start the slave threads on server
  24492.      startup. The user can start them later with `START SLAVE'.
  24493.  
  24494. `--slave_compressed_protocol=#'
  24495.      If 1, then use compression on the slave/client protocol if both
  24496.      slave and master support this.
  24497.  
  24498. `--slave-load-tmpdir=filename'
  24499.      This option is by default equal to the value of the `tmpdir'
  24500.      variable.  When the slave SQL thread replicates a `LOAD DATA
  24501.      INFILE' command, it extracts the to-be-loaded file from the relay
  24502.      log into temporary files, then loads these into the table. If the
  24503.      file loaded on the master was huge, the temporary files on the
  24504.      slave will be huge, too; therefore you may wish/have to tell the
  24505.      slave to put the temporary files on some large disk different from
  24506.      `tmpdir', using this option. In that case, you may also use the
  24507.      `--relay-log' option, as relay logs will be huge, too.
  24508.      `--slave-load-tmpdir' should point to a disk-based filesystem; not
  24509.      a memory-based one. Because the slave needs the temporary files
  24510.      used to replicate `LOAD DATA INFILE') to survive a machine's
  24511.      reboot.
  24512.  
  24513. `--slave-net-timeout=#'
  24514.      Number of seconds to wait for more data from the master before
  24515.      aborting the read, considering the connection broken and retrying
  24516.      to connect. The first retry occurs immediately after timeout. The
  24517.      interval between retries is controlled by the
  24518.      `--master-connect-retry' option.
  24519.  
  24520. `--slave-skip-errors= [err_code1,err_code2,... | all]'
  24521.      Tells the slave SQL thread to continue replication when a query
  24522.      returns an error from the provided list. Normally, replication
  24523.      will discontinue when an error is encountered, giving the user a
  24524.      chance to resolve the inconsistency in the data manually. Do not
  24525.      use this option unless you fully understand why you are getting
  24526.      the errors.  If there are no bugs in your replication setup and
  24527.      client programs, and no bugs in MySQL itself, you should never get
  24528.      an abort with error. Indiscriminate use of this option will result
  24529.      in slaves being hopelessly out of sync with the master and you
  24530.      having no idea how the problem happened.
  24531.  
  24532.      For error codes, you should use the numbers provided by the error
  24533.      message in your slave error log and in the output of `SHOW SLAVE
  24534.      STATUS'. A full list of error messages can be found in the source
  24535.      distribution in `Docs/mysqld_error.txt'.  The server error codes
  24536.      also are listed at *Note Error-returns::.
  24537.  
  24538.      You can (but should not) also use a very non-recommended value of
  24539.      `all' which will ignore all error messages and keep barging along
  24540.      regardless.  Needless to say, if you use it, we make no promises
  24541.      regarding your data integrity. Please do not complain if your data
  24542.      on the slave is not anywhere close to what it is on the master in
  24543.      this case -- you have been warned.
  24544.  
  24545.      Examples:
  24546.  
  24547.           --slave-skip-errors=1062,1053
  24548.           --slave-skip-errors=all
  24549.  
  24550. Some of these options, like all `--replicate-*' options, can only be
  24551. set at the slave server's startup, not on-the-fly. We plan to fix this.
  24552.  
  24553. Here is the order of evaluation of the `r--eplicate-*' rules, to decide
  24554. if the query is going to be executed by the slave or ignored by it:
  24555.   1. Are there some `--replicate-do-db' or `--replicate-ignore-db'
  24556.      rules?
  24557.         * Yes: test them like for `--binlog-do-db' and
  24558.           `--binlog-ignore-db' (*note Binary log::). What is the result
  24559.           of the test?
  24560.              * ignore the query: ignore it and exit.
  24561.  
  24562.              * execute the query: don't execute it immediately, defer
  24563.                the decision, go to step below.
  24564.  
  24565.         * No: go to step below.
  24566.  
  24567.   2. Are there some `--replicate-*-table' rules?
  24568.         * No: execute the query and exit.
  24569.  
  24570.         * Yes: go to step below. Only tables which are to be updated
  24571.           will be compared to rules (`INSERT INTO sales SELECT * from
  24572.           prices': only `sales' will be compared to rules). If several
  24573.           tables are to be updated (multi-table statement), the first
  24574.           matching table (matching "do" or "ignore") wins (that is, the
  24575.           first table is compared to rules, then if no decision could
  24576.           be taken the second table is compared to rules, etc).
  24577.  
  24578.   3. Are there some `--replicate-do-table' rules?
  24579.         * Yes: does the table match any of them?
  24580.              * Yes: execute the query and exit.
  24581.  
  24582.              * No: go to step below.
  24583.  
  24584.         * No: go to step below.
  24585.  
  24586.   4. Are there some `--replicate-ignore-table' rules?
  24587.         * Yes: does the table match any of them?
  24588.              * Yes: ignore the query and exit.
  24589.  
  24590.              * No: go to step below.
  24591.  
  24592.         * No: go to step below.
  24593.  
  24594.   5. Are there some `--replicate-wild-do-table' rules?
  24595.         * Yes: does the table match any of them?
  24596.              * Yes: execute the query and exit.
  24597.  
  24598.              * No: go to step below.
  24599.  
  24600.         * No: go to step below.
  24601.  
  24602.   6. Are there some `--replicate-wild-ignore-table' rules?
  24603.         * Yes: does the table match any of them?
  24604.              * Yes: ignore the query and exit.
  24605.  
  24606.              * No: go to step below.
  24607.  
  24608.         * No: go to step below.
  24609.  
  24610.   7. No `--replicate-*-table' rule was matched.  Is there another table
  24611.      to test against these rules?
  24612.         * Yes: loop.
  24613.  
  24614.         * No: we have tested all tables to be updated, could not match
  24615.           any rule.  Are there `--replicate-do-table' or
  24616.           `--replicate-wild-do-table' rules ?
  24617.              * Yes: ignore the query and exit.
  24618.  
  24619.              * No: execute the query and exit.
  24620.  
  24621. SQL Statements for Controlling Master Servers
  24622. ---------------------------------------------
  24623.  
  24624. Replication can be controlled through the SQL interface. This section
  24625. discusses statements for managing master replication servers.  *Note
  24626. Replication Slave SQL:: discusses statements for managing slave servers.
  24627.  
  24628. `PURGE MASTER LOGS'
  24629. ...................
  24630.  
  24631.      PURGE {MASTER|BINARY} LOGS TO 'log_name'
  24632.      PURGE {MASTER|BINARY} LOGS BEFORE 'date'
  24633.  
  24634. Deletes all the binary logs listed in the log index that are strictly
  24635. prior to the specified log or date.  The logs also are removed from
  24636. this list recorded in the log index file, so that the given log now
  24637. becomes the first.
  24638.  
  24639. Example:
  24640.  
  24641.      PURGE MASTER LOGS TO 'mysql-bin.010';
  24642.      PURGE MASTER LOGS BEFORE '2003-04-02 22:46:26';
  24643.  
  24644. The `BEFORE' variant is available in MySQL 4.1; its date argument can
  24645. be in `'YYYY-MM-DD hh:mm:ss'' format.  `MASTER' and `BINARY' are
  24646. synonyms, though `BINARY' can be used only as of MySQL 4.1.1.
  24647.  
  24648. If you have an active slave that is currently reading one of the logs
  24649. you are trying to delete, this command does nothing and fails with an
  24650. error.  However, if you have a dormant slave, and happen to purge one of
  24651. the logs it wants to read, the slave will be unable to replicate once it
  24652. comes up.  The command is safe to run while slaves are replicating. You
  24653. do not need to stop them.
  24654.  
  24655. You must first check all the slaves with `SHOW SLAVE STATUS' to see
  24656. which log they are reading, then do a listing of the logs on the master
  24657. with `SHOW MASTER LOGS', find the earliest log among all the slaves (if
  24658. all the slaves are up to date, this will be the last log on the list),
  24659. backup all the logs you are about to delete (optional) and purge up to
  24660. the target log.
  24661.  
  24662. `RESET MASTER'
  24663. ..............
  24664.  
  24665.      RESET MASTER
  24666.  
  24667. Deletes all binary logs listed in the index file, resetting the binlog
  24668. index file to be empty.
  24669.  
  24670. This statement was named `FLUSH MASTER' before MySQL 3.23.26.
  24671.  
  24672. `SET SQL_LOG_BIN'
  24673. .................
  24674.  
  24675.      SET SQL_LOG_BIN = {0|1}
  24676.  
  24677. Disables or enables binary logging for the current connection
  24678. (`SQL_LOG_BIN' is a session variable) if the client connects using an
  24679. account that has the `SUPER' privilege.  The statement is ignored if
  24680. the client does not have that privilege.
  24681.  
  24682. `SHOW BINLOG EVENTS'
  24683. ....................
  24684.  
  24685.      SHOW BINLOG EVENTS [ IN 'log_name' ] [ FROM pos ] [ LIMIT [offset,] row_count ]
  24686.  
  24687. Shows the events in the binary log.  If you do not specify
  24688. `'log_name'', the first binary log will be displayed.
  24689.  
  24690. This statement is available as of MySQL 4.0
  24691.  
  24692. `SHOW MASTER STATUS'
  24693. ....................
  24694.  
  24695.      SHOW MASTER STATUS
  24696.  
  24697. Provides status information on the binlog of the master.
  24698.  
  24699. `SHOW MASTER LOGS'
  24700. ..................
  24701.  
  24702.      SHOW MASTER LOGS
  24703.  
  24704. Lists the binary logs on the master. You should use this command before
  24705. using `PURGE MASTER LOGS' to find out how far you should go.
  24706.  
  24707. `SHOW SLAVE HOSTS'
  24708. ..................
  24709.  
  24710.      SHOW SLAVE HOSTS
  24711.  
  24712. Displays a list of slaves currently registered with the master.
  24713.  
  24714. SQL Statements for Controlling Slave Servers
  24715. --------------------------------------------
  24716.  
  24717. Replication can be controlled through the SQL interface. This section
  24718. discusses statements for managing slave replication servers.  *Note
  24719. Replication Master SQL:: discusses statements for managing master
  24720. servers.
  24721.  
  24722. `CHANGE MASTER TO'
  24723. ..................
  24724.  
  24725.      CHANGE MASTER TO master_def [, master_def] ...
  24726.      
  24727.      master_def =
  24728.            MASTER_HOST = 'host_name'
  24729.          | MASTER_USER = 'user_name'
  24730.          | MASTER_PASSWORD = 'password'
  24731.          | MASTER_PORT = port_num
  24732.          | MASTER_CONNECT_RETRY = count
  24733.          | MASTER_LOG_FILE = 'master_log_name'
  24734.          | MASTER_LOG_POS = master_log_pos
  24735.          | RELAY_LOG_FILE = 'relay_log_name'
  24736.          | RELAY_LOG_POS = relay_log_pos
  24737.          | MASTER_SSL = {0|1}
  24738.          | MASTER_SSL_CA = 'ca_file_name'
  24739.          | MASTER_SSL_CAPATH = 'ca_directory_name'
  24740.          | MASTER_SSL_CERT = 'cert_file_name'
  24741.          | MASTER_SSL_KEY = 'key_file_name'
  24742.          | MASTER_SSL_CIPHER = 'cipher_list'
  24743.  
  24744. `CHANGE MASTER' *is a "brutal" command. Before using it in production,
  24745. you should read this entire description.*
  24746.  
  24747. Changes the parameters that the slave server uses for connecting to and
  24748. communicating with the master server.  The possible `master_def' values
  24749. are shown above.
  24750.  
  24751. The relay log options (`RELAY_LOG_FILE' and `RELAY_LOG_POS') are
  24752. available beginning with MySQL 4.0.
  24753.  
  24754. The SSL options (`MASTER_SSL', `MASTER_SSL_CA', `MASTER_SSL_CAPATH',
  24755. `MASTER_SSL_CERT', `MASTER_SSL_KEY', and `MASTER_SSL_CIPHER') are
  24756. available beginning with MySQL 4.1.1.  You can change these options
  24757. even on slaves that are compiled without SSL support. They will be
  24758. saved to the `master.info' file but ignored until you use a server that
  24759. has SSL support enabled.
  24760.  
  24761. For example:
  24762.  
  24763.      mysql> CHANGE MASTER TO
  24764.          ->     MASTER_HOST='master2.mycompany.com',
  24765.          ->     MASTER_USER='replication',
  24766.          ->     MASTER_PASSWORD='bigs3cret',
  24767.          ->     MASTER_PORT=3306,
  24768.          ->     MASTER_LOG_FILE='master2-bin.001',
  24769.          ->     MASTER_LOG_POS=4,
  24770.          ->     MASTER_CONNECT_RETRY=10;
  24771.      mysql> CHANGE MASTER TO
  24772.          ->     RELAY_LOG_FILE='slave-relay-bin.006',
  24773.          ->     RELAY_LOG_POS=4025;
  24774.  
  24775. You need to specify only the values that you want to change. The values
  24776. that you omit will stay the same, with the exception that if you specify
  24777. the master host or port, the slave will assume that the master server
  24778. is different than before. (This is true even if you specify a host or
  24779. port value value that is the same as the current value.) In this case,
  24780. the old values of master binlog name and position are considered no
  24781. longer applicable, so if you do not specify `MASTER_LOG_FILE' and
  24782. `MASTER_LOG_POS' in the command, `MASTER_LOG_FILE=''' and
  24783. `MASTER_LOG_POS=4' are silently appended to it.
  24784.  
  24785. `MASTER_LOG_FILE' and `MASTER_LOG_POS' are the coordinates at which the
  24786. slave I/O thread should begin reading from the master the next time the
  24787. thread starts. Because `CHANGE MASTER' deletes relay logs (see below),
  24788. these are also the coordinates from which the slave SQL thread will
  24789. begin executing the next time it starts.
  24790.  
  24791. `CHANGE MASTER' *deletes all relay logs* (and starts a new one), unless
  24792. you specified `RELAY_LOG_FILE' or `RELAY_LOG_POS' (in that case relay
  24793. logs will be kept; since MySQL 4.1.1 the `RELAY_LOG_PURGE' global
  24794. variable will silently be set to 0).  `CHANGE MASTER TO' updates
  24795. `master.info' and `relay-log.info'.
  24796.  
  24797. *Note:* If the slave SQL thread is late by one or more queries compared
  24798. to the I/O thread just before you issue `CHANGE MASTER' (a very common
  24799. case when replication is running in high-load environments), then as
  24800. `CHANGE MASTER' deletes relay logs containing these non-executed
  24801. queries, and so replication then restarts *from the coordinates of the
  24802. I/O thread*, *the SQL thread will have "leapt" over the non-executed
  24803. queries*.  Therefore, unless these queries were not important, you
  24804. should do one of the following before issuing `CHANGE MASTER':
  24805.  
  24806.    * Ensure that the slave SQL thread has read all existing relay logs.
  24807.      You can achieve this by stopping only the slave I/O thread (`STOP
  24808.      SLAVE IO_THREAD'), then monitoring the progress of the running
  24809.      slave SQL thread with `SHOW SLAVE STATUS' and `SELECT
  24810.      MASTER_POS_WAIT()', until it has caught up. This way there will be
  24811.      no leap for the slave SQL thread.
  24812.  
  24813.    * Run `STOP SLAVE', check where the slave SQL thread is in the
  24814.      master's binlog (using `SHOW SLAVE STATUS', columns
  24815.      `Relay_Master_Log_File' and `Exec_master_log_pos'), and add a
  24816.      specification of these coordinates to the `CHANGE MASTER' command
  24817.      (`MASTER_LOG_FILE=..., MASTER_LOG_POS=...').  This way, you will
  24818.      instruct the slave I/O thread to start replication from the former
  24819.      coordinates of the slave SQL thread, so there will be no leap for
  24820.      the slave SQL thread.
  24821. If you don't take care of this issue, even a simple `STOP SLAVE; CHANGE
  24822. MASTER TO MASTER_USER='repl'; START SLAVE;' run in the middle of a
  24823. highly-loaded replication could break this replication and spoil the
  24824. slave's data.
  24825.  
  24826. `CHANGE MASTER' is useful for setting up a slave when you have the
  24827. snapshot of the master and have recorded the log and the offset on the
  24828. master that the snapshot corresponds to. You can run  `CHANGE MASTER TO
  24829. MASTER_LOG_FILE='log_name_on_master',
  24830. MASTER_LOG_POS=log_offset_on_master' on the slave after restoring the
  24831. snapshot.
  24832.  
  24833. The first example above (`CHANGE MASTER TO
  24834. MASTER_HOST='master2.mycompany.com' etc') changes the master and
  24835. master's binlog coordinates. This is when you want the slave to
  24836. replicate the master.  The second example, less frequently used, is
  24837. when the slave has relay logs which, for some reason, you want the
  24838. slave to execute again; to do this the master needn't be reachable, you
  24839. just have to do `CHANGE MASTER TO' and start the SQL thread (`START
  24840. SLAVE SQL_THREAD').  You can even use this out of a replication setup,
  24841. on a standalone, slave-of-nobody server, to recover after a crash.
  24842. Suppose your server has crashed and you have restored a backup.  You
  24843. want to replay the server's own binlogs (not relay logs, but regular
  24844. binary logs), supposedly named `myhost-bin.*'. First make a backup copy
  24845. of these binlogs in some safe place, in case you don't exactly follow
  24846. the procedure below and accidentally have the server purge the binlogs.
  24847. If using MySQL 4.1.1 or newer, do `SET GLOBAL RELAY_LOG_PURGE=0' for
  24848. additional safety.  Then start the server without `log-bin', with a new
  24849. (different from before) server ID, with `relay-log=myhost-bin' (to make
  24850. the server believe that these regular binlogs are relay logs) and
  24851. `skip-slave-start', then issue these statements:
  24852.  
  24853.      mysql> CHANGE MASTER TO
  24854.          ->     RELAY_LOG_FILE='myhost-bin.153',
  24855.          ->     RELAY_LOG_POS=410,
  24856.          ->     MASTER_HOST='some_dummy_string';
  24857.      mysql> START SLAVE SQL_THREAD;
  24858.  
  24859. Then the server will read and execute its own binlogs, thus achieving
  24860. crash recovery.  Once the recovery is finished, run `STOP SLAVE',
  24861. shutdown the server, delete `master.info' and `relay-log.info', and
  24862. restart the server with its original options.  For the moment,
  24863. specifying `MASTER_HOST' (even with a dummy value) is compulsory to
  24864. make the server think it is a slave, and giving the server a new,
  24865. different from before, server ID is also compulsory otherwise the
  24866. server will see events with its ID and think it is in a circular
  24867. replication setup and skip the events, which is unwanted. In the future
  24868. we plan to add options to get rid of these small constraints.
  24869.  
  24870. `LOAD DATA FROM MASTER'
  24871. .......................
  24872.  
  24873.      LOAD DATA FROM MASTER
  24874.  
  24875. Takes a snapshot of the master and copies it to the slave.  Updates the
  24876. values of `MASTER_LOG_FILE' and `MASTER_LOG_POS' so that the slave will
  24877. start replicating from the correct position. Will honor table and
  24878. database exclusion rules specified with `replicate-*' options.
  24879.  
  24880. Use of this statement is subject to the following conditions:
  24881.  
  24882.    * It works only with `MyISAM' tables.
  24883.  
  24884.    * It acquires a global read lock on the master while taking the
  24885.      snapshot, which prevents updates on the master during the load
  24886.      operation.
  24887.  
  24888.  
  24889. In the future, it is planned to make this statement work with `InnoDB'
  24890. tables and to remove the need for global read lock by using the
  24891. non-blocking online backup